compiler-sfc.esm-browser.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952
  1. function makeMap(str, expectsLowerCase) {
  2. const map = /* @__PURE__ */ Object.create(null);
  3. const list = str.split(",");
  4. for (let i = 0; i < list.length; i++) {
  5. map[list[i]] = true;
  6. }
  7. return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];
  8. }
  9. const EMPTY_OBJ = Object.freeze({}) ;
  10. const NOOP = () => {
  11. };
  12. const NO = () => false;
  13. const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
  14. (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
  15. const extend = Object.assign;
  16. const hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  17. const hasOwn = (val, key) => hasOwnProperty$3.call(val, key);
  18. const isArray$3 = Array.isArray;
  19. const isMap = (val) => toTypeString(val) === "[object Map]";
  20. const isSet = (val) => toTypeString(val) === "[object Set]";
  21. const isFunction$1 = (val) => typeof val === "function";
  22. const isString$2 = (val) => typeof val === "string";
  23. const isSymbol$1 = (val) => typeof val === "symbol";
  24. const isObject$2 = (val) => val !== null && typeof val === "object";
  25. const objectToString$1 = Object.prototype.toString;
  26. const toTypeString = (value) => objectToString$1.call(value);
  27. const isPlainObject = (val) => toTypeString(val) === "[object Object]";
  28. const isReservedProp = /* @__PURE__ */ makeMap(
  29. // the leading comma is intentional so empty string "" is also included
  30. ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
  31. );
  32. const isBuiltInDirective = /* @__PURE__ */ makeMap(
  33. "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
  34. );
  35. const cacheStringFunction = (fn) => {
  36. const cache = /* @__PURE__ */ Object.create(null);
  37. return (str) => {
  38. const hit = cache[str];
  39. return hit || (cache[str] = fn(str));
  40. };
  41. };
  42. const camelizeRE = /-(\w)/g;
  43. const camelize = cacheStringFunction((str) => {
  44. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
  45. });
  46. const hyphenateRE = /\B([A-Z])/g;
  47. const hyphenate = cacheStringFunction(
  48. (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
  49. );
  50. const capitalize$1 = cacheStringFunction((str) => {
  51. return str.charAt(0).toUpperCase() + str.slice(1);
  52. });
  53. const toHandlerKey = cacheStringFunction((str) => {
  54. const s = str ? `on${capitalize$1(str)}` : ``;
  55. return s;
  56. });
  57. const identRE = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
  58. function genPropsAccessExp(name) {
  59. return identRE.test(name) ? `__props.${name}` : `__props[${JSON.stringify(name)}]`;
  60. }
  61. const PatchFlagNames = {
  62. [1]: `TEXT`,
  63. [2]: `CLASS`,
  64. [4]: `STYLE`,
  65. [8]: `PROPS`,
  66. [16]: `FULL_PROPS`,
  67. [32]: `NEED_HYDRATION`,
  68. [64]: `STABLE_FRAGMENT`,
  69. [128]: `KEYED_FRAGMENT`,
  70. [256]: `UNKEYED_FRAGMENT`,
  71. [512]: `NEED_PATCH`,
  72. [1024]: `DYNAMIC_SLOTS`,
  73. [2048]: `DEV_ROOT_FRAGMENT`,
  74. [-1]: `HOISTED`,
  75. [-2]: `BAIL`
  76. };
  77. const slotFlagsText = {
  78. [1]: "STABLE",
  79. [2]: "DYNAMIC",
  80. [3]: "FORWARDED"
  81. };
  82. 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";
  83. const isGloballyAllowed = /* @__PURE__ */ makeMap(GLOBALS_ALLOWED);
  84. const range = 2;
  85. function generateCodeFrame(source, start = 0, end = source.length) {
  86. let lines = source.split(/(\r?\n)/);
  87. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  88. lines = lines.filter((_, idx) => idx % 2 === 0);
  89. let count = 0;
  90. const res = [];
  91. for (let i = 0; i < lines.length; i++) {
  92. count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
  93. if (count >= start) {
  94. for (let j = i - range; j <= i + range || end > count; j++) {
  95. if (j < 0 || j >= lines.length)
  96. continue;
  97. const line = j + 1;
  98. res.push(
  99. `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
  100. );
  101. const lineLength = lines[j].length;
  102. const newLineSeqLength = newlineSequences[j] && newlineSequences[j].length || 0;
  103. if (j === i) {
  104. const pad = start - (count - (lineLength + newLineSeqLength));
  105. const length = Math.max(
  106. 1,
  107. end > count ? lineLength - pad : end - start
  108. );
  109. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  110. } else if (j > i) {
  111. if (end > count) {
  112. const length = Math.max(Math.min(end - count, lineLength), 1);
  113. res.push(` | ` + "^".repeat(length));
  114. }
  115. count += lineLength + newLineSeqLength;
  116. }
  117. }
  118. break;
  119. }
  120. }
  121. return res.join("\n");
  122. }
  123. function normalizeStyle(value) {
  124. if (isArray$3(value)) {
  125. const res = {};
  126. for (let i = 0; i < value.length; i++) {
  127. const item = value[i];
  128. const normalized = isString$2(item) ? parseStringStyle(item) : normalizeStyle(item);
  129. if (normalized) {
  130. for (const key in normalized) {
  131. res[key] = normalized[key];
  132. }
  133. }
  134. }
  135. return res;
  136. } else if (isString$2(value) || isObject$2(value)) {
  137. return value;
  138. }
  139. }
  140. const listDelimiterRE = /;(?![^(]*\))/g;
  141. const propertyDelimiterRE = /:([^]+)/;
  142. const styleCommentRE = /\/\*[^]*?\*\//g;
  143. function parseStringStyle(cssText) {
  144. const ret = {};
  145. cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
  146. if (item) {
  147. const tmp = item.split(propertyDelimiterRE);
  148. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  149. }
  150. });
  151. return ret;
  152. }
  153. function stringifyStyle(styles) {
  154. let ret = "";
  155. if (!styles || isString$2(styles)) {
  156. return ret;
  157. }
  158. for (const key in styles) {
  159. const value = styles[key];
  160. const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
  161. if (isString$2(value) || typeof value === "number") {
  162. ret += `${normalizedKey}:${value};`;
  163. }
  164. }
  165. return ret;
  166. }
  167. function normalizeClass(value) {
  168. let res = "";
  169. if (isString$2(value)) {
  170. res = value;
  171. } else if (isArray$3(value)) {
  172. for (let i = 0; i < value.length; i++) {
  173. const normalized = normalizeClass(value[i]);
  174. if (normalized) {
  175. res += normalized + " ";
  176. }
  177. }
  178. } else if (isObject$2(value)) {
  179. for (const name in value) {
  180. if (value[name]) {
  181. res += name + " ";
  182. }
  183. }
  184. }
  185. return res.trim();
  186. }
  187. 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";
  188. 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";
  189. const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
  190. const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
  191. const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
  192. const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
  193. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  194. const isBooleanAttr = /* @__PURE__ */ makeMap(
  195. specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`
  196. );
  197. const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
  198. const attrValidationCache = {};
  199. function isSSRSafeAttrName(name) {
  200. if (attrValidationCache.hasOwnProperty(name)) {
  201. return attrValidationCache[name];
  202. }
  203. const isUnsafe = unsafeAttrCharRE.test(name);
  204. if (isUnsafe) {
  205. console.error(`unsafe attribute name: ${name}`);
  206. }
  207. return attrValidationCache[name] = !isUnsafe;
  208. }
  209. const propsToAttrMap = {
  210. acceptCharset: "accept-charset",
  211. className: "class",
  212. htmlFor: "for",
  213. httpEquiv: "http-equiv"
  214. };
  215. const isKnownHtmlAttr = /* @__PURE__ */ makeMap(
  216. `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`
  217. );
  218. const isKnownSvgAttr = /* @__PURE__ */ makeMap(
  219. `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,xml:base,xml:lang,xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`
  220. );
  221. const escapeRE = /["'&<>]/;
  222. function escapeHtml(string) {
  223. const str = "" + string;
  224. const match = escapeRE.exec(str);
  225. if (!match) {
  226. return str;
  227. }
  228. let html = "";
  229. let escaped;
  230. let index;
  231. let lastIndex = 0;
  232. for (index = match.index; index < str.length; index++) {
  233. switch (str.charCodeAt(index)) {
  234. case 34:
  235. escaped = "&quot;";
  236. break;
  237. case 38:
  238. escaped = "&amp;";
  239. break;
  240. case 39:
  241. escaped = "&#39;";
  242. break;
  243. case 60:
  244. escaped = "&lt;";
  245. break;
  246. case 62:
  247. escaped = "&gt;";
  248. break;
  249. default:
  250. continue;
  251. }
  252. if (lastIndex !== index) {
  253. html += str.slice(lastIndex, index);
  254. }
  255. lastIndex = index + 1;
  256. html += escaped;
  257. }
  258. return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
  259. }
  260. const toDisplayString = (val) => {
  261. return isString$2(val) ? val : val == null ? "" : isArray$3(val) || isObject$2(val) && (val.toString === objectToString$1 || !isFunction$1(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);
  262. };
  263. const replacer = (_key, val) => {
  264. if (val && val.__v_isRef) {
  265. return replacer(_key, val.value);
  266. } else if (isMap(val)) {
  267. return {
  268. [`Map(${val.size})`]: [...val.entries()].reduce(
  269. (entries, [key, val2], i) => {
  270. entries[stringifySymbol(key, i) + " =>"] = val2;
  271. return entries;
  272. },
  273. {}
  274. )
  275. };
  276. } else if (isSet(val)) {
  277. return {
  278. [`Set(${val.size})`]: [...val.values()].map((v) => stringifySymbol(v))
  279. };
  280. } else if (isSymbol$1(val)) {
  281. return stringifySymbol(val);
  282. } else if (isObject$2(val) && !isArray$3(val) && !isPlainObject(val)) {
  283. return String(val);
  284. }
  285. return val;
  286. };
  287. const stringifySymbol = (v, i = "") => {
  288. var _a;
  289. return isSymbol$1(v) ? `Symbol(${(_a = v.description) != null ? _a : i})` : v;
  290. };
  291. function defaultOnError(error) {
  292. throw error;
  293. }
  294. function defaultOnWarn(msg) {
  295. console.warn(`[Vue warn] ${msg.message}`);
  296. }
  297. function createCompilerError(code, loc, messages, additionalMessage) {
  298. const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
  299. const error = new SyntaxError(String(msg));
  300. error.code = code;
  301. error.loc = loc;
  302. return error;
  303. }
  304. const errorMessages = {
  305. // parse errors
  306. [0]: "Illegal comment.",
  307. [1]: "CDATA section is allowed only in XML context.",
  308. [2]: "Duplicate attribute.",
  309. [3]: "End tag cannot have attributes.",
  310. [4]: "Illegal '/' in tags.",
  311. [5]: "Unexpected EOF in tag.",
  312. [6]: "Unexpected EOF in CDATA section.",
  313. [7]: "Unexpected EOF in comment.",
  314. [8]: "Unexpected EOF in script.",
  315. [9]: "Unexpected EOF in tag.",
  316. [10]: "Incorrectly closed comment.",
  317. [11]: "Incorrectly opened comment.",
  318. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  319. [13]: "Attribute value was expected.",
  320. [14]: "End tag name was expected.",
  321. [15]: "Whitespace was expected.",
  322. [16]: "Unexpected '<!--' in comment.",
  323. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  324. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  325. [19]: "Attribute name cannot start with '='.",
  326. [21]: "'<?' is allowed only in XML context.",
  327. [20]: `Unexpected null character.`,
  328. [22]: "Illegal '/' in tags.",
  329. // Vue-specific parse errors
  330. [23]: "Invalid end tag.",
  331. [24]: "Element is missing end tag.",
  332. [25]: "Interpolation end sign was not found.",
  333. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  334. [26]: "Legal directive name was expected.",
  335. // transform errors
  336. [28]: `v-if/v-else-if is missing expression.`,
  337. [29]: `v-if/else branches must use unique keys.`,
  338. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  339. [31]: `v-for is missing expression.`,
  340. [32]: `v-for has invalid expression.`,
  341. [33]: `<template v-for> key should be placed on the <template> tag.`,
  342. [34]: `v-bind is missing expression.`,
  343. [35]: `v-on is missing expression.`,
  344. [36]: `Unexpected custom directive on <slot> outlet.`,
  345. [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.`,
  346. [38]: `Duplicate slot names found. `,
  347. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  348. [40]: `v-slot can only be used on components or <template> tags.`,
  349. [41]: `v-model is missing expression.`,
  350. [42]: `v-model value must be a valid JavaScript member expression.`,
  351. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  352. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  353. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  354. [45]: `Error parsing JavaScript expression: `,
  355. [46]: `<KeepAlive> expects exactly one child component.`,
  356. // generic errors
  357. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  358. [48]: `ES module mode is not supported in this build of compiler.`,
  359. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  360. [50]: `"scopeId" option is only supported in module mode.`,
  361. // deprecations
  362. [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
  363. [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
  364. // just to fulfill types
  365. [53]: ``
  366. };
  367. const FRAGMENT = Symbol(`Fragment` );
  368. const TELEPORT = Symbol(`Teleport` );
  369. const SUSPENSE = Symbol(`Suspense` );
  370. const KEEP_ALIVE = Symbol(`KeepAlive` );
  371. const BASE_TRANSITION = Symbol(`BaseTransition` );
  372. const OPEN_BLOCK = Symbol(`openBlock` );
  373. const CREATE_BLOCK = Symbol(`createBlock` );
  374. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  375. const CREATE_VNODE = Symbol(`createVNode` );
  376. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  377. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  378. const CREATE_TEXT = Symbol(`createTextVNode` );
  379. const CREATE_STATIC = Symbol(`createStaticVNode` );
  380. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  381. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  382. `resolveDynamicComponent`
  383. );
  384. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  385. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  386. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  387. const RENDER_LIST = Symbol(`renderList` );
  388. const RENDER_SLOT = Symbol(`renderSlot` );
  389. const CREATE_SLOTS = Symbol(`createSlots` );
  390. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  391. const MERGE_PROPS = Symbol(`mergeProps` );
  392. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  393. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  394. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  395. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  396. const TO_HANDLERS = Symbol(`toHandlers` );
  397. const CAMELIZE = Symbol(`camelize` );
  398. const CAPITALIZE = Symbol(`capitalize` );
  399. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  400. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  401. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  402. const POP_SCOPE_ID = Symbol(`popScopeId` );
  403. const WITH_CTX = Symbol(`withCtx` );
  404. const UNREF = Symbol(`unref` );
  405. const IS_REF = Symbol(`isRef` );
  406. const WITH_MEMO = Symbol(`withMemo` );
  407. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  408. const helperNameMap = {
  409. [FRAGMENT]: `Fragment`,
  410. [TELEPORT]: `Teleport`,
  411. [SUSPENSE]: `Suspense`,
  412. [KEEP_ALIVE]: `KeepAlive`,
  413. [BASE_TRANSITION]: `BaseTransition`,
  414. [OPEN_BLOCK]: `openBlock`,
  415. [CREATE_BLOCK]: `createBlock`,
  416. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  417. [CREATE_VNODE]: `createVNode`,
  418. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  419. [CREATE_COMMENT]: `createCommentVNode`,
  420. [CREATE_TEXT]: `createTextVNode`,
  421. [CREATE_STATIC]: `createStaticVNode`,
  422. [RESOLVE_COMPONENT]: `resolveComponent`,
  423. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  424. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  425. [RESOLVE_FILTER]: `resolveFilter`,
  426. [WITH_DIRECTIVES]: `withDirectives`,
  427. [RENDER_LIST]: `renderList`,
  428. [RENDER_SLOT]: `renderSlot`,
  429. [CREATE_SLOTS]: `createSlots`,
  430. [TO_DISPLAY_STRING]: `toDisplayString`,
  431. [MERGE_PROPS]: `mergeProps`,
  432. [NORMALIZE_CLASS]: `normalizeClass`,
  433. [NORMALIZE_STYLE]: `normalizeStyle`,
  434. [NORMALIZE_PROPS]: `normalizeProps`,
  435. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  436. [TO_HANDLERS]: `toHandlers`,
  437. [CAMELIZE]: `camelize`,
  438. [CAPITALIZE]: `capitalize`,
  439. [TO_HANDLER_KEY]: `toHandlerKey`,
  440. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  441. [PUSH_SCOPE_ID]: `pushScopeId`,
  442. [POP_SCOPE_ID]: `popScopeId`,
  443. [WITH_CTX]: `withCtx`,
  444. [UNREF]: `unref`,
  445. [IS_REF]: `isRef`,
  446. [WITH_MEMO]: `withMemo`,
  447. [IS_MEMO_SAME]: `isMemoSame`
  448. };
  449. function registerRuntimeHelpers(helpers) {
  450. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  451. helperNameMap[s] = helpers[s];
  452. });
  453. }
  454. const locStub = {
  455. source: "",
  456. start: { line: 1, column: 1, offset: 0 },
  457. end: { line: 1, column: 1, offset: 0 }
  458. };
  459. function createRoot(children, loc = locStub) {
  460. return {
  461. type: 0,
  462. children,
  463. helpers: /* @__PURE__ */ new Set(),
  464. components: [],
  465. directives: [],
  466. hoists: [],
  467. imports: [],
  468. cached: 0,
  469. temps: 0,
  470. codegenNode: void 0,
  471. loc
  472. };
  473. }
  474. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  475. if (context) {
  476. if (isBlock) {
  477. context.helper(OPEN_BLOCK);
  478. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  479. } else {
  480. context.helper(getVNodeHelper(context.inSSR, isComponent));
  481. }
  482. if (directives) {
  483. context.helper(WITH_DIRECTIVES);
  484. }
  485. }
  486. return {
  487. type: 13,
  488. tag,
  489. props,
  490. children,
  491. patchFlag,
  492. dynamicProps,
  493. directives,
  494. isBlock,
  495. disableTracking,
  496. isComponent,
  497. loc
  498. };
  499. }
  500. function createArrayExpression(elements, loc = locStub) {
  501. return {
  502. type: 17,
  503. loc,
  504. elements
  505. };
  506. }
  507. function createObjectExpression(properties, loc = locStub) {
  508. return {
  509. type: 15,
  510. loc,
  511. properties
  512. };
  513. }
  514. function createObjectProperty(key, value) {
  515. return {
  516. type: 16,
  517. loc: locStub,
  518. key: isString$2(key) ? createSimpleExpression(key, true) : key,
  519. value
  520. };
  521. }
  522. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  523. return {
  524. type: 4,
  525. loc,
  526. content,
  527. isStatic,
  528. constType: isStatic ? 3 : constType
  529. };
  530. }
  531. function createInterpolation(content, loc) {
  532. return {
  533. type: 5,
  534. loc,
  535. content: isString$2(content) ? createSimpleExpression(content, false, loc) : content
  536. };
  537. }
  538. function createCompoundExpression(children, loc = locStub) {
  539. return {
  540. type: 8,
  541. loc,
  542. children
  543. };
  544. }
  545. function createCallExpression(callee, args = [], loc = locStub) {
  546. return {
  547. type: 14,
  548. loc,
  549. callee,
  550. arguments: args
  551. };
  552. }
  553. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  554. return {
  555. type: 18,
  556. params,
  557. returns,
  558. newline,
  559. isSlot,
  560. loc
  561. };
  562. }
  563. function createConditionalExpression(test, consequent, alternate, newline = true) {
  564. return {
  565. type: 19,
  566. test,
  567. consequent,
  568. alternate,
  569. newline,
  570. loc: locStub
  571. };
  572. }
  573. function createCacheExpression(index, value, isVNode = false) {
  574. return {
  575. type: 20,
  576. index,
  577. value,
  578. isVNode,
  579. loc: locStub
  580. };
  581. }
  582. function createBlockStatement(body) {
  583. return {
  584. type: 21,
  585. body,
  586. loc: locStub
  587. };
  588. }
  589. function createTemplateLiteral(elements) {
  590. return {
  591. type: 22,
  592. elements,
  593. loc: locStub
  594. };
  595. }
  596. function createIfStatement(test, consequent, alternate) {
  597. return {
  598. type: 23,
  599. test,
  600. consequent,
  601. alternate,
  602. loc: locStub
  603. };
  604. }
  605. function createAssignmentExpression(left, right) {
  606. return {
  607. type: 24,
  608. left,
  609. right,
  610. loc: locStub
  611. };
  612. }
  613. function createSequenceExpression(expressions) {
  614. return {
  615. type: 25,
  616. expressions,
  617. loc: locStub
  618. };
  619. }
  620. function createReturnStatement(returns) {
  621. return {
  622. type: 26,
  623. returns,
  624. loc: locStub
  625. };
  626. }
  627. function getVNodeHelper(ssr, isComponent) {
  628. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  629. }
  630. function getVNodeBlockHelper(ssr, isComponent) {
  631. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  632. }
  633. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  634. if (!node.isBlock) {
  635. node.isBlock = true;
  636. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  637. helper(OPEN_BLOCK);
  638. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  639. }
  640. }
  641. function getDefaultExportFromCjs (x) {
  642. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  643. }
  644. function getAugmentedNamespace(n) {
  645. if (n.__esModule) return n;
  646. var f = n.default;
  647. if (typeof f == "function") {
  648. var a = function a () {
  649. if (this instanceof a) {
  650. return Reflect.construct(f, arguments, this.constructor);
  651. }
  652. return f.apply(this, arguments);
  653. };
  654. a.prototype = f.prototype;
  655. } else a = {};
  656. Object.defineProperty(a, '__esModule', {value: true});
  657. Object.keys(n).forEach(function (k) {
  658. var d = Object.getOwnPropertyDescriptor(n, k);
  659. Object.defineProperty(a, k, d.get ? d : {
  660. enumerable: true,
  661. get: function () {
  662. return n[k];
  663. }
  664. });
  665. });
  666. return a;
  667. }
  668. var lib = {};
  669. Object.defineProperty(lib, '__esModule', {
  670. value: true
  671. });
  672. function _objectWithoutPropertiesLoose(source, excluded) {
  673. if (source == null) return {};
  674. var target = {};
  675. var sourceKeys = Object.keys(source);
  676. var key, i;
  677. for (i = 0; i < sourceKeys.length; i++) {
  678. key = sourceKeys[i];
  679. if (excluded.indexOf(key) >= 0) continue;
  680. target[key] = source[key];
  681. }
  682. return target;
  683. }
  684. class Position {
  685. constructor(line, col, index) {
  686. this.line = void 0;
  687. this.column = void 0;
  688. this.index = void 0;
  689. this.line = line;
  690. this.column = col;
  691. this.index = index;
  692. }
  693. }
  694. class SourceLocation {
  695. constructor(start, end) {
  696. this.start = void 0;
  697. this.end = void 0;
  698. this.filename = void 0;
  699. this.identifierName = void 0;
  700. this.start = start;
  701. this.end = end;
  702. }
  703. }
  704. function createPositionWithColumnOffset(position, columnOffset) {
  705. const {
  706. line,
  707. column,
  708. index
  709. } = position;
  710. return new Position(line, column + columnOffset, index + columnOffset);
  711. }
  712. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  713. var ModuleErrors = {
  714. ImportMetaOutsideModule: {
  715. message: `import.meta may appear only with 'sourceType: "module"'`,
  716. code
  717. },
  718. ImportOutsideModule: {
  719. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  720. code
  721. }
  722. };
  723. const NodeDescriptions = {
  724. ArrayPattern: "array destructuring pattern",
  725. AssignmentExpression: "assignment expression",
  726. AssignmentPattern: "assignment expression",
  727. ArrowFunctionExpression: "arrow function expression",
  728. ConditionalExpression: "conditional expression",
  729. CatchClause: "catch clause",
  730. ForOfStatement: "for-of statement",
  731. ForInStatement: "for-in statement",
  732. ForStatement: "for-loop",
  733. FormalParameters: "function parameter list",
  734. Identifier: "identifier",
  735. ImportSpecifier: "import specifier",
  736. ImportDefaultSpecifier: "import default specifier",
  737. ImportNamespaceSpecifier: "import namespace specifier",
  738. ObjectPattern: "object destructuring pattern",
  739. ParenthesizedExpression: "parenthesized expression",
  740. RestElement: "rest element",
  741. UpdateExpression: {
  742. true: "prefix operation",
  743. false: "postfix operation"
  744. },
  745. VariableDeclarator: "variable declaration",
  746. YieldExpression: "yield expression"
  747. };
  748. const toNodeDescription = ({
  749. type,
  750. prefix
  751. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  752. var StandardErrors = {
  753. AccessorIsGenerator: ({
  754. kind
  755. }) => `A ${kind}ter cannot be a generator.`,
  756. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  757. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  758. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  759. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  760. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  761. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  762. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  763. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  764. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  765. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  766. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  767. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  768. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  769. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  770. ConstructorIsAsync: "Constructor can't be an async function.",
  771. ConstructorIsGenerator: "Constructor can't be a generator.",
  772. DeclarationMissingInitializer: ({
  773. kind
  774. }) => `Missing initializer in ${kind} declaration.`,
  775. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  776. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  777. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  778. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  779. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  780. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  781. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  782. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  783. DeletePrivateField: "Deleting a private field is not allowed.",
  784. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  785. DuplicateConstructor: "Duplicate constructor in the same class.",
  786. DuplicateDefaultExport: "Only one default export allowed per module.",
  787. DuplicateExport: ({
  788. exportName
  789. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  790. DuplicateProto: "Redefinition of __proto__ property.",
  791. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  792. DynamicImportPhaseRequiresImportExpressions: ({
  793. phase
  794. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  795. ElementAfterRest: "Rest element must be last element.",
  796. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  797. ExportBindingIsString: ({
  798. localName,
  799. exportName
  800. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  801. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  802. ForInOfLoopInitializer: ({
  803. type
  804. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  805. ForInUsing: "For-in loop may not start with 'using' declaration.",
  806. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  807. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  808. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  809. IllegalBreakContinue: ({
  810. type
  811. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  812. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  813. IllegalReturn: "'return' outside of function.",
  814. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedAssertSyntax: true` option in the import attributes plugin to suppress this error.",
  815. ImportBindingIsString: ({
  816. importName
  817. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  818. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  819. ImportCallArity: ({
  820. maxArgumentCount
  821. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  822. ImportCallNotNewExpression: "Cannot use new with import(...).",
  823. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  824. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  825. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  826. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  827. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  828. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  829. InvalidCodePoint: "Code point out of bounds.",
  830. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  831. InvalidDecimal: "Invalid decimal.",
  832. InvalidDigit: ({
  833. radix
  834. }) => `Expected number in radix ${radix}.`,
  835. InvalidEscapeSequence: "Bad character escape sequence.",
  836. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  837. InvalidEscapedReservedWord: ({
  838. reservedWord
  839. }) => `Escape sequence in keyword ${reservedWord}.`,
  840. InvalidIdentifier: ({
  841. identifierName
  842. }) => `Invalid identifier ${identifierName}.`,
  843. InvalidLhs: ({
  844. ancestor
  845. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  846. InvalidLhsBinding: ({
  847. ancestor
  848. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  849. InvalidLhsOptionalChaining: ({
  850. ancestor
  851. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  852. InvalidNumber: "Invalid number.",
  853. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  854. InvalidOrUnexpectedToken: ({
  855. unexpected
  856. }) => `Unexpected character '${unexpected}'.`,
  857. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  858. InvalidPrivateFieldResolution: ({
  859. identifierName
  860. }) => `Private name #${identifierName} is not defined.`,
  861. InvalidPropertyBindingPattern: "Binding member expression.",
  862. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  863. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  864. LabelRedeclaration: ({
  865. labelName
  866. }) => `Label '${labelName}' is already declared.`,
  867. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  868. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  869. MalformedRegExpFlags: "Invalid regular expression flag.",
  870. MissingClassName: "A class name is required.",
  871. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  872. MissingSemicolon: "Missing semicolon.",
  873. MissingPlugin: ({
  874. missingPlugin
  875. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  876. MissingOneOfPlugins: ({
  877. missingPlugin
  878. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  879. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  880. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  881. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  882. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  883. ModuleAttributesWithDuplicateKeys: ({
  884. key
  885. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  886. ModuleExportNameHasLoneSurrogate: ({
  887. surrogateCharCode
  888. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  889. ModuleExportUndefined: ({
  890. localName
  891. }) => `Export '${localName}' is not defined.`,
  892. MultipleDefaultsInSwitch: "Multiple default clauses.",
  893. NewlineAfterThrow: "Illegal newline after throw.",
  894. NoCatchOrFinally: "Missing catch or finally clause.",
  895. NumberIdentifier: "Identifier directly after number.",
  896. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  897. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  898. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  899. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  900. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  901. ParamDupe: "Argument name clash.",
  902. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  903. PatternHasMethod: "Object pattern can't contain methods.",
  904. PrivateInExpectedIn: ({
  905. identifierName
  906. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  907. PrivateNameRedeclaration: ({
  908. identifierName
  909. }) => `Duplicate private name #${identifierName}.`,
  910. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  911. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  912. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  913. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  914. RestTrailingComma: "Unexpected trailing comma after rest element.",
  915. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  916. 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.",
  917. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  918. StaticPrototype: "Classes may not have static property named prototype.",
  919. 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?",
  920. SuperPrivateField: "Private fields can't be accessed on super.",
  921. TrailingDecorator: "Decorators must be attached to a class element.",
  922. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  923. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  924. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  925. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  926. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  927. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  928. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  929. UnexpectedKeyword: ({
  930. keyword
  931. }) => `Unexpected keyword '${keyword}'.`,
  932. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  933. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  934. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  935. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  936. UnexpectedPrivateField: "Unexpected private name.",
  937. UnexpectedReservedWord: ({
  938. reservedWord
  939. }) => `Unexpected reserved word '${reservedWord}'.`,
  940. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  941. UnexpectedToken: ({
  942. expected,
  943. unexpected
  944. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  945. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  946. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  947. UnsupportedBind: "Binding should be performed on object property.",
  948. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  949. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  950. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  951. UnsupportedMetaProperty: ({
  952. target,
  953. onlyValidPropertyName
  954. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  955. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  956. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  957. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  958. UnterminatedComment: "Unterminated comment.",
  959. UnterminatedRegExp: "Unterminated regular expression.",
  960. UnterminatedString: "Unterminated string constant.",
  961. UnterminatedTemplate: "Unterminated template.",
  962. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  963. VarRedeclaration: ({
  964. identifierName
  965. }) => `Identifier '${identifierName}' has already been declared.`,
  966. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  967. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  968. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  969. };
  970. var StrictModeErrors = {
  971. StrictDelete: "Deleting local variable in strict mode.",
  972. StrictEvalArguments: ({
  973. referenceName
  974. }) => `Assigning to '${referenceName}' in strict mode.`,
  975. StrictEvalArgumentsBinding: ({
  976. bindingName
  977. }) => `Binding '${bindingName}' in strict mode.`,
  978. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  979. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  980. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  981. StrictWith: "'with' in strict mode."
  982. };
  983. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  984. var PipelineOperatorErrors = {
  985. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  986. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  987. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  988. PipeTopicUnconfiguredToken: ({
  989. token
  990. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  991. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  992. PipeUnparenthesizedBody: ({
  993. type
  994. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  995. type
  996. })}; please wrap it in parentheses.`,
  997. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  998. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  999. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  1000. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  1001. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  1002. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  1003. };
  1004. const _excluded$1 = ["toMessage"],
  1005. _excluded2$1 = ["message"];
  1006. function defineHidden(obj, key, value) {
  1007. Object.defineProperty(obj, key, {
  1008. enumerable: false,
  1009. configurable: true,
  1010. value
  1011. });
  1012. }
  1013. function toParseErrorConstructor(_ref) {
  1014. let {
  1015. toMessage
  1016. } = _ref,
  1017. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  1018. return function constructor({
  1019. loc,
  1020. details
  1021. }) {
  1022. const error = new SyntaxError();
  1023. Object.assign(error, properties, {
  1024. loc,
  1025. pos: loc.index
  1026. });
  1027. if ("missingPlugin" in details) {
  1028. Object.assign(error, {
  1029. missingPlugin: details.missingPlugin
  1030. });
  1031. }
  1032. defineHidden(error, "clone", function clone(overrides = {}) {
  1033. var _overrides$loc;
  1034. const {
  1035. line,
  1036. column,
  1037. index
  1038. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  1039. return constructor({
  1040. loc: new Position(line, column, index),
  1041. details: Object.assign({}, details, overrides.details)
  1042. });
  1043. });
  1044. defineHidden(error, "details", details);
  1045. Object.defineProperty(error, "message", {
  1046. configurable: true,
  1047. get() {
  1048. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  1049. this.message = message;
  1050. return message;
  1051. },
  1052. set(value) {
  1053. Object.defineProperty(this, "message", {
  1054. value,
  1055. writable: true
  1056. });
  1057. }
  1058. });
  1059. return error;
  1060. };
  1061. }
  1062. function ParseErrorEnum(argument, syntaxPlugin) {
  1063. if (Array.isArray(argument)) {
  1064. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  1065. }
  1066. const ParseErrorConstructors = {};
  1067. for (const reasonCode of Object.keys(argument)) {
  1068. const template = argument[reasonCode];
  1069. const _ref2 = typeof template === "string" ? {
  1070. message: () => template
  1071. } : typeof template === "function" ? {
  1072. message: template
  1073. } : template,
  1074. {
  1075. message
  1076. } = _ref2,
  1077. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  1078. const toMessage = typeof message === "string" ? () => message : message;
  1079. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  1080. code: "BABEL_PARSER_SYNTAX_ERROR",
  1081. reasonCode,
  1082. toMessage
  1083. }, syntaxPlugin ? {
  1084. syntaxPlugin
  1085. } : {}, rest));
  1086. }
  1087. return ParseErrorConstructors;
  1088. }
  1089. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  1090. const {
  1091. defineProperty
  1092. } = Object;
  1093. const toUnenumerable = (object, key) => defineProperty(object, key, {
  1094. enumerable: false,
  1095. value: object[key]
  1096. });
  1097. function toESTreeLocation(node) {
  1098. node.loc.start && toUnenumerable(node.loc.start, "index");
  1099. node.loc.end && toUnenumerable(node.loc.end, "index");
  1100. return node;
  1101. }
  1102. var estree = superClass => class ESTreeParserMixin extends superClass {
  1103. parse() {
  1104. const file = toESTreeLocation(super.parse());
  1105. if (this.options.tokens) {
  1106. file.tokens = file.tokens.map(toESTreeLocation);
  1107. }
  1108. return file;
  1109. }
  1110. parseRegExpLiteral({
  1111. pattern,
  1112. flags
  1113. }) {
  1114. let regex = null;
  1115. try {
  1116. regex = new RegExp(pattern, flags);
  1117. } catch (e) {}
  1118. const node = this.estreeParseLiteral(regex);
  1119. node.regex = {
  1120. pattern,
  1121. flags
  1122. };
  1123. return node;
  1124. }
  1125. parseBigIntLiteral(value) {
  1126. let bigInt;
  1127. try {
  1128. bigInt = BigInt(value);
  1129. } catch (_unused) {
  1130. bigInt = null;
  1131. }
  1132. const node = this.estreeParseLiteral(bigInt);
  1133. node.bigint = String(node.value || value);
  1134. return node;
  1135. }
  1136. parseDecimalLiteral(value) {
  1137. const decimal = null;
  1138. const node = this.estreeParseLiteral(decimal);
  1139. node.decimal = String(node.value || value);
  1140. return node;
  1141. }
  1142. estreeParseLiteral(value) {
  1143. return this.parseLiteral(value, "Literal");
  1144. }
  1145. parseStringLiteral(value) {
  1146. return this.estreeParseLiteral(value);
  1147. }
  1148. parseNumericLiteral(value) {
  1149. return this.estreeParseLiteral(value);
  1150. }
  1151. parseNullLiteral() {
  1152. return this.estreeParseLiteral(null);
  1153. }
  1154. parseBooleanLiteral(value) {
  1155. return this.estreeParseLiteral(value);
  1156. }
  1157. directiveToStmt(directive) {
  1158. const expression = directive.value;
  1159. delete directive.value;
  1160. expression.type = "Literal";
  1161. expression.raw = expression.extra.raw;
  1162. expression.value = expression.extra.expressionValue;
  1163. const stmt = directive;
  1164. stmt.type = "ExpressionStatement";
  1165. stmt.expression = expression;
  1166. stmt.directive = expression.extra.rawValue;
  1167. delete expression.extra;
  1168. return stmt;
  1169. }
  1170. initFunction(node, isAsync) {
  1171. super.initFunction(node, isAsync);
  1172. node.expression = false;
  1173. }
  1174. checkDeclaration(node) {
  1175. if (node != null && this.isObjectProperty(node)) {
  1176. this.checkDeclaration(node.value);
  1177. } else {
  1178. super.checkDeclaration(node);
  1179. }
  1180. }
  1181. getObjectOrClassMethodParams(method) {
  1182. return method.value.params;
  1183. }
  1184. isValidDirective(stmt) {
  1185. var _stmt$expression$extr;
  1186. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  1187. }
  1188. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  1189. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  1190. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  1191. node.body = directiveStatements.concat(node.body);
  1192. delete node.directives;
  1193. }
  1194. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  1195. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  1196. if (method.typeParameters) {
  1197. method.value.typeParameters = method.typeParameters;
  1198. delete method.typeParameters;
  1199. }
  1200. classBody.body.push(method);
  1201. }
  1202. parsePrivateName() {
  1203. const node = super.parsePrivateName();
  1204. {
  1205. if (!this.getPluginOption("estree", "classFeatures")) {
  1206. return node;
  1207. }
  1208. }
  1209. return this.convertPrivateNameToPrivateIdentifier(node);
  1210. }
  1211. convertPrivateNameToPrivateIdentifier(node) {
  1212. const name = super.getPrivateNameSV(node);
  1213. node = node;
  1214. delete node.id;
  1215. node.name = name;
  1216. node.type = "PrivateIdentifier";
  1217. return node;
  1218. }
  1219. isPrivateName(node) {
  1220. {
  1221. if (!this.getPluginOption("estree", "classFeatures")) {
  1222. return super.isPrivateName(node);
  1223. }
  1224. }
  1225. return node.type === "PrivateIdentifier";
  1226. }
  1227. getPrivateNameSV(node) {
  1228. {
  1229. if (!this.getPluginOption("estree", "classFeatures")) {
  1230. return super.getPrivateNameSV(node);
  1231. }
  1232. }
  1233. return node.name;
  1234. }
  1235. parseLiteral(value, type) {
  1236. const node = super.parseLiteral(value, type);
  1237. node.raw = node.extra.raw;
  1238. delete node.extra;
  1239. return node;
  1240. }
  1241. parseFunctionBody(node, allowExpression, isMethod = false) {
  1242. super.parseFunctionBody(node, allowExpression, isMethod);
  1243. node.expression = node.body.type !== "BlockStatement";
  1244. }
  1245. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  1246. let funcNode = this.startNode();
  1247. funcNode.kind = node.kind;
  1248. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  1249. funcNode.type = "FunctionExpression";
  1250. delete funcNode.kind;
  1251. node.value = funcNode;
  1252. if (type === "ClassPrivateMethod") {
  1253. node.computed = false;
  1254. }
  1255. return this.finishNode(node, "MethodDefinition");
  1256. }
  1257. parseClassProperty(...args) {
  1258. const propertyNode = super.parseClassProperty(...args);
  1259. {
  1260. if (!this.getPluginOption("estree", "classFeatures")) {
  1261. return propertyNode;
  1262. }
  1263. }
  1264. propertyNode.type = "PropertyDefinition";
  1265. return propertyNode;
  1266. }
  1267. parseClassPrivateProperty(...args) {
  1268. const propertyNode = super.parseClassPrivateProperty(...args);
  1269. {
  1270. if (!this.getPluginOption("estree", "classFeatures")) {
  1271. return propertyNode;
  1272. }
  1273. }
  1274. propertyNode.type = "PropertyDefinition";
  1275. propertyNode.computed = false;
  1276. return propertyNode;
  1277. }
  1278. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  1279. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  1280. if (node) {
  1281. node.type = "Property";
  1282. if (node.kind === "method") {
  1283. node.kind = "init";
  1284. }
  1285. node.shorthand = false;
  1286. }
  1287. return node;
  1288. }
  1289. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  1290. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  1291. if (node) {
  1292. node.kind = "init";
  1293. node.type = "Property";
  1294. }
  1295. return node;
  1296. }
  1297. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  1298. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  1299. }
  1300. isAssignable(node, isBinding) {
  1301. if (node != null && this.isObjectProperty(node)) {
  1302. return this.isAssignable(node.value, isBinding);
  1303. }
  1304. return super.isAssignable(node, isBinding);
  1305. }
  1306. toAssignable(node, isLHS = false) {
  1307. if (node != null && this.isObjectProperty(node)) {
  1308. const {
  1309. key,
  1310. value
  1311. } = node;
  1312. if (this.isPrivateName(key)) {
  1313. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  1314. }
  1315. this.toAssignable(value, isLHS);
  1316. } else {
  1317. super.toAssignable(node, isLHS);
  1318. }
  1319. }
  1320. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  1321. if (prop.kind === "get" || prop.kind === "set") {
  1322. this.raise(Errors.PatternHasAccessor, {
  1323. at: prop.key
  1324. });
  1325. } else if (prop.method) {
  1326. this.raise(Errors.PatternHasMethod, {
  1327. at: prop.key
  1328. });
  1329. } else {
  1330. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  1331. }
  1332. }
  1333. finishCallExpression(unfinished, optional) {
  1334. const node = super.finishCallExpression(unfinished, optional);
  1335. if (node.callee.type === "Import") {
  1336. node.type = "ImportExpression";
  1337. node.source = node.arguments[0];
  1338. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  1339. var _node$arguments$, _node$arguments$2;
  1340. node.options = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  1341. node.attributes = (_node$arguments$2 = node.arguments[1]) != null ? _node$arguments$2 : null;
  1342. }
  1343. delete node.arguments;
  1344. delete node.callee;
  1345. }
  1346. return node;
  1347. }
  1348. toReferencedArguments(node) {
  1349. if (node.type === "ImportExpression") {
  1350. return;
  1351. }
  1352. super.toReferencedArguments(node);
  1353. }
  1354. parseExport(unfinished, decorators) {
  1355. const exportStartLoc = this.state.lastTokStartLoc;
  1356. const node = super.parseExport(unfinished, decorators);
  1357. switch (node.type) {
  1358. case "ExportAllDeclaration":
  1359. node.exported = null;
  1360. break;
  1361. case "ExportNamedDeclaration":
  1362. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  1363. node.type = "ExportAllDeclaration";
  1364. node.exported = node.specifiers[0].exported;
  1365. delete node.specifiers;
  1366. }
  1367. case "ExportDefaultDeclaration":
  1368. {
  1369. var _declaration$decorato;
  1370. const {
  1371. declaration
  1372. } = node;
  1373. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  1374. this.resetStartLocation(node, exportStartLoc);
  1375. }
  1376. }
  1377. break;
  1378. }
  1379. return node;
  1380. }
  1381. parseSubscript(base, startLoc, noCalls, state) {
  1382. const node = super.parseSubscript(base, startLoc, noCalls, state);
  1383. if (state.optionalChainMember) {
  1384. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  1385. node.type = node.type.substring(8);
  1386. }
  1387. if (state.stop) {
  1388. const chain = this.startNodeAtNode(node);
  1389. chain.expression = node;
  1390. return this.finishNode(chain, "ChainExpression");
  1391. }
  1392. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  1393. node.optional = false;
  1394. }
  1395. return node;
  1396. }
  1397. isOptionalMemberExpression(node) {
  1398. if (node.type === "ChainExpression") {
  1399. return node.expression.type === "MemberExpression";
  1400. }
  1401. return super.isOptionalMemberExpression(node);
  1402. }
  1403. hasPropertyAsPrivateName(node) {
  1404. if (node.type === "ChainExpression") {
  1405. node = node.expression;
  1406. }
  1407. return super.hasPropertyAsPrivateName(node);
  1408. }
  1409. isObjectProperty(node) {
  1410. return node.type === "Property" && node.kind === "init" && !node.method;
  1411. }
  1412. isObjectMethod(node) {
  1413. return node.method || node.kind === "get" || node.kind === "set";
  1414. }
  1415. finishNodeAt(node, type, endLoc) {
  1416. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  1417. }
  1418. resetStartLocation(node, startLoc) {
  1419. super.resetStartLocation(node, startLoc);
  1420. toESTreeLocation(node);
  1421. }
  1422. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  1423. super.resetEndLocation(node, endLoc);
  1424. toESTreeLocation(node);
  1425. }
  1426. };
  1427. class TokContext {
  1428. constructor(token, preserveSpace) {
  1429. this.token = void 0;
  1430. this.preserveSpace = void 0;
  1431. this.token = token;
  1432. this.preserveSpace = !!preserveSpace;
  1433. }
  1434. }
  1435. const types$1 = {
  1436. brace: new TokContext("{"),
  1437. j_oTag: new TokContext("<tag"),
  1438. j_cTag: new TokContext("</tag"),
  1439. j_expr: new TokContext("<tag>...</tag>", true)
  1440. };
  1441. {
  1442. types$1.template = new TokContext("`", true);
  1443. }
  1444. const beforeExpr = true;
  1445. const startsExpr = true;
  1446. const isLoop = true;
  1447. const isAssign = true;
  1448. const prefix = true;
  1449. const postfix = true;
  1450. class ExportedTokenType {
  1451. constructor(label, conf = {}) {
  1452. this.label = void 0;
  1453. this.keyword = void 0;
  1454. this.beforeExpr = void 0;
  1455. this.startsExpr = void 0;
  1456. this.rightAssociative = void 0;
  1457. this.isLoop = void 0;
  1458. this.isAssign = void 0;
  1459. this.prefix = void 0;
  1460. this.postfix = void 0;
  1461. this.binop = void 0;
  1462. this.label = label;
  1463. this.keyword = conf.keyword;
  1464. this.beforeExpr = !!conf.beforeExpr;
  1465. this.startsExpr = !!conf.startsExpr;
  1466. this.rightAssociative = !!conf.rightAssociative;
  1467. this.isLoop = !!conf.isLoop;
  1468. this.isAssign = !!conf.isAssign;
  1469. this.prefix = !!conf.prefix;
  1470. this.postfix = !!conf.postfix;
  1471. this.binop = conf.binop != null ? conf.binop : null;
  1472. {
  1473. this.updateContext = null;
  1474. }
  1475. }
  1476. }
  1477. const keywords$1 = new Map();
  1478. function createKeyword(name, options = {}) {
  1479. options.keyword = name;
  1480. const token = createToken(name, options);
  1481. keywords$1.set(name, token);
  1482. return token;
  1483. }
  1484. function createBinop(name, binop) {
  1485. return createToken(name, {
  1486. beforeExpr,
  1487. binop
  1488. });
  1489. }
  1490. let tokenTypeCounter = -1;
  1491. const tokenTypes$1 = [];
  1492. const tokenLabels = [];
  1493. const tokenBinops = [];
  1494. const tokenBeforeExprs = [];
  1495. const tokenStartsExprs = [];
  1496. const tokenPrefixes = [];
  1497. function createToken(name, options = {}) {
  1498. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  1499. ++tokenTypeCounter;
  1500. tokenLabels.push(name);
  1501. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  1502. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  1503. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  1504. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  1505. tokenTypes$1.push(new ExportedTokenType(name, options));
  1506. return tokenTypeCounter;
  1507. }
  1508. function createKeywordLike(name, options = {}) {
  1509. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  1510. ++tokenTypeCounter;
  1511. keywords$1.set(name, tokenTypeCounter);
  1512. tokenLabels.push(name);
  1513. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  1514. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  1515. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  1516. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  1517. tokenTypes$1.push(new ExportedTokenType("name", options));
  1518. return tokenTypeCounter;
  1519. }
  1520. const tt = {
  1521. bracketL: createToken("[", {
  1522. beforeExpr,
  1523. startsExpr
  1524. }),
  1525. bracketHashL: createToken("#[", {
  1526. beforeExpr,
  1527. startsExpr
  1528. }),
  1529. bracketBarL: createToken("[|", {
  1530. beforeExpr,
  1531. startsExpr
  1532. }),
  1533. bracketR: createToken("]"),
  1534. bracketBarR: createToken("|]"),
  1535. braceL: createToken("{", {
  1536. beforeExpr,
  1537. startsExpr
  1538. }),
  1539. braceBarL: createToken("{|", {
  1540. beforeExpr,
  1541. startsExpr
  1542. }),
  1543. braceHashL: createToken("#{", {
  1544. beforeExpr,
  1545. startsExpr
  1546. }),
  1547. braceR: createToken("}"),
  1548. braceBarR: createToken("|}"),
  1549. parenL: createToken("(", {
  1550. beforeExpr,
  1551. startsExpr
  1552. }),
  1553. parenR: createToken(")"),
  1554. comma: createToken(",", {
  1555. beforeExpr
  1556. }),
  1557. semi: createToken(";", {
  1558. beforeExpr
  1559. }),
  1560. colon: createToken(":", {
  1561. beforeExpr
  1562. }),
  1563. doubleColon: createToken("::", {
  1564. beforeExpr
  1565. }),
  1566. dot: createToken("."),
  1567. question: createToken("?", {
  1568. beforeExpr
  1569. }),
  1570. questionDot: createToken("?."),
  1571. arrow: createToken("=>", {
  1572. beforeExpr
  1573. }),
  1574. template: createToken("template"),
  1575. ellipsis: createToken("...", {
  1576. beforeExpr
  1577. }),
  1578. backQuote: createToken("`", {
  1579. startsExpr
  1580. }),
  1581. dollarBraceL: createToken("${", {
  1582. beforeExpr,
  1583. startsExpr
  1584. }),
  1585. templateTail: createToken("...`", {
  1586. startsExpr
  1587. }),
  1588. templateNonTail: createToken("...${", {
  1589. beforeExpr,
  1590. startsExpr
  1591. }),
  1592. at: createToken("@"),
  1593. hash: createToken("#", {
  1594. startsExpr
  1595. }),
  1596. interpreterDirective: createToken("#!..."),
  1597. eq: createToken("=", {
  1598. beforeExpr,
  1599. isAssign
  1600. }),
  1601. assign: createToken("_=", {
  1602. beforeExpr,
  1603. isAssign
  1604. }),
  1605. slashAssign: createToken("_=", {
  1606. beforeExpr,
  1607. isAssign
  1608. }),
  1609. xorAssign: createToken("_=", {
  1610. beforeExpr,
  1611. isAssign
  1612. }),
  1613. moduloAssign: createToken("_=", {
  1614. beforeExpr,
  1615. isAssign
  1616. }),
  1617. incDec: createToken("++/--", {
  1618. prefix,
  1619. postfix,
  1620. startsExpr
  1621. }),
  1622. bang: createToken("!", {
  1623. beforeExpr,
  1624. prefix,
  1625. startsExpr
  1626. }),
  1627. tilde: createToken("~", {
  1628. beforeExpr,
  1629. prefix,
  1630. startsExpr
  1631. }),
  1632. doubleCaret: createToken("^^", {
  1633. startsExpr
  1634. }),
  1635. doubleAt: createToken("@@", {
  1636. startsExpr
  1637. }),
  1638. pipeline: createBinop("|>", 0),
  1639. nullishCoalescing: createBinop("??", 1),
  1640. logicalOR: createBinop("||", 1),
  1641. logicalAND: createBinop("&&", 2),
  1642. bitwiseOR: createBinop("|", 3),
  1643. bitwiseXOR: createBinop("^", 4),
  1644. bitwiseAND: createBinop("&", 5),
  1645. equality: createBinop("==/!=/===/!==", 6),
  1646. lt: createBinop("</>/<=/>=", 7),
  1647. gt: createBinop("</>/<=/>=", 7),
  1648. relational: createBinop("</>/<=/>=", 7),
  1649. bitShift: createBinop("<</>>/>>>", 8),
  1650. bitShiftL: createBinop("<</>>/>>>", 8),
  1651. bitShiftR: createBinop("<</>>/>>>", 8),
  1652. plusMin: createToken("+/-", {
  1653. beforeExpr,
  1654. binop: 9,
  1655. prefix,
  1656. startsExpr
  1657. }),
  1658. modulo: createToken("%", {
  1659. binop: 10,
  1660. startsExpr
  1661. }),
  1662. star: createToken("*", {
  1663. binop: 10
  1664. }),
  1665. slash: createBinop("/", 10),
  1666. exponent: createToken("**", {
  1667. beforeExpr,
  1668. binop: 11,
  1669. rightAssociative: true
  1670. }),
  1671. _in: createKeyword("in", {
  1672. beforeExpr,
  1673. binop: 7
  1674. }),
  1675. _instanceof: createKeyword("instanceof", {
  1676. beforeExpr,
  1677. binop: 7
  1678. }),
  1679. _break: createKeyword("break"),
  1680. _case: createKeyword("case", {
  1681. beforeExpr
  1682. }),
  1683. _catch: createKeyword("catch"),
  1684. _continue: createKeyword("continue"),
  1685. _debugger: createKeyword("debugger"),
  1686. _default: createKeyword("default", {
  1687. beforeExpr
  1688. }),
  1689. _else: createKeyword("else", {
  1690. beforeExpr
  1691. }),
  1692. _finally: createKeyword("finally"),
  1693. _function: createKeyword("function", {
  1694. startsExpr
  1695. }),
  1696. _if: createKeyword("if"),
  1697. _return: createKeyword("return", {
  1698. beforeExpr
  1699. }),
  1700. _switch: createKeyword("switch"),
  1701. _throw: createKeyword("throw", {
  1702. beforeExpr,
  1703. prefix,
  1704. startsExpr
  1705. }),
  1706. _try: createKeyword("try"),
  1707. _var: createKeyword("var"),
  1708. _const: createKeyword("const"),
  1709. _with: createKeyword("with"),
  1710. _new: createKeyword("new", {
  1711. beforeExpr,
  1712. startsExpr
  1713. }),
  1714. _this: createKeyword("this", {
  1715. startsExpr
  1716. }),
  1717. _super: createKeyword("super", {
  1718. startsExpr
  1719. }),
  1720. _class: createKeyword("class", {
  1721. startsExpr
  1722. }),
  1723. _extends: createKeyword("extends", {
  1724. beforeExpr
  1725. }),
  1726. _export: createKeyword("export"),
  1727. _import: createKeyword("import", {
  1728. startsExpr
  1729. }),
  1730. _null: createKeyword("null", {
  1731. startsExpr
  1732. }),
  1733. _true: createKeyword("true", {
  1734. startsExpr
  1735. }),
  1736. _false: createKeyword("false", {
  1737. startsExpr
  1738. }),
  1739. _typeof: createKeyword("typeof", {
  1740. beforeExpr,
  1741. prefix,
  1742. startsExpr
  1743. }),
  1744. _void: createKeyword("void", {
  1745. beforeExpr,
  1746. prefix,
  1747. startsExpr
  1748. }),
  1749. _delete: createKeyword("delete", {
  1750. beforeExpr,
  1751. prefix,
  1752. startsExpr
  1753. }),
  1754. _do: createKeyword("do", {
  1755. isLoop,
  1756. beforeExpr
  1757. }),
  1758. _for: createKeyword("for", {
  1759. isLoop
  1760. }),
  1761. _while: createKeyword("while", {
  1762. isLoop
  1763. }),
  1764. _as: createKeywordLike("as", {
  1765. startsExpr
  1766. }),
  1767. _assert: createKeywordLike("assert", {
  1768. startsExpr
  1769. }),
  1770. _async: createKeywordLike("async", {
  1771. startsExpr
  1772. }),
  1773. _await: createKeywordLike("await", {
  1774. startsExpr
  1775. }),
  1776. _defer: createKeywordLike("defer", {
  1777. startsExpr
  1778. }),
  1779. _from: createKeywordLike("from", {
  1780. startsExpr
  1781. }),
  1782. _get: createKeywordLike("get", {
  1783. startsExpr
  1784. }),
  1785. _let: createKeywordLike("let", {
  1786. startsExpr
  1787. }),
  1788. _meta: createKeywordLike("meta", {
  1789. startsExpr
  1790. }),
  1791. _of: createKeywordLike("of", {
  1792. startsExpr
  1793. }),
  1794. _sent: createKeywordLike("sent", {
  1795. startsExpr
  1796. }),
  1797. _set: createKeywordLike("set", {
  1798. startsExpr
  1799. }),
  1800. _source: createKeywordLike("source", {
  1801. startsExpr
  1802. }),
  1803. _static: createKeywordLike("static", {
  1804. startsExpr
  1805. }),
  1806. _using: createKeywordLike("using", {
  1807. startsExpr
  1808. }),
  1809. _yield: createKeywordLike("yield", {
  1810. startsExpr
  1811. }),
  1812. _asserts: createKeywordLike("asserts", {
  1813. startsExpr
  1814. }),
  1815. _checks: createKeywordLike("checks", {
  1816. startsExpr
  1817. }),
  1818. _exports: createKeywordLike("exports", {
  1819. startsExpr
  1820. }),
  1821. _global: createKeywordLike("global", {
  1822. startsExpr
  1823. }),
  1824. _implements: createKeywordLike("implements", {
  1825. startsExpr
  1826. }),
  1827. _intrinsic: createKeywordLike("intrinsic", {
  1828. startsExpr
  1829. }),
  1830. _infer: createKeywordLike("infer", {
  1831. startsExpr
  1832. }),
  1833. _is: createKeywordLike("is", {
  1834. startsExpr
  1835. }),
  1836. _mixins: createKeywordLike("mixins", {
  1837. startsExpr
  1838. }),
  1839. _proto: createKeywordLike("proto", {
  1840. startsExpr
  1841. }),
  1842. _require: createKeywordLike("require", {
  1843. startsExpr
  1844. }),
  1845. _satisfies: createKeywordLike("satisfies", {
  1846. startsExpr
  1847. }),
  1848. _keyof: createKeywordLike("keyof", {
  1849. startsExpr
  1850. }),
  1851. _readonly: createKeywordLike("readonly", {
  1852. startsExpr
  1853. }),
  1854. _unique: createKeywordLike("unique", {
  1855. startsExpr
  1856. }),
  1857. _abstract: createKeywordLike("abstract", {
  1858. startsExpr
  1859. }),
  1860. _declare: createKeywordLike("declare", {
  1861. startsExpr
  1862. }),
  1863. _enum: createKeywordLike("enum", {
  1864. startsExpr
  1865. }),
  1866. _module: createKeywordLike("module", {
  1867. startsExpr
  1868. }),
  1869. _namespace: createKeywordLike("namespace", {
  1870. startsExpr
  1871. }),
  1872. _interface: createKeywordLike("interface", {
  1873. startsExpr
  1874. }),
  1875. _type: createKeywordLike("type", {
  1876. startsExpr
  1877. }),
  1878. _opaque: createKeywordLike("opaque", {
  1879. startsExpr
  1880. }),
  1881. name: createToken("name", {
  1882. startsExpr
  1883. }),
  1884. string: createToken("string", {
  1885. startsExpr
  1886. }),
  1887. num: createToken("num", {
  1888. startsExpr
  1889. }),
  1890. bigint: createToken("bigint", {
  1891. startsExpr
  1892. }),
  1893. decimal: createToken("decimal", {
  1894. startsExpr
  1895. }),
  1896. regexp: createToken("regexp", {
  1897. startsExpr
  1898. }),
  1899. privateName: createToken("#name", {
  1900. startsExpr
  1901. }),
  1902. eof: createToken("eof"),
  1903. jsxName: createToken("jsxName"),
  1904. jsxText: createToken("jsxText", {
  1905. beforeExpr: true
  1906. }),
  1907. jsxTagStart: createToken("jsxTagStart", {
  1908. startsExpr: true
  1909. }),
  1910. jsxTagEnd: createToken("jsxTagEnd"),
  1911. placeholder: createToken("%%", {
  1912. startsExpr: true
  1913. })
  1914. };
  1915. function tokenIsIdentifier(token) {
  1916. return token >= 93 && token <= 132;
  1917. }
  1918. function tokenKeywordOrIdentifierIsKeyword(token) {
  1919. return token <= 92;
  1920. }
  1921. function tokenIsKeywordOrIdentifier(token) {
  1922. return token >= 58 && token <= 132;
  1923. }
  1924. function tokenIsLiteralPropertyName(token) {
  1925. return token >= 58 && token <= 136;
  1926. }
  1927. function tokenComesBeforeExpression(token) {
  1928. return tokenBeforeExprs[token];
  1929. }
  1930. function tokenCanStartExpression(token) {
  1931. return tokenStartsExprs[token];
  1932. }
  1933. function tokenIsAssignment(token) {
  1934. return token >= 29 && token <= 33;
  1935. }
  1936. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1937. return token >= 129 && token <= 131;
  1938. }
  1939. function tokenIsLoop(token) {
  1940. return token >= 90 && token <= 92;
  1941. }
  1942. function tokenIsKeyword(token) {
  1943. return token >= 58 && token <= 92;
  1944. }
  1945. function tokenIsOperator(token) {
  1946. return token >= 39 && token <= 59;
  1947. }
  1948. function tokenIsPostfix(token) {
  1949. return token === 34;
  1950. }
  1951. function tokenIsPrefix(token) {
  1952. return tokenPrefixes[token];
  1953. }
  1954. function tokenIsTSTypeOperator(token) {
  1955. return token >= 121 && token <= 123;
  1956. }
  1957. function tokenIsTSDeclarationStart(token) {
  1958. return token >= 124 && token <= 130;
  1959. }
  1960. function tokenLabelName(token) {
  1961. return tokenLabels[token];
  1962. }
  1963. function tokenOperatorPrecedence(token) {
  1964. return tokenBinops[token];
  1965. }
  1966. function tokenIsRightAssociative(token) {
  1967. return token === 57;
  1968. }
  1969. function tokenIsTemplate(token) {
  1970. return token >= 24 && token <= 25;
  1971. }
  1972. function getExportedToken(token) {
  1973. return tokenTypes$1[token];
  1974. }
  1975. {
  1976. tokenTypes$1[8].updateContext = context => {
  1977. context.pop();
  1978. };
  1979. tokenTypes$1[5].updateContext = tokenTypes$1[7].updateContext = tokenTypes$1[23].updateContext = context => {
  1980. context.push(types$1.brace);
  1981. };
  1982. tokenTypes$1[22].updateContext = context => {
  1983. if (context[context.length - 1] === types$1.template) {
  1984. context.pop();
  1985. } else {
  1986. context.push(types$1.template);
  1987. }
  1988. };
  1989. tokenTypes$1[142].updateContext = context => {
  1990. context.push(types$1.j_expr, types$1.j_oTag);
  1991. };
  1992. }
  1993. 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-\u1c88\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-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\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";
  1994. let nonASCIIidentifierChars = "\u200c\u200d\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\u0898-\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";
  1995. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1996. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1997. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1998. 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, 68, 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, 349, 41, 7, 1, 79, 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, 159, 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, 264, 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, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 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, 757, 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];
  1999. 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, 370, 1, 81, 2, 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, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 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, 406, 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, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 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, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  2000. function isInAstralSet(code, set) {
  2001. let pos = 0x10000;
  2002. for (let i = 0, length = set.length; i < length; i += 2) {
  2003. pos += set[i];
  2004. if (pos > code) return false;
  2005. pos += set[i + 1];
  2006. if (pos >= code) return true;
  2007. }
  2008. return false;
  2009. }
  2010. function isIdentifierStart(code) {
  2011. if (code < 65) return code === 36;
  2012. if (code <= 90) return true;
  2013. if (code < 97) return code === 95;
  2014. if (code <= 122) return true;
  2015. if (code <= 0xffff) {
  2016. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  2017. }
  2018. return isInAstralSet(code, astralIdentifierStartCodes);
  2019. }
  2020. function isIdentifierChar(code) {
  2021. if (code < 48) return code === 36;
  2022. if (code < 58) return true;
  2023. if (code < 65) return false;
  2024. if (code <= 90) return true;
  2025. if (code < 97) return code === 95;
  2026. if (code <= 122) return true;
  2027. if (code <= 0xffff) {
  2028. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  2029. }
  2030. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  2031. }
  2032. const reservedWords = {
  2033. 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"],
  2034. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  2035. strictBind: ["eval", "arguments"]
  2036. };
  2037. const keywords = new Set(reservedWords.keyword);
  2038. const reservedWordsStrictSet = new Set(reservedWords.strict);
  2039. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  2040. function isReservedWord(word, inModule) {
  2041. return inModule && word === "await" || word === "enum";
  2042. }
  2043. function isStrictReservedWord(word, inModule) {
  2044. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  2045. }
  2046. function isStrictBindOnlyReservedWord(word) {
  2047. return reservedWordsStrictBindSet.has(word);
  2048. }
  2049. function isStrictBindReservedWord(word, inModule) {
  2050. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  2051. }
  2052. function isKeyword(word) {
  2053. return keywords.has(word);
  2054. }
  2055. function isIteratorStart(current, next, next2) {
  2056. return current === 64 && next === 64 && isIdentifierStart(next2);
  2057. }
  2058. 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"]);
  2059. function canBeReservedWord(word) {
  2060. return reservedWordLikeSet.has(word);
  2061. }
  2062. class Scope {
  2063. constructor(flags) {
  2064. this.var = new Set();
  2065. this.lexical = new Set();
  2066. this.functions = new Set();
  2067. this.flags = flags;
  2068. }
  2069. }
  2070. class ScopeHandler {
  2071. constructor(parser, inModule) {
  2072. this.parser = void 0;
  2073. this.scopeStack = [];
  2074. this.inModule = void 0;
  2075. this.undefinedExports = new Map();
  2076. this.parser = parser;
  2077. this.inModule = inModule;
  2078. }
  2079. get inTopLevel() {
  2080. return (this.currentScope().flags & 1) > 0;
  2081. }
  2082. get inFunction() {
  2083. return (this.currentVarScopeFlags() & 2) > 0;
  2084. }
  2085. get allowSuper() {
  2086. return (this.currentThisScopeFlags() & 16) > 0;
  2087. }
  2088. get allowDirectSuper() {
  2089. return (this.currentThisScopeFlags() & 32) > 0;
  2090. }
  2091. get inClass() {
  2092. return (this.currentThisScopeFlags() & 64) > 0;
  2093. }
  2094. get inClassAndNotInNonArrowFunction() {
  2095. const flags = this.currentThisScopeFlags();
  2096. return (flags & 64) > 0 && (flags & 2) === 0;
  2097. }
  2098. get inStaticBlock() {
  2099. for (let i = this.scopeStack.length - 1;; i--) {
  2100. const {
  2101. flags
  2102. } = this.scopeStack[i];
  2103. if (flags & 128) {
  2104. return true;
  2105. }
  2106. if (flags & (387 | 64)) {
  2107. return false;
  2108. }
  2109. }
  2110. }
  2111. get inNonArrowFunction() {
  2112. return (this.currentThisScopeFlags() & 2) > 0;
  2113. }
  2114. get treatFunctionsAsVar() {
  2115. return this.treatFunctionsAsVarInScope(this.currentScope());
  2116. }
  2117. createScope(flags) {
  2118. return new Scope(flags);
  2119. }
  2120. enter(flags) {
  2121. this.scopeStack.push(this.createScope(flags));
  2122. }
  2123. exit() {
  2124. const scope = this.scopeStack.pop();
  2125. return scope.flags;
  2126. }
  2127. treatFunctionsAsVarInScope(scope) {
  2128. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  2129. }
  2130. declareName(name, bindingType, loc) {
  2131. let scope = this.currentScope();
  2132. if (bindingType & 8 || bindingType & 16) {
  2133. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  2134. if (bindingType & 16) {
  2135. scope.functions.add(name);
  2136. } else {
  2137. scope.lexical.add(name);
  2138. }
  2139. if (bindingType & 8) {
  2140. this.maybeExportDefined(scope, name);
  2141. }
  2142. } else if (bindingType & 4) {
  2143. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  2144. scope = this.scopeStack[i];
  2145. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  2146. scope.var.add(name);
  2147. this.maybeExportDefined(scope, name);
  2148. if (scope.flags & 387) break;
  2149. }
  2150. }
  2151. if (this.parser.inModule && scope.flags & 1) {
  2152. this.undefinedExports.delete(name);
  2153. }
  2154. }
  2155. maybeExportDefined(scope, name) {
  2156. if (this.parser.inModule && scope.flags & 1) {
  2157. this.undefinedExports.delete(name);
  2158. }
  2159. }
  2160. checkRedeclarationInScope(scope, name, bindingType, loc) {
  2161. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  2162. this.parser.raise(Errors.VarRedeclaration, {
  2163. at: loc,
  2164. identifierName: name
  2165. });
  2166. }
  2167. }
  2168. isRedeclaredInScope(scope, name, bindingType) {
  2169. if (!(bindingType & 1)) return false;
  2170. if (bindingType & 8) {
  2171. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  2172. }
  2173. if (bindingType & 16) {
  2174. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  2175. }
  2176. return scope.lexical.has(name) && !(scope.flags & 8 && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  2177. }
  2178. checkLocalExport(id) {
  2179. const {
  2180. name
  2181. } = id;
  2182. const topLevelScope = this.scopeStack[0];
  2183. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  2184. this.undefinedExports.set(name, id.loc.start);
  2185. }
  2186. }
  2187. currentScope() {
  2188. return this.scopeStack[this.scopeStack.length - 1];
  2189. }
  2190. currentVarScopeFlags() {
  2191. for (let i = this.scopeStack.length - 1;; i--) {
  2192. const {
  2193. flags
  2194. } = this.scopeStack[i];
  2195. if (flags & 387) {
  2196. return flags;
  2197. }
  2198. }
  2199. }
  2200. currentThisScopeFlags() {
  2201. for (let i = this.scopeStack.length - 1;; i--) {
  2202. const {
  2203. flags
  2204. } = this.scopeStack[i];
  2205. if (flags & (387 | 64) && !(flags & 4)) {
  2206. return flags;
  2207. }
  2208. }
  2209. }
  2210. }
  2211. class FlowScope extends Scope {
  2212. constructor(...args) {
  2213. super(...args);
  2214. this.declareFunctions = new Set();
  2215. }
  2216. }
  2217. class FlowScopeHandler extends ScopeHandler {
  2218. createScope(flags) {
  2219. return new FlowScope(flags);
  2220. }
  2221. declareName(name, bindingType, loc) {
  2222. const scope = this.currentScope();
  2223. if (bindingType & 2048) {
  2224. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  2225. this.maybeExportDefined(scope, name);
  2226. scope.declareFunctions.add(name);
  2227. return;
  2228. }
  2229. super.declareName(name, bindingType, loc);
  2230. }
  2231. isRedeclaredInScope(scope, name, bindingType) {
  2232. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  2233. if (bindingType & 2048) {
  2234. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  2235. }
  2236. return false;
  2237. }
  2238. checkLocalExport(id) {
  2239. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  2240. super.checkLocalExport(id);
  2241. }
  2242. }
  2243. }
  2244. class BaseParser {
  2245. constructor() {
  2246. this.sawUnambiguousESM = false;
  2247. this.ambiguousScriptDifferentAst = false;
  2248. }
  2249. hasPlugin(pluginConfig) {
  2250. if (typeof pluginConfig === "string") {
  2251. return this.plugins.has(pluginConfig);
  2252. } else {
  2253. const [pluginName, pluginOptions] = pluginConfig;
  2254. if (!this.hasPlugin(pluginName)) {
  2255. return false;
  2256. }
  2257. const actualOptions = this.plugins.get(pluginName);
  2258. for (const key of Object.keys(pluginOptions)) {
  2259. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  2260. return false;
  2261. }
  2262. }
  2263. return true;
  2264. }
  2265. }
  2266. getPluginOption(plugin, name) {
  2267. var _this$plugins$get;
  2268. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  2269. }
  2270. }
  2271. function setTrailingComments(node, comments) {
  2272. if (node.trailingComments === undefined) {
  2273. node.trailingComments = comments;
  2274. } else {
  2275. node.trailingComments.unshift(...comments);
  2276. }
  2277. }
  2278. function setLeadingComments(node, comments) {
  2279. if (node.leadingComments === undefined) {
  2280. node.leadingComments = comments;
  2281. } else {
  2282. node.leadingComments.unshift(...comments);
  2283. }
  2284. }
  2285. function setInnerComments(node, comments) {
  2286. if (node.innerComments === undefined) {
  2287. node.innerComments = comments;
  2288. } else {
  2289. node.innerComments.unshift(...comments);
  2290. }
  2291. }
  2292. function adjustInnerComments(node, elements, commentWS) {
  2293. let lastElement = null;
  2294. let i = elements.length;
  2295. while (lastElement === null && i > 0) {
  2296. lastElement = elements[--i];
  2297. }
  2298. if (lastElement === null || lastElement.start > commentWS.start) {
  2299. setInnerComments(node, commentWS.comments);
  2300. } else {
  2301. setTrailingComments(lastElement, commentWS.comments);
  2302. }
  2303. }
  2304. class CommentsParser extends BaseParser {
  2305. addComment(comment) {
  2306. if (this.filename) comment.loc.filename = this.filename;
  2307. this.state.comments.push(comment);
  2308. }
  2309. processComment(node) {
  2310. const {
  2311. commentStack
  2312. } = this.state;
  2313. const commentStackLength = commentStack.length;
  2314. if (commentStackLength === 0) return;
  2315. let i = commentStackLength - 1;
  2316. const lastCommentWS = commentStack[i];
  2317. if (lastCommentWS.start === node.end) {
  2318. lastCommentWS.leadingNode = node;
  2319. i--;
  2320. }
  2321. const {
  2322. start: nodeStart
  2323. } = node;
  2324. for (; i >= 0; i--) {
  2325. const commentWS = commentStack[i];
  2326. const commentEnd = commentWS.end;
  2327. if (commentEnd > nodeStart) {
  2328. commentWS.containingNode = node;
  2329. this.finalizeComment(commentWS);
  2330. commentStack.splice(i, 1);
  2331. } else {
  2332. if (commentEnd === nodeStart) {
  2333. commentWS.trailingNode = node;
  2334. }
  2335. break;
  2336. }
  2337. }
  2338. }
  2339. finalizeComment(commentWS) {
  2340. const {
  2341. comments
  2342. } = commentWS;
  2343. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  2344. if (commentWS.leadingNode !== null) {
  2345. setTrailingComments(commentWS.leadingNode, comments);
  2346. }
  2347. if (commentWS.trailingNode !== null) {
  2348. setLeadingComments(commentWS.trailingNode, comments);
  2349. }
  2350. } else {
  2351. const {
  2352. containingNode: node,
  2353. start: commentStart
  2354. } = commentWS;
  2355. if (this.input.charCodeAt(commentStart - 1) === 44) {
  2356. switch (node.type) {
  2357. case "ObjectExpression":
  2358. case "ObjectPattern":
  2359. case "RecordExpression":
  2360. adjustInnerComments(node, node.properties, commentWS);
  2361. break;
  2362. case "CallExpression":
  2363. case "OptionalCallExpression":
  2364. adjustInnerComments(node, node.arguments, commentWS);
  2365. break;
  2366. case "FunctionDeclaration":
  2367. case "FunctionExpression":
  2368. case "ArrowFunctionExpression":
  2369. case "ObjectMethod":
  2370. case "ClassMethod":
  2371. case "ClassPrivateMethod":
  2372. adjustInnerComments(node, node.params, commentWS);
  2373. break;
  2374. case "ArrayExpression":
  2375. case "ArrayPattern":
  2376. case "TupleExpression":
  2377. adjustInnerComments(node, node.elements, commentWS);
  2378. break;
  2379. case "ExportNamedDeclaration":
  2380. case "ImportDeclaration":
  2381. adjustInnerComments(node, node.specifiers, commentWS);
  2382. break;
  2383. default:
  2384. {
  2385. setInnerComments(node, comments);
  2386. }
  2387. }
  2388. } else {
  2389. setInnerComments(node, comments);
  2390. }
  2391. }
  2392. }
  2393. finalizeRemainingComments() {
  2394. const {
  2395. commentStack
  2396. } = this.state;
  2397. for (let i = commentStack.length - 1; i >= 0; i--) {
  2398. this.finalizeComment(commentStack[i]);
  2399. }
  2400. this.state.commentStack = [];
  2401. }
  2402. resetPreviousNodeTrailingComments(node) {
  2403. const {
  2404. commentStack
  2405. } = this.state;
  2406. const {
  2407. length
  2408. } = commentStack;
  2409. if (length === 0) return;
  2410. const commentWS = commentStack[length - 1];
  2411. if (commentWS.leadingNode === node) {
  2412. commentWS.leadingNode = null;
  2413. }
  2414. }
  2415. resetPreviousIdentifierLeadingComments(node) {
  2416. const {
  2417. commentStack
  2418. } = this.state;
  2419. const {
  2420. length
  2421. } = commentStack;
  2422. if (length === 0) return;
  2423. if (commentStack[length - 1].trailingNode === node) {
  2424. commentStack[length - 1].trailingNode = null;
  2425. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  2426. commentStack[length - 2].trailingNode = null;
  2427. }
  2428. }
  2429. takeSurroundingComments(node, start, end) {
  2430. const {
  2431. commentStack
  2432. } = this.state;
  2433. const commentStackLength = commentStack.length;
  2434. if (commentStackLength === 0) return;
  2435. let i = commentStackLength - 1;
  2436. for (; i >= 0; i--) {
  2437. const commentWS = commentStack[i];
  2438. const commentEnd = commentWS.end;
  2439. const commentStart = commentWS.start;
  2440. if (commentStart === end) {
  2441. commentWS.leadingNode = node;
  2442. } else if (commentEnd === start) {
  2443. commentWS.trailingNode = node;
  2444. } else if (commentEnd < start) {
  2445. break;
  2446. }
  2447. }
  2448. }
  2449. }
  2450. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  2451. const lineBreakG = new RegExp(lineBreak.source, "g");
  2452. function isNewLine(code) {
  2453. switch (code) {
  2454. case 10:
  2455. case 13:
  2456. case 8232:
  2457. case 8233:
  2458. return true;
  2459. default:
  2460. return false;
  2461. }
  2462. }
  2463. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  2464. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  2465. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  2466. function isWhitespace(code) {
  2467. switch (code) {
  2468. case 0x0009:
  2469. case 0x000b:
  2470. case 0x000c:
  2471. case 32:
  2472. case 160:
  2473. case 5760:
  2474. case 0x2000:
  2475. case 0x2001:
  2476. case 0x2002:
  2477. case 0x2003:
  2478. case 0x2004:
  2479. case 0x2005:
  2480. case 0x2006:
  2481. case 0x2007:
  2482. case 0x2008:
  2483. case 0x2009:
  2484. case 0x200a:
  2485. case 0x202f:
  2486. case 0x205f:
  2487. case 0x3000:
  2488. case 0xfeff:
  2489. return true;
  2490. default:
  2491. return false;
  2492. }
  2493. }
  2494. class State {
  2495. constructor() {
  2496. this.strict = void 0;
  2497. this.curLine = void 0;
  2498. this.lineStart = void 0;
  2499. this.startLoc = void 0;
  2500. this.endLoc = void 0;
  2501. this.errors = [];
  2502. this.potentialArrowAt = -1;
  2503. this.noArrowAt = [];
  2504. this.noArrowParamsConversionAt = [];
  2505. this.maybeInArrowParameters = false;
  2506. this.inType = false;
  2507. this.noAnonFunctionType = false;
  2508. this.hasFlowComment = false;
  2509. this.isAmbientContext = false;
  2510. this.inAbstractClass = false;
  2511. this.inDisallowConditionalTypesContext = false;
  2512. this.topicContext = {
  2513. maxNumOfResolvableTopics: 0,
  2514. maxTopicIndex: null
  2515. };
  2516. this.soloAwait = false;
  2517. this.inFSharpPipelineDirectBody = false;
  2518. this.labels = [];
  2519. this.comments = [];
  2520. this.commentStack = [];
  2521. this.pos = 0;
  2522. this.type = 139;
  2523. this.value = null;
  2524. this.start = 0;
  2525. this.end = 0;
  2526. this.lastTokEndLoc = null;
  2527. this.lastTokStartLoc = null;
  2528. this.lastTokStart = 0;
  2529. this.context = [types$1.brace];
  2530. this.canStartJSXElement = true;
  2531. this.containsEsc = false;
  2532. this.firstInvalidTemplateEscapePos = null;
  2533. this.strictErrors = new Map();
  2534. this.tokensLength = 0;
  2535. }
  2536. init({
  2537. strictMode,
  2538. sourceType,
  2539. startLine,
  2540. startColumn
  2541. }) {
  2542. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  2543. this.curLine = startLine;
  2544. this.lineStart = -startColumn;
  2545. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  2546. }
  2547. curPosition() {
  2548. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  2549. }
  2550. clone(skipArrays) {
  2551. const state = new State();
  2552. const keys = Object.keys(this);
  2553. for (let i = 0, length = keys.length; i < length; i++) {
  2554. const key = keys[i];
  2555. let val = this[key];
  2556. if (!skipArrays && Array.isArray(val)) {
  2557. val = val.slice();
  2558. }
  2559. state[key] = val;
  2560. }
  2561. return state;
  2562. }
  2563. }
  2564. var _isDigit = function isDigit(code) {
  2565. return code >= 48 && code <= 57;
  2566. };
  2567. const forbiddenNumericSeparatorSiblings = {
  2568. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  2569. hex: new Set([46, 88, 95, 120])
  2570. };
  2571. const isAllowedNumericSeparatorSibling = {
  2572. bin: ch => ch === 48 || ch === 49,
  2573. oct: ch => ch >= 48 && ch <= 55,
  2574. dec: ch => ch >= 48 && ch <= 57,
  2575. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  2576. };
  2577. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  2578. const initialPos = pos;
  2579. const initialLineStart = lineStart;
  2580. const initialCurLine = curLine;
  2581. let out = "";
  2582. let firstInvalidLoc = null;
  2583. let chunkStart = pos;
  2584. const {
  2585. length
  2586. } = input;
  2587. for (;;) {
  2588. if (pos >= length) {
  2589. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2590. out += input.slice(chunkStart, pos);
  2591. break;
  2592. }
  2593. const ch = input.charCodeAt(pos);
  2594. if (isStringEnd(type, ch, input, pos)) {
  2595. out += input.slice(chunkStart, pos);
  2596. break;
  2597. }
  2598. if (ch === 92) {
  2599. out += input.slice(chunkStart, pos);
  2600. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  2601. if (res.ch === null && !firstInvalidLoc) {
  2602. firstInvalidLoc = {
  2603. pos,
  2604. lineStart,
  2605. curLine
  2606. };
  2607. } else {
  2608. out += res.ch;
  2609. }
  2610. ({
  2611. pos,
  2612. lineStart,
  2613. curLine
  2614. } = res);
  2615. chunkStart = pos;
  2616. } else if (ch === 8232 || ch === 8233) {
  2617. ++pos;
  2618. ++curLine;
  2619. lineStart = pos;
  2620. } else if (ch === 10 || ch === 13) {
  2621. if (type === "template") {
  2622. out += input.slice(chunkStart, pos) + "\n";
  2623. ++pos;
  2624. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2625. ++pos;
  2626. }
  2627. ++curLine;
  2628. chunkStart = lineStart = pos;
  2629. } else {
  2630. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2631. }
  2632. } else {
  2633. ++pos;
  2634. }
  2635. }
  2636. return {
  2637. pos,
  2638. str: out,
  2639. firstInvalidLoc,
  2640. lineStart,
  2641. curLine,
  2642. containsInvalid: !!firstInvalidLoc
  2643. };
  2644. }
  2645. function isStringEnd(type, ch, input, pos) {
  2646. if (type === "template") {
  2647. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2648. }
  2649. return ch === (type === "double" ? 34 : 39);
  2650. }
  2651. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2652. const throwOnInvalid = !inTemplate;
  2653. pos++;
  2654. const res = ch => ({
  2655. pos,
  2656. ch,
  2657. lineStart,
  2658. curLine
  2659. });
  2660. const ch = input.charCodeAt(pos++);
  2661. switch (ch) {
  2662. case 110:
  2663. return res("\n");
  2664. case 114:
  2665. return res("\r");
  2666. case 120:
  2667. {
  2668. let code;
  2669. ({
  2670. code,
  2671. pos
  2672. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2673. return res(code === null ? null : String.fromCharCode(code));
  2674. }
  2675. case 117:
  2676. {
  2677. let code;
  2678. ({
  2679. code,
  2680. pos
  2681. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2682. return res(code === null ? null : String.fromCodePoint(code));
  2683. }
  2684. case 116:
  2685. return res("\t");
  2686. case 98:
  2687. return res("\b");
  2688. case 118:
  2689. return res("\u000b");
  2690. case 102:
  2691. return res("\f");
  2692. case 13:
  2693. if (input.charCodeAt(pos) === 10) {
  2694. ++pos;
  2695. }
  2696. case 10:
  2697. lineStart = pos;
  2698. ++curLine;
  2699. case 8232:
  2700. case 8233:
  2701. return res("");
  2702. case 56:
  2703. case 57:
  2704. if (inTemplate) {
  2705. return res(null);
  2706. } else {
  2707. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2708. }
  2709. default:
  2710. if (ch >= 48 && ch <= 55) {
  2711. const startPos = pos - 1;
  2712. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2713. let octalStr = match[0];
  2714. let octal = parseInt(octalStr, 8);
  2715. if (octal > 255) {
  2716. octalStr = octalStr.slice(0, -1);
  2717. octal = parseInt(octalStr, 8);
  2718. }
  2719. pos += octalStr.length - 1;
  2720. const next = input.charCodeAt(pos);
  2721. if (octalStr !== "0" || next === 56 || next === 57) {
  2722. if (inTemplate) {
  2723. return res(null);
  2724. } else {
  2725. errors.strictNumericEscape(startPos, lineStart, curLine);
  2726. }
  2727. }
  2728. return res(String.fromCharCode(octal));
  2729. }
  2730. return res(String.fromCharCode(ch));
  2731. }
  2732. }
  2733. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2734. const initialPos = pos;
  2735. let n;
  2736. ({
  2737. n,
  2738. pos
  2739. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2740. if (n === null) {
  2741. if (throwOnInvalid) {
  2742. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2743. } else {
  2744. pos = initialPos - 1;
  2745. }
  2746. }
  2747. return {
  2748. code: n,
  2749. pos
  2750. };
  2751. }
  2752. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2753. const start = pos;
  2754. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2755. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2756. let invalid = false;
  2757. let total = 0;
  2758. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2759. const code = input.charCodeAt(pos);
  2760. let val;
  2761. if (code === 95 && allowNumSeparator !== "bail") {
  2762. const prev = input.charCodeAt(pos - 1);
  2763. const next = input.charCodeAt(pos + 1);
  2764. if (!allowNumSeparator) {
  2765. if (bailOnError) return {
  2766. n: null,
  2767. pos
  2768. };
  2769. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2770. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2771. if (bailOnError) return {
  2772. n: null,
  2773. pos
  2774. };
  2775. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2776. }
  2777. ++pos;
  2778. continue;
  2779. }
  2780. if (code >= 97) {
  2781. val = code - 97 + 10;
  2782. } else if (code >= 65) {
  2783. val = code - 65 + 10;
  2784. } else if (_isDigit(code)) {
  2785. val = code - 48;
  2786. } else {
  2787. val = Infinity;
  2788. }
  2789. if (val >= radix) {
  2790. if (val <= 9 && bailOnError) {
  2791. return {
  2792. n: null,
  2793. pos
  2794. };
  2795. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2796. val = 0;
  2797. } else if (forceLen) {
  2798. val = 0;
  2799. invalid = true;
  2800. } else {
  2801. break;
  2802. }
  2803. }
  2804. ++pos;
  2805. total = total * radix + val;
  2806. }
  2807. if (pos === start || len != null && pos - start !== len || invalid) {
  2808. return {
  2809. n: null,
  2810. pos
  2811. };
  2812. }
  2813. return {
  2814. n: total,
  2815. pos
  2816. };
  2817. }
  2818. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2819. const ch = input.charCodeAt(pos);
  2820. let code;
  2821. if (ch === 123) {
  2822. ++pos;
  2823. ({
  2824. code,
  2825. pos
  2826. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2827. ++pos;
  2828. if (code !== null && code > 0x10ffff) {
  2829. if (throwOnInvalid) {
  2830. errors.invalidCodePoint(pos, lineStart, curLine);
  2831. } else {
  2832. return {
  2833. code: null,
  2834. pos
  2835. };
  2836. }
  2837. }
  2838. } else {
  2839. ({
  2840. code,
  2841. pos
  2842. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2843. }
  2844. return {
  2845. code,
  2846. pos
  2847. };
  2848. }
  2849. const _excluded = ["at"],
  2850. _excluded2 = ["at"];
  2851. function buildPosition(pos, lineStart, curLine) {
  2852. return new Position(curLine, pos - lineStart, pos);
  2853. }
  2854. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2855. class Token {
  2856. constructor(state) {
  2857. this.type = state.type;
  2858. this.value = state.value;
  2859. this.start = state.start;
  2860. this.end = state.end;
  2861. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2862. }
  2863. }
  2864. class Tokenizer extends CommentsParser {
  2865. constructor(options, input) {
  2866. super();
  2867. this.isLookahead = void 0;
  2868. this.tokens = [];
  2869. this.errorHandlers_readInt = {
  2870. invalidDigit: (pos, lineStart, curLine, radix) => {
  2871. if (!this.options.errorRecovery) return false;
  2872. this.raise(Errors.InvalidDigit, {
  2873. at: buildPosition(pos, lineStart, curLine),
  2874. radix
  2875. });
  2876. return true;
  2877. },
  2878. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2879. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2880. };
  2881. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2882. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2883. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2884. });
  2885. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2886. strictNumericEscape: (pos, lineStart, curLine) => {
  2887. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2888. at: buildPosition(pos, lineStart, curLine)
  2889. });
  2890. },
  2891. unterminated: (pos, lineStart, curLine) => {
  2892. throw this.raise(Errors.UnterminatedString, {
  2893. at: buildPosition(pos - 1, lineStart, curLine)
  2894. });
  2895. }
  2896. });
  2897. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2898. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2899. unterminated: (pos, lineStart, curLine) => {
  2900. throw this.raise(Errors.UnterminatedTemplate, {
  2901. at: buildPosition(pos, lineStart, curLine)
  2902. });
  2903. }
  2904. });
  2905. this.state = new State();
  2906. this.state.init(options);
  2907. this.input = input;
  2908. this.length = input.length;
  2909. this.isLookahead = false;
  2910. }
  2911. pushToken(token) {
  2912. this.tokens.length = this.state.tokensLength;
  2913. this.tokens.push(token);
  2914. ++this.state.tokensLength;
  2915. }
  2916. next() {
  2917. this.checkKeywordEscapes();
  2918. if (this.options.tokens) {
  2919. this.pushToken(new Token(this.state));
  2920. }
  2921. this.state.lastTokStart = this.state.start;
  2922. this.state.lastTokEndLoc = this.state.endLoc;
  2923. this.state.lastTokStartLoc = this.state.startLoc;
  2924. this.nextToken();
  2925. }
  2926. eat(type) {
  2927. if (this.match(type)) {
  2928. this.next();
  2929. return true;
  2930. } else {
  2931. return false;
  2932. }
  2933. }
  2934. match(type) {
  2935. return this.state.type === type;
  2936. }
  2937. createLookaheadState(state) {
  2938. return {
  2939. pos: state.pos,
  2940. value: null,
  2941. type: state.type,
  2942. start: state.start,
  2943. end: state.end,
  2944. context: [this.curContext()],
  2945. inType: state.inType,
  2946. startLoc: state.startLoc,
  2947. lastTokEndLoc: state.lastTokEndLoc,
  2948. curLine: state.curLine,
  2949. lineStart: state.lineStart,
  2950. curPosition: state.curPosition
  2951. };
  2952. }
  2953. lookahead() {
  2954. const old = this.state;
  2955. this.state = this.createLookaheadState(old);
  2956. this.isLookahead = true;
  2957. this.nextToken();
  2958. this.isLookahead = false;
  2959. const curr = this.state;
  2960. this.state = old;
  2961. return curr;
  2962. }
  2963. nextTokenStart() {
  2964. return this.nextTokenStartSince(this.state.pos);
  2965. }
  2966. nextTokenStartSince(pos) {
  2967. skipWhiteSpace.lastIndex = pos;
  2968. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2969. }
  2970. lookaheadCharCode() {
  2971. return this.input.charCodeAt(this.nextTokenStart());
  2972. }
  2973. nextTokenInLineStart() {
  2974. return this.nextTokenInLineStartSince(this.state.pos);
  2975. }
  2976. nextTokenInLineStartSince(pos) {
  2977. skipWhiteSpaceInLine.lastIndex = pos;
  2978. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2979. }
  2980. lookaheadInLineCharCode() {
  2981. return this.input.charCodeAt(this.nextTokenInLineStart());
  2982. }
  2983. codePointAtPos(pos) {
  2984. let cp = this.input.charCodeAt(pos);
  2985. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2986. const trail = this.input.charCodeAt(pos);
  2987. if ((trail & 0xfc00) === 0xdc00) {
  2988. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2989. }
  2990. }
  2991. return cp;
  2992. }
  2993. setStrict(strict) {
  2994. this.state.strict = strict;
  2995. if (strict) {
  2996. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  2997. at
  2998. }));
  2999. this.state.strictErrors.clear();
  3000. }
  3001. }
  3002. curContext() {
  3003. return this.state.context[this.state.context.length - 1];
  3004. }
  3005. nextToken() {
  3006. this.skipSpace();
  3007. this.state.start = this.state.pos;
  3008. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  3009. if (this.state.pos >= this.length) {
  3010. this.finishToken(139);
  3011. return;
  3012. }
  3013. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  3014. }
  3015. skipBlockComment(commentEnd) {
  3016. let startLoc;
  3017. if (!this.isLookahead) startLoc = this.state.curPosition();
  3018. const start = this.state.pos;
  3019. const end = this.input.indexOf(commentEnd, start + 2);
  3020. if (end === -1) {
  3021. throw this.raise(Errors.UnterminatedComment, {
  3022. at: this.state.curPosition()
  3023. });
  3024. }
  3025. this.state.pos = end + commentEnd.length;
  3026. lineBreakG.lastIndex = start + 2;
  3027. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  3028. ++this.state.curLine;
  3029. this.state.lineStart = lineBreakG.lastIndex;
  3030. }
  3031. if (this.isLookahead) return;
  3032. const comment = {
  3033. type: "CommentBlock",
  3034. value: this.input.slice(start + 2, end),
  3035. start,
  3036. end: end + commentEnd.length,
  3037. loc: new SourceLocation(startLoc, this.state.curPosition())
  3038. };
  3039. if (this.options.tokens) this.pushToken(comment);
  3040. return comment;
  3041. }
  3042. skipLineComment(startSkip) {
  3043. const start = this.state.pos;
  3044. let startLoc;
  3045. if (!this.isLookahead) startLoc = this.state.curPosition();
  3046. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  3047. if (this.state.pos < this.length) {
  3048. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  3049. ch = this.input.charCodeAt(this.state.pos);
  3050. }
  3051. }
  3052. if (this.isLookahead) return;
  3053. const end = this.state.pos;
  3054. const value = this.input.slice(start + startSkip, end);
  3055. const comment = {
  3056. type: "CommentLine",
  3057. value,
  3058. start,
  3059. end,
  3060. loc: new SourceLocation(startLoc, this.state.curPosition())
  3061. };
  3062. if (this.options.tokens) this.pushToken(comment);
  3063. return comment;
  3064. }
  3065. skipSpace() {
  3066. const spaceStart = this.state.pos;
  3067. const comments = [];
  3068. loop: while (this.state.pos < this.length) {
  3069. const ch = this.input.charCodeAt(this.state.pos);
  3070. switch (ch) {
  3071. case 32:
  3072. case 160:
  3073. case 9:
  3074. ++this.state.pos;
  3075. break;
  3076. case 13:
  3077. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  3078. ++this.state.pos;
  3079. }
  3080. case 10:
  3081. case 8232:
  3082. case 8233:
  3083. ++this.state.pos;
  3084. ++this.state.curLine;
  3085. this.state.lineStart = this.state.pos;
  3086. break;
  3087. case 47:
  3088. switch (this.input.charCodeAt(this.state.pos + 1)) {
  3089. case 42:
  3090. {
  3091. const comment = this.skipBlockComment("*/");
  3092. if (comment !== undefined) {
  3093. this.addComment(comment);
  3094. if (this.options.attachComment) comments.push(comment);
  3095. }
  3096. break;
  3097. }
  3098. case 47:
  3099. {
  3100. const comment = this.skipLineComment(2);
  3101. if (comment !== undefined) {
  3102. this.addComment(comment);
  3103. if (this.options.attachComment) comments.push(comment);
  3104. }
  3105. break;
  3106. }
  3107. default:
  3108. break loop;
  3109. }
  3110. break;
  3111. default:
  3112. if (isWhitespace(ch)) {
  3113. ++this.state.pos;
  3114. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  3115. const pos = this.state.pos;
  3116. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  3117. const comment = this.skipLineComment(3);
  3118. if (comment !== undefined) {
  3119. this.addComment(comment);
  3120. if (this.options.attachComment) comments.push(comment);
  3121. }
  3122. } else {
  3123. break loop;
  3124. }
  3125. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  3126. const pos = this.state.pos;
  3127. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  3128. const comment = this.skipLineComment(4);
  3129. if (comment !== undefined) {
  3130. this.addComment(comment);
  3131. if (this.options.attachComment) comments.push(comment);
  3132. }
  3133. } else {
  3134. break loop;
  3135. }
  3136. } else {
  3137. break loop;
  3138. }
  3139. }
  3140. }
  3141. if (comments.length > 0) {
  3142. const end = this.state.pos;
  3143. const commentWhitespace = {
  3144. start: spaceStart,
  3145. end,
  3146. comments,
  3147. leadingNode: null,
  3148. trailingNode: null,
  3149. containingNode: null
  3150. };
  3151. this.state.commentStack.push(commentWhitespace);
  3152. }
  3153. }
  3154. finishToken(type, val) {
  3155. this.state.end = this.state.pos;
  3156. this.state.endLoc = this.state.curPosition();
  3157. const prevType = this.state.type;
  3158. this.state.type = type;
  3159. this.state.value = val;
  3160. if (!this.isLookahead) {
  3161. this.updateContext(prevType);
  3162. }
  3163. }
  3164. replaceToken(type) {
  3165. this.state.type = type;
  3166. this.updateContext();
  3167. }
  3168. readToken_numberSign() {
  3169. if (this.state.pos === 0 && this.readToken_interpreter()) {
  3170. return;
  3171. }
  3172. const nextPos = this.state.pos + 1;
  3173. const next = this.codePointAtPos(nextPos);
  3174. if (next >= 48 && next <= 57) {
  3175. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  3176. at: this.state.curPosition()
  3177. });
  3178. }
  3179. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  3180. this.expectPlugin("recordAndTuple");
  3181. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  3182. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  3183. at: this.state.curPosition()
  3184. });
  3185. }
  3186. this.state.pos += 2;
  3187. if (next === 123) {
  3188. this.finishToken(7);
  3189. } else {
  3190. this.finishToken(1);
  3191. }
  3192. } else if (isIdentifierStart(next)) {
  3193. ++this.state.pos;
  3194. this.finishToken(138, this.readWord1(next));
  3195. } else if (next === 92) {
  3196. ++this.state.pos;
  3197. this.finishToken(138, this.readWord1());
  3198. } else {
  3199. this.finishOp(27, 1);
  3200. }
  3201. }
  3202. readToken_dot() {
  3203. const next = this.input.charCodeAt(this.state.pos + 1);
  3204. if (next >= 48 && next <= 57) {
  3205. this.readNumber(true);
  3206. return;
  3207. }
  3208. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  3209. this.state.pos += 3;
  3210. this.finishToken(21);
  3211. } else {
  3212. ++this.state.pos;
  3213. this.finishToken(16);
  3214. }
  3215. }
  3216. readToken_slash() {
  3217. const next = this.input.charCodeAt(this.state.pos + 1);
  3218. if (next === 61) {
  3219. this.finishOp(31, 2);
  3220. } else {
  3221. this.finishOp(56, 1);
  3222. }
  3223. }
  3224. readToken_interpreter() {
  3225. if (this.state.pos !== 0 || this.length < 2) return false;
  3226. let ch = this.input.charCodeAt(this.state.pos + 1);
  3227. if (ch !== 33) return false;
  3228. const start = this.state.pos;
  3229. this.state.pos += 1;
  3230. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  3231. ch = this.input.charCodeAt(this.state.pos);
  3232. }
  3233. const value = this.input.slice(start + 2, this.state.pos);
  3234. this.finishToken(28, value);
  3235. return true;
  3236. }
  3237. readToken_mult_modulo(code) {
  3238. let type = code === 42 ? 55 : 54;
  3239. let width = 1;
  3240. let next = this.input.charCodeAt(this.state.pos + 1);
  3241. if (code === 42 && next === 42) {
  3242. width++;
  3243. next = this.input.charCodeAt(this.state.pos + 2);
  3244. type = 57;
  3245. }
  3246. if (next === 61 && !this.state.inType) {
  3247. width++;
  3248. type = code === 37 ? 33 : 30;
  3249. }
  3250. this.finishOp(type, width);
  3251. }
  3252. readToken_pipe_amp(code) {
  3253. const next = this.input.charCodeAt(this.state.pos + 1);
  3254. if (next === code) {
  3255. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  3256. this.finishOp(30, 3);
  3257. } else {
  3258. this.finishOp(code === 124 ? 41 : 42, 2);
  3259. }
  3260. return;
  3261. }
  3262. if (code === 124) {
  3263. if (next === 62) {
  3264. this.finishOp(39, 2);
  3265. return;
  3266. }
  3267. if (this.hasPlugin("recordAndTuple") && next === 125) {
  3268. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3269. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  3270. at: this.state.curPosition()
  3271. });
  3272. }
  3273. this.state.pos += 2;
  3274. this.finishToken(9);
  3275. return;
  3276. }
  3277. if (this.hasPlugin("recordAndTuple") && next === 93) {
  3278. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3279. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  3280. at: this.state.curPosition()
  3281. });
  3282. }
  3283. this.state.pos += 2;
  3284. this.finishToken(4);
  3285. return;
  3286. }
  3287. }
  3288. if (next === 61) {
  3289. this.finishOp(30, 2);
  3290. return;
  3291. }
  3292. this.finishOp(code === 124 ? 43 : 45, 1);
  3293. }
  3294. readToken_caret() {
  3295. const next = this.input.charCodeAt(this.state.pos + 1);
  3296. if (next === 61 && !this.state.inType) {
  3297. this.finishOp(32, 2);
  3298. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  3299. proposal: "hack",
  3300. topicToken: "^^"
  3301. }])) {
  3302. this.finishOp(37, 2);
  3303. const lookaheadCh = this.input.codePointAt(this.state.pos);
  3304. if (lookaheadCh === 94) {
  3305. this.unexpected();
  3306. }
  3307. } else {
  3308. this.finishOp(44, 1);
  3309. }
  3310. }
  3311. readToken_atSign() {
  3312. const next = this.input.charCodeAt(this.state.pos + 1);
  3313. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  3314. proposal: "hack",
  3315. topicToken: "@@"
  3316. }])) {
  3317. this.finishOp(38, 2);
  3318. } else {
  3319. this.finishOp(26, 1);
  3320. }
  3321. }
  3322. readToken_plus_min(code) {
  3323. const next = this.input.charCodeAt(this.state.pos + 1);
  3324. if (next === code) {
  3325. this.finishOp(34, 2);
  3326. return;
  3327. }
  3328. if (next === 61) {
  3329. this.finishOp(30, 2);
  3330. } else {
  3331. this.finishOp(53, 1);
  3332. }
  3333. }
  3334. readToken_lt() {
  3335. const {
  3336. pos
  3337. } = this.state;
  3338. const next = this.input.charCodeAt(pos + 1);
  3339. if (next === 60) {
  3340. if (this.input.charCodeAt(pos + 2) === 61) {
  3341. this.finishOp(30, 3);
  3342. return;
  3343. }
  3344. this.finishOp(51, 2);
  3345. return;
  3346. }
  3347. if (next === 61) {
  3348. this.finishOp(49, 2);
  3349. return;
  3350. }
  3351. this.finishOp(47, 1);
  3352. }
  3353. readToken_gt() {
  3354. const {
  3355. pos
  3356. } = this.state;
  3357. const next = this.input.charCodeAt(pos + 1);
  3358. if (next === 62) {
  3359. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  3360. if (this.input.charCodeAt(pos + size) === 61) {
  3361. this.finishOp(30, size + 1);
  3362. return;
  3363. }
  3364. this.finishOp(52, size);
  3365. return;
  3366. }
  3367. if (next === 61) {
  3368. this.finishOp(49, 2);
  3369. return;
  3370. }
  3371. this.finishOp(48, 1);
  3372. }
  3373. readToken_eq_excl(code) {
  3374. const next = this.input.charCodeAt(this.state.pos + 1);
  3375. if (next === 61) {
  3376. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  3377. return;
  3378. }
  3379. if (code === 61 && next === 62) {
  3380. this.state.pos += 2;
  3381. this.finishToken(19);
  3382. return;
  3383. }
  3384. this.finishOp(code === 61 ? 29 : 35, 1);
  3385. }
  3386. readToken_question() {
  3387. const next = this.input.charCodeAt(this.state.pos + 1);
  3388. const next2 = this.input.charCodeAt(this.state.pos + 2);
  3389. if (next === 63) {
  3390. if (next2 === 61) {
  3391. this.finishOp(30, 3);
  3392. } else {
  3393. this.finishOp(40, 2);
  3394. }
  3395. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  3396. this.state.pos += 2;
  3397. this.finishToken(18);
  3398. } else {
  3399. ++this.state.pos;
  3400. this.finishToken(17);
  3401. }
  3402. }
  3403. getTokenFromCode(code) {
  3404. switch (code) {
  3405. case 46:
  3406. this.readToken_dot();
  3407. return;
  3408. case 40:
  3409. ++this.state.pos;
  3410. this.finishToken(10);
  3411. return;
  3412. case 41:
  3413. ++this.state.pos;
  3414. this.finishToken(11);
  3415. return;
  3416. case 59:
  3417. ++this.state.pos;
  3418. this.finishToken(13);
  3419. return;
  3420. case 44:
  3421. ++this.state.pos;
  3422. this.finishToken(12);
  3423. return;
  3424. case 91:
  3425. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  3426. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3427. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  3428. at: this.state.curPosition()
  3429. });
  3430. }
  3431. this.state.pos += 2;
  3432. this.finishToken(2);
  3433. } else {
  3434. ++this.state.pos;
  3435. this.finishToken(0);
  3436. }
  3437. return;
  3438. case 93:
  3439. ++this.state.pos;
  3440. this.finishToken(3);
  3441. return;
  3442. case 123:
  3443. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  3444. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  3445. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  3446. at: this.state.curPosition()
  3447. });
  3448. }
  3449. this.state.pos += 2;
  3450. this.finishToken(6);
  3451. } else {
  3452. ++this.state.pos;
  3453. this.finishToken(5);
  3454. }
  3455. return;
  3456. case 125:
  3457. ++this.state.pos;
  3458. this.finishToken(8);
  3459. return;
  3460. case 58:
  3461. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  3462. this.finishOp(15, 2);
  3463. } else {
  3464. ++this.state.pos;
  3465. this.finishToken(14);
  3466. }
  3467. return;
  3468. case 63:
  3469. this.readToken_question();
  3470. return;
  3471. case 96:
  3472. this.readTemplateToken();
  3473. return;
  3474. case 48:
  3475. {
  3476. const next = this.input.charCodeAt(this.state.pos + 1);
  3477. if (next === 120 || next === 88) {
  3478. this.readRadixNumber(16);
  3479. return;
  3480. }
  3481. if (next === 111 || next === 79) {
  3482. this.readRadixNumber(8);
  3483. return;
  3484. }
  3485. if (next === 98 || next === 66) {
  3486. this.readRadixNumber(2);
  3487. return;
  3488. }
  3489. }
  3490. case 49:
  3491. case 50:
  3492. case 51:
  3493. case 52:
  3494. case 53:
  3495. case 54:
  3496. case 55:
  3497. case 56:
  3498. case 57:
  3499. this.readNumber(false);
  3500. return;
  3501. case 34:
  3502. case 39:
  3503. this.readString(code);
  3504. return;
  3505. case 47:
  3506. this.readToken_slash();
  3507. return;
  3508. case 37:
  3509. case 42:
  3510. this.readToken_mult_modulo(code);
  3511. return;
  3512. case 124:
  3513. case 38:
  3514. this.readToken_pipe_amp(code);
  3515. return;
  3516. case 94:
  3517. this.readToken_caret();
  3518. return;
  3519. case 43:
  3520. case 45:
  3521. this.readToken_plus_min(code);
  3522. return;
  3523. case 60:
  3524. this.readToken_lt();
  3525. return;
  3526. case 62:
  3527. this.readToken_gt();
  3528. return;
  3529. case 61:
  3530. case 33:
  3531. this.readToken_eq_excl(code);
  3532. return;
  3533. case 126:
  3534. this.finishOp(36, 1);
  3535. return;
  3536. case 64:
  3537. this.readToken_atSign();
  3538. return;
  3539. case 35:
  3540. this.readToken_numberSign();
  3541. return;
  3542. case 92:
  3543. this.readWord();
  3544. return;
  3545. default:
  3546. if (isIdentifierStart(code)) {
  3547. this.readWord(code);
  3548. return;
  3549. }
  3550. }
  3551. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  3552. at: this.state.curPosition(),
  3553. unexpected: String.fromCodePoint(code)
  3554. });
  3555. }
  3556. finishOp(type, size) {
  3557. const str = this.input.slice(this.state.pos, this.state.pos + size);
  3558. this.state.pos += size;
  3559. this.finishToken(type, str);
  3560. }
  3561. readRegexp() {
  3562. const startLoc = this.state.startLoc;
  3563. const start = this.state.start + 1;
  3564. let escaped, inClass;
  3565. let {
  3566. pos
  3567. } = this.state;
  3568. for (;; ++pos) {
  3569. if (pos >= this.length) {
  3570. throw this.raise(Errors.UnterminatedRegExp, {
  3571. at: createPositionWithColumnOffset(startLoc, 1)
  3572. });
  3573. }
  3574. const ch = this.input.charCodeAt(pos);
  3575. if (isNewLine(ch)) {
  3576. throw this.raise(Errors.UnterminatedRegExp, {
  3577. at: createPositionWithColumnOffset(startLoc, 1)
  3578. });
  3579. }
  3580. if (escaped) {
  3581. escaped = false;
  3582. } else {
  3583. if (ch === 91) {
  3584. inClass = true;
  3585. } else if (ch === 93 && inClass) {
  3586. inClass = false;
  3587. } else if (ch === 47 && !inClass) {
  3588. break;
  3589. }
  3590. escaped = ch === 92;
  3591. }
  3592. }
  3593. const content = this.input.slice(start, pos);
  3594. ++pos;
  3595. let mods = "";
  3596. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  3597. while (pos < this.length) {
  3598. const cp = this.codePointAtPos(pos);
  3599. const char = String.fromCharCode(cp);
  3600. if (VALID_REGEX_FLAGS.has(cp)) {
  3601. if (cp === 118) {
  3602. if (mods.includes("u")) {
  3603. this.raise(Errors.IncompatibleRegExpUVFlags, {
  3604. at: nextPos()
  3605. });
  3606. }
  3607. } else if (cp === 117) {
  3608. if (mods.includes("v")) {
  3609. this.raise(Errors.IncompatibleRegExpUVFlags, {
  3610. at: nextPos()
  3611. });
  3612. }
  3613. }
  3614. if (mods.includes(char)) {
  3615. this.raise(Errors.DuplicateRegExpFlags, {
  3616. at: nextPos()
  3617. });
  3618. }
  3619. } else if (isIdentifierChar(cp) || cp === 92) {
  3620. this.raise(Errors.MalformedRegExpFlags, {
  3621. at: nextPos()
  3622. });
  3623. } else {
  3624. break;
  3625. }
  3626. ++pos;
  3627. mods += char;
  3628. }
  3629. this.state.pos = pos;
  3630. this.finishToken(137, {
  3631. pattern: content,
  3632. flags: mods
  3633. });
  3634. }
  3635. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3636. const {
  3637. n,
  3638. pos
  3639. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3640. this.state.pos = pos;
  3641. return n;
  3642. }
  3643. readRadixNumber(radix) {
  3644. const startLoc = this.state.curPosition();
  3645. let isBigInt = false;
  3646. this.state.pos += 2;
  3647. const val = this.readInt(radix);
  3648. if (val == null) {
  3649. this.raise(Errors.InvalidDigit, {
  3650. at: createPositionWithColumnOffset(startLoc, 2),
  3651. radix
  3652. });
  3653. }
  3654. const next = this.input.charCodeAt(this.state.pos);
  3655. if (next === 110) {
  3656. ++this.state.pos;
  3657. isBigInt = true;
  3658. } else if (next === 109) {
  3659. throw this.raise(Errors.InvalidDecimal, {
  3660. at: startLoc
  3661. });
  3662. }
  3663. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3664. throw this.raise(Errors.NumberIdentifier, {
  3665. at: this.state.curPosition()
  3666. });
  3667. }
  3668. if (isBigInt) {
  3669. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3670. this.finishToken(135, str);
  3671. return;
  3672. }
  3673. this.finishToken(134, val);
  3674. }
  3675. readNumber(startsWithDot) {
  3676. const start = this.state.pos;
  3677. const startLoc = this.state.curPosition();
  3678. let isFloat = false;
  3679. let isBigInt = false;
  3680. let isDecimal = false;
  3681. let hasExponent = false;
  3682. let isOctal = false;
  3683. if (!startsWithDot && this.readInt(10) === null) {
  3684. this.raise(Errors.InvalidNumber, {
  3685. at: this.state.curPosition()
  3686. });
  3687. }
  3688. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3689. if (hasLeadingZero) {
  3690. const integer = this.input.slice(start, this.state.pos);
  3691. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3692. at: startLoc
  3693. });
  3694. if (!this.state.strict) {
  3695. const underscorePos = integer.indexOf("_");
  3696. if (underscorePos > 0) {
  3697. this.raise(Errors.ZeroDigitNumericSeparator, {
  3698. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3699. });
  3700. }
  3701. }
  3702. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3703. }
  3704. let next = this.input.charCodeAt(this.state.pos);
  3705. if (next === 46 && !isOctal) {
  3706. ++this.state.pos;
  3707. this.readInt(10);
  3708. isFloat = true;
  3709. next = this.input.charCodeAt(this.state.pos);
  3710. }
  3711. if ((next === 69 || next === 101) && !isOctal) {
  3712. next = this.input.charCodeAt(++this.state.pos);
  3713. if (next === 43 || next === 45) {
  3714. ++this.state.pos;
  3715. }
  3716. if (this.readInt(10) === null) {
  3717. this.raise(Errors.InvalidOrMissingExponent, {
  3718. at: startLoc
  3719. });
  3720. }
  3721. isFloat = true;
  3722. hasExponent = true;
  3723. next = this.input.charCodeAt(this.state.pos);
  3724. }
  3725. if (next === 110) {
  3726. if (isFloat || hasLeadingZero) {
  3727. this.raise(Errors.InvalidBigIntLiteral, {
  3728. at: startLoc
  3729. });
  3730. }
  3731. ++this.state.pos;
  3732. isBigInt = true;
  3733. }
  3734. if (next === 109) {
  3735. this.expectPlugin("decimal", this.state.curPosition());
  3736. if (hasExponent || hasLeadingZero) {
  3737. this.raise(Errors.InvalidDecimal, {
  3738. at: startLoc
  3739. });
  3740. }
  3741. ++this.state.pos;
  3742. isDecimal = true;
  3743. }
  3744. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3745. throw this.raise(Errors.NumberIdentifier, {
  3746. at: this.state.curPosition()
  3747. });
  3748. }
  3749. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3750. if (isBigInt) {
  3751. this.finishToken(135, str);
  3752. return;
  3753. }
  3754. if (isDecimal) {
  3755. this.finishToken(136, str);
  3756. return;
  3757. }
  3758. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3759. this.finishToken(134, val);
  3760. }
  3761. readCodePoint(throwOnInvalid) {
  3762. const {
  3763. code,
  3764. pos
  3765. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3766. this.state.pos = pos;
  3767. return code;
  3768. }
  3769. readString(quote) {
  3770. const {
  3771. str,
  3772. pos,
  3773. curLine,
  3774. lineStart
  3775. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3776. this.state.pos = pos + 1;
  3777. this.state.lineStart = lineStart;
  3778. this.state.curLine = curLine;
  3779. this.finishToken(133, str);
  3780. }
  3781. readTemplateContinuation() {
  3782. if (!this.match(8)) {
  3783. this.unexpected(null, 8);
  3784. }
  3785. this.state.pos--;
  3786. this.readTemplateToken();
  3787. }
  3788. readTemplateToken() {
  3789. const opening = this.input[this.state.pos];
  3790. const {
  3791. str,
  3792. firstInvalidLoc,
  3793. pos,
  3794. curLine,
  3795. lineStart
  3796. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3797. this.state.pos = pos + 1;
  3798. this.state.lineStart = lineStart;
  3799. this.state.curLine = curLine;
  3800. if (firstInvalidLoc) {
  3801. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3802. }
  3803. if (this.input.codePointAt(pos) === 96) {
  3804. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3805. } else {
  3806. this.state.pos++;
  3807. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3808. }
  3809. }
  3810. recordStrictModeErrors(toParseError, {
  3811. at
  3812. }) {
  3813. const index = at.index;
  3814. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3815. this.raise(toParseError, {
  3816. at
  3817. });
  3818. } else {
  3819. this.state.strictErrors.set(index, [toParseError, at]);
  3820. }
  3821. }
  3822. readWord1(firstCode) {
  3823. this.state.containsEsc = false;
  3824. let word = "";
  3825. const start = this.state.pos;
  3826. let chunkStart = this.state.pos;
  3827. if (firstCode !== undefined) {
  3828. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3829. }
  3830. while (this.state.pos < this.length) {
  3831. const ch = this.codePointAtPos(this.state.pos);
  3832. if (isIdentifierChar(ch)) {
  3833. this.state.pos += ch <= 0xffff ? 1 : 2;
  3834. } else if (ch === 92) {
  3835. this.state.containsEsc = true;
  3836. word += this.input.slice(chunkStart, this.state.pos);
  3837. const escStart = this.state.curPosition();
  3838. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3839. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3840. this.raise(Errors.MissingUnicodeEscape, {
  3841. at: this.state.curPosition()
  3842. });
  3843. chunkStart = this.state.pos - 1;
  3844. continue;
  3845. }
  3846. ++this.state.pos;
  3847. const esc = this.readCodePoint(true);
  3848. if (esc !== null) {
  3849. if (!identifierCheck(esc)) {
  3850. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3851. at: escStart
  3852. });
  3853. }
  3854. word += String.fromCodePoint(esc);
  3855. }
  3856. chunkStart = this.state.pos;
  3857. } else {
  3858. break;
  3859. }
  3860. }
  3861. return word + this.input.slice(chunkStart, this.state.pos);
  3862. }
  3863. readWord(firstCode) {
  3864. const word = this.readWord1(firstCode);
  3865. const type = keywords$1.get(word);
  3866. if (type !== undefined) {
  3867. this.finishToken(type, tokenLabelName(type));
  3868. } else {
  3869. this.finishToken(132, word);
  3870. }
  3871. }
  3872. checkKeywordEscapes() {
  3873. const {
  3874. type
  3875. } = this.state;
  3876. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3877. this.raise(Errors.InvalidEscapedReservedWord, {
  3878. at: this.state.startLoc,
  3879. reservedWord: tokenLabelName(type)
  3880. });
  3881. }
  3882. }
  3883. raise(toParseError, raiseProperties) {
  3884. const {
  3885. at
  3886. } = raiseProperties,
  3887. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3888. const loc = at instanceof Position ? at : at.loc.start;
  3889. const error = toParseError({
  3890. loc,
  3891. details
  3892. });
  3893. if (!this.options.errorRecovery) throw error;
  3894. if (!this.isLookahead) this.state.errors.push(error);
  3895. return error;
  3896. }
  3897. raiseOverwrite(toParseError, raiseProperties) {
  3898. const {
  3899. at
  3900. } = raiseProperties,
  3901. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3902. const loc = at instanceof Position ? at : at.loc.start;
  3903. const pos = loc.index;
  3904. const errors = this.state.errors;
  3905. for (let i = errors.length - 1; i >= 0; i--) {
  3906. const error = errors[i];
  3907. if (error.loc.index === pos) {
  3908. return errors[i] = toParseError({
  3909. loc,
  3910. details
  3911. });
  3912. }
  3913. if (error.loc.index < pos) break;
  3914. }
  3915. return this.raise(toParseError, raiseProperties);
  3916. }
  3917. updateContext(prevType) {}
  3918. unexpected(loc, type) {
  3919. throw this.raise(Errors.UnexpectedToken, {
  3920. expected: type ? tokenLabelName(type) : null,
  3921. at: loc != null ? loc : this.state.startLoc
  3922. });
  3923. }
  3924. expectPlugin(pluginName, loc) {
  3925. if (this.hasPlugin(pluginName)) {
  3926. return true;
  3927. }
  3928. throw this.raise(Errors.MissingPlugin, {
  3929. at: loc != null ? loc : this.state.startLoc,
  3930. missingPlugin: [pluginName]
  3931. });
  3932. }
  3933. expectOnePlugin(pluginNames) {
  3934. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3935. throw this.raise(Errors.MissingOneOfPlugins, {
  3936. at: this.state.startLoc,
  3937. missingPlugin: pluginNames
  3938. });
  3939. }
  3940. }
  3941. errorBuilder(error) {
  3942. return (pos, lineStart, curLine) => {
  3943. this.raise(error, {
  3944. at: buildPosition(pos, lineStart, curLine)
  3945. });
  3946. };
  3947. }
  3948. }
  3949. class ClassScope {
  3950. constructor() {
  3951. this.privateNames = new Set();
  3952. this.loneAccessors = new Map();
  3953. this.undefinedPrivateNames = new Map();
  3954. }
  3955. }
  3956. class ClassScopeHandler {
  3957. constructor(parser) {
  3958. this.parser = void 0;
  3959. this.stack = [];
  3960. this.undefinedPrivateNames = new Map();
  3961. this.parser = parser;
  3962. }
  3963. current() {
  3964. return this.stack[this.stack.length - 1];
  3965. }
  3966. enter() {
  3967. this.stack.push(new ClassScope());
  3968. }
  3969. exit() {
  3970. const oldClassScope = this.stack.pop();
  3971. const current = this.current();
  3972. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3973. if (current) {
  3974. if (!current.undefinedPrivateNames.has(name)) {
  3975. current.undefinedPrivateNames.set(name, loc);
  3976. }
  3977. } else {
  3978. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3979. at: loc,
  3980. identifierName: name
  3981. });
  3982. }
  3983. }
  3984. }
  3985. declarePrivateName(name, elementType, loc) {
  3986. const {
  3987. privateNames,
  3988. loneAccessors,
  3989. undefinedPrivateNames
  3990. } = this.current();
  3991. let redefined = privateNames.has(name);
  3992. if (elementType & 3) {
  3993. const accessor = redefined && loneAccessors.get(name);
  3994. if (accessor) {
  3995. const oldStatic = accessor & 4;
  3996. const newStatic = elementType & 4;
  3997. const oldKind = accessor & 3;
  3998. const newKind = elementType & 3;
  3999. redefined = oldKind === newKind || oldStatic !== newStatic;
  4000. if (!redefined) loneAccessors.delete(name);
  4001. } else if (!redefined) {
  4002. loneAccessors.set(name, elementType);
  4003. }
  4004. }
  4005. if (redefined) {
  4006. this.parser.raise(Errors.PrivateNameRedeclaration, {
  4007. at: loc,
  4008. identifierName: name
  4009. });
  4010. }
  4011. privateNames.add(name);
  4012. undefinedPrivateNames.delete(name);
  4013. }
  4014. usePrivateName(name, loc) {
  4015. let classScope;
  4016. for (classScope of this.stack) {
  4017. if (classScope.privateNames.has(name)) return;
  4018. }
  4019. if (classScope) {
  4020. classScope.undefinedPrivateNames.set(name, loc);
  4021. } else {
  4022. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  4023. at: loc,
  4024. identifierName: name
  4025. });
  4026. }
  4027. }
  4028. }
  4029. class ExpressionScope {
  4030. constructor(type = 0) {
  4031. this.type = type;
  4032. }
  4033. canBeArrowParameterDeclaration() {
  4034. return this.type === 2 || this.type === 1;
  4035. }
  4036. isCertainlyParameterDeclaration() {
  4037. return this.type === 3;
  4038. }
  4039. }
  4040. class ArrowHeadParsingScope extends ExpressionScope {
  4041. constructor(type) {
  4042. super(type);
  4043. this.declarationErrors = new Map();
  4044. }
  4045. recordDeclarationError(ParsingErrorClass, {
  4046. at
  4047. }) {
  4048. const index = at.index;
  4049. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  4050. }
  4051. clearDeclarationError(index) {
  4052. this.declarationErrors.delete(index);
  4053. }
  4054. iterateErrors(iterator) {
  4055. this.declarationErrors.forEach(iterator);
  4056. }
  4057. }
  4058. class ExpressionScopeHandler {
  4059. constructor(parser) {
  4060. this.parser = void 0;
  4061. this.stack = [new ExpressionScope()];
  4062. this.parser = parser;
  4063. }
  4064. enter(scope) {
  4065. this.stack.push(scope);
  4066. }
  4067. exit() {
  4068. this.stack.pop();
  4069. }
  4070. recordParameterInitializerError(toParseError, {
  4071. at: node
  4072. }) {
  4073. const origin = {
  4074. at: node.loc.start
  4075. };
  4076. const {
  4077. stack
  4078. } = this;
  4079. let i = stack.length - 1;
  4080. let scope = stack[i];
  4081. while (!scope.isCertainlyParameterDeclaration()) {
  4082. if (scope.canBeArrowParameterDeclaration()) {
  4083. scope.recordDeclarationError(toParseError, origin);
  4084. } else {
  4085. return;
  4086. }
  4087. scope = stack[--i];
  4088. }
  4089. this.parser.raise(toParseError, origin);
  4090. }
  4091. recordArrowParameterBindingError(error, {
  4092. at: node
  4093. }) {
  4094. const {
  4095. stack
  4096. } = this;
  4097. const scope = stack[stack.length - 1];
  4098. const origin = {
  4099. at: node.loc.start
  4100. };
  4101. if (scope.isCertainlyParameterDeclaration()) {
  4102. this.parser.raise(error, origin);
  4103. } else if (scope.canBeArrowParameterDeclaration()) {
  4104. scope.recordDeclarationError(error, origin);
  4105. } else {
  4106. return;
  4107. }
  4108. }
  4109. recordAsyncArrowParametersError({
  4110. at
  4111. }) {
  4112. const {
  4113. stack
  4114. } = this;
  4115. let i = stack.length - 1;
  4116. let scope = stack[i];
  4117. while (scope.canBeArrowParameterDeclaration()) {
  4118. if (scope.type === 2) {
  4119. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  4120. at
  4121. });
  4122. }
  4123. scope = stack[--i];
  4124. }
  4125. }
  4126. validateAsPattern() {
  4127. const {
  4128. stack
  4129. } = this;
  4130. const currentScope = stack[stack.length - 1];
  4131. if (!currentScope.canBeArrowParameterDeclaration()) return;
  4132. currentScope.iterateErrors(([toParseError, loc]) => {
  4133. this.parser.raise(toParseError, {
  4134. at: loc
  4135. });
  4136. let i = stack.length - 2;
  4137. let scope = stack[i];
  4138. while (scope.canBeArrowParameterDeclaration()) {
  4139. scope.clearDeclarationError(loc.index);
  4140. scope = stack[--i];
  4141. }
  4142. });
  4143. }
  4144. }
  4145. function newParameterDeclarationScope() {
  4146. return new ExpressionScope(3);
  4147. }
  4148. function newArrowHeadScope() {
  4149. return new ArrowHeadParsingScope(1);
  4150. }
  4151. function newAsyncArrowScope() {
  4152. return new ArrowHeadParsingScope(2);
  4153. }
  4154. function newExpressionScope() {
  4155. return new ExpressionScope();
  4156. }
  4157. class ProductionParameterHandler {
  4158. constructor() {
  4159. this.stacks = [];
  4160. }
  4161. enter(flags) {
  4162. this.stacks.push(flags);
  4163. }
  4164. exit() {
  4165. this.stacks.pop();
  4166. }
  4167. currentFlags() {
  4168. return this.stacks[this.stacks.length - 1];
  4169. }
  4170. get hasAwait() {
  4171. return (this.currentFlags() & 2) > 0;
  4172. }
  4173. get hasYield() {
  4174. return (this.currentFlags() & 1) > 0;
  4175. }
  4176. get hasReturn() {
  4177. return (this.currentFlags() & 4) > 0;
  4178. }
  4179. get hasIn() {
  4180. return (this.currentFlags() & 8) > 0;
  4181. }
  4182. }
  4183. function functionFlags(isAsync, isGenerator) {
  4184. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  4185. }
  4186. class UtilParser extends Tokenizer {
  4187. addExtra(node, key, value, enumerable = true) {
  4188. if (!node) return;
  4189. const extra = node.extra = node.extra || {};
  4190. if (enumerable) {
  4191. extra[key] = value;
  4192. } else {
  4193. Object.defineProperty(extra, key, {
  4194. enumerable,
  4195. value
  4196. });
  4197. }
  4198. }
  4199. isContextual(token) {
  4200. return this.state.type === token && !this.state.containsEsc;
  4201. }
  4202. isUnparsedContextual(nameStart, name) {
  4203. const nameEnd = nameStart + name.length;
  4204. if (this.input.slice(nameStart, nameEnd) === name) {
  4205. const nextCh = this.input.charCodeAt(nameEnd);
  4206. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  4207. }
  4208. return false;
  4209. }
  4210. isLookaheadContextual(name) {
  4211. const next = this.nextTokenStart();
  4212. return this.isUnparsedContextual(next, name);
  4213. }
  4214. eatContextual(token) {
  4215. if (this.isContextual(token)) {
  4216. this.next();
  4217. return true;
  4218. }
  4219. return false;
  4220. }
  4221. expectContextual(token, toParseError) {
  4222. if (!this.eatContextual(token)) {
  4223. if (toParseError != null) {
  4224. throw this.raise(toParseError, {
  4225. at: this.state.startLoc
  4226. });
  4227. }
  4228. this.unexpected(null, token);
  4229. }
  4230. }
  4231. canInsertSemicolon() {
  4232. return this.match(139) || this.match(8) || this.hasPrecedingLineBreak();
  4233. }
  4234. hasPrecedingLineBreak() {
  4235. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  4236. }
  4237. hasFollowingLineBreak() {
  4238. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  4239. return skipWhiteSpaceToLineBreak.test(this.input);
  4240. }
  4241. isLineTerminator() {
  4242. return this.eat(13) || this.canInsertSemicolon();
  4243. }
  4244. semicolon(allowAsi = true) {
  4245. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  4246. this.raise(Errors.MissingSemicolon, {
  4247. at: this.state.lastTokEndLoc
  4248. });
  4249. }
  4250. expect(type, loc) {
  4251. this.eat(type) || this.unexpected(loc, type);
  4252. }
  4253. tryParse(fn, oldState = this.state.clone()) {
  4254. const abortSignal = {
  4255. node: null
  4256. };
  4257. try {
  4258. const node = fn((node = null) => {
  4259. abortSignal.node = node;
  4260. throw abortSignal;
  4261. });
  4262. if (this.state.errors.length > oldState.errors.length) {
  4263. const failState = this.state;
  4264. this.state = oldState;
  4265. this.state.tokensLength = failState.tokensLength;
  4266. return {
  4267. node,
  4268. error: failState.errors[oldState.errors.length],
  4269. thrown: false,
  4270. aborted: false,
  4271. failState
  4272. };
  4273. }
  4274. return {
  4275. node,
  4276. error: null,
  4277. thrown: false,
  4278. aborted: false,
  4279. failState: null
  4280. };
  4281. } catch (error) {
  4282. const failState = this.state;
  4283. this.state = oldState;
  4284. if (error instanceof SyntaxError) {
  4285. return {
  4286. node: null,
  4287. error,
  4288. thrown: true,
  4289. aborted: false,
  4290. failState
  4291. };
  4292. }
  4293. if (error === abortSignal) {
  4294. return {
  4295. node: abortSignal.node,
  4296. error: null,
  4297. thrown: false,
  4298. aborted: true,
  4299. failState
  4300. };
  4301. }
  4302. throw error;
  4303. }
  4304. }
  4305. checkExpressionErrors(refExpressionErrors, andThrow) {
  4306. if (!refExpressionErrors) return false;
  4307. const {
  4308. shorthandAssignLoc,
  4309. doubleProtoLoc,
  4310. privateKeyLoc,
  4311. optionalParametersLoc
  4312. } = refExpressionErrors;
  4313. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  4314. if (!andThrow) {
  4315. return hasErrors;
  4316. }
  4317. if (shorthandAssignLoc != null) {
  4318. this.raise(Errors.InvalidCoverInitializedName, {
  4319. at: shorthandAssignLoc
  4320. });
  4321. }
  4322. if (doubleProtoLoc != null) {
  4323. this.raise(Errors.DuplicateProto, {
  4324. at: doubleProtoLoc
  4325. });
  4326. }
  4327. if (privateKeyLoc != null) {
  4328. this.raise(Errors.UnexpectedPrivateField, {
  4329. at: privateKeyLoc
  4330. });
  4331. }
  4332. if (optionalParametersLoc != null) {
  4333. this.unexpected(optionalParametersLoc);
  4334. }
  4335. }
  4336. isLiteralPropertyName() {
  4337. return tokenIsLiteralPropertyName(this.state.type);
  4338. }
  4339. isPrivateName(node) {
  4340. return node.type === "PrivateName";
  4341. }
  4342. getPrivateNameSV(node) {
  4343. return node.id.name;
  4344. }
  4345. hasPropertyAsPrivateName(node) {
  4346. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  4347. }
  4348. isObjectProperty(node) {
  4349. return node.type === "ObjectProperty";
  4350. }
  4351. isObjectMethod(node) {
  4352. return node.type === "ObjectMethod";
  4353. }
  4354. initializeScopes(inModule = this.options.sourceType === "module") {
  4355. const oldLabels = this.state.labels;
  4356. this.state.labels = [];
  4357. const oldExportedIdentifiers = this.exportedIdentifiers;
  4358. this.exportedIdentifiers = new Set();
  4359. const oldInModule = this.inModule;
  4360. this.inModule = inModule;
  4361. const oldScope = this.scope;
  4362. const ScopeHandler = this.getScopeHandler();
  4363. this.scope = new ScopeHandler(this, inModule);
  4364. const oldProdParam = this.prodParam;
  4365. this.prodParam = new ProductionParameterHandler();
  4366. const oldClassScope = this.classScope;
  4367. this.classScope = new ClassScopeHandler(this);
  4368. const oldExpressionScope = this.expressionScope;
  4369. this.expressionScope = new ExpressionScopeHandler(this);
  4370. return () => {
  4371. this.state.labels = oldLabels;
  4372. this.exportedIdentifiers = oldExportedIdentifiers;
  4373. this.inModule = oldInModule;
  4374. this.scope = oldScope;
  4375. this.prodParam = oldProdParam;
  4376. this.classScope = oldClassScope;
  4377. this.expressionScope = oldExpressionScope;
  4378. };
  4379. }
  4380. enterInitialScopes() {
  4381. let paramFlags = 0;
  4382. if (this.inModule) {
  4383. paramFlags |= 2;
  4384. }
  4385. this.scope.enter(1);
  4386. this.prodParam.enter(paramFlags);
  4387. }
  4388. checkDestructuringPrivate(refExpressionErrors) {
  4389. const {
  4390. privateKeyLoc
  4391. } = refExpressionErrors;
  4392. if (privateKeyLoc !== null) {
  4393. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  4394. }
  4395. }
  4396. }
  4397. class ExpressionErrors {
  4398. constructor() {
  4399. this.shorthandAssignLoc = null;
  4400. this.doubleProtoLoc = null;
  4401. this.privateKeyLoc = null;
  4402. this.optionalParametersLoc = null;
  4403. }
  4404. }
  4405. let Node$5 = class Node {
  4406. constructor(parser, pos, loc) {
  4407. this.type = "";
  4408. this.start = pos;
  4409. this.end = 0;
  4410. this.loc = new SourceLocation(loc);
  4411. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  4412. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  4413. }
  4414. };
  4415. const NodePrototype = Node$5.prototype;
  4416. {
  4417. NodePrototype.__clone = function () {
  4418. const newNode = new Node$5(undefined, this.start, this.loc.start);
  4419. const keys = Object.keys(this);
  4420. for (let i = 0, length = keys.length; i < length; i++) {
  4421. const key = keys[i];
  4422. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  4423. newNode[key] = this[key];
  4424. }
  4425. }
  4426. return newNode;
  4427. };
  4428. }
  4429. function clonePlaceholder(node) {
  4430. return cloneIdentifier(node);
  4431. }
  4432. function cloneIdentifier(node) {
  4433. const {
  4434. type,
  4435. start,
  4436. end,
  4437. loc,
  4438. range,
  4439. extra,
  4440. name
  4441. } = node;
  4442. const cloned = Object.create(NodePrototype);
  4443. cloned.type = type;
  4444. cloned.start = start;
  4445. cloned.end = end;
  4446. cloned.loc = loc;
  4447. cloned.range = range;
  4448. cloned.extra = extra;
  4449. cloned.name = name;
  4450. if (type === "Placeholder") {
  4451. cloned.expectedNode = node.expectedNode;
  4452. }
  4453. return cloned;
  4454. }
  4455. function cloneStringLiteral(node) {
  4456. const {
  4457. type,
  4458. start,
  4459. end,
  4460. loc,
  4461. range,
  4462. extra
  4463. } = node;
  4464. if (type === "Placeholder") {
  4465. return clonePlaceholder(node);
  4466. }
  4467. const cloned = Object.create(NodePrototype);
  4468. cloned.type = type;
  4469. cloned.start = start;
  4470. cloned.end = end;
  4471. cloned.loc = loc;
  4472. cloned.range = range;
  4473. if (node.raw !== undefined) {
  4474. cloned.raw = node.raw;
  4475. } else {
  4476. cloned.extra = extra;
  4477. }
  4478. cloned.value = node.value;
  4479. return cloned;
  4480. }
  4481. class NodeUtils extends UtilParser {
  4482. startNode() {
  4483. return new Node$5(this, this.state.start, this.state.startLoc);
  4484. }
  4485. startNodeAt(loc) {
  4486. return new Node$5(this, loc.index, loc);
  4487. }
  4488. startNodeAtNode(type) {
  4489. return this.startNodeAt(type.loc.start);
  4490. }
  4491. finishNode(node, type) {
  4492. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  4493. }
  4494. finishNodeAt(node, type, endLoc) {
  4495. node.type = type;
  4496. node.end = endLoc.index;
  4497. node.loc.end = endLoc;
  4498. if (this.options.ranges) node.range[1] = endLoc.index;
  4499. if (this.options.attachComment) this.processComment(node);
  4500. return node;
  4501. }
  4502. resetStartLocation(node, startLoc) {
  4503. node.start = startLoc.index;
  4504. node.loc.start = startLoc;
  4505. if (this.options.ranges) node.range[0] = startLoc.index;
  4506. }
  4507. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  4508. node.end = endLoc.index;
  4509. node.loc.end = endLoc;
  4510. if (this.options.ranges) node.range[1] = endLoc.index;
  4511. }
  4512. resetStartLocationFromNode(node, locationNode) {
  4513. this.resetStartLocation(node, locationNode.loc.start);
  4514. }
  4515. }
  4516. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  4517. const FlowErrors = ParseErrorEnum`flow`({
  4518. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  4519. 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.",
  4520. AssignReservedType: ({
  4521. reservedType
  4522. }) => `Cannot overwrite reserved type ${reservedType}.`,
  4523. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  4524. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  4525. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  4526. EnumBooleanMemberNotInitialized: ({
  4527. memberName,
  4528. enumName
  4529. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  4530. EnumDuplicateMemberName: ({
  4531. memberName,
  4532. enumName
  4533. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  4534. EnumInconsistentMemberValues: ({
  4535. enumName
  4536. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  4537. EnumInvalidExplicitType: ({
  4538. invalidEnumType,
  4539. enumName
  4540. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4541. EnumInvalidExplicitTypeUnknownSupplied: ({
  4542. enumName
  4543. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4544. EnumInvalidMemberInitializerPrimaryType: ({
  4545. enumName,
  4546. memberName,
  4547. explicitType
  4548. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  4549. EnumInvalidMemberInitializerSymbolType: ({
  4550. enumName,
  4551. memberName
  4552. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  4553. EnumInvalidMemberInitializerUnknownType: ({
  4554. enumName,
  4555. memberName
  4556. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  4557. EnumInvalidMemberName: ({
  4558. enumName,
  4559. memberName,
  4560. suggestion
  4561. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  4562. EnumNumberMemberNotInitialized: ({
  4563. enumName,
  4564. memberName
  4565. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  4566. EnumStringMemberInconsistentlyInitialized: ({
  4567. enumName
  4568. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  4569. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  4570. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  4571. 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.",
  4572. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  4573. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  4574. InexactVariance: "Explicit inexact syntax cannot have variance.",
  4575. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  4576. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  4577. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  4578. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  4579. PatternIsOptional: Object.assign({
  4580. message: "A binding pattern parameter cannot be optional in an implementation signature."
  4581. }, {
  4582. reasonCode: "OptionalBindingPattern"
  4583. }),
  4584. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  4585. SpreadVariance: "Spread properties cannot have variance.",
  4586. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  4587. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  4588. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  4589. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  4590. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  4591. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  4592. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  4593. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  4594. UnexpectedReservedType: ({
  4595. reservedType
  4596. }) => `Unexpected reserved type ${reservedType}.`,
  4597. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  4598. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  4599. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  4600. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  4601. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  4602. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  4603. UnsupportedDeclareExportKind: ({
  4604. unsupportedExportKind,
  4605. suggestion
  4606. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  4607. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  4608. UnterminatedFlowComment: "Unterminated flow-comment."
  4609. });
  4610. function isEsModuleType(bodyElement) {
  4611. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  4612. }
  4613. function hasTypeImportKind(node) {
  4614. return node.importKind === "type" || node.importKind === "typeof";
  4615. }
  4616. const exportSuggestions = {
  4617. const: "declare export var",
  4618. let: "declare export var",
  4619. type: "export type",
  4620. interface: "export interface"
  4621. };
  4622. function partition(list, test) {
  4623. const list1 = [];
  4624. const list2 = [];
  4625. for (let i = 0; i < list.length; i++) {
  4626. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4627. }
  4628. return [list1, list2];
  4629. }
  4630. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4631. var flow = superClass => class FlowParserMixin extends superClass {
  4632. constructor(...args) {
  4633. super(...args);
  4634. this.flowPragma = undefined;
  4635. }
  4636. getScopeHandler() {
  4637. return FlowScopeHandler;
  4638. }
  4639. shouldParseTypes() {
  4640. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4641. }
  4642. shouldParseEnums() {
  4643. return !!this.getPluginOption("flow", "enums");
  4644. }
  4645. finishToken(type, val) {
  4646. if (type !== 133 && type !== 13 && type !== 28) {
  4647. if (this.flowPragma === undefined) {
  4648. this.flowPragma = null;
  4649. }
  4650. }
  4651. super.finishToken(type, val);
  4652. }
  4653. addComment(comment) {
  4654. if (this.flowPragma === undefined) {
  4655. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4656. if (!matches) ;else if (matches[1] === "flow") {
  4657. this.flowPragma = "flow";
  4658. } else if (matches[1] === "noflow") {
  4659. this.flowPragma = "noflow";
  4660. } else {
  4661. throw new Error("Unexpected flow pragma");
  4662. }
  4663. }
  4664. super.addComment(comment);
  4665. }
  4666. flowParseTypeInitialiser(tok) {
  4667. const oldInType = this.state.inType;
  4668. this.state.inType = true;
  4669. this.expect(tok || 14);
  4670. const type = this.flowParseType();
  4671. this.state.inType = oldInType;
  4672. return type;
  4673. }
  4674. flowParsePredicate() {
  4675. const node = this.startNode();
  4676. const moduloLoc = this.state.startLoc;
  4677. this.next();
  4678. this.expectContextual(110);
  4679. if (this.state.lastTokStart > moduloLoc.index + 1) {
  4680. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4681. at: moduloLoc
  4682. });
  4683. }
  4684. if (this.eat(10)) {
  4685. node.value = super.parseExpression();
  4686. this.expect(11);
  4687. return this.finishNode(node, "DeclaredPredicate");
  4688. } else {
  4689. return this.finishNode(node, "InferredPredicate");
  4690. }
  4691. }
  4692. flowParseTypeAndPredicateInitialiser() {
  4693. const oldInType = this.state.inType;
  4694. this.state.inType = true;
  4695. this.expect(14);
  4696. let type = null;
  4697. let predicate = null;
  4698. if (this.match(54)) {
  4699. this.state.inType = oldInType;
  4700. predicate = this.flowParsePredicate();
  4701. } else {
  4702. type = this.flowParseType();
  4703. this.state.inType = oldInType;
  4704. if (this.match(54)) {
  4705. predicate = this.flowParsePredicate();
  4706. }
  4707. }
  4708. return [type, predicate];
  4709. }
  4710. flowParseDeclareClass(node) {
  4711. this.next();
  4712. this.flowParseInterfaceish(node, true);
  4713. return this.finishNode(node, "DeclareClass");
  4714. }
  4715. flowParseDeclareFunction(node) {
  4716. this.next();
  4717. const id = node.id = this.parseIdentifier();
  4718. const typeNode = this.startNode();
  4719. const typeContainer = this.startNode();
  4720. if (this.match(47)) {
  4721. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4722. } else {
  4723. typeNode.typeParameters = null;
  4724. }
  4725. this.expect(10);
  4726. const tmp = this.flowParseFunctionTypeParams();
  4727. typeNode.params = tmp.params;
  4728. typeNode.rest = tmp.rest;
  4729. typeNode.this = tmp._this;
  4730. this.expect(11);
  4731. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4732. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4733. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4734. this.resetEndLocation(id);
  4735. this.semicolon();
  4736. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4737. return this.finishNode(node, "DeclareFunction");
  4738. }
  4739. flowParseDeclare(node, insideModule) {
  4740. if (this.match(80)) {
  4741. return this.flowParseDeclareClass(node);
  4742. } else if (this.match(68)) {
  4743. return this.flowParseDeclareFunction(node);
  4744. } else if (this.match(74)) {
  4745. return this.flowParseDeclareVariable(node);
  4746. } else if (this.eatContextual(127)) {
  4747. if (this.match(16)) {
  4748. return this.flowParseDeclareModuleExports(node);
  4749. } else {
  4750. if (insideModule) {
  4751. this.raise(FlowErrors.NestedDeclareModule, {
  4752. at: this.state.lastTokStartLoc
  4753. });
  4754. }
  4755. return this.flowParseDeclareModule(node);
  4756. }
  4757. } else if (this.isContextual(130)) {
  4758. return this.flowParseDeclareTypeAlias(node);
  4759. } else if (this.isContextual(131)) {
  4760. return this.flowParseDeclareOpaqueType(node);
  4761. } else if (this.isContextual(129)) {
  4762. return this.flowParseDeclareInterface(node);
  4763. } else if (this.match(82)) {
  4764. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4765. } else {
  4766. this.unexpected();
  4767. }
  4768. }
  4769. flowParseDeclareVariable(node) {
  4770. this.next();
  4771. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4772. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4773. this.semicolon();
  4774. return this.finishNode(node, "DeclareVariable");
  4775. }
  4776. flowParseDeclareModule(node) {
  4777. this.scope.enter(0);
  4778. if (this.match(133)) {
  4779. node.id = super.parseExprAtom();
  4780. } else {
  4781. node.id = this.parseIdentifier();
  4782. }
  4783. const bodyNode = node.body = this.startNode();
  4784. const body = bodyNode.body = [];
  4785. this.expect(5);
  4786. while (!this.match(8)) {
  4787. let bodyNode = this.startNode();
  4788. if (this.match(83)) {
  4789. this.next();
  4790. if (!this.isContextual(130) && !this.match(87)) {
  4791. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4792. at: this.state.lastTokStartLoc
  4793. });
  4794. }
  4795. super.parseImport(bodyNode);
  4796. } else {
  4797. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4798. bodyNode = this.flowParseDeclare(bodyNode, true);
  4799. }
  4800. body.push(bodyNode);
  4801. }
  4802. this.scope.exit();
  4803. this.expect(8);
  4804. this.finishNode(bodyNode, "BlockStatement");
  4805. let kind = null;
  4806. let hasModuleExport = false;
  4807. body.forEach(bodyElement => {
  4808. if (isEsModuleType(bodyElement)) {
  4809. if (kind === "CommonJS") {
  4810. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4811. at: bodyElement
  4812. });
  4813. }
  4814. kind = "ES";
  4815. } else if (bodyElement.type === "DeclareModuleExports") {
  4816. if (hasModuleExport) {
  4817. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4818. at: bodyElement
  4819. });
  4820. }
  4821. if (kind === "ES") {
  4822. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4823. at: bodyElement
  4824. });
  4825. }
  4826. kind = "CommonJS";
  4827. hasModuleExport = true;
  4828. }
  4829. });
  4830. node.kind = kind || "CommonJS";
  4831. return this.finishNode(node, "DeclareModule");
  4832. }
  4833. flowParseDeclareExportDeclaration(node, insideModule) {
  4834. this.expect(82);
  4835. if (this.eat(65)) {
  4836. if (this.match(68) || this.match(80)) {
  4837. node.declaration = this.flowParseDeclare(this.startNode());
  4838. } else {
  4839. node.declaration = this.flowParseType();
  4840. this.semicolon();
  4841. }
  4842. node.default = true;
  4843. return this.finishNode(node, "DeclareExportDeclaration");
  4844. } else {
  4845. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4846. const label = this.state.value;
  4847. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4848. at: this.state.startLoc,
  4849. unsupportedExportKind: label,
  4850. suggestion: exportSuggestions[label]
  4851. });
  4852. }
  4853. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4854. node.declaration = this.flowParseDeclare(this.startNode());
  4855. node.default = false;
  4856. return this.finishNode(node, "DeclareExportDeclaration");
  4857. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4858. node = this.parseExport(node, null);
  4859. if (node.type === "ExportNamedDeclaration") {
  4860. node.type = "ExportDeclaration";
  4861. node.default = false;
  4862. delete node.exportKind;
  4863. }
  4864. node.type = "Declare" + node.type;
  4865. return node;
  4866. }
  4867. }
  4868. this.unexpected();
  4869. }
  4870. flowParseDeclareModuleExports(node) {
  4871. this.next();
  4872. this.expectContextual(111);
  4873. node.typeAnnotation = this.flowParseTypeAnnotation();
  4874. this.semicolon();
  4875. return this.finishNode(node, "DeclareModuleExports");
  4876. }
  4877. flowParseDeclareTypeAlias(node) {
  4878. this.next();
  4879. const finished = this.flowParseTypeAlias(node);
  4880. finished.type = "DeclareTypeAlias";
  4881. return finished;
  4882. }
  4883. flowParseDeclareOpaqueType(node) {
  4884. this.next();
  4885. const finished = this.flowParseOpaqueType(node, true);
  4886. finished.type = "DeclareOpaqueType";
  4887. return finished;
  4888. }
  4889. flowParseDeclareInterface(node) {
  4890. this.next();
  4891. this.flowParseInterfaceish(node, false);
  4892. return this.finishNode(node, "DeclareInterface");
  4893. }
  4894. flowParseInterfaceish(node, isClass) {
  4895. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4896. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4897. if (this.match(47)) {
  4898. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4899. } else {
  4900. node.typeParameters = null;
  4901. }
  4902. node.extends = [];
  4903. if (this.eat(81)) {
  4904. do {
  4905. node.extends.push(this.flowParseInterfaceExtends());
  4906. } while (!isClass && this.eat(12));
  4907. }
  4908. if (isClass) {
  4909. node.implements = [];
  4910. node.mixins = [];
  4911. if (this.eatContextual(117)) {
  4912. do {
  4913. node.mixins.push(this.flowParseInterfaceExtends());
  4914. } while (this.eat(12));
  4915. }
  4916. if (this.eatContextual(113)) {
  4917. do {
  4918. node.implements.push(this.flowParseInterfaceExtends());
  4919. } while (this.eat(12));
  4920. }
  4921. }
  4922. node.body = this.flowParseObjectType({
  4923. allowStatic: isClass,
  4924. allowExact: false,
  4925. allowSpread: false,
  4926. allowProto: isClass,
  4927. allowInexact: false
  4928. });
  4929. }
  4930. flowParseInterfaceExtends() {
  4931. const node = this.startNode();
  4932. node.id = this.flowParseQualifiedTypeIdentifier();
  4933. if (this.match(47)) {
  4934. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4935. } else {
  4936. node.typeParameters = null;
  4937. }
  4938. return this.finishNode(node, "InterfaceExtends");
  4939. }
  4940. flowParseInterface(node) {
  4941. this.flowParseInterfaceish(node, false);
  4942. return this.finishNode(node, "InterfaceDeclaration");
  4943. }
  4944. checkNotUnderscore(word) {
  4945. if (word === "_") {
  4946. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4947. at: this.state.startLoc
  4948. });
  4949. }
  4950. }
  4951. checkReservedType(word, startLoc, declaration) {
  4952. if (!reservedTypes.has(word)) return;
  4953. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4954. at: startLoc,
  4955. reservedType: word
  4956. });
  4957. }
  4958. flowParseRestrictedIdentifier(liberal, declaration) {
  4959. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4960. return this.parseIdentifier(liberal);
  4961. }
  4962. flowParseTypeAlias(node) {
  4963. node.id = this.flowParseRestrictedIdentifier(false, true);
  4964. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4965. if (this.match(47)) {
  4966. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4967. } else {
  4968. node.typeParameters = null;
  4969. }
  4970. node.right = this.flowParseTypeInitialiser(29);
  4971. this.semicolon();
  4972. return this.finishNode(node, "TypeAlias");
  4973. }
  4974. flowParseOpaqueType(node, declare) {
  4975. this.expectContextual(130);
  4976. node.id = this.flowParseRestrictedIdentifier(true, true);
  4977. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4978. if (this.match(47)) {
  4979. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4980. } else {
  4981. node.typeParameters = null;
  4982. }
  4983. node.supertype = null;
  4984. if (this.match(14)) {
  4985. node.supertype = this.flowParseTypeInitialiser(14);
  4986. }
  4987. node.impltype = null;
  4988. if (!declare) {
  4989. node.impltype = this.flowParseTypeInitialiser(29);
  4990. }
  4991. this.semicolon();
  4992. return this.finishNode(node, "OpaqueType");
  4993. }
  4994. flowParseTypeParameter(requireDefault = false) {
  4995. const nodeStartLoc = this.state.startLoc;
  4996. const node = this.startNode();
  4997. const variance = this.flowParseVariance();
  4998. const ident = this.flowParseTypeAnnotatableIdentifier();
  4999. node.name = ident.name;
  5000. node.variance = variance;
  5001. node.bound = ident.typeAnnotation;
  5002. if (this.match(29)) {
  5003. this.eat(29);
  5004. node.default = this.flowParseType();
  5005. } else {
  5006. if (requireDefault) {
  5007. this.raise(FlowErrors.MissingTypeParamDefault, {
  5008. at: nodeStartLoc
  5009. });
  5010. }
  5011. }
  5012. return this.finishNode(node, "TypeParameter");
  5013. }
  5014. flowParseTypeParameterDeclaration() {
  5015. const oldInType = this.state.inType;
  5016. const node = this.startNode();
  5017. node.params = [];
  5018. this.state.inType = true;
  5019. if (this.match(47) || this.match(142)) {
  5020. this.next();
  5021. } else {
  5022. this.unexpected();
  5023. }
  5024. let defaultRequired = false;
  5025. do {
  5026. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  5027. node.params.push(typeParameter);
  5028. if (typeParameter.default) {
  5029. defaultRequired = true;
  5030. }
  5031. if (!this.match(48)) {
  5032. this.expect(12);
  5033. }
  5034. } while (!this.match(48));
  5035. this.expect(48);
  5036. this.state.inType = oldInType;
  5037. return this.finishNode(node, "TypeParameterDeclaration");
  5038. }
  5039. flowParseTypeParameterInstantiation() {
  5040. const node = this.startNode();
  5041. const oldInType = this.state.inType;
  5042. node.params = [];
  5043. this.state.inType = true;
  5044. this.expect(47);
  5045. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5046. this.state.noAnonFunctionType = false;
  5047. while (!this.match(48)) {
  5048. node.params.push(this.flowParseType());
  5049. if (!this.match(48)) {
  5050. this.expect(12);
  5051. }
  5052. }
  5053. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5054. this.expect(48);
  5055. this.state.inType = oldInType;
  5056. return this.finishNode(node, "TypeParameterInstantiation");
  5057. }
  5058. flowParseTypeParameterInstantiationCallOrNew() {
  5059. const node = this.startNode();
  5060. const oldInType = this.state.inType;
  5061. node.params = [];
  5062. this.state.inType = true;
  5063. this.expect(47);
  5064. while (!this.match(48)) {
  5065. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  5066. if (!this.match(48)) {
  5067. this.expect(12);
  5068. }
  5069. }
  5070. this.expect(48);
  5071. this.state.inType = oldInType;
  5072. return this.finishNode(node, "TypeParameterInstantiation");
  5073. }
  5074. flowParseInterfaceType() {
  5075. const node = this.startNode();
  5076. this.expectContextual(129);
  5077. node.extends = [];
  5078. if (this.eat(81)) {
  5079. do {
  5080. node.extends.push(this.flowParseInterfaceExtends());
  5081. } while (this.eat(12));
  5082. }
  5083. node.body = this.flowParseObjectType({
  5084. allowStatic: false,
  5085. allowExact: false,
  5086. allowSpread: false,
  5087. allowProto: false,
  5088. allowInexact: false
  5089. });
  5090. return this.finishNode(node, "InterfaceTypeAnnotation");
  5091. }
  5092. flowParseObjectPropertyKey() {
  5093. return this.match(134) || this.match(133) ? super.parseExprAtom() : this.parseIdentifier(true);
  5094. }
  5095. flowParseObjectTypeIndexer(node, isStatic, variance) {
  5096. node.static = isStatic;
  5097. if (this.lookahead().type === 14) {
  5098. node.id = this.flowParseObjectPropertyKey();
  5099. node.key = this.flowParseTypeInitialiser();
  5100. } else {
  5101. node.id = null;
  5102. node.key = this.flowParseType();
  5103. }
  5104. this.expect(3);
  5105. node.value = this.flowParseTypeInitialiser();
  5106. node.variance = variance;
  5107. return this.finishNode(node, "ObjectTypeIndexer");
  5108. }
  5109. flowParseObjectTypeInternalSlot(node, isStatic) {
  5110. node.static = isStatic;
  5111. node.id = this.flowParseObjectPropertyKey();
  5112. this.expect(3);
  5113. this.expect(3);
  5114. if (this.match(47) || this.match(10)) {
  5115. node.method = true;
  5116. node.optional = false;
  5117. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  5118. } else {
  5119. node.method = false;
  5120. if (this.eat(17)) {
  5121. node.optional = true;
  5122. }
  5123. node.value = this.flowParseTypeInitialiser();
  5124. }
  5125. return this.finishNode(node, "ObjectTypeInternalSlot");
  5126. }
  5127. flowParseObjectTypeMethodish(node) {
  5128. node.params = [];
  5129. node.rest = null;
  5130. node.typeParameters = null;
  5131. node.this = null;
  5132. if (this.match(47)) {
  5133. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5134. }
  5135. this.expect(10);
  5136. if (this.match(78)) {
  5137. node.this = this.flowParseFunctionTypeParam(true);
  5138. node.this.name = null;
  5139. if (!this.match(11)) {
  5140. this.expect(12);
  5141. }
  5142. }
  5143. while (!this.match(11) && !this.match(21)) {
  5144. node.params.push(this.flowParseFunctionTypeParam(false));
  5145. if (!this.match(11)) {
  5146. this.expect(12);
  5147. }
  5148. }
  5149. if (this.eat(21)) {
  5150. node.rest = this.flowParseFunctionTypeParam(false);
  5151. }
  5152. this.expect(11);
  5153. node.returnType = this.flowParseTypeInitialiser();
  5154. return this.finishNode(node, "FunctionTypeAnnotation");
  5155. }
  5156. flowParseObjectTypeCallProperty(node, isStatic) {
  5157. const valueNode = this.startNode();
  5158. node.static = isStatic;
  5159. node.value = this.flowParseObjectTypeMethodish(valueNode);
  5160. return this.finishNode(node, "ObjectTypeCallProperty");
  5161. }
  5162. flowParseObjectType({
  5163. allowStatic,
  5164. allowExact,
  5165. allowSpread,
  5166. allowProto,
  5167. allowInexact
  5168. }) {
  5169. const oldInType = this.state.inType;
  5170. this.state.inType = true;
  5171. const nodeStart = this.startNode();
  5172. nodeStart.callProperties = [];
  5173. nodeStart.properties = [];
  5174. nodeStart.indexers = [];
  5175. nodeStart.internalSlots = [];
  5176. let endDelim;
  5177. let exact;
  5178. let inexact = false;
  5179. if (allowExact && this.match(6)) {
  5180. this.expect(6);
  5181. endDelim = 9;
  5182. exact = true;
  5183. } else {
  5184. this.expect(5);
  5185. endDelim = 8;
  5186. exact = false;
  5187. }
  5188. nodeStart.exact = exact;
  5189. while (!this.match(endDelim)) {
  5190. let isStatic = false;
  5191. let protoStartLoc = null;
  5192. let inexactStartLoc = null;
  5193. const node = this.startNode();
  5194. if (allowProto && this.isContextual(118)) {
  5195. const lookahead = this.lookahead();
  5196. if (lookahead.type !== 14 && lookahead.type !== 17) {
  5197. this.next();
  5198. protoStartLoc = this.state.startLoc;
  5199. allowStatic = false;
  5200. }
  5201. }
  5202. if (allowStatic && this.isContextual(106)) {
  5203. const lookahead = this.lookahead();
  5204. if (lookahead.type !== 14 && lookahead.type !== 17) {
  5205. this.next();
  5206. isStatic = true;
  5207. }
  5208. }
  5209. const variance = this.flowParseVariance();
  5210. if (this.eat(0)) {
  5211. if (protoStartLoc != null) {
  5212. this.unexpected(protoStartLoc);
  5213. }
  5214. if (this.eat(0)) {
  5215. if (variance) {
  5216. this.unexpected(variance.loc.start);
  5217. }
  5218. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  5219. } else {
  5220. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  5221. }
  5222. } else if (this.match(10) || this.match(47)) {
  5223. if (protoStartLoc != null) {
  5224. this.unexpected(protoStartLoc);
  5225. }
  5226. if (variance) {
  5227. this.unexpected(variance.loc.start);
  5228. }
  5229. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  5230. } else {
  5231. let kind = "init";
  5232. if (this.isContextual(99) || this.isContextual(104)) {
  5233. const lookahead = this.lookahead();
  5234. if (tokenIsLiteralPropertyName(lookahead.type)) {
  5235. kind = this.state.value;
  5236. this.next();
  5237. }
  5238. }
  5239. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  5240. if (propOrInexact === null) {
  5241. inexact = true;
  5242. inexactStartLoc = this.state.lastTokStartLoc;
  5243. } else {
  5244. nodeStart.properties.push(propOrInexact);
  5245. }
  5246. }
  5247. this.flowObjectTypeSemicolon();
  5248. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  5249. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  5250. at: inexactStartLoc
  5251. });
  5252. }
  5253. }
  5254. this.expect(endDelim);
  5255. if (allowSpread) {
  5256. nodeStart.inexact = inexact;
  5257. }
  5258. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  5259. this.state.inType = oldInType;
  5260. return out;
  5261. }
  5262. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  5263. if (this.eat(21)) {
  5264. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  5265. if (isInexactToken) {
  5266. if (!allowSpread) {
  5267. this.raise(FlowErrors.InexactInsideNonObject, {
  5268. at: this.state.lastTokStartLoc
  5269. });
  5270. } else if (!allowInexact) {
  5271. this.raise(FlowErrors.InexactInsideExact, {
  5272. at: this.state.lastTokStartLoc
  5273. });
  5274. }
  5275. if (variance) {
  5276. this.raise(FlowErrors.InexactVariance, {
  5277. at: variance
  5278. });
  5279. }
  5280. return null;
  5281. }
  5282. if (!allowSpread) {
  5283. this.raise(FlowErrors.UnexpectedSpreadType, {
  5284. at: this.state.lastTokStartLoc
  5285. });
  5286. }
  5287. if (protoStartLoc != null) {
  5288. this.unexpected(protoStartLoc);
  5289. }
  5290. if (variance) {
  5291. this.raise(FlowErrors.SpreadVariance, {
  5292. at: variance
  5293. });
  5294. }
  5295. node.argument = this.flowParseType();
  5296. return this.finishNode(node, "ObjectTypeSpreadProperty");
  5297. } else {
  5298. node.key = this.flowParseObjectPropertyKey();
  5299. node.static = isStatic;
  5300. node.proto = protoStartLoc != null;
  5301. node.kind = kind;
  5302. let optional = false;
  5303. if (this.match(47) || this.match(10)) {
  5304. node.method = true;
  5305. if (protoStartLoc != null) {
  5306. this.unexpected(protoStartLoc);
  5307. }
  5308. if (variance) {
  5309. this.unexpected(variance.loc.start);
  5310. }
  5311. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  5312. if (kind === "get" || kind === "set") {
  5313. this.flowCheckGetterSetterParams(node);
  5314. }
  5315. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  5316. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5317. at: node.value.this
  5318. });
  5319. }
  5320. } else {
  5321. if (kind !== "init") this.unexpected();
  5322. node.method = false;
  5323. if (this.eat(17)) {
  5324. optional = true;
  5325. }
  5326. node.value = this.flowParseTypeInitialiser();
  5327. node.variance = variance;
  5328. }
  5329. node.optional = optional;
  5330. return this.finishNode(node, "ObjectTypeProperty");
  5331. }
  5332. }
  5333. flowCheckGetterSetterParams(property) {
  5334. const paramCount = property.kind === "get" ? 0 : 1;
  5335. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  5336. if (property.value.this) {
  5337. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  5338. at: property.value.this
  5339. });
  5340. }
  5341. if (length !== paramCount) {
  5342. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  5343. at: property
  5344. });
  5345. }
  5346. if (property.kind === "set" && property.value.rest) {
  5347. this.raise(Errors.BadSetterRestParameter, {
  5348. at: property
  5349. });
  5350. }
  5351. }
  5352. flowObjectTypeSemicolon() {
  5353. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  5354. this.unexpected();
  5355. }
  5356. }
  5357. flowParseQualifiedTypeIdentifier(startLoc, id) {
  5358. var _startLoc;
  5359. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  5360. let node = id || this.flowParseRestrictedIdentifier(true);
  5361. while (this.eat(16)) {
  5362. const node2 = this.startNodeAt(startLoc);
  5363. node2.qualification = node;
  5364. node2.id = this.flowParseRestrictedIdentifier(true);
  5365. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  5366. }
  5367. return node;
  5368. }
  5369. flowParseGenericType(startLoc, id) {
  5370. const node = this.startNodeAt(startLoc);
  5371. node.typeParameters = null;
  5372. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  5373. if (this.match(47)) {
  5374. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5375. }
  5376. return this.finishNode(node, "GenericTypeAnnotation");
  5377. }
  5378. flowParseTypeofType() {
  5379. const node = this.startNode();
  5380. this.expect(87);
  5381. node.argument = this.flowParsePrimaryType();
  5382. return this.finishNode(node, "TypeofTypeAnnotation");
  5383. }
  5384. flowParseTupleType() {
  5385. const node = this.startNode();
  5386. node.types = [];
  5387. this.expect(0);
  5388. while (this.state.pos < this.length && !this.match(3)) {
  5389. node.types.push(this.flowParseType());
  5390. if (this.match(3)) break;
  5391. this.expect(12);
  5392. }
  5393. this.expect(3);
  5394. return this.finishNode(node, "TupleTypeAnnotation");
  5395. }
  5396. flowParseFunctionTypeParam(first) {
  5397. let name = null;
  5398. let optional = false;
  5399. let typeAnnotation = null;
  5400. const node = this.startNode();
  5401. const lh = this.lookahead();
  5402. const isThis = this.state.type === 78;
  5403. if (lh.type === 14 || lh.type === 17) {
  5404. if (isThis && !first) {
  5405. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5406. at: node
  5407. });
  5408. }
  5409. name = this.parseIdentifier(isThis);
  5410. if (this.eat(17)) {
  5411. optional = true;
  5412. if (isThis) {
  5413. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5414. at: node
  5415. });
  5416. }
  5417. }
  5418. typeAnnotation = this.flowParseTypeInitialiser();
  5419. } else {
  5420. typeAnnotation = this.flowParseType();
  5421. }
  5422. node.name = name;
  5423. node.optional = optional;
  5424. node.typeAnnotation = typeAnnotation;
  5425. return this.finishNode(node, "FunctionTypeParam");
  5426. }
  5427. reinterpretTypeAsFunctionTypeParam(type) {
  5428. const node = this.startNodeAt(type.loc.start);
  5429. node.name = null;
  5430. node.optional = false;
  5431. node.typeAnnotation = type;
  5432. return this.finishNode(node, "FunctionTypeParam");
  5433. }
  5434. flowParseFunctionTypeParams(params = []) {
  5435. let rest = null;
  5436. let _this = null;
  5437. if (this.match(78)) {
  5438. _this = this.flowParseFunctionTypeParam(true);
  5439. _this.name = null;
  5440. if (!this.match(11)) {
  5441. this.expect(12);
  5442. }
  5443. }
  5444. while (!this.match(11) && !this.match(21)) {
  5445. params.push(this.flowParseFunctionTypeParam(false));
  5446. if (!this.match(11)) {
  5447. this.expect(12);
  5448. }
  5449. }
  5450. if (this.eat(21)) {
  5451. rest = this.flowParseFunctionTypeParam(false);
  5452. }
  5453. return {
  5454. params,
  5455. rest,
  5456. _this
  5457. };
  5458. }
  5459. flowIdentToTypeAnnotation(startLoc, node, id) {
  5460. switch (id.name) {
  5461. case "any":
  5462. return this.finishNode(node, "AnyTypeAnnotation");
  5463. case "bool":
  5464. case "boolean":
  5465. return this.finishNode(node, "BooleanTypeAnnotation");
  5466. case "mixed":
  5467. return this.finishNode(node, "MixedTypeAnnotation");
  5468. case "empty":
  5469. return this.finishNode(node, "EmptyTypeAnnotation");
  5470. case "number":
  5471. return this.finishNode(node, "NumberTypeAnnotation");
  5472. case "string":
  5473. return this.finishNode(node, "StringTypeAnnotation");
  5474. case "symbol":
  5475. return this.finishNode(node, "SymbolTypeAnnotation");
  5476. default:
  5477. this.checkNotUnderscore(id.name);
  5478. return this.flowParseGenericType(startLoc, id);
  5479. }
  5480. }
  5481. flowParsePrimaryType() {
  5482. const startLoc = this.state.startLoc;
  5483. const node = this.startNode();
  5484. let tmp;
  5485. let type;
  5486. let isGroupedType = false;
  5487. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5488. switch (this.state.type) {
  5489. case 5:
  5490. return this.flowParseObjectType({
  5491. allowStatic: false,
  5492. allowExact: false,
  5493. allowSpread: true,
  5494. allowProto: false,
  5495. allowInexact: true
  5496. });
  5497. case 6:
  5498. return this.flowParseObjectType({
  5499. allowStatic: false,
  5500. allowExact: true,
  5501. allowSpread: true,
  5502. allowProto: false,
  5503. allowInexact: false
  5504. });
  5505. case 0:
  5506. this.state.noAnonFunctionType = false;
  5507. type = this.flowParseTupleType();
  5508. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5509. return type;
  5510. case 47:
  5511. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5512. this.expect(10);
  5513. tmp = this.flowParseFunctionTypeParams();
  5514. node.params = tmp.params;
  5515. node.rest = tmp.rest;
  5516. node.this = tmp._this;
  5517. this.expect(11);
  5518. this.expect(19);
  5519. node.returnType = this.flowParseType();
  5520. return this.finishNode(node, "FunctionTypeAnnotation");
  5521. case 10:
  5522. this.next();
  5523. if (!this.match(11) && !this.match(21)) {
  5524. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  5525. const token = this.lookahead().type;
  5526. isGroupedType = token !== 17 && token !== 14;
  5527. } else {
  5528. isGroupedType = true;
  5529. }
  5530. }
  5531. if (isGroupedType) {
  5532. this.state.noAnonFunctionType = false;
  5533. type = this.flowParseType();
  5534. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5535. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  5536. this.expect(11);
  5537. return type;
  5538. } else {
  5539. this.eat(12);
  5540. }
  5541. }
  5542. if (type) {
  5543. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  5544. } else {
  5545. tmp = this.flowParseFunctionTypeParams();
  5546. }
  5547. node.params = tmp.params;
  5548. node.rest = tmp.rest;
  5549. node.this = tmp._this;
  5550. this.expect(11);
  5551. this.expect(19);
  5552. node.returnType = this.flowParseType();
  5553. node.typeParameters = null;
  5554. return this.finishNode(node, "FunctionTypeAnnotation");
  5555. case 133:
  5556. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  5557. case 85:
  5558. case 86:
  5559. node.value = this.match(85);
  5560. this.next();
  5561. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  5562. case 53:
  5563. if (this.state.value === "-") {
  5564. this.next();
  5565. if (this.match(134)) {
  5566. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  5567. }
  5568. if (this.match(135)) {
  5569. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  5570. }
  5571. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  5572. at: this.state.startLoc
  5573. });
  5574. }
  5575. this.unexpected();
  5576. return;
  5577. case 134:
  5578. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  5579. case 135:
  5580. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  5581. case 88:
  5582. this.next();
  5583. return this.finishNode(node, "VoidTypeAnnotation");
  5584. case 84:
  5585. this.next();
  5586. return this.finishNode(node, "NullLiteralTypeAnnotation");
  5587. case 78:
  5588. this.next();
  5589. return this.finishNode(node, "ThisTypeAnnotation");
  5590. case 55:
  5591. this.next();
  5592. return this.finishNode(node, "ExistsTypeAnnotation");
  5593. case 87:
  5594. return this.flowParseTypeofType();
  5595. default:
  5596. if (tokenIsKeyword(this.state.type)) {
  5597. const label = tokenLabelName(this.state.type);
  5598. this.next();
  5599. return super.createIdentifier(node, label);
  5600. } else if (tokenIsIdentifier(this.state.type)) {
  5601. if (this.isContextual(129)) {
  5602. return this.flowParseInterfaceType();
  5603. }
  5604. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  5605. }
  5606. }
  5607. this.unexpected();
  5608. }
  5609. flowParsePostfixType() {
  5610. const startLoc = this.state.startLoc;
  5611. let type = this.flowParsePrimaryType();
  5612. let seenOptionalIndexedAccess = false;
  5613. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  5614. const node = this.startNodeAt(startLoc);
  5615. const optional = this.eat(18);
  5616. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5617. this.expect(0);
  5618. if (!optional && this.match(3)) {
  5619. node.elementType = type;
  5620. this.next();
  5621. type = this.finishNode(node, "ArrayTypeAnnotation");
  5622. } else {
  5623. node.objectType = type;
  5624. node.indexType = this.flowParseType();
  5625. this.expect(3);
  5626. if (seenOptionalIndexedAccess) {
  5627. node.optional = optional;
  5628. type = this.finishNode(node, "OptionalIndexedAccessType");
  5629. } else {
  5630. type = this.finishNode(node, "IndexedAccessType");
  5631. }
  5632. }
  5633. }
  5634. return type;
  5635. }
  5636. flowParsePrefixType() {
  5637. const node = this.startNode();
  5638. if (this.eat(17)) {
  5639. node.typeAnnotation = this.flowParsePrefixType();
  5640. return this.finishNode(node, "NullableTypeAnnotation");
  5641. } else {
  5642. return this.flowParsePostfixType();
  5643. }
  5644. }
  5645. flowParseAnonFunctionWithoutParens() {
  5646. const param = this.flowParsePrefixType();
  5647. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5648. const node = this.startNodeAt(param.loc.start);
  5649. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5650. node.rest = null;
  5651. node.this = null;
  5652. node.returnType = this.flowParseType();
  5653. node.typeParameters = null;
  5654. return this.finishNode(node, "FunctionTypeAnnotation");
  5655. }
  5656. return param;
  5657. }
  5658. flowParseIntersectionType() {
  5659. const node = this.startNode();
  5660. this.eat(45);
  5661. const type = this.flowParseAnonFunctionWithoutParens();
  5662. node.types = [type];
  5663. while (this.eat(45)) {
  5664. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5665. }
  5666. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5667. }
  5668. flowParseUnionType() {
  5669. const node = this.startNode();
  5670. this.eat(43);
  5671. const type = this.flowParseIntersectionType();
  5672. node.types = [type];
  5673. while (this.eat(43)) {
  5674. node.types.push(this.flowParseIntersectionType());
  5675. }
  5676. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5677. }
  5678. flowParseType() {
  5679. const oldInType = this.state.inType;
  5680. this.state.inType = true;
  5681. const type = this.flowParseUnionType();
  5682. this.state.inType = oldInType;
  5683. return type;
  5684. }
  5685. flowParseTypeOrImplicitInstantiation() {
  5686. if (this.state.type === 132 && this.state.value === "_") {
  5687. const startLoc = this.state.startLoc;
  5688. const node = this.parseIdentifier();
  5689. return this.flowParseGenericType(startLoc, node);
  5690. } else {
  5691. return this.flowParseType();
  5692. }
  5693. }
  5694. flowParseTypeAnnotation() {
  5695. const node = this.startNode();
  5696. node.typeAnnotation = this.flowParseTypeInitialiser();
  5697. return this.finishNode(node, "TypeAnnotation");
  5698. }
  5699. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5700. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5701. if (this.match(14)) {
  5702. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5703. this.resetEndLocation(ident);
  5704. }
  5705. return ident;
  5706. }
  5707. typeCastToParameter(node) {
  5708. node.expression.typeAnnotation = node.typeAnnotation;
  5709. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5710. return node.expression;
  5711. }
  5712. flowParseVariance() {
  5713. let variance = null;
  5714. if (this.match(53)) {
  5715. variance = this.startNode();
  5716. if (this.state.value === "+") {
  5717. variance.kind = "plus";
  5718. } else {
  5719. variance.kind = "minus";
  5720. }
  5721. this.next();
  5722. return this.finishNode(variance, "Variance");
  5723. }
  5724. return variance;
  5725. }
  5726. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5727. if (allowExpressionBody) {
  5728. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5729. return;
  5730. }
  5731. super.parseFunctionBody(node, false, isMethod);
  5732. }
  5733. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5734. if (this.match(14)) {
  5735. const typeNode = this.startNode();
  5736. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5737. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5738. }
  5739. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5740. }
  5741. parseStatementLike(flags) {
  5742. if (this.state.strict && this.isContextual(129)) {
  5743. const lookahead = this.lookahead();
  5744. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5745. const node = this.startNode();
  5746. this.next();
  5747. return this.flowParseInterface(node);
  5748. }
  5749. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5750. const node = this.startNode();
  5751. this.next();
  5752. return this.flowParseEnumDeclaration(node);
  5753. }
  5754. const stmt = super.parseStatementLike(flags);
  5755. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5756. this.flowPragma = null;
  5757. }
  5758. return stmt;
  5759. }
  5760. parseExpressionStatement(node, expr, decorators) {
  5761. if (expr.type === "Identifier") {
  5762. if (expr.name === "declare") {
  5763. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5764. return this.flowParseDeclare(node);
  5765. }
  5766. } else if (tokenIsIdentifier(this.state.type)) {
  5767. if (expr.name === "interface") {
  5768. return this.flowParseInterface(node);
  5769. } else if (expr.name === "type") {
  5770. return this.flowParseTypeAlias(node);
  5771. } else if (expr.name === "opaque") {
  5772. return this.flowParseOpaqueType(node, false);
  5773. }
  5774. }
  5775. }
  5776. return super.parseExpressionStatement(node, expr, decorators);
  5777. }
  5778. shouldParseExportDeclaration() {
  5779. const {
  5780. type
  5781. } = this.state;
  5782. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5783. return !this.state.containsEsc;
  5784. }
  5785. return super.shouldParseExportDeclaration();
  5786. }
  5787. isExportDefaultSpecifier() {
  5788. const {
  5789. type
  5790. } = this.state;
  5791. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5792. return this.state.containsEsc;
  5793. }
  5794. return super.isExportDefaultSpecifier();
  5795. }
  5796. parseExportDefaultExpression() {
  5797. if (this.shouldParseEnums() && this.isContextual(126)) {
  5798. const node = this.startNode();
  5799. this.next();
  5800. return this.flowParseEnumDeclaration(node);
  5801. }
  5802. return super.parseExportDefaultExpression();
  5803. }
  5804. parseConditional(expr, startLoc, refExpressionErrors) {
  5805. if (!this.match(17)) return expr;
  5806. if (this.state.maybeInArrowParameters) {
  5807. const nextCh = this.lookaheadCharCode();
  5808. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5809. this.setOptionalParametersError(refExpressionErrors);
  5810. return expr;
  5811. }
  5812. }
  5813. this.expect(17);
  5814. const state = this.state.clone();
  5815. const originalNoArrowAt = this.state.noArrowAt;
  5816. const node = this.startNodeAt(startLoc);
  5817. let {
  5818. consequent,
  5819. failed
  5820. } = this.tryParseConditionalConsequent();
  5821. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5822. if (failed || invalid.length > 0) {
  5823. const noArrowAt = [...originalNoArrowAt];
  5824. if (invalid.length > 0) {
  5825. this.state = state;
  5826. this.state.noArrowAt = noArrowAt;
  5827. for (let i = 0; i < invalid.length; i++) {
  5828. noArrowAt.push(invalid[i].start);
  5829. }
  5830. ({
  5831. consequent,
  5832. failed
  5833. } = this.tryParseConditionalConsequent());
  5834. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5835. }
  5836. if (failed && valid.length > 1) {
  5837. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5838. at: state.startLoc
  5839. });
  5840. }
  5841. if (failed && valid.length === 1) {
  5842. this.state = state;
  5843. noArrowAt.push(valid[0].start);
  5844. this.state.noArrowAt = noArrowAt;
  5845. ({
  5846. consequent,
  5847. failed
  5848. } = this.tryParseConditionalConsequent());
  5849. }
  5850. }
  5851. this.getArrowLikeExpressions(consequent, true);
  5852. this.state.noArrowAt = originalNoArrowAt;
  5853. this.expect(14);
  5854. node.test = expr;
  5855. node.consequent = consequent;
  5856. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5857. return this.finishNode(node, "ConditionalExpression");
  5858. }
  5859. tryParseConditionalConsequent() {
  5860. this.state.noArrowParamsConversionAt.push(this.state.start);
  5861. const consequent = this.parseMaybeAssignAllowIn();
  5862. const failed = !this.match(14);
  5863. this.state.noArrowParamsConversionAt.pop();
  5864. return {
  5865. consequent,
  5866. failed
  5867. };
  5868. }
  5869. getArrowLikeExpressions(node, disallowInvalid) {
  5870. const stack = [node];
  5871. const arrows = [];
  5872. while (stack.length !== 0) {
  5873. const node = stack.pop();
  5874. if (node.type === "ArrowFunctionExpression") {
  5875. if (node.typeParameters || !node.returnType) {
  5876. this.finishArrowValidation(node);
  5877. } else {
  5878. arrows.push(node);
  5879. }
  5880. stack.push(node.body);
  5881. } else if (node.type === "ConditionalExpression") {
  5882. stack.push(node.consequent);
  5883. stack.push(node.alternate);
  5884. }
  5885. }
  5886. if (disallowInvalid) {
  5887. arrows.forEach(node => this.finishArrowValidation(node));
  5888. return [arrows, []];
  5889. }
  5890. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5891. }
  5892. finishArrowValidation(node) {
  5893. var _node$extra;
  5894. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5895. this.scope.enter(2 | 4);
  5896. super.checkParams(node, false, true);
  5897. this.scope.exit();
  5898. }
  5899. forwardNoArrowParamsConversionAt(node, parse) {
  5900. let result;
  5901. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5902. this.state.noArrowParamsConversionAt.push(this.state.start);
  5903. result = parse();
  5904. this.state.noArrowParamsConversionAt.pop();
  5905. } else {
  5906. result = parse();
  5907. }
  5908. return result;
  5909. }
  5910. parseParenItem(node, startLoc) {
  5911. node = super.parseParenItem(node, startLoc);
  5912. if (this.eat(17)) {
  5913. node.optional = true;
  5914. this.resetEndLocation(node);
  5915. }
  5916. if (this.match(14)) {
  5917. const typeCastNode = this.startNodeAt(startLoc);
  5918. typeCastNode.expression = node;
  5919. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5920. return this.finishNode(typeCastNode, "TypeCastExpression");
  5921. }
  5922. return node;
  5923. }
  5924. assertModuleNodeAllowed(node) {
  5925. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5926. return;
  5927. }
  5928. super.assertModuleNodeAllowed(node);
  5929. }
  5930. parseExportDeclaration(node) {
  5931. if (this.isContextual(130)) {
  5932. node.exportKind = "type";
  5933. const declarationNode = this.startNode();
  5934. this.next();
  5935. if (this.match(5)) {
  5936. node.specifiers = this.parseExportSpecifiers(true);
  5937. super.parseExportFrom(node);
  5938. return null;
  5939. } else {
  5940. return this.flowParseTypeAlias(declarationNode);
  5941. }
  5942. } else if (this.isContextual(131)) {
  5943. node.exportKind = "type";
  5944. const declarationNode = this.startNode();
  5945. this.next();
  5946. return this.flowParseOpaqueType(declarationNode, false);
  5947. } else if (this.isContextual(129)) {
  5948. node.exportKind = "type";
  5949. const declarationNode = this.startNode();
  5950. this.next();
  5951. return this.flowParseInterface(declarationNode);
  5952. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5953. node.exportKind = "value";
  5954. const declarationNode = this.startNode();
  5955. this.next();
  5956. return this.flowParseEnumDeclaration(declarationNode);
  5957. } else {
  5958. return super.parseExportDeclaration(node);
  5959. }
  5960. }
  5961. eatExportStar(node) {
  5962. if (super.eatExportStar(node)) return true;
  5963. if (this.isContextual(130) && this.lookahead().type === 55) {
  5964. node.exportKind = "type";
  5965. this.next();
  5966. this.next();
  5967. return true;
  5968. }
  5969. return false;
  5970. }
  5971. maybeParseExportNamespaceSpecifier(node) {
  5972. const {
  5973. startLoc
  5974. } = this.state;
  5975. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5976. if (hasNamespace && node.exportKind === "type") {
  5977. this.unexpected(startLoc);
  5978. }
  5979. return hasNamespace;
  5980. }
  5981. parseClassId(node, isStatement, optionalId) {
  5982. super.parseClassId(node, isStatement, optionalId);
  5983. if (this.match(47)) {
  5984. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5985. }
  5986. }
  5987. parseClassMember(classBody, member, state) {
  5988. const {
  5989. startLoc
  5990. } = this.state;
  5991. if (this.isContextual(125)) {
  5992. if (super.parseClassMemberFromModifier(classBody, member)) {
  5993. return;
  5994. }
  5995. member.declare = true;
  5996. }
  5997. super.parseClassMember(classBody, member, state);
  5998. if (member.declare) {
  5999. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  6000. this.raise(FlowErrors.DeclareClassElement, {
  6001. at: startLoc
  6002. });
  6003. } else if (member.value) {
  6004. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  6005. at: member.value
  6006. });
  6007. }
  6008. }
  6009. }
  6010. isIterator(word) {
  6011. return word === "iterator" || word === "asyncIterator";
  6012. }
  6013. readIterator() {
  6014. const word = super.readWord1();
  6015. const fullWord = "@@" + word;
  6016. if (!this.isIterator(word) || !this.state.inType) {
  6017. this.raise(Errors.InvalidIdentifier, {
  6018. at: this.state.curPosition(),
  6019. identifierName: fullWord
  6020. });
  6021. }
  6022. this.finishToken(132, fullWord);
  6023. }
  6024. getTokenFromCode(code) {
  6025. const next = this.input.charCodeAt(this.state.pos + 1);
  6026. if (code === 123 && next === 124) {
  6027. this.finishOp(6, 2);
  6028. } else if (this.state.inType && (code === 62 || code === 60)) {
  6029. this.finishOp(code === 62 ? 48 : 47, 1);
  6030. } else if (this.state.inType && code === 63) {
  6031. if (next === 46) {
  6032. this.finishOp(18, 2);
  6033. } else {
  6034. this.finishOp(17, 1);
  6035. }
  6036. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  6037. this.state.pos += 2;
  6038. this.readIterator();
  6039. } else {
  6040. super.getTokenFromCode(code);
  6041. }
  6042. }
  6043. isAssignable(node, isBinding) {
  6044. if (node.type === "TypeCastExpression") {
  6045. return this.isAssignable(node.expression, isBinding);
  6046. } else {
  6047. return super.isAssignable(node, isBinding);
  6048. }
  6049. }
  6050. toAssignable(node, isLHS = false) {
  6051. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  6052. node.left = this.typeCastToParameter(node.left);
  6053. }
  6054. super.toAssignable(node, isLHS);
  6055. }
  6056. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  6057. for (let i = 0; i < exprList.length; i++) {
  6058. const expr = exprList[i];
  6059. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  6060. exprList[i] = this.typeCastToParameter(expr);
  6061. }
  6062. }
  6063. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  6064. }
  6065. toReferencedList(exprList, isParenthesizedExpr) {
  6066. for (let i = 0; i < exprList.length; i++) {
  6067. var _expr$extra;
  6068. const expr = exprList[i];
  6069. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  6070. this.raise(FlowErrors.TypeCastInPattern, {
  6071. at: expr.typeAnnotation
  6072. });
  6073. }
  6074. }
  6075. return exprList;
  6076. }
  6077. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  6078. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  6079. if (canBePattern && !this.state.maybeInArrowParameters) {
  6080. this.toReferencedList(node.elements);
  6081. }
  6082. return node;
  6083. }
  6084. isValidLVal(type, isParenthesized, binding) {
  6085. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  6086. }
  6087. parseClassProperty(node) {
  6088. if (this.match(14)) {
  6089. node.typeAnnotation = this.flowParseTypeAnnotation();
  6090. }
  6091. return super.parseClassProperty(node);
  6092. }
  6093. parseClassPrivateProperty(node) {
  6094. if (this.match(14)) {
  6095. node.typeAnnotation = this.flowParseTypeAnnotation();
  6096. }
  6097. return super.parseClassPrivateProperty(node);
  6098. }
  6099. isClassMethod() {
  6100. return this.match(47) || super.isClassMethod();
  6101. }
  6102. isClassProperty() {
  6103. return this.match(14) || super.isClassProperty();
  6104. }
  6105. isNonstaticConstructor(method) {
  6106. return !this.match(14) && super.isNonstaticConstructor(method);
  6107. }
  6108. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  6109. if (method.variance) {
  6110. this.unexpected(method.variance.loc.start);
  6111. }
  6112. delete method.variance;
  6113. if (this.match(47)) {
  6114. method.typeParameters = this.flowParseTypeParameterDeclaration();
  6115. }
  6116. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  6117. if (method.params && isConstructor) {
  6118. const params = method.params;
  6119. if (params.length > 0 && this.isThisParam(params[0])) {
  6120. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  6121. at: method
  6122. });
  6123. }
  6124. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  6125. const params = method.value.params;
  6126. if (params.length > 0 && this.isThisParam(params[0])) {
  6127. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  6128. at: method
  6129. });
  6130. }
  6131. }
  6132. }
  6133. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  6134. if (method.variance) {
  6135. this.unexpected(method.variance.loc.start);
  6136. }
  6137. delete method.variance;
  6138. if (this.match(47)) {
  6139. method.typeParameters = this.flowParseTypeParameterDeclaration();
  6140. }
  6141. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  6142. }
  6143. parseClassSuper(node) {
  6144. super.parseClassSuper(node);
  6145. if (node.superClass && this.match(47)) {
  6146. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  6147. }
  6148. if (this.isContextual(113)) {
  6149. this.next();
  6150. const implemented = node.implements = [];
  6151. do {
  6152. const node = this.startNode();
  6153. node.id = this.flowParseRestrictedIdentifier(true);
  6154. if (this.match(47)) {
  6155. node.typeParameters = this.flowParseTypeParameterInstantiation();
  6156. } else {
  6157. node.typeParameters = null;
  6158. }
  6159. implemented.push(this.finishNode(node, "ClassImplements"));
  6160. } while (this.eat(12));
  6161. }
  6162. }
  6163. checkGetterSetterParams(method) {
  6164. super.checkGetterSetterParams(method);
  6165. const params = this.getObjectOrClassMethodParams(method);
  6166. if (params.length > 0) {
  6167. const param = params[0];
  6168. if (this.isThisParam(param) && method.kind === "get") {
  6169. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  6170. at: param
  6171. });
  6172. } else if (this.isThisParam(param)) {
  6173. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  6174. at: param
  6175. });
  6176. }
  6177. }
  6178. }
  6179. parsePropertyNamePrefixOperator(node) {
  6180. node.variance = this.flowParseVariance();
  6181. }
  6182. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  6183. if (prop.variance) {
  6184. this.unexpected(prop.variance.loc.start);
  6185. }
  6186. delete prop.variance;
  6187. let typeParameters;
  6188. if (this.match(47) && !isAccessor) {
  6189. typeParameters = this.flowParseTypeParameterDeclaration();
  6190. if (!this.match(10)) this.unexpected();
  6191. }
  6192. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  6193. if (typeParameters) {
  6194. (result.value || result).typeParameters = typeParameters;
  6195. }
  6196. return result;
  6197. }
  6198. parseAssignableListItemTypes(param) {
  6199. if (this.eat(17)) {
  6200. if (param.type !== "Identifier") {
  6201. this.raise(FlowErrors.PatternIsOptional, {
  6202. at: param
  6203. });
  6204. }
  6205. if (this.isThisParam(param)) {
  6206. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  6207. at: param
  6208. });
  6209. }
  6210. param.optional = true;
  6211. }
  6212. if (this.match(14)) {
  6213. param.typeAnnotation = this.flowParseTypeAnnotation();
  6214. } else if (this.isThisParam(param)) {
  6215. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  6216. at: param
  6217. });
  6218. }
  6219. if (this.match(29) && this.isThisParam(param)) {
  6220. this.raise(FlowErrors.ThisParamNoDefault, {
  6221. at: param
  6222. });
  6223. }
  6224. this.resetEndLocation(param);
  6225. return param;
  6226. }
  6227. parseMaybeDefault(startLoc, left) {
  6228. const node = super.parseMaybeDefault(startLoc, left);
  6229. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  6230. this.raise(FlowErrors.TypeBeforeInitializer, {
  6231. at: node.typeAnnotation
  6232. });
  6233. }
  6234. return node;
  6235. }
  6236. checkImportReflection(node) {
  6237. super.checkImportReflection(node);
  6238. if (node.module && node.importKind !== "value") {
  6239. this.raise(FlowErrors.ImportReflectionHasImportType, {
  6240. at: node.specifiers[0].loc.start
  6241. });
  6242. }
  6243. }
  6244. parseImportSpecifierLocal(node, specifier, type) {
  6245. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  6246. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  6247. }
  6248. isPotentialImportPhase(isExport) {
  6249. if (super.isPotentialImportPhase(isExport)) return true;
  6250. if (this.isContextual(130)) {
  6251. if (!isExport) return true;
  6252. const ch = this.lookaheadCharCode();
  6253. return ch === 123 || ch === 42;
  6254. }
  6255. return !isExport && this.isContextual(87);
  6256. }
  6257. applyImportPhase(node, isExport, phase, loc) {
  6258. super.applyImportPhase(node, isExport, phase, loc);
  6259. if (isExport) {
  6260. if (!phase && this.match(65)) {
  6261. return;
  6262. }
  6263. node.exportKind = phase === "type" ? phase : "value";
  6264. } else {
  6265. if (phase === "type" && this.match(55)) this.unexpected();
  6266. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  6267. }
  6268. }
  6269. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  6270. const firstIdent = specifier.imported;
  6271. let specifierTypeKind = null;
  6272. if (firstIdent.type === "Identifier") {
  6273. if (firstIdent.name === "type") {
  6274. specifierTypeKind = "type";
  6275. } else if (firstIdent.name === "typeof") {
  6276. specifierTypeKind = "typeof";
  6277. }
  6278. }
  6279. let isBinding = false;
  6280. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  6281. const as_ident = this.parseIdentifier(true);
  6282. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  6283. specifier.imported = as_ident;
  6284. specifier.importKind = specifierTypeKind;
  6285. specifier.local = cloneIdentifier(as_ident);
  6286. } else {
  6287. specifier.imported = firstIdent;
  6288. specifier.importKind = null;
  6289. specifier.local = this.parseIdentifier();
  6290. }
  6291. } else {
  6292. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  6293. specifier.imported = this.parseIdentifier(true);
  6294. specifier.importKind = specifierTypeKind;
  6295. } else {
  6296. if (importedIsString) {
  6297. throw this.raise(Errors.ImportBindingIsString, {
  6298. at: specifier,
  6299. importName: firstIdent.value
  6300. });
  6301. }
  6302. specifier.imported = firstIdent;
  6303. specifier.importKind = null;
  6304. }
  6305. if (this.eatContextual(93)) {
  6306. specifier.local = this.parseIdentifier();
  6307. } else {
  6308. isBinding = true;
  6309. specifier.local = cloneIdentifier(specifier.imported);
  6310. }
  6311. }
  6312. const specifierIsTypeImport = hasTypeImportKind(specifier);
  6313. if (isInTypeOnlyImport && specifierIsTypeImport) {
  6314. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  6315. at: specifier
  6316. });
  6317. }
  6318. if (isInTypeOnlyImport || specifierIsTypeImport) {
  6319. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  6320. }
  6321. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  6322. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  6323. }
  6324. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  6325. }
  6326. parseBindingAtom() {
  6327. switch (this.state.type) {
  6328. case 78:
  6329. return this.parseIdentifier(true);
  6330. default:
  6331. return super.parseBindingAtom();
  6332. }
  6333. }
  6334. parseFunctionParams(node, isConstructor) {
  6335. const kind = node.kind;
  6336. if (kind !== "get" && kind !== "set" && this.match(47)) {
  6337. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6338. }
  6339. super.parseFunctionParams(node, isConstructor);
  6340. }
  6341. parseVarId(decl, kind) {
  6342. super.parseVarId(decl, kind);
  6343. if (this.match(14)) {
  6344. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  6345. this.resetEndLocation(decl.id);
  6346. }
  6347. }
  6348. parseAsyncArrowFromCallExpression(node, call) {
  6349. if (this.match(14)) {
  6350. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6351. this.state.noAnonFunctionType = true;
  6352. node.returnType = this.flowParseTypeAnnotation();
  6353. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6354. }
  6355. return super.parseAsyncArrowFromCallExpression(node, call);
  6356. }
  6357. shouldParseAsyncArrow() {
  6358. return this.match(14) || super.shouldParseAsyncArrow();
  6359. }
  6360. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  6361. var _jsx;
  6362. let state = null;
  6363. let jsx;
  6364. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  6365. state = this.state.clone();
  6366. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  6367. if (!jsx.error) return jsx.node;
  6368. const {
  6369. context
  6370. } = this.state;
  6371. const currentContext = context[context.length - 1];
  6372. if (currentContext === types$1.j_oTag || currentContext === types$1.j_expr) {
  6373. context.pop();
  6374. }
  6375. }
  6376. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  6377. var _jsx2, _jsx3;
  6378. state = state || this.state.clone();
  6379. let typeParameters;
  6380. const arrow = this.tryParse(abort => {
  6381. var _arrowExpression$extr;
  6382. typeParameters = this.flowParseTypeParameterDeclaration();
  6383. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  6384. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  6385. this.resetStartLocationFromNode(result, typeParameters);
  6386. return result;
  6387. });
  6388. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  6389. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  6390. if (expr.type !== "ArrowFunctionExpression") abort();
  6391. expr.typeParameters = typeParameters;
  6392. this.resetStartLocationFromNode(expr, typeParameters);
  6393. return arrowExpression;
  6394. }, state);
  6395. let arrowExpression = null;
  6396. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  6397. if (!arrow.error && !arrow.aborted) {
  6398. if (arrow.node.async) {
  6399. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  6400. at: typeParameters
  6401. });
  6402. }
  6403. return arrow.node;
  6404. }
  6405. arrowExpression = arrow.node;
  6406. }
  6407. if ((_jsx2 = jsx) != null && _jsx2.node) {
  6408. this.state = jsx.failState;
  6409. return jsx.node;
  6410. }
  6411. if (arrowExpression) {
  6412. this.state = arrow.failState;
  6413. return arrowExpression;
  6414. }
  6415. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  6416. if (arrow.thrown) throw arrow.error;
  6417. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  6418. at: typeParameters
  6419. });
  6420. }
  6421. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  6422. }
  6423. parseArrow(node) {
  6424. if (this.match(14)) {
  6425. const result = this.tryParse(() => {
  6426. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6427. this.state.noAnonFunctionType = true;
  6428. const typeNode = this.startNode();
  6429. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  6430. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6431. if (this.canInsertSemicolon()) this.unexpected();
  6432. if (!this.match(19)) this.unexpected();
  6433. return typeNode;
  6434. });
  6435. if (result.thrown) return null;
  6436. if (result.error) this.state = result.failState;
  6437. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  6438. }
  6439. return super.parseArrow(node);
  6440. }
  6441. shouldParseArrow(params) {
  6442. return this.match(14) || super.shouldParseArrow(params);
  6443. }
  6444. setArrowFunctionParameters(node, params) {
  6445. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  6446. node.params = params;
  6447. } else {
  6448. super.setArrowFunctionParameters(node, params);
  6449. }
  6450. }
  6451. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  6452. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  6453. return;
  6454. }
  6455. for (let i = 0; i < node.params.length; i++) {
  6456. if (this.isThisParam(node.params[i]) && i > 0) {
  6457. this.raise(FlowErrors.ThisParamMustBeFirst, {
  6458. at: node.params[i]
  6459. });
  6460. }
  6461. }
  6462. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  6463. }
  6464. parseParenAndDistinguishExpression(canBeArrow) {
  6465. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  6466. }
  6467. parseSubscripts(base, startLoc, noCalls) {
  6468. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  6469. this.next();
  6470. const node = this.startNodeAt(startLoc);
  6471. node.callee = base;
  6472. node.arguments = super.parseCallExpressionArguments(11, false);
  6473. base = this.finishNode(node, "CallExpression");
  6474. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  6475. const state = this.state.clone();
  6476. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  6477. if (!arrow.error && !arrow.aborted) return arrow.node;
  6478. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  6479. if (result.node && !result.error) return result.node;
  6480. if (arrow.node) {
  6481. this.state = arrow.failState;
  6482. return arrow.node;
  6483. }
  6484. if (result.node) {
  6485. this.state = result.failState;
  6486. return result.node;
  6487. }
  6488. throw arrow.error || result.error;
  6489. }
  6490. return super.parseSubscripts(base, startLoc, noCalls);
  6491. }
  6492. parseSubscript(base, startLoc, noCalls, subscriptState) {
  6493. if (this.match(18) && this.isLookaheadToken_lt()) {
  6494. subscriptState.optionalChainMember = true;
  6495. if (noCalls) {
  6496. subscriptState.stop = true;
  6497. return base;
  6498. }
  6499. this.next();
  6500. const node = this.startNodeAt(startLoc);
  6501. node.callee = base;
  6502. node.typeArguments = this.flowParseTypeParameterInstantiation();
  6503. this.expect(10);
  6504. node.arguments = this.parseCallExpressionArguments(11, false);
  6505. node.optional = true;
  6506. return this.finishCallExpression(node, true);
  6507. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  6508. const node = this.startNodeAt(startLoc);
  6509. node.callee = base;
  6510. const result = this.tryParse(() => {
  6511. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  6512. this.expect(10);
  6513. node.arguments = super.parseCallExpressionArguments(11, false);
  6514. if (subscriptState.optionalChainMember) {
  6515. node.optional = false;
  6516. }
  6517. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  6518. });
  6519. if (result.node) {
  6520. if (result.error) this.state = result.failState;
  6521. return result.node;
  6522. }
  6523. }
  6524. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  6525. }
  6526. parseNewCallee(node) {
  6527. super.parseNewCallee(node);
  6528. let targs = null;
  6529. if (this.shouldParseTypes() && this.match(47)) {
  6530. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  6531. }
  6532. node.typeArguments = targs;
  6533. }
  6534. parseAsyncArrowWithTypeParameters(startLoc) {
  6535. const node = this.startNodeAt(startLoc);
  6536. this.parseFunctionParams(node, false);
  6537. if (!this.parseArrow(node)) return;
  6538. return super.parseArrowExpression(node, undefined, true);
  6539. }
  6540. readToken_mult_modulo(code) {
  6541. const next = this.input.charCodeAt(this.state.pos + 1);
  6542. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  6543. this.state.hasFlowComment = false;
  6544. this.state.pos += 2;
  6545. this.nextToken();
  6546. return;
  6547. }
  6548. super.readToken_mult_modulo(code);
  6549. }
  6550. readToken_pipe_amp(code) {
  6551. const next = this.input.charCodeAt(this.state.pos + 1);
  6552. if (code === 124 && next === 125) {
  6553. this.finishOp(9, 2);
  6554. return;
  6555. }
  6556. super.readToken_pipe_amp(code);
  6557. }
  6558. parseTopLevel(file, program) {
  6559. const fileNode = super.parseTopLevel(file, program);
  6560. if (this.state.hasFlowComment) {
  6561. this.raise(FlowErrors.UnterminatedFlowComment, {
  6562. at: this.state.curPosition()
  6563. });
  6564. }
  6565. return fileNode;
  6566. }
  6567. skipBlockComment() {
  6568. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  6569. if (this.state.hasFlowComment) {
  6570. throw this.raise(FlowErrors.NestedFlowComment, {
  6571. at: this.state.startLoc
  6572. });
  6573. }
  6574. this.hasFlowCommentCompletion();
  6575. const commentSkip = this.skipFlowComment();
  6576. if (commentSkip) {
  6577. this.state.pos += commentSkip;
  6578. this.state.hasFlowComment = true;
  6579. }
  6580. return;
  6581. }
  6582. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  6583. }
  6584. skipFlowComment() {
  6585. const {
  6586. pos
  6587. } = this.state;
  6588. let shiftToFirstNonWhiteSpace = 2;
  6589. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  6590. shiftToFirstNonWhiteSpace++;
  6591. }
  6592. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  6593. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  6594. if (ch2 === 58 && ch3 === 58) {
  6595. return shiftToFirstNonWhiteSpace + 2;
  6596. }
  6597. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  6598. return shiftToFirstNonWhiteSpace + 12;
  6599. }
  6600. if (ch2 === 58 && ch3 !== 58) {
  6601. return shiftToFirstNonWhiteSpace;
  6602. }
  6603. return false;
  6604. }
  6605. hasFlowCommentCompletion() {
  6606. const end = this.input.indexOf("*/", this.state.pos);
  6607. if (end === -1) {
  6608. throw this.raise(Errors.UnterminatedComment, {
  6609. at: this.state.curPosition()
  6610. });
  6611. }
  6612. }
  6613. flowEnumErrorBooleanMemberNotInitialized(loc, {
  6614. enumName,
  6615. memberName
  6616. }) {
  6617. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  6618. at: loc,
  6619. memberName,
  6620. enumName
  6621. });
  6622. }
  6623. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  6624. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  6625. at: loc
  6626. }, enumContext));
  6627. }
  6628. flowEnumErrorNumberMemberNotInitialized(loc, {
  6629. enumName,
  6630. memberName
  6631. }) {
  6632. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  6633. at: loc,
  6634. enumName,
  6635. memberName
  6636. });
  6637. }
  6638. flowEnumErrorStringMemberInconsistentlyInitialized(node, {
  6639. enumName
  6640. }) {
  6641. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, {
  6642. at: node,
  6643. enumName
  6644. });
  6645. }
  6646. flowEnumMemberInit() {
  6647. const startLoc = this.state.startLoc;
  6648. const endOfInit = () => this.match(12) || this.match(8);
  6649. switch (this.state.type) {
  6650. case 134:
  6651. {
  6652. const literal = this.parseNumericLiteral(this.state.value);
  6653. if (endOfInit()) {
  6654. return {
  6655. type: "number",
  6656. loc: literal.loc.start,
  6657. value: literal
  6658. };
  6659. }
  6660. return {
  6661. type: "invalid",
  6662. loc: startLoc
  6663. };
  6664. }
  6665. case 133:
  6666. {
  6667. const literal = this.parseStringLiteral(this.state.value);
  6668. if (endOfInit()) {
  6669. return {
  6670. type: "string",
  6671. loc: literal.loc.start,
  6672. value: literal
  6673. };
  6674. }
  6675. return {
  6676. type: "invalid",
  6677. loc: startLoc
  6678. };
  6679. }
  6680. case 85:
  6681. case 86:
  6682. {
  6683. const literal = this.parseBooleanLiteral(this.match(85));
  6684. if (endOfInit()) {
  6685. return {
  6686. type: "boolean",
  6687. loc: literal.loc.start,
  6688. value: literal
  6689. };
  6690. }
  6691. return {
  6692. type: "invalid",
  6693. loc: startLoc
  6694. };
  6695. }
  6696. default:
  6697. return {
  6698. type: "invalid",
  6699. loc: startLoc
  6700. };
  6701. }
  6702. }
  6703. flowEnumMemberRaw() {
  6704. const loc = this.state.startLoc;
  6705. const id = this.parseIdentifier(true);
  6706. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6707. type: "none",
  6708. loc
  6709. };
  6710. return {
  6711. id,
  6712. init
  6713. };
  6714. }
  6715. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6716. const {
  6717. explicitType
  6718. } = context;
  6719. if (explicitType === null) {
  6720. return;
  6721. }
  6722. if (explicitType !== expectedType) {
  6723. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6724. }
  6725. }
  6726. flowEnumMembers({
  6727. enumName,
  6728. explicitType
  6729. }) {
  6730. const seenNames = new Set();
  6731. const members = {
  6732. booleanMembers: [],
  6733. numberMembers: [],
  6734. stringMembers: [],
  6735. defaultedMembers: []
  6736. };
  6737. let hasUnknownMembers = false;
  6738. while (!this.match(8)) {
  6739. if (this.eat(21)) {
  6740. hasUnknownMembers = true;
  6741. break;
  6742. }
  6743. const memberNode = this.startNode();
  6744. const {
  6745. id,
  6746. init
  6747. } = this.flowEnumMemberRaw();
  6748. const memberName = id.name;
  6749. if (memberName === "") {
  6750. continue;
  6751. }
  6752. if (/^[a-z]/.test(memberName)) {
  6753. this.raise(FlowErrors.EnumInvalidMemberName, {
  6754. at: id,
  6755. memberName,
  6756. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6757. enumName
  6758. });
  6759. }
  6760. if (seenNames.has(memberName)) {
  6761. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6762. at: id,
  6763. memberName,
  6764. enumName
  6765. });
  6766. }
  6767. seenNames.add(memberName);
  6768. const context = {
  6769. enumName,
  6770. explicitType,
  6771. memberName
  6772. };
  6773. memberNode.id = id;
  6774. switch (init.type) {
  6775. case "boolean":
  6776. {
  6777. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6778. memberNode.init = init.value;
  6779. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6780. break;
  6781. }
  6782. case "number":
  6783. {
  6784. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6785. memberNode.init = init.value;
  6786. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6787. break;
  6788. }
  6789. case "string":
  6790. {
  6791. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6792. memberNode.init = init.value;
  6793. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6794. break;
  6795. }
  6796. case "invalid":
  6797. {
  6798. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6799. }
  6800. case "none":
  6801. {
  6802. switch (explicitType) {
  6803. case "boolean":
  6804. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6805. break;
  6806. case "number":
  6807. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6808. break;
  6809. default:
  6810. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6811. }
  6812. }
  6813. }
  6814. if (!this.match(8)) {
  6815. this.expect(12);
  6816. }
  6817. }
  6818. return {
  6819. members,
  6820. hasUnknownMembers
  6821. };
  6822. }
  6823. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6824. enumName
  6825. }) {
  6826. if (initializedMembers.length === 0) {
  6827. return defaultedMembers;
  6828. } else if (defaultedMembers.length === 0) {
  6829. return initializedMembers;
  6830. } else if (defaultedMembers.length > initializedMembers.length) {
  6831. for (const member of initializedMembers) {
  6832. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6833. enumName
  6834. });
  6835. }
  6836. return defaultedMembers;
  6837. } else {
  6838. for (const member of defaultedMembers) {
  6839. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6840. enumName
  6841. });
  6842. }
  6843. return initializedMembers;
  6844. }
  6845. }
  6846. flowEnumParseExplicitType({
  6847. enumName
  6848. }) {
  6849. if (!this.eatContextual(102)) return null;
  6850. if (!tokenIsIdentifier(this.state.type)) {
  6851. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6852. at: this.state.startLoc,
  6853. enumName
  6854. });
  6855. }
  6856. const {
  6857. value
  6858. } = this.state;
  6859. this.next();
  6860. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6861. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6862. at: this.state.startLoc,
  6863. enumName,
  6864. invalidEnumType: value
  6865. });
  6866. }
  6867. return value;
  6868. }
  6869. flowEnumBody(node, id) {
  6870. const enumName = id.name;
  6871. const nameLoc = id.loc.start;
  6872. const explicitType = this.flowEnumParseExplicitType({
  6873. enumName
  6874. });
  6875. this.expect(5);
  6876. const {
  6877. members,
  6878. hasUnknownMembers
  6879. } = this.flowEnumMembers({
  6880. enumName,
  6881. explicitType
  6882. });
  6883. node.hasUnknownMembers = hasUnknownMembers;
  6884. switch (explicitType) {
  6885. case "boolean":
  6886. node.explicitType = true;
  6887. node.members = members.booleanMembers;
  6888. this.expect(8);
  6889. return this.finishNode(node, "EnumBooleanBody");
  6890. case "number":
  6891. node.explicitType = true;
  6892. node.members = members.numberMembers;
  6893. this.expect(8);
  6894. return this.finishNode(node, "EnumNumberBody");
  6895. case "string":
  6896. node.explicitType = true;
  6897. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6898. enumName
  6899. });
  6900. this.expect(8);
  6901. return this.finishNode(node, "EnumStringBody");
  6902. case "symbol":
  6903. node.members = members.defaultedMembers;
  6904. this.expect(8);
  6905. return this.finishNode(node, "EnumSymbolBody");
  6906. default:
  6907. {
  6908. const empty = () => {
  6909. node.members = [];
  6910. this.expect(8);
  6911. return this.finishNode(node, "EnumStringBody");
  6912. };
  6913. node.explicitType = false;
  6914. const boolsLen = members.booleanMembers.length;
  6915. const numsLen = members.numberMembers.length;
  6916. const strsLen = members.stringMembers.length;
  6917. const defaultedLen = members.defaultedMembers.length;
  6918. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6919. return empty();
  6920. } else if (!boolsLen && !numsLen) {
  6921. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6922. enumName
  6923. });
  6924. this.expect(8);
  6925. return this.finishNode(node, "EnumStringBody");
  6926. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6927. for (const member of members.defaultedMembers) {
  6928. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6929. enumName,
  6930. memberName: member.id.name
  6931. });
  6932. }
  6933. node.members = members.booleanMembers;
  6934. this.expect(8);
  6935. return this.finishNode(node, "EnumBooleanBody");
  6936. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6937. for (const member of members.defaultedMembers) {
  6938. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6939. enumName,
  6940. memberName: member.id.name
  6941. });
  6942. }
  6943. node.members = members.numberMembers;
  6944. this.expect(8);
  6945. return this.finishNode(node, "EnumNumberBody");
  6946. } else {
  6947. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6948. at: nameLoc,
  6949. enumName
  6950. });
  6951. return empty();
  6952. }
  6953. }
  6954. }
  6955. }
  6956. flowParseEnumDeclaration(node) {
  6957. const id = this.parseIdentifier();
  6958. node.id = id;
  6959. node.body = this.flowEnumBody(this.startNode(), id);
  6960. return this.finishNode(node, "EnumDeclaration");
  6961. }
  6962. isLookaheadToken_lt() {
  6963. const next = this.nextTokenStart();
  6964. if (this.input.charCodeAt(next) === 60) {
  6965. const afterNext = this.input.charCodeAt(next + 1);
  6966. return afterNext !== 60 && afterNext !== 61;
  6967. }
  6968. return false;
  6969. }
  6970. maybeUnwrapTypeCastExpression(node) {
  6971. return node.type === "TypeCastExpression" ? node.expression : node;
  6972. }
  6973. };
  6974. const entities = {
  6975. __proto__: null,
  6976. quot: "\u0022",
  6977. amp: "&",
  6978. apos: "\u0027",
  6979. lt: "<",
  6980. gt: ">",
  6981. nbsp: "\u00A0",
  6982. iexcl: "\u00A1",
  6983. cent: "\u00A2",
  6984. pound: "\u00A3",
  6985. curren: "\u00A4",
  6986. yen: "\u00A5",
  6987. brvbar: "\u00A6",
  6988. sect: "\u00A7",
  6989. uml: "\u00A8",
  6990. copy: "\u00A9",
  6991. ordf: "\u00AA",
  6992. laquo: "\u00AB",
  6993. not: "\u00AC",
  6994. shy: "\u00AD",
  6995. reg: "\u00AE",
  6996. macr: "\u00AF",
  6997. deg: "\u00B0",
  6998. plusmn: "\u00B1",
  6999. sup2: "\u00B2",
  7000. sup3: "\u00B3",
  7001. acute: "\u00B4",
  7002. micro: "\u00B5",
  7003. para: "\u00B6",
  7004. middot: "\u00B7",
  7005. cedil: "\u00B8",
  7006. sup1: "\u00B9",
  7007. ordm: "\u00BA",
  7008. raquo: "\u00BB",
  7009. frac14: "\u00BC",
  7010. frac12: "\u00BD",
  7011. frac34: "\u00BE",
  7012. iquest: "\u00BF",
  7013. Agrave: "\u00C0",
  7014. Aacute: "\u00C1",
  7015. Acirc: "\u00C2",
  7016. Atilde: "\u00C3",
  7017. Auml: "\u00C4",
  7018. Aring: "\u00C5",
  7019. AElig: "\u00C6",
  7020. Ccedil: "\u00C7",
  7021. Egrave: "\u00C8",
  7022. Eacute: "\u00C9",
  7023. Ecirc: "\u00CA",
  7024. Euml: "\u00CB",
  7025. Igrave: "\u00CC",
  7026. Iacute: "\u00CD",
  7027. Icirc: "\u00CE",
  7028. Iuml: "\u00CF",
  7029. ETH: "\u00D0",
  7030. Ntilde: "\u00D1",
  7031. Ograve: "\u00D2",
  7032. Oacute: "\u00D3",
  7033. Ocirc: "\u00D4",
  7034. Otilde: "\u00D5",
  7035. Ouml: "\u00D6",
  7036. times: "\u00D7",
  7037. Oslash: "\u00D8",
  7038. Ugrave: "\u00D9",
  7039. Uacute: "\u00DA",
  7040. Ucirc: "\u00DB",
  7041. Uuml: "\u00DC",
  7042. Yacute: "\u00DD",
  7043. THORN: "\u00DE",
  7044. szlig: "\u00DF",
  7045. agrave: "\u00E0",
  7046. aacute: "\u00E1",
  7047. acirc: "\u00E2",
  7048. atilde: "\u00E3",
  7049. auml: "\u00E4",
  7050. aring: "\u00E5",
  7051. aelig: "\u00E6",
  7052. ccedil: "\u00E7",
  7053. egrave: "\u00E8",
  7054. eacute: "\u00E9",
  7055. ecirc: "\u00EA",
  7056. euml: "\u00EB",
  7057. igrave: "\u00EC",
  7058. iacute: "\u00ED",
  7059. icirc: "\u00EE",
  7060. iuml: "\u00EF",
  7061. eth: "\u00F0",
  7062. ntilde: "\u00F1",
  7063. ograve: "\u00F2",
  7064. oacute: "\u00F3",
  7065. ocirc: "\u00F4",
  7066. otilde: "\u00F5",
  7067. ouml: "\u00F6",
  7068. divide: "\u00F7",
  7069. oslash: "\u00F8",
  7070. ugrave: "\u00F9",
  7071. uacute: "\u00FA",
  7072. ucirc: "\u00FB",
  7073. uuml: "\u00FC",
  7074. yacute: "\u00FD",
  7075. thorn: "\u00FE",
  7076. yuml: "\u00FF",
  7077. OElig: "\u0152",
  7078. oelig: "\u0153",
  7079. Scaron: "\u0160",
  7080. scaron: "\u0161",
  7081. Yuml: "\u0178",
  7082. fnof: "\u0192",
  7083. circ: "\u02C6",
  7084. tilde: "\u02DC",
  7085. Alpha: "\u0391",
  7086. Beta: "\u0392",
  7087. Gamma: "\u0393",
  7088. Delta: "\u0394",
  7089. Epsilon: "\u0395",
  7090. Zeta: "\u0396",
  7091. Eta: "\u0397",
  7092. Theta: "\u0398",
  7093. Iota: "\u0399",
  7094. Kappa: "\u039A",
  7095. Lambda: "\u039B",
  7096. Mu: "\u039C",
  7097. Nu: "\u039D",
  7098. Xi: "\u039E",
  7099. Omicron: "\u039F",
  7100. Pi: "\u03A0",
  7101. Rho: "\u03A1",
  7102. Sigma: "\u03A3",
  7103. Tau: "\u03A4",
  7104. Upsilon: "\u03A5",
  7105. Phi: "\u03A6",
  7106. Chi: "\u03A7",
  7107. Psi: "\u03A8",
  7108. Omega: "\u03A9",
  7109. alpha: "\u03B1",
  7110. beta: "\u03B2",
  7111. gamma: "\u03B3",
  7112. delta: "\u03B4",
  7113. epsilon: "\u03B5",
  7114. zeta: "\u03B6",
  7115. eta: "\u03B7",
  7116. theta: "\u03B8",
  7117. iota: "\u03B9",
  7118. kappa: "\u03BA",
  7119. lambda: "\u03BB",
  7120. mu: "\u03BC",
  7121. nu: "\u03BD",
  7122. xi: "\u03BE",
  7123. omicron: "\u03BF",
  7124. pi: "\u03C0",
  7125. rho: "\u03C1",
  7126. sigmaf: "\u03C2",
  7127. sigma: "\u03C3",
  7128. tau: "\u03C4",
  7129. upsilon: "\u03C5",
  7130. phi: "\u03C6",
  7131. chi: "\u03C7",
  7132. psi: "\u03C8",
  7133. omega: "\u03C9",
  7134. thetasym: "\u03D1",
  7135. upsih: "\u03D2",
  7136. piv: "\u03D6",
  7137. ensp: "\u2002",
  7138. emsp: "\u2003",
  7139. thinsp: "\u2009",
  7140. zwnj: "\u200C",
  7141. zwj: "\u200D",
  7142. lrm: "\u200E",
  7143. rlm: "\u200F",
  7144. ndash: "\u2013",
  7145. mdash: "\u2014",
  7146. lsquo: "\u2018",
  7147. rsquo: "\u2019",
  7148. sbquo: "\u201A",
  7149. ldquo: "\u201C",
  7150. rdquo: "\u201D",
  7151. bdquo: "\u201E",
  7152. dagger: "\u2020",
  7153. Dagger: "\u2021",
  7154. bull: "\u2022",
  7155. hellip: "\u2026",
  7156. permil: "\u2030",
  7157. prime: "\u2032",
  7158. Prime: "\u2033",
  7159. lsaquo: "\u2039",
  7160. rsaquo: "\u203A",
  7161. oline: "\u203E",
  7162. frasl: "\u2044",
  7163. euro: "\u20AC",
  7164. image: "\u2111",
  7165. weierp: "\u2118",
  7166. real: "\u211C",
  7167. trade: "\u2122",
  7168. alefsym: "\u2135",
  7169. larr: "\u2190",
  7170. uarr: "\u2191",
  7171. rarr: "\u2192",
  7172. darr: "\u2193",
  7173. harr: "\u2194",
  7174. crarr: "\u21B5",
  7175. lArr: "\u21D0",
  7176. uArr: "\u21D1",
  7177. rArr: "\u21D2",
  7178. dArr: "\u21D3",
  7179. hArr: "\u21D4",
  7180. forall: "\u2200",
  7181. part: "\u2202",
  7182. exist: "\u2203",
  7183. empty: "\u2205",
  7184. nabla: "\u2207",
  7185. isin: "\u2208",
  7186. notin: "\u2209",
  7187. ni: "\u220B",
  7188. prod: "\u220F",
  7189. sum: "\u2211",
  7190. minus: "\u2212",
  7191. lowast: "\u2217",
  7192. radic: "\u221A",
  7193. prop: "\u221D",
  7194. infin: "\u221E",
  7195. ang: "\u2220",
  7196. and: "\u2227",
  7197. or: "\u2228",
  7198. cap: "\u2229",
  7199. cup: "\u222A",
  7200. int: "\u222B",
  7201. there4: "\u2234",
  7202. sim: "\u223C",
  7203. cong: "\u2245",
  7204. asymp: "\u2248",
  7205. ne: "\u2260",
  7206. equiv: "\u2261",
  7207. le: "\u2264",
  7208. ge: "\u2265",
  7209. sub: "\u2282",
  7210. sup: "\u2283",
  7211. nsub: "\u2284",
  7212. sube: "\u2286",
  7213. supe: "\u2287",
  7214. oplus: "\u2295",
  7215. otimes: "\u2297",
  7216. perp: "\u22A5",
  7217. sdot: "\u22C5",
  7218. lceil: "\u2308",
  7219. rceil: "\u2309",
  7220. lfloor: "\u230A",
  7221. rfloor: "\u230B",
  7222. lang: "\u2329",
  7223. rang: "\u232A",
  7224. loz: "\u25CA",
  7225. spades: "\u2660",
  7226. clubs: "\u2663",
  7227. hearts: "\u2665",
  7228. diams: "\u2666"
  7229. };
  7230. const JsxErrors = ParseErrorEnum`jsx`({
  7231. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  7232. MissingClosingTagElement: ({
  7233. openingTagName
  7234. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  7235. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  7236. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  7237. UnexpectedToken: ({
  7238. unexpected,
  7239. HTMLEntity
  7240. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  7241. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  7242. UnterminatedJsxContent: "Unterminated JSX contents.",
  7243. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  7244. });
  7245. function isFragment(object) {
  7246. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  7247. }
  7248. function getQualifiedJSXName(object) {
  7249. if (object.type === "JSXIdentifier") {
  7250. return object.name;
  7251. }
  7252. if (object.type === "JSXNamespacedName") {
  7253. return object.namespace.name + ":" + object.name.name;
  7254. }
  7255. if (object.type === "JSXMemberExpression") {
  7256. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  7257. }
  7258. throw new Error("Node had unexpected type: " + object.type);
  7259. }
  7260. var jsx = superClass => class JSXParserMixin extends superClass {
  7261. jsxReadToken() {
  7262. let out = "";
  7263. let chunkStart = this.state.pos;
  7264. for (;;) {
  7265. if (this.state.pos >= this.length) {
  7266. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  7267. at: this.state.startLoc
  7268. });
  7269. }
  7270. const ch = this.input.charCodeAt(this.state.pos);
  7271. switch (ch) {
  7272. case 60:
  7273. case 123:
  7274. if (this.state.pos === this.state.start) {
  7275. if (ch === 60 && this.state.canStartJSXElement) {
  7276. ++this.state.pos;
  7277. this.finishToken(142);
  7278. } else {
  7279. super.getTokenFromCode(ch);
  7280. }
  7281. return;
  7282. }
  7283. out += this.input.slice(chunkStart, this.state.pos);
  7284. this.finishToken(141, out);
  7285. return;
  7286. case 38:
  7287. out += this.input.slice(chunkStart, this.state.pos);
  7288. out += this.jsxReadEntity();
  7289. chunkStart = this.state.pos;
  7290. break;
  7291. case 62:
  7292. case 125:
  7293. default:
  7294. if (isNewLine(ch)) {
  7295. out += this.input.slice(chunkStart, this.state.pos);
  7296. out += this.jsxReadNewLine(true);
  7297. chunkStart = this.state.pos;
  7298. } else {
  7299. ++this.state.pos;
  7300. }
  7301. }
  7302. }
  7303. }
  7304. jsxReadNewLine(normalizeCRLF) {
  7305. const ch = this.input.charCodeAt(this.state.pos);
  7306. let out;
  7307. ++this.state.pos;
  7308. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  7309. ++this.state.pos;
  7310. out = normalizeCRLF ? "\n" : "\r\n";
  7311. } else {
  7312. out = String.fromCharCode(ch);
  7313. }
  7314. ++this.state.curLine;
  7315. this.state.lineStart = this.state.pos;
  7316. return out;
  7317. }
  7318. jsxReadString(quote) {
  7319. let out = "";
  7320. let chunkStart = ++this.state.pos;
  7321. for (;;) {
  7322. if (this.state.pos >= this.length) {
  7323. throw this.raise(Errors.UnterminatedString, {
  7324. at: this.state.startLoc
  7325. });
  7326. }
  7327. const ch = this.input.charCodeAt(this.state.pos);
  7328. if (ch === quote) break;
  7329. if (ch === 38) {
  7330. out += this.input.slice(chunkStart, this.state.pos);
  7331. out += this.jsxReadEntity();
  7332. chunkStart = this.state.pos;
  7333. } else if (isNewLine(ch)) {
  7334. out += this.input.slice(chunkStart, this.state.pos);
  7335. out += this.jsxReadNewLine(false);
  7336. chunkStart = this.state.pos;
  7337. } else {
  7338. ++this.state.pos;
  7339. }
  7340. }
  7341. out += this.input.slice(chunkStart, this.state.pos++);
  7342. this.finishToken(133, out);
  7343. }
  7344. jsxReadEntity() {
  7345. const startPos = ++this.state.pos;
  7346. if (this.codePointAtPos(this.state.pos) === 35) {
  7347. ++this.state.pos;
  7348. let radix = 10;
  7349. if (this.codePointAtPos(this.state.pos) === 120) {
  7350. radix = 16;
  7351. ++this.state.pos;
  7352. }
  7353. const codePoint = this.readInt(radix, undefined, false, "bail");
  7354. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  7355. ++this.state.pos;
  7356. return String.fromCodePoint(codePoint);
  7357. }
  7358. } else {
  7359. let count = 0;
  7360. let semi = false;
  7361. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  7362. ++this.state.pos;
  7363. }
  7364. if (semi) {
  7365. const desc = this.input.slice(startPos, this.state.pos);
  7366. const entity = entities[desc];
  7367. ++this.state.pos;
  7368. if (entity) {
  7369. return entity;
  7370. }
  7371. }
  7372. }
  7373. this.state.pos = startPos;
  7374. return "&";
  7375. }
  7376. jsxReadWord() {
  7377. let ch;
  7378. const start = this.state.pos;
  7379. do {
  7380. ch = this.input.charCodeAt(++this.state.pos);
  7381. } while (isIdentifierChar(ch) || ch === 45);
  7382. this.finishToken(140, this.input.slice(start, this.state.pos));
  7383. }
  7384. jsxParseIdentifier() {
  7385. const node = this.startNode();
  7386. if (this.match(140)) {
  7387. node.name = this.state.value;
  7388. } else if (tokenIsKeyword(this.state.type)) {
  7389. node.name = tokenLabelName(this.state.type);
  7390. } else {
  7391. this.unexpected();
  7392. }
  7393. this.next();
  7394. return this.finishNode(node, "JSXIdentifier");
  7395. }
  7396. jsxParseNamespacedName() {
  7397. const startLoc = this.state.startLoc;
  7398. const name = this.jsxParseIdentifier();
  7399. if (!this.eat(14)) return name;
  7400. const node = this.startNodeAt(startLoc);
  7401. node.namespace = name;
  7402. node.name = this.jsxParseIdentifier();
  7403. return this.finishNode(node, "JSXNamespacedName");
  7404. }
  7405. jsxParseElementName() {
  7406. const startLoc = this.state.startLoc;
  7407. let node = this.jsxParseNamespacedName();
  7408. if (node.type === "JSXNamespacedName") {
  7409. return node;
  7410. }
  7411. while (this.eat(16)) {
  7412. const newNode = this.startNodeAt(startLoc);
  7413. newNode.object = node;
  7414. newNode.property = this.jsxParseIdentifier();
  7415. node = this.finishNode(newNode, "JSXMemberExpression");
  7416. }
  7417. return node;
  7418. }
  7419. jsxParseAttributeValue() {
  7420. let node;
  7421. switch (this.state.type) {
  7422. case 5:
  7423. node = this.startNode();
  7424. this.setContext(types$1.brace);
  7425. this.next();
  7426. node = this.jsxParseExpressionContainer(node, types$1.j_oTag);
  7427. if (node.expression.type === "JSXEmptyExpression") {
  7428. this.raise(JsxErrors.AttributeIsEmpty, {
  7429. at: node
  7430. });
  7431. }
  7432. return node;
  7433. case 142:
  7434. case 133:
  7435. return this.parseExprAtom();
  7436. default:
  7437. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  7438. at: this.state.startLoc
  7439. });
  7440. }
  7441. }
  7442. jsxParseEmptyExpression() {
  7443. const node = this.startNodeAt(this.state.lastTokEndLoc);
  7444. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  7445. }
  7446. jsxParseSpreadChild(node) {
  7447. this.next();
  7448. node.expression = this.parseExpression();
  7449. this.setContext(types$1.j_expr);
  7450. this.state.canStartJSXElement = true;
  7451. this.expect(8);
  7452. return this.finishNode(node, "JSXSpreadChild");
  7453. }
  7454. jsxParseExpressionContainer(node, previousContext) {
  7455. if (this.match(8)) {
  7456. node.expression = this.jsxParseEmptyExpression();
  7457. } else {
  7458. const expression = this.parseExpression();
  7459. node.expression = expression;
  7460. }
  7461. this.setContext(previousContext);
  7462. this.state.canStartJSXElement = true;
  7463. this.expect(8);
  7464. return this.finishNode(node, "JSXExpressionContainer");
  7465. }
  7466. jsxParseAttribute() {
  7467. const node = this.startNode();
  7468. if (this.match(5)) {
  7469. this.setContext(types$1.brace);
  7470. this.next();
  7471. this.expect(21);
  7472. node.argument = this.parseMaybeAssignAllowIn();
  7473. this.setContext(types$1.j_oTag);
  7474. this.state.canStartJSXElement = true;
  7475. this.expect(8);
  7476. return this.finishNode(node, "JSXSpreadAttribute");
  7477. }
  7478. node.name = this.jsxParseNamespacedName();
  7479. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  7480. return this.finishNode(node, "JSXAttribute");
  7481. }
  7482. jsxParseOpeningElementAt(startLoc) {
  7483. const node = this.startNodeAt(startLoc);
  7484. if (this.eat(143)) {
  7485. return this.finishNode(node, "JSXOpeningFragment");
  7486. }
  7487. node.name = this.jsxParseElementName();
  7488. return this.jsxParseOpeningElementAfterName(node);
  7489. }
  7490. jsxParseOpeningElementAfterName(node) {
  7491. const attributes = [];
  7492. while (!this.match(56) && !this.match(143)) {
  7493. attributes.push(this.jsxParseAttribute());
  7494. }
  7495. node.attributes = attributes;
  7496. node.selfClosing = this.eat(56);
  7497. this.expect(143);
  7498. return this.finishNode(node, "JSXOpeningElement");
  7499. }
  7500. jsxParseClosingElementAt(startLoc) {
  7501. const node = this.startNodeAt(startLoc);
  7502. if (this.eat(143)) {
  7503. return this.finishNode(node, "JSXClosingFragment");
  7504. }
  7505. node.name = this.jsxParseElementName();
  7506. this.expect(143);
  7507. return this.finishNode(node, "JSXClosingElement");
  7508. }
  7509. jsxParseElementAt(startLoc) {
  7510. const node = this.startNodeAt(startLoc);
  7511. const children = [];
  7512. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  7513. let closingElement = null;
  7514. if (!openingElement.selfClosing) {
  7515. contents: for (;;) {
  7516. switch (this.state.type) {
  7517. case 142:
  7518. startLoc = this.state.startLoc;
  7519. this.next();
  7520. if (this.eat(56)) {
  7521. closingElement = this.jsxParseClosingElementAt(startLoc);
  7522. break contents;
  7523. }
  7524. children.push(this.jsxParseElementAt(startLoc));
  7525. break;
  7526. case 141:
  7527. children.push(this.parseExprAtom());
  7528. break;
  7529. case 5:
  7530. {
  7531. const node = this.startNode();
  7532. this.setContext(types$1.brace);
  7533. this.next();
  7534. if (this.match(21)) {
  7535. children.push(this.jsxParseSpreadChild(node));
  7536. } else {
  7537. children.push(this.jsxParseExpressionContainer(node, types$1.j_expr));
  7538. }
  7539. break;
  7540. }
  7541. default:
  7542. this.unexpected();
  7543. }
  7544. }
  7545. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  7546. this.raise(JsxErrors.MissingClosingTagFragment, {
  7547. at: closingElement
  7548. });
  7549. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  7550. this.raise(JsxErrors.MissingClosingTagElement, {
  7551. at: closingElement,
  7552. openingTagName: getQualifiedJSXName(openingElement.name)
  7553. });
  7554. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  7555. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  7556. this.raise(JsxErrors.MissingClosingTagElement, {
  7557. at: closingElement,
  7558. openingTagName: getQualifiedJSXName(openingElement.name)
  7559. });
  7560. }
  7561. }
  7562. }
  7563. if (isFragment(openingElement)) {
  7564. node.openingFragment = openingElement;
  7565. node.closingFragment = closingElement;
  7566. } else {
  7567. node.openingElement = openingElement;
  7568. node.closingElement = closingElement;
  7569. }
  7570. node.children = children;
  7571. if (this.match(47)) {
  7572. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  7573. at: this.state.startLoc
  7574. });
  7575. }
  7576. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  7577. }
  7578. jsxParseElement() {
  7579. const startLoc = this.state.startLoc;
  7580. this.next();
  7581. return this.jsxParseElementAt(startLoc);
  7582. }
  7583. setContext(newContext) {
  7584. const {
  7585. context
  7586. } = this.state;
  7587. context[context.length - 1] = newContext;
  7588. }
  7589. parseExprAtom(refExpressionErrors) {
  7590. if (this.match(141)) {
  7591. return this.parseLiteral(this.state.value, "JSXText");
  7592. } else if (this.match(142)) {
  7593. return this.jsxParseElement();
  7594. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  7595. this.replaceToken(142);
  7596. return this.jsxParseElement();
  7597. } else {
  7598. return super.parseExprAtom(refExpressionErrors);
  7599. }
  7600. }
  7601. skipSpace() {
  7602. const curContext = this.curContext();
  7603. if (!curContext.preserveSpace) super.skipSpace();
  7604. }
  7605. getTokenFromCode(code) {
  7606. const context = this.curContext();
  7607. if (context === types$1.j_expr) {
  7608. this.jsxReadToken();
  7609. return;
  7610. }
  7611. if (context === types$1.j_oTag || context === types$1.j_cTag) {
  7612. if (isIdentifierStart(code)) {
  7613. this.jsxReadWord();
  7614. return;
  7615. }
  7616. if (code === 62) {
  7617. ++this.state.pos;
  7618. this.finishToken(143);
  7619. return;
  7620. }
  7621. if ((code === 34 || code === 39) && context === types$1.j_oTag) {
  7622. this.jsxReadString(code);
  7623. return;
  7624. }
  7625. }
  7626. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  7627. ++this.state.pos;
  7628. this.finishToken(142);
  7629. return;
  7630. }
  7631. super.getTokenFromCode(code);
  7632. }
  7633. updateContext(prevType) {
  7634. const {
  7635. context,
  7636. type
  7637. } = this.state;
  7638. if (type === 56 && prevType === 142) {
  7639. context.splice(-2, 2, types$1.j_cTag);
  7640. this.state.canStartJSXElement = false;
  7641. } else if (type === 142) {
  7642. context.push(types$1.j_oTag);
  7643. } else if (type === 143) {
  7644. const out = context[context.length - 1];
  7645. if (out === types$1.j_oTag && prevType === 56 || out === types$1.j_cTag) {
  7646. context.pop();
  7647. this.state.canStartJSXElement = context[context.length - 1] === types$1.j_expr;
  7648. } else {
  7649. this.setContext(types$1.j_expr);
  7650. this.state.canStartJSXElement = true;
  7651. }
  7652. } else {
  7653. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  7654. }
  7655. }
  7656. };
  7657. class TypeScriptScope extends Scope {
  7658. constructor(...args) {
  7659. super(...args);
  7660. this.types = new Set();
  7661. this.enums = new Set();
  7662. this.constEnums = new Set();
  7663. this.classes = new Set();
  7664. this.exportOnlyBindings = new Set();
  7665. }
  7666. }
  7667. class TypeScriptScopeHandler extends ScopeHandler {
  7668. constructor(...args) {
  7669. super(...args);
  7670. this.importsStack = [];
  7671. }
  7672. createScope(flags) {
  7673. this.importsStack.push(new Set());
  7674. return new TypeScriptScope(flags);
  7675. }
  7676. enter(flags) {
  7677. if (flags == 256) {
  7678. this.importsStack.push(new Set());
  7679. }
  7680. super.enter(flags);
  7681. }
  7682. exit() {
  7683. const flags = super.exit();
  7684. if (flags == 256) {
  7685. this.importsStack.pop();
  7686. }
  7687. return flags;
  7688. }
  7689. hasImport(name, allowShadow) {
  7690. const len = this.importsStack.length;
  7691. if (this.importsStack[len - 1].has(name)) {
  7692. return true;
  7693. }
  7694. if (!allowShadow && len > 1) {
  7695. for (let i = 0; i < len - 1; i++) {
  7696. if (this.importsStack[i].has(name)) return true;
  7697. }
  7698. }
  7699. return false;
  7700. }
  7701. declareName(name, bindingType, loc) {
  7702. if (bindingType & 4096) {
  7703. if (this.hasImport(name, true)) {
  7704. this.parser.raise(Errors.VarRedeclaration, {
  7705. at: loc,
  7706. identifierName: name
  7707. });
  7708. }
  7709. this.importsStack[this.importsStack.length - 1].add(name);
  7710. return;
  7711. }
  7712. const scope = this.currentScope();
  7713. if (bindingType & 1024) {
  7714. this.maybeExportDefined(scope, name);
  7715. scope.exportOnlyBindings.add(name);
  7716. return;
  7717. }
  7718. super.declareName(name, bindingType, loc);
  7719. if (bindingType & 2) {
  7720. if (!(bindingType & 1)) {
  7721. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7722. this.maybeExportDefined(scope, name);
  7723. }
  7724. scope.types.add(name);
  7725. }
  7726. if (bindingType & 256) scope.enums.add(name);
  7727. if (bindingType & 512) {
  7728. scope.constEnums.add(name);
  7729. }
  7730. if (bindingType & 128) scope.classes.add(name);
  7731. }
  7732. isRedeclaredInScope(scope, name, bindingType) {
  7733. if (scope.enums.has(name)) {
  7734. if (bindingType & 256) {
  7735. const isConst = !!(bindingType & 512);
  7736. const wasConst = scope.constEnums.has(name);
  7737. return isConst !== wasConst;
  7738. }
  7739. return true;
  7740. }
  7741. if (bindingType & 128 && scope.classes.has(name)) {
  7742. if (scope.lexical.has(name)) {
  7743. return !!(bindingType & 1);
  7744. } else {
  7745. return false;
  7746. }
  7747. }
  7748. if (bindingType & 2 && scope.types.has(name)) {
  7749. return true;
  7750. }
  7751. return super.isRedeclaredInScope(scope, name, bindingType);
  7752. }
  7753. checkLocalExport(id) {
  7754. const {
  7755. name
  7756. } = id;
  7757. if (this.hasImport(name)) return;
  7758. const len = this.scopeStack.length;
  7759. for (let i = len - 1; i >= 0; i--) {
  7760. const scope = this.scopeStack[i];
  7761. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7762. }
  7763. super.checkLocalExport(id);
  7764. }
  7765. }
  7766. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7767. const unwrapParenthesizedExpression = node => {
  7768. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7769. };
  7770. class LValParser extends NodeUtils {
  7771. toAssignable(node, isLHS = false) {
  7772. var _node$extra, _node$extra3;
  7773. let parenthesized = undefined;
  7774. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7775. parenthesized = unwrapParenthesizedExpression(node);
  7776. if (isLHS) {
  7777. if (parenthesized.type === "Identifier") {
  7778. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
  7779. at: node
  7780. });
  7781. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7782. this.raise(Errors.InvalidParenthesizedAssignment, {
  7783. at: node
  7784. });
  7785. }
  7786. } else {
  7787. this.raise(Errors.InvalidParenthesizedAssignment, {
  7788. at: node
  7789. });
  7790. }
  7791. }
  7792. switch (node.type) {
  7793. case "Identifier":
  7794. case "ObjectPattern":
  7795. case "ArrayPattern":
  7796. case "AssignmentPattern":
  7797. case "RestElement":
  7798. break;
  7799. case "ObjectExpression":
  7800. node.type = "ObjectPattern";
  7801. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7802. var _node$extra2;
  7803. const prop = node.properties[i];
  7804. const isLast = i === last;
  7805. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7806. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7807. this.raise(Errors.RestTrailingComma, {
  7808. at: node.extra.trailingCommaLoc
  7809. });
  7810. }
  7811. }
  7812. break;
  7813. case "ObjectProperty":
  7814. {
  7815. const {
  7816. key,
  7817. value
  7818. } = node;
  7819. if (this.isPrivateName(key)) {
  7820. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7821. }
  7822. this.toAssignable(value, isLHS);
  7823. break;
  7824. }
  7825. case "SpreadElement":
  7826. {
  7827. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7828. }
  7829. case "ArrayExpression":
  7830. node.type = "ArrayPattern";
  7831. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7832. break;
  7833. case "AssignmentExpression":
  7834. if (node.operator !== "=") {
  7835. this.raise(Errors.MissingEqInAssignment, {
  7836. at: node.left.loc.end
  7837. });
  7838. }
  7839. node.type = "AssignmentPattern";
  7840. delete node.operator;
  7841. this.toAssignable(node.left, isLHS);
  7842. break;
  7843. case "ParenthesizedExpression":
  7844. this.toAssignable(parenthesized, isLHS);
  7845. break;
  7846. }
  7847. }
  7848. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7849. if (prop.type === "ObjectMethod") {
  7850. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  7851. at: prop.key
  7852. });
  7853. } else if (prop.type === "SpreadElement") {
  7854. prop.type = "RestElement";
  7855. const arg = prop.argument;
  7856. this.checkToRestConversion(arg, false);
  7857. this.toAssignable(arg, isLHS);
  7858. if (!isLast) {
  7859. this.raise(Errors.RestTrailingComma, {
  7860. at: prop
  7861. });
  7862. }
  7863. } else {
  7864. this.toAssignable(prop, isLHS);
  7865. }
  7866. }
  7867. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7868. const end = exprList.length - 1;
  7869. for (let i = 0; i <= end; i++) {
  7870. const elt = exprList[i];
  7871. if (!elt) continue;
  7872. if (elt.type === "SpreadElement") {
  7873. elt.type = "RestElement";
  7874. const arg = elt.argument;
  7875. this.checkToRestConversion(arg, true);
  7876. this.toAssignable(arg, isLHS);
  7877. } else {
  7878. this.toAssignable(elt, isLHS);
  7879. }
  7880. if (elt.type === "RestElement") {
  7881. if (i < end) {
  7882. this.raise(Errors.RestTrailingComma, {
  7883. at: elt
  7884. });
  7885. } else if (trailingCommaLoc) {
  7886. this.raise(Errors.RestTrailingComma, {
  7887. at: trailingCommaLoc
  7888. });
  7889. }
  7890. }
  7891. }
  7892. }
  7893. isAssignable(node, isBinding) {
  7894. switch (node.type) {
  7895. case "Identifier":
  7896. case "ObjectPattern":
  7897. case "ArrayPattern":
  7898. case "AssignmentPattern":
  7899. case "RestElement":
  7900. return true;
  7901. case "ObjectExpression":
  7902. {
  7903. const last = node.properties.length - 1;
  7904. return node.properties.every((prop, i) => {
  7905. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7906. });
  7907. }
  7908. case "ObjectProperty":
  7909. return this.isAssignable(node.value);
  7910. case "SpreadElement":
  7911. return this.isAssignable(node.argument);
  7912. case "ArrayExpression":
  7913. return node.elements.every(element => element === null || this.isAssignable(element));
  7914. case "AssignmentExpression":
  7915. return node.operator === "=";
  7916. case "ParenthesizedExpression":
  7917. return this.isAssignable(node.expression);
  7918. case "MemberExpression":
  7919. case "OptionalMemberExpression":
  7920. return !isBinding;
  7921. default:
  7922. return false;
  7923. }
  7924. }
  7925. toReferencedList(exprList, isParenthesizedExpr) {
  7926. return exprList;
  7927. }
  7928. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7929. this.toReferencedList(exprList, isParenthesizedExpr);
  7930. for (const expr of exprList) {
  7931. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7932. this.toReferencedListDeep(expr.elements);
  7933. }
  7934. }
  7935. }
  7936. parseSpread(refExpressionErrors) {
  7937. const node = this.startNode();
  7938. this.next();
  7939. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7940. return this.finishNode(node, "SpreadElement");
  7941. }
  7942. parseRestBinding() {
  7943. const node = this.startNode();
  7944. this.next();
  7945. node.argument = this.parseBindingAtom();
  7946. return this.finishNode(node, "RestElement");
  7947. }
  7948. parseBindingAtom() {
  7949. switch (this.state.type) {
  7950. case 0:
  7951. {
  7952. const node = this.startNode();
  7953. this.next();
  7954. node.elements = this.parseBindingList(3, 93, 1);
  7955. return this.finishNode(node, "ArrayPattern");
  7956. }
  7957. case 5:
  7958. return this.parseObjectLike(8, true);
  7959. }
  7960. return this.parseIdentifier();
  7961. }
  7962. parseBindingList(close, closeCharCode, flags) {
  7963. const allowEmpty = flags & 1;
  7964. const elts = [];
  7965. let first = true;
  7966. while (!this.eat(close)) {
  7967. if (first) {
  7968. first = false;
  7969. } else {
  7970. this.expect(12);
  7971. }
  7972. if (allowEmpty && this.match(12)) {
  7973. elts.push(null);
  7974. } else if (this.eat(close)) {
  7975. break;
  7976. } else if (this.match(21)) {
  7977. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  7978. if (!this.checkCommaAfterRest(closeCharCode)) {
  7979. this.expect(close);
  7980. break;
  7981. }
  7982. } else {
  7983. const decorators = [];
  7984. if (this.match(26) && this.hasPlugin("decorators")) {
  7985. this.raise(Errors.UnsupportedParameterDecorator, {
  7986. at: this.state.startLoc
  7987. });
  7988. }
  7989. while (this.match(26)) {
  7990. decorators.push(this.parseDecorator());
  7991. }
  7992. elts.push(this.parseAssignableListItem(flags, decorators));
  7993. }
  7994. }
  7995. return elts;
  7996. }
  7997. parseBindingRestProperty(prop) {
  7998. this.next();
  7999. prop.argument = this.parseIdentifier();
  8000. this.checkCommaAfterRest(125);
  8001. return this.finishNode(prop, "RestElement");
  8002. }
  8003. parseBindingProperty() {
  8004. const prop = this.startNode();
  8005. const {
  8006. type,
  8007. startLoc
  8008. } = this.state;
  8009. if (type === 21) {
  8010. return this.parseBindingRestProperty(prop);
  8011. } else if (type === 138) {
  8012. this.expectPlugin("destructuringPrivate", startLoc);
  8013. this.classScope.usePrivateName(this.state.value, startLoc);
  8014. prop.key = this.parsePrivateName();
  8015. } else {
  8016. this.parsePropertyName(prop);
  8017. }
  8018. prop.method = false;
  8019. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  8020. }
  8021. parseAssignableListItem(flags, decorators) {
  8022. const left = this.parseMaybeDefault();
  8023. this.parseAssignableListItemTypes(left, flags);
  8024. const elt = this.parseMaybeDefault(left.loc.start, left);
  8025. if (decorators.length) {
  8026. left.decorators = decorators;
  8027. }
  8028. return elt;
  8029. }
  8030. parseAssignableListItemTypes(param, flags) {
  8031. return param;
  8032. }
  8033. parseMaybeDefault(startLoc, left) {
  8034. var _startLoc, _left;
  8035. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  8036. left = (_left = left) != null ? _left : this.parseBindingAtom();
  8037. if (!this.eat(29)) return left;
  8038. const node = this.startNodeAt(startLoc);
  8039. node.left = left;
  8040. node.right = this.parseMaybeAssignAllowIn();
  8041. return this.finishNode(node, "AssignmentPattern");
  8042. }
  8043. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  8044. return getOwn$1({
  8045. AssignmentPattern: "left",
  8046. RestElement: "argument",
  8047. ObjectProperty: "value",
  8048. ParenthesizedExpression: "expression",
  8049. ArrayPattern: "elements",
  8050. ObjectPattern: "properties"
  8051. }, type);
  8052. }
  8053. isOptionalMemberExpression(expression) {
  8054. return expression.type === "OptionalMemberExpression";
  8055. }
  8056. checkLVal(expression, {
  8057. in: ancestor,
  8058. binding = 64,
  8059. checkClashes = false,
  8060. strictModeChanged = false,
  8061. hasParenthesizedAncestor = false
  8062. }) {
  8063. var _expression$extra;
  8064. const type = expression.type;
  8065. if (this.isObjectMethod(expression)) return;
  8066. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  8067. if (isOptionalMemberExpression || type === "MemberExpression") {
  8068. if (isOptionalMemberExpression) {
  8069. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  8070. if (ancestor.type !== "AssignmentExpression") {
  8071. this.raise(Errors.InvalidLhsOptionalChaining, {
  8072. at: expression,
  8073. ancestor
  8074. });
  8075. }
  8076. }
  8077. if (binding !== 64) {
  8078. this.raise(Errors.InvalidPropertyBindingPattern, {
  8079. at: expression
  8080. });
  8081. }
  8082. return;
  8083. }
  8084. if (type === "Identifier") {
  8085. this.checkIdentifier(expression, binding, strictModeChanged);
  8086. const {
  8087. name
  8088. } = expression;
  8089. if (checkClashes) {
  8090. if (checkClashes.has(name)) {
  8091. this.raise(Errors.ParamDupe, {
  8092. at: expression
  8093. });
  8094. } else {
  8095. checkClashes.add(name);
  8096. }
  8097. }
  8098. return;
  8099. }
  8100. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  8101. if (validity === true) return;
  8102. if (validity === false) {
  8103. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  8104. this.raise(ParseErrorClass, {
  8105. at: expression,
  8106. ancestor
  8107. });
  8108. return;
  8109. }
  8110. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  8111. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  8112. type
  8113. } : ancestor;
  8114. for (const child of [].concat(expression[key])) {
  8115. if (child) {
  8116. this.checkLVal(child, {
  8117. in: nextAncestor,
  8118. binding,
  8119. checkClashes,
  8120. strictModeChanged,
  8121. hasParenthesizedAncestor: isParenthesizedExpression
  8122. });
  8123. }
  8124. }
  8125. }
  8126. checkIdentifier(at, bindingType, strictModeChanged = false) {
  8127. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  8128. if (bindingType === 64) {
  8129. this.raise(Errors.StrictEvalArguments, {
  8130. at,
  8131. referenceName: at.name
  8132. });
  8133. } else {
  8134. this.raise(Errors.StrictEvalArgumentsBinding, {
  8135. at,
  8136. bindingName: at.name
  8137. });
  8138. }
  8139. }
  8140. if (bindingType & 8192 && at.name === "let") {
  8141. this.raise(Errors.LetInLexicalBinding, {
  8142. at
  8143. });
  8144. }
  8145. if (!(bindingType & 64)) {
  8146. this.declareNameFromIdentifier(at, bindingType);
  8147. }
  8148. }
  8149. declareNameFromIdentifier(identifier, binding) {
  8150. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  8151. }
  8152. checkToRestConversion(node, allowPattern) {
  8153. switch (node.type) {
  8154. case "ParenthesizedExpression":
  8155. this.checkToRestConversion(node.expression, allowPattern);
  8156. break;
  8157. case "Identifier":
  8158. case "MemberExpression":
  8159. break;
  8160. case "ArrayExpression":
  8161. case "ObjectExpression":
  8162. if (allowPattern) break;
  8163. default:
  8164. this.raise(Errors.InvalidRestAssignmentPattern, {
  8165. at: node
  8166. });
  8167. }
  8168. }
  8169. checkCommaAfterRest(close) {
  8170. if (!this.match(12)) {
  8171. return false;
  8172. }
  8173. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  8174. at: this.state.startLoc
  8175. });
  8176. return true;
  8177. }
  8178. }
  8179. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  8180. function nonNull(x) {
  8181. if (x == null) {
  8182. throw new Error(`Unexpected ${x} value.`);
  8183. }
  8184. return x;
  8185. }
  8186. function assert$1(x) {
  8187. if (!x) {
  8188. throw new Error("Assert fail");
  8189. }
  8190. }
  8191. const TSErrors = ParseErrorEnum`typescript`({
  8192. AbstractMethodHasImplementation: ({
  8193. methodName
  8194. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  8195. AbstractPropertyHasInitializer: ({
  8196. propertyName
  8197. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  8198. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  8199. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  8200. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  8201. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  8202. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  8203. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  8204. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  8205. DeclareAccessor: ({
  8206. kind
  8207. }) => `'declare' is not allowed in ${kind}ters.`,
  8208. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  8209. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  8210. DuplicateAccessibilityModifier: ({
  8211. modifier
  8212. }) => `Accessibility modifier already seen.`,
  8213. DuplicateModifier: ({
  8214. modifier
  8215. }) => `Duplicate modifier: '${modifier}'.`,
  8216. EmptyHeritageClauseType: ({
  8217. token
  8218. }) => `'${token}' list cannot be empty.`,
  8219. EmptyTypeArguments: "Type argument list cannot be empty.",
  8220. EmptyTypeParameters: "Type parameter list cannot be empty.",
  8221. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  8222. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  8223. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  8224. IncompatibleModifiers: ({
  8225. modifiers
  8226. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  8227. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  8228. IndexSignatureHasAccessibility: ({
  8229. modifier
  8230. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  8231. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  8232. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  8233. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  8234. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  8235. InvalidModifierOnTypeMember: ({
  8236. modifier
  8237. }) => `'${modifier}' modifier cannot appear on a type member.`,
  8238. InvalidModifierOnTypeParameter: ({
  8239. modifier
  8240. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  8241. InvalidModifierOnTypeParameterPositions: ({
  8242. modifier
  8243. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  8244. InvalidModifiersOrder: ({
  8245. orderedModifiers
  8246. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  8247. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  8248. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  8249. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  8250. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  8251. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  8252. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  8253. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  8254. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  8255. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  8256. PrivateElementHasAccessibility: ({
  8257. modifier
  8258. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  8259. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  8260. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  8261. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  8262. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  8263. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  8264. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  8265. SingleTypeParameterWithoutTrailingComma: ({
  8266. typeParameterName
  8267. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  8268. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  8269. 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?`).",
  8270. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  8271. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  8272. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  8273. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  8274. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  8275. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  8276. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  8277. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  8278. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  8279. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  8280. UnsupportedSignatureParameterKind: ({
  8281. type
  8282. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  8283. });
  8284. function keywordTypeFromName(value) {
  8285. switch (value) {
  8286. case "any":
  8287. return "TSAnyKeyword";
  8288. case "boolean":
  8289. return "TSBooleanKeyword";
  8290. case "bigint":
  8291. return "TSBigIntKeyword";
  8292. case "never":
  8293. return "TSNeverKeyword";
  8294. case "number":
  8295. return "TSNumberKeyword";
  8296. case "object":
  8297. return "TSObjectKeyword";
  8298. case "string":
  8299. return "TSStringKeyword";
  8300. case "symbol":
  8301. return "TSSymbolKeyword";
  8302. case "undefined":
  8303. return "TSUndefinedKeyword";
  8304. case "unknown":
  8305. return "TSUnknownKeyword";
  8306. default:
  8307. return undefined;
  8308. }
  8309. }
  8310. function tsIsAccessModifier(modifier) {
  8311. return modifier === "private" || modifier === "public" || modifier === "protected";
  8312. }
  8313. function tsIsVarianceAnnotations(modifier) {
  8314. return modifier === "in" || modifier === "out";
  8315. }
  8316. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  8317. constructor(...args) {
  8318. super(...args);
  8319. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  8320. allowedModifiers: ["in", "out"],
  8321. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  8322. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  8323. });
  8324. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  8325. allowedModifiers: ["const"],
  8326. disallowedModifiers: ["in", "out"],
  8327. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  8328. });
  8329. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  8330. allowedModifiers: ["in", "out", "const"],
  8331. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  8332. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  8333. });
  8334. }
  8335. getScopeHandler() {
  8336. return TypeScriptScopeHandler;
  8337. }
  8338. tsIsIdentifier() {
  8339. return tokenIsIdentifier(this.state.type);
  8340. }
  8341. tsTokenCanFollowModifier() {
  8342. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(138) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  8343. }
  8344. tsNextTokenCanFollowModifier() {
  8345. this.next();
  8346. return this.tsTokenCanFollowModifier();
  8347. }
  8348. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  8349. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  8350. return undefined;
  8351. }
  8352. const modifier = this.state.value;
  8353. if (allowedModifiers.indexOf(modifier) !== -1) {
  8354. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  8355. return undefined;
  8356. }
  8357. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  8358. return modifier;
  8359. }
  8360. }
  8361. return undefined;
  8362. }
  8363. tsParseModifiers({
  8364. allowedModifiers,
  8365. disallowedModifiers,
  8366. stopOnStartOfClassStaticBlock,
  8367. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  8368. }, modified) {
  8369. const enforceOrder = (loc, modifier, before, after) => {
  8370. if (modifier === before && modified[after]) {
  8371. this.raise(TSErrors.InvalidModifiersOrder, {
  8372. at: loc,
  8373. orderedModifiers: [before, after]
  8374. });
  8375. }
  8376. };
  8377. const incompatible = (loc, modifier, mod1, mod2) => {
  8378. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  8379. this.raise(TSErrors.IncompatibleModifiers, {
  8380. at: loc,
  8381. modifiers: [mod1, mod2]
  8382. });
  8383. }
  8384. };
  8385. for (;;) {
  8386. const {
  8387. startLoc
  8388. } = this.state;
  8389. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  8390. if (!modifier) break;
  8391. if (tsIsAccessModifier(modifier)) {
  8392. if (modified.accessibility) {
  8393. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  8394. at: startLoc,
  8395. modifier
  8396. });
  8397. } else {
  8398. enforceOrder(startLoc, modifier, modifier, "override");
  8399. enforceOrder(startLoc, modifier, modifier, "static");
  8400. enforceOrder(startLoc, modifier, modifier, "readonly");
  8401. modified.accessibility = modifier;
  8402. }
  8403. } else if (tsIsVarianceAnnotations(modifier)) {
  8404. if (modified[modifier]) {
  8405. this.raise(TSErrors.DuplicateModifier, {
  8406. at: startLoc,
  8407. modifier
  8408. });
  8409. }
  8410. modified[modifier] = true;
  8411. enforceOrder(startLoc, modifier, "in", "out");
  8412. } else {
  8413. if (Object.hasOwnProperty.call(modified, modifier)) {
  8414. this.raise(TSErrors.DuplicateModifier, {
  8415. at: startLoc,
  8416. modifier
  8417. });
  8418. } else {
  8419. enforceOrder(startLoc, modifier, "static", "readonly");
  8420. enforceOrder(startLoc, modifier, "static", "override");
  8421. enforceOrder(startLoc, modifier, "override", "readonly");
  8422. enforceOrder(startLoc, modifier, "abstract", "override");
  8423. incompatible(startLoc, modifier, "declare", "override");
  8424. incompatible(startLoc, modifier, "static", "abstract");
  8425. }
  8426. modified[modifier] = true;
  8427. }
  8428. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  8429. this.raise(errorTemplate, {
  8430. at: startLoc,
  8431. modifier
  8432. });
  8433. }
  8434. }
  8435. }
  8436. tsIsListTerminator(kind) {
  8437. switch (kind) {
  8438. case "EnumMembers":
  8439. case "TypeMembers":
  8440. return this.match(8);
  8441. case "HeritageClauseElement":
  8442. return this.match(5);
  8443. case "TupleElementTypes":
  8444. return this.match(3);
  8445. case "TypeParametersOrArguments":
  8446. return this.match(48);
  8447. }
  8448. }
  8449. tsParseList(kind, parseElement) {
  8450. const result = [];
  8451. while (!this.tsIsListTerminator(kind)) {
  8452. result.push(parseElement());
  8453. }
  8454. return result;
  8455. }
  8456. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  8457. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  8458. }
  8459. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  8460. const result = [];
  8461. let trailingCommaPos = -1;
  8462. for (;;) {
  8463. if (this.tsIsListTerminator(kind)) {
  8464. break;
  8465. }
  8466. trailingCommaPos = -1;
  8467. const element = parseElement();
  8468. if (element == null) {
  8469. return undefined;
  8470. }
  8471. result.push(element);
  8472. if (this.eat(12)) {
  8473. trailingCommaPos = this.state.lastTokStart;
  8474. continue;
  8475. }
  8476. if (this.tsIsListTerminator(kind)) {
  8477. break;
  8478. }
  8479. if (expectSuccess) {
  8480. this.expect(12);
  8481. }
  8482. return undefined;
  8483. }
  8484. if (refTrailingCommaPos) {
  8485. refTrailingCommaPos.value = trailingCommaPos;
  8486. }
  8487. return result;
  8488. }
  8489. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  8490. if (!skipFirstToken) {
  8491. if (bracket) {
  8492. this.expect(0);
  8493. } else {
  8494. this.expect(47);
  8495. }
  8496. }
  8497. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  8498. if (bracket) {
  8499. this.expect(3);
  8500. } else {
  8501. this.expect(48);
  8502. }
  8503. return result;
  8504. }
  8505. tsParseImportType() {
  8506. const node = this.startNode();
  8507. this.expect(83);
  8508. this.expect(10);
  8509. if (!this.match(133)) {
  8510. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  8511. at: this.state.startLoc
  8512. });
  8513. }
  8514. node.argument = super.parseExprAtom();
  8515. this.expect(11);
  8516. if (this.eat(16)) {
  8517. node.qualifier = this.tsParseEntityName();
  8518. }
  8519. if (this.match(47)) {
  8520. node.typeParameters = this.tsParseTypeArguments();
  8521. }
  8522. return this.finishNode(node, "TSImportType");
  8523. }
  8524. tsParseEntityName(allowReservedWords = true) {
  8525. let entity = this.parseIdentifier(allowReservedWords);
  8526. while (this.eat(16)) {
  8527. const node = this.startNodeAtNode(entity);
  8528. node.left = entity;
  8529. node.right = this.parseIdentifier(allowReservedWords);
  8530. entity = this.finishNode(node, "TSQualifiedName");
  8531. }
  8532. return entity;
  8533. }
  8534. tsParseTypeReference() {
  8535. const node = this.startNode();
  8536. node.typeName = this.tsParseEntityName();
  8537. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8538. node.typeParameters = this.tsParseTypeArguments();
  8539. }
  8540. return this.finishNode(node, "TSTypeReference");
  8541. }
  8542. tsParseThisTypePredicate(lhs) {
  8543. this.next();
  8544. const node = this.startNodeAtNode(lhs);
  8545. node.parameterName = lhs;
  8546. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  8547. node.asserts = false;
  8548. return this.finishNode(node, "TSTypePredicate");
  8549. }
  8550. tsParseThisTypeNode() {
  8551. const node = this.startNode();
  8552. this.next();
  8553. return this.finishNode(node, "TSThisType");
  8554. }
  8555. tsParseTypeQuery() {
  8556. const node = this.startNode();
  8557. this.expect(87);
  8558. if (this.match(83)) {
  8559. node.exprName = this.tsParseImportType();
  8560. } else {
  8561. node.exprName = this.tsParseEntityName();
  8562. }
  8563. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  8564. node.typeParameters = this.tsParseTypeArguments();
  8565. }
  8566. return this.finishNode(node, "TSTypeQuery");
  8567. }
  8568. tsParseTypeParameter(parseModifiers) {
  8569. const node = this.startNode();
  8570. parseModifiers(node);
  8571. node.name = this.tsParseTypeParameterName();
  8572. node.constraint = this.tsEatThenParseType(81);
  8573. node.default = this.tsEatThenParseType(29);
  8574. return this.finishNode(node, "TSTypeParameter");
  8575. }
  8576. tsTryParseTypeParameters(parseModifiers) {
  8577. if (this.match(47)) {
  8578. return this.tsParseTypeParameters(parseModifiers);
  8579. }
  8580. }
  8581. tsParseTypeParameters(parseModifiers) {
  8582. const node = this.startNode();
  8583. if (this.match(47) || this.match(142)) {
  8584. this.next();
  8585. } else {
  8586. this.unexpected();
  8587. }
  8588. const refTrailingCommaPos = {
  8589. value: -1
  8590. };
  8591. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  8592. if (node.params.length === 0) {
  8593. this.raise(TSErrors.EmptyTypeParameters, {
  8594. at: node
  8595. });
  8596. }
  8597. if (refTrailingCommaPos.value !== -1) {
  8598. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  8599. }
  8600. return this.finishNode(node, "TSTypeParameterDeclaration");
  8601. }
  8602. tsFillSignature(returnToken, signature) {
  8603. const returnTokenRequired = returnToken === 19;
  8604. const paramsKey = "parameters";
  8605. const returnTypeKey = "typeAnnotation";
  8606. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  8607. this.expect(10);
  8608. signature[paramsKey] = this.tsParseBindingListForSignature();
  8609. if (returnTokenRequired) {
  8610. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8611. } else if (this.match(returnToken)) {
  8612. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  8613. }
  8614. }
  8615. tsParseBindingListForSignature() {
  8616. const list = super.parseBindingList(11, 41, 2);
  8617. for (const pattern of list) {
  8618. const {
  8619. type
  8620. } = pattern;
  8621. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  8622. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  8623. at: pattern,
  8624. type
  8625. });
  8626. }
  8627. }
  8628. return list;
  8629. }
  8630. tsParseTypeMemberSemicolon() {
  8631. if (!this.eat(12) && !this.isLineTerminator()) {
  8632. this.expect(13);
  8633. }
  8634. }
  8635. tsParseSignatureMember(kind, node) {
  8636. this.tsFillSignature(14, node);
  8637. this.tsParseTypeMemberSemicolon();
  8638. return this.finishNode(node, kind);
  8639. }
  8640. tsIsUnambiguouslyIndexSignature() {
  8641. this.next();
  8642. if (tokenIsIdentifier(this.state.type)) {
  8643. this.next();
  8644. return this.match(14);
  8645. }
  8646. return false;
  8647. }
  8648. tsTryParseIndexSignature(node) {
  8649. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  8650. return;
  8651. }
  8652. this.expect(0);
  8653. const id = this.parseIdentifier();
  8654. id.typeAnnotation = this.tsParseTypeAnnotation();
  8655. this.resetEndLocation(id);
  8656. this.expect(3);
  8657. node.parameters = [id];
  8658. const type = this.tsTryParseTypeAnnotation();
  8659. if (type) node.typeAnnotation = type;
  8660. this.tsParseTypeMemberSemicolon();
  8661. return this.finishNode(node, "TSIndexSignature");
  8662. }
  8663. tsParsePropertyOrMethodSignature(node, readonly) {
  8664. if (this.eat(17)) node.optional = true;
  8665. const nodeAny = node;
  8666. if (this.match(10) || this.match(47)) {
  8667. if (readonly) {
  8668. this.raise(TSErrors.ReadonlyForMethodSignature, {
  8669. at: node
  8670. });
  8671. }
  8672. const method = nodeAny;
  8673. if (method.kind && this.match(47)) {
  8674. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  8675. at: this.state.curPosition()
  8676. });
  8677. }
  8678. this.tsFillSignature(14, method);
  8679. this.tsParseTypeMemberSemicolon();
  8680. const paramsKey = "parameters";
  8681. const returnTypeKey = "typeAnnotation";
  8682. if (method.kind === "get") {
  8683. if (method[paramsKey].length > 0) {
  8684. this.raise(Errors.BadGetterArity, {
  8685. at: this.state.curPosition()
  8686. });
  8687. if (this.isThisParam(method[paramsKey][0])) {
  8688. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8689. at: this.state.curPosition()
  8690. });
  8691. }
  8692. }
  8693. } else if (method.kind === "set") {
  8694. if (method[paramsKey].length !== 1) {
  8695. this.raise(Errors.BadSetterArity, {
  8696. at: this.state.curPosition()
  8697. });
  8698. } else {
  8699. const firstParameter = method[paramsKey][0];
  8700. if (this.isThisParam(firstParameter)) {
  8701. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8702. at: this.state.curPosition()
  8703. });
  8704. }
  8705. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8706. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  8707. at: this.state.curPosition()
  8708. });
  8709. }
  8710. if (firstParameter.type === "RestElement") {
  8711. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  8712. at: this.state.curPosition()
  8713. });
  8714. }
  8715. }
  8716. if (method[returnTypeKey]) {
  8717. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  8718. at: method[returnTypeKey]
  8719. });
  8720. }
  8721. } else {
  8722. method.kind = "method";
  8723. }
  8724. return this.finishNode(method, "TSMethodSignature");
  8725. } else {
  8726. const property = nodeAny;
  8727. if (readonly) property.readonly = true;
  8728. const type = this.tsTryParseTypeAnnotation();
  8729. if (type) property.typeAnnotation = type;
  8730. this.tsParseTypeMemberSemicolon();
  8731. return this.finishNode(property, "TSPropertySignature");
  8732. }
  8733. }
  8734. tsParseTypeMember() {
  8735. const node = this.startNode();
  8736. if (this.match(10) || this.match(47)) {
  8737. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8738. }
  8739. if (this.match(77)) {
  8740. const id = this.startNode();
  8741. this.next();
  8742. if (this.match(10) || this.match(47)) {
  8743. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8744. } else {
  8745. node.key = this.createIdentifier(id, "new");
  8746. return this.tsParsePropertyOrMethodSignature(node, false);
  8747. }
  8748. }
  8749. this.tsParseModifiers({
  8750. allowedModifiers: ["readonly"],
  8751. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8752. }, node);
  8753. const idx = this.tsTryParseIndexSignature(node);
  8754. if (idx) {
  8755. return idx;
  8756. }
  8757. super.parsePropertyName(node);
  8758. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8759. node.kind = node.key.name;
  8760. super.parsePropertyName(node);
  8761. }
  8762. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8763. }
  8764. tsParseTypeLiteral() {
  8765. const node = this.startNode();
  8766. node.members = this.tsParseObjectTypeMembers();
  8767. return this.finishNode(node, "TSTypeLiteral");
  8768. }
  8769. tsParseObjectTypeMembers() {
  8770. this.expect(5);
  8771. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8772. this.expect(8);
  8773. return members;
  8774. }
  8775. tsIsStartOfMappedType() {
  8776. this.next();
  8777. if (this.eat(53)) {
  8778. return this.isContextual(122);
  8779. }
  8780. if (this.isContextual(122)) {
  8781. this.next();
  8782. }
  8783. if (!this.match(0)) {
  8784. return false;
  8785. }
  8786. this.next();
  8787. if (!this.tsIsIdentifier()) {
  8788. return false;
  8789. }
  8790. this.next();
  8791. return this.match(58);
  8792. }
  8793. tsParseMappedTypeParameter() {
  8794. const node = this.startNode();
  8795. node.name = this.tsParseTypeParameterName();
  8796. node.constraint = this.tsExpectThenParseType(58);
  8797. return this.finishNode(node, "TSTypeParameter");
  8798. }
  8799. tsParseMappedType() {
  8800. const node = this.startNode();
  8801. this.expect(5);
  8802. if (this.match(53)) {
  8803. node.readonly = this.state.value;
  8804. this.next();
  8805. this.expectContextual(122);
  8806. } else if (this.eatContextual(122)) {
  8807. node.readonly = true;
  8808. }
  8809. this.expect(0);
  8810. node.typeParameter = this.tsParseMappedTypeParameter();
  8811. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8812. this.expect(3);
  8813. if (this.match(53)) {
  8814. node.optional = this.state.value;
  8815. this.next();
  8816. this.expect(17);
  8817. } else if (this.eat(17)) {
  8818. node.optional = true;
  8819. }
  8820. node.typeAnnotation = this.tsTryParseType();
  8821. this.semicolon();
  8822. this.expect(8);
  8823. return this.finishNode(node, "TSMappedType");
  8824. }
  8825. tsParseTupleType() {
  8826. const node = this.startNode();
  8827. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8828. let seenOptionalElement = false;
  8829. node.elementTypes.forEach(elementNode => {
  8830. const {
  8831. type
  8832. } = elementNode;
  8833. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8834. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  8835. at: elementNode
  8836. });
  8837. }
  8838. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8839. });
  8840. return this.finishNode(node, "TSTupleType");
  8841. }
  8842. tsParseTupleElementType() {
  8843. const {
  8844. startLoc
  8845. } = this.state;
  8846. const rest = this.eat(21);
  8847. let labeled;
  8848. let label;
  8849. let optional;
  8850. let type;
  8851. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8852. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8853. if (chAfterWord === 58) {
  8854. labeled = true;
  8855. optional = false;
  8856. label = this.parseIdentifier(true);
  8857. this.expect(14);
  8858. type = this.tsParseType();
  8859. } else if (chAfterWord === 63) {
  8860. optional = true;
  8861. const startLoc = this.state.startLoc;
  8862. const wordName = this.state.value;
  8863. const typeOrLabel = this.tsParseNonArrayType();
  8864. if (this.lookaheadCharCode() === 58) {
  8865. labeled = true;
  8866. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8867. this.expect(17);
  8868. this.expect(14);
  8869. type = this.tsParseType();
  8870. } else {
  8871. labeled = false;
  8872. type = typeOrLabel;
  8873. this.expect(17);
  8874. }
  8875. } else {
  8876. type = this.tsParseType();
  8877. optional = this.eat(17);
  8878. labeled = this.eat(14);
  8879. }
  8880. if (labeled) {
  8881. let labeledNode;
  8882. if (label) {
  8883. labeledNode = this.startNodeAtNode(label);
  8884. labeledNode.optional = optional;
  8885. labeledNode.label = label;
  8886. labeledNode.elementType = type;
  8887. if (this.eat(17)) {
  8888. labeledNode.optional = true;
  8889. this.raise(TSErrors.TupleOptionalAfterType, {
  8890. at: this.state.lastTokStartLoc
  8891. });
  8892. }
  8893. } else {
  8894. labeledNode = this.startNodeAtNode(type);
  8895. labeledNode.optional = optional;
  8896. this.raise(TSErrors.InvalidTupleMemberLabel, {
  8897. at: type
  8898. });
  8899. labeledNode.label = type;
  8900. labeledNode.elementType = this.tsParseType();
  8901. }
  8902. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8903. } else if (optional) {
  8904. const optionalTypeNode = this.startNodeAtNode(type);
  8905. optionalTypeNode.typeAnnotation = type;
  8906. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8907. }
  8908. if (rest) {
  8909. const restNode = this.startNodeAt(startLoc);
  8910. restNode.typeAnnotation = type;
  8911. type = this.finishNode(restNode, "TSRestType");
  8912. }
  8913. return type;
  8914. }
  8915. tsParseParenthesizedType() {
  8916. const node = this.startNode();
  8917. this.expect(10);
  8918. node.typeAnnotation = this.tsParseType();
  8919. this.expect(11);
  8920. return this.finishNode(node, "TSParenthesizedType");
  8921. }
  8922. tsParseFunctionOrConstructorType(type, abstract) {
  8923. const node = this.startNode();
  8924. if (type === "TSConstructorType") {
  8925. node.abstract = !!abstract;
  8926. if (abstract) this.next();
  8927. this.next();
  8928. }
  8929. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8930. return this.finishNode(node, type);
  8931. }
  8932. tsParseLiteralTypeNode() {
  8933. const node = this.startNode();
  8934. switch (this.state.type) {
  8935. case 134:
  8936. case 135:
  8937. case 133:
  8938. case 85:
  8939. case 86:
  8940. node.literal = super.parseExprAtom();
  8941. break;
  8942. default:
  8943. this.unexpected();
  8944. }
  8945. return this.finishNode(node, "TSLiteralType");
  8946. }
  8947. tsParseTemplateLiteralType() {
  8948. const node = this.startNode();
  8949. node.literal = super.parseTemplate(false);
  8950. return this.finishNode(node, "TSLiteralType");
  8951. }
  8952. parseTemplateSubstitution() {
  8953. if (this.state.inType) return this.tsParseType();
  8954. return super.parseTemplateSubstitution();
  8955. }
  8956. tsParseThisTypeOrThisTypePredicate() {
  8957. const thisKeyword = this.tsParseThisTypeNode();
  8958. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8959. return this.tsParseThisTypePredicate(thisKeyword);
  8960. } else {
  8961. return thisKeyword;
  8962. }
  8963. }
  8964. tsParseNonArrayType() {
  8965. switch (this.state.type) {
  8966. case 133:
  8967. case 134:
  8968. case 135:
  8969. case 85:
  8970. case 86:
  8971. return this.tsParseLiteralTypeNode();
  8972. case 53:
  8973. if (this.state.value === "-") {
  8974. const node = this.startNode();
  8975. const nextToken = this.lookahead();
  8976. if (nextToken.type !== 134 && nextToken.type !== 135) {
  8977. this.unexpected();
  8978. }
  8979. node.literal = this.parseMaybeUnary();
  8980. return this.finishNode(node, "TSLiteralType");
  8981. }
  8982. break;
  8983. case 78:
  8984. return this.tsParseThisTypeOrThisTypePredicate();
  8985. case 87:
  8986. return this.tsParseTypeQuery();
  8987. case 83:
  8988. return this.tsParseImportType();
  8989. case 5:
  8990. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8991. case 0:
  8992. return this.tsParseTupleType();
  8993. case 10:
  8994. return this.tsParseParenthesizedType();
  8995. case 25:
  8996. case 24:
  8997. return this.tsParseTemplateLiteralType();
  8998. default:
  8999. {
  9000. const {
  9001. type
  9002. } = this.state;
  9003. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  9004. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  9005. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  9006. const node = this.startNode();
  9007. this.next();
  9008. return this.finishNode(node, nodeType);
  9009. }
  9010. return this.tsParseTypeReference();
  9011. }
  9012. }
  9013. }
  9014. this.unexpected();
  9015. }
  9016. tsParseArrayTypeOrHigher() {
  9017. let type = this.tsParseNonArrayType();
  9018. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  9019. if (this.match(3)) {
  9020. const node = this.startNodeAtNode(type);
  9021. node.elementType = type;
  9022. this.expect(3);
  9023. type = this.finishNode(node, "TSArrayType");
  9024. } else {
  9025. const node = this.startNodeAtNode(type);
  9026. node.objectType = type;
  9027. node.indexType = this.tsParseType();
  9028. this.expect(3);
  9029. type = this.finishNode(node, "TSIndexedAccessType");
  9030. }
  9031. }
  9032. return type;
  9033. }
  9034. tsParseTypeOperator() {
  9035. const node = this.startNode();
  9036. const operator = this.state.value;
  9037. this.next();
  9038. node.operator = operator;
  9039. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  9040. if (operator === "readonly") {
  9041. this.tsCheckTypeAnnotationForReadOnly(node);
  9042. }
  9043. return this.finishNode(node, "TSTypeOperator");
  9044. }
  9045. tsCheckTypeAnnotationForReadOnly(node) {
  9046. switch (node.typeAnnotation.type) {
  9047. case "TSTupleType":
  9048. case "TSArrayType":
  9049. return;
  9050. default:
  9051. this.raise(TSErrors.UnexpectedReadonly, {
  9052. at: node
  9053. });
  9054. }
  9055. }
  9056. tsParseInferType() {
  9057. const node = this.startNode();
  9058. this.expectContextual(115);
  9059. const typeParameter = this.startNode();
  9060. typeParameter.name = this.tsParseTypeParameterName();
  9061. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  9062. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  9063. return this.finishNode(node, "TSInferType");
  9064. }
  9065. tsParseConstraintForInferType() {
  9066. if (this.eat(81)) {
  9067. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  9068. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  9069. return constraint;
  9070. }
  9071. }
  9072. }
  9073. tsParseTypeOperatorOrHigher() {
  9074. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  9075. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  9076. }
  9077. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  9078. const node = this.startNode();
  9079. const hasLeadingOperator = this.eat(operator);
  9080. const types = [];
  9081. do {
  9082. types.push(parseConstituentType());
  9083. } while (this.eat(operator));
  9084. if (types.length === 1 && !hasLeadingOperator) {
  9085. return types[0];
  9086. }
  9087. node.types = types;
  9088. return this.finishNode(node, kind);
  9089. }
  9090. tsParseIntersectionTypeOrHigher() {
  9091. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  9092. }
  9093. tsParseUnionTypeOrHigher() {
  9094. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  9095. }
  9096. tsIsStartOfFunctionType() {
  9097. if (this.match(47)) {
  9098. return true;
  9099. }
  9100. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  9101. }
  9102. tsSkipParameterStart() {
  9103. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  9104. this.next();
  9105. return true;
  9106. }
  9107. if (this.match(5)) {
  9108. const {
  9109. errors
  9110. } = this.state;
  9111. const previousErrorCount = errors.length;
  9112. try {
  9113. this.parseObjectLike(8, true);
  9114. return errors.length === previousErrorCount;
  9115. } catch (_unused) {
  9116. return false;
  9117. }
  9118. }
  9119. if (this.match(0)) {
  9120. this.next();
  9121. const {
  9122. errors
  9123. } = this.state;
  9124. const previousErrorCount = errors.length;
  9125. try {
  9126. super.parseBindingList(3, 93, 1);
  9127. return errors.length === previousErrorCount;
  9128. } catch (_unused2) {
  9129. return false;
  9130. }
  9131. }
  9132. return false;
  9133. }
  9134. tsIsUnambiguouslyStartOfFunctionType() {
  9135. this.next();
  9136. if (this.match(11) || this.match(21)) {
  9137. return true;
  9138. }
  9139. if (this.tsSkipParameterStart()) {
  9140. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  9141. return true;
  9142. }
  9143. if (this.match(11)) {
  9144. this.next();
  9145. if (this.match(19)) {
  9146. return true;
  9147. }
  9148. }
  9149. }
  9150. return false;
  9151. }
  9152. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  9153. return this.tsInType(() => {
  9154. const t = this.startNode();
  9155. this.expect(returnToken);
  9156. const node = this.startNode();
  9157. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  9158. if (asserts && this.match(78)) {
  9159. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  9160. if (thisTypePredicate.type === "TSThisType") {
  9161. node.parameterName = thisTypePredicate;
  9162. node.asserts = true;
  9163. node.typeAnnotation = null;
  9164. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  9165. } else {
  9166. this.resetStartLocationFromNode(thisTypePredicate, node);
  9167. thisTypePredicate.asserts = true;
  9168. }
  9169. t.typeAnnotation = thisTypePredicate;
  9170. return this.finishNode(t, "TSTypeAnnotation");
  9171. }
  9172. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  9173. if (!typePredicateVariable) {
  9174. if (!asserts) {
  9175. return this.tsParseTypeAnnotation(false, t);
  9176. }
  9177. node.parameterName = this.parseIdentifier();
  9178. node.asserts = asserts;
  9179. node.typeAnnotation = null;
  9180. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  9181. return this.finishNode(t, "TSTypeAnnotation");
  9182. }
  9183. const type = this.tsParseTypeAnnotation(false);
  9184. node.parameterName = typePredicateVariable;
  9185. node.typeAnnotation = type;
  9186. node.asserts = asserts;
  9187. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  9188. return this.finishNode(t, "TSTypeAnnotation");
  9189. });
  9190. }
  9191. tsTryParseTypeOrTypePredicateAnnotation() {
  9192. if (this.match(14)) {
  9193. return this.tsParseTypeOrTypePredicateAnnotation(14);
  9194. }
  9195. }
  9196. tsTryParseTypeAnnotation() {
  9197. if (this.match(14)) {
  9198. return this.tsParseTypeAnnotation();
  9199. }
  9200. }
  9201. tsTryParseType() {
  9202. return this.tsEatThenParseType(14);
  9203. }
  9204. tsParseTypePredicatePrefix() {
  9205. const id = this.parseIdentifier();
  9206. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  9207. this.next();
  9208. return id;
  9209. }
  9210. }
  9211. tsParseTypePredicateAsserts() {
  9212. if (this.state.type !== 109) {
  9213. return false;
  9214. }
  9215. const containsEsc = this.state.containsEsc;
  9216. this.next();
  9217. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  9218. return false;
  9219. }
  9220. if (containsEsc) {
  9221. this.raise(Errors.InvalidEscapedReservedWord, {
  9222. at: this.state.lastTokStartLoc,
  9223. reservedWord: "asserts"
  9224. });
  9225. }
  9226. return true;
  9227. }
  9228. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  9229. this.tsInType(() => {
  9230. if (eatColon) this.expect(14);
  9231. t.typeAnnotation = this.tsParseType();
  9232. });
  9233. return this.finishNode(t, "TSTypeAnnotation");
  9234. }
  9235. tsParseType() {
  9236. assert$1(this.state.inType);
  9237. const type = this.tsParseNonConditionalType();
  9238. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  9239. return type;
  9240. }
  9241. const node = this.startNodeAtNode(type);
  9242. node.checkType = type;
  9243. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  9244. this.expect(17);
  9245. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  9246. this.expect(14);
  9247. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  9248. return this.finishNode(node, "TSConditionalType");
  9249. }
  9250. isAbstractConstructorSignature() {
  9251. return this.isContextual(124) && this.lookahead().type === 77;
  9252. }
  9253. tsParseNonConditionalType() {
  9254. if (this.tsIsStartOfFunctionType()) {
  9255. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  9256. }
  9257. if (this.match(77)) {
  9258. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  9259. } else if (this.isAbstractConstructorSignature()) {
  9260. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  9261. }
  9262. return this.tsParseUnionTypeOrHigher();
  9263. }
  9264. tsParseTypeAssertion() {
  9265. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9266. this.raise(TSErrors.ReservedTypeAssertion, {
  9267. at: this.state.startLoc
  9268. });
  9269. }
  9270. const node = this.startNode();
  9271. node.typeAnnotation = this.tsInType(() => {
  9272. this.next();
  9273. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  9274. });
  9275. this.expect(48);
  9276. node.expression = this.parseMaybeUnary();
  9277. return this.finishNode(node, "TSTypeAssertion");
  9278. }
  9279. tsParseHeritageClause(token) {
  9280. const originalStartLoc = this.state.startLoc;
  9281. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  9282. const node = this.startNode();
  9283. node.expression = this.tsParseEntityName();
  9284. if (this.match(47)) {
  9285. node.typeParameters = this.tsParseTypeArguments();
  9286. }
  9287. return this.finishNode(node, "TSExpressionWithTypeArguments");
  9288. });
  9289. if (!delimitedList.length) {
  9290. this.raise(TSErrors.EmptyHeritageClauseType, {
  9291. at: originalStartLoc,
  9292. token
  9293. });
  9294. }
  9295. return delimitedList;
  9296. }
  9297. tsParseInterfaceDeclaration(node, properties = {}) {
  9298. if (this.hasFollowingLineBreak()) return null;
  9299. this.expectContextual(129);
  9300. if (properties.declare) node.declare = true;
  9301. if (tokenIsIdentifier(this.state.type)) {
  9302. node.id = this.parseIdentifier();
  9303. this.checkIdentifier(node.id, 130);
  9304. } else {
  9305. node.id = null;
  9306. this.raise(TSErrors.MissingInterfaceName, {
  9307. at: this.state.startLoc
  9308. });
  9309. }
  9310. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9311. if (this.eat(81)) {
  9312. node.extends = this.tsParseHeritageClause("extends");
  9313. }
  9314. const body = this.startNode();
  9315. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  9316. node.body = this.finishNode(body, "TSInterfaceBody");
  9317. return this.finishNode(node, "TSInterfaceDeclaration");
  9318. }
  9319. tsParseTypeAliasDeclaration(node) {
  9320. node.id = this.parseIdentifier();
  9321. this.checkIdentifier(node.id, 2);
  9322. node.typeAnnotation = this.tsInType(() => {
  9323. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  9324. this.expect(29);
  9325. if (this.isContextual(114) && this.lookahead().type !== 16) {
  9326. const node = this.startNode();
  9327. this.next();
  9328. return this.finishNode(node, "TSIntrinsicKeyword");
  9329. }
  9330. return this.tsParseType();
  9331. });
  9332. this.semicolon();
  9333. return this.finishNode(node, "TSTypeAliasDeclaration");
  9334. }
  9335. tsInNoContext(cb) {
  9336. const oldContext = this.state.context;
  9337. this.state.context = [oldContext[0]];
  9338. try {
  9339. return cb();
  9340. } finally {
  9341. this.state.context = oldContext;
  9342. }
  9343. }
  9344. tsInType(cb) {
  9345. const oldInType = this.state.inType;
  9346. this.state.inType = true;
  9347. try {
  9348. return cb();
  9349. } finally {
  9350. this.state.inType = oldInType;
  9351. }
  9352. }
  9353. tsInDisallowConditionalTypesContext(cb) {
  9354. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  9355. this.state.inDisallowConditionalTypesContext = true;
  9356. try {
  9357. return cb();
  9358. } finally {
  9359. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  9360. }
  9361. }
  9362. tsInAllowConditionalTypesContext(cb) {
  9363. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  9364. this.state.inDisallowConditionalTypesContext = false;
  9365. try {
  9366. return cb();
  9367. } finally {
  9368. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  9369. }
  9370. }
  9371. tsEatThenParseType(token) {
  9372. if (this.match(token)) {
  9373. return this.tsNextThenParseType();
  9374. }
  9375. }
  9376. tsExpectThenParseType(token) {
  9377. return this.tsInType(() => {
  9378. this.expect(token);
  9379. return this.tsParseType();
  9380. });
  9381. }
  9382. tsNextThenParseType() {
  9383. return this.tsInType(() => {
  9384. this.next();
  9385. return this.tsParseType();
  9386. });
  9387. }
  9388. tsParseEnumMember() {
  9389. const node = this.startNode();
  9390. node.id = this.match(133) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  9391. if (this.eat(29)) {
  9392. node.initializer = super.parseMaybeAssignAllowIn();
  9393. }
  9394. return this.finishNode(node, "TSEnumMember");
  9395. }
  9396. tsParseEnumDeclaration(node, properties = {}) {
  9397. if (properties.const) node.const = true;
  9398. if (properties.declare) node.declare = true;
  9399. this.expectContextual(126);
  9400. node.id = this.parseIdentifier();
  9401. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  9402. this.expect(5);
  9403. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  9404. this.expect(8);
  9405. return this.finishNode(node, "TSEnumDeclaration");
  9406. }
  9407. tsParseModuleBlock() {
  9408. const node = this.startNode();
  9409. this.scope.enter(0);
  9410. this.expect(5);
  9411. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  9412. this.scope.exit();
  9413. return this.finishNode(node, "TSModuleBlock");
  9414. }
  9415. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  9416. node.id = this.parseIdentifier();
  9417. if (!nested) {
  9418. this.checkIdentifier(node.id, 1024);
  9419. }
  9420. if (this.eat(16)) {
  9421. const inner = this.startNode();
  9422. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  9423. node.body = inner;
  9424. } else {
  9425. this.scope.enter(256);
  9426. this.prodParam.enter(0);
  9427. node.body = this.tsParseModuleBlock();
  9428. this.prodParam.exit();
  9429. this.scope.exit();
  9430. }
  9431. return this.finishNode(node, "TSModuleDeclaration");
  9432. }
  9433. tsParseAmbientExternalModuleDeclaration(node) {
  9434. if (this.isContextual(112)) {
  9435. node.global = true;
  9436. node.id = this.parseIdentifier();
  9437. } else if (this.match(133)) {
  9438. node.id = super.parseStringLiteral(this.state.value);
  9439. } else {
  9440. this.unexpected();
  9441. }
  9442. if (this.match(5)) {
  9443. this.scope.enter(256);
  9444. this.prodParam.enter(0);
  9445. node.body = this.tsParseModuleBlock();
  9446. this.prodParam.exit();
  9447. this.scope.exit();
  9448. } else {
  9449. this.semicolon();
  9450. }
  9451. return this.finishNode(node, "TSModuleDeclaration");
  9452. }
  9453. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  9454. node.isExport = isExport || false;
  9455. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  9456. this.checkIdentifier(node.id, 4096);
  9457. this.expect(29);
  9458. const moduleReference = this.tsParseModuleReference();
  9459. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  9460. this.raise(TSErrors.ImportAliasHasImportType, {
  9461. at: moduleReference
  9462. });
  9463. }
  9464. node.moduleReference = moduleReference;
  9465. this.semicolon();
  9466. return this.finishNode(node, "TSImportEqualsDeclaration");
  9467. }
  9468. tsIsExternalModuleReference() {
  9469. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  9470. }
  9471. tsParseModuleReference() {
  9472. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  9473. }
  9474. tsParseExternalModuleReference() {
  9475. const node = this.startNode();
  9476. this.expectContextual(119);
  9477. this.expect(10);
  9478. if (!this.match(133)) {
  9479. this.unexpected();
  9480. }
  9481. node.expression = super.parseExprAtom();
  9482. this.expect(11);
  9483. this.sawUnambiguousESM = true;
  9484. return this.finishNode(node, "TSExternalModuleReference");
  9485. }
  9486. tsLookAhead(f) {
  9487. const state = this.state.clone();
  9488. const res = f();
  9489. this.state = state;
  9490. return res;
  9491. }
  9492. tsTryParseAndCatch(f) {
  9493. const result = this.tryParse(abort => f() || abort());
  9494. if (result.aborted || !result.node) return;
  9495. if (result.error) this.state = result.failState;
  9496. return result.node;
  9497. }
  9498. tsTryParse(f) {
  9499. const state = this.state.clone();
  9500. const result = f();
  9501. if (result !== undefined && result !== false) {
  9502. return result;
  9503. }
  9504. this.state = state;
  9505. }
  9506. tsTryParseDeclare(nany) {
  9507. if (this.isLineTerminator()) {
  9508. return;
  9509. }
  9510. let startType = this.state.type;
  9511. let kind;
  9512. if (this.isContextual(100)) {
  9513. startType = 74;
  9514. kind = "let";
  9515. }
  9516. return this.tsInAmbientContext(() => {
  9517. switch (startType) {
  9518. case 68:
  9519. nany.declare = true;
  9520. return super.parseFunctionStatement(nany, false, false);
  9521. case 80:
  9522. nany.declare = true;
  9523. return this.parseClass(nany, true, false);
  9524. case 126:
  9525. return this.tsParseEnumDeclaration(nany, {
  9526. declare: true
  9527. });
  9528. case 112:
  9529. return this.tsParseAmbientExternalModuleDeclaration(nany);
  9530. case 75:
  9531. case 74:
  9532. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  9533. nany.declare = true;
  9534. return this.parseVarStatement(nany, kind || this.state.value, true);
  9535. }
  9536. this.expect(75);
  9537. return this.tsParseEnumDeclaration(nany, {
  9538. const: true,
  9539. declare: true
  9540. });
  9541. case 129:
  9542. {
  9543. const result = this.tsParseInterfaceDeclaration(nany, {
  9544. declare: true
  9545. });
  9546. if (result) return result;
  9547. }
  9548. default:
  9549. if (tokenIsIdentifier(startType)) {
  9550. return this.tsParseDeclaration(nany, this.state.value, true, null);
  9551. }
  9552. }
  9553. });
  9554. }
  9555. tsTryParseExportDeclaration() {
  9556. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  9557. }
  9558. tsParseExpressionStatement(node, expr, decorators) {
  9559. switch (expr.name) {
  9560. case "declare":
  9561. {
  9562. const declaration = this.tsTryParseDeclare(node);
  9563. if (declaration) {
  9564. declaration.declare = true;
  9565. }
  9566. return declaration;
  9567. }
  9568. case "global":
  9569. if (this.match(5)) {
  9570. this.scope.enter(256);
  9571. this.prodParam.enter(0);
  9572. const mod = node;
  9573. mod.global = true;
  9574. mod.id = expr;
  9575. mod.body = this.tsParseModuleBlock();
  9576. this.scope.exit();
  9577. this.prodParam.exit();
  9578. return this.finishNode(mod, "TSModuleDeclaration");
  9579. }
  9580. break;
  9581. default:
  9582. return this.tsParseDeclaration(node, expr.name, false, decorators);
  9583. }
  9584. }
  9585. tsParseDeclaration(node, value, next, decorators) {
  9586. switch (value) {
  9587. case "abstract":
  9588. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  9589. return this.tsParseAbstractDeclaration(node, decorators);
  9590. }
  9591. break;
  9592. case "module":
  9593. if (this.tsCheckLineTerminator(next)) {
  9594. if (this.match(133)) {
  9595. return this.tsParseAmbientExternalModuleDeclaration(node);
  9596. } else if (tokenIsIdentifier(this.state.type)) {
  9597. return this.tsParseModuleOrNamespaceDeclaration(node);
  9598. }
  9599. }
  9600. break;
  9601. case "namespace":
  9602. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9603. return this.tsParseModuleOrNamespaceDeclaration(node);
  9604. }
  9605. break;
  9606. case "type":
  9607. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  9608. return this.tsParseTypeAliasDeclaration(node);
  9609. }
  9610. break;
  9611. }
  9612. }
  9613. tsCheckLineTerminator(next) {
  9614. if (next) {
  9615. if (this.hasFollowingLineBreak()) return false;
  9616. this.next();
  9617. return true;
  9618. }
  9619. return !this.isLineTerminator();
  9620. }
  9621. tsTryParseGenericAsyncArrowFunction(startLoc) {
  9622. if (!this.match(47)) return;
  9623. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  9624. this.state.maybeInArrowParameters = true;
  9625. const res = this.tsTryParseAndCatch(() => {
  9626. const node = this.startNodeAt(startLoc);
  9627. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9628. super.parseFunctionParams(node);
  9629. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  9630. this.expect(19);
  9631. return node;
  9632. });
  9633. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  9634. if (!res) return;
  9635. return super.parseArrowExpression(res, null, true);
  9636. }
  9637. tsParseTypeArgumentsInExpression() {
  9638. if (this.reScan_lt() !== 47) return;
  9639. return this.tsParseTypeArguments();
  9640. }
  9641. tsParseTypeArguments() {
  9642. const node = this.startNode();
  9643. node.params = this.tsInType(() => this.tsInNoContext(() => {
  9644. this.expect(47);
  9645. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  9646. }));
  9647. if (node.params.length === 0) {
  9648. this.raise(TSErrors.EmptyTypeArguments, {
  9649. at: node
  9650. });
  9651. } else if (!this.state.inType && this.curContext() === types$1.brace) {
  9652. this.reScan_lt_gt();
  9653. }
  9654. this.expect(48);
  9655. return this.finishNode(node, "TSTypeParameterInstantiation");
  9656. }
  9657. tsIsDeclarationStart() {
  9658. return tokenIsTSDeclarationStart(this.state.type);
  9659. }
  9660. isExportDefaultSpecifier() {
  9661. if (this.tsIsDeclarationStart()) return false;
  9662. return super.isExportDefaultSpecifier();
  9663. }
  9664. parseAssignableListItem(flags, decorators) {
  9665. const startLoc = this.state.startLoc;
  9666. const modified = {};
  9667. this.tsParseModifiers({
  9668. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9669. }, modified);
  9670. const accessibility = modified.accessibility;
  9671. const override = modified.override;
  9672. const readonly = modified.readonly;
  9673. if (!(flags & 4) && (accessibility || readonly || override)) {
  9674. this.raise(TSErrors.UnexpectedParameterModifier, {
  9675. at: startLoc
  9676. });
  9677. }
  9678. const left = this.parseMaybeDefault();
  9679. this.parseAssignableListItemTypes(left, flags);
  9680. const elt = this.parseMaybeDefault(left.loc.start, left);
  9681. if (accessibility || readonly || override) {
  9682. const pp = this.startNodeAt(startLoc);
  9683. if (decorators.length) {
  9684. pp.decorators = decorators;
  9685. }
  9686. if (accessibility) pp.accessibility = accessibility;
  9687. if (readonly) pp.readonly = readonly;
  9688. if (override) pp.override = override;
  9689. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9690. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  9691. at: pp
  9692. });
  9693. }
  9694. pp.parameter = elt;
  9695. return this.finishNode(pp, "TSParameterProperty");
  9696. }
  9697. if (decorators.length) {
  9698. left.decorators = decorators;
  9699. }
  9700. return elt;
  9701. }
  9702. isSimpleParameter(node) {
  9703. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9704. }
  9705. tsDisallowOptionalPattern(node) {
  9706. for (const param of node.params) {
  9707. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9708. this.raise(TSErrors.PatternIsOptional, {
  9709. at: param
  9710. });
  9711. }
  9712. }
  9713. }
  9714. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9715. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9716. this.tsDisallowOptionalPattern(node);
  9717. }
  9718. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9719. if (this.match(14)) {
  9720. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9721. }
  9722. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9723. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9724. return this.finishNode(node, bodilessType);
  9725. }
  9726. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9727. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  9728. at: node
  9729. });
  9730. if (node.declare) {
  9731. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9732. }
  9733. }
  9734. this.tsDisallowOptionalPattern(node);
  9735. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9736. }
  9737. registerFunctionStatementId(node) {
  9738. if (!node.body && node.id) {
  9739. this.checkIdentifier(node.id, 1024);
  9740. } else {
  9741. super.registerFunctionStatementId(node);
  9742. }
  9743. }
  9744. tsCheckForInvalidTypeCasts(items) {
  9745. items.forEach(node => {
  9746. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9747. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  9748. at: node.typeAnnotation
  9749. });
  9750. }
  9751. });
  9752. }
  9753. toReferencedList(exprList, isInParens) {
  9754. this.tsCheckForInvalidTypeCasts(exprList);
  9755. return exprList;
  9756. }
  9757. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9758. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9759. if (node.type === "ArrayExpression") {
  9760. this.tsCheckForInvalidTypeCasts(node.elements);
  9761. }
  9762. return node;
  9763. }
  9764. parseSubscript(base, startLoc, noCalls, state) {
  9765. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9766. this.state.canStartJSXElement = false;
  9767. this.next();
  9768. const nonNullExpression = this.startNodeAt(startLoc);
  9769. nonNullExpression.expression = base;
  9770. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9771. }
  9772. let isOptionalCall = false;
  9773. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9774. if (noCalls) {
  9775. state.stop = true;
  9776. return base;
  9777. }
  9778. state.optionalChainMember = isOptionalCall = true;
  9779. this.next();
  9780. }
  9781. if (this.match(47) || this.match(51)) {
  9782. let missingParenErrorLoc;
  9783. const result = this.tsTryParseAndCatch(() => {
  9784. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9785. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9786. if (asyncArrowFn) {
  9787. return asyncArrowFn;
  9788. }
  9789. }
  9790. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9791. if (!typeArguments) return;
  9792. if (isOptionalCall && !this.match(10)) {
  9793. missingParenErrorLoc = this.state.curPosition();
  9794. return;
  9795. }
  9796. if (tokenIsTemplate(this.state.type)) {
  9797. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9798. result.typeParameters = typeArguments;
  9799. return result;
  9800. }
  9801. if (!noCalls && this.eat(10)) {
  9802. const node = this.startNodeAt(startLoc);
  9803. node.callee = base;
  9804. node.arguments = this.parseCallExpressionArguments(11, false);
  9805. this.tsCheckForInvalidTypeCasts(node.arguments);
  9806. node.typeParameters = typeArguments;
  9807. if (state.optionalChainMember) {
  9808. node.optional = isOptionalCall;
  9809. }
  9810. return this.finishCallExpression(node, state.optionalChainMember);
  9811. }
  9812. const tokenType = this.state.type;
  9813. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9814. return;
  9815. }
  9816. const node = this.startNodeAt(startLoc);
  9817. node.expression = base;
  9818. node.typeParameters = typeArguments;
  9819. return this.finishNode(node, "TSInstantiationExpression");
  9820. });
  9821. if (missingParenErrorLoc) {
  9822. this.unexpected(missingParenErrorLoc, 10);
  9823. }
  9824. if (result) {
  9825. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9826. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  9827. at: this.state.startLoc
  9828. });
  9829. }
  9830. return result;
  9831. }
  9832. }
  9833. return super.parseSubscript(base, startLoc, noCalls, state);
  9834. }
  9835. parseNewCallee(node) {
  9836. var _callee$extra;
  9837. super.parseNewCallee(node);
  9838. const {
  9839. callee
  9840. } = node;
  9841. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9842. node.typeParameters = callee.typeParameters;
  9843. node.callee = callee.expression;
  9844. }
  9845. }
  9846. parseExprOp(left, leftStartLoc, minPrec) {
  9847. let isSatisfies;
  9848. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9849. const node = this.startNodeAt(leftStartLoc);
  9850. node.expression = left;
  9851. node.typeAnnotation = this.tsInType(() => {
  9852. this.next();
  9853. if (this.match(75)) {
  9854. if (isSatisfies) {
  9855. this.raise(Errors.UnexpectedKeyword, {
  9856. at: this.state.startLoc,
  9857. keyword: "const"
  9858. });
  9859. }
  9860. return this.tsParseTypeReference();
  9861. }
  9862. return this.tsParseType();
  9863. });
  9864. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9865. this.reScan_lt_gt();
  9866. return this.parseExprOp(node, leftStartLoc, minPrec);
  9867. }
  9868. return super.parseExprOp(left, leftStartLoc, minPrec);
  9869. }
  9870. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9871. if (!this.state.isAmbientContext) {
  9872. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9873. }
  9874. }
  9875. checkImportReflection(node) {
  9876. super.checkImportReflection(node);
  9877. if (node.module && node.importKind !== "value") {
  9878. this.raise(TSErrors.ImportReflectionHasImportType, {
  9879. at: node.specifiers[0].loc.start
  9880. });
  9881. }
  9882. }
  9883. checkDuplicateExports() {}
  9884. isPotentialImportPhase(isExport) {
  9885. if (super.isPotentialImportPhase(isExport)) return true;
  9886. if (this.isContextual(130)) {
  9887. const ch = this.lookaheadCharCode();
  9888. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9889. }
  9890. return !isExport && this.isContextual(87);
  9891. }
  9892. applyImportPhase(node, isExport, phase, loc) {
  9893. super.applyImportPhase(node, isExport, phase, loc);
  9894. if (isExport) {
  9895. node.exportKind = phase === "type" ? "type" : "value";
  9896. } else {
  9897. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9898. }
  9899. }
  9900. parseImport(node) {
  9901. if (this.match(133)) {
  9902. node.importKind = "value";
  9903. return super.parseImport(node);
  9904. }
  9905. let importNode;
  9906. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9907. node.importKind = "value";
  9908. return this.tsParseImportEqualsDeclaration(node);
  9909. } else if (this.isContextual(130)) {
  9910. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9911. if (this.lookaheadCharCode() === 61) {
  9912. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9913. } else {
  9914. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9915. }
  9916. } else {
  9917. importNode = super.parseImport(node);
  9918. }
  9919. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9920. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  9921. at: importNode
  9922. });
  9923. }
  9924. return importNode;
  9925. }
  9926. parseExport(node, decorators) {
  9927. if (this.match(83)) {
  9928. this.next();
  9929. let maybeDefaultIdentifier = null;
  9930. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9931. maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9932. } else {
  9933. node.importKind = "value";
  9934. }
  9935. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true);
  9936. } else if (this.eat(29)) {
  9937. const assign = node;
  9938. assign.expression = super.parseExpression();
  9939. this.semicolon();
  9940. this.sawUnambiguousESM = true;
  9941. return this.finishNode(assign, "TSExportAssignment");
  9942. } else if (this.eatContextual(93)) {
  9943. const decl = node;
  9944. this.expectContextual(128);
  9945. decl.id = this.parseIdentifier();
  9946. this.semicolon();
  9947. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9948. } else {
  9949. return super.parseExport(node, decorators);
  9950. }
  9951. }
  9952. isAbstractClass() {
  9953. return this.isContextual(124) && this.lookahead().type === 80;
  9954. }
  9955. parseExportDefaultExpression() {
  9956. if (this.isAbstractClass()) {
  9957. const cls = this.startNode();
  9958. this.next();
  9959. cls.abstract = true;
  9960. return this.parseClass(cls, true, true);
  9961. }
  9962. if (this.match(129)) {
  9963. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9964. if (result) return result;
  9965. }
  9966. return super.parseExportDefaultExpression();
  9967. }
  9968. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9969. const {
  9970. isAmbientContext
  9971. } = this.state;
  9972. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9973. if (!isAmbientContext) return declaration;
  9974. for (const {
  9975. id,
  9976. init
  9977. } of declaration.declarations) {
  9978. if (!init) continue;
  9979. if (kind !== "const" || !!id.typeAnnotation) {
  9980. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  9981. at: init
  9982. });
  9983. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9984. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  9985. at: init
  9986. });
  9987. }
  9988. }
  9989. return declaration;
  9990. }
  9991. parseStatementContent(flags, decorators) {
  9992. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9993. const node = this.startNode();
  9994. this.expect(75);
  9995. return this.tsParseEnumDeclaration(node, {
  9996. const: true
  9997. });
  9998. }
  9999. if (this.isContextual(126)) {
  10000. return this.tsParseEnumDeclaration(this.startNode());
  10001. }
  10002. if (this.isContextual(129)) {
  10003. const result = this.tsParseInterfaceDeclaration(this.startNode());
  10004. if (result) return result;
  10005. }
  10006. return super.parseStatementContent(flags, decorators);
  10007. }
  10008. parseAccessModifier() {
  10009. return this.tsParseModifier(["public", "protected", "private"]);
  10010. }
  10011. tsHasSomeModifiers(member, modifiers) {
  10012. return modifiers.some(modifier => {
  10013. if (tsIsAccessModifier(modifier)) {
  10014. return member.accessibility === modifier;
  10015. }
  10016. return !!member[modifier];
  10017. });
  10018. }
  10019. tsIsStartOfStaticBlocks() {
  10020. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  10021. }
  10022. parseClassMember(classBody, member, state) {
  10023. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  10024. this.tsParseModifiers({
  10025. allowedModifiers: modifiers,
  10026. disallowedModifiers: ["in", "out"],
  10027. stopOnStartOfClassStaticBlock: true,
  10028. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  10029. }, member);
  10030. const callParseClassMemberWithIsStatic = () => {
  10031. if (this.tsIsStartOfStaticBlocks()) {
  10032. this.next();
  10033. this.next();
  10034. if (this.tsHasSomeModifiers(member, modifiers)) {
  10035. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  10036. at: this.state.curPosition()
  10037. });
  10038. }
  10039. super.parseClassStaticBlock(classBody, member);
  10040. } else {
  10041. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  10042. }
  10043. };
  10044. if (member.declare) {
  10045. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  10046. } else {
  10047. callParseClassMemberWithIsStatic();
  10048. }
  10049. }
  10050. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  10051. const idx = this.tsTryParseIndexSignature(member);
  10052. if (idx) {
  10053. classBody.body.push(idx);
  10054. if (member.abstract) {
  10055. this.raise(TSErrors.IndexSignatureHasAbstract, {
  10056. at: member
  10057. });
  10058. }
  10059. if (member.accessibility) {
  10060. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  10061. at: member,
  10062. modifier: member.accessibility
  10063. });
  10064. }
  10065. if (member.declare) {
  10066. this.raise(TSErrors.IndexSignatureHasDeclare, {
  10067. at: member
  10068. });
  10069. }
  10070. if (member.override) {
  10071. this.raise(TSErrors.IndexSignatureHasOverride, {
  10072. at: member
  10073. });
  10074. }
  10075. return;
  10076. }
  10077. if (!this.state.inAbstractClass && member.abstract) {
  10078. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  10079. at: member
  10080. });
  10081. }
  10082. if (member.override) {
  10083. if (!state.hadSuperClass) {
  10084. this.raise(TSErrors.OverrideNotInSubClass, {
  10085. at: member
  10086. });
  10087. }
  10088. }
  10089. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  10090. }
  10091. parsePostMemberNameModifiers(methodOrProp) {
  10092. const optional = this.eat(17);
  10093. if (optional) methodOrProp.optional = true;
  10094. if (methodOrProp.readonly && this.match(10)) {
  10095. this.raise(TSErrors.ClassMethodHasReadonly, {
  10096. at: methodOrProp
  10097. });
  10098. }
  10099. if (methodOrProp.declare && this.match(10)) {
  10100. this.raise(TSErrors.ClassMethodHasDeclare, {
  10101. at: methodOrProp
  10102. });
  10103. }
  10104. }
  10105. parseExpressionStatement(node, expr, decorators) {
  10106. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  10107. return decl || super.parseExpressionStatement(node, expr, decorators);
  10108. }
  10109. shouldParseExportDeclaration() {
  10110. if (this.tsIsDeclarationStart()) return true;
  10111. return super.shouldParseExportDeclaration();
  10112. }
  10113. parseConditional(expr, startLoc, refExpressionErrors) {
  10114. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  10115. return super.parseConditional(expr, startLoc, refExpressionErrors);
  10116. }
  10117. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  10118. if (!result.node) {
  10119. if (result.error) {
  10120. super.setOptionalParametersError(refExpressionErrors, result.error);
  10121. }
  10122. return expr;
  10123. }
  10124. if (result.error) this.state = result.failState;
  10125. return result.node;
  10126. }
  10127. parseParenItem(node, startLoc) {
  10128. node = super.parseParenItem(node, startLoc);
  10129. if (this.eat(17)) {
  10130. node.optional = true;
  10131. this.resetEndLocation(node);
  10132. }
  10133. if (this.match(14)) {
  10134. const typeCastNode = this.startNodeAt(startLoc);
  10135. typeCastNode.expression = node;
  10136. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  10137. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  10138. }
  10139. return node;
  10140. }
  10141. parseExportDeclaration(node) {
  10142. if (!this.state.isAmbientContext && this.isContextual(125)) {
  10143. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  10144. }
  10145. const startLoc = this.state.startLoc;
  10146. const isDeclare = this.eatContextual(125);
  10147. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  10148. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  10149. at: this.state.startLoc
  10150. });
  10151. }
  10152. const isIdentifier = tokenIsIdentifier(this.state.type);
  10153. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  10154. if (!declaration) return null;
  10155. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  10156. node.exportKind = "type";
  10157. }
  10158. if (isDeclare) {
  10159. this.resetStartLocation(declaration, startLoc);
  10160. declaration.declare = true;
  10161. }
  10162. return declaration;
  10163. }
  10164. parseClassId(node, isStatement, optionalId, bindingType) {
  10165. if ((!isStatement || optionalId) && this.isContextual(113)) {
  10166. return;
  10167. }
  10168. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  10169. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  10170. if (typeParameters) node.typeParameters = typeParameters;
  10171. }
  10172. parseClassPropertyAnnotation(node) {
  10173. if (!node.optional) {
  10174. if (this.eat(35)) {
  10175. node.definite = true;
  10176. } else if (this.eat(17)) {
  10177. node.optional = true;
  10178. }
  10179. }
  10180. const type = this.tsTryParseTypeAnnotation();
  10181. if (type) node.typeAnnotation = type;
  10182. }
  10183. parseClassProperty(node) {
  10184. this.parseClassPropertyAnnotation(node);
  10185. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  10186. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  10187. at: this.state.startLoc
  10188. });
  10189. }
  10190. if (node.abstract && this.match(29)) {
  10191. const {
  10192. key
  10193. } = node;
  10194. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  10195. at: this.state.startLoc,
  10196. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  10197. });
  10198. }
  10199. return super.parseClassProperty(node);
  10200. }
  10201. parseClassPrivateProperty(node) {
  10202. if (node.abstract) {
  10203. this.raise(TSErrors.PrivateElementHasAbstract, {
  10204. at: node
  10205. });
  10206. }
  10207. if (node.accessibility) {
  10208. this.raise(TSErrors.PrivateElementHasAccessibility, {
  10209. at: node,
  10210. modifier: node.accessibility
  10211. });
  10212. }
  10213. this.parseClassPropertyAnnotation(node);
  10214. return super.parseClassPrivateProperty(node);
  10215. }
  10216. parseClassAccessorProperty(node) {
  10217. this.parseClassPropertyAnnotation(node);
  10218. if (node.optional) {
  10219. this.raise(TSErrors.AccessorCannotBeOptional, {
  10220. at: node
  10221. });
  10222. }
  10223. return super.parseClassAccessorProperty(node);
  10224. }
  10225. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  10226. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10227. if (typeParameters && isConstructor) {
  10228. this.raise(TSErrors.ConstructorHasTypeParameters, {
  10229. at: typeParameters
  10230. });
  10231. }
  10232. const {
  10233. declare = false,
  10234. kind
  10235. } = method;
  10236. if (declare && (kind === "get" || kind === "set")) {
  10237. this.raise(TSErrors.DeclareAccessor, {
  10238. at: method,
  10239. kind
  10240. });
  10241. }
  10242. if (typeParameters) method.typeParameters = typeParameters;
  10243. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  10244. }
  10245. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  10246. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10247. if (typeParameters) method.typeParameters = typeParameters;
  10248. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  10249. }
  10250. declareClassPrivateMethodInScope(node, kind) {
  10251. if (node.type === "TSDeclareMethod") return;
  10252. if (node.type === "MethodDefinition" && !node.value.body) return;
  10253. super.declareClassPrivateMethodInScope(node, kind);
  10254. }
  10255. parseClassSuper(node) {
  10256. super.parseClassSuper(node);
  10257. if (node.superClass && (this.match(47) || this.match(51))) {
  10258. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  10259. }
  10260. if (this.eatContextual(113)) {
  10261. node.implements = this.tsParseHeritageClause("implements");
  10262. }
  10263. }
  10264. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  10265. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10266. if (typeParameters) prop.typeParameters = typeParameters;
  10267. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  10268. }
  10269. parseFunctionParams(node, isConstructor) {
  10270. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10271. if (typeParameters) node.typeParameters = typeParameters;
  10272. super.parseFunctionParams(node, isConstructor);
  10273. }
  10274. parseVarId(decl, kind) {
  10275. super.parseVarId(decl, kind);
  10276. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  10277. decl.definite = true;
  10278. }
  10279. const type = this.tsTryParseTypeAnnotation();
  10280. if (type) {
  10281. decl.id.typeAnnotation = type;
  10282. this.resetEndLocation(decl.id);
  10283. }
  10284. }
  10285. parseAsyncArrowFromCallExpression(node, call) {
  10286. if (this.match(14)) {
  10287. node.returnType = this.tsParseTypeAnnotation();
  10288. }
  10289. return super.parseAsyncArrowFromCallExpression(node, call);
  10290. }
  10291. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10292. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  10293. let state;
  10294. let jsx;
  10295. let typeCast;
  10296. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  10297. state = this.state.clone();
  10298. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  10299. if (!jsx.error) return jsx.node;
  10300. const {
  10301. context
  10302. } = this.state;
  10303. const currentContext = context[context.length - 1];
  10304. if (currentContext === types$1.j_oTag || currentContext === types$1.j_expr) {
  10305. context.pop();
  10306. }
  10307. }
  10308. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  10309. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  10310. }
  10311. if (!state || state === this.state) state = this.state.clone();
  10312. let typeParameters;
  10313. const arrow = this.tryParse(abort => {
  10314. var _expr$extra, _typeParameters;
  10315. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  10316. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  10317. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10318. abort();
  10319. }
  10320. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  10321. this.resetStartLocationFromNode(expr, typeParameters);
  10322. }
  10323. expr.typeParameters = typeParameters;
  10324. return expr;
  10325. }, state);
  10326. if (!arrow.error && !arrow.aborted) {
  10327. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  10328. return arrow.node;
  10329. }
  10330. if (!jsx) {
  10331. assert$1(!this.hasPlugin("jsx"));
  10332. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  10333. if (!typeCast.error) return typeCast.node;
  10334. }
  10335. if ((_jsx2 = jsx) != null && _jsx2.node) {
  10336. this.state = jsx.failState;
  10337. return jsx.node;
  10338. }
  10339. if (arrow.node) {
  10340. this.state = arrow.failState;
  10341. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  10342. return arrow.node;
  10343. }
  10344. if ((_typeCast = typeCast) != null && _typeCast.node) {
  10345. this.state = typeCast.failState;
  10346. return typeCast.node;
  10347. }
  10348. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  10349. }
  10350. reportReservedArrowTypeParam(node) {
  10351. var _node$extra;
  10352. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  10353. this.raise(TSErrors.ReservedArrowTypeParam, {
  10354. at: node
  10355. });
  10356. }
  10357. }
  10358. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10359. if (!this.hasPlugin("jsx") && this.match(47)) {
  10360. return this.tsParseTypeAssertion();
  10361. }
  10362. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  10363. }
  10364. parseArrow(node) {
  10365. if (this.match(14)) {
  10366. const result = this.tryParse(abort => {
  10367. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  10368. if (this.canInsertSemicolon() || !this.match(19)) abort();
  10369. return returnType;
  10370. });
  10371. if (result.aborted) return;
  10372. if (!result.thrown) {
  10373. if (result.error) this.state = result.failState;
  10374. node.returnType = result.node;
  10375. }
  10376. }
  10377. return super.parseArrow(node);
  10378. }
  10379. parseAssignableListItemTypes(param, flags) {
  10380. if (!(flags & 2)) return param;
  10381. if (this.eat(17)) {
  10382. param.optional = true;
  10383. }
  10384. const type = this.tsTryParseTypeAnnotation();
  10385. if (type) param.typeAnnotation = type;
  10386. this.resetEndLocation(param);
  10387. return param;
  10388. }
  10389. isAssignable(node, isBinding) {
  10390. switch (node.type) {
  10391. case "TSTypeCastExpression":
  10392. return this.isAssignable(node.expression, isBinding);
  10393. case "TSParameterProperty":
  10394. return true;
  10395. default:
  10396. return super.isAssignable(node, isBinding);
  10397. }
  10398. }
  10399. toAssignable(node, isLHS = false) {
  10400. switch (node.type) {
  10401. case "ParenthesizedExpression":
  10402. this.toAssignableParenthesizedExpression(node, isLHS);
  10403. break;
  10404. case "TSAsExpression":
  10405. case "TSSatisfiesExpression":
  10406. case "TSNonNullExpression":
  10407. case "TSTypeAssertion":
  10408. if (isLHS) {
  10409. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  10410. at: node
  10411. });
  10412. } else {
  10413. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  10414. at: node
  10415. });
  10416. }
  10417. this.toAssignable(node.expression, isLHS);
  10418. break;
  10419. case "AssignmentExpression":
  10420. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  10421. node.left = this.typeCastToParameter(node.left);
  10422. }
  10423. default:
  10424. super.toAssignable(node, isLHS);
  10425. }
  10426. }
  10427. toAssignableParenthesizedExpression(node, isLHS) {
  10428. switch (node.expression.type) {
  10429. case "TSAsExpression":
  10430. case "TSSatisfiesExpression":
  10431. case "TSNonNullExpression":
  10432. case "TSTypeAssertion":
  10433. case "ParenthesizedExpression":
  10434. this.toAssignable(node.expression, isLHS);
  10435. break;
  10436. default:
  10437. super.toAssignable(node, isLHS);
  10438. }
  10439. }
  10440. checkToRestConversion(node, allowPattern) {
  10441. switch (node.type) {
  10442. case "TSAsExpression":
  10443. case "TSSatisfiesExpression":
  10444. case "TSTypeAssertion":
  10445. case "TSNonNullExpression":
  10446. this.checkToRestConversion(node.expression, false);
  10447. break;
  10448. default:
  10449. super.checkToRestConversion(node, allowPattern);
  10450. }
  10451. }
  10452. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  10453. return getOwn({
  10454. TSTypeCastExpression: true,
  10455. TSParameterProperty: "parameter",
  10456. TSNonNullExpression: "expression",
  10457. TSAsExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  10458. TSSatisfiesExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  10459. TSTypeAssertion: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true]
  10460. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  10461. }
  10462. parseBindingAtom() {
  10463. if (this.state.type === 78) {
  10464. return this.parseIdentifier(true);
  10465. }
  10466. return super.parseBindingAtom();
  10467. }
  10468. parseMaybeDecoratorArguments(expr) {
  10469. if (this.match(47) || this.match(51)) {
  10470. const typeArguments = this.tsParseTypeArgumentsInExpression();
  10471. if (this.match(10)) {
  10472. const call = super.parseMaybeDecoratorArguments(expr);
  10473. call.typeParameters = typeArguments;
  10474. return call;
  10475. }
  10476. this.unexpected(null, 10);
  10477. }
  10478. return super.parseMaybeDecoratorArguments(expr);
  10479. }
  10480. checkCommaAfterRest(close) {
  10481. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  10482. this.next();
  10483. return false;
  10484. }
  10485. return super.checkCommaAfterRest(close);
  10486. }
  10487. isClassMethod() {
  10488. return this.match(47) || super.isClassMethod();
  10489. }
  10490. isClassProperty() {
  10491. return this.match(35) || this.match(14) || super.isClassProperty();
  10492. }
  10493. parseMaybeDefault(startLoc, left) {
  10494. const node = super.parseMaybeDefault(startLoc, left);
  10495. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  10496. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  10497. at: node.typeAnnotation
  10498. });
  10499. }
  10500. return node;
  10501. }
  10502. getTokenFromCode(code) {
  10503. if (this.state.inType) {
  10504. if (code === 62) {
  10505. this.finishOp(48, 1);
  10506. return;
  10507. }
  10508. if (code === 60) {
  10509. this.finishOp(47, 1);
  10510. return;
  10511. }
  10512. }
  10513. super.getTokenFromCode(code);
  10514. }
  10515. reScan_lt_gt() {
  10516. const {
  10517. type
  10518. } = this.state;
  10519. if (type === 47) {
  10520. this.state.pos -= 1;
  10521. this.readToken_lt();
  10522. } else if (type === 48) {
  10523. this.state.pos -= 1;
  10524. this.readToken_gt();
  10525. }
  10526. }
  10527. reScan_lt() {
  10528. const {
  10529. type
  10530. } = this.state;
  10531. if (type === 51) {
  10532. this.state.pos -= 2;
  10533. this.finishOp(47, 1);
  10534. return 47;
  10535. }
  10536. return type;
  10537. }
  10538. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  10539. for (let i = 0; i < exprList.length; i++) {
  10540. const expr = exprList[i];
  10541. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  10542. exprList[i] = this.typeCastToParameter(expr);
  10543. }
  10544. }
  10545. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  10546. }
  10547. typeCastToParameter(node) {
  10548. node.expression.typeAnnotation = node.typeAnnotation;
  10549. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  10550. return node.expression;
  10551. }
  10552. shouldParseArrow(params) {
  10553. if (this.match(14)) {
  10554. return params.every(expr => this.isAssignable(expr, true));
  10555. }
  10556. return super.shouldParseArrow(params);
  10557. }
  10558. shouldParseAsyncArrow() {
  10559. return this.match(14) || super.shouldParseAsyncArrow();
  10560. }
  10561. canHaveLeadingDecorator() {
  10562. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  10563. }
  10564. jsxParseOpeningElementAfterName(node) {
  10565. if (this.match(47) || this.match(51)) {
  10566. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  10567. if (typeArguments) node.typeParameters = typeArguments;
  10568. }
  10569. return super.jsxParseOpeningElementAfterName(node);
  10570. }
  10571. getGetterSetterExpectedParamCount(method) {
  10572. const baseCount = super.getGetterSetterExpectedParamCount(method);
  10573. const params = this.getObjectOrClassMethodParams(method);
  10574. const firstParam = params[0];
  10575. const hasContextParam = firstParam && this.isThisParam(firstParam);
  10576. return hasContextParam ? baseCount + 1 : baseCount;
  10577. }
  10578. parseCatchClauseParam() {
  10579. const param = super.parseCatchClauseParam();
  10580. const type = this.tsTryParseTypeAnnotation();
  10581. if (type) {
  10582. param.typeAnnotation = type;
  10583. this.resetEndLocation(param);
  10584. }
  10585. return param;
  10586. }
  10587. tsInAmbientContext(cb) {
  10588. const oldIsAmbientContext = this.state.isAmbientContext;
  10589. this.state.isAmbientContext = true;
  10590. try {
  10591. return cb();
  10592. } finally {
  10593. this.state.isAmbientContext = oldIsAmbientContext;
  10594. }
  10595. }
  10596. parseClass(node, isStatement, optionalId) {
  10597. const oldInAbstractClass = this.state.inAbstractClass;
  10598. this.state.inAbstractClass = !!node.abstract;
  10599. try {
  10600. return super.parseClass(node, isStatement, optionalId);
  10601. } finally {
  10602. this.state.inAbstractClass = oldInAbstractClass;
  10603. }
  10604. }
  10605. tsParseAbstractDeclaration(node, decorators) {
  10606. if (this.match(80)) {
  10607. node.abstract = true;
  10608. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  10609. } else if (this.isContextual(129)) {
  10610. if (!this.hasFollowingLineBreak()) {
  10611. node.abstract = true;
  10612. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  10613. at: node
  10614. });
  10615. return this.tsParseInterfaceDeclaration(node);
  10616. }
  10617. } else {
  10618. this.unexpected(null, 80);
  10619. }
  10620. }
  10621. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  10622. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  10623. if (method.abstract) {
  10624. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  10625. if (hasBody) {
  10626. const {
  10627. key
  10628. } = method;
  10629. this.raise(TSErrors.AbstractMethodHasImplementation, {
  10630. at: method,
  10631. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  10632. });
  10633. }
  10634. }
  10635. return method;
  10636. }
  10637. tsParseTypeParameterName() {
  10638. const typeName = this.parseIdentifier();
  10639. return typeName.name;
  10640. }
  10641. shouldParseAsAmbientContext() {
  10642. return !!this.getPluginOption("typescript", "dts");
  10643. }
  10644. parse() {
  10645. if (this.shouldParseAsAmbientContext()) {
  10646. this.state.isAmbientContext = true;
  10647. }
  10648. return super.parse();
  10649. }
  10650. getExpression() {
  10651. if (this.shouldParseAsAmbientContext()) {
  10652. this.state.isAmbientContext = true;
  10653. }
  10654. return super.getExpression();
  10655. }
  10656. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  10657. if (!isString && isMaybeTypeOnly) {
  10658. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  10659. return this.finishNode(node, "ExportSpecifier");
  10660. }
  10661. node.exportKind = "value";
  10662. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10663. }
  10664. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10665. if (!importedIsString && isMaybeTypeOnly) {
  10666. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10667. return this.finishNode(specifier, "ImportSpecifier");
  10668. }
  10669. specifier.importKind = "value";
  10670. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10671. }
  10672. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10673. const leftOfAsKey = isImport ? "imported" : "local";
  10674. const rightOfAsKey = isImport ? "local" : "exported";
  10675. let leftOfAs = node[leftOfAsKey];
  10676. let rightOfAs;
  10677. let hasTypeSpecifier = false;
  10678. let canParseAsKeyword = true;
  10679. const loc = leftOfAs.loc.start;
  10680. if (this.isContextual(93)) {
  10681. const firstAs = this.parseIdentifier();
  10682. if (this.isContextual(93)) {
  10683. const secondAs = this.parseIdentifier();
  10684. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10685. hasTypeSpecifier = true;
  10686. leftOfAs = firstAs;
  10687. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10688. canParseAsKeyword = false;
  10689. } else {
  10690. rightOfAs = secondAs;
  10691. canParseAsKeyword = false;
  10692. }
  10693. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10694. canParseAsKeyword = false;
  10695. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10696. } else {
  10697. hasTypeSpecifier = true;
  10698. leftOfAs = firstAs;
  10699. }
  10700. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10701. hasTypeSpecifier = true;
  10702. if (isImport) {
  10703. leftOfAs = this.parseIdentifier(true);
  10704. if (!this.isContextual(93)) {
  10705. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10706. }
  10707. } else {
  10708. leftOfAs = this.parseModuleExportName();
  10709. }
  10710. }
  10711. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10712. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  10713. at: loc
  10714. });
  10715. }
  10716. node[leftOfAsKey] = leftOfAs;
  10717. node[rightOfAsKey] = rightOfAs;
  10718. const kindKey = isImport ? "importKind" : "exportKind";
  10719. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10720. if (canParseAsKeyword && this.eatContextual(93)) {
  10721. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10722. }
  10723. if (!node[rightOfAsKey]) {
  10724. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10725. }
  10726. if (isImport) {
  10727. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10728. }
  10729. }
  10730. };
  10731. function isPossiblyLiteralEnum(expression) {
  10732. if (expression.type !== "MemberExpression") return false;
  10733. const {
  10734. computed,
  10735. property
  10736. } = expression;
  10737. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10738. return false;
  10739. }
  10740. return isUncomputedMemberExpressionChain(expression.object);
  10741. }
  10742. function isValidAmbientConstInitializer(expression, estree) {
  10743. var _expression$extra;
  10744. const {
  10745. type
  10746. } = expression;
  10747. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10748. return false;
  10749. }
  10750. if (estree) {
  10751. if (type === "Literal") {
  10752. const {
  10753. value
  10754. } = expression;
  10755. if (typeof value === "string" || typeof value === "boolean") {
  10756. return true;
  10757. }
  10758. }
  10759. } else {
  10760. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10761. return true;
  10762. }
  10763. }
  10764. if (isNumber$1(expression, estree) || isNegativeNumber(expression, estree)) {
  10765. return true;
  10766. }
  10767. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10768. return true;
  10769. }
  10770. if (isPossiblyLiteralEnum(expression)) {
  10771. return true;
  10772. }
  10773. return false;
  10774. }
  10775. function isNumber$1(expression, estree) {
  10776. if (estree) {
  10777. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10778. }
  10779. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10780. }
  10781. function isNegativeNumber(expression, estree) {
  10782. if (expression.type === "UnaryExpression") {
  10783. const {
  10784. operator,
  10785. argument
  10786. } = expression;
  10787. if (operator === "-" && isNumber$1(argument, estree)) {
  10788. return true;
  10789. }
  10790. }
  10791. return false;
  10792. }
  10793. function isUncomputedMemberExpressionChain(expression) {
  10794. if (expression.type === "Identifier") return true;
  10795. if (expression.type !== "MemberExpression" || expression.computed) {
  10796. return false;
  10797. }
  10798. return isUncomputedMemberExpressionChain(expression.object);
  10799. }
  10800. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10801. ClassNameIsRequired: "A class name is required.",
  10802. UnexpectedSpace: "Unexpected space in placeholder."
  10803. });
  10804. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10805. parsePlaceholder(expectedNode) {
  10806. if (this.match(144)) {
  10807. const node = this.startNode();
  10808. this.next();
  10809. this.assertNoSpace();
  10810. node.name = super.parseIdentifier(true);
  10811. this.assertNoSpace();
  10812. this.expect(144);
  10813. return this.finishPlaceholder(node, expectedNode);
  10814. }
  10815. }
  10816. finishPlaceholder(node, expectedNode) {
  10817. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  10818. node.expectedNode = expectedNode;
  10819. return isFinished ? node : this.finishNode(node, "Placeholder");
  10820. }
  10821. getTokenFromCode(code) {
  10822. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10823. this.finishOp(144, 2);
  10824. } else {
  10825. super.getTokenFromCode(code);
  10826. }
  10827. }
  10828. parseExprAtom(refExpressionErrors) {
  10829. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10830. }
  10831. parseIdentifier(liberal) {
  10832. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10833. }
  10834. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10835. if (word !== undefined) {
  10836. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10837. }
  10838. }
  10839. parseBindingAtom() {
  10840. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10841. }
  10842. isValidLVal(type, isParenthesized, binding) {
  10843. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10844. }
  10845. toAssignable(node, isLHS) {
  10846. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10847. node.expectedNode = "Pattern";
  10848. } else {
  10849. super.toAssignable(node, isLHS);
  10850. }
  10851. }
  10852. chStartsBindingIdentifier(ch, pos) {
  10853. if (super.chStartsBindingIdentifier(ch, pos)) {
  10854. return true;
  10855. }
  10856. const nextToken = this.lookahead();
  10857. if (nextToken.type === 144) {
  10858. return true;
  10859. }
  10860. return false;
  10861. }
  10862. verifyBreakContinue(node, isBreak) {
  10863. if (node.label && node.label.type === "Placeholder") return;
  10864. super.verifyBreakContinue(node, isBreak);
  10865. }
  10866. parseExpressionStatement(node, expr) {
  10867. var _expr$extra;
  10868. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10869. return super.parseExpressionStatement(node, expr);
  10870. }
  10871. if (this.match(14)) {
  10872. const stmt = node;
  10873. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10874. this.next();
  10875. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10876. return this.finishNode(stmt, "LabeledStatement");
  10877. }
  10878. this.semicolon();
  10879. node.name = expr.name;
  10880. return this.finishPlaceholder(node, "Statement");
  10881. }
  10882. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10883. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10884. }
  10885. parseFunctionId(requireId) {
  10886. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10887. }
  10888. parseClass(node, isStatement, optionalId) {
  10889. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10890. this.next();
  10891. const oldStrict = this.state.strict;
  10892. const placeholder = this.parsePlaceholder("Identifier");
  10893. if (placeholder) {
  10894. if (this.match(81) || this.match(144) || this.match(5)) {
  10895. node.id = placeholder;
  10896. } else if (optionalId || !isStatement) {
  10897. node.id = null;
  10898. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10899. return this.finishNode(node, type);
  10900. } else {
  10901. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  10902. at: this.state.startLoc
  10903. });
  10904. }
  10905. } else {
  10906. this.parseClassId(node, isStatement, optionalId);
  10907. }
  10908. super.parseClassSuper(node);
  10909. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10910. return this.finishNode(node, type);
  10911. }
  10912. parseExport(node, decorators) {
  10913. const placeholder = this.parsePlaceholder("Identifier");
  10914. if (!placeholder) return super.parseExport(node, decorators);
  10915. if (!this.isContextual(98) && !this.match(12)) {
  10916. node.specifiers = [];
  10917. node.source = null;
  10918. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10919. return this.finishNode(node, "ExportNamedDeclaration");
  10920. }
  10921. this.expectPlugin("exportDefaultFrom");
  10922. const specifier = this.startNode();
  10923. specifier.exported = placeholder;
  10924. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10925. return super.parseExport(node, decorators);
  10926. }
  10927. isExportDefaultSpecifier() {
  10928. if (this.match(65)) {
  10929. const next = this.nextTokenStart();
  10930. if (this.isUnparsedContextual(next, "from")) {
  10931. if (this.input.startsWith(tokenLabelName(144), this.nextTokenStartSince(next + 4))) {
  10932. return true;
  10933. }
  10934. }
  10935. }
  10936. return super.isExportDefaultSpecifier();
  10937. }
  10938. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10939. var _specifiers;
  10940. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10941. return true;
  10942. }
  10943. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10944. }
  10945. checkExport(node) {
  10946. const {
  10947. specifiers
  10948. } = node;
  10949. if (specifiers != null && specifiers.length) {
  10950. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10951. }
  10952. super.checkExport(node);
  10953. node.specifiers = specifiers;
  10954. }
  10955. parseImport(node) {
  10956. const placeholder = this.parsePlaceholder("Identifier");
  10957. if (!placeholder) return super.parseImport(node);
  10958. node.specifiers = [];
  10959. if (!this.isContextual(98) && !this.match(12)) {
  10960. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10961. this.semicolon();
  10962. return this.finishNode(node, "ImportDeclaration");
  10963. }
  10964. const specifier = this.startNodeAtNode(placeholder);
  10965. specifier.local = placeholder;
  10966. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10967. if (this.eat(12)) {
  10968. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10969. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10970. }
  10971. this.expectContextual(98);
  10972. node.source = this.parseImportSource();
  10973. this.semicolon();
  10974. return this.finishNode(node, "ImportDeclaration");
  10975. }
  10976. parseImportSource() {
  10977. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10978. }
  10979. assertNoSpace() {
  10980. if (this.state.start > this.state.lastTokEndLoc.index) {
  10981. this.raise(PlaceholderErrors.UnexpectedSpace, {
  10982. at: this.state.lastTokEndLoc
  10983. });
  10984. }
  10985. }
  10986. };
  10987. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10988. parseV8Intrinsic() {
  10989. if (this.match(54)) {
  10990. const v8IntrinsicStartLoc = this.state.startLoc;
  10991. const node = this.startNode();
  10992. this.next();
  10993. if (tokenIsIdentifier(this.state.type)) {
  10994. const name = this.parseIdentifierName();
  10995. const identifier = this.createIdentifier(node, name);
  10996. identifier.type = "V8IntrinsicIdentifier";
  10997. if (this.match(10)) {
  10998. return identifier;
  10999. }
  11000. }
  11001. this.unexpected(v8IntrinsicStartLoc);
  11002. }
  11003. }
  11004. parseExprAtom(refExpressionErrors) {
  11005. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  11006. }
  11007. };
  11008. function hasPlugin(plugins, expectedConfig) {
  11009. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  11010. const expectedKeys = Object.keys(expectedOptions);
  11011. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  11012. return plugins.some(p => {
  11013. if (typeof p === "string") {
  11014. return expectedOptionsIsEmpty && p === expectedName;
  11015. } else {
  11016. const [pluginName, pluginOptions] = p;
  11017. if (pluginName !== expectedName) {
  11018. return false;
  11019. }
  11020. for (const key of expectedKeys) {
  11021. if (pluginOptions[key] !== expectedOptions[key]) {
  11022. return false;
  11023. }
  11024. }
  11025. return true;
  11026. }
  11027. });
  11028. }
  11029. function getPluginOption(plugins, name, option) {
  11030. const plugin = plugins.find(plugin => {
  11031. if (Array.isArray(plugin)) {
  11032. return plugin[0] === name;
  11033. } else {
  11034. return plugin === name;
  11035. }
  11036. });
  11037. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  11038. return plugin[1][option];
  11039. }
  11040. return null;
  11041. }
  11042. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  11043. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  11044. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  11045. function validatePlugins(plugins) {
  11046. if (hasPlugin(plugins, "decorators")) {
  11047. if (hasPlugin(plugins, "decorators-legacy")) {
  11048. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  11049. }
  11050. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  11051. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  11052. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  11053. }
  11054. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  11055. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  11056. throw new Error("'allowCallParenthesized' must be a boolean.");
  11057. }
  11058. }
  11059. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  11060. throw new Error("Cannot combine flow and typescript plugins.");
  11061. }
  11062. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  11063. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  11064. }
  11065. if (hasPlugin(plugins, "pipelineOperator")) {
  11066. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  11067. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  11068. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  11069. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  11070. }
  11071. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  11072. syntaxType: "hash"
  11073. }]);
  11074. if (proposal === "hack") {
  11075. if (hasPlugin(plugins, "placeholders")) {
  11076. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  11077. }
  11078. if (hasPlugin(plugins, "v8intrinsic")) {
  11079. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  11080. }
  11081. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  11082. if (!TOPIC_TOKENS.includes(topicToken)) {
  11083. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  11084. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  11085. }
  11086. if (topicToken === "#" && tupleSyntaxIsHash) {
  11087. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  11088. }
  11089. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  11090. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  11091. }
  11092. }
  11093. if (hasPlugin(plugins, "moduleAttributes")) {
  11094. {
  11095. if (hasPlugin(plugins, "importAssertions") || hasPlugin(plugins, "importAttributes")) {
  11096. throw new Error("Cannot combine importAssertions, importAttributes and moduleAttributes plugins.");
  11097. }
  11098. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  11099. if (moduleAttributesVersionPluginOption !== "may-2020") {
  11100. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  11101. }
  11102. }
  11103. }
  11104. if (hasPlugin(plugins, "importAssertions") && hasPlugin(plugins, "importAttributes")) {
  11105. throw new Error("Cannot combine importAssertions and importAttributes plugins.");
  11106. }
  11107. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  11108. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  11109. }
  11110. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  11111. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  11112. error.missingPlugins = "doExpressions";
  11113. throw error;
  11114. }
  11115. if (hasPlugin(plugins, "optionalChainingAssign") && getPluginOption(plugins, "optionalChainingAssign", "version") !== "2023-07") {
  11116. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  11117. }
  11118. }
  11119. const mixinPlugins = {
  11120. estree,
  11121. jsx,
  11122. flow,
  11123. typescript,
  11124. v8intrinsic,
  11125. placeholders
  11126. };
  11127. const mixinPluginNames = Object.keys(mixinPlugins);
  11128. const defaultOptions = {
  11129. sourceType: "script",
  11130. sourceFilename: undefined,
  11131. startColumn: 0,
  11132. startLine: 1,
  11133. allowAwaitOutsideFunction: false,
  11134. allowReturnOutsideFunction: false,
  11135. allowNewTargetOutsideFunction: false,
  11136. allowImportExportEverywhere: false,
  11137. allowSuperOutsideMethod: false,
  11138. allowUndeclaredExports: false,
  11139. plugins: [],
  11140. strictMode: null,
  11141. ranges: false,
  11142. tokens: false,
  11143. createImportExpressions: false,
  11144. createParenthesizedExpressions: false,
  11145. errorRecovery: false,
  11146. attachComment: true,
  11147. annexB: true
  11148. };
  11149. function getOptions(opts) {
  11150. if (opts == null) {
  11151. return Object.assign({}, defaultOptions);
  11152. }
  11153. if (opts.annexB != null && opts.annexB !== false) {
  11154. throw new Error("The `annexB` option can only be set to `false`.");
  11155. }
  11156. const options = {};
  11157. for (const key of Object.keys(defaultOptions)) {
  11158. var _opts$key;
  11159. options[key] = (_opts$key = opts[key]) != null ? _opts$key : defaultOptions[key];
  11160. }
  11161. return options;
  11162. }
  11163. class ExpressionParser extends LValParser {
  11164. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  11165. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  11166. return;
  11167. }
  11168. const key = prop.key;
  11169. const name = key.type === "Identifier" ? key.name : key.value;
  11170. if (name === "__proto__") {
  11171. if (isRecord) {
  11172. this.raise(Errors.RecordNoProto, {
  11173. at: key
  11174. });
  11175. return;
  11176. }
  11177. if (protoRef.used) {
  11178. if (refExpressionErrors) {
  11179. if (refExpressionErrors.doubleProtoLoc === null) {
  11180. refExpressionErrors.doubleProtoLoc = key.loc.start;
  11181. }
  11182. } else {
  11183. this.raise(Errors.DuplicateProto, {
  11184. at: key
  11185. });
  11186. }
  11187. }
  11188. protoRef.used = true;
  11189. }
  11190. }
  11191. shouldExitDescending(expr, potentialArrowAt) {
  11192. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  11193. }
  11194. getExpression() {
  11195. this.enterInitialScopes();
  11196. this.nextToken();
  11197. const expr = this.parseExpression();
  11198. if (!this.match(139)) {
  11199. this.unexpected();
  11200. }
  11201. this.finalizeRemainingComments();
  11202. expr.comments = this.state.comments;
  11203. expr.errors = this.state.errors;
  11204. if (this.options.tokens) {
  11205. expr.tokens = this.tokens;
  11206. }
  11207. return expr;
  11208. }
  11209. parseExpression(disallowIn, refExpressionErrors) {
  11210. if (disallowIn) {
  11211. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  11212. }
  11213. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  11214. }
  11215. parseExpressionBase(refExpressionErrors) {
  11216. const startLoc = this.state.startLoc;
  11217. const expr = this.parseMaybeAssign(refExpressionErrors);
  11218. if (this.match(12)) {
  11219. const node = this.startNodeAt(startLoc);
  11220. node.expressions = [expr];
  11221. while (this.eat(12)) {
  11222. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  11223. }
  11224. this.toReferencedList(node.expressions);
  11225. return this.finishNode(node, "SequenceExpression");
  11226. }
  11227. return expr;
  11228. }
  11229. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  11230. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  11231. }
  11232. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  11233. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  11234. }
  11235. setOptionalParametersError(refExpressionErrors, resultError) {
  11236. var _resultError$loc;
  11237. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  11238. }
  11239. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  11240. const startLoc = this.state.startLoc;
  11241. if (this.isContextual(108)) {
  11242. if (this.prodParam.hasYield) {
  11243. let left = this.parseYield();
  11244. if (afterLeftParse) {
  11245. left = afterLeftParse.call(this, left, startLoc);
  11246. }
  11247. return left;
  11248. }
  11249. }
  11250. let ownExpressionErrors;
  11251. if (refExpressionErrors) {
  11252. ownExpressionErrors = false;
  11253. } else {
  11254. refExpressionErrors = new ExpressionErrors();
  11255. ownExpressionErrors = true;
  11256. }
  11257. const {
  11258. type
  11259. } = this.state;
  11260. if (type === 10 || tokenIsIdentifier(type)) {
  11261. this.state.potentialArrowAt = this.state.start;
  11262. }
  11263. let left = this.parseMaybeConditional(refExpressionErrors);
  11264. if (afterLeftParse) {
  11265. left = afterLeftParse.call(this, left, startLoc);
  11266. }
  11267. if (tokenIsAssignment(this.state.type)) {
  11268. const node = this.startNodeAt(startLoc);
  11269. const operator = this.state.value;
  11270. node.operator = operator;
  11271. if (this.match(29)) {
  11272. this.toAssignable(left, true);
  11273. node.left = left;
  11274. const startIndex = startLoc.index;
  11275. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  11276. refExpressionErrors.doubleProtoLoc = null;
  11277. }
  11278. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  11279. refExpressionErrors.shorthandAssignLoc = null;
  11280. }
  11281. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  11282. this.checkDestructuringPrivate(refExpressionErrors);
  11283. refExpressionErrors.privateKeyLoc = null;
  11284. }
  11285. } else {
  11286. node.left = left;
  11287. }
  11288. this.next();
  11289. node.right = this.parseMaybeAssign();
  11290. this.checkLVal(left, {
  11291. in: this.finishNode(node, "AssignmentExpression")
  11292. });
  11293. return node;
  11294. } else if (ownExpressionErrors) {
  11295. this.checkExpressionErrors(refExpressionErrors, true);
  11296. }
  11297. return left;
  11298. }
  11299. parseMaybeConditional(refExpressionErrors) {
  11300. const startLoc = this.state.startLoc;
  11301. const potentialArrowAt = this.state.potentialArrowAt;
  11302. const expr = this.parseExprOps(refExpressionErrors);
  11303. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11304. return expr;
  11305. }
  11306. return this.parseConditional(expr, startLoc, refExpressionErrors);
  11307. }
  11308. parseConditional(expr, startLoc, refExpressionErrors) {
  11309. if (this.eat(17)) {
  11310. const node = this.startNodeAt(startLoc);
  11311. node.test = expr;
  11312. node.consequent = this.parseMaybeAssignAllowIn();
  11313. this.expect(14);
  11314. node.alternate = this.parseMaybeAssign();
  11315. return this.finishNode(node, "ConditionalExpression");
  11316. }
  11317. return expr;
  11318. }
  11319. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  11320. return this.match(138) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  11321. }
  11322. parseExprOps(refExpressionErrors) {
  11323. const startLoc = this.state.startLoc;
  11324. const potentialArrowAt = this.state.potentialArrowAt;
  11325. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  11326. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11327. return expr;
  11328. }
  11329. return this.parseExprOp(expr, startLoc, -1);
  11330. }
  11331. parseExprOp(left, leftStartLoc, minPrec) {
  11332. if (this.isPrivateName(left)) {
  11333. const value = this.getPrivateNameSV(left);
  11334. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  11335. this.raise(Errors.PrivateInExpectedIn, {
  11336. at: left,
  11337. identifierName: value
  11338. });
  11339. }
  11340. this.classScope.usePrivateName(value, left.loc.start);
  11341. }
  11342. const op = this.state.type;
  11343. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  11344. let prec = tokenOperatorPrecedence(op);
  11345. if (prec > minPrec) {
  11346. if (op === 39) {
  11347. this.expectPlugin("pipelineOperator");
  11348. if (this.state.inFSharpPipelineDirectBody) {
  11349. return left;
  11350. }
  11351. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  11352. }
  11353. const node = this.startNodeAt(leftStartLoc);
  11354. node.left = left;
  11355. node.operator = this.state.value;
  11356. const logical = op === 41 || op === 42;
  11357. const coalesce = op === 40;
  11358. if (coalesce) {
  11359. prec = tokenOperatorPrecedence(42);
  11360. }
  11361. this.next();
  11362. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  11363. proposal: "minimal"
  11364. }])) {
  11365. if (this.state.type === 96 && this.prodParam.hasAwait) {
  11366. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  11367. at: this.state.startLoc
  11368. });
  11369. }
  11370. }
  11371. node.right = this.parseExprOpRightExpr(op, prec);
  11372. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  11373. const nextOp = this.state.type;
  11374. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  11375. throw this.raise(Errors.MixingCoalesceWithLogical, {
  11376. at: this.state.startLoc
  11377. });
  11378. }
  11379. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  11380. }
  11381. }
  11382. return left;
  11383. }
  11384. parseExprOpRightExpr(op, prec) {
  11385. const startLoc = this.state.startLoc;
  11386. switch (op) {
  11387. case 39:
  11388. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  11389. case "hack":
  11390. return this.withTopicBindingContext(() => {
  11391. return this.parseHackPipeBody();
  11392. });
  11393. case "smart":
  11394. return this.withTopicBindingContext(() => {
  11395. if (this.prodParam.hasYield && this.isContextual(108)) {
  11396. throw this.raise(Errors.PipeBodyIsTighter, {
  11397. at: this.state.startLoc
  11398. });
  11399. }
  11400. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  11401. });
  11402. case "fsharp":
  11403. return this.withSoloAwaitPermittingContext(() => {
  11404. return this.parseFSharpPipelineBody(prec);
  11405. });
  11406. }
  11407. default:
  11408. return this.parseExprOpBaseRightExpr(op, prec);
  11409. }
  11410. }
  11411. parseExprOpBaseRightExpr(op, prec) {
  11412. const startLoc = this.state.startLoc;
  11413. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  11414. }
  11415. parseHackPipeBody() {
  11416. var _body$extra;
  11417. const {
  11418. startLoc
  11419. } = this.state;
  11420. const body = this.parseMaybeAssign();
  11421. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  11422. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  11423. this.raise(Errors.PipeUnparenthesizedBody, {
  11424. at: startLoc,
  11425. type: body.type
  11426. });
  11427. }
  11428. if (!this.topicReferenceWasUsedInCurrentContext()) {
  11429. this.raise(Errors.PipeTopicUnused, {
  11430. at: startLoc
  11431. });
  11432. }
  11433. return body;
  11434. }
  11435. checkExponentialAfterUnary(node) {
  11436. if (this.match(57)) {
  11437. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  11438. at: node.argument
  11439. });
  11440. }
  11441. }
  11442. parseMaybeUnary(refExpressionErrors, sawUnary) {
  11443. const startLoc = this.state.startLoc;
  11444. const isAwait = this.isContextual(96);
  11445. if (isAwait && this.isAwaitAllowed()) {
  11446. this.next();
  11447. const expr = this.parseAwait(startLoc);
  11448. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  11449. return expr;
  11450. }
  11451. const update = this.match(34);
  11452. const node = this.startNode();
  11453. if (tokenIsPrefix(this.state.type)) {
  11454. node.operator = this.state.value;
  11455. node.prefix = true;
  11456. if (this.match(72)) {
  11457. this.expectPlugin("throwExpressions");
  11458. }
  11459. const isDelete = this.match(89);
  11460. this.next();
  11461. node.argument = this.parseMaybeUnary(null, true);
  11462. this.checkExpressionErrors(refExpressionErrors, true);
  11463. if (this.state.strict && isDelete) {
  11464. const arg = node.argument;
  11465. if (arg.type === "Identifier") {
  11466. this.raise(Errors.StrictDelete, {
  11467. at: node
  11468. });
  11469. } else if (this.hasPropertyAsPrivateName(arg)) {
  11470. this.raise(Errors.DeletePrivateField, {
  11471. at: node
  11472. });
  11473. }
  11474. }
  11475. if (!update) {
  11476. if (!sawUnary) {
  11477. this.checkExponentialAfterUnary(node);
  11478. }
  11479. return this.finishNode(node, "UnaryExpression");
  11480. }
  11481. }
  11482. const expr = this.parseUpdate(node, update, refExpressionErrors);
  11483. if (isAwait) {
  11484. const {
  11485. type
  11486. } = this.state;
  11487. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  11488. if (startsExpr && !this.isAmbiguousAwait()) {
  11489. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  11490. at: startLoc
  11491. });
  11492. return this.parseAwait(startLoc);
  11493. }
  11494. }
  11495. return expr;
  11496. }
  11497. parseUpdate(node, update, refExpressionErrors) {
  11498. if (update) {
  11499. const updateExpressionNode = node;
  11500. this.checkLVal(updateExpressionNode.argument, {
  11501. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  11502. });
  11503. return node;
  11504. }
  11505. const startLoc = this.state.startLoc;
  11506. let expr = this.parseExprSubscripts(refExpressionErrors);
  11507. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  11508. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  11509. const node = this.startNodeAt(startLoc);
  11510. node.operator = this.state.value;
  11511. node.prefix = false;
  11512. node.argument = expr;
  11513. this.next();
  11514. this.checkLVal(expr, {
  11515. in: expr = this.finishNode(node, "UpdateExpression")
  11516. });
  11517. }
  11518. return expr;
  11519. }
  11520. parseExprSubscripts(refExpressionErrors) {
  11521. const startLoc = this.state.startLoc;
  11522. const potentialArrowAt = this.state.potentialArrowAt;
  11523. const expr = this.parseExprAtom(refExpressionErrors);
  11524. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  11525. return expr;
  11526. }
  11527. return this.parseSubscripts(expr, startLoc);
  11528. }
  11529. parseSubscripts(base, startLoc, noCalls) {
  11530. const state = {
  11531. optionalChainMember: false,
  11532. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  11533. stop: false
  11534. };
  11535. do {
  11536. base = this.parseSubscript(base, startLoc, noCalls, state);
  11537. state.maybeAsyncArrow = false;
  11538. } while (!state.stop);
  11539. return base;
  11540. }
  11541. parseSubscript(base, startLoc, noCalls, state) {
  11542. const {
  11543. type
  11544. } = this.state;
  11545. if (!noCalls && type === 15) {
  11546. return this.parseBind(base, startLoc, noCalls, state);
  11547. } else if (tokenIsTemplate(type)) {
  11548. return this.parseTaggedTemplateExpression(base, startLoc, state);
  11549. }
  11550. let optional = false;
  11551. if (type === 18) {
  11552. if (noCalls) {
  11553. this.raise(Errors.OptionalChainingNoNew, {
  11554. at: this.state.startLoc
  11555. });
  11556. if (this.lookaheadCharCode() === 40) {
  11557. state.stop = true;
  11558. return base;
  11559. }
  11560. }
  11561. state.optionalChainMember = optional = true;
  11562. this.next();
  11563. }
  11564. if (!noCalls && this.match(10)) {
  11565. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  11566. } else {
  11567. const computed = this.eat(0);
  11568. if (computed || optional || this.eat(16)) {
  11569. return this.parseMember(base, startLoc, state, computed, optional);
  11570. } else {
  11571. state.stop = true;
  11572. return base;
  11573. }
  11574. }
  11575. }
  11576. parseMember(base, startLoc, state, computed, optional) {
  11577. const node = this.startNodeAt(startLoc);
  11578. node.object = base;
  11579. node.computed = computed;
  11580. if (computed) {
  11581. node.property = this.parseExpression();
  11582. this.expect(3);
  11583. } else if (this.match(138)) {
  11584. if (base.type === "Super") {
  11585. this.raise(Errors.SuperPrivateField, {
  11586. at: startLoc
  11587. });
  11588. }
  11589. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  11590. node.property = this.parsePrivateName();
  11591. } else {
  11592. node.property = this.parseIdentifier(true);
  11593. }
  11594. if (state.optionalChainMember) {
  11595. node.optional = optional;
  11596. return this.finishNode(node, "OptionalMemberExpression");
  11597. } else {
  11598. return this.finishNode(node, "MemberExpression");
  11599. }
  11600. }
  11601. parseBind(base, startLoc, noCalls, state) {
  11602. const node = this.startNodeAt(startLoc);
  11603. node.object = base;
  11604. this.next();
  11605. node.callee = this.parseNoCallExpr();
  11606. state.stop = true;
  11607. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  11608. }
  11609. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  11610. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11611. let refExpressionErrors = null;
  11612. this.state.maybeInArrowParameters = true;
  11613. this.next();
  11614. const node = this.startNodeAt(startLoc);
  11615. node.callee = base;
  11616. const {
  11617. maybeAsyncArrow,
  11618. optionalChainMember
  11619. } = state;
  11620. if (maybeAsyncArrow) {
  11621. this.expressionScope.enter(newAsyncArrowScope());
  11622. refExpressionErrors = new ExpressionErrors();
  11623. }
  11624. if (optionalChainMember) {
  11625. node.optional = optional;
  11626. }
  11627. if (optional) {
  11628. node.arguments = this.parseCallExpressionArguments(11);
  11629. } else {
  11630. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  11631. }
  11632. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  11633. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  11634. state.stop = true;
  11635. this.checkDestructuringPrivate(refExpressionErrors);
  11636. this.expressionScope.validateAsPattern();
  11637. this.expressionScope.exit();
  11638. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  11639. } else {
  11640. if (maybeAsyncArrow) {
  11641. this.checkExpressionErrors(refExpressionErrors, true);
  11642. this.expressionScope.exit();
  11643. }
  11644. this.toReferencedArguments(finishedNode);
  11645. }
  11646. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11647. return finishedNode;
  11648. }
  11649. toReferencedArguments(node, isParenthesizedExpr) {
  11650. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  11651. }
  11652. parseTaggedTemplateExpression(base, startLoc, state) {
  11653. const node = this.startNodeAt(startLoc);
  11654. node.tag = base;
  11655. node.quasi = this.parseTemplate(true);
  11656. if (state.optionalChainMember) {
  11657. this.raise(Errors.OptionalChainingNoTemplate, {
  11658. at: startLoc
  11659. });
  11660. }
  11661. return this.finishNode(node, "TaggedTemplateExpression");
  11662. }
  11663. atPossibleAsyncArrow(base) {
  11664. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
  11665. }
  11666. expectImportAttributesPlugin() {
  11667. if (!this.hasPlugin("importAssertions")) {
  11668. this.expectPlugin("importAttributes");
  11669. }
  11670. }
  11671. finishCallExpression(node, optional) {
  11672. if (node.callee.type === "Import") {
  11673. if (node.arguments.length === 2) {
  11674. {
  11675. if (!this.hasPlugin("moduleAttributes")) {
  11676. this.expectImportAttributesPlugin();
  11677. }
  11678. }
  11679. }
  11680. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11681. this.raise(Errors.ImportCallArity, {
  11682. at: node,
  11683. maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  11684. });
  11685. } else {
  11686. for (const arg of node.arguments) {
  11687. if (arg.type === "SpreadElement") {
  11688. this.raise(Errors.ImportCallSpreadArgument, {
  11689. at: arg
  11690. });
  11691. }
  11692. }
  11693. }
  11694. }
  11695. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11696. }
  11697. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11698. const elts = [];
  11699. let first = true;
  11700. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11701. this.state.inFSharpPipelineDirectBody = false;
  11702. while (!this.eat(close)) {
  11703. if (first) {
  11704. first = false;
  11705. } else {
  11706. this.expect(12);
  11707. if (this.match(close)) {
  11708. if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  11709. this.raise(Errors.ImportCallArgumentTrailingComma, {
  11710. at: this.state.lastTokStartLoc
  11711. });
  11712. }
  11713. if (nodeForExtra) {
  11714. this.addTrailingCommaExtraToNode(nodeForExtra);
  11715. }
  11716. this.next();
  11717. break;
  11718. }
  11719. }
  11720. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11721. }
  11722. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11723. return elts;
  11724. }
  11725. shouldParseAsyncArrow() {
  11726. return this.match(19) && !this.canInsertSemicolon();
  11727. }
  11728. parseAsyncArrowFromCallExpression(node, call) {
  11729. var _call$extra;
  11730. this.resetPreviousNodeTrailingComments(call);
  11731. this.expect(19);
  11732. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11733. if (call.innerComments) {
  11734. setInnerComments(node, call.innerComments);
  11735. }
  11736. if (call.callee.trailingComments) {
  11737. setInnerComments(node, call.callee.trailingComments);
  11738. }
  11739. return node;
  11740. }
  11741. parseNoCallExpr() {
  11742. const startLoc = this.state.startLoc;
  11743. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11744. }
  11745. parseExprAtom(refExpressionErrors) {
  11746. let node;
  11747. let decorators = null;
  11748. const {
  11749. type
  11750. } = this.state;
  11751. switch (type) {
  11752. case 79:
  11753. return this.parseSuper();
  11754. case 83:
  11755. node = this.startNode();
  11756. this.next();
  11757. if (this.match(16)) {
  11758. return this.parseImportMetaProperty(node);
  11759. }
  11760. if (this.match(10)) {
  11761. if (this.options.createImportExpressions) {
  11762. return this.parseImportCall(node);
  11763. } else {
  11764. return this.finishNode(node, "Import");
  11765. }
  11766. } else {
  11767. this.raise(Errors.UnsupportedImport, {
  11768. at: this.state.lastTokStartLoc
  11769. });
  11770. return this.finishNode(node, "Import");
  11771. }
  11772. case 78:
  11773. node = this.startNode();
  11774. this.next();
  11775. return this.finishNode(node, "ThisExpression");
  11776. case 90:
  11777. {
  11778. return this.parseDo(this.startNode(), false);
  11779. }
  11780. case 56:
  11781. case 31:
  11782. {
  11783. this.readRegexp();
  11784. return this.parseRegExpLiteral(this.state.value);
  11785. }
  11786. case 134:
  11787. return this.parseNumericLiteral(this.state.value);
  11788. case 135:
  11789. return this.parseBigIntLiteral(this.state.value);
  11790. case 136:
  11791. return this.parseDecimalLiteral(this.state.value);
  11792. case 133:
  11793. return this.parseStringLiteral(this.state.value);
  11794. case 84:
  11795. return this.parseNullLiteral();
  11796. case 85:
  11797. return this.parseBooleanLiteral(true);
  11798. case 86:
  11799. return this.parseBooleanLiteral(false);
  11800. case 10:
  11801. {
  11802. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11803. return this.parseParenAndDistinguishExpression(canBeArrow);
  11804. }
  11805. case 2:
  11806. case 1:
  11807. {
  11808. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11809. }
  11810. case 0:
  11811. {
  11812. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11813. }
  11814. case 6:
  11815. case 7:
  11816. {
  11817. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11818. }
  11819. case 5:
  11820. {
  11821. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11822. }
  11823. case 68:
  11824. return this.parseFunctionOrFunctionSent();
  11825. case 26:
  11826. decorators = this.parseDecorators();
  11827. case 80:
  11828. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11829. case 77:
  11830. return this.parseNewOrNewTarget();
  11831. case 25:
  11832. case 24:
  11833. return this.parseTemplate(false);
  11834. case 15:
  11835. {
  11836. node = this.startNode();
  11837. this.next();
  11838. node.object = null;
  11839. const callee = node.callee = this.parseNoCallExpr();
  11840. if (callee.type === "MemberExpression") {
  11841. return this.finishNode(node, "BindExpression");
  11842. } else {
  11843. throw this.raise(Errors.UnsupportedBind, {
  11844. at: callee
  11845. });
  11846. }
  11847. }
  11848. case 138:
  11849. {
  11850. this.raise(Errors.PrivateInExpectedIn, {
  11851. at: this.state.startLoc,
  11852. identifierName: this.state.value
  11853. });
  11854. return this.parsePrivateName();
  11855. }
  11856. case 33:
  11857. {
  11858. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11859. }
  11860. case 32:
  11861. {
  11862. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11863. }
  11864. case 37:
  11865. case 38:
  11866. {
  11867. return this.parseTopicReference("hack");
  11868. }
  11869. case 44:
  11870. case 54:
  11871. case 27:
  11872. {
  11873. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11874. if (pipeProposal) {
  11875. return this.parseTopicReference(pipeProposal);
  11876. }
  11877. this.unexpected();
  11878. break;
  11879. }
  11880. case 47:
  11881. {
  11882. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11883. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11884. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11885. } else {
  11886. this.unexpected();
  11887. }
  11888. break;
  11889. }
  11890. default:
  11891. if (tokenIsIdentifier(type)) {
  11892. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11893. return this.parseModuleExpression();
  11894. }
  11895. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11896. const containsEsc = this.state.containsEsc;
  11897. const id = this.parseIdentifier();
  11898. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11899. const {
  11900. type
  11901. } = this.state;
  11902. if (type === 68) {
  11903. this.resetPreviousNodeTrailingComments(id);
  11904. this.next();
  11905. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11906. } else if (tokenIsIdentifier(type)) {
  11907. if (this.lookaheadCharCode() === 61) {
  11908. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11909. } else {
  11910. return id;
  11911. }
  11912. } else if (type === 90) {
  11913. this.resetPreviousNodeTrailingComments(id);
  11914. return this.parseDo(this.startNodeAtNode(id), true);
  11915. }
  11916. }
  11917. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11918. this.next();
  11919. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11920. }
  11921. return id;
  11922. } else {
  11923. this.unexpected();
  11924. }
  11925. }
  11926. }
  11927. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11928. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11929. if (pipeProposal) {
  11930. this.state.type = topicTokenType;
  11931. this.state.value = topicTokenValue;
  11932. this.state.pos--;
  11933. this.state.end--;
  11934. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11935. return this.parseTopicReference(pipeProposal);
  11936. } else {
  11937. this.unexpected();
  11938. }
  11939. }
  11940. parseTopicReference(pipeProposal) {
  11941. const node = this.startNode();
  11942. const startLoc = this.state.startLoc;
  11943. const tokenType = this.state.type;
  11944. this.next();
  11945. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11946. }
  11947. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11948. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11949. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11950. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11951. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  11952. at: startLoc
  11953. });
  11954. }
  11955. this.registerTopicReference();
  11956. return this.finishNode(node, nodeType);
  11957. } else {
  11958. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11959. at: startLoc,
  11960. token: tokenLabelName(tokenType)
  11961. });
  11962. }
  11963. }
  11964. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11965. switch (pipeProposal) {
  11966. case "hack":
  11967. {
  11968. return this.hasPlugin(["pipelineOperator", {
  11969. topicToken: tokenLabelName(tokenType)
  11970. }]);
  11971. }
  11972. case "smart":
  11973. return tokenType === 27;
  11974. default:
  11975. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11976. at: startLoc
  11977. });
  11978. }
  11979. }
  11980. parseAsyncArrowUnaryFunction(node) {
  11981. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11982. const params = [this.parseIdentifier()];
  11983. this.prodParam.exit();
  11984. if (this.hasPrecedingLineBreak()) {
  11985. this.raise(Errors.LineTerminatorBeforeArrow, {
  11986. at: this.state.curPosition()
  11987. });
  11988. }
  11989. this.expect(19);
  11990. return this.parseArrowExpression(node, params, true);
  11991. }
  11992. parseDo(node, isAsync) {
  11993. this.expectPlugin("doExpressions");
  11994. if (isAsync) {
  11995. this.expectPlugin("asyncDoExpressions");
  11996. }
  11997. node.async = isAsync;
  11998. this.next();
  11999. const oldLabels = this.state.labels;
  12000. this.state.labels = [];
  12001. if (isAsync) {
  12002. this.prodParam.enter(2);
  12003. node.body = this.parseBlock();
  12004. this.prodParam.exit();
  12005. } else {
  12006. node.body = this.parseBlock();
  12007. }
  12008. this.state.labels = oldLabels;
  12009. return this.finishNode(node, "DoExpression");
  12010. }
  12011. parseSuper() {
  12012. const node = this.startNode();
  12013. this.next();
  12014. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  12015. this.raise(Errors.SuperNotAllowed, {
  12016. at: node
  12017. });
  12018. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  12019. this.raise(Errors.UnexpectedSuper, {
  12020. at: node
  12021. });
  12022. }
  12023. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  12024. this.raise(Errors.UnsupportedSuper, {
  12025. at: node
  12026. });
  12027. }
  12028. return this.finishNode(node, "Super");
  12029. }
  12030. parsePrivateName() {
  12031. const node = this.startNode();
  12032. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  12033. const name = this.state.value;
  12034. this.next();
  12035. node.id = this.createIdentifier(id, name);
  12036. return this.finishNode(node, "PrivateName");
  12037. }
  12038. parseFunctionOrFunctionSent() {
  12039. const node = this.startNode();
  12040. this.next();
  12041. if (this.prodParam.hasYield && this.match(16)) {
  12042. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  12043. this.next();
  12044. if (this.match(103)) {
  12045. this.expectPlugin("functionSent");
  12046. } else if (!this.hasPlugin("functionSent")) {
  12047. this.unexpected();
  12048. }
  12049. return this.parseMetaProperty(node, meta, "sent");
  12050. }
  12051. return this.parseFunction(node);
  12052. }
  12053. parseMetaProperty(node, meta, propertyName) {
  12054. node.meta = meta;
  12055. const containsEsc = this.state.containsEsc;
  12056. node.property = this.parseIdentifier(true);
  12057. if (node.property.name !== propertyName || containsEsc) {
  12058. this.raise(Errors.UnsupportedMetaProperty, {
  12059. at: node.property,
  12060. target: meta.name,
  12061. onlyValidPropertyName: propertyName
  12062. });
  12063. }
  12064. return this.finishNode(node, "MetaProperty");
  12065. }
  12066. parseImportMetaProperty(node) {
  12067. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  12068. this.next();
  12069. if (this.isContextual(101)) {
  12070. if (!this.inModule) {
  12071. this.raise(Errors.ImportMetaOutsideModule, {
  12072. at: id
  12073. });
  12074. }
  12075. this.sawUnambiguousESM = true;
  12076. } else if (this.isContextual(105) || this.isContextual(97)) {
  12077. const isSource = this.isContextual(105);
  12078. if (!isSource) this.unexpected();
  12079. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  12080. if (!this.options.createImportExpressions) {
  12081. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, {
  12082. at: this.state.startLoc,
  12083. phase: this.state.value
  12084. });
  12085. }
  12086. this.next();
  12087. node.phase = isSource ? "source" : "defer";
  12088. return this.parseImportCall(node);
  12089. }
  12090. return this.parseMetaProperty(node, id, "meta");
  12091. }
  12092. parseLiteralAtNode(value, type, node) {
  12093. this.addExtra(node, "rawValue", value);
  12094. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  12095. node.value = value;
  12096. this.next();
  12097. return this.finishNode(node, type);
  12098. }
  12099. parseLiteral(value, type) {
  12100. const node = this.startNode();
  12101. return this.parseLiteralAtNode(value, type, node);
  12102. }
  12103. parseStringLiteral(value) {
  12104. return this.parseLiteral(value, "StringLiteral");
  12105. }
  12106. parseNumericLiteral(value) {
  12107. return this.parseLiteral(value, "NumericLiteral");
  12108. }
  12109. parseBigIntLiteral(value) {
  12110. return this.parseLiteral(value, "BigIntLiteral");
  12111. }
  12112. parseDecimalLiteral(value) {
  12113. return this.parseLiteral(value, "DecimalLiteral");
  12114. }
  12115. parseRegExpLiteral(value) {
  12116. const node = this.parseLiteral(value.value, "RegExpLiteral");
  12117. node.pattern = value.pattern;
  12118. node.flags = value.flags;
  12119. return node;
  12120. }
  12121. parseBooleanLiteral(value) {
  12122. const node = this.startNode();
  12123. node.value = value;
  12124. this.next();
  12125. return this.finishNode(node, "BooleanLiteral");
  12126. }
  12127. parseNullLiteral() {
  12128. const node = this.startNode();
  12129. this.next();
  12130. return this.finishNode(node, "NullLiteral");
  12131. }
  12132. parseParenAndDistinguishExpression(canBeArrow) {
  12133. const startLoc = this.state.startLoc;
  12134. let val;
  12135. this.next();
  12136. this.expressionScope.enter(newArrowHeadScope());
  12137. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12138. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12139. this.state.maybeInArrowParameters = true;
  12140. this.state.inFSharpPipelineDirectBody = false;
  12141. const innerStartLoc = this.state.startLoc;
  12142. const exprList = [];
  12143. const refExpressionErrors = new ExpressionErrors();
  12144. let first = true;
  12145. let spreadStartLoc;
  12146. let optionalCommaStartLoc;
  12147. while (!this.match(11)) {
  12148. if (first) {
  12149. first = false;
  12150. } else {
  12151. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  12152. if (this.match(11)) {
  12153. optionalCommaStartLoc = this.state.startLoc;
  12154. break;
  12155. }
  12156. }
  12157. if (this.match(21)) {
  12158. const spreadNodeStartLoc = this.state.startLoc;
  12159. spreadStartLoc = this.state.startLoc;
  12160. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  12161. if (!this.checkCommaAfterRest(41)) {
  12162. break;
  12163. }
  12164. } else {
  12165. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  12166. }
  12167. }
  12168. const innerEndLoc = this.state.lastTokEndLoc;
  12169. this.expect(11);
  12170. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12171. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12172. let arrowNode = this.startNodeAt(startLoc);
  12173. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  12174. this.checkDestructuringPrivate(refExpressionErrors);
  12175. this.expressionScope.validateAsPattern();
  12176. this.expressionScope.exit();
  12177. this.parseArrowExpression(arrowNode, exprList, false);
  12178. return arrowNode;
  12179. }
  12180. this.expressionScope.exit();
  12181. if (!exprList.length) {
  12182. this.unexpected(this.state.lastTokStartLoc);
  12183. }
  12184. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  12185. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  12186. this.checkExpressionErrors(refExpressionErrors, true);
  12187. this.toReferencedListDeep(exprList, true);
  12188. if (exprList.length > 1) {
  12189. val = this.startNodeAt(innerStartLoc);
  12190. val.expressions = exprList;
  12191. this.finishNode(val, "SequenceExpression");
  12192. this.resetEndLocation(val, innerEndLoc);
  12193. } else {
  12194. val = exprList[0];
  12195. }
  12196. return this.wrapParenthesis(startLoc, val);
  12197. }
  12198. wrapParenthesis(startLoc, expression) {
  12199. if (!this.options.createParenthesizedExpressions) {
  12200. this.addExtra(expression, "parenthesized", true);
  12201. this.addExtra(expression, "parenStart", startLoc.index);
  12202. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  12203. return expression;
  12204. }
  12205. const parenExpression = this.startNodeAt(startLoc);
  12206. parenExpression.expression = expression;
  12207. return this.finishNode(parenExpression, "ParenthesizedExpression");
  12208. }
  12209. shouldParseArrow(params) {
  12210. return !this.canInsertSemicolon();
  12211. }
  12212. parseArrow(node) {
  12213. if (this.eat(19)) {
  12214. return node;
  12215. }
  12216. }
  12217. parseParenItem(node, startLoc) {
  12218. return node;
  12219. }
  12220. parseNewOrNewTarget() {
  12221. const node = this.startNode();
  12222. this.next();
  12223. if (this.match(16)) {
  12224. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  12225. this.next();
  12226. const metaProp = this.parseMetaProperty(node, meta, "target");
  12227. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  12228. this.raise(Errors.UnexpectedNewTarget, {
  12229. at: metaProp
  12230. });
  12231. }
  12232. return metaProp;
  12233. }
  12234. return this.parseNew(node);
  12235. }
  12236. parseNew(node) {
  12237. this.parseNewCallee(node);
  12238. if (this.eat(10)) {
  12239. const args = this.parseExprList(11);
  12240. this.toReferencedList(args);
  12241. node.arguments = args;
  12242. } else {
  12243. node.arguments = [];
  12244. }
  12245. return this.finishNode(node, "NewExpression");
  12246. }
  12247. parseNewCallee(node) {
  12248. const isImport = this.match(83);
  12249. const callee = this.parseNoCallExpr();
  12250. node.callee = callee;
  12251. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  12252. this.raise(Errors.ImportCallNotNewExpression, {
  12253. at: callee
  12254. });
  12255. }
  12256. }
  12257. parseTemplateElement(isTagged) {
  12258. const {
  12259. start,
  12260. startLoc,
  12261. end,
  12262. value
  12263. } = this.state;
  12264. const elemStart = start + 1;
  12265. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  12266. if (value === null) {
  12267. if (!isTagged) {
  12268. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  12269. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  12270. });
  12271. }
  12272. }
  12273. const isTail = this.match(24);
  12274. const endOffset = isTail ? -1 : -2;
  12275. const elemEnd = end + endOffset;
  12276. elem.value = {
  12277. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  12278. cooked: value === null ? null : value.slice(1, endOffset)
  12279. };
  12280. elem.tail = isTail;
  12281. this.next();
  12282. const finishedNode = this.finishNode(elem, "TemplateElement");
  12283. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  12284. return finishedNode;
  12285. }
  12286. parseTemplate(isTagged) {
  12287. const node = this.startNode();
  12288. node.expressions = [];
  12289. let curElt = this.parseTemplateElement(isTagged);
  12290. node.quasis = [curElt];
  12291. while (!curElt.tail) {
  12292. node.expressions.push(this.parseTemplateSubstitution());
  12293. this.readTemplateContinuation();
  12294. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  12295. }
  12296. return this.finishNode(node, "TemplateLiteral");
  12297. }
  12298. parseTemplateSubstitution() {
  12299. return this.parseExpression();
  12300. }
  12301. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  12302. if (isRecord) {
  12303. this.expectPlugin("recordAndTuple");
  12304. }
  12305. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12306. this.state.inFSharpPipelineDirectBody = false;
  12307. const propHash = Object.create(null);
  12308. let first = true;
  12309. const node = this.startNode();
  12310. node.properties = [];
  12311. this.next();
  12312. while (!this.match(close)) {
  12313. if (first) {
  12314. first = false;
  12315. } else {
  12316. this.expect(12);
  12317. if (this.match(close)) {
  12318. this.addTrailingCommaExtraToNode(node);
  12319. break;
  12320. }
  12321. }
  12322. let prop;
  12323. if (isPattern) {
  12324. prop = this.parseBindingProperty();
  12325. } else {
  12326. prop = this.parsePropertyDefinition(refExpressionErrors);
  12327. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  12328. }
  12329. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  12330. this.raise(Errors.InvalidRecordProperty, {
  12331. at: prop
  12332. });
  12333. }
  12334. if (prop.shorthand) {
  12335. this.addExtra(prop, "shorthand", true);
  12336. }
  12337. node.properties.push(prop);
  12338. }
  12339. this.next();
  12340. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12341. let type = "ObjectExpression";
  12342. if (isPattern) {
  12343. type = "ObjectPattern";
  12344. } else if (isRecord) {
  12345. type = "RecordExpression";
  12346. }
  12347. return this.finishNode(node, type);
  12348. }
  12349. addTrailingCommaExtraToNode(node) {
  12350. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  12351. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  12352. }
  12353. maybeAsyncOrAccessorProp(prop) {
  12354. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  12355. }
  12356. parsePropertyDefinition(refExpressionErrors) {
  12357. let decorators = [];
  12358. if (this.match(26)) {
  12359. if (this.hasPlugin("decorators")) {
  12360. this.raise(Errors.UnsupportedPropertyDecorator, {
  12361. at: this.state.startLoc
  12362. });
  12363. }
  12364. while (this.match(26)) {
  12365. decorators.push(this.parseDecorator());
  12366. }
  12367. }
  12368. const prop = this.startNode();
  12369. let isAsync = false;
  12370. let isAccessor = false;
  12371. let startLoc;
  12372. if (this.match(21)) {
  12373. if (decorators.length) this.unexpected();
  12374. return this.parseSpread();
  12375. }
  12376. if (decorators.length) {
  12377. prop.decorators = decorators;
  12378. decorators = [];
  12379. }
  12380. prop.method = false;
  12381. if (refExpressionErrors) {
  12382. startLoc = this.state.startLoc;
  12383. }
  12384. let isGenerator = this.eat(55);
  12385. this.parsePropertyNamePrefixOperator(prop);
  12386. const containsEsc = this.state.containsEsc;
  12387. const key = this.parsePropertyName(prop, refExpressionErrors);
  12388. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  12389. const keyName = key.name;
  12390. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  12391. isAsync = true;
  12392. this.resetPreviousNodeTrailingComments(key);
  12393. isGenerator = this.eat(55);
  12394. this.parsePropertyName(prop);
  12395. }
  12396. if (keyName === "get" || keyName === "set") {
  12397. isAccessor = true;
  12398. this.resetPreviousNodeTrailingComments(key);
  12399. prop.kind = keyName;
  12400. if (this.match(55)) {
  12401. isGenerator = true;
  12402. this.raise(Errors.AccessorIsGenerator, {
  12403. at: this.state.curPosition(),
  12404. kind: keyName
  12405. });
  12406. this.next();
  12407. }
  12408. this.parsePropertyName(prop);
  12409. }
  12410. }
  12411. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  12412. }
  12413. getGetterSetterExpectedParamCount(method) {
  12414. return method.kind === "get" ? 0 : 1;
  12415. }
  12416. getObjectOrClassMethodParams(method) {
  12417. return method.params;
  12418. }
  12419. checkGetterSetterParams(method) {
  12420. var _params;
  12421. const paramCount = this.getGetterSetterExpectedParamCount(method);
  12422. const params = this.getObjectOrClassMethodParams(method);
  12423. if (params.length !== paramCount) {
  12424. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  12425. at: method
  12426. });
  12427. }
  12428. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  12429. this.raise(Errors.BadSetterRestParameter, {
  12430. at: method
  12431. });
  12432. }
  12433. }
  12434. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  12435. if (isAccessor) {
  12436. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  12437. this.checkGetterSetterParams(finishedProp);
  12438. return finishedProp;
  12439. }
  12440. if (isAsync || isGenerator || this.match(10)) {
  12441. if (isPattern) this.unexpected();
  12442. prop.kind = "method";
  12443. prop.method = true;
  12444. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  12445. }
  12446. }
  12447. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  12448. prop.shorthand = false;
  12449. if (this.eat(14)) {
  12450. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  12451. return this.finishNode(prop, "ObjectProperty");
  12452. }
  12453. if (!prop.computed && prop.key.type === "Identifier") {
  12454. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  12455. if (isPattern) {
  12456. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  12457. } else if (this.match(29)) {
  12458. const shorthandAssignLoc = this.state.startLoc;
  12459. if (refExpressionErrors != null) {
  12460. if (refExpressionErrors.shorthandAssignLoc === null) {
  12461. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  12462. }
  12463. } else {
  12464. this.raise(Errors.InvalidCoverInitializedName, {
  12465. at: shorthandAssignLoc
  12466. });
  12467. }
  12468. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  12469. } else {
  12470. prop.value = cloneIdentifier(prop.key);
  12471. }
  12472. prop.shorthand = true;
  12473. return this.finishNode(prop, "ObjectProperty");
  12474. }
  12475. }
  12476. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  12477. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  12478. if (!node) this.unexpected();
  12479. return node;
  12480. }
  12481. parsePropertyName(prop, refExpressionErrors) {
  12482. if (this.eat(0)) {
  12483. prop.computed = true;
  12484. prop.key = this.parseMaybeAssignAllowIn();
  12485. this.expect(3);
  12486. } else {
  12487. const {
  12488. type,
  12489. value
  12490. } = this.state;
  12491. let key;
  12492. if (tokenIsKeywordOrIdentifier(type)) {
  12493. key = this.parseIdentifier(true);
  12494. } else {
  12495. switch (type) {
  12496. case 134:
  12497. key = this.parseNumericLiteral(value);
  12498. break;
  12499. case 133:
  12500. key = this.parseStringLiteral(value);
  12501. break;
  12502. case 135:
  12503. key = this.parseBigIntLiteral(value);
  12504. break;
  12505. case 136:
  12506. key = this.parseDecimalLiteral(value);
  12507. break;
  12508. case 138:
  12509. {
  12510. const privateKeyLoc = this.state.startLoc;
  12511. if (refExpressionErrors != null) {
  12512. if (refExpressionErrors.privateKeyLoc === null) {
  12513. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  12514. }
  12515. } else {
  12516. this.raise(Errors.UnexpectedPrivateField, {
  12517. at: privateKeyLoc
  12518. });
  12519. }
  12520. key = this.parsePrivateName();
  12521. break;
  12522. }
  12523. default:
  12524. this.unexpected();
  12525. }
  12526. }
  12527. prop.key = key;
  12528. if (type !== 138) {
  12529. prop.computed = false;
  12530. }
  12531. }
  12532. return prop.key;
  12533. }
  12534. initFunction(node, isAsync) {
  12535. node.id = null;
  12536. node.generator = false;
  12537. node.async = isAsync;
  12538. }
  12539. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  12540. this.initFunction(node, isAsync);
  12541. node.generator = isGenerator;
  12542. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  12543. this.prodParam.enter(functionFlags(isAsync, node.generator));
  12544. this.parseFunctionParams(node, isConstructor);
  12545. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  12546. this.prodParam.exit();
  12547. this.scope.exit();
  12548. return finishedNode;
  12549. }
  12550. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  12551. if (isTuple) {
  12552. this.expectPlugin("recordAndTuple");
  12553. }
  12554. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12555. this.state.inFSharpPipelineDirectBody = false;
  12556. const node = this.startNode();
  12557. this.next();
  12558. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  12559. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12560. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  12561. }
  12562. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  12563. this.scope.enter(2 | 4);
  12564. let flags = functionFlags(isAsync, false);
  12565. if (!this.match(5) && this.prodParam.hasIn) {
  12566. flags |= 8;
  12567. }
  12568. this.prodParam.enter(flags);
  12569. this.initFunction(node, isAsync);
  12570. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  12571. if (params) {
  12572. this.state.maybeInArrowParameters = true;
  12573. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  12574. }
  12575. this.state.maybeInArrowParameters = false;
  12576. this.parseFunctionBody(node, true);
  12577. this.prodParam.exit();
  12578. this.scope.exit();
  12579. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  12580. return this.finishNode(node, "ArrowFunctionExpression");
  12581. }
  12582. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  12583. this.toAssignableList(params, trailingCommaLoc, false);
  12584. node.params = params;
  12585. }
  12586. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  12587. this.parseFunctionBody(node, false, isMethod);
  12588. return this.finishNode(node, type);
  12589. }
  12590. parseFunctionBody(node, allowExpression, isMethod = false) {
  12591. const isExpression = allowExpression && !this.match(5);
  12592. this.expressionScope.enter(newExpressionScope());
  12593. if (isExpression) {
  12594. node.body = this.parseMaybeAssign();
  12595. this.checkParams(node, false, allowExpression, false);
  12596. } else {
  12597. const oldStrict = this.state.strict;
  12598. const oldLabels = this.state.labels;
  12599. this.state.labels = [];
  12600. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  12601. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  12602. const nonSimple = !this.isSimpleParamList(node.params);
  12603. if (hasStrictModeDirective && nonSimple) {
  12604. this.raise(Errors.IllegalLanguageModeDirective, {
  12605. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  12606. });
  12607. }
  12608. const strictModeChanged = !oldStrict && this.state.strict;
  12609. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  12610. if (this.state.strict && node.id) {
  12611. this.checkIdentifier(node.id, 65, strictModeChanged);
  12612. }
  12613. });
  12614. this.prodParam.exit();
  12615. this.state.labels = oldLabels;
  12616. }
  12617. this.expressionScope.exit();
  12618. }
  12619. isSimpleParameter(node) {
  12620. return node.type === "Identifier";
  12621. }
  12622. isSimpleParamList(params) {
  12623. for (let i = 0, len = params.length; i < len; i++) {
  12624. if (!this.isSimpleParameter(params[i])) return false;
  12625. }
  12626. return true;
  12627. }
  12628. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  12629. const checkClashes = !allowDuplicates && new Set();
  12630. const formalParameters = {
  12631. type: "FormalParameters"
  12632. };
  12633. for (const param of node.params) {
  12634. this.checkLVal(param, {
  12635. in: formalParameters,
  12636. binding: 5,
  12637. checkClashes,
  12638. strictModeChanged
  12639. });
  12640. }
  12641. }
  12642. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  12643. const elts = [];
  12644. let first = true;
  12645. while (!this.eat(close)) {
  12646. if (first) {
  12647. first = false;
  12648. } else {
  12649. this.expect(12);
  12650. if (this.match(close)) {
  12651. if (nodeForExtra) {
  12652. this.addTrailingCommaExtraToNode(nodeForExtra);
  12653. }
  12654. this.next();
  12655. break;
  12656. }
  12657. }
  12658. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  12659. }
  12660. return elts;
  12661. }
  12662. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  12663. let elt;
  12664. if (this.match(12)) {
  12665. if (!allowEmpty) {
  12666. this.raise(Errors.UnexpectedToken, {
  12667. at: this.state.curPosition(),
  12668. unexpected: ","
  12669. });
  12670. }
  12671. elt = null;
  12672. } else if (this.match(21)) {
  12673. const spreadNodeStartLoc = this.state.startLoc;
  12674. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12675. } else if (this.match(17)) {
  12676. this.expectPlugin("partialApplication");
  12677. if (!allowPlaceholder) {
  12678. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  12679. at: this.state.startLoc
  12680. });
  12681. }
  12682. const node = this.startNode();
  12683. this.next();
  12684. elt = this.finishNode(node, "ArgumentPlaceholder");
  12685. } else {
  12686. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  12687. }
  12688. return elt;
  12689. }
  12690. parseIdentifier(liberal) {
  12691. const node = this.startNode();
  12692. const name = this.parseIdentifierName(liberal);
  12693. return this.createIdentifier(node, name);
  12694. }
  12695. createIdentifier(node, name) {
  12696. node.name = name;
  12697. node.loc.identifierName = name;
  12698. return this.finishNode(node, "Identifier");
  12699. }
  12700. parseIdentifierName(liberal) {
  12701. let name;
  12702. const {
  12703. startLoc,
  12704. type
  12705. } = this.state;
  12706. if (tokenIsKeywordOrIdentifier(type)) {
  12707. name = this.state.value;
  12708. } else {
  12709. this.unexpected();
  12710. }
  12711. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12712. if (liberal) {
  12713. if (tokenIsKeyword) {
  12714. this.replaceToken(132);
  12715. }
  12716. } else {
  12717. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12718. }
  12719. this.next();
  12720. return name;
  12721. }
  12722. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12723. if (word.length > 10) {
  12724. return;
  12725. }
  12726. if (!canBeReservedWord(word)) {
  12727. return;
  12728. }
  12729. if (checkKeywords && isKeyword(word)) {
  12730. this.raise(Errors.UnexpectedKeyword, {
  12731. at: startLoc,
  12732. keyword: word
  12733. });
  12734. return;
  12735. }
  12736. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12737. if (reservedTest(word, this.inModule)) {
  12738. this.raise(Errors.UnexpectedReservedWord, {
  12739. at: startLoc,
  12740. reservedWord: word
  12741. });
  12742. return;
  12743. } else if (word === "yield") {
  12744. if (this.prodParam.hasYield) {
  12745. this.raise(Errors.YieldBindingIdentifier, {
  12746. at: startLoc
  12747. });
  12748. return;
  12749. }
  12750. } else if (word === "await") {
  12751. if (this.prodParam.hasAwait) {
  12752. this.raise(Errors.AwaitBindingIdentifier, {
  12753. at: startLoc
  12754. });
  12755. return;
  12756. }
  12757. if (this.scope.inStaticBlock) {
  12758. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12759. at: startLoc
  12760. });
  12761. return;
  12762. }
  12763. this.expressionScope.recordAsyncArrowParametersError({
  12764. at: startLoc
  12765. });
  12766. } else if (word === "arguments") {
  12767. if (this.scope.inClassAndNotInNonArrowFunction) {
  12768. this.raise(Errors.ArgumentsInClass, {
  12769. at: startLoc
  12770. });
  12771. return;
  12772. }
  12773. }
  12774. }
  12775. isAwaitAllowed() {
  12776. if (this.prodParam.hasAwait) return true;
  12777. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12778. return true;
  12779. }
  12780. return false;
  12781. }
  12782. parseAwait(startLoc) {
  12783. const node = this.startNodeAt(startLoc);
  12784. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12785. at: node
  12786. });
  12787. if (this.eat(55)) {
  12788. this.raise(Errors.ObsoleteAwaitStar, {
  12789. at: node
  12790. });
  12791. }
  12792. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12793. if (this.isAmbiguousAwait()) {
  12794. this.ambiguousScriptDifferentAst = true;
  12795. } else {
  12796. this.sawUnambiguousESM = true;
  12797. }
  12798. }
  12799. if (!this.state.soloAwait) {
  12800. node.argument = this.parseMaybeUnary(null, true);
  12801. }
  12802. return this.finishNode(node, "AwaitExpression");
  12803. }
  12804. isAmbiguousAwait() {
  12805. if (this.hasPrecedingLineBreak()) return true;
  12806. const {
  12807. type
  12808. } = this.state;
  12809. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 137 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12810. }
  12811. parseYield() {
  12812. const node = this.startNode();
  12813. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12814. at: node
  12815. });
  12816. this.next();
  12817. let delegating = false;
  12818. let argument = null;
  12819. if (!this.hasPrecedingLineBreak()) {
  12820. delegating = this.eat(55);
  12821. switch (this.state.type) {
  12822. case 13:
  12823. case 139:
  12824. case 8:
  12825. case 11:
  12826. case 3:
  12827. case 9:
  12828. case 14:
  12829. case 12:
  12830. if (!delegating) break;
  12831. default:
  12832. argument = this.parseMaybeAssign();
  12833. }
  12834. }
  12835. node.delegate = delegating;
  12836. node.argument = argument;
  12837. return this.finishNode(node, "YieldExpression");
  12838. }
  12839. parseImportCall(node) {
  12840. this.next();
  12841. node.source = this.parseMaybeAssignAllowIn();
  12842. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  12843. node.options = null;
  12844. }
  12845. if (this.eat(12)) {
  12846. this.expectImportAttributesPlugin();
  12847. if (!this.match(11)) {
  12848. node.options = this.parseMaybeAssignAllowIn();
  12849. this.eat(12);
  12850. }
  12851. }
  12852. this.expect(11);
  12853. return this.finishNode(node, "ImportExpression");
  12854. }
  12855. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12856. if (this.hasPlugin(["pipelineOperator", {
  12857. proposal: "smart"
  12858. }])) {
  12859. if (left.type === "SequenceExpression") {
  12860. this.raise(Errors.PipelineHeadSequenceExpression, {
  12861. at: leftStartLoc
  12862. });
  12863. }
  12864. }
  12865. }
  12866. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12867. if (this.isSimpleReference(childExpr)) {
  12868. const bodyNode = this.startNodeAt(startLoc);
  12869. bodyNode.callee = childExpr;
  12870. return this.finishNode(bodyNode, "PipelineBareFunction");
  12871. } else {
  12872. const bodyNode = this.startNodeAt(startLoc);
  12873. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12874. bodyNode.expression = childExpr;
  12875. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12876. }
  12877. }
  12878. isSimpleReference(expression) {
  12879. switch (expression.type) {
  12880. case "MemberExpression":
  12881. return !expression.computed && this.isSimpleReference(expression.object);
  12882. case "Identifier":
  12883. return true;
  12884. default:
  12885. return false;
  12886. }
  12887. }
  12888. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12889. if (this.match(19)) {
  12890. throw this.raise(Errors.PipelineBodyNoArrow, {
  12891. at: this.state.startLoc
  12892. });
  12893. }
  12894. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12895. this.raise(Errors.PipelineTopicUnused, {
  12896. at: startLoc
  12897. });
  12898. }
  12899. }
  12900. withTopicBindingContext(callback) {
  12901. const outerContextTopicState = this.state.topicContext;
  12902. this.state.topicContext = {
  12903. maxNumOfResolvableTopics: 1,
  12904. maxTopicIndex: null
  12905. };
  12906. try {
  12907. return callback();
  12908. } finally {
  12909. this.state.topicContext = outerContextTopicState;
  12910. }
  12911. }
  12912. withSmartMixTopicForbiddingContext(callback) {
  12913. if (this.hasPlugin(["pipelineOperator", {
  12914. proposal: "smart"
  12915. }])) {
  12916. const outerContextTopicState = this.state.topicContext;
  12917. this.state.topicContext = {
  12918. maxNumOfResolvableTopics: 0,
  12919. maxTopicIndex: null
  12920. };
  12921. try {
  12922. return callback();
  12923. } finally {
  12924. this.state.topicContext = outerContextTopicState;
  12925. }
  12926. } else {
  12927. return callback();
  12928. }
  12929. }
  12930. withSoloAwaitPermittingContext(callback) {
  12931. const outerContextSoloAwaitState = this.state.soloAwait;
  12932. this.state.soloAwait = true;
  12933. try {
  12934. return callback();
  12935. } finally {
  12936. this.state.soloAwait = outerContextSoloAwaitState;
  12937. }
  12938. }
  12939. allowInAnd(callback) {
  12940. const flags = this.prodParam.currentFlags();
  12941. const prodParamToSet = 8 & ~flags;
  12942. if (prodParamToSet) {
  12943. this.prodParam.enter(flags | 8);
  12944. try {
  12945. return callback();
  12946. } finally {
  12947. this.prodParam.exit();
  12948. }
  12949. }
  12950. return callback();
  12951. }
  12952. disallowInAnd(callback) {
  12953. const flags = this.prodParam.currentFlags();
  12954. const prodParamToClear = 8 & flags;
  12955. if (prodParamToClear) {
  12956. this.prodParam.enter(flags & ~8);
  12957. try {
  12958. return callback();
  12959. } finally {
  12960. this.prodParam.exit();
  12961. }
  12962. }
  12963. return callback();
  12964. }
  12965. registerTopicReference() {
  12966. this.state.topicContext.maxTopicIndex = 0;
  12967. }
  12968. topicReferenceIsAllowedInCurrentContext() {
  12969. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12970. }
  12971. topicReferenceWasUsedInCurrentContext() {
  12972. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12973. }
  12974. parseFSharpPipelineBody(prec) {
  12975. const startLoc = this.state.startLoc;
  12976. this.state.potentialArrowAt = this.state.start;
  12977. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12978. this.state.inFSharpPipelineDirectBody = true;
  12979. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12980. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12981. return ret;
  12982. }
  12983. parseModuleExpression() {
  12984. this.expectPlugin("moduleBlocks");
  12985. const node = this.startNode();
  12986. this.next();
  12987. if (!this.match(5)) {
  12988. this.unexpected(null, 5);
  12989. }
  12990. const program = this.startNodeAt(this.state.endLoc);
  12991. this.next();
  12992. const revertScopes = this.initializeScopes(true);
  12993. this.enterInitialScopes();
  12994. try {
  12995. node.body = this.parseProgram(program, 8, "module");
  12996. } finally {
  12997. revertScopes();
  12998. }
  12999. return this.finishNode(node, "ModuleExpression");
  13000. }
  13001. parsePropertyNamePrefixOperator(prop) {}
  13002. }
  13003. const loopLabel = {
  13004. kind: "loop"
  13005. },
  13006. switchLabel = {
  13007. kind: "switch"
  13008. };
  13009. const loneSurrogate = /[\uD800-\uDFFF]/u;
  13010. const keywordRelationalOperator = /in(?:stanceof)?/y;
  13011. function babel7CompatTokens(tokens, input) {
  13012. for (let i = 0; i < tokens.length; i++) {
  13013. const token = tokens[i];
  13014. const {
  13015. type
  13016. } = token;
  13017. if (typeof type === "number") {
  13018. {
  13019. if (type === 138) {
  13020. const {
  13021. loc,
  13022. start,
  13023. value,
  13024. end
  13025. } = token;
  13026. const hashEndPos = start + 1;
  13027. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  13028. tokens.splice(i, 1, new Token({
  13029. type: getExportedToken(27),
  13030. value: "#",
  13031. start: start,
  13032. end: hashEndPos,
  13033. startLoc: loc.start,
  13034. endLoc: hashEndLoc
  13035. }), new Token({
  13036. type: getExportedToken(132),
  13037. value: value,
  13038. start: hashEndPos,
  13039. end: end,
  13040. startLoc: hashEndLoc,
  13041. endLoc: loc.end
  13042. }));
  13043. i++;
  13044. continue;
  13045. }
  13046. if (tokenIsTemplate(type)) {
  13047. const {
  13048. loc,
  13049. start,
  13050. value,
  13051. end
  13052. } = token;
  13053. const backquoteEnd = start + 1;
  13054. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  13055. let startToken;
  13056. if (input.charCodeAt(start) === 96) {
  13057. startToken = new Token({
  13058. type: getExportedToken(22),
  13059. value: "`",
  13060. start: start,
  13061. end: backquoteEnd,
  13062. startLoc: loc.start,
  13063. endLoc: backquoteEndLoc
  13064. });
  13065. } else {
  13066. startToken = new Token({
  13067. type: getExportedToken(8),
  13068. value: "}",
  13069. start: start,
  13070. end: backquoteEnd,
  13071. startLoc: loc.start,
  13072. endLoc: backquoteEndLoc
  13073. });
  13074. }
  13075. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  13076. if (type === 24) {
  13077. templateElementEnd = end - 1;
  13078. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  13079. templateValue = value === null ? null : value.slice(1, -1);
  13080. endToken = new Token({
  13081. type: getExportedToken(22),
  13082. value: "`",
  13083. start: templateElementEnd,
  13084. end: end,
  13085. startLoc: templateElementEndLoc,
  13086. endLoc: loc.end
  13087. });
  13088. } else {
  13089. templateElementEnd = end - 2;
  13090. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  13091. templateValue = value === null ? null : value.slice(1, -2);
  13092. endToken = new Token({
  13093. type: getExportedToken(23),
  13094. value: "${",
  13095. start: templateElementEnd,
  13096. end: end,
  13097. startLoc: templateElementEndLoc,
  13098. endLoc: loc.end
  13099. });
  13100. }
  13101. tokens.splice(i, 1, startToken, new Token({
  13102. type: getExportedToken(20),
  13103. value: templateValue,
  13104. start: backquoteEnd,
  13105. end: templateElementEnd,
  13106. startLoc: backquoteEndLoc,
  13107. endLoc: templateElementEndLoc
  13108. }), endToken);
  13109. i += 2;
  13110. continue;
  13111. }
  13112. }
  13113. token.type = getExportedToken(type);
  13114. }
  13115. }
  13116. return tokens;
  13117. }
  13118. class StatementParser extends ExpressionParser {
  13119. parseTopLevel(file, program) {
  13120. file.program = this.parseProgram(program);
  13121. file.comments = this.state.comments;
  13122. if (this.options.tokens) {
  13123. file.tokens = babel7CompatTokens(this.tokens, this.input);
  13124. }
  13125. return this.finishNode(file, "File");
  13126. }
  13127. parseProgram(program, end = 139, sourceType = this.options.sourceType) {
  13128. program.sourceType = sourceType;
  13129. program.interpreter = this.parseInterpreterDirective();
  13130. this.parseBlockBody(program, true, true, end);
  13131. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  13132. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  13133. this.raise(Errors.ModuleExportUndefined, {
  13134. at,
  13135. localName
  13136. });
  13137. }
  13138. }
  13139. let finishedProgram;
  13140. if (end === 139) {
  13141. finishedProgram = this.finishNode(program, "Program");
  13142. } else {
  13143. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  13144. }
  13145. return finishedProgram;
  13146. }
  13147. stmtToDirective(stmt) {
  13148. const directive = stmt;
  13149. directive.type = "Directive";
  13150. directive.value = directive.expression;
  13151. delete directive.expression;
  13152. const directiveLiteral = directive.value;
  13153. const expressionValue = directiveLiteral.value;
  13154. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  13155. const val = directiveLiteral.value = raw.slice(1, -1);
  13156. this.addExtra(directiveLiteral, "raw", raw);
  13157. this.addExtra(directiveLiteral, "rawValue", val);
  13158. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  13159. directiveLiteral.type = "DirectiveLiteral";
  13160. return directive;
  13161. }
  13162. parseInterpreterDirective() {
  13163. if (!this.match(28)) {
  13164. return null;
  13165. }
  13166. const node = this.startNode();
  13167. node.value = this.state.value;
  13168. this.next();
  13169. return this.finishNode(node, "InterpreterDirective");
  13170. }
  13171. isLet() {
  13172. if (!this.isContextual(100)) {
  13173. return false;
  13174. }
  13175. return this.hasFollowingBindingAtom();
  13176. }
  13177. chStartsBindingIdentifier(ch, pos) {
  13178. if (isIdentifierStart(ch)) {
  13179. keywordRelationalOperator.lastIndex = pos;
  13180. if (keywordRelationalOperator.test(this.input)) {
  13181. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  13182. if (!isIdentifierChar(endCh) && endCh !== 92) {
  13183. return false;
  13184. }
  13185. }
  13186. return true;
  13187. } else if (ch === 92) {
  13188. return true;
  13189. } else {
  13190. return false;
  13191. }
  13192. }
  13193. chStartsBindingPattern(ch) {
  13194. return ch === 91 || ch === 123;
  13195. }
  13196. hasFollowingBindingAtom() {
  13197. const next = this.nextTokenStart();
  13198. const nextCh = this.codePointAtPos(next);
  13199. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  13200. }
  13201. hasInLineFollowingBindingIdentifier() {
  13202. const next = this.nextTokenInLineStart();
  13203. const nextCh = this.codePointAtPos(next);
  13204. return this.chStartsBindingIdentifier(nextCh, next);
  13205. }
  13206. startsUsingForOf() {
  13207. const {
  13208. type,
  13209. containsEsc
  13210. } = this.lookahead();
  13211. if (type === 102 && !containsEsc) {
  13212. return false;
  13213. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  13214. this.expectPlugin("explicitResourceManagement");
  13215. return true;
  13216. }
  13217. }
  13218. startsAwaitUsing() {
  13219. let next = this.nextTokenInLineStart();
  13220. if (this.isUnparsedContextual(next, "using")) {
  13221. next = this.nextTokenInLineStartSince(next + 5);
  13222. const nextCh = this.codePointAtPos(next);
  13223. if (this.chStartsBindingIdentifier(nextCh, next)) {
  13224. this.expectPlugin("explicitResourceManagement");
  13225. return true;
  13226. }
  13227. }
  13228. return false;
  13229. }
  13230. parseModuleItem() {
  13231. return this.parseStatementLike(1 | 2 | 4 | 8);
  13232. }
  13233. parseStatementListItem() {
  13234. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  13235. }
  13236. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  13237. let flags = 0;
  13238. if (this.options.annexB && !this.state.strict) {
  13239. flags |= 4;
  13240. if (allowLabeledFunction) {
  13241. flags |= 8;
  13242. }
  13243. }
  13244. return this.parseStatementLike(flags);
  13245. }
  13246. parseStatement() {
  13247. return this.parseStatementLike(0);
  13248. }
  13249. parseStatementLike(flags) {
  13250. let decorators = null;
  13251. if (this.match(26)) {
  13252. decorators = this.parseDecorators(true);
  13253. }
  13254. return this.parseStatementContent(flags, decorators);
  13255. }
  13256. parseStatementContent(flags, decorators) {
  13257. const starttype = this.state.type;
  13258. const node = this.startNode();
  13259. const allowDeclaration = !!(flags & 2);
  13260. const allowFunctionDeclaration = !!(flags & 4);
  13261. const topLevel = flags & 1;
  13262. switch (starttype) {
  13263. case 60:
  13264. return this.parseBreakContinueStatement(node, true);
  13265. case 63:
  13266. return this.parseBreakContinueStatement(node, false);
  13267. case 64:
  13268. return this.parseDebuggerStatement(node);
  13269. case 90:
  13270. return this.parseDoWhileStatement(node);
  13271. case 91:
  13272. return this.parseForStatement(node);
  13273. case 68:
  13274. if (this.lookaheadCharCode() === 46) break;
  13275. if (!allowFunctionDeclaration) {
  13276. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
  13277. at: this.state.startLoc
  13278. });
  13279. }
  13280. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  13281. case 80:
  13282. if (!allowDeclaration) this.unexpected();
  13283. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  13284. case 69:
  13285. return this.parseIfStatement(node);
  13286. case 70:
  13287. return this.parseReturnStatement(node);
  13288. case 71:
  13289. return this.parseSwitchStatement(node);
  13290. case 72:
  13291. return this.parseThrowStatement(node);
  13292. case 73:
  13293. return this.parseTryStatement(node);
  13294. case 96:
  13295. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  13296. if (!this.isAwaitAllowed()) {
  13297. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  13298. at: node
  13299. });
  13300. } else if (!allowDeclaration) {
  13301. this.raise(Errors.UnexpectedLexicalDeclaration, {
  13302. at: node
  13303. });
  13304. }
  13305. this.next();
  13306. return this.parseVarStatement(node, "await using");
  13307. }
  13308. break;
  13309. case 107:
  13310. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
  13311. break;
  13312. }
  13313. this.expectPlugin("explicitResourceManagement");
  13314. if (!this.scope.inModule && this.scope.inTopLevel) {
  13315. this.raise(Errors.UnexpectedUsingDeclaration, {
  13316. at: this.state.startLoc
  13317. });
  13318. } else if (!allowDeclaration) {
  13319. this.raise(Errors.UnexpectedLexicalDeclaration, {
  13320. at: this.state.startLoc
  13321. });
  13322. }
  13323. return this.parseVarStatement(node, "using");
  13324. case 100:
  13325. {
  13326. if (this.state.containsEsc) {
  13327. break;
  13328. }
  13329. const next = this.nextTokenStart();
  13330. const nextCh = this.codePointAtPos(next);
  13331. if (nextCh !== 91) {
  13332. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  13333. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  13334. break;
  13335. }
  13336. }
  13337. }
  13338. case 75:
  13339. {
  13340. if (!allowDeclaration) {
  13341. this.raise(Errors.UnexpectedLexicalDeclaration, {
  13342. at: this.state.startLoc
  13343. });
  13344. }
  13345. }
  13346. case 74:
  13347. {
  13348. const kind = this.state.value;
  13349. return this.parseVarStatement(node, kind);
  13350. }
  13351. case 92:
  13352. return this.parseWhileStatement(node);
  13353. case 76:
  13354. return this.parseWithStatement(node);
  13355. case 5:
  13356. return this.parseBlock();
  13357. case 13:
  13358. return this.parseEmptyStatement(node);
  13359. case 83:
  13360. {
  13361. const nextTokenCharCode = this.lookaheadCharCode();
  13362. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  13363. break;
  13364. }
  13365. }
  13366. case 82:
  13367. {
  13368. if (!this.options.allowImportExportEverywhere && !topLevel) {
  13369. this.raise(Errors.UnexpectedImportExport, {
  13370. at: this.state.startLoc
  13371. });
  13372. }
  13373. this.next();
  13374. let result;
  13375. if (starttype === 83) {
  13376. result = this.parseImport(node);
  13377. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  13378. this.sawUnambiguousESM = true;
  13379. }
  13380. } else {
  13381. result = this.parseExport(node, decorators);
  13382. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  13383. this.sawUnambiguousESM = true;
  13384. }
  13385. }
  13386. this.assertModuleNodeAllowed(result);
  13387. return result;
  13388. }
  13389. default:
  13390. {
  13391. if (this.isAsyncFunction()) {
  13392. if (!allowDeclaration) {
  13393. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  13394. at: this.state.startLoc
  13395. });
  13396. }
  13397. this.next();
  13398. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  13399. }
  13400. }
  13401. }
  13402. const maybeName = this.state.value;
  13403. const expr = this.parseExpression();
  13404. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  13405. return this.parseLabeledStatement(node, maybeName, expr, flags);
  13406. } else {
  13407. return this.parseExpressionStatement(node, expr, decorators);
  13408. }
  13409. }
  13410. assertModuleNodeAllowed(node) {
  13411. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  13412. this.raise(Errors.ImportOutsideModule, {
  13413. at: node
  13414. });
  13415. }
  13416. }
  13417. decoratorsEnabledBeforeExport() {
  13418. if (this.hasPlugin("decorators-legacy")) return true;
  13419. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  13420. }
  13421. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  13422. if (maybeDecorators) {
  13423. if (classNode.decorators && classNode.decorators.length > 0) {
  13424. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  13425. this.raise(Errors.DecoratorsBeforeAfterExport, {
  13426. at: classNode.decorators[0]
  13427. });
  13428. }
  13429. classNode.decorators.unshift(...maybeDecorators);
  13430. } else {
  13431. classNode.decorators = maybeDecorators;
  13432. }
  13433. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  13434. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  13435. }
  13436. return classNode;
  13437. }
  13438. canHaveLeadingDecorator() {
  13439. return this.match(80);
  13440. }
  13441. parseDecorators(allowExport) {
  13442. const decorators = [];
  13443. do {
  13444. decorators.push(this.parseDecorator());
  13445. } while (this.match(26));
  13446. if (this.match(82)) {
  13447. if (!allowExport) {
  13448. this.unexpected();
  13449. }
  13450. if (!this.decoratorsEnabledBeforeExport()) {
  13451. this.raise(Errors.DecoratorExportClass, {
  13452. at: this.state.startLoc
  13453. });
  13454. }
  13455. } else if (!this.canHaveLeadingDecorator()) {
  13456. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  13457. at: this.state.startLoc
  13458. });
  13459. }
  13460. return decorators;
  13461. }
  13462. parseDecorator() {
  13463. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13464. const node = this.startNode();
  13465. this.next();
  13466. if (this.hasPlugin("decorators")) {
  13467. const startLoc = this.state.startLoc;
  13468. let expr;
  13469. if (this.match(10)) {
  13470. const startLoc = this.state.startLoc;
  13471. this.next();
  13472. expr = this.parseExpression();
  13473. this.expect(11);
  13474. expr = this.wrapParenthesis(startLoc, expr);
  13475. const paramsStartLoc = this.state.startLoc;
  13476. node.expression = this.parseMaybeDecoratorArguments(expr);
  13477. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  13478. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  13479. at: paramsStartLoc
  13480. });
  13481. }
  13482. } else {
  13483. expr = this.parseIdentifier(false);
  13484. while (this.eat(16)) {
  13485. const node = this.startNodeAt(startLoc);
  13486. node.object = expr;
  13487. if (this.match(138)) {
  13488. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  13489. node.property = this.parsePrivateName();
  13490. } else {
  13491. node.property = this.parseIdentifier(true);
  13492. }
  13493. node.computed = false;
  13494. expr = this.finishNode(node, "MemberExpression");
  13495. }
  13496. node.expression = this.parseMaybeDecoratorArguments(expr);
  13497. }
  13498. } else {
  13499. node.expression = this.parseExprSubscripts();
  13500. }
  13501. return this.finishNode(node, "Decorator");
  13502. }
  13503. parseMaybeDecoratorArguments(expr) {
  13504. if (this.eat(10)) {
  13505. const node = this.startNodeAtNode(expr);
  13506. node.callee = expr;
  13507. node.arguments = this.parseCallExpressionArguments(11, false);
  13508. this.toReferencedList(node.arguments);
  13509. return this.finishNode(node, "CallExpression");
  13510. }
  13511. return expr;
  13512. }
  13513. parseBreakContinueStatement(node, isBreak) {
  13514. this.next();
  13515. if (this.isLineTerminator()) {
  13516. node.label = null;
  13517. } else {
  13518. node.label = this.parseIdentifier();
  13519. this.semicolon();
  13520. }
  13521. this.verifyBreakContinue(node, isBreak);
  13522. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  13523. }
  13524. verifyBreakContinue(node, isBreak) {
  13525. let i;
  13526. for (i = 0; i < this.state.labels.length; ++i) {
  13527. const lab = this.state.labels[i];
  13528. if (node.label == null || lab.name === node.label.name) {
  13529. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  13530. if (node.label && isBreak) break;
  13531. }
  13532. }
  13533. if (i === this.state.labels.length) {
  13534. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  13535. this.raise(Errors.IllegalBreakContinue, {
  13536. at: node,
  13537. type
  13538. });
  13539. }
  13540. }
  13541. parseDebuggerStatement(node) {
  13542. this.next();
  13543. this.semicolon();
  13544. return this.finishNode(node, "DebuggerStatement");
  13545. }
  13546. parseHeaderExpression() {
  13547. this.expect(10);
  13548. const val = this.parseExpression();
  13549. this.expect(11);
  13550. return val;
  13551. }
  13552. parseDoWhileStatement(node) {
  13553. this.next();
  13554. this.state.labels.push(loopLabel);
  13555. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13556. this.state.labels.pop();
  13557. this.expect(92);
  13558. node.test = this.parseHeaderExpression();
  13559. this.eat(13);
  13560. return this.finishNode(node, "DoWhileStatement");
  13561. }
  13562. parseForStatement(node) {
  13563. this.next();
  13564. this.state.labels.push(loopLabel);
  13565. let awaitAt = null;
  13566. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  13567. awaitAt = this.state.lastTokStartLoc;
  13568. }
  13569. this.scope.enter(0);
  13570. this.expect(10);
  13571. if (this.match(13)) {
  13572. if (awaitAt !== null) {
  13573. this.unexpected(awaitAt);
  13574. }
  13575. return this.parseFor(node, null);
  13576. }
  13577. const startsWithLet = this.isContextual(100);
  13578. {
  13579. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  13580. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.startsUsingForOf();
  13581. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  13582. if (this.match(74) || this.match(75) || isLetOrUsing) {
  13583. const initNode = this.startNode();
  13584. let kind;
  13585. if (startsWithAwaitUsing) {
  13586. kind = "await using";
  13587. if (!this.isAwaitAllowed()) {
  13588. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  13589. at: this.state.startLoc
  13590. });
  13591. }
  13592. this.next();
  13593. } else {
  13594. kind = this.state.value;
  13595. }
  13596. this.next();
  13597. this.parseVar(initNode, true, kind);
  13598. const init = this.finishNode(initNode, "VariableDeclaration");
  13599. const isForIn = this.match(58);
  13600. if (isForIn && starsWithUsingDeclaration) {
  13601. this.raise(Errors.ForInUsing, {
  13602. at: init
  13603. });
  13604. }
  13605. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  13606. return this.parseForIn(node, init, awaitAt);
  13607. }
  13608. if (awaitAt !== null) {
  13609. this.unexpected(awaitAt);
  13610. }
  13611. return this.parseFor(node, init);
  13612. }
  13613. }
  13614. const startsWithAsync = this.isContextual(95);
  13615. const refExpressionErrors = new ExpressionErrors();
  13616. const init = this.parseExpression(true, refExpressionErrors);
  13617. const isForOf = this.isContextual(102);
  13618. if (isForOf) {
  13619. if (startsWithLet) {
  13620. this.raise(Errors.ForOfLet, {
  13621. at: init
  13622. });
  13623. }
  13624. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  13625. this.raise(Errors.ForOfAsync, {
  13626. at: init
  13627. });
  13628. }
  13629. }
  13630. if (isForOf || this.match(58)) {
  13631. this.checkDestructuringPrivate(refExpressionErrors);
  13632. this.toAssignable(init, true);
  13633. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  13634. this.checkLVal(init, {
  13635. in: {
  13636. type
  13637. }
  13638. });
  13639. return this.parseForIn(node, init, awaitAt);
  13640. } else {
  13641. this.checkExpressionErrors(refExpressionErrors, true);
  13642. }
  13643. if (awaitAt !== null) {
  13644. this.unexpected(awaitAt);
  13645. }
  13646. return this.parseFor(node, init);
  13647. }
  13648. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  13649. this.next();
  13650. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  13651. }
  13652. parseIfStatement(node) {
  13653. this.next();
  13654. node.test = this.parseHeaderExpression();
  13655. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  13656. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  13657. return this.finishNode(node, "IfStatement");
  13658. }
  13659. parseReturnStatement(node) {
  13660. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  13661. this.raise(Errors.IllegalReturn, {
  13662. at: this.state.startLoc
  13663. });
  13664. }
  13665. this.next();
  13666. if (this.isLineTerminator()) {
  13667. node.argument = null;
  13668. } else {
  13669. node.argument = this.parseExpression();
  13670. this.semicolon();
  13671. }
  13672. return this.finishNode(node, "ReturnStatement");
  13673. }
  13674. parseSwitchStatement(node) {
  13675. this.next();
  13676. node.discriminant = this.parseHeaderExpression();
  13677. const cases = node.cases = [];
  13678. this.expect(5);
  13679. this.state.labels.push(switchLabel);
  13680. this.scope.enter(0);
  13681. let cur;
  13682. for (let sawDefault; !this.match(8);) {
  13683. if (this.match(61) || this.match(65)) {
  13684. const isCase = this.match(61);
  13685. if (cur) this.finishNode(cur, "SwitchCase");
  13686. cases.push(cur = this.startNode());
  13687. cur.consequent = [];
  13688. this.next();
  13689. if (isCase) {
  13690. cur.test = this.parseExpression();
  13691. } else {
  13692. if (sawDefault) {
  13693. this.raise(Errors.MultipleDefaultsInSwitch, {
  13694. at: this.state.lastTokStartLoc
  13695. });
  13696. }
  13697. sawDefault = true;
  13698. cur.test = null;
  13699. }
  13700. this.expect(14);
  13701. } else {
  13702. if (cur) {
  13703. cur.consequent.push(this.parseStatementListItem());
  13704. } else {
  13705. this.unexpected();
  13706. }
  13707. }
  13708. }
  13709. this.scope.exit();
  13710. if (cur) this.finishNode(cur, "SwitchCase");
  13711. this.next();
  13712. this.state.labels.pop();
  13713. return this.finishNode(node, "SwitchStatement");
  13714. }
  13715. parseThrowStatement(node) {
  13716. this.next();
  13717. if (this.hasPrecedingLineBreak()) {
  13718. this.raise(Errors.NewlineAfterThrow, {
  13719. at: this.state.lastTokEndLoc
  13720. });
  13721. }
  13722. node.argument = this.parseExpression();
  13723. this.semicolon();
  13724. return this.finishNode(node, "ThrowStatement");
  13725. }
  13726. parseCatchClauseParam() {
  13727. const param = this.parseBindingAtom();
  13728. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13729. this.checkLVal(param, {
  13730. in: {
  13731. type: "CatchClause"
  13732. },
  13733. binding: 9
  13734. });
  13735. return param;
  13736. }
  13737. parseTryStatement(node) {
  13738. this.next();
  13739. node.block = this.parseBlock();
  13740. node.handler = null;
  13741. if (this.match(62)) {
  13742. const clause = this.startNode();
  13743. this.next();
  13744. if (this.match(10)) {
  13745. this.expect(10);
  13746. clause.param = this.parseCatchClauseParam();
  13747. this.expect(11);
  13748. } else {
  13749. clause.param = null;
  13750. this.scope.enter(0);
  13751. }
  13752. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13753. this.scope.exit();
  13754. node.handler = this.finishNode(clause, "CatchClause");
  13755. }
  13756. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13757. if (!node.handler && !node.finalizer) {
  13758. this.raise(Errors.NoCatchOrFinally, {
  13759. at: node
  13760. });
  13761. }
  13762. return this.finishNode(node, "TryStatement");
  13763. }
  13764. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13765. this.next();
  13766. this.parseVar(node, false, kind, allowMissingInitializer);
  13767. this.semicolon();
  13768. return this.finishNode(node, "VariableDeclaration");
  13769. }
  13770. parseWhileStatement(node) {
  13771. this.next();
  13772. node.test = this.parseHeaderExpression();
  13773. this.state.labels.push(loopLabel);
  13774. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13775. this.state.labels.pop();
  13776. return this.finishNode(node, "WhileStatement");
  13777. }
  13778. parseWithStatement(node) {
  13779. if (this.state.strict) {
  13780. this.raise(Errors.StrictWith, {
  13781. at: this.state.startLoc
  13782. });
  13783. }
  13784. this.next();
  13785. node.object = this.parseHeaderExpression();
  13786. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13787. return this.finishNode(node, "WithStatement");
  13788. }
  13789. parseEmptyStatement(node) {
  13790. this.next();
  13791. return this.finishNode(node, "EmptyStatement");
  13792. }
  13793. parseLabeledStatement(node, maybeName, expr, flags) {
  13794. for (const label of this.state.labels) {
  13795. if (label.name === maybeName) {
  13796. this.raise(Errors.LabelRedeclaration, {
  13797. at: expr,
  13798. labelName: maybeName
  13799. });
  13800. }
  13801. }
  13802. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13803. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13804. const label = this.state.labels[i];
  13805. if (label.statementStart === node.start) {
  13806. label.statementStart = this.state.start;
  13807. label.kind = kind;
  13808. } else {
  13809. break;
  13810. }
  13811. }
  13812. this.state.labels.push({
  13813. name: maybeName,
  13814. kind: kind,
  13815. statementStart: this.state.start
  13816. });
  13817. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13818. this.state.labels.pop();
  13819. node.label = expr;
  13820. return this.finishNode(node, "LabeledStatement");
  13821. }
  13822. parseExpressionStatement(node, expr, decorators) {
  13823. node.expression = expr;
  13824. this.semicolon();
  13825. return this.finishNode(node, "ExpressionStatement");
  13826. }
  13827. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13828. const node = this.startNode();
  13829. if (allowDirectives) {
  13830. this.state.strictErrors.clear();
  13831. }
  13832. this.expect(5);
  13833. if (createNewLexicalScope) {
  13834. this.scope.enter(0);
  13835. }
  13836. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13837. if (createNewLexicalScope) {
  13838. this.scope.exit();
  13839. }
  13840. return this.finishNode(node, "BlockStatement");
  13841. }
  13842. isValidDirective(stmt) {
  13843. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13844. }
  13845. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13846. const body = node.body = [];
  13847. const directives = node.directives = [];
  13848. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13849. }
  13850. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13851. const oldStrict = this.state.strict;
  13852. let hasStrictModeDirective = false;
  13853. let parsedNonDirective = false;
  13854. while (!this.match(end)) {
  13855. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13856. if (directives && !parsedNonDirective) {
  13857. if (this.isValidDirective(stmt)) {
  13858. const directive = this.stmtToDirective(stmt);
  13859. directives.push(directive);
  13860. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13861. hasStrictModeDirective = true;
  13862. this.setStrict(true);
  13863. }
  13864. continue;
  13865. }
  13866. parsedNonDirective = true;
  13867. this.state.strictErrors.clear();
  13868. }
  13869. body.push(stmt);
  13870. }
  13871. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  13872. if (!oldStrict) {
  13873. this.setStrict(false);
  13874. }
  13875. this.next();
  13876. }
  13877. parseFor(node, init) {
  13878. node.init = init;
  13879. this.semicolon(false);
  13880. node.test = this.match(13) ? null : this.parseExpression();
  13881. this.semicolon(false);
  13882. node.update = this.match(11) ? null : this.parseExpression();
  13883. this.expect(11);
  13884. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13885. this.scope.exit();
  13886. this.state.labels.pop();
  13887. return this.finishNode(node, "ForStatement");
  13888. }
  13889. parseForIn(node, init, awaitAt) {
  13890. const isForIn = this.match(58);
  13891. this.next();
  13892. if (isForIn) {
  13893. if (awaitAt !== null) this.unexpected(awaitAt);
  13894. } else {
  13895. node.await = awaitAt !== null;
  13896. }
  13897. 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")) {
  13898. this.raise(Errors.ForInOfLoopInitializer, {
  13899. at: init,
  13900. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13901. });
  13902. }
  13903. if (init.type === "AssignmentPattern") {
  13904. this.raise(Errors.InvalidLhs, {
  13905. at: init,
  13906. ancestor: {
  13907. type: "ForStatement"
  13908. }
  13909. });
  13910. }
  13911. node.left = init;
  13912. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13913. this.expect(11);
  13914. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13915. this.scope.exit();
  13916. this.state.labels.pop();
  13917. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13918. }
  13919. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13920. const declarations = node.declarations = [];
  13921. node.kind = kind;
  13922. for (;;) {
  13923. const decl = this.startNode();
  13924. this.parseVarId(decl, kind);
  13925. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13926. if (decl.init === null && !allowMissingInitializer) {
  13927. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13928. this.raise(Errors.DeclarationMissingInitializer, {
  13929. at: this.state.lastTokEndLoc,
  13930. kind: "destructuring"
  13931. });
  13932. } else if (kind === "const" && !(this.match(58) || this.isContextual(102))) {
  13933. this.raise(Errors.DeclarationMissingInitializer, {
  13934. at: this.state.lastTokEndLoc,
  13935. kind: "const"
  13936. });
  13937. }
  13938. }
  13939. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13940. if (!this.eat(12)) break;
  13941. }
  13942. return node;
  13943. }
  13944. parseVarId(decl, kind) {
  13945. const id = this.parseBindingAtom();
  13946. this.checkLVal(id, {
  13947. in: {
  13948. type: "VariableDeclarator"
  13949. },
  13950. binding: kind === "var" ? 5 : 8201
  13951. });
  13952. decl.id = id;
  13953. }
  13954. parseAsyncFunctionExpression(node) {
  13955. return this.parseFunction(node, 8);
  13956. }
  13957. parseFunction(node, flags = 0) {
  13958. const hangingDeclaration = flags & 2;
  13959. const isDeclaration = !!(flags & 1);
  13960. const requireId = isDeclaration && !(flags & 4);
  13961. const isAsync = !!(flags & 8);
  13962. this.initFunction(node, isAsync);
  13963. if (this.match(55)) {
  13964. if (hangingDeclaration) {
  13965. this.raise(Errors.GeneratorInSingleStatementContext, {
  13966. at: this.state.startLoc
  13967. });
  13968. }
  13969. this.next();
  13970. node.generator = true;
  13971. }
  13972. if (isDeclaration) {
  13973. node.id = this.parseFunctionId(requireId);
  13974. }
  13975. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13976. this.state.maybeInArrowParameters = false;
  13977. this.scope.enter(2);
  13978. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13979. if (!isDeclaration) {
  13980. node.id = this.parseFunctionId();
  13981. }
  13982. this.parseFunctionParams(node, false);
  13983. this.withSmartMixTopicForbiddingContext(() => {
  13984. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13985. });
  13986. this.prodParam.exit();
  13987. this.scope.exit();
  13988. if (isDeclaration && !hangingDeclaration) {
  13989. this.registerFunctionStatementId(node);
  13990. }
  13991. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13992. return node;
  13993. }
  13994. parseFunctionId(requireId) {
  13995. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13996. }
  13997. parseFunctionParams(node, isConstructor) {
  13998. this.expect(10);
  13999. this.expressionScope.enter(newParameterDeclarationScope());
  14000. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  14001. this.expressionScope.exit();
  14002. }
  14003. registerFunctionStatementId(node) {
  14004. if (!node.id) return;
  14005. 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);
  14006. }
  14007. parseClass(node, isStatement, optionalId) {
  14008. this.next();
  14009. const oldStrict = this.state.strict;
  14010. this.state.strict = true;
  14011. this.parseClassId(node, isStatement, optionalId);
  14012. this.parseClassSuper(node);
  14013. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  14014. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  14015. }
  14016. isClassProperty() {
  14017. return this.match(29) || this.match(13) || this.match(8);
  14018. }
  14019. isClassMethod() {
  14020. return this.match(10);
  14021. }
  14022. isNonstaticConstructor(method) {
  14023. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  14024. }
  14025. parseClassBody(hadSuperClass, oldStrict) {
  14026. this.classScope.enter();
  14027. const state = {
  14028. hadConstructor: false,
  14029. hadSuperClass
  14030. };
  14031. let decorators = [];
  14032. const classBody = this.startNode();
  14033. classBody.body = [];
  14034. this.expect(5);
  14035. this.withSmartMixTopicForbiddingContext(() => {
  14036. while (!this.match(8)) {
  14037. if (this.eat(13)) {
  14038. if (decorators.length > 0) {
  14039. throw this.raise(Errors.DecoratorSemicolon, {
  14040. at: this.state.lastTokEndLoc
  14041. });
  14042. }
  14043. continue;
  14044. }
  14045. if (this.match(26)) {
  14046. decorators.push(this.parseDecorator());
  14047. continue;
  14048. }
  14049. const member = this.startNode();
  14050. if (decorators.length) {
  14051. member.decorators = decorators;
  14052. this.resetStartLocationFromNode(member, decorators[0]);
  14053. decorators = [];
  14054. }
  14055. this.parseClassMember(classBody, member, state);
  14056. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  14057. this.raise(Errors.DecoratorConstructor, {
  14058. at: member
  14059. });
  14060. }
  14061. }
  14062. });
  14063. this.state.strict = oldStrict;
  14064. this.next();
  14065. if (decorators.length) {
  14066. throw this.raise(Errors.TrailingDecorator, {
  14067. at: this.state.startLoc
  14068. });
  14069. }
  14070. this.classScope.exit();
  14071. return this.finishNode(classBody, "ClassBody");
  14072. }
  14073. parseClassMemberFromModifier(classBody, member) {
  14074. const key = this.parseIdentifier(true);
  14075. if (this.isClassMethod()) {
  14076. const method = member;
  14077. method.kind = "method";
  14078. method.computed = false;
  14079. method.key = key;
  14080. method.static = false;
  14081. this.pushClassMethod(classBody, method, false, false, false, false);
  14082. return true;
  14083. } else if (this.isClassProperty()) {
  14084. const prop = member;
  14085. prop.computed = false;
  14086. prop.key = key;
  14087. prop.static = false;
  14088. classBody.body.push(this.parseClassProperty(prop));
  14089. return true;
  14090. }
  14091. this.resetPreviousNodeTrailingComments(key);
  14092. return false;
  14093. }
  14094. parseClassMember(classBody, member, state) {
  14095. const isStatic = this.isContextual(106);
  14096. if (isStatic) {
  14097. if (this.parseClassMemberFromModifier(classBody, member)) {
  14098. return;
  14099. }
  14100. if (this.eat(5)) {
  14101. this.parseClassStaticBlock(classBody, member);
  14102. return;
  14103. }
  14104. }
  14105. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  14106. }
  14107. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  14108. const publicMethod = member;
  14109. const privateMethod = member;
  14110. const publicProp = member;
  14111. const privateProp = member;
  14112. const accessorProp = member;
  14113. const method = publicMethod;
  14114. const publicMember = publicMethod;
  14115. member.static = isStatic;
  14116. this.parsePropertyNamePrefixOperator(member);
  14117. if (this.eat(55)) {
  14118. method.kind = "method";
  14119. const isPrivateName = this.match(138);
  14120. this.parseClassElementName(method);
  14121. if (isPrivateName) {
  14122. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  14123. return;
  14124. }
  14125. if (this.isNonstaticConstructor(publicMethod)) {
  14126. this.raise(Errors.ConstructorIsGenerator, {
  14127. at: publicMethod.key
  14128. });
  14129. }
  14130. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  14131. return;
  14132. }
  14133. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  14134. const isPrivate = this.match(138);
  14135. const key = this.parseClassElementName(member);
  14136. const maybeQuestionTokenStartLoc = this.state.startLoc;
  14137. this.parsePostMemberNameModifiers(publicMember);
  14138. if (this.isClassMethod()) {
  14139. method.kind = "method";
  14140. if (isPrivate) {
  14141. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  14142. return;
  14143. }
  14144. const isConstructor = this.isNonstaticConstructor(publicMethod);
  14145. let allowsDirectSuper = false;
  14146. if (isConstructor) {
  14147. publicMethod.kind = "constructor";
  14148. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  14149. this.raise(Errors.DuplicateConstructor, {
  14150. at: key
  14151. });
  14152. }
  14153. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  14154. this.raise(Errors.OverrideOnConstructor, {
  14155. at: key
  14156. });
  14157. }
  14158. state.hadConstructor = true;
  14159. allowsDirectSuper = state.hadSuperClass;
  14160. }
  14161. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  14162. } else if (this.isClassProperty()) {
  14163. if (isPrivate) {
  14164. this.pushClassPrivateProperty(classBody, privateProp);
  14165. } else {
  14166. this.pushClassProperty(classBody, publicProp);
  14167. }
  14168. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  14169. this.resetPreviousNodeTrailingComments(key);
  14170. const isGenerator = this.eat(55);
  14171. if (publicMember.optional) {
  14172. this.unexpected(maybeQuestionTokenStartLoc);
  14173. }
  14174. method.kind = "method";
  14175. const isPrivate = this.match(138);
  14176. this.parseClassElementName(method);
  14177. this.parsePostMemberNameModifiers(publicMember);
  14178. if (isPrivate) {
  14179. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  14180. } else {
  14181. if (this.isNonstaticConstructor(publicMethod)) {
  14182. this.raise(Errors.ConstructorIsAsync, {
  14183. at: publicMethod.key
  14184. });
  14185. }
  14186. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  14187. }
  14188. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  14189. this.resetPreviousNodeTrailingComments(key);
  14190. method.kind = key.name;
  14191. const isPrivate = this.match(138);
  14192. this.parseClassElementName(publicMethod);
  14193. if (isPrivate) {
  14194. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  14195. } else {
  14196. if (this.isNonstaticConstructor(publicMethod)) {
  14197. this.raise(Errors.ConstructorIsAccessor, {
  14198. at: publicMethod.key
  14199. });
  14200. }
  14201. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  14202. }
  14203. this.checkGetterSetterParams(publicMethod);
  14204. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  14205. this.expectPlugin("decoratorAutoAccessors");
  14206. this.resetPreviousNodeTrailingComments(key);
  14207. const isPrivate = this.match(138);
  14208. this.parseClassElementName(publicProp);
  14209. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  14210. } else if (this.isLineTerminator()) {
  14211. if (isPrivate) {
  14212. this.pushClassPrivateProperty(classBody, privateProp);
  14213. } else {
  14214. this.pushClassProperty(classBody, publicProp);
  14215. }
  14216. } else {
  14217. this.unexpected();
  14218. }
  14219. }
  14220. parseClassElementName(member) {
  14221. const {
  14222. type,
  14223. value
  14224. } = this.state;
  14225. if ((type === 132 || type === 133) && member.static && value === "prototype") {
  14226. this.raise(Errors.StaticPrototype, {
  14227. at: this.state.startLoc
  14228. });
  14229. }
  14230. if (type === 138) {
  14231. if (value === "constructor") {
  14232. this.raise(Errors.ConstructorClassPrivateField, {
  14233. at: this.state.startLoc
  14234. });
  14235. }
  14236. const key = this.parsePrivateName();
  14237. member.key = key;
  14238. return key;
  14239. }
  14240. return this.parsePropertyName(member);
  14241. }
  14242. parseClassStaticBlock(classBody, member) {
  14243. var _member$decorators;
  14244. this.scope.enter(64 | 128 | 16);
  14245. const oldLabels = this.state.labels;
  14246. this.state.labels = [];
  14247. this.prodParam.enter(0);
  14248. const body = member.body = [];
  14249. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  14250. this.prodParam.exit();
  14251. this.scope.exit();
  14252. this.state.labels = oldLabels;
  14253. classBody.body.push(this.finishNode(member, "StaticBlock"));
  14254. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  14255. this.raise(Errors.DecoratorStaticBlock, {
  14256. at: member
  14257. });
  14258. }
  14259. }
  14260. pushClassProperty(classBody, prop) {
  14261. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  14262. this.raise(Errors.ConstructorClassField, {
  14263. at: prop.key
  14264. });
  14265. }
  14266. classBody.body.push(this.parseClassProperty(prop));
  14267. }
  14268. pushClassPrivateProperty(classBody, prop) {
  14269. const node = this.parseClassPrivateProperty(prop);
  14270. classBody.body.push(node);
  14271. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  14272. }
  14273. pushClassAccessorProperty(classBody, prop, isPrivate) {
  14274. if (!isPrivate && !prop.computed) {
  14275. const key = prop.key;
  14276. if (key.name === "constructor" || key.value === "constructor") {
  14277. this.raise(Errors.ConstructorClassField, {
  14278. at: key
  14279. });
  14280. }
  14281. }
  14282. const node = this.parseClassAccessorProperty(prop);
  14283. classBody.body.push(node);
  14284. if (isPrivate) {
  14285. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  14286. }
  14287. }
  14288. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  14289. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  14290. }
  14291. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  14292. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  14293. classBody.body.push(node);
  14294. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  14295. this.declareClassPrivateMethodInScope(node, kind);
  14296. }
  14297. declareClassPrivateMethodInScope(node, kind) {
  14298. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  14299. }
  14300. parsePostMemberNameModifiers(methodOrProp) {}
  14301. parseClassPrivateProperty(node) {
  14302. this.parseInitializer(node);
  14303. this.semicolon();
  14304. return this.finishNode(node, "ClassPrivateProperty");
  14305. }
  14306. parseClassProperty(node) {
  14307. this.parseInitializer(node);
  14308. this.semicolon();
  14309. return this.finishNode(node, "ClassProperty");
  14310. }
  14311. parseClassAccessorProperty(node) {
  14312. this.parseInitializer(node);
  14313. this.semicolon();
  14314. return this.finishNode(node, "ClassAccessorProperty");
  14315. }
  14316. parseInitializer(node) {
  14317. this.scope.enter(64 | 16);
  14318. this.expressionScope.enter(newExpressionScope());
  14319. this.prodParam.enter(0);
  14320. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  14321. this.expressionScope.exit();
  14322. this.prodParam.exit();
  14323. this.scope.exit();
  14324. }
  14325. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  14326. if (tokenIsIdentifier(this.state.type)) {
  14327. node.id = this.parseIdentifier();
  14328. if (isStatement) {
  14329. this.declareNameFromIdentifier(node.id, bindingType);
  14330. }
  14331. } else {
  14332. if (optionalId || !isStatement) {
  14333. node.id = null;
  14334. } else {
  14335. throw this.raise(Errors.MissingClassName, {
  14336. at: this.state.startLoc
  14337. });
  14338. }
  14339. }
  14340. }
  14341. parseClassSuper(node) {
  14342. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  14343. }
  14344. parseExport(node, decorators) {
  14345. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  14346. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  14347. const parseAfterDefault = !hasDefault || this.eat(12);
  14348. const hasStar = parseAfterDefault && this.eatExportStar(node);
  14349. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  14350. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  14351. const isFromRequired = hasDefault || hasStar;
  14352. if (hasStar && !hasNamespace) {
  14353. if (hasDefault) this.unexpected();
  14354. if (decorators) {
  14355. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14356. at: node
  14357. });
  14358. }
  14359. this.parseExportFrom(node, true);
  14360. return this.finishNode(node, "ExportAllDeclaration");
  14361. }
  14362. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  14363. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  14364. this.unexpected(null, 5);
  14365. }
  14366. if (hasNamespace && parseAfterNamespace) {
  14367. this.unexpected(null, 98);
  14368. }
  14369. let hasDeclaration;
  14370. if (isFromRequired || hasSpecifiers) {
  14371. hasDeclaration = false;
  14372. if (decorators) {
  14373. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14374. at: node
  14375. });
  14376. }
  14377. this.parseExportFrom(node, isFromRequired);
  14378. } else {
  14379. hasDeclaration = this.maybeParseExportDeclaration(node);
  14380. }
  14381. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  14382. var _node2$declaration;
  14383. const node2 = node;
  14384. this.checkExport(node2, true, false, !!node2.source);
  14385. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  14386. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  14387. } else if (decorators) {
  14388. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14389. at: node
  14390. });
  14391. }
  14392. return this.finishNode(node2, "ExportNamedDeclaration");
  14393. }
  14394. if (this.eat(65)) {
  14395. const node2 = node;
  14396. const decl = this.parseExportDefaultExpression();
  14397. node2.declaration = decl;
  14398. if (decl.type === "ClassDeclaration") {
  14399. this.maybeTakeDecorators(decorators, decl, node2);
  14400. } else if (decorators) {
  14401. throw this.raise(Errors.UnsupportedDecoratorExport, {
  14402. at: node
  14403. });
  14404. }
  14405. this.checkExport(node2, true, true);
  14406. return this.finishNode(node2, "ExportDefaultDeclaration");
  14407. }
  14408. this.unexpected(null, 5);
  14409. }
  14410. eatExportStar(node) {
  14411. return this.eat(55);
  14412. }
  14413. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  14414. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  14415. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  14416. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  14417. const specifier = this.startNodeAtNode(id);
  14418. specifier.exported = id;
  14419. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  14420. return true;
  14421. }
  14422. return false;
  14423. }
  14424. maybeParseExportNamespaceSpecifier(node) {
  14425. if (this.isContextual(93)) {
  14426. if (!node.specifiers) node.specifiers = [];
  14427. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  14428. this.next();
  14429. specifier.exported = this.parseModuleExportName();
  14430. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  14431. return true;
  14432. }
  14433. return false;
  14434. }
  14435. maybeParseExportNamedSpecifiers(node) {
  14436. if (this.match(5)) {
  14437. if (!node.specifiers) node.specifiers = [];
  14438. const isTypeExport = node.exportKind === "type";
  14439. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  14440. node.source = null;
  14441. node.declaration = null;
  14442. if (this.hasPlugin("importAssertions")) {
  14443. node.assertions = [];
  14444. }
  14445. return true;
  14446. }
  14447. return false;
  14448. }
  14449. maybeParseExportDeclaration(node) {
  14450. if (this.shouldParseExportDeclaration()) {
  14451. node.specifiers = [];
  14452. node.source = null;
  14453. if (this.hasPlugin("importAssertions")) {
  14454. node.assertions = [];
  14455. }
  14456. node.declaration = this.parseExportDeclaration(node);
  14457. return true;
  14458. }
  14459. return false;
  14460. }
  14461. isAsyncFunction() {
  14462. if (!this.isContextual(95)) return false;
  14463. const next = this.nextTokenInLineStart();
  14464. return this.isUnparsedContextual(next, "function");
  14465. }
  14466. parseExportDefaultExpression() {
  14467. const expr = this.startNode();
  14468. if (this.match(68)) {
  14469. this.next();
  14470. return this.parseFunction(expr, 1 | 4);
  14471. } else if (this.isAsyncFunction()) {
  14472. this.next();
  14473. this.next();
  14474. return this.parseFunction(expr, 1 | 4 | 8);
  14475. }
  14476. if (this.match(80)) {
  14477. return this.parseClass(expr, true, true);
  14478. }
  14479. if (this.match(26)) {
  14480. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  14481. this.raise(Errors.DecoratorBeforeExport, {
  14482. at: this.state.startLoc
  14483. });
  14484. }
  14485. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  14486. }
  14487. if (this.match(75) || this.match(74) || this.isLet()) {
  14488. throw this.raise(Errors.UnsupportedDefaultExport, {
  14489. at: this.state.startLoc
  14490. });
  14491. }
  14492. const res = this.parseMaybeAssignAllowIn();
  14493. this.semicolon();
  14494. return res;
  14495. }
  14496. parseExportDeclaration(node) {
  14497. if (this.match(80)) {
  14498. const node = this.parseClass(this.startNode(), true, false);
  14499. return node;
  14500. }
  14501. return this.parseStatementListItem();
  14502. }
  14503. isExportDefaultSpecifier() {
  14504. const {
  14505. type
  14506. } = this.state;
  14507. if (tokenIsIdentifier(type)) {
  14508. if (type === 95 && !this.state.containsEsc || type === 100) {
  14509. return false;
  14510. }
  14511. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  14512. const {
  14513. type: nextType
  14514. } = this.lookahead();
  14515. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  14516. this.expectOnePlugin(["flow", "typescript"]);
  14517. return false;
  14518. }
  14519. }
  14520. } else if (!this.match(65)) {
  14521. return false;
  14522. }
  14523. const next = this.nextTokenStart();
  14524. const hasFrom = this.isUnparsedContextual(next, "from");
  14525. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  14526. return true;
  14527. }
  14528. if (this.match(65) && hasFrom) {
  14529. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  14530. return nextAfterFrom === 34 || nextAfterFrom === 39;
  14531. }
  14532. return false;
  14533. }
  14534. parseExportFrom(node, expect) {
  14535. if (this.eatContextual(98)) {
  14536. node.source = this.parseImportSource();
  14537. this.checkExport(node);
  14538. this.maybeParseImportAttributes(node);
  14539. this.checkJSONModuleImport(node);
  14540. } else if (expect) {
  14541. this.unexpected();
  14542. }
  14543. this.semicolon();
  14544. }
  14545. shouldParseExportDeclaration() {
  14546. const {
  14547. type
  14548. } = this.state;
  14549. if (type === 26) {
  14550. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  14551. if (this.hasPlugin("decorators")) {
  14552. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  14553. this.raise(Errors.DecoratorBeforeExport, {
  14554. at: this.state.startLoc
  14555. });
  14556. }
  14557. return true;
  14558. }
  14559. }
  14560. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  14561. }
  14562. checkExport(node, checkNames, isDefault, isFrom) {
  14563. if (checkNames) {
  14564. var _node$specifiers;
  14565. if (isDefault) {
  14566. this.checkDuplicateExports(node, "default");
  14567. if (this.hasPlugin("exportDefaultFrom")) {
  14568. var _declaration$extra;
  14569. const declaration = node.declaration;
  14570. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  14571. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  14572. at: declaration
  14573. });
  14574. }
  14575. }
  14576. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  14577. for (const specifier of node.specifiers) {
  14578. const {
  14579. exported
  14580. } = specifier;
  14581. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  14582. this.checkDuplicateExports(specifier, exportName);
  14583. if (!isFrom && specifier.local) {
  14584. const {
  14585. local
  14586. } = specifier;
  14587. if (local.type !== "Identifier") {
  14588. this.raise(Errors.ExportBindingIsString, {
  14589. at: specifier,
  14590. localName: local.value,
  14591. exportName
  14592. });
  14593. } else {
  14594. this.checkReservedWord(local.name, local.loc.start, true, false);
  14595. this.scope.checkLocalExport(local);
  14596. }
  14597. }
  14598. }
  14599. } else if (node.declaration) {
  14600. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  14601. const id = node.declaration.id;
  14602. if (!id) throw new Error("Assertion failure");
  14603. this.checkDuplicateExports(node, id.name);
  14604. } else if (node.declaration.type === "VariableDeclaration") {
  14605. for (const declaration of node.declaration.declarations) {
  14606. this.checkDeclaration(declaration.id);
  14607. }
  14608. }
  14609. }
  14610. }
  14611. }
  14612. checkDeclaration(node) {
  14613. if (node.type === "Identifier") {
  14614. this.checkDuplicateExports(node, node.name);
  14615. } else if (node.type === "ObjectPattern") {
  14616. for (const prop of node.properties) {
  14617. this.checkDeclaration(prop);
  14618. }
  14619. } else if (node.type === "ArrayPattern") {
  14620. for (const elem of node.elements) {
  14621. if (elem) {
  14622. this.checkDeclaration(elem);
  14623. }
  14624. }
  14625. } else if (node.type === "ObjectProperty") {
  14626. this.checkDeclaration(node.value);
  14627. } else if (node.type === "RestElement") {
  14628. this.checkDeclaration(node.argument);
  14629. } else if (node.type === "AssignmentPattern") {
  14630. this.checkDeclaration(node.left);
  14631. }
  14632. }
  14633. checkDuplicateExports(node, exportName) {
  14634. if (this.exportedIdentifiers.has(exportName)) {
  14635. if (exportName === "default") {
  14636. this.raise(Errors.DuplicateDefaultExport, {
  14637. at: node
  14638. });
  14639. } else {
  14640. this.raise(Errors.DuplicateExport, {
  14641. at: node,
  14642. exportName
  14643. });
  14644. }
  14645. }
  14646. this.exportedIdentifiers.add(exportName);
  14647. }
  14648. parseExportSpecifiers(isInTypeExport) {
  14649. const nodes = [];
  14650. let first = true;
  14651. this.expect(5);
  14652. while (!this.eat(8)) {
  14653. if (first) {
  14654. first = false;
  14655. } else {
  14656. this.expect(12);
  14657. if (this.eat(8)) break;
  14658. }
  14659. const isMaybeTypeOnly = this.isContextual(130);
  14660. const isString = this.match(133);
  14661. const node = this.startNode();
  14662. node.local = this.parseModuleExportName();
  14663. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14664. }
  14665. return nodes;
  14666. }
  14667. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14668. if (this.eatContextual(93)) {
  14669. node.exported = this.parseModuleExportName();
  14670. } else if (isString) {
  14671. node.exported = cloneStringLiteral(node.local);
  14672. } else if (!node.exported) {
  14673. node.exported = cloneIdentifier(node.local);
  14674. }
  14675. return this.finishNode(node, "ExportSpecifier");
  14676. }
  14677. parseModuleExportName() {
  14678. if (this.match(133)) {
  14679. const result = this.parseStringLiteral(this.state.value);
  14680. const surrogate = result.value.match(loneSurrogate);
  14681. if (surrogate) {
  14682. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  14683. at: result,
  14684. surrogateCharCode: surrogate[0].charCodeAt(0)
  14685. });
  14686. }
  14687. return result;
  14688. }
  14689. return this.parseIdentifier(true);
  14690. }
  14691. isJSONModuleImport(node) {
  14692. if (node.assertions != null) {
  14693. return node.assertions.some(({
  14694. key,
  14695. value
  14696. }) => {
  14697. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14698. });
  14699. }
  14700. return false;
  14701. }
  14702. checkImportReflection(node) {
  14703. const {
  14704. specifiers
  14705. } = node;
  14706. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14707. if (node.phase === "source") {
  14708. if (singleBindingType !== "ImportDefaultSpecifier") {
  14709. this.raise(Errors.SourcePhaseImportRequiresDefault, {
  14710. at: specifiers[0].loc.start
  14711. });
  14712. }
  14713. } else if (node.phase === "defer") {
  14714. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14715. this.raise(Errors.DeferImportRequiresNamespace, {
  14716. at: specifiers[0].loc.start
  14717. });
  14718. }
  14719. } else if (node.module) {
  14720. var _node$assertions;
  14721. if (singleBindingType !== "ImportDefaultSpecifier") {
  14722. this.raise(Errors.ImportReflectionNotBinding, {
  14723. at: specifiers[0].loc.start
  14724. });
  14725. }
  14726. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14727. this.raise(Errors.ImportReflectionHasAssertion, {
  14728. at: node.specifiers[0].loc.start
  14729. });
  14730. }
  14731. }
  14732. }
  14733. checkJSONModuleImport(node) {
  14734. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14735. const {
  14736. specifiers
  14737. } = node;
  14738. if (specifiers != null) {
  14739. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14740. let imported;
  14741. if (specifier.type === "ExportSpecifier") {
  14742. imported = specifier.local;
  14743. } else if (specifier.type === "ImportSpecifier") {
  14744. imported = specifier.imported;
  14745. }
  14746. if (imported !== undefined) {
  14747. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14748. }
  14749. });
  14750. if (nonDefaultNamedSpecifier !== undefined) {
  14751. this.raise(Errors.ImportJSONBindingNotDefault, {
  14752. at: nonDefaultNamedSpecifier.loc.start
  14753. });
  14754. }
  14755. }
  14756. }
  14757. }
  14758. isPotentialImportPhase(isExport) {
  14759. if (isExport) return false;
  14760. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14761. }
  14762. applyImportPhase(node, isExport, phase, loc) {
  14763. if (isExport) {
  14764. return;
  14765. }
  14766. if (phase === "module") {
  14767. this.expectPlugin("importReflection", loc);
  14768. node.module = true;
  14769. } else if (this.hasPlugin("importReflection")) {
  14770. node.module = false;
  14771. }
  14772. if (phase === "source") {
  14773. this.expectPlugin("sourcePhaseImports", loc);
  14774. node.phase = "source";
  14775. } else if (phase === "defer") {
  14776. this.expectPlugin("deferredImportEvaluation", loc);
  14777. node.phase = "defer";
  14778. } else if (this.hasPlugin("sourcePhaseImports")) {
  14779. node.phase = null;
  14780. }
  14781. }
  14782. parseMaybeImportPhase(node, isExport) {
  14783. if (!this.isPotentialImportPhase(isExport)) {
  14784. this.applyImportPhase(node, isExport, null);
  14785. return null;
  14786. }
  14787. const phaseIdentifier = this.parseIdentifier(true);
  14788. const {
  14789. type
  14790. } = this.state;
  14791. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14792. if (isImportPhase) {
  14793. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  14794. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  14795. return null;
  14796. } else {
  14797. this.applyImportPhase(node, isExport, null);
  14798. return phaseIdentifier;
  14799. }
  14800. }
  14801. isPrecedingIdImportPhase(phase) {
  14802. const {
  14803. type
  14804. } = this.state;
  14805. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14806. }
  14807. parseImport(node) {
  14808. if (this.match(133)) {
  14809. return this.parseImportSourceAndAttributes(node);
  14810. }
  14811. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14812. }
  14813. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14814. node.specifiers = [];
  14815. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14816. const parseNext = !hasDefault || this.eat(12);
  14817. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14818. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14819. this.expectContextual(98);
  14820. return this.parseImportSourceAndAttributes(node);
  14821. }
  14822. parseImportSourceAndAttributes(node) {
  14823. var _node$specifiers2;
  14824. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14825. node.source = this.parseImportSource();
  14826. this.maybeParseImportAttributes(node);
  14827. this.checkImportReflection(node);
  14828. this.checkJSONModuleImport(node);
  14829. this.semicolon();
  14830. return this.finishNode(node, "ImportDeclaration");
  14831. }
  14832. parseImportSource() {
  14833. if (!this.match(133)) this.unexpected();
  14834. return this.parseExprAtom();
  14835. }
  14836. parseImportSpecifierLocal(node, specifier, type) {
  14837. specifier.local = this.parseIdentifier();
  14838. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14839. }
  14840. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14841. this.checkLVal(specifier.local, {
  14842. in: {
  14843. type
  14844. },
  14845. binding: bindingType
  14846. });
  14847. return this.finishNode(specifier, type);
  14848. }
  14849. parseImportAttributes() {
  14850. this.expect(5);
  14851. const attrs = [];
  14852. const attrNames = new Set();
  14853. do {
  14854. if (this.match(8)) {
  14855. break;
  14856. }
  14857. const node = this.startNode();
  14858. const keyName = this.state.value;
  14859. if (attrNames.has(keyName)) {
  14860. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14861. at: this.state.startLoc,
  14862. key: keyName
  14863. });
  14864. }
  14865. attrNames.add(keyName);
  14866. if (this.match(133)) {
  14867. node.key = this.parseStringLiteral(keyName);
  14868. } else {
  14869. node.key = this.parseIdentifier(true);
  14870. }
  14871. this.expect(14);
  14872. if (!this.match(133)) {
  14873. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14874. at: this.state.startLoc
  14875. });
  14876. }
  14877. node.value = this.parseStringLiteral(this.state.value);
  14878. attrs.push(this.finishNode(node, "ImportAttribute"));
  14879. } while (this.eat(12));
  14880. this.expect(8);
  14881. return attrs;
  14882. }
  14883. parseModuleAttributes() {
  14884. const attrs = [];
  14885. const attributes = new Set();
  14886. do {
  14887. const node = this.startNode();
  14888. node.key = this.parseIdentifier(true);
  14889. if (node.key.name !== "type") {
  14890. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14891. at: node.key
  14892. });
  14893. }
  14894. if (attributes.has(node.key.name)) {
  14895. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14896. at: node.key,
  14897. key: node.key.name
  14898. });
  14899. }
  14900. attributes.add(node.key.name);
  14901. this.expect(14);
  14902. if (!this.match(133)) {
  14903. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14904. at: this.state.startLoc
  14905. });
  14906. }
  14907. node.value = this.parseStringLiteral(this.state.value);
  14908. attrs.push(this.finishNode(node, "ImportAttribute"));
  14909. } while (this.eat(12));
  14910. return attrs;
  14911. }
  14912. maybeParseImportAttributes(node) {
  14913. let attributes;
  14914. let useWith = false;
  14915. if (this.match(76)) {
  14916. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14917. return;
  14918. }
  14919. this.next();
  14920. {
  14921. if (this.hasPlugin("moduleAttributes")) {
  14922. attributes = this.parseModuleAttributes();
  14923. } else {
  14924. this.expectImportAttributesPlugin();
  14925. attributes = this.parseImportAttributes();
  14926. }
  14927. }
  14928. useWith = true;
  14929. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14930. if (this.hasPlugin("importAttributes")) {
  14931. if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) {
  14932. this.raise(Errors.ImportAttributesUseAssert, {
  14933. at: this.state.startLoc
  14934. });
  14935. }
  14936. this.addExtra(node, "deprecatedAssertSyntax", true);
  14937. } else {
  14938. this.expectOnePlugin(["importAttributes", "importAssertions"]);
  14939. }
  14940. this.next();
  14941. attributes = this.parseImportAttributes();
  14942. } else if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  14943. attributes = [];
  14944. } else {
  14945. if (this.hasPlugin("moduleAttributes")) {
  14946. attributes = [];
  14947. } else return;
  14948. }
  14949. if (!useWith && this.hasPlugin("importAssertions")) {
  14950. node.assertions = attributes;
  14951. } else {
  14952. node.attributes = attributes;
  14953. }
  14954. }
  14955. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14956. if (maybeDefaultIdentifier) {
  14957. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14958. specifier.local = maybeDefaultIdentifier;
  14959. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14960. return true;
  14961. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14962. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14963. return true;
  14964. }
  14965. return false;
  14966. }
  14967. maybeParseStarImportSpecifier(node) {
  14968. if (this.match(55)) {
  14969. const specifier = this.startNode();
  14970. this.next();
  14971. this.expectContextual(93);
  14972. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14973. return true;
  14974. }
  14975. return false;
  14976. }
  14977. parseNamedImportSpecifiers(node) {
  14978. let first = true;
  14979. this.expect(5);
  14980. while (!this.eat(8)) {
  14981. if (first) {
  14982. first = false;
  14983. } else {
  14984. if (this.eat(14)) {
  14985. throw this.raise(Errors.DestructureNamedImport, {
  14986. at: this.state.startLoc
  14987. });
  14988. }
  14989. this.expect(12);
  14990. if (this.eat(8)) break;
  14991. }
  14992. const specifier = this.startNode();
  14993. const importedIsString = this.match(133);
  14994. const isMaybeTypeOnly = this.isContextual(130);
  14995. specifier.imported = this.parseModuleExportName();
  14996. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14997. node.specifiers.push(importSpecifier);
  14998. }
  14999. }
  15000. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  15001. if (this.eatContextual(93)) {
  15002. specifier.local = this.parseIdentifier();
  15003. } else {
  15004. const {
  15005. imported
  15006. } = specifier;
  15007. if (importedIsString) {
  15008. throw this.raise(Errors.ImportBindingIsString, {
  15009. at: specifier,
  15010. importName: imported.value
  15011. });
  15012. }
  15013. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  15014. if (!specifier.local) {
  15015. specifier.local = cloneIdentifier(imported);
  15016. }
  15017. }
  15018. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  15019. }
  15020. isThisParam(param) {
  15021. return param.type === "Identifier" && param.name === "this";
  15022. }
  15023. }
  15024. let Parser$2 = class Parser extends StatementParser {
  15025. constructor(options, input) {
  15026. options = getOptions(options);
  15027. super(options, input);
  15028. this.options = options;
  15029. this.initializeScopes();
  15030. this.plugins = pluginsMap(this.options.plugins);
  15031. this.filename = options.sourceFilename;
  15032. }
  15033. getScopeHandler() {
  15034. return ScopeHandler;
  15035. }
  15036. parse() {
  15037. this.enterInitialScopes();
  15038. const file = this.startNode();
  15039. const program = this.startNode();
  15040. this.nextToken();
  15041. file.errors = null;
  15042. this.parseTopLevel(file, program);
  15043. file.errors = this.state.errors;
  15044. return file;
  15045. }
  15046. };
  15047. function pluginsMap(plugins) {
  15048. const pluginMap = new Map();
  15049. for (const plugin of plugins) {
  15050. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  15051. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  15052. }
  15053. return pluginMap;
  15054. }
  15055. function parse$9(input, options) {
  15056. var _options;
  15057. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  15058. options = Object.assign({}, options);
  15059. try {
  15060. options.sourceType = "module";
  15061. const parser = getParser(options, input);
  15062. const ast = parser.parse();
  15063. if (parser.sawUnambiguousESM) {
  15064. return ast;
  15065. }
  15066. if (parser.ambiguousScriptDifferentAst) {
  15067. try {
  15068. options.sourceType = "script";
  15069. return getParser(options, input).parse();
  15070. } catch (_unused) {}
  15071. } else {
  15072. ast.program.sourceType = "script";
  15073. }
  15074. return ast;
  15075. } catch (moduleError) {
  15076. try {
  15077. options.sourceType = "script";
  15078. return getParser(options, input).parse();
  15079. } catch (_unused2) {}
  15080. throw moduleError;
  15081. }
  15082. } else {
  15083. return getParser(options, input).parse();
  15084. }
  15085. }
  15086. function parseExpression(input, options) {
  15087. const parser = getParser(options, input);
  15088. if (parser.options.strictMode) {
  15089. parser.state.strict = true;
  15090. }
  15091. return parser.getExpression();
  15092. }
  15093. function generateExportedTokenTypes(internalTokenTypes) {
  15094. const tokenTypes = {};
  15095. for (const typeName of Object.keys(internalTokenTypes)) {
  15096. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  15097. }
  15098. return tokenTypes;
  15099. }
  15100. const tokTypes = generateExportedTokenTypes(tt);
  15101. function getParser(options, input) {
  15102. let cls = Parser$2;
  15103. if (options != null && options.plugins) {
  15104. validatePlugins(options.plugins);
  15105. cls = getParserClass(options.plugins);
  15106. }
  15107. return new cls(options, input);
  15108. }
  15109. const parserClassCache = {};
  15110. function getParserClass(pluginsFromOptions) {
  15111. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  15112. const key = pluginList.join("/");
  15113. let cls = parserClassCache[key];
  15114. if (!cls) {
  15115. cls = Parser$2;
  15116. for (const plugin of pluginList) {
  15117. cls = mixinPlugins[plugin](cls);
  15118. }
  15119. parserClassCache[key] = cls;
  15120. }
  15121. return cls;
  15122. }
  15123. var parse_1$1 = lib.parse = parse$9;
  15124. var parseExpression_1 = lib.parseExpression = parseExpression;
  15125. lib.tokTypes = tokTypes;
  15126. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  15127. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  15128. function isCoreComponent(tag) {
  15129. if (isBuiltInType(tag, "Teleport")) {
  15130. return TELEPORT;
  15131. } else if (isBuiltInType(tag, "Suspense")) {
  15132. return SUSPENSE;
  15133. } else if (isBuiltInType(tag, "KeepAlive")) {
  15134. return KEEP_ALIVE;
  15135. } else if (isBuiltInType(tag, "BaseTransition")) {
  15136. return BASE_TRANSITION;
  15137. }
  15138. }
  15139. const nonIdentifierRE = /^\d|[^\$\w]/;
  15140. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  15141. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  15142. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  15143. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  15144. const isMemberExpressionBrowser = (path) => {
  15145. path = path.trim().replace(whitespaceRE, (s) => s.trim());
  15146. let state = 0 /* inMemberExp */;
  15147. let stateStack = [];
  15148. let currentOpenBracketCount = 0;
  15149. let currentOpenParensCount = 0;
  15150. let currentStringType = null;
  15151. for (let i = 0; i < path.length; i++) {
  15152. const char = path.charAt(i);
  15153. switch (state) {
  15154. case 0 /* inMemberExp */:
  15155. if (char === "[") {
  15156. stateStack.push(state);
  15157. state = 1 /* inBrackets */;
  15158. currentOpenBracketCount++;
  15159. } else if (char === "(") {
  15160. stateStack.push(state);
  15161. state = 2 /* inParens */;
  15162. currentOpenParensCount++;
  15163. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  15164. return false;
  15165. }
  15166. break;
  15167. case 1 /* inBrackets */:
  15168. if (char === `'` || char === `"` || char === "`") {
  15169. stateStack.push(state);
  15170. state = 3 /* inString */;
  15171. currentStringType = char;
  15172. } else if (char === `[`) {
  15173. currentOpenBracketCount++;
  15174. } else if (char === `]`) {
  15175. if (!--currentOpenBracketCount) {
  15176. state = stateStack.pop();
  15177. }
  15178. }
  15179. break;
  15180. case 2 /* inParens */:
  15181. if (char === `'` || char === `"` || char === "`") {
  15182. stateStack.push(state);
  15183. state = 3 /* inString */;
  15184. currentStringType = char;
  15185. } else if (char === `(`) {
  15186. currentOpenParensCount++;
  15187. } else if (char === `)`) {
  15188. if (i === path.length - 1) {
  15189. return false;
  15190. }
  15191. if (!--currentOpenParensCount) {
  15192. state = stateStack.pop();
  15193. }
  15194. }
  15195. break;
  15196. case 3 /* inString */:
  15197. if (char === currentStringType) {
  15198. state = stateStack.pop();
  15199. currentStringType = null;
  15200. }
  15201. break;
  15202. }
  15203. }
  15204. return !currentOpenBracketCount && !currentOpenParensCount;
  15205. };
  15206. const isMemberExpressionNode = (path, context) => {
  15207. try {
  15208. let ret = parseExpression_1(path, {
  15209. plugins: context.expressionPlugins
  15210. });
  15211. if (ret.type === "TSAsExpression" || ret.type === "TSTypeAssertion") {
  15212. ret = ret.expression;
  15213. }
  15214. return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier";
  15215. } catch (e) {
  15216. return false;
  15217. }
  15218. };
  15219. const isMemberExpression = isMemberExpressionNode;
  15220. function getInnerRange(loc, offset, length) {
  15221. const source = loc.source.slice(offset, offset + length);
  15222. const newLoc = {
  15223. source,
  15224. start: advancePositionWithClone(loc.start, loc.source, offset),
  15225. end: loc.end
  15226. };
  15227. if (length != null) {
  15228. newLoc.end = advancePositionWithClone(
  15229. loc.start,
  15230. loc.source,
  15231. offset + length
  15232. );
  15233. }
  15234. return newLoc;
  15235. }
  15236. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  15237. return advancePositionWithMutation(
  15238. extend({}, pos),
  15239. source,
  15240. numberOfCharacters
  15241. );
  15242. }
  15243. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  15244. let linesCount = 0;
  15245. let lastNewLinePos = -1;
  15246. for (let i = 0; i < numberOfCharacters; i++) {
  15247. if (source.charCodeAt(i) === 10) {
  15248. linesCount++;
  15249. lastNewLinePos = i;
  15250. }
  15251. }
  15252. pos.offset += numberOfCharacters;
  15253. pos.line += linesCount;
  15254. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  15255. return pos;
  15256. }
  15257. function assert(condition, msg) {
  15258. if (!condition) {
  15259. throw new Error(msg || `unexpected compiler condition`);
  15260. }
  15261. }
  15262. function findDir(node, name, allowEmpty = false) {
  15263. for (let i = 0; i < node.props.length; i++) {
  15264. const p = node.props[i];
  15265. if (p.type === 7 && (allowEmpty || p.exp) && (isString$2(name) ? p.name === name : name.test(p.name))) {
  15266. return p;
  15267. }
  15268. }
  15269. }
  15270. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  15271. for (let i = 0; i < node.props.length; i++) {
  15272. const p = node.props[i];
  15273. if (p.type === 6) {
  15274. if (dynamicOnly)
  15275. continue;
  15276. if (p.name === name && (p.value || allowEmpty)) {
  15277. return p;
  15278. }
  15279. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  15280. return p;
  15281. }
  15282. }
  15283. }
  15284. function isStaticArgOf(arg, name) {
  15285. return !!(arg && isStaticExp(arg) && arg.content === name);
  15286. }
  15287. function hasDynamicKeyVBind(node) {
  15288. return node.props.some(
  15289. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  15290. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  15291. !p.arg.isStatic)
  15292. // v-bind:[foo]
  15293. );
  15294. }
  15295. function isText$1(node) {
  15296. return node.type === 5 || node.type === 2;
  15297. }
  15298. function isVSlot(p) {
  15299. return p.type === 7 && p.name === "slot";
  15300. }
  15301. function isTemplateNode(node) {
  15302. return node.type === 1 && node.tagType === 3;
  15303. }
  15304. function isSlotOutlet(node) {
  15305. return node.type === 1 && node.tagType === 2;
  15306. }
  15307. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  15308. function getUnnormalizedProps(props, callPath = []) {
  15309. if (props && !isString$2(props) && props.type === 14) {
  15310. const callee = props.callee;
  15311. if (!isString$2(callee) && propsHelperSet.has(callee)) {
  15312. return getUnnormalizedProps(
  15313. props.arguments[0],
  15314. callPath.concat(props)
  15315. );
  15316. }
  15317. }
  15318. return [props, callPath];
  15319. }
  15320. function injectProp(node, prop, context) {
  15321. let propsWithInjection;
  15322. let props = node.type === 13 ? node.props : node.arguments[2];
  15323. let callPath = [];
  15324. let parentCall;
  15325. if (props && !isString$2(props) && props.type === 14) {
  15326. const ret = getUnnormalizedProps(props);
  15327. props = ret[0];
  15328. callPath = ret[1];
  15329. parentCall = callPath[callPath.length - 1];
  15330. }
  15331. if (props == null || isString$2(props)) {
  15332. propsWithInjection = createObjectExpression([prop]);
  15333. } else if (props.type === 14) {
  15334. const first = props.arguments[0];
  15335. if (!isString$2(first) && first.type === 15) {
  15336. if (!hasProp(prop, first)) {
  15337. first.properties.unshift(prop);
  15338. }
  15339. } else {
  15340. if (props.callee === TO_HANDLERS) {
  15341. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  15342. createObjectExpression([prop]),
  15343. props
  15344. ]);
  15345. } else {
  15346. props.arguments.unshift(createObjectExpression([prop]));
  15347. }
  15348. }
  15349. !propsWithInjection && (propsWithInjection = props);
  15350. } else if (props.type === 15) {
  15351. if (!hasProp(prop, props)) {
  15352. props.properties.unshift(prop);
  15353. }
  15354. propsWithInjection = props;
  15355. } else {
  15356. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  15357. createObjectExpression([prop]),
  15358. props
  15359. ]);
  15360. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  15361. parentCall = callPath[callPath.length - 2];
  15362. }
  15363. }
  15364. if (node.type === 13) {
  15365. if (parentCall) {
  15366. parentCall.arguments[0] = propsWithInjection;
  15367. } else {
  15368. node.props = propsWithInjection;
  15369. }
  15370. } else {
  15371. if (parentCall) {
  15372. parentCall.arguments[0] = propsWithInjection;
  15373. } else {
  15374. node.arguments[2] = propsWithInjection;
  15375. }
  15376. }
  15377. }
  15378. function hasProp(prop, props) {
  15379. let result = false;
  15380. if (prop.key.type === 4) {
  15381. const propKeyName = prop.key.content;
  15382. result = props.properties.some(
  15383. (p) => p.key.type === 4 && p.key.content === propKeyName
  15384. );
  15385. }
  15386. return result;
  15387. }
  15388. function toValidAssetId(name, type) {
  15389. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  15390. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  15391. })}`;
  15392. }
  15393. function hasScopeRef(node, ids) {
  15394. if (!node || Object.keys(ids).length === 0) {
  15395. return false;
  15396. }
  15397. switch (node.type) {
  15398. case 1:
  15399. for (let i = 0; i < node.props.length; i++) {
  15400. const p = node.props[i];
  15401. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  15402. return true;
  15403. }
  15404. }
  15405. return node.children.some((c) => hasScopeRef(c, ids));
  15406. case 11:
  15407. if (hasScopeRef(node.source, ids)) {
  15408. return true;
  15409. }
  15410. return node.children.some((c) => hasScopeRef(c, ids));
  15411. case 9:
  15412. return node.branches.some((b) => hasScopeRef(b, ids));
  15413. case 10:
  15414. if (hasScopeRef(node.condition, ids)) {
  15415. return true;
  15416. }
  15417. return node.children.some((c) => hasScopeRef(c, ids));
  15418. case 4:
  15419. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  15420. case 8:
  15421. return node.children.some((c) => isObject$2(c) && hasScopeRef(c, ids));
  15422. case 5:
  15423. case 12:
  15424. return hasScopeRef(node.content, ids);
  15425. case 2:
  15426. case 3:
  15427. return false;
  15428. default:
  15429. return false;
  15430. }
  15431. }
  15432. function getMemoedVNodeCall(node) {
  15433. if (node.type === 14 && node.callee === WITH_MEMO) {
  15434. return node.arguments[1].returns;
  15435. } else {
  15436. return node;
  15437. }
  15438. }
  15439. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  15440. const deprecationData = {
  15441. ["COMPILER_IS_ON_ELEMENT"]: {
  15442. 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:".`,
  15443. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  15444. },
  15445. ["COMPILER_V_BIND_SYNC"]: {
  15446. 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}\`.`,
  15447. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  15448. },
  15449. ["COMPILER_V_BIND_PROP"]: {
  15450. message: `.prop modifier for v-bind has been removed and no longer necessary. Vue 3 will automatically set a binding as DOM property when appropriate.`
  15451. },
  15452. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  15453. 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.`,
  15454. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  15455. },
  15456. ["COMPILER_V_ON_NATIVE"]: {
  15457. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  15458. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  15459. },
  15460. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  15461. 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.`,
  15462. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  15463. },
  15464. ["COMPILER_NATIVE_TEMPLATE"]: {
  15465. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  15466. },
  15467. ["COMPILER_INLINE_TEMPLATE"]: {
  15468. message: `"inline-template" has been removed in Vue 3.`,
  15469. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  15470. },
  15471. ["COMPILER_FILTER"]: {
  15472. 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.`,
  15473. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  15474. }
  15475. };
  15476. function getCompatValue(key, context) {
  15477. const config = context.options ? context.options.compatConfig : context.compatConfig;
  15478. const value = config && config[key];
  15479. if (key === "MODE") {
  15480. return value || 3;
  15481. } else {
  15482. return value;
  15483. }
  15484. }
  15485. function isCompatEnabled(key, context) {
  15486. const mode = getCompatValue("MODE", context);
  15487. const value = getCompatValue(key, context);
  15488. return mode === 3 ? value === true : value !== false;
  15489. }
  15490. function checkCompatEnabled(key, context, loc, ...args) {
  15491. const enabled = isCompatEnabled(key, context);
  15492. if (enabled) {
  15493. warnDeprecation(key, context, loc, ...args);
  15494. }
  15495. return enabled;
  15496. }
  15497. function warnDeprecation(key, context, loc, ...args) {
  15498. const val = getCompatValue(key, context);
  15499. if (val === "suppress-warning") {
  15500. return;
  15501. }
  15502. const { message, link } = deprecationData[key];
  15503. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  15504. Details: ${link}` : ``}`;
  15505. const err = new SyntaxError(msg);
  15506. err.code = key;
  15507. if (loc)
  15508. err.loc = loc;
  15509. context.onWarn(err);
  15510. }
  15511. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  15512. const decodeMap = {
  15513. gt: ">",
  15514. lt: "<",
  15515. amp: "&",
  15516. apos: "'",
  15517. quot: '"'
  15518. };
  15519. const defaultParserOptions = {
  15520. delimiters: [`{{`, `}}`],
  15521. getNamespace: () => 0,
  15522. getTextMode: () => 0,
  15523. isVoidTag: NO,
  15524. isPreTag: NO,
  15525. isCustomElement: NO,
  15526. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  15527. onError: defaultOnError,
  15528. onWarn: defaultOnWarn,
  15529. comments: true
  15530. };
  15531. function baseParse(content, options = {}) {
  15532. const context = createParserContext(content, options);
  15533. const start = getCursor(context);
  15534. return createRoot(
  15535. parseChildren(context, 0, []),
  15536. getSelection(context, start)
  15537. );
  15538. }
  15539. function createParserContext(content, rawOptions) {
  15540. const options = extend({}, defaultParserOptions);
  15541. let key;
  15542. for (key in rawOptions) {
  15543. options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
  15544. }
  15545. return {
  15546. options,
  15547. column: 1,
  15548. line: 1,
  15549. offset: 0,
  15550. originalSource: content,
  15551. source: content,
  15552. inPre: false,
  15553. inVPre: false,
  15554. onWarn: options.onWarn
  15555. };
  15556. }
  15557. function parseChildren(context, mode, ancestors) {
  15558. const parent = last(ancestors);
  15559. const ns = parent ? parent.ns : 0;
  15560. const nodes = [];
  15561. while (!isEnd(context, mode, ancestors)) {
  15562. const s = context.source;
  15563. let node = void 0;
  15564. if (mode === 0 || mode === 1) {
  15565. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  15566. node = parseInterpolation(context, mode);
  15567. } else if (mode === 0 && s[0] === "<") {
  15568. if (s.length === 1) {
  15569. emitError(context, 5, 1);
  15570. } else if (s[1] === "!") {
  15571. if (startsWith(s, "<!--")) {
  15572. node = parseComment(context);
  15573. } else if (startsWith(s, "<!DOCTYPE")) {
  15574. node = parseBogusComment(context);
  15575. } else if (startsWith(s, "<![CDATA[")) {
  15576. if (ns !== 0) {
  15577. node = parseCDATA(context, ancestors);
  15578. } else {
  15579. emitError(context, 1);
  15580. node = parseBogusComment(context);
  15581. }
  15582. } else {
  15583. emitError(context, 11);
  15584. node = parseBogusComment(context);
  15585. }
  15586. } else if (s[1] === "/") {
  15587. if (s.length === 2) {
  15588. emitError(context, 5, 2);
  15589. } else if (s[2] === ">") {
  15590. emitError(context, 14, 2);
  15591. advanceBy(context, 3);
  15592. continue;
  15593. } else if (/[a-z]/i.test(s[2])) {
  15594. emitError(context, 23);
  15595. parseTag(context, 1 /* End */, parent);
  15596. continue;
  15597. } else {
  15598. emitError(
  15599. context,
  15600. 12,
  15601. 2
  15602. );
  15603. node = parseBogusComment(context);
  15604. }
  15605. } else if (/[a-z]/i.test(s[1])) {
  15606. node = parseElement(context, ancestors);
  15607. } else if (s[1] === "?") {
  15608. emitError(
  15609. context,
  15610. 21,
  15611. 1
  15612. );
  15613. node = parseBogusComment(context);
  15614. } else {
  15615. emitError(context, 12, 1);
  15616. }
  15617. }
  15618. }
  15619. if (!node) {
  15620. node = parseText(context, mode);
  15621. }
  15622. if (isArray$3(node)) {
  15623. for (let i = 0; i < node.length; i++) {
  15624. pushNode(nodes, node[i]);
  15625. }
  15626. } else {
  15627. pushNode(nodes, node);
  15628. }
  15629. }
  15630. let removedWhitespace = false;
  15631. if (mode !== 2 && mode !== 1) {
  15632. const shouldCondense = context.options.whitespace !== "preserve";
  15633. for (let i = 0; i < nodes.length; i++) {
  15634. const node = nodes[i];
  15635. if (node.type === 2) {
  15636. if (!context.inPre) {
  15637. if (!/[^\t\r\n\f ]/.test(node.content)) {
  15638. const prev = nodes[i - 1];
  15639. const next = nodes[i + 1];
  15640. if (!prev || !next || shouldCondense && (prev.type === 3 && next.type === 3 || prev.type === 3 && next.type === 1 || prev.type === 1 && next.type === 3 || prev.type === 1 && next.type === 1 && /[\r\n]/.test(node.content))) {
  15641. removedWhitespace = true;
  15642. nodes[i] = null;
  15643. } else {
  15644. node.content = " ";
  15645. }
  15646. } else if (shouldCondense) {
  15647. node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
  15648. }
  15649. } else {
  15650. node.content = node.content.replace(/\r\n/g, "\n");
  15651. }
  15652. } else if (node.type === 3 && !context.options.comments) {
  15653. removedWhitespace = true;
  15654. nodes[i] = null;
  15655. }
  15656. }
  15657. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  15658. const first = nodes[0];
  15659. if (first && first.type === 2) {
  15660. first.content = first.content.replace(/^\r?\n/, "");
  15661. }
  15662. }
  15663. }
  15664. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  15665. }
  15666. function pushNode(nodes, node) {
  15667. if (node.type === 2) {
  15668. const prev = last(nodes);
  15669. if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
  15670. prev.content += node.content;
  15671. prev.loc.end = node.loc.end;
  15672. prev.loc.source += node.loc.source;
  15673. return;
  15674. }
  15675. }
  15676. nodes.push(node);
  15677. }
  15678. function parseCDATA(context, ancestors) {
  15679. advanceBy(context, 9);
  15680. const nodes = parseChildren(context, 3, ancestors);
  15681. if (context.source.length === 0) {
  15682. emitError(context, 6);
  15683. } else {
  15684. advanceBy(context, 3);
  15685. }
  15686. return nodes;
  15687. }
  15688. function parseComment(context) {
  15689. const start = getCursor(context);
  15690. let content;
  15691. const match = /--(\!)?>/.exec(context.source);
  15692. if (!match) {
  15693. content = context.source.slice(4);
  15694. advanceBy(context, context.source.length);
  15695. emitError(context, 7);
  15696. } else {
  15697. if (match.index <= 3) {
  15698. emitError(context, 0);
  15699. }
  15700. if (match[1]) {
  15701. emitError(context, 10);
  15702. }
  15703. content = context.source.slice(4, match.index);
  15704. const s = context.source.slice(0, match.index);
  15705. let prevIndex = 1, nestedIndex = 0;
  15706. while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
  15707. advanceBy(context, nestedIndex - prevIndex + 1);
  15708. if (nestedIndex + 4 < s.length) {
  15709. emitError(context, 16);
  15710. }
  15711. prevIndex = nestedIndex + 1;
  15712. }
  15713. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  15714. }
  15715. return {
  15716. type: 3,
  15717. content,
  15718. loc: getSelection(context, start)
  15719. };
  15720. }
  15721. function parseBogusComment(context) {
  15722. const start = getCursor(context);
  15723. const contentStart = context.source[1] === "?" ? 1 : 2;
  15724. let content;
  15725. const closeIndex = context.source.indexOf(">");
  15726. if (closeIndex === -1) {
  15727. content = context.source.slice(contentStart);
  15728. advanceBy(context, context.source.length);
  15729. } else {
  15730. content = context.source.slice(contentStart, closeIndex);
  15731. advanceBy(context, closeIndex + 1);
  15732. }
  15733. return {
  15734. type: 3,
  15735. content,
  15736. loc: getSelection(context, start)
  15737. };
  15738. }
  15739. function parseElement(context, ancestors) {
  15740. const wasInPre = context.inPre;
  15741. const wasInVPre = context.inVPre;
  15742. const parent = last(ancestors);
  15743. const element = parseTag(context, 0 /* Start */, parent);
  15744. const isPreBoundary = context.inPre && !wasInPre;
  15745. const isVPreBoundary = context.inVPre && !wasInVPre;
  15746. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  15747. if (isPreBoundary) {
  15748. context.inPre = false;
  15749. }
  15750. if (isVPreBoundary) {
  15751. context.inVPre = false;
  15752. }
  15753. return element;
  15754. }
  15755. ancestors.push(element);
  15756. const mode = context.options.getTextMode(element, parent);
  15757. const children = parseChildren(context, mode, ancestors);
  15758. ancestors.pop();
  15759. element.children = children;
  15760. if (startsWithEndTagOpen(context.source, element.tag)) {
  15761. parseTag(context, 1 /* End */, parent);
  15762. } else {
  15763. emitError(context, 24, 0, element.loc.start);
  15764. if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
  15765. const first = children[0];
  15766. if (first && startsWith(first.loc.source, "<!--")) {
  15767. emitError(context, 8);
  15768. }
  15769. }
  15770. }
  15771. element.loc = getSelection(context, element.loc.start);
  15772. if (isPreBoundary) {
  15773. context.inPre = false;
  15774. }
  15775. if (isVPreBoundary) {
  15776. context.inVPre = false;
  15777. }
  15778. return element;
  15779. }
  15780. const isSpecialTemplateDirective = /* @__PURE__ */ makeMap(
  15781. `if,else,else-if,for,slot`
  15782. );
  15783. function parseTag(context, type, parent) {
  15784. const start = getCursor(context);
  15785. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  15786. const tag = match[1];
  15787. const ns = context.options.getNamespace(tag, parent);
  15788. advanceBy(context, match[0].length);
  15789. advanceSpaces(context);
  15790. const cursor = getCursor(context);
  15791. const currentSource = context.source;
  15792. if (context.options.isPreTag(tag)) {
  15793. context.inPre = true;
  15794. }
  15795. let props = parseAttributes(context, type);
  15796. if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
  15797. context.inVPre = true;
  15798. extend(context, cursor);
  15799. context.source = currentSource;
  15800. props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
  15801. }
  15802. let isSelfClosing = false;
  15803. if (context.source.length === 0) {
  15804. emitError(context, 9);
  15805. } else {
  15806. isSelfClosing = startsWith(context.source, "/>");
  15807. if (type === 1 /* End */ && isSelfClosing) {
  15808. emitError(context, 4);
  15809. }
  15810. advanceBy(context, isSelfClosing ? 2 : 1);
  15811. }
  15812. if (type === 1 /* End */) {
  15813. return;
  15814. }
  15815. let tagType = 0;
  15816. if (!context.inVPre) {
  15817. if (tag === "slot") {
  15818. tagType = 2;
  15819. } else if (tag === "template") {
  15820. if (props.some(
  15821. (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
  15822. )) {
  15823. tagType = 3;
  15824. }
  15825. } else if (isComponent(tag, props, context)) {
  15826. tagType = 1;
  15827. }
  15828. }
  15829. return {
  15830. type: 1,
  15831. ns,
  15832. tag,
  15833. tagType,
  15834. props,
  15835. isSelfClosing,
  15836. children: [],
  15837. loc: getSelection(context, start),
  15838. codegenNode: void 0
  15839. // to be created during transform phase
  15840. };
  15841. }
  15842. function isComponent(tag, props, context) {
  15843. const options = context.options;
  15844. if (options.isCustomElement(tag)) {
  15845. return false;
  15846. }
  15847. if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
  15848. return true;
  15849. }
  15850. for (let i = 0; i < props.length; i++) {
  15851. const p = props[i];
  15852. if (p.type === 6) {
  15853. if (p.name === "is" && p.value) {
  15854. if (p.value.content.startsWith("vue:")) {
  15855. return true;
  15856. }
  15857. }
  15858. } else {
  15859. if (p.name === "is") {
  15860. return true;
  15861. } else if (
  15862. // :is on plain element - only treat as component in compat mode
  15863. p.name === "bind" && isStaticArgOf(p.arg, "is") && false
  15864. ) {
  15865. return true;
  15866. }
  15867. }
  15868. }
  15869. }
  15870. function parseAttributes(context, type) {
  15871. const props = [];
  15872. const attributeNames = /* @__PURE__ */ new Set();
  15873. while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
  15874. if (startsWith(context.source, "/")) {
  15875. emitError(context, 22);
  15876. advanceBy(context, 1);
  15877. advanceSpaces(context);
  15878. continue;
  15879. }
  15880. if (type === 1 /* End */) {
  15881. emitError(context, 3);
  15882. }
  15883. const attr = parseAttribute(context, attributeNames);
  15884. if (attr.type === 6 && attr.value && attr.name === "class") {
  15885. attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
  15886. }
  15887. if (type === 0 /* Start */) {
  15888. props.push(attr);
  15889. }
  15890. if (/^[^\t\r\n\f />]/.test(context.source)) {
  15891. emitError(context, 15);
  15892. }
  15893. advanceSpaces(context);
  15894. }
  15895. return props;
  15896. }
  15897. function parseAttribute(context, nameSet) {
  15898. var _a;
  15899. const start = getCursor(context);
  15900. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  15901. const name = match[0];
  15902. if (nameSet.has(name)) {
  15903. emitError(context, 2);
  15904. }
  15905. nameSet.add(name);
  15906. if (name[0] === "=") {
  15907. emitError(context, 19);
  15908. }
  15909. {
  15910. const pattern = /["'<]/g;
  15911. let m;
  15912. while (m = pattern.exec(name)) {
  15913. emitError(
  15914. context,
  15915. 17,
  15916. m.index
  15917. );
  15918. }
  15919. }
  15920. advanceBy(context, name.length);
  15921. let value = void 0;
  15922. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  15923. advanceSpaces(context);
  15924. advanceBy(context, 1);
  15925. advanceSpaces(context);
  15926. value = parseAttributeValue(context);
  15927. if (!value) {
  15928. emitError(context, 13);
  15929. }
  15930. }
  15931. const loc = getSelection(context, start);
  15932. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  15933. const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
  15934. name
  15935. );
  15936. let isPropShorthand = startsWith(name, ".");
  15937. let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
  15938. let arg;
  15939. if (match2[2]) {
  15940. const isSlot = dirName === "slot";
  15941. const startOffset = name.lastIndexOf(
  15942. match2[2],
  15943. name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
  15944. );
  15945. const loc2 = getSelection(
  15946. context,
  15947. getNewPosition(context, start, startOffset),
  15948. getNewPosition(
  15949. context,
  15950. start,
  15951. startOffset + match2[2].length + (isSlot && match2[3] || "").length
  15952. )
  15953. );
  15954. let content = match2[2];
  15955. let isStatic = true;
  15956. if (content.startsWith("[")) {
  15957. isStatic = false;
  15958. if (!content.endsWith("]")) {
  15959. emitError(
  15960. context,
  15961. 27
  15962. );
  15963. content = content.slice(1);
  15964. } else {
  15965. content = content.slice(1, content.length - 1);
  15966. }
  15967. } else if (isSlot) {
  15968. content += match2[3] || "";
  15969. }
  15970. arg = {
  15971. type: 4,
  15972. content,
  15973. isStatic,
  15974. constType: isStatic ? 3 : 0,
  15975. loc: loc2
  15976. };
  15977. }
  15978. if (value && value.isQuoted) {
  15979. const valueLoc = value.loc;
  15980. valueLoc.start.offset++;
  15981. valueLoc.start.column++;
  15982. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  15983. valueLoc.source = valueLoc.source.slice(1, -1);
  15984. }
  15985. const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
  15986. if (isPropShorthand)
  15987. modifiers.push("prop");
  15988. return {
  15989. type: 7,
  15990. name: dirName,
  15991. exp: value && {
  15992. type: 4,
  15993. content: value.content,
  15994. isStatic: false,
  15995. // Treat as non-constant by default. This can be potentially set to
  15996. // other values by `transformExpression` to make it eligible for hoisting.
  15997. constType: 0,
  15998. loc: value.loc
  15999. },
  16000. arg,
  16001. modifiers,
  16002. loc
  16003. };
  16004. }
  16005. if (!context.inVPre && startsWith(name, "v-")) {
  16006. emitError(context, 26);
  16007. }
  16008. return {
  16009. type: 6,
  16010. name,
  16011. value: value && {
  16012. type: 2,
  16013. content: value.content,
  16014. loc: value.loc
  16015. },
  16016. loc
  16017. };
  16018. }
  16019. function parseAttributeValue(context) {
  16020. const start = getCursor(context);
  16021. let content;
  16022. const quote = context.source[0];
  16023. const isQuoted = quote === `"` || quote === `'`;
  16024. if (isQuoted) {
  16025. advanceBy(context, 1);
  16026. const endIndex = context.source.indexOf(quote);
  16027. if (endIndex === -1) {
  16028. content = parseTextData(
  16029. context,
  16030. context.source.length,
  16031. 4
  16032. );
  16033. } else {
  16034. content = parseTextData(context, endIndex, 4);
  16035. advanceBy(context, 1);
  16036. }
  16037. } else {
  16038. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  16039. if (!match) {
  16040. return void 0;
  16041. }
  16042. const unexpectedChars = /["'<=`]/g;
  16043. let m;
  16044. while (m = unexpectedChars.exec(match[0])) {
  16045. emitError(
  16046. context,
  16047. 18,
  16048. m.index
  16049. );
  16050. }
  16051. content = parseTextData(context, match[0].length, 4);
  16052. }
  16053. return { content, isQuoted, loc: getSelection(context, start) };
  16054. }
  16055. function parseInterpolation(context, mode) {
  16056. const [open, close] = context.options.delimiters;
  16057. const closeIndex = context.source.indexOf(close, open.length);
  16058. if (closeIndex === -1) {
  16059. emitError(context, 25);
  16060. return void 0;
  16061. }
  16062. const start = getCursor(context);
  16063. advanceBy(context, open.length);
  16064. const innerStart = getCursor(context);
  16065. const innerEnd = getCursor(context);
  16066. const rawContentLength = closeIndex - open.length;
  16067. const rawContent = context.source.slice(0, rawContentLength);
  16068. const preTrimContent = parseTextData(context, rawContentLength, mode);
  16069. const content = preTrimContent.trim();
  16070. const startOffset = preTrimContent.indexOf(content);
  16071. if (startOffset > 0) {
  16072. advancePositionWithMutation(innerStart, rawContent, startOffset);
  16073. }
  16074. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  16075. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  16076. advanceBy(context, close.length);
  16077. return {
  16078. type: 5,
  16079. content: {
  16080. type: 4,
  16081. isStatic: false,
  16082. // Set `isConstant` to false by default and will decide in transformExpression
  16083. constType: 0,
  16084. content,
  16085. loc: getSelection(context, innerStart, innerEnd)
  16086. },
  16087. loc: getSelection(context, start)
  16088. };
  16089. }
  16090. function parseText(context, mode) {
  16091. const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
  16092. let endIndex = context.source.length;
  16093. for (let i = 0; i < endTokens.length; i++) {
  16094. const index = context.source.indexOf(endTokens[i], 1);
  16095. if (index !== -1 && endIndex > index) {
  16096. endIndex = index;
  16097. }
  16098. }
  16099. const start = getCursor(context);
  16100. const content = parseTextData(context, endIndex, mode);
  16101. return {
  16102. type: 2,
  16103. content,
  16104. loc: getSelection(context, start)
  16105. };
  16106. }
  16107. function parseTextData(context, length, mode) {
  16108. const rawText = context.source.slice(0, length);
  16109. advanceBy(context, length);
  16110. if (mode === 2 || mode === 3 || !rawText.includes("&")) {
  16111. return rawText;
  16112. } else {
  16113. return context.options.decodeEntities(
  16114. rawText,
  16115. mode === 4
  16116. );
  16117. }
  16118. }
  16119. function getCursor(context) {
  16120. const { column, line, offset } = context;
  16121. return { column, line, offset };
  16122. }
  16123. function getSelection(context, start, end) {
  16124. end = end || getCursor(context);
  16125. return {
  16126. start,
  16127. end,
  16128. source: context.originalSource.slice(start.offset, end.offset)
  16129. };
  16130. }
  16131. function last(xs) {
  16132. return xs[xs.length - 1];
  16133. }
  16134. function startsWith(source, searchString) {
  16135. return source.startsWith(searchString);
  16136. }
  16137. function advanceBy(context, numberOfCharacters) {
  16138. const { source } = context;
  16139. advancePositionWithMutation(context, source, numberOfCharacters);
  16140. context.source = source.slice(numberOfCharacters);
  16141. }
  16142. function advanceSpaces(context) {
  16143. const match = /^[\t\r\n\f ]+/.exec(context.source);
  16144. if (match) {
  16145. advanceBy(context, match[0].length);
  16146. }
  16147. }
  16148. function getNewPosition(context, start, numberOfCharacters) {
  16149. return advancePositionWithClone(
  16150. start,
  16151. context.originalSource.slice(start.offset, numberOfCharacters),
  16152. numberOfCharacters
  16153. );
  16154. }
  16155. function emitError(context, code, offset, loc = getCursor(context)) {
  16156. if (offset) {
  16157. loc.offset += offset;
  16158. loc.column += offset;
  16159. }
  16160. context.options.onError(
  16161. createCompilerError(code, {
  16162. start: loc,
  16163. end: loc,
  16164. source: ""
  16165. })
  16166. );
  16167. }
  16168. function isEnd(context, mode, ancestors) {
  16169. const s = context.source;
  16170. switch (mode) {
  16171. case 0:
  16172. if (startsWith(s, "</")) {
  16173. for (let i = ancestors.length - 1; i >= 0; --i) {
  16174. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  16175. return true;
  16176. }
  16177. }
  16178. }
  16179. break;
  16180. case 1:
  16181. case 2: {
  16182. const parent = last(ancestors);
  16183. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  16184. return true;
  16185. }
  16186. break;
  16187. }
  16188. case 3:
  16189. if (startsWith(s, "]]>")) {
  16190. return true;
  16191. }
  16192. break;
  16193. }
  16194. return !s;
  16195. }
  16196. function startsWithEndTagOpen(source, tag) {
  16197. return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
  16198. }
  16199. function hoistStatic(root, context) {
  16200. walk$2(
  16201. root,
  16202. context,
  16203. // Root node is unfortunately non-hoistable due to potential parent
  16204. // fallthrough attributes.
  16205. isSingleElementRoot(root, root.children[0])
  16206. );
  16207. }
  16208. function isSingleElementRoot(root, child) {
  16209. const { children } = root;
  16210. return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
  16211. }
  16212. function walk$2(node, context, doNotHoistNode = false) {
  16213. const { children } = node;
  16214. const originalCount = children.length;
  16215. let hoistedCount = 0;
  16216. for (let i = 0; i < children.length; i++) {
  16217. const child = children[i];
  16218. if (child.type === 1 && child.tagType === 0) {
  16219. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  16220. if (constantType > 0) {
  16221. if (constantType >= 2) {
  16222. child.codegenNode.patchFlag = -1 + (` /* HOISTED */` );
  16223. child.codegenNode = context.hoist(child.codegenNode);
  16224. hoistedCount++;
  16225. continue;
  16226. }
  16227. } else {
  16228. const codegenNode = child.codegenNode;
  16229. if (codegenNode.type === 13) {
  16230. const flag = getPatchFlag(codegenNode);
  16231. if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  16232. const props = getNodeProps(child);
  16233. if (props) {
  16234. codegenNode.props = context.hoist(props);
  16235. }
  16236. }
  16237. if (codegenNode.dynamicProps) {
  16238. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  16239. }
  16240. }
  16241. }
  16242. }
  16243. if (child.type === 1) {
  16244. const isComponent = child.tagType === 1;
  16245. if (isComponent) {
  16246. context.scopes.vSlot++;
  16247. }
  16248. walk$2(child, context);
  16249. if (isComponent) {
  16250. context.scopes.vSlot--;
  16251. }
  16252. } else if (child.type === 11) {
  16253. walk$2(child, context, child.children.length === 1);
  16254. } else if (child.type === 9) {
  16255. for (let i2 = 0; i2 < child.branches.length; i2++) {
  16256. walk$2(
  16257. child.branches[i2],
  16258. context,
  16259. child.branches[i2].children.length === 1
  16260. );
  16261. }
  16262. }
  16263. }
  16264. if (hoistedCount && context.transformHoist) {
  16265. context.transformHoist(children, context, node);
  16266. }
  16267. if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray$3(node.codegenNode.children)) {
  16268. const hoisted = context.hoist(
  16269. createArrayExpression(node.codegenNode.children)
  16270. );
  16271. if (context.hmr) {
  16272. hoisted.content = `[...${hoisted.content}]`;
  16273. }
  16274. node.codegenNode.children = hoisted;
  16275. }
  16276. }
  16277. function getConstantType(node, context) {
  16278. const { constantCache } = context;
  16279. switch (node.type) {
  16280. case 1:
  16281. if (node.tagType !== 0) {
  16282. return 0;
  16283. }
  16284. const cached = constantCache.get(node);
  16285. if (cached !== void 0) {
  16286. return cached;
  16287. }
  16288. const codegenNode = node.codegenNode;
  16289. if (codegenNode.type !== 13) {
  16290. return 0;
  16291. }
  16292. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
  16293. return 0;
  16294. }
  16295. const flag = getPatchFlag(codegenNode);
  16296. if (!flag) {
  16297. let returnType2 = 3;
  16298. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  16299. if (generatedPropsType === 0) {
  16300. constantCache.set(node, 0);
  16301. return 0;
  16302. }
  16303. if (generatedPropsType < returnType2) {
  16304. returnType2 = generatedPropsType;
  16305. }
  16306. for (let i = 0; i < node.children.length; i++) {
  16307. const childType = getConstantType(node.children[i], context);
  16308. if (childType === 0) {
  16309. constantCache.set(node, 0);
  16310. return 0;
  16311. }
  16312. if (childType < returnType2) {
  16313. returnType2 = childType;
  16314. }
  16315. }
  16316. if (returnType2 > 1) {
  16317. for (let i = 0; i < node.props.length; i++) {
  16318. const p = node.props[i];
  16319. if (p.type === 7 && p.name === "bind" && p.exp) {
  16320. const expType = getConstantType(p.exp, context);
  16321. if (expType === 0) {
  16322. constantCache.set(node, 0);
  16323. return 0;
  16324. }
  16325. if (expType < returnType2) {
  16326. returnType2 = expType;
  16327. }
  16328. }
  16329. }
  16330. }
  16331. if (codegenNode.isBlock) {
  16332. for (let i = 0; i < node.props.length; i++) {
  16333. const p = node.props[i];
  16334. if (p.type === 7) {
  16335. constantCache.set(node, 0);
  16336. return 0;
  16337. }
  16338. }
  16339. context.removeHelper(OPEN_BLOCK);
  16340. context.removeHelper(
  16341. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  16342. );
  16343. codegenNode.isBlock = false;
  16344. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  16345. }
  16346. constantCache.set(node, returnType2);
  16347. return returnType2;
  16348. } else {
  16349. constantCache.set(node, 0);
  16350. return 0;
  16351. }
  16352. case 2:
  16353. case 3:
  16354. return 3;
  16355. case 9:
  16356. case 11:
  16357. case 10:
  16358. return 0;
  16359. case 5:
  16360. case 12:
  16361. return getConstantType(node.content, context);
  16362. case 4:
  16363. return node.constType;
  16364. case 8:
  16365. let returnType = 3;
  16366. for (let i = 0; i < node.children.length; i++) {
  16367. const child = node.children[i];
  16368. if (isString$2(child) || isSymbol$1(child)) {
  16369. continue;
  16370. }
  16371. const childType = getConstantType(child, context);
  16372. if (childType === 0) {
  16373. return 0;
  16374. } else if (childType < returnType) {
  16375. returnType = childType;
  16376. }
  16377. }
  16378. return returnType;
  16379. default:
  16380. return 0;
  16381. }
  16382. }
  16383. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  16384. NORMALIZE_CLASS,
  16385. NORMALIZE_STYLE,
  16386. NORMALIZE_PROPS,
  16387. GUARD_REACTIVE_PROPS
  16388. ]);
  16389. function getConstantTypeOfHelperCall(value, context) {
  16390. if (value.type === 14 && !isString$2(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  16391. const arg = value.arguments[0];
  16392. if (arg.type === 4) {
  16393. return getConstantType(arg, context);
  16394. } else if (arg.type === 14) {
  16395. return getConstantTypeOfHelperCall(arg, context);
  16396. }
  16397. }
  16398. return 0;
  16399. }
  16400. function getGeneratedPropsConstantType(node, context) {
  16401. let returnType = 3;
  16402. const props = getNodeProps(node);
  16403. if (props && props.type === 15) {
  16404. const { properties } = props;
  16405. for (let i = 0; i < properties.length; i++) {
  16406. const { key, value } = properties[i];
  16407. const keyType = getConstantType(key, context);
  16408. if (keyType === 0) {
  16409. return keyType;
  16410. }
  16411. if (keyType < returnType) {
  16412. returnType = keyType;
  16413. }
  16414. let valueType;
  16415. if (value.type === 4) {
  16416. valueType = getConstantType(value, context);
  16417. } else if (value.type === 14) {
  16418. valueType = getConstantTypeOfHelperCall(value, context);
  16419. } else {
  16420. valueType = 0;
  16421. }
  16422. if (valueType === 0) {
  16423. return valueType;
  16424. }
  16425. if (valueType < returnType) {
  16426. returnType = valueType;
  16427. }
  16428. }
  16429. }
  16430. return returnType;
  16431. }
  16432. function getNodeProps(node) {
  16433. const codegenNode = node.codegenNode;
  16434. if (codegenNode.type === 13) {
  16435. return codegenNode.props;
  16436. }
  16437. }
  16438. function getPatchFlag(node) {
  16439. const flag = node.patchFlag;
  16440. return flag ? parseInt(flag, 10) : void 0;
  16441. }
  16442. function createTransformContext(root, {
  16443. filename = "",
  16444. prefixIdentifiers = false,
  16445. hoistStatic: hoistStatic2 = false,
  16446. hmr = false,
  16447. cacheHandlers = false,
  16448. nodeTransforms = [],
  16449. directiveTransforms = {},
  16450. transformHoist = null,
  16451. isBuiltInComponent = NOOP,
  16452. isCustomElement = NOOP,
  16453. expressionPlugins = [],
  16454. scopeId = null,
  16455. slotted = true,
  16456. ssr = false,
  16457. inSSR = false,
  16458. ssrCssVars = ``,
  16459. bindingMetadata = EMPTY_OBJ,
  16460. inline = false,
  16461. isTS = false,
  16462. onError = defaultOnError,
  16463. onWarn = defaultOnWarn,
  16464. compatConfig
  16465. }) {
  16466. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  16467. const context = {
  16468. // options
  16469. selfName: nameMatch && capitalize$1(camelize(nameMatch[1])),
  16470. prefixIdentifiers,
  16471. hoistStatic: hoistStatic2,
  16472. hmr,
  16473. cacheHandlers,
  16474. nodeTransforms,
  16475. directiveTransforms,
  16476. transformHoist,
  16477. isBuiltInComponent,
  16478. isCustomElement,
  16479. expressionPlugins,
  16480. scopeId,
  16481. slotted,
  16482. ssr,
  16483. inSSR,
  16484. ssrCssVars,
  16485. bindingMetadata,
  16486. inline,
  16487. isTS,
  16488. onError,
  16489. onWarn,
  16490. compatConfig,
  16491. // state
  16492. root,
  16493. helpers: /* @__PURE__ */ new Map(),
  16494. components: /* @__PURE__ */ new Set(),
  16495. directives: /* @__PURE__ */ new Set(),
  16496. hoists: [],
  16497. imports: [],
  16498. constantCache: /* @__PURE__ */ new WeakMap(),
  16499. temps: 0,
  16500. cached: 0,
  16501. identifiers: /* @__PURE__ */ Object.create(null),
  16502. scopes: {
  16503. vFor: 0,
  16504. vSlot: 0,
  16505. vPre: 0,
  16506. vOnce: 0
  16507. },
  16508. parent: null,
  16509. currentNode: root,
  16510. childIndex: 0,
  16511. inVOnce: false,
  16512. // methods
  16513. helper(name) {
  16514. const count = context.helpers.get(name) || 0;
  16515. context.helpers.set(name, count + 1);
  16516. return name;
  16517. },
  16518. removeHelper(name) {
  16519. const count = context.helpers.get(name);
  16520. if (count) {
  16521. const currentCount = count - 1;
  16522. if (!currentCount) {
  16523. context.helpers.delete(name);
  16524. } else {
  16525. context.helpers.set(name, currentCount);
  16526. }
  16527. }
  16528. },
  16529. helperString(name) {
  16530. return `_${helperNameMap[context.helper(name)]}`;
  16531. },
  16532. replaceNode(node) {
  16533. {
  16534. if (!context.currentNode) {
  16535. throw new Error(`Node being replaced is already removed.`);
  16536. }
  16537. if (!context.parent) {
  16538. throw new Error(`Cannot replace root node.`);
  16539. }
  16540. }
  16541. context.parent.children[context.childIndex] = context.currentNode = node;
  16542. },
  16543. removeNode(node) {
  16544. if (!context.parent) {
  16545. throw new Error(`Cannot remove root node.`);
  16546. }
  16547. const list = context.parent.children;
  16548. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  16549. if (removalIndex < 0) {
  16550. throw new Error(`node being removed is not a child of current parent`);
  16551. }
  16552. if (!node || node === context.currentNode) {
  16553. context.currentNode = null;
  16554. context.onNodeRemoved();
  16555. } else {
  16556. if (context.childIndex > removalIndex) {
  16557. context.childIndex--;
  16558. context.onNodeRemoved();
  16559. }
  16560. }
  16561. context.parent.children.splice(removalIndex, 1);
  16562. },
  16563. onNodeRemoved: () => {
  16564. },
  16565. addIdentifiers(exp) {
  16566. {
  16567. if (isString$2(exp)) {
  16568. addId(exp);
  16569. } else if (exp.identifiers) {
  16570. exp.identifiers.forEach(addId);
  16571. } else if (exp.type === 4) {
  16572. addId(exp.content);
  16573. }
  16574. }
  16575. },
  16576. removeIdentifiers(exp) {
  16577. {
  16578. if (isString$2(exp)) {
  16579. removeId(exp);
  16580. } else if (exp.identifiers) {
  16581. exp.identifiers.forEach(removeId);
  16582. } else if (exp.type === 4) {
  16583. removeId(exp.content);
  16584. }
  16585. }
  16586. },
  16587. hoist(exp) {
  16588. if (isString$2(exp))
  16589. exp = createSimpleExpression(exp);
  16590. context.hoists.push(exp);
  16591. const identifier = createSimpleExpression(
  16592. `_hoisted_${context.hoists.length}`,
  16593. false,
  16594. exp.loc,
  16595. 2
  16596. );
  16597. identifier.hoisted = exp;
  16598. return identifier;
  16599. },
  16600. cache(exp, isVNode = false) {
  16601. return createCacheExpression(context.cached++, exp, isVNode);
  16602. }
  16603. };
  16604. function addId(id) {
  16605. const { identifiers } = context;
  16606. if (identifiers[id] === void 0) {
  16607. identifiers[id] = 0;
  16608. }
  16609. identifiers[id]++;
  16610. }
  16611. function removeId(id) {
  16612. context.identifiers[id]--;
  16613. }
  16614. return context;
  16615. }
  16616. function transform$1(root, options) {
  16617. const context = createTransformContext(root, options);
  16618. traverseNode(root, context);
  16619. if (options.hoistStatic) {
  16620. hoistStatic(root, context);
  16621. }
  16622. if (!options.ssr) {
  16623. createRootCodegen(root, context);
  16624. }
  16625. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  16626. root.components = [...context.components];
  16627. root.directives = [...context.directives];
  16628. root.imports = context.imports;
  16629. root.hoists = context.hoists;
  16630. root.temps = context.temps;
  16631. root.cached = context.cached;
  16632. }
  16633. function createRootCodegen(root, context) {
  16634. const { helper } = context;
  16635. const { children } = root;
  16636. if (children.length === 1) {
  16637. const child = children[0];
  16638. if (isSingleElementRoot(root, child) && child.codegenNode) {
  16639. const codegenNode = child.codegenNode;
  16640. if (codegenNode.type === 13) {
  16641. convertToBlock(codegenNode, context);
  16642. }
  16643. root.codegenNode = codegenNode;
  16644. } else {
  16645. root.codegenNode = child;
  16646. }
  16647. } else if (children.length > 1) {
  16648. let patchFlag = 64;
  16649. let patchFlagText = PatchFlagNames[64];
  16650. if (children.filter((c) => c.type !== 3).length === 1) {
  16651. patchFlag |= 2048;
  16652. patchFlagText += `, ${PatchFlagNames[2048]}`;
  16653. }
  16654. root.codegenNode = createVNodeCall(
  16655. context,
  16656. helper(FRAGMENT),
  16657. void 0,
  16658. root.children,
  16659. patchFlag + (` /* ${patchFlagText} */` ),
  16660. void 0,
  16661. void 0,
  16662. true,
  16663. void 0,
  16664. false
  16665. /* isComponent */
  16666. );
  16667. } else ;
  16668. }
  16669. function traverseChildren(parent, context) {
  16670. let i = 0;
  16671. const nodeRemoved = () => {
  16672. i--;
  16673. };
  16674. for (; i < parent.children.length; i++) {
  16675. const child = parent.children[i];
  16676. if (isString$2(child))
  16677. continue;
  16678. context.parent = parent;
  16679. context.childIndex = i;
  16680. context.onNodeRemoved = nodeRemoved;
  16681. traverseNode(child, context);
  16682. }
  16683. }
  16684. function traverseNode(node, context) {
  16685. context.currentNode = node;
  16686. const { nodeTransforms } = context;
  16687. const exitFns = [];
  16688. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  16689. const onExit = nodeTransforms[i2](node, context);
  16690. if (onExit) {
  16691. if (isArray$3(onExit)) {
  16692. exitFns.push(...onExit);
  16693. } else {
  16694. exitFns.push(onExit);
  16695. }
  16696. }
  16697. if (!context.currentNode) {
  16698. return;
  16699. } else {
  16700. node = context.currentNode;
  16701. }
  16702. }
  16703. switch (node.type) {
  16704. case 3:
  16705. if (!context.ssr) {
  16706. context.helper(CREATE_COMMENT);
  16707. }
  16708. break;
  16709. case 5:
  16710. if (!context.ssr) {
  16711. context.helper(TO_DISPLAY_STRING);
  16712. }
  16713. break;
  16714. case 9:
  16715. for (let i2 = 0; i2 < node.branches.length; i2++) {
  16716. traverseNode(node.branches[i2], context);
  16717. }
  16718. break;
  16719. case 10:
  16720. case 11:
  16721. case 1:
  16722. case 0:
  16723. traverseChildren(node, context);
  16724. break;
  16725. }
  16726. context.currentNode = node;
  16727. let i = exitFns.length;
  16728. while (i--) {
  16729. exitFns[i]();
  16730. }
  16731. }
  16732. function createStructuralDirectiveTransform(name, fn) {
  16733. const matches = isString$2(name) ? (n) => n === name : (n) => name.test(n);
  16734. return (node, context) => {
  16735. if (node.type === 1) {
  16736. const { props } = node;
  16737. if (node.tagType === 3 && props.some(isVSlot)) {
  16738. return;
  16739. }
  16740. const exitFns = [];
  16741. for (let i = 0; i < props.length; i++) {
  16742. const prop = props[i];
  16743. if (prop.type === 7 && matches(prop.name)) {
  16744. props.splice(i, 1);
  16745. i--;
  16746. const onExit = fn(node, prop, context);
  16747. if (onExit)
  16748. exitFns.push(onExit);
  16749. }
  16750. }
  16751. return exitFns;
  16752. }
  16753. };
  16754. }
  16755. var sourceMap$2 = {};
  16756. var sourceMapGenerator$1 = {};
  16757. var base64Vlq$1 = {};
  16758. var base64$3 = {};
  16759. /* -*- Mode: js; js-indent-level: 2; -*- */
  16760. /*
  16761. * Copyright 2011 Mozilla Foundation and contributors
  16762. * Licensed under the New BSD license. See LICENSE or:
  16763. * http://opensource.org/licenses/BSD-3-Clause
  16764. */
  16765. var intToCharMap$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  16766. /**
  16767. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  16768. */
  16769. base64$3.encode = function (number) {
  16770. if (0 <= number && number < intToCharMap$1.length) {
  16771. return intToCharMap$1[number];
  16772. }
  16773. throw new TypeError("Must be between 0 and 63: " + number);
  16774. };
  16775. /**
  16776. * Decode a single base 64 character code digit to an integer. Returns -1 on
  16777. * failure.
  16778. */
  16779. base64$3.decode = function (charCode) {
  16780. var bigA = 65; // 'A'
  16781. var bigZ = 90; // 'Z'
  16782. var littleA = 97; // 'a'
  16783. var littleZ = 122; // 'z'
  16784. var zero = 48; // '0'
  16785. var nine = 57; // '9'
  16786. var plus = 43; // '+'
  16787. var slash = 47; // '/'
  16788. var littleOffset = 26;
  16789. var numberOffset = 52;
  16790. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  16791. if (bigA <= charCode && charCode <= bigZ) {
  16792. return (charCode - bigA);
  16793. }
  16794. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  16795. if (littleA <= charCode && charCode <= littleZ) {
  16796. return (charCode - littleA + littleOffset);
  16797. }
  16798. // 52 - 61: 0123456789
  16799. if (zero <= charCode && charCode <= nine) {
  16800. return (charCode - zero + numberOffset);
  16801. }
  16802. // 62: +
  16803. if (charCode == plus) {
  16804. return 62;
  16805. }
  16806. // 63: /
  16807. if (charCode == slash) {
  16808. return 63;
  16809. }
  16810. // Invalid base64 digit.
  16811. return -1;
  16812. };
  16813. /* -*- Mode: js; js-indent-level: 2; -*- */
  16814. /*
  16815. * Copyright 2011 Mozilla Foundation and contributors
  16816. * Licensed under the New BSD license. See LICENSE or:
  16817. * http://opensource.org/licenses/BSD-3-Clause
  16818. *
  16819. * Based on the Base 64 VLQ implementation in Closure Compiler:
  16820. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  16821. *
  16822. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  16823. * Redistribution and use in source and binary forms, with or without
  16824. * modification, are permitted provided that the following conditions are
  16825. * met:
  16826. *
  16827. * * Redistributions of source code must retain the above copyright
  16828. * notice, this list of conditions and the following disclaimer.
  16829. * * Redistributions in binary form must reproduce the above
  16830. * copyright notice, this list of conditions and the following
  16831. * disclaimer in the documentation and/or other materials provided
  16832. * with the distribution.
  16833. * * Neither the name of Google Inc. nor the names of its
  16834. * contributors may be used to endorse or promote products derived
  16835. * from this software without specific prior written permission.
  16836. *
  16837. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16838. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16839. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16840. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  16841. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16842. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  16843. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  16844. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  16845. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  16846. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16847. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16848. */
  16849. var base64$2 = base64$3;
  16850. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  16851. // length quantities we use in the source map spec, the first bit is the sign,
  16852. // the next four bits are the actual value, and the 6th bit is the
  16853. // continuation bit. The continuation bit tells us whether there are more
  16854. // digits in this value following this digit.
  16855. //
  16856. // Continuation
  16857. // | Sign
  16858. // | |
  16859. // V V
  16860. // 101011
  16861. var VLQ_BASE_SHIFT$1 = 5;
  16862. // binary: 100000
  16863. var VLQ_BASE$1 = 1 << VLQ_BASE_SHIFT$1;
  16864. // binary: 011111
  16865. var VLQ_BASE_MASK$1 = VLQ_BASE$1 - 1;
  16866. // binary: 100000
  16867. var VLQ_CONTINUATION_BIT$1 = VLQ_BASE$1;
  16868. /**
  16869. * Converts from a two-complement value to a value where the sign bit is
  16870. * placed in the least significant bit. For example, as decimals:
  16871. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  16872. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  16873. */
  16874. function toVLQSigned$1(aValue) {
  16875. return aValue < 0
  16876. ? ((-aValue) << 1) + 1
  16877. : (aValue << 1) + 0;
  16878. }
  16879. /**
  16880. * Converts to a two-complement value from a value where the sign bit is
  16881. * placed in the least significant bit. For example, as decimals:
  16882. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  16883. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  16884. */
  16885. function fromVLQSigned$1(aValue) {
  16886. var isNegative = (aValue & 1) === 1;
  16887. var shifted = aValue >> 1;
  16888. return isNegative
  16889. ? -shifted
  16890. : shifted;
  16891. }
  16892. /**
  16893. * Returns the base 64 VLQ encoded value.
  16894. */
  16895. base64Vlq$1.encode = function base64VLQ_encode(aValue) {
  16896. var encoded = "";
  16897. var digit;
  16898. var vlq = toVLQSigned$1(aValue);
  16899. do {
  16900. digit = vlq & VLQ_BASE_MASK$1;
  16901. vlq >>>= VLQ_BASE_SHIFT$1;
  16902. if (vlq > 0) {
  16903. // There are still more digits in this value, so we must make sure the
  16904. // continuation bit is marked.
  16905. digit |= VLQ_CONTINUATION_BIT$1;
  16906. }
  16907. encoded += base64$2.encode(digit);
  16908. } while (vlq > 0);
  16909. return encoded;
  16910. };
  16911. /**
  16912. * Decodes the next base 64 VLQ value from the given string and returns the
  16913. * value and the rest of the string via the out parameter.
  16914. */
  16915. base64Vlq$1.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  16916. var strLen = aStr.length;
  16917. var result = 0;
  16918. var shift = 0;
  16919. var continuation, digit;
  16920. do {
  16921. if (aIndex >= strLen) {
  16922. throw new Error("Expected more digits in base 64 VLQ value.");
  16923. }
  16924. digit = base64$2.decode(aStr.charCodeAt(aIndex++));
  16925. if (digit === -1) {
  16926. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  16927. }
  16928. continuation = !!(digit & VLQ_CONTINUATION_BIT$1);
  16929. digit &= VLQ_BASE_MASK$1;
  16930. result = result + (digit << shift);
  16931. shift += VLQ_BASE_SHIFT$1;
  16932. } while (continuation);
  16933. aOutParam.value = fromVLQSigned$1(result);
  16934. aOutParam.rest = aIndex;
  16935. };
  16936. var util$c = {};
  16937. /* -*- Mode: js; js-indent-level: 2; -*- */
  16938. (function (exports) {
  16939. /*
  16940. * Copyright 2011 Mozilla Foundation and contributors
  16941. * Licensed under the New BSD license. See LICENSE or:
  16942. * http://opensource.org/licenses/BSD-3-Clause
  16943. */
  16944. /**
  16945. * This is a helper function for getting values from parameter/options
  16946. * objects.
  16947. *
  16948. * @param args The object we are extracting values from
  16949. * @param name The name of the property we are getting.
  16950. * @param defaultValue An optional value to return if the property is missing
  16951. * from the object. If this is not specified and the property is missing, an
  16952. * error will be thrown.
  16953. */
  16954. function getArg(aArgs, aName, aDefaultValue) {
  16955. if (aName in aArgs) {
  16956. return aArgs[aName];
  16957. } else if (arguments.length === 3) {
  16958. return aDefaultValue;
  16959. } else {
  16960. throw new Error('"' + aName + '" is a required argument.');
  16961. }
  16962. }
  16963. exports.getArg = getArg;
  16964. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  16965. var dataUrlRegexp = /^data:.+\,.+$/;
  16966. function urlParse(aUrl) {
  16967. var match = aUrl.match(urlRegexp);
  16968. if (!match) {
  16969. return null;
  16970. }
  16971. return {
  16972. scheme: match[1],
  16973. auth: match[2],
  16974. host: match[3],
  16975. port: match[4],
  16976. path: match[5]
  16977. };
  16978. }
  16979. exports.urlParse = urlParse;
  16980. function urlGenerate(aParsedUrl) {
  16981. var url = '';
  16982. if (aParsedUrl.scheme) {
  16983. url += aParsedUrl.scheme + ':';
  16984. }
  16985. url += '//';
  16986. if (aParsedUrl.auth) {
  16987. url += aParsedUrl.auth + '@';
  16988. }
  16989. if (aParsedUrl.host) {
  16990. url += aParsedUrl.host;
  16991. }
  16992. if (aParsedUrl.port) {
  16993. url += ":" + aParsedUrl.port;
  16994. }
  16995. if (aParsedUrl.path) {
  16996. url += aParsedUrl.path;
  16997. }
  16998. return url;
  16999. }
  17000. exports.urlGenerate = urlGenerate;
  17001. var MAX_CACHED_INPUTS = 32;
  17002. /**
  17003. * Takes some function `f(input) -> result` and returns a memoized version of
  17004. * `f`.
  17005. *
  17006. * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
  17007. * memoization is a dumb-simple, linear least-recently-used cache.
  17008. */
  17009. function lruMemoize(f) {
  17010. var cache = [];
  17011. return function(input) {
  17012. for (var i = 0; i < cache.length; i++) {
  17013. if (cache[i].input === input) {
  17014. var temp = cache[0];
  17015. cache[0] = cache[i];
  17016. cache[i] = temp;
  17017. return cache[0].result;
  17018. }
  17019. }
  17020. var result = f(input);
  17021. cache.unshift({
  17022. input,
  17023. result,
  17024. });
  17025. if (cache.length > MAX_CACHED_INPUTS) {
  17026. cache.pop();
  17027. }
  17028. return result;
  17029. };
  17030. }
  17031. /**
  17032. * Normalizes a path, or the path portion of a URL:
  17033. *
  17034. * - Replaces consecutive slashes with one slash.
  17035. * - Removes unnecessary '.' parts.
  17036. * - Removes unnecessary '<dir>/..' parts.
  17037. *
  17038. * Based on code in the Node.js 'path' core module.
  17039. *
  17040. * @param aPath The path or url to normalize.
  17041. */
  17042. var normalize = lruMemoize(function normalize(aPath) {
  17043. var path = aPath;
  17044. var url = urlParse(aPath);
  17045. if (url) {
  17046. if (!url.path) {
  17047. return aPath;
  17048. }
  17049. path = url.path;
  17050. }
  17051. var isAbsolute = exports.isAbsolute(path);
  17052. // Split the path into parts between `/` characters. This is much faster than
  17053. // using `.split(/\/+/g)`.
  17054. var parts = [];
  17055. var start = 0;
  17056. var i = 0;
  17057. while (true) {
  17058. start = i;
  17059. i = path.indexOf("/", start);
  17060. if (i === -1) {
  17061. parts.push(path.slice(start));
  17062. break;
  17063. } else {
  17064. parts.push(path.slice(start, i));
  17065. while (i < path.length && path[i] === "/") {
  17066. i++;
  17067. }
  17068. }
  17069. }
  17070. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  17071. part = parts[i];
  17072. if (part === '.') {
  17073. parts.splice(i, 1);
  17074. } else if (part === '..') {
  17075. up++;
  17076. } else if (up > 0) {
  17077. if (part === '') {
  17078. // The first part is blank if the path is absolute. Trying to go
  17079. // above the root is a no-op. Therefore we can remove all '..' parts
  17080. // directly after the root.
  17081. parts.splice(i + 1, up);
  17082. up = 0;
  17083. } else {
  17084. parts.splice(i, 2);
  17085. up--;
  17086. }
  17087. }
  17088. }
  17089. path = parts.join('/');
  17090. if (path === '') {
  17091. path = isAbsolute ? '/' : '.';
  17092. }
  17093. if (url) {
  17094. url.path = path;
  17095. return urlGenerate(url);
  17096. }
  17097. return path;
  17098. });
  17099. exports.normalize = normalize;
  17100. /**
  17101. * Joins two paths/URLs.
  17102. *
  17103. * @param aRoot The root path or URL.
  17104. * @param aPath The path or URL to be joined with the root.
  17105. *
  17106. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  17107. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  17108. * first.
  17109. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  17110. * is updated with the result and aRoot is returned. Otherwise the result
  17111. * is returned.
  17112. * - If aPath is absolute, the result is aPath.
  17113. * - Otherwise the two paths are joined with a slash.
  17114. * - Joining for example 'http://' and 'www.example.com' is also supported.
  17115. */
  17116. function join(aRoot, aPath) {
  17117. if (aRoot === "") {
  17118. aRoot = ".";
  17119. }
  17120. if (aPath === "") {
  17121. aPath = ".";
  17122. }
  17123. var aPathUrl = urlParse(aPath);
  17124. var aRootUrl = urlParse(aRoot);
  17125. if (aRootUrl) {
  17126. aRoot = aRootUrl.path || '/';
  17127. }
  17128. // `join(foo, '//www.example.org')`
  17129. if (aPathUrl && !aPathUrl.scheme) {
  17130. if (aRootUrl) {
  17131. aPathUrl.scheme = aRootUrl.scheme;
  17132. }
  17133. return urlGenerate(aPathUrl);
  17134. }
  17135. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  17136. return aPath;
  17137. }
  17138. // `join('http://', 'www.example.com')`
  17139. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  17140. aRootUrl.host = aPath;
  17141. return urlGenerate(aRootUrl);
  17142. }
  17143. var joined = aPath.charAt(0) === '/'
  17144. ? aPath
  17145. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  17146. if (aRootUrl) {
  17147. aRootUrl.path = joined;
  17148. return urlGenerate(aRootUrl);
  17149. }
  17150. return joined;
  17151. }
  17152. exports.join = join;
  17153. exports.isAbsolute = function (aPath) {
  17154. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  17155. };
  17156. /**
  17157. * Make a path relative to a URL or another path.
  17158. *
  17159. * @param aRoot The root path or URL.
  17160. * @param aPath The path or URL to be made relative to aRoot.
  17161. */
  17162. function relative(aRoot, aPath) {
  17163. if (aRoot === "") {
  17164. aRoot = ".";
  17165. }
  17166. aRoot = aRoot.replace(/\/$/, '');
  17167. // It is possible for the path to be above the root. In this case, simply
  17168. // checking whether the root is a prefix of the path won't work. Instead, we
  17169. // need to remove components from the root one by one, until either we find
  17170. // a prefix that fits, or we run out of components to remove.
  17171. var level = 0;
  17172. while (aPath.indexOf(aRoot + '/') !== 0) {
  17173. var index = aRoot.lastIndexOf("/");
  17174. if (index < 0) {
  17175. return aPath;
  17176. }
  17177. // If the only part of the root that is left is the scheme (i.e. http://,
  17178. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  17179. // have exhausted all components, so the path is not relative to the root.
  17180. aRoot = aRoot.slice(0, index);
  17181. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  17182. return aPath;
  17183. }
  17184. ++level;
  17185. }
  17186. // Make sure we add a "../" for each component we removed from the root.
  17187. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  17188. }
  17189. exports.relative = relative;
  17190. var supportsNullProto = (function () {
  17191. var obj = Object.create(null);
  17192. return !('__proto__' in obj);
  17193. }());
  17194. function identity (s) {
  17195. return s;
  17196. }
  17197. /**
  17198. * Because behavior goes wacky when you set `__proto__` on objects, we
  17199. * have to prefix all the strings in our set with an arbitrary character.
  17200. *
  17201. * See https://github.com/mozilla/source-map/pull/31 and
  17202. * https://github.com/mozilla/source-map/issues/30
  17203. *
  17204. * @param String aStr
  17205. */
  17206. function toSetString(aStr) {
  17207. if (isProtoString(aStr)) {
  17208. return '$' + aStr;
  17209. }
  17210. return aStr;
  17211. }
  17212. exports.toSetString = supportsNullProto ? identity : toSetString;
  17213. function fromSetString(aStr) {
  17214. if (isProtoString(aStr)) {
  17215. return aStr.slice(1);
  17216. }
  17217. return aStr;
  17218. }
  17219. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  17220. function isProtoString(s) {
  17221. if (!s) {
  17222. return false;
  17223. }
  17224. var length = s.length;
  17225. if (length < 9 /* "__proto__".length */) {
  17226. return false;
  17227. }
  17228. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  17229. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  17230. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  17231. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  17232. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  17233. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  17234. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  17235. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  17236. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  17237. return false;
  17238. }
  17239. for (var i = length - 10; i >= 0; i--) {
  17240. if (s.charCodeAt(i) !== 36 /* '$' */) {
  17241. return false;
  17242. }
  17243. }
  17244. return true;
  17245. }
  17246. /**
  17247. * Comparator between two mappings where the original positions are compared.
  17248. *
  17249. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  17250. * mappings with the same original source/line/column, but different generated
  17251. * line and column the same. Useful when searching for a mapping with a
  17252. * stubbed out mapping.
  17253. */
  17254. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  17255. var cmp = strcmp(mappingA.source, mappingB.source);
  17256. if (cmp !== 0) {
  17257. return cmp;
  17258. }
  17259. cmp = mappingA.originalLine - mappingB.originalLine;
  17260. if (cmp !== 0) {
  17261. return cmp;
  17262. }
  17263. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17264. if (cmp !== 0 || onlyCompareOriginal) {
  17265. return cmp;
  17266. }
  17267. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17268. if (cmp !== 0) {
  17269. return cmp;
  17270. }
  17271. cmp = mappingA.generatedLine - mappingB.generatedLine;
  17272. if (cmp !== 0) {
  17273. return cmp;
  17274. }
  17275. return strcmp(mappingA.name, mappingB.name);
  17276. }
  17277. exports.compareByOriginalPositions = compareByOriginalPositions;
  17278. function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
  17279. var cmp;
  17280. cmp = mappingA.originalLine - mappingB.originalLine;
  17281. if (cmp !== 0) {
  17282. return cmp;
  17283. }
  17284. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17285. if (cmp !== 0 || onlyCompareOriginal) {
  17286. return cmp;
  17287. }
  17288. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17289. if (cmp !== 0) {
  17290. return cmp;
  17291. }
  17292. cmp = mappingA.generatedLine - mappingB.generatedLine;
  17293. if (cmp !== 0) {
  17294. return cmp;
  17295. }
  17296. return strcmp(mappingA.name, mappingB.name);
  17297. }
  17298. exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
  17299. /**
  17300. * Comparator between two mappings with deflated source and name indices where
  17301. * the generated positions are compared.
  17302. *
  17303. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  17304. * mappings with the same generated line and column, but different
  17305. * source/name/original line and column the same. Useful when searching for a
  17306. * mapping with a stubbed out mapping.
  17307. */
  17308. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  17309. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  17310. if (cmp !== 0) {
  17311. return cmp;
  17312. }
  17313. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17314. if (cmp !== 0 || onlyCompareGenerated) {
  17315. return cmp;
  17316. }
  17317. cmp = strcmp(mappingA.source, mappingB.source);
  17318. if (cmp !== 0) {
  17319. return cmp;
  17320. }
  17321. cmp = mappingA.originalLine - mappingB.originalLine;
  17322. if (cmp !== 0) {
  17323. return cmp;
  17324. }
  17325. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17326. if (cmp !== 0) {
  17327. return cmp;
  17328. }
  17329. return strcmp(mappingA.name, mappingB.name);
  17330. }
  17331. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  17332. function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
  17333. var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17334. if (cmp !== 0 || onlyCompareGenerated) {
  17335. return cmp;
  17336. }
  17337. cmp = strcmp(mappingA.source, mappingB.source);
  17338. if (cmp !== 0) {
  17339. return cmp;
  17340. }
  17341. cmp = mappingA.originalLine - mappingB.originalLine;
  17342. if (cmp !== 0) {
  17343. return cmp;
  17344. }
  17345. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17346. if (cmp !== 0) {
  17347. return cmp;
  17348. }
  17349. return strcmp(mappingA.name, mappingB.name);
  17350. }
  17351. exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
  17352. function strcmp(aStr1, aStr2) {
  17353. if (aStr1 === aStr2) {
  17354. return 0;
  17355. }
  17356. if (aStr1 === null) {
  17357. return 1; // aStr2 !== null
  17358. }
  17359. if (aStr2 === null) {
  17360. return -1; // aStr1 !== null
  17361. }
  17362. if (aStr1 > aStr2) {
  17363. return 1;
  17364. }
  17365. return -1;
  17366. }
  17367. /**
  17368. * Comparator between two mappings with inflated source and name strings where
  17369. * the generated positions are compared.
  17370. */
  17371. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  17372. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  17373. if (cmp !== 0) {
  17374. return cmp;
  17375. }
  17376. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  17377. if (cmp !== 0) {
  17378. return cmp;
  17379. }
  17380. cmp = strcmp(mappingA.source, mappingB.source);
  17381. if (cmp !== 0) {
  17382. return cmp;
  17383. }
  17384. cmp = mappingA.originalLine - mappingB.originalLine;
  17385. if (cmp !== 0) {
  17386. return cmp;
  17387. }
  17388. cmp = mappingA.originalColumn - mappingB.originalColumn;
  17389. if (cmp !== 0) {
  17390. return cmp;
  17391. }
  17392. return strcmp(mappingA.name, mappingB.name);
  17393. }
  17394. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  17395. /**
  17396. * Strip any JSON XSSI avoidance prefix from the string (as documented
  17397. * in the source maps specification), and then parse the string as
  17398. * JSON.
  17399. */
  17400. function parseSourceMapInput(str) {
  17401. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  17402. }
  17403. exports.parseSourceMapInput = parseSourceMapInput;
  17404. /**
  17405. * Compute the URL of a source given the the source root, the source's
  17406. * URL, and the source map's URL.
  17407. */
  17408. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  17409. sourceURL = sourceURL || '';
  17410. if (sourceRoot) {
  17411. // This follows what Chrome does.
  17412. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  17413. sourceRoot += '/';
  17414. }
  17415. // The spec says:
  17416. // Line 4: An optional source root, useful for relocating source
  17417. // files on a server or removing repeated values in the
  17418. // “sources” entry. This value is prepended to the individual
  17419. // entries in the “source” field.
  17420. sourceURL = sourceRoot + sourceURL;
  17421. }
  17422. // Historically, SourceMapConsumer did not take the sourceMapURL as
  17423. // a parameter. This mode is still somewhat supported, which is why
  17424. // this code block is conditional. However, it's preferable to pass
  17425. // the source map URL to SourceMapConsumer, so that this function
  17426. // can implement the source URL resolution algorithm as outlined in
  17427. // the spec. This block is basically the equivalent of:
  17428. // new URL(sourceURL, sourceMapURL).toString()
  17429. // ... except it avoids using URL, which wasn't available in the
  17430. // older releases of node still supported by this library.
  17431. //
  17432. // The spec says:
  17433. // If the sources are not absolute URLs after prepending of the
  17434. // “sourceRoot”, the sources are resolved relative to the
  17435. // SourceMap (like resolving script src in a html document).
  17436. if (sourceMapURL) {
  17437. var parsed = urlParse(sourceMapURL);
  17438. if (!parsed) {
  17439. throw new Error("sourceMapURL could not be parsed");
  17440. }
  17441. if (parsed.path) {
  17442. // Strip the last path component, but keep the "/".
  17443. var index = parsed.path.lastIndexOf('/');
  17444. if (index >= 0) {
  17445. parsed.path = parsed.path.substring(0, index + 1);
  17446. }
  17447. }
  17448. sourceURL = join(urlGenerate(parsed), sourceURL);
  17449. }
  17450. return normalize(sourceURL);
  17451. }
  17452. exports.computeSourceURL = computeSourceURL;
  17453. } (util$c));
  17454. var arraySet$1 = {};
  17455. /* -*- Mode: js; js-indent-level: 2; -*- */
  17456. /*
  17457. * Copyright 2011 Mozilla Foundation and contributors
  17458. * Licensed under the New BSD license. See LICENSE or:
  17459. * http://opensource.org/licenses/BSD-3-Clause
  17460. */
  17461. var util$b = util$c;
  17462. var has$1 = Object.prototype.hasOwnProperty;
  17463. var hasNativeMap$1 = typeof Map !== "undefined";
  17464. /**
  17465. * A data structure which is a combination of an array and a set. Adding a new
  17466. * member is O(1), testing for membership is O(1), and finding the index of an
  17467. * element is O(1). Removing elements from the set is not supported. Only
  17468. * strings are supported for membership.
  17469. */
  17470. function ArraySet$5() {
  17471. this._array = [];
  17472. this._set = hasNativeMap$1 ? new Map() : Object.create(null);
  17473. }
  17474. /**
  17475. * Static method for creating ArraySet instances from an existing array.
  17476. */
  17477. ArraySet$5.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  17478. var set = new ArraySet$5();
  17479. for (var i = 0, len = aArray.length; i < len; i++) {
  17480. set.add(aArray[i], aAllowDuplicates);
  17481. }
  17482. return set;
  17483. };
  17484. /**
  17485. * Return how many unique items are in this ArraySet. If duplicates have been
  17486. * added, than those do not count towards the size.
  17487. *
  17488. * @returns Number
  17489. */
  17490. ArraySet$5.prototype.size = function ArraySet_size() {
  17491. return hasNativeMap$1 ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  17492. };
  17493. /**
  17494. * Add the given string to this set.
  17495. *
  17496. * @param String aStr
  17497. */
  17498. ArraySet$5.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  17499. var sStr = hasNativeMap$1 ? aStr : util$b.toSetString(aStr);
  17500. var isDuplicate = hasNativeMap$1 ? this.has(aStr) : has$1.call(this._set, sStr);
  17501. var idx = this._array.length;
  17502. if (!isDuplicate || aAllowDuplicates) {
  17503. this._array.push(aStr);
  17504. }
  17505. if (!isDuplicate) {
  17506. if (hasNativeMap$1) {
  17507. this._set.set(aStr, idx);
  17508. } else {
  17509. this._set[sStr] = idx;
  17510. }
  17511. }
  17512. };
  17513. /**
  17514. * Is the given string a member of this set?
  17515. *
  17516. * @param String aStr
  17517. */
  17518. ArraySet$5.prototype.has = function ArraySet_has(aStr) {
  17519. if (hasNativeMap$1) {
  17520. return this._set.has(aStr);
  17521. } else {
  17522. var sStr = util$b.toSetString(aStr);
  17523. return has$1.call(this._set, sStr);
  17524. }
  17525. };
  17526. /**
  17527. * What is the index of the given string in the array?
  17528. *
  17529. * @param String aStr
  17530. */
  17531. ArraySet$5.prototype.indexOf = function ArraySet_indexOf(aStr) {
  17532. if (hasNativeMap$1) {
  17533. var idx = this._set.get(aStr);
  17534. if (idx >= 0) {
  17535. return idx;
  17536. }
  17537. } else {
  17538. var sStr = util$b.toSetString(aStr);
  17539. if (has$1.call(this._set, sStr)) {
  17540. return this._set[sStr];
  17541. }
  17542. }
  17543. throw new Error('"' + aStr + '" is not in the set.');
  17544. };
  17545. /**
  17546. * What is the element at the given index?
  17547. *
  17548. * @param Number aIdx
  17549. */
  17550. ArraySet$5.prototype.at = function ArraySet_at(aIdx) {
  17551. if (aIdx >= 0 && aIdx < this._array.length) {
  17552. return this._array[aIdx];
  17553. }
  17554. throw new Error('No element indexed by ' + aIdx);
  17555. };
  17556. /**
  17557. * Returns the array representation of this set (which has the proper indices
  17558. * indicated by indexOf). Note that this is a copy of the internal array used
  17559. * for storing the members so that no one can mess with internal state.
  17560. */
  17561. ArraySet$5.prototype.toArray = function ArraySet_toArray() {
  17562. return this._array.slice();
  17563. };
  17564. arraySet$1.ArraySet = ArraySet$5;
  17565. var mappingList$1 = {};
  17566. /* -*- Mode: js; js-indent-level: 2; -*- */
  17567. /*
  17568. * Copyright 2014 Mozilla Foundation and contributors
  17569. * Licensed under the New BSD license. See LICENSE or:
  17570. * http://opensource.org/licenses/BSD-3-Clause
  17571. */
  17572. var util$a = util$c;
  17573. /**
  17574. * Determine whether mappingB is after mappingA with respect to generated
  17575. * position.
  17576. */
  17577. function generatedPositionAfter$1(mappingA, mappingB) {
  17578. // Optimized for most common case
  17579. var lineA = mappingA.generatedLine;
  17580. var lineB = mappingB.generatedLine;
  17581. var columnA = mappingA.generatedColumn;
  17582. var columnB = mappingB.generatedColumn;
  17583. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  17584. util$a.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  17585. }
  17586. /**
  17587. * A data structure to provide a sorted view of accumulated mappings in a
  17588. * performance conscious manner. It trades a neglibable overhead in general
  17589. * case for a large speedup in case of mappings being added in order.
  17590. */
  17591. function MappingList$3() {
  17592. this._array = [];
  17593. this._sorted = true;
  17594. // Serves as infimum
  17595. this._last = {generatedLine: -1, generatedColumn: 0};
  17596. }
  17597. /**
  17598. * Iterate through internal items. This method takes the same arguments that
  17599. * `Array.prototype.forEach` takes.
  17600. *
  17601. * NOTE: The order of the mappings is NOT guaranteed.
  17602. */
  17603. MappingList$3.prototype.unsortedForEach =
  17604. function MappingList_forEach(aCallback, aThisArg) {
  17605. this._array.forEach(aCallback, aThisArg);
  17606. };
  17607. /**
  17608. * Add the given source mapping.
  17609. *
  17610. * @param Object aMapping
  17611. */
  17612. MappingList$3.prototype.add = function MappingList_add(aMapping) {
  17613. if (generatedPositionAfter$1(this._last, aMapping)) {
  17614. this._last = aMapping;
  17615. this._array.push(aMapping);
  17616. } else {
  17617. this._sorted = false;
  17618. this._array.push(aMapping);
  17619. }
  17620. };
  17621. /**
  17622. * Returns the flat, sorted array of mappings. The mappings are sorted by
  17623. * generated position.
  17624. *
  17625. * WARNING: This method returns internal data without copying, for
  17626. * performance. The return value must NOT be mutated, and should be treated as
  17627. * an immutable borrow. If you want to take ownership, you must make your own
  17628. * copy.
  17629. */
  17630. MappingList$3.prototype.toArray = function MappingList_toArray() {
  17631. if (!this._sorted) {
  17632. this._array.sort(util$a.compareByGeneratedPositionsInflated);
  17633. this._sorted = true;
  17634. }
  17635. return this._array;
  17636. };
  17637. mappingList$1.MappingList = MappingList$3;
  17638. /* -*- Mode: js; js-indent-level: 2; -*- */
  17639. /*
  17640. * Copyright 2011 Mozilla Foundation and contributors
  17641. * Licensed under the New BSD license. See LICENSE or:
  17642. * http://opensource.org/licenses/BSD-3-Clause
  17643. */
  17644. var base64VLQ$3 = base64Vlq$1;
  17645. var util$9 = util$c;
  17646. var ArraySet$4 = arraySet$1.ArraySet;
  17647. var MappingList$2 = mappingList$1.MappingList;
  17648. /**
  17649. * An instance of the SourceMapGenerator represents a source map which is
  17650. * being built incrementally. You may pass an object with the following
  17651. * properties:
  17652. *
  17653. * - file: The filename of the generated source.
  17654. * - sourceRoot: A root for all relative URLs in this source map.
  17655. */
  17656. function SourceMapGenerator$8(aArgs) {
  17657. if (!aArgs) {
  17658. aArgs = {};
  17659. }
  17660. this._file = util$9.getArg(aArgs, 'file', null);
  17661. this._sourceRoot = util$9.getArg(aArgs, 'sourceRoot', null);
  17662. this._skipValidation = util$9.getArg(aArgs, 'skipValidation', false);
  17663. this._sources = new ArraySet$4();
  17664. this._names = new ArraySet$4();
  17665. this._mappings = new MappingList$2();
  17666. this._sourcesContents = null;
  17667. }
  17668. SourceMapGenerator$8.prototype._version = 3;
  17669. /**
  17670. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  17671. *
  17672. * @param aSourceMapConsumer The SourceMap.
  17673. */
  17674. SourceMapGenerator$8.fromSourceMap =
  17675. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  17676. var sourceRoot = aSourceMapConsumer.sourceRoot;
  17677. var generator = new SourceMapGenerator$8({
  17678. file: aSourceMapConsumer.file,
  17679. sourceRoot: sourceRoot
  17680. });
  17681. aSourceMapConsumer.eachMapping(function (mapping) {
  17682. var newMapping = {
  17683. generated: {
  17684. line: mapping.generatedLine,
  17685. column: mapping.generatedColumn
  17686. }
  17687. };
  17688. if (mapping.source != null) {
  17689. newMapping.source = mapping.source;
  17690. if (sourceRoot != null) {
  17691. newMapping.source = util$9.relative(sourceRoot, newMapping.source);
  17692. }
  17693. newMapping.original = {
  17694. line: mapping.originalLine,
  17695. column: mapping.originalColumn
  17696. };
  17697. if (mapping.name != null) {
  17698. newMapping.name = mapping.name;
  17699. }
  17700. }
  17701. generator.addMapping(newMapping);
  17702. });
  17703. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  17704. var sourceRelative = sourceFile;
  17705. if (sourceRoot !== null) {
  17706. sourceRelative = util$9.relative(sourceRoot, sourceFile);
  17707. }
  17708. if (!generator._sources.has(sourceRelative)) {
  17709. generator._sources.add(sourceRelative);
  17710. }
  17711. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  17712. if (content != null) {
  17713. generator.setSourceContent(sourceFile, content);
  17714. }
  17715. });
  17716. return generator;
  17717. };
  17718. /**
  17719. * Add a single mapping from original source line and column to the generated
  17720. * source's line and column for this source map being created. The mapping
  17721. * object should have the following properties:
  17722. *
  17723. * - generated: An object with the generated line and column positions.
  17724. * - original: An object with the original line and column positions.
  17725. * - source: The original source file (relative to the sourceRoot).
  17726. * - name: An optional original token name for this mapping.
  17727. */
  17728. SourceMapGenerator$8.prototype.addMapping =
  17729. function SourceMapGenerator_addMapping(aArgs) {
  17730. var generated = util$9.getArg(aArgs, 'generated');
  17731. var original = util$9.getArg(aArgs, 'original', null);
  17732. var source = util$9.getArg(aArgs, 'source', null);
  17733. var name = util$9.getArg(aArgs, 'name', null);
  17734. if (!this._skipValidation) {
  17735. this._validateMapping(generated, original, source, name);
  17736. }
  17737. if (source != null) {
  17738. source = String(source);
  17739. if (!this._sources.has(source)) {
  17740. this._sources.add(source);
  17741. }
  17742. }
  17743. if (name != null) {
  17744. name = String(name);
  17745. if (!this._names.has(name)) {
  17746. this._names.add(name);
  17747. }
  17748. }
  17749. this._mappings.add({
  17750. generatedLine: generated.line,
  17751. generatedColumn: generated.column,
  17752. originalLine: original != null && original.line,
  17753. originalColumn: original != null && original.column,
  17754. source: source,
  17755. name: name
  17756. });
  17757. };
  17758. /**
  17759. * Set the source content for a source file.
  17760. */
  17761. SourceMapGenerator$8.prototype.setSourceContent =
  17762. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  17763. var source = aSourceFile;
  17764. if (this._sourceRoot != null) {
  17765. source = util$9.relative(this._sourceRoot, source);
  17766. }
  17767. if (aSourceContent != null) {
  17768. // Add the source content to the _sourcesContents map.
  17769. // Create a new _sourcesContents map if the property is null.
  17770. if (!this._sourcesContents) {
  17771. this._sourcesContents = Object.create(null);
  17772. }
  17773. this._sourcesContents[util$9.toSetString(source)] = aSourceContent;
  17774. } else if (this._sourcesContents) {
  17775. // Remove the source file from the _sourcesContents map.
  17776. // If the _sourcesContents map is empty, set the property to null.
  17777. delete this._sourcesContents[util$9.toSetString(source)];
  17778. if (Object.keys(this._sourcesContents).length === 0) {
  17779. this._sourcesContents = null;
  17780. }
  17781. }
  17782. };
  17783. /**
  17784. * Applies the mappings of a sub-source-map for a specific source file to the
  17785. * source map being generated. Each mapping to the supplied source file is
  17786. * rewritten using the supplied source map. Note: The resolution for the
  17787. * resulting mappings is the minimium of this map and the supplied map.
  17788. *
  17789. * @param aSourceMapConsumer The source map to be applied.
  17790. * @param aSourceFile Optional. The filename of the source file.
  17791. * If omitted, SourceMapConsumer's file property will be used.
  17792. * @param aSourceMapPath Optional. The dirname of the path to the source map
  17793. * to be applied. If relative, it is relative to the SourceMapConsumer.
  17794. * This parameter is needed when the two source maps aren't in the same
  17795. * directory, and the source map to be applied contains relative source
  17796. * paths. If so, those relative source paths need to be rewritten
  17797. * relative to the SourceMapGenerator.
  17798. */
  17799. SourceMapGenerator$8.prototype.applySourceMap =
  17800. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  17801. var sourceFile = aSourceFile;
  17802. // If aSourceFile is omitted, we will use the file property of the SourceMap
  17803. if (aSourceFile == null) {
  17804. if (aSourceMapConsumer.file == null) {
  17805. throw new Error(
  17806. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  17807. 'or the source map\'s "file" property. Both were omitted.'
  17808. );
  17809. }
  17810. sourceFile = aSourceMapConsumer.file;
  17811. }
  17812. var sourceRoot = this._sourceRoot;
  17813. // Make "sourceFile" relative if an absolute Url is passed.
  17814. if (sourceRoot != null) {
  17815. sourceFile = util$9.relative(sourceRoot, sourceFile);
  17816. }
  17817. // Applying the SourceMap can add and remove items from the sources and
  17818. // the names array.
  17819. var newSources = new ArraySet$4();
  17820. var newNames = new ArraySet$4();
  17821. // Find mappings for the "sourceFile"
  17822. this._mappings.unsortedForEach(function (mapping) {
  17823. if (mapping.source === sourceFile && mapping.originalLine != null) {
  17824. // Check if it can be mapped by the source map, then update the mapping.
  17825. var original = aSourceMapConsumer.originalPositionFor({
  17826. line: mapping.originalLine,
  17827. column: mapping.originalColumn
  17828. });
  17829. if (original.source != null) {
  17830. // Copy mapping
  17831. mapping.source = original.source;
  17832. if (aSourceMapPath != null) {
  17833. mapping.source = util$9.join(aSourceMapPath, mapping.source);
  17834. }
  17835. if (sourceRoot != null) {
  17836. mapping.source = util$9.relative(sourceRoot, mapping.source);
  17837. }
  17838. mapping.originalLine = original.line;
  17839. mapping.originalColumn = original.column;
  17840. if (original.name != null) {
  17841. mapping.name = original.name;
  17842. }
  17843. }
  17844. }
  17845. var source = mapping.source;
  17846. if (source != null && !newSources.has(source)) {
  17847. newSources.add(source);
  17848. }
  17849. var name = mapping.name;
  17850. if (name != null && !newNames.has(name)) {
  17851. newNames.add(name);
  17852. }
  17853. }, this);
  17854. this._sources = newSources;
  17855. this._names = newNames;
  17856. // Copy sourcesContents of applied map.
  17857. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  17858. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  17859. if (content != null) {
  17860. if (aSourceMapPath != null) {
  17861. sourceFile = util$9.join(aSourceMapPath, sourceFile);
  17862. }
  17863. if (sourceRoot != null) {
  17864. sourceFile = util$9.relative(sourceRoot, sourceFile);
  17865. }
  17866. this.setSourceContent(sourceFile, content);
  17867. }
  17868. }, this);
  17869. };
  17870. /**
  17871. * A mapping can have one of the three levels of data:
  17872. *
  17873. * 1. Just the generated position.
  17874. * 2. The Generated position, original position, and original source.
  17875. * 3. Generated and original position, original source, as well as a name
  17876. * token.
  17877. *
  17878. * To maintain consistency, we validate that any new mapping being added falls
  17879. * in to one of these categories.
  17880. */
  17881. SourceMapGenerator$8.prototype._validateMapping =
  17882. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  17883. aName) {
  17884. // When aOriginal is truthy but has empty values for .line and .column,
  17885. // it is most likely a programmer error. In this case we throw a very
  17886. // specific error message to try to guide them the right way.
  17887. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  17888. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  17889. throw new Error(
  17890. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  17891. 'the original mapping entirely and only map the generated position. If so, pass ' +
  17892. 'null for the original mapping instead of an object with empty or null values.'
  17893. );
  17894. }
  17895. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  17896. && aGenerated.line > 0 && aGenerated.column >= 0
  17897. && !aOriginal && !aSource && !aName) {
  17898. // Case 1.
  17899. return;
  17900. }
  17901. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  17902. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  17903. && aGenerated.line > 0 && aGenerated.column >= 0
  17904. && aOriginal.line > 0 && aOriginal.column >= 0
  17905. && aSource) {
  17906. // Cases 2 and 3.
  17907. return;
  17908. }
  17909. else {
  17910. throw new Error('Invalid mapping: ' + JSON.stringify({
  17911. generated: aGenerated,
  17912. source: aSource,
  17913. original: aOriginal,
  17914. name: aName
  17915. }));
  17916. }
  17917. };
  17918. /**
  17919. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  17920. * specified by the source map format.
  17921. */
  17922. SourceMapGenerator$8.prototype._serializeMappings =
  17923. function SourceMapGenerator_serializeMappings() {
  17924. var previousGeneratedColumn = 0;
  17925. var previousGeneratedLine = 1;
  17926. var previousOriginalColumn = 0;
  17927. var previousOriginalLine = 0;
  17928. var previousName = 0;
  17929. var previousSource = 0;
  17930. var result = '';
  17931. var next;
  17932. var mapping;
  17933. var nameIdx;
  17934. var sourceIdx;
  17935. var mappings = this._mappings.toArray();
  17936. for (var i = 0, len = mappings.length; i < len; i++) {
  17937. mapping = mappings[i];
  17938. next = '';
  17939. if (mapping.generatedLine !== previousGeneratedLine) {
  17940. previousGeneratedColumn = 0;
  17941. while (mapping.generatedLine !== previousGeneratedLine) {
  17942. next += ';';
  17943. previousGeneratedLine++;
  17944. }
  17945. }
  17946. else {
  17947. if (i > 0) {
  17948. if (!util$9.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  17949. continue;
  17950. }
  17951. next += ',';
  17952. }
  17953. }
  17954. next += base64VLQ$3.encode(mapping.generatedColumn
  17955. - previousGeneratedColumn);
  17956. previousGeneratedColumn = mapping.generatedColumn;
  17957. if (mapping.source != null) {
  17958. sourceIdx = this._sources.indexOf(mapping.source);
  17959. next += base64VLQ$3.encode(sourceIdx - previousSource);
  17960. previousSource = sourceIdx;
  17961. // lines are stored 0-based in SourceMap spec version 3
  17962. next += base64VLQ$3.encode(mapping.originalLine - 1
  17963. - previousOriginalLine);
  17964. previousOriginalLine = mapping.originalLine - 1;
  17965. next += base64VLQ$3.encode(mapping.originalColumn
  17966. - previousOriginalColumn);
  17967. previousOriginalColumn = mapping.originalColumn;
  17968. if (mapping.name != null) {
  17969. nameIdx = this._names.indexOf(mapping.name);
  17970. next += base64VLQ$3.encode(nameIdx - previousName);
  17971. previousName = nameIdx;
  17972. }
  17973. }
  17974. result += next;
  17975. }
  17976. return result;
  17977. };
  17978. SourceMapGenerator$8.prototype._generateSourcesContent =
  17979. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  17980. return aSources.map(function (source) {
  17981. if (!this._sourcesContents) {
  17982. return null;
  17983. }
  17984. if (aSourceRoot != null) {
  17985. source = util$9.relative(aSourceRoot, source);
  17986. }
  17987. var key = util$9.toSetString(source);
  17988. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  17989. ? this._sourcesContents[key]
  17990. : null;
  17991. }, this);
  17992. };
  17993. /**
  17994. * Externalize the source map.
  17995. */
  17996. SourceMapGenerator$8.prototype.toJSON =
  17997. function SourceMapGenerator_toJSON() {
  17998. var map = {
  17999. version: this._version,
  18000. sources: this._sources.toArray(),
  18001. names: this._names.toArray(),
  18002. mappings: this._serializeMappings()
  18003. };
  18004. if (this._file != null) {
  18005. map.file = this._file;
  18006. }
  18007. if (this._sourceRoot != null) {
  18008. map.sourceRoot = this._sourceRoot;
  18009. }
  18010. if (this._sourcesContents) {
  18011. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  18012. }
  18013. return map;
  18014. };
  18015. /**
  18016. * Render the source map being generated to a string.
  18017. */
  18018. SourceMapGenerator$8.prototype.toString =
  18019. function SourceMapGenerator_toString() {
  18020. return JSON.stringify(this.toJSON());
  18021. };
  18022. sourceMapGenerator$1.SourceMapGenerator = SourceMapGenerator$8;
  18023. var sourceMapConsumer$1 = {};
  18024. var binarySearch$3 = {};
  18025. /* -*- Mode: js; js-indent-level: 2; -*- */
  18026. (function (exports) {
  18027. /*
  18028. * Copyright 2011 Mozilla Foundation and contributors
  18029. * Licensed under the New BSD license. See LICENSE or:
  18030. * http://opensource.org/licenses/BSD-3-Clause
  18031. */
  18032. exports.GREATEST_LOWER_BOUND = 1;
  18033. exports.LEAST_UPPER_BOUND = 2;
  18034. /**
  18035. * Recursive implementation of binary search.
  18036. *
  18037. * @param aLow Indices here and lower do not contain the needle.
  18038. * @param aHigh Indices here and higher do not contain the needle.
  18039. * @param aNeedle The element being searched for.
  18040. * @param aHaystack The non-empty array being searched.
  18041. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  18042. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  18043. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  18044. * closest element that is smaller than or greater than the one we are
  18045. * searching for, respectively, if the exact element cannot be found.
  18046. */
  18047. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  18048. // This function terminates when one of the following is true:
  18049. //
  18050. // 1. We find the exact element we are looking for.
  18051. //
  18052. // 2. We did not find the exact element, but we can return the index of
  18053. // the next-closest element.
  18054. //
  18055. // 3. We did not find the exact element, and there is no next-closest
  18056. // element than the one we are searching for, so we return -1.
  18057. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  18058. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  18059. if (cmp === 0) {
  18060. // Found the element we are looking for.
  18061. return mid;
  18062. }
  18063. else if (cmp > 0) {
  18064. // Our needle is greater than aHaystack[mid].
  18065. if (aHigh - mid > 1) {
  18066. // The element is in the upper half.
  18067. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  18068. }
  18069. // The exact needle element was not found in this haystack. Determine if
  18070. // we are in termination case (3) or (2) and return the appropriate thing.
  18071. if (aBias == exports.LEAST_UPPER_BOUND) {
  18072. return aHigh < aHaystack.length ? aHigh : -1;
  18073. } else {
  18074. return mid;
  18075. }
  18076. }
  18077. else {
  18078. // Our needle is less than aHaystack[mid].
  18079. if (mid - aLow > 1) {
  18080. // The element is in the lower half.
  18081. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  18082. }
  18083. // we are in termination case (3) or (2) and return the appropriate thing.
  18084. if (aBias == exports.LEAST_UPPER_BOUND) {
  18085. return mid;
  18086. } else {
  18087. return aLow < 0 ? -1 : aLow;
  18088. }
  18089. }
  18090. }
  18091. /**
  18092. * This is an implementation of binary search which will always try and return
  18093. * the index of the closest element if there is no exact hit. This is because
  18094. * mappings between original and generated line/col pairs are single points,
  18095. * and there is an implicit region between each of them, so a miss just means
  18096. * that you aren't on the very start of a region.
  18097. *
  18098. * @param aNeedle The element you are looking for.
  18099. * @param aHaystack The array that is being searched.
  18100. * @param aCompare A function which takes the needle and an element in the
  18101. * array and returns -1, 0, or 1 depending on whether the needle is less
  18102. * than, equal to, or greater than the element, respectively.
  18103. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  18104. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  18105. * closest element that is smaller than or greater than the one we are
  18106. * searching for, respectively, if the exact element cannot be found.
  18107. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  18108. */
  18109. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  18110. if (aHaystack.length === 0) {
  18111. return -1;
  18112. }
  18113. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  18114. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  18115. if (index < 0) {
  18116. return -1;
  18117. }
  18118. // We have found either the exact element, or the next-closest element than
  18119. // the one we are searching for. However, there may be more than one such
  18120. // element. Make sure we always return the smallest of these.
  18121. while (index - 1 >= 0) {
  18122. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  18123. break;
  18124. }
  18125. --index;
  18126. }
  18127. return index;
  18128. };
  18129. } (binarySearch$3));
  18130. var quickSort$3 = {};
  18131. /* -*- Mode: js; js-indent-level: 2; -*- */
  18132. /*
  18133. * Copyright 2011 Mozilla Foundation and contributors
  18134. * Licensed under the New BSD license. See LICENSE or:
  18135. * http://opensource.org/licenses/BSD-3-Clause
  18136. */
  18137. // It turns out that some (most?) JavaScript engines don't self-host
  18138. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  18139. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  18140. // custom comparator function, calling back and forth between the VM's C++ and
  18141. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  18142. // worse generated code for the comparator function than would be optimal. In
  18143. // fact, when sorting with a comparator, these costs outweigh the benefits of
  18144. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  18145. // a ~3500ms mean speed-up in `bench/bench.html`.
  18146. function SortTemplate(comparator) {
  18147. /**
  18148. * Swap the elements indexed by `x` and `y` in the array `ary`.
  18149. *
  18150. * @param {Array} ary
  18151. * The array.
  18152. * @param {Number} x
  18153. * The index of the first item.
  18154. * @param {Number} y
  18155. * The index of the second item.
  18156. */
  18157. function swap(ary, x, y) {
  18158. var temp = ary[x];
  18159. ary[x] = ary[y];
  18160. ary[y] = temp;
  18161. }
  18162. /**
  18163. * Returns a random integer within the range `low .. high` inclusive.
  18164. *
  18165. * @param {Number} low
  18166. * The lower bound on the range.
  18167. * @param {Number} high
  18168. * The upper bound on the range.
  18169. */
  18170. function randomIntInRange(low, high) {
  18171. return Math.round(low + (Math.random() * (high - low)));
  18172. }
  18173. /**
  18174. * The Quick Sort algorithm.
  18175. *
  18176. * @param {Array} ary
  18177. * An array to sort.
  18178. * @param {function} comparator
  18179. * Function to use to compare two items.
  18180. * @param {Number} p
  18181. * Start index of the array
  18182. * @param {Number} r
  18183. * End index of the array
  18184. */
  18185. function doQuickSort(ary, comparator, p, r) {
  18186. // If our lower bound is less than our upper bound, we (1) partition the
  18187. // array into two pieces and (2) recurse on each half. If it is not, this is
  18188. // the empty array and our base case.
  18189. if (p < r) {
  18190. // (1) Partitioning.
  18191. //
  18192. // The partitioning chooses a pivot between `p` and `r` and moves all
  18193. // elements that are less than or equal to the pivot to the before it, and
  18194. // all the elements that are greater than it after it. The effect is that
  18195. // once partition is done, the pivot is in the exact place it will be when
  18196. // the array is put in sorted order, and it will not need to be moved
  18197. // again. This runs in O(n) time.
  18198. // Always choose a random pivot so that an input array which is reverse
  18199. // sorted does not cause O(n^2) running time.
  18200. var pivotIndex = randomIntInRange(p, r);
  18201. var i = p - 1;
  18202. swap(ary, pivotIndex, r);
  18203. var pivot = ary[r];
  18204. // Immediately after `j` is incremented in this loop, the following hold
  18205. // true:
  18206. //
  18207. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  18208. //
  18209. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  18210. for (var j = p; j < r; j++) {
  18211. if (comparator(ary[j], pivot, false) <= 0) {
  18212. i += 1;
  18213. swap(ary, i, j);
  18214. }
  18215. }
  18216. swap(ary, i + 1, j);
  18217. var q = i + 1;
  18218. // (2) Recurse on each half.
  18219. doQuickSort(ary, comparator, p, q - 1);
  18220. doQuickSort(ary, comparator, q + 1, r);
  18221. }
  18222. }
  18223. return doQuickSort;
  18224. }
  18225. function cloneSort(comparator) {
  18226. let template = SortTemplate.toString();
  18227. let templateFn = new Function(`return ${template}`)();
  18228. return templateFn(comparator);
  18229. }
  18230. /**
  18231. * Sort the given array in-place with the given comparator function.
  18232. *
  18233. * @param {Array} ary
  18234. * An array to sort.
  18235. * @param {function} comparator
  18236. * Function to use to compare two items.
  18237. */
  18238. let sortCache = new WeakMap();
  18239. quickSort$3.quickSort = function (ary, comparator, start = 0) {
  18240. let doQuickSort = sortCache.get(comparator);
  18241. if (doQuickSort === void 0) {
  18242. doQuickSort = cloneSort(comparator);
  18243. sortCache.set(comparator, doQuickSort);
  18244. }
  18245. doQuickSort(ary, comparator, start, ary.length - 1);
  18246. };
  18247. /* -*- Mode: js; js-indent-level: 2; -*- */
  18248. /*
  18249. * Copyright 2011 Mozilla Foundation and contributors
  18250. * Licensed under the New BSD license. See LICENSE or:
  18251. * http://opensource.org/licenses/BSD-3-Clause
  18252. */
  18253. var util$8 = util$c;
  18254. var binarySearch$2 = binarySearch$3;
  18255. var ArraySet$3 = arraySet$1.ArraySet;
  18256. var base64VLQ$2 = base64Vlq$1;
  18257. var quickSort$2 = quickSort$3.quickSort;
  18258. function SourceMapConsumer$6(aSourceMap, aSourceMapURL) {
  18259. var sourceMap = aSourceMap;
  18260. if (typeof aSourceMap === 'string') {
  18261. sourceMap = util$8.parseSourceMapInput(aSourceMap);
  18262. }
  18263. return sourceMap.sections != null
  18264. ? new IndexedSourceMapConsumer$1(sourceMap, aSourceMapURL)
  18265. : new BasicSourceMapConsumer$1(sourceMap, aSourceMapURL);
  18266. }
  18267. SourceMapConsumer$6.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  18268. return BasicSourceMapConsumer$1.fromSourceMap(aSourceMap, aSourceMapURL);
  18269. };
  18270. /**
  18271. * The version of the source mapping spec that we are consuming.
  18272. */
  18273. SourceMapConsumer$6.prototype._version = 3;
  18274. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  18275. // parsed mapping coordinates from the source map's "mappings" attribute. They
  18276. // are lazily instantiated, accessed via the `_generatedMappings` and
  18277. // `_originalMappings` getters respectively, and we only parse the mappings
  18278. // and create these arrays once queried for a source location. We jump through
  18279. // these hoops because there can be many thousands of mappings, and parsing
  18280. // them is expensive, so we only want to do it if we must.
  18281. //
  18282. // Each object in the arrays is of the form:
  18283. //
  18284. // {
  18285. // generatedLine: The line number in the generated code,
  18286. // generatedColumn: The column number in the generated code,
  18287. // source: The path to the original source file that generated this
  18288. // chunk of code,
  18289. // originalLine: The line number in the original source that
  18290. // corresponds to this chunk of generated code,
  18291. // originalColumn: The column number in the original source that
  18292. // corresponds to this chunk of generated code,
  18293. // name: The name of the original symbol which generated this chunk of
  18294. // code.
  18295. // }
  18296. //
  18297. // All properties except for `generatedLine` and `generatedColumn` can be
  18298. // `null`.
  18299. //
  18300. // `_generatedMappings` is ordered by the generated positions.
  18301. //
  18302. // `_originalMappings` is ordered by the original positions.
  18303. SourceMapConsumer$6.prototype.__generatedMappings = null;
  18304. Object.defineProperty(SourceMapConsumer$6.prototype, '_generatedMappings', {
  18305. configurable: true,
  18306. enumerable: true,
  18307. get: function () {
  18308. if (!this.__generatedMappings) {
  18309. this._parseMappings(this._mappings, this.sourceRoot);
  18310. }
  18311. return this.__generatedMappings;
  18312. }
  18313. });
  18314. SourceMapConsumer$6.prototype.__originalMappings = null;
  18315. Object.defineProperty(SourceMapConsumer$6.prototype, '_originalMappings', {
  18316. configurable: true,
  18317. enumerable: true,
  18318. get: function () {
  18319. if (!this.__originalMappings) {
  18320. this._parseMappings(this._mappings, this.sourceRoot);
  18321. }
  18322. return this.__originalMappings;
  18323. }
  18324. });
  18325. SourceMapConsumer$6.prototype._charIsMappingSeparator =
  18326. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  18327. var c = aStr.charAt(index);
  18328. return c === ";" || c === ",";
  18329. };
  18330. /**
  18331. * Parse the mappings in a string in to a data structure which we can easily
  18332. * query (the ordered arrays in the `this.__generatedMappings` and
  18333. * `this.__originalMappings` properties).
  18334. */
  18335. SourceMapConsumer$6.prototype._parseMappings =
  18336. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  18337. throw new Error("Subclasses must implement _parseMappings");
  18338. };
  18339. SourceMapConsumer$6.GENERATED_ORDER = 1;
  18340. SourceMapConsumer$6.ORIGINAL_ORDER = 2;
  18341. SourceMapConsumer$6.GREATEST_LOWER_BOUND = 1;
  18342. SourceMapConsumer$6.LEAST_UPPER_BOUND = 2;
  18343. /**
  18344. * Iterate over each mapping between an original source/line/column and a
  18345. * generated line/column in this source map.
  18346. *
  18347. * @param Function aCallback
  18348. * The function that is called with each mapping.
  18349. * @param Object aContext
  18350. * Optional. If specified, this object will be the value of `this` every
  18351. * time that `aCallback` is called.
  18352. * @param aOrder
  18353. * Either `SourceMapConsumer.GENERATED_ORDER` or
  18354. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  18355. * iterate over the mappings sorted by the generated file's line/column
  18356. * order or the original's source/line/column order, respectively. Defaults to
  18357. * `SourceMapConsumer.GENERATED_ORDER`.
  18358. */
  18359. SourceMapConsumer$6.prototype.eachMapping =
  18360. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  18361. var context = aContext || null;
  18362. var order = aOrder || SourceMapConsumer$6.GENERATED_ORDER;
  18363. var mappings;
  18364. switch (order) {
  18365. case SourceMapConsumer$6.GENERATED_ORDER:
  18366. mappings = this._generatedMappings;
  18367. break;
  18368. case SourceMapConsumer$6.ORIGINAL_ORDER:
  18369. mappings = this._originalMappings;
  18370. break;
  18371. default:
  18372. throw new Error("Unknown order of iteration.");
  18373. }
  18374. var sourceRoot = this.sourceRoot;
  18375. var boundCallback = aCallback.bind(context);
  18376. var names = this._names;
  18377. var sources = this._sources;
  18378. var sourceMapURL = this._sourceMapURL;
  18379. for (var i = 0, n = mappings.length; i < n; i++) {
  18380. var mapping = mappings[i];
  18381. var source = mapping.source === null ? null : sources.at(mapping.source);
  18382. source = util$8.computeSourceURL(sourceRoot, source, sourceMapURL);
  18383. boundCallback({
  18384. source: source,
  18385. generatedLine: mapping.generatedLine,
  18386. generatedColumn: mapping.generatedColumn,
  18387. originalLine: mapping.originalLine,
  18388. originalColumn: mapping.originalColumn,
  18389. name: mapping.name === null ? null : names.at(mapping.name)
  18390. });
  18391. }
  18392. };
  18393. /**
  18394. * Returns all generated line and column information for the original source,
  18395. * line, and column provided. If no column is provided, returns all mappings
  18396. * corresponding to a either the line we are searching for or the next
  18397. * closest line that has any mappings. Otherwise, returns all mappings
  18398. * corresponding to the given line and either the column we are searching for
  18399. * or the next closest column that has any offsets.
  18400. *
  18401. * The only argument is an object with the following properties:
  18402. *
  18403. * - source: The filename of the original source.
  18404. * - line: The line number in the original source. The line number is 1-based.
  18405. * - column: Optional. the column number in the original source.
  18406. * The column number is 0-based.
  18407. *
  18408. * and an array of objects is returned, each with the following properties:
  18409. *
  18410. * - line: The line number in the generated source, or null. The
  18411. * line number is 1-based.
  18412. * - column: The column number in the generated source, or null.
  18413. * The column number is 0-based.
  18414. */
  18415. SourceMapConsumer$6.prototype.allGeneratedPositionsFor =
  18416. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  18417. var line = util$8.getArg(aArgs, 'line');
  18418. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  18419. // returns the index of the closest mapping less than the needle. By
  18420. // setting needle.originalColumn to 0, we thus find the last mapping for
  18421. // the given line, provided such a mapping exists.
  18422. var needle = {
  18423. source: util$8.getArg(aArgs, 'source'),
  18424. originalLine: line,
  18425. originalColumn: util$8.getArg(aArgs, 'column', 0)
  18426. };
  18427. needle.source = this._findSourceIndex(needle.source);
  18428. if (needle.source < 0) {
  18429. return [];
  18430. }
  18431. var mappings = [];
  18432. var index = this._findMapping(needle,
  18433. this._originalMappings,
  18434. "originalLine",
  18435. "originalColumn",
  18436. util$8.compareByOriginalPositions,
  18437. binarySearch$2.LEAST_UPPER_BOUND);
  18438. if (index >= 0) {
  18439. var mapping = this._originalMappings[index];
  18440. if (aArgs.column === undefined) {
  18441. var originalLine = mapping.originalLine;
  18442. // Iterate until either we run out of mappings, or we run into
  18443. // a mapping for a different line than the one we found. Since
  18444. // mappings are sorted, this is guaranteed to find all mappings for
  18445. // the line we found.
  18446. while (mapping && mapping.originalLine === originalLine) {
  18447. mappings.push({
  18448. line: util$8.getArg(mapping, 'generatedLine', null),
  18449. column: util$8.getArg(mapping, 'generatedColumn', null),
  18450. lastColumn: util$8.getArg(mapping, 'lastGeneratedColumn', null)
  18451. });
  18452. mapping = this._originalMappings[++index];
  18453. }
  18454. } else {
  18455. var originalColumn = mapping.originalColumn;
  18456. // Iterate until either we run out of mappings, or we run into
  18457. // a mapping for a different line than the one we were searching for.
  18458. // Since mappings are sorted, this is guaranteed to find all mappings for
  18459. // the line we are searching for.
  18460. while (mapping &&
  18461. mapping.originalLine === line &&
  18462. mapping.originalColumn == originalColumn) {
  18463. mappings.push({
  18464. line: util$8.getArg(mapping, 'generatedLine', null),
  18465. column: util$8.getArg(mapping, 'generatedColumn', null),
  18466. lastColumn: util$8.getArg(mapping, 'lastGeneratedColumn', null)
  18467. });
  18468. mapping = this._originalMappings[++index];
  18469. }
  18470. }
  18471. }
  18472. return mappings;
  18473. };
  18474. sourceMapConsumer$1.SourceMapConsumer = SourceMapConsumer$6;
  18475. /**
  18476. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  18477. * query for information about the original file positions by giving it a file
  18478. * position in the generated source.
  18479. *
  18480. * The first parameter is the raw source map (either as a JSON string, or
  18481. * already parsed to an object). According to the spec, source maps have the
  18482. * following attributes:
  18483. *
  18484. * - version: Which version of the source map spec this map is following.
  18485. * - sources: An array of URLs to the original source files.
  18486. * - names: An array of identifiers which can be referrenced by individual mappings.
  18487. * - sourceRoot: Optional. The URL root from which all sources are relative.
  18488. * - sourcesContent: Optional. An array of contents of the original source files.
  18489. * - mappings: A string of base64 VLQs which contain the actual mappings.
  18490. * - file: Optional. The generated file this source map is associated with.
  18491. *
  18492. * Here is an example source map, taken from the source map spec[0]:
  18493. *
  18494. * {
  18495. * version : 3,
  18496. * file: "out.js",
  18497. * sourceRoot : "",
  18498. * sources: ["foo.js", "bar.js"],
  18499. * names: ["src", "maps", "are", "fun"],
  18500. * mappings: "AA,AB;;ABCDE;"
  18501. * }
  18502. *
  18503. * The second parameter, if given, is a string whose value is the URL
  18504. * at which the source map was found. This URL is used to compute the
  18505. * sources array.
  18506. *
  18507. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  18508. */
  18509. function BasicSourceMapConsumer$1(aSourceMap, aSourceMapURL) {
  18510. var sourceMap = aSourceMap;
  18511. if (typeof aSourceMap === 'string') {
  18512. sourceMap = util$8.parseSourceMapInput(aSourceMap);
  18513. }
  18514. var version = util$8.getArg(sourceMap, 'version');
  18515. var sources = util$8.getArg(sourceMap, 'sources');
  18516. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  18517. // requires the array) to play nice here.
  18518. var names = util$8.getArg(sourceMap, 'names', []);
  18519. var sourceRoot = util$8.getArg(sourceMap, 'sourceRoot', null);
  18520. var sourcesContent = util$8.getArg(sourceMap, 'sourcesContent', null);
  18521. var mappings = util$8.getArg(sourceMap, 'mappings');
  18522. var file = util$8.getArg(sourceMap, 'file', null);
  18523. // Once again, Sass deviates from the spec and supplies the version as a
  18524. // string rather than a number, so we use loose equality checking here.
  18525. if (version != this._version) {
  18526. throw new Error('Unsupported version: ' + version);
  18527. }
  18528. if (sourceRoot) {
  18529. sourceRoot = util$8.normalize(sourceRoot);
  18530. }
  18531. sources = sources
  18532. .map(String)
  18533. // Some source maps produce relative source paths like "./foo.js" instead of
  18534. // "foo.js". Normalize these first so that future comparisons will succeed.
  18535. // See bugzil.la/1090768.
  18536. .map(util$8.normalize)
  18537. // Always ensure that absolute sources are internally stored relative to
  18538. // the source root, if the source root is absolute. Not doing this would
  18539. // be particularly problematic when the source root is a prefix of the
  18540. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  18541. .map(function (source) {
  18542. return sourceRoot && util$8.isAbsolute(sourceRoot) && util$8.isAbsolute(source)
  18543. ? util$8.relative(sourceRoot, source)
  18544. : source;
  18545. });
  18546. // Pass `true` below to allow duplicate names and sources. While source maps
  18547. // are intended to be compressed and deduplicated, the TypeScript compiler
  18548. // sometimes generates source maps with duplicates in them. See Github issue
  18549. // #72 and bugzil.la/889492.
  18550. this._names = ArraySet$3.fromArray(names.map(String), true);
  18551. this._sources = ArraySet$3.fromArray(sources, true);
  18552. this._absoluteSources = this._sources.toArray().map(function (s) {
  18553. return util$8.computeSourceURL(sourceRoot, s, aSourceMapURL);
  18554. });
  18555. this.sourceRoot = sourceRoot;
  18556. this.sourcesContent = sourcesContent;
  18557. this._mappings = mappings;
  18558. this._sourceMapURL = aSourceMapURL;
  18559. this.file = file;
  18560. }
  18561. BasicSourceMapConsumer$1.prototype = Object.create(SourceMapConsumer$6.prototype);
  18562. BasicSourceMapConsumer$1.prototype.consumer = SourceMapConsumer$6;
  18563. /**
  18564. * Utility function to find the index of a source. Returns -1 if not
  18565. * found.
  18566. */
  18567. BasicSourceMapConsumer$1.prototype._findSourceIndex = function(aSource) {
  18568. var relativeSource = aSource;
  18569. if (this.sourceRoot != null) {
  18570. relativeSource = util$8.relative(this.sourceRoot, relativeSource);
  18571. }
  18572. if (this._sources.has(relativeSource)) {
  18573. return this._sources.indexOf(relativeSource);
  18574. }
  18575. // Maybe aSource is an absolute URL as returned by |sources|. In
  18576. // this case we can't simply undo the transform.
  18577. var i;
  18578. for (i = 0; i < this._absoluteSources.length; ++i) {
  18579. if (this._absoluteSources[i] == aSource) {
  18580. return i;
  18581. }
  18582. }
  18583. return -1;
  18584. };
  18585. /**
  18586. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  18587. *
  18588. * @param SourceMapGenerator aSourceMap
  18589. * The source map that will be consumed.
  18590. * @param String aSourceMapURL
  18591. * The URL at which the source map can be found (optional)
  18592. * @returns BasicSourceMapConsumer
  18593. */
  18594. BasicSourceMapConsumer$1.fromSourceMap =
  18595. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  18596. var smc = Object.create(BasicSourceMapConsumer$1.prototype);
  18597. var names = smc._names = ArraySet$3.fromArray(aSourceMap._names.toArray(), true);
  18598. var sources = smc._sources = ArraySet$3.fromArray(aSourceMap._sources.toArray(), true);
  18599. smc.sourceRoot = aSourceMap._sourceRoot;
  18600. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  18601. smc.sourceRoot);
  18602. smc.file = aSourceMap._file;
  18603. smc._sourceMapURL = aSourceMapURL;
  18604. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  18605. return util$8.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  18606. });
  18607. // Because we are modifying the entries (by converting string sources and
  18608. // names to indices into the sources and names ArraySets), we have to make
  18609. // a copy of the entry or else bad things happen. Shared mutable state
  18610. // strikes again! See github issue #191.
  18611. var generatedMappings = aSourceMap._mappings.toArray().slice();
  18612. var destGeneratedMappings = smc.__generatedMappings = [];
  18613. var destOriginalMappings = smc.__originalMappings = [];
  18614. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  18615. var srcMapping = generatedMappings[i];
  18616. var destMapping = new Mapping$1;
  18617. destMapping.generatedLine = srcMapping.generatedLine;
  18618. destMapping.generatedColumn = srcMapping.generatedColumn;
  18619. if (srcMapping.source) {
  18620. destMapping.source = sources.indexOf(srcMapping.source);
  18621. destMapping.originalLine = srcMapping.originalLine;
  18622. destMapping.originalColumn = srcMapping.originalColumn;
  18623. if (srcMapping.name) {
  18624. destMapping.name = names.indexOf(srcMapping.name);
  18625. }
  18626. destOriginalMappings.push(destMapping);
  18627. }
  18628. destGeneratedMappings.push(destMapping);
  18629. }
  18630. quickSort$2(smc.__originalMappings, util$8.compareByOriginalPositions);
  18631. return smc;
  18632. };
  18633. /**
  18634. * The version of the source mapping spec that we are consuming.
  18635. */
  18636. BasicSourceMapConsumer$1.prototype._version = 3;
  18637. /**
  18638. * The list of original sources.
  18639. */
  18640. Object.defineProperty(BasicSourceMapConsumer$1.prototype, 'sources', {
  18641. get: function () {
  18642. return this._absoluteSources.slice();
  18643. }
  18644. });
  18645. /**
  18646. * Provide the JIT with a nice shape / hidden class.
  18647. */
  18648. function Mapping$1() {
  18649. this.generatedLine = 0;
  18650. this.generatedColumn = 0;
  18651. this.source = null;
  18652. this.originalLine = null;
  18653. this.originalColumn = null;
  18654. this.name = null;
  18655. }
  18656. /**
  18657. * Parse the mappings in a string in to a data structure which we can easily
  18658. * query (the ordered arrays in the `this.__generatedMappings` and
  18659. * `this.__originalMappings` properties).
  18660. */
  18661. const compareGenerated = util$8.compareByGeneratedPositionsDeflatedNoLine;
  18662. function sortGenerated(array, start) {
  18663. let l = array.length;
  18664. let n = array.length - start;
  18665. if (n <= 1) {
  18666. return;
  18667. } else if (n == 2) {
  18668. let a = array[start];
  18669. let b = array[start + 1];
  18670. if (compareGenerated(a, b) > 0) {
  18671. array[start] = b;
  18672. array[start + 1] = a;
  18673. }
  18674. } else if (n < 20) {
  18675. for (let i = start; i < l; i++) {
  18676. for (let j = i; j > start; j--) {
  18677. let a = array[j - 1];
  18678. let b = array[j];
  18679. if (compareGenerated(a, b) <= 0) {
  18680. break;
  18681. }
  18682. array[j - 1] = b;
  18683. array[j] = a;
  18684. }
  18685. }
  18686. } else {
  18687. quickSort$2(array, compareGenerated, start);
  18688. }
  18689. }
  18690. BasicSourceMapConsumer$1.prototype._parseMappings =
  18691. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  18692. var generatedLine = 1;
  18693. var previousGeneratedColumn = 0;
  18694. var previousOriginalLine = 0;
  18695. var previousOriginalColumn = 0;
  18696. var previousSource = 0;
  18697. var previousName = 0;
  18698. var length = aStr.length;
  18699. var index = 0;
  18700. var temp = {};
  18701. var originalMappings = [];
  18702. var generatedMappings = [];
  18703. var mapping, segment, end, value;
  18704. let subarrayStart = 0;
  18705. while (index < length) {
  18706. if (aStr.charAt(index) === ';') {
  18707. generatedLine++;
  18708. index++;
  18709. previousGeneratedColumn = 0;
  18710. sortGenerated(generatedMappings, subarrayStart);
  18711. subarrayStart = generatedMappings.length;
  18712. }
  18713. else if (aStr.charAt(index) === ',') {
  18714. index++;
  18715. }
  18716. else {
  18717. mapping = new Mapping$1();
  18718. mapping.generatedLine = generatedLine;
  18719. for (end = index; end < length; end++) {
  18720. if (this._charIsMappingSeparator(aStr, end)) {
  18721. break;
  18722. }
  18723. }
  18724. aStr.slice(index, end);
  18725. segment = [];
  18726. while (index < end) {
  18727. base64VLQ$2.decode(aStr, index, temp);
  18728. value = temp.value;
  18729. index = temp.rest;
  18730. segment.push(value);
  18731. }
  18732. if (segment.length === 2) {
  18733. throw new Error('Found a source, but no line and column');
  18734. }
  18735. if (segment.length === 3) {
  18736. throw new Error('Found a source and line, but no column');
  18737. }
  18738. // Generated column.
  18739. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  18740. previousGeneratedColumn = mapping.generatedColumn;
  18741. if (segment.length > 1) {
  18742. // Original source.
  18743. mapping.source = previousSource + segment[1];
  18744. previousSource += segment[1];
  18745. // Original line.
  18746. mapping.originalLine = previousOriginalLine + segment[2];
  18747. previousOriginalLine = mapping.originalLine;
  18748. // Lines are stored 0-based
  18749. mapping.originalLine += 1;
  18750. // Original column.
  18751. mapping.originalColumn = previousOriginalColumn + segment[3];
  18752. previousOriginalColumn = mapping.originalColumn;
  18753. if (segment.length > 4) {
  18754. // Original name.
  18755. mapping.name = previousName + segment[4];
  18756. previousName += segment[4];
  18757. }
  18758. }
  18759. generatedMappings.push(mapping);
  18760. if (typeof mapping.originalLine === 'number') {
  18761. let currentSource = mapping.source;
  18762. while (originalMappings.length <= currentSource) {
  18763. originalMappings.push(null);
  18764. }
  18765. if (originalMappings[currentSource] === null) {
  18766. originalMappings[currentSource] = [];
  18767. }
  18768. originalMappings[currentSource].push(mapping);
  18769. }
  18770. }
  18771. }
  18772. sortGenerated(generatedMappings, subarrayStart);
  18773. this.__generatedMappings = generatedMappings;
  18774. for (var i = 0; i < originalMappings.length; i++) {
  18775. if (originalMappings[i] != null) {
  18776. quickSort$2(originalMappings[i], util$8.compareByOriginalPositionsNoSource);
  18777. }
  18778. }
  18779. this.__originalMappings = [].concat(...originalMappings);
  18780. };
  18781. /**
  18782. * Find the mapping that best matches the hypothetical "needle" mapping that
  18783. * we are searching for in the given "haystack" of mappings.
  18784. */
  18785. BasicSourceMapConsumer$1.prototype._findMapping =
  18786. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  18787. aColumnName, aComparator, aBias) {
  18788. // To return the position we are searching for, we must first find the
  18789. // mapping for the given position and then return the opposite position it
  18790. // points to. Because the mappings are sorted, we can use binary search to
  18791. // find the best mapping.
  18792. if (aNeedle[aLineName] <= 0) {
  18793. throw new TypeError('Line must be greater than or equal to 1, got '
  18794. + aNeedle[aLineName]);
  18795. }
  18796. if (aNeedle[aColumnName] < 0) {
  18797. throw new TypeError('Column must be greater than or equal to 0, got '
  18798. + aNeedle[aColumnName]);
  18799. }
  18800. return binarySearch$2.search(aNeedle, aMappings, aComparator, aBias);
  18801. };
  18802. /**
  18803. * Compute the last column for each generated mapping. The last column is
  18804. * inclusive.
  18805. */
  18806. BasicSourceMapConsumer$1.prototype.computeColumnSpans =
  18807. function SourceMapConsumer_computeColumnSpans() {
  18808. for (var index = 0; index < this._generatedMappings.length; ++index) {
  18809. var mapping = this._generatedMappings[index];
  18810. // Mappings do not contain a field for the last generated columnt. We
  18811. // can come up with an optimistic estimate, however, by assuming that
  18812. // mappings are contiguous (i.e. given two consecutive mappings, the
  18813. // first mapping ends where the second one starts).
  18814. if (index + 1 < this._generatedMappings.length) {
  18815. var nextMapping = this._generatedMappings[index + 1];
  18816. if (mapping.generatedLine === nextMapping.generatedLine) {
  18817. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  18818. continue;
  18819. }
  18820. }
  18821. // The last mapping for each line spans the entire line.
  18822. mapping.lastGeneratedColumn = Infinity;
  18823. }
  18824. };
  18825. /**
  18826. * Returns the original source, line, and column information for the generated
  18827. * source's line and column positions provided. The only argument is an object
  18828. * with the following properties:
  18829. *
  18830. * - line: The line number in the generated source. The line number
  18831. * is 1-based.
  18832. * - column: The column number in the generated source. The column
  18833. * number is 0-based.
  18834. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  18835. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  18836. * closest element that is smaller than or greater than the one we are
  18837. * searching for, respectively, if the exact element cannot be found.
  18838. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  18839. *
  18840. * and an object is returned with the following properties:
  18841. *
  18842. * - source: The original source file, or null.
  18843. * - line: The line number in the original source, or null. The
  18844. * line number is 1-based.
  18845. * - column: The column number in the original source, or null. The
  18846. * column number is 0-based.
  18847. * - name: The original identifier, or null.
  18848. */
  18849. BasicSourceMapConsumer$1.prototype.originalPositionFor =
  18850. function SourceMapConsumer_originalPositionFor(aArgs) {
  18851. var needle = {
  18852. generatedLine: util$8.getArg(aArgs, 'line'),
  18853. generatedColumn: util$8.getArg(aArgs, 'column')
  18854. };
  18855. var index = this._findMapping(
  18856. needle,
  18857. this._generatedMappings,
  18858. "generatedLine",
  18859. "generatedColumn",
  18860. util$8.compareByGeneratedPositionsDeflated,
  18861. util$8.getArg(aArgs, 'bias', SourceMapConsumer$6.GREATEST_LOWER_BOUND)
  18862. );
  18863. if (index >= 0) {
  18864. var mapping = this._generatedMappings[index];
  18865. if (mapping.generatedLine === needle.generatedLine) {
  18866. var source = util$8.getArg(mapping, 'source', null);
  18867. if (source !== null) {
  18868. source = this._sources.at(source);
  18869. source = util$8.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  18870. }
  18871. var name = util$8.getArg(mapping, 'name', null);
  18872. if (name !== null) {
  18873. name = this._names.at(name);
  18874. }
  18875. return {
  18876. source: source,
  18877. line: util$8.getArg(mapping, 'originalLine', null),
  18878. column: util$8.getArg(mapping, 'originalColumn', null),
  18879. name: name
  18880. };
  18881. }
  18882. }
  18883. return {
  18884. source: null,
  18885. line: null,
  18886. column: null,
  18887. name: null
  18888. };
  18889. };
  18890. /**
  18891. * Return true if we have the source content for every source in the source
  18892. * map, false otherwise.
  18893. */
  18894. BasicSourceMapConsumer$1.prototype.hasContentsOfAllSources =
  18895. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  18896. if (!this.sourcesContent) {
  18897. return false;
  18898. }
  18899. return this.sourcesContent.length >= this._sources.size() &&
  18900. !this.sourcesContent.some(function (sc) { return sc == null; });
  18901. };
  18902. /**
  18903. * Returns the original source content. The only argument is the url of the
  18904. * original source file. Returns null if no original source content is
  18905. * available.
  18906. */
  18907. BasicSourceMapConsumer$1.prototype.sourceContentFor =
  18908. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  18909. if (!this.sourcesContent) {
  18910. return null;
  18911. }
  18912. var index = this._findSourceIndex(aSource);
  18913. if (index >= 0) {
  18914. return this.sourcesContent[index];
  18915. }
  18916. var relativeSource = aSource;
  18917. if (this.sourceRoot != null) {
  18918. relativeSource = util$8.relative(this.sourceRoot, relativeSource);
  18919. }
  18920. var url;
  18921. if (this.sourceRoot != null
  18922. && (url = util$8.urlParse(this.sourceRoot))) {
  18923. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  18924. // many users. We can help them out when they expect file:// URIs to
  18925. // behave like it would if they were running a local HTTP server. See
  18926. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  18927. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  18928. if (url.scheme == "file"
  18929. && this._sources.has(fileUriAbsPath)) {
  18930. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  18931. }
  18932. if ((!url.path || url.path == "/")
  18933. && this._sources.has("/" + relativeSource)) {
  18934. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  18935. }
  18936. }
  18937. // This function is used recursively from
  18938. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  18939. // don't want to throw if we can't find the source - we just want to
  18940. // return null, so we provide a flag to exit gracefully.
  18941. if (nullOnMissing) {
  18942. return null;
  18943. }
  18944. else {
  18945. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  18946. }
  18947. };
  18948. /**
  18949. * Returns the generated line and column information for the original source,
  18950. * line, and column positions provided. The only argument is an object with
  18951. * the following properties:
  18952. *
  18953. * - source: The filename of the original source.
  18954. * - line: The line number in the original source. The line number
  18955. * is 1-based.
  18956. * - column: The column number in the original source. The column
  18957. * number is 0-based.
  18958. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  18959. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  18960. * closest element that is smaller than or greater than the one we are
  18961. * searching for, respectively, if the exact element cannot be found.
  18962. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  18963. *
  18964. * and an object is returned with the following properties:
  18965. *
  18966. * - line: The line number in the generated source, or null. The
  18967. * line number is 1-based.
  18968. * - column: The column number in the generated source, or null.
  18969. * The column number is 0-based.
  18970. */
  18971. BasicSourceMapConsumer$1.prototype.generatedPositionFor =
  18972. function SourceMapConsumer_generatedPositionFor(aArgs) {
  18973. var source = util$8.getArg(aArgs, 'source');
  18974. source = this._findSourceIndex(source);
  18975. if (source < 0) {
  18976. return {
  18977. line: null,
  18978. column: null,
  18979. lastColumn: null
  18980. };
  18981. }
  18982. var needle = {
  18983. source: source,
  18984. originalLine: util$8.getArg(aArgs, 'line'),
  18985. originalColumn: util$8.getArg(aArgs, 'column')
  18986. };
  18987. var index = this._findMapping(
  18988. needle,
  18989. this._originalMappings,
  18990. "originalLine",
  18991. "originalColumn",
  18992. util$8.compareByOriginalPositions,
  18993. util$8.getArg(aArgs, 'bias', SourceMapConsumer$6.GREATEST_LOWER_BOUND)
  18994. );
  18995. if (index >= 0) {
  18996. var mapping = this._originalMappings[index];
  18997. if (mapping.source === needle.source) {
  18998. return {
  18999. line: util$8.getArg(mapping, 'generatedLine', null),
  19000. column: util$8.getArg(mapping, 'generatedColumn', null),
  19001. lastColumn: util$8.getArg(mapping, 'lastGeneratedColumn', null)
  19002. };
  19003. }
  19004. }
  19005. return {
  19006. line: null,
  19007. column: null,
  19008. lastColumn: null
  19009. };
  19010. };
  19011. sourceMapConsumer$1.BasicSourceMapConsumer = BasicSourceMapConsumer$1;
  19012. /**
  19013. * An IndexedSourceMapConsumer instance represents a parsed source map which
  19014. * we can query for information. It differs from BasicSourceMapConsumer in
  19015. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  19016. * input.
  19017. *
  19018. * The first parameter is a raw source map (either as a JSON string, or already
  19019. * parsed to an object). According to the spec for indexed source maps, they
  19020. * have the following attributes:
  19021. *
  19022. * - version: Which version of the source map spec this map is following.
  19023. * - file: Optional. The generated file this source map is associated with.
  19024. * - sections: A list of section definitions.
  19025. *
  19026. * Each value under the "sections" field has two fields:
  19027. * - offset: The offset into the original specified at which this section
  19028. * begins to apply, defined as an object with a "line" and "column"
  19029. * field.
  19030. * - map: A source map definition. This source map could also be indexed,
  19031. * but doesn't have to be.
  19032. *
  19033. * Instead of the "map" field, it's also possible to have a "url" field
  19034. * specifying a URL to retrieve a source map from, but that's currently
  19035. * unsupported.
  19036. *
  19037. * Here's an example source map, taken from the source map spec[0], but
  19038. * modified to omit a section which uses the "url" field.
  19039. *
  19040. * {
  19041. * version : 3,
  19042. * file: "app.js",
  19043. * sections: [{
  19044. * offset: {line:100, column:10},
  19045. * map: {
  19046. * version : 3,
  19047. * file: "section.js",
  19048. * sources: ["foo.js", "bar.js"],
  19049. * names: ["src", "maps", "are", "fun"],
  19050. * mappings: "AAAA,E;;ABCDE;"
  19051. * }
  19052. * }],
  19053. * }
  19054. *
  19055. * The second parameter, if given, is a string whose value is the URL
  19056. * at which the source map was found. This URL is used to compute the
  19057. * sources array.
  19058. *
  19059. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  19060. */
  19061. function IndexedSourceMapConsumer$1(aSourceMap, aSourceMapURL) {
  19062. var sourceMap = aSourceMap;
  19063. if (typeof aSourceMap === 'string') {
  19064. sourceMap = util$8.parseSourceMapInput(aSourceMap);
  19065. }
  19066. var version = util$8.getArg(sourceMap, 'version');
  19067. var sections = util$8.getArg(sourceMap, 'sections');
  19068. if (version != this._version) {
  19069. throw new Error('Unsupported version: ' + version);
  19070. }
  19071. this._sources = new ArraySet$3();
  19072. this._names = new ArraySet$3();
  19073. var lastOffset = {
  19074. line: -1,
  19075. column: 0
  19076. };
  19077. this._sections = sections.map(function (s) {
  19078. if (s.url) {
  19079. // The url field will require support for asynchronicity.
  19080. // See https://github.com/mozilla/source-map/issues/16
  19081. throw new Error('Support for url field in sections not implemented.');
  19082. }
  19083. var offset = util$8.getArg(s, 'offset');
  19084. var offsetLine = util$8.getArg(offset, 'line');
  19085. var offsetColumn = util$8.getArg(offset, 'column');
  19086. if (offsetLine < lastOffset.line ||
  19087. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  19088. throw new Error('Section offsets must be ordered and non-overlapping.');
  19089. }
  19090. lastOffset = offset;
  19091. return {
  19092. generatedOffset: {
  19093. // The offset fields are 0-based, but we use 1-based indices when
  19094. // encoding/decoding from VLQ.
  19095. generatedLine: offsetLine + 1,
  19096. generatedColumn: offsetColumn + 1
  19097. },
  19098. consumer: new SourceMapConsumer$6(util$8.getArg(s, 'map'), aSourceMapURL)
  19099. }
  19100. });
  19101. }
  19102. IndexedSourceMapConsumer$1.prototype = Object.create(SourceMapConsumer$6.prototype);
  19103. IndexedSourceMapConsumer$1.prototype.constructor = SourceMapConsumer$6;
  19104. /**
  19105. * The version of the source mapping spec that we are consuming.
  19106. */
  19107. IndexedSourceMapConsumer$1.prototype._version = 3;
  19108. /**
  19109. * The list of original sources.
  19110. */
  19111. Object.defineProperty(IndexedSourceMapConsumer$1.prototype, 'sources', {
  19112. get: function () {
  19113. var sources = [];
  19114. for (var i = 0; i < this._sections.length; i++) {
  19115. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  19116. sources.push(this._sections[i].consumer.sources[j]);
  19117. }
  19118. }
  19119. return sources;
  19120. }
  19121. });
  19122. /**
  19123. * Returns the original source, line, and column information for the generated
  19124. * source's line and column positions provided. The only argument is an object
  19125. * with the following properties:
  19126. *
  19127. * - line: The line number in the generated source. The line number
  19128. * is 1-based.
  19129. * - column: The column number in the generated source. The column
  19130. * number is 0-based.
  19131. *
  19132. * and an object is returned with the following properties:
  19133. *
  19134. * - source: The original source file, or null.
  19135. * - line: The line number in the original source, or null. The
  19136. * line number is 1-based.
  19137. * - column: The column number in the original source, or null. The
  19138. * column number is 0-based.
  19139. * - name: The original identifier, or null.
  19140. */
  19141. IndexedSourceMapConsumer$1.prototype.originalPositionFor =
  19142. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  19143. var needle = {
  19144. generatedLine: util$8.getArg(aArgs, 'line'),
  19145. generatedColumn: util$8.getArg(aArgs, 'column')
  19146. };
  19147. // Find the section containing the generated position we're trying to map
  19148. // to an original position.
  19149. var sectionIndex = binarySearch$2.search(needle, this._sections,
  19150. function(needle, section) {
  19151. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  19152. if (cmp) {
  19153. return cmp;
  19154. }
  19155. return (needle.generatedColumn -
  19156. section.generatedOffset.generatedColumn);
  19157. });
  19158. var section = this._sections[sectionIndex];
  19159. if (!section) {
  19160. return {
  19161. source: null,
  19162. line: null,
  19163. column: null,
  19164. name: null
  19165. };
  19166. }
  19167. return section.consumer.originalPositionFor({
  19168. line: needle.generatedLine -
  19169. (section.generatedOffset.generatedLine - 1),
  19170. column: needle.generatedColumn -
  19171. (section.generatedOffset.generatedLine === needle.generatedLine
  19172. ? section.generatedOffset.generatedColumn - 1
  19173. : 0),
  19174. bias: aArgs.bias
  19175. });
  19176. };
  19177. /**
  19178. * Return true if we have the source content for every source in the source
  19179. * map, false otherwise.
  19180. */
  19181. IndexedSourceMapConsumer$1.prototype.hasContentsOfAllSources =
  19182. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  19183. return this._sections.every(function (s) {
  19184. return s.consumer.hasContentsOfAllSources();
  19185. });
  19186. };
  19187. /**
  19188. * Returns the original source content. The only argument is the url of the
  19189. * original source file. Returns null if no original source content is
  19190. * available.
  19191. */
  19192. IndexedSourceMapConsumer$1.prototype.sourceContentFor =
  19193. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  19194. for (var i = 0; i < this._sections.length; i++) {
  19195. var section = this._sections[i];
  19196. var content = section.consumer.sourceContentFor(aSource, true);
  19197. if (content) {
  19198. return content;
  19199. }
  19200. }
  19201. if (nullOnMissing) {
  19202. return null;
  19203. }
  19204. else {
  19205. throw new Error('"' + aSource + '" is not in the SourceMap.');
  19206. }
  19207. };
  19208. /**
  19209. * Returns the generated line and column information for the original source,
  19210. * line, and column positions provided. The only argument is an object with
  19211. * the following properties:
  19212. *
  19213. * - source: The filename of the original source.
  19214. * - line: The line number in the original source. The line number
  19215. * is 1-based.
  19216. * - column: The column number in the original source. The column
  19217. * number is 0-based.
  19218. *
  19219. * and an object is returned with the following properties:
  19220. *
  19221. * - line: The line number in the generated source, or null. The
  19222. * line number is 1-based.
  19223. * - column: The column number in the generated source, or null.
  19224. * The column number is 0-based.
  19225. */
  19226. IndexedSourceMapConsumer$1.prototype.generatedPositionFor =
  19227. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  19228. for (var i = 0; i < this._sections.length; i++) {
  19229. var section = this._sections[i];
  19230. // Only consider this section if the requested source is in the list of
  19231. // sources of the consumer.
  19232. if (section.consumer._findSourceIndex(util$8.getArg(aArgs, 'source')) === -1) {
  19233. continue;
  19234. }
  19235. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  19236. if (generatedPosition) {
  19237. var ret = {
  19238. line: generatedPosition.line +
  19239. (section.generatedOffset.generatedLine - 1),
  19240. column: generatedPosition.column +
  19241. (section.generatedOffset.generatedLine === generatedPosition.line
  19242. ? section.generatedOffset.generatedColumn - 1
  19243. : 0)
  19244. };
  19245. return ret;
  19246. }
  19247. }
  19248. return {
  19249. line: null,
  19250. column: null
  19251. };
  19252. };
  19253. /**
  19254. * Parse the mappings in a string in to a data structure which we can easily
  19255. * query (the ordered arrays in the `this.__generatedMappings` and
  19256. * `this.__originalMappings` properties).
  19257. */
  19258. IndexedSourceMapConsumer$1.prototype._parseMappings =
  19259. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  19260. this.__generatedMappings = [];
  19261. this.__originalMappings = [];
  19262. for (var i = 0; i < this._sections.length; i++) {
  19263. var section = this._sections[i];
  19264. var sectionMappings = section.consumer._generatedMappings;
  19265. for (var j = 0; j < sectionMappings.length; j++) {
  19266. var mapping = sectionMappings[j];
  19267. var source = section.consumer._sources.at(mapping.source);
  19268. source = util$8.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  19269. this._sources.add(source);
  19270. source = this._sources.indexOf(source);
  19271. var name = null;
  19272. if (mapping.name) {
  19273. name = section.consumer._names.at(mapping.name);
  19274. this._names.add(name);
  19275. name = this._names.indexOf(name);
  19276. }
  19277. // The mappings coming from the consumer for the section have
  19278. // generated positions relative to the start of the section, so we
  19279. // need to offset them to be relative to the start of the concatenated
  19280. // generated file.
  19281. var adjustedMapping = {
  19282. source: source,
  19283. generatedLine: mapping.generatedLine +
  19284. (section.generatedOffset.generatedLine - 1),
  19285. generatedColumn: mapping.generatedColumn +
  19286. (section.generatedOffset.generatedLine === mapping.generatedLine
  19287. ? section.generatedOffset.generatedColumn - 1
  19288. : 0),
  19289. originalLine: mapping.originalLine,
  19290. originalColumn: mapping.originalColumn,
  19291. name: name
  19292. };
  19293. this.__generatedMappings.push(adjustedMapping);
  19294. if (typeof adjustedMapping.originalLine === 'number') {
  19295. this.__originalMappings.push(adjustedMapping);
  19296. }
  19297. }
  19298. }
  19299. quickSort$2(this.__generatedMappings, util$8.compareByGeneratedPositionsDeflated);
  19300. quickSort$2(this.__originalMappings, util$8.compareByOriginalPositions);
  19301. };
  19302. sourceMapConsumer$1.IndexedSourceMapConsumer = IndexedSourceMapConsumer$1;
  19303. var sourceNode$1 = {};
  19304. /* -*- Mode: js; js-indent-level: 2; -*- */
  19305. /*
  19306. * Copyright 2011 Mozilla Foundation and contributors
  19307. * Licensed under the New BSD license. See LICENSE or:
  19308. * http://opensource.org/licenses/BSD-3-Clause
  19309. */
  19310. var SourceMapGenerator$7 = sourceMapGenerator$1.SourceMapGenerator;
  19311. var util$7 = util$c;
  19312. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  19313. // operating systems these days (capturing the result).
  19314. var REGEX_NEWLINE$1 = /(\r?\n)/;
  19315. // Newline character code for charCodeAt() comparisons
  19316. var NEWLINE_CODE$1 = 10;
  19317. // Private symbol for identifying `SourceNode`s when multiple versions of
  19318. // the source-map library are loaded. This MUST NOT CHANGE across
  19319. // versions!
  19320. var isSourceNode$1 = "$$$isSourceNode$$$";
  19321. /**
  19322. * SourceNodes provide a way to abstract over interpolating/concatenating
  19323. * snippets of generated JavaScript source code while maintaining the line and
  19324. * column information associated with the original source code.
  19325. *
  19326. * @param aLine The original line number.
  19327. * @param aColumn The original column number.
  19328. * @param aSource The original source's filename.
  19329. * @param aChunks Optional. An array of strings which are snippets of
  19330. * generated JS, or other SourceNodes.
  19331. * @param aName The original identifier.
  19332. */
  19333. function SourceNode$1(aLine, aColumn, aSource, aChunks, aName) {
  19334. this.children = [];
  19335. this.sourceContents = {};
  19336. this.line = aLine == null ? null : aLine;
  19337. this.column = aColumn == null ? null : aColumn;
  19338. this.source = aSource == null ? null : aSource;
  19339. this.name = aName == null ? null : aName;
  19340. this[isSourceNode$1] = true;
  19341. if (aChunks != null) this.add(aChunks);
  19342. }
  19343. /**
  19344. * Creates a SourceNode from generated code and a SourceMapConsumer.
  19345. *
  19346. * @param aGeneratedCode The generated code
  19347. * @param aSourceMapConsumer The SourceMap for the generated code
  19348. * @param aRelativePath Optional. The path that relative sources in the
  19349. * SourceMapConsumer should be relative to.
  19350. */
  19351. SourceNode$1.fromStringWithSourceMap =
  19352. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  19353. // The SourceNode we want to fill with the generated code
  19354. // and the SourceMap
  19355. var node = new SourceNode$1();
  19356. // All even indices of this array are one line of the generated code,
  19357. // while all odd indices are the newlines between two adjacent lines
  19358. // (since `REGEX_NEWLINE` captures its match).
  19359. // Processed fragments are accessed by calling `shiftNextLine`.
  19360. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE$1);
  19361. var remainingLinesIndex = 0;
  19362. var shiftNextLine = function() {
  19363. var lineContents = getNextLine();
  19364. // The last line of a file might not have a newline.
  19365. var newLine = getNextLine() || "";
  19366. return lineContents + newLine;
  19367. function getNextLine() {
  19368. return remainingLinesIndex < remainingLines.length ?
  19369. remainingLines[remainingLinesIndex++] : undefined;
  19370. }
  19371. };
  19372. // We need to remember the position of "remainingLines"
  19373. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  19374. // The generate SourceNodes we need a code range.
  19375. // To extract it current and last mapping is used.
  19376. // Here we store the last mapping.
  19377. var lastMapping = null;
  19378. aSourceMapConsumer.eachMapping(function (mapping) {
  19379. if (lastMapping !== null) {
  19380. // We add the code from "lastMapping" to "mapping":
  19381. // First check if there is a new line in between.
  19382. if (lastGeneratedLine < mapping.generatedLine) {
  19383. // Associate first line with "lastMapping"
  19384. addMappingWithCode(lastMapping, shiftNextLine());
  19385. lastGeneratedLine++;
  19386. lastGeneratedColumn = 0;
  19387. // The remaining code is added without mapping
  19388. } else {
  19389. // There is no new line in between.
  19390. // Associate the code between "lastGeneratedColumn" and
  19391. // "mapping.generatedColumn" with "lastMapping"
  19392. var nextLine = remainingLines[remainingLinesIndex] || '';
  19393. var code = nextLine.substr(0, mapping.generatedColumn -
  19394. lastGeneratedColumn);
  19395. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  19396. lastGeneratedColumn);
  19397. lastGeneratedColumn = mapping.generatedColumn;
  19398. addMappingWithCode(lastMapping, code);
  19399. // No more remaining code, continue
  19400. lastMapping = mapping;
  19401. return;
  19402. }
  19403. }
  19404. // We add the generated code until the first mapping
  19405. // to the SourceNode without any mapping.
  19406. // Each line is added as separate string.
  19407. while (lastGeneratedLine < mapping.generatedLine) {
  19408. node.add(shiftNextLine());
  19409. lastGeneratedLine++;
  19410. }
  19411. if (lastGeneratedColumn < mapping.generatedColumn) {
  19412. var nextLine = remainingLines[remainingLinesIndex] || '';
  19413. node.add(nextLine.substr(0, mapping.generatedColumn));
  19414. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  19415. lastGeneratedColumn = mapping.generatedColumn;
  19416. }
  19417. lastMapping = mapping;
  19418. }, this);
  19419. // We have processed all mappings.
  19420. if (remainingLinesIndex < remainingLines.length) {
  19421. if (lastMapping) {
  19422. // Associate the remaining code in the current line with "lastMapping"
  19423. addMappingWithCode(lastMapping, shiftNextLine());
  19424. }
  19425. // and add the remaining lines without any mapping
  19426. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  19427. }
  19428. // Copy sourcesContent into SourceNode
  19429. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  19430. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  19431. if (content != null) {
  19432. if (aRelativePath != null) {
  19433. sourceFile = util$7.join(aRelativePath, sourceFile);
  19434. }
  19435. node.setSourceContent(sourceFile, content);
  19436. }
  19437. });
  19438. return node;
  19439. function addMappingWithCode(mapping, code) {
  19440. if (mapping === null || mapping.source === undefined) {
  19441. node.add(code);
  19442. } else {
  19443. var source = aRelativePath
  19444. ? util$7.join(aRelativePath, mapping.source)
  19445. : mapping.source;
  19446. node.add(new SourceNode$1(mapping.originalLine,
  19447. mapping.originalColumn,
  19448. source,
  19449. code,
  19450. mapping.name));
  19451. }
  19452. }
  19453. };
  19454. /**
  19455. * Add a chunk of generated JS to this source node.
  19456. *
  19457. * @param aChunk A string snippet of generated JS code, another instance of
  19458. * SourceNode, or an array where each member is one of those things.
  19459. */
  19460. SourceNode$1.prototype.add = function SourceNode_add(aChunk) {
  19461. if (Array.isArray(aChunk)) {
  19462. aChunk.forEach(function (chunk) {
  19463. this.add(chunk);
  19464. }, this);
  19465. }
  19466. else if (aChunk[isSourceNode$1] || typeof aChunk === "string") {
  19467. if (aChunk) {
  19468. this.children.push(aChunk);
  19469. }
  19470. }
  19471. else {
  19472. throw new TypeError(
  19473. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  19474. );
  19475. }
  19476. return this;
  19477. };
  19478. /**
  19479. * Add a chunk of generated JS to the beginning of this source node.
  19480. *
  19481. * @param aChunk A string snippet of generated JS code, another instance of
  19482. * SourceNode, or an array where each member is one of those things.
  19483. */
  19484. SourceNode$1.prototype.prepend = function SourceNode_prepend(aChunk) {
  19485. if (Array.isArray(aChunk)) {
  19486. for (var i = aChunk.length-1; i >= 0; i--) {
  19487. this.prepend(aChunk[i]);
  19488. }
  19489. }
  19490. else if (aChunk[isSourceNode$1] || typeof aChunk === "string") {
  19491. this.children.unshift(aChunk);
  19492. }
  19493. else {
  19494. throw new TypeError(
  19495. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  19496. );
  19497. }
  19498. return this;
  19499. };
  19500. /**
  19501. * Walk over the tree of JS snippets in this node and its children. The
  19502. * walking function is called once for each snippet of JS and is passed that
  19503. * snippet and the its original associated source's line/column location.
  19504. *
  19505. * @param aFn The traversal function.
  19506. */
  19507. SourceNode$1.prototype.walk = function SourceNode_walk(aFn) {
  19508. var chunk;
  19509. for (var i = 0, len = this.children.length; i < len; i++) {
  19510. chunk = this.children[i];
  19511. if (chunk[isSourceNode$1]) {
  19512. chunk.walk(aFn);
  19513. }
  19514. else {
  19515. if (chunk !== '') {
  19516. aFn(chunk, { source: this.source,
  19517. line: this.line,
  19518. column: this.column,
  19519. name: this.name });
  19520. }
  19521. }
  19522. }
  19523. };
  19524. /**
  19525. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  19526. * each of `this.children`.
  19527. *
  19528. * @param aSep The separator.
  19529. */
  19530. SourceNode$1.prototype.join = function SourceNode_join(aSep) {
  19531. var newChildren;
  19532. var i;
  19533. var len = this.children.length;
  19534. if (len > 0) {
  19535. newChildren = [];
  19536. for (i = 0; i < len-1; i++) {
  19537. newChildren.push(this.children[i]);
  19538. newChildren.push(aSep);
  19539. }
  19540. newChildren.push(this.children[i]);
  19541. this.children = newChildren;
  19542. }
  19543. return this;
  19544. };
  19545. /**
  19546. * Call String.prototype.replace on the very right-most source snippet. Useful
  19547. * for trimming whitespace from the end of a source node, etc.
  19548. *
  19549. * @param aPattern The pattern to replace.
  19550. * @param aReplacement The thing to replace the pattern with.
  19551. */
  19552. SourceNode$1.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  19553. var lastChild = this.children[this.children.length - 1];
  19554. if (lastChild[isSourceNode$1]) {
  19555. lastChild.replaceRight(aPattern, aReplacement);
  19556. }
  19557. else if (typeof lastChild === 'string') {
  19558. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  19559. }
  19560. else {
  19561. this.children.push(''.replace(aPattern, aReplacement));
  19562. }
  19563. return this;
  19564. };
  19565. /**
  19566. * Set the source content for a source file. This will be added to the SourceMapGenerator
  19567. * in the sourcesContent field.
  19568. *
  19569. * @param aSourceFile The filename of the source file
  19570. * @param aSourceContent The content of the source file
  19571. */
  19572. SourceNode$1.prototype.setSourceContent =
  19573. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  19574. this.sourceContents[util$7.toSetString(aSourceFile)] = aSourceContent;
  19575. };
  19576. /**
  19577. * Walk over the tree of SourceNodes. The walking function is called for each
  19578. * source file content and is passed the filename and source content.
  19579. *
  19580. * @param aFn The traversal function.
  19581. */
  19582. SourceNode$1.prototype.walkSourceContents =
  19583. function SourceNode_walkSourceContents(aFn) {
  19584. for (var i = 0, len = this.children.length; i < len; i++) {
  19585. if (this.children[i][isSourceNode$1]) {
  19586. this.children[i].walkSourceContents(aFn);
  19587. }
  19588. }
  19589. var sources = Object.keys(this.sourceContents);
  19590. for (var i = 0, len = sources.length; i < len; i++) {
  19591. aFn(util$7.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  19592. }
  19593. };
  19594. /**
  19595. * Return the string representation of this source node. Walks over the tree
  19596. * and concatenates all the various snippets together to one string.
  19597. */
  19598. SourceNode$1.prototype.toString = function SourceNode_toString() {
  19599. var str = "";
  19600. this.walk(function (chunk) {
  19601. str += chunk;
  19602. });
  19603. return str;
  19604. };
  19605. /**
  19606. * Returns the string representation of this source node along with a source
  19607. * map.
  19608. */
  19609. SourceNode$1.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  19610. var generated = {
  19611. code: "",
  19612. line: 1,
  19613. column: 0
  19614. };
  19615. var map = new SourceMapGenerator$7(aArgs);
  19616. var sourceMappingActive = false;
  19617. var lastOriginalSource = null;
  19618. var lastOriginalLine = null;
  19619. var lastOriginalColumn = null;
  19620. var lastOriginalName = null;
  19621. this.walk(function (chunk, original) {
  19622. generated.code += chunk;
  19623. if (original.source !== null
  19624. && original.line !== null
  19625. && original.column !== null) {
  19626. if(lastOriginalSource !== original.source
  19627. || lastOriginalLine !== original.line
  19628. || lastOriginalColumn !== original.column
  19629. || lastOriginalName !== original.name) {
  19630. map.addMapping({
  19631. source: original.source,
  19632. original: {
  19633. line: original.line,
  19634. column: original.column
  19635. },
  19636. generated: {
  19637. line: generated.line,
  19638. column: generated.column
  19639. },
  19640. name: original.name
  19641. });
  19642. }
  19643. lastOriginalSource = original.source;
  19644. lastOriginalLine = original.line;
  19645. lastOriginalColumn = original.column;
  19646. lastOriginalName = original.name;
  19647. sourceMappingActive = true;
  19648. } else if (sourceMappingActive) {
  19649. map.addMapping({
  19650. generated: {
  19651. line: generated.line,
  19652. column: generated.column
  19653. }
  19654. });
  19655. lastOriginalSource = null;
  19656. sourceMappingActive = false;
  19657. }
  19658. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  19659. if (chunk.charCodeAt(idx) === NEWLINE_CODE$1) {
  19660. generated.line++;
  19661. generated.column = 0;
  19662. // Mappings end at eol
  19663. if (idx + 1 === length) {
  19664. lastOriginalSource = null;
  19665. sourceMappingActive = false;
  19666. } else if (sourceMappingActive) {
  19667. map.addMapping({
  19668. source: original.source,
  19669. original: {
  19670. line: original.line,
  19671. column: original.column
  19672. },
  19673. generated: {
  19674. line: generated.line,
  19675. column: generated.column
  19676. },
  19677. name: original.name
  19678. });
  19679. }
  19680. } else {
  19681. generated.column++;
  19682. }
  19683. }
  19684. });
  19685. this.walkSourceContents(function (sourceFile, sourceContent) {
  19686. map.setSourceContent(sourceFile, sourceContent);
  19687. });
  19688. return { code: generated.code, map: map };
  19689. };
  19690. sourceNode$1.SourceNode = SourceNode$1;
  19691. /*
  19692. * Copyright 2009-2011 Mozilla Foundation and contributors
  19693. * Licensed under the New BSD license. See LICENSE.txt or:
  19694. * http://opensource.org/licenses/BSD-3-Clause
  19695. */
  19696. var SourceMapGenerator$6 = sourceMap$2.SourceMapGenerator = sourceMapGenerator$1.SourceMapGenerator;
  19697. var SourceMapConsumer$5 = sourceMap$2.SourceMapConsumer = sourceMapConsumer$1.SourceMapConsumer;
  19698. sourceMap$2.SourceNode = sourceNode$1.SourceNode;
  19699. const PURE_ANNOTATION = `/*#__PURE__*/`;
  19700. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  19701. function createCodegenContext(ast, {
  19702. mode = "function",
  19703. prefixIdentifiers = mode === "module",
  19704. sourceMap = false,
  19705. filename = `template.vue.html`,
  19706. scopeId = null,
  19707. optimizeImports = false,
  19708. runtimeGlobalName = `Vue`,
  19709. runtimeModuleName = `vue`,
  19710. ssrRuntimeModuleName = "vue/server-renderer",
  19711. ssr = false,
  19712. isTS = false,
  19713. inSSR = false
  19714. }) {
  19715. const context = {
  19716. mode,
  19717. prefixIdentifiers,
  19718. sourceMap,
  19719. filename,
  19720. scopeId,
  19721. optimizeImports,
  19722. runtimeGlobalName,
  19723. runtimeModuleName,
  19724. ssrRuntimeModuleName,
  19725. ssr,
  19726. isTS,
  19727. inSSR,
  19728. source: ast.loc.source,
  19729. code: ``,
  19730. column: 1,
  19731. line: 1,
  19732. offset: 0,
  19733. indentLevel: 0,
  19734. pure: false,
  19735. map: void 0,
  19736. helper(key) {
  19737. return `_${helperNameMap[key]}`;
  19738. },
  19739. push(code, node) {
  19740. context.code += code;
  19741. if (context.map) {
  19742. if (node) {
  19743. let name;
  19744. if (node.type === 4 && !node.isStatic) {
  19745. const content = node.content.replace(/^_ctx\./, "");
  19746. if (content !== node.content && isSimpleIdentifier(content)) {
  19747. name = content;
  19748. }
  19749. }
  19750. addMapping(node.loc.start, name);
  19751. }
  19752. advancePositionWithMutation(context, code);
  19753. if (node && node.loc !== locStub) {
  19754. addMapping(node.loc.end);
  19755. }
  19756. }
  19757. },
  19758. indent() {
  19759. newline(++context.indentLevel);
  19760. },
  19761. deindent(withoutNewLine = false) {
  19762. if (withoutNewLine) {
  19763. --context.indentLevel;
  19764. } else {
  19765. newline(--context.indentLevel);
  19766. }
  19767. },
  19768. newline() {
  19769. newline(context.indentLevel);
  19770. }
  19771. };
  19772. function newline(n) {
  19773. context.push("\n" + ` `.repeat(n));
  19774. }
  19775. function addMapping(loc, name) {
  19776. context.map.addMapping({
  19777. name,
  19778. source: context.filename,
  19779. original: {
  19780. line: loc.line,
  19781. column: loc.column - 1
  19782. // source-map column is 0 based
  19783. },
  19784. generated: {
  19785. line: context.line,
  19786. column: context.column - 1
  19787. }
  19788. });
  19789. }
  19790. if (sourceMap) {
  19791. context.map = new SourceMapGenerator$6();
  19792. context.map.setSourceContent(filename, context.source);
  19793. }
  19794. return context;
  19795. }
  19796. function generate(ast, options = {}) {
  19797. const context = createCodegenContext(ast, options);
  19798. if (options.onContextCreated)
  19799. options.onContextCreated(context);
  19800. const {
  19801. mode,
  19802. push,
  19803. prefixIdentifiers,
  19804. indent,
  19805. deindent,
  19806. newline,
  19807. scopeId,
  19808. ssr
  19809. } = context;
  19810. const helpers = Array.from(ast.helpers);
  19811. const hasHelpers = helpers.length > 0;
  19812. const useWithBlock = !prefixIdentifiers && mode !== "module";
  19813. const genScopeId = scopeId != null && mode === "module";
  19814. const isSetupInlined = !!options.inline;
  19815. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  19816. if (mode === "module") {
  19817. genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
  19818. } else {
  19819. genFunctionPreamble(ast, preambleContext);
  19820. }
  19821. const functionName = ssr ? `ssrRender` : `render`;
  19822. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  19823. if (options.bindingMetadata && !options.inline) {
  19824. args.push("$props", "$setup", "$data", "$options");
  19825. }
  19826. const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
  19827. if (isSetupInlined) {
  19828. push(`(${signature}) => {`);
  19829. } else {
  19830. push(`function ${functionName}(${signature}) {`);
  19831. }
  19832. indent();
  19833. if (useWithBlock) {
  19834. push(`with (_ctx) {`);
  19835. indent();
  19836. if (hasHelpers) {
  19837. push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
  19838. push(`
  19839. `);
  19840. newline();
  19841. }
  19842. }
  19843. if (ast.components.length) {
  19844. genAssets(ast.components, "component", context);
  19845. if (ast.directives.length || ast.temps > 0) {
  19846. newline();
  19847. }
  19848. }
  19849. if (ast.directives.length) {
  19850. genAssets(ast.directives, "directive", context);
  19851. if (ast.temps > 0) {
  19852. newline();
  19853. }
  19854. }
  19855. if (ast.temps > 0) {
  19856. push(`let `);
  19857. for (let i = 0; i < ast.temps; i++) {
  19858. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  19859. }
  19860. }
  19861. if (ast.components.length || ast.directives.length || ast.temps) {
  19862. push(`
  19863. `);
  19864. newline();
  19865. }
  19866. if (!ssr) {
  19867. push(`return `);
  19868. }
  19869. if (ast.codegenNode) {
  19870. genNode(ast.codegenNode, context);
  19871. } else {
  19872. push(`null`);
  19873. }
  19874. if (useWithBlock) {
  19875. deindent();
  19876. push(`}`);
  19877. }
  19878. deindent();
  19879. push(`}`);
  19880. return {
  19881. ast,
  19882. code: context.code,
  19883. preamble: isSetupInlined ? preambleContext.code : ``,
  19884. // SourceMapGenerator does have toJSON() method but it's not in the types
  19885. map: context.map ? context.map.toJSON() : void 0
  19886. };
  19887. }
  19888. function genFunctionPreamble(ast, context) {
  19889. const {
  19890. ssr,
  19891. prefixIdentifiers,
  19892. push,
  19893. newline,
  19894. runtimeModuleName,
  19895. runtimeGlobalName,
  19896. ssrRuntimeModuleName
  19897. } = context;
  19898. const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
  19899. const helpers = Array.from(ast.helpers);
  19900. if (helpers.length > 0) {
  19901. if (prefixIdentifiers) {
  19902. push(`const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
  19903. `);
  19904. } else {
  19905. push(`const _Vue = ${VueBinding}
  19906. `);
  19907. if (ast.hoists.length) {
  19908. const staticHelpers = [
  19909. CREATE_VNODE,
  19910. CREATE_ELEMENT_VNODE,
  19911. CREATE_COMMENT,
  19912. CREATE_TEXT,
  19913. CREATE_STATIC
  19914. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  19915. push(`const { ${staticHelpers} } = _Vue
  19916. `);
  19917. }
  19918. }
  19919. }
  19920. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  19921. push(
  19922. `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
  19923. `
  19924. );
  19925. }
  19926. genHoists(ast.hoists, context);
  19927. newline();
  19928. push(`return `);
  19929. }
  19930. function genModulePreamble(ast, context, genScopeId, inline) {
  19931. const {
  19932. push,
  19933. newline,
  19934. optimizeImports,
  19935. runtimeModuleName,
  19936. ssrRuntimeModuleName
  19937. } = context;
  19938. if (genScopeId && ast.hoists.length) {
  19939. ast.helpers.add(PUSH_SCOPE_ID);
  19940. ast.helpers.add(POP_SCOPE_ID);
  19941. }
  19942. if (ast.helpers.size) {
  19943. const helpers = Array.from(ast.helpers);
  19944. if (optimizeImports) {
  19945. push(
  19946. `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  19947. `
  19948. );
  19949. push(
  19950. `
  19951. // Binding optimization for webpack code-split
  19952. const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
  19953. `
  19954. );
  19955. } else {
  19956. push(
  19957. `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  19958. `
  19959. );
  19960. }
  19961. }
  19962. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  19963. push(
  19964. `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
  19965. `
  19966. );
  19967. }
  19968. if (ast.imports.length) {
  19969. genImports(ast.imports, context);
  19970. newline();
  19971. }
  19972. genHoists(ast.hoists, context);
  19973. newline();
  19974. if (!inline) {
  19975. push(`export `);
  19976. }
  19977. }
  19978. function genAssets(assets, type, { helper, push, newline, isTS }) {
  19979. const resolver = helper(
  19980. type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  19981. );
  19982. for (let i = 0; i < assets.length; i++) {
  19983. let id = assets[i];
  19984. const maybeSelfReference = id.endsWith("__self");
  19985. if (maybeSelfReference) {
  19986. id = id.slice(0, -6);
  19987. }
  19988. push(
  19989. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  19990. );
  19991. if (i < assets.length - 1) {
  19992. newline();
  19993. }
  19994. }
  19995. }
  19996. function genHoists(hoists, context) {
  19997. if (!hoists.length) {
  19998. return;
  19999. }
  20000. context.pure = true;
  20001. const { push, newline, helper, scopeId, mode } = context;
  20002. const genScopeId = scopeId != null && mode !== "function";
  20003. newline();
  20004. if (genScopeId) {
  20005. push(
  20006. `const _withScopeId = n => (${helper(
  20007. PUSH_SCOPE_ID
  20008. )}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`
  20009. );
  20010. newline();
  20011. }
  20012. for (let i = 0; i < hoists.length; i++) {
  20013. const exp = hoists[i];
  20014. if (exp) {
  20015. const needScopeIdWrapper = genScopeId && exp.type === 13;
  20016. push(
  20017. `const _hoisted_${i + 1} = ${needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : ``}`
  20018. );
  20019. genNode(exp, context);
  20020. if (needScopeIdWrapper) {
  20021. push(`)`);
  20022. }
  20023. newline();
  20024. }
  20025. }
  20026. context.pure = false;
  20027. }
  20028. function genImports(importsOptions, context) {
  20029. if (!importsOptions.length) {
  20030. return;
  20031. }
  20032. importsOptions.forEach((imports) => {
  20033. context.push(`import `);
  20034. genNode(imports.exp, context);
  20035. context.push(` from '${imports.path}'`);
  20036. context.newline();
  20037. });
  20038. }
  20039. function isText(n) {
  20040. return isString$2(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  20041. }
  20042. function genNodeListAsArray(nodes, context) {
  20043. const multilines = nodes.length > 3 || nodes.some((n) => isArray$3(n) || !isText(n));
  20044. context.push(`[`);
  20045. multilines && context.indent();
  20046. genNodeList(nodes, context, multilines);
  20047. multilines && context.deindent();
  20048. context.push(`]`);
  20049. }
  20050. function genNodeList(nodes, context, multilines = false, comma = true) {
  20051. const { push, newline } = context;
  20052. for (let i = 0; i < nodes.length; i++) {
  20053. const node = nodes[i];
  20054. if (isString$2(node)) {
  20055. push(node);
  20056. } else if (isArray$3(node)) {
  20057. genNodeListAsArray(node, context);
  20058. } else {
  20059. genNode(node, context);
  20060. }
  20061. if (i < nodes.length - 1) {
  20062. if (multilines) {
  20063. comma && push(",");
  20064. newline();
  20065. } else {
  20066. comma && push(", ");
  20067. }
  20068. }
  20069. }
  20070. }
  20071. function genNode(node, context) {
  20072. if (isString$2(node)) {
  20073. context.push(node);
  20074. return;
  20075. }
  20076. if (isSymbol$1(node)) {
  20077. context.push(context.helper(node));
  20078. return;
  20079. }
  20080. switch (node.type) {
  20081. case 1:
  20082. case 9:
  20083. case 11:
  20084. assert(
  20085. node.codegenNode != null,
  20086. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  20087. );
  20088. genNode(node.codegenNode, context);
  20089. break;
  20090. case 2:
  20091. genText(node, context);
  20092. break;
  20093. case 4:
  20094. genExpression(node, context);
  20095. break;
  20096. case 5:
  20097. genInterpolation(node, context);
  20098. break;
  20099. case 12:
  20100. genNode(node.codegenNode, context);
  20101. break;
  20102. case 8:
  20103. genCompoundExpression(node, context);
  20104. break;
  20105. case 3:
  20106. genComment(node, context);
  20107. break;
  20108. case 13:
  20109. genVNodeCall(node, context);
  20110. break;
  20111. case 14:
  20112. genCallExpression(node, context);
  20113. break;
  20114. case 15:
  20115. genObjectExpression(node, context);
  20116. break;
  20117. case 17:
  20118. genArrayExpression(node, context);
  20119. break;
  20120. case 18:
  20121. genFunctionExpression(node, context);
  20122. break;
  20123. case 19:
  20124. genConditionalExpression(node, context);
  20125. break;
  20126. case 20:
  20127. genCacheExpression(node, context);
  20128. break;
  20129. case 21:
  20130. genNodeList(node.body, context, true, false);
  20131. break;
  20132. case 22:
  20133. genTemplateLiteral(node, context);
  20134. break;
  20135. case 23:
  20136. genIfStatement(node, context);
  20137. break;
  20138. case 24:
  20139. genAssignmentExpression(node, context);
  20140. break;
  20141. case 25:
  20142. genSequenceExpression(node, context);
  20143. break;
  20144. case 26:
  20145. genReturnStatement(node, context);
  20146. break;
  20147. case 10:
  20148. break;
  20149. default:
  20150. {
  20151. assert(false, `unhandled codegen node type: ${node.type}`);
  20152. const exhaustiveCheck = node;
  20153. return exhaustiveCheck;
  20154. }
  20155. }
  20156. }
  20157. function genText(node, context) {
  20158. context.push(JSON.stringify(node.content), node);
  20159. }
  20160. function genExpression(node, context) {
  20161. const { content, isStatic } = node;
  20162. context.push(isStatic ? JSON.stringify(content) : content, node);
  20163. }
  20164. function genInterpolation(node, context) {
  20165. const { push, helper, pure } = context;
  20166. if (pure)
  20167. push(PURE_ANNOTATION);
  20168. push(`${helper(TO_DISPLAY_STRING)}(`);
  20169. genNode(node.content, context);
  20170. push(`)`);
  20171. }
  20172. function genCompoundExpression(node, context) {
  20173. for (let i = 0; i < node.children.length; i++) {
  20174. const child = node.children[i];
  20175. if (isString$2(child)) {
  20176. context.push(child);
  20177. } else {
  20178. genNode(child, context);
  20179. }
  20180. }
  20181. }
  20182. function genExpressionAsPropertyKey(node, context) {
  20183. const { push } = context;
  20184. if (node.type === 8) {
  20185. push(`[`);
  20186. genCompoundExpression(node, context);
  20187. push(`]`);
  20188. } else if (node.isStatic) {
  20189. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  20190. push(text, node);
  20191. } else {
  20192. push(`[${node.content}]`, node);
  20193. }
  20194. }
  20195. function genComment(node, context) {
  20196. const { push, helper, pure } = context;
  20197. if (pure) {
  20198. push(PURE_ANNOTATION);
  20199. }
  20200. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  20201. }
  20202. function genVNodeCall(node, context) {
  20203. const { push, helper, pure } = context;
  20204. const {
  20205. tag,
  20206. props,
  20207. children,
  20208. patchFlag,
  20209. dynamicProps,
  20210. directives,
  20211. isBlock,
  20212. disableTracking,
  20213. isComponent
  20214. } = node;
  20215. if (directives) {
  20216. push(helper(WITH_DIRECTIVES) + `(`);
  20217. }
  20218. if (isBlock) {
  20219. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  20220. }
  20221. if (pure) {
  20222. push(PURE_ANNOTATION);
  20223. }
  20224. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  20225. push(helper(callHelper) + `(`, node);
  20226. genNodeList(
  20227. genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
  20228. context
  20229. );
  20230. push(`)`);
  20231. if (isBlock) {
  20232. push(`)`);
  20233. }
  20234. if (directives) {
  20235. push(`, `);
  20236. genNode(directives, context);
  20237. push(`)`);
  20238. }
  20239. }
  20240. function genNullableArgs(args) {
  20241. let i = args.length;
  20242. while (i--) {
  20243. if (args[i] != null)
  20244. break;
  20245. }
  20246. return args.slice(0, i + 1).map((arg) => arg || `null`);
  20247. }
  20248. function genCallExpression(node, context) {
  20249. const { push, helper, pure } = context;
  20250. const callee = isString$2(node.callee) ? node.callee : helper(node.callee);
  20251. if (pure) {
  20252. push(PURE_ANNOTATION);
  20253. }
  20254. push(callee + `(`, node);
  20255. genNodeList(node.arguments, context);
  20256. push(`)`);
  20257. }
  20258. function genObjectExpression(node, context) {
  20259. const { push, indent, deindent, newline } = context;
  20260. const { properties } = node;
  20261. if (!properties.length) {
  20262. push(`{}`, node);
  20263. return;
  20264. }
  20265. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  20266. push(multilines ? `{` : `{ `);
  20267. multilines && indent();
  20268. for (let i = 0; i < properties.length; i++) {
  20269. const { key, value } = properties[i];
  20270. genExpressionAsPropertyKey(key, context);
  20271. push(`: `);
  20272. genNode(value, context);
  20273. if (i < properties.length - 1) {
  20274. push(`,`);
  20275. newline();
  20276. }
  20277. }
  20278. multilines && deindent();
  20279. push(multilines ? `}` : ` }`);
  20280. }
  20281. function genArrayExpression(node, context) {
  20282. genNodeListAsArray(node.elements, context);
  20283. }
  20284. function genFunctionExpression(node, context) {
  20285. const { push, indent, deindent } = context;
  20286. const { params, returns, body, newline, isSlot } = node;
  20287. if (isSlot) {
  20288. push(`_${helperNameMap[WITH_CTX]}(`);
  20289. }
  20290. push(`(`, node);
  20291. if (isArray$3(params)) {
  20292. genNodeList(params, context);
  20293. } else if (params) {
  20294. genNode(params, context);
  20295. }
  20296. push(`) => `);
  20297. if (newline || body) {
  20298. push(`{`);
  20299. indent();
  20300. }
  20301. if (returns) {
  20302. if (newline) {
  20303. push(`return `);
  20304. }
  20305. if (isArray$3(returns)) {
  20306. genNodeListAsArray(returns, context);
  20307. } else {
  20308. genNode(returns, context);
  20309. }
  20310. } else if (body) {
  20311. genNode(body, context);
  20312. }
  20313. if (newline || body) {
  20314. deindent();
  20315. push(`}`);
  20316. }
  20317. if (isSlot) {
  20318. push(`)`);
  20319. }
  20320. }
  20321. function genConditionalExpression(node, context) {
  20322. const { test, consequent, alternate, newline: needNewline } = node;
  20323. const { push, indent, deindent, newline } = context;
  20324. if (test.type === 4) {
  20325. const needsParens = !isSimpleIdentifier(test.content);
  20326. needsParens && push(`(`);
  20327. genExpression(test, context);
  20328. needsParens && push(`)`);
  20329. } else {
  20330. push(`(`);
  20331. genNode(test, context);
  20332. push(`)`);
  20333. }
  20334. needNewline && indent();
  20335. context.indentLevel++;
  20336. needNewline || push(` `);
  20337. push(`? `);
  20338. genNode(consequent, context);
  20339. context.indentLevel--;
  20340. needNewline && newline();
  20341. needNewline || push(` `);
  20342. push(`: `);
  20343. const isNested = alternate.type === 19;
  20344. if (!isNested) {
  20345. context.indentLevel++;
  20346. }
  20347. genNode(alternate, context);
  20348. if (!isNested) {
  20349. context.indentLevel--;
  20350. }
  20351. needNewline && deindent(
  20352. true
  20353. /* without newline */
  20354. );
  20355. }
  20356. function genCacheExpression(node, context) {
  20357. const { push, helper, indent, deindent, newline } = context;
  20358. push(`_cache[${node.index}] || (`);
  20359. if (node.isVNode) {
  20360. indent();
  20361. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  20362. newline();
  20363. }
  20364. push(`_cache[${node.index}] = `);
  20365. genNode(node.value, context);
  20366. if (node.isVNode) {
  20367. push(`,`);
  20368. newline();
  20369. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  20370. newline();
  20371. push(`_cache[${node.index}]`);
  20372. deindent();
  20373. }
  20374. push(`)`);
  20375. }
  20376. function genTemplateLiteral(node, context) {
  20377. const { push, indent, deindent } = context;
  20378. push("`");
  20379. const l = node.elements.length;
  20380. const multilines = l > 3;
  20381. for (let i = 0; i < l; i++) {
  20382. const e = node.elements[i];
  20383. if (isString$2(e)) {
  20384. push(e.replace(/(`|\$|\\)/g, "\\$1"));
  20385. } else {
  20386. push("${");
  20387. if (multilines)
  20388. indent();
  20389. genNode(e, context);
  20390. if (multilines)
  20391. deindent();
  20392. push("}");
  20393. }
  20394. }
  20395. push("`");
  20396. }
  20397. function genIfStatement(node, context) {
  20398. const { push, indent, deindent } = context;
  20399. const { test, consequent, alternate } = node;
  20400. push(`if (`);
  20401. genNode(test, context);
  20402. push(`) {`);
  20403. indent();
  20404. genNode(consequent, context);
  20405. deindent();
  20406. push(`}`);
  20407. if (alternate) {
  20408. push(` else `);
  20409. if (alternate.type === 23) {
  20410. genIfStatement(alternate, context);
  20411. } else {
  20412. push(`{`);
  20413. indent();
  20414. genNode(alternate, context);
  20415. deindent();
  20416. push(`}`);
  20417. }
  20418. }
  20419. }
  20420. function genAssignmentExpression(node, context) {
  20421. genNode(node.left, context);
  20422. context.push(` = `);
  20423. genNode(node.right, context);
  20424. }
  20425. function genSequenceExpression(node, context) {
  20426. context.push(`(`);
  20427. genNodeList(node.expressions, context);
  20428. context.push(`)`);
  20429. }
  20430. function genReturnStatement({ returns }, context) {
  20431. context.push(`return `);
  20432. if (isArray$3(returns)) {
  20433. genNodeListAsArray(returns, context);
  20434. } else {
  20435. genNode(returns, context);
  20436. }
  20437. }
  20438. // @ts-check
  20439. /** @typedef { import('estree').BaseNode} BaseNode */
  20440. /** @typedef {{
  20441. skip: () => void;
  20442. remove: () => void;
  20443. replace: (node: BaseNode) => void;
  20444. }} WalkerContext */
  20445. class WalkerBase {
  20446. constructor() {
  20447. /** @type {boolean} */
  20448. this.should_skip = false;
  20449. /** @type {boolean} */
  20450. this.should_remove = false;
  20451. /** @type {BaseNode | null} */
  20452. this.replacement = null;
  20453. /** @type {WalkerContext} */
  20454. this.context = {
  20455. skip: () => (this.should_skip = true),
  20456. remove: () => (this.should_remove = true),
  20457. replace: (node) => (this.replacement = node)
  20458. };
  20459. }
  20460. /**
  20461. *
  20462. * @param {any} parent
  20463. * @param {string} prop
  20464. * @param {number} index
  20465. * @param {BaseNode} node
  20466. */
  20467. replace(parent, prop, index, node) {
  20468. if (parent) {
  20469. if (index !== null) {
  20470. parent[prop][index] = node;
  20471. } else {
  20472. parent[prop] = node;
  20473. }
  20474. }
  20475. }
  20476. /**
  20477. *
  20478. * @param {any} parent
  20479. * @param {string} prop
  20480. * @param {number} index
  20481. */
  20482. remove(parent, prop, index) {
  20483. if (parent) {
  20484. if (index !== null) {
  20485. parent[prop].splice(index, 1);
  20486. } else {
  20487. delete parent[prop];
  20488. }
  20489. }
  20490. }
  20491. }
  20492. // @ts-check
  20493. /** @typedef { import('estree').BaseNode} BaseNode */
  20494. /** @typedef { import('./walker.js').WalkerContext} WalkerContext */
  20495. /** @typedef {(
  20496. * this: WalkerContext,
  20497. * node: BaseNode,
  20498. * parent: BaseNode,
  20499. * key: string,
  20500. * index: number
  20501. * ) => void} SyncHandler */
  20502. class SyncWalker extends WalkerBase {
  20503. /**
  20504. *
  20505. * @param {SyncHandler} enter
  20506. * @param {SyncHandler} leave
  20507. */
  20508. constructor(enter, leave) {
  20509. super();
  20510. /** @type {SyncHandler} */
  20511. this.enter = enter;
  20512. /** @type {SyncHandler} */
  20513. this.leave = leave;
  20514. }
  20515. /**
  20516. *
  20517. * @param {BaseNode} node
  20518. * @param {BaseNode} parent
  20519. * @param {string} [prop]
  20520. * @param {number} [index]
  20521. * @returns {BaseNode}
  20522. */
  20523. visit(node, parent, prop, index) {
  20524. if (node) {
  20525. if (this.enter) {
  20526. const _should_skip = this.should_skip;
  20527. const _should_remove = this.should_remove;
  20528. const _replacement = this.replacement;
  20529. this.should_skip = false;
  20530. this.should_remove = false;
  20531. this.replacement = null;
  20532. this.enter.call(this.context, node, parent, prop, index);
  20533. if (this.replacement) {
  20534. node = this.replacement;
  20535. this.replace(parent, prop, index, node);
  20536. }
  20537. if (this.should_remove) {
  20538. this.remove(parent, prop, index);
  20539. }
  20540. const skipped = this.should_skip;
  20541. const removed = this.should_remove;
  20542. this.should_skip = _should_skip;
  20543. this.should_remove = _should_remove;
  20544. this.replacement = _replacement;
  20545. if (skipped) return node;
  20546. if (removed) return null;
  20547. }
  20548. for (const key in node) {
  20549. const value = node[key];
  20550. if (typeof value !== "object") {
  20551. continue;
  20552. } else if (Array.isArray(value)) {
  20553. for (let i = 0; i < value.length; i += 1) {
  20554. if (value[i] !== null && typeof value[i].type === 'string') {
  20555. if (!this.visit(value[i], node, key, i)) {
  20556. // removed
  20557. i--;
  20558. }
  20559. }
  20560. }
  20561. } else if (value !== null && typeof value.type === "string") {
  20562. this.visit(value, node, key, null);
  20563. }
  20564. }
  20565. if (this.leave) {
  20566. const _replacement = this.replacement;
  20567. const _should_remove = this.should_remove;
  20568. this.replacement = null;
  20569. this.should_remove = false;
  20570. this.leave.call(this.context, node, parent, prop, index);
  20571. if (this.replacement) {
  20572. node = this.replacement;
  20573. this.replace(parent, prop, index, node);
  20574. }
  20575. if (this.should_remove) {
  20576. this.remove(parent, prop, index);
  20577. }
  20578. const removed = this.should_remove;
  20579. this.replacement = _replacement;
  20580. this.should_remove = _should_remove;
  20581. if (removed) return null;
  20582. }
  20583. }
  20584. return node;
  20585. }
  20586. }
  20587. // @ts-check
  20588. /** @typedef { import('estree').BaseNode} BaseNode */
  20589. /** @typedef { import('./sync.js').SyncHandler} SyncHandler */
  20590. /** @typedef { import('./async.js').AsyncHandler} AsyncHandler */
  20591. /**
  20592. *
  20593. * @param {BaseNode} ast
  20594. * @param {{
  20595. * enter?: SyncHandler
  20596. * leave?: SyncHandler
  20597. * }} walker
  20598. * @returns {BaseNode}
  20599. */
  20600. function walk$1(ast, { enter, leave }) {
  20601. const instance = new SyncWalker(enter, leave);
  20602. return instance.visit(ast, null);
  20603. }
  20604. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  20605. const rootExp = root.type === "Program" && root.body[0].type === "ExpressionStatement" && root.body[0].expression;
  20606. walk$1(root, {
  20607. enter(node, parent) {
  20608. parent && parentStack.push(parent);
  20609. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  20610. return this.skip();
  20611. }
  20612. if (node.type === "Identifier") {
  20613. const isLocal = !!knownIds[node.name];
  20614. const isRefed = isReferencedIdentifier(node, parent, parentStack);
  20615. if (includeAll || isRefed && !isLocal) {
  20616. onIdentifier(node, parent, parentStack, isRefed, isLocal);
  20617. }
  20618. } else if (node.type === "ObjectProperty" && parent.type === "ObjectPattern") {
  20619. node.inPattern = true;
  20620. } else if (isFunctionType(node)) {
  20621. walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
  20622. } else if (node.type === "BlockStatement") {
  20623. walkBlockDeclarations(
  20624. node,
  20625. (id) => markScopeIdentifier(node, id, knownIds)
  20626. );
  20627. }
  20628. },
  20629. leave(node, parent) {
  20630. parent && parentStack.pop();
  20631. if (node !== rootExp && node.scopeIds) {
  20632. for (const id of node.scopeIds) {
  20633. knownIds[id]--;
  20634. if (knownIds[id] === 0) {
  20635. delete knownIds[id];
  20636. }
  20637. }
  20638. }
  20639. }
  20640. });
  20641. }
  20642. function isReferencedIdentifier(id, parent, parentStack) {
  20643. if (!parent) {
  20644. return true;
  20645. }
  20646. if (id.name === "arguments") {
  20647. return false;
  20648. }
  20649. if (isReferenced(id, parent)) {
  20650. return true;
  20651. }
  20652. switch (parent.type) {
  20653. case "AssignmentExpression":
  20654. case "AssignmentPattern":
  20655. return true;
  20656. case "ObjectPattern":
  20657. case "ArrayPattern":
  20658. return isInDestructureAssignment(parent, parentStack);
  20659. }
  20660. return false;
  20661. }
  20662. function isInDestructureAssignment(parent, parentStack) {
  20663. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  20664. let i = parentStack.length;
  20665. while (i--) {
  20666. const p = parentStack[i];
  20667. if (p.type === "AssignmentExpression") {
  20668. return true;
  20669. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  20670. break;
  20671. }
  20672. }
  20673. }
  20674. return false;
  20675. }
  20676. function walkFunctionParams(node, onIdent) {
  20677. for (const p of node.params) {
  20678. for (const id of extractIdentifiers(p)) {
  20679. onIdent(id);
  20680. }
  20681. }
  20682. }
  20683. function walkBlockDeclarations(block, onIdent) {
  20684. for (const stmt of block.body) {
  20685. if (stmt.type === "VariableDeclaration") {
  20686. if (stmt.declare)
  20687. continue;
  20688. for (const decl of stmt.declarations) {
  20689. for (const id of extractIdentifiers(decl.id)) {
  20690. onIdent(id);
  20691. }
  20692. }
  20693. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  20694. if (stmt.declare || !stmt.id)
  20695. continue;
  20696. onIdent(stmt.id);
  20697. } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
  20698. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  20699. if (variable && variable.type === "VariableDeclaration") {
  20700. for (const decl of variable.declarations) {
  20701. for (const id of extractIdentifiers(decl.id)) {
  20702. onIdent(id);
  20703. }
  20704. }
  20705. }
  20706. }
  20707. }
  20708. }
  20709. function extractIdentifiers(param, nodes = []) {
  20710. switch (param.type) {
  20711. case "Identifier":
  20712. nodes.push(param);
  20713. break;
  20714. case "MemberExpression":
  20715. let object = param;
  20716. while (object.type === "MemberExpression") {
  20717. object = object.object;
  20718. }
  20719. nodes.push(object);
  20720. break;
  20721. case "ObjectPattern":
  20722. for (const prop of param.properties) {
  20723. if (prop.type === "RestElement") {
  20724. extractIdentifiers(prop.argument, nodes);
  20725. } else {
  20726. extractIdentifiers(prop.value, nodes);
  20727. }
  20728. }
  20729. break;
  20730. case "ArrayPattern":
  20731. param.elements.forEach((element) => {
  20732. if (element)
  20733. extractIdentifiers(element, nodes);
  20734. });
  20735. break;
  20736. case "RestElement":
  20737. extractIdentifiers(param.argument, nodes);
  20738. break;
  20739. case "AssignmentPattern":
  20740. extractIdentifiers(param.left, nodes);
  20741. break;
  20742. }
  20743. return nodes;
  20744. }
  20745. function markScopeIdentifier(node, child, knownIds) {
  20746. const { name } = child;
  20747. if (node.scopeIds && node.scopeIds.has(name)) {
  20748. return;
  20749. }
  20750. if (name in knownIds) {
  20751. knownIds[name]++;
  20752. } else {
  20753. knownIds[name] = 1;
  20754. }
  20755. (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
  20756. }
  20757. const isFunctionType = (node) => {
  20758. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  20759. };
  20760. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  20761. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  20762. function isReferenced(node, parent, grandparent) {
  20763. switch (parent.type) {
  20764. case "MemberExpression":
  20765. case "OptionalMemberExpression":
  20766. if (parent.property === node) {
  20767. return !!parent.computed;
  20768. }
  20769. return parent.object === node;
  20770. case "JSXMemberExpression":
  20771. return parent.object === node;
  20772. case "VariableDeclarator":
  20773. return parent.init === node;
  20774. case "ArrowFunctionExpression":
  20775. return parent.body === node;
  20776. case "PrivateName":
  20777. return false;
  20778. case "ClassMethod":
  20779. case "ClassPrivateMethod":
  20780. case "ObjectMethod":
  20781. if (parent.key === node) {
  20782. return !!parent.computed;
  20783. }
  20784. return false;
  20785. case "ObjectProperty":
  20786. if (parent.key === node) {
  20787. return !!parent.computed;
  20788. }
  20789. return !grandparent || grandparent.type !== "ObjectPattern";
  20790. case "ClassProperty":
  20791. if (parent.key === node) {
  20792. return !!parent.computed;
  20793. }
  20794. return true;
  20795. case "ClassPrivateProperty":
  20796. return parent.key !== node;
  20797. case "ClassDeclaration":
  20798. case "ClassExpression":
  20799. return parent.superClass === node;
  20800. case "AssignmentExpression":
  20801. return parent.right === node;
  20802. case "AssignmentPattern":
  20803. return parent.right === node;
  20804. case "LabeledStatement":
  20805. return false;
  20806. case "CatchClause":
  20807. return false;
  20808. case "RestElement":
  20809. return false;
  20810. case "BreakStatement":
  20811. case "ContinueStatement":
  20812. return false;
  20813. case "FunctionDeclaration":
  20814. case "FunctionExpression":
  20815. return false;
  20816. case "ExportNamespaceSpecifier":
  20817. case "ExportDefaultSpecifier":
  20818. return false;
  20819. case "ExportSpecifier":
  20820. if (grandparent == null ? void 0 : grandparent.source) {
  20821. return false;
  20822. }
  20823. return parent.local === node;
  20824. case "ImportDefaultSpecifier":
  20825. case "ImportNamespaceSpecifier":
  20826. case "ImportSpecifier":
  20827. return false;
  20828. case "ImportAttribute":
  20829. return false;
  20830. case "JSXAttribute":
  20831. return false;
  20832. case "ObjectPattern":
  20833. case "ArrayPattern":
  20834. return false;
  20835. case "MetaProperty":
  20836. return false;
  20837. case "ObjectTypeProperty":
  20838. return parent.key !== node;
  20839. case "TSEnumMember":
  20840. return parent.id !== node;
  20841. case "TSPropertySignature":
  20842. if (parent.key === node) {
  20843. return !!parent.computed;
  20844. }
  20845. return true;
  20846. }
  20847. return true;
  20848. }
  20849. const TS_NODE_TYPES = [
  20850. "TSAsExpression",
  20851. // foo as number
  20852. "TSTypeAssertion",
  20853. // (<number>foo)
  20854. "TSNonNullExpression",
  20855. // foo!
  20856. "TSInstantiationExpression",
  20857. // foo<string>
  20858. "TSSatisfiesExpression"
  20859. // foo satisfies T
  20860. ];
  20861. const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
  20862. const constantBailRE = /\w\s*\(|\.[^\d]/;
  20863. const transformExpression = (node, context) => {
  20864. if (node.type === 5) {
  20865. node.content = processExpression(
  20866. node.content,
  20867. context
  20868. );
  20869. } else if (node.type === 1) {
  20870. for (let i = 0; i < node.props.length; i++) {
  20871. const dir = node.props[i];
  20872. if (dir.type === 7 && dir.name !== "for") {
  20873. const exp = dir.exp;
  20874. const arg = dir.arg;
  20875. if (exp && exp.type === 4 && !(dir.name === "on" && arg)) {
  20876. dir.exp = processExpression(
  20877. exp,
  20878. context,
  20879. // slot args must be processed as function params
  20880. dir.name === "slot"
  20881. );
  20882. }
  20883. if (arg && arg.type === 4 && !arg.isStatic) {
  20884. dir.arg = processExpression(arg, context);
  20885. }
  20886. }
  20887. }
  20888. }
  20889. };
  20890. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  20891. if (!context.prefixIdentifiers || !node.content.trim()) {
  20892. return node;
  20893. }
  20894. const { inline, bindingMetadata } = context;
  20895. const rewriteIdentifier = (raw, parent, id) => {
  20896. const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
  20897. if (inline) {
  20898. const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
  20899. const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
  20900. const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
  20901. if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
  20902. return raw;
  20903. } else if (type === "setup-ref") {
  20904. return `${raw}.value`;
  20905. } else if (type === "setup-maybe-ref") {
  20906. return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : `${context.helperString(UNREF)}(${raw})`;
  20907. } else if (type === "setup-let") {
  20908. if (isAssignmentLVal) {
  20909. const { right: rVal, operator } = parent;
  20910. const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
  20911. const rExpString = stringifyExpression(
  20912. processExpression(
  20913. createSimpleExpression(rExp, false),
  20914. context,
  20915. false,
  20916. false,
  20917. knownIds
  20918. )
  20919. );
  20920. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  20921. ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
  20922. } else if (isUpdateArg) {
  20923. id.start = parent.start;
  20924. id.end = parent.end;
  20925. const { prefix: isPrefix, operator } = parent;
  20926. const prefix = isPrefix ? operator : ``;
  20927. const postfix = isPrefix ? `` : operator;
  20928. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  20929. ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
  20930. } else if (isDestructureAssignment) {
  20931. return raw;
  20932. } else {
  20933. return `${context.helperString(UNREF)}(${raw})`;
  20934. }
  20935. } else if (type === "props") {
  20936. return genPropsAccessExp(raw);
  20937. } else if (type === "props-aliased") {
  20938. return genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
  20939. }
  20940. } else {
  20941. if (type && type.startsWith("setup") || type === "literal-const") {
  20942. return `$setup.${raw}`;
  20943. } else if (type === "props-aliased") {
  20944. return `$props['${bindingMetadata.__propsAliases[raw]}']`;
  20945. } else if (type) {
  20946. return `$${type}.${raw}`;
  20947. }
  20948. }
  20949. return `_ctx.${raw}`;
  20950. };
  20951. const rawExp = node.content;
  20952. const bailConstant = constantBailRE.test(rawExp);
  20953. if (isSimpleIdentifier(rawExp)) {
  20954. const isScopeVarReference = context.identifiers[rawExp];
  20955. const isAllowedGlobal = isGloballyAllowed(rawExp);
  20956. const isLiteral = isLiteralWhitelisted(rawExp);
  20957. if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
  20958. if (isConst(bindingMetadata[rawExp])) {
  20959. node.constType = 1;
  20960. }
  20961. node.content = rewriteIdentifier(rawExp);
  20962. } else if (!isScopeVarReference) {
  20963. if (isLiteral) {
  20964. node.constType = 3;
  20965. } else {
  20966. node.constType = 2;
  20967. }
  20968. }
  20969. return node;
  20970. }
  20971. let ast;
  20972. const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
  20973. try {
  20974. ast = parse_1$1(source, {
  20975. plugins: context.expressionPlugins
  20976. }).program;
  20977. } catch (e) {
  20978. context.onError(
  20979. createCompilerError(
  20980. 45,
  20981. node.loc,
  20982. void 0,
  20983. e.message
  20984. )
  20985. );
  20986. return node;
  20987. }
  20988. const ids = [];
  20989. const parentStack = [];
  20990. const knownIds = Object.create(context.identifiers);
  20991. walkIdentifiers(
  20992. ast,
  20993. (node2, parent, _, isReferenced, isLocal) => {
  20994. if (isStaticPropertyKey(node2, parent)) {
  20995. return;
  20996. }
  20997. const needPrefix = isReferenced && canPrefix(node2);
  20998. if (needPrefix && !isLocal) {
  20999. if (isStaticProperty(parent) && parent.shorthand) {
  21000. node2.prefix = `${node2.name}: `;
  21001. }
  21002. node2.name = rewriteIdentifier(node2.name, parent, node2);
  21003. ids.push(node2);
  21004. } else {
  21005. if (!(needPrefix && isLocal) && !bailConstant) {
  21006. node2.isConstant = true;
  21007. }
  21008. ids.push(node2);
  21009. }
  21010. },
  21011. true,
  21012. // invoke on ALL identifiers
  21013. parentStack,
  21014. knownIds
  21015. );
  21016. const children = [];
  21017. ids.sort((a, b) => a.start - b.start);
  21018. ids.forEach((id, i) => {
  21019. const start = id.start - 1;
  21020. const end = id.end - 1;
  21021. const last = ids[i - 1];
  21022. const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
  21023. if (leadingText.length || id.prefix) {
  21024. children.push(leadingText + (id.prefix || ``));
  21025. }
  21026. const source2 = rawExp.slice(start, end);
  21027. children.push(
  21028. createSimpleExpression(
  21029. id.name,
  21030. false,
  21031. {
  21032. source: source2,
  21033. start: advancePositionWithClone(node.loc.start, source2, start),
  21034. end: advancePositionWithClone(node.loc.start, source2, end)
  21035. },
  21036. id.isConstant ? 3 : 0
  21037. )
  21038. );
  21039. if (i === ids.length - 1 && end < rawExp.length) {
  21040. children.push(rawExp.slice(end));
  21041. }
  21042. });
  21043. let ret;
  21044. if (children.length) {
  21045. ret = createCompoundExpression(children, node.loc);
  21046. } else {
  21047. ret = node;
  21048. ret.constType = bailConstant ? 0 : 3;
  21049. }
  21050. ret.identifiers = Object.keys(knownIds);
  21051. return ret;
  21052. }
  21053. function canPrefix(id) {
  21054. if (isGloballyAllowed(id.name)) {
  21055. return false;
  21056. }
  21057. if (id.name === "require") {
  21058. return false;
  21059. }
  21060. return true;
  21061. }
  21062. function stringifyExpression(exp) {
  21063. if (isString$2(exp)) {
  21064. return exp;
  21065. } else if (exp.type === 4) {
  21066. return exp.content;
  21067. } else {
  21068. return exp.children.map(stringifyExpression).join("");
  21069. }
  21070. }
  21071. function isConst(type) {
  21072. return type === "setup-const" || type === "literal-const";
  21073. }
  21074. const transformIf = createStructuralDirectiveTransform(
  21075. /^(if|else|else-if)$/,
  21076. (node, dir, context) => {
  21077. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  21078. const siblings = context.parent.children;
  21079. let i = siblings.indexOf(ifNode);
  21080. let key = 0;
  21081. while (i-- >= 0) {
  21082. const sibling = siblings[i];
  21083. if (sibling && sibling.type === 9) {
  21084. key += sibling.branches.length;
  21085. }
  21086. }
  21087. return () => {
  21088. if (isRoot) {
  21089. ifNode.codegenNode = createCodegenNodeForBranch(
  21090. branch,
  21091. key,
  21092. context
  21093. );
  21094. } else {
  21095. const parentCondition = getParentCondition(ifNode.codegenNode);
  21096. parentCondition.alternate = createCodegenNodeForBranch(
  21097. branch,
  21098. key + ifNode.branches.length - 1,
  21099. context
  21100. );
  21101. }
  21102. };
  21103. });
  21104. }
  21105. );
  21106. function processIf(node, dir, context, processCodegen) {
  21107. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  21108. const loc = dir.exp ? dir.exp.loc : node.loc;
  21109. context.onError(
  21110. createCompilerError(28, dir.loc)
  21111. );
  21112. dir.exp = createSimpleExpression(`true`, false, loc);
  21113. }
  21114. if (context.prefixIdentifiers && dir.exp) {
  21115. dir.exp = processExpression(dir.exp, context);
  21116. }
  21117. if (dir.name === "if") {
  21118. const branch = createIfBranch(node, dir);
  21119. const ifNode = {
  21120. type: 9,
  21121. loc: node.loc,
  21122. branches: [branch]
  21123. };
  21124. context.replaceNode(ifNode);
  21125. if (processCodegen) {
  21126. return processCodegen(ifNode, branch, true);
  21127. }
  21128. } else {
  21129. const siblings = context.parent.children;
  21130. const comments = [];
  21131. let i = siblings.indexOf(node);
  21132. while (i-- >= -1) {
  21133. const sibling = siblings[i];
  21134. if (sibling && sibling.type === 3) {
  21135. context.removeNode(sibling);
  21136. comments.unshift(sibling);
  21137. continue;
  21138. }
  21139. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  21140. context.removeNode(sibling);
  21141. continue;
  21142. }
  21143. if (sibling && sibling.type === 9) {
  21144. if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  21145. context.onError(
  21146. createCompilerError(30, node.loc)
  21147. );
  21148. }
  21149. context.removeNode();
  21150. const branch = createIfBranch(node, dir);
  21151. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  21152. !(context.parent && context.parent.type === 1 && isBuiltInType(context.parent.tag, "transition"))) {
  21153. branch.children = [...comments, ...branch.children];
  21154. }
  21155. {
  21156. const key = branch.userKey;
  21157. if (key) {
  21158. sibling.branches.forEach(({ userKey }) => {
  21159. if (isSameKey(userKey, key)) {
  21160. context.onError(
  21161. createCompilerError(
  21162. 29,
  21163. branch.userKey.loc
  21164. )
  21165. );
  21166. }
  21167. });
  21168. }
  21169. }
  21170. sibling.branches.push(branch);
  21171. const onExit = processCodegen && processCodegen(sibling, branch, false);
  21172. traverseNode(branch, context);
  21173. if (onExit)
  21174. onExit();
  21175. context.currentNode = null;
  21176. } else {
  21177. context.onError(
  21178. createCompilerError(30, node.loc)
  21179. );
  21180. }
  21181. break;
  21182. }
  21183. }
  21184. }
  21185. function createIfBranch(node, dir) {
  21186. const isTemplateIf = node.tagType === 3;
  21187. return {
  21188. type: 10,
  21189. loc: node.loc,
  21190. condition: dir.name === "else" ? void 0 : dir.exp,
  21191. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  21192. userKey: findProp(node, `key`),
  21193. isTemplateIf
  21194. };
  21195. }
  21196. function createCodegenNodeForBranch(branch, keyIndex, context) {
  21197. if (branch.condition) {
  21198. return createConditionalExpression(
  21199. branch.condition,
  21200. createChildrenCodegenNode(branch, keyIndex, context),
  21201. // make sure to pass in asBlock: true so that the comment node call
  21202. // closes the current block.
  21203. createCallExpression(context.helper(CREATE_COMMENT), [
  21204. '"v-if"' ,
  21205. "true"
  21206. ])
  21207. );
  21208. } else {
  21209. return createChildrenCodegenNode(branch, keyIndex, context);
  21210. }
  21211. }
  21212. function createChildrenCodegenNode(branch, keyIndex, context) {
  21213. const { helper } = context;
  21214. const keyProperty = createObjectProperty(
  21215. `key`,
  21216. createSimpleExpression(
  21217. `${keyIndex}`,
  21218. false,
  21219. locStub,
  21220. 2
  21221. )
  21222. );
  21223. const { children } = branch;
  21224. const firstChild = children[0];
  21225. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  21226. if (needFragmentWrapper) {
  21227. if (children.length === 1 && firstChild.type === 11) {
  21228. const vnodeCall = firstChild.codegenNode;
  21229. injectProp(vnodeCall, keyProperty, context);
  21230. return vnodeCall;
  21231. } else {
  21232. let patchFlag = 64;
  21233. let patchFlagText = PatchFlagNames[64];
  21234. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  21235. patchFlag |= 2048;
  21236. patchFlagText += `, ${PatchFlagNames[2048]}`;
  21237. }
  21238. return createVNodeCall(
  21239. context,
  21240. helper(FRAGMENT),
  21241. createObjectExpression([keyProperty]),
  21242. children,
  21243. patchFlag + (` /* ${patchFlagText} */` ),
  21244. void 0,
  21245. void 0,
  21246. true,
  21247. false,
  21248. false,
  21249. branch.loc
  21250. );
  21251. }
  21252. } else {
  21253. const ret = firstChild.codegenNode;
  21254. const vnodeCall = getMemoedVNodeCall(ret);
  21255. if (vnodeCall.type === 13) {
  21256. convertToBlock(vnodeCall, context);
  21257. }
  21258. injectProp(vnodeCall, keyProperty, context);
  21259. return ret;
  21260. }
  21261. }
  21262. function isSameKey(a, b) {
  21263. if (!a || a.type !== b.type) {
  21264. return false;
  21265. }
  21266. if (a.type === 6) {
  21267. if (a.value.content !== b.value.content) {
  21268. return false;
  21269. }
  21270. } else {
  21271. const exp = a.exp;
  21272. const branchExp = b.exp;
  21273. if (exp.type !== branchExp.type) {
  21274. return false;
  21275. }
  21276. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  21277. return false;
  21278. }
  21279. }
  21280. return true;
  21281. }
  21282. function getParentCondition(node) {
  21283. while (true) {
  21284. if (node.type === 19) {
  21285. if (node.alternate.type === 19) {
  21286. node = node.alternate;
  21287. } else {
  21288. return node;
  21289. }
  21290. } else if (node.type === 20) {
  21291. node = node.value;
  21292. }
  21293. }
  21294. }
  21295. const transformFor = createStructuralDirectiveTransform(
  21296. "for",
  21297. (node, dir, context) => {
  21298. const { helper, removeHelper } = context;
  21299. return processFor(node, dir, context, (forNode) => {
  21300. const renderExp = createCallExpression(helper(RENDER_LIST), [
  21301. forNode.source
  21302. ]);
  21303. const isTemplate = isTemplateNode(node);
  21304. const memo = findDir(node, "memo");
  21305. const keyProp = findProp(node, `key`);
  21306. const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
  21307. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  21308. if (isTemplate) {
  21309. if (memo) {
  21310. memo.exp = processExpression(
  21311. memo.exp,
  21312. context
  21313. );
  21314. }
  21315. if (keyProperty && keyProp.type !== 6) {
  21316. keyProperty.value = processExpression(
  21317. keyProperty.value,
  21318. context
  21319. );
  21320. }
  21321. }
  21322. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  21323. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  21324. forNode.codegenNode = createVNodeCall(
  21325. context,
  21326. helper(FRAGMENT),
  21327. void 0,
  21328. renderExp,
  21329. fragmentFlag + (` /* ${PatchFlagNames[fragmentFlag]} */` ),
  21330. void 0,
  21331. void 0,
  21332. true,
  21333. !isStableFragment,
  21334. false,
  21335. node.loc
  21336. );
  21337. return () => {
  21338. let childBlock;
  21339. const { children } = forNode;
  21340. if (isTemplate) {
  21341. node.children.some((c) => {
  21342. if (c.type === 1) {
  21343. const key = findProp(c, "key");
  21344. if (key) {
  21345. context.onError(
  21346. createCompilerError(
  21347. 33,
  21348. key.loc
  21349. )
  21350. );
  21351. return true;
  21352. }
  21353. }
  21354. });
  21355. }
  21356. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  21357. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  21358. if (slotOutlet) {
  21359. childBlock = slotOutlet.codegenNode;
  21360. if (isTemplate && keyProperty) {
  21361. injectProp(childBlock, keyProperty, context);
  21362. }
  21363. } else if (needFragmentWrapper) {
  21364. childBlock = createVNodeCall(
  21365. context,
  21366. helper(FRAGMENT),
  21367. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  21368. node.children,
  21369. 64 + (` /* ${PatchFlagNames[64]} */` ),
  21370. void 0,
  21371. void 0,
  21372. true,
  21373. void 0,
  21374. false
  21375. /* isComponent */
  21376. );
  21377. } else {
  21378. childBlock = children[0].codegenNode;
  21379. if (isTemplate && keyProperty) {
  21380. injectProp(childBlock, keyProperty, context);
  21381. }
  21382. if (childBlock.isBlock !== !isStableFragment) {
  21383. if (childBlock.isBlock) {
  21384. removeHelper(OPEN_BLOCK);
  21385. removeHelper(
  21386. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  21387. );
  21388. } else {
  21389. removeHelper(
  21390. getVNodeHelper(context.inSSR, childBlock.isComponent)
  21391. );
  21392. }
  21393. }
  21394. childBlock.isBlock = !isStableFragment;
  21395. if (childBlock.isBlock) {
  21396. helper(OPEN_BLOCK);
  21397. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  21398. } else {
  21399. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  21400. }
  21401. }
  21402. if (memo) {
  21403. const loop = createFunctionExpression(
  21404. createForLoopParams(forNode.parseResult, [
  21405. createSimpleExpression(`_cached`)
  21406. ])
  21407. );
  21408. loop.body = createBlockStatement([
  21409. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  21410. createCompoundExpression([
  21411. `if (_cached`,
  21412. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  21413. ` && ${context.helperString(
  21414. IS_MEMO_SAME
  21415. )}(_cached, _memo)) return _cached`
  21416. ]),
  21417. createCompoundExpression([`const _item = `, childBlock]),
  21418. createSimpleExpression(`_item.memo = _memo`),
  21419. createSimpleExpression(`return _item`)
  21420. ]);
  21421. renderExp.arguments.push(
  21422. loop,
  21423. createSimpleExpression(`_cache`),
  21424. createSimpleExpression(String(context.cached++))
  21425. );
  21426. } else {
  21427. renderExp.arguments.push(
  21428. createFunctionExpression(
  21429. createForLoopParams(forNode.parseResult),
  21430. childBlock,
  21431. true
  21432. /* force newline */
  21433. )
  21434. );
  21435. }
  21436. };
  21437. });
  21438. }
  21439. );
  21440. function processFor(node, dir, context, processCodegen) {
  21441. if (!dir.exp) {
  21442. context.onError(
  21443. createCompilerError(31, dir.loc)
  21444. );
  21445. return;
  21446. }
  21447. const parseResult = parseForExpression(
  21448. // can only be simple expression because vFor transform is applied
  21449. // before expression transform.
  21450. dir.exp,
  21451. context
  21452. );
  21453. if (!parseResult) {
  21454. context.onError(
  21455. createCompilerError(32, dir.loc)
  21456. );
  21457. return;
  21458. }
  21459. const { addIdentifiers, removeIdentifiers, scopes } = context;
  21460. const { source, value, key, index } = parseResult;
  21461. const forNode = {
  21462. type: 11,
  21463. loc: dir.loc,
  21464. source,
  21465. valueAlias: value,
  21466. keyAlias: key,
  21467. objectIndexAlias: index,
  21468. parseResult,
  21469. children: isTemplateNode(node) ? node.children : [node]
  21470. };
  21471. context.replaceNode(forNode);
  21472. scopes.vFor++;
  21473. if (context.prefixIdentifiers) {
  21474. value && addIdentifiers(value);
  21475. key && addIdentifiers(key);
  21476. index && addIdentifiers(index);
  21477. }
  21478. const onExit = processCodegen && processCodegen(forNode);
  21479. return () => {
  21480. scopes.vFor--;
  21481. if (context.prefixIdentifiers) {
  21482. value && removeIdentifiers(value);
  21483. key && removeIdentifiers(key);
  21484. index && removeIdentifiers(index);
  21485. }
  21486. if (onExit)
  21487. onExit();
  21488. };
  21489. }
  21490. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  21491. const stripParensRE = /^\(|\)$/g;
  21492. function parseForExpression(input, context) {
  21493. const loc = input.loc;
  21494. const exp = input.content;
  21495. const inMatch = exp.match(forAliasRE);
  21496. if (!inMatch)
  21497. return;
  21498. const [, LHS, RHS] = inMatch;
  21499. const result = {
  21500. source: createAliasExpression(
  21501. loc,
  21502. RHS.trim(),
  21503. exp.indexOf(RHS, LHS.length)
  21504. ),
  21505. value: void 0,
  21506. key: void 0,
  21507. index: void 0
  21508. };
  21509. if (context.prefixIdentifiers) {
  21510. result.source = processExpression(
  21511. result.source,
  21512. context
  21513. );
  21514. }
  21515. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  21516. const trimmedOffset = LHS.indexOf(valueContent);
  21517. const iteratorMatch = valueContent.match(forIteratorRE);
  21518. if (iteratorMatch) {
  21519. valueContent = valueContent.replace(forIteratorRE, "").trim();
  21520. const keyContent = iteratorMatch[1].trim();
  21521. let keyOffset;
  21522. if (keyContent) {
  21523. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  21524. result.key = createAliasExpression(loc, keyContent, keyOffset);
  21525. if (context.prefixIdentifiers) {
  21526. result.key = processExpression(result.key, context, true);
  21527. }
  21528. }
  21529. if (iteratorMatch[2]) {
  21530. const indexContent = iteratorMatch[2].trim();
  21531. if (indexContent) {
  21532. result.index = createAliasExpression(
  21533. loc,
  21534. indexContent,
  21535. exp.indexOf(
  21536. indexContent,
  21537. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  21538. )
  21539. );
  21540. if (context.prefixIdentifiers) {
  21541. result.index = processExpression(result.index, context, true);
  21542. }
  21543. }
  21544. }
  21545. }
  21546. if (valueContent) {
  21547. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  21548. if (context.prefixIdentifiers) {
  21549. result.value = processExpression(result.value, context, true);
  21550. }
  21551. }
  21552. return result;
  21553. }
  21554. function createAliasExpression(range, content, offset) {
  21555. return createSimpleExpression(
  21556. content,
  21557. false,
  21558. getInnerRange(range, offset, content.length)
  21559. );
  21560. }
  21561. function createForLoopParams({ value, key, index }, memoArgs = []) {
  21562. return createParamsList([value, key, index, ...memoArgs]);
  21563. }
  21564. function createParamsList(args) {
  21565. let i = args.length;
  21566. while (i--) {
  21567. if (args[i])
  21568. break;
  21569. }
  21570. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  21571. }
  21572. const defaultFallback = createSimpleExpression(`undefined`, false);
  21573. const trackSlotScopes = (node, context) => {
  21574. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  21575. const vSlot = findDir(node, "slot");
  21576. if (vSlot) {
  21577. const slotProps = vSlot.exp;
  21578. if (context.prefixIdentifiers) {
  21579. slotProps && context.addIdentifiers(slotProps);
  21580. }
  21581. context.scopes.vSlot++;
  21582. return () => {
  21583. if (context.prefixIdentifiers) {
  21584. slotProps && context.removeIdentifiers(slotProps);
  21585. }
  21586. context.scopes.vSlot--;
  21587. };
  21588. }
  21589. }
  21590. };
  21591. const trackVForSlotScopes = (node, context) => {
  21592. let vFor;
  21593. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  21594. const result = vFor.parseResult = parseForExpression(
  21595. vFor.exp,
  21596. context
  21597. );
  21598. if (result) {
  21599. const { value, key, index } = result;
  21600. const { addIdentifiers, removeIdentifiers } = context;
  21601. value && addIdentifiers(value);
  21602. key && addIdentifiers(key);
  21603. index && addIdentifiers(index);
  21604. return () => {
  21605. value && removeIdentifiers(value);
  21606. key && removeIdentifiers(key);
  21607. index && removeIdentifiers(index);
  21608. };
  21609. }
  21610. }
  21611. };
  21612. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  21613. props,
  21614. children,
  21615. false,
  21616. true,
  21617. children.length ? children[0].loc : loc
  21618. );
  21619. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  21620. context.helper(WITH_CTX);
  21621. const { children, loc } = node;
  21622. const slotsProperties = [];
  21623. const dynamicSlots = [];
  21624. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  21625. if (!context.ssr && context.prefixIdentifiers) {
  21626. hasDynamicSlots = hasScopeRef(node, context.identifiers);
  21627. }
  21628. const onComponentSlot = findDir(node, "slot", true);
  21629. if (onComponentSlot) {
  21630. const { arg, exp } = onComponentSlot;
  21631. if (arg && !isStaticExp(arg)) {
  21632. hasDynamicSlots = true;
  21633. }
  21634. slotsProperties.push(
  21635. createObjectProperty(
  21636. arg || createSimpleExpression("default", true),
  21637. buildSlotFn(exp, void 0, children, loc)
  21638. )
  21639. );
  21640. }
  21641. let hasTemplateSlots = false;
  21642. let hasNamedDefaultSlot = false;
  21643. const implicitDefaultChildren = [];
  21644. const seenSlotNames = /* @__PURE__ */ new Set();
  21645. let conditionalBranchIndex = 0;
  21646. for (let i = 0; i < children.length; i++) {
  21647. const slotElement = children[i];
  21648. let slotDir;
  21649. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  21650. if (slotElement.type !== 3) {
  21651. implicitDefaultChildren.push(slotElement);
  21652. }
  21653. continue;
  21654. }
  21655. if (onComponentSlot) {
  21656. context.onError(
  21657. createCompilerError(37, slotDir.loc)
  21658. );
  21659. break;
  21660. }
  21661. hasTemplateSlots = true;
  21662. const { children: slotChildren, loc: slotLoc } = slotElement;
  21663. const {
  21664. arg: slotName = createSimpleExpression(`default`, true),
  21665. exp: slotProps,
  21666. loc: dirLoc
  21667. } = slotDir;
  21668. let staticSlotName;
  21669. if (isStaticExp(slotName)) {
  21670. staticSlotName = slotName ? slotName.content : `default`;
  21671. } else {
  21672. hasDynamicSlots = true;
  21673. }
  21674. const vFor = findDir(slotElement, "for");
  21675. const slotFunction = buildSlotFn(
  21676. slotProps,
  21677. vFor == null ? void 0 : vFor.exp,
  21678. slotChildren,
  21679. slotLoc
  21680. );
  21681. let vIf;
  21682. let vElse;
  21683. if (vIf = findDir(slotElement, "if")) {
  21684. hasDynamicSlots = true;
  21685. dynamicSlots.push(
  21686. createConditionalExpression(
  21687. vIf.exp,
  21688. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  21689. defaultFallback
  21690. )
  21691. );
  21692. } else if (vElse = findDir(
  21693. slotElement,
  21694. /^else(-if)?$/,
  21695. true
  21696. /* allowEmpty */
  21697. )) {
  21698. let j = i;
  21699. let prev;
  21700. while (j--) {
  21701. prev = children[j];
  21702. if (prev.type !== 3) {
  21703. break;
  21704. }
  21705. }
  21706. if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
  21707. children.splice(i, 1);
  21708. i--;
  21709. let conditional = dynamicSlots[dynamicSlots.length - 1];
  21710. while (conditional.alternate.type === 19) {
  21711. conditional = conditional.alternate;
  21712. }
  21713. conditional.alternate = vElse.exp ? createConditionalExpression(
  21714. vElse.exp,
  21715. buildDynamicSlot(
  21716. slotName,
  21717. slotFunction,
  21718. conditionalBranchIndex++
  21719. ),
  21720. defaultFallback
  21721. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  21722. } else {
  21723. context.onError(
  21724. createCompilerError(30, vElse.loc)
  21725. );
  21726. }
  21727. } else if (vFor) {
  21728. hasDynamicSlots = true;
  21729. const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
  21730. if (parseResult) {
  21731. dynamicSlots.push(
  21732. createCallExpression(context.helper(RENDER_LIST), [
  21733. parseResult.source,
  21734. createFunctionExpression(
  21735. createForLoopParams(parseResult),
  21736. buildDynamicSlot(slotName, slotFunction),
  21737. true
  21738. /* force newline */
  21739. )
  21740. ])
  21741. );
  21742. } else {
  21743. context.onError(
  21744. createCompilerError(32, vFor.loc)
  21745. );
  21746. }
  21747. } else {
  21748. if (staticSlotName) {
  21749. if (seenSlotNames.has(staticSlotName)) {
  21750. context.onError(
  21751. createCompilerError(
  21752. 38,
  21753. dirLoc
  21754. )
  21755. );
  21756. continue;
  21757. }
  21758. seenSlotNames.add(staticSlotName);
  21759. if (staticSlotName === "default") {
  21760. hasNamedDefaultSlot = true;
  21761. }
  21762. }
  21763. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  21764. }
  21765. }
  21766. if (!onComponentSlot) {
  21767. const buildDefaultSlotProperty = (props, children2) => {
  21768. const fn = buildSlotFn(props, void 0, children2, loc);
  21769. return createObjectProperty(`default`, fn);
  21770. };
  21771. if (!hasTemplateSlots) {
  21772. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  21773. } else if (implicitDefaultChildren.length && // #3766
  21774. // with whitespace: 'preserve', whitespaces between slots will end up in
  21775. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  21776. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  21777. if (hasNamedDefaultSlot) {
  21778. context.onError(
  21779. createCompilerError(
  21780. 39,
  21781. implicitDefaultChildren[0].loc
  21782. )
  21783. );
  21784. } else {
  21785. slotsProperties.push(
  21786. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  21787. );
  21788. }
  21789. }
  21790. }
  21791. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  21792. let slots = createObjectExpression(
  21793. slotsProperties.concat(
  21794. createObjectProperty(
  21795. `_`,
  21796. // 2 = compiled but dynamic = can skip normalization, but must run diff
  21797. // 1 = compiled and static = can skip normalization AND diff as optimized
  21798. createSimpleExpression(
  21799. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  21800. false
  21801. )
  21802. )
  21803. ),
  21804. loc
  21805. );
  21806. if (dynamicSlots.length) {
  21807. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  21808. slots,
  21809. createArrayExpression(dynamicSlots)
  21810. ]);
  21811. }
  21812. return {
  21813. slots,
  21814. hasDynamicSlots
  21815. };
  21816. }
  21817. function buildDynamicSlot(name, fn, index) {
  21818. const props = [
  21819. createObjectProperty(`name`, name),
  21820. createObjectProperty(`fn`, fn)
  21821. ];
  21822. if (index != null) {
  21823. props.push(
  21824. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  21825. );
  21826. }
  21827. return createObjectExpression(props);
  21828. }
  21829. function hasForwardedSlots(children) {
  21830. for (let i = 0; i < children.length; i++) {
  21831. const child = children[i];
  21832. switch (child.type) {
  21833. case 1:
  21834. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  21835. return true;
  21836. }
  21837. break;
  21838. case 9:
  21839. if (hasForwardedSlots(child.branches))
  21840. return true;
  21841. break;
  21842. case 10:
  21843. case 11:
  21844. if (hasForwardedSlots(child.children))
  21845. return true;
  21846. break;
  21847. }
  21848. }
  21849. return false;
  21850. }
  21851. function isNonWhitespaceContent(node) {
  21852. if (node.type !== 2 && node.type !== 12)
  21853. return true;
  21854. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  21855. }
  21856. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  21857. const transformElement = (node, context) => {
  21858. return function postTransformElement() {
  21859. node = context.currentNode;
  21860. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  21861. return;
  21862. }
  21863. const { tag, props } = node;
  21864. const isComponent = node.tagType === 1;
  21865. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  21866. const isDynamicComponent = isObject$2(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  21867. let vnodeProps;
  21868. let vnodeChildren;
  21869. let vnodePatchFlag;
  21870. let patchFlag = 0;
  21871. let vnodeDynamicProps;
  21872. let dynamicPropNames;
  21873. let vnodeDirectives;
  21874. let shouldUseBlock = (
  21875. // dynamic component may resolve to plain elements
  21876. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  21877. // updates inside get proper isSVG flag at runtime. (#639, #643)
  21878. // This is technically web-specific, but splitting the logic out of core
  21879. // leads to too much unnecessary complexity.
  21880. (tag === "svg" || tag === "foreignObject")
  21881. );
  21882. if (props.length > 0) {
  21883. const propsBuildResult = buildProps(
  21884. node,
  21885. context,
  21886. void 0,
  21887. isComponent,
  21888. isDynamicComponent
  21889. );
  21890. vnodeProps = propsBuildResult.props;
  21891. patchFlag = propsBuildResult.patchFlag;
  21892. dynamicPropNames = propsBuildResult.dynamicPropNames;
  21893. const directives = propsBuildResult.directives;
  21894. vnodeDirectives = directives && directives.length ? createArrayExpression(
  21895. directives.map((dir) => buildDirectiveArgs(dir, context))
  21896. ) : void 0;
  21897. if (propsBuildResult.shouldUseBlock) {
  21898. shouldUseBlock = true;
  21899. }
  21900. }
  21901. if (node.children.length > 0) {
  21902. if (vnodeTag === KEEP_ALIVE) {
  21903. shouldUseBlock = true;
  21904. patchFlag |= 1024;
  21905. if (node.children.length > 1) {
  21906. context.onError(
  21907. createCompilerError(46, {
  21908. start: node.children[0].loc.start,
  21909. end: node.children[node.children.length - 1].loc.end,
  21910. source: ""
  21911. })
  21912. );
  21913. }
  21914. }
  21915. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  21916. vnodeTag !== TELEPORT && // explained above.
  21917. vnodeTag !== KEEP_ALIVE;
  21918. if (shouldBuildAsSlots) {
  21919. const { slots, hasDynamicSlots } = buildSlots(node, context);
  21920. vnodeChildren = slots;
  21921. if (hasDynamicSlots) {
  21922. patchFlag |= 1024;
  21923. }
  21924. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  21925. const child = node.children[0];
  21926. const type = child.type;
  21927. const hasDynamicTextChild = type === 5 || type === 8;
  21928. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  21929. patchFlag |= 1;
  21930. }
  21931. if (hasDynamicTextChild || type === 2) {
  21932. vnodeChildren = child;
  21933. } else {
  21934. vnodeChildren = node.children;
  21935. }
  21936. } else {
  21937. vnodeChildren = node.children;
  21938. }
  21939. }
  21940. if (patchFlag !== 0) {
  21941. {
  21942. if (patchFlag < 0) {
  21943. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  21944. } else {
  21945. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  21946. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  21947. }
  21948. }
  21949. if (dynamicPropNames && dynamicPropNames.length) {
  21950. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  21951. }
  21952. }
  21953. node.codegenNode = createVNodeCall(
  21954. context,
  21955. vnodeTag,
  21956. vnodeProps,
  21957. vnodeChildren,
  21958. vnodePatchFlag,
  21959. vnodeDynamicProps,
  21960. vnodeDirectives,
  21961. !!shouldUseBlock,
  21962. false,
  21963. isComponent,
  21964. node.loc
  21965. );
  21966. };
  21967. };
  21968. function resolveComponentType(node, context, ssr = false) {
  21969. let { tag } = node;
  21970. const isExplicitDynamic = isComponentTag(tag);
  21971. const isProp = findProp(node, "is");
  21972. if (isProp) {
  21973. if (isExplicitDynamic || false) {
  21974. const exp = isProp.type === 6 ? isProp.value && createSimpleExpression(isProp.value.content, true) : isProp.exp;
  21975. if (exp) {
  21976. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  21977. exp
  21978. ]);
  21979. }
  21980. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  21981. tag = isProp.value.content.slice(4);
  21982. }
  21983. }
  21984. const isDir = !isExplicitDynamic && findDir(node, "is");
  21985. if (isDir && isDir.exp) {
  21986. {
  21987. context.onWarn(
  21988. createCompilerError(52, isDir.loc)
  21989. );
  21990. }
  21991. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  21992. isDir.exp
  21993. ]);
  21994. }
  21995. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  21996. if (builtIn) {
  21997. if (!ssr)
  21998. context.helper(builtIn);
  21999. return builtIn;
  22000. }
  22001. {
  22002. const fromSetup = resolveSetupReference(tag, context);
  22003. if (fromSetup) {
  22004. return fromSetup;
  22005. }
  22006. const dotIndex = tag.indexOf(".");
  22007. if (dotIndex > 0) {
  22008. const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
  22009. if (ns) {
  22010. return ns + tag.slice(dotIndex);
  22011. }
  22012. }
  22013. }
  22014. if (context.selfName && capitalize$1(camelize(tag)) === context.selfName) {
  22015. context.helper(RESOLVE_COMPONENT);
  22016. context.components.add(tag + `__self`);
  22017. return toValidAssetId(tag, `component`);
  22018. }
  22019. context.helper(RESOLVE_COMPONENT);
  22020. context.components.add(tag);
  22021. return toValidAssetId(tag, `component`);
  22022. }
  22023. function resolveSetupReference(name, context) {
  22024. const bindings = context.bindingMetadata;
  22025. if (!bindings || bindings.__isScriptSetup === false) {
  22026. return;
  22027. }
  22028. const camelName = camelize(name);
  22029. const PascalName = capitalize$1(camelName);
  22030. const checkType = (type) => {
  22031. if (bindings[name] === type) {
  22032. return name;
  22033. }
  22034. if (bindings[camelName] === type) {
  22035. return camelName;
  22036. }
  22037. if (bindings[PascalName] === type) {
  22038. return PascalName;
  22039. }
  22040. };
  22041. const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
  22042. if (fromConst) {
  22043. return context.inline ? (
  22044. // in inline mode, const setup bindings (e.g. imports) can be used as-is
  22045. fromConst
  22046. ) : `$setup[${JSON.stringify(fromConst)}]`;
  22047. }
  22048. const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
  22049. if (fromMaybeRef) {
  22050. return context.inline ? (
  22051. // setup scope bindings that may be refs need to be unrefed
  22052. `${context.helperString(UNREF)}(${fromMaybeRef})`
  22053. ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
  22054. }
  22055. const fromProps = checkType("props");
  22056. if (fromProps) {
  22057. return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
  22058. }
  22059. }
  22060. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  22061. const { tag, loc: elementLoc, children } = node;
  22062. let properties = [];
  22063. const mergeArgs = [];
  22064. const runtimeDirectives = [];
  22065. const hasChildren = children.length > 0;
  22066. let shouldUseBlock = false;
  22067. let patchFlag = 0;
  22068. let hasRef = false;
  22069. let hasClassBinding = false;
  22070. let hasStyleBinding = false;
  22071. let hasHydrationEventBinding = false;
  22072. let hasDynamicKeys = false;
  22073. let hasVnodeHook = false;
  22074. const dynamicPropNames = [];
  22075. const pushMergeArg = (arg) => {
  22076. if (properties.length) {
  22077. mergeArgs.push(
  22078. createObjectExpression(dedupeProperties(properties), elementLoc)
  22079. );
  22080. properties = [];
  22081. }
  22082. if (arg)
  22083. mergeArgs.push(arg);
  22084. };
  22085. const analyzePatchFlag = ({ key, value }) => {
  22086. if (isStaticExp(key)) {
  22087. const name = key.content;
  22088. const isEventHandler = isOn(name);
  22089. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  22090. // dedicated fast path.
  22091. name.toLowerCase() !== "onclick" && // omit v-model handlers
  22092. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  22093. !isReservedProp(name)) {
  22094. hasHydrationEventBinding = true;
  22095. }
  22096. if (isEventHandler && isReservedProp(name)) {
  22097. hasVnodeHook = true;
  22098. }
  22099. if (isEventHandler && value.type === 14) {
  22100. value = value.arguments[0];
  22101. }
  22102. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  22103. return;
  22104. }
  22105. if (name === "ref") {
  22106. hasRef = true;
  22107. } else if (name === "class") {
  22108. hasClassBinding = true;
  22109. } else if (name === "style") {
  22110. hasStyleBinding = true;
  22111. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  22112. dynamicPropNames.push(name);
  22113. }
  22114. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  22115. dynamicPropNames.push(name);
  22116. }
  22117. } else {
  22118. hasDynamicKeys = true;
  22119. }
  22120. };
  22121. for (let i = 0; i < props.length; i++) {
  22122. const prop = props[i];
  22123. if (prop.type === 6) {
  22124. const { loc, name, value } = prop;
  22125. let isStatic = true;
  22126. if (name === "ref") {
  22127. hasRef = true;
  22128. if (context.scopes.vFor > 0) {
  22129. properties.push(
  22130. createObjectProperty(
  22131. createSimpleExpression("ref_for", true),
  22132. createSimpleExpression("true")
  22133. )
  22134. );
  22135. }
  22136. if (value && context.inline) {
  22137. const binding = context.bindingMetadata[value.content];
  22138. if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
  22139. isStatic = false;
  22140. properties.push(
  22141. createObjectProperty(
  22142. createSimpleExpression("ref_key", true),
  22143. createSimpleExpression(value.content, true, value.loc)
  22144. )
  22145. );
  22146. }
  22147. }
  22148. }
  22149. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || false)) {
  22150. continue;
  22151. }
  22152. properties.push(
  22153. createObjectProperty(
  22154. createSimpleExpression(
  22155. name,
  22156. true,
  22157. getInnerRange(loc, 0, name.length)
  22158. ),
  22159. createSimpleExpression(
  22160. value ? value.content : "",
  22161. isStatic,
  22162. value ? value.loc : loc
  22163. )
  22164. )
  22165. );
  22166. } else {
  22167. const { name, arg, exp, loc, modifiers } = prop;
  22168. const isVBind = name === "bind";
  22169. const isVOn = name === "on";
  22170. if (name === "slot") {
  22171. if (!isComponent) {
  22172. context.onError(
  22173. createCompilerError(40, loc)
  22174. );
  22175. }
  22176. continue;
  22177. }
  22178. if (name === "once" || name === "memo") {
  22179. continue;
  22180. }
  22181. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || false)) {
  22182. continue;
  22183. }
  22184. if (isVOn && ssr) {
  22185. continue;
  22186. }
  22187. if (
  22188. // #938: elements with dynamic keys should be forced into blocks
  22189. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  22190. // before children
  22191. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  22192. ) {
  22193. shouldUseBlock = true;
  22194. }
  22195. if (isVBind && isStaticArgOf(arg, "ref") && context.scopes.vFor > 0) {
  22196. properties.push(
  22197. createObjectProperty(
  22198. createSimpleExpression("ref_for", true),
  22199. createSimpleExpression("true")
  22200. )
  22201. );
  22202. }
  22203. if (!arg && (isVBind || isVOn)) {
  22204. hasDynamicKeys = true;
  22205. if (exp) {
  22206. if (isVBind) {
  22207. pushMergeArg();
  22208. mergeArgs.push(exp);
  22209. } else {
  22210. pushMergeArg({
  22211. type: 14,
  22212. loc,
  22213. callee: context.helper(TO_HANDLERS),
  22214. arguments: isComponent ? [exp] : [exp, `true`]
  22215. });
  22216. }
  22217. } else {
  22218. context.onError(
  22219. createCompilerError(
  22220. isVBind ? 34 : 35,
  22221. loc
  22222. )
  22223. );
  22224. }
  22225. continue;
  22226. }
  22227. if (isVBind && modifiers.includes("prop")) {
  22228. patchFlag |= 32;
  22229. }
  22230. const directiveTransform = context.directiveTransforms[name];
  22231. if (directiveTransform) {
  22232. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  22233. !ssr && props2.forEach(analyzePatchFlag);
  22234. if (isVOn && arg && !isStaticExp(arg)) {
  22235. pushMergeArg(createObjectExpression(props2, elementLoc));
  22236. } else {
  22237. properties.push(...props2);
  22238. }
  22239. if (needRuntime) {
  22240. runtimeDirectives.push(prop);
  22241. if (isSymbol$1(needRuntime)) {
  22242. directiveImportMap.set(prop, needRuntime);
  22243. }
  22244. }
  22245. } else if (!isBuiltInDirective(name)) {
  22246. runtimeDirectives.push(prop);
  22247. if (hasChildren) {
  22248. shouldUseBlock = true;
  22249. }
  22250. }
  22251. }
  22252. }
  22253. let propsExpression = void 0;
  22254. if (mergeArgs.length) {
  22255. pushMergeArg();
  22256. if (mergeArgs.length > 1) {
  22257. propsExpression = createCallExpression(
  22258. context.helper(MERGE_PROPS),
  22259. mergeArgs,
  22260. elementLoc
  22261. );
  22262. } else {
  22263. propsExpression = mergeArgs[0];
  22264. }
  22265. } else if (properties.length) {
  22266. propsExpression = createObjectExpression(
  22267. dedupeProperties(properties),
  22268. elementLoc
  22269. );
  22270. }
  22271. if (hasDynamicKeys) {
  22272. patchFlag |= 16;
  22273. } else {
  22274. if (hasClassBinding && !isComponent) {
  22275. patchFlag |= 2;
  22276. }
  22277. if (hasStyleBinding && !isComponent) {
  22278. patchFlag |= 4;
  22279. }
  22280. if (dynamicPropNames.length) {
  22281. patchFlag |= 8;
  22282. }
  22283. if (hasHydrationEventBinding) {
  22284. patchFlag |= 32;
  22285. }
  22286. }
  22287. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  22288. patchFlag |= 512;
  22289. }
  22290. if (!context.inSSR && propsExpression) {
  22291. switch (propsExpression.type) {
  22292. case 15:
  22293. let classKeyIndex = -1;
  22294. let styleKeyIndex = -1;
  22295. let hasDynamicKey = false;
  22296. for (let i = 0; i < propsExpression.properties.length; i++) {
  22297. const key = propsExpression.properties[i].key;
  22298. if (isStaticExp(key)) {
  22299. if (key.content === "class") {
  22300. classKeyIndex = i;
  22301. } else if (key.content === "style") {
  22302. styleKeyIndex = i;
  22303. }
  22304. } else if (!key.isHandlerKey) {
  22305. hasDynamicKey = true;
  22306. }
  22307. }
  22308. const classProp = propsExpression.properties[classKeyIndex];
  22309. const styleProp = propsExpression.properties[styleKeyIndex];
  22310. if (!hasDynamicKey) {
  22311. if (classProp && !isStaticExp(classProp.value)) {
  22312. classProp.value = createCallExpression(
  22313. context.helper(NORMALIZE_CLASS),
  22314. [classProp.value]
  22315. );
  22316. }
  22317. if (styleProp && // the static style is compiled into an object,
  22318. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  22319. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  22320. // v-bind:style with static literal object
  22321. styleProp.value.type === 17)) {
  22322. styleProp.value = createCallExpression(
  22323. context.helper(NORMALIZE_STYLE),
  22324. [styleProp.value]
  22325. );
  22326. }
  22327. } else {
  22328. propsExpression = createCallExpression(
  22329. context.helper(NORMALIZE_PROPS),
  22330. [propsExpression]
  22331. );
  22332. }
  22333. break;
  22334. case 14:
  22335. break;
  22336. default:
  22337. propsExpression = createCallExpression(
  22338. context.helper(NORMALIZE_PROPS),
  22339. [
  22340. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  22341. propsExpression
  22342. ])
  22343. ]
  22344. );
  22345. break;
  22346. }
  22347. }
  22348. return {
  22349. props: propsExpression,
  22350. directives: runtimeDirectives,
  22351. patchFlag,
  22352. dynamicPropNames,
  22353. shouldUseBlock
  22354. };
  22355. }
  22356. function dedupeProperties(properties) {
  22357. const knownProps = /* @__PURE__ */ new Map();
  22358. const deduped = [];
  22359. for (let i = 0; i < properties.length; i++) {
  22360. const prop = properties[i];
  22361. if (prop.key.type === 8 || !prop.key.isStatic) {
  22362. deduped.push(prop);
  22363. continue;
  22364. }
  22365. const name = prop.key.content;
  22366. const existing = knownProps.get(name);
  22367. if (existing) {
  22368. if (name === "style" || name === "class" || isOn(name)) {
  22369. mergeAsArray(existing, prop);
  22370. }
  22371. } else {
  22372. knownProps.set(name, prop);
  22373. deduped.push(prop);
  22374. }
  22375. }
  22376. return deduped;
  22377. }
  22378. function mergeAsArray(existing, incoming) {
  22379. if (existing.value.type === 17) {
  22380. existing.value.elements.push(incoming.value);
  22381. } else {
  22382. existing.value = createArrayExpression(
  22383. [existing.value, incoming.value],
  22384. existing.loc
  22385. );
  22386. }
  22387. }
  22388. function buildDirectiveArgs(dir, context) {
  22389. const dirArgs = [];
  22390. const runtime = directiveImportMap.get(dir);
  22391. if (runtime) {
  22392. dirArgs.push(context.helperString(runtime));
  22393. } else {
  22394. const fromSetup = resolveSetupReference("v-" + dir.name, context);
  22395. if (fromSetup) {
  22396. dirArgs.push(fromSetup);
  22397. } else {
  22398. context.helper(RESOLVE_DIRECTIVE);
  22399. context.directives.add(dir.name);
  22400. dirArgs.push(toValidAssetId(dir.name, `directive`));
  22401. }
  22402. }
  22403. const { loc } = dir;
  22404. if (dir.exp)
  22405. dirArgs.push(dir.exp);
  22406. if (dir.arg) {
  22407. if (!dir.exp) {
  22408. dirArgs.push(`void 0`);
  22409. }
  22410. dirArgs.push(dir.arg);
  22411. }
  22412. if (Object.keys(dir.modifiers).length) {
  22413. if (!dir.arg) {
  22414. if (!dir.exp) {
  22415. dirArgs.push(`void 0`);
  22416. }
  22417. dirArgs.push(`void 0`);
  22418. }
  22419. const trueExpression = createSimpleExpression(`true`, false, loc);
  22420. dirArgs.push(
  22421. createObjectExpression(
  22422. dir.modifiers.map(
  22423. (modifier) => createObjectProperty(modifier, trueExpression)
  22424. ),
  22425. loc
  22426. )
  22427. );
  22428. }
  22429. return createArrayExpression(dirArgs, dir.loc);
  22430. }
  22431. function stringifyDynamicPropNames(props) {
  22432. let propsNamesString = `[`;
  22433. for (let i = 0, l = props.length; i < l; i++) {
  22434. propsNamesString += JSON.stringify(props[i]);
  22435. if (i < l - 1)
  22436. propsNamesString += ", ";
  22437. }
  22438. return propsNamesString + `]`;
  22439. }
  22440. function isComponentTag(tag) {
  22441. return tag === "component" || tag === "Component";
  22442. }
  22443. const transformSlotOutlet = (node, context) => {
  22444. if (isSlotOutlet(node)) {
  22445. const { children, loc } = node;
  22446. const { slotName, slotProps } = processSlotOutlet(node, context);
  22447. const slotArgs = [
  22448. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  22449. slotName,
  22450. "{}",
  22451. "undefined",
  22452. "true"
  22453. ];
  22454. let expectedLen = 2;
  22455. if (slotProps) {
  22456. slotArgs[2] = slotProps;
  22457. expectedLen = 3;
  22458. }
  22459. if (children.length) {
  22460. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  22461. expectedLen = 4;
  22462. }
  22463. if (context.scopeId && !context.slotted) {
  22464. expectedLen = 5;
  22465. }
  22466. slotArgs.splice(expectedLen);
  22467. node.codegenNode = createCallExpression(
  22468. context.helper(RENDER_SLOT),
  22469. slotArgs,
  22470. loc
  22471. );
  22472. }
  22473. };
  22474. function processSlotOutlet(node, context) {
  22475. let slotName = `"default"`;
  22476. let slotProps = void 0;
  22477. const nonNameProps = [];
  22478. for (let i = 0; i < node.props.length; i++) {
  22479. const p = node.props[i];
  22480. if (p.type === 6) {
  22481. if (p.value) {
  22482. if (p.name === "name") {
  22483. slotName = JSON.stringify(p.value.content);
  22484. } else {
  22485. p.name = camelize(p.name);
  22486. nonNameProps.push(p);
  22487. }
  22488. }
  22489. } else {
  22490. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  22491. if (p.exp)
  22492. slotName = p.exp;
  22493. } else {
  22494. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  22495. p.arg.content = camelize(p.arg.content);
  22496. }
  22497. nonNameProps.push(p);
  22498. }
  22499. }
  22500. }
  22501. if (nonNameProps.length > 0) {
  22502. const { props, directives } = buildProps(
  22503. node,
  22504. context,
  22505. nonNameProps,
  22506. false,
  22507. false
  22508. );
  22509. slotProps = props;
  22510. if (directives.length) {
  22511. context.onError(
  22512. createCompilerError(
  22513. 36,
  22514. directives[0].loc
  22515. )
  22516. );
  22517. }
  22518. }
  22519. return {
  22520. slotName,
  22521. slotProps
  22522. };
  22523. }
  22524. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  22525. const transformOn$1 = (dir, node, context, augmentor) => {
  22526. const { loc, modifiers, arg } = dir;
  22527. if (!dir.exp && !modifiers.length) {
  22528. context.onError(createCompilerError(35, loc));
  22529. }
  22530. let eventName;
  22531. if (arg.type === 4) {
  22532. if (arg.isStatic) {
  22533. let rawName = arg.content;
  22534. if (rawName.startsWith("vnode")) {
  22535. context.onWarn(
  22536. createCompilerError(51, arg.loc)
  22537. );
  22538. }
  22539. if (rawName.startsWith("vue:")) {
  22540. rawName = `vnode-${rawName.slice(4)}`;
  22541. }
  22542. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  22543. // for non-element and vnode lifecycle event listeners, auto convert
  22544. // it to camelCase. See issue #2249
  22545. toHandlerKey(camelize(rawName))
  22546. ) : (
  22547. // preserve case for plain element listeners that have uppercase
  22548. // letters, as these may be custom elements' custom events
  22549. `on:${rawName}`
  22550. );
  22551. eventName = createSimpleExpression(eventString, true, arg.loc);
  22552. } else {
  22553. eventName = createCompoundExpression([
  22554. `${context.helperString(TO_HANDLER_KEY)}(`,
  22555. arg,
  22556. `)`
  22557. ]);
  22558. }
  22559. } else {
  22560. eventName = arg;
  22561. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  22562. eventName.children.push(`)`);
  22563. }
  22564. let exp = dir.exp;
  22565. if (exp && !exp.content.trim()) {
  22566. exp = void 0;
  22567. }
  22568. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  22569. if (exp) {
  22570. const isMemberExp = isMemberExpression(exp.content, context);
  22571. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  22572. const hasMultipleStatements = exp.content.includes(`;`);
  22573. if (context.prefixIdentifiers) {
  22574. isInlineStatement && context.addIdentifiers(`$event`);
  22575. exp = dir.exp = processExpression(
  22576. exp,
  22577. context,
  22578. false,
  22579. hasMultipleStatements
  22580. );
  22581. isInlineStatement && context.removeIdentifiers(`$event`);
  22582. shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
  22583. !context.inVOnce && // runtime constants don't need to be cached
  22584. // (this is analyzed by compileScript in SFC <script setup>)
  22585. !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
  22586. // we need to use the original function to preserve arity,
  22587. // e.g. <transition> relies on checking cb.length to determine
  22588. // transition end handling. Inline function is ok since its arity
  22589. // is preserved even when cached.
  22590. !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
  22591. // it must be passed fresh to avoid stale values.
  22592. !hasScopeRef(exp, context.identifiers);
  22593. if (shouldCache && isMemberExp) {
  22594. if (exp.type === 4) {
  22595. exp.content = `${exp.content} && ${exp.content}(...args)`;
  22596. } else {
  22597. exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
  22598. }
  22599. }
  22600. }
  22601. if (isInlineStatement || shouldCache && isMemberExp) {
  22602. exp = createCompoundExpression([
  22603. `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
  22604. //@ts-ignore
  22605. ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  22606. exp,
  22607. hasMultipleStatements ? `}` : `)`
  22608. ]);
  22609. }
  22610. }
  22611. let ret = {
  22612. props: [
  22613. createObjectProperty(
  22614. eventName,
  22615. exp || createSimpleExpression(`() => {}`, false, loc)
  22616. )
  22617. ]
  22618. };
  22619. if (augmentor) {
  22620. ret = augmentor(ret);
  22621. }
  22622. if (shouldCache) {
  22623. ret.props[0].value = context.cache(ret.props[0].value);
  22624. }
  22625. ret.props.forEach((p) => p.key.isHandlerKey = true);
  22626. return ret;
  22627. };
  22628. const transformBind = (dir, _node, context) => {
  22629. const { exp, modifiers, loc } = dir;
  22630. const arg = dir.arg;
  22631. if (arg.type !== 4) {
  22632. arg.children.unshift(`(`);
  22633. arg.children.push(`) || ""`);
  22634. } else if (!arg.isStatic) {
  22635. arg.content = `${arg.content} || ""`;
  22636. }
  22637. if (modifiers.includes("camel")) {
  22638. if (arg.type === 4) {
  22639. if (arg.isStatic) {
  22640. arg.content = camelize(arg.content);
  22641. } else {
  22642. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  22643. }
  22644. } else {
  22645. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  22646. arg.children.push(`)`);
  22647. }
  22648. }
  22649. if (!context.inSSR) {
  22650. if (modifiers.includes("prop")) {
  22651. injectPrefix(arg, ".");
  22652. }
  22653. if (modifiers.includes("attr")) {
  22654. injectPrefix(arg, "^");
  22655. }
  22656. }
  22657. if (!exp || exp.type === 4 && !exp.content.trim()) {
  22658. context.onError(createCompilerError(34, loc));
  22659. return {
  22660. props: [createObjectProperty(arg, createSimpleExpression("", true, loc))]
  22661. };
  22662. }
  22663. return {
  22664. props: [createObjectProperty(arg, exp)]
  22665. };
  22666. };
  22667. const injectPrefix = (arg, prefix) => {
  22668. if (arg.type === 4) {
  22669. if (arg.isStatic) {
  22670. arg.content = prefix + arg.content;
  22671. } else {
  22672. arg.content = `\`${prefix}\${${arg.content}}\``;
  22673. }
  22674. } else {
  22675. arg.children.unshift(`'${prefix}' + (`);
  22676. arg.children.push(`)`);
  22677. }
  22678. };
  22679. const transformText = (node, context) => {
  22680. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  22681. return () => {
  22682. const children = node.children;
  22683. let currentContainer = void 0;
  22684. let hasText = false;
  22685. for (let i = 0; i < children.length; i++) {
  22686. const child = children[i];
  22687. if (isText$1(child)) {
  22688. hasText = true;
  22689. for (let j = i + 1; j < children.length; j++) {
  22690. const next = children[j];
  22691. if (isText$1(next)) {
  22692. if (!currentContainer) {
  22693. currentContainer = children[i] = createCompoundExpression(
  22694. [child],
  22695. child.loc
  22696. );
  22697. }
  22698. currentContainer.children.push(` + `, next);
  22699. children.splice(j, 1);
  22700. j--;
  22701. } else {
  22702. currentContainer = void 0;
  22703. break;
  22704. }
  22705. }
  22706. }
  22707. }
  22708. if (!hasText || // if this is a plain element with a single text child, leave it
  22709. // as-is since the runtime has dedicated fast path for this by directly
  22710. // setting textContent of the element.
  22711. // for component root it's always normalized anyway.
  22712. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  22713. // custom directives can potentially add DOM elements arbitrarily,
  22714. // we need to avoid setting textContent of the element at runtime
  22715. // to avoid accidentally overwriting the DOM elements added
  22716. // by the user through custom directives.
  22717. !node.props.find(
  22718. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  22719. ) && // in compat mode, <template> tags with no special directives
  22720. // will be rendered as a fragment so its children must be
  22721. // converted into vnodes.
  22722. true)) {
  22723. return;
  22724. }
  22725. for (let i = 0; i < children.length; i++) {
  22726. const child = children[i];
  22727. if (isText$1(child) || child.type === 8) {
  22728. const callArgs = [];
  22729. if (child.type !== 2 || child.content !== " ") {
  22730. callArgs.push(child);
  22731. }
  22732. if (!context.ssr && getConstantType(child, context) === 0) {
  22733. callArgs.push(
  22734. 1 + (` /* ${PatchFlagNames[1]} */` )
  22735. );
  22736. }
  22737. children[i] = {
  22738. type: 12,
  22739. content: child,
  22740. loc: child.loc,
  22741. codegenNode: createCallExpression(
  22742. context.helper(CREATE_TEXT),
  22743. callArgs
  22744. )
  22745. };
  22746. }
  22747. }
  22748. };
  22749. }
  22750. };
  22751. const seen$1 = /* @__PURE__ */ new WeakSet();
  22752. const transformOnce = (node, context) => {
  22753. if (node.type === 1 && findDir(node, "once", true)) {
  22754. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  22755. return;
  22756. }
  22757. seen$1.add(node);
  22758. context.inVOnce = true;
  22759. context.helper(SET_BLOCK_TRACKING);
  22760. return () => {
  22761. context.inVOnce = false;
  22762. const cur = context.currentNode;
  22763. if (cur.codegenNode) {
  22764. cur.codegenNode = context.cache(
  22765. cur.codegenNode,
  22766. true
  22767. /* isVNode */
  22768. );
  22769. }
  22770. };
  22771. }
  22772. };
  22773. const transformModel$1 = (dir, node, context) => {
  22774. const { exp, arg } = dir;
  22775. if (!exp) {
  22776. context.onError(
  22777. createCompilerError(41, dir.loc)
  22778. );
  22779. return createTransformProps();
  22780. }
  22781. const rawExp = exp.loc.source;
  22782. const expString = exp.type === 4 ? exp.content : rawExp;
  22783. const bindingType = context.bindingMetadata[rawExp];
  22784. if (bindingType === "props" || bindingType === "props-aliased") {
  22785. context.onError(createCompilerError(44, exp.loc));
  22786. return createTransformProps();
  22787. }
  22788. const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
  22789. if (!expString.trim() || !isMemberExpression(expString, context) && !maybeRef) {
  22790. context.onError(
  22791. createCompilerError(42, exp.loc)
  22792. );
  22793. return createTransformProps();
  22794. }
  22795. if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
  22796. context.onError(
  22797. createCompilerError(43, exp.loc)
  22798. );
  22799. return createTransformProps();
  22800. }
  22801. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  22802. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  22803. let assignmentExp;
  22804. const eventArg = context.isTS ? `($event: any)` : `$event`;
  22805. if (maybeRef) {
  22806. if (bindingType === "setup-ref") {
  22807. assignmentExp = createCompoundExpression([
  22808. `${eventArg} => ((`,
  22809. createSimpleExpression(rawExp, false, exp.loc),
  22810. `).value = $event)`
  22811. ]);
  22812. } else {
  22813. const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
  22814. assignmentExp = createCompoundExpression([
  22815. `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
  22816. createSimpleExpression(rawExp, false, exp.loc),
  22817. `).value = $event : ${altAssignment})`
  22818. ]);
  22819. }
  22820. } else {
  22821. assignmentExp = createCompoundExpression([
  22822. `${eventArg} => ((`,
  22823. exp,
  22824. `) = $event)`
  22825. ]);
  22826. }
  22827. const props = [
  22828. // modelValue: foo
  22829. createObjectProperty(propName, dir.exp),
  22830. // "onUpdate:modelValue": $event => (foo = $event)
  22831. createObjectProperty(eventName, assignmentExp)
  22832. ];
  22833. if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
  22834. props[1].value = context.cache(props[1].value);
  22835. }
  22836. if (dir.modifiers.length && node.tagType === 1) {
  22837. const modifiers = dir.modifiers.map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  22838. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  22839. props.push(
  22840. createObjectProperty(
  22841. modifiersKey,
  22842. createSimpleExpression(
  22843. `{ ${modifiers} }`,
  22844. false,
  22845. dir.loc,
  22846. 2
  22847. )
  22848. )
  22849. );
  22850. }
  22851. return createTransformProps(props);
  22852. };
  22853. function createTransformProps(props = []) {
  22854. return { props };
  22855. }
  22856. const seen = /* @__PURE__ */ new WeakSet();
  22857. const transformMemo = (node, context) => {
  22858. if (node.type === 1) {
  22859. const dir = findDir(node, "memo");
  22860. if (!dir || seen.has(node)) {
  22861. return;
  22862. }
  22863. seen.add(node);
  22864. return () => {
  22865. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  22866. if (codegenNode && codegenNode.type === 13) {
  22867. if (node.tagType !== 1) {
  22868. convertToBlock(codegenNode, context);
  22869. }
  22870. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  22871. dir.exp,
  22872. createFunctionExpression(void 0, codegenNode),
  22873. `_cache`,
  22874. String(context.cached++)
  22875. ]);
  22876. }
  22877. };
  22878. }
  22879. };
  22880. function getBaseTransformPreset(prefixIdentifiers) {
  22881. return [
  22882. [
  22883. transformOnce,
  22884. transformIf,
  22885. transformMemo,
  22886. transformFor,
  22887. ...[],
  22888. ...prefixIdentifiers ? [
  22889. // order is important
  22890. trackVForSlotScopes,
  22891. transformExpression
  22892. ] : [],
  22893. transformSlotOutlet,
  22894. transformElement,
  22895. trackSlotScopes,
  22896. transformText
  22897. ],
  22898. {
  22899. on: transformOn$1,
  22900. bind: transformBind,
  22901. model: transformModel$1
  22902. }
  22903. ];
  22904. }
  22905. function baseCompile(template, options = {}) {
  22906. const onError = options.onError || defaultOnError;
  22907. const isModuleMode = options.mode === "module";
  22908. const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
  22909. if (!prefixIdentifiers && options.cacheHandlers) {
  22910. onError(createCompilerError(49));
  22911. }
  22912. if (options.scopeId && !isModuleMode) {
  22913. onError(createCompilerError(50));
  22914. }
  22915. const ast = isString$2(template) ? baseParse(template, options) : template;
  22916. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
  22917. if (options.isTS) {
  22918. const { expressionPlugins } = options;
  22919. if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
  22920. options.expressionPlugins = [...expressionPlugins || [], "typescript"];
  22921. }
  22922. }
  22923. transform$1(
  22924. ast,
  22925. extend({}, options, {
  22926. prefixIdentifiers,
  22927. nodeTransforms: [
  22928. ...nodeTransforms,
  22929. ...options.nodeTransforms || []
  22930. // user transforms
  22931. ],
  22932. directiveTransforms: extend(
  22933. {},
  22934. directiveTransforms,
  22935. options.directiveTransforms || {}
  22936. // user transforms
  22937. )
  22938. })
  22939. );
  22940. return generate(
  22941. ast,
  22942. extend({}, options, {
  22943. prefixIdentifiers
  22944. })
  22945. );
  22946. }
  22947. const noopDirectiveTransform = () => ({ props: [] });
  22948. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  22949. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  22950. const V_MODEL_TEXT = Symbol(`vModelText` );
  22951. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  22952. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  22953. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  22954. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  22955. const V_SHOW = Symbol(`vShow` );
  22956. const TRANSITION = Symbol(`Transition` );
  22957. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  22958. registerRuntimeHelpers({
  22959. [V_MODEL_RADIO]: `vModelRadio`,
  22960. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  22961. [V_MODEL_TEXT]: `vModelText`,
  22962. [V_MODEL_SELECT]: `vModelSelect`,
  22963. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  22964. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  22965. [V_ON_WITH_KEYS]: `withKeys`,
  22966. [V_SHOW]: `vShow`,
  22967. [TRANSITION]: `Transition`,
  22968. [TRANSITION_GROUP]: `TransitionGroup`
  22969. });
  22970. var namedCharacterReferences = {
  22971. GT: ">",
  22972. gt: ">",
  22973. LT: "<",
  22974. lt: "<",
  22975. "ac;": "∾",
  22976. "af;": "⁡",
  22977. AMP: "&",
  22978. amp: "&",
  22979. "ap;": "≈",
  22980. "DD;": "ⅅ",
  22981. "dd;": "ⅆ",
  22982. deg: "°",
  22983. "ee;": "ⅇ",
  22984. "eg;": "⪚",
  22985. "el;": "⪙",
  22986. ETH: "Ð",
  22987. eth: "ð",
  22988. "gE;": "≧",
  22989. "ge;": "≥",
  22990. "Gg;": "⋙",
  22991. "gg;": "≫",
  22992. "gl;": "≷",
  22993. "GT;": ">",
  22994. "Gt;": "≫",
  22995. "gt;": ">",
  22996. "ic;": "⁣",
  22997. "ii;": "ⅈ",
  22998. "Im;": "ℑ",
  22999. "in;": "∈",
  23000. "it;": "⁢",
  23001. "lE;": "≦",
  23002. "le;": "≤",
  23003. "lg;": "≶",
  23004. "Ll;": "⋘",
  23005. "ll;": "≪",
  23006. "LT;": "<",
  23007. "Lt;": "≪",
  23008. "lt;": "<",
  23009. "mp;": "∓",
  23010. "Mu;": "Μ",
  23011. "mu;": "μ",
  23012. "ne;": "≠",
  23013. "ni;": "∋",
  23014. not: "¬",
  23015. "Nu;": "Ν",
  23016. "nu;": "ν",
  23017. "Or;": "⩔",
  23018. "or;": "∨",
  23019. "oS;": "Ⓢ",
  23020. "Pi;": "Π",
  23021. "pi;": "π",
  23022. "pm;": "±",
  23023. "Pr;": "⪻",
  23024. "pr;": "≺",
  23025. "Re;": "ℜ",
  23026. REG: "®",
  23027. reg: "®",
  23028. "rx;": "℞",
  23029. "Sc;": "⪼",
  23030. "sc;": "≻",
  23031. shy: "­",
  23032. uml: "¨",
  23033. "wp;": "℘",
  23034. "wr;": "≀",
  23035. "Xi;": "Ξ",
  23036. "xi;": "ξ",
  23037. yen: "¥",
  23038. "acd;": "∿",
  23039. "acE;": "∾̳",
  23040. "Acy;": "А",
  23041. "acy;": "а",
  23042. "Afr;": "𝔄",
  23043. "afr;": "𝔞",
  23044. "AMP;": "&",
  23045. "amp;": "&",
  23046. "And;": "⩓",
  23047. "and;": "∧",
  23048. "ang;": "∠",
  23049. "apE;": "⩰",
  23050. "ape;": "≊",
  23051. "ast;": "*",
  23052. Auml: "Ä",
  23053. auml: "ä",
  23054. "Bcy;": "Б",
  23055. "bcy;": "б",
  23056. "Bfr;": "𝔅",
  23057. "bfr;": "𝔟",
  23058. "bne;": "=⃥",
  23059. "bot;": "⊥",
  23060. "Cap;": "⋒",
  23061. "cap;": "∩",
  23062. cent: "¢",
  23063. "Cfr;": "ℭ",
  23064. "cfr;": "𝔠",
  23065. "Chi;": "Χ",
  23066. "chi;": "χ",
  23067. "cir;": "○",
  23068. COPY: "©",
  23069. copy: "©",
  23070. "Cup;": "⋓",
  23071. "cup;": "∪",
  23072. "Dcy;": "Д",
  23073. "dcy;": "д",
  23074. "deg;": "°",
  23075. "Del;": "∇",
  23076. "Dfr;": "𝔇",
  23077. "dfr;": "𝔡",
  23078. "die;": "¨",
  23079. "div;": "÷",
  23080. "Dot;": "¨",
  23081. "dot;": "˙",
  23082. "Ecy;": "Э",
  23083. "ecy;": "э",
  23084. "Efr;": "𝔈",
  23085. "efr;": "𝔢",
  23086. "egs;": "⪖",
  23087. "ell;": "ℓ",
  23088. "els;": "⪕",
  23089. "ENG;": "Ŋ",
  23090. "eng;": "ŋ",
  23091. "Eta;": "Η",
  23092. "eta;": "η",
  23093. "ETH;": "Ð",
  23094. "eth;": "ð",
  23095. Euml: "Ë",
  23096. euml: "ë",
  23097. "Fcy;": "Ф",
  23098. "fcy;": "ф",
  23099. "Ffr;": "𝔉",
  23100. "ffr;": "𝔣",
  23101. "gap;": "⪆",
  23102. "Gcy;": "Г",
  23103. "gcy;": "г",
  23104. "gEl;": "⪌",
  23105. "gel;": "⋛",
  23106. "geq;": "≥",
  23107. "ges;": "⩾",
  23108. "Gfr;": "𝔊",
  23109. "gfr;": "𝔤",
  23110. "ggg;": "⋙",
  23111. "gla;": "⪥",
  23112. "glE;": "⪒",
  23113. "glj;": "⪤",
  23114. "gnE;": "≩",
  23115. "gne;": "⪈",
  23116. "Hat;": "^",
  23117. "Hfr;": "ℌ",
  23118. "hfr;": "𝔥",
  23119. "Icy;": "И",
  23120. "icy;": "и",
  23121. "iff;": "⇔",
  23122. "Ifr;": "ℑ",
  23123. "ifr;": "𝔦",
  23124. "Int;": "∬",
  23125. "int;": "∫",
  23126. Iuml: "Ï",
  23127. iuml: "ï",
  23128. "Jcy;": "Й",
  23129. "jcy;": "й",
  23130. "Jfr;": "𝔍",
  23131. "jfr;": "𝔧",
  23132. "Kcy;": "К",
  23133. "kcy;": "к",
  23134. "Kfr;": "𝔎",
  23135. "kfr;": "𝔨",
  23136. "lap;": "⪅",
  23137. "lat;": "⪫",
  23138. "Lcy;": "Л",
  23139. "lcy;": "л",
  23140. "lEg;": "⪋",
  23141. "leg;": "⋚",
  23142. "leq;": "≤",
  23143. "les;": "⩽",
  23144. "Lfr;": "𝔏",
  23145. "lfr;": "𝔩",
  23146. "lgE;": "⪑",
  23147. "lnE;": "≨",
  23148. "lne;": "⪇",
  23149. "loz;": "◊",
  23150. "lrm;": "‎",
  23151. "Lsh;": "↰",
  23152. "lsh;": "↰",
  23153. macr: "¯",
  23154. "Map;": "⤅",
  23155. "map;": "↦",
  23156. "Mcy;": "М",
  23157. "mcy;": "м",
  23158. "Mfr;": "𝔐",
  23159. "mfr;": "𝔪",
  23160. "mho;": "℧",
  23161. "mid;": "∣",
  23162. "nap;": "≉",
  23163. nbsp: " ",
  23164. "Ncy;": "Н",
  23165. "ncy;": "н",
  23166. "Nfr;": "𝔑",
  23167. "nfr;": "𝔫",
  23168. "ngE;": "≧̸",
  23169. "nge;": "≱",
  23170. "nGg;": "⋙̸",
  23171. "nGt;": "≫⃒",
  23172. "ngt;": "≯",
  23173. "nis;": "⋼",
  23174. "niv;": "∋",
  23175. "nlE;": "≦̸",
  23176. "nle;": "≰",
  23177. "nLl;": "⋘̸",
  23178. "nLt;": "≪⃒",
  23179. "nlt;": "≮",
  23180. "Not;": "⫬",
  23181. "not;": "¬",
  23182. "npr;": "⊀",
  23183. "nsc;": "⊁",
  23184. "num;": "#",
  23185. "Ocy;": "О",
  23186. "ocy;": "о",
  23187. "Ofr;": "𝔒",
  23188. "ofr;": "𝔬",
  23189. "ogt;": "⧁",
  23190. "ohm;": "Ω",
  23191. "olt;": "⧀",
  23192. "ord;": "⩝",
  23193. ordf: "ª",
  23194. ordm: "º",
  23195. "orv;": "⩛",
  23196. Ouml: "Ö",
  23197. ouml: "ö",
  23198. "par;": "∥",
  23199. para: "¶",
  23200. "Pcy;": "П",
  23201. "pcy;": "п",
  23202. "Pfr;": "𝔓",
  23203. "pfr;": "𝔭",
  23204. "Phi;": "Φ",
  23205. "phi;": "φ",
  23206. "piv;": "ϖ",
  23207. "prE;": "⪳",
  23208. "pre;": "⪯",
  23209. "Psi;": "Ψ",
  23210. "psi;": "ψ",
  23211. "Qfr;": "𝔔",
  23212. "qfr;": "𝔮",
  23213. QUOT: "\"",
  23214. quot: "\"",
  23215. "Rcy;": "Р",
  23216. "rcy;": "р",
  23217. "REG;": "®",
  23218. "reg;": "®",
  23219. "Rfr;": "ℜ",
  23220. "rfr;": "𝔯",
  23221. "Rho;": "Ρ",
  23222. "rho;": "ρ",
  23223. "rlm;": "‏",
  23224. "Rsh;": "↱",
  23225. "rsh;": "↱",
  23226. "scE;": "⪴",
  23227. "sce;": "⪰",
  23228. "Scy;": "С",
  23229. "scy;": "с",
  23230. sect: "§",
  23231. "Sfr;": "𝔖",
  23232. "sfr;": "𝔰",
  23233. "shy;": "­",
  23234. "sim;": "∼",
  23235. "smt;": "⪪",
  23236. "sol;": "/",
  23237. "squ;": "□",
  23238. "Sub;": "⋐",
  23239. "sub;": "⊂",
  23240. "Sum;": "∑",
  23241. "sum;": "∑",
  23242. "Sup;": "⋑",
  23243. "sup;": "⊃",
  23244. sup1: "¹",
  23245. sup2: "²",
  23246. sup3: "³",
  23247. "Tab;": "\t",
  23248. "Tau;": "Τ",
  23249. "tau;": "τ",
  23250. "Tcy;": "Т",
  23251. "tcy;": "т",
  23252. "Tfr;": "𝔗",
  23253. "tfr;": "𝔱",
  23254. "top;": "⊤",
  23255. "Ucy;": "У",
  23256. "ucy;": "у",
  23257. "Ufr;": "𝔘",
  23258. "ufr;": "𝔲",
  23259. "uml;": "¨",
  23260. Uuml: "Ü",
  23261. uuml: "ü",
  23262. "Vcy;": "В",
  23263. "vcy;": "в",
  23264. "Vee;": "⋁",
  23265. "vee;": "∨",
  23266. "Vfr;": "𝔙",
  23267. "vfr;": "𝔳",
  23268. "Wfr;": "𝔚",
  23269. "wfr;": "𝔴",
  23270. "Xfr;": "𝔛",
  23271. "xfr;": "𝔵",
  23272. "Ycy;": "Ы",
  23273. "ycy;": "ы",
  23274. "yen;": "¥",
  23275. "Yfr;": "𝔜",
  23276. "yfr;": "𝔶",
  23277. yuml: "ÿ",
  23278. "Zcy;": "З",
  23279. "zcy;": "з",
  23280. "Zfr;": "ℨ",
  23281. "zfr;": "𝔷",
  23282. "zwj;": "‍",
  23283. Acirc: "Â",
  23284. acirc: "â",
  23285. acute: "´",
  23286. AElig: "Æ",
  23287. aelig: "æ",
  23288. "andd;": "⩜",
  23289. "andv;": "⩚",
  23290. "ange;": "⦤",
  23291. "Aopf;": "𝔸",
  23292. "aopf;": "𝕒",
  23293. "apid;": "≋",
  23294. "apos;": "'",
  23295. Aring: "Å",
  23296. aring: "å",
  23297. "Ascr;": "𝒜",
  23298. "ascr;": "𝒶",
  23299. "Auml;": "Ä",
  23300. "auml;": "ä",
  23301. "Barv;": "⫧",
  23302. "bbrk;": "⎵",
  23303. "Beta;": "Β",
  23304. "beta;": "β",
  23305. "beth;": "ℶ",
  23306. "bNot;": "⫭",
  23307. "bnot;": "⌐",
  23308. "Bopf;": "𝔹",
  23309. "bopf;": "𝕓",
  23310. "boxH;": "═",
  23311. "boxh;": "─",
  23312. "boxV;": "║",
  23313. "boxv;": "│",
  23314. "Bscr;": "ℬ",
  23315. "bscr;": "𝒷",
  23316. "bsim;": "∽",
  23317. "bsol;": "\\",
  23318. "bull;": "•",
  23319. "bump;": "≎",
  23320. "caps;": "∩︀",
  23321. "Cdot;": "Ċ",
  23322. "cdot;": "ċ",
  23323. cedil: "¸",
  23324. "cent;": "¢",
  23325. "CHcy;": "Ч",
  23326. "chcy;": "ч",
  23327. "circ;": "ˆ",
  23328. "cirE;": "⧃",
  23329. "cire;": "≗",
  23330. "comp;": "∁",
  23331. "cong;": "≅",
  23332. "Copf;": "ℂ",
  23333. "copf;": "𝕔",
  23334. "COPY;": "©",
  23335. "copy;": "©",
  23336. "Cscr;": "𝒞",
  23337. "cscr;": "𝒸",
  23338. "csub;": "⫏",
  23339. "csup;": "⫐",
  23340. "cups;": "∪︀",
  23341. "Darr;": "↡",
  23342. "dArr;": "⇓",
  23343. "darr;": "↓",
  23344. "dash;": "‐",
  23345. "dHar;": "⥥",
  23346. "diam;": "⋄",
  23347. "DJcy;": "Ђ",
  23348. "djcy;": "ђ",
  23349. "Dopf;": "𝔻",
  23350. "dopf;": "𝕕",
  23351. "Dscr;": "𝒟",
  23352. "dscr;": "𝒹",
  23353. "DScy;": "Ѕ",
  23354. "dscy;": "ѕ",
  23355. "dsol;": "⧶",
  23356. "dtri;": "▿",
  23357. "DZcy;": "Џ",
  23358. "dzcy;": "џ",
  23359. "ecir;": "≖",
  23360. Ecirc: "Ê",
  23361. ecirc: "ê",
  23362. "Edot;": "Ė",
  23363. "eDot;": "≑",
  23364. "edot;": "ė",
  23365. "emsp;": " ",
  23366. "ensp;": " ",
  23367. "Eopf;": "𝔼",
  23368. "eopf;": "𝕖",
  23369. "epar;": "⋕",
  23370. "epsi;": "ε",
  23371. "Escr;": "ℰ",
  23372. "escr;": "ℯ",
  23373. "Esim;": "⩳",
  23374. "esim;": "≂",
  23375. "Euml;": "Ë",
  23376. "euml;": "ë",
  23377. "euro;": "€",
  23378. "excl;": "!",
  23379. "flat;": "♭",
  23380. "fnof;": "ƒ",
  23381. "Fopf;": "𝔽",
  23382. "fopf;": "𝕗",
  23383. "fork;": "⋔",
  23384. "Fscr;": "ℱ",
  23385. "fscr;": "𝒻",
  23386. "Gdot;": "Ġ",
  23387. "gdot;": "ġ",
  23388. "geqq;": "≧",
  23389. "gesl;": "⋛︀",
  23390. "GJcy;": "Ѓ",
  23391. "gjcy;": "ѓ",
  23392. "gnap;": "⪊",
  23393. "gneq;": "⪈",
  23394. "Gopf;": "𝔾",
  23395. "gopf;": "𝕘",
  23396. "Gscr;": "𝒢",
  23397. "gscr;": "ℊ",
  23398. "gsim;": "≳",
  23399. "gtcc;": "⪧",
  23400. "gvnE;": "≩︀",
  23401. "half;": "½",
  23402. "hArr;": "⇔",
  23403. "harr;": "↔",
  23404. "hbar;": "ℏ",
  23405. "Hopf;": "ℍ",
  23406. "hopf;": "𝕙",
  23407. "Hscr;": "ℋ",
  23408. "hscr;": "𝒽",
  23409. Icirc: "Î",
  23410. icirc: "î",
  23411. "Idot;": "İ",
  23412. "IEcy;": "Е",
  23413. "iecy;": "е",
  23414. iexcl: "¡",
  23415. "imof;": "⊷",
  23416. "IOcy;": "Ё",
  23417. "iocy;": "ё",
  23418. "Iopf;": "𝕀",
  23419. "iopf;": "𝕚",
  23420. "Iota;": "Ι",
  23421. "iota;": "ι",
  23422. "Iscr;": "ℐ",
  23423. "iscr;": "𝒾",
  23424. "isin;": "∈",
  23425. "Iuml;": "Ï",
  23426. "iuml;": "ï",
  23427. "Jopf;": "𝕁",
  23428. "jopf;": "𝕛",
  23429. "Jscr;": "𝒥",
  23430. "jscr;": "𝒿",
  23431. "KHcy;": "Х",
  23432. "khcy;": "х",
  23433. "KJcy;": "Ќ",
  23434. "kjcy;": "ќ",
  23435. "Kopf;": "𝕂",
  23436. "kopf;": "𝕜",
  23437. "Kscr;": "𝒦",
  23438. "kscr;": "𝓀",
  23439. "Lang;": "⟪",
  23440. "lang;": "⟨",
  23441. laquo: "«",
  23442. "Larr;": "↞",
  23443. "lArr;": "⇐",
  23444. "larr;": "←",
  23445. "late;": "⪭",
  23446. "lcub;": "{",
  23447. "ldca;": "⤶",
  23448. "ldsh;": "↲",
  23449. "leqq;": "≦",
  23450. "lesg;": "⋚︀",
  23451. "lHar;": "⥢",
  23452. "LJcy;": "Љ",
  23453. "ljcy;": "љ",
  23454. "lnap;": "⪉",
  23455. "lneq;": "⪇",
  23456. "Lopf;": "𝕃",
  23457. "lopf;": "𝕝",
  23458. "lozf;": "⧫",
  23459. "lpar;": "(",
  23460. "Lscr;": "ℒ",
  23461. "lscr;": "𝓁",
  23462. "lsim;": "≲",
  23463. "lsqb;": "[",
  23464. "ltcc;": "⪦",
  23465. "ltri;": "◃",
  23466. "lvnE;": "≨︀",
  23467. "macr;": "¯",
  23468. "male;": "♂",
  23469. "malt;": "✠",
  23470. micro: "µ",
  23471. "mlcp;": "⫛",
  23472. "mldr;": "…",
  23473. "Mopf;": "𝕄",
  23474. "mopf;": "𝕞",
  23475. "Mscr;": "ℳ",
  23476. "mscr;": "𝓂",
  23477. "nang;": "∠⃒",
  23478. "napE;": "⩰̸",
  23479. "nbsp;": " ",
  23480. "ncap;": "⩃",
  23481. "ncup;": "⩂",
  23482. "ngeq;": "≱",
  23483. "nges;": "⩾̸",
  23484. "ngtr;": "≯",
  23485. "nGtv;": "≫̸",
  23486. "nisd;": "⋺",
  23487. "NJcy;": "Њ",
  23488. "njcy;": "њ",
  23489. "nldr;": "‥",
  23490. "nleq;": "≰",
  23491. "nles;": "⩽̸",
  23492. "nLtv;": "≪̸",
  23493. "nmid;": "∤",
  23494. "Nopf;": "ℕ",
  23495. "nopf;": "𝕟",
  23496. "npar;": "∦",
  23497. "npre;": "⪯̸",
  23498. "nsce;": "⪰̸",
  23499. "Nscr;": "𝒩",
  23500. "nscr;": "𝓃",
  23501. "nsim;": "≁",
  23502. "nsub;": "⊄",
  23503. "nsup;": "⊅",
  23504. "ntgl;": "≹",
  23505. "ntlg;": "≸",
  23506. "nvap;": "≍⃒",
  23507. "nvge;": "≥⃒",
  23508. "nvgt;": ">⃒",
  23509. "nvle;": "≤⃒",
  23510. "nvlt;": "<⃒",
  23511. "oast;": "⊛",
  23512. "ocir;": "⊚",
  23513. Ocirc: "Ô",
  23514. ocirc: "ô",
  23515. "odiv;": "⨸",
  23516. "odot;": "⊙",
  23517. "ogon;": "˛",
  23518. "oint;": "∮",
  23519. "omid;": "⦶",
  23520. "Oopf;": "𝕆",
  23521. "oopf;": "𝕠",
  23522. "opar;": "⦷",
  23523. "ordf;": "ª",
  23524. "ordm;": "º",
  23525. "oror;": "⩖",
  23526. "Oscr;": "𝒪",
  23527. "oscr;": "ℴ",
  23528. "osol;": "⊘",
  23529. "Ouml;": "Ö",
  23530. "ouml;": "ö",
  23531. "para;": "¶",
  23532. "part;": "∂",
  23533. "perp;": "⊥",
  23534. "phiv;": "ϕ",
  23535. "plus;": "+",
  23536. "Popf;": "ℙ",
  23537. "popf;": "𝕡",
  23538. pound: "£",
  23539. "prap;": "⪷",
  23540. "prec;": "≺",
  23541. "prnE;": "⪵",
  23542. "prod;": "∏",
  23543. "prop;": "∝",
  23544. "Pscr;": "𝒫",
  23545. "pscr;": "𝓅",
  23546. "qint;": "⨌",
  23547. "Qopf;": "ℚ",
  23548. "qopf;": "𝕢",
  23549. "Qscr;": "𝒬",
  23550. "qscr;": "𝓆",
  23551. "QUOT;": "\"",
  23552. "quot;": "\"",
  23553. "race;": "∽̱",
  23554. "Rang;": "⟫",
  23555. "rang;": "⟩",
  23556. raquo: "»",
  23557. "Rarr;": "↠",
  23558. "rArr;": "⇒",
  23559. "rarr;": "→",
  23560. "rcub;": "}",
  23561. "rdca;": "⤷",
  23562. "rdsh;": "↳",
  23563. "real;": "ℜ",
  23564. "rect;": "▭",
  23565. "rHar;": "⥤",
  23566. "rhov;": "ϱ",
  23567. "ring;": "˚",
  23568. "Ropf;": "ℝ",
  23569. "ropf;": "𝕣",
  23570. "rpar;": ")",
  23571. "Rscr;": "ℛ",
  23572. "rscr;": "𝓇",
  23573. "rsqb;": "]",
  23574. "rtri;": "▹",
  23575. "scap;": "⪸",
  23576. "scnE;": "⪶",
  23577. "sdot;": "⋅",
  23578. "sect;": "§",
  23579. "semi;": ";",
  23580. "sext;": "✶",
  23581. "SHcy;": "Ш",
  23582. "shcy;": "ш",
  23583. "sime;": "≃",
  23584. "simg;": "⪞",
  23585. "siml;": "⪝",
  23586. "smid;": "∣",
  23587. "smte;": "⪬",
  23588. "solb;": "⧄",
  23589. "Sopf;": "𝕊",
  23590. "sopf;": "𝕤",
  23591. "spar;": "∥",
  23592. "Sqrt;": "√",
  23593. "squf;": "▪",
  23594. "Sscr;": "𝒮",
  23595. "sscr;": "𝓈",
  23596. "Star;": "⋆",
  23597. "star;": "☆",
  23598. "subE;": "⫅",
  23599. "sube;": "⊆",
  23600. "succ;": "≻",
  23601. "sung;": "♪",
  23602. "sup1;": "¹",
  23603. "sup2;": "²",
  23604. "sup3;": "³",
  23605. "supE;": "⫆",
  23606. "supe;": "⊇",
  23607. szlig: "ß",
  23608. "tbrk;": "⎴",
  23609. "tdot;": "⃛",
  23610. THORN: "Þ",
  23611. thorn: "þ",
  23612. times: "×",
  23613. "tint;": "∭",
  23614. "toea;": "⤨",
  23615. "Topf;": "𝕋",
  23616. "topf;": "𝕥",
  23617. "tosa;": "⤩",
  23618. "trie;": "≜",
  23619. "Tscr;": "𝒯",
  23620. "tscr;": "𝓉",
  23621. "TScy;": "Ц",
  23622. "tscy;": "ц",
  23623. "Uarr;": "↟",
  23624. "uArr;": "⇑",
  23625. "uarr;": "↑",
  23626. Ucirc: "Û",
  23627. ucirc: "û",
  23628. "uHar;": "⥣",
  23629. "Uopf;": "𝕌",
  23630. "uopf;": "𝕦",
  23631. "Upsi;": "ϒ",
  23632. "upsi;": "υ",
  23633. "Uscr;": "𝒰",
  23634. "uscr;": "𝓊",
  23635. "utri;": "▵",
  23636. "Uuml;": "Ü",
  23637. "uuml;": "ü",
  23638. "vArr;": "⇕",
  23639. "varr;": "↕",
  23640. "Vbar;": "⫫",
  23641. "vBar;": "⫨",
  23642. "Vert;": "‖",
  23643. "vert;": "|",
  23644. "Vopf;": "𝕍",
  23645. "vopf;": "𝕧",
  23646. "Vscr;": "𝒱",
  23647. "vscr;": "𝓋",
  23648. "Wopf;": "𝕎",
  23649. "wopf;": "𝕨",
  23650. "Wscr;": "𝒲",
  23651. "wscr;": "𝓌",
  23652. "xcap;": "⋂",
  23653. "xcup;": "⋃",
  23654. "xmap;": "⟼",
  23655. "xnis;": "⋻",
  23656. "Xopf;": "𝕏",
  23657. "xopf;": "𝕩",
  23658. "Xscr;": "𝒳",
  23659. "xscr;": "𝓍",
  23660. "xvee;": "⋁",
  23661. "YAcy;": "Я",
  23662. "yacy;": "я",
  23663. "YIcy;": "Ї",
  23664. "yicy;": "ї",
  23665. "Yopf;": "𝕐",
  23666. "yopf;": "𝕪",
  23667. "Yscr;": "𝒴",
  23668. "yscr;": "𝓎",
  23669. "YUcy;": "Ю",
  23670. "yucy;": "ю",
  23671. "Yuml;": "Ÿ",
  23672. "yuml;": "ÿ",
  23673. "Zdot;": "Ż",
  23674. "zdot;": "ż",
  23675. "Zeta;": "Ζ",
  23676. "zeta;": "ζ",
  23677. "ZHcy;": "Ж",
  23678. "zhcy;": "ж",
  23679. "Zopf;": "ℤ",
  23680. "zopf;": "𝕫",
  23681. "Zscr;": "𝒵",
  23682. "zscr;": "𝓏",
  23683. "zwnj;": "‌",
  23684. Aacute: "Á",
  23685. aacute: "á",
  23686. "Acirc;": "Â",
  23687. "acirc;": "â",
  23688. "acute;": "´",
  23689. "AElig;": "Æ",
  23690. "aelig;": "æ",
  23691. Agrave: "À",
  23692. agrave: "à",
  23693. "aleph;": "ℵ",
  23694. "Alpha;": "Α",
  23695. "alpha;": "α",
  23696. "Amacr;": "Ā",
  23697. "amacr;": "ā",
  23698. "amalg;": "⨿",
  23699. "angle;": "∠",
  23700. "angrt;": "∟",
  23701. "angst;": "Å",
  23702. "Aogon;": "Ą",
  23703. "aogon;": "ą",
  23704. "Aring;": "Å",
  23705. "aring;": "å",
  23706. "asymp;": "≈",
  23707. Atilde: "Ã",
  23708. atilde: "ã",
  23709. "awint;": "⨑",
  23710. "bcong;": "≌",
  23711. "bdquo;": "„",
  23712. "bepsi;": "϶",
  23713. "blank;": "␣",
  23714. "blk12;": "▒",
  23715. "blk14;": "░",
  23716. "blk34;": "▓",
  23717. "block;": "█",
  23718. "boxDL;": "╗",
  23719. "boxDl;": "╖",
  23720. "boxdL;": "╕",
  23721. "boxdl;": "┐",
  23722. "boxDR;": "╔",
  23723. "boxDr;": "╓",
  23724. "boxdR;": "╒",
  23725. "boxdr;": "┌",
  23726. "boxHD;": "╦",
  23727. "boxHd;": "╤",
  23728. "boxhD;": "╥",
  23729. "boxhd;": "┬",
  23730. "boxHU;": "╩",
  23731. "boxHu;": "╧",
  23732. "boxhU;": "╨",
  23733. "boxhu;": "┴",
  23734. "boxUL;": "╝",
  23735. "boxUl;": "╜",
  23736. "boxuL;": "╛",
  23737. "boxul;": "┘",
  23738. "boxUR;": "╚",
  23739. "boxUr;": "╙",
  23740. "boxuR;": "╘",
  23741. "boxur;": "└",
  23742. "boxVH;": "╬",
  23743. "boxVh;": "╫",
  23744. "boxvH;": "╪",
  23745. "boxvh;": "┼",
  23746. "boxVL;": "╣",
  23747. "boxVl;": "╢",
  23748. "boxvL;": "╡",
  23749. "boxvl;": "┤",
  23750. "boxVR;": "╠",
  23751. "boxVr;": "╟",
  23752. "boxvR;": "╞",
  23753. "boxvr;": "├",
  23754. "Breve;": "˘",
  23755. "breve;": "˘",
  23756. brvbar: "¦",
  23757. "bsemi;": "⁏",
  23758. "bsime;": "⋍",
  23759. "bsolb;": "⧅",
  23760. "bumpE;": "⪮",
  23761. "bumpe;": "≏",
  23762. "caret;": "⁁",
  23763. "caron;": "ˇ",
  23764. "ccaps;": "⩍",
  23765. Ccedil: "Ç",
  23766. ccedil: "ç",
  23767. "Ccirc;": "Ĉ",
  23768. "ccirc;": "ĉ",
  23769. "ccups;": "⩌",
  23770. "cedil;": "¸",
  23771. "check;": "✓",
  23772. "clubs;": "♣",
  23773. "Colon;": "∷",
  23774. "colon;": ":",
  23775. "comma;": ",",
  23776. "crarr;": "↵",
  23777. "Cross;": "⨯",
  23778. "cross;": "✗",
  23779. "csube;": "⫑",
  23780. "csupe;": "⫒",
  23781. "ctdot;": "⋯",
  23782. "cuepr;": "⋞",
  23783. "cuesc;": "⋟",
  23784. "cupor;": "⩅",
  23785. curren: "¤",
  23786. "cuvee;": "⋎",
  23787. "cuwed;": "⋏",
  23788. "cwint;": "∱",
  23789. "Dashv;": "⫤",
  23790. "dashv;": "⊣",
  23791. "dblac;": "˝",
  23792. "ddarr;": "⇊",
  23793. "Delta;": "Δ",
  23794. "delta;": "δ",
  23795. "dharl;": "⇃",
  23796. "dharr;": "⇂",
  23797. "diams;": "♦",
  23798. "disin;": "⋲",
  23799. divide: "÷",
  23800. "doteq;": "≐",
  23801. "dtdot;": "⋱",
  23802. "dtrif;": "▾",
  23803. "duarr;": "⇵",
  23804. "duhar;": "⥯",
  23805. Eacute: "É",
  23806. eacute: "é",
  23807. "Ecirc;": "Ê",
  23808. "ecirc;": "ê",
  23809. "eDDot;": "⩷",
  23810. "efDot;": "≒",
  23811. Egrave: "È",
  23812. egrave: "è",
  23813. "Emacr;": "Ē",
  23814. "emacr;": "ē",
  23815. "empty;": "∅",
  23816. "Eogon;": "Ę",
  23817. "eogon;": "ę",
  23818. "eplus;": "⩱",
  23819. "epsiv;": "ϵ",
  23820. "eqsim;": "≂",
  23821. "Equal;": "⩵",
  23822. "equiv;": "≡",
  23823. "erarr;": "⥱",
  23824. "erDot;": "≓",
  23825. "esdot;": "≐",
  23826. "exist;": "∃",
  23827. "fflig;": "ff",
  23828. "filig;": "fi",
  23829. "fjlig;": "fj",
  23830. "fllig;": "fl",
  23831. "fltns;": "▱",
  23832. "forkv;": "⫙",
  23833. frac12: "½",
  23834. frac14: "¼",
  23835. frac34: "¾",
  23836. "frasl;": "⁄",
  23837. "frown;": "⌢",
  23838. "Gamma;": "Γ",
  23839. "gamma;": "γ",
  23840. "Gcirc;": "Ĝ",
  23841. "gcirc;": "ĝ",
  23842. "gescc;": "⪩",
  23843. "gimel;": "ℷ",
  23844. "gneqq;": "≩",
  23845. "gnsim;": "⋧",
  23846. "grave;": "`",
  23847. "gsime;": "⪎",
  23848. "gsiml;": "⪐",
  23849. "gtcir;": "⩺",
  23850. "gtdot;": "⋗",
  23851. "Hacek;": "ˇ",
  23852. "harrw;": "↭",
  23853. "Hcirc;": "Ĥ",
  23854. "hcirc;": "ĥ",
  23855. "hoarr;": "⇿",
  23856. Iacute: "Í",
  23857. iacute: "í",
  23858. "Icirc;": "Î",
  23859. "icirc;": "î",
  23860. "iexcl;": "¡",
  23861. Igrave: "Ì",
  23862. igrave: "ì",
  23863. "iiint;": "∭",
  23864. "iiota;": "℩",
  23865. "IJlig;": "IJ",
  23866. "ijlig;": "ij",
  23867. "Imacr;": "Ī",
  23868. "imacr;": "ī",
  23869. "image;": "ℑ",
  23870. "imath;": "ı",
  23871. "imped;": "Ƶ",
  23872. "infin;": "∞",
  23873. "Iogon;": "Į",
  23874. "iogon;": "į",
  23875. "iprod;": "⨼",
  23876. iquest: "¿",
  23877. "isinE;": "⋹",
  23878. "isins;": "⋴",
  23879. "isinv;": "∈",
  23880. "Iukcy;": "І",
  23881. "iukcy;": "і",
  23882. "Jcirc;": "Ĵ",
  23883. "jcirc;": "ĵ",
  23884. "jmath;": "ȷ",
  23885. "Jukcy;": "Є",
  23886. "jukcy;": "є",
  23887. "Kappa;": "Κ",
  23888. "kappa;": "κ",
  23889. "lAarr;": "⇚",
  23890. "langd;": "⦑",
  23891. "laquo;": "«",
  23892. "larrb;": "⇤",
  23893. "lates;": "⪭︀",
  23894. "lBarr;": "⤎",
  23895. "lbarr;": "⤌",
  23896. "lbbrk;": "❲",
  23897. "lbrke;": "⦋",
  23898. "lceil;": "⌈",
  23899. "ldquo;": "“",
  23900. "lescc;": "⪨",
  23901. "lhard;": "↽",
  23902. "lharu;": "↼",
  23903. "lhblk;": "▄",
  23904. "llarr;": "⇇",
  23905. "lltri;": "◺",
  23906. "lneqq;": "≨",
  23907. "lnsim;": "⋦",
  23908. "loang;": "⟬",
  23909. "loarr;": "⇽",
  23910. "lobrk;": "⟦",
  23911. "lopar;": "⦅",
  23912. "lrarr;": "⇆",
  23913. "lrhar;": "⇋",
  23914. "lrtri;": "⊿",
  23915. "lsime;": "⪍",
  23916. "lsimg;": "⪏",
  23917. "lsquo;": "‘",
  23918. "ltcir;": "⩹",
  23919. "ltdot;": "⋖",
  23920. "ltrie;": "⊴",
  23921. "ltrif;": "◂",
  23922. "mdash;": "—",
  23923. "mDDot;": "∺",
  23924. "micro;": "µ",
  23925. middot: "·",
  23926. "minus;": "−",
  23927. "mumap;": "⊸",
  23928. "nabla;": "∇",
  23929. "napid;": "≋̸",
  23930. "napos;": "ʼn",
  23931. "natur;": "♮",
  23932. "nbump;": "≎̸",
  23933. "ncong;": "≇",
  23934. "ndash;": "–",
  23935. "neArr;": "⇗",
  23936. "nearr;": "↗",
  23937. "nedot;": "≐̸",
  23938. "nesim;": "≂̸",
  23939. "ngeqq;": "≧̸",
  23940. "ngsim;": "≵",
  23941. "nhArr;": "⇎",
  23942. "nharr;": "↮",
  23943. "nhpar;": "⫲",
  23944. "nlArr;": "⇍",
  23945. "nlarr;": "↚",
  23946. "nleqq;": "≦̸",
  23947. "nless;": "≮",
  23948. "nlsim;": "≴",
  23949. "nltri;": "⋪",
  23950. "notin;": "∉",
  23951. "notni;": "∌",
  23952. "npart;": "∂̸",
  23953. "nprec;": "⊀",
  23954. "nrArr;": "⇏",
  23955. "nrarr;": "↛",
  23956. "nrtri;": "⋫",
  23957. "nsime;": "≄",
  23958. "nsmid;": "∤",
  23959. "nspar;": "∦",
  23960. "nsubE;": "⫅̸",
  23961. "nsube;": "⊈",
  23962. "nsucc;": "⊁",
  23963. "nsupE;": "⫆̸",
  23964. "nsupe;": "⊉",
  23965. Ntilde: "Ñ",
  23966. ntilde: "ñ",
  23967. "numsp;": " ",
  23968. "nvsim;": "∼⃒",
  23969. "nwArr;": "⇖",
  23970. "nwarr;": "↖",
  23971. Oacute: "Ó",
  23972. oacute: "ó",
  23973. "Ocirc;": "Ô",
  23974. "ocirc;": "ô",
  23975. "odash;": "⊝",
  23976. "OElig;": "Œ",
  23977. "oelig;": "œ",
  23978. "ofcir;": "⦿",
  23979. Ograve: "Ò",
  23980. ograve: "ò",
  23981. "ohbar;": "⦵",
  23982. "olarr;": "↺",
  23983. "olcir;": "⦾",
  23984. "oline;": "‾",
  23985. "Omacr;": "Ō",
  23986. "omacr;": "ō",
  23987. "Omega;": "Ω",
  23988. "omega;": "ω",
  23989. "operp;": "⦹",
  23990. "oplus;": "⊕",
  23991. "orarr;": "↻",
  23992. "order;": "ℴ",
  23993. Oslash: "Ø",
  23994. oslash: "ø",
  23995. Otilde: "Õ",
  23996. otilde: "õ",
  23997. "ovbar;": "⌽",
  23998. "parsl;": "⫽",
  23999. "phone;": "☎",
  24000. "plusb;": "⊞",
  24001. "pluse;": "⩲",
  24002. plusmn: "±",
  24003. "pound;": "£",
  24004. "prcue;": "≼",
  24005. "Prime;": "″",
  24006. "prime;": "′",
  24007. "prnap;": "⪹",
  24008. "prsim;": "≾",
  24009. "quest;": "?",
  24010. "rAarr;": "⇛",
  24011. "radic;": "√",
  24012. "rangd;": "⦒",
  24013. "range;": "⦥",
  24014. "raquo;": "»",
  24015. "rarrb;": "⇥",
  24016. "rarrc;": "⤳",
  24017. "rarrw;": "↝",
  24018. "ratio;": "∶",
  24019. "RBarr;": "⤐",
  24020. "rBarr;": "⤏",
  24021. "rbarr;": "⤍",
  24022. "rbbrk;": "❳",
  24023. "rbrke;": "⦌",
  24024. "rceil;": "⌉",
  24025. "rdquo;": "”",
  24026. "reals;": "ℝ",
  24027. "rhard;": "⇁",
  24028. "rharu;": "⇀",
  24029. "rlarr;": "⇄",
  24030. "rlhar;": "⇌",
  24031. "rnmid;": "⫮",
  24032. "roang;": "⟭",
  24033. "roarr;": "⇾",
  24034. "robrk;": "⟧",
  24035. "ropar;": "⦆",
  24036. "rrarr;": "⇉",
  24037. "rsquo;": "’",
  24038. "rtrie;": "⊵",
  24039. "rtrif;": "▸",
  24040. "sbquo;": "‚",
  24041. "sccue;": "≽",
  24042. "Scirc;": "Ŝ",
  24043. "scirc;": "ŝ",
  24044. "scnap;": "⪺",
  24045. "scsim;": "≿",
  24046. "sdotb;": "⊡",
  24047. "sdote;": "⩦",
  24048. "seArr;": "⇘",
  24049. "searr;": "↘",
  24050. "setmn;": "∖",
  24051. "sharp;": "♯",
  24052. "Sigma;": "Σ",
  24053. "sigma;": "σ",
  24054. "simeq;": "≃",
  24055. "simgE;": "⪠",
  24056. "simlE;": "⪟",
  24057. "simne;": "≆",
  24058. "slarr;": "←",
  24059. "smile;": "⌣",
  24060. "smtes;": "⪬︀",
  24061. "sqcap;": "⊓",
  24062. "sqcup;": "⊔",
  24063. "sqsub;": "⊏",
  24064. "sqsup;": "⊐",
  24065. "srarr;": "→",
  24066. "starf;": "★",
  24067. "strns;": "¯",
  24068. "subnE;": "⫋",
  24069. "subne;": "⊊",
  24070. "supnE;": "⫌",
  24071. "supne;": "⊋",
  24072. "swArr;": "⇙",
  24073. "swarr;": "↙",
  24074. "szlig;": "ß",
  24075. "Theta;": "Θ",
  24076. "theta;": "θ",
  24077. "thkap;": "≈",
  24078. "THORN;": "Þ",
  24079. "thorn;": "þ",
  24080. "Tilde;": "∼",
  24081. "tilde;": "˜",
  24082. "times;": "×",
  24083. "TRADE;": "™",
  24084. "trade;": "™",
  24085. "trisb;": "⧍",
  24086. "TSHcy;": "Ћ",
  24087. "tshcy;": "ћ",
  24088. "twixt;": "≬",
  24089. Uacute: "Ú",
  24090. uacute: "ú",
  24091. "Ubrcy;": "Ў",
  24092. "ubrcy;": "ў",
  24093. "Ucirc;": "Û",
  24094. "ucirc;": "û",
  24095. "udarr;": "⇅",
  24096. "udhar;": "⥮",
  24097. Ugrave: "Ù",
  24098. ugrave: "ù",
  24099. "uharl;": "↿",
  24100. "uharr;": "↾",
  24101. "uhblk;": "▀",
  24102. "ultri;": "◸",
  24103. "Umacr;": "Ū",
  24104. "umacr;": "ū",
  24105. "Union;": "⋃",
  24106. "Uogon;": "Ų",
  24107. "uogon;": "ų",
  24108. "uplus;": "⊎",
  24109. "upsih;": "ϒ",
  24110. "UpTee;": "⊥",
  24111. "Uring;": "Ů",
  24112. "uring;": "ů",
  24113. "urtri;": "◹",
  24114. "utdot;": "⋰",
  24115. "utrif;": "▴",
  24116. "uuarr;": "⇈",
  24117. "varpi;": "ϖ",
  24118. "vBarv;": "⫩",
  24119. "VDash;": "⊫",
  24120. "Vdash;": "⊩",
  24121. "vDash;": "⊨",
  24122. "vdash;": "⊢",
  24123. "veeeq;": "≚",
  24124. "vltri;": "⊲",
  24125. "vnsub;": "⊂⃒",
  24126. "vnsup;": "⊃⃒",
  24127. "vprop;": "∝",
  24128. "vrtri;": "⊳",
  24129. "Wcirc;": "Ŵ",
  24130. "wcirc;": "ŵ",
  24131. "Wedge;": "⋀",
  24132. "wedge;": "∧",
  24133. "xcirc;": "◯",
  24134. "xdtri;": "▽",
  24135. "xhArr;": "⟺",
  24136. "xharr;": "⟷",
  24137. "xlArr;": "⟸",
  24138. "xlarr;": "⟵",
  24139. "xodot;": "⨀",
  24140. "xrArr;": "⟹",
  24141. "xrarr;": "⟶",
  24142. "xutri;": "△",
  24143. Yacute: "Ý",
  24144. yacute: "ý",
  24145. "Ycirc;": "Ŷ",
  24146. "ycirc;": "ŷ",
  24147. "Aacute;": "Á",
  24148. "aacute;": "á",
  24149. "Abreve;": "Ă",
  24150. "abreve;": "ă",
  24151. "Agrave;": "À",
  24152. "agrave;": "à",
  24153. "andand;": "⩕",
  24154. "angmsd;": "∡",
  24155. "angsph;": "∢",
  24156. "apacir;": "⩯",
  24157. "approx;": "≈",
  24158. "Assign;": "≔",
  24159. "Atilde;": "Ã",
  24160. "atilde;": "ã",
  24161. "barvee;": "⊽",
  24162. "Barwed;": "⌆",
  24163. "barwed;": "⌅",
  24164. "becaus;": "∵",
  24165. "bernou;": "ℬ",
  24166. "bigcap;": "⋂",
  24167. "bigcup;": "⋃",
  24168. "bigvee;": "⋁",
  24169. "bkarow;": "⤍",
  24170. "bottom;": "⊥",
  24171. "bowtie;": "⋈",
  24172. "boxbox;": "⧉",
  24173. "bprime;": "‵",
  24174. "brvbar;": "¦",
  24175. "bullet;": "•",
  24176. "Bumpeq;": "≎",
  24177. "bumpeq;": "≏",
  24178. "Cacute;": "Ć",
  24179. "cacute;": "ć",
  24180. "capand;": "⩄",
  24181. "capcap;": "⩋",
  24182. "capcup;": "⩇",
  24183. "capdot;": "⩀",
  24184. "Ccaron;": "Č",
  24185. "ccaron;": "č",
  24186. "Ccedil;": "Ç",
  24187. "ccedil;": "ç",
  24188. "circeq;": "≗",
  24189. "cirmid;": "⫯",
  24190. "Colone;": "⩴",
  24191. "colone;": "≔",
  24192. "commat;": "@",
  24193. "compfn;": "∘",
  24194. "Conint;": "∯",
  24195. "conint;": "∮",
  24196. "coprod;": "∐",
  24197. "copysr;": "℗",
  24198. "cularr;": "↶",
  24199. "CupCap;": "≍",
  24200. "cupcap;": "⩆",
  24201. "cupcup;": "⩊",
  24202. "cupdot;": "⊍",
  24203. "curarr;": "↷",
  24204. "curren;": "¤",
  24205. "cylcty;": "⌭",
  24206. "Dagger;": "‡",
  24207. "dagger;": "†",
  24208. "daleth;": "ℸ",
  24209. "Dcaron;": "Ď",
  24210. "dcaron;": "ď",
  24211. "dfisht;": "⥿",
  24212. "divide;": "÷",
  24213. "divonx;": "⋇",
  24214. "dlcorn;": "⌞",
  24215. "dlcrop;": "⌍",
  24216. "dollar;": "$",
  24217. "DotDot;": "⃜",
  24218. "drcorn;": "⌟",
  24219. "drcrop;": "⌌",
  24220. "Dstrok;": "Đ",
  24221. "dstrok;": "đ",
  24222. "Eacute;": "É",
  24223. "eacute;": "é",
  24224. "easter;": "⩮",
  24225. "Ecaron;": "Ě",
  24226. "ecaron;": "ě",
  24227. "ecolon;": "≕",
  24228. "Egrave;": "È",
  24229. "egrave;": "è",
  24230. "egsdot;": "⪘",
  24231. "elsdot;": "⪗",
  24232. "emptyv;": "∅",
  24233. "emsp13;": " ",
  24234. "emsp14;": " ",
  24235. "eparsl;": "⧣",
  24236. "eqcirc;": "≖",
  24237. "equals;": "=",
  24238. "equest;": "≟",
  24239. "Exists;": "∃",
  24240. "female;": "♀",
  24241. "ffilig;": "ffi",
  24242. "ffllig;": "ffl",
  24243. "ForAll;": "∀",
  24244. "forall;": "∀",
  24245. "frac12;": "½",
  24246. "frac13;": "⅓",
  24247. "frac14;": "¼",
  24248. "frac15;": "⅕",
  24249. "frac16;": "⅙",
  24250. "frac18;": "⅛",
  24251. "frac23;": "⅔",
  24252. "frac25;": "⅖",
  24253. "frac34;": "¾",
  24254. "frac35;": "⅗",
  24255. "frac38;": "⅜",
  24256. "frac45;": "⅘",
  24257. "frac56;": "⅚",
  24258. "frac58;": "⅝",
  24259. "frac78;": "⅞",
  24260. "gacute;": "ǵ",
  24261. "Gammad;": "Ϝ",
  24262. "gammad;": "ϝ",
  24263. "Gbreve;": "Ğ",
  24264. "gbreve;": "ğ",
  24265. "Gcedil;": "Ģ",
  24266. "gesdot;": "⪀",
  24267. "gesles;": "⪔",
  24268. "gtlPar;": "⦕",
  24269. "gtrarr;": "⥸",
  24270. "gtrdot;": "⋗",
  24271. "gtrsim;": "≳",
  24272. "hairsp;": " ",
  24273. "hamilt;": "ℋ",
  24274. "HARDcy;": "Ъ",
  24275. "hardcy;": "ъ",
  24276. "hearts;": "♥",
  24277. "hellip;": "…",
  24278. "hercon;": "⊹",
  24279. "homtht;": "∻",
  24280. "horbar;": "―",
  24281. "hslash;": "ℏ",
  24282. "Hstrok;": "Ħ",
  24283. "hstrok;": "ħ",
  24284. "hybull;": "⁃",
  24285. "hyphen;": "‐",
  24286. "Iacute;": "Í",
  24287. "iacute;": "í",
  24288. "Igrave;": "Ì",
  24289. "igrave;": "ì",
  24290. "iiiint;": "⨌",
  24291. "iinfin;": "⧜",
  24292. "incare;": "℅",
  24293. "inodot;": "ı",
  24294. "intcal;": "⊺",
  24295. "iquest;": "¿",
  24296. "isinsv;": "⋳",
  24297. "Itilde;": "Ĩ",
  24298. "itilde;": "ĩ",
  24299. "Jsercy;": "Ј",
  24300. "jsercy;": "ј",
  24301. "kappav;": "ϰ",
  24302. "Kcedil;": "Ķ",
  24303. "kcedil;": "ķ",
  24304. "kgreen;": "ĸ",
  24305. "Lacute;": "Ĺ",
  24306. "lacute;": "ĺ",
  24307. "lagran;": "ℒ",
  24308. "Lambda;": "Λ",
  24309. "lambda;": "λ",
  24310. "langle;": "⟨",
  24311. "larrfs;": "⤝",
  24312. "larrhk;": "↩",
  24313. "larrlp;": "↫",
  24314. "larrpl;": "⤹",
  24315. "larrtl;": "↢",
  24316. "lAtail;": "⤛",
  24317. "latail;": "⤙",
  24318. "lbrace;": "{",
  24319. "lbrack;": "[",
  24320. "Lcaron;": "Ľ",
  24321. "lcaron;": "ľ",
  24322. "Lcedil;": "Ļ",
  24323. "lcedil;": "ļ",
  24324. "ldquor;": "„",
  24325. "lesdot;": "⩿",
  24326. "lesges;": "⪓",
  24327. "lfisht;": "⥼",
  24328. "lfloor;": "⌊",
  24329. "lharul;": "⥪",
  24330. "llhard;": "⥫",
  24331. "Lmidot;": "Ŀ",
  24332. "lmidot;": "ŀ",
  24333. "lmoust;": "⎰",
  24334. "loplus;": "⨭",
  24335. "lowast;": "∗",
  24336. "lowbar;": "_",
  24337. "lparlt;": "⦓",
  24338. "lrhard;": "⥭",
  24339. "lsaquo;": "‹",
  24340. "lsquor;": "‚",
  24341. "Lstrok;": "Ł",
  24342. "lstrok;": "ł",
  24343. "lthree;": "⋋",
  24344. "ltimes;": "⋉",
  24345. "ltlarr;": "⥶",
  24346. "ltrPar;": "⦖",
  24347. "mapsto;": "↦",
  24348. "marker;": "▮",
  24349. "mcomma;": "⨩",
  24350. "midast;": "*",
  24351. "midcir;": "⫰",
  24352. "middot;": "·",
  24353. "minusb;": "⊟",
  24354. "minusd;": "∸",
  24355. "mnplus;": "∓",
  24356. "models;": "⊧",
  24357. "mstpos;": "∾",
  24358. "Nacute;": "Ń",
  24359. "nacute;": "ń",
  24360. "nbumpe;": "≏̸",
  24361. "Ncaron;": "Ň",
  24362. "ncaron;": "ň",
  24363. "Ncedil;": "Ņ",
  24364. "ncedil;": "ņ",
  24365. "nearhk;": "⤤",
  24366. "nequiv;": "≢",
  24367. "nesear;": "⤨",
  24368. "nexist;": "∄",
  24369. "nltrie;": "⋬",
  24370. "notinE;": "⋹̸",
  24371. "nparsl;": "⫽⃥",
  24372. "nprcue;": "⋠",
  24373. "nrarrc;": "⤳̸",
  24374. "nrarrw;": "↝̸",
  24375. "nrtrie;": "⋭",
  24376. "nsccue;": "⋡",
  24377. "nsimeq;": "≄",
  24378. "Ntilde;": "Ñ",
  24379. "ntilde;": "ñ",
  24380. "numero;": "№",
  24381. "nVDash;": "⊯",
  24382. "nVdash;": "⊮",
  24383. "nvDash;": "⊭",
  24384. "nvdash;": "⊬",
  24385. "nvHarr;": "⤄",
  24386. "nvlArr;": "⤂",
  24387. "nvrArr;": "⤃",
  24388. "nwarhk;": "⤣",
  24389. "nwnear;": "⤧",
  24390. "Oacute;": "Ó",
  24391. "oacute;": "ó",
  24392. "Odblac;": "Ő",
  24393. "odblac;": "ő",
  24394. "odsold;": "⦼",
  24395. "Ograve;": "Ò",
  24396. "ograve;": "ò",
  24397. "ominus;": "⊖",
  24398. "origof;": "⊶",
  24399. "Oslash;": "Ø",
  24400. "oslash;": "ø",
  24401. "Otilde;": "Õ",
  24402. "otilde;": "õ",
  24403. "Otimes;": "⨷",
  24404. "otimes;": "⊗",
  24405. "parsim;": "⫳",
  24406. "percnt;": "%",
  24407. "period;": ".",
  24408. "permil;": "‰",
  24409. "phmmat;": "ℳ",
  24410. "planck;": "ℏ",
  24411. "plankv;": "ℏ",
  24412. "plusdo;": "∔",
  24413. "plusdu;": "⨥",
  24414. "plusmn;": "±",
  24415. "preceq;": "⪯",
  24416. "primes;": "ℙ",
  24417. "prnsim;": "⋨",
  24418. "propto;": "∝",
  24419. "prurel;": "⊰",
  24420. "puncsp;": " ",
  24421. "qprime;": "⁗",
  24422. "Racute;": "Ŕ",
  24423. "racute;": "ŕ",
  24424. "rangle;": "⟩",
  24425. "rarrap;": "⥵",
  24426. "rarrfs;": "⤞",
  24427. "rarrhk;": "↪",
  24428. "rarrlp;": "↬",
  24429. "rarrpl;": "⥅",
  24430. "Rarrtl;": "⤖",
  24431. "rarrtl;": "↣",
  24432. "rAtail;": "⤜",
  24433. "ratail;": "⤚",
  24434. "rbrace;": "}",
  24435. "rbrack;": "]",
  24436. "Rcaron;": "Ř",
  24437. "rcaron;": "ř",
  24438. "Rcedil;": "Ŗ",
  24439. "rcedil;": "ŗ",
  24440. "rdquor;": "”",
  24441. "rfisht;": "⥽",
  24442. "rfloor;": "⌋",
  24443. "rharul;": "⥬",
  24444. "rmoust;": "⎱",
  24445. "roplus;": "⨮",
  24446. "rpargt;": "⦔",
  24447. "rsaquo;": "›",
  24448. "rsquor;": "’",
  24449. "rthree;": "⋌",
  24450. "rtimes;": "⋊",
  24451. "Sacute;": "Ś",
  24452. "sacute;": "ś",
  24453. "Scaron;": "Š",
  24454. "scaron;": "š",
  24455. "Scedil;": "Ş",
  24456. "scedil;": "ş",
  24457. "scnsim;": "⋩",
  24458. "searhk;": "⤥",
  24459. "seswar;": "⤩",
  24460. "sfrown;": "⌢",
  24461. "SHCHcy;": "Щ",
  24462. "shchcy;": "щ",
  24463. "sigmaf;": "ς",
  24464. "sigmav;": "ς",
  24465. "simdot;": "⩪",
  24466. "smashp;": "⨳",
  24467. "SOFTcy;": "Ь",
  24468. "softcy;": "ь",
  24469. "solbar;": "⌿",
  24470. "spades;": "♠",
  24471. "sqcaps;": "⊓︀",
  24472. "sqcups;": "⊔︀",
  24473. "sqsube;": "⊑",
  24474. "sqsupe;": "⊒",
  24475. "Square;": "□",
  24476. "square;": "□",
  24477. "squarf;": "▪",
  24478. "ssetmn;": "∖",
  24479. "ssmile;": "⌣",
  24480. "sstarf;": "⋆",
  24481. "subdot;": "⪽",
  24482. "Subset;": "⋐",
  24483. "subset;": "⊂",
  24484. "subsim;": "⫇",
  24485. "subsub;": "⫕",
  24486. "subsup;": "⫓",
  24487. "succeq;": "⪰",
  24488. "supdot;": "⪾",
  24489. "Supset;": "⋑",
  24490. "supset;": "⊃",
  24491. "supsim;": "⫈",
  24492. "supsub;": "⫔",
  24493. "supsup;": "⫖",
  24494. "swarhk;": "⤦",
  24495. "swnwar;": "⤪",
  24496. "target;": "⌖",
  24497. "Tcaron;": "Ť",
  24498. "tcaron;": "ť",
  24499. "Tcedil;": "Ţ",
  24500. "tcedil;": "ţ",
  24501. "telrec;": "⌕",
  24502. "there4;": "∴",
  24503. "thetav;": "ϑ",
  24504. "thinsp;": " ",
  24505. "thksim;": "∼",
  24506. "timesb;": "⊠",
  24507. "timesd;": "⨰",
  24508. "topbot;": "⌶",
  24509. "topcir;": "⫱",
  24510. "tprime;": "‴",
  24511. "tridot;": "◬",
  24512. "Tstrok;": "Ŧ",
  24513. "tstrok;": "ŧ",
  24514. "Uacute;": "Ú",
  24515. "uacute;": "ú",
  24516. "Ubreve;": "Ŭ",
  24517. "ubreve;": "ŭ",
  24518. "Udblac;": "Ű",
  24519. "udblac;": "ű",
  24520. "ufisht;": "⥾",
  24521. "Ugrave;": "Ù",
  24522. "ugrave;": "ù",
  24523. "ulcorn;": "⌜",
  24524. "ulcrop;": "⌏",
  24525. "urcorn;": "⌝",
  24526. "urcrop;": "⌎",
  24527. "Utilde;": "Ũ",
  24528. "utilde;": "ũ",
  24529. "vangrt;": "⦜",
  24530. "varphi;": "ϕ",
  24531. "varrho;": "ϱ",
  24532. "Vdashl;": "⫦",
  24533. "veebar;": "⊻",
  24534. "vellip;": "⋮",
  24535. "Verbar;": "‖",
  24536. "verbar;": "|",
  24537. "vsubnE;": "⫋︀",
  24538. "vsubne;": "⊊︀",
  24539. "vsupnE;": "⫌︀",
  24540. "vsupne;": "⊋︀",
  24541. "Vvdash;": "⊪",
  24542. "wedbar;": "⩟",
  24543. "wedgeq;": "≙",
  24544. "weierp;": "℘",
  24545. "wreath;": "≀",
  24546. "xoplus;": "⨁",
  24547. "xotime;": "⨂",
  24548. "xsqcup;": "⨆",
  24549. "xuplus;": "⨄",
  24550. "xwedge;": "⋀",
  24551. "Yacute;": "Ý",
  24552. "yacute;": "ý",
  24553. "Zacute;": "Ź",
  24554. "zacute;": "ź",
  24555. "Zcaron;": "Ž",
  24556. "zcaron;": "ž",
  24557. "zeetrf;": "ℨ",
  24558. "alefsym;": "ℵ",
  24559. "angrtvb;": "⊾",
  24560. "angzarr;": "⍼",
  24561. "asympeq;": "≍",
  24562. "backsim;": "∽",
  24563. "Because;": "∵",
  24564. "because;": "∵",
  24565. "bemptyv;": "⦰",
  24566. "between;": "≬",
  24567. "bigcirc;": "◯",
  24568. "bigodot;": "⨀",
  24569. "bigstar;": "★",
  24570. "bnequiv;": "≡⃥",
  24571. "boxplus;": "⊞",
  24572. "Cayleys;": "ℭ",
  24573. "Cconint;": "∰",
  24574. "ccupssm;": "⩐",
  24575. "Cedilla;": "¸",
  24576. "cemptyv;": "⦲",
  24577. "cirscir;": "⧂",
  24578. "coloneq;": "≔",
  24579. "congdot;": "⩭",
  24580. "cudarrl;": "⤸",
  24581. "cudarrr;": "⤵",
  24582. "cularrp;": "⤽",
  24583. "curarrm;": "⤼",
  24584. "dbkarow;": "⤏",
  24585. "ddagger;": "‡",
  24586. "ddotseq;": "⩷",
  24587. "demptyv;": "⦱",
  24588. "Diamond;": "⋄",
  24589. "diamond;": "⋄",
  24590. "digamma;": "ϝ",
  24591. "dotplus;": "∔",
  24592. "DownTee;": "⊤",
  24593. "dwangle;": "⦦",
  24594. "Element;": "∈",
  24595. "Epsilon;": "Ε",
  24596. "epsilon;": "ε",
  24597. "eqcolon;": "≕",
  24598. "equivDD;": "⩸",
  24599. "gesdoto;": "⪂",
  24600. "gtquest;": "⩼",
  24601. "gtrless;": "≷",
  24602. "harrcir;": "⥈",
  24603. "Implies;": "⇒",
  24604. "intprod;": "⨼",
  24605. "isindot;": "⋵",
  24606. "larrbfs;": "⤟",
  24607. "larrsim;": "⥳",
  24608. "lbrksld;": "⦏",
  24609. "lbrkslu;": "⦍",
  24610. "ldrdhar;": "⥧",
  24611. "LeftTee;": "⊣",
  24612. "lesdoto;": "⪁",
  24613. "lessdot;": "⋖",
  24614. "lessgtr;": "≶",
  24615. "lesssim;": "≲",
  24616. "lotimes;": "⨴",
  24617. "lozenge;": "◊",
  24618. "ltquest;": "⩻",
  24619. "luruhar;": "⥦",
  24620. "maltese;": "✠",
  24621. "minusdu;": "⨪",
  24622. "napprox;": "≉",
  24623. "natural;": "♮",
  24624. "nearrow;": "↗",
  24625. "NewLine;": "\n",
  24626. "nexists;": "∄",
  24627. "NoBreak;": "⁠",
  24628. "notinva;": "∉",
  24629. "notinvb;": "⋷",
  24630. "notinvc;": "⋶",
  24631. "NotLess;": "≮",
  24632. "notniva;": "∌",
  24633. "notnivb;": "⋾",
  24634. "notnivc;": "⋽",
  24635. "npolint;": "⨔",
  24636. "npreceq;": "⪯̸",
  24637. "nsqsube;": "⋢",
  24638. "nsqsupe;": "⋣",
  24639. "nsubset;": "⊂⃒",
  24640. "nsucceq;": "⪰̸",
  24641. "nsupset;": "⊃⃒",
  24642. "nvinfin;": "⧞",
  24643. "nvltrie;": "⊴⃒",
  24644. "nvrtrie;": "⊵⃒",
  24645. "nwarrow;": "↖",
  24646. "olcross;": "⦻",
  24647. "Omicron;": "Ο",
  24648. "omicron;": "ο",
  24649. "orderof;": "ℴ",
  24650. "orslope;": "⩗",
  24651. "OverBar;": "‾",
  24652. "pertenk;": "‱",
  24653. "planckh;": "ℎ",
  24654. "pluscir;": "⨢",
  24655. "plussim;": "⨦",
  24656. "plustwo;": "⨧",
  24657. "precsim;": "≾",
  24658. "Product;": "∏",
  24659. "quatint;": "⨖",
  24660. "questeq;": "≟",
  24661. "rarrbfs;": "⤠",
  24662. "rarrsim;": "⥴",
  24663. "rbrksld;": "⦎",
  24664. "rbrkslu;": "⦐",
  24665. "rdldhar;": "⥩",
  24666. "realine;": "ℛ",
  24667. "rotimes;": "⨵",
  24668. "ruluhar;": "⥨",
  24669. "searrow;": "↘",
  24670. "simplus;": "⨤",
  24671. "simrarr;": "⥲",
  24672. "subedot;": "⫃",
  24673. "submult;": "⫁",
  24674. "subplus;": "⪿",
  24675. "subrarr;": "⥹",
  24676. "succsim;": "≿",
  24677. "supdsub;": "⫘",
  24678. "supedot;": "⫄",
  24679. "suphsol;": "⟉",
  24680. "suphsub;": "⫗",
  24681. "suplarr;": "⥻",
  24682. "supmult;": "⫂",
  24683. "supplus;": "⫀",
  24684. "swarrow;": "↙",
  24685. "topfork;": "⫚",
  24686. "triplus;": "⨹",
  24687. "tritime;": "⨻",
  24688. "UpArrow;": "↑",
  24689. "Uparrow;": "⇑",
  24690. "uparrow;": "↑",
  24691. "Upsilon;": "Υ",
  24692. "upsilon;": "υ",
  24693. "uwangle;": "⦧",
  24694. "vzigzag;": "⦚",
  24695. "zigrarr;": "⇝",
  24696. "andslope;": "⩘",
  24697. "angmsdaa;": "⦨",
  24698. "angmsdab;": "⦩",
  24699. "angmsdac;": "⦪",
  24700. "angmsdad;": "⦫",
  24701. "angmsdae;": "⦬",
  24702. "angmsdaf;": "⦭",
  24703. "angmsdag;": "⦮",
  24704. "angmsdah;": "⦯",
  24705. "angrtvbd;": "⦝",
  24706. "approxeq;": "≊",
  24707. "awconint;": "∳",
  24708. "backcong;": "≌",
  24709. "barwedge;": "⌅",
  24710. "bbrktbrk;": "⎶",
  24711. "bigoplus;": "⨁",
  24712. "bigsqcup;": "⨆",
  24713. "biguplus;": "⨄",
  24714. "bigwedge;": "⋀",
  24715. "boxminus;": "⊟",
  24716. "boxtimes;": "⊠",
  24717. "bsolhsub;": "⟈",
  24718. "capbrcup;": "⩉",
  24719. "circledR;": "®",
  24720. "circledS;": "Ⓢ",
  24721. "cirfnint;": "⨐",
  24722. "clubsuit;": "♣",
  24723. "cupbrcap;": "⩈",
  24724. "curlyvee;": "⋎",
  24725. "cwconint;": "∲",
  24726. "DDotrahd;": "⤑",
  24727. "doteqdot;": "≑",
  24728. "DotEqual;": "≐",
  24729. "dotminus;": "∸",
  24730. "drbkarow;": "⤐",
  24731. "dzigrarr;": "⟿",
  24732. "elinters;": "⏧",
  24733. "emptyset;": "∅",
  24734. "eqvparsl;": "⧥",
  24735. "fpartint;": "⨍",
  24736. "geqslant;": "⩾",
  24737. "gesdotol;": "⪄",
  24738. "gnapprox;": "⪊",
  24739. "hksearow;": "⤥",
  24740. "hkswarow;": "⤦",
  24741. "imagline;": "ℐ",
  24742. "imagpart;": "ℑ",
  24743. "infintie;": "⧝",
  24744. "integers;": "ℤ",
  24745. "Integral;": "∫",
  24746. "intercal;": "⊺",
  24747. "intlarhk;": "⨗",
  24748. "laemptyv;": "⦴",
  24749. "ldrushar;": "⥋",
  24750. "leqslant;": "⩽",
  24751. "lesdotor;": "⪃",
  24752. "LessLess;": "⪡",
  24753. "llcorner;": "⌞",
  24754. "lnapprox;": "⪉",
  24755. "lrcorner;": "⌟",
  24756. "lurdshar;": "⥊",
  24757. "mapstoup;": "↥",
  24758. "multimap;": "⊸",
  24759. "naturals;": "ℕ",
  24760. "ncongdot;": "⩭̸",
  24761. "NotEqual;": "≠",
  24762. "notindot;": "⋵̸",
  24763. "NotTilde;": "≁",
  24764. "otimesas;": "⨶",
  24765. "parallel;": "∥",
  24766. "PartialD;": "∂",
  24767. "plusacir;": "⨣",
  24768. "pointint;": "⨕",
  24769. "Precedes;": "≺",
  24770. "precneqq;": "⪵",
  24771. "precnsim;": "⋨",
  24772. "profalar;": "⌮",
  24773. "profline;": "⌒",
  24774. "profsurf;": "⌓",
  24775. "raemptyv;": "⦳",
  24776. "realpart;": "ℜ",
  24777. "RightTee;": "⊢",
  24778. "rppolint;": "⨒",
  24779. "rtriltri;": "⧎",
  24780. "scpolint;": "⨓",
  24781. "setminus;": "∖",
  24782. "shortmid;": "∣",
  24783. "smeparsl;": "⧤",
  24784. "sqsubset;": "⊏",
  24785. "sqsupset;": "⊐",
  24786. "subseteq;": "⊆",
  24787. "Succeeds;": "≻",
  24788. "succneqq;": "⪶",
  24789. "succnsim;": "⋩",
  24790. "SuchThat;": "∋",
  24791. "Superset;": "⊃",
  24792. "supseteq;": "⊇",
  24793. "thetasym;": "ϑ",
  24794. "thicksim;": "∼",
  24795. "timesbar;": "⨱",
  24796. "triangle;": "▵",
  24797. "triminus;": "⨺",
  24798. "trpezium;": "⏢",
  24799. "Uarrocir;": "⥉",
  24800. "ulcorner;": "⌜",
  24801. "UnderBar;": "_",
  24802. "urcorner;": "⌝",
  24803. "varkappa;": "ϰ",
  24804. "varsigma;": "ς",
  24805. "vartheta;": "ϑ",
  24806. "backprime;": "‵",
  24807. "backsimeq;": "⋍",
  24808. "Backslash;": "∖",
  24809. "bigotimes;": "⨂",
  24810. "CenterDot;": "·",
  24811. "centerdot;": "·",
  24812. "checkmark;": "✓",
  24813. "CircleDot;": "⊙",
  24814. "complexes;": "ℂ",
  24815. "Congruent;": "≡",
  24816. "Coproduct;": "∐",
  24817. "dotsquare;": "⊡",
  24818. "DoubleDot;": "¨",
  24819. "DownArrow;": "↓",
  24820. "Downarrow;": "⇓",
  24821. "downarrow;": "↓",
  24822. "DownBreve;": "̑",
  24823. "gtrapprox;": "⪆",
  24824. "gtreqless;": "⋛",
  24825. "gvertneqq;": "≩︀",
  24826. "heartsuit;": "♥",
  24827. "HumpEqual;": "≏",
  24828. "LeftArrow;": "←",
  24829. "Leftarrow;": "⇐",
  24830. "leftarrow;": "←",
  24831. "LeftFloor;": "⌊",
  24832. "lesseqgtr;": "⋚",
  24833. "LessTilde;": "≲",
  24834. "lvertneqq;": "≨︀",
  24835. "Mellintrf;": "ℳ",
  24836. "MinusPlus;": "∓",
  24837. "ngeqslant;": "⩾̸",
  24838. "nleqslant;": "⩽̸",
  24839. "NotCupCap;": "≭",
  24840. "NotExists;": "∄",
  24841. "NotSubset;": "⊂⃒",
  24842. "nparallel;": "∦",
  24843. "nshortmid;": "∤",
  24844. "nsubseteq;": "⊈",
  24845. "nsupseteq;": "⊉",
  24846. "OverBrace;": "⏞",
  24847. "pitchfork;": "⋔",
  24848. "PlusMinus;": "±",
  24849. "rationals;": "ℚ",
  24850. "spadesuit;": "♠",
  24851. "subseteqq;": "⫅",
  24852. "subsetneq;": "⊊",
  24853. "supseteqq;": "⫆",
  24854. "supsetneq;": "⊋",
  24855. "Therefore;": "∴",
  24856. "therefore;": "∴",
  24857. "ThinSpace;": " ",
  24858. "triangleq;": "≜",
  24859. "TripleDot;": "⃛",
  24860. "UnionPlus;": "⊎",
  24861. "varpropto;": "∝",
  24862. "Bernoullis;": "ℬ",
  24863. "circledast;": "⊛",
  24864. "CirclePlus;": "⊕",
  24865. "complement;": "∁",
  24866. "curlywedge;": "⋏",
  24867. "eqslantgtr;": "⪖",
  24868. "EqualTilde;": "≂",
  24869. "Fouriertrf;": "ℱ",
  24870. "gtreqqless;": "⪌",
  24871. "ImaginaryI;": "ⅈ",
  24872. "Laplacetrf;": "ℒ",
  24873. "LeftVector;": "↼",
  24874. "lessapprox;": "⪅",
  24875. "lesseqqgtr;": "⪋",
  24876. "Lleftarrow;": "⇚",
  24877. "lmoustache;": "⎰",
  24878. "longmapsto;": "⟼",
  24879. "mapstodown;": "↧",
  24880. "mapstoleft;": "↤",
  24881. "nLeftarrow;": "⇍",
  24882. "nleftarrow;": "↚",
  24883. "NotElement;": "∉",
  24884. "NotGreater;": "≯",
  24885. "nsubseteqq;": "⫅̸",
  24886. "nsupseteqq;": "⫆̸",
  24887. "precapprox;": "⪷",
  24888. "Proportion;": "∷",
  24889. "RightArrow;": "→",
  24890. "Rightarrow;": "⇒",
  24891. "rightarrow;": "→",
  24892. "RightFloor;": "⌋",
  24893. "rmoustache;": "⎱",
  24894. "sqsubseteq;": "⊑",
  24895. "sqsupseteq;": "⊒",
  24896. "subsetneqq;": "⫋",
  24897. "succapprox;": "⪸",
  24898. "supsetneqq;": "⫌",
  24899. "ThickSpace;": "  ",
  24900. "TildeEqual;": "≃",
  24901. "TildeTilde;": "≈",
  24902. "UnderBrace;": "⏟",
  24903. "UpArrowBar;": "⤒",
  24904. "UpTeeArrow;": "↥",
  24905. "upuparrows;": "⇈",
  24906. "varepsilon;": "ϵ",
  24907. "varnothing;": "∅",
  24908. "backepsilon;": "϶",
  24909. "blacksquare;": "▪",
  24910. "circledcirc;": "⊚",
  24911. "circleddash;": "⊝",
  24912. "CircleMinus;": "⊖",
  24913. "CircleTimes;": "⊗",
  24914. "curlyeqprec;": "⋞",
  24915. "curlyeqsucc;": "⋟",
  24916. "diamondsuit;": "♦",
  24917. "eqslantless;": "⪕",
  24918. "Equilibrium;": "⇌",
  24919. "expectation;": "ℰ",
  24920. "GreaterLess;": "≷",
  24921. "LeftCeiling;": "⌈",
  24922. "LessGreater;": "≶",
  24923. "MediumSpace;": " ",
  24924. "NotLessLess;": "≪̸",
  24925. "NotPrecedes;": "⊀",
  24926. "NotSucceeds;": "⊁",
  24927. "NotSuperset;": "⊃⃒",
  24928. "nRightarrow;": "⇏",
  24929. "nrightarrow;": "↛",
  24930. "OverBracket;": "⎴",
  24931. "preccurlyeq;": "≼",
  24932. "precnapprox;": "⪹",
  24933. "quaternions;": "ℍ",
  24934. "RightVector;": "⇀",
  24935. "Rrightarrow;": "⇛",
  24936. "RuleDelayed;": "⧴",
  24937. "SmallCircle;": "∘",
  24938. "SquareUnion;": "⊔",
  24939. "straightphi;": "ϕ",
  24940. "SubsetEqual;": "⊆",
  24941. "succcurlyeq;": "≽",
  24942. "succnapprox;": "⪺",
  24943. "thickapprox;": "≈",
  24944. "UpDownArrow;": "↕",
  24945. "Updownarrow;": "⇕",
  24946. "updownarrow;": "↕",
  24947. "VerticalBar;": "∣",
  24948. "blacklozenge;": "⧫",
  24949. "DownArrowBar;": "⤓",
  24950. "DownTeeArrow;": "↧",
  24951. "ExponentialE;": "ⅇ",
  24952. "exponentiale;": "ⅇ",
  24953. "GreaterEqual;": "≥",
  24954. "GreaterTilde;": "≳",
  24955. "HilbertSpace;": "ℋ",
  24956. "HumpDownHump;": "≎",
  24957. "Intersection;": "⋂",
  24958. "LeftArrowBar;": "⇤",
  24959. "LeftTeeArrow;": "↤",
  24960. "LeftTriangle;": "⊲",
  24961. "LeftUpVector;": "↿",
  24962. "NotCongruent;": "≢",
  24963. "NotHumpEqual;": "≏̸",
  24964. "NotLessEqual;": "≰",
  24965. "NotLessTilde;": "≴",
  24966. "Proportional;": "∝",
  24967. "RightCeiling;": "⌉",
  24968. "risingdotseq;": "≓",
  24969. "RoundImplies;": "⥰",
  24970. "ShortUpArrow;": "↑",
  24971. "SquareSubset;": "⊏",
  24972. "triangledown;": "▿",
  24973. "triangleleft;": "◃",
  24974. "UnderBracket;": "⎵",
  24975. "varsubsetneq;": "⊊︀",
  24976. "varsupsetneq;": "⊋︀",
  24977. "VerticalLine;": "|",
  24978. "ApplyFunction;": "⁡",
  24979. "bigtriangleup;": "△",
  24980. "blacktriangle;": "▴",
  24981. "DifferentialD;": "ⅆ",
  24982. "divideontimes;": "⋇",
  24983. "DoubleLeftTee;": "⫤",
  24984. "DoubleUpArrow;": "⇑",
  24985. "fallingdotseq;": "≒",
  24986. "hookleftarrow;": "↩",
  24987. "leftarrowtail;": "↢",
  24988. "leftharpoonup;": "↼",
  24989. "LeftTeeVector;": "⥚",
  24990. "LeftVectorBar;": "⥒",
  24991. "LessFullEqual;": "≦",
  24992. "LongLeftArrow;": "⟵",
  24993. "Longleftarrow;": "⟸",
  24994. "longleftarrow;": "⟵",
  24995. "looparrowleft;": "↫",
  24996. "measuredangle;": "∡",
  24997. "NotEqualTilde;": "≂̸",
  24998. "NotTildeEqual;": "≄",
  24999. "NotTildeTilde;": "≉",
  25000. "ntriangleleft;": "⋪",
  25001. "Poincareplane;": "ℌ",
  25002. "PrecedesEqual;": "⪯",
  25003. "PrecedesTilde;": "≾",
  25004. "RightArrowBar;": "⇥",
  25005. "RightTeeArrow;": "↦",
  25006. "RightTriangle;": "⊳",
  25007. "RightUpVector;": "↾",
  25008. "shortparallel;": "∥",
  25009. "smallsetminus;": "∖",
  25010. "SucceedsEqual;": "⪰",
  25011. "SucceedsTilde;": "≿",
  25012. "SupersetEqual;": "⊇",
  25013. "triangleright;": "▹",
  25014. "UpEquilibrium;": "⥮",
  25015. "upharpoonleft;": "↿",
  25016. "varsubsetneqq;": "⫋︀",
  25017. "varsupsetneqq;": "⫌︀",
  25018. "VerticalTilde;": "≀",
  25019. "VeryThinSpace;": " ",
  25020. "curvearrowleft;": "↶",
  25021. "DiacriticalDot;": "˙",
  25022. "doublebarwedge;": "⌆",
  25023. "DoubleRightTee;": "⊨",
  25024. "downdownarrows;": "⇊",
  25025. "DownLeftVector;": "↽",
  25026. "GreaterGreater;": "⪢",
  25027. "hookrightarrow;": "↪",
  25028. "HorizontalLine;": "─",
  25029. "InvisibleComma;": "⁣",
  25030. "InvisibleTimes;": "⁢",
  25031. "LeftDownVector;": "⇃",
  25032. "leftleftarrows;": "⇇",
  25033. "LeftRightArrow;": "↔",
  25034. "Leftrightarrow;": "⇔",
  25035. "leftrightarrow;": "↔",
  25036. "leftthreetimes;": "⋋",
  25037. "LessSlantEqual;": "⩽",
  25038. "LongRightArrow;": "⟶",
  25039. "Longrightarrow;": "⟹",
  25040. "longrightarrow;": "⟶",
  25041. "looparrowright;": "↬",
  25042. "LowerLeftArrow;": "↙",
  25043. "NestedLessLess;": "≪",
  25044. "NotGreaterLess;": "≹",
  25045. "NotLessGreater;": "≸",
  25046. "NotSubsetEqual;": "⊈",
  25047. "NotVerticalBar;": "∤",
  25048. "nshortparallel;": "∦",
  25049. "ntriangleright;": "⋫",
  25050. "OpenCurlyQuote;": "‘",
  25051. "ReverseElement;": "∋",
  25052. "rightarrowtail;": "↣",
  25053. "rightharpoonup;": "⇀",
  25054. "RightTeeVector;": "⥛",
  25055. "RightVectorBar;": "⥓",
  25056. "ShortDownArrow;": "↓",
  25057. "ShortLeftArrow;": "←",
  25058. "SquareSuperset;": "⊐",
  25059. "TildeFullEqual;": "≅",
  25060. "trianglelefteq;": "⊴",
  25061. "upharpoonright;": "↾",
  25062. "UpperLeftArrow;": "↖",
  25063. "ZeroWidthSpace;": "​",
  25064. "bigtriangledown;": "▽",
  25065. "circlearrowleft;": "↺",
  25066. "CloseCurlyQuote;": "’",
  25067. "ContourIntegral;": "∮",
  25068. "curvearrowright;": "↷",
  25069. "DoubleDownArrow;": "⇓",
  25070. "DoubleLeftArrow;": "⇐",
  25071. "downharpoonleft;": "⇃",
  25072. "DownRightVector;": "⇁",
  25073. "leftharpoondown;": "↽",
  25074. "leftrightarrows;": "⇆",
  25075. "LeftRightVector;": "⥎",
  25076. "LeftTriangleBar;": "⧏",
  25077. "LeftUpTeeVector;": "⥠",
  25078. "LeftUpVectorBar;": "⥘",
  25079. "LowerRightArrow;": "↘",
  25080. "nLeftrightarrow;": "⇎",
  25081. "nleftrightarrow;": "↮",
  25082. "NotGreaterEqual;": "≱",
  25083. "NotGreaterTilde;": "≵",
  25084. "NotHumpDownHump;": "≎̸",
  25085. "NotLeftTriangle;": "⋪",
  25086. "NotSquareSubset;": "⊏̸",
  25087. "ntrianglelefteq;": "⋬",
  25088. "OverParenthesis;": "⏜",
  25089. "RightDownVector;": "⇂",
  25090. "rightleftarrows;": "⇄",
  25091. "rightsquigarrow;": "↝",
  25092. "rightthreetimes;": "⋌",
  25093. "ShortRightArrow;": "→",
  25094. "straightepsilon;": "ϵ",
  25095. "trianglerighteq;": "⊵",
  25096. "UpperRightArrow;": "↗",
  25097. "vartriangleleft;": "⊲",
  25098. "circlearrowright;": "↻",
  25099. "DiacriticalAcute;": "´",
  25100. "DiacriticalGrave;": "`",
  25101. "DiacriticalTilde;": "˜",
  25102. "DoubleRightArrow;": "⇒",
  25103. "DownArrowUpArrow;": "⇵",
  25104. "downharpoonright;": "⇂",
  25105. "EmptySmallSquare;": "◻",
  25106. "GreaterEqualLess;": "⋛",
  25107. "GreaterFullEqual;": "≧",
  25108. "LeftAngleBracket;": "⟨",
  25109. "LeftUpDownVector;": "⥑",
  25110. "LessEqualGreater;": "⋚",
  25111. "NonBreakingSpace;": " ",
  25112. "NotPrecedesEqual;": "⪯̸",
  25113. "NotRightTriangle;": "⋫",
  25114. "NotSucceedsEqual;": "⪰̸",
  25115. "NotSucceedsTilde;": "≿̸",
  25116. "NotSupersetEqual;": "⊉",
  25117. "ntrianglerighteq;": "⋭",
  25118. "rightharpoondown;": "⇁",
  25119. "rightrightarrows;": "⇉",
  25120. "RightTriangleBar;": "⧐",
  25121. "RightUpTeeVector;": "⥜",
  25122. "RightUpVectorBar;": "⥔",
  25123. "twoheadleftarrow;": "↞",
  25124. "UnderParenthesis;": "⏝",
  25125. "UpArrowDownArrow;": "⇅",
  25126. "vartriangleright;": "⊳",
  25127. "blacktriangledown;": "▾",
  25128. "blacktriangleleft;": "◂",
  25129. "DoubleUpDownArrow;": "⇕",
  25130. "DoubleVerticalBar;": "∥",
  25131. "DownLeftTeeVector;": "⥞",
  25132. "DownLeftVectorBar;": "⥖",
  25133. "FilledSmallSquare;": "◼",
  25134. "GreaterSlantEqual;": "⩾",
  25135. "LeftDoubleBracket;": "⟦",
  25136. "LeftDownTeeVector;": "⥡",
  25137. "LeftDownVectorBar;": "⥙",
  25138. "leftrightharpoons;": "⇋",
  25139. "LeftTriangleEqual;": "⊴",
  25140. "NegativeThinSpace;": "​",
  25141. "NotGreaterGreater;": "≫̸",
  25142. "NotLessSlantEqual;": "⩽̸",
  25143. "NotNestedLessLess;": "⪡̸",
  25144. "NotReverseElement;": "∌",
  25145. "NotSquareSuperset;": "⊐̸",
  25146. "NotTildeFullEqual;": "≇",
  25147. "RightAngleBracket;": "⟩",
  25148. "rightleftharpoons;": "⇌",
  25149. "RightUpDownVector;": "⥏",
  25150. "SquareSubsetEqual;": "⊑",
  25151. "twoheadrightarrow;": "↠",
  25152. "VerticalSeparator;": "❘",
  25153. "blacktriangleright;": "▸",
  25154. "DownRightTeeVector;": "⥟",
  25155. "DownRightVectorBar;": "⥗",
  25156. "LongLeftRightArrow;": "⟷",
  25157. "Longleftrightarrow;": "⟺",
  25158. "longleftrightarrow;": "⟷",
  25159. "NegativeThickSpace;": "​",
  25160. "NotLeftTriangleBar;": "⧏̸",
  25161. "PrecedesSlantEqual;": "≼",
  25162. "ReverseEquilibrium;": "⇋",
  25163. "RightDoubleBracket;": "⟧",
  25164. "RightDownTeeVector;": "⥝",
  25165. "RightDownVectorBar;": "⥕",
  25166. "RightTriangleEqual;": "⊵",
  25167. "SquareIntersection;": "⊓",
  25168. "SucceedsSlantEqual;": "≽",
  25169. "DoubleLongLeftArrow;": "⟸",
  25170. "DownLeftRightVector;": "⥐",
  25171. "LeftArrowRightArrow;": "⇆",
  25172. "leftrightsquigarrow;": "↭",
  25173. "NegativeMediumSpace;": "​",
  25174. "NotGreaterFullEqual;": "≧̸",
  25175. "NotRightTriangleBar;": "⧐̸",
  25176. "RightArrowLeftArrow;": "⇄",
  25177. "SquareSupersetEqual;": "⊒",
  25178. "CapitalDifferentialD;": "ⅅ",
  25179. "DoubleLeftRightArrow;": "⇔",
  25180. "DoubleLongRightArrow;": "⟹",
  25181. "EmptyVerySmallSquare;": "▫",
  25182. "NestedGreaterGreater;": "≫",
  25183. "NotDoubleVerticalBar;": "∦",
  25184. "NotGreaterSlantEqual;": "⩾̸",
  25185. "NotLeftTriangleEqual;": "⋬",
  25186. "NotSquareSubsetEqual;": "⋢",
  25187. "OpenCurlyDoubleQuote;": "“",
  25188. "ReverseUpEquilibrium;": "⥯",
  25189. "CloseCurlyDoubleQuote;": "”",
  25190. "DoubleContourIntegral;": "∯",
  25191. "FilledVerySmallSquare;": "▪",
  25192. "NegativeVeryThinSpace;": "​",
  25193. "NotPrecedesSlantEqual;": "⋠",
  25194. "NotRightTriangleEqual;": "⋭",
  25195. "NotSucceedsSlantEqual;": "⋡",
  25196. "DiacriticalDoubleAcute;": "˝",
  25197. "NotSquareSupersetEqual;": "⋣",
  25198. "NotNestedGreaterGreater;": "⪢̸",
  25199. "ClockwiseContourIntegral;": "∲",
  25200. "DoubleLongLeftRightArrow;": "⟺",
  25201. "CounterClockwiseContourIntegral;": "∳"
  25202. };
  25203. let maxCRNameLength;
  25204. const decodeHtml = (rawText, asAttr) => {
  25205. let offset = 0;
  25206. const end = rawText.length;
  25207. let decodedText = "";
  25208. function advance(length) {
  25209. offset += length;
  25210. rawText = rawText.slice(length);
  25211. }
  25212. while (offset < end) {
  25213. const head = /&(?:#x?)?/i.exec(rawText);
  25214. if (!head || offset + head.index >= end) {
  25215. const remaining = end - offset;
  25216. decodedText += rawText.slice(0, remaining);
  25217. advance(remaining);
  25218. break;
  25219. }
  25220. decodedText += rawText.slice(0, head.index);
  25221. advance(head.index);
  25222. if (head[0] === "&") {
  25223. let name = "";
  25224. let value = void 0;
  25225. if (/[0-9a-z]/i.test(rawText[1])) {
  25226. if (!maxCRNameLength) {
  25227. maxCRNameLength = Object.keys(namedCharacterReferences).reduce(
  25228. (max, name2) => Math.max(max, name2.length),
  25229. 0
  25230. );
  25231. }
  25232. for (let length = maxCRNameLength; !value && length > 0; --length) {
  25233. name = rawText.slice(1, 1 + length);
  25234. value = namedCharacterReferences[name];
  25235. }
  25236. if (value) {
  25237. const semi = name.endsWith(";");
  25238. if (asAttr && !semi && /[=a-z0-9]/i.test(rawText[name.length + 1] || "")) {
  25239. decodedText += "&" + name;
  25240. advance(1 + name.length);
  25241. } else {
  25242. decodedText += value;
  25243. advance(1 + name.length);
  25244. }
  25245. } else {
  25246. decodedText += "&" + name;
  25247. advance(1 + name.length);
  25248. }
  25249. } else {
  25250. decodedText += "&";
  25251. advance(1);
  25252. }
  25253. } else {
  25254. const hex = head[0] === "&#x";
  25255. const pattern = hex ? /^&#x([0-9a-f]+);?/i : /^&#([0-9]+);?/;
  25256. const body = pattern.exec(rawText);
  25257. if (!body) {
  25258. decodedText += head[0];
  25259. advance(head[0].length);
  25260. } else {
  25261. let cp = Number.parseInt(body[1], hex ? 16 : 10);
  25262. if (cp === 0) {
  25263. cp = 65533;
  25264. } else if (cp > 1114111) {
  25265. cp = 65533;
  25266. } else if (cp >= 55296 && cp <= 57343) {
  25267. cp = 65533;
  25268. } else if (cp >= 64976 && cp <= 65007 || (cp & 65534) === 65534) ; else if (cp >= 1 && cp <= 8 || cp === 11 || cp >= 13 && cp <= 31 || cp >= 127 && cp <= 159) {
  25269. cp = CCR_REPLACEMENTS[cp] || cp;
  25270. }
  25271. decodedText += String.fromCodePoint(cp);
  25272. advance(body[0].length);
  25273. }
  25274. }
  25275. }
  25276. return decodedText;
  25277. };
  25278. const CCR_REPLACEMENTS = {
  25279. 128: 8364,
  25280. 130: 8218,
  25281. 131: 402,
  25282. 132: 8222,
  25283. 133: 8230,
  25284. 134: 8224,
  25285. 135: 8225,
  25286. 136: 710,
  25287. 137: 8240,
  25288. 138: 352,
  25289. 139: 8249,
  25290. 140: 338,
  25291. 142: 381,
  25292. 145: 8216,
  25293. 146: 8217,
  25294. 147: 8220,
  25295. 148: 8221,
  25296. 149: 8226,
  25297. 150: 8211,
  25298. 151: 8212,
  25299. 152: 732,
  25300. 153: 8482,
  25301. 154: 353,
  25302. 155: 8250,
  25303. 156: 339,
  25304. 158: 382,
  25305. 159: 376
  25306. };
  25307. const isRawTextContainer = /* @__PURE__ */ makeMap(
  25308. "style,iframe,script,noscript",
  25309. true
  25310. );
  25311. const parserOptions = {
  25312. isVoidTag,
  25313. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  25314. isPreTag: (tag) => tag === "pre",
  25315. decodeEntities: decodeHtml,
  25316. isBuiltInComponent: (tag) => {
  25317. if (isBuiltInType(tag, `Transition`)) {
  25318. return TRANSITION;
  25319. } else if (isBuiltInType(tag, `TransitionGroup`)) {
  25320. return TRANSITION_GROUP;
  25321. }
  25322. },
  25323. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  25324. getNamespace(tag, parent) {
  25325. let ns = parent ? parent.ns : 0;
  25326. if (parent && ns === 2) {
  25327. if (parent.tag === "annotation-xml") {
  25328. if (tag === "svg") {
  25329. return 1;
  25330. }
  25331. if (parent.props.some(
  25332. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  25333. )) {
  25334. ns = 0;
  25335. }
  25336. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  25337. ns = 0;
  25338. }
  25339. } else if (parent && ns === 1) {
  25340. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  25341. ns = 0;
  25342. }
  25343. }
  25344. if (ns === 0) {
  25345. if (tag === "svg") {
  25346. return 1;
  25347. }
  25348. if (tag === "math") {
  25349. return 2;
  25350. }
  25351. }
  25352. return ns;
  25353. },
  25354. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  25355. getTextMode({ tag, ns }) {
  25356. if (ns === 0) {
  25357. if (tag === "textarea" || tag === "title") {
  25358. return 1;
  25359. }
  25360. if (isRawTextContainer(tag)) {
  25361. return 2;
  25362. }
  25363. }
  25364. return 0;
  25365. }
  25366. };
  25367. const transformStyle = (node) => {
  25368. if (node.type === 1) {
  25369. node.props.forEach((p, i) => {
  25370. if (p.type === 6 && p.name === "style" && p.value) {
  25371. node.props[i] = {
  25372. type: 7,
  25373. name: `bind`,
  25374. arg: createSimpleExpression(`style`, true, p.loc),
  25375. exp: parseInlineCSS(p.value.content, p.loc),
  25376. modifiers: [],
  25377. loc: p.loc
  25378. };
  25379. }
  25380. });
  25381. }
  25382. };
  25383. const parseInlineCSS = (cssText, loc) => {
  25384. const normalized = parseStringStyle(cssText);
  25385. return createSimpleExpression(
  25386. JSON.stringify(normalized),
  25387. false,
  25388. loc,
  25389. 3
  25390. );
  25391. };
  25392. function createDOMCompilerError(code, loc) {
  25393. return createCompilerError(
  25394. code,
  25395. loc,
  25396. DOMErrorMessages
  25397. );
  25398. }
  25399. const DOMErrorMessages = {
  25400. [53]: `v-html is missing expression.`,
  25401. [54]: `v-html will override element children.`,
  25402. [55]: `v-text is missing expression.`,
  25403. [56]: `v-text will override element children.`,
  25404. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  25405. [58]: `v-model argument is not supported on plain elements.`,
  25406. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  25407. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  25408. [61]: `v-show is missing expression.`,
  25409. [62]: `<Transition> expects exactly one child element or component.`,
  25410. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  25411. };
  25412. const transformVHtml = (dir, node, context) => {
  25413. const { exp, loc } = dir;
  25414. if (!exp) {
  25415. context.onError(
  25416. createDOMCompilerError(53, loc)
  25417. );
  25418. }
  25419. if (node.children.length) {
  25420. context.onError(
  25421. createDOMCompilerError(54, loc)
  25422. );
  25423. node.children.length = 0;
  25424. }
  25425. return {
  25426. props: [
  25427. createObjectProperty(
  25428. createSimpleExpression(`innerHTML`, true, loc),
  25429. exp || createSimpleExpression("", true)
  25430. )
  25431. ]
  25432. };
  25433. };
  25434. const transformVText = (dir, node, context) => {
  25435. const { exp, loc } = dir;
  25436. if (!exp) {
  25437. context.onError(
  25438. createDOMCompilerError(55, loc)
  25439. );
  25440. }
  25441. if (node.children.length) {
  25442. context.onError(
  25443. createDOMCompilerError(56, loc)
  25444. );
  25445. node.children.length = 0;
  25446. }
  25447. return {
  25448. props: [
  25449. createObjectProperty(
  25450. createSimpleExpression(`textContent`, true),
  25451. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  25452. context.helperString(TO_DISPLAY_STRING),
  25453. [exp],
  25454. loc
  25455. ) : createSimpleExpression("", true)
  25456. )
  25457. ]
  25458. };
  25459. };
  25460. const transformModel = (dir, node, context) => {
  25461. const baseResult = transformModel$1(dir, node, context);
  25462. if (!baseResult.props.length || node.tagType === 1) {
  25463. return baseResult;
  25464. }
  25465. if (dir.arg) {
  25466. context.onError(
  25467. createDOMCompilerError(
  25468. 58,
  25469. dir.arg.loc
  25470. )
  25471. );
  25472. }
  25473. function checkDuplicatedValue() {
  25474. const value = findDir(node, "bind");
  25475. if (value && isStaticArgOf(value.arg, "value")) {
  25476. context.onError(
  25477. createDOMCompilerError(
  25478. 60,
  25479. value.loc
  25480. )
  25481. );
  25482. }
  25483. }
  25484. const { tag } = node;
  25485. const isCustomElement = context.isCustomElement(tag);
  25486. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  25487. let directiveToUse = V_MODEL_TEXT;
  25488. let isInvalidType = false;
  25489. if (tag === "input" || isCustomElement) {
  25490. const type = findProp(node, `type`);
  25491. if (type) {
  25492. if (type.type === 7) {
  25493. directiveToUse = V_MODEL_DYNAMIC;
  25494. } else if (type.value) {
  25495. switch (type.value.content) {
  25496. case "radio":
  25497. directiveToUse = V_MODEL_RADIO;
  25498. break;
  25499. case "checkbox":
  25500. directiveToUse = V_MODEL_CHECKBOX;
  25501. break;
  25502. case "file":
  25503. isInvalidType = true;
  25504. context.onError(
  25505. createDOMCompilerError(
  25506. 59,
  25507. dir.loc
  25508. )
  25509. );
  25510. break;
  25511. default:
  25512. checkDuplicatedValue();
  25513. break;
  25514. }
  25515. }
  25516. } else if (hasDynamicKeyVBind(node)) {
  25517. directiveToUse = V_MODEL_DYNAMIC;
  25518. } else {
  25519. checkDuplicatedValue();
  25520. }
  25521. } else if (tag === "select") {
  25522. directiveToUse = V_MODEL_SELECT;
  25523. } else {
  25524. checkDuplicatedValue();
  25525. }
  25526. if (!isInvalidType) {
  25527. baseResult.needRuntime = context.helper(directiveToUse);
  25528. }
  25529. } else {
  25530. context.onError(
  25531. createDOMCompilerError(
  25532. 57,
  25533. dir.loc
  25534. )
  25535. );
  25536. }
  25537. baseResult.props = baseResult.props.filter(
  25538. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  25539. );
  25540. return baseResult;
  25541. };
  25542. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  25543. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  25544. // event propagation management
  25545. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  25546. );
  25547. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  25548. const isKeyboardEvent = /* @__PURE__ */ makeMap(
  25549. `onkeyup,onkeydown,onkeypress`,
  25550. true
  25551. );
  25552. const resolveModifiers = (key, modifiers, context, loc) => {
  25553. const keyModifiers = [];
  25554. const nonKeyModifiers = [];
  25555. const eventOptionModifiers = [];
  25556. for (let i = 0; i < modifiers.length; i++) {
  25557. const modifier = modifiers[i];
  25558. if (isEventOptionModifier(modifier)) {
  25559. eventOptionModifiers.push(modifier);
  25560. } else {
  25561. if (maybeKeyModifier(modifier)) {
  25562. if (isStaticExp(key)) {
  25563. if (isKeyboardEvent(key.content)) {
  25564. keyModifiers.push(modifier);
  25565. } else {
  25566. nonKeyModifiers.push(modifier);
  25567. }
  25568. } else {
  25569. keyModifiers.push(modifier);
  25570. nonKeyModifiers.push(modifier);
  25571. }
  25572. } else {
  25573. if (isNonKeyModifier(modifier)) {
  25574. nonKeyModifiers.push(modifier);
  25575. } else {
  25576. keyModifiers.push(modifier);
  25577. }
  25578. }
  25579. }
  25580. }
  25581. return {
  25582. keyModifiers,
  25583. nonKeyModifiers,
  25584. eventOptionModifiers
  25585. };
  25586. };
  25587. const transformClick = (key, event) => {
  25588. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  25589. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  25590. `(`,
  25591. key,
  25592. `) === "onClick" ? "${event}" : (`,
  25593. key,
  25594. `)`
  25595. ]) : key;
  25596. };
  25597. const transformOn = (dir, node, context) => {
  25598. return transformOn$1(dir, node, context, (baseResult) => {
  25599. const { modifiers } = dir;
  25600. if (!modifiers.length)
  25601. return baseResult;
  25602. let { key, value: handlerExp } = baseResult.props[0];
  25603. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  25604. if (nonKeyModifiers.includes("right")) {
  25605. key = transformClick(key, `onContextmenu`);
  25606. }
  25607. if (nonKeyModifiers.includes("middle")) {
  25608. key = transformClick(key, `onMouseup`);
  25609. }
  25610. if (nonKeyModifiers.length) {
  25611. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  25612. handlerExp,
  25613. JSON.stringify(nonKeyModifiers)
  25614. ]);
  25615. }
  25616. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  25617. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  25618. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  25619. handlerExp,
  25620. JSON.stringify(keyModifiers)
  25621. ]);
  25622. }
  25623. if (eventOptionModifiers.length) {
  25624. const modifierPostfix = eventOptionModifiers.map(capitalize$1).join("");
  25625. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  25626. }
  25627. return {
  25628. props: [createObjectProperty(key, handlerExp)]
  25629. };
  25630. });
  25631. };
  25632. const transformShow = (dir, node, context) => {
  25633. const { exp, loc } = dir;
  25634. if (!exp) {
  25635. context.onError(
  25636. createDOMCompilerError(61, loc)
  25637. );
  25638. }
  25639. return {
  25640. props: [],
  25641. needRuntime: context.helper(V_SHOW)
  25642. };
  25643. };
  25644. const transformTransition = (node, context) => {
  25645. if (node.type === 1 && node.tagType === 1) {
  25646. const component = context.isBuiltInComponent(node.tag);
  25647. if (component === TRANSITION) {
  25648. return () => {
  25649. if (!node.children.length) {
  25650. return;
  25651. }
  25652. if (hasMultipleChildren(node)) {
  25653. context.onError(
  25654. createDOMCompilerError(
  25655. 62,
  25656. {
  25657. start: node.children[0].loc.start,
  25658. end: node.children[node.children.length - 1].loc.end,
  25659. source: ""
  25660. }
  25661. )
  25662. );
  25663. }
  25664. const child = node.children[0];
  25665. if (child.type === 1) {
  25666. for (const p of child.props) {
  25667. if (p.type === 7 && p.name === "show") {
  25668. node.props.push({
  25669. type: 6,
  25670. name: "persisted",
  25671. value: void 0,
  25672. loc: node.loc
  25673. });
  25674. }
  25675. }
  25676. }
  25677. };
  25678. }
  25679. }
  25680. };
  25681. function hasMultipleChildren(node) {
  25682. const children = node.children = node.children.filter(
  25683. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  25684. );
  25685. const child = children[0];
  25686. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  25687. }
  25688. const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
  25689. const stringifyStatic = (children, context, parent) => {
  25690. if (context.scopes.vSlot > 0) {
  25691. return;
  25692. }
  25693. let nc = 0;
  25694. let ec = 0;
  25695. const currentChunk = [];
  25696. const stringifyCurrentChunk = (currentIndex) => {
  25697. if (nc >= 20 || ec >= 5) {
  25698. const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
  25699. JSON.stringify(
  25700. currentChunk.map((node) => stringifyNode(node, context)).join("")
  25701. ).replace(expReplaceRE, `" + $1 + "`),
  25702. // the 2nd argument indicates the number of DOM nodes this static vnode
  25703. // will insert / hydrate
  25704. String(currentChunk.length)
  25705. ]);
  25706. replaceHoist(currentChunk[0], staticCall, context);
  25707. if (currentChunk.length > 1) {
  25708. for (let i2 = 1; i2 < currentChunk.length; i2++) {
  25709. replaceHoist(currentChunk[i2], null, context);
  25710. }
  25711. const deleteCount = currentChunk.length - 1;
  25712. children.splice(currentIndex - currentChunk.length + 1, deleteCount);
  25713. return deleteCount;
  25714. }
  25715. }
  25716. return 0;
  25717. };
  25718. let i = 0;
  25719. for (; i < children.length; i++) {
  25720. const child = children[i];
  25721. const hoisted = getHoistedNode(child);
  25722. if (hoisted) {
  25723. const node = child;
  25724. const result = analyzeNode(node);
  25725. if (result) {
  25726. nc += result[0];
  25727. ec += result[1];
  25728. currentChunk.push(node);
  25729. continue;
  25730. }
  25731. }
  25732. i -= stringifyCurrentChunk(i);
  25733. nc = 0;
  25734. ec = 0;
  25735. currentChunk.length = 0;
  25736. }
  25737. stringifyCurrentChunk(i);
  25738. };
  25739. const getHoistedNode = (node) => (node.type === 1 && node.tagType === 0 || node.type == 12) && node.codegenNode && node.codegenNode.type === 4 && node.codegenNode.hoisted;
  25740. const dataAriaRE = /^(data|aria)-/;
  25741. const isStringifiableAttr = (name, ns) => {
  25742. return (ns === 0 ? isKnownHtmlAttr(name) : ns === 1 ? isKnownSvgAttr(name) : false) || dataAriaRE.test(name);
  25743. };
  25744. const replaceHoist = (node, replacement, context) => {
  25745. const hoistToReplace = node.codegenNode.hoisted;
  25746. context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement;
  25747. };
  25748. const isNonStringifiable = /* @__PURE__ */ makeMap(
  25749. `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
  25750. );
  25751. function analyzeNode(node) {
  25752. if (node.type === 1 && isNonStringifiable(node.tag)) {
  25753. return false;
  25754. }
  25755. if (node.type === 12) {
  25756. return [1, 0];
  25757. }
  25758. let nc = 1;
  25759. let ec = node.props.length > 0 ? 1 : 0;
  25760. let bailed = false;
  25761. const bail = () => {
  25762. bailed = true;
  25763. return false;
  25764. };
  25765. function walk(node2) {
  25766. for (let i = 0; i < node2.props.length; i++) {
  25767. const p = node2.props[i];
  25768. if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
  25769. return bail();
  25770. }
  25771. if (p.type === 7 && p.name === "bind") {
  25772. if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
  25773. return bail();
  25774. }
  25775. if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
  25776. return bail();
  25777. }
  25778. }
  25779. }
  25780. for (let i = 0; i < node2.children.length; i++) {
  25781. nc++;
  25782. const child = node2.children[i];
  25783. if (child.type === 1) {
  25784. if (child.props.length > 0) {
  25785. ec++;
  25786. }
  25787. walk(child);
  25788. if (bailed) {
  25789. return false;
  25790. }
  25791. }
  25792. }
  25793. return true;
  25794. }
  25795. return walk(node) ? [nc, ec] : false;
  25796. }
  25797. function stringifyNode(node, context) {
  25798. if (isString$2(node)) {
  25799. return node;
  25800. }
  25801. if (isSymbol$1(node)) {
  25802. return ``;
  25803. }
  25804. switch (node.type) {
  25805. case 1:
  25806. return stringifyElement(node, context);
  25807. case 2:
  25808. return escapeHtml(node.content);
  25809. case 3:
  25810. return `<!--${escapeHtml(node.content)}-->`;
  25811. case 5:
  25812. return escapeHtml(toDisplayString(evaluateConstant(node.content)));
  25813. case 8:
  25814. return escapeHtml(evaluateConstant(node));
  25815. case 12:
  25816. return stringifyNode(node.content, context);
  25817. default:
  25818. return "";
  25819. }
  25820. }
  25821. function stringifyElement(node, context) {
  25822. let res = `<${node.tag}`;
  25823. let innerHTML = "";
  25824. for (let i = 0; i < node.props.length; i++) {
  25825. const p = node.props[i];
  25826. if (p.type === 6) {
  25827. res += ` ${p.name}`;
  25828. if (p.value) {
  25829. res += `="${escapeHtml(p.value.content)}"`;
  25830. }
  25831. } else if (p.type === 7) {
  25832. if (p.name === "bind") {
  25833. const exp = p.exp;
  25834. if (exp.content[0] === "_") {
  25835. res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
  25836. continue;
  25837. }
  25838. if (isBooleanAttr(p.arg.content) && exp.content === "false") {
  25839. continue;
  25840. }
  25841. let evaluated = evaluateConstant(exp);
  25842. if (evaluated != null) {
  25843. const arg = p.arg && p.arg.content;
  25844. if (arg === "class") {
  25845. evaluated = normalizeClass(evaluated);
  25846. } else if (arg === "style") {
  25847. evaluated = stringifyStyle(normalizeStyle(evaluated));
  25848. }
  25849. res += ` ${p.arg.content}="${escapeHtml(
  25850. evaluated
  25851. )}"`;
  25852. }
  25853. } else if (p.name === "html") {
  25854. innerHTML = evaluateConstant(p.exp);
  25855. } else if (p.name === "text") {
  25856. innerHTML = escapeHtml(
  25857. toDisplayString(evaluateConstant(p.exp))
  25858. );
  25859. }
  25860. }
  25861. }
  25862. if (context.scopeId) {
  25863. res += ` ${context.scopeId}`;
  25864. }
  25865. res += `>`;
  25866. if (innerHTML) {
  25867. res += innerHTML;
  25868. } else {
  25869. for (let i = 0; i < node.children.length; i++) {
  25870. res += stringifyNode(node.children[i], context);
  25871. }
  25872. }
  25873. if (!isVoidTag(node.tag)) {
  25874. res += `</${node.tag}>`;
  25875. }
  25876. return res;
  25877. }
  25878. function evaluateConstant(exp) {
  25879. if (exp.type === 4) {
  25880. return new Function(`return (${exp.content})`)();
  25881. } else {
  25882. let res = ``;
  25883. exp.children.forEach((c) => {
  25884. if (isString$2(c) || isSymbol$1(c)) {
  25885. return;
  25886. }
  25887. if (c.type === 2) {
  25888. res += c.content;
  25889. } else if (c.type === 5) {
  25890. res += toDisplayString(evaluateConstant(c.content));
  25891. } else {
  25892. res += evaluateConstant(c);
  25893. }
  25894. });
  25895. return res;
  25896. }
  25897. }
  25898. const ignoreSideEffectTags = (node, context) => {
  25899. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  25900. context.onError(
  25901. createDOMCompilerError(
  25902. 63,
  25903. node.loc
  25904. )
  25905. );
  25906. context.removeNode();
  25907. }
  25908. };
  25909. const DOMNodeTransforms = [
  25910. transformStyle,
  25911. ...[transformTransition]
  25912. ];
  25913. const DOMDirectiveTransforms = {
  25914. cloak: noopDirectiveTransform,
  25915. html: transformVHtml,
  25916. text: transformVText,
  25917. model: transformModel,
  25918. // override compiler-core
  25919. on: transformOn,
  25920. // override compiler-core
  25921. show: transformShow
  25922. };
  25923. function compile$1(template, options = {}) {
  25924. return baseCompile(
  25925. template,
  25926. extend({}, parserOptions, options, {
  25927. nodeTransforms: [
  25928. // ignore <script> and <tag>
  25929. // this is not put inside DOMNodeTransforms because that list is used
  25930. // by compiler-ssr to generate vnode fallback branches
  25931. ignoreSideEffectTags,
  25932. ...DOMNodeTransforms,
  25933. ...options.nodeTransforms || []
  25934. ],
  25935. directiveTransforms: extend(
  25936. {},
  25937. DOMDirectiveTransforms,
  25938. options.directiveTransforms || {}
  25939. ),
  25940. transformHoist: stringifyStatic
  25941. })
  25942. );
  25943. }
  25944. function parse$8(template, options = {}) {
  25945. return baseParse(template, extend({}, parserOptions, options));
  25946. }
  25947. var CompilerDOM = /*#__PURE__*/Object.freeze({
  25948. __proto__: null,
  25949. BASE_TRANSITION: BASE_TRANSITION,
  25950. CAMELIZE: CAMELIZE,
  25951. CAPITALIZE: CAPITALIZE,
  25952. CREATE_BLOCK: CREATE_BLOCK,
  25953. CREATE_COMMENT: CREATE_COMMENT,
  25954. CREATE_ELEMENT_BLOCK: CREATE_ELEMENT_BLOCK,
  25955. CREATE_ELEMENT_VNODE: CREATE_ELEMENT_VNODE,
  25956. CREATE_SLOTS: CREATE_SLOTS,
  25957. CREATE_STATIC: CREATE_STATIC,
  25958. CREATE_TEXT: CREATE_TEXT,
  25959. CREATE_VNODE: CREATE_VNODE,
  25960. DOMDirectiveTransforms: DOMDirectiveTransforms,
  25961. DOMNodeTransforms: DOMNodeTransforms,
  25962. FRAGMENT: FRAGMENT,
  25963. GUARD_REACTIVE_PROPS: GUARD_REACTIVE_PROPS,
  25964. IS_MEMO_SAME: IS_MEMO_SAME,
  25965. IS_REF: IS_REF,
  25966. KEEP_ALIVE: KEEP_ALIVE,
  25967. MERGE_PROPS: MERGE_PROPS,
  25968. NORMALIZE_CLASS: NORMALIZE_CLASS,
  25969. NORMALIZE_PROPS: NORMALIZE_PROPS,
  25970. NORMALIZE_STYLE: NORMALIZE_STYLE,
  25971. OPEN_BLOCK: OPEN_BLOCK,
  25972. POP_SCOPE_ID: POP_SCOPE_ID,
  25973. PUSH_SCOPE_ID: PUSH_SCOPE_ID,
  25974. RENDER_LIST: RENDER_LIST,
  25975. RENDER_SLOT: RENDER_SLOT,
  25976. RESOLVE_COMPONENT: RESOLVE_COMPONENT,
  25977. RESOLVE_DIRECTIVE: RESOLVE_DIRECTIVE,
  25978. RESOLVE_DYNAMIC_COMPONENT: RESOLVE_DYNAMIC_COMPONENT,
  25979. RESOLVE_FILTER: RESOLVE_FILTER,
  25980. SET_BLOCK_TRACKING: SET_BLOCK_TRACKING,
  25981. SUSPENSE: SUSPENSE,
  25982. TELEPORT: TELEPORT,
  25983. TO_DISPLAY_STRING: TO_DISPLAY_STRING,
  25984. TO_HANDLERS: TO_HANDLERS,
  25985. TO_HANDLER_KEY: TO_HANDLER_KEY,
  25986. TRANSITION: TRANSITION,
  25987. TRANSITION_GROUP: TRANSITION_GROUP,
  25988. TS_NODE_TYPES: TS_NODE_TYPES,
  25989. UNREF: UNREF,
  25990. V_MODEL_CHECKBOX: V_MODEL_CHECKBOX,
  25991. V_MODEL_DYNAMIC: V_MODEL_DYNAMIC,
  25992. V_MODEL_RADIO: V_MODEL_RADIO,
  25993. V_MODEL_SELECT: V_MODEL_SELECT,
  25994. V_MODEL_TEXT: V_MODEL_TEXT,
  25995. V_ON_WITH_KEYS: V_ON_WITH_KEYS,
  25996. V_ON_WITH_MODIFIERS: V_ON_WITH_MODIFIERS,
  25997. V_SHOW: V_SHOW,
  25998. WITH_CTX: WITH_CTX,
  25999. WITH_DIRECTIVES: WITH_DIRECTIVES,
  26000. WITH_MEMO: WITH_MEMO,
  26001. advancePositionWithClone: advancePositionWithClone,
  26002. advancePositionWithMutation: advancePositionWithMutation,
  26003. assert: assert,
  26004. baseCompile: baseCompile,
  26005. baseParse: baseParse,
  26006. buildDirectiveArgs: buildDirectiveArgs,
  26007. buildProps: buildProps,
  26008. buildSlots: buildSlots,
  26009. checkCompatEnabled: checkCompatEnabled,
  26010. compile: compile$1,
  26011. convertToBlock: convertToBlock,
  26012. createArrayExpression: createArrayExpression,
  26013. createAssignmentExpression: createAssignmentExpression,
  26014. createBlockStatement: createBlockStatement,
  26015. createCacheExpression: createCacheExpression,
  26016. createCallExpression: createCallExpression,
  26017. createCompilerError: createCompilerError,
  26018. createCompoundExpression: createCompoundExpression,
  26019. createConditionalExpression: createConditionalExpression,
  26020. createDOMCompilerError: createDOMCompilerError,
  26021. createForLoopParams: createForLoopParams,
  26022. createFunctionExpression: createFunctionExpression,
  26023. createIfStatement: createIfStatement,
  26024. createInterpolation: createInterpolation,
  26025. createObjectExpression: createObjectExpression,
  26026. createObjectProperty: createObjectProperty,
  26027. createReturnStatement: createReturnStatement,
  26028. createRoot: createRoot,
  26029. createSequenceExpression: createSequenceExpression,
  26030. createSimpleExpression: createSimpleExpression,
  26031. createStructuralDirectiveTransform: createStructuralDirectiveTransform,
  26032. createTemplateLiteral: createTemplateLiteral,
  26033. createTransformContext: createTransformContext,
  26034. createVNodeCall: createVNodeCall,
  26035. extractIdentifiers: extractIdentifiers,
  26036. findDir: findDir,
  26037. findProp: findProp,
  26038. forAliasRE: forAliasRE,
  26039. generate: generate,
  26040. generateCodeFrame: generateCodeFrame,
  26041. getBaseTransformPreset: getBaseTransformPreset,
  26042. getConstantType: getConstantType,
  26043. getInnerRange: getInnerRange,
  26044. getMemoedVNodeCall: getMemoedVNodeCall,
  26045. getVNodeBlockHelper: getVNodeBlockHelper,
  26046. getVNodeHelper: getVNodeHelper,
  26047. hasDynamicKeyVBind: hasDynamicKeyVBind,
  26048. hasScopeRef: hasScopeRef,
  26049. helperNameMap: helperNameMap,
  26050. injectProp: injectProp,
  26051. isBuiltInType: isBuiltInType,
  26052. isCoreComponent: isCoreComponent,
  26053. isFunctionType: isFunctionType,
  26054. isInDestructureAssignment: isInDestructureAssignment,
  26055. isMemberExpression: isMemberExpression,
  26056. isMemberExpressionBrowser: isMemberExpressionBrowser,
  26057. isMemberExpressionNode: isMemberExpressionNode,
  26058. isReferencedIdentifier: isReferencedIdentifier,
  26059. isSimpleIdentifier: isSimpleIdentifier,
  26060. isSlotOutlet: isSlotOutlet,
  26061. isStaticArgOf: isStaticArgOf,
  26062. isStaticExp: isStaticExp,
  26063. isStaticProperty: isStaticProperty,
  26064. isStaticPropertyKey: isStaticPropertyKey,
  26065. isTemplateNode: isTemplateNode,
  26066. isText: isText$1,
  26067. isVSlot: isVSlot,
  26068. locStub: locStub,
  26069. noopDirectiveTransform: noopDirectiveTransform,
  26070. parse: parse$8,
  26071. parserOptions: parserOptions,
  26072. processExpression: processExpression,
  26073. processFor: processFor,
  26074. processIf: processIf,
  26075. processSlotOutlet: processSlotOutlet,
  26076. registerRuntimeHelpers: registerRuntimeHelpers,
  26077. resolveComponentType: resolveComponentType,
  26078. stringifyExpression: stringifyExpression,
  26079. toValidAssetId: toValidAssetId,
  26080. trackSlotScopes: trackSlotScopes,
  26081. trackVForSlotScopes: trackVForSlotScopes,
  26082. transform: transform$1,
  26083. transformBind: transformBind,
  26084. transformElement: transformElement,
  26085. transformExpression: transformExpression,
  26086. transformModel: transformModel$1,
  26087. transformOn: transformOn$1,
  26088. transformStyle: transformStyle,
  26089. traverseNode: traverseNode,
  26090. walkBlockDeclarations: walkBlockDeclarations,
  26091. walkFunctionParams: walkFunctionParams,
  26092. walkIdentifiers: walkIdentifiers,
  26093. warnDeprecation: warnDeprecation
  26094. });
  26095. // Copyright Joyent, Inc. and other Node contributors.
  26096. //
  26097. // Permission is hereby granted, free of charge, to any person obtaining a
  26098. // copy of this software and associated documentation files (the
  26099. // "Software"), to deal in the Software without restriction, including
  26100. // without limitation the rights to use, copy, modify, merge, publish,
  26101. // distribute, sublicense, and/or sell copies of the Software, and to permit
  26102. // persons to whom the Software is furnished to do so, subject to the
  26103. // following conditions:
  26104. //
  26105. // The above copyright notice and this permission notice shall be included
  26106. // in all copies or substantial portions of the Software.
  26107. //
  26108. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  26109. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26110. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  26111. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  26112. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  26113. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  26114. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  26115. // resolves . and .. elements in a path array with directory names there
  26116. // must be no slashes, empty elements, or device names (c:\) in the array
  26117. // (so also no leading and trailing slashes - it does not distinguish
  26118. // relative and absolute paths)
  26119. function normalizeArray(parts, allowAboveRoot) {
  26120. // if the path tries to go above the root, `up` ends up > 0
  26121. var up = 0;
  26122. for (var i = parts.length - 1; i >= 0; i--) {
  26123. var last = parts[i];
  26124. if (last === '.') {
  26125. parts.splice(i, 1);
  26126. } else if (last === '..') {
  26127. parts.splice(i, 1);
  26128. up++;
  26129. } else if (up) {
  26130. parts.splice(i, 1);
  26131. up--;
  26132. }
  26133. }
  26134. // if the path is allowed to go above the root, restore leading ..s
  26135. if (allowAboveRoot) {
  26136. for (; up--; up) {
  26137. parts.unshift('..');
  26138. }
  26139. }
  26140. return parts;
  26141. }
  26142. // Split a filename into [root, dir, basename, ext], unix version
  26143. // 'root' is just a slash, or nothing.
  26144. var splitPathRe =
  26145. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  26146. var splitPath = function(filename) {
  26147. return splitPathRe.exec(filename).slice(1);
  26148. };
  26149. // path.resolve([from ...], to)
  26150. // posix version
  26151. function resolve$2() {
  26152. var resolvedPath = '',
  26153. resolvedAbsolute = false;
  26154. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  26155. var path = (i >= 0) ? arguments[i] : '/';
  26156. // Skip empty and invalid entries
  26157. if (typeof path !== 'string') {
  26158. throw new TypeError('Arguments to path.resolve must be strings');
  26159. } else if (!path) {
  26160. continue;
  26161. }
  26162. resolvedPath = path + '/' + resolvedPath;
  26163. resolvedAbsolute = path.charAt(0) === '/';
  26164. }
  26165. // At this point the path should be resolved to a full absolute path, but
  26166. // handle relative paths to be safe (might happen when process.cwd() fails)
  26167. // Normalize the path
  26168. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  26169. return !!p;
  26170. }), !resolvedAbsolute).join('/');
  26171. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  26172. }
  26173. // path.normalize(path)
  26174. // posix version
  26175. function normalize$1(path) {
  26176. var isPathAbsolute = isAbsolute$1(path),
  26177. trailingSlash = substr(path, -1) === '/';
  26178. // Normalize the path
  26179. path = normalizeArray(filter(path.split('/'), function(p) {
  26180. return !!p;
  26181. }), !isPathAbsolute).join('/');
  26182. if (!path && !isPathAbsolute) {
  26183. path = '.';
  26184. }
  26185. if (path && trailingSlash) {
  26186. path += '/';
  26187. }
  26188. return (isPathAbsolute ? '/' : '') + path;
  26189. }
  26190. // posix version
  26191. function isAbsolute$1(path) {
  26192. return path.charAt(0) === '/';
  26193. }
  26194. // posix version
  26195. function join$1() {
  26196. var paths = Array.prototype.slice.call(arguments, 0);
  26197. return normalize$1(filter(paths, function(p, index) {
  26198. if (typeof p !== 'string') {
  26199. throw new TypeError('Arguments to path.join must be strings');
  26200. }
  26201. return p;
  26202. }).join('/'));
  26203. }
  26204. // path.relative(from, to)
  26205. // posix version
  26206. function relative$1(from, to) {
  26207. from = resolve$2(from).substr(1);
  26208. to = resolve$2(to).substr(1);
  26209. function trim(arr) {
  26210. var start = 0;
  26211. for (; start < arr.length; start++) {
  26212. if (arr[start] !== '') break;
  26213. }
  26214. var end = arr.length - 1;
  26215. for (; end >= 0; end--) {
  26216. if (arr[end] !== '') break;
  26217. }
  26218. if (start > end) return [];
  26219. return arr.slice(start, end - start + 1);
  26220. }
  26221. var fromParts = trim(from.split('/'));
  26222. var toParts = trim(to.split('/'));
  26223. var length = Math.min(fromParts.length, toParts.length);
  26224. var samePartsLength = length;
  26225. for (var i = 0; i < length; i++) {
  26226. if (fromParts[i] !== toParts[i]) {
  26227. samePartsLength = i;
  26228. break;
  26229. }
  26230. }
  26231. var outputParts = [];
  26232. for (var i = samePartsLength; i < fromParts.length; i++) {
  26233. outputParts.push('..');
  26234. }
  26235. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  26236. return outputParts.join('/');
  26237. }
  26238. var sep$1 = '/';
  26239. var delimiter$1 = ':';
  26240. function dirname$2(path) {
  26241. var result = splitPath(path),
  26242. root = result[0],
  26243. dir = result[1];
  26244. if (!root && !dir) {
  26245. // No dirname whatsoever
  26246. return '.';
  26247. }
  26248. if (dir) {
  26249. // It has a dirname, strip trailing slash
  26250. dir = dir.substr(0, dir.length - 1);
  26251. }
  26252. return root + dir;
  26253. }
  26254. function basename(path, ext) {
  26255. var f = splitPath(path)[2];
  26256. // TODO: make this comparison case-insensitive on windows?
  26257. if (ext && f.substr(-1 * ext.length) === ext) {
  26258. f = f.substr(0, f.length - ext.length);
  26259. }
  26260. return f;
  26261. }
  26262. function extname(path) {
  26263. return splitPath(path)[3];
  26264. }
  26265. var path = {
  26266. extname: extname,
  26267. basename: basename,
  26268. dirname: dirname$2,
  26269. sep: sep$1,
  26270. delimiter: delimiter$1,
  26271. relative: relative$1,
  26272. join: join$1,
  26273. isAbsolute: isAbsolute$1,
  26274. normalize: normalize$1,
  26275. resolve: resolve$2
  26276. };
  26277. function filter (xs, f) {
  26278. if (xs.filter) return xs.filter(f);
  26279. var res = [];
  26280. for (var i = 0; i < xs.length; i++) {
  26281. if (f(xs[i], i, xs)) res.push(xs[i]);
  26282. }
  26283. return res;
  26284. }
  26285. // String.prototype.substr - negative index don't work in IE8
  26286. var substr = 'ab'.substr(-1) === 'b' ?
  26287. function (str, start, len) { return str.substr(start, len) } :
  26288. function (str, start, len) {
  26289. if (start < 0) start = str.length + start;
  26290. return str.substr(start, len);
  26291. }
  26292. ;
  26293. var _polyfillNode_path = /*#__PURE__*/Object.freeze({
  26294. __proto__: null,
  26295. basename: basename,
  26296. default: path,
  26297. delimiter: delimiter$1,
  26298. dirname: dirname$2,
  26299. extname: extname,
  26300. isAbsolute: isAbsolute$1,
  26301. join: join$1,
  26302. normalize: normalize$1,
  26303. relative: relative$1,
  26304. resolve: resolve$2,
  26305. sep: sep$1
  26306. });
  26307. const UNKNOWN_TYPE = "Unknown";
  26308. function resolveObjectKey(node, computed) {
  26309. switch (node.type) {
  26310. case "StringLiteral":
  26311. case "NumericLiteral":
  26312. return String(node.value);
  26313. case "Identifier":
  26314. if (!computed)
  26315. return node.name;
  26316. }
  26317. return void 0;
  26318. }
  26319. function concatStrings(strs) {
  26320. return strs.filter((s) => !!s).join(", ");
  26321. }
  26322. function isLiteralNode(node) {
  26323. return node.type.endsWith("Literal");
  26324. }
  26325. function unwrapTSNode(node) {
  26326. if (TS_NODE_TYPES.includes(node.type)) {
  26327. return unwrapTSNode(node.expression);
  26328. } else {
  26329. return node;
  26330. }
  26331. }
  26332. function isCallOf(node, test) {
  26333. return !!(node && test && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : test(node.callee.name)));
  26334. }
  26335. function toRuntimeTypeString(types) {
  26336. return types.length > 1 ? `[${types.join(", ")}]` : types[0];
  26337. }
  26338. function getImportedName(specifier) {
  26339. if (specifier.type === "ImportSpecifier")
  26340. return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
  26341. else if (specifier.type === "ImportNamespaceSpecifier")
  26342. return "*";
  26343. return "default";
  26344. }
  26345. function getId(node) {
  26346. return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
  26347. }
  26348. const normalize = (path.posix || path).normalize;
  26349. const windowsSlashRE = /\\/g;
  26350. function normalizePath(p) {
  26351. return normalize(p.replace(windowsSlashRE, "/"));
  26352. }
  26353. const joinPaths = (path.posix || path).join;
  26354. const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
  26355. function getEscapedPropName(key) {
  26356. return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
  26357. }
  26358. const cssVarNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g;
  26359. function getEscapedCssVarName(key, doubleEscape) {
  26360. return key.replace(
  26361. cssVarNameEscapeSymbolsRE,
  26362. (s) => doubleEscape ? `\\\\${s}` : `\\${s}`
  26363. );
  26364. }
  26365. function pad$1 (hash, len) {
  26366. while (hash.length < len) {
  26367. hash = '0' + hash;
  26368. }
  26369. return hash;
  26370. }
  26371. function fold (hash, text) {
  26372. var i;
  26373. var chr;
  26374. var len;
  26375. if (text.length === 0) {
  26376. return hash;
  26377. }
  26378. for (i = 0, len = text.length; i < len; i++) {
  26379. chr = text.charCodeAt(i);
  26380. hash = ((hash << 5) - hash) + chr;
  26381. hash |= 0;
  26382. }
  26383. return hash < 0 ? hash * -2 : hash;
  26384. }
  26385. function foldObject (hash, o, seen) {
  26386. return Object.keys(o).sort().reduce(foldKey, hash);
  26387. function foldKey (hash, key) {
  26388. return foldValue(hash, o[key], key, seen);
  26389. }
  26390. }
  26391. function foldValue (input, value, key, seen) {
  26392. var hash = fold(fold(fold(input, key), toString$2(value)), typeof value);
  26393. if (value === null) {
  26394. return fold(hash, 'null');
  26395. }
  26396. if (value === undefined) {
  26397. return fold(hash, 'undefined');
  26398. }
  26399. if (typeof value === 'object' || typeof value === 'function') {
  26400. if (seen.indexOf(value) !== -1) {
  26401. return fold(hash, '[Circular]' + key);
  26402. }
  26403. seen.push(value);
  26404. var objHash = foldObject(hash, value, seen);
  26405. if (!('valueOf' in value) || typeof value.valueOf !== 'function') {
  26406. return objHash;
  26407. }
  26408. try {
  26409. return fold(objHash, String(value.valueOf()))
  26410. } catch (err) {
  26411. return fold(objHash, '[valueOf exception]' + (err.stack || err.message))
  26412. }
  26413. }
  26414. return fold(hash, value.toString());
  26415. }
  26416. function toString$2 (o) {
  26417. return Object.prototype.toString.call(o);
  26418. }
  26419. function sum (o) {
  26420. return pad$1(foldValue(0, o, '', []).toString(16), 8);
  26421. }
  26422. var hashSum = sum;
  26423. var hash = /*@__PURE__*/getDefaultExportFromCjs(hashSum);
  26424. const CSS_VARS_HELPER = `useCssVars`;
  26425. function genCssVarsFromList(vars, id, isProd, isSSR = false) {
  26426. return `{
  26427. ${vars.map(
  26428. (key) => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd, isSSR)}": (${key})`
  26429. ).join(",\n ")}
  26430. }`;
  26431. }
  26432. function genVarName(id, raw, isProd, isSSR = false) {
  26433. if (isProd) {
  26434. return hash(id + raw);
  26435. } else {
  26436. return `${id}-${getEscapedCssVarName(raw, isSSR)}`;
  26437. }
  26438. }
  26439. function normalizeExpression(exp) {
  26440. exp = exp.trim();
  26441. if (exp[0] === `'` && exp[exp.length - 1] === `'` || exp[0] === `"` && exp[exp.length - 1] === `"`) {
  26442. return exp.slice(1, -1);
  26443. }
  26444. return exp;
  26445. }
  26446. const vBindRE = /v-bind\s*\(/g;
  26447. function parseCssVars(sfc) {
  26448. const vars = [];
  26449. sfc.styles.forEach((style) => {
  26450. let match;
  26451. const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
  26452. while (match = vBindRE.exec(content)) {
  26453. const start = match.index + match[0].length;
  26454. const end = lexBinding(content, start);
  26455. if (end !== null) {
  26456. const variable = normalizeExpression(content.slice(start, end));
  26457. if (!vars.includes(variable)) {
  26458. vars.push(variable);
  26459. }
  26460. }
  26461. }
  26462. });
  26463. return vars;
  26464. }
  26465. function lexBinding(content, start) {
  26466. let state = 0 /* inParens */;
  26467. let parenDepth = 0;
  26468. for (let i = start; i < content.length; i++) {
  26469. const char = content.charAt(i);
  26470. switch (state) {
  26471. case 0 /* inParens */:
  26472. if (char === `'`) {
  26473. state = 1 /* inSingleQuoteString */;
  26474. } else if (char === `"`) {
  26475. state = 2 /* inDoubleQuoteString */;
  26476. } else if (char === `(`) {
  26477. parenDepth++;
  26478. } else if (char === `)`) {
  26479. if (parenDepth > 0) {
  26480. parenDepth--;
  26481. } else {
  26482. return i;
  26483. }
  26484. }
  26485. break;
  26486. case 1 /* inSingleQuoteString */:
  26487. if (char === `'`) {
  26488. state = 0 /* inParens */;
  26489. }
  26490. break;
  26491. case 2 /* inDoubleQuoteString */:
  26492. if (char === `"`) {
  26493. state = 0 /* inParens */;
  26494. }
  26495. break;
  26496. }
  26497. }
  26498. return null;
  26499. }
  26500. const cssVarsPlugin = (opts) => {
  26501. const { id, isProd } = opts;
  26502. return {
  26503. postcssPlugin: "vue-sfc-vars",
  26504. Declaration(decl) {
  26505. const value = decl.value;
  26506. if (vBindRE.test(value)) {
  26507. vBindRE.lastIndex = 0;
  26508. let transformed = "";
  26509. let lastIndex = 0;
  26510. let match;
  26511. while (match = vBindRE.exec(value)) {
  26512. const start = match.index + match[0].length;
  26513. const end = lexBinding(value, start);
  26514. if (end !== null) {
  26515. const variable = normalizeExpression(value.slice(start, end));
  26516. transformed += value.slice(lastIndex, match.index) + `var(--${genVarName(id, variable, isProd)})`;
  26517. lastIndex = end + 1;
  26518. }
  26519. }
  26520. decl.value = transformed + value.slice(lastIndex);
  26521. }
  26522. }
  26523. };
  26524. };
  26525. cssVarsPlugin.postcss = true;
  26526. function genCssVarsCode(vars, bindings, id, isProd) {
  26527. const varsExp = genCssVarsFromList(vars, id, isProd);
  26528. const exp = createSimpleExpression(varsExp, false);
  26529. const context = createTransformContext(createRoot([]), {
  26530. prefixIdentifiers: true,
  26531. inline: true,
  26532. bindingMetadata: bindings.__isScriptSetup === false ? void 0 : bindings
  26533. });
  26534. const transformed = processExpression(exp, context);
  26535. const transformedString = transformed.type === 4 ? transformed.content : transformed.children.map((c) => {
  26536. return typeof c === "string" ? c : c.content;
  26537. }).join("");
  26538. return `_${CSS_VARS_HELPER}(_ctx => (${transformedString}))`;
  26539. }
  26540. function genNormalScriptCssVarsCode(cssVars, bindings, id, isProd, defaultVar) {
  26541. return `
  26542. import { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'
  26543. const __injectCSSVars__ = () => {
  26544. ${genCssVarsCode(
  26545. cssVars,
  26546. bindings,
  26547. id,
  26548. isProd
  26549. )}}
  26550. const __setup__ = ${defaultVar}.setup
  26551. ${defaultVar}.setup = __setup__
  26552. ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }
  26553. : __injectCSSVars__
  26554. `;
  26555. }
  26556. var global$1 = (typeof global !== "undefined" ? global :
  26557. typeof self !== "undefined" ? self :
  26558. typeof window !== "undefined" ? window : {});
  26559. // shim for using process in browser
  26560. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  26561. function defaultSetTimout() {
  26562. throw new Error('setTimeout has not been defined');
  26563. }
  26564. function defaultClearTimeout () {
  26565. throw new Error('clearTimeout has not been defined');
  26566. }
  26567. var cachedSetTimeout = defaultSetTimout;
  26568. var cachedClearTimeout = defaultClearTimeout;
  26569. if (typeof global$1.setTimeout === 'function') {
  26570. cachedSetTimeout = setTimeout;
  26571. }
  26572. if (typeof global$1.clearTimeout === 'function') {
  26573. cachedClearTimeout = clearTimeout;
  26574. }
  26575. function runTimeout(fun) {
  26576. if (cachedSetTimeout === setTimeout) {
  26577. //normal enviroments in sane situations
  26578. return setTimeout(fun, 0);
  26579. }
  26580. // if setTimeout wasn't available but was latter defined
  26581. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  26582. cachedSetTimeout = setTimeout;
  26583. return setTimeout(fun, 0);
  26584. }
  26585. try {
  26586. // when when somebody has screwed with setTimeout but no I.E. maddness
  26587. return cachedSetTimeout(fun, 0);
  26588. } catch(e){
  26589. try {
  26590. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  26591. return cachedSetTimeout.call(null, fun, 0);
  26592. } catch(e){
  26593. // 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
  26594. return cachedSetTimeout.call(this, fun, 0);
  26595. }
  26596. }
  26597. }
  26598. function runClearTimeout(marker) {
  26599. if (cachedClearTimeout === clearTimeout) {
  26600. //normal enviroments in sane situations
  26601. return clearTimeout(marker);
  26602. }
  26603. // if clearTimeout wasn't available but was latter defined
  26604. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  26605. cachedClearTimeout = clearTimeout;
  26606. return clearTimeout(marker);
  26607. }
  26608. try {
  26609. // when when somebody has screwed with setTimeout but no I.E. maddness
  26610. return cachedClearTimeout(marker);
  26611. } catch (e){
  26612. try {
  26613. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  26614. return cachedClearTimeout.call(null, marker);
  26615. } catch (e){
  26616. // 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.
  26617. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  26618. return cachedClearTimeout.call(this, marker);
  26619. }
  26620. }
  26621. }
  26622. var queue = [];
  26623. var draining = false;
  26624. var currentQueue;
  26625. var queueIndex = -1;
  26626. function cleanUpNextTick() {
  26627. if (!draining || !currentQueue) {
  26628. return;
  26629. }
  26630. draining = false;
  26631. if (currentQueue.length) {
  26632. queue = currentQueue.concat(queue);
  26633. } else {
  26634. queueIndex = -1;
  26635. }
  26636. if (queue.length) {
  26637. drainQueue();
  26638. }
  26639. }
  26640. function drainQueue() {
  26641. if (draining) {
  26642. return;
  26643. }
  26644. var timeout = runTimeout(cleanUpNextTick);
  26645. draining = true;
  26646. var len = queue.length;
  26647. while(len) {
  26648. currentQueue = queue;
  26649. queue = [];
  26650. while (++queueIndex < len) {
  26651. if (currentQueue) {
  26652. currentQueue[queueIndex].run();
  26653. }
  26654. }
  26655. queueIndex = -1;
  26656. len = queue.length;
  26657. }
  26658. currentQueue = null;
  26659. draining = false;
  26660. runClearTimeout(timeout);
  26661. }
  26662. function nextTick(fun) {
  26663. var args = new Array(arguments.length - 1);
  26664. if (arguments.length > 1) {
  26665. for (var i = 1; i < arguments.length; i++) {
  26666. args[i - 1] = arguments[i];
  26667. }
  26668. }
  26669. queue.push(new Item(fun, args));
  26670. if (queue.length === 1 && !draining) {
  26671. runTimeout(drainQueue);
  26672. }
  26673. }
  26674. // v8 likes predictible objects
  26675. function Item(fun, array) {
  26676. this.fun = fun;
  26677. this.array = array;
  26678. }
  26679. Item.prototype.run = function () {
  26680. this.fun.apply(null, this.array);
  26681. };
  26682. var title = 'browser';
  26683. var platform = 'browser';
  26684. var browser = true;
  26685. var env = {};
  26686. var argv = [];
  26687. var version$1 = ''; // empty string to avoid regexp issues
  26688. var versions = {};
  26689. var release = {};
  26690. var config = {};
  26691. function noop() {}
  26692. var on = noop;
  26693. var addListener = noop;
  26694. var once = noop;
  26695. var off = noop;
  26696. var removeListener = noop;
  26697. var removeAllListeners = noop;
  26698. var emit = noop;
  26699. function binding(name) {
  26700. throw new Error('process.binding is not supported');
  26701. }
  26702. function cwd () { return '/' }
  26703. function chdir (dir) {
  26704. throw new Error('process.chdir is not supported');
  26705. }function umask() { return 0; }
  26706. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  26707. var performance = global$1.performance || {};
  26708. var performanceNow =
  26709. performance.now ||
  26710. performance.mozNow ||
  26711. performance.msNow ||
  26712. performance.oNow ||
  26713. performance.webkitNow ||
  26714. function(){ return (new Date()).getTime() };
  26715. // generate timestamp or delta
  26716. // see http://nodejs.org/api/process.html#process_process_hrtime
  26717. function hrtime(previousTimestamp){
  26718. var clocktime = performanceNow.call(performance)*1e-3;
  26719. var seconds = Math.floor(clocktime);
  26720. var nanoseconds = Math.floor((clocktime%1)*1e9);
  26721. if (previousTimestamp) {
  26722. seconds = seconds - previousTimestamp[0];
  26723. nanoseconds = nanoseconds - previousTimestamp[1];
  26724. if (nanoseconds<0) {
  26725. seconds--;
  26726. nanoseconds += 1e9;
  26727. }
  26728. }
  26729. return [seconds,nanoseconds]
  26730. }
  26731. var startTime = new Date();
  26732. function uptime() {
  26733. var currentTime = new Date();
  26734. var dif = currentTime - startTime;
  26735. return dif / 1000;
  26736. }
  26737. var browser$1 = {
  26738. nextTick: nextTick,
  26739. title: title,
  26740. browser: browser,
  26741. env: env,
  26742. argv: argv,
  26743. version: version$1,
  26744. versions: versions,
  26745. on: on,
  26746. addListener: addListener,
  26747. once: once,
  26748. off: off,
  26749. removeListener: removeListener,
  26750. removeAllListeners: removeAllListeners,
  26751. emit: emit,
  26752. binding: binding,
  26753. cwd: cwd,
  26754. chdir: chdir,
  26755. umask: umask,
  26756. hrtime: hrtime,
  26757. platform: platform,
  26758. release: release,
  26759. config: config,
  26760. uptime: uptime
  26761. };
  26762. function createCache(max = 500) {
  26763. {
  26764. return /* @__PURE__ */ new Map();
  26765. }
  26766. }
  26767. function isImportUsed(local, sfc) {
  26768. return new RegExp(
  26769. // #4274 escape $ since it's a special char in regex
  26770. // (and is the only regex special char that is valid in identifiers)
  26771. `[^\\w$_]${local.replace(/\$/g, "\\$")}[^\\w$_]`
  26772. ).test(resolveTemplateUsageCheckString(sfc));
  26773. }
  26774. const templateUsageCheckCache = createCache();
  26775. function resolveTemplateUsageCheckString(sfc) {
  26776. const { content, ast } = sfc.template;
  26777. const cached = templateUsageCheckCache.get(content);
  26778. if (cached) {
  26779. return cached;
  26780. }
  26781. let code = "";
  26782. transform$1(createRoot([ast]), {
  26783. nodeTransforms: [
  26784. (node) => {
  26785. var _a;
  26786. if (node.type === 1) {
  26787. if (!parserOptions.isNativeTag(node.tag) && !parserOptions.isBuiltInComponent(node.tag)) {
  26788. code += `,${camelize(node.tag)},${capitalize$1(camelize(node.tag))}`;
  26789. }
  26790. for (let i = 0; i < node.props.length; i++) {
  26791. const prop = node.props[i];
  26792. if (prop.type === 7) {
  26793. if (!isBuiltInDirective(prop.name)) {
  26794. code += `,v${capitalize$1(camelize(prop.name))}`;
  26795. }
  26796. if (prop.arg && !prop.arg.isStatic) {
  26797. code += `,${stripStrings(
  26798. prop.arg.content
  26799. )}`;
  26800. }
  26801. if (prop.exp) {
  26802. code += `,${processExp(
  26803. prop.exp.content,
  26804. prop.name
  26805. )}`;
  26806. }
  26807. }
  26808. if (prop.type === 6 && prop.name === "ref" && ((_a = prop.value) == null ? void 0 : _a.content)) {
  26809. code += `,${prop.value.content}`;
  26810. }
  26811. }
  26812. } else if (node.type === 5) {
  26813. code += `,${processExp(
  26814. node.content.content
  26815. )}`;
  26816. }
  26817. }
  26818. ]
  26819. });
  26820. code += ";";
  26821. templateUsageCheckCache.set(content, code);
  26822. return code;
  26823. }
  26824. function processExp(exp, dir) {
  26825. if (/ as\s+\w|<.*>|:/.test(exp)) {
  26826. if (dir === "slot") {
  26827. exp = `(${exp})=>{}`;
  26828. } else if (dir === "on") {
  26829. exp = `()=>{return ${exp}}`;
  26830. } else if (dir === "for") {
  26831. const inMatch = exp.match(forAliasRE);
  26832. if (inMatch) {
  26833. let [, LHS, RHS] = inMatch;
  26834. LHS = LHS.trim().replace(/^\(|\)$/g, "");
  26835. return processExp(`(${LHS})=>{}`) + processExp(RHS);
  26836. }
  26837. }
  26838. let ret = "";
  26839. const ast = parseExpression_1(exp, { plugins: ["typescript"] });
  26840. walkIdentifiers(ast, (node) => {
  26841. ret += `,` + node.name;
  26842. });
  26843. return ret;
  26844. }
  26845. return stripStrings(exp);
  26846. }
  26847. function stripStrings(exp) {
  26848. return exp.replace(/'[^']*'|"[^"]*"/g, "").replace(/`[^`]+`/g, stripTemplateString);
  26849. }
  26850. function stripTemplateString(str) {
  26851. const interpMatch = str.match(/\${[^}]+}/g);
  26852. if (interpMatch) {
  26853. return interpMatch.map((m) => m.slice(2, -1)).join(",");
  26854. }
  26855. return "";
  26856. }
  26857. var __defProp$a = Object.defineProperty;
  26858. var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
  26859. var __hasOwnProp$a = Object.prototype.hasOwnProperty;
  26860. var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
  26861. var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  26862. var __spreadValues$a = (a, b) => {
  26863. for (var prop in b || (b = {}))
  26864. if (__hasOwnProp$a.call(b, prop))
  26865. __defNormalProp$a(a, prop, b[prop]);
  26866. if (__getOwnPropSymbols$a)
  26867. for (var prop of __getOwnPropSymbols$a(b)) {
  26868. if (__propIsEnum$a.call(b, prop))
  26869. __defNormalProp$a(a, prop, b[prop]);
  26870. }
  26871. return a;
  26872. };
  26873. const DEFAULT_FILENAME = "anonymous.vue";
  26874. const parseCache$1 = createCache();
  26875. function parse$7(source, {
  26876. sourceMap = true,
  26877. filename = DEFAULT_FILENAME,
  26878. sourceRoot = "",
  26879. pad = false,
  26880. ignoreEmpty = true,
  26881. compiler = CompilerDOM
  26882. } = {}) {
  26883. const sourceKey = source + sourceMap + filename + sourceRoot + pad + compiler.parse;
  26884. const cache = parseCache$1.get(sourceKey);
  26885. if (cache) {
  26886. return cache;
  26887. }
  26888. const descriptor = {
  26889. filename,
  26890. source,
  26891. template: null,
  26892. script: null,
  26893. scriptSetup: null,
  26894. styles: [],
  26895. customBlocks: [],
  26896. cssVars: [],
  26897. slotted: false,
  26898. shouldForceReload: (prevImports) => hmrShouldReload(prevImports, descriptor)
  26899. };
  26900. const errors = [];
  26901. const ast = compiler.parse(source, {
  26902. // there are no components at SFC parsing level
  26903. isNativeTag: () => true,
  26904. // preserve all whitespaces
  26905. isPreTag: () => true,
  26906. getTextMode: ({ tag, props }, parent) => {
  26907. if (!parent && tag !== "template" || // <template lang="xxx"> should also be treated as raw text
  26908. tag === "template" && props.some(
  26909. (p) => p.type === 6 && p.name === "lang" && p.value && p.value.content && p.value.content !== "html"
  26910. )) {
  26911. return 2;
  26912. } else {
  26913. return 0;
  26914. }
  26915. },
  26916. onError: (e) => {
  26917. errors.push(e);
  26918. }
  26919. });
  26920. ast.children.forEach((node) => {
  26921. if (node.type !== 1) {
  26922. return;
  26923. }
  26924. if (ignoreEmpty && node.tag !== "template" && isEmpty(node) && !hasSrc(node)) {
  26925. return;
  26926. }
  26927. switch (node.tag) {
  26928. case "template":
  26929. if (!descriptor.template) {
  26930. const templateBlock = descriptor.template = createBlock(
  26931. node,
  26932. source,
  26933. false
  26934. );
  26935. templateBlock.ast = node;
  26936. if (templateBlock.attrs.functional) {
  26937. const err = new SyntaxError(
  26938. `<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.`
  26939. );
  26940. err.loc = node.props.find((p) => p.name === "functional").loc;
  26941. errors.push(err);
  26942. }
  26943. } else {
  26944. errors.push(createDuplicateBlockError(node));
  26945. }
  26946. break;
  26947. case "script":
  26948. const scriptBlock = createBlock(node, source, pad);
  26949. const isSetup = !!scriptBlock.attrs.setup;
  26950. if (isSetup && !descriptor.scriptSetup) {
  26951. descriptor.scriptSetup = scriptBlock;
  26952. break;
  26953. }
  26954. if (!isSetup && !descriptor.script) {
  26955. descriptor.script = scriptBlock;
  26956. break;
  26957. }
  26958. errors.push(createDuplicateBlockError(node, isSetup));
  26959. break;
  26960. case "style":
  26961. const styleBlock = createBlock(node, source, pad);
  26962. if (styleBlock.attrs.vars) {
  26963. errors.push(
  26964. new SyntaxError(
  26965. `<style vars> has been replaced by a new proposal: https://github.com/vuejs/rfcs/pull/231`
  26966. )
  26967. );
  26968. }
  26969. descriptor.styles.push(styleBlock);
  26970. break;
  26971. default:
  26972. descriptor.customBlocks.push(createBlock(node, source, pad));
  26973. break;
  26974. }
  26975. });
  26976. if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
  26977. errors.push(
  26978. new SyntaxError(
  26979. `At least one <template> or <script> is required in a single file component.`
  26980. )
  26981. );
  26982. }
  26983. if (descriptor.scriptSetup) {
  26984. if (descriptor.scriptSetup.src) {
  26985. errors.push(
  26986. new SyntaxError(
  26987. `<script setup> cannot use the "src" attribute because its syntax will be ambiguous outside of the component.`
  26988. )
  26989. );
  26990. descriptor.scriptSetup = null;
  26991. }
  26992. if (descriptor.script && descriptor.script.src) {
  26993. errors.push(
  26994. new SyntaxError(
  26995. `<script> cannot use the "src" attribute when <script setup> is also present because they must be processed together.`
  26996. )
  26997. );
  26998. descriptor.script = null;
  26999. }
  27000. }
  27001. let templateColumnOffset = 0;
  27002. if (descriptor.template && (descriptor.template.lang === "pug" || descriptor.template.lang === "jade")) {
  27003. [descriptor.template.content, templateColumnOffset] = dedent(
  27004. descriptor.template.content
  27005. );
  27006. }
  27007. if (sourceMap) {
  27008. const genMap = (block, columnOffset = 0) => {
  27009. if (block && !block.src) {
  27010. block.map = generateSourceMap(
  27011. filename,
  27012. source,
  27013. block.content,
  27014. sourceRoot,
  27015. !pad || block.type === "template" ? block.loc.start.line - 1 : 0,
  27016. columnOffset
  27017. );
  27018. }
  27019. };
  27020. genMap(descriptor.template, templateColumnOffset);
  27021. genMap(descriptor.script);
  27022. descriptor.styles.forEach((s) => genMap(s));
  27023. descriptor.customBlocks.forEach((s) => genMap(s));
  27024. }
  27025. descriptor.cssVars = parseCssVars(descriptor);
  27026. const slottedRE = /(?:::v-|:)slotted\(/;
  27027. descriptor.slotted = descriptor.styles.some(
  27028. (s) => s.scoped && slottedRE.test(s.content)
  27029. );
  27030. const result = {
  27031. descriptor,
  27032. errors
  27033. };
  27034. parseCache$1.set(sourceKey, result);
  27035. return result;
  27036. }
  27037. function createDuplicateBlockError(node, isScriptSetup = false) {
  27038. const err = new SyntaxError(
  27039. `Single file component can contain only one <${node.tag}${isScriptSetup ? ` setup` : ``}> element`
  27040. );
  27041. err.loc = node.loc;
  27042. return err;
  27043. }
  27044. function createBlock(node, source, pad) {
  27045. const type = node.tag;
  27046. let { start, end } = node.loc;
  27047. let content = "";
  27048. if (node.children.length) {
  27049. start = node.children[0].loc.start;
  27050. end = node.children[node.children.length - 1].loc.end;
  27051. content = source.slice(start.offset, end.offset);
  27052. } else {
  27053. const offset = node.loc.source.indexOf(`</`);
  27054. if (offset > -1) {
  27055. start = {
  27056. line: start.line,
  27057. column: start.column + offset,
  27058. offset: start.offset + offset
  27059. };
  27060. }
  27061. end = __spreadValues$a({}, start);
  27062. }
  27063. const loc = {
  27064. source: content,
  27065. start,
  27066. end
  27067. };
  27068. const attrs = {};
  27069. const block = {
  27070. type,
  27071. content,
  27072. loc,
  27073. attrs
  27074. };
  27075. if (pad) {
  27076. block.content = padContent(source, block, pad) + block.content;
  27077. }
  27078. node.props.forEach((p) => {
  27079. if (p.type === 6) {
  27080. attrs[p.name] = p.value ? p.value.content || true : true;
  27081. if (p.name === "lang") {
  27082. block.lang = p.value && p.value.content;
  27083. } else if (p.name === "src") {
  27084. block.src = p.value && p.value.content;
  27085. } else if (type === "style") {
  27086. if (p.name === "scoped") {
  27087. block.scoped = true;
  27088. } else if (p.name === "module") {
  27089. block.module = attrs[p.name];
  27090. }
  27091. } else if (type === "script" && p.name === "setup") {
  27092. block.setup = attrs.setup;
  27093. }
  27094. }
  27095. });
  27096. return block;
  27097. }
  27098. const splitRE = /\r?\n/g;
  27099. const emptyRE = /^(?:\/\/)?\s*$/;
  27100. const replaceRE = /./g;
  27101. function generateSourceMap(filename, source, generated, sourceRoot, lineOffset, columnOffset) {
  27102. const map = new SourceMapGenerator$6({
  27103. file: filename.replace(/\\/g, "/"),
  27104. sourceRoot: sourceRoot.replace(/\\/g, "/")
  27105. });
  27106. map.setSourceContent(filename, source);
  27107. generated.split(splitRE).forEach((line, index) => {
  27108. if (!emptyRE.test(line)) {
  27109. const originalLine = index + 1 + lineOffset;
  27110. const generatedLine = index + 1;
  27111. for (let i = 0; i < line.length; i++) {
  27112. if (!/\s/.test(line[i])) {
  27113. map.addMapping({
  27114. source: filename,
  27115. original: {
  27116. line: originalLine,
  27117. column: i + columnOffset
  27118. },
  27119. generated: {
  27120. line: generatedLine,
  27121. column: i
  27122. }
  27123. });
  27124. }
  27125. }
  27126. }
  27127. });
  27128. return JSON.parse(map.toString());
  27129. }
  27130. function padContent(content, block, pad) {
  27131. content = content.slice(0, block.loc.start.offset);
  27132. if (pad === "space") {
  27133. return content.replace(replaceRE, " ");
  27134. } else {
  27135. const offset = content.split(splitRE).length;
  27136. const padChar = block.type === "script" && !block.lang ? "//\n" : "\n";
  27137. return Array(offset).join(padChar);
  27138. }
  27139. }
  27140. function hasSrc(node) {
  27141. return node.props.some((p) => {
  27142. if (p.type !== 6) {
  27143. return false;
  27144. }
  27145. return p.name === "src";
  27146. });
  27147. }
  27148. function isEmpty(node) {
  27149. for (let i = 0; i < node.children.length; i++) {
  27150. const child = node.children[i];
  27151. if (child.type !== 2 || child.content.trim() !== "") {
  27152. return false;
  27153. }
  27154. }
  27155. return true;
  27156. }
  27157. function hmrShouldReload(prevImports, next) {
  27158. if (!next.scriptSetup || next.scriptSetup.lang !== "ts" && next.scriptSetup.lang !== "tsx") {
  27159. return false;
  27160. }
  27161. for (const key in prevImports) {
  27162. if (!prevImports[key].isUsedInTemplate && isImportUsed(key, next)) {
  27163. return true;
  27164. }
  27165. }
  27166. return false;
  27167. }
  27168. function dedent(s) {
  27169. const lines = s.split("\n");
  27170. const minIndent = lines.reduce(function(minIndent2, line) {
  27171. var _a, _b;
  27172. if (line.trim() === "") {
  27173. return minIndent2;
  27174. }
  27175. const indent = ((_b = (_a = line.match(/^\s*/)) == null ? void 0 : _a[0]) == null ? void 0 : _b.length) || 0;
  27176. return Math.min(indent, minIndent2);
  27177. }, Infinity);
  27178. if (minIndent === 0) {
  27179. return [s, minIndent];
  27180. }
  27181. return [
  27182. lines.map(function(line) {
  27183. return line.slice(minIndent);
  27184. }).join("\n"),
  27185. minIndent
  27186. ];
  27187. }
  27188. /*! https://mths.be/punycode v1.4.1 by @mathias */
  27189. /** Highest positive signed 32-bit float value */
  27190. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  27191. /** Bootstring parameters */
  27192. var base = 36;
  27193. var tMin = 1;
  27194. var tMax = 26;
  27195. var skew = 38;
  27196. var damp = 700;
  27197. var initialBias = 72;
  27198. var initialN = 128; // 0x80
  27199. var delimiter = '-'; // '\x2D'
  27200. var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
  27201. var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  27202. /** Error messages */
  27203. var errors = {
  27204. 'overflow': 'Overflow: input needs wider integers to process',
  27205. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  27206. 'invalid-input': 'Invalid input'
  27207. };
  27208. /** Convenience shortcuts */
  27209. var baseMinusTMin = base - tMin;
  27210. var floor = Math.floor;
  27211. var stringFromCharCode = String.fromCharCode;
  27212. /*--------------------------------------------------------------------------*/
  27213. /**
  27214. * A generic error utility function.
  27215. * @private
  27216. * @param {String} type The error type.
  27217. * @returns {Error} Throws a `RangeError` with the applicable error message.
  27218. */
  27219. function error(type) {
  27220. throw new RangeError(errors[type]);
  27221. }
  27222. /**
  27223. * A generic `Array#map` utility function.
  27224. * @private
  27225. * @param {Array} array The array to iterate over.
  27226. * @param {Function} callback The function that gets called for every array
  27227. * item.
  27228. * @returns {Array} A new array of values returned by the callback function.
  27229. */
  27230. function map$1(array, fn) {
  27231. var length = array.length;
  27232. var result = [];
  27233. while (length--) {
  27234. result[length] = fn(array[length]);
  27235. }
  27236. return result;
  27237. }
  27238. /**
  27239. * A simple `Array#map`-like wrapper to work with domain name strings or email
  27240. * addresses.
  27241. * @private
  27242. * @param {String} domain The domain name or email address.
  27243. * @param {Function} callback The function that gets called for every
  27244. * character.
  27245. * @returns {Array} A new string of characters returned by the callback
  27246. * function.
  27247. */
  27248. function mapDomain(string, fn) {
  27249. var parts = string.split('@');
  27250. var result = '';
  27251. if (parts.length > 1) {
  27252. // In email addresses, only the domain name should be punycoded. Leave
  27253. // the local part (i.e. everything up to `@`) intact.
  27254. result = parts[0] + '@';
  27255. string = parts[1];
  27256. }
  27257. // Avoid `split(regex)` for IE8 compatibility. See #17.
  27258. string = string.replace(regexSeparators, '\x2E');
  27259. var labels = string.split('.');
  27260. var encoded = map$1(labels, fn).join('.');
  27261. return result + encoded;
  27262. }
  27263. /**
  27264. * Creates an array containing the numeric code points of each Unicode
  27265. * character in the string. While JavaScript uses UCS-2 internally,
  27266. * this function will convert a pair of surrogate halves (each of which
  27267. * UCS-2 exposes as separate characters) into a single code point,
  27268. * matching UTF-16.
  27269. * @see `punycode.ucs2.encode`
  27270. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  27271. * @memberOf punycode.ucs2
  27272. * @name decode
  27273. * @param {String} string The Unicode input string (UCS-2).
  27274. * @returns {Array} The new array of code points.
  27275. */
  27276. function ucs2decode(string) {
  27277. var output = [],
  27278. counter = 0,
  27279. length = string.length,
  27280. value,
  27281. extra;
  27282. while (counter < length) {
  27283. value = string.charCodeAt(counter++);
  27284. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  27285. // high surrogate, and there is a next character
  27286. extra = string.charCodeAt(counter++);
  27287. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  27288. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  27289. } else {
  27290. // unmatched surrogate; only append this code unit, in case the next
  27291. // code unit is the high surrogate of a surrogate pair
  27292. output.push(value);
  27293. counter--;
  27294. }
  27295. } else {
  27296. output.push(value);
  27297. }
  27298. }
  27299. return output;
  27300. }
  27301. /**
  27302. * Converts a digit/integer into a basic code point.
  27303. * @see `basicToDigit()`
  27304. * @private
  27305. * @param {Number} digit The numeric value of a basic code point.
  27306. * @returns {Number} The basic code point whose value (when used for
  27307. * representing integers) is `digit`, which needs to be in the range
  27308. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  27309. * used; else, the lowercase form is used. The behavior is undefined
  27310. * if `flag` is non-zero and `digit` has no uppercase form.
  27311. */
  27312. function digitToBasic(digit, flag) {
  27313. // 0..25 map to ASCII a..z or A..Z
  27314. // 26..35 map to ASCII 0..9
  27315. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  27316. }
  27317. /**
  27318. * Bias adaptation function as per section 3.4 of RFC 3492.
  27319. * https://tools.ietf.org/html/rfc3492#section-3.4
  27320. * @private
  27321. */
  27322. function adapt(delta, numPoints, firstTime) {
  27323. var k = 0;
  27324. delta = firstTime ? floor(delta / damp) : delta >> 1;
  27325. delta += floor(delta / numPoints);
  27326. for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
  27327. delta = floor(delta / baseMinusTMin);
  27328. }
  27329. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  27330. }
  27331. /**
  27332. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  27333. * Punycode string of ASCII-only symbols.
  27334. * @memberOf punycode
  27335. * @param {String} input The string of Unicode symbols.
  27336. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  27337. */
  27338. function encode$1(input) {
  27339. var n,
  27340. delta,
  27341. handledCPCount,
  27342. basicLength,
  27343. bias,
  27344. j,
  27345. m,
  27346. q,
  27347. k,
  27348. t,
  27349. currentValue,
  27350. output = [],
  27351. /** `inputLength` will hold the number of code points in `input`. */
  27352. inputLength,
  27353. /** Cached calculation results */
  27354. handledCPCountPlusOne,
  27355. baseMinusT,
  27356. qMinusT;
  27357. // Convert the input in UCS-2 to Unicode
  27358. input = ucs2decode(input);
  27359. // Cache the length
  27360. inputLength = input.length;
  27361. // Initialize the state
  27362. n = initialN;
  27363. delta = 0;
  27364. bias = initialBias;
  27365. // Handle the basic code points
  27366. for (j = 0; j < inputLength; ++j) {
  27367. currentValue = input[j];
  27368. if (currentValue < 0x80) {
  27369. output.push(stringFromCharCode(currentValue));
  27370. }
  27371. }
  27372. handledCPCount = basicLength = output.length;
  27373. // `handledCPCount` is the number of code points that have been handled;
  27374. // `basicLength` is the number of basic code points.
  27375. // Finish the basic string - if it is not empty - with a delimiter
  27376. if (basicLength) {
  27377. output.push(delimiter);
  27378. }
  27379. // Main encoding loop:
  27380. while (handledCPCount < inputLength) {
  27381. // All non-basic code points < n have been handled already. Find the next
  27382. // larger one:
  27383. for (m = maxInt, j = 0; j < inputLength; ++j) {
  27384. currentValue = input[j];
  27385. if (currentValue >= n && currentValue < m) {
  27386. m = currentValue;
  27387. }
  27388. }
  27389. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  27390. // but guard against overflow
  27391. handledCPCountPlusOne = handledCPCount + 1;
  27392. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  27393. error('overflow');
  27394. }
  27395. delta += (m - n) * handledCPCountPlusOne;
  27396. n = m;
  27397. for (j = 0; j < inputLength; ++j) {
  27398. currentValue = input[j];
  27399. if (currentValue < n && ++delta > maxInt) {
  27400. error('overflow');
  27401. }
  27402. if (currentValue == n) {
  27403. // Represent delta as a generalized variable-length integer
  27404. for (q = delta, k = base; /* no condition */ ; k += base) {
  27405. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  27406. if (q < t) {
  27407. break;
  27408. }
  27409. qMinusT = q - t;
  27410. baseMinusT = base - t;
  27411. output.push(
  27412. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  27413. );
  27414. q = floor(qMinusT / baseMinusT);
  27415. }
  27416. output.push(stringFromCharCode(digitToBasic(q, 0)));
  27417. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  27418. delta = 0;
  27419. ++handledCPCount;
  27420. }
  27421. }
  27422. ++delta;
  27423. ++n;
  27424. }
  27425. return output.join('');
  27426. }
  27427. /**
  27428. * Converts a Unicode string representing a domain name or an email address to
  27429. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  27430. * i.e. it doesn't matter if you call it with a domain that's already in
  27431. * ASCII.
  27432. * @memberOf punycode
  27433. * @param {String} input The domain name or email address to convert, as a
  27434. * Unicode string.
  27435. * @returns {String} The Punycode representation of the given domain name or
  27436. * email address.
  27437. */
  27438. function toASCII(input) {
  27439. return mapDomain(input, function(string) {
  27440. return regexNonASCII.test(string) ?
  27441. 'xn--' + encode$1(string) :
  27442. string;
  27443. });
  27444. }
  27445. var lookup = [];
  27446. var revLookup = [];
  27447. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  27448. var inited = false;
  27449. function init () {
  27450. inited = true;
  27451. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  27452. for (var i = 0, len = code.length; i < len; ++i) {
  27453. lookup[i] = code[i];
  27454. revLookup[code.charCodeAt(i)] = i;
  27455. }
  27456. revLookup['-'.charCodeAt(0)] = 62;
  27457. revLookup['_'.charCodeAt(0)] = 63;
  27458. }
  27459. function toByteArray (b64) {
  27460. if (!inited) {
  27461. init();
  27462. }
  27463. var i, j, l, tmp, placeHolders, arr;
  27464. var len = b64.length;
  27465. if (len % 4 > 0) {
  27466. throw new Error('Invalid string. Length must be a multiple of 4')
  27467. }
  27468. // the number of equal signs (place holders)
  27469. // if there are two placeholders, than the two characters before it
  27470. // represent one byte
  27471. // if there is only one, then the three characters before it represent 2 bytes
  27472. // this is just a cheap hack to not do indexOf twice
  27473. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
  27474. // base64 is 4/3 + up to two characters of the original data
  27475. arr = new Arr(len * 3 / 4 - placeHolders);
  27476. // if there are placeholders, only get up to the last complete 4 chars
  27477. l = placeHolders > 0 ? len - 4 : len;
  27478. var L = 0;
  27479. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  27480. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
  27481. arr[L++] = (tmp >> 16) & 0xFF;
  27482. arr[L++] = (tmp >> 8) & 0xFF;
  27483. arr[L++] = tmp & 0xFF;
  27484. }
  27485. if (placeHolders === 2) {
  27486. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
  27487. arr[L++] = tmp & 0xFF;
  27488. } else if (placeHolders === 1) {
  27489. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
  27490. arr[L++] = (tmp >> 8) & 0xFF;
  27491. arr[L++] = tmp & 0xFF;
  27492. }
  27493. return arr
  27494. }
  27495. function tripletToBase64 (num) {
  27496. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  27497. }
  27498. function encodeChunk (uint8, start, end) {
  27499. var tmp;
  27500. var output = [];
  27501. for (var i = start; i < end; i += 3) {
  27502. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  27503. output.push(tripletToBase64(tmp));
  27504. }
  27505. return output.join('')
  27506. }
  27507. function fromByteArray (uint8) {
  27508. if (!inited) {
  27509. init();
  27510. }
  27511. var tmp;
  27512. var len = uint8.length;
  27513. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  27514. var output = '';
  27515. var parts = [];
  27516. var maxChunkLength = 16383; // must be multiple of 3
  27517. // go through the array every three bytes, we'll deal with trailing stuff later
  27518. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  27519. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
  27520. }
  27521. // pad the end with zeros, but make sure to not forget the extra bytes
  27522. if (extraBytes === 1) {
  27523. tmp = uint8[len - 1];
  27524. output += lookup[tmp >> 2];
  27525. output += lookup[(tmp << 4) & 0x3F];
  27526. output += '==';
  27527. } else if (extraBytes === 2) {
  27528. tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
  27529. output += lookup[tmp >> 10];
  27530. output += lookup[(tmp >> 4) & 0x3F];
  27531. output += lookup[(tmp << 2) & 0x3F];
  27532. output += '=';
  27533. }
  27534. parts.push(output);
  27535. return parts.join('')
  27536. }
  27537. function read (buffer, offset, isLE, mLen, nBytes) {
  27538. var e, m;
  27539. var eLen = nBytes * 8 - mLen - 1;
  27540. var eMax = (1 << eLen) - 1;
  27541. var eBias = eMax >> 1;
  27542. var nBits = -7;
  27543. var i = isLE ? (nBytes - 1) : 0;
  27544. var d = isLE ? -1 : 1;
  27545. var s = buffer[offset + i];
  27546. i += d;
  27547. e = s & ((1 << (-nBits)) - 1);
  27548. s >>= (-nBits);
  27549. nBits += eLen;
  27550. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27551. m = e & ((1 << (-nBits)) - 1);
  27552. e >>= (-nBits);
  27553. nBits += mLen;
  27554. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27555. if (e === 0) {
  27556. e = 1 - eBias;
  27557. } else if (e === eMax) {
  27558. return m ? NaN : ((s ? -1 : 1) * Infinity)
  27559. } else {
  27560. m = m + Math.pow(2, mLen);
  27561. e = e - eBias;
  27562. }
  27563. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  27564. }
  27565. function write (buffer, value, offset, isLE, mLen, nBytes) {
  27566. var e, m, c;
  27567. var eLen = nBytes * 8 - mLen - 1;
  27568. var eMax = (1 << eLen) - 1;
  27569. var eBias = eMax >> 1;
  27570. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
  27571. var i = isLE ? 0 : (nBytes - 1);
  27572. var d = isLE ? 1 : -1;
  27573. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  27574. value = Math.abs(value);
  27575. if (isNaN(value) || value === Infinity) {
  27576. m = isNaN(value) ? 1 : 0;
  27577. e = eMax;
  27578. } else {
  27579. e = Math.floor(Math.log(value) / Math.LN2);
  27580. if (value * (c = Math.pow(2, -e)) < 1) {
  27581. e--;
  27582. c *= 2;
  27583. }
  27584. if (e + eBias >= 1) {
  27585. value += rt / c;
  27586. } else {
  27587. value += rt * Math.pow(2, 1 - eBias);
  27588. }
  27589. if (value * c >= 2) {
  27590. e++;
  27591. c /= 2;
  27592. }
  27593. if (e + eBias >= eMax) {
  27594. m = 0;
  27595. e = eMax;
  27596. } else if (e + eBias >= 1) {
  27597. m = (value * c - 1) * Math.pow(2, mLen);
  27598. e = e + eBias;
  27599. } else {
  27600. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  27601. e = 0;
  27602. }
  27603. }
  27604. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  27605. e = (e << mLen) | m;
  27606. eLen += mLen;
  27607. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  27608. buffer[offset + i - d] |= s * 128;
  27609. }
  27610. var toString$1 = {}.toString;
  27611. var isArray$2 = Array.isArray || function (arr) {
  27612. return toString$1.call(arr) == '[object Array]';
  27613. };
  27614. /*!
  27615. * The buffer module from node.js, for the browser.
  27616. *
  27617. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  27618. * @license MIT
  27619. */
  27620. var INSPECT_MAX_BYTES = 50;
  27621. /**
  27622. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  27623. * === true Use Uint8Array implementation (fastest)
  27624. * === false Use Object implementation (most compatible, even IE6)
  27625. *
  27626. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  27627. * Opera 11.6+, iOS 4.2+.
  27628. *
  27629. * Due to various browser bugs, sometimes the Object implementation will be used even
  27630. * when the browser supports typed arrays.
  27631. *
  27632. * Note:
  27633. *
  27634. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  27635. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  27636. *
  27637. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  27638. *
  27639. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  27640. * incorrect length in some situations.
  27641. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  27642. * get the Object implementation, which is slower but behaves correctly.
  27643. */
  27644. Buffer$1.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
  27645. ? global$1.TYPED_ARRAY_SUPPORT
  27646. : true;
  27647. /*
  27648. * Export kMaxLength after typed array support is determined.
  27649. */
  27650. kMaxLength();
  27651. function kMaxLength () {
  27652. return Buffer$1.TYPED_ARRAY_SUPPORT
  27653. ? 0x7fffffff
  27654. : 0x3fffffff
  27655. }
  27656. function createBuffer (that, length) {
  27657. if (kMaxLength() < length) {
  27658. throw new RangeError('Invalid typed array length')
  27659. }
  27660. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27661. // Return an augmented `Uint8Array` instance, for best performance
  27662. that = new Uint8Array(length);
  27663. that.__proto__ = Buffer$1.prototype;
  27664. } else {
  27665. // Fallback: Return an object instance of the Buffer class
  27666. if (that === null) {
  27667. that = new Buffer$1(length);
  27668. }
  27669. that.length = length;
  27670. }
  27671. return that
  27672. }
  27673. /**
  27674. * The Buffer constructor returns instances of `Uint8Array` that have their
  27675. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  27676. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  27677. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  27678. * returns a single octet.
  27679. *
  27680. * The `Uint8Array` prototype remains unmodified.
  27681. */
  27682. function Buffer$1 (arg, encodingOrOffset, length) {
  27683. if (!Buffer$1.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer$1)) {
  27684. return new Buffer$1(arg, encodingOrOffset, length)
  27685. }
  27686. // Common case.
  27687. if (typeof arg === 'number') {
  27688. if (typeof encodingOrOffset === 'string') {
  27689. throw new Error(
  27690. 'If encoding is specified then the first argument must be a string'
  27691. )
  27692. }
  27693. return allocUnsafe(this, arg)
  27694. }
  27695. return from(this, arg, encodingOrOffset, length)
  27696. }
  27697. Buffer$1.poolSize = 8192; // not used by this implementation
  27698. // TODO: Legacy, not needed anymore. Remove in next major version.
  27699. Buffer$1._augment = function (arr) {
  27700. arr.__proto__ = Buffer$1.prototype;
  27701. return arr
  27702. };
  27703. function from (that, value, encodingOrOffset, length) {
  27704. if (typeof value === 'number') {
  27705. throw new TypeError('"value" argument must not be a number')
  27706. }
  27707. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  27708. return fromArrayBuffer(that, value, encodingOrOffset, length)
  27709. }
  27710. if (typeof value === 'string') {
  27711. return fromString(that, value, encodingOrOffset)
  27712. }
  27713. return fromObject(that, value)
  27714. }
  27715. /**
  27716. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  27717. * if value is a number.
  27718. * Buffer.from(str[, encoding])
  27719. * Buffer.from(array)
  27720. * Buffer.from(buffer)
  27721. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  27722. **/
  27723. Buffer$1.from = function (value, encodingOrOffset, length) {
  27724. return from(null, value, encodingOrOffset, length)
  27725. };
  27726. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27727. Buffer$1.prototype.__proto__ = Uint8Array.prototype;
  27728. Buffer$1.__proto__ = Uint8Array;
  27729. if (typeof Symbol !== 'undefined' && Symbol.species &&
  27730. Buffer$1[Symbol.species] === Buffer$1) ;
  27731. }
  27732. function assertSize (size) {
  27733. if (typeof size !== 'number') {
  27734. throw new TypeError('"size" argument must be a number')
  27735. } else if (size < 0) {
  27736. throw new RangeError('"size" argument must not be negative')
  27737. }
  27738. }
  27739. function alloc (that, size, fill, encoding) {
  27740. assertSize(size);
  27741. if (size <= 0) {
  27742. return createBuffer(that, size)
  27743. }
  27744. if (fill !== undefined) {
  27745. // Only pay attention to encoding if it's a string. This
  27746. // prevents accidentally sending in a number that would
  27747. // be interpretted as a start offset.
  27748. return typeof encoding === 'string'
  27749. ? createBuffer(that, size).fill(fill, encoding)
  27750. : createBuffer(that, size).fill(fill)
  27751. }
  27752. return createBuffer(that, size)
  27753. }
  27754. /**
  27755. * Creates a new filled Buffer instance.
  27756. * alloc(size[, fill[, encoding]])
  27757. **/
  27758. Buffer$1.alloc = function (size, fill, encoding) {
  27759. return alloc(null, size, fill, encoding)
  27760. };
  27761. function allocUnsafe (that, size) {
  27762. assertSize(size);
  27763. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  27764. if (!Buffer$1.TYPED_ARRAY_SUPPORT) {
  27765. for (var i = 0; i < size; ++i) {
  27766. that[i] = 0;
  27767. }
  27768. }
  27769. return that
  27770. }
  27771. /**
  27772. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  27773. * */
  27774. Buffer$1.allocUnsafe = function (size) {
  27775. return allocUnsafe(null, size)
  27776. };
  27777. /**
  27778. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  27779. */
  27780. Buffer$1.allocUnsafeSlow = function (size) {
  27781. return allocUnsafe(null, size)
  27782. };
  27783. function fromString (that, string, encoding) {
  27784. if (typeof encoding !== 'string' || encoding === '') {
  27785. encoding = 'utf8';
  27786. }
  27787. if (!Buffer$1.isEncoding(encoding)) {
  27788. throw new TypeError('"encoding" must be a valid string encoding')
  27789. }
  27790. var length = byteLength(string, encoding) | 0;
  27791. that = createBuffer(that, length);
  27792. var actual = that.write(string, encoding);
  27793. if (actual !== length) {
  27794. // Writing a hex string, for example, that contains invalid characters will
  27795. // cause everything after the first invalid character to be ignored. (e.g.
  27796. // 'abxxcd' will be treated as 'ab')
  27797. that = that.slice(0, actual);
  27798. }
  27799. return that
  27800. }
  27801. function fromArrayLike (that, array) {
  27802. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  27803. that = createBuffer(that, length);
  27804. for (var i = 0; i < length; i += 1) {
  27805. that[i] = array[i] & 255;
  27806. }
  27807. return that
  27808. }
  27809. function fromArrayBuffer (that, array, byteOffset, length) {
  27810. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  27811. if (byteOffset < 0 || array.byteLength < byteOffset) {
  27812. throw new RangeError('\'offset\' is out of bounds')
  27813. }
  27814. if (array.byteLength < byteOffset + (length || 0)) {
  27815. throw new RangeError('\'length\' is out of bounds')
  27816. }
  27817. if (byteOffset === undefined && length === undefined) {
  27818. array = new Uint8Array(array);
  27819. } else if (length === undefined) {
  27820. array = new Uint8Array(array, byteOffset);
  27821. } else {
  27822. array = new Uint8Array(array, byteOffset, length);
  27823. }
  27824. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27825. // Return an augmented `Uint8Array` instance, for best performance
  27826. that = array;
  27827. that.__proto__ = Buffer$1.prototype;
  27828. } else {
  27829. // Fallback: Return an object instance of the Buffer class
  27830. that = fromArrayLike(that, array);
  27831. }
  27832. return that
  27833. }
  27834. function fromObject (that, obj) {
  27835. if (internalIsBuffer(obj)) {
  27836. var len = checked(obj.length) | 0;
  27837. that = createBuffer(that, len);
  27838. if (that.length === 0) {
  27839. return that
  27840. }
  27841. obj.copy(that, 0, 0, len);
  27842. return that
  27843. }
  27844. if (obj) {
  27845. if ((typeof ArrayBuffer !== 'undefined' &&
  27846. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  27847. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  27848. return createBuffer(that, 0)
  27849. }
  27850. return fromArrayLike(that, obj)
  27851. }
  27852. if (obj.type === 'Buffer' && isArray$2(obj.data)) {
  27853. return fromArrayLike(that, obj.data)
  27854. }
  27855. }
  27856. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  27857. }
  27858. function checked (length) {
  27859. // Note: cannot use `length < kMaxLength()` here because that fails when
  27860. // length is NaN (which is otherwise coerced to zero.)
  27861. if (length >= kMaxLength()) {
  27862. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  27863. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  27864. }
  27865. return length | 0
  27866. }
  27867. Buffer$1.isBuffer = isBuffer$1;
  27868. function internalIsBuffer (b) {
  27869. return !!(b != null && b._isBuffer)
  27870. }
  27871. Buffer$1.compare = function compare (a, b) {
  27872. if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
  27873. throw new TypeError('Arguments must be Buffers')
  27874. }
  27875. if (a === b) return 0
  27876. var x = a.length;
  27877. var y = b.length;
  27878. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  27879. if (a[i] !== b[i]) {
  27880. x = a[i];
  27881. y = b[i];
  27882. break
  27883. }
  27884. }
  27885. if (x < y) return -1
  27886. if (y < x) return 1
  27887. return 0
  27888. };
  27889. Buffer$1.isEncoding = function isEncoding (encoding) {
  27890. switch (String(encoding).toLowerCase()) {
  27891. case 'hex':
  27892. case 'utf8':
  27893. case 'utf-8':
  27894. case 'ascii':
  27895. case 'latin1':
  27896. case 'binary':
  27897. case 'base64':
  27898. case 'ucs2':
  27899. case 'ucs-2':
  27900. case 'utf16le':
  27901. case 'utf-16le':
  27902. return true
  27903. default:
  27904. return false
  27905. }
  27906. };
  27907. Buffer$1.concat = function concat (list, length) {
  27908. if (!isArray$2(list)) {
  27909. throw new TypeError('"list" argument must be an Array of Buffers')
  27910. }
  27911. if (list.length === 0) {
  27912. return Buffer$1.alloc(0)
  27913. }
  27914. var i;
  27915. if (length === undefined) {
  27916. length = 0;
  27917. for (i = 0; i < list.length; ++i) {
  27918. length += list[i].length;
  27919. }
  27920. }
  27921. var buffer = Buffer$1.allocUnsafe(length);
  27922. var pos = 0;
  27923. for (i = 0; i < list.length; ++i) {
  27924. var buf = list[i];
  27925. if (!internalIsBuffer(buf)) {
  27926. throw new TypeError('"list" argument must be an Array of Buffers')
  27927. }
  27928. buf.copy(buffer, pos);
  27929. pos += buf.length;
  27930. }
  27931. return buffer
  27932. };
  27933. function byteLength (string, encoding) {
  27934. if (internalIsBuffer(string)) {
  27935. return string.length
  27936. }
  27937. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  27938. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  27939. return string.byteLength
  27940. }
  27941. if (typeof string !== 'string') {
  27942. string = '' + string;
  27943. }
  27944. var len = string.length;
  27945. if (len === 0) return 0
  27946. // Use a for loop to avoid recursion
  27947. var loweredCase = false;
  27948. for (;;) {
  27949. switch (encoding) {
  27950. case 'ascii':
  27951. case 'latin1':
  27952. case 'binary':
  27953. return len
  27954. case 'utf8':
  27955. case 'utf-8':
  27956. case undefined:
  27957. return utf8ToBytes(string).length
  27958. case 'ucs2':
  27959. case 'ucs-2':
  27960. case 'utf16le':
  27961. case 'utf-16le':
  27962. return len * 2
  27963. case 'hex':
  27964. return len >>> 1
  27965. case 'base64':
  27966. return base64ToBytes(string).length
  27967. default:
  27968. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  27969. encoding = ('' + encoding).toLowerCase();
  27970. loweredCase = true;
  27971. }
  27972. }
  27973. }
  27974. Buffer$1.byteLength = byteLength;
  27975. function slowToString (encoding, start, end) {
  27976. var loweredCase = false;
  27977. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  27978. // property of a typed array.
  27979. // This behaves neither like String nor Uint8Array in that we set start/end
  27980. // to their upper/lower bounds if the value passed is out of range.
  27981. // undefined is handled specially as per ECMA-262 6th Edition,
  27982. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  27983. if (start === undefined || start < 0) {
  27984. start = 0;
  27985. }
  27986. // Return early if start > this.length. Done here to prevent potential uint32
  27987. // coercion fail below.
  27988. if (start > this.length) {
  27989. return ''
  27990. }
  27991. if (end === undefined || end > this.length) {
  27992. end = this.length;
  27993. }
  27994. if (end <= 0) {
  27995. return ''
  27996. }
  27997. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  27998. end >>>= 0;
  27999. start >>>= 0;
  28000. if (end <= start) {
  28001. return ''
  28002. }
  28003. if (!encoding) encoding = 'utf8';
  28004. while (true) {
  28005. switch (encoding) {
  28006. case 'hex':
  28007. return hexSlice(this, start, end)
  28008. case 'utf8':
  28009. case 'utf-8':
  28010. return utf8Slice(this, start, end)
  28011. case 'ascii':
  28012. return asciiSlice(this, start, end)
  28013. case 'latin1':
  28014. case 'binary':
  28015. return latin1Slice(this, start, end)
  28016. case 'base64':
  28017. return base64Slice(this, start, end)
  28018. case 'ucs2':
  28019. case 'ucs-2':
  28020. case 'utf16le':
  28021. case 'utf-16le':
  28022. return utf16leSlice(this, start, end)
  28023. default:
  28024. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  28025. encoding = (encoding + '').toLowerCase();
  28026. loweredCase = true;
  28027. }
  28028. }
  28029. }
  28030. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  28031. // Buffer instances.
  28032. Buffer$1.prototype._isBuffer = true;
  28033. function swap$1 (b, n, m) {
  28034. var i = b[n];
  28035. b[n] = b[m];
  28036. b[m] = i;
  28037. }
  28038. Buffer$1.prototype.swap16 = function swap16 () {
  28039. var len = this.length;
  28040. if (len % 2 !== 0) {
  28041. throw new RangeError('Buffer size must be a multiple of 16-bits')
  28042. }
  28043. for (var i = 0; i < len; i += 2) {
  28044. swap$1(this, i, i + 1);
  28045. }
  28046. return this
  28047. };
  28048. Buffer$1.prototype.swap32 = function swap32 () {
  28049. var len = this.length;
  28050. if (len % 4 !== 0) {
  28051. throw new RangeError('Buffer size must be a multiple of 32-bits')
  28052. }
  28053. for (var i = 0; i < len; i += 4) {
  28054. swap$1(this, i, i + 3);
  28055. swap$1(this, i + 1, i + 2);
  28056. }
  28057. return this
  28058. };
  28059. Buffer$1.prototype.swap64 = function swap64 () {
  28060. var len = this.length;
  28061. if (len % 8 !== 0) {
  28062. throw new RangeError('Buffer size must be a multiple of 64-bits')
  28063. }
  28064. for (var i = 0; i < len; i += 8) {
  28065. swap$1(this, i, i + 7);
  28066. swap$1(this, i + 1, i + 6);
  28067. swap$1(this, i + 2, i + 5);
  28068. swap$1(this, i + 3, i + 4);
  28069. }
  28070. return this
  28071. };
  28072. Buffer$1.prototype.toString = function toString () {
  28073. var length = this.length | 0;
  28074. if (length === 0) return ''
  28075. if (arguments.length === 0) return utf8Slice(this, 0, length)
  28076. return slowToString.apply(this, arguments)
  28077. };
  28078. Buffer$1.prototype.equals = function equals (b) {
  28079. if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
  28080. if (this === b) return true
  28081. return Buffer$1.compare(this, b) === 0
  28082. };
  28083. Buffer$1.prototype.inspect = function inspect () {
  28084. var str = '';
  28085. var max = INSPECT_MAX_BYTES;
  28086. if (this.length > 0) {
  28087. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  28088. if (this.length > max) str += ' ... ';
  28089. }
  28090. return '<Buffer ' + str + '>'
  28091. };
  28092. Buffer$1.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  28093. if (!internalIsBuffer(target)) {
  28094. throw new TypeError('Argument must be a Buffer')
  28095. }
  28096. if (start === undefined) {
  28097. start = 0;
  28098. }
  28099. if (end === undefined) {
  28100. end = target ? target.length : 0;
  28101. }
  28102. if (thisStart === undefined) {
  28103. thisStart = 0;
  28104. }
  28105. if (thisEnd === undefined) {
  28106. thisEnd = this.length;
  28107. }
  28108. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  28109. throw new RangeError('out of range index')
  28110. }
  28111. if (thisStart >= thisEnd && start >= end) {
  28112. return 0
  28113. }
  28114. if (thisStart >= thisEnd) {
  28115. return -1
  28116. }
  28117. if (start >= end) {
  28118. return 1
  28119. }
  28120. start >>>= 0;
  28121. end >>>= 0;
  28122. thisStart >>>= 0;
  28123. thisEnd >>>= 0;
  28124. if (this === target) return 0
  28125. var x = thisEnd - thisStart;
  28126. var y = end - start;
  28127. var len = Math.min(x, y);
  28128. var thisCopy = this.slice(thisStart, thisEnd);
  28129. var targetCopy = target.slice(start, end);
  28130. for (var i = 0; i < len; ++i) {
  28131. if (thisCopy[i] !== targetCopy[i]) {
  28132. x = thisCopy[i];
  28133. y = targetCopy[i];
  28134. break
  28135. }
  28136. }
  28137. if (x < y) return -1
  28138. if (y < x) return 1
  28139. return 0
  28140. };
  28141. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  28142. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  28143. //
  28144. // Arguments:
  28145. // - buffer - a Buffer to search
  28146. // - val - a string, Buffer, or number
  28147. // - byteOffset - an index into `buffer`; will be clamped to an int32
  28148. // - encoding - an optional encoding, relevant is val is a string
  28149. // - dir - true for indexOf, false for lastIndexOf
  28150. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  28151. // Empty buffer means no match
  28152. if (buffer.length === 0) return -1
  28153. // Normalize byteOffset
  28154. if (typeof byteOffset === 'string') {
  28155. encoding = byteOffset;
  28156. byteOffset = 0;
  28157. } else if (byteOffset > 0x7fffffff) {
  28158. byteOffset = 0x7fffffff;
  28159. } else if (byteOffset < -0x80000000) {
  28160. byteOffset = -0x80000000;
  28161. }
  28162. byteOffset = +byteOffset; // Coerce to Number.
  28163. if (isNaN(byteOffset)) {
  28164. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  28165. byteOffset = dir ? 0 : (buffer.length - 1);
  28166. }
  28167. // Normalize byteOffset: negative offsets start from the end of the buffer
  28168. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  28169. if (byteOffset >= buffer.length) {
  28170. if (dir) return -1
  28171. else byteOffset = buffer.length - 1;
  28172. } else if (byteOffset < 0) {
  28173. if (dir) byteOffset = 0;
  28174. else return -1
  28175. }
  28176. // Normalize val
  28177. if (typeof val === 'string') {
  28178. val = Buffer$1.from(val, encoding);
  28179. }
  28180. // Finally, search either indexOf (if dir is true) or lastIndexOf
  28181. if (internalIsBuffer(val)) {
  28182. // Special case: looking for empty string/buffer always fails
  28183. if (val.length === 0) {
  28184. return -1
  28185. }
  28186. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  28187. } else if (typeof val === 'number') {
  28188. val = val & 0xFF; // Search for a byte value [0-255]
  28189. if (Buffer$1.TYPED_ARRAY_SUPPORT &&
  28190. typeof Uint8Array.prototype.indexOf === 'function') {
  28191. if (dir) {
  28192. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  28193. } else {
  28194. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  28195. }
  28196. }
  28197. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  28198. }
  28199. throw new TypeError('val must be string, number or Buffer')
  28200. }
  28201. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  28202. var indexSize = 1;
  28203. var arrLength = arr.length;
  28204. var valLength = val.length;
  28205. if (encoding !== undefined) {
  28206. encoding = String(encoding).toLowerCase();
  28207. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  28208. encoding === 'utf16le' || encoding === 'utf-16le') {
  28209. if (arr.length < 2 || val.length < 2) {
  28210. return -1
  28211. }
  28212. indexSize = 2;
  28213. arrLength /= 2;
  28214. valLength /= 2;
  28215. byteOffset /= 2;
  28216. }
  28217. }
  28218. function read (buf, i) {
  28219. if (indexSize === 1) {
  28220. return buf[i]
  28221. } else {
  28222. return buf.readUInt16BE(i * indexSize)
  28223. }
  28224. }
  28225. var i;
  28226. if (dir) {
  28227. var foundIndex = -1;
  28228. for (i = byteOffset; i < arrLength; i++) {
  28229. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  28230. if (foundIndex === -1) foundIndex = i;
  28231. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  28232. } else {
  28233. if (foundIndex !== -1) i -= i - foundIndex;
  28234. foundIndex = -1;
  28235. }
  28236. }
  28237. } else {
  28238. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  28239. for (i = byteOffset; i >= 0; i--) {
  28240. var found = true;
  28241. for (var j = 0; j < valLength; j++) {
  28242. if (read(arr, i + j) !== read(val, j)) {
  28243. found = false;
  28244. break
  28245. }
  28246. }
  28247. if (found) return i
  28248. }
  28249. }
  28250. return -1
  28251. }
  28252. Buffer$1.prototype.includes = function includes (val, byteOffset, encoding) {
  28253. return this.indexOf(val, byteOffset, encoding) !== -1
  28254. };
  28255. Buffer$1.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  28256. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  28257. };
  28258. Buffer$1.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  28259. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  28260. };
  28261. function hexWrite (buf, string, offset, length) {
  28262. offset = Number(offset) || 0;
  28263. var remaining = buf.length - offset;
  28264. if (!length) {
  28265. length = remaining;
  28266. } else {
  28267. length = Number(length);
  28268. if (length > remaining) {
  28269. length = remaining;
  28270. }
  28271. }
  28272. // must be an even number of digits
  28273. var strLen = string.length;
  28274. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  28275. if (length > strLen / 2) {
  28276. length = strLen / 2;
  28277. }
  28278. for (var i = 0; i < length; ++i) {
  28279. var parsed = parseInt(string.substr(i * 2, 2), 16);
  28280. if (isNaN(parsed)) return i
  28281. buf[offset + i] = parsed;
  28282. }
  28283. return i
  28284. }
  28285. function utf8Write (buf, string, offset, length) {
  28286. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  28287. }
  28288. function asciiWrite (buf, string, offset, length) {
  28289. return blitBuffer(asciiToBytes(string), buf, offset, length)
  28290. }
  28291. function latin1Write (buf, string, offset, length) {
  28292. return asciiWrite(buf, string, offset, length)
  28293. }
  28294. function base64Write (buf, string, offset, length) {
  28295. return blitBuffer(base64ToBytes(string), buf, offset, length)
  28296. }
  28297. function ucs2Write (buf, string, offset, length) {
  28298. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  28299. }
  28300. Buffer$1.prototype.write = function write (string, offset, length, encoding) {
  28301. // Buffer#write(string)
  28302. if (offset === undefined) {
  28303. encoding = 'utf8';
  28304. length = this.length;
  28305. offset = 0;
  28306. // Buffer#write(string, encoding)
  28307. } else if (length === undefined && typeof offset === 'string') {
  28308. encoding = offset;
  28309. length = this.length;
  28310. offset = 0;
  28311. // Buffer#write(string, offset[, length][, encoding])
  28312. } else if (isFinite(offset)) {
  28313. offset = offset | 0;
  28314. if (isFinite(length)) {
  28315. length = length | 0;
  28316. if (encoding === undefined) encoding = 'utf8';
  28317. } else {
  28318. encoding = length;
  28319. length = undefined;
  28320. }
  28321. // legacy write(string, encoding, offset, length) - remove in v0.13
  28322. } else {
  28323. throw new Error(
  28324. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  28325. )
  28326. }
  28327. var remaining = this.length - offset;
  28328. if (length === undefined || length > remaining) length = remaining;
  28329. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  28330. throw new RangeError('Attempt to write outside buffer bounds')
  28331. }
  28332. if (!encoding) encoding = 'utf8';
  28333. var loweredCase = false;
  28334. for (;;) {
  28335. switch (encoding) {
  28336. case 'hex':
  28337. return hexWrite(this, string, offset, length)
  28338. case 'utf8':
  28339. case 'utf-8':
  28340. return utf8Write(this, string, offset, length)
  28341. case 'ascii':
  28342. return asciiWrite(this, string, offset, length)
  28343. case 'latin1':
  28344. case 'binary':
  28345. return latin1Write(this, string, offset, length)
  28346. case 'base64':
  28347. // Warning: maxLength not taken into account in base64Write
  28348. return base64Write(this, string, offset, length)
  28349. case 'ucs2':
  28350. case 'ucs-2':
  28351. case 'utf16le':
  28352. case 'utf-16le':
  28353. return ucs2Write(this, string, offset, length)
  28354. default:
  28355. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  28356. encoding = ('' + encoding).toLowerCase();
  28357. loweredCase = true;
  28358. }
  28359. }
  28360. };
  28361. Buffer$1.prototype.toJSON = function toJSON () {
  28362. return {
  28363. type: 'Buffer',
  28364. data: Array.prototype.slice.call(this._arr || this, 0)
  28365. }
  28366. };
  28367. function base64Slice (buf, start, end) {
  28368. if (start === 0 && end === buf.length) {
  28369. return fromByteArray(buf)
  28370. } else {
  28371. return fromByteArray(buf.slice(start, end))
  28372. }
  28373. }
  28374. function utf8Slice (buf, start, end) {
  28375. end = Math.min(buf.length, end);
  28376. var res = [];
  28377. var i = start;
  28378. while (i < end) {
  28379. var firstByte = buf[i];
  28380. var codePoint = null;
  28381. var bytesPerSequence = (firstByte > 0xEF) ? 4
  28382. : (firstByte > 0xDF) ? 3
  28383. : (firstByte > 0xBF) ? 2
  28384. : 1;
  28385. if (i + bytesPerSequence <= end) {
  28386. var secondByte, thirdByte, fourthByte, tempCodePoint;
  28387. switch (bytesPerSequence) {
  28388. case 1:
  28389. if (firstByte < 0x80) {
  28390. codePoint = firstByte;
  28391. }
  28392. break
  28393. case 2:
  28394. secondByte = buf[i + 1];
  28395. if ((secondByte & 0xC0) === 0x80) {
  28396. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
  28397. if (tempCodePoint > 0x7F) {
  28398. codePoint = tempCodePoint;
  28399. }
  28400. }
  28401. break
  28402. case 3:
  28403. secondByte = buf[i + 1];
  28404. thirdByte = buf[i + 2];
  28405. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  28406. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
  28407. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  28408. codePoint = tempCodePoint;
  28409. }
  28410. }
  28411. break
  28412. case 4:
  28413. secondByte = buf[i + 1];
  28414. thirdByte = buf[i + 2];
  28415. fourthByte = buf[i + 3];
  28416. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  28417. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
  28418. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  28419. codePoint = tempCodePoint;
  28420. }
  28421. }
  28422. }
  28423. }
  28424. if (codePoint === null) {
  28425. // we did not generate a valid codePoint so insert a
  28426. // replacement char (U+FFFD) and advance only 1 byte
  28427. codePoint = 0xFFFD;
  28428. bytesPerSequence = 1;
  28429. } else if (codePoint > 0xFFFF) {
  28430. // encode to utf16 (surrogate pair dance)
  28431. codePoint -= 0x10000;
  28432. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  28433. codePoint = 0xDC00 | codePoint & 0x3FF;
  28434. }
  28435. res.push(codePoint);
  28436. i += bytesPerSequence;
  28437. }
  28438. return decodeCodePointsArray(res)
  28439. }
  28440. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  28441. // the lowest limit is Chrome, with 0x10000 args.
  28442. // We go 1 magnitude less, for safety
  28443. var MAX_ARGUMENTS_LENGTH = 0x1000;
  28444. function decodeCodePointsArray (codePoints) {
  28445. var len = codePoints.length;
  28446. if (len <= MAX_ARGUMENTS_LENGTH) {
  28447. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  28448. }
  28449. // Decode in chunks to avoid "call stack size exceeded".
  28450. var res = '';
  28451. var i = 0;
  28452. while (i < len) {
  28453. res += String.fromCharCode.apply(
  28454. String,
  28455. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  28456. );
  28457. }
  28458. return res
  28459. }
  28460. function asciiSlice (buf, start, end) {
  28461. var ret = '';
  28462. end = Math.min(buf.length, end);
  28463. for (var i = start; i < end; ++i) {
  28464. ret += String.fromCharCode(buf[i] & 0x7F);
  28465. }
  28466. return ret
  28467. }
  28468. function latin1Slice (buf, start, end) {
  28469. var ret = '';
  28470. end = Math.min(buf.length, end);
  28471. for (var i = start; i < end; ++i) {
  28472. ret += String.fromCharCode(buf[i]);
  28473. }
  28474. return ret
  28475. }
  28476. function hexSlice (buf, start, end) {
  28477. var len = buf.length;
  28478. if (!start || start < 0) start = 0;
  28479. if (!end || end < 0 || end > len) end = len;
  28480. var out = '';
  28481. for (var i = start; i < end; ++i) {
  28482. out += toHex(buf[i]);
  28483. }
  28484. return out
  28485. }
  28486. function utf16leSlice (buf, start, end) {
  28487. var bytes = buf.slice(start, end);
  28488. var res = '';
  28489. for (var i = 0; i < bytes.length; i += 2) {
  28490. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  28491. }
  28492. return res
  28493. }
  28494. Buffer$1.prototype.slice = function slice (start, end) {
  28495. var len = this.length;
  28496. start = ~~start;
  28497. end = end === undefined ? len : ~~end;
  28498. if (start < 0) {
  28499. start += len;
  28500. if (start < 0) start = 0;
  28501. } else if (start > len) {
  28502. start = len;
  28503. }
  28504. if (end < 0) {
  28505. end += len;
  28506. if (end < 0) end = 0;
  28507. } else if (end > len) {
  28508. end = len;
  28509. }
  28510. if (end < start) end = start;
  28511. var newBuf;
  28512. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28513. newBuf = this.subarray(start, end);
  28514. newBuf.__proto__ = Buffer$1.prototype;
  28515. } else {
  28516. var sliceLen = end - start;
  28517. newBuf = new Buffer$1(sliceLen, undefined);
  28518. for (var i = 0; i < sliceLen; ++i) {
  28519. newBuf[i] = this[i + start];
  28520. }
  28521. }
  28522. return newBuf
  28523. };
  28524. /*
  28525. * Need to make sure that buffer isn't trying to write out of bounds.
  28526. */
  28527. function checkOffset (offset, ext, length) {
  28528. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  28529. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  28530. }
  28531. Buffer$1.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  28532. offset = offset | 0;
  28533. byteLength = byteLength | 0;
  28534. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28535. var val = this[offset];
  28536. var mul = 1;
  28537. var i = 0;
  28538. while (++i < byteLength && (mul *= 0x100)) {
  28539. val += this[offset + i] * mul;
  28540. }
  28541. return val
  28542. };
  28543. Buffer$1.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  28544. offset = offset | 0;
  28545. byteLength = byteLength | 0;
  28546. if (!noAssert) {
  28547. checkOffset(offset, byteLength, this.length);
  28548. }
  28549. var val = this[offset + --byteLength];
  28550. var mul = 1;
  28551. while (byteLength > 0 && (mul *= 0x100)) {
  28552. val += this[offset + --byteLength] * mul;
  28553. }
  28554. return val
  28555. };
  28556. Buffer$1.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  28557. if (!noAssert) checkOffset(offset, 1, this.length);
  28558. return this[offset]
  28559. };
  28560. Buffer$1.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  28561. if (!noAssert) checkOffset(offset, 2, this.length);
  28562. return this[offset] | (this[offset + 1] << 8)
  28563. };
  28564. Buffer$1.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  28565. if (!noAssert) checkOffset(offset, 2, this.length);
  28566. return (this[offset] << 8) | this[offset + 1]
  28567. };
  28568. Buffer$1.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  28569. if (!noAssert) checkOffset(offset, 4, this.length);
  28570. return ((this[offset]) |
  28571. (this[offset + 1] << 8) |
  28572. (this[offset + 2] << 16)) +
  28573. (this[offset + 3] * 0x1000000)
  28574. };
  28575. Buffer$1.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  28576. if (!noAssert) checkOffset(offset, 4, this.length);
  28577. return (this[offset] * 0x1000000) +
  28578. ((this[offset + 1] << 16) |
  28579. (this[offset + 2] << 8) |
  28580. this[offset + 3])
  28581. };
  28582. Buffer$1.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  28583. offset = offset | 0;
  28584. byteLength = byteLength | 0;
  28585. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28586. var val = this[offset];
  28587. var mul = 1;
  28588. var i = 0;
  28589. while (++i < byteLength && (mul *= 0x100)) {
  28590. val += this[offset + i] * mul;
  28591. }
  28592. mul *= 0x80;
  28593. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28594. return val
  28595. };
  28596. Buffer$1.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  28597. offset = offset | 0;
  28598. byteLength = byteLength | 0;
  28599. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28600. var i = byteLength;
  28601. var mul = 1;
  28602. var val = this[offset + --i];
  28603. while (i > 0 && (mul *= 0x100)) {
  28604. val += this[offset + --i] * mul;
  28605. }
  28606. mul *= 0x80;
  28607. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28608. return val
  28609. };
  28610. Buffer$1.prototype.readInt8 = function readInt8 (offset, noAssert) {
  28611. if (!noAssert) checkOffset(offset, 1, this.length);
  28612. if (!(this[offset] & 0x80)) return (this[offset])
  28613. return ((0xff - this[offset] + 1) * -1)
  28614. };
  28615. Buffer$1.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  28616. if (!noAssert) checkOffset(offset, 2, this.length);
  28617. var val = this[offset] | (this[offset + 1] << 8);
  28618. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28619. };
  28620. Buffer$1.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  28621. if (!noAssert) checkOffset(offset, 2, this.length);
  28622. var val = this[offset + 1] | (this[offset] << 8);
  28623. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28624. };
  28625. Buffer$1.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  28626. if (!noAssert) checkOffset(offset, 4, this.length);
  28627. return (this[offset]) |
  28628. (this[offset + 1] << 8) |
  28629. (this[offset + 2] << 16) |
  28630. (this[offset + 3] << 24)
  28631. };
  28632. Buffer$1.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  28633. if (!noAssert) checkOffset(offset, 4, this.length);
  28634. return (this[offset] << 24) |
  28635. (this[offset + 1] << 16) |
  28636. (this[offset + 2] << 8) |
  28637. (this[offset + 3])
  28638. };
  28639. Buffer$1.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  28640. if (!noAssert) checkOffset(offset, 4, this.length);
  28641. return read(this, offset, true, 23, 4)
  28642. };
  28643. Buffer$1.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  28644. if (!noAssert) checkOffset(offset, 4, this.length);
  28645. return read(this, offset, false, 23, 4)
  28646. };
  28647. Buffer$1.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  28648. if (!noAssert) checkOffset(offset, 8, this.length);
  28649. return read(this, offset, true, 52, 8)
  28650. };
  28651. Buffer$1.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  28652. if (!noAssert) checkOffset(offset, 8, this.length);
  28653. return read(this, offset, false, 52, 8)
  28654. };
  28655. function checkInt (buf, value, offset, ext, max, min) {
  28656. if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  28657. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  28658. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28659. }
  28660. Buffer$1.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  28661. value = +value;
  28662. offset = offset | 0;
  28663. byteLength = byteLength | 0;
  28664. if (!noAssert) {
  28665. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28666. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28667. }
  28668. var mul = 1;
  28669. var i = 0;
  28670. this[offset] = value & 0xFF;
  28671. while (++i < byteLength && (mul *= 0x100)) {
  28672. this[offset + i] = (value / mul) & 0xFF;
  28673. }
  28674. return offset + byteLength
  28675. };
  28676. Buffer$1.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  28677. value = +value;
  28678. offset = offset | 0;
  28679. byteLength = byteLength | 0;
  28680. if (!noAssert) {
  28681. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28682. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28683. }
  28684. var i = byteLength - 1;
  28685. var mul = 1;
  28686. this[offset + i] = value & 0xFF;
  28687. while (--i >= 0 && (mul *= 0x100)) {
  28688. this[offset + i] = (value / mul) & 0xFF;
  28689. }
  28690. return offset + byteLength
  28691. };
  28692. Buffer$1.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  28693. value = +value;
  28694. offset = offset | 0;
  28695. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  28696. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28697. this[offset] = (value & 0xff);
  28698. return offset + 1
  28699. };
  28700. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  28701. if (value < 0) value = 0xffff + value + 1;
  28702. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  28703. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  28704. (littleEndian ? i : 1 - i) * 8;
  28705. }
  28706. }
  28707. Buffer$1.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  28708. value = +value;
  28709. offset = offset | 0;
  28710. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28711. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28712. this[offset] = (value & 0xff);
  28713. this[offset + 1] = (value >>> 8);
  28714. } else {
  28715. objectWriteUInt16(this, value, offset, true);
  28716. }
  28717. return offset + 2
  28718. };
  28719. Buffer$1.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  28720. value = +value;
  28721. offset = offset | 0;
  28722. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28723. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28724. this[offset] = (value >>> 8);
  28725. this[offset + 1] = (value & 0xff);
  28726. } else {
  28727. objectWriteUInt16(this, value, offset, false);
  28728. }
  28729. return offset + 2
  28730. };
  28731. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  28732. if (value < 0) value = 0xffffffff + value + 1;
  28733. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  28734. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
  28735. }
  28736. }
  28737. Buffer$1.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  28738. value = +value;
  28739. offset = offset | 0;
  28740. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28741. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28742. this[offset + 3] = (value >>> 24);
  28743. this[offset + 2] = (value >>> 16);
  28744. this[offset + 1] = (value >>> 8);
  28745. this[offset] = (value & 0xff);
  28746. } else {
  28747. objectWriteUInt32(this, value, offset, true);
  28748. }
  28749. return offset + 4
  28750. };
  28751. Buffer$1.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  28752. value = +value;
  28753. offset = offset | 0;
  28754. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28755. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28756. this[offset] = (value >>> 24);
  28757. this[offset + 1] = (value >>> 16);
  28758. this[offset + 2] = (value >>> 8);
  28759. this[offset + 3] = (value & 0xff);
  28760. } else {
  28761. objectWriteUInt32(this, value, offset, false);
  28762. }
  28763. return offset + 4
  28764. };
  28765. Buffer$1.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  28766. value = +value;
  28767. offset = offset | 0;
  28768. if (!noAssert) {
  28769. var limit = Math.pow(2, 8 * byteLength - 1);
  28770. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28771. }
  28772. var i = 0;
  28773. var mul = 1;
  28774. var sub = 0;
  28775. this[offset] = value & 0xFF;
  28776. while (++i < byteLength && (mul *= 0x100)) {
  28777. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  28778. sub = 1;
  28779. }
  28780. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28781. }
  28782. return offset + byteLength
  28783. };
  28784. Buffer$1.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  28785. value = +value;
  28786. offset = offset | 0;
  28787. if (!noAssert) {
  28788. var limit = Math.pow(2, 8 * byteLength - 1);
  28789. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28790. }
  28791. var i = byteLength - 1;
  28792. var mul = 1;
  28793. var sub = 0;
  28794. this[offset + i] = value & 0xFF;
  28795. while (--i >= 0 && (mul *= 0x100)) {
  28796. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  28797. sub = 1;
  28798. }
  28799. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28800. }
  28801. return offset + byteLength
  28802. };
  28803. Buffer$1.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  28804. value = +value;
  28805. offset = offset | 0;
  28806. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  28807. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28808. if (value < 0) value = 0xff + value + 1;
  28809. this[offset] = (value & 0xff);
  28810. return offset + 1
  28811. };
  28812. Buffer$1.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  28813. value = +value;
  28814. offset = offset | 0;
  28815. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  28816. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28817. this[offset] = (value & 0xff);
  28818. this[offset + 1] = (value >>> 8);
  28819. } else {
  28820. objectWriteUInt16(this, value, offset, true);
  28821. }
  28822. return offset + 2
  28823. };
  28824. Buffer$1.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  28825. value = +value;
  28826. offset = offset | 0;
  28827. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  28828. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28829. this[offset] = (value >>> 8);
  28830. this[offset + 1] = (value & 0xff);
  28831. } else {
  28832. objectWriteUInt16(this, value, offset, false);
  28833. }
  28834. return offset + 2
  28835. };
  28836. Buffer$1.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  28837. value = +value;
  28838. offset = offset | 0;
  28839. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  28840. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28841. this[offset] = (value & 0xff);
  28842. this[offset + 1] = (value >>> 8);
  28843. this[offset + 2] = (value >>> 16);
  28844. this[offset + 3] = (value >>> 24);
  28845. } else {
  28846. objectWriteUInt32(this, value, offset, true);
  28847. }
  28848. return offset + 4
  28849. };
  28850. Buffer$1.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  28851. value = +value;
  28852. offset = offset | 0;
  28853. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  28854. if (value < 0) value = 0xffffffff + value + 1;
  28855. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28856. this[offset] = (value >>> 24);
  28857. this[offset + 1] = (value >>> 16);
  28858. this[offset + 2] = (value >>> 8);
  28859. this[offset + 3] = (value & 0xff);
  28860. } else {
  28861. objectWriteUInt32(this, value, offset, false);
  28862. }
  28863. return offset + 4
  28864. };
  28865. function checkIEEE754 (buf, value, offset, ext, max, min) {
  28866. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28867. if (offset < 0) throw new RangeError('Index out of range')
  28868. }
  28869. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  28870. if (!noAssert) {
  28871. checkIEEE754(buf, value, offset, 4);
  28872. }
  28873. write(buf, value, offset, littleEndian, 23, 4);
  28874. return offset + 4
  28875. }
  28876. Buffer$1.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  28877. return writeFloat(this, value, offset, true, noAssert)
  28878. };
  28879. Buffer$1.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  28880. return writeFloat(this, value, offset, false, noAssert)
  28881. };
  28882. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  28883. if (!noAssert) {
  28884. checkIEEE754(buf, value, offset, 8);
  28885. }
  28886. write(buf, value, offset, littleEndian, 52, 8);
  28887. return offset + 8
  28888. }
  28889. Buffer$1.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  28890. return writeDouble(this, value, offset, true, noAssert)
  28891. };
  28892. Buffer$1.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  28893. return writeDouble(this, value, offset, false, noAssert)
  28894. };
  28895. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  28896. Buffer$1.prototype.copy = function copy (target, targetStart, start, end) {
  28897. if (!start) start = 0;
  28898. if (!end && end !== 0) end = this.length;
  28899. if (targetStart >= target.length) targetStart = target.length;
  28900. if (!targetStart) targetStart = 0;
  28901. if (end > 0 && end < start) end = start;
  28902. // Copy 0 bytes; we're done
  28903. if (end === start) return 0
  28904. if (target.length === 0 || this.length === 0) return 0
  28905. // Fatal error conditions
  28906. if (targetStart < 0) {
  28907. throw new RangeError('targetStart out of bounds')
  28908. }
  28909. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  28910. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  28911. // Are we oob?
  28912. if (end > this.length) end = this.length;
  28913. if (target.length - targetStart < end - start) {
  28914. end = target.length - targetStart + start;
  28915. }
  28916. var len = end - start;
  28917. var i;
  28918. if (this === target && start < targetStart && targetStart < end) {
  28919. // descending copy from end
  28920. for (i = len - 1; i >= 0; --i) {
  28921. target[i + targetStart] = this[i + start];
  28922. }
  28923. } else if (len < 1000 || !Buffer$1.TYPED_ARRAY_SUPPORT) {
  28924. // ascending copy from start
  28925. for (i = 0; i < len; ++i) {
  28926. target[i + targetStart] = this[i + start];
  28927. }
  28928. } else {
  28929. Uint8Array.prototype.set.call(
  28930. target,
  28931. this.subarray(start, start + len),
  28932. targetStart
  28933. );
  28934. }
  28935. return len
  28936. };
  28937. // Usage:
  28938. // buffer.fill(number[, offset[, end]])
  28939. // buffer.fill(buffer[, offset[, end]])
  28940. // buffer.fill(string[, offset[, end]][, encoding])
  28941. Buffer$1.prototype.fill = function fill (val, start, end, encoding) {
  28942. // Handle string cases:
  28943. if (typeof val === 'string') {
  28944. if (typeof start === 'string') {
  28945. encoding = start;
  28946. start = 0;
  28947. end = this.length;
  28948. } else if (typeof end === 'string') {
  28949. encoding = end;
  28950. end = this.length;
  28951. }
  28952. if (val.length === 1) {
  28953. var code = val.charCodeAt(0);
  28954. if (code < 256) {
  28955. val = code;
  28956. }
  28957. }
  28958. if (encoding !== undefined && typeof encoding !== 'string') {
  28959. throw new TypeError('encoding must be a string')
  28960. }
  28961. if (typeof encoding === 'string' && !Buffer$1.isEncoding(encoding)) {
  28962. throw new TypeError('Unknown encoding: ' + encoding)
  28963. }
  28964. } else if (typeof val === 'number') {
  28965. val = val & 255;
  28966. }
  28967. // Invalid ranges are not set to a default, so can range check early.
  28968. if (start < 0 || this.length < start || this.length < end) {
  28969. throw new RangeError('Out of range index')
  28970. }
  28971. if (end <= start) {
  28972. return this
  28973. }
  28974. start = start >>> 0;
  28975. end = end === undefined ? this.length : end >>> 0;
  28976. if (!val) val = 0;
  28977. var i;
  28978. if (typeof val === 'number') {
  28979. for (i = start; i < end; ++i) {
  28980. this[i] = val;
  28981. }
  28982. } else {
  28983. var bytes = internalIsBuffer(val)
  28984. ? val
  28985. : utf8ToBytes(new Buffer$1(val, encoding).toString());
  28986. var len = bytes.length;
  28987. for (i = 0; i < end - start; ++i) {
  28988. this[i + start] = bytes[i % len];
  28989. }
  28990. }
  28991. return this
  28992. };
  28993. // HELPER FUNCTIONS
  28994. // ================
  28995. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  28996. function base64clean (str) {
  28997. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  28998. str = stringtrim(str).replace(INVALID_BASE64_RE, '');
  28999. // Node converts strings with length < 2 to ''
  29000. if (str.length < 2) return ''
  29001. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  29002. while (str.length % 4 !== 0) {
  29003. str = str + '=';
  29004. }
  29005. return str
  29006. }
  29007. function stringtrim (str) {
  29008. if (str.trim) return str.trim()
  29009. return str.replace(/^\s+|\s+$/g, '')
  29010. }
  29011. function toHex (n) {
  29012. if (n < 16) return '0' + n.toString(16)
  29013. return n.toString(16)
  29014. }
  29015. function utf8ToBytes (string, units) {
  29016. units = units || Infinity;
  29017. var codePoint;
  29018. var length = string.length;
  29019. var leadSurrogate = null;
  29020. var bytes = [];
  29021. for (var i = 0; i < length; ++i) {
  29022. codePoint = string.charCodeAt(i);
  29023. // is surrogate component
  29024. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  29025. // last char was a lead
  29026. if (!leadSurrogate) {
  29027. // no lead yet
  29028. if (codePoint > 0xDBFF) {
  29029. // unexpected trail
  29030. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  29031. continue
  29032. } else if (i + 1 === length) {
  29033. // unpaired lead
  29034. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  29035. continue
  29036. }
  29037. // valid lead
  29038. leadSurrogate = codePoint;
  29039. continue
  29040. }
  29041. // 2 leads in a row
  29042. if (codePoint < 0xDC00) {
  29043. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  29044. leadSurrogate = codePoint;
  29045. continue
  29046. }
  29047. // valid surrogate pair
  29048. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  29049. } else if (leadSurrogate) {
  29050. // valid bmp char, but last char was a lead
  29051. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  29052. }
  29053. leadSurrogate = null;
  29054. // encode utf8
  29055. if (codePoint < 0x80) {
  29056. if ((units -= 1) < 0) break
  29057. bytes.push(codePoint);
  29058. } else if (codePoint < 0x800) {
  29059. if ((units -= 2) < 0) break
  29060. bytes.push(
  29061. codePoint >> 0x6 | 0xC0,
  29062. codePoint & 0x3F | 0x80
  29063. );
  29064. } else if (codePoint < 0x10000) {
  29065. if ((units -= 3) < 0) break
  29066. bytes.push(
  29067. codePoint >> 0xC | 0xE0,
  29068. codePoint >> 0x6 & 0x3F | 0x80,
  29069. codePoint & 0x3F | 0x80
  29070. );
  29071. } else if (codePoint < 0x110000) {
  29072. if ((units -= 4) < 0) break
  29073. bytes.push(
  29074. codePoint >> 0x12 | 0xF0,
  29075. codePoint >> 0xC & 0x3F | 0x80,
  29076. codePoint >> 0x6 & 0x3F | 0x80,
  29077. codePoint & 0x3F | 0x80
  29078. );
  29079. } else {
  29080. throw new Error('Invalid code point')
  29081. }
  29082. }
  29083. return bytes
  29084. }
  29085. function asciiToBytes (str) {
  29086. var byteArray = [];
  29087. for (var i = 0; i < str.length; ++i) {
  29088. // Node's code seems to be doing this and not & 0x7F..
  29089. byteArray.push(str.charCodeAt(i) & 0xFF);
  29090. }
  29091. return byteArray
  29092. }
  29093. function utf16leToBytes (str, units) {
  29094. var c, hi, lo;
  29095. var byteArray = [];
  29096. for (var i = 0; i < str.length; ++i) {
  29097. if ((units -= 2) < 0) break
  29098. c = str.charCodeAt(i);
  29099. hi = c >> 8;
  29100. lo = c % 256;
  29101. byteArray.push(lo);
  29102. byteArray.push(hi);
  29103. }
  29104. return byteArray
  29105. }
  29106. function base64ToBytes (str) {
  29107. return toByteArray(base64clean(str))
  29108. }
  29109. function blitBuffer (src, dst, offset, length) {
  29110. for (var i = 0; i < length; ++i) {
  29111. if ((i + offset >= dst.length) || (i >= src.length)) break
  29112. dst[i + offset] = src[i];
  29113. }
  29114. return i
  29115. }
  29116. function isnan (val) {
  29117. return val !== val // eslint-disable-line no-self-compare
  29118. }
  29119. // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
  29120. // The _isBuffer check is for Safari 5-7 support, because it's missing
  29121. // Object.prototype.constructor. Remove this eventually
  29122. function isBuffer$1(obj) {
  29123. return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
  29124. }
  29125. function isFastBuffer (obj) {
  29126. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  29127. }
  29128. // For Node v0.10 support. Remove this eventually.
  29129. function isSlowBuffer (obj) {
  29130. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
  29131. }
  29132. var inherits;
  29133. if (typeof Object.create === 'function'){
  29134. inherits = function inherits(ctor, superCtor) {
  29135. // implementation from standard node.js 'util' module
  29136. ctor.super_ = superCtor;
  29137. ctor.prototype = Object.create(superCtor.prototype, {
  29138. constructor: {
  29139. value: ctor,
  29140. enumerable: false,
  29141. writable: true,
  29142. configurable: true
  29143. }
  29144. });
  29145. };
  29146. } else {
  29147. inherits = function inherits(ctor, superCtor) {
  29148. ctor.super_ = superCtor;
  29149. var TempCtor = function () {};
  29150. TempCtor.prototype = superCtor.prototype;
  29151. ctor.prototype = new TempCtor();
  29152. ctor.prototype.constructor = ctor;
  29153. };
  29154. }
  29155. var inherits$1 = inherits;
  29156. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  29157. function getOwnPropertyDescriptors(obj) {
  29158. var keys = Object.keys(obj);
  29159. var descriptors = {};
  29160. for (var i = 0; i < keys.length; i++) {
  29161. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  29162. }
  29163. return descriptors;
  29164. };
  29165. var formatRegExp = /%[sdj%]/g;
  29166. function format$1(f) {
  29167. if (!isString$1(f)) {
  29168. var objects = [];
  29169. for (var i = 0; i < arguments.length; i++) {
  29170. objects.push(inspect(arguments[i]));
  29171. }
  29172. return objects.join(' ');
  29173. }
  29174. var i = 1;
  29175. var args = arguments;
  29176. var len = args.length;
  29177. var str = String(f).replace(formatRegExp, function(x) {
  29178. if (x === '%%') return '%';
  29179. if (i >= len) return x;
  29180. switch (x) {
  29181. case '%s': return String(args[i++]);
  29182. case '%d': return Number(args[i++]);
  29183. case '%j':
  29184. try {
  29185. return JSON.stringify(args[i++]);
  29186. } catch (_) {
  29187. return '[Circular]';
  29188. }
  29189. default:
  29190. return x;
  29191. }
  29192. });
  29193. for (var x = args[i]; i < len; x = args[++i]) {
  29194. if (isNull(x) || !isObject$1(x)) {
  29195. str += ' ' + x;
  29196. } else {
  29197. str += ' ' + inspect(x);
  29198. }
  29199. }
  29200. return str;
  29201. }
  29202. // Mark that a method should not be used.
  29203. // Returns a modified function which warns once by default.
  29204. // If --no-deprecation is set, then it is a no-op.
  29205. function deprecate(fn, msg) {
  29206. // Allow for deprecating things in the process of starting up.
  29207. if (isUndefined(global$1.process)) {
  29208. return function() {
  29209. return deprecate(fn, msg).apply(this, arguments);
  29210. };
  29211. }
  29212. if (browser$1.noDeprecation === true) {
  29213. return fn;
  29214. }
  29215. var warned = false;
  29216. function deprecated() {
  29217. if (!warned) {
  29218. if (browser$1.throwDeprecation) {
  29219. throw new Error(msg);
  29220. } else if (browser$1.traceDeprecation) {
  29221. console.trace(msg);
  29222. } else {
  29223. console.error(msg);
  29224. }
  29225. warned = true;
  29226. }
  29227. return fn.apply(this, arguments);
  29228. }
  29229. return deprecated;
  29230. }
  29231. var debugs = {};
  29232. var debugEnviron;
  29233. function debuglog(set) {
  29234. if (isUndefined(debugEnviron))
  29235. debugEnviron = browser$1.env.NODE_DEBUG || '';
  29236. set = set.toUpperCase();
  29237. if (!debugs[set]) {
  29238. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  29239. var pid = 0;
  29240. debugs[set] = function() {
  29241. var msg = format$1.apply(null, arguments);
  29242. console.error('%s %d: %s', set, pid, msg);
  29243. };
  29244. } else {
  29245. debugs[set] = function() {};
  29246. }
  29247. }
  29248. return debugs[set];
  29249. }
  29250. /**
  29251. * Echos the value of a value. Trys to print the value out
  29252. * in the best way possible given the different types.
  29253. *
  29254. * @param {Object} obj The object to print out.
  29255. * @param {Object} opts Optional options object that alters the output.
  29256. */
  29257. /* legacy: obj, showHidden, depth, colors*/
  29258. function inspect(obj, opts) {
  29259. // default options
  29260. var ctx = {
  29261. seen: [],
  29262. stylize: stylizeNoColor
  29263. };
  29264. // legacy...
  29265. if (arguments.length >= 3) ctx.depth = arguments[2];
  29266. if (arguments.length >= 4) ctx.colors = arguments[3];
  29267. if (isBoolean(opts)) {
  29268. // legacy...
  29269. ctx.showHidden = opts;
  29270. } else if (opts) {
  29271. // got an "options" object
  29272. _extend(ctx, opts);
  29273. }
  29274. // set default options
  29275. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  29276. if (isUndefined(ctx.depth)) ctx.depth = 2;
  29277. if (isUndefined(ctx.colors)) ctx.colors = false;
  29278. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  29279. if (ctx.colors) ctx.stylize = stylizeWithColor;
  29280. return formatValue(ctx, obj, ctx.depth);
  29281. }
  29282. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  29283. inspect.colors = {
  29284. 'bold' : [1, 22],
  29285. 'italic' : [3, 23],
  29286. 'underline' : [4, 24],
  29287. 'inverse' : [7, 27],
  29288. 'white' : [37, 39],
  29289. 'grey' : [90, 39],
  29290. 'black' : [30, 39],
  29291. 'blue' : [34, 39],
  29292. 'cyan' : [36, 39],
  29293. 'green' : [32, 39],
  29294. 'magenta' : [35, 39],
  29295. 'red' : [31, 39],
  29296. 'yellow' : [33, 39]
  29297. };
  29298. // Don't use 'blue' not visible on cmd.exe
  29299. inspect.styles = {
  29300. 'special': 'cyan',
  29301. 'number': 'yellow',
  29302. 'boolean': 'yellow',
  29303. 'undefined': 'grey',
  29304. 'null': 'bold',
  29305. 'string': 'green',
  29306. 'date': 'magenta',
  29307. // "name": intentionally not styling
  29308. 'regexp': 'red'
  29309. };
  29310. function stylizeWithColor(str, styleType) {
  29311. var style = inspect.styles[styleType];
  29312. if (style) {
  29313. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  29314. '\u001b[' + inspect.colors[style][1] + 'm';
  29315. } else {
  29316. return str;
  29317. }
  29318. }
  29319. function stylizeNoColor(str, styleType) {
  29320. return str;
  29321. }
  29322. function arrayToHash(array) {
  29323. var hash = {};
  29324. array.forEach(function(val, idx) {
  29325. hash[val] = true;
  29326. });
  29327. return hash;
  29328. }
  29329. function formatValue(ctx, value, recurseTimes) {
  29330. // Provide a hook for user-specified inspect functions.
  29331. // Check that value is an object with an inspect function on it
  29332. if (ctx.customInspect &&
  29333. value &&
  29334. isFunction(value.inspect) &&
  29335. // Filter out the util module, it's inspect function is special
  29336. value.inspect !== inspect &&
  29337. // Also filter out any prototype objects using the circular check.
  29338. !(value.constructor && value.constructor.prototype === value)) {
  29339. var ret = value.inspect(recurseTimes, ctx);
  29340. if (!isString$1(ret)) {
  29341. ret = formatValue(ctx, ret, recurseTimes);
  29342. }
  29343. return ret;
  29344. }
  29345. // Primitive types cannot have properties
  29346. var primitive = formatPrimitive(ctx, value);
  29347. if (primitive) {
  29348. return primitive;
  29349. }
  29350. // Look up the keys of the object.
  29351. var keys = Object.keys(value);
  29352. var visibleKeys = arrayToHash(keys);
  29353. if (ctx.showHidden) {
  29354. keys = Object.getOwnPropertyNames(value);
  29355. }
  29356. // IE doesn't make error fields non-enumerable
  29357. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  29358. if (isError(value)
  29359. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  29360. return formatError(value);
  29361. }
  29362. // Some type of object without properties can be shortcutted.
  29363. if (keys.length === 0) {
  29364. if (isFunction(value)) {
  29365. var name = value.name ? ': ' + value.name : '';
  29366. return ctx.stylize('[Function' + name + ']', 'special');
  29367. }
  29368. if (isRegExp(value)) {
  29369. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29370. }
  29371. if (isDate(value)) {
  29372. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  29373. }
  29374. if (isError(value)) {
  29375. return formatError(value);
  29376. }
  29377. }
  29378. var base = '', array = false, braces = ['{', '}'];
  29379. // Make Array say that they are Array
  29380. if (isArray$1(value)) {
  29381. array = true;
  29382. braces = ['[', ']'];
  29383. }
  29384. // Make functions say that they are functions
  29385. if (isFunction(value)) {
  29386. var n = value.name ? ': ' + value.name : '';
  29387. base = ' [Function' + n + ']';
  29388. }
  29389. // Make RegExps say that they are RegExps
  29390. if (isRegExp(value)) {
  29391. base = ' ' + RegExp.prototype.toString.call(value);
  29392. }
  29393. // Make dates with properties first say the date
  29394. if (isDate(value)) {
  29395. base = ' ' + Date.prototype.toUTCString.call(value);
  29396. }
  29397. // Make error with message first say the error
  29398. if (isError(value)) {
  29399. base = ' ' + formatError(value);
  29400. }
  29401. if (keys.length === 0 && (!array || value.length == 0)) {
  29402. return braces[0] + base + braces[1];
  29403. }
  29404. if (recurseTimes < 0) {
  29405. if (isRegExp(value)) {
  29406. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29407. } else {
  29408. return ctx.stylize('[Object]', 'special');
  29409. }
  29410. }
  29411. ctx.seen.push(value);
  29412. var output;
  29413. if (array) {
  29414. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  29415. } else {
  29416. output = keys.map(function(key) {
  29417. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  29418. });
  29419. }
  29420. ctx.seen.pop();
  29421. return reduceToSingleString(output, base, braces);
  29422. }
  29423. function formatPrimitive(ctx, value) {
  29424. if (isUndefined(value))
  29425. return ctx.stylize('undefined', 'undefined');
  29426. if (isString$1(value)) {
  29427. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  29428. .replace(/'/g, "\\'")
  29429. .replace(/\\"/g, '"') + '\'';
  29430. return ctx.stylize(simple, 'string');
  29431. }
  29432. if (isNumber(value))
  29433. return ctx.stylize('' + value, 'number');
  29434. if (isBoolean(value))
  29435. return ctx.stylize('' + value, 'boolean');
  29436. // For some reason typeof null is "object", so special case here.
  29437. if (isNull(value))
  29438. return ctx.stylize('null', 'null');
  29439. }
  29440. function formatError(value) {
  29441. return '[' + Error.prototype.toString.call(value) + ']';
  29442. }
  29443. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  29444. var output = [];
  29445. for (var i = 0, l = value.length; i < l; ++i) {
  29446. if (hasOwnProperty$2(value, String(i))) {
  29447. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29448. String(i), true));
  29449. } else {
  29450. output.push('');
  29451. }
  29452. }
  29453. keys.forEach(function(key) {
  29454. if (!key.match(/^\d+$/)) {
  29455. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29456. key, true));
  29457. }
  29458. });
  29459. return output;
  29460. }
  29461. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  29462. var name, str, desc;
  29463. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  29464. if (desc.get) {
  29465. if (desc.set) {
  29466. str = ctx.stylize('[Getter/Setter]', 'special');
  29467. } else {
  29468. str = ctx.stylize('[Getter]', 'special');
  29469. }
  29470. } else {
  29471. if (desc.set) {
  29472. str = ctx.stylize('[Setter]', 'special');
  29473. }
  29474. }
  29475. if (!hasOwnProperty$2(visibleKeys, key)) {
  29476. name = '[' + key + ']';
  29477. }
  29478. if (!str) {
  29479. if (ctx.seen.indexOf(desc.value) < 0) {
  29480. if (isNull(recurseTimes)) {
  29481. str = formatValue(ctx, desc.value, null);
  29482. } else {
  29483. str = formatValue(ctx, desc.value, recurseTimes - 1);
  29484. }
  29485. if (str.indexOf('\n') > -1) {
  29486. if (array) {
  29487. str = str.split('\n').map(function(line) {
  29488. return ' ' + line;
  29489. }).join('\n').substr(2);
  29490. } else {
  29491. str = '\n' + str.split('\n').map(function(line) {
  29492. return ' ' + line;
  29493. }).join('\n');
  29494. }
  29495. }
  29496. } else {
  29497. str = ctx.stylize('[Circular]', 'special');
  29498. }
  29499. }
  29500. if (isUndefined(name)) {
  29501. if (array && key.match(/^\d+$/)) {
  29502. return str;
  29503. }
  29504. name = JSON.stringify('' + key);
  29505. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  29506. name = name.substr(1, name.length - 2);
  29507. name = ctx.stylize(name, 'name');
  29508. } else {
  29509. name = name.replace(/'/g, "\\'")
  29510. .replace(/\\"/g, '"')
  29511. .replace(/(^"|"$)/g, "'");
  29512. name = ctx.stylize(name, 'string');
  29513. }
  29514. }
  29515. return name + ': ' + str;
  29516. }
  29517. function reduceToSingleString(output, base, braces) {
  29518. var length = output.reduce(function(prev, cur) {
  29519. if (cur.indexOf('\n') >= 0) ;
  29520. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  29521. }, 0);
  29522. if (length > 60) {
  29523. return braces[0] +
  29524. (base === '' ? '' : base + '\n ') +
  29525. ' ' +
  29526. output.join(',\n ') +
  29527. ' ' +
  29528. braces[1];
  29529. }
  29530. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  29531. }
  29532. // NOTE: These type checking functions intentionally don't use `instanceof`
  29533. // because it is fragile and can be easily faked with `Object.create()`.
  29534. function isArray$1(ar) {
  29535. return Array.isArray(ar);
  29536. }
  29537. function isBoolean(arg) {
  29538. return typeof arg === 'boolean';
  29539. }
  29540. function isNull(arg) {
  29541. return arg === null;
  29542. }
  29543. function isNullOrUndefined(arg) {
  29544. return arg == null;
  29545. }
  29546. function isNumber(arg) {
  29547. return typeof arg === 'number';
  29548. }
  29549. function isString$1(arg) {
  29550. return typeof arg === 'string';
  29551. }
  29552. function isSymbol(arg) {
  29553. return typeof arg === 'symbol';
  29554. }
  29555. function isUndefined(arg) {
  29556. return arg === void 0;
  29557. }
  29558. function isRegExp(re) {
  29559. return isObject$1(re) && objectToString(re) === '[object RegExp]';
  29560. }
  29561. function isObject$1(arg) {
  29562. return typeof arg === 'object' && arg !== null;
  29563. }
  29564. function isDate(d) {
  29565. return isObject$1(d) && objectToString(d) === '[object Date]';
  29566. }
  29567. function isError(e) {
  29568. return isObject$1(e) &&
  29569. (objectToString(e) === '[object Error]' || e instanceof Error);
  29570. }
  29571. function isFunction(arg) {
  29572. return typeof arg === 'function';
  29573. }
  29574. function isPrimitive(arg) {
  29575. return arg === null ||
  29576. typeof arg === 'boolean' ||
  29577. typeof arg === 'number' ||
  29578. typeof arg === 'string' ||
  29579. typeof arg === 'symbol' || // ES6 symbol
  29580. typeof arg === 'undefined';
  29581. }
  29582. function isBuffer(maybeBuf) {
  29583. return Buffer$1.isBuffer(maybeBuf);
  29584. }
  29585. function objectToString(o) {
  29586. return Object.prototype.toString.call(o);
  29587. }
  29588. function pad(n) {
  29589. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  29590. }
  29591. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  29592. 'Oct', 'Nov', 'Dec'];
  29593. // 26 Feb 16:19:34
  29594. function timestamp() {
  29595. var d = new Date();
  29596. var time = [pad(d.getHours()),
  29597. pad(d.getMinutes()),
  29598. pad(d.getSeconds())].join(':');
  29599. return [d.getDate(), months[d.getMonth()], time].join(' ');
  29600. }
  29601. // log is just a thin wrapper to console.log that prepends a timestamp
  29602. function log() {
  29603. console.log('%s - %s', timestamp(), format$1.apply(null, arguments));
  29604. }
  29605. function _extend(origin, add) {
  29606. // Don't do anything if add isn't an object
  29607. if (!add || !isObject$1(add)) return origin;
  29608. var keys = Object.keys(add);
  29609. var i = keys.length;
  29610. while (i--) {
  29611. origin[keys[i]] = add[keys[i]];
  29612. }
  29613. return origin;
  29614. }
  29615. function hasOwnProperty$2(obj, prop) {
  29616. return Object.prototype.hasOwnProperty.call(obj, prop);
  29617. }
  29618. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  29619. function promisify(original) {
  29620. if (typeof original !== 'function')
  29621. throw new TypeError('The "original" argument must be of type Function');
  29622. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  29623. var fn = original[kCustomPromisifiedSymbol];
  29624. if (typeof fn !== 'function') {
  29625. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  29626. }
  29627. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29628. value: fn, enumerable: false, writable: false, configurable: true
  29629. });
  29630. return fn;
  29631. }
  29632. function fn() {
  29633. var promiseResolve, promiseReject;
  29634. var promise = new Promise(function (resolve, reject) {
  29635. promiseResolve = resolve;
  29636. promiseReject = reject;
  29637. });
  29638. var args = [];
  29639. for (var i = 0; i < arguments.length; i++) {
  29640. args.push(arguments[i]);
  29641. }
  29642. args.push(function (err, value) {
  29643. if (err) {
  29644. promiseReject(err);
  29645. } else {
  29646. promiseResolve(value);
  29647. }
  29648. });
  29649. try {
  29650. original.apply(this, args);
  29651. } catch (err) {
  29652. promiseReject(err);
  29653. }
  29654. return promise;
  29655. }
  29656. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  29657. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29658. value: fn, enumerable: false, writable: false, configurable: true
  29659. });
  29660. return Object.defineProperties(
  29661. fn,
  29662. getOwnPropertyDescriptors(original)
  29663. );
  29664. }
  29665. promisify.custom = kCustomPromisifiedSymbol;
  29666. function callbackifyOnRejected(reason, cb) {
  29667. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  29668. // Because `null` is a special error value in callbacks which means "no error
  29669. // occurred", we error-wrap so the callback consumer can distinguish between
  29670. // "the promise rejected with null" or "the promise fulfilled with undefined".
  29671. if (!reason) {
  29672. var newReason = new Error('Promise was rejected with a falsy value');
  29673. newReason.reason = reason;
  29674. reason = newReason;
  29675. }
  29676. return cb(reason);
  29677. }
  29678. function callbackify(original) {
  29679. if (typeof original !== 'function') {
  29680. throw new TypeError('The "original" argument must be of type Function');
  29681. }
  29682. // We DO NOT return the promise as it gives the user a false sense that
  29683. // the promise is actually somehow related to the callback's execution
  29684. // and that the callback throwing will reject the promise.
  29685. function callbackified() {
  29686. var args = [];
  29687. for (var i = 0; i < arguments.length; i++) {
  29688. args.push(arguments[i]);
  29689. }
  29690. var maybeCb = args.pop();
  29691. if (typeof maybeCb !== 'function') {
  29692. throw new TypeError('The last argument must be of type Function');
  29693. }
  29694. var self = this;
  29695. var cb = function() {
  29696. return maybeCb.apply(self, arguments);
  29697. };
  29698. // In true node style we process the callback on `nextTick` with all the
  29699. // implications (stack, `uncaughtException`, `async_hooks`)
  29700. original.apply(this, args)
  29701. .then(function(ret) { browser$1.nextTick(cb.bind(null, null, ret)); },
  29702. function(rej) { browser$1.nextTick(callbackifyOnRejected.bind(null, rej, cb)); });
  29703. }
  29704. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  29705. Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
  29706. return callbackified;
  29707. }
  29708. var _polyfillNode_util = {
  29709. inherits: inherits$1,
  29710. _extend: _extend,
  29711. log: log,
  29712. isBuffer: isBuffer,
  29713. isPrimitive: isPrimitive,
  29714. isFunction: isFunction,
  29715. isError: isError,
  29716. isDate: isDate,
  29717. isObject: isObject$1,
  29718. isRegExp: isRegExp,
  29719. isUndefined: isUndefined,
  29720. isSymbol: isSymbol,
  29721. isString: isString$1,
  29722. isNumber: isNumber,
  29723. isNullOrUndefined: isNullOrUndefined,
  29724. isNull: isNull,
  29725. isBoolean: isBoolean,
  29726. isArray: isArray$1,
  29727. inspect: inspect,
  29728. deprecate: deprecate,
  29729. format: format$1,
  29730. debuglog: debuglog,
  29731. promisify: promisify,
  29732. callbackify: callbackify,
  29733. };
  29734. var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
  29735. __proto__: null,
  29736. _extend: _extend,
  29737. callbackify: callbackify,
  29738. debuglog: debuglog,
  29739. default: _polyfillNode_util,
  29740. deprecate: deprecate,
  29741. format: format$1,
  29742. inherits: inherits$1,
  29743. inspect: inspect,
  29744. isArray: isArray$1,
  29745. isBoolean: isBoolean,
  29746. isBuffer: isBuffer,
  29747. isDate: isDate,
  29748. isError: isError,
  29749. isFunction: isFunction,
  29750. isNull: isNull,
  29751. isNullOrUndefined: isNullOrUndefined,
  29752. isNumber: isNumber,
  29753. isObject: isObject$1,
  29754. isPrimitive: isPrimitive,
  29755. isRegExp: isRegExp,
  29756. isString: isString$1,
  29757. isSymbol: isSymbol,
  29758. isUndefined: isUndefined,
  29759. log: log,
  29760. promisify: promisify
  29761. });
  29762. // Copyright Joyent, Inc. and other Node contributors.
  29763. //
  29764. // Permission is hereby granted, free of charge, to any person obtaining a
  29765. // copy of this software and associated documentation files (the
  29766. // "Software"), to deal in the Software without restriction, including
  29767. // without limitation the rights to use, copy, modify, merge, publish,
  29768. // distribute, sublicense, and/or sell copies of the Software, and to permit
  29769. // persons to whom the Software is furnished to do so, subject to the
  29770. // following conditions:
  29771. //
  29772. // The above copyright notice and this permission notice shall be included
  29773. // in all copies or substantial portions of the Software.
  29774. //
  29775. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  29776. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29777. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  29778. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  29779. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  29780. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  29781. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  29782. // If obj.hasOwnProperty has been overridden, then calling
  29783. // obj.hasOwnProperty(prop) will break.
  29784. // See: https://github.com/joyent/node/issues/1707
  29785. function hasOwnProperty$1(obj, prop) {
  29786. return Object.prototype.hasOwnProperty.call(obj, prop);
  29787. }
  29788. var isArray = Array.isArray || function (xs) {
  29789. return Object.prototype.toString.call(xs) === '[object Array]';
  29790. };
  29791. function stringifyPrimitive(v) {
  29792. switch (typeof v) {
  29793. case 'string':
  29794. return v;
  29795. case 'boolean':
  29796. return v ? 'true' : 'false';
  29797. case 'number':
  29798. return isFinite(v) ? v : '';
  29799. default:
  29800. return '';
  29801. }
  29802. }
  29803. function stringify$5 (obj, sep, eq, name) {
  29804. sep = sep || '&';
  29805. eq = eq || '=';
  29806. if (obj === null) {
  29807. obj = undefined;
  29808. }
  29809. if (typeof obj === 'object') {
  29810. return map(objectKeys(obj), function(k) {
  29811. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  29812. if (isArray(obj[k])) {
  29813. return map(obj[k], function(v) {
  29814. return ks + encodeURIComponent(stringifyPrimitive(v));
  29815. }).join(sep);
  29816. } else {
  29817. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  29818. }
  29819. }).join(sep);
  29820. }
  29821. if (!name) return '';
  29822. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  29823. encodeURIComponent(stringifyPrimitive(obj));
  29824. }
  29825. function map (xs, f) {
  29826. if (xs.map) return xs.map(f);
  29827. var res = [];
  29828. for (var i = 0; i < xs.length; i++) {
  29829. res.push(f(xs[i], i));
  29830. }
  29831. return res;
  29832. }
  29833. var objectKeys = Object.keys || function (obj) {
  29834. var res = [];
  29835. for (var key in obj) {
  29836. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  29837. }
  29838. return res;
  29839. };
  29840. function parse$6(qs, sep, eq, options) {
  29841. sep = sep || '&';
  29842. eq = eq || '=';
  29843. var obj = {};
  29844. if (typeof qs !== 'string' || qs.length === 0) {
  29845. return obj;
  29846. }
  29847. var regexp = /\+/g;
  29848. qs = qs.split(sep);
  29849. var maxKeys = 1000;
  29850. if (options && typeof options.maxKeys === 'number') {
  29851. maxKeys = options.maxKeys;
  29852. }
  29853. var len = qs.length;
  29854. // maxKeys <= 0 means that we should not limit keys count
  29855. if (maxKeys > 0 && len > maxKeys) {
  29856. len = maxKeys;
  29857. }
  29858. for (var i = 0; i < len; ++i) {
  29859. var x = qs[i].replace(regexp, '%20'),
  29860. idx = x.indexOf(eq),
  29861. kstr, vstr, k, v;
  29862. if (idx >= 0) {
  29863. kstr = x.substr(0, idx);
  29864. vstr = x.substr(idx + 1);
  29865. } else {
  29866. kstr = x;
  29867. vstr = '';
  29868. }
  29869. k = decodeURIComponent(kstr);
  29870. v = decodeURIComponent(vstr);
  29871. if (!hasOwnProperty$1(obj, k)) {
  29872. obj[k] = v;
  29873. } else if (isArray(obj[k])) {
  29874. obj[k].push(v);
  29875. } else {
  29876. obj[k] = [obj[k], v];
  29877. }
  29878. }
  29879. return obj;
  29880. }
  29881. // WHATWG API
  29882. const URL$1 = global$1.URL;
  29883. const URLSearchParams = global$1.URLSearchParams;
  29884. var _polyfillNode_url = {
  29885. parse: urlParse,
  29886. resolve: urlResolve,
  29887. resolveObject: urlResolveObject,
  29888. fileURLToPath: urlFileURLToPath,
  29889. format: urlFormat,
  29890. Url: Url,
  29891. // WHATWG API
  29892. URL: URL$1,
  29893. URLSearchParams,
  29894. };
  29895. function Url() {
  29896. this.protocol = null;
  29897. this.slashes = null;
  29898. this.auth = null;
  29899. this.host = null;
  29900. this.port = null;
  29901. this.hostname = null;
  29902. this.hash = null;
  29903. this.search = null;
  29904. this.query = null;
  29905. this.pathname = null;
  29906. this.path = null;
  29907. this.href = null;
  29908. }
  29909. // Reference: RFC 3986, RFC 1808, RFC 2396
  29910. // define these here so at least they only have to be
  29911. // compiled once on the first module load.
  29912. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  29913. portPattern = /:[0-9]*$/,
  29914. // Special case for a simple path URL
  29915. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  29916. // RFC 2396: characters reserved for delimiting URLs.
  29917. // We actually just auto-escape these.
  29918. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  29919. // RFC 2396: characters not allowed for various reasons.
  29920. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  29921. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  29922. autoEscape = ['\''].concat(unwise),
  29923. // Characters that are never ever allowed in a hostname.
  29924. // Note that any invalid chars are also handled, but these
  29925. // are the ones that are *expected* to be seen, so we fast-path
  29926. // them.
  29927. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  29928. hostEndingChars = ['/', '?', '#'],
  29929. hostnameMaxLen = 255,
  29930. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  29931. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  29932. // protocols that can allow "unsafe" and "unwise" chars.
  29933. unsafeProtocol = {
  29934. 'javascript': true,
  29935. 'javascript:': true
  29936. },
  29937. // protocols that never have a hostname.
  29938. hostlessProtocol = {
  29939. 'javascript': true,
  29940. 'javascript:': true
  29941. },
  29942. // protocols that always contain a // bit.
  29943. slashedProtocol = {
  29944. 'http': true,
  29945. 'https': true,
  29946. 'ftp': true,
  29947. 'gopher': true,
  29948. 'file': true,
  29949. 'http:': true,
  29950. 'https:': true,
  29951. 'ftp:': true,
  29952. 'gopher:': true,
  29953. 'file:': true
  29954. };
  29955. function urlParse(url, parseQueryString, slashesDenoteHost) {
  29956. if (url && isObject$1(url) && url instanceof Url) return url;
  29957. var u = new Url;
  29958. u.parse(url, parseQueryString, slashesDenoteHost);
  29959. return u;
  29960. }
  29961. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  29962. return parse$5(this, url, parseQueryString, slashesDenoteHost);
  29963. };
  29964. function parse$5(self, url, parseQueryString, slashesDenoteHost) {
  29965. if (!isString$1(url)) {
  29966. throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
  29967. }
  29968. // Copy chrome, IE, opera backslash-handling behavior.
  29969. // Back slashes before the query string get converted to forward slashes
  29970. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  29971. var queryIndex = url.indexOf('?'),
  29972. splitter =
  29973. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  29974. uSplit = url.split(splitter),
  29975. slashRegex = /\\/g;
  29976. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  29977. url = uSplit.join(splitter);
  29978. var rest = url;
  29979. // trim before proceeding.
  29980. // This is to support parse stuff like " http://foo.com \n"
  29981. rest = rest.trim();
  29982. if (!slashesDenoteHost && url.split('#').length === 1) {
  29983. // Try fast path regexp
  29984. var simplePath = simplePathPattern.exec(rest);
  29985. if (simplePath) {
  29986. self.path = rest;
  29987. self.href = rest;
  29988. self.pathname = simplePath[1];
  29989. if (simplePath[2]) {
  29990. self.search = simplePath[2];
  29991. if (parseQueryString) {
  29992. self.query = parse$6(self.search.substr(1));
  29993. } else {
  29994. self.query = self.search.substr(1);
  29995. }
  29996. } else if (parseQueryString) {
  29997. self.search = '';
  29998. self.query = {};
  29999. }
  30000. return self;
  30001. }
  30002. }
  30003. var proto = protocolPattern.exec(rest);
  30004. if (proto) {
  30005. proto = proto[0];
  30006. var lowerProto = proto.toLowerCase();
  30007. self.protocol = lowerProto;
  30008. rest = rest.substr(proto.length);
  30009. }
  30010. // figure out if it's got a host
  30011. // user@server is *always* interpreted as a hostname, and url
  30012. // resolution will treat //foo/bar as host=foo,path=bar because that's
  30013. // how the browser resolves relative URLs.
  30014. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  30015. var slashes = rest.substr(0, 2) === '//';
  30016. if (slashes && !(proto && hostlessProtocol[proto])) {
  30017. rest = rest.substr(2);
  30018. self.slashes = true;
  30019. }
  30020. }
  30021. var i, hec, l, p;
  30022. if (!hostlessProtocol[proto] &&
  30023. (slashes || (proto && !slashedProtocol[proto]))) {
  30024. // there's a hostname.
  30025. // the first instance of /, ?, ;, or # ends the host.
  30026. //
  30027. // If there is an @ in the hostname, then non-host chars *are* allowed
  30028. // to the left of the last @ sign, unless some host-ending character
  30029. // comes *before* the @-sign.
  30030. // URLs are obnoxious.
  30031. //
  30032. // ex:
  30033. // http://a@b@c/ => user:a@b host:c
  30034. // http://a@b?@c => user:a host:c path:/?@c
  30035. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  30036. // Review our test case against browsers more comprehensively.
  30037. // find the first instance of any hostEndingChars
  30038. var hostEnd = -1;
  30039. for (i = 0; i < hostEndingChars.length; i++) {
  30040. hec = rest.indexOf(hostEndingChars[i]);
  30041. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  30042. hostEnd = hec;
  30043. }
  30044. // at this point, either we have an explicit point where the
  30045. // auth portion cannot go past, or the last @ char is the decider.
  30046. var auth, atSign;
  30047. if (hostEnd === -1) {
  30048. // atSign can be anywhere.
  30049. atSign = rest.lastIndexOf('@');
  30050. } else {
  30051. // atSign must be in auth portion.
  30052. // http://a@b/c@d => host:b auth:a path:/c@d
  30053. atSign = rest.lastIndexOf('@', hostEnd);
  30054. }
  30055. // Now we have a portion which is definitely the auth.
  30056. // Pull that off.
  30057. if (atSign !== -1) {
  30058. auth = rest.slice(0, atSign);
  30059. rest = rest.slice(atSign + 1);
  30060. self.auth = decodeURIComponent(auth);
  30061. }
  30062. // the host is the remaining to the left of the first non-host char
  30063. hostEnd = -1;
  30064. for (i = 0; i < nonHostChars.length; i++) {
  30065. hec = rest.indexOf(nonHostChars[i]);
  30066. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  30067. hostEnd = hec;
  30068. }
  30069. // if we still have not hit it, then the entire thing is a host.
  30070. if (hostEnd === -1)
  30071. hostEnd = rest.length;
  30072. self.host = rest.slice(0, hostEnd);
  30073. rest = rest.slice(hostEnd);
  30074. // pull out port.
  30075. parseHost(self);
  30076. // we've indicated that there is a hostname,
  30077. // so even if it's empty, it has to be present.
  30078. self.hostname = self.hostname || '';
  30079. // if hostname begins with [ and ends with ]
  30080. // assume that it's an IPv6 address.
  30081. var ipv6Hostname = self.hostname[0] === '[' &&
  30082. self.hostname[self.hostname.length - 1] === ']';
  30083. // validate a little.
  30084. if (!ipv6Hostname) {
  30085. var hostparts = self.hostname.split(/\./);
  30086. for (i = 0, l = hostparts.length; i < l; i++) {
  30087. var part = hostparts[i];
  30088. if (!part) continue;
  30089. if (!part.match(hostnamePartPattern)) {
  30090. var newpart = '';
  30091. for (var j = 0, k = part.length; j < k; j++) {
  30092. if (part.charCodeAt(j) > 127) {
  30093. // we replace non-ASCII char with a temporary placeholder
  30094. // we need this to make sure size of hostname is not
  30095. // broken by replacing non-ASCII by nothing
  30096. newpart += 'x';
  30097. } else {
  30098. newpart += part[j];
  30099. }
  30100. }
  30101. // we test again with ASCII char only
  30102. if (!newpart.match(hostnamePartPattern)) {
  30103. var validParts = hostparts.slice(0, i);
  30104. var notHost = hostparts.slice(i + 1);
  30105. var bit = part.match(hostnamePartStart);
  30106. if (bit) {
  30107. validParts.push(bit[1]);
  30108. notHost.unshift(bit[2]);
  30109. }
  30110. if (notHost.length) {
  30111. rest = '/' + notHost.join('.') + rest;
  30112. }
  30113. self.hostname = validParts.join('.');
  30114. break;
  30115. }
  30116. }
  30117. }
  30118. }
  30119. if (self.hostname.length > hostnameMaxLen) {
  30120. self.hostname = '';
  30121. } else {
  30122. // hostnames are always lower case.
  30123. self.hostname = self.hostname.toLowerCase();
  30124. }
  30125. if (!ipv6Hostname) {
  30126. // IDNA Support: Returns a punycoded representation of "domain".
  30127. // It only converts parts of the domain name that
  30128. // have non-ASCII characters, i.e. it doesn't matter if
  30129. // you call it with a domain that already is ASCII-only.
  30130. self.hostname = toASCII(self.hostname);
  30131. }
  30132. p = self.port ? ':' + self.port : '';
  30133. var h = self.hostname || '';
  30134. self.host = h + p;
  30135. self.href += self.host;
  30136. // strip [ and ] from the hostname
  30137. // the host field still retains them, though
  30138. if (ipv6Hostname) {
  30139. self.hostname = self.hostname.substr(1, self.hostname.length - 2);
  30140. if (rest[0] !== '/') {
  30141. rest = '/' + rest;
  30142. }
  30143. }
  30144. }
  30145. // now rest is set to the post-host stuff.
  30146. // chop off any delim chars.
  30147. if (!unsafeProtocol[lowerProto]) {
  30148. // First, make 100% sure that any "autoEscape" chars get
  30149. // escaped, even if encodeURIComponent doesn't think they
  30150. // need to be.
  30151. for (i = 0, l = autoEscape.length; i < l; i++) {
  30152. var ae = autoEscape[i];
  30153. if (rest.indexOf(ae) === -1)
  30154. continue;
  30155. var esc = encodeURIComponent(ae);
  30156. if (esc === ae) {
  30157. esc = escape(ae);
  30158. }
  30159. rest = rest.split(ae).join(esc);
  30160. }
  30161. }
  30162. // chop off from the tail first.
  30163. var hash = rest.indexOf('#');
  30164. if (hash !== -1) {
  30165. // got a fragment string.
  30166. self.hash = rest.substr(hash);
  30167. rest = rest.slice(0, hash);
  30168. }
  30169. var qm = rest.indexOf('?');
  30170. if (qm !== -1) {
  30171. self.search = rest.substr(qm);
  30172. self.query = rest.substr(qm + 1);
  30173. if (parseQueryString) {
  30174. self.query = parse$6(self.query);
  30175. }
  30176. rest = rest.slice(0, qm);
  30177. } else if (parseQueryString) {
  30178. // no query string, but parseQueryString still requested
  30179. self.search = '';
  30180. self.query = {};
  30181. }
  30182. if (rest) self.pathname = rest;
  30183. if (slashedProtocol[lowerProto] &&
  30184. self.hostname && !self.pathname) {
  30185. self.pathname = '/';
  30186. }
  30187. //to support http.request
  30188. if (self.pathname || self.search) {
  30189. p = self.pathname || '';
  30190. var s = self.search || '';
  30191. self.path = p + s;
  30192. }
  30193. // finally, reconstruct the href based on what has been validated.
  30194. self.href = format(self);
  30195. return self;
  30196. }
  30197. function urlFileURLToPath(path) {
  30198. if (typeof path === 'string')
  30199. path = new Url().parse(path);
  30200. else if (!(path instanceof Url))
  30201. throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type ' + (typeof path) + String(path));
  30202. if (path.protocol !== 'file:')
  30203. throw new TypeError('The URL must be of scheme file');
  30204. return getPathFromURLPosix(path);
  30205. }
  30206. function getPathFromURLPosix(url) {
  30207. const pathname = url.pathname;
  30208. for (let n = 0; n < pathname.length; n++) {
  30209. if (pathname[n] === '%') {
  30210. const third = pathname.codePointAt(n + 2) | 0x20;
  30211. if (pathname[n + 1] === '2' && third === 102) {
  30212. throw new TypeError(
  30213. 'must not include encoded / characters'
  30214. );
  30215. }
  30216. }
  30217. }
  30218. return decodeURIComponent(pathname);
  30219. }
  30220. // format a parsed object into a url string
  30221. function urlFormat(obj) {
  30222. // ensure it's an object, and not a string url.
  30223. // If it's an obj, this is a no-op.
  30224. // this way, you can call url_format() on strings
  30225. // to clean up potentially wonky urls.
  30226. if (isString$1(obj)) obj = parse$5({}, obj);
  30227. return format(obj);
  30228. }
  30229. function format(self) {
  30230. var auth = self.auth || '';
  30231. if (auth) {
  30232. auth = encodeURIComponent(auth);
  30233. auth = auth.replace(/%3A/i, ':');
  30234. auth += '@';
  30235. }
  30236. var protocol = self.protocol || '',
  30237. pathname = self.pathname || '',
  30238. hash = self.hash || '',
  30239. host = false,
  30240. query = '';
  30241. if (self.host) {
  30242. host = auth + self.host;
  30243. } else if (self.hostname) {
  30244. host = auth + (self.hostname.indexOf(':') === -1 ?
  30245. self.hostname :
  30246. '[' + this.hostname + ']');
  30247. if (self.port) {
  30248. host += ':' + self.port;
  30249. }
  30250. }
  30251. if (self.query &&
  30252. isObject$1(self.query) &&
  30253. Object.keys(self.query).length) {
  30254. query = stringify$5(self.query);
  30255. }
  30256. var search = self.search || (query && ('?' + query)) || '';
  30257. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  30258. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  30259. // unless they had them to begin with.
  30260. if (self.slashes ||
  30261. (!protocol || slashedProtocol[protocol]) && host !== false) {
  30262. host = '//' + (host || '');
  30263. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  30264. } else if (!host) {
  30265. host = '';
  30266. }
  30267. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  30268. if (search && search.charAt(0) !== '?') search = '?' + search;
  30269. pathname = pathname.replace(/[?#]/g, function(match) {
  30270. return encodeURIComponent(match);
  30271. });
  30272. search = search.replace('#', '%23');
  30273. return protocol + host + pathname + search + hash;
  30274. }
  30275. Url.prototype.format = function() {
  30276. return format(this);
  30277. };
  30278. function urlResolve(source, relative) {
  30279. return urlParse(source, false, true).resolve(relative);
  30280. }
  30281. Url.prototype.resolve = function(relative) {
  30282. return this.resolveObject(urlParse(relative, false, true)).format();
  30283. };
  30284. function urlResolveObject(source, relative) {
  30285. if (!source) return relative;
  30286. return urlParse(source, false, true).resolveObject(relative);
  30287. }
  30288. Url.prototype.resolveObject = function(relative) {
  30289. if (isString$1(relative)) {
  30290. var rel = new Url();
  30291. rel.parse(relative, false, true);
  30292. relative = rel;
  30293. }
  30294. var result = new Url();
  30295. var tkeys = Object.keys(this);
  30296. for (var tk = 0; tk < tkeys.length; tk++) {
  30297. var tkey = tkeys[tk];
  30298. result[tkey] = this[tkey];
  30299. }
  30300. // hash is always overridden, no matter what.
  30301. // even href="" will remove it.
  30302. result.hash = relative.hash;
  30303. // if the relative url is empty, then there's nothing left to do here.
  30304. if (relative.href === '') {
  30305. result.href = result.format();
  30306. return result;
  30307. }
  30308. // hrefs like //foo/bar always cut to the protocol.
  30309. if (relative.slashes && !relative.protocol) {
  30310. // take everything except the protocol from relative
  30311. var rkeys = Object.keys(relative);
  30312. for (var rk = 0; rk < rkeys.length; rk++) {
  30313. var rkey = rkeys[rk];
  30314. if (rkey !== 'protocol')
  30315. result[rkey] = relative[rkey];
  30316. }
  30317. //urlParse appends trailing / to urls like http://www.example.com
  30318. if (slashedProtocol[result.protocol] &&
  30319. result.hostname && !result.pathname) {
  30320. result.path = result.pathname = '/';
  30321. }
  30322. result.href = result.format();
  30323. return result;
  30324. }
  30325. var relPath;
  30326. if (relative.protocol && relative.protocol !== result.protocol) {
  30327. // if it's a known url protocol, then changing
  30328. // the protocol does weird things
  30329. // first, if it's not file:, then we MUST have a host,
  30330. // and if there was a path
  30331. // to begin with, then we MUST have a path.
  30332. // if it is file:, then the host is dropped,
  30333. // because that's known to be hostless.
  30334. // anything else is assumed to be absolute.
  30335. if (!slashedProtocol[relative.protocol]) {
  30336. var keys = Object.keys(relative);
  30337. for (var v = 0; v < keys.length; v++) {
  30338. var k = keys[v];
  30339. result[k] = relative[k];
  30340. }
  30341. result.href = result.format();
  30342. return result;
  30343. }
  30344. result.protocol = relative.protocol;
  30345. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  30346. relPath = (relative.pathname || '').split('/');
  30347. while (relPath.length && !(relative.host = relPath.shift()));
  30348. if (!relative.host) relative.host = '';
  30349. if (!relative.hostname) relative.hostname = '';
  30350. if (relPath[0] !== '') relPath.unshift('');
  30351. if (relPath.length < 2) relPath.unshift('');
  30352. result.pathname = relPath.join('/');
  30353. } else {
  30354. result.pathname = relative.pathname;
  30355. }
  30356. result.search = relative.search;
  30357. result.query = relative.query;
  30358. result.host = relative.host || '';
  30359. result.auth = relative.auth;
  30360. result.hostname = relative.hostname || relative.host;
  30361. result.port = relative.port;
  30362. // to support http.request
  30363. if (result.pathname || result.search) {
  30364. var p = result.pathname || '';
  30365. var s = result.search || '';
  30366. result.path = p + s;
  30367. }
  30368. result.slashes = result.slashes || relative.slashes;
  30369. result.href = result.format();
  30370. return result;
  30371. }
  30372. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  30373. isRelAbs = (
  30374. relative.host ||
  30375. relative.pathname && relative.pathname.charAt(0) === '/'
  30376. ),
  30377. mustEndAbs = (isRelAbs || isSourceAbs ||
  30378. (result.host && relative.pathname)),
  30379. removeAllDots = mustEndAbs,
  30380. srcPath = result.pathname && result.pathname.split('/') || [],
  30381. psychotic = result.protocol && !slashedProtocol[result.protocol];
  30382. relPath = relative.pathname && relative.pathname.split('/') || [];
  30383. // if the url is a non-slashed url, then relative
  30384. // links like ../.. should be able
  30385. // to crawl up to the hostname, as well. This is strange.
  30386. // result.protocol has already been set by now.
  30387. // Later on, put the first path part into the host field.
  30388. if (psychotic) {
  30389. result.hostname = '';
  30390. result.port = null;
  30391. if (result.host) {
  30392. if (srcPath[0] === '') srcPath[0] = result.host;
  30393. else srcPath.unshift(result.host);
  30394. }
  30395. result.host = '';
  30396. if (relative.protocol) {
  30397. relative.hostname = null;
  30398. relative.port = null;
  30399. if (relative.host) {
  30400. if (relPath[0] === '') relPath[0] = relative.host;
  30401. else relPath.unshift(relative.host);
  30402. }
  30403. relative.host = null;
  30404. }
  30405. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  30406. }
  30407. var authInHost;
  30408. if (isRelAbs) {
  30409. // it's absolute.
  30410. result.host = (relative.host || relative.host === '') ?
  30411. relative.host : result.host;
  30412. result.hostname = (relative.hostname || relative.hostname === '') ?
  30413. relative.hostname : result.hostname;
  30414. result.search = relative.search;
  30415. result.query = relative.query;
  30416. srcPath = relPath;
  30417. // fall through to the dot-handling below.
  30418. } else if (relPath.length) {
  30419. // it's relative
  30420. // throw away the existing file, and take the new path instead.
  30421. if (!srcPath) srcPath = [];
  30422. srcPath.pop();
  30423. srcPath = srcPath.concat(relPath);
  30424. result.search = relative.search;
  30425. result.query = relative.query;
  30426. } else if (!isNullOrUndefined(relative.search)) {
  30427. // just pull out the search.
  30428. // like href='?foo'.
  30429. // Put this after the other two cases because it simplifies the booleans
  30430. if (psychotic) {
  30431. result.hostname = result.host = srcPath.shift();
  30432. //occationaly the auth can get stuck only in host
  30433. //this especially happens in cases like
  30434. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30435. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30436. result.host.split('@') : false;
  30437. if (authInHost) {
  30438. result.auth = authInHost.shift();
  30439. result.host = result.hostname = authInHost.shift();
  30440. }
  30441. }
  30442. result.search = relative.search;
  30443. result.query = relative.query;
  30444. //to support http.request
  30445. if (!isNull(result.pathname) || !isNull(result.search)) {
  30446. result.path = (result.pathname ? result.pathname : '') +
  30447. (result.search ? result.search : '');
  30448. }
  30449. result.href = result.format();
  30450. return result;
  30451. }
  30452. if (!srcPath.length) {
  30453. // no path at all. easy.
  30454. // we've already handled the other stuff above.
  30455. result.pathname = null;
  30456. //to support http.request
  30457. if (result.search) {
  30458. result.path = '/' + result.search;
  30459. } else {
  30460. result.path = null;
  30461. }
  30462. result.href = result.format();
  30463. return result;
  30464. }
  30465. // if a url ENDs in . or .., then it must get a trailing slash.
  30466. // however, if it ends in anything else non-slashy,
  30467. // then it must NOT get a trailing slash.
  30468. var last = srcPath.slice(-1)[0];
  30469. var hasTrailingSlash = (
  30470. (result.host || relative.host || srcPath.length > 1) &&
  30471. (last === '.' || last === '..') || last === '');
  30472. // strip single dots, resolve double dots to parent dir
  30473. // if the path tries to go above the root, `up` ends up > 0
  30474. var up = 0;
  30475. for (var i = srcPath.length; i >= 0; i--) {
  30476. last = srcPath[i];
  30477. if (last === '.') {
  30478. srcPath.splice(i, 1);
  30479. } else if (last === '..') {
  30480. srcPath.splice(i, 1);
  30481. up++;
  30482. } else if (up) {
  30483. srcPath.splice(i, 1);
  30484. up--;
  30485. }
  30486. }
  30487. // if the path is allowed to go above the root, restore leading ..s
  30488. if (!mustEndAbs && !removeAllDots) {
  30489. for (; up--; up) {
  30490. srcPath.unshift('..');
  30491. }
  30492. }
  30493. if (mustEndAbs && srcPath[0] !== '' &&
  30494. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  30495. srcPath.unshift('');
  30496. }
  30497. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  30498. srcPath.push('');
  30499. }
  30500. var isAbsolute = srcPath[0] === '' ||
  30501. (srcPath[0] && srcPath[0].charAt(0) === '/');
  30502. // put the host back
  30503. if (psychotic) {
  30504. result.hostname = result.host = isAbsolute ? '' :
  30505. srcPath.length ? srcPath.shift() : '';
  30506. //occationaly the auth can get stuck only in host
  30507. //this especially happens in cases like
  30508. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30509. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30510. result.host.split('@') : false;
  30511. if (authInHost) {
  30512. result.auth = authInHost.shift();
  30513. result.host = result.hostname = authInHost.shift();
  30514. }
  30515. }
  30516. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  30517. if (mustEndAbs && !isAbsolute) {
  30518. srcPath.unshift('');
  30519. }
  30520. if (!srcPath.length) {
  30521. result.pathname = null;
  30522. result.path = null;
  30523. } else {
  30524. result.pathname = srcPath.join('/');
  30525. }
  30526. //to support request.http
  30527. if (!isNull(result.pathname) || !isNull(result.search)) {
  30528. result.path = (result.pathname ? result.pathname : '') +
  30529. (result.search ? result.search : '');
  30530. }
  30531. result.auth = relative.auth || result.auth;
  30532. result.slashes = result.slashes || relative.slashes;
  30533. result.href = result.format();
  30534. return result;
  30535. };
  30536. Url.prototype.parseHost = function() {
  30537. return parseHost(this);
  30538. };
  30539. function parseHost(self) {
  30540. var host = self.host;
  30541. var port = portPattern.exec(host);
  30542. if (port) {
  30543. port = port[0];
  30544. if (port !== ':') {
  30545. self.port = port.substr(1);
  30546. }
  30547. host = host.substr(0, host.length - port.length);
  30548. }
  30549. if (host) self.hostname = host;
  30550. }
  30551. var _polyfillNode_url$1 = /*#__PURE__*/Object.freeze({
  30552. __proto__: null,
  30553. URL: URL$1,
  30554. URLSearchParams: URLSearchParams,
  30555. Url: Url,
  30556. default: _polyfillNode_url,
  30557. fileURLToPath: urlFileURLToPath,
  30558. format: urlFormat,
  30559. parse: urlParse,
  30560. resolve: urlResolve,
  30561. resolveObject: urlResolveObject
  30562. });
  30563. function isRelativeUrl(url) {
  30564. const firstChar = url.charAt(0);
  30565. return firstChar === "." || firstChar === "~" || firstChar === "@";
  30566. }
  30567. const externalRE = /^(https?:)?\/\//;
  30568. function isExternalUrl(url) {
  30569. return externalRE.test(url);
  30570. }
  30571. const dataUrlRE = /^\s*data:/i;
  30572. function isDataUrl(url) {
  30573. return dataUrlRE.test(url);
  30574. }
  30575. function parseUrl(url) {
  30576. const firstChar = url.charAt(0);
  30577. if (firstChar === "~") {
  30578. const secondChar = url.charAt(1);
  30579. url = url.slice(secondChar === "/" ? 2 : 1);
  30580. }
  30581. return parseUriParts(url);
  30582. }
  30583. function parseUriParts(urlString) {
  30584. return urlParse(isString$2(urlString) ? urlString : "", false, true);
  30585. }
  30586. var __defProp$9 = Object.defineProperty;
  30587. var __defProps$9 = Object.defineProperties;
  30588. var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
  30589. var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
  30590. var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
  30591. var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
  30592. var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  30593. var __spreadValues$9 = (a, b) => {
  30594. for (var prop in b || (b = {}))
  30595. if (__hasOwnProp$9.call(b, prop))
  30596. __defNormalProp$9(a, prop, b[prop]);
  30597. if (__getOwnPropSymbols$9)
  30598. for (var prop of __getOwnPropSymbols$9(b)) {
  30599. if (__propIsEnum$9.call(b, prop))
  30600. __defNormalProp$9(a, prop, b[prop]);
  30601. }
  30602. return a;
  30603. };
  30604. var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
  30605. const defaultAssetUrlOptions = {
  30606. base: null,
  30607. includeAbsolute: false,
  30608. tags: {
  30609. video: ["src", "poster"],
  30610. source: ["src"],
  30611. img: ["src"],
  30612. image: ["xlink:href", "href"],
  30613. use: ["xlink:href", "href"]
  30614. }
  30615. };
  30616. const normalizeOptions = (options) => {
  30617. if (Object.keys(options).some((key) => isArray$3(options[key]))) {
  30618. return __spreadProps$9(__spreadValues$9({}, defaultAssetUrlOptions), {
  30619. tags: options
  30620. });
  30621. }
  30622. return __spreadValues$9(__spreadValues$9({}, defaultAssetUrlOptions), options);
  30623. };
  30624. const createAssetUrlTransformWithOptions = (options) => {
  30625. return (node, context) => transformAssetUrl(node, context, options);
  30626. };
  30627. const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
  30628. if (node.type === 1) {
  30629. if (!node.props.length) {
  30630. return;
  30631. }
  30632. const tags = options.tags || defaultAssetUrlOptions.tags;
  30633. const attrs = tags[node.tag];
  30634. const wildCardAttrs = tags["*"];
  30635. if (!attrs && !wildCardAttrs) {
  30636. return;
  30637. }
  30638. const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
  30639. node.props.forEach((attr, index) => {
  30640. 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)) {
  30641. return;
  30642. }
  30643. const url = parseUrl(attr.value.content);
  30644. if (options.base && attr.value.content[0] === ".") {
  30645. const base = parseUrl(options.base);
  30646. const protocol = base.protocol || "";
  30647. const host = base.host ? protocol + "//" + base.host : "";
  30648. const basePath = base.path || "/";
  30649. attr.value.content = host + (path.posix || path).join(basePath, url.path + (url.hash || ""));
  30650. return;
  30651. }
  30652. const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
  30653. node.props[index] = {
  30654. type: 7,
  30655. name: "bind",
  30656. arg: createSimpleExpression(attr.name, true, attr.loc),
  30657. exp,
  30658. modifiers: [],
  30659. loc: attr.loc
  30660. };
  30661. });
  30662. }
  30663. };
  30664. function getImportsExpressionExp(path2, hash, loc, context) {
  30665. if (path2) {
  30666. let name;
  30667. let exp;
  30668. const existingIndex = context.imports.findIndex((i) => i.path === path2);
  30669. if (existingIndex > -1) {
  30670. name = `_imports_${existingIndex}`;
  30671. exp = context.imports[existingIndex].exp;
  30672. } else {
  30673. name = `_imports_${context.imports.length}`;
  30674. exp = createSimpleExpression(
  30675. name,
  30676. false,
  30677. loc,
  30678. 3
  30679. );
  30680. context.imports.push({
  30681. exp,
  30682. path: decodeURIComponent(path2)
  30683. });
  30684. }
  30685. if (!hash) {
  30686. return exp;
  30687. }
  30688. const hashExp = `${name} + '${hash}'`;
  30689. const finalExp = createSimpleExpression(
  30690. hashExp,
  30691. false,
  30692. loc,
  30693. 3
  30694. );
  30695. if (!context.hoistStatic) {
  30696. return finalExp;
  30697. }
  30698. const existingHoistIndex = context.hoists.findIndex((h) => {
  30699. return h && h.type === 4 && !h.isStatic && h.content === hashExp;
  30700. });
  30701. if (existingHoistIndex > -1) {
  30702. return createSimpleExpression(
  30703. `_hoisted_${existingHoistIndex + 1}`,
  30704. false,
  30705. loc,
  30706. 3
  30707. );
  30708. }
  30709. return context.hoist(finalExp);
  30710. } else {
  30711. return createSimpleExpression(`''`, false, loc, 3);
  30712. }
  30713. }
  30714. const srcsetTags = ["img", "source"];
  30715. const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
  30716. const createSrcsetTransformWithOptions = (options) => {
  30717. return (node, context) => transformSrcset(node, context, options);
  30718. };
  30719. const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
  30720. if (node.type === 1) {
  30721. if (srcsetTags.includes(node.tag) && node.props.length) {
  30722. node.props.forEach((attr, index) => {
  30723. if (attr.name === "srcset" && attr.type === 6) {
  30724. if (!attr.value)
  30725. return;
  30726. const value = attr.value.content;
  30727. if (!value)
  30728. return;
  30729. const imageCandidates = value.split(",").map((s) => {
  30730. const [url, descriptor] = s.replace(escapedSpaceCharacters, " ").trim().split(" ", 2);
  30731. return { url, descriptor };
  30732. });
  30733. for (let i = 0; i < imageCandidates.length; i++) {
  30734. const { url } = imageCandidates[i];
  30735. if (isDataUrl(url)) {
  30736. imageCandidates[i + 1].url = url + "," + imageCandidates[i + 1].url;
  30737. imageCandidates.splice(i, 1);
  30738. }
  30739. }
  30740. const shouldProcessUrl = (url) => {
  30741. return !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
  30742. };
  30743. if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
  30744. return;
  30745. }
  30746. if (options.base) {
  30747. const base = options.base;
  30748. const set = [];
  30749. let needImportTransform = false;
  30750. imageCandidates.forEach((candidate) => {
  30751. let { url, descriptor } = candidate;
  30752. descriptor = descriptor ? ` ${descriptor}` : ``;
  30753. if (url[0] === ".") {
  30754. candidate.url = (path.posix || path).join(base, url);
  30755. set.push(candidate.url + descriptor);
  30756. } else if (shouldProcessUrl(url)) {
  30757. needImportTransform = true;
  30758. } else {
  30759. set.push(url + descriptor);
  30760. }
  30761. });
  30762. if (!needImportTransform) {
  30763. attr.value.content = set.join(", ");
  30764. return;
  30765. }
  30766. }
  30767. const compoundExpression = createCompoundExpression([], attr.loc);
  30768. imageCandidates.forEach(({ url, descriptor }, index2) => {
  30769. if (shouldProcessUrl(url)) {
  30770. const { path: path2 } = parseUrl(url);
  30771. let exp2;
  30772. if (path2) {
  30773. const existingImportsIndex = context.imports.findIndex(
  30774. (i) => i.path === path2
  30775. );
  30776. if (existingImportsIndex > -1) {
  30777. exp2 = createSimpleExpression(
  30778. `_imports_${existingImportsIndex}`,
  30779. false,
  30780. attr.loc,
  30781. 3
  30782. );
  30783. } else {
  30784. exp2 = createSimpleExpression(
  30785. `_imports_${context.imports.length}`,
  30786. false,
  30787. attr.loc,
  30788. 3
  30789. );
  30790. context.imports.push({ exp: exp2, path: path2 });
  30791. }
  30792. compoundExpression.children.push(exp2);
  30793. }
  30794. } else {
  30795. const exp2 = createSimpleExpression(
  30796. `"${url}"`,
  30797. false,
  30798. attr.loc,
  30799. 3
  30800. );
  30801. compoundExpression.children.push(exp2);
  30802. }
  30803. const isNotLast = imageCandidates.length - 1 > index2;
  30804. if (descriptor && isNotLast) {
  30805. compoundExpression.children.push(` + ' ${descriptor}, ' + `);
  30806. } else if (descriptor) {
  30807. compoundExpression.children.push(` + ' ${descriptor}'`);
  30808. } else if (isNotLast) {
  30809. compoundExpression.children.push(` + ', ' + `);
  30810. }
  30811. });
  30812. let exp = compoundExpression;
  30813. if (context.hoistStatic) {
  30814. exp = context.hoist(compoundExpression);
  30815. exp.constType = 3;
  30816. }
  30817. node.props[index] = {
  30818. type: 7,
  30819. name: "bind",
  30820. arg: createSimpleExpression("srcset", true, attr.loc),
  30821. exp,
  30822. modifiers: [],
  30823. loc: attr.loc
  30824. };
  30825. }
  30826. });
  30827. }
  30828. }
  30829. };
  30830. const SSR_INTERPOLATE = Symbol(`ssrInterpolate`);
  30831. const SSR_RENDER_VNODE = Symbol(`ssrRenderVNode`);
  30832. const SSR_RENDER_COMPONENT = Symbol(`ssrRenderComponent`);
  30833. const SSR_RENDER_SLOT = Symbol(`ssrRenderSlot`);
  30834. const SSR_RENDER_SLOT_INNER = Symbol(`ssrRenderSlotInner`);
  30835. const SSR_RENDER_CLASS = Symbol(`ssrRenderClass`);
  30836. const SSR_RENDER_STYLE = Symbol(`ssrRenderStyle`);
  30837. const SSR_RENDER_ATTRS = Symbol(`ssrRenderAttrs`);
  30838. const SSR_RENDER_ATTR = Symbol(`ssrRenderAttr`);
  30839. const SSR_RENDER_DYNAMIC_ATTR = Symbol(`ssrRenderDynamicAttr`);
  30840. const SSR_RENDER_LIST = Symbol(`ssrRenderList`);
  30841. const SSR_INCLUDE_BOOLEAN_ATTR = Symbol(`ssrIncludeBooleanAttr`);
  30842. const SSR_LOOSE_EQUAL = Symbol(`ssrLooseEqual`);
  30843. const SSR_LOOSE_CONTAIN = Symbol(`ssrLooseContain`);
  30844. const SSR_RENDER_DYNAMIC_MODEL = Symbol(`ssrRenderDynamicModel`);
  30845. const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(`ssrGetDynamicModelProps`);
  30846. const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`);
  30847. const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`);
  30848. const SSR_GET_DIRECTIVE_PROPS = Symbol(`ssrGetDirectiveProps`);
  30849. const ssrHelpers = {
  30850. [SSR_INTERPOLATE]: `ssrInterpolate`,
  30851. [SSR_RENDER_VNODE]: `ssrRenderVNode`,
  30852. [SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
  30853. [SSR_RENDER_SLOT]: `ssrRenderSlot`,
  30854. [SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
  30855. [SSR_RENDER_CLASS]: `ssrRenderClass`,
  30856. [SSR_RENDER_STYLE]: `ssrRenderStyle`,
  30857. [SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
  30858. [SSR_RENDER_ATTR]: `ssrRenderAttr`,
  30859. [SSR_RENDER_DYNAMIC_ATTR]: `ssrRenderDynamicAttr`,
  30860. [SSR_RENDER_LIST]: `ssrRenderList`,
  30861. [SSR_INCLUDE_BOOLEAN_ATTR]: `ssrIncludeBooleanAttr`,
  30862. [SSR_LOOSE_EQUAL]: `ssrLooseEqual`,
  30863. [SSR_LOOSE_CONTAIN]: `ssrLooseContain`,
  30864. [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
  30865. [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
  30866. [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
  30867. [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
  30868. [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps`
  30869. };
  30870. registerRuntimeHelpers(ssrHelpers);
  30871. const ssrTransformIf = createStructuralDirectiveTransform(
  30872. /^(if|else|else-if)$/,
  30873. processIf
  30874. );
  30875. function ssrProcessIf(node, context, disableNestedFragments = false) {
  30876. const [rootBranch] = node.branches;
  30877. const ifStatement = createIfStatement(
  30878. rootBranch.condition,
  30879. processIfBranch(rootBranch, context, disableNestedFragments)
  30880. );
  30881. context.pushStatement(ifStatement);
  30882. let currentIf = ifStatement;
  30883. for (let i = 1; i < node.branches.length; i++) {
  30884. const branch = node.branches[i];
  30885. const branchBlockStatement = processIfBranch(
  30886. branch,
  30887. context,
  30888. disableNestedFragments
  30889. );
  30890. if (branch.condition) {
  30891. currentIf = currentIf.alternate = createIfStatement(
  30892. branch.condition,
  30893. branchBlockStatement
  30894. );
  30895. } else {
  30896. currentIf.alternate = branchBlockStatement;
  30897. }
  30898. }
  30899. if (!currentIf.alternate) {
  30900. currentIf.alternate = createBlockStatement([
  30901. createCallExpression(`_push`, ["`<!---->`"])
  30902. ]);
  30903. }
  30904. }
  30905. function processIfBranch(branch, context, disableNestedFragments = false) {
  30906. const { children } = branch;
  30907. const needFragmentWrapper = !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && // optimize away nested fragments when the only child is a ForNode
  30908. !(children.length === 1 && children[0].type === 11);
  30909. return processChildrenAsStatement(branch, context, needFragmentWrapper);
  30910. }
  30911. const ssrTransformFor = createStructuralDirectiveTransform(
  30912. "for",
  30913. processFor
  30914. );
  30915. function ssrProcessFor(node, context, disableNestedFragments = false) {
  30916. const needFragmentWrapper = !disableNestedFragments && (node.children.length !== 1 || node.children[0].type !== 1);
  30917. const renderLoop = createFunctionExpression(
  30918. createForLoopParams(node.parseResult)
  30919. );
  30920. renderLoop.body = processChildrenAsStatement(
  30921. node,
  30922. context,
  30923. needFragmentWrapper
  30924. );
  30925. if (!disableNestedFragments) {
  30926. context.pushStringPart(`<!--[-->`);
  30927. }
  30928. context.pushStatement(
  30929. createCallExpression(context.helper(SSR_RENDER_LIST), [
  30930. node.source,
  30931. renderLoop
  30932. ])
  30933. );
  30934. if (!disableNestedFragments) {
  30935. context.pushStringPart(`<!--]-->`);
  30936. }
  30937. }
  30938. const ssrTransformSlotOutlet = (node, context) => {
  30939. if (isSlotOutlet(node)) {
  30940. const { slotName, slotProps } = processSlotOutlet(node, context);
  30941. const args = [
  30942. `_ctx.$slots`,
  30943. slotName,
  30944. slotProps || `{}`,
  30945. // fallback content placeholder. will be replaced in the process phase
  30946. `null`,
  30947. `_push`,
  30948. `_parent`
  30949. ];
  30950. if (context.scopeId && context.slotted !== false) {
  30951. args.push(`"${context.scopeId}-s"`);
  30952. }
  30953. let method = SSR_RENDER_SLOT;
  30954. const parent = context.parent;
  30955. if (parent && parent.type === 1 && parent.tagType === 1 && resolveComponentType(parent, context, true) === TRANSITION && parent.children.filter((c) => c.type === 1).length === 1) {
  30956. method = SSR_RENDER_SLOT_INNER;
  30957. if (!(context.scopeId && context.slotted !== false)) {
  30958. args.push("null");
  30959. }
  30960. args.push("true");
  30961. }
  30962. node.ssrCodegenNode = createCallExpression(context.helper(method), args);
  30963. }
  30964. };
  30965. function ssrProcessSlotOutlet(node, context) {
  30966. const renderCall = node.ssrCodegenNode;
  30967. if (node.children.length) {
  30968. const fallbackRenderFn = createFunctionExpression([]);
  30969. fallbackRenderFn.body = processChildrenAsStatement(node, context);
  30970. renderCall.arguments[3] = fallbackRenderFn;
  30971. }
  30972. if (context.withSlotScopeId) {
  30973. const slotScopeId = renderCall.arguments[6];
  30974. renderCall.arguments[6] = slotScopeId ? `${slotScopeId} + _scopeId` : `_scopeId`;
  30975. }
  30976. context.pushStatement(node.ssrCodegenNode);
  30977. }
  30978. function createSSRCompilerError(code, loc) {
  30979. return createCompilerError(code, loc, SSRErrorMessages);
  30980. }
  30981. const SSRErrorMessages = {
  30982. [65]: `Unsafe attribute name for SSR.`,
  30983. [66]: `Missing the 'to' prop on teleport element.`,
  30984. [67]: `Invalid AST node during SSR transform.`
  30985. };
  30986. function ssrProcessTeleport(node, context) {
  30987. const targetProp = findProp(node, "to");
  30988. if (!targetProp) {
  30989. context.onError(
  30990. createSSRCompilerError(66, node.loc)
  30991. );
  30992. return;
  30993. }
  30994. let target;
  30995. if (targetProp.type === 6) {
  30996. target = targetProp.value && createSimpleExpression(targetProp.value.content, true);
  30997. } else {
  30998. target = targetProp.exp;
  30999. }
  31000. if (!target) {
  31001. context.onError(
  31002. createSSRCompilerError(
  31003. 66,
  31004. targetProp.loc
  31005. )
  31006. );
  31007. return;
  31008. }
  31009. const disabledProp = findProp(
  31010. node,
  31011. "disabled",
  31012. false,
  31013. true
  31014. /* allow empty */
  31015. );
  31016. const disabled = disabledProp ? disabledProp.type === 6 ? `true` : disabledProp.exp || `false` : `false`;
  31017. const contentRenderFn = createFunctionExpression(
  31018. [`_push`],
  31019. void 0,
  31020. // Body is added later
  31021. true,
  31022. // newline
  31023. false,
  31024. // isSlot
  31025. node.loc
  31026. );
  31027. contentRenderFn.body = processChildrenAsStatement(node, context);
  31028. context.pushStatement(
  31029. createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
  31030. `_push`,
  31031. contentRenderFn,
  31032. target,
  31033. disabled,
  31034. `_parent`
  31035. ])
  31036. );
  31037. }
  31038. const wipMap$3 = /* @__PURE__ */ new WeakMap();
  31039. function ssrTransformSuspense(node, context) {
  31040. return () => {
  31041. if (node.children.length) {
  31042. const wipEntry = {
  31043. slotsExp: null,
  31044. // to be immediately set
  31045. wipSlots: []
  31046. };
  31047. wipMap$3.set(node, wipEntry);
  31048. wipEntry.slotsExp = buildSlots(
  31049. node,
  31050. context,
  31051. (_props, _vForExp, children, loc) => {
  31052. const fn = createFunctionExpression(
  31053. [],
  31054. void 0,
  31055. // no return, assign body later
  31056. true,
  31057. // newline
  31058. false,
  31059. // suspense slots are not treated as normal slots
  31060. loc
  31061. );
  31062. wipEntry.wipSlots.push({
  31063. fn,
  31064. children
  31065. });
  31066. return fn;
  31067. }
  31068. ).slots;
  31069. }
  31070. };
  31071. }
  31072. function ssrProcessSuspense(node, context) {
  31073. const wipEntry = wipMap$3.get(node);
  31074. if (!wipEntry) {
  31075. return;
  31076. }
  31077. const { slotsExp, wipSlots } = wipEntry;
  31078. for (let i = 0; i < wipSlots.length; i++) {
  31079. const slot = wipSlots[i];
  31080. slot.fn.body = processChildrenAsStatement(slot, context);
  31081. }
  31082. context.pushStatement(
  31083. createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
  31084. `_push`,
  31085. slotsExp
  31086. ])
  31087. );
  31088. }
  31089. const rawChildrenMap = /* @__PURE__ */ new WeakMap();
  31090. const ssrTransformElement = (node, context) => {
  31091. if (node.type !== 1 || node.tagType !== 0) {
  31092. return;
  31093. }
  31094. return function ssrPostTransformElement() {
  31095. const openTag = [`<${node.tag}`];
  31096. const needTagForRuntime = node.tag === "textarea" || node.tag.indexOf("-") > 0;
  31097. const hasDynamicVBind = hasDynamicKeyVBind(node);
  31098. const hasCustomDir = node.props.some(
  31099. (p) => p.type === 7 && !isBuiltInDirective(p.name)
  31100. );
  31101. const needMergeProps = hasDynamicVBind || hasCustomDir;
  31102. if (needMergeProps) {
  31103. const { props, directives } = buildProps(
  31104. node,
  31105. context,
  31106. node.props,
  31107. false,
  31108. false,
  31109. true
  31110. /* ssr */
  31111. );
  31112. if (props || directives.length) {
  31113. const mergedProps = buildSSRProps(props, directives, context);
  31114. const propsExp = createCallExpression(
  31115. context.helper(SSR_RENDER_ATTRS),
  31116. [mergedProps]
  31117. );
  31118. if (node.tag === "textarea") {
  31119. const existingText = node.children[0];
  31120. if (!existingText || existingText.type !== 5) {
  31121. const tempId = `_temp${context.temps++}`;
  31122. propsExp.arguments = [
  31123. createAssignmentExpression(
  31124. createSimpleExpression(tempId, false),
  31125. mergedProps
  31126. )
  31127. ];
  31128. rawChildrenMap.set(
  31129. node,
  31130. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31131. createConditionalExpression(
  31132. createSimpleExpression(`"value" in ${tempId}`, false),
  31133. createSimpleExpression(`${tempId}.value`, false),
  31134. createSimpleExpression(
  31135. existingText ? existingText.content : ``,
  31136. true
  31137. ),
  31138. false
  31139. )
  31140. ])
  31141. );
  31142. }
  31143. } else if (node.tag === "input") {
  31144. const vModel = findVModel(node);
  31145. if (vModel) {
  31146. const tempId = `_temp${context.temps++}`;
  31147. const tempExp = createSimpleExpression(tempId, false);
  31148. propsExp.arguments = [
  31149. createSequenceExpression([
  31150. createAssignmentExpression(tempExp, mergedProps),
  31151. createCallExpression(context.helper(MERGE_PROPS), [
  31152. tempExp,
  31153. createCallExpression(
  31154. context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
  31155. [
  31156. tempExp,
  31157. // existing props
  31158. vModel.exp
  31159. // model
  31160. ]
  31161. )
  31162. ])
  31163. ])
  31164. ];
  31165. }
  31166. }
  31167. if (needTagForRuntime) {
  31168. propsExp.arguments.push(`"${node.tag}"`);
  31169. }
  31170. openTag.push(propsExp);
  31171. }
  31172. }
  31173. let dynamicClassBinding = void 0;
  31174. let staticClassBinding = void 0;
  31175. let dynamicStyleBinding = void 0;
  31176. for (let i = 0; i < node.props.length; i++) {
  31177. const prop = node.props[i];
  31178. if (node.tag === "input" && isTrueFalseValue(prop)) {
  31179. continue;
  31180. }
  31181. if (prop.type === 7) {
  31182. if (prop.name === "html" && prop.exp) {
  31183. rawChildrenMap.set(node, prop.exp);
  31184. } else if (prop.name === "text" && prop.exp) {
  31185. node.children = [createInterpolation(prop.exp, prop.loc)];
  31186. } else if (prop.name === "slot") {
  31187. context.onError(
  31188. createCompilerError(40, prop.loc)
  31189. );
  31190. } else if (isTextareaWithValue(node, prop) && prop.exp) {
  31191. if (!needMergeProps) {
  31192. node.children = [createInterpolation(prop.exp, prop.loc)];
  31193. }
  31194. } else if (!needMergeProps && prop.name !== "on") {
  31195. const directiveTransform = context.directiveTransforms[prop.name];
  31196. if (directiveTransform) {
  31197. const { props, ssrTagParts } = directiveTransform(
  31198. prop,
  31199. node,
  31200. context
  31201. );
  31202. if (ssrTagParts) {
  31203. openTag.push(...ssrTagParts);
  31204. }
  31205. for (let j = 0; j < props.length; j++) {
  31206. const { key, value } = props[j];
  31207. if (isStaticExp(key)) {
  31208. let attrName = key.content;
  31209. if (attrName === "key" || attrName === "ref") {
  31210. continue;
  31211. }
  31212. if (attrName === "class") {
  31213. openTag.push(
  31214. ` class="`,
  31215. dynamicClassBinding = createCallExpression(
  31216. context.helper(SSR_RENDER_CLASS),
  31217. [value]
  31218. ),
  31219. `"`
  31220. );
  31221. } else if (attrName === "style") {
  31222. if (dynamicStyleBinding) {
  31223. mergeCall(dynamicStyleBinding, value);
  31224. } else {
  31225. openTag.push(
  31226. ` style="`,
  31227. dynamicStyleBinding = createCallExpression(
  31228. context.helper(SSR_RENDER_STYLE),
  31229. [value]
  31230. ),
  31231. `"`
  31232. );
  31233. }
  31234. } else {
  31235. attrName = node.tag.indexOf("-") > 0 ? attrName : propsToAttrMap[attrName] || attrName.toLowerCase();
  31236. if (isBooleanAttr(attrName)) {
  31237. openTag.push(
  31238. createConditionalExpression(
  31239. createCallExpression(
  31240. context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
  31241. [value]
  31242. ),
  31243. createSimpleExpression(" " + attrName, true),
  31244. createSimpleExpression("", true),
  31245. false
  31246. /* no newline */
  31247. )
  31248. );
  31249. } else if (isSSRSafeAttrName(attrName)) {
  31250. openTag.push(
  31251. createCallExpression(context.helper(SSR_RENDER_ATTR), [
  31252. key,
  31253. value
  31254. ])
  31255. );
  31256. } else {
  31257. context.onError(
  31258. createSSRCompilerError(
  31259. 65,
  31260. key.loc
  31261. )
  31262. );
  31263. }
  31264. }
  31265. } else {
  31266. const args = [key, value];
  31267. if (needTagForRuntime) {
  31268. args.push(`"${node.tag}"`);
  31269. }
  31270. openTag.push(
  31271. createCallExpression(
  31272. context.helper(SSR_RENDER_DYNAMIC_ATTR),
  31273. args
  31274. )
  31275. );
  31276. }
  31277. }
  31278. }
  31279. }
  31280. } else {
  31281. if (node.tag === "textarea" && prop.name === "value" && prop.value) {
  31282. rawChildrenMap.set(node, escapeHtml(prop.value.content));
  31283. } else if (!needMergeProps) {
  31284. if (prop.name === "key" || prop.name === "ref") {
  31285. continue;
  31286. }
  31287. if (prop.name === "class" && prop.value) {
  31288. staticClassBinding = JSON.stringify(prop.value.content);
  31289. }
  31290. openTag.push(
  31291. ` ${prop.name}` + (prop.value ? `="${escapeHtml(prop.value.content)}"` : ``)
  31292. );
  31293. }
  31294. }
  31295. }
  31296. if (dynamicClassBinding && staticClassBinding) {
  31297. mergeCall(dynamicClassBinding, staticClassBinding);
  31298. removeStaticBinding(openTag, "class");
  31299. }
  31300. if (context.scopeId) {
  31301. openTag.push(` ${context.scopeId}`);
  31302. }
  31303. node.ssrCodegenNode = createTemplateLiteral(openTag);
  31304. };
  31305. };
  31306. function buildSSRProps(props, directives, context) {
  31307. let mergePropsArgs = [];
  31308. if (props) {
  31309. if (props.type === 14) {
  31310. mergePropsArgs = props.arguments;
  31311. } else {
  31312. mergePropsArgs.push(props);
  31313. }
  31314. }
  31315. if (directives.length) {
  31316. for (const dir of directives) {
  31317. mergePropsArgs.push(
  31318. createCallExpression(context.helper(SSR_GET_DIRECTIVE_PROPS), [
  31319. `_ctx`,
  31320. ...buildDirectiveArgs(dir, context).elements
  31321. ])
  31322. );
  31323. }
  31324. }
  31325. return mergePropsArgs.length > 1 ? createCallExpression(context.helper(MERGE_PROPS), mergePropsArgs) : mergePropsArgs[0];
  31326. }
  31327. function isTrueFalseValue(prop) {
  31328. if (prop.type === 7) {
  31329. return prop.name === "bind" && prop.arg && isStaticExp(prop.arg) && (prop.arg.content === "true-value" || prop.arg.content === "false-value");
  31330. } else {
  31331. return prop.name === "true-value" || prop.name === "false-value";
  31332. }
  31333. }
  31334. function isTextareaWithValue(node, prop) {
  31335. return !!(node.tag === "textarea" && prop.name === "bind" && isStaticArgOf(prop.arg, "value"));
  31336. }
  31337. function mergeCall(call, arg) {
  31338. const existing = call.arguments[0];
  31339. if (existing.type === 17) {
  31340. existing.elements.push(arg);
  31341. } else {
  31342. call.arguments[0] = createArrayExpression([existing, arg]);
  31343. }
  31344. }
  31345. function removeStaticBinding(tag, binding) {
  31346. const regExp = new RegExp(`^ ${binding}=".+"$`);
  31347. const i = tag.findIndex((e) => typeof e === "string" && regExp.test(e));
  31348. if (i > -1) {
  31349. tag.splice(i, 1);
  31350. }
  31351. }
  31352. function findVModel(node) {
  31353. return node.props.find(
  31354. (p) => p.type === 7 && p.name === "model" && p.exp
  31355. );
  31356. }
  31357. function ssrProcessElement(node, context) {
  31358. const isVoidTag = context.options.isVoidTag || NO;
  31359. const elementsToAdd = node.ssrCodegenNode.elements;
  31360. for (let j = 0; j < elementsToAdd.length; j++) {
  31361. context.pushStringPart(elementsToAdd[j]);
  31362. }
  31363. if (context.withSlotScopeId) {
  31364. context.pushStringPart(createSimpleExpression(`_scopeId`, false));
  31365. }
  31366. context.pushStringPart(`>`);
  31367. const rawChildren = rawChildrenMap.get(node);
  31368. if (rawChildren) {
  31369. context.pushStringPart(rawChildren);
  31370. } else if (node.children.length) {
  31371. processChildren(node, context);
  31372. }
  31373. if (!isVoidTag(node.tag)) {
  31374. context.pushStringPart(`</${node.tag}>`);
  31375. }
  31376. }
  31377. const wipMap$2 = /* @__PURE__ */ new WeakMap();
  31378. function ssrTransformTransitionGroup(node, context) {
  31379. return () => {
  31380. const tag = findProp(node, "tag");
  31381. if (tag) {
  31382. const otherProps = node.props.filter((p) => p !== tag);
  31383. const { props, directives } = buildProps(
  31384. node,
  31385. context,
  31386. otherProps,
  31387. true,
  31388. false,
  31389. true
  31390. /* ssr (skip event listeners) */
  31391. );
  31392. let propsExp = null;
  31393. if (props || directives.length) {
  31394. propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [
  31395. buildSSRProps(props, directives, context)
  31396. ]);
  31397. }
  31398. wipMap$2.set(node, {
  31399. tag,
  31400. propsExp,
  31401. scopeId: context.scopeId || null
  31402. });
  31403. }
  31404. };
  31405. }
  31406. function ssrProcessTransitionGroup(node, context) {
  31407. const entry = wipMap$2.get(node);
  31408. if (entry) {
  31409. const { tag, propsExp, scopeId } = entry;
  31410. if (tag.type === 7) {
  31411. context.pushStringPart(`<`);
  31412. context.pushStringPart(tag.exp);
  31413. if (propsExp) {
  31414. context.pushStringPart(propsExp);
  31415. }
  31416. if (scopeId) {
  31417. context.pushStringPart(` ${scopeId}`);
  31418. }
  31419. context.pushStringPart(`>`);
  31420. processChildren(
  31421. node,
  31422. context,
  31423. false,
  31424. /**
  31425. * TransitionGroup has the special runtime behavior of flattening and
  31426. * concatenating all children into a single fragment (in order for them to
  31427. * be patched using the same key map) so we need to account for that here
  31428. * by disabling nested fragment wrappers from being generated.
  31429. */
  31430. true
  31431. );
  31432. context.pushStringPart(`</`);
  31433. context.pushStringPart(tag.exp);
  31434. context.pushStringPart(`>`);
  31435. } else {
  31436. context.pushStringPart(`<${tag.value.content}`);
  31437. if (propsExp) {
  31438. context.pushStringPart(propsExp);
  31439. }
  31440. if (scopeId) {
  31441. context.pushStringPart(` ${scopeId}`);
  31442. }
  31443. context.pushStringPart(`>`);
  31444. processChildren(node, context, false, true);
  31445. context.pushStringPart(`</${tag.value.content}>`);
  31446. }
  31447. } else {
  31448. processChildren(node, context, true, true);
  31449. }
  31450. }
  31451. const wipMap$1 = /* @__PURE__ */ new WeakMap();
  31452. function ssrTransformTransition(node, context) {
  31453. return () => {
  31454. const appear = findProp(node, "appear", false, true);
  31455. wipMap$1.set(node, !!appear);
  31456. };
  31457. }
  31458. function ssrProcessTransition(node, context) {
  31459. node.children = node.children.filter((c) => c.type !== 3);
  31460. const appear = wipMap$1.get(node);
  31461. if (appear) {
  31462. context.pushStringPart(`<template>`);
  31463. processChildren(node, context, false, true);
  31464. context.pushStringPart(`</template>`);
  31465. } else {
  31466. processChildren(node, context, false, true);
  31467. }
  31468. }
  31469. var __defProp$8 = Object.defineProperty;
  31470. var __defProps$8 = Object.defineProperties;
  31471. var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
  31472. var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
  31473. var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
  31474. var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
  31475. var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31476. var __spreadValues$8 = (a, b) => {
  31477. for (var prop in b || (b = {}))
  31478. if (__hasOwnProp$8.call(b, prop))
  31479. __defNormalProp$8(a, prop, b[prop]);
  31480. if (__getOwnPropSymbols$8)
  31481. for (var prop of __getOwnPropSymbols$8(b)) {
  31482. if (__propIsEnum$8.call(b, prop))
  31483. __defNormalProp$8(a, prop, b[prop]);
  31484. }
  31485. return a;
  31486. };
  31487. var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
  31488. const wipMap = /* @__PURE__ */ new WeakMap();
  31489. const WIP_SLOT = Symbol();
  31490. const componentTypeMap = /* @__PURE__ */ new WeakMap();
  31491. const ssrTransformComponent = (node, context) => {
  31492. if (node.type !== 1 || node.tagType !== 1) {
  31493. return;
  31494. }
  31495. const component = resolveComponentType(
  31496. node,
  31497. context,
  31498. true
  31499. /* ssr */
  31500. );
  31501. const isDynamicComponent = isObject$2(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
  31502. componentTypeMap.set(node, component);
  31503. if (isSymbol$1(component)) {
  31504. if (component === SUSPENSE) {
  31505. return ssrTransformSuspense(node, context);
  31506. } else if (component === TRANSITION_GROUP) {
  31507. return ssrTransformTransitionGroup(node, context);
  31508. } else if (component === TRANSITION) {
  31509. return ssrTransformTransition(node);
  31510. }
  31511. return;
  31512. }
  31513. const vnodeBranches = [];
  31514. const clonedNode = clone(node);
  31515. return function ssrPostTransformComponent() {
  31516. if (clonedNode.children.length) {
  31517. buildSlots(clonedNode, context, (props, vFor, children) => {
  31518. vnodeBranches.push(
  31519. createVNodeSlotBranch(props, vFor, children, context)
  31520. );
  31521. return createFunctionExpression(void 0);
  31522. });
  31523. }
  31524. let propsExp = `null`;
  31525. if (node.props.length) {
  31526. const { props, directives } = buildProps(
  31527. node,
  31528. context,
  31529. void 0,
  31530. true,
  31531. isDynamicComponent
  31532. );
  31533. if (props || directives.length) {
  31534. propsExp = buildSSRProps(props, directives, context);
  31535. }
  31536. }
  31537. const wipEntries = [];
  31538. wipMap.set(node, wipEntries);
  31539. const buildSSRSlotFn = (props, _vForExp, children, loc) => {
  31540. const param0 = props && stringifyExpression(props) || `_`;
  31541. const fn = createFunctionExpression(
  31542. [param0, `_push`, `_parent`, `_scopeId`],
  31543. void 0,
  31544. // no return, assign body later
  31545. true,
  31546. // newline
  31547. true,
  31548. // isSlot
  31549. loc
  31550. );
  31551. wipEntries.push({
  31552. type: WIP_SLOT,
  31553. fn,
  31554. children,
  31555. // also collect the corresponding vnode branch built earlier
  31556. vnodeBranch: vnodeBranches[wipEntries.length]
  31557. });
  31558. return fn;
  31559. };
  31560. const slots = node.children.length ? buildSlots(node, context, buildSSRSlotFn).slots : `null`;
  31561. if (typeof component !== "string") {
  31562. node.ssrCodegenNode = createCallExpression(
  31563. context.helper(SSR_RENDER_VNODE),
  31564. [
  31565. `_push`,
  31566. createCallExpression(context.helper(CREATE_VNODE), [
  31567. component,
  31568. propsExp,
  31569. slots
  31570. ]),
  31571. `_parent`
  31572. ]
  31573. );
  31574. } else {
  31575. node.ssrCodegenNode = createCallExpression(
  31576. context.helper(SSR_RENDER_COMPONENT),
  31577. [component, propsExp, slots, `_parent`]
  31578. );
  31579. }
  31580. };
  31581. };
  31582. function ssrProcessComponent(node, context, parent) {
  31583. const component = componentTypeMap.get(node);
  31584. if (!node.ssrCodegenNode) {
  31585. if (component === TELEPORT) {
  31586. return ssrProcessTeleport(node, context);
  31587. } else if (component === SUSPENSE) {
  31588. return ssrProcessSuspense(node, context);
  31589. } else if (component === TRANSITION_GROUP) {
  31590. return ssrProcessTransitionGroup(node, context);
  31591. } else {
  31592. if (parent.type === WIP_SLOT) {
  31593. context.pushStringPart(``);
  31594. }
  31595. if (component === TRANSITION) {
  31596. return ssrProcessTransition(node, context);
  31597. }
  31598. processChildren(node, context);
  31599. }
  31600. } else {
  31601. const wipEntries = wipMap.get(node) || [];
  31602. for (let i = 0; i < wipEntries.length; i++) {
  31603. const { fn, vnodeBranch } = wipEntries[i];
  31604. fn.body = createIfStatement(
  31605. createSimpleExpression(`_push`, false),
  31606. processChildrenAsStatement(
  31607. wipEntries[i],
  31608. context,
  31609. false,
  31610. true
  31611. /* withSlotScopeId */
  31612. ),
  31613. vnodeBranch
  31614. );
  31615. }
  31616. if (context.withSlotScopeId) {
  31617. node.ssrCodegenNode.arguments.push(`_scopeId`);
  31618. }
  31619. if (typeof component === "string") {
  31620. context.pushStatement(
  31621. createCallExpression(`_push`, [node.ssrCodegenNode])
  31622. );
  31623. } else {
  31624. context.pushStatement(node.ssrCodegenNode);
  31625. }
  31626. }
  31627. }
  31628. const rawOptionsMap = /* @__PURE__ */ new WeakMap();
  31629. const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(true);
  31630. const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms];
  31631. const vnodeDirectiveTransforms = __spreadValues$8(__spreadValues$8({}, baseDirectiveTransforms), DOMDirectiveTransforms);
  31632. function createVNodeSlotBranch(props, vForExp, children, parentContext) {
  31633. const rawOptions = rawOptionsMap.get(parentContext.root);
  31634. const subOptions = __spreadProps$8(__spreadValues$8({}, rawOptions), {
  31635. // overwrite with vnode-based transforms
  31636. nodeTransforms: [
  31637. ...vnodeNodeTransforms,
  31638. ...rawOptions.nodeTransforms || []
  31639. ],
  31640. directiveTransforms: __spreadValues$8(__spreadValues$8({}, vnodeDirectiveTransforms), rawOptions.directiveTransforms || {})
  31641. });
  31642. const wrapperNode = {
  31643. type: 1,
  31644. ns: 0,
  31645. tag: "template",
  31646. tagType: 3,
  31647. isSelfClosing: false,
  31648. // important: provide v-slot="props" and v-for="exp" on the wrapper for
  31649. // proper scope analysis
  31650. props: [
  31651. {
  31652. type: 7,
  31653. name: "slot",
  31654. exp: props,
  31655. arg: void 0,
  31656. modifiers: [],
  31657. loc: locStub
  31658. },
  31659. {
  31660. type: 7,
  31661. name: "for",
  31662. exp: vForExp,
  31663. arg: void 0,
  31664. modifiers: [],
  31665. loc: locStub
  31666. }
  31667. ],
  31668. children,
  31669. loc: locStub,
  31670. codegenNode: void 0
  31671. };
  31672. subTransform(wrapperNode, subOptions, parentContext);
  31673. return createReturnStatement(children);
  31674. }
  31675. function subTransform(node, options, parentContext) {
  31676. const childRoot = createRoot([node]);
  31677. const childContext = createTransformContext(childRoot, options);
  31678. childContext.ssr = false;
  31679. childContext.scopes = __spreadValues$8({}, parentContext.scopes);
  31680. childContext.identifiers = __spreadValues$8({}, parentContext.identifiers);
  31681. childContext.imports = parentContext.imports;
  31682. traverseNode(childRoot, childContext);
  31683. ["helpers", "components", "directives"].forEach((key) => {
  31684. childContext[key].forEach((value, helperKey) => {
  31685. if (key === "helpers") {
  31686. const parentCount = parentContext.helpers.get(helperKey);
  31687. if (parentCount === void 0) {
  31688. parentContext.helpers.set(helperKey, value);
  31689. } else {
  31690. parentContext.helpers.set(helperKey, value + parentCount);
  31691. }
  31692. } else {
  31693. parentContext[key].add(value);
  31694. }
  31695. });
  31696. });
  31697. }
  31698. function clone(v) {
  31699. if (isArray$3(v)) {
  31700. return v.map(clone);
  31701. } else if (isObject$2(v)) {
  31702. const res = {};
  31703. for (const key in v) {
  31704. res[key] = clone(v[key]);
  31705. }
  31706. return res;
  31707. } else {
  31708. return v;
  31709. }
  31710. }
  31711. function ssrCodegenTransform(ast, options) {
  31712. const context = createSSRTransformContext(ast, options);
  31713. if (options.ssrCssVars) {
  31714. const cssContext = createTransformContext(createRoot([]), options);
  31715. const varsExp = processExpression(
  31716. createSimpleExpression(options.ssrCssVars, false),
  31717. cssContext
  31718. );
  31719. context.body.push(
  31720. createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
  31721. );
  31722. Array.from(cssContext.helpers.keys()).forEach((helper) => {
  31723. ast.helpers.add(helper);
  31724. });
  31725. }
  31726. const isFragment = ast.children.length > 1 && ast.children.some((c) => !isText$1(c));
  31727. processChildren(ast, context, isFragment);
  31728. ast.codegenNode = createBlockStatement(context.body);
  31729. ast.ssrHelpers = Array.from(
  31730. /* @__PURE__ */ new Set([
  31731. ...Array.from(ast.helpers).filter((h) => h in ssrHelpers),
  31732. ...context.helpers
  31733. ])
  31734. );
  31735. ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
  31736. }
  31737. function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new Set(), withSlotScopeId = false) {
  31738. const body = [];
  31739. let currentString = null;
  31740. return {
  31741. root,
  31742. options,
  31743. body,
  31744. helpers,
  31745. withSlotScopeId,
  31746. onError: options.onError || ((e) => {
  31747. throw e;
  31748. }),
  31749. helper(name) {
  31750. helpers.add(name);
  31751. return name;
  31752. },
  31753. pushStringPart(part) {
  31754. if (!currentString) {
  31755. const currentCall = createCallExpression(`_push`);
  31756. body.push(currentCall);
  31757. currentString = createTemplateLiteral([]);
  31758. currentCall.arguments.push(currentString);
  31759. }
  31760. const bufferedElements = currentString.elements;
  31761. const lastItem = bufferedElements[bufferedElements.length - 1];
  31762. if (isString$2(part) && isString$2(lastItem)) {
  31763. bufferedElements[bufferedElements.length - 1] += part;
  31764. } else {
  31765. bufferedElements.push(part);
  31766. }
  31767. },
  31768. pushStatement(statement) {
  31769. currentString = null;
  31770. body.push(statement);
  31771. }
  31772. };
  31773. }
  31774. function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
  31775. return createSSRTransformContext(
  31776. parent.root,
  31777. parent.options,
  31778. parent.helpers,
  31779. withSlotScopeId
  31780. );
  31781. }
  31782. function processChildren(parent, context, asFragment = false, disableNestedFragments = false) {
  31783. if (asFragment) {
  31784. context.pushStringPart(`<!--[-->`);
  31785. }
  31786. const { children } = parent;
  31787. for (let i = 0; i < children.length; i++) {
  31788. const child = children[i];
  31789. switch (child.type) {
  31790. case 1:
  31791. switch (child.tagType) {
  31792. case 0:
  31793. ssrProcessElement(child, context);
  31794. break;
  31795. case 1:
  31796. ssrProcessComponent(child, context, parent);
  31797. break;
  31798. case 2:
  31799. ssrProcessSlotOutlet(child, context);
  31800. break;
  31801. case 3:
  31802. break;
  31803. default:
  31804. context.onError(
  31805. createSSRCompilerError(
  31806. 67,
  31807. child.loc
  31808. )
  31809. );
  31810. const exhaustiveCheck2 = child;
  31811. return exhaustiveCheck2;
  31812. }
  31813. break;
  31814. case 2:
  31815. context.pushStringPart(escapeHtml(child.content));
  31816. break;
  31817. case 3:
  31818. context.pushStringPart(`<!--${child.content}-->`);
  31819. break;
  31820. case 5:
  31821. context.pushStringPart(
  31822. createCallExpression(context.helper(SSR_INTERPOLATE), [child.content])
  31823. );
  31824. break;
  31825. case 9:
  31826. ssrProcessIf(child, context, disableNestedFragments);
  31827. break;
  31828. case 11:
  31829. ssrProcessFor(child, context, disableNestedFragments);
  31830. break;
  31831. case 10:
  31832. break;
  31833. case 12:
  31834. case 8:
  31835. break;
  31836. default:
  31837. context.onError(
  31838. createSSRCompilerError(
  31839. 67,
  31840. child.loc
  31841. )
  31842. );
  31843. const exhaustiveCheck = child;
  31844. return exhaustiveCheck;
  31845. }
  31846. }
  31847. if (asFragment) {
  31848. context.pushStringPart(`<!--]-->`);
  31849. }
  31850. }
  31851. function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
  31852. const childContext = createChildContext(parentContext, withSlotScopeId);
  31853. processChildren(parent, childContext, asFragment);
  31854. return createBlockStatement(childContext.body);
  31855. }
  31856. const ssrTransformModel = (dir, node, context) => {
  31857. const model = dir.exp;
  31858. function checkDuplicatedValue() {
  31859. const value = findProp(node, "value");
  31860. if (value) {
  31861. context.onError(
  31862. createDOMCompilerError(
  31863. 60,
  31864. value.loc
  31865. )
  31866. );
  31867. }
  31868. }
  31869. function processOption(plainNode) {
  31870. if (plainNode.tag === "option") {
  31871. if (plainNode.props.findIndex((p) => p.name === "selected") === -1) {
  31872. const value = findValueBinding(plainNode);
  31873. plainNode.ssrCodegenNode.elements.push(
  31874. createConditionalExpression(
  31875. createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [
  31876. createConditionalExpression(
  31877. createCallExpression(`Array.isArray`, [model]),
  31878. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  31879. model,
  31880. value
  31881. ]),
  31882. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31883. model,
  31884. value
  31885. ])
  31886. )
  31887. ]),
  31888. createSimpleExpression(" selected", true),
  31889. createSimpleExpression("", true),
  31890. false
  31891. /* no newline */
  31892. )
  31893. );
  31894. }
  31895. } else if (plainNode.tag === "optgroup") {
  31896. plainNode.children.forEach(
  31897. (option) => processOption(option)
  31898. );
  31899. }
  31900. }
  31901. if (node.tagType === 0) {
  31902. const res = { props: [] };
  31903. const defaultProps = [
  31904. // default value binding for text type inputs
  31905. createObjectProperty(`value`, model)
  31906. ];
  31907. if (node.tag === "input") {
  31908. const type = findProp(node, "type");
  31909. if (type) {
  31910. const value = findValueBinding(node);
  31911. if (type.type === 7) {
  31912. res.ssrTagParts = [
  31913. createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
  31914. type.exp,
  31915. model,
  31916. value
  31917. ])
  31918. ];
  31919. } else if (type.value) {
  31920. switch (type.value.content) {
  31921. case "radio":
  31922. res.props = [
  31923. createObjectProperty(
  31924. `checked`,
  31925. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31926. model,
  31927. value
  31928. ])
  31929. )
  31930. ];
  31931. break;
  31932. case "checkbox":
  31933. const trueValueBinding = findProp(node, "true-value");
  31934. if (trueValueBinding) {
  31935. const trueValue = trueValueBinding.type === 6 ? JSON.stringify(trueValueBinding.value.content) : trueValueBinding.exp;
  31936. res.props = [
  31937. createObjectProperty(
  31938. `checked`,
  31939. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31940. model,
  31941. trueValue
  31942. ])
  31943. )
  31944. ];
  31945. } else {
  31946. res.props = [
  31947. createObjectProperty(
  31948. `checked`,
  31949. createConditionalExpression(
  31950. createCallExpression(`Array.isArray`, [model]),
  31951. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  31952. model,
  31953. value
  31954. ]),
  31955. model
  31956. )
  31957. )
  31958. ];
  31959. }
  31960. break;
  31961. case "file":
  31962. context.onError(
  31963. createDOMCompilerError(
  31964. 59,
  31965. dir.loc
  31966. )
  31967. );
  31968. break;
  31969. default:
  31970. checkDuplicatedValue();
  31971. res.props = defaultProps;
  31972. break;
  31973. }
  31974. }
  31975. } else if (hasDynamicKeyVBind(node)) ; else {
  31976. checkDuplicatedValue();
  31977. res.props = defaultProps;
  31978. }
  31979. } else if (node.tag === "textarea") {
  31980. checkDuplicatedValue();
  31981. node.children = [createInterpolation(model, model.loc)];
  31982. } else if (node.tag === "select") {
  31983. node.children.forEach((child) => {
  31984. if (child.type === 1) {
  31985. processOption(child);
  31986. }
  31987. });
  31988. } else {
  31989. context.onError(
  31990. createDOMCompilerError(
  31991. 57,
  31992. dir.loc
  31993. )
  31994. );
  31995. }
  31996. return res;
  31997. } else {
  31998. return transformModel$1(dir, node, context);
  31999. }
  32000. };
  32001. function findValueBinding(node) {
  32002. const valueBinding = findProp(node, "value");
  32003. return valueBinding ? valueBinding.type === 7 ? valueBinding.exp : createSimpleExpression(valueBinding.value.content, true) : createSimpleExpression(`null`, false);
  32004. }
  32005. const ssrTransformShow = (dir, node, context) => {
  32006. if (!dir.exp) {
  32007. context.onError(
  32008. createDOMCompilerError(61)
  32009. );
  32010. }
  32011. return {
  32012. props: [
  32013. createObjectProperty(
  32014. `style`,
  32015. createConditionalExpression(
  32016. dir.exp,
  32017. createSimpleExpression(`null`, false),
  32018. createObjectExpression([
  32019. createObjectProperty(
  32020. `display`,
  32021. createSimpleExpression(`none`, true)
  32022. )
  32023. ]),
  32024. false
  32025. /* no newline */
  32026. )
  32027. )
  32028. ]
  32029. };
  32030. };
  32031. const filterChild = (node) => node.children.filter((n) => n.type !== 3);
  32032. const hasSingleChild = (node) => filterChild(node).length === 1;
  32033. const ssrInjectFallthroughAttrs = (node, context) => {
  32034. if (node.type === 0) {
  32035. context.identifiers._attrs = 1;
  32036. }
  32037. if (node.type === 1 && node.tagType === 1 && (isBuiltInType(node.tag, "Transition") || isBuiltInType(node.tag, "KeepAlive"))) {
  32038. const rootChildren = filterChild(context.root);
  32039. if (rootChildren.length === 1 && rootChildren[0] === node) {
  32040. if (hasSingleChild(node)) {
  32041. injectFallthroughAttrs(node.children[0]);
  32042. }
  32043. return;
  32044. }
  32045. }
  32046. const parent = context.parent;
  32047. if (!parent || parent.type !== 0) {
  32048. return;
  32049. }
  32050. if (node.type === 10 && hasSingleChild(node)) {
  32051. let hasEncounteredIf = false;
  32052. for (const c of filterChild(parent)) {
  32053. if (c.type === 9 || c.type === 1 && findDir(c, "if")) {
  32054. if (hasEncounteredIf)
  32055. return;
  32056. hasEncounteredIf = true;
  32057. } else if (
  32058. // node before v-if
  32059. !hasEncounteredIf || // non else nodes
  32060. !(c.type === 1 && findDir(c, /else/, true))
  32061. ) {
  32062. return;
  32063. }
  32064. }
  32065. injectFallthroughAttrs(node.children[0]);
  32066. } else if (hasSingleChild(parent)) {
  32067. injectFallthroughAttrs(node);
  32068. }
  32069. };
  32070. function injectFallthroughAttrs(node) {
  32071. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32072. node.props.push({
  32073. type: 7,
  32074. name: "bind",
  32075. arg: void 0,
  32076. exp: createSimpleExpression(`_attrs`, false),
  32077. modifiers: [],
  32078. loc: locStub
  32079. });
  32080. }
  32081. }
  32082. const ssrInjectCssVars = (node, context) => {
  32083. if (!context.ssrCssVars) {
  32084. return;
  32085. }
  32086. if (node.type === 0) {
  32087. context.identifiers._cssVars = 1;
  32088. }
  32089. const parent = context.parent;
  32090. if (!parent || parent.type !== 0) {
  32091. return;
  32092. }
  32093. if (node.type === 10) {
  32094. for (const child of node.children) {
  32095. injectCssVars(child);
  32096. }
  32097. } else {
  32098. injectCssVars(node);
  32099. }
  32100. };
  32101. function injectCssVars(node) {
  32102. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32103. if (isBuiltInType(node.tag, "Suspense")) {
  32104. for (const child of node.children) {
  32105. if (child.type === 1 && child.tagType === 3) {
  32106. child.children.forEach(injectCssVars);
  32107. } else {
  32108. injectCssVars(child);
  32109. }
  32110. }
  32111. } else {
  32112. node.props.push({
  32113. type: 7,
  32114. name: "bind",
  32115. arg: void 0,
  32116. exp: createSimpleExpression(`_cssVars`, false),
  32117. modifiers: [],
  32118. loc: locStub
  32119. });
  32120. }
  32121. }
  32122. }
  32123. var __defProp$7 = Object.defineProperty;
  32124. var __defProps$7 = Object.defineProperties;
  32125. var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
  32126. var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
  32127. var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
  32128. var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
  32129. var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32130. var __spreadValues$7 = (a, b) => {
  32131. for (var prop in b || (b = {}))
  32132. if (__hasOwnProp$7.call(b, prop))
  32133. __defNormalProp$7(a, prop, b[prop]);
  32134. if (__getOwnPropSymbols$7)
  32135. for (var prop of __getOwnPropSymbols$7(b)) {
  32136. if (__propIsEnum$7.call(b, prop))
  32137. __defNormalProp$7(a, prop, b[prop]);
  32138. }
  32139. return a;
  32140. };
  32141. var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
  32142. function compile(template, options = {}) {
  32143. options = __spreadProps$7(__spreadValues$7(__spreadValues$7({}, options), parserOptions), {
  32144. ssr: true,
  32145. inSSR: true,
  32146. scopeId: options.mode === "function" ? null : options.scopeId,
  32147. // always prefix since compiler-ssr doesn't have size concern
  32148. prefixIdentifiers: true,
  32149. // disable optimizations that are unnecessary for ssr
  32150. cacheHandlers: false,
  32151. hoistStatic: false
  32152. });
  32153. const ast = baseParse(template, options);
  32154. rawOptionsMap.set(ast, options);
  32155. transform$1(ast, __spreadProps$7(__spreadValues$7({}, options), {
  32156. hoistStatic: false,
  32157. nodeTransforms: [
  32158. ssrTransformIf,
  32159. ssrTransformFor,
  32160. trackVForSlotScopes,
  32161. transformExpression,
  32162. ssrTransformSlotOutlet,
  32163. ssrInjectFallthroughAttrs,
  32164. ssrInjectCssVars,
  32165. ssrTransformElement,
  32166. ssrTransformComponent,
  32167. trackSlotScopes,
  32168. transformStyle,
  32169. ...options.nodeTransforms || []
  32170. // user transforms
  32171. ],
  32172. directiveTransforms: __spreadValues$7({
  32173. // reusing core v-bind
  32174. bind: transformBind,
  32175. on: transformOn$1,
  32176. // model and show have dedicated SSR handling
  32177. model: ssrTransformModel,
  32178. show: ssrTransformShow,
  32179. // the following are ignored during SSR
  32180. // on: noopDirectiveTransform,
  32181. cloak: noopDirectiveTransform,
  32182. once: noopDirectiveTransform,
  32183. memo: noopDirectiveTransform
  32184. }, options.directiveTransforms || {})
  32185. }));
  32186. ssrCodegenTransform(ast, options);
  32187. return generate(ast, options);
  32188. }
  32189. var CompilerSSR = /*#__PURE__*/Object.freeze({
  32190. __proto__: null,
  32191. compile: compile
  32192. });
  32193. var _polyfillNode_fs = {};
  32194. var _polyfillNode_fs$1 = /*#__PURE__*/Object.freeze({
  32195. __proto__: null,
  32196. default: _polyfillNode_fs
  32197. });
  32198. var require$$0$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
  32199. var require$$2$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_path);
  32200. var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_util$1);
  32201. const hasWarned$1 = {};
  32202. function warnOnce$4(msg) {
  32203. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  32204. if (!isNodeProd && true && !hasWarned$1[msg]) {
  32205. hasWarned$1[msg] = true;
  32206. warn$1(msg);
  32207. }
  32208. }
  32209. function warn$1(msg) {
  32210. console.warn(
  32211. `\x1B[1m\x1B[33m[@vue/compiler-sfc]\x1B[0m\x1B[33m ${msg}\x1B[0m
  32212. `
  32213. );
  32214. }
  32215. var __defProp$6 = Object.defineProperty;
  32216. var __defProps$6 = Object.defineProperties;
  32217. var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
  32218. var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
  32219. var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
  32220. var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
  32221. var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32222. var __spreadValues$6 = (a, b) => {
  32223. for (var prop in b || (b = {}))
  32224. if (__hasOwnProp$6.call(b, prop))
  32225. __defNormalProp$6(a, prop, b[prop]);
  32226. if (__getOwnPropSymbols$6)
  32227. for (var prop of __getOwnPropSymbols$6(b)) {
  32228. if (__propIsEnum$6.call(b, prop))
  32229. __defNormalProp$6(a, prop, b[prop]);
  32230. }
  32231. return a;
  32232. };
  32233. var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
  32234. function preprocess$1({ source, filename, preprocessOptions }, preprocessor) {
  32235. let res = "";
  32236. let err = null;
  32237. preprocessor.render(
  32238. source,
  32239. __spreadValues$6({ filename }, preprocessOptions),
  32240. (_err, _res) => {
  32241. if (_err)
  32242. err = _err;
  32243. res = _res;
  32244. }
  32245. );
  32246. if (err)
  32247. throw err;
  32248. return res;
  32249. }
  32250. function compileTemplate(options) {
  32251. const { preprocessLang, preprocessCustomRequire } = options;
  32252. if (preprocessLang && !preprocessCustomRequire) {
  32253. throw new Error(
  32254. `[@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 }.`
  32255. );
  32256. }
  32257. const preprocessor = preprocessLang ? preprocessCustomRequire ? preprocessCustomRequire(preprocessLang) : void 0 : false;
  32258. if (preprocessor) {
  32259. try {
  32260. return doCompileTemplate(__spreadProps$6(__spreadValues$6({}, options), {
  32261. source: preprocess$1(options, preprocessor)
  32262. }));
  32263. } catch (e) {
  32264. return {
  32265. code: `export default function render() {}`,
  32266. source: options.source,
  32267. tips: [],
  32268. errors: [e]
  32269. };
  32270. }
  32271. } else if (preprocessLang) {
  32272. return {
  32273. code: `export default function render() {}`,
  32274. source: options.source,
  32275. tips: [
  32276. `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
  32277. ],
  32278. errors: [
  32279. `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
  32280. ]
  32281. };
  32282. } else {
  32283. return doCompileTemplate(options);
  32284. }
  32285. }
  32286. function doCompileTemplate({
  32287. filename,
  32288. id,
  32289. scoped,
  32290. slotted,
  32291. inMap,
  32292. source,
  32293. ssr = false,
  32294. ssrCssVars,
  32295. isProd = false,
  32296. compiler = ssr ? CompilerSSR : CompilerDOM,
  32297. compilerOptions = {},
  32298. transformAssetUrls
  32299. }) {
  32300. const errors = [];
  32301. const warnings = [];
  32302. let nodeTransforms = [];
  32303. if (isObject$2(transformAssetUrls)) {
  32304. const assetOptions = normalizeOptions(transformAssetUrls);
  32305. nodeTransforms = [
  32306. createAssetUrlTransformWithOptions(assetOptions),
  32307. createSrcsetTransformWithOptions(assetOptions)
  32308. ];
  32309. } else if (transformAssetUrls !== false) {
  32310. nodeTransforms = [transformAssetUrl, transformSrcset];
  32311. }
  32312. if (ssr && !ssrCssVars) {
  32313. warnOnce$4(
  32314. `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.\`.`
  32315. );
  32316. }
  32317. if (!id) {
  32318. warnOnce$4(`compileTemplate now requires the \`id\` option.\`.`);
  32319. id = "";
  32320. }
  32321. const shortId = id.replace(/^data-v-/, "");
  32322. const longId = `data-v-${shortId}`;
  32323. let { code, ast, preamble, map } = compiler.compile(source, __spreadProps$6(__spreadValues$6({
  32324. mode: "module",
  32325. prefixIdentifiers: true,
  32326. hoistStatic: true,
  32327. cacheHandlers: true,
  32328. ssrCssVars: ssr && ssrCssVars && ssrCssVars.length ? genCssVarsFromList(ssrCssVars, shortId, isProd, true) : "",
  32329. scopeId: scoped ? longId : void 0,
  32330. slotted,
  32331. sourceMap: true
  32332. }, compilerOptions), {
  32333. hmr: !isProd,
  32334. nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
  32335. filename,
  32336. onError: (e) => errors.push(e),
  32337. onWarn: (w) => warnings.push(w)
  32338. }));
  32339. if (inMap) {
  32340. if (map) {
  32341. map = mapLines(inMap, map);
  32342. }
  32343. if (errors.length) {
  32344. patchErrors(errors, source, inMap);
  32345. }
  32346. }
  32347. const tips = warnings.map((w) => {
  32348. let msg = w.message;
  32349. if (w.loc) {
  32350. msg += `
  32351. ${generateCodeFrame(
  32352. source,
  32353. w.loc.start.offset,
  32354. w.loc.end.offset
  32355. )}`;
  32356. }
  32357. return msg;
  32358. });
  32359. return { code, ast, preamble, source, errors, tips, map };
  32360. }
  32361. function mapLines(oldMap, newMap) {
  32362. if (!oldMap)
  32363. return newMap;
  32364. if (!newMap)
  32365. return oldMap;
  32366. const oldMapConsumer = new SourceMapConsumer$5(oldMap);
  32367. const newMapConsumer = new SourceMapConsumer$5(newMap);
  32368. const mergedMapGenerator = new SourceMapGenerator$6();
  32369. newMapConsumer.eachMapping((m) => {
  32370. if (m.originalLine == null) {
  32371. return;
  32372. }
  32373. const origPosInOldMap = oldMapConsumer.originalPositionFor({
  32374. line: m.originalLine,
  32375. column: m.originalColumn
  32376. });
  32377. if (origPosInOldMap.source == null) {
  32378. return;
  32379. }
  32380. mergedMapGenerator.addMapping({
  32381. generated: {
  32382. line: m.generatedLine,
  32383. column: m.generatedColumn
  32384. },
  32385. original: {
  32386. line: origPosInOldMap.line,
  32387. // map line
  32388. // use current column, since the oldMap produced by @vue/compiler-sfc
  32389. // does not
  32390. column: m.originalColumn
  32391. },
  32392. source: origPosInOldMap.source,
  32393. name: origPosInOldMap.name
  32394. });
  32395. });
  32396. const generator = mergedMapGenerator;
  32397. oldMapConsumer.sources.forEach((sourceFile) => {
  32398. generator._sources.add(sourceFile);
  32399. const sourceContent = oldMapConsumer.sourceContentFor(sourceFile);
  32400. if (sourceContent != null) {
  32401. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  32402. }
  32403. });
  32404. generator._sourceRoot = oldMap.sourceRoot;
  32405. generator._file = oldMap.file;
  32406. return generator.toJSON();
  32407. }
  32408. function patchErrors(errors, source, inMap) {
  32409. const originalSource = inMap.sourcesContent[0];
  32410. const offset = originalSource.indexOf(source);
  32411. const lineOffset = originalSource.slice(0, offset).split(/\r?\n/).length - 1;
  32412. errors.forEach((err) => {
  32413. if (err.loc) {
  32414. err.loc.start.line += lineOffset;
  32415. err.loc.start.offset += offset;
  32416. if (err.loc.end !== err.loc.start) {
  32417. err.loc.end.line += lineOffset;
  32418. err.loc.end.offset += offset;
  32419. }
  32420. }
  32421. });
  32422. }
  32423. var picocolors = {exports: {}};
  32424. // MIT lisence
  32425. // from https://github.com/substack/tty-browserify/blob/1ba769a6429d242f36226538835b4034bf6b7886/index.js
  32426. function isatty() {
  32427. return false;
  32428. }
  32429. function ReadStream() {
  32430. throw new Error('tty.ReadStream is not implemented');
  32431. }
  32432. function WriteStream() {
  32433. throw new Error('tty.ReadStream is not implemented');
  32434. }
  32435. var _polyfillNode_tty = {
  32436. isatty: isatty,
  32437. ReadStream: ReadStream,
  32438. WriteStream: WriteStream
  32439. };
  32440. var _polyfillNode_tty$1 = /*#__PURE__*/Object.freeze({
  32441. __proto__: null,
  32442. ReadStream: ReadStream,
  32443. WriteStream: WriteStream,
  32444. default: _polyfillNode_tty,
  32445. isatty: isatty
  32446. });
  32447. var require$$0 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_tty$1);
  32448. let tty = require$$0;
  32449. let isColorSupported =
  32450. !("NO_COLOR" in ({}) || browser$1.argv.includes("--no-color")) &&
  32451. ("FORCE_COLOR" in ({}) ||
  32452. browser$1.argv.includes("--color") ||
  32453. "" === "win32" ||
  32454. (tty.isatty(1) && browser$1.env.TERM !== "dumb") ||
  32455. "CI" in ({}));
  32456. let formatter =
  32457. (open, close, replace = open) =>
  32458. input => {
  32459. let string = "" + input;
  32460. let index = string.indexOf(close, open.length);
  32461. return ~index
  32462. ? open + replaceClose(string, close, replace, index) + close
  32463. : open + string + close
  32464. };
  32465. let replaceClose = (string, close, replace, index) => {
  32466. let start = string.substring(0, index) + replace;
  32467. let end = string.substring(index + close.length);
  32468. let nextIndex = end.indexOf(close);
  32469. return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
  32470. };
  32471. let createColors = (enabled = isColorSupported) => ({
  32472. isColorSupported: enabled,
  32473. reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
  32474. bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
  32475. dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
  32476. italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
  32477. underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
  32478. inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
  32479. hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
  32480. strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
  32481. black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
  32482. red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
  32483. green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
  32484. yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
  32485. blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
  32486. magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
  32487. cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
  32488. white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
  32489. gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
  32490. bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
  32491. bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
  32492. bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
  32493. bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
  32494. bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
  32495. bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
  32496. bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
  32497. bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
  32498. });
  32499. picocolors.exports = createColors();
  32500. picocolors.exports.createColors = createColors;
  32501. var picocolorsExports = picocolors.exports;
  32502. const SINGLE_QUOTE = "'".charCodeAt(0);
  32503. const DOUBLE_QUOTE = '"'.charCodeAt(0);
  32504. const BACKSLASH = '\\'.charCodeAt(0);
  32505. const SLASH = '/'.charCodeAt(0);
  32506. const NEWLINE = '\n'.charCodeAt(0);
  32507. const SPACE = ' '.charCodeAt(0);
  32508. const FEED = '\f'.charCodeAt(0);
  32509. const TAB = '\t'.charCodeAt(0);
  32510. const CR = '\r'.charCodeAt(0);
  32511. const OPEN_SQUARE = '['.charCodeAt(0);
  32512. const CLOSE_SQUARE = ']'.charCodeAt(0);
  32513. const OPEN_PARENTHESES = '('.charCodeAt(0);
  32514. const CLOSE_PARENTHESES = ')'.charCodeAt(0);
  32515. const OPEN_CURLY = '{'.charCodeAt(0);
  32516. const CLOSE_CURLY = '}'.charCodeAt(0);
  32517. const SEMICOLON = ';'.charCodeAt(0);
  32518. const ASTERISK = '*'.charCodeAt(0);
  32519. const COLON = ':'.charCodeAt(0);
  32520. const AT = '@'.charCodeAt(0);
  32521. const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g;
  32522. const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g;
  32523. const RE_BAD_BRACKET = /.[\r\n"'(/\\]/;
  32524. const RE_HEX_ESCAPE = /[\da-f]/i;
  32525. var tokenize$1 = function tokenizer(input, options = {}) {
  32526. let css = input.css.valueOf();
  32527. let ignore = options.ignoreErrors;
  32528. let code, next, quote, content, escape;
  32529. let escaped, escapePos, prev, n, currentToken;
  32530. let length = css.length;
  32531. let pos = 0;
  32532. let buffer = [];
  32533. let returned = [];
  32534. function position() {
  32535. return pos
  32536. }
  32537. function unclosed(what) {
  32538. throw input.error('Unclosed ' + what, pos)
  32539. }
  32540. function endOfFile() {
  32541. return returned.length === 0 && pos >= length
  32542. }
  32543. function nextToken(opts) {
  32544. if (returned.length) return returned.pop()
  32545. if (pos >= length) return
  32546. let ignoreUnclosed = opts ? opts.ignoreUnclosed : false;
  32547. code = css.charCodeAt(pos);
  32548. switch (code) {
  32549. case NEWLINE:
  32550. case SPACE:
  32551. case TAB:
  32552. case CR:
  32553. case FEED: {
  32554. next = pos;
  32555. do {
  32556. next += 1;
  32557. code = css.charCodeAt(next);
  32558. } while (
  32559. code === SPACE ||
  32560. code === NEWLINE ||
  32561. code === TAB ||
  32562. code === CR ||
  32563. code === FEED
  32564. )
  32565. currentToken = ['space', css.slice(pos, next)];
  32566. pos = next - 1;
  32567. break
  32568. }
  32569. case OPEN_SQUARE:
  32570. case CLOSE_SQUARE:
  32571. case OPEN_CURLY:
  32572. case CLOSE_CURLY:
  32573. case COLON:
  32574. case SEMICOLON:
  32575. case CLOSE_PARENTHESES: {
  32576. let controlChar = String.fromCharCode(code);
  32577. currentToken = [controlChar, controlChar, pos];
  32578. break
  32579. }
  32580. case OPEN_PARENTHESES: {
  32581. prev = buffer.length ? buffer.pop()[1] : '';
  32582. n = css.charCodeAt(pos + 1);
  32583. if (
  32584. prev === 'url' &&
  32585. n !== SINGLE_QUOTE &&
  32586. n !== DOUBLE_QUOTE &&
  32587. n !== SPACE &&
  32588. n !== NEWLINE &&
  32589. n !== TAB &&
  32590. n !== FEED &&
  32591. n !== CR
  32592. ) {
  32593. next = pos;
  32594. do {
  32595. escaped = false;
  32596. next = css.indexOf(')', next + 1);
  32597. if (next === -1) {
  32598. if (ignore || ignoreUnclosed) {
  32599. next = pos;
  32600. break
  32601. } else {
  32602. unclosed('bracket');
  32603. }
  32604. }
  32605. escapePos = next;
  32606. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32607. escapePos -= 1;
  32608. escaped = !escaped;
  32609. }
  32610. } while (escaped)
  32611. currentToken = ['brackets', css.slice(pos, next + 1), pos, next];
  32612. pos = next;
  32613. } else {
  32614. next = css.indexOf(')', pos + 1);
  32615. content = css.slice(pos, next + 1);
  32616. if (next === -1 || RE_BAD_BRACKET.test(content)) {
  32617. currentToken = ['(', '(', pos];
  32618. } else {
  32619. currentToken = ['brackets', content, pos, next];
  32620. pos = next;
  32621. }
  32622. }
  32623. break
  32624. }
  32625. case SINGLE_QUOTE:
  32626. case DOUBLE_QUOTE: {
  32627. quote = code === SINGLE_QUOTE ? "'" : '"';
  32628. next = pos;
  32629. do {
  32630. escaped = false;
  32631. next = css.indexOf(quote, next + 1);
  32632. if (next === -1) {
  32633. if (ignore || ignoreUnclosed) {
  32634. next = pos + 1;
  32635. break
  32636. } else {
  32637. unclosed('string');
  32638. }
  32639. }
  32640. escapePos = next;
  32641. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32642. escapePos -= 1;
  32643. escaped = !escaped;
  32644. }
  32645. } while (escaped)
  32646. currentToken = ['string', css.slice(pos, next + 1), pos, next];
  32647. pos = next;
  32648. break
  32649. }
  32650. case AT: {
  32651. RE_AT_END.lastIndex = pos + 1;
  32652. RE_AT_END.test(css);
  32653. if (RE_AT_END.lastIndex === 0) {
  32654. next = css.length - 1;
  32655. } else {
  32656. next = RE_AT_END.lastIndex - 2;
  32657. }
  32658. currentToken = ['at-word', css.slice(pos, next + 1), pos, next];
  32659. pos = next;
  32660. break
  32661. }
  32662. case BACKSLASH: {
  32663. next = pos;
  32664. escape = true;
  32665. while (css.charCodeAt(next + 1) === BACKSLASH) {
  32666. next += 1;
  32667. escape = !escape;
  32668. }
  32669. code = css.charCodeAt(next + 1);
  32670. if (
  32671. escape &&
  32672. code !== SLASH &&
  32673. code !== SPACE &&
  32674. code !== NEWLINE &&
  32675. code !== TAB &&
  32676. code !== CR &&
  32677. code !== FEED
  32678. ) {
  32679. next += 1;
  32680. if (RE_HEX_ESCAPE.test(css.charAt(next))) {
  32681. while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
  32682. next += 1;
  32683. }
  32684. if (css.charCodeAt(next + 1) === SPACE) {
  32685. next += 1;
  32686. }
  32687. }
  32688. }
  32689. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32690. pos = next;
  32691. break
  32692. }
  32693. default: {
  32694. if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
  32695. next = css.indexOf('*/', pos + 2) + 1;
  32696. if (next === 0) {
  32697. if (ignore || ignoreUnclosed) {
  32698. next = css.length;
  32699. } else {
  32700. unclosed('comment');
  32701. }
  32702. }
  32703. currentToken = ['comment', css.slice(pos, next + 1), pos, next];
  32704. pos = next;
  32705. } else {
  32706. RE_WORD_END.lastIndex = pos + 1;
  32707. RE_WORD_END.test(css);
  32708. if (RE_WORD_END.lastIndex === 0) {
  32709. next = css.length - 1;
  32710. } else {
  32711. next = RE_WORD_END.lastIndex - 2;
  32712. }
  32713. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32714. buffer.push(currentToken);
  32715. pos = next;
  32716. }
  32717. break
  32718. }
  32719. }
  32720. pos++;
  32721. return currentToken
  32722. }
  32723. function back(token) {
  32724. returned.push(token);
  32725. }
  32726. return {
  32727. back,
  32728. endOfFile,
  32729. nextToken,
  32730. position
  32731. }
  32732. };
  32733. let pico$1 = picocolorsExports;
  32734. let tokenizer$1 = tokenize$1;
  32735. let Input$5;
  32736. function registerInput(dependant) {
  32737. Input$5 = dependant;
  32738. }
  32739. const HIGHLIGHT_THEME = {
  32740. ';': pico$1.yellow,
  32741. ':': pico$1.yellow,
  32742. '(': pico$1.cyan,
  32743. ')': pico$1.cyan,
  32744. '[': pico$1.yellow,
  32745. ']': pico$1.yellow,
  32746. '{': pico$1.yellow,
  32747. '}': pico$1.yellow,
  32748. 'at-word': pico$1.cyan,
  32749. 'brackets': pico$1.cyan,
  32750. 'call': pico$1.cyan,
  32751. 'class': pico$1.yellow,
  32752. 'comment': pico$1.gray,
  32753. 'hash': pico$1.magenta,
  32754. 'string': pico$1.green
  32755. };
  32756. function getTokenType([type, value], processor) {
  32757. if (type === 'word') {
  32758. if (value[0] === '.') {
  32759. return 'class'
  32760. }
  32761. if (value[0] === '#') {
  32762. return 'hash'
  32763. }
  32764. }
  32765. if (!processor.endOfFile()) {
  32766. let next = processor.nextToken();
  32767. processor.back(next);
  32768. if (next[0] === 'brackets' || next[0] === '(') return 'call'
  32769. }
  32770. return type
  32771. }
  32772. function terminalHighlight$2(css) {
  32773. let processor = tokenizer$1(new Input$5(css), { ignoreErrors: true });
  32774. let result = '';
  32775. while (!processor.endOfFile()) {
  32776. let token = processor.nextToken();
  32777. let color = HIGHLIGHT_THEME[getTokenType(token, processor)];
  32778. if (color) {
  32779. result += token[1]
  32780. .split(/\r?\n/)
  32781. .map(i => color(i))
  32782. .join('\n');
  32783. } else {
  32784. result += token[1];
  32785. }
  32786. }
  32787. return result
  32788. }
  32789. terminalHighlight$2.registerInput = registerInput;
  32790. var terminalHighlight_1 = terminalHighlight$2;
  32791. let pico = picocolorsExports;
  32792. let terminalHighlight$1 = terminalHighlight_1;
  32793. let CssSyntaxError$3 = class CssSyntaxError extends Error {
  32794. constructor(message, line, column, source, file, plugin) {
  32795. super(message);
  32796. this.name = 'CssSyntaxError';
  32797. this.reason = message;
  32798. if (file) {
  32799. this.file = file;
  32800. }
  32801. if (source) {
  32802. this.source = source;
  32803. }
  32804. if (plugin) {
  32805. this.plugin = plugin;
  32806. }
  32807. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  32808. if (typeof line === 'number') {
  32809. this.line = line;
  32810. this.column = column;
  32811. } else {
  32812. this.line = line.line;
  32813. this.column = line.column;
  32814. this.endLine = column.line;
  32815. this.endColumn = column.column;
  32816. }
  32817. }
  32818. this.setMessage();
  32819. if (Error.captureStackTrace) {
  32820. Error.captureStackTrace(this, CssSyntaxError);
  32821. }
  32822. }
  32823. setMessage() {
  32824. this.message = this.plugin ? this.plugin + ': ' : '';
  32825. this.message += this.file ? this.file : '<css input>';
  32826. if (typeof this.line !== 'undefined') {
  32827. this.message += ':' + this.line + ':' + this.column;
  32828. }
  32829. this.message += ': ' + this.reason;
  32830. }
  32831. showSourceCode(color) {
  32832. if (!this.source) return ''
  32833. let css = this.source;
  32834. if (color == null) color = pico.isColorSupported;
  32835. if (terminalHighlight$1) {
  32836. if (color) css = terminalHighlight$1(css);
  32837. }
  32838. let lines = css.split(/\r?\n/);
  32839. let start = Math.max(this.line - 3, 0);
  32840. let end = Math.min(this.line + 2, lines.length);
  32841. let maxWidth = String(end).length;
  32842. let mark, aside;
  32843. if (color) {
  32844. let { bold, gray, red } = pico.createColors(true);
  32845. mark = text => bold(red(text));
  32846. aside = text => gray(text);
  32847. } else {
  32848. mark = aside = str => str;
  32849. }
  32850. return lines
  32851. .slice(start, end)
  32852. .map((line, index) => {
  32853. let number = start + 1 + index;
  32854. let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  32855. if (number === this.line) {
  32856. let spacing =
  32857. aside(gutter.replace(/\d/g, ' ')) +
  32858. line.slice(0, this.column - 1).replace(/[^\t]/g, ' ');
  32859. return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^')
  32860. }
  32861. return ' ' + aside(gutter) + line
  32862. })
  32863. .join('\n')
  32864. }
  32865. toString() {
  32866. let code = this.showSourceCode();
  32867. if (code) {
  32868. code = '\n\n' + code + '\n';
  32869. }
  32870. return this.name + ': ' + this.message + code
  32871. }
  32872. };
  32873. var cssSyntaxError = CssSyntaxError$3;
  32874. CssSyntaxError$3.default = CssSyntaxError$3;
  32875. var symbols = {};
  32876. symbols.isClean = Symbol('isClean');
  32877. symbols.my = Symbol('my');
  32878. const DEFAULT_RAW = {
  32879. after: '\n',
  32880. beforeClose: '\n',
  32881. beforeComment: '\n',
  32882. beforeDecl: '\n',
  32883. beforeOpen: ' ',
  32884. beforeRule: '\n',
  32885. colon: ': ',
  32886. commentLeft: ' ',
  32887. commentRight: ' ',
  32888. emptyBody: '',
  32889. indent: ' ',
  32890. semicolon: false
  32891. };
  32892. function capitalize(str) {
  32893. return str[0].toUpperCase() + str.slice(1)
  32894. }
  32895. let Stringifier$2 = class Stringifier {
  32896. constructor(builder) {
  32897. this.builder = builder;
  32898. }
  32899. atrule(node, semicolon) {
  32900. let name = '@' + node.name;
  32901. let params = node.params ? this.rawValue(node, 'params') : '';
  32902. if (typeof node.raws.afterName !== 'undefined') {
  32903. name += node.raws.afterName;
  32904. } else if (params) {
  32905. name += ' ';
  32906. }
  32907. if (node.nodes) {
  32908. this.block(node, name + params);
  32909. } else {
  32910. let end = (node.raws.between || '') + (semicolon ? ';' : '');
  32911. this.builder(name + params + end, node);
  32912. }
  32913. }
  32914. beforeAfter(node, detect) {
  32915. let value;
  32916. if (node.type === 'decl') {
  32917. value = this.raw(node, null, 'beforeDecl');
  32918. } else if (node.type === 'comment') {
  32919. value = this.raw(node, null, 'beforeComment');
  32920. } else if (detect === 'before') {
  32921. value = this.raw(node, null, 'beforeRule');
  32922. } else {
  32923. value = this.raw(node, null, 'beforeClose');
  32924. }
  32925. let buf = node.parent;
  32926. let depth = 0;
  32927. while (buf && buf.type !== 'root') {
  32928. depth += 1;
  32929. buf = buf.parent;
  32930. }
  32931. if (value.includes('\n')) {
  32932. let indent = this.raw(node, null, 'indent');
  32933. if (indent.length) {
  32934. for (let step = 0; step < depth; step++) value += indent;
  32935. }
  32936. }
  32937. return value
  32938. }
  32939. block(node, start) {
  32940. let between = this.raw(node, 'between', 'beforeOpen');
  32941. this.builder(start + between + '{', node, 'start');
  32942. let after;
  32943. if (node.nodes && node.nodes.length) {
  32944. this.body(node);
  32945. after = this.raw(node, 'after');
  32946. } else {
  32947. after = this.raw(node, 'after', 'emptyBody');
  32948. }
  32949. if (after) this.builder(after);
  32950. this.builder('}', node, 'end');
  32951. }
  32952. body(node) {
  32953. let last = node.nodes.length - 1;
  32954. while (last > 0) {
  32955. if (node.nodes[last].type !== 'comment') break
  32956. last -= 1;
  32957. }
  32958. let semicolon = this.raw(node, 'semicolon');
  32959. for (let i = 0; i < node.nodes.length; i++) {
  32960. let child = node.nodes[i];
  32961. let before = this.raw(child, 'before');
  32962. if (before) this.builder(before);
  32963. this.stringify(child, last !== i || semicolon);
  32964. }
  32965. }
  32966. comment(node) {
  32967. let left = this.raw(node, 'left', 'commentLeft');
  32968. let right = this.raw(node, 'right', 'commentRight');
  32969. this.builder('/*' + left + node.text + right + '*/', node);
  32970. }
  32971. decl(node, semicolon) {
  32972. let between = this.raw(node, 'between', 'colon');
  32973. let string = node.prop + between + this.rawValue(node, 'value');
  32974. if (node.important) {
  32975. string += node.raws.important || ' !important';
  32976. }
  32977. if (semicolon) string += ';';
  32978. this.builder(string, node);
  32979. }
  32980. document(node) {
  32981. this.body(node);
  32982. }
  32983. raw(node, own, detect) {
  32984. let value;
  32985. if (!detect) detect = own;
  32986. // Already had
  32987. if (own) {
  32988. value = node.raws[own];
  32989. if (typeof value !== 'undefined') return value
  32990. }
  32991. let parent = node.parent;
  32992. if (detect === 'before') {
  32993. // Hack for first rule in CSS
  32994. if (!parent || (parent.type === 'root' && parent.first === node)) {
  32995. return ''
  32996. }
  32997. // `root` nodes in `document` should use only their own raws
  32998. if (parent && parent.type === 'document') {
  32999. return ''
  33000. }
  33001. }
  33002. // Floating child without parent
  33003. if (!parent) return DEFAULT_RAW[detect]
  33004. // Detect style by other nodes
  33005. let root = node.root();
  33006. if (!root.rawCache) root.rawCache = {};
  33007. if (typeof root.rawCache[detect] !== 'undefined') {
  33008. return root.rawCache[detect]
  33009. }
  33010. if (detect === 'before' || detect === 'after') {
  33011. return this.beforeAfter(node, detect)
  33012. } else {
  33013. let method = 'raw' + capitalize(detect);
  33014. if (this[method]) {
  33015. value = this[method](root, node);
  33016. } else {
  33017. root.walk(i => {
  33018. value = i.raws[own];
  33019. if (typeof value !== 'undefined') return false
  33020. });
  33021. }
  33022. }
  33023. if (typeof value === 'undefined') value = DEFAULT_RAW[detect];
  33024. root.rawCache[detect] = value;
  33025. return value
  33026. }
  33027. rawBeforeClose(root) {
  33028. let value;
  33029. root.walk(i => {
  33030. if (i.nodes && i.nodes.length > 0) {
  33031. if (typeof i.raws.after !== 'undefined') {
  33032. value = i.raws.after;
  33033. if (value.includes('\n')) {
  33034. value = value.replace(/[^\n]+$/, '');
  33035. }
  33036. return false
  33037. }
  33038. }
  33039. });
  33040. if (value) value = value.replace(/\S/g, '');
  33041. return value
  33042. }
  33043. rawBeforeComment(root, node) {
  33044. let value;
  33045. root.walkComments(i => {
  33046. if (typeof i.raws.before !== 'undefined') {
  33047. value = i.raws.before;
  33048. if (value.includes('\n')) {
  33049. value = value.replace(/[^\n]+$/, '');
  33050. }
  33051. return false
  33052. }
  33053. });
  33054. if (typeof value === 'undefined') {
  33055. value = this.raw(node, null, 'beforeDecl');
  33056. } else if (value) {
  33057. value = value.replace(/\S/g, '');
  33058. }
  33059. return value
  33060. }
  33061. rawBeforeDecl(root, node) {
  33062. let value;
  33063. root.walkDecls(i => {
  33064. if (typeof i.raws.before !== 'undefined') {
  33065. value = i.raws.before;
  33066. if (value.includes('\n')) {
  33067. value = value.replace(/[^\n]+$/, '');
  33068. }
  33069. return false
  33070. }
  33071. });
  33072. if (typeof value === 'undefined') {
  33073. value = this.raw(node, null, 'beforeRule');
  33074. } else if (value) {
  33075. value = value.replace(/\S/g, '');
  33076. }
  33077. return value
  33078. }
  33079. rawBeforeOpen(root) {
  33080. let value;
  33081. root.walk(i => {
  33082. if (i.type !== 'decl') {
  33083. value = i.raws.between;
  33084. if (typeof value !== 'undefined') return false
  33085. }
  33086. });
  33087. return value
  33088. }
  33089. rawBeforeRule(root) {
  33090. let value;
  33091. root.walk(i => {
  33092. if (i.nodes && (i.parent !== root || root.first !== i)) {
  33093. if (typeof i.raws.before !== 'undefined') {
  33094. value = i.raws.before;
  33095. if (value.includes('\n')) {
  33096. value = value.replace(/[^\n]+$/, '');
  33097. }
  33098. return false
  33099. }
  33100. }
  33101. });
  33102. if (value) value = value.replace(/\S/g, '');
  33103. return value
  33104. }
  33105. rawColon(root) {
  33106. let value;
  33107. root.walkDecls(i => {
  33108. if (typeof i.raws.between !== 'undefined') {
  33109. value = i.raws.between.replace(/[^\s:]/g, '');
  33110. return false
  33111. }
  33112. });
  33113. return value
  33114. }
  33115. rawEmptyBody(root) {
  33116. let value;
  33117. root.walk(i => {
  33118. if (i.nodes && i.nodes.length === 0) {
  33119. value = i.raws.after;
  33120. if (typeof value !== 'undefined') return false
  33121. }
  33122. });
  33123. return value
  33124. }
  33125. rawIndent(root) {
  33126. if (root.raws.indent) return root.raws.indent
  33127. let value;
  33128. root.walk(i => {
  33129. let p = i.parent;
  33130. if (p && p !== root && p.parent && p.parent === root) {
  33131. if (typeof i.raws.before !== 'undefined') {
  33132. let parts = i.raws.before.split('\n');
  33133. value = parts[parts.length - 1];
  33134. value = value.replace(/\S/g, '');
  33135. return false
  33136. }
  33137. }
  33138. });
  33139. return value
  33140. }
  33141. rawSemicolon(root) {
  33142. let value;
  33143. root.walk(i => {
  33144. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  33145. value = i.raws.semicolon;
  33146. if (typeof value !== 'undefined') return false
  33147. }
  33148. });
  33149. return value
  33150. }
  33151. rawValue(node, prop) {
  33152. let value = node[prop];
  33153. let raw = node.raws[prop];
  33154. if (raw && raw.value === value) {
  33155. return raw.raw
  33156. }
  33157. return value
  33158. }
  33159. root(node) {
  33160. this.body(node);
  33161. if (node.raws.after) this.builder(node.raws.after);
  33162. }
  33163. rule(node) {
  33164. this.block(node, this.rawValue(node, 'selector'));
  33165. if (node.raws.ownSemicolon) {
  33166. this.builder(node.raws.ownSemicolon, node, 'end');
  33167. }
  33168. }
  33169. stringify(node, semicolon) {
  33170. /* c8 ignore start */
  33171. if (!this[node.type]) {
  33172. throw new Error(
  33173. 'Unknown AST node type ' +
  33174. node.type +
  33175. '. ' +
  33176. 'Maybe you need to change PostCSS stringifier.'
  33177. )
  33178. }
  33179. /* c8 ignore stop */
  33180. this[node.type](node, semicolon);
  33181. }
  33182. };
  33183. var stringifier = Stringifier$2;
  33184. Stringifier$2.default = Stringifier$2;
  33185. let Stringifier$1 = stringifier;
  33186. function stringify$4(node, builder) {
  33187. let str = new Stringifier$1(builder);
  33188. str.stringify(node);
  33189. }
  33190. var stringify_1 = stringify$4;
  33191. stringify$4.default = stringify$4;
  33192. let { isClean: isClean$2, my: my$2 } = symbols;
  33193. let CssSyntaxError$2 = cssSyntaxError;
  33194. let Stringifier = stringifier;
  33195. let stringify$3 = stringify_1;
  33196. function cloneNode(obj, parent) {
  33197. let cloned = new obj.constructor();
  33198. for (let i in obj) {
  33199. if (!Object.prototype.hasOwnProperty.call(obj, i)) {
  33200. /* c8 ignore next 2 */
  33201. continue
  33202. }
  33203. if (i === 'proxyCache') continue
  33204. let value = obj[i];
  33205. let type = typeof value;
  33206. if (i === 'parent' && type === 'object') {
  33207. if (parent) cloned[i] = parent;
  33208. } else if (i === 'source') {
  33209. cloned[i] = value;
  33210. } else if (Array.isArray(value)) {
  33211. cloned[i] = value.map(j => cloneNode(j, cloned));
  33212. } else {
  33213. if (type === 'object' && value !== null) value = cloneNode(value);
  33214. cloned[i] = value;
  33215. }
  33216. }
  33217. return cloned
  33218. }
  33219. let Node$4 = class Node {
  33220. constructor(defaults = {}) {
  33221. this.raws = {};
  33222. this[isClean$2] = false;
  33223. this[my$2] = true;
  33224. for (let name in defaults) {
  33225. if (name === 'nodes') {
  33226. this.nodes = [];
  33227. for (let node of defaults[name]) {
  33228. if (typeof node.clone === 'function') {
  33229. this.append(node.clone());
  33230. } else {
  33231. this.append(node);
  33232. }
  33233. }
  33234. } else {
  33235. this[name] = defaults[name];
  33236. }
  33237. }
  33238. }
  33239. addToError(error) {
  33240. error.postcssNode = this;
  33241. if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
  33242. let s = this.source;
  33243. error.stack = error.stack.replace(
  33244. /\n\s{4}at /,
  33245. `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
  33246. );
  33247. }
  33248. return error
  33249. }
  33250. after(add) {
  33251. this.parent.insertAfter(this, add);
  33252. return this
  33253. }
  33254. assign(overrides = {}) {
  33255. for (let name in overrides) {
  33256. this[name] = overrides[name];
  33257. }
  33258. return this
  33259. }
  33260. before(add) {
  33261. this.parent.insertBefore(this, add);
  33262. return this
  33263. }
  33264. cleanRaws(keepBetween) {
  33265. delete this.raws.before;
  33266. delete this.raws.after;
  33267. if (!keepBetween) delete this.raws.between;
  33268. }
  33269. clone(overrides = {}) {
  33270. let cloned = cloneNode(this);
  33271. for (let name in overrides) {
  33272. cloned[name] = overrides[name];
  33273. }
  33274. return cloned
  33275. }
  33276. cloneAfter(overrides = {}) {
  33277. let cloned = this.clone(overrides);
  33278. this.parent.insertAfter(this, cloned);
  33279. return cloned
  33280. }
  33281. cloneBefore(overrides = {}) {
  33282. let cloned = this.clone(overrides);
  33283. this.parent.insertBefore(this, cloned);
  33284. return cloned
  33285. }
  33286. error(message, opts = {}) {
  33287. if (this.source) {
  33288. let { end, start } = this.rangeBy(opts);
  33289. return this.source.input.error(
  33290. message,
  33291. { column: start.column, line: start.line },
  33292. { column: end.column, line: end.line },
  33293. opts
  33294. )
  33295. }
  33296. return new CssSyntaxError$2(message)
  33297. }
  33298. getProxyProcessor() {
  33299. return {
  33300. get(node, prop) {
  33301. if (prop === 'proxyOf') {
  33302. return node
  33303. } else if (prop === 'root') {
  33304. return () => node.root().toProxy()
  33305. } else {
  33306. return node[prop]
  33307. }
  33308. },
  33309. set(node, prop, value) {
  33310. if (node[prop] === value) return true
  33311. node[prop] = value;
  33312. if (
  33313. prop === 'prop' ||
  33314. prop === 'value' ||
  33315. prop === 'name' ||
  33316. prop === 'params' ||
  33317. prop === 'important' ||
  33318. /* c8 ignore next */
  33319. prop === 'text'
  33320. ) {
  33321. node.markDirty();
  33322. }
  33323. return true
  33324. }
  33325. }
  33326. }
  33327. markDirty() {
  33328. if (this[isClean$2]) {
  33329. this[isClean$2] = false;
  33330. let next = this;
  33331. while ((next = next.parent)) {
  33332. next[isClean$2] = false;
  33333. }
  33334. }
  33335. }
  33336. next() {
  33337. if (!this.parent) return undefined
  33338. let index = this.parent.index(this);
  33339. return this.parent.nodes[index + 1]
  33340. }
  33341. positionBy(opts, stringRepresentation) {
  33342. let pos = this.source.start;
  33343. if (opts.index) {
  33344. pos = this.positionInside(opts.index, stringRepresentation);
  33345. } else if (opts.word) {
  33346. stringRepresentation = this.toString();
  33347. let index = stringRepresentation.indexOf(opts.word);
  33348. if (index !== -1) pos = this.positionInside(index, stringRepresentation);
  33349. }
  33350. return pos
  33351. }
  33352. positionInside(index, stringRepresentation) {
  33353. let string = stringRepresentation || this.toString();
  33354. let column = this.source.start.column;
  33355. let line = this.source.start.line;
  33356. for (let i = 0; i < index; i++) {
  33357. if (string[i] === '\n') {
  33358. column = 1;
  33359. line += 1;
  33360. } else {
  33361. column += 1;
  33362. }
  33363. }
  33364. return { column, line }
  33365. }
  33366. prev() {
  33367. if (!this.parent) return undefined
  33368. let index = this.parent.index(this);
  33369. return this.parent.nodes[index - 1]
  33370. }
  33371. rangeBy(opts) {
  33372. let start = {
  33373. column: this.source.start.column,
  33374. line: this.source.start.line
  33375. };
  33376. let end = this.source.end
  33377. ? {
  33378. column: this.source.end.column + 1,
  33379. line: this.source.end.line
  33380. }
  33381. : {
  33382. column: start.column + 1,
  33383. line: start.line
  33384. };
  33385. if (opts.word) {
  33386. let stringRepresentation = this.toString();
  33387. let index = stringRepresentation.indexOf(opts.word);
  33388. if (index !== -1) {
  33389. start = this.positionInside(index, stringRepresentation);
  33390. end = this.positionInside(index + opts.word.length, stringRepresentation);
  33391. }
  33392. } else {
  33393. if (opts.start) {
  33394. start = {
  33395. column: opts.start.column,
  33396. line: opts.start.line
  33397. };
  33398. } else if (opts.index) {
  33399. start = this.positionInside(opts.index);
  33400. }
  33401. if (opts.end) {
  33402. end = {
  33403. column: opts.end.column,
  33404. line: opts.end.line
  33405. };
  33406. } else if (opts.endIndex) {
  33407. end = this.positionInside(opts.endIndex);
  33408. } else if (opts.index) {
  33409. end = this.positionInside(opts.index + 1);
  33410. }
  33411. }
  33412. if (
  33413. end.line < start.line ||
  33414. (end.line === start.line && end.column <= start.column)
  33415. ) {
  33416. end = { column: start.column + 1, line: start.line };
  33417. }
  33418. return { end, start }
  33419. }
  33420. raw(prop, defaultType) {
  33421. let str = new Stringifier();
  33422. return str.raw(this, prop, defaultType)
  33423. }
  33424. remove() {
  33425. if (this.parent) {
  33426. this.parent.removeChild(this);
  33427. }
  33428. this.parent = undefined;
  33429. return this
  33430. }
  33431. replaceWith(...nodes) {
  33432. if (this.parent) {
  33433. let bookmark = this;
  33434. let foundSelf = false;
  33435. for (let node of nodes) {
  33436. if (node === this) {
  33437. foundSelf = true;
  33438. } else if (foundSelf) {
  33439. this.parent.insertAfter(bookmark, node);
  33440. bookmark = node;
  33441. } else {
  33442. this.parent.insertBefore(bookmark, node);
  33443. }
  33444. }
  33445. if (!foundSelf) {
  33446. this.remove();
  33447. }
  33448. }
  33449. return this
  33450. }
  33451. root() {
  33452. let result = this;
  33453. while (result.parent && result.parent.type !== 'document') {
  33454. result = result.parent;
  33455. }
  33456. return result
  33457. }
  33458. toJSON(_, inputs) {
  33459. let fixed = {};
  33460. let emitInputs = inputs == null;
  33461. inputs = inputs || new Map();
  33462. let inputsNextIndex = 0;
  33463. for (let name in this) {
  33464. if (!Object.prototype.hasOwnProperty.call(this, name)) {
  33465. /* c8 ignore next 2 */
  33466. continue
  33467. }
  33468. if (name === 'parent' || name === 'proxyCache') continue
  33469. let value = this[name];
  33470. if (Array.isArray(value)) {
  33471. fixed[name] = value.map(i => {
  33472. if (typeof i === 'object' && i.toJSON) {
  33473. return i.toJSON(null, inputs)
  33474. } else {
  33475. return i
  33476. }
  33477. });
  33478. } else if (typeof value === 'object' && value.toJSON) {
  33479. fixed[name] = value.toJSON(null, inputs);
  33480. } else if (name === 'source') {
  33481. let inputId = inputs.get(value.input);
  33482. if (inputId == null) {
  33483. inputId = inputsNextIndex;
  33484. inputs.set(value.input, inputsNextIndex);
  33485. inputsNextIndex++;
  33486. }
  33487. fixed[name] = {
  33488. end: value.end,
  33489. inputId,
  33490. start: value.start
  33491. };
  33492. } else {
  33493. fixed[name] = value;
  33494. }
  33495. }
  33496. if (emitInputs) {
  33497. fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
  33498. }
  33499. return fixed
  33500. }
  33501. toProxy() {
  33502. if (!this.proxyCache) {
  33503. this.proxyCache = new Proxy(this, this.getProxyProcessor());
  33504. }
  33505. return this.proxyCache
  33506. }
  33507. toString(stringifier = stringify$3) {
  33508. if (stringifier.stringify) stringifier = stringifier.stringify;
  33509. let result = '';
  33510. stringifier(this, i => {
  33511. result += i;
  33512. });
  33513. return result
  33514. }
  33515. warn(result, text, opts) {
  33516. let data = { node: this };
  33517. for (let i in opts) data[i] = opts[i];
  33518. return result.warn(text, data)
  33519. }
  33520. get proxyOf() {
  33521. return this
  33522. }
  33523. };
  33524. var node$2 = Node$4;
  33525. Node$4.default = Node$4;
  33526. let Node$3 = node$2;
  33527. let Declaration$4 = class Declaration extends Node$3 {
  33528. constructor(defaults) {
  33529. if (
  33530. defaults &&
  33531. typeof defaults.value !== 'undefined' &&
  33532. typeof defaults.value !== 'string'
  33533. ) {
  33534. defaults = { ...defaults, value: String(defaults.value) };
  33535. }
  33536. super(defaults);
  33537. this.type = 'decl';
  33538. }
  33539. get variable() {
  33540. return this.prop.startsWith('--') || this.prop[0] === '$'
  33541. }
  33542. };
  33543. var declaration = Declaration$4;
  33544. Declaration$4.default = Declaration$4;
  33545. var require$$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_url$1);
  33546. let urlAlphabet =
  33547. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
  33548. let customAlphabet = (alphabet, defaultSize = 21) => {
  33549. return (size = defaultSize) => {
  33550. let id = '';
  33551. let i = size;
  33552. while (i--) {
  33553. id += alphabet[(Math.random() * alphabet.length) | 0];
  33554. }
  33555. return id
  33556. }
  33557. };
  33558. let nanoid$1 = (size = 21) => {
  33559. let id = '';
  33560. let i = size;
  33561. while (i--) {
  33562. id += urlAlphabet[(Math.random() * 64) | 0];
  33563. }
  33564. return id
  33565. };
  33566. var nonSecure = { nanoid: nanoid$1, customAlphabet };
  33567. let { SourceMapConsumer: SourceMapConsumer$4, SourceMapGenerator: SourceMapGenerator$5 } = sourceMap$2;
  33568. let { existsSync, readFileSync } = require$$0$2;
  33569. let { dirname: dirname$1, join } = require$$2$1;
  33570. function fromBase64(str) {
  33571. if (Buffer$1) {
  33572. return Buffer$1.from(str, 'base64').toString()
  33573. } else {
  33574. /* c8 ignore next 2 */
  33575. return window.atob(str)
  33576. }
  33577. }
  33578. let PreviousMap$2 = class PreviousMap {
  33579. constructor(css, opts) {
  33580. if (opts.map === false) return
  33581. this.loadAnnotation(css);
  33582. this.inline = this.startWith(this.annotation, 'data:');
  33583. let prev = opts.map ? opts.map.prev : undefined;
  33584. let text = this.loadMap(opts.from, prev);
  33585. if (!this.mapFile && opts.from) {
  33586. this.mapFile = opts.from;
  33587. }
  33588. if (this.mapFile) this.root = dirname$1(this.mapFile);
  33589. if (text) this.text = text;
  33590. }
  33591. consumer() {
  33592. if (!this.consumerCache) {
  33593. this.consumerCache = new SourceMapConsumer$4(this.text);
  33594. }
  33595. return this.consumerCache
  33596. }
  33597. decodeInline(text) {
  33598. let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  33599. let baseUri = /^data:application\/json;base64,/;
  33600. let charsetUri = /^data:application\/json;charset=utf-?8,/;
  33601. let uri = /^data:application\/json,/;
  33602. if (charsetUri.test(text) || uri.test(text)) {
  33603. return decodeURIComponent(text.substr(RegExp.lastMatch.length))
  33604. }
  33605. if (baseCharsetUri.test(text) || baseUri.test(text)) {
  33606. return fromBase64(text.substr(RegExp.lastMatch.length))
  33607. }
  33608. let encoding = text.match(/data:application\/json;([^,]+),/)[1];
  33609. throw new Error('Unsupported source map encoding ' + encoding)
  33610. }
  33611. getAnnotationURL(sourceMapString) {
  33612. return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
  33613. }
  33614. isMap(map) {
  33615. if (typeof map !== 'object') return false
  33616. return (
  33617. typeof map.mappings === 'string' ||
  33618. typeof map._mappings === 'string' ||
  33619. Array.isArray(map.sections)
  33620. )
  33621. }
  33622. loadAnnotation(css) {
  33623. let comments = css.match(/\/\*\s*# sourceMappingURL=/gm);
  33624. if (!comments) return
  33625. // sourceMappingURLs from comments, strings, etc.
  33626. let start = css.lastIndexOf(comments.pop());
  33627. let end = css.indexOf('*/', start);
  33628. if (start > -1 && end > -1) {
  33629. // Locate the last sourceMappingURL to avoid pickin
  33630. this.annotation = this.getAnnotationURL(css.substring(start, end));
  33631. }
  33632. }
  33633. loadFile(path) {
  33634. this.root = dirname$1(path);
  33635. if (existsSync(path)) {
  33636. this.mapFile = path;
  33637. return readFileSync(path, 'utf-8').toString().trim()
  33638. }
  33639. }
  33640. loadMap(file, prev) {
  33641. if (prev === false) return false
  33642. if (prev) {
  33643. if (typeof prev === 'string') {
  33644. return prev
  33645. } else if (typeof prev === 'function') {
  33646. let prevPath = prev(file);
  33647. if (prevPath) {
  33648. let map = this.loadFile(prevPath);
  33649. if (!map) {
  33650. throw new Error(
  33651. 'Unable to load previous source map: ' + prevPath.toString()
  33652. )
  33653. }
  33654. return map
  33655. }
  33656. } else if (prev instanceof SourceMapConsumer$4) {
  33657. return SourceMapGenerator$5.fromSourceMap(prev).toString()
  33658. } else if (prev instanceof SourceMapGenerator$5) {
  33659. return prev.toString()
  33660. } else if (this.isMap(prev)) {
  33661. return JSON.stringify(prev)
  33662. } else {
  33663. throw new Error(
  33664. 'Unsupported previous source map format: ' + prev.toString()
  33665. )
  33666. }
  33667. } else if (this.inline) {
  33668. return this.decodeInline(this.annotation)
  33669. } else if (this.annotation) {
  33670. let map = this.annotation;
  33671. if (file) map = join(dirname$1(file), map);
  33672. return this.loadFile(map)
  33673. }
  33674. }
  33675. startWith(string, start) {
  33676. if (!string) return false
  33677. return string.substr(0, start.length) === start
  33678. }
  33679. withContent() {
  33680. return !!(
  33681. this.consumer().sourcesContent &&
  33682. this.consumer().sourcesContent.length > 0
  33683. )
  33684. }
  33685. };
  33686. var previousMap = PreviousMap$2;
  33687. PreviousMap$2.default = PreviousMap$2;
  33688. let { SourceMapConsumer: SourceMapConsumer$3, SourceMapGenerator: SourceMapGenerator$4 } = sourceMap$2;
  33689. let { fileURLToPath, pathToFileURL: pathToFileURL$1 } = require$$2;
  33690. let { isAbsolute, resolve: resolve$1 } = require$$2$1;
  33691. let { nanoid } = nonSecure;
  33692. let terminalHighlight = terminalHighlight_1;
  33693. let CssSyntaxError$1 = cssSyntaxError;
  33694. let PreviousMap$1 = previousMap;
  33695. let fromOffsetCache = Symbol('fromOffsetCache');
  33696. let sourceMapAvailable$1 = Boolean(SourceMapConsumer$3 && SourceMapGenerator$4);
  33697. let pathAvailable$1 = Boolean(resolve$1 && isAbsolute);
  33698. let Input$4 = class Input {
  33699. constructor(css, opts = {}) {
  33700. if (
  33701. css === null ||
  33702. typeof css === 'undefined' ||
  33703. (typeof css === 'object' && !css.toString)
  33704. ) {
  33705. throw new Error(`PostCSS received ${css} instead of CSS string`)
  33706. }
  33707. this.css = css.toString();
  33708. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  33709. this.hasBOM = true;
  33710. this.css = this.css.slice(1);
  33711. } else {
  33712. this.hasBOM = false;
  33713. }
  33714. if (opts.from) {
  33715. if (
  33716. !pathAvailable$1 ||
  33717. /^\w+:\/\//.test(opts.from) ||
  33718. isAbsolute(opts.from)
  33719. ) {
  33720. this.file = opts.from;
  33721. } else {
  33722. this.file = resolve$1(opts.from);
  33723. }
  33724. }
  33725. if (pathAvailable$1 && sourceMapAvailable$1) {
  33726. let map = new PreviousMap$1(this.css, opts);
  33727. if (map.text) {
  33728. this.map = map;
  33729. let file = map.consumer().file;
  33730. if (!this.file && file) this.file = this.mapResolve(file);
  33731. }
  33732. }
  33733. if (!this.file) {
  33734. this.id = '<input css ' + nanoid(6) + '>';
  33735. }
  33736. if (this.map) this.map.file = this.from;
  33737. }
  33738. error(message, line, column, opts = {}) {
  33739. let result, endLine, endColumn;
  33740. if (line && typeof line === 'object') {
  33741. let start = line;
  33742. let end = column;
  33743. if (typeof start.offset === 'number') {
  33744. let pos = this.fromOffset(start.offset);
  33745. line = pos.line;
  33746. column = pos.col;
  33747. } else {
  33748. line = start.line;
  33749. column = start.column;
  33750. }
  33751. if (typeof end.offset === 'number') {
  33752. let pos = this.fromOffset(end.offset);
  33753. endLine = pos.line;
  33754. endColumn = pos.col;
  33755. } else {
  33756. endLine = end.line;
  33757. endColumn = end.column;
  33758. }
  33759. } else if (!column) {
  33760. let pos = this.fromOffset(line);
  33761. line = pos.line;
  33762. column = pos.col;
  33763. }
  33764. let origin = this.origin(line, column, endLine, endColumn);
  33765. if (origin) {
  33766. result = new CssSyntaxError$1(
  33767. message,
  33768. origin.endLine === undefined
  33769. ? origin.line
  33770. : { column: origin.column, line: origin.line },
  33771. origin.endLine === undefined
  33772. ? origin.column
  33773. : { column: origin.endColumn, line: origin.endLine },
  33774. origin.source,
  33775. origin.file,
  33776. opts.plugin
  33777. );
  33778. } else {
  33779. result = new CssSyntaxError$1(
  33780. message,
  33781. endLine === undefined ? line : { column, line },
  33782. endLine === undefined ? column : { column: endColumn, line: endLine },
  33783. this.css,
  33784. this.file,
  33785. opts.plugin
  33786. );
  33787. }
  33788. result.input = { column, endColumn, endLine, line, source: this.css };
  33789. if (this.file) {
  33790. if (pathToFileURL$1) {
  33791. result.input.url = pathToFileURL$1(this.file).toString();
  33792. }
  33793. result.input.file = this.file;
  33794. }
  33795. return result
  33796. }
  33797. fromOffset(offset) {
  33798. let lastLine, lineToIndex;
  33799. if (!this[fromOffsetCache]) {
  33800. let lines = this.css.split('\n');
  33801. lineToIndex = new Array(lines.length);
  33802. let prevIndex = 0;
  33803. for (let i = 0, l = lines.length; i < l; i++) {
  33804. lineToIndex[i] = prevIndex;
  33805. prevIndex += lines[i].length + 1;
  33806. }
  33807. this[fromOffsetCache] = lineToIndex;
  33808. } else {
  33809. lineToIndex = this[fromOffsetCache];
  33810. }
  33811. lastLine = lineToIndex[lineToIndex.length - 1];
  33812. let min = 0;
  33813. if (offset >= lastLine) {
  33814. min = lineToIndex.length - 1;
  33815. } else {
  33816. let max = lineToIndex.length - 2;
  33817. let mid;
  33818. while (min < max) {
  33819. mid = min + ((max - min) >> 1);
  33820. if (offset < lineToIndex[mid]) {
  33821. max = mid - 1;
  33822. } else if (offset >= lineToIndex[mid + 1]) {
  33823. min = mid + 1;
  33824. } else {
  33825. min = mid;
  33826. break
  33827. }
  33828. }
  33829. }
  33830. return {
  33831. col: offset - lineToIndex[min] + 1,
  33832. line: min + 1
  33833. }
  33834. }
  33835. mapResolve(file) {
  33836. if (/^\w+:\/\//.test(file)) {
  33837. return file
  33838. }
  33839. return resolve$1(this.map.consumer().sourceRoot || this.map.root || '.', file)
  33840. }
  33841. origin(line, column, endLine, endColumn) {
  33842. if (!this.map) return false
  33843. let consumer = this.map.consumer();
  33844. let from = consumer.originalPositionFor({ column, line });
  33845. if (!from.source) return false
  33846. let to;
  33847. if (typeof endLine === 'number') {
  33848. to = consumer.originalPositionFor({ column: endColumn, line: endLine });
  33849. }
  33850. let fromUrl;
  33851. if (isAbsolute(from.source)) {
  33852. fromUrl = pathToFileURL$1(from.source);
  33853. } else {
  33854. fromUrl = new URL(
  33855. from.source,
  33856. this.map.consumer().sourceRoot || pathToFileURL$1(this.map.mapFile)
  33857. );
  33858. }
  33859. let result = {
  33860. column: from.column,
  33861. endColumn: to && to.column,
  33862. endLine: to && to.line,
  33863. line: from.line,
  33864. url: fromUrl.toString()
  33865. };
  33866. if (fromUrl.protocol === 'file:') {
  33867. if (fileURLToPath) {
  33868. result.file = fileURLToPath(fromUrl);
  33869. } else {
  33870. /* c8 ignore next 2 */
  33871. throw new Error(`file: protocol is not available in this PostCSS build`)
  33872. }
  33873. }
  33874. let source = consumer.sourceContentFor(from.source);
  33875. if (source) result.source = source;
  33876. return result
  33877. }
  33878. toJSON() {
  33879. let json = {};
  33880. for (let name of ['hasBOM', 'css', 'file', 'id']) {
  33881. if (this[name] != null) {
  33882. json[name] = this[name];
  33883. }
  33884. }
  33885. if (this.map) {
  33886. json.map = { ...this.map };
  33887. if (json.map.consumerCache) {
  33888. json.map.consumerCache = undefined;
  33889. }
  33890. }
  33891. return json
  33892. }
  33893. get from() {
  33894. return this.file || this.id
  33895. }
  33896. };
  33897. var input = Input$4;
  33898. Input$4.default = Input$4;
  33899. if (terminalHighlight && terminalHighlight.registerInput) {
  33900. terminalHighlight.registerInput(Input$4);
  33901. }
  33902. let { SourceMapConsumer: SourceMapConsumer$2, SourceMapGenerator: SourceMapGenerator$3 } = sourceMap$2;
  33903. let { dirname, relative, resolve, sep } = require$$2$1;
  33904. let { pathToFileURL } = require$$2;
  33905. let Input$3 = input;
  33906. let sourceMapAvailable = Boolean(SourceMapConsumer$2 && SourceMapGenerator$3);
  33907. let pathAvailable = Boolean(dirname && resolve && relative && sep);
  33908. let MapGenerator$2 = class MapGenerator {
  33909. constructor(stringify, root, opts, cssString) {
  33910. this.stringify = stringify;
  33911. this.mapOpts = opts.map || {};
  33912. this.root = root;
  33913. this.opts = opts;
  33914. this.css = cssString;
  33915. this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
  33916. this.memoizedFileURLs = new Map();
  33917. this.memoizedPaths = new Map();
  33918. this.memoizedURLs = new Map();
  33919. }
  33920. addAnnotation() {
  33921. let content;
  33922. if (this.isInline()) {
  33923. content =
  33924. 'data:application/json;base64,' + this.toBase64(this.map.toString());
  33925. } else if (typeof this.mapOpts.annotation === 'string') {
  33926. content = this.mapOpts.annotation;
  33927. } else if (typeof this.mapOpts.annotation === 'function') {
  33928. content = this.mapOpts.annotation(this.opts.to, this.root);
  33929. } else {
  33930. content = this.outputFile() + '.map';
  33931. }
  33932. let eol = '\n';
  33933. if (this.css.includes('\r\n')) eol = '\r\n';
  33934. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  33935. }
  33936. applyPrevMaps() {
  33937. for (let prev of this.previous()) {
  33938. let from = this.toUrl(this.path(prev.file));
  33939. let root = prev.root || dirname(prev.file);
  33940. let map;
  33941. if (this.mapOpts.sourcesContent === false) {
  33942. map = new SourceMapConsumer$2(prev.text);
  33943. if (map.sourcesContent) {
  33944. map.sourcesContent = map.sourcesContent.map(() => null);
  33945. }
  33946. } else {
  33947. map = prev.consumer();
  33948. }
  33949. this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
  33950. }
  33951. }
  33952. clearAnnotation() {
  33953. if (this.mapOpts.annotation === false) return
  33954. if (this.root) {
  33955. let node;
  33956. for (let i = this.root.nodes.length - 1; i >= 0; i--) {
  33957. node = this.root.nodes[i];
  33958. if (node.type !== 'comment') continue
  33959. if (node.text.indexOf('# sourceMappingURL=') === 0) {
  33960. this.root.removeChild(i);
  33961. }
  33962. }
  33963. } else if (this.css) {
  33964. this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '');
  33965. }
  33966. }
  33967. generate() {
  33968. this.clearAnnotation();
  33969. if (pathAvailable && sourceMapAvailable && this.isMap()) {
  33970. return this.generateMap()
  33971. } else {
  33972. let result = '';
  33973. this.stringify(this.root, i => {
  33974. result += i;
  33975. });
  33976. return [result]
  33977. }
  33978. }
  33979. generateMap() {
  33980. if (this.root) {
  33981. this.generateString();
  33982. } else if (this.previous().length === 1) {
  33983. let prev = this.previous()[0].consumer();
  33984. prev.file = this.outputFile();
  33985. this.map = SourceMapGenerator$3.fromSourceMap(prev);
  33986. } else {
  33987. this.map = new SourceMapGenerator$3({ file: this.outputFile() });
  33988. this.map.addMapping({
  33989. generated: { column: 0, line: 1 },
  33990. original: { column: 0, line: 1 },
  33991. source: this.opts.from
  33992. ? this.toUrl(this.path(this.opts.from))
  33993. : '<no source>'
  33994. });
  33995. }
  33996. if (this.isSourcesContent()) this.setSourcesContent();
  33997. if (this.root && this.previous().length > 0) this.applyPrevMaps();
  33998. if (this.isAnnotation()) this.addAnnotation();
  33999. if (this.isInline()) {
  34000. return [this.css]
  34001. } else {
  34002. return [this.css, this.map]
  34003. }
  34004. }
  34005. generateString() {
  34006. this.css = '';
  34007. this.map = new SourceMapGenerator$3({ file: this.outputFile() });
  34008. let line = 1;
  34009. let column = 1;
  34010. let noSource = '<no source>';
  34011. let mapping = {
  34012. generated: { column: 0, line: 0 },
  34013. original: { column: 0, line: 0 },
  34014. source: ''
  34015. };
  34016. let lines, last;
  34017. this.stringify(this.root, (str, node, type) => {
  34018. this.css += str;
  34019. if (node && type !== 'end') {
  34020. mapping.generated.line = line;
  34021. mapping.generated.column = column - 1;
  34022. if (node.source && node.source.start) {
  34023. mapping.source = this.sourcePath(node);
  34024. mapping.original.line = node.source.start.line;
  34025. mapping.original.column = node.source.start.column - 1;
  34026. this.map.addMapping(mapping);
  34027. } else {
  34028. mapping.source = noSource;
  34029. mapping.original.line = 1;
  34030. mapping.original.column = 0;
  34031. this.map.addMapping(mapping);
  34032. }
  34033. }
  34034. lines = str.match(/\n/g);
  34035. if (lines) {
  34036. line += lines.length;
  34037. last = str.lastIndexOf('\n');
  34038. column = str.length - last;
  34039. } else {
  34040. column += str.length;
  34041. }
  34042. if (node && type !== 'start') {
  34043. let p = node.parent || { raws: {} };
  34044. let childless =
  34045. node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
  34046. if (!childless || node !== p.last || p.raws.semicolon) {
  34047. if (node.source && node.source.end) {
  34048. mapping.source = this.sourcePath(node);
  34049. mapping.original.line = node.source.end.line;
  34050. mapping.original.column = node.source.end.column - 1;
  34051. mapping.generated.line = line;
  34052. mapping.generated.column = column - 2;
  34053. this.map.addMapping(mapping);
  34054. } else {
  34055. mapping.source = noSource;
  34056. mapping.original.line = 1;
  34057. mapping.original.column = 0;
  34058. mapping.generated.line = line;
  34059. mapping.generated.column = column - 1;
  34060. this.map.addMapping(mapping);
  34061. }
  34062. }
  34063. }
  34064. });
  34065. }
  34066. isAnnotation() {
  34067. if (this.isInline()) {
  34068. return true
  34069. }
  34070. if (typeof this.mapOpts.annotation !== 'undefined') {
  34071. return this.mapOpts.annotation
  34072. }
  34073. if (this.previous().length) {
  34074. return this.previous().some(i => i.annotation)
  34075. }
  34076. return true
  34077. }
  34078. isInline() {
  34079. if (typeof this.mapOpts.inline !== 'undefined') {
  34080. return this.mapOpts.inline
  34081. }
  34082. let annotation = this.mapOpts.annotation;
  34083. if (typeof annotation !== 'undefined' && annotation !== true) {
  34084. return false
  34085. }
  34086. if (this.previous().length) {
  34087. return this.previous().some(i => i.inline)
  34088. }
  34089. return true
  34090. }
  34091. isMap() {
  34092. if (typeof this.opts.map !== 'undefined') {
  34093. return !!this.opts.map
  34094. }
  34095. return this.previous().length > 0
  34096. }
  34097. isSourcesContent() {
  34098. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  34099. return this.mapOpts.sourcesContent
  34100. }
  34101. if (this.previous().length) {
  34102. return this.previous().some(i => i.withContent())
  34103. }
  34104. return true
  34105. }
  34106. outputFile() {
  34107. if (this.opts.to) {
  34108. return this.path(this.opts.to)
  34109. } else if (this.opts.from) {
  34110. return this.path(this.opts.from)
  34111. } else {
  34112. return 'to.css'
  34113. }
  34114. }
  34115. path(file) {
  34116. if (this.mapOpts.absolute) return file
  34117. if (file.charCodeAt(0) === 60 /* `<` */) return file
  34118. if (/^\w+:\/\//.test(file)) return file
  34119. let cached = this.memoizedPaths.get(file);
  34120. if (cached) return cached
  34121. let from = this.opts.to ? dirname(this.opts.to) : '.';
  34122. if (typeof this.mapOpts.annotation === 'string') {
  34123. from = dirname(resolve(from, this.mapOpts.annotation));
  34124. }
  34125. let path = relative(from, file);
  34126. this.memoizedPaths.set(file, path);
  34127. return path
  34128. }
  34129. previous() {
  34130. if (!this.previousMaps) {
  34131. this.previousMaps = [];
  34132. if (this.root) {
  34133. this.root.walk(node => {
  34134. if (node.source && node.source.input.map) {
  34135. let map = node.source.input.map;
  34136. if (!this.previousMaps.includes(map)) {
  34137. this.previousMaps.push(map);
  34138. }
  34139. }
  34140. });
  34141. } else {
  34142. let input = new Input$3(this.css, this.opts);
  34143. if (input.map) this.previousMaps.push(input.map);
  34144. }
  34145. }
  34146. return this.previousMaps
  34147. }
  34148. setSourcesContent() {
  34149. let already = {};
  34150. if (this.root) {
  34151. this.root.walk(node => {
  34152. if (node.source) {
  34153. let from = node.source.input.from;
  34154. if (from && !already[from]) {
  34155. already[from] = true;
  34156. let fromUrl = this.usesFileUrls
  34157. ? this.toFileUrl(from)
  34158. : this.toUrl(this.path(from));
  34159. this.map.setSourceContent(fromUrl, node.source.input.css);
  34160. }
  34161. }
  34162. });
  34163. } else if (this.css) {
  34164. let from = this.opts.from
  34165. ? this.toUrl(this.path(this.opts.from))
  34166. : '<no source>';
  34167. this.map.setSourceContent(from, this.css);
  34168. }
  34169. }
  34170. sourcePath(node) {
  34171. if (this.mapOpts.from) {
  34172. return this.toUrl(this.mapOpts.from)
  34173. } else if (this.usesFileUrls) {
  34174. return this.toFileUrl(node.source.input.from)
  34175. } else {
  34176. return this.toUrl(this.path(node.source.input.from))
  34177. }
  34178. }
  34179. toBase64(str) {
  34180. if (Buffer$1) {
  34181. return Buffer$1.from(str).toString('base64')
  34182. } else {
  34183. return window.btoa(unescape(encodeURIComponent(str)))
  34184. }
  34185. }
  34186. toFileUrl(path) {
  34187. let cached = this.memoizedFileURLs.get(path);
  34188. if (cached) return cached
  34189. if (pathToFileURL) {
  34190. let fileURL = pathToFileURL(path).toString();
  34191. this.memoizedFileURLs.set(path, fileURL);
  34192. return fileURL
  34193. } else {
  34194. throw new Error(
  34195. '`map.absolute` option is not available in this PostCSS build'
  34196. )
  34197. }
  34198. }
  34199. toUrl(path) {
  34200. let cached = this.memoizedURLs.get(path);
  34201. if (cached) return cached
  34202. if (sep === '\\') {
  34203. path = path.replace(/\\/g, '/');
  34204. }
  34205. let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
  34206. this.memoizedURLs.set(path, url);
  34207. return url
  34208. }
  34209. };
  34210. var mapGenerator = MapGenerator$2;
  34211. let Node$2 = node$2;
  34212. let Comment$4 = class Comment extends Node$2 {
  34213. constructor(defaults) {
  34214. super(defaults);
  34215. this.type = 'comment';
  34216. }
  34217. };
  34218. var comment$3 = Comment$4;
  34219. Comment$4.default = Comment$4;
  34220. let { isClean: isClean$1, my: my$1 } = symbols;
  34221. let Declaration$3 = declaration;
  34222. let Comment$3 = comment$3;
  34223. let Node$1 = node$2;
  34224. let parse$4, Rule$4, AtRule$4, Root$6;
  34225. function cleanSource(nodes) {
  34226. return nodes.map(i => {
  34227. if (i.nodes) i.nodes = cleanSource(i.nodes);
  34228. delete i.source;
  34229. return i
  34230. })
  34231. }
  34232. function markDirtyUp(node) {
  34233. node[isClean$1] = false;
  34234. if (node.proxyOf.nodes) {
  34235. for (let i of node.proxyOf.nodes) {
  34236. markDirtyUp(i);
  34237. }
  34238. }
  34239. }
  34240. let Container$7 = class Container extends Node$1 {
  34241. append(...children) {
  34242. for (let child of children) {
  34243. let nodes = this.normalize(child, this.last);
  34244. for (let node of nodes) this.proxyOf.nodes.push(node);
  34245. }
  34246. this.markDirty();
  34247. return this
  34248. }
  34249. cleanRaws(keepBetween) {
  34250. super.cleanRaws(keepBetween);
  34251. if (this.nodes) {
  34252. for (let node of this.nodes) node.cleanRaws(keepBetween);
  34253. }
  34254. }
  34255. each(callback) {
  34256. if (!this.proxyOf.nodes) return undefined
  34257. let iterator = this.getIterator();
  34258. let index, result;
  34259. while (this.indexes[iterator] < this.proxyOf.nodes.length) {
  34260. index = this.indexes[iterator];
  34261. result = callback(this.proxyOf.nodes[index], index);
  34262. if (result === false) break
  34263. this.indexes[iterator] += 1;
  34264. }
  34265. delete this.indexes[iterator];
  34266. return result
  34267. }
  34268. every(condition) {
  34269. return this.nodes.every(condition)
  34270. }
  34271. getIterator() {
  34272. if (!this.lastEach) this.lastEach = 0;
  34273. if (!this.indexes) this.indexes = {};
  34274. this.lastEach += 1;
  34275. let iterator = this.lastEach;
  34276. this.indexes[iterator] = 0;
  34277. return iterator
  34278. }
  34279. getProxyProcessor() {
  34280. return {
  34281. get(node, prop) {
  34282. if (prop === 'proxyOf') {
  34283. return node
  34284. } else if (!node[prop]) {
  34285. return node[prop]
  34286. } else if (
  34287. prop === 'each' ||
  34288. (typeof prop === 'string' && prop.startsWith('walk'))
  34289. ) {
  34290. return (...args) => {
  34291. return node[prop](
  34292. ...args.map(i => {
  34293. if (typeof i === 'function') {
  34294. return (child, index) => i(child.toProxy(), index)
  34295. } else {
  34296. return i
  34297. }
  34298. })
  34299. )
  34300. }
  34301. } else if (prop === 'every' || prop === 'some') {
  34302. return cb => {
  34303. return node[prop]((child, ...other) =>
  34304. cb(child.toProxy(), ...other)
  34305. )
  34306. }
  34307. } else if (prop === 'root') {
  34308. return () => node.root().toProxy()
  34309. } else if (prop === 'nodes') {
  34310. return node.nodes.map(i => i.toProxy())
  34311. } else if (prop === 'first' || prop === 'last') {
  34312. return node[prop].toProxy()
  34313. } else {
  34314. return node[prop]
  34315. }
  34316. },
  34317. set(node, prop, value) {
  34318. if (node[prop] === value) return true
  34319. node[prop] = value;
  34320. if (prop === 'name' || prop === 'params' || prop === 'selector') {
  34321. node.markDirty();
  34322. }
  34323. return true
  34324. }
  34325. }
  34326. }
  34327. index(child) {
  34328. if (typeof child === 'number') return child
  34329. if (child.proxyOf) child = child.proxyOf;
  34330. return this.proxyOf.nodes.indexOf(child)
  34331. }
  34332. insertAfter(exist, add) {
  34333. let existIndex = this.index(exist);
  34334. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
  34335. existIndex = this.index(exist);
  34336. for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
  34337. let index;
  34338. for (let id in this.indexes) {
  34339. index = this.indexes[id];
  34340. if (existIndex < index) {
  34341. this.indexes[id] = index + nodes.length;
  34342. }
  34343. }
  34344. this.markDirty();
  34345. return this
  34346. }
  34347. insertBefore(exist, add) {
  34348. let existIndex = this.index(exist);
  34349. let type = existIndex === 0 ? 'prepend' : false;
  34350. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse();
  34351. existIndex = this.index(exist);
  34352. for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
  34353. let index;
  34354. for (let id in this.indexes) {
  34355. index = this.indexes[id];
  34356. if (existIndex <= index) {
  34357. this.indexes[id] = index + nodes.length;
  34358. }
  34359. }
  34360. this.markDirty();
  34361. return this
  34362. }
  34363. normalize(nodes, sample) {
  34364. if (typeof nodes === 'string') {
  34365. nodes = cleanSource(parse$4(nodes).nodes);
  34366. } else if (Array.isArray(nodes)) {
  34367. nodes = nodes.slice(0);
  34368. for (let i of nodes) {
  34369. if (i.parent) i.parent.removeChild(i, 'ignore');
  34370. }
  34371. } else if (nodes.type === 'root' && this.type !== 'document') {
  34372. nodes = nodes.nodes.slice(0);
  34373. for (let i of nodes) {
  34374. if (i.parent) i.parent.removeChild(i, 'ignore');
  34375. }
  34376. } else if (nodes.type) {
  34377. nodes = [nodes];
  34378. } else if (nodes.prop) {
  34379. if (typeof nodes.value === 'undefined') {
  34380. throw new Error('Value field is missed in node creation')
  34381. } else if (typeof nodes.value !== 'string') {
  34382. nodes.value = String(nodes.value);
  34383. }
  34384. nodes = [new Declaration$3(nodes)];
  34385. } else if (nodes.selector) {
  34386. nodes = [new Rule$4(nodes)];
  34387. } else if (nodes.name) {
  34388. nodes = [new AtRule$4(nodes)];
  34389. } else if (nodes.text) {
  34390. nodes = [new Comment$3(nodes)];
  34391. } else {
  34392. throw new Error('Unknown node type in node creation')
  34393. }
  34394. let processed = nodes.map(i => {
  34395. /* c8 ignore next */
  34396. if (!i[my$1]) Container.rebuild(i);
  34397. i = i.proxyOf;
  34398. if (i.parent) i.parent.removeChild(i);
  34399. if (i[isClean$1]) markDirtyUp(i);
  34400. if (typeof i.raws.before === 'undefined') {
  34401. if (sample && typeof sample.raws.before !== 'undefined') {
  34402. i.raws.before = sample.raws.before.replace(/\S/g, '');
  34403. }
  34404. }
  34405. i.parent = this.proxyOf;
  34406. return i
  34407. });
  34408. return processed
  34409. }
  34410. prepend(...children) {
  34411. children = children.reverse();
  34412. for (let child of children) {
  34413. let nodes = this.normalize(child, this.first, 'prepend').reverse();
  34414. for (let node of nodes) this.proxyOf.nodes.unshift(node);
  34415. for (let id in this.indexes) {
  34416. this.indexes[id] = this.indexes[id] + nodes.length;
  34417. }
  34418. }
  34419. this.markDirty();
  34420. return this
  34421. }
  34422. push(child) {
  34423. child.parent = this;
  34424. this.proxyOf.nodes.push(child);
  34425. return this
  34426. }
  34427. removeAll() {
  34428. for (let node of this.proxyOf.nodes) node.parent = undefined;
  34429. this.proxyOf.nodes = [];
  34430. this.markDirty();
  34431. return this
  34432. }
  34433. removeChild(child) {
  34434. child = this.index(child);
  34435. this.proxyOf.nodes[child].parent = undefined;
  34436. this.proxyOf.nodes.splice(child, 1);
  34437. let index;
  34438. for (let id in this.indexes) {
  34439. index = this.indexes[id];
  34440. if (index >= child) {
  34441. this.indexes[id] = index - 1;
  34442. }
  34443. }
  34444. this.markDirty();
  34445. return this
  34446. }
  34447. replaceValues(pattern, opts, callback) {
  34448. if (!callback) {
  34449. callback = opts;
  34450. opts = {};
  34451. }
  34452. this.walkDecls(decl => {
  34453. if (opts.props && !opts.props.includes(decl.prop)) return
  34454. if (opts.fast && !decl.value.includes(opts.fast)) return
  34455. decl.value = decl.value.replace(pattern, callback);
  34456. });
  34457. this.markDirty();
  34458. return this
  34459. }
  34460. some(condition) {
  34461. return this.nodes.some(condition)
  34462. }
  34463. walk(callback) {
  34464. return this.each((child, i) => {
  34465. let result;
  34466. try {
  34467. result = callback(child, i);
  34468. } catch (e) {
  34469. throw child.addToError(e)
  34470. }
  34471. if (result !== false && child.walk) {
  34472. result = child.walk(callback);
  34473. }
  34474. return result
  34475. })
  34476. }
  34477. walkAtRules(name, callback) {
  34478. if (!callback) {
  34479. callback = name;
  34480. return this.walk((child, i) => {
  34481. if (child.type === 'atrule') {
  34482. return callback(child, i)
  34483. }
  34484. })
  34485. }
  34486. if (name instanceof RegExp) {
  34487. return this.walk((child, i) => {
  34488. if (child.type === 'atrule' && name.test(child.name)) {
  34489. return callback(child, i)
  34490. }
  34491. })
  34492. }
  34493. return this.walk((child, i) => {
  34494. if (child.type === 'atrule' && child.name === name) {
  34495. return callback(child, i)
  34496. }
  34497. })
  34498. }
  34499. walkComments(callback) {
  34500. return this.walk((child, i) => {
  34501. if (child.type === 'comment') {
  34502. return callback(child, i)
  34503. }
  34504. })
  34505. }
  34506. walkDecls(prop, callback) {
  34507. if (!callback) {
  34508. callback = prop;
  34509. return this.walk((child, i) => {
  34510. if (child.type === 'decl') {
  34511. return callback(child, i)
  34512. }
  34513. })
  34514. }
  34515. if (prop instanceof RegExp) {
  34516. return this.walk((child, i) => {
  34517. if (child.type === 'decl' && prop.test(child.prop)) {
  34518. return callback(child, i)
  34519. }
  34520. })
  34521. }
  34522. return this.walk((child, i) => {
  34523. if (child.type === 'decl' && child.prop === prop) {
  34524. return callback(child, i)
  34525. }
  34526. })
  34527. }
  34528. walkRules(selector, callback) {
  34529. if (!callback) {
  34530. callback = selector;
  34531. return this.walk((child, i) => {
  34532. if (child.type === 'rule') {
  34533. return callback(child, i)
  34534. }
  34535. })
  34536. }
  34537. if (selector instanceof RegExp) {
  34538. return this.walk((child, i) => {
  34539. if (child.type === 'rule' && selector.test(child.selector)) {
  34540. return callback(child, i)
  34541. }
  34542. })
  34543. }
  34544. return this.walk((child, i) => {
  34545. if (child.type === 'rule' && child.selector === selector) {
  34546. return callback(child, i)
  34547. }
  34548. })
  34549. }
  34550. get first() {
  34551. if (!this.proxyOf.nodes) return undefined
  34552. return this.proxyOf.nodes[0]
  34553. }
  34554. get last() {
  34555. if (!this.proxyOf.nodes) return undefined
  34556. return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
  34557. }
  34558. };
  34559. Container$7.registerParse = dependant => {
  34560. parse$4 = dependant;
  34561. };
  34562. Container$7.registerRule = dependant => {
  34563. Rule$4 = dependant;
  34564. };
  34565. Container$7.registerAtRule = dependant => {
  34566. AtRule$4 = dependant;
  34567. };
  34568. Container$7.registerRoot = dependant => {
  34569. Root$6 = dependant;
  34570. };
  34571. var container$1 = Container$7;
  34572. Container$7.default = Container$7;
  34573. /* c8 ignore start */
  34574. Container$7.rebuild = node => {
  34575. if (node.type === 'atrule') {
  34576. Object.setPrototypeOf(node, AtRule$4.prototype);
  34577. } else if (node.type === 'rule') {
  34578. Object.setPrototypeOf(node, Rule$4.prototype);
  34579. } else if (node.type === 'decl') {
  34580. Object.setPrototypeOf(node, Declaration$3.prototype);
  34581. } else if (node.type === 'comment') {
  34582. Object.setPrototypeOf(node, Comment$3.prototype);
  34583. } else if (node.type === 'root') {
  34584. Object.setPrototypeOf(node, Root$6.prototype);
  34585. }
  34586. node[my$1] = true;
  34587. if (node.nodes) {
  34588. node.nodes.forEach(child => {
  34589. Container$7.rebuild(child);
  34590. });
  34591. }
  34592. };
  34593. let Container$6 = container$1;
  34594. let LazyResult$4, Processor$3;
  34595. let Document$3 = class Document extends Container$6 {
  34596. constructor(defaults) {
  34597. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  34598. super({ type: 'document', ...defaults });
  34599. if (!this.nodes) {
  34600. this.nodes = [];
  34601. }
  34602. }
  34603. toResult(opts = {}) {
  34604. let lazy = new LazyResult$4(new Processor$3(), this, opts);
  34605. return lazy.stringify()
  34606. }
  34607. };
  34608. Document$3.registerLazyResult = dependant => {
  34609. LazyResult$4 = dependant;
  34610. };
  34611. Document$3.registerProcessor = dependant => {
  34612. Processor$3 = dependant;
  34613. };
  34614. var document = Document$3;
  34615. Document$3.default = Document$3;
  34616. /* eslint-disable no-console */
  34617. let printed = {};
  34618. var warnOnce$3 = function warnOnce(message) {
  34619. if (printed[message]) return
  34620. printed[message] = true;
  34621. if (typeof console !== 'undefined' && console.warn) {
  34622. console.warn(message);
  34623. }
  34624. };
  34625. let Warning$2 = class Warning {
  34626. constructor(text, opts = {}) {
  34627. this.type = 'warning';
  34628. this.text = text;
  34629. if (opts.node && opts.node.source) {
  34630. let range = opts.node.rangeBy(opts);
  34631. this.line = range.start.line;
  34632. this.column = range.start.column;
  34633. this.endLine = range.end.line;
  34634. this.endColumn = range.end.column;
  34635. }
  34636. for (let opt in opts) this[opt] = opts[opt];
  34637. }
  34638. toString() {
  34639. if (this.node) {
  34640. return this.node.error(this.text, {
  34641. index: this.index,
  34642. plugin: this.plugin,
  34643. word: this.word
  34644. }).message
  34645. }
  34646. if (this.plugin) {
  34647. return this.plugin + ': ' + this.text
  34648. }
  34649. return this.text
  34650. }
  34651. };
  34652. var warning = Warning$2;
  34653. Warning$2.default = Warning$2;
  34654. let Warning$1 = warning;
  34655. let Result$3 = class Result {
  34656. constructor(processor, root, opts) {
  34657. this.processor = processor;
  34658. this.messages = [];
  34659. this.root = root;
  34660. this.opts = opts;
  34661. this.css = undefined;
  34662. this.map = undefined;
  34663. }
  34664. toString() {
  34665. return this.css
  34666. }
  34667. warn(text, opts = {}) {
  34668. if (!opts.plugin) {
  34669. if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
  34670. opts.plugin = this.lastPlugin.postcssPlugin;
  34671. }
  34672. }
  34673. let warning = new Warning$1(text, opts);
  34674. this.messages.push(warning);
  34675. return warning
  34676. }
  34677. warnings() {
  34678. return this.messages.filter(i => i.type === 'warning')
  34679. }
  34680. get content() {
  34681. return this.css
  34682. }
  34683. };
  34684. var result = Result$3;
  34685. Result$3.default = Result$3;
  34686. let Container$5 = container$1;
  34687. let AtRule$3 = class AtRule extends Container$5 {
  34688. constructor(defaults) {
  34689. super(defaults);
  34690. this.type = 'atrule';
  34691. }
  34692. append(...children) {
  34693. if (!this.proxyOf.nodes) this.nodes = [];
  34694. return super.append(...children)
  34695. }
  34696. prepend(...children) {
  34697. if (!this.proxyOf.nodes) this.nodes = [];
  34698. return super.prepend(...children)
  34699. }
  34700. };
  34701. var atRule = AtRule$3;
  34702. AtRule$3.default = AtRule$3;
  34703. Container$5.registerAtRule(AtRule$3);
  34704. let Container$4 = container$1;
  34705. let LazyResult$3, Processor$2;
  34706. let Root$5 = class Root extends Container$4 {
  34707. constructor(defaults) {
  34708. super(defaults);
  34709. this.type = 'root';
  34710. if (!this.nodes) this.nodes = [];
  34711. }
  34712. normalize(child, sample, type) {
  34713. let nodes = super.normalize(child);
  34714. if (sample) {
  34715. if (type === 'prepend') {
  34716. if (this.nodes.length > 1) {
  34717. sample.raws.before = this.nodes[1].raws.before;
  34718. } else {
  34719. delete sample.raws.before;
  34720. }
  34721. } else if (this.first !== sample) {
  34722. for (let node of nodes) {
  34723. node.raws.before = sample.raws.before;
  34724. }
  34725. }
  34726. }
  34727. return nodes
  34728. }
  34729. removeChild(child, ignore) {
  34730. let index = this.index(child);
  34731. if (!ignore && index === 0 && this.nodes.length > 1) {
  34732. this.nodes[1].raws.before = this.nodes[index].raws.before;
  34733. }
  34734. return super.removeChild(child)
  34735. }
  34736. toResult(opts = {}) {
  34737. let lazy = new LazyResult$3(new Processor$2(), this, opts);
  34738. return lazy.stringify()
  34739. }
  34740. };
  34741. Root$5.registerLazyResult = dependant => {
  34742. LazyResult$3 = dependant;
  34743. };
  34744. Root$5.registerProcessor = dependant => {
  34745. Processor$2 = dependant;
  34746. };
  34747. var root$2 = Root$5;
  34748. Root$5.default = Root$5;
  34749. Container$4.registerRoot(Root$5);
  34750. let list$2 = {
  34751. comma(string) {
  34752. return list$2.split(string, [','], true)
  34753. },
  34754. space(string) {
  34755. let spaces = [' ', '\n', '\t'];
  34756. return list$2.split(string, spaces)
  34757. },
  34758. split(string, separators, last) {
  34759. let array = [];
  34760. let current = '';
  34761. let split = false;
  34762. let func = 0;
  34763. let inQuote = false;
  34764. let prevQuote = '';
  34765. let escape = false;
  34766. for (let letter of string) {
  34767. if (escape) {
  34768. escape = false;
  34769. } else if (letter === '\\') {
  34770. escape = true;
  34771. } else if (inQuote) {
  34772. if (letter === prevQuote) {
  34773. inQuote = false;
  34774. }
  34775. } else if (letter === '"' || letter === "'") {
  34776. inQuote = true;
  34777. prevQuote = letter;
  34778. } else if (letter === '(') {
  34779. func += 1;
  34780. } else if (letter === ')') {
  34781. if (func > 0) func -= 1;
  34782. } else if (func === 0) {
  34783. if (separators.includes(letter)) split = true;
  34784. }
  34785. if (split) {
  34786. if (current !== '') array.push(current.trim());
  34787. current = '';
  34788. split = false;
  34789. } else {
  34790. current += letter;
  34791. }
  34792. }
  34793. if (last || current !== '') array.push(current.trim());
  34794. return array
  34795. }
  34796. };
  34797. var list_1 = list$2;
  34798. list$2.default = list$2;
  34799. let Container$3 = container$1;
  34800. let list$1 = list_1;
  34801. let Rule$3 = class Rule extends Container$3 {
  34802. constructor(defaults) {
  34803. super(defaults);
  34804. this.type = 'rule';
  34805. if (!this.nodes) this.nodes = [];
  34806. }
  34807. get selectors() {
  34808. return list$1.comma(this.selector)
  34809. }
  34810. set selectors(values) {
  34811. let match = this.selector ? this.selector.match(/,\s*/) : null;
  34812. let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  34813. this.selector = values.join(sep);
  34814. }
  34815. };
  34816. var rule = Rule$3;
  34817. Rule$3.default = Rule$3;
  34818. Container$3.registerRule(Rule$3);
  34819. let Declaration$2 = declaration;
  34820. let tokenizer = tokenize$1;
  34821. let Comment$2 = comment$3;
  34822. let AtRule$2 = atRule;
  34823. let Root$4 = root$2;
  34824. let Rule$2 = rule;
  34825. const SAFE_COMMENT_NEIGHBOR = {
  34826. empty: true,
  34827. space: true
  34828. };
  34829. function findLastWithPosition(tokens) {
  34830. for (let i = tokens.length - 1; i >= 0; i--) {
  34831. let token = tokens[i];
  34832. let pos = token[3] || token[2];
  34833. if (pos) return pos
  34834. }
  34835. }
  34836. let Parser$1 = class Parser {
  34837. constructor(input) {
  34838. this.input = input;
  34839. this.root = new Root$4();
  34840. this.current = this.root;
  34841. this.spaces = '';
  34842. this.semicolon = false;
  34843. this.customProperty = false;
  34844. this.createTokenizer();
  34845. this.root.source = { input, start: { column: 1, line: 1, offset: 0 } };
  34846. }
  34847. atrule(token) {
  34848. let node = new AtRule$2();
  34849. node.name = token[1].slice(1);
  34850. if (node.name === '') {
  34851. this.unnamedAtrule(node, token);
  34852. }
  34853. this.init(node, token[2]);
  34854. let type;
  34855. let prev;
  34856. let shift;
  34857. let last = false;
  34858. let open = false;
  34859. let params = [];
  34860. let brackets = [];
  34861. while (!this.tokenizer.endOfFile()) {
  34862. token = this.tokenizer.nextToken();
  34863. type = token[0];
  34864. if (type === '(' || type === '[') {
  34865. brackets.push(type === '(' ? ')' : ']');
  34866. } else if (type === '{' && brackets.length > 0) {
  34867. brackets.push('}');
  34868. } else if (type === brackets[brackets.length - 1]) {
  34869. brackets.pop();
  34870. }
  34871. if (brackets.length === 0) {
  34872. if (type === ';') {
  34873. node.source.end = this.getPosition(token[2]);
  34874. node.source.end.offset++;
  34875. this.semicolon = true;
  34876. break
  34877. } else if (type === '{') {
  34878. open = true;
  34879. break
  34880. } else if (type === '}') {
  34881. if (params.length > 0) {
  34882. shift = params.length - 1;
  34883. prev = params[shift];
  34884. while (prev && prev[0] === 'space') {
  34885. prev = params[--shift];
  34886. }
  34887. if (prev) {
  34888. node.source.end = this.getPosition(prev[3] || prev[2]);
  34889. node.source.end.offset++;
  34890. }
  34891. }
  34892. this.end(token);
  34893. break
  34894. } else {
  34895. params.push(token);
  34896. }
  34897. } else {
  34898. params.push(token);
  34899. }
  34900. if (this.tokenizer.endOfFile()) {
  34901. last = true;
  34902. break
  34903. }
  34904. }
  34905. node.raws.between = this.spacesAndCommentsFromEnd(params);
  34906. if (params.length) {
  34907. node.raws.afterName = this.spacesAndCommentsFromStart(params);
  34908. this.raw(node, 'params', params);
  34909. if (last) {
  34910. token = params[params.length - 1];
  34911. node.source.end = this.getPosition(token[3] || token[2]);
  34912. node.source.end.offset++;
  34913. this.spaces = node.raws.between;
  34914. node.raws.between = '';
  34915. }
  34916. } else {
  34917. node.raws.afterName = '';
  34918. node.params = '';
  34919. }
  34920. if (open) {
  34921. node.nodes = [];
  34922. this.current = node;
  34923. }
  34924. }
  34925. checkMissedSemicolon(tokens) {
  34926. let colon = this.colon(tokens);
  34927. if (colon === false) return
  34928. let founded = 0;
  34929. let token;
  34930. for (let j = colon - 1; j >= 0; j--) {
  34931. token = tokens[j];
  34932. if (token[0] !== 'space') {
  34933. founded += 1;
  34934. if (founded === 2) break
  34935. }
  34936. }
  34937. // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
  34938. // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
  34939. // And because we need it after that one we do +1 to get the next one.
  34940. throw this.input.error(
  34941. 'Missed semicolon',
  34942. token[0] === 'word' ? token[3] + 1 : token[2]
  34943. )
  34944. }
  34945. colon(tokens) {
  34946. let brackets = 0;
  34947. let token, type, prev;
  34948. for (let [i, element] of tokens.entries()) {
  34949. token = element;
  34950. type = token[0];
  34951. if (type === '(') {
  34952. brackets += 1;
  34953. }
  34954. if (type === ')') {
  34955. brackets -= 1;
  34956. }
  34957. if (brackets === 0 && type === ':') {
  34958. if (!prev) {
  34959. this.doubleColon(token);
  34960. } else if (prev[0] === 'word' && prev[1] === 'progid') {
  34961. continue
  34962. } else {
  34963. return i
  34964. }
  34965. }
  34966. prev = token;
  34967. }
  34968. return false
  34969. }
  34970. comment(token) {
  34971. let node = new Comment$2();
  34972. this.init(node, token[2]);
  34973. node.source.end = this.getPosition(token[3] || token[2]);
  34974. node.source.end.offset++;
  34975. let text = token[1].slice(2, -2);
  34976. if (/^\s*$/.test(text)) {
  34977. node.text = '';
  34978. node.raws.left = text;
  34979. node.raws.right = '';
  34980. } else {
  34981. let match = text.match(/^(\s*)([^]*\S)(\s*)$/);
  34982. node.text = match[2];
  34983. node.raws.left = match[1];
  34984. node.raws.right = match[3];
  34985. }
  34986. }
  34987. createTokenizer() {
  34988. this.tokenizer = tokenizer(this.input);
  34989. }
  34990. decl(tokens, customProperty) {
  34991. let node = new Declaration$2();
  34992. this.init(node, tokens[0][2]);
  34993. let last = tokens[tokens.length - 1];
  34994. if (last[0] === ';') {
  34995. this.semicolon = true;
  34996. tokens.pop();
  34997. }
  34998. node.source.end = this.getPosition(
  34999. last[3] || last[2] || findLastWithPosition(tokens)
  35000. );
  35001. node.source.end.offset++;
  35002. while (tokens[0][0] !== 'word') {
  35003. if (tokens.length === 1) this.unknownWord(tokens);
  35004. node.raws.before += tokens.shift()[1];
  35005. }
  35006. node.source.start = this.getPosition(tokens[0][2]);
  35007. node.prop = '';
  35008. while (tokens.length) {
  35009. let type = tokens[0][0];
  35010. if (type === ':' || type === 'space' || type === 'comment') {
  35011. break
  35012. }
  35013. node.prop += tokens.shift()[1];
  35014. }
  35015. node.raws.between = '';
  35016. let token;
  35017. while (tokens.length) {
  35018. token = tokens.shift();
  35019. if (token[0] === ':') {
  35020. node.raws.between += token[1];
  35021. break
  35022. } else {
  35023. if (token[0] === 'word' && /\w/.test(token[1])) {
  35024. this.unknownWord([token]);
  35025. }
  35026. node.raws.between += token[1];
  35027. }
  35028. }
  35029. if (node.prop[0] === '_' || node.prop[0] === '*') {
  35030. node.raws.before += node.prop[0];
  35031. node.prop = node.prop.slice(1);
  35032. }
  35033. let firstSpaces = [];
  35034. let next;
  35035. while (tokens.length) {
  35036. next = tokens[0][0];
  35037. if (next !== 'space' && next !== 'comment') break
  35038. firstSpaces.push(tokens.shift());
  35039. }
  35040. this.precheckMissedSemicolon(tokens);
  35041. for (let i = tokens.length - 1; i >= 0; i--) {
  35042. token = tokens[i];
  35043. if (token[1].toLowerCase() === '!important') {
  35044. node.important = true;
  35045. let string = this.stringFrom(tokens, i);
  35046. string = this.spacesFromEnd(tokens) + string;
  35047. if (string !== ' !important') node.raws.important = string;
  35048. break
  35049. } else if (token[1].toLowerCase() === 'important') {
  35050. let cache = tokens.slice(0);
  35051. let str = '';
  35052. for (let j = i; j > 0; j--) {
  35053. let type = cache[j][0];
  35054. if (str.trim().indexOf('!') === 0 && type !== 'space') {
  35055. break
  35056. }
  35057. str = cache.pop()[1] + str;
  35058. }
  35059. if (str.trim().indexOf('!') === 0) {
  35060. node.important = true;
  35061. node.raws.important = str;
  35062. tokens = cache;
  35063. }
  35064. }
  35065. if (token[0] !== 'space' && token[0] !== 'comment') {
  35066. break
  35067. }
  35068. }
  35069. let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment');
  35070. if (hasWord) {
  35071. node.raws.between += firstSpaces.map(i => i[1]).join('');
  35072. firstSpaces = [];
  35073. }
  35074. this.raw(node, 'value', firstSpaces.concat(tokens), customProperty);
  35075. if (node.value.includes(':') && !customProperty) {
  35076. this.checkMissedSemicolon(tokens);
  35077. }
  35078. }
  35079. doubleColon(token) {
  35080. throw this.input.error(
  35081. 'Double colon',
  35082. { offset: token[2] },
  35083. { offset: token[2] + token[1].length }
  35084. )
  35085. }
  35086. emptyRule(token) {
  35087. let node = new Rule$2();
  35088. this.init(node, token[2]);
  35089. node.selector = '';
  35090. node.raws.between = '';
  35091. this.current = node;
  35092. }
  35093. end(token) {
  35094. if (this.current.nodes && this.current.nodes.length) {
  35095. this.current.raws.semicolon = this.semicolon;
  35096. }
  35097. this.semicolon = false;
  35098. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35099. this.spaces = '';
  35100. if (this.current.parent) {
  35101. this.current.source.end = this.getPosition(token[2]);
  35102. this.current.source.end.offset++;
  35103. this.current = this.current.parent;
  35104. } else {
  35105. this.unexpectedClose(token);
  35106. }
  35107. }
  35108. endFile() {
  35109. if (this.current.parent) this.unclosedBlock();
  35110. if (this.current.nodes && this.current.nodes.length) {
  35111. this.current.raws.semicolon = this.semicolon;
  35112. }
  35113. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35114. this.root.source.end = this.getPosition(this.tokenizer.position());
  35115. }
  35116. freeSemicolon(token) {
  35117. this.spaces += token[1];
  35118. if (this.current.nodes) {
  35119. let prev = this.current.nodes[this.current.nodes.length - 1];
  35120. if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
  35121. prev.raws.ownSemicolon = this.spaces;
  35122. this.spaces = '';
  35123. }
  35124. }
  35125. }
  35126. // Helpers
  35127. getPosition(offset) {
  35128. let pos = this.input.fromOffset(offset);
  35129. return {
  35130. column: pos.col,
  35131. line: pos.line,
  35132. offset
  35133. }
  35134. }
  35135. init(node, offset) {
  35136. this.current.push(node);
  35137. node.source = {
  35138. input: this.input,
  35139. start: this.getPosition(offset)
  35140. };
  35141. node.raws.before = this.spaces;
  35142. this.spaces = '';
  35143. if (node.type !== 'comment') this.semicolon = false;
  35144. }
  35145. other(start) {
  35146. let end = false;
  35147. let type = null;
  35148. let colon = false;
  35149. let bracket = null;
  35150. let brackets = [];
  35151. let customProperty = start[1].startsWith('--');
  35152. let tokens = [];
  35153. let token = start;
  35154. while (token) {
  35155. type = token[0];
  35156. tokens.push(token);
  35157. if (type === '(' || type === '[') {
  35158. if (!bracket) bracket = token;
  35159. brackets.push(type === '(' ? ')' : ']');
  35160. } else if (customProperty && colon && type === '{') {
  35161. if (!bracket) bracket = token;
  35162. brackets.push('}');
  35163. } else if (brackets.length === 0) {
  35164. if (type === ';') {
  35165. if (colon) {
  35166. this.decl(tokens, customProperty);
  35167. return
  35168. } else {
  35169. break
  35170. }
  35171. } else if (type === '{') {
  35172. this.rule(tokens);
  35173. return
  35174. } else if (type === '}') {
  35175. this.tokenizer.back(tokens.pop());
  35176. end = true;
  35177. break
  35178. } else if (type === ':') {
  35179. colon = true;
  35180. }
  35181. } else if (type === brackets[brackets.length - 1]) {
  35182. brackets.pop();
  35183. if (brackets.length === 0) bracket = null;
  35184. }
  35185. token = this.tokenizer.nextToken();
  35186. }
  35187. if (this.tokenizer.endOfFile()) end = true;
  35188. if (brackets.length > 0) this.unclosedBracket(bracket);
  35189. if (end && colon) {
  35190. if (!customProperty) {
  35191. while (tokens.length) {
  35192. token = tokens[tokens.length - 1][0];
  35193. if (token !== 'space' && token !== 'comment') break
  35194. this.tokenizer.back(tokens.pop());
  35195. }
  35196. }
  35197. this.decl(tokens, customProperty);
  35198. } else {
  35199. this.unknownWord(tokens);
  35200. }
  35201. }
  35202. parse() {
  35203. let token;
  35204. while (!this.tokenizer.endOfFile()) {
  35205. token = this.tokenizer.nextToken();
  35206. switch (token[0]) {
  35207. case 'space':
  35208. this.spaces += token[1];
  35209. break
  35210. case ';':
  35211. this.freeSemicolon(token);
  35212. break
  35213. case '}':
  35214. this.end(token);
  35215. break
  35216. case 'comment':
  35217. this.comment(token);
  35218. break
  35219. case 'at-word':
  35220. this.atrule(token);
  35221. break
  35222. case '{':
  35223. this.emptyRule(token);
  35224. break
  35225. default:
  35226. this.other(token);
  35227. break
  35228. }
  35229. }
  35230. this.endFile();
  35231. }
  35232. precheckMissedSemicolon(/* tokens */) {
  35233. // Hook for Safe Parser
  35234. }
  35235. raw(node, prop, tokens, customProperty) {
  35236. let token, type;
  35237. let length = tokens.length;
  35238. let value = '';
  35239. let clean = true;
  35240. let next, prev;
  35241. for (let i = 0; i < length; i += 1) {
  35242. token = tokens[i];
  35243. type = token[0];
  35244. if (type === 'space' && i === length - 1 && !customProperty) {
  35245. clean = false;
  35246. } else if (type === 'comment') {
  35247. prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty';
  35248. next = tokens[i + 1] ? tokens[i + 1][0] : 'empty';
  35249. if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
  35250. if (value.slice(-1) === ',') {
  35251. clean = false;
  35252. } else {
  35253. value += token[1];
  35254. }
  35255. } else {
  35256. clean = false;
  35257. }
  35258. } else {
  35259. value += token[1];
  35260. }
  35261. }
  35262. if (!clean) {
  35263. let raw = tokens.reduce((all, i) => all + i[1], '');
  35264. node.raws[prop] = { raw, value };
  35265. }
  35266. node[prop] = value;
  35267. }
  35268. rule(tokens) {
  35269. tokens.pop();
  35270. let node = new Rule$2();
  35271. this.init(node, tokens[0][2]);
  35272. node.raws.between = this.spacesAndCommentsFromEnd(tokens);
  35273. this.raw(node, 'selector', tokens);
  35274. this.current = node;
  35275. }
  35276. spacesAndCommentsFromEnd(tokens) {
  35277. let lastTokenType;
  35278. let spaces = '';
  35279. while (tokens.length) {
  35280. lastTokenType = tokens[tokens.length - 1][0];
  35281. if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
  35282. spaces = tokens.pop()[1] + spaces;
  35283. }
  35284. return spaces
  35285. }
  35286. // Errors
  35287. spacesAndCommentsFromStart(tokens) {
  35288. let next;
  35289. let spaces = '';
  35290. while (tokens.length) {
  35291. next = tokens[0][0];
  35292. if (next !== 'space' && next !== 'comment') break
  35293. spaces += tokens.shift()[1];
  35294. }
  35295. return spaces
  35296. }
  35297. spacesFromEnd(tokens) {
  35298. let lastTokenType;
  35299. let spaces = '';
  35300. while (tokens.length) {
  35301. lastTokenType = tokens[tokens.length - 1][0];
  35302. if (lastTokenType !== 'space') break
  35303. spaces = tokens.pop()[1] + spaces;
  35304. }
  35305. return spaces
  35306. }
  35307. stringFrom(tokens, from) {
  35308. let result = '';
  35309. for (let i = from; i < tokens.length; i++) {
  35310. result += tokens[i][1];
  35311. }
  35312. tokens.splice(from, tokens.length - from);
  35313. return result
  35314. }
  35315. unclosedBlock() {
  35316. let pos = this.current.source.start;
  35317. throw this.input.error('Unclosed block', pos.line, pos.column)
  35318. }
  35319. unclosedBracket(bracket) {
  35320. throw this.input.error(
  35321. 'Unclosed bracket',
  35322. { offset: bracket[2] },
  35323. { offset: bracket[2] + 1 }
  35324. )
  35325. }
  35326. unexpectedClose(token) {
  35327. throw this.input.error(
  35328. 'Unexpected }',
  35329. { offset: token[2] },
  35330. { offset: token[2] + 1 }
  35331. )
  35332. }
  35333. unknownWord(tokens) {
  35334. throw this.input.error(
  35335. 'Unknown word',
  35336. { offset: tokens[0][2] },
  35337. { offset: tokens[0][2] + tokens[0][1].length }
  35338. )
  35339. }
  35340. unnamedAtrule(node, token) {
  35341. throw this.input.error(
  35342. 'At-rule without name',
  35343. { offset: token[2] },
  35344. { offset: token[2] + token[1].length }
  35345. )
  35346. }
  35347. };
  35348. var parser$1 = Parser$1;
  35349. let Container$2 = container$1;
  35350. let Parser = parser$1;
  35351. let Input$2 = input;
  35352. function parse$3(css, opts) {
  35353. let input = new Input$2(css, opts);
  35354. let parser = new Parser(input);
  35355. try {
  35356. parser.parse();
  35357. } catch (e) {
  35358. if (browser$1.env.NODE_ENV !== 'production') {
  35359. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  35360. if (/\.scss$/i.test(opts.from)) {
  35361. e.message +=
  35362. '\nYou tried to parse SCSS with ' +
  35363. 'the standard CSS parser; ' +
  35364. 'try again with the postcss-scss parser';
  35365. } else if (/\.sass/i.test(opts.from)) {
  35366. e.message +=
  35367. '\nYou tried to parse Sass with ' +
  35368. 'the standard CSS parser; ' +
  35369. 'try again with the postcss-sass parser';
  35370. } else if (/\.less$/i.test(opts.from)) {
  35371. e.message +=
  35372. '\nYou tried to parse Less with ' +
  35373. 'the standard CSS parser; ' +
  35374. 'try again with the postcss-less parser';
  35375. }
  35376. }
  35377. }
  35378. throw e
  35379. }
  35380. return parser.root
  35381. }
  35382. var parse_1 = parse$3;
  35383. parse$3.default = parse$3;
  35384. Container$2.registerParse(parse$3);
  35385. let { isClean, my } = symbols;
  35386. let MapGenerator$1 = mapGenerator;
  35387. let stringify$2 = stringify_1;
  35388. let Container$1 = container$1;
  35389. let Document$2 = document;
  35390. let warnOnce$2 = warnOnce$3;
  35391. let Result$2 = result;
  35392. let parse$2 = parse_1;
  35393. let Root$3 = root$2;
  35394. const TYPE_TO_CLASS_NAME = {
  35395. atrule: 'AtRule',
  35396. comment: 'Comment',
  35397. decl: 'Declaration',
  35398. document: 'Document',
  35399. root: 'Root',
  35400. rule: 'Rule'
  35401. };
  35402. const PLUGIN_PROPS = {
  35403. AtRule: true,
  35404. AtRuleExit: true,
  35405. Comment: true,
  35406. CommentExit: true,
  35407. Declaration: true,
  35408. DeclarationExit: true,
  35409. Document: true,
  35410. DocumentExit: true,
  35411. Once: true,
  35412. OnceExit: true,
  35413. postcssPlugin: true,
  35414. prepare: true,
  35415. Root: true,
  35416. RootExit: true,
  35417. Rule: true,
  35418. RuleExit: true
  35419. };
  35420. const NOT_VISITORS = {
  35421. Once: true,
  35422. postcssPlugin: true,
  35423. prepare: true
  35424. };
  35425. const CHILDREN = 0;
  35426. function isPromise(obj) {
  35427. return typeof obj === 'object' && typeof obj.then === 'function'
  35428. }
  35429. function getEvents(node) {
  35430. let key = false;
  35431. let type = TYPE_TO_CLASS_NAME[node.type];
  35432. if (node.type === 'decl') {
  35433. key = node.prop.toLowerCase();
  35434. } else if (node.type === 'atrule') {
  35435. key = node.name.toLowerCase();
  35436. }
  35437. if (key && node.append) {
  35438. return [
  35439. type,
  35440. type + '-' + key,
  35441. CHILDREN,
  35442. type + 'Exit',
  35443. type + 'Exit-' + key
  35444. ]
  35445. } else if (key) {
  35446. return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
  35447. } else if (node.append) {
  35448. return [type, CHILDREN, type + 'Exit']
  35449. } else {
  35450. return [type, type + 'Exit']
  35451. }
  35452. }
  35453. function toStack(node) {
  35454. let events;
  35455. if (node.type === 'document') {
  35456. events = ['Document', CHILDREN, 'DocumentExit'];
  35457. } else if (node.type === 'root') {
  35458. events = ['Root', CHILDREN, 'RootExit'];
  35459. } else {
  35460. events = getEvents(node);
  35461. }
  35462. return {
  35463. eventIndex: 0,
  35464. events,
  35465. iterator: 0,
  35466. node,
  35467. visitorIndex: 0,
  35468. visitors: []
  35469. }
  35470. }
  35471. function cleanMarks(node) {
  35472. node[isClean] = false;
  35473. if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
  35474. return node
  35475. }
  35476. let postcss$2 = {};
  35477. let LazyResult$2 = class LazyResult {
  35478. constructor(processor, css, opts) {
  35479. this.stringified = false;
  35480. this.processed = false;
  35481. let root;
  35482. if (
  35483. typeof css === 'object' &&
  35484. css !== null &&
  35485. (css.type === 'root' || css.type === 'document')
  35486. ) {
  35487. root = cleanMarks(css);
  35488. } else if (css instanceof LazyResult || css instanceof Result$2) {
  35489. root = cleanMarks(css.root);
  35490. if (css.map) {
  35491. if (typeof opts.map === 'undefined') opts.map = {};
  35492. if (!opts.map.inline) opts.map.inline = false;
  35493. opts.map.prev = css.map;
  35494. }
  35495. } else {
  35496. let parser = parse$2;
  35497. if (opts.syntax) parser = opts.syntax.parse;
  35498. if (opts.parser) parser = opts.parser;
  35499. if (parser.parse) parser = parser.parse;
  35500. try {
  35501. root = parser(css, opts);
  35502. } catch (error) {
  35503. this.processed = true;
  35504. this.error = error;
  35505. }
  35506. if (root && !root[my]) {
  35507. /* c8 ignore next 2 */
  35508. Container$1.rebuild(root);
  35509. }
  35510. }
  35511. this.result = new Result$2(processor, root, opts);
  35512. this.helpers = { ...postcss$2, postcss: postcss$2, result: this.result };
  35513. this.plugins = this.processor.plugins.map(plugin => {
  35514. if (typeof plugin === 'object' && plugin.prepare) {
  35515. return { ...plugin, ...plugin.prepare(this.result) }
  35516. } else {
  35517. return plugin
  35518. }
  35519. });
  35520. }
  35521. async() {
  35522. if (this.error) return Promise.reject(this.error)
  35523. if (this.processed) return Promise.resolve(this.result)
  35524. if (!this.processing) {
  35525. this.processing = this.runAsync();
  35526. }
  35527. return this.processing
  35528. }
  35529. catch(onRejected) {
  35530. return this.async().catch(onRejected)
  35531. }
  35532. finally(onFinally) {
  35533. return this.async().then(onFinally, onFinally)
  35534. }
  35535. getAsyncError() {
  35536. throw new Error('Use process(css).then(cb) to work with async plugins')
  35537. }
  35538. handleError(error, node) {
  35539. let plugin = this.result.lastPlugin;
  35540. try {
  35541. if (node) node.addToError(error);
  35542. this.error = error;
  35543. if (error.name === 'CssSyntaxError' && !error.plugin) {
  35544. error.plugin = plugin.postcssPlugin;
  35545. error.setMessage();
  35546. } else if (plugin.postcssVersion) {
  35547. if (browser$1.env.NODE_ENV !== 'production') {
  35548. let pluginName = plugin.postcssPlugin;
  35549. let pluginVer = plugin.postcssVersion;
  35550. let runtimeVer = this.result.processor.version;
  35551. let a = pluginVer.split('.');
  35552. let b = runtimeVer.split('.');
  35553. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  35554. // eslint-disable-next-line no-console
  35555. console.error(
  35556. 'Unknown error from PostCSS plugin. Your current PostCSS ' +
  35557. 'version is ' +
  35558. runtimeVer +
  35559. ', but ' +
  35560. pluginName +
  35561. ' uses ' +
  35562. pluginVer +
  35563. '. Perhaps this is the source of the error below.'
  35564. );
  35565. }
  35566. }
  35567. }
  35568. } catch (err) {
  35569. /* c8 ignore next 3 */
  35570. // eslint-disable-next-line no-console
  35571. if (console && console.error) console.error(err);
  35572. }
  35573. return error
  35574. }
  35575. prepareVisitors() {
  35576. this.listeners = {};
  35577. let add = (plugin, type, cb) => {
  35578. if (!this.listeners[type]) this.listeners[type] = [];
  35579. this.listeners[type].push([plugin, cb]);
  35580. };
  35581. for (let plugin of this.plugins) {
  35582. if (typeof plugin === 'object') {
  35583. for (let event in plugin) {
  35584. if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
  35585. throw new Error(
  35586. `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
  35587. `Try to update PostCSS (${this.processor.version} now).`
  35588. )
  35589. }
  35590. if (!NOT_VISITORS[event]) {
  35591. if (typeof plugin[event] === 'object') {
  35592. for (let filter in plugin[event]) {
  35593. if (filter === '*') {
  35594. add(plugin, event, plugin[event][filter]);
  35595. } else {
  35596. add(
  35597. plugin,
  35598. event + '-' + filter.toLowerCase(),
  35599. plugin[event][filter]
  35600. );
  35601. }
  35602. }
  35603. } else if (typeof plugin[event] === 'function') {
  35604. add(plugin, event, plugin[event]);
  35605. }
  35606. }
  35607. }
  35608. }
  35609. }
  35610. this.hasListener = Object.keys(this.listeners).length > 0;
  35611. }
  35612. async runAsync() {
  35613. this.plugin = 0;
  35614. for (let i = 0; i < this.plugins.length; i++) {
  35615. let plugin = this.plugins[i];
  35616. let promise = this.runOnRoot(plugin);
  35617. if (isPromise(promise)) {
  35618. try {
  35619. await promise;
  35620. } catch (error) {
  35621. throw this.handleError(error)
  35622. }
  35623. }
  35624. }
  35625. this.prepareVisitors();
  35626. if (this.hasListener) {
  35627. let root = this.result.root;
  35628. while (!root[isClean]) {
  35629. root[isClean] = true;
  35630. let stack = [toStack(root)];
  35631. while (stack.length > 0) {
  35632. let promise = this.visitTick(stack);
  35633. if (isPromise(promise)) {
  35634. try {
  35635. await promise;
  35636. } catch (e) {
  35637. let node = stack[stack.length - 1].node;
  35638. throw this.handleError(e, node)
  35639. }
  35640. }
  35641. }
  35642. }
  35643. if (this.listeners.OnceExit) {
  35644. for (let [plugin, visitor] of this.listeners.OnceExit) {
  35645. this.result.lastPlugin = plugin;
  35646. try {
  35647. if (root.type === 'document') {
  35648. let roots = root.nodes.map(subRoot =>
  35649. visitor(subRoot, this.helpers)
  35650. );
  35651. await Promise.all(roots);
  35652. } else {
  35653. await visitor(root, this.helpers);
  35654. }
  35655. } catch (e) {
  35656. throw this.handleError(e)
  35657. }
  35658. }
  35659. }
  35660. }
  35661. this.processed = true;
  35662. return this.stringify()
  35663. }
  35664. runOnRoot(plugin) {
  35665. this.result.lastPlugin = plugin;
  35666. try {
  35667. if (typeof plugin === 'object' && plugin.Once) {
  35668. if (this.result.root.type === 'document') {
  35669. let roots = this.result.root.nodes.map(root =>
  35670. plugin.Once(root, this.helpers)
  35671. );
  35672. if (isPromise(roots[0])) {
  35673. return Promise.all(roots)
  35674. }
  35675. return roots
  35676. }
  35677. return plugin.Once(this.result.root, this.helpers)
  35678. } else if (typeof plugin === 'function') {
  35679. return plugin(this.result.root, this.result)
  35680. }
  35681. } catch (error) {
  35682. throw this.handleError(error)
  35683. }
  35684. }
  35685. stringify() {
  35686. if (this.error) throw this.error
  35687. if (this.stringified) return this.result
  35688. this.stringified = true;
  35689. this.sync();
  35690. let opts = this.result.opts;
  35691. let str = stringify$2;
  35692. if (opts.syntax) str = opts.syntax.stringify;
  35693. if (opts.stringifier) str = opts.stringifier;
  35694. if (str.stringify) str = str.stringify;
  35695. let map = new MapGenerator$1(str, this.result.root, this.result.opts);
  35696. let data = map.generate();
  35697. this.result.css = data[0];
  35698. this.result.map = data[1];
  35699. return this.result
  35700. }
  35701. sync() {
  35702. if (this.error) throw this.error
  35703. if (this.processed) return this.result
  35704. this.processed = true;
  35705. if (this.processing) {
  35706. throw this.getAsyncError()
  35707. }
  35708. for (let plugin of this.plugins) {
  35709. let promise = this.runOnRoot(plugin);
  35710. if (isPromise(promise)) {
  35711. throw this.getAsyncError()
  35712. }
  35713. }
  35714. this.prepareVisitors();
  35715. if (this.hasListener) {
  35716. let root = this.result.root;
  35717. while (!root[isClean]) {
  35718. root[isClean] = true;
  35719. this.walkSync(root);
  35720. }
  35721. if (this.listeners.OnceExit) {
  35722. if (root.type === 'document') {
  35723. for (let subRoot of root.nodes) {
  35724. this.visitSync(this.listeners.OnceExit, subRoot);
  35725. }
  35726. } else {
  35727. this.visitSync(this.listeners.OnceExit, root);
  35728. }
  35729. }
  35730. }
  35731. return this.result
  35732. }
  35733. then(onFulfilled, onRejected) {
  35734. if (browser$1.env.NODE_ENV !== 'production') {
  35735. if (!('from' in this.opts)) {
  35736. warnOnce$2(
  35737. 'Without `from` option PostCSS could generate wrong source map ' +
  35738. 'and will not find Browserslist config. Set it to CSS file path ' +
  35739. 'or to `undefined` to prevent this warning.'
  35740. );
  35741. }
  35742. }
  35743. return this.async().then(onFulfilled, onRejected)
  35744. }
  35745. toString() {
  35746. return this.css
  35747. }
  35748. visitSync(visitors, node) {
  35749. for (let [plugin, visitor] of visitors) {
  35750. this.result.lastPlugin = plugin;
  35751. let promise;
  35752. try {
  35753. promise = visitor(node, this.helpers);
  35754. } catch (e) {
  35755. throw this.handleError(e, node.proxyOf)
  35756. }
  35757. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  35758. return true
  35759. }
  35760. if (isPromise(promise)) {
  35761. throw this.getAsyncError()
  35762. }
  35763. }
  35764. }
  35765. visitTick(stack) {
  35766. let visit = stack[stack.length - 1];
  35767. let { node, visitors } = visit;
  35768. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  35769. stack.pop();
  35770. return
  35771. }
  35772. if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
  35773. let [plugin, visitor] = visitors[visit.visitorIndex];
  35774. visit.visitorIndex += 1;
  35775. if (visit.visitorIndex === visitors.length) {
  35776. visit.visitors = [];
  35777. visit.visitorIndex = 0;
  35778. }
  35779. this.result.lastPlugin = plugin;
  35780. try {
  35781. return visitor(node.toProxy(), this.helpers)
  35782. } catch (e) {
  35783. throw this.handleError(e, node)
  35784. }
  35785. }
  35786. if (visit.iterator !== 0) {
  35787. let iterator = visit.iterator;
  35788. let child;
  35789. while ((child = node.nodes[node.indexes[iterator]])) {
  35790. node.indexes[iterator] += 1;
  35791. if (!child[isClean]) {
  35792. child[isClean] = true;
  35793. stack.push(toStack(child));
  35794. return
  35795. }
  35796. }
  35797. visit.iterator = 0;
  35798. delete node.indexes[iterator];
  35799. }
  35800. let events = visit.events;
  35801. while (visit.eventIndex < events.length) {
  35802. let event = events[visit.eventIndex];
  35803. visit.eventIndex += 1;
  35804. if (event === CHILDREN) {
  35805. if (node.nodes && node.nodes.length) {
  35806. node[isClean] = true;
  35807. visit.iterator = node.getIterator();
  35808. }
  35809. return
  35810. } else if (this.listeners[event]) {
  35811. visit.visitors = this.listeners[event];
  35812. return
  35813. }
  35814. }
  35815. stack.pop();
  35816. }
  35817. walkSync(node) {
  35818. node[isClean] = true;
  35819. let events = getEvents(node);
  35820. for (let event of events) {
  35821. if (event === CHILDREN) {
  35822. if (node.nodes) {
  35823. node.each(child => {
  35824. if (!child[isClean]) this.walkSync(child);
  35825. });
  35826. }
  35827. } else {
  35828. let visitors = this.listeners[event];
  35829. if (visitors) {
  35830. if (this.visitSync(visitors, node.toProxy())) return
  35831. }
  35832. }
  35833. }
  35834. }
  35835. warnings() {
  35836. return this.sync().warnings()
  35837. }
  35838. get content() {
  35839. return this.stringify().content
  35840. }
  35841. get css() {
  35842. return this.stringify().css
  35843. }
  35844. get map() {
  35845. return this.stringify().map
  35846. }
  35847. get messages() {
  35848. return this.sync().messages
  35849. }
  35850. get opts() {
  35851. return this.result.opts
  35852. }
  35853. get processor() {
  35854. return this.result.processor
  35855. }
  35856. get root() {
  35857. return this.sync().root
  35858. }
  35859. get [Symbol.toStringTag]() {
  35860. return 'LazyResult'
  35861. }
  35862. };
  35863. LazyResult$2.registerPostcss = dependant => {
  35864. postcss$2 = dependant;
  35865. };
  35866. var lazyResult = LazyResult$2;
  35867. LazyResult$2.default = LazyResult$2;
  35868. Root$3.registerLazyResult(LazyResult$2);
  35869. Document$2.registerLazyResult(LazyResult$2);
  35870. let MapGenerator = mapGenerator;
  35871. let stringify$1 = stringify_1;
  35872. let warnOnce$1 = warnOnce$3;
  35873. let parse$1 = parse_1;
  35874. const Result$1 = result;
  35875. let NoWorkResult$1 = class NoWorkResult {
  35876. constructor(processor, css, opts) {
  35877. css = css.toString();
  35878. this.stringified = false;
  35879. this._processor = processor;
  35880. this._css = css;
  35881. this._opts = opts;
  35882. this._map = undefined;
  35883. let root;
  35884. let str = stringify$1;
  35885. this.result = new Result$1(this._processor, root, this._opts);
  35886. this.result.css = css;
  35887. let self = this;
  35888. Object.defineProperty(this.result, 'root', {
  35889. get() {
  35890. return self.root
  35891. }
  35892. });
  35893. let map = new MapGenerator(str, root, this._opts, css);
  35894. if (map.isMap()) {
  35895. let [generatedCSS, generatedMap] = map.generate();
  35896. if (generatedCSS) {
  35897. this.result.css = generatedCSS;
  35898. }
  35899. if (generatedMap) {
  35900. this.result.map = generatedMap;
  35901. }
  35902. }
  35903. }
  35904. async() {
  35905. if (this.error) return Promise.reject(this.error)
  35906. return Promise.resolve(this.result)
  35907. }
  35908. catch(onRejected) {
  35909. return this.async().catch(onRejected)
  35910. }
  35911. finally(onFinally) {
  35912. return this.async().then(onFinally, onFinally)
  35913. }
  35914. sync() {
  35915. if (this.error) throw this.error
  35916. return this.result
  35917. }
  35918. then(onFulfilled, onRejected) {
  35919. if (browser$1.env.NODE_ENV !== 'production') {
  35920. if (!('from' in this._opts)) {
  35921. warnOnce$1(
  35922. 'Without `from` option PostCSS could generate wrong source map ' +
  35923. 'and will not find Browserslist config. Set it to CSS file path ' +
  35924. 'or to `undefined` to prevent this warning.'
  35925. );
  35926. }
  35927. }
  35928. return this.async().then(onFulfilled, onRejected)
  35929. }
  35930. toString() {
  35931. return this._css
  35932. }
  35933. warnings() {
  35934. return []
  35935. }
  35936. get content() {
  35937. return this.result.css
  35938. }
  35939. get css() {
  35940. return this.result.css
  35941. }
  35942. get map() {
  35943. return this.result.map
  35944. }
  35945. get messages() {
  35946. return []
  35947. }
  35948. get opts() {
  35949. return this.result.opts
  35950. }
  35951. get processor() {
  35952. return this.result.processor
  35953. }
  35954. get root() {
  35955. if (this._root) {
  35956. return this._root
  35957. }
  35958. let root;
  35959. let parser = parse$1;
  35960. try {
  35961. root = parser(this._css, this._opts);
  35962. } catch (error) {
  35963. this.error = error;
  35964. }
  35965. if (this.error) {
  35966. throw this.error
  35967. } else {
  35968. this._root = root;
  35969. return root
  35970. }
  35971. }
  35972. get [Symbol.toStringTag]() {
  35973. return 'NoWorkResult'
  35974. }
  35975. };
  35976. var noWorkResult = NoWorkResult$1;
  35977. NoWorkResult$1.default = NoWorkResult$1;
  35978. let NoWorkResult = noWorkResult;
  35979. let LazyResult$1 = lazyResult;
  35980. let Document$1 = document;
  35981. let Root$2 = root$2;
  35982. let Processor$1 = class Processor {
  35983. constructor(plugins = []) {
  35984. this.version = '8.4.32';
  35985. this.plugins = this.normalize(plugins);
  35986. }
  35987. normalize(plugins) {
  35988. let normalized = [];
  35989. for (let i of plugins) {
  35990. if (i.postcss === true) {
  35991. i = i();
  35992. } else if (i.postcss) {
  35993. i = i.postcss;
  35994. }
  35995. if (typeof i === 'object' && Array.isArray(i.plugins)) {
  35996. normalized = normalized.concat(i.plugins);
  35997. } else if (typeof i === 'object' && i.postcssPlugin) {
  35998. normalized.push(i);
  35999. } else if (typeof i === 'function') {
  36000. normalized.push(i);
  36001. } else if (typeof i === 'object' && (i.parse || i.stringify)) {
  36002. if (browser$1.env.NODE_ENV !== 'production') {
  36003. throw new Error(
  36004. 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
  36005. 'one of the syntax/parser/stringifier options as outlined ' +
  36006. 'in your PostCSS runner documentation.'
  36007. )
  36008. }
  36009. } else {
  36010. throw new Error(i + ' is not a PostCSS plugin')
  36011. }
  36012. }
  36013. return normalized
  36014. }
  36015. process(css, opts = {}) {
  36016. if (
  36017. this.plugins.length === 0 &&
  36018. typeof opts.parser === 'undefined' &&
  36019. typeof opts.stringifier === 'undefined' &&
  36020. typeof opts.syntax === 'undefined'
  36021. ) {
  36022. return new NoWorkResult(this, css, opts)
  36023. } else {
  36024. return new LazyResult$1(this, css, opts)
  36025. }
  36026. }
  36027. use(plugin) {
  36028. this.plugins = this.plugins.concat(this.normalize([plugin]));
  36029. return this
  36030. }
  36031. };
  36032. var processor$1 = Processor$1;
  36033. Processor$1.default = Processor$1;
  36034. Root$2.registerProcessor(Processor$1);
  36035. Document$1.registerProcessor(Processor$1);
  36036. let Declaration$1 = declaration;
  36037. let PreviousMap = previousMap;
  36038. let Comment$1 = comment$3;
  36039. let AtRule$1 = atRule;
  36040. let Input$1 = input;
  36041. let Root$1 = root$2;
  36042. let Rule$1 = rule;
  36043. function fromJSON$1(json, inputs) {
  36044. if (Array.isArray(json)) return json.map(n => fromJSON$1(n))
  36045. let { inputs: ownInputs, ...defaults } = json;
  36046. if (ownInputs) {
  36047. inputs = [];
  36048. for (let input of ownInputs) {
  36049. let inputHydrated = { ...input, __proto__: Input$1.prototype };
  36050. if (inputHydrated.map) {
  36051. inputHydrated.map = {
  36052. ...inputHydrated.map,
  36053. __proto__: PreviousMap.prototype
  36054. };
  36055. }
  36056. inputs.push(inputHydrated);
  36057. }
  36058. }
  36059. if (defaults.nodes) {
  36060. defaults.nodes = json.nodes.map(n => fromJSON$1(n, inputs));
  36061. }
  36062. if (defaults.source) {
  36063. let { inputId, ...source } = defaults.source;
  36064. defaults.source = source;
  36065. if (inputId != null) {
  36066. defaults.source.input = inputs[inputId];
  36067. }
  36068. }
  36069. if (defaults.type === 'root') {
  36070. return new Root$1(defaults)
  36071. } else if (defaults.type === 'decl') {
  36072. return new Declaration$1(defaults)
  36073. } else if (defaults.type === 'rule') {
  36074. return new Rule$1(defaults)
  36075. } else if (defaults.type === 'comment') {
  36076. return new Comment$1(defaults)
  36077. } else if (defaults.type === 'atrule') {
  36078. return new AtRule$1(defaults)
  36079. } else {
  36080. throw new Error('Unknown node type: ' + json.type)
  36081. }
  36082. }
  36083. var fromJSON_1 = fromJSON$1;
  36084. fromJSON$1.default = fromJSON$1;
  36085. let CssSyntaxError = cssSyntaxError;
  36086. let Declaration = declaration;
  36087. let LazyResult = lazyResult;
  36088. let Container = container$1;
  36089. let Processor = processor$1;
  36090. let stringify = stringify_1;
  36091. let fromJSON = fromJSON_1;
  36092. let Document = document;
  36093. let Warning = warning;
  36094. let Comment = comment$3;
  36095. let AtRule = atRule;
  36096. let Result = result;
  36097. let Input = input;
  36098. let parse = parse_1;
  36099. let list = list_1;
  36100. let Rule = rule;
  36101. let Root = root$2;
  36102. let Node = node$2;
  36103. function postcss(...plugins) {
  36104. if (plugins.length === 1 && Array.isArray(plugins[0])) {
  36105. plugins = plugins[0];
  36106. }
  36107. return new Processor(plugins)
  36108. }
  36109. postcss.plugin = function plugin(name, initializer) {
  36110. let warningPrinted = false;
  36111. function creator(...args) {
  36112. // eslint-disable-next-line no-console
  36113. if (console && console.warn && !warningPrinted) {
  36114. warningPrinted = true;
  36115. // eslint-disable-next-line no-console
  36116. console.warn(
  36117. name +
  36118. ': postcss.plugin was deprecated. Migration guide:\n' +
  36119. 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
  36120. );
  36121. if (browser$1.env.LANG && browser$1.env.LANG.startsWith('cn')) {
  36122. /* c8 ignore next 7 */
  36123. // eslint-disable-next-line no-console
  36124. console.warn(
  36125. name +
  36126. ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
  36127. 'https://www.w3ctech.com/topic/2226'
  36128. );
  36129. }
  36130. }
  36131. let transformer = initializer(...args);
  36132. transformer.postcssPlugin = name;
  36133. transformer.postcssVersion = new Processor().version;
  36134. return transformer
  36135. }
  36136. let cache;
  36137. Object.defineProperty(creator, 'postcss', {
  36138. get() {
  36139. if (!cache) cache = creator();
  36140. return cache
  36141. }
  36142. });
  36143. creator.process = function (css, processOpts, pluginOpts) {
  36144. return postcss([creator(pluginOpts)]).process(css, processOpts)
  36145. };
  36146. return creator
  36147. };
  36148. postcss.stringify = stringify;
  36149. postcss.parse = parse;
  36150. postcss.fromJSON = fromJSON;
  36151. postcss.list = list;
  36152. postcss.comment = defaults => new Comment(defaults);
  36153. postcss.atRule = defaults => new AtRule(defaults);
  36154. postcss.decl = defaults => new Declaration(defaults);
  36155. postcss.rule = defaults => new Rule(defaults);
  36156. postcss.root = defaults => new Root(defaults);
  36157. postcss.document = defaults => new Document(defaults);
  36158. postcss.CssSyntaxError = CssSyntaxError;
  36159. postcss.Declaration = Declaration;
  36160. postcss.Container = Container;
  36161. postcss.Processor = Processor;
  36162. postcss.Document = Document;
  36163. postcss.Comment = Comment;
  36164. postcss.Warning = Warning;
  36165. postcss.AtRule = AtRule;
  36166. postcss.Result = Result;
  36167. postcss.Input = Input;
  36168. postcss.Rule = Rule;
  36169. postcss.Root = Root;
  36170. postcss.Node = Node;
  36171. LazyResult.registerPostcss(postcss);
  36172. var postcss_1 = postcss;
  36173. postcss.default = postcss;
  36174. var postcss$1 = /*@__PURE__*/getDefaultExportFromCjs(postcss_1);
  36175. postcss$1.stringify;
  36176. postcss$1.fromJSON;
  36177. postcss$1.plugin;
  36178. postcss$1.parse;
  36179. postcss$1.list;
  36180. postcss$1.document;
  36181. postcss$1.comment;
  36182. postcss$1.atRule;
  36183. postcss$1.rule;
  36184. postcss$1.decl;
  36185. postcss$1.root;
  36186. postcss$1.CssSyntaxError;
  36187. postcss$1.Declaration;
  36188. postcss$1.Container;
  36189. postcss$1.Processor;
  36190. postcss$1.Document;
  36191. postcss$1.Comment;
  36192. postcss$1.Warning;
  36193. postcss$1.AtRule;
  36194. postcss$1.Result;
  36195. postcss$1.Input;
  36196. postcss$1.Rule;
  36197. postcss$1.Root;
  36198. postcss$1.Node;
  36199. const trimPlugin = () => {
  36200. return {
  36201. postcssPlugin: "vue-sfc-trim",
  36202. Once(root) {
  36203. root.walk(({ type, raws }) => {
  36204. if (type === "rule" || type === "atrule") {
  36205. if (raws.before)
  36206. raws.before = "\n";
  36207. if ("after" in raws && raws.after)
  36208. raws.after = "\n";
  36209. }
  36210. });
  36211. }
  36212. };
  36213. };
  36214. trimPlugin.postcss = true;
  36215. var trimPlugin$1 = trimPlugin;
  36216. var dist = {exports: {}};
  36217. var processor = {exports: {}};
  36218. var parser = {exports: {}};
  36219. var root$1 = {exports: {}};
  36220. var container = {exports: {}};
  36221. var node$1 = {exports: {}};
  36222. var util$6 = {};
  36223. var unesc = {exports: {}};
  36224. (function (module, exports) {
  36225. exports.__esModule = true;
  36226. exports["default"] = unesc;
  36227. // Many thanks for this post which made this migration much easier.
  36228. // https://mathiasbynens.be/notes/css-escapes
  36229. /**
  36230. *
  36231. * @param {string} str
  36232. * @returns {[string, number]|undefined}
  36233. */
  36234. function gobbleHex(str) {
  36235. var lower = str.toLowerCase();
  36236. var hex = '';
  36237. var spaceTerminated = false;
  36238. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  36239. var code = lower.charCodeAt(i);
  36240. // check to see if we are dealing with a valid hex char [a-f|0-9]
  36241. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
  36242. // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  36243. spaceTerminated = code === 32;
  36244. if (!valid) {
  36245. break;
  36246. }
  36247. hex += lower[i];
  36248. }
  36249. if (hex.length === 0) {
  36250. return undefined;
  36251. }
  36252. var codePoint = parseInt(hex, 16);
  36253. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
  36254. // Add special case for
  36255. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  36256. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  36257. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  36258. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  36259. }
  36260. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  36261. }
  36262. var CONTAINS_ESCAPE = /\\/;
  36263. function unesc(str) {
  36264. var needToProcess = CONTAINS_ESCAPE.test(str);
  36265. if (!needToProcess) {
  36266. return str;
  36267. }
  36268. var ret = "";
  36269. for (var i = 0; i < str.length; i++) {
  36270. if (str[i] === "\\") {
  36271. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  36272. if (gobbled !== undefined) {
  36273. ret += gobbled[0];
  36274. i += gobbled[1];
  36275. continue;
  36276. }
  36277. // Retain a pair of \\ if double escaped `\\\\`
  36278. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  36279. if (str[i + 1] === "\\") {
  36280. ret += "\\";
  36281. i++;
  36282. continue;
  36283. }
  36284. // if \\ is at the end of the string retain it
  36285. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  36286. if (str.length === i + 1) {
  36287. ret += str[i];
  36288. }
  36289. continue;
  36290. }
  36291. ret += str[i];
  36292. }
  36293. return ret;
  36294. }
  36295. module.exports = exports.default;
  36296. } (unesc, unesc.exports));
  36297. var unescExports = unesc.exports;
  36298. var getProp = {exports: {}};
  36299. (function (module, exports) {
  36300. exports.__esModule = true;
  36301. exports["default"] = getProp;
  36302. function getProp(obj) {
  36303. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36304. props[_key - 1] = arguments[_key];
  36305. }
  36306. while (props.length > 0) {
  36307. var prop = props.shift();
  36308. if (!obj[prop]) {
  36309. return undefined;
  36310. }
  36311. obj = obj[prop];
  36312. }
  36313. return obj;
  36314. }
  36315. module.exports = exports.default;
  36316. } (getProp, getProp.exports));
  36317. var getPropExports = getProp.exports;
  36318. var ensureObject = {exports: {}};
  36319. (function (module, exports) {
  36320. exports.__esModule = true;
  36321. exports["default"] = ensureObject;
  36322. function ensureObject(obj) {
  36323. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36324. props[_key - 1] = arguments[_key];
  36325. }
  36326. while (props.length > 0) {
  36327. var prop = props.shift();
  36328. if (!obj[prop]) {
  36329. obj[prop] = {};
  36330. }
  36331. obj = obj[prop];
  36332. }
  36333. }
  36334. module.exports = exports.default;
  36335. } (ensureObject, ensureObject.exports));
  36336. var ensureObjectExports = ensureObject.exports;
  36337. var stripComments = {exports: {}};
  36338. (function (module, exports) {
  36339. exports.__esModule = true;
  36340. exports["default"] = stripComments;
  36341. function stripComments(str) {
  36342. var s = "";
  36343. var commentStart = str.indexOf("/*");
  36344. var lastEnd = 0;
  36345. while (commentStart >= 0) {
  36346. s = s + str.slice(lastEnd, commentStart);
  36347. var commentEnd = str.indexOf("*/", commentStart + 2);
  36348. if (commentEnd < 0) {
  36349. return s;
  36350. }
  36351. lastEnd = commentEnd + 2;
  36352. commentStart = str.indexOf("/*", lastEnd);
  36353. }
  36354. s = s + str.slice(lastEnd);
  36355. return s;
  36356. }
  36357. module.exports = exports.default;
  36358. } (stripComments, stripComments.exports));
  36359. var stripCommentsExports = stripComments.exports;
  36360. util$6.__esModule = true;
  36361. util$6.unesc = util$6.stripComments = util$6.getProp = util$6.ensureObject = void 0;
  36362. var _unesc = _interopRequireDefault$1(unescExports);
  36363. util$6.unesc = _unesc["default"];
  36364. var _getProp = _interopRequireDefault$1(getPropExports);
  36365. util$6.getProp = _getProp["default"];
  36366. var _ensureObject = _interopRequireDefault$1(ensureObjectExports);
  36367. util$6.ensureObject = _ensureObject["default"];
  36368. var _stripComments = _interopRequireDefault$1(stripCommentsExports);
  36369. util$6.stripComments = _stripComments["default"];
  36370. function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36371. (function (module, exports) {
  36372. exports.__esModule = true;
  36373. exports["default"] = void 0;
  36374. var _util = util$6;
  36375. 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); } }
  36376. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36377. var cloneNode = function cloneNode(obj, parent) {
  36378. if (typeof obj !== 'object' || obj === null) {
  36379. return obj;
  36380. }
  36381. var cloned = new obj.constructor();
  36382. for (var i in obj) {
  36383. if (!obj.hasOwnProperty(i)) {
  36384. continue;
  36385. }
  36386. var value = obj[i];
  36387. var type = typeof value;
  36388. if (i === 'parent' && type === 'object') {
  36389. if (parent) {
  36390. cloned[i] = parent;
  36391. }
  36392. } else if (value instanceof Array) {
  36393. cloned[i] = value.map(function (j) {
  36394. return cloneNode(j, cloned);
  36395. });
  36396. } else {
  36397. cloned[i] = cloneNode(value, cloned);
  36398. }
  36399. }
  36400. return cloned;
  36401. };
  36402. var Node = /*#__PURE__*/function () {
  36403. function Node(opts) {
  36404. if (opts === void 0) {
  36405. opts = {};
  36406. }
  36407. Object.assign(this, opts);
  36408. this.spaces = this.spaces || {};
  36409. this.spaces.before = this.spaces.before || '';
  36410. this.spaces.after = this.spaces.after || '';
  36411. }
  36412. var _proto = Node.prototype;
  36413. _proto.remove = function remove() {
  36414. if (this.parent) {
  36415. this.parent.removeChild(this);
  36416. }
  36417. this.parent = undefined;
  36418. return this;
  36419. };
  36420. _proto.replaceWith = function replaceWith() {
  36421. if (this.parent) {
  36422. for (var index in arguments) {
  36423. this.parent.insertBefore(this, arguments[index]);
  36424. }
  36425. this.remove();
  36426. }
  36427. return this;
  36428. };
  36429. _proto.next = function next() {
  36430. return this.parent.at(this.parent.index(this) + 1);
  36431. };
  36432. _proto.prev = function prev() {
  36433. return this.parent.at(this.parent.index(this) - 1);
  36434. };
  36435. _proto.clone = function clone(overrides) {
  36436. if (overrides === void 0) {
  36437. overrides = {};
  36438. }
  36439. var cloned = cloneNode(this);
  36440. for (var name in overrides) {
  36441. cloned[name] = overrides[name];
  36442. }
  36443. return cloned;
  36444. }
  36445. /**
  36446. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36447. * This allows non standard syntax to be appended to an existing property
  36448. * by specifying the escaped value. By specifying the escaped value,
  36449. * illegal characters are allowed to be directly inserted into css output.
  36450. * @param {string} name the property to set
  36451. * @param {any} value the unescaped value of the property
  36452. * @param {string} valueEscaped optional. the escaped value of the property.
  36453. */;
  36454. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  36455. if (!this.raws) {
  36456. this.raws = {};
  36457. }
  36458. var originalValue = this[name];
  36459. var originalEscaped = this.raws[name];
  36460. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  36461. if (originalEscaped || valueEscaped !== value) {
  36462. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  36463. } else {
  36464. delete this.raws[name]; // delete any escaped value that was created by the setter.
  36465. }
  36466. }
  36467. /**
  36468. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36469. * This allows the escaped value to be specified directly, allowing illegal
  36470. * characters to be directly inserted into css output.
  36471. * @param {string} name the property to set
  36472. * @param {any} value the unescaped value of the property
  36473. * @param {string} valueEscaped the escaped value of the property.
  36474. */;
  36475. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  36476. if (!this.raws) {
  36477. this.raws = {};
  36478. }
  36479. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36480. this.raws[name] = valueEscaped;
  36481. }
  36482. /**
  36483. * When you want a value to passed through to CSS directly. This method
  36484. * deletes the corresponding raw value causing the stringifier to fallback
  36485. * to the unescaped value.
  36486. * @param {string} name the property to set.
  36487. * @param {any} value The value that is both escaped and unescaped.
  36488. */;
  36489. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  36490. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36491. if (this.raws) {
  36492. delete this.raws[name];
  36493. }
  36494. }
  36495. /**
  36496. *
  36497. * @param {number} line The number (starting with 1)
  36498. * @param {number} column The column number (starting with 1)
  36499. */;
  36500. _proto.isAtPosition = function isAtPosition(line, column) {
  36501. if (this.source && this.source.start && this.source.end) {
  36502. if (this.source.start.line > line) {
  36503. return false;
  36504. }
  36505. if (this.source.end.line < line) {
  36506. return false;
  36507. }
  36508. if (this.source.start.line === line && this.source.start.column > column) {
  36509. return false;
  36510. }
  36511. if (this.source.end.line === line && this.source.end.column < column) {
  36512. return false;
  36513. }
  36514. return true;
  36515. }
  36516. return undefined;
  36517. };
  36518. _proto.stringifyProperty = function stringifyProperty(name) {
  36519. return this.raws && this.raws[name] || this[name];
  36520. };
  36521. _proto.valueToString = function valueToString() {
  36522. return String(this.stringifyProperty("value"));
  36523. };
  36524. _proto.toString = function toString() {
  36525. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  36526. };
  36527. _createClass(Node, [{
  36528. key: "rawSpaceBefore",
  36529. get: function get() {
  36530. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  36531. if (rawSpace === undefined) {
  36532. rawSpace = this.spaces && this.spaces.before;
  36533. }
  36534. return rawSpace || "";
  36535. },
  36536. set: function set(raw) {
  36537. (0, _util.ensureObject)(this, "raws", "spaces");
  36538. this.raws.spaces.before = raw;
  36539. }
  36540. }, {
  36541. key: "rawSpaceAfter",
  36542. get: function get() {
  36543. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  36544. if (rawSpace === undefined) {
  36545. rawSpace = this.spaces.after;
  36546. }
  36547. return rawSpace || "";
  36548. },
  36549. set: function set(raw) {
  36550. (0, _util.ensureObject)(this, "raws", "spaces");
  36551. this.raws.spaces.after = raw;
  36552. }
  36553. }]);
  36554. return Node;
  36555. }();
  36556. exports["default"] = Node;
  36557. module.exports = exports.default;
  36558. } (node$1, node$1.exports));
  36559. var nodeExports = node$1.exports;
  36560. var types = {};
  36561. types.__esModule = true;
  36562. 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;
  36563. var TAG = 'tag';
  36564. types.TAG = TAG;
  36565. var STRING = 'string';
  36566. types.STRING = STRING;
  36567. var SELECTOR = 'selector';
  36568. types.SELECTOR = SELECTOR;
  36569. var ROOT = 'root';
  36570. types.ROOT = ROOT;
  36571. var PSEUDO = 'pseudo';
  36572. types.PSEUDO = PSEUDO;
  36573. var NESTING = 'nesting';
  36574. types.NESTING = NESTING;
  36575. var ID = 'id';
  36576. types.ID = ID;
  36577. var COMMENT = 'comment';
  36578. types.COMMENT = COMMENT;
  36579. var COMBINATOR = 'combinator';
  36580. types.COMBINATOR = COMBINATOR;
  36581. var CLASS = 'class';
  36582. types.CLASS = CLASS;
  36583. var ATTRIBUTE = 'attribute';
  36584. types.ATTRIBUTE = ATTRIBUTE;
  36585. var UNIVERSAL = 'universal';
  36586. types.UNIVERSAL = UNIVERSAL;
  36587. (function (module, exports) {
  36588. exports.__esModule = true;
  36589. exports["default"] = void 0;
  36590. var _node = _interopRequireDefault(nodeExports);
  36591. var types$1 = _interopRequireWildcard(types);
  36592. 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); }
  36593. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && 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; }
  36594. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36595. 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 && o && typeof o.length === "number") { 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."); }
  36596. 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); }
  36597. 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; }
  36598. 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); } }
  36599. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36600. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36601. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36602. var Container = /*#__PURE__*/function (_Node) {
  36603. _inheritsLoose(Container, _Node);
  36604. function Container(opts) {
  36605. var _this;
  36606. _this = _Node.call(this, opts) || this;
  36607. if (!_this.nodes) {
  36608. _this.nodes = [];
  36609. }
  36610. return _this;
  36611. }
  36612. var _proto = Container.prototype;
  36613. _proto.append = function append(selector) {
  36614. selector.parent = this;
  36615. this.nodes.push(selector);
  36616. return this;
  36617. };
  36618. _proto.prepend = function prepend(selector) {
  36619. selector.parent = this;
  36620. this.nodes.unshift(selector);
  36621. return this;
  36622. };
  36623. _proto.at = function at(index) {
  36624. return this.nodes[index];
  36625. };
  36626. _proto.index = function index(child) {
  36627. if (typeof child === 'number') {
  36628. return child;
  36629. }
  36630. return this.nodes.indexOf(child);
  36631. };
  36632. _proto.removeChild = function removeChild(child) {
  36633. child = this.index(child);
  36634. this.at(child).parent = undefined;
  36635. this.nodes.splice(child, 1);
  36636. var index;
  36637. for (var id in this.indexes) {
  36638. index = this.indexes[id];
  36639. if (index >= child) {
  36640. this.indexes[id] = index - 1;
  36641. }
  36642. }
  36643. return this;
  36644. };
  36645. _proto.removeAll = function removeAll() {
  36646. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  36647. var node = _step.value;
  36648. node.parent = undefined;
  36649. }
  36650. this.nodes = [];
  36651. return this;
  36652. };
  36653. _proto.empty = function empty() {
  36654. return this.removeAll();
  36655. };
  36656. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  36657. newNode.parent = this;
  36658. var oldIndex = this.index(oldNode);
  36659. this.nodes.splice(oldIndex + 1, 0, newNode);
  36660. newNode.parent = this;
  36661. var index;
  36662. for (var id in this.indexes) {
  36663. index = this.indexes[id];
  36664. if (oldIndex <= index) {
  36665. this.indexes[id] = index + 1;
  36666. }
  36667. }
  36668. return this;
  36669. };
  36670. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  36671. newNode.parent = this;
  36672. var oldIndex = this.index(oldNode);
  36673. this.nodes.splice(oldIndex, 0, newNode);
  36674. newNode.parent = this;
  36675. var index;
  36676. for (var id in this.indexes) {
  36677. index = this.indexes[id];
  36678. if (index <= oldIndex) {
  36679. this.indexes[id] = index + 1;
  36680. }
  36681. }
  36682. return this;
  36683. };
  36684. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  36685. var found = undefined;
  36686. this.each(function (node) {
  36687. if (node.atPosition) {
  36688. var foundChild = node.atPosition(line, col);
  36689. if (foundChild) {
  36690. found = foundChild;
  36691. return false;
  36692. }
  36693. } else if (node.isAtPosition(line, col)) {
  36694. found = node;
  36695. return false;
  36696. }
  36697. });
  36698. return found;
  36699. }
  36700. /**
  36701. * Return the most specific node at the line and column number given.
  36702. * The source location is based on the original parsed location, locations aren't
  36703. * updated as selector nodes are mutated.
  36704. *
  36705. * Note that this location is relative to the location of the first character
  36706. * of the selector, and not the location of the selector in the overall document
  36707. * when used in conjunction with postcss.
  36708. *
  36709. * If not found, returns undefined.
  36710. * @param {number} line The line number of the node to find. (1-based index)
  36711. * @param {number} col The column number of the node to find. (1-based index)
  36712. */;
  36713. _proto.atPosition = function atPosition(line, col) {
  36714. if (this.isAtPosition(line, col)) {
  36715. return this._findChildAtPosition(line, col) || this;
  36716. } else {
  36717. return undefined;
  36718. }
  36719. };
  36720. _proto._inferEndPosition = function _inferEndPosition() {
  36721. if (this.last && this.last.source && this.last.source.end) {
  36722. this.source = this.source || {};
  36723. this.source.end = this.source.end || {};
  36724. Object.assign(this.source.end, this.last.source.end);
  36725. }
  36726. };
  36727. _proto.each = function each(callback) {
  36728. if (!this.lastEach) {
  36729. this.lastEach = 0;
  36730. }
  36731. if (!this.indexes) {
  36732. this.indexes = {};
  36733. }
  36734. this.lastEach++;
  36735. var id = this.lastEach;
  36736. this.indexes[id] = 0;
  36737. if (!this.length) {
  36738. return undefined;
  36739. }
  36740. var index, result;
  36741. while (this.indexes[id] < this.length) {
  36742. index = this.indexes[id];
  36743. result = callback(this.at(index), index);
  36744. if (result === false) {
  36745. break;
  36746. }
  36747. this.indexes[id] += 1;
  36748. }
  36749. delete this.indexes[id];
  36750. if (result === false) {
  36751. return false;
  36752. }
  36753. };
  36754. _proto.walk = function walk(callback) {
  36755. return this.each(function (node, i) {
  36756. var result = callback(node, i);
  36757. if (result !== false && node.length) {
  36758. result = node.walk(callback);
  36759. }
  36760. if (result === false) {
  36761. return false;
  36762. }
  36763. });
  36764. };
  36765. _proto.walkAttributes = function walkAttributes(callback) {
  36766. var _this2 = this;
  36767. return this.walk(function (selector) {
  36768. if (selector.type === types$1.ATTRIBUTE) {
  36769. return callback.call(_this2, selector);
  36770. }
  36771. });
  36772. };
  36773. _proto.walkClasses = function walkClasses(callback) {
  36774. var _this3 = this;
  36775. return this.walk(function (selector) {
  36776. if (selector.type === types$1.CLASS) {
  36777. return callback.call(_this3, selector);
  36778. }
  36779. });
  36780. };
  36781. _proto.walkCombinators = function walkCombinators(callback) {
  36782. var _this4 = this;
  36783. return this.walk(function (selector) {
  36784. if (selector.type === types$1.COMBINATOR) {
  36785. return callback.call(_this4, selector);
  36786. }
  36787. });
  36788. };
  36789. _proto.walkComments = function walkComments(callback) {
  36790. var _this5 = this;
  36791. return this.walk(function (selector) {
  36792. if (selector.type === types$1.COMMENT) {
  36793. return callback.call(_this5, selector);
  36794. }
  36795. });
  36796. };
  36797. _proto.walkIds = function walkIds(callback) {
  36798. var _this6 = this;
  36799. return this.walk(function (selector) {
  36800. if (selector.type === types$1.ID) {
  36801. return callback.call(_this6, selector);
  36802. }
  36803. });
  36804. };
  36805. _proto.walkNesting = function walkNesting(callback) {
  36806. var _this7 = this;
  36807. return this.walk(function (selector) {
  36808. if (selector.type === types$1.NESTING) {
  36809. return callback.call(_this7, selector);
  36810. }
  36811. });
  36812. };
  36813. _proto.walkPseudos = function walkPseudos(callback) {
  36814. var _this8 = this;
  36815. return this.walk(function (selector) {
  36816. if (selector.type === types$1.PSEUDO) {
  36817. return callback.call(_this8, selector);
  36818. }
  36819. });
  36820. };
  36821. _proto.walkTags = function walkTags(callback) {
  36822. var _this9 = this;
  36823. return this.walk(function (selector) {
  36824. if (selector.type === types$1.TAG) {
  36825. return callback.call(_this9, selector);
  36826. }
  36827. });
  36828. };
  36829. _proto.walkUniversals = function walkUniversals(callback) {
  36830. var _this10 = this;
  36831. return this.walk(function (selector) {
  36832. if (selector.type === types$1.UNIVERSAL) {
  36833. return callback.call(_this10, selector);
  36834. }
  36835. });
  36836. };
  36837. _proto.split = function split(callback) {
  36838. var _this11 = this;
  36839. var current = [];
  36840. return this.reduce(function (memo, node, index) {
  36841. var split = callback.call(_this11, node);
  36842. current.push(node);
  36843. if (split) {
  36844. memo.push(current);
  36845. current = [];
  36846. } else if (index === _this11.length - 1) {
  36847. memo.push(current);
  36848. }
  36849. return memo;
  36850. }, []);
  36851. };
  36852. _proto.map = function map(callback) {
  36853. return this.nodes.map(callback);
  36854. };
  36855. _proto.reduce = function reduce(callback, memo) {
  36856. return this.nodes.reduce(callback, memo);
  36857. };
  36858. _proto.every = function every(callback) {
  36859. return this.nodes.every(callback);
  36860. };
  36861. _proto.some = function some(callback) {
  36862. return this.nodes.some(callback);
  36863. };
  36864. _proto.filter = function filter(callback) {
  36865. return this.nodes.filter(callback);
  36866. };
  36867. _proto.sort = function sort(callback) {
  36868. return this.nodes.sort(callback);
  36869. };
  36870. _proto.toString = function toString() {
  36871. return this.map(String).join('');
  36872. };
  36873. _createClass(Container, [{
  36874. key: "first",
  36875. get: function get() {
  36876. return this.at(0);
  36877. }
  36878. }, {
  36879. key: "last",
  36880. get: function get() {
  36881. return this.at(this.length - 1);
  36882. }
  36883. }, {
  36884. key: "length",
  36885. get: function get() {
  36886. return this.nodes.length;
  36887. }
  36888. }]);
  36889. return Container;
  36890. }(_node["default"]);
  36891. exports["default"] = Container;
  36892. module.exports = exports.default;
  36893. } (container, container.exports));
  36894. var containerExports = container.exports;
  36895. (function (module, exports) {
  36896. exports.__esModule = true;
  36897. exports["default"] = void 0;
  36898. var _container = _interopRequireDefault(containerExports);
  36899. var _types = types;
  36900. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36901. 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); } }
  36902. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36903. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36904. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36905. var Root = /*#__PURE__*/function (_Container) {
  36906. _inheritsLoose(Root, _Container);
  36907. function Root(opts) {
  36908. var _this;
  36909. _this = _Container.call(this, opts) || this;
  36910. _this.type = _types.ROOT;
  36911. return _this;
  36912. }
  36913. var _proto = Root.prototype;
  36914. _proto.toString = function toString() {
  36915. var str = this.reduce(function (memo, selector) {
  36916. memo.push(String(selector));
  36917. return memo;
  36918. }, []).join(',');
  36919. return this.trailingComma ? str + ',' : str;
  36920. };
  36921. _proto.error = function error(message, options) {
  36922. if (this._error) {
  36923. return this._error(message, options);
  36924. } else {
  36925. return new Error(message);
  36926. }
  36927. };
  36928. _createClass(Root, [{
  36929. key: "errorGenerator",
  36930. set: function set(handler) {
  36931. this._error = handler;
  36932. }
  36933. }]);
  36934. return Root;
  36935. }(_container["default"]);
  36936. exports["default"] = Root;
  36937. module.exports = exports.default;
  36938. } (root$1, root$1.exports));
  36939. var rootExports = root$1.exports;
  36940. var selector$1 = {exports: {}};
  36941. (function (module, exports) {
  36942. exports.__esModule = true;
  36943. exports["default"] = void 0;
  36944. var _container = _interopRequireDefault(containerExports);
  36945. var _types = types;
  36946. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36947. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36948. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36949. var Selector = /*#__PURE__*/function (_Container) {
  36950. _inheritsLoose(Selector, _Container);
  36951. function Selector(opts) {
  36952. var _this;
  36953. _this = _Container.call(this, opts) || this;
  36954. _this.type = _types.SELECTOR;
  36955. return _this;
  36956. }
  36957. return Selector;
  36958. }(_container["default"]);
  36959. exports["default"] = Selector;
  36960. module.exports = exports.default;
  36961. } (selector$1, selector$1.exports));
  36962. var selectorExports = selector$1.exports;
  36963. var className$1 = {exports: {}};
  36964. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  36965. var object = {};
  36966. var hasOwnProperty = object.hasOwnProperty;
  36967. var merge$2 = function merge(options, defaults) {
  36968. if (!options) {
  36969. return defaults;
  36970. }
  36971. var result = {};
  36972. for (var key in defaults) {
  36973. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  36974. // only recognized option names are used.
  36975. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  36976. }
  36977. return result;
  36978. };
  36979. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  36980. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  36981. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
  36982. // https://mathiasbynens.be/notes/css-escapes#css
  36983. var cssesc = function cssesc(string, options) {
  36984. options = merge$2(options, cssesc.options);
  36985. if (options.quotes != 'single' && options.quotes != 'double') {
  36986. options.quotes = 'single';
  36987. }
  36988. var quote = options.quotes == 'double' ? '"' : '\'';
  36989. var isIdentifier = options.isIdentifier;
  36990. var firstChar = string.charAt(0);
  36991. var output = '';
  36992. var counter = 0;
  36993. var length = string.length;
  36994. while (counter < length) {
  36995. var character = string.charAt(counter++);
  36996. var codePoint = character.charCodeAt();
  36997. var value = void 0;
  36998. // If it’s not a printable ASCII character…
  36999. if (codePoint < 0x20 || codePoint > 0x7E) {
  37000. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  37001. // It’s a high surrogate, and there is a next character.
  37002. var extra = string.charCodeAt(counter++);
  37003. if ((extra & 0xFC00) == 0xDC00) {
  37004. // next character is low surrogate
  37005. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  37006. } else {
  37007. // It’s an unmatched surrogate; only append this code unit, in case
  37008. // the next code unit is the high surrogate of a surrogate pair.
  37009. counter--;
  37010. }
  37011. }
  37012. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37013. } else {
  37014. if (options.escapeEverything) {
  37015. if (regexAnySingleEscape.test(character)) {
  37016. value = '\\' + character;
  37017. } else {
  37018. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37019. }
  37020. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  37021. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37022. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  37023. value = '\\' + character;
  37024. } else {
  37025. value = character;
  37026. }
  37027. }
  37028. output += value;
  37029. }
  37030. if (isIdentifier) {
  37031. if (/^-[-\d]/.test(output)) {
  37032. output = '\\-' + output.slice(1);
  37033. } else if (/\d/.test(firstChar)) {
  37034. output = '\\3' + firstChar + ' ' + output.slice(1);
  37035. }
  37036. }
  37037. // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  37038. // since they’re redundant. Note that this is only possible if the escape
  37039. // sequence isn’t preceded by an odd number of backslashes.
  37040. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  37041. if ($1 && $1.length % 2) {
  37042. // It’s not safe to remove the space, so don’t.
  37043. return $0;
  37044. }
  37045. // Strip the space.
  37046. return ($1 || '') + $2;
  37047. });
  37048. if (!isIdentifier && options.wrap) {
  37049. return quote + output + quote;
  37050. }
  37051. return output;
  37052. };
  37053. // Expose default options (so they can be overridden globally).
  37054. cssesc.options = {
  37055. 'escapeEverything': false,
  37056. 'isIdentifier': false,
  37057. 'quotes': 'single',
  37058. 'wrap': false
  37059. };
  37060. cssesc.version = '3.0.0';
  37061. var cssesc_1 = cssesc;
  37062. (function (module, exports) {
  37063. exports.__esModule = true;
  37064. exports["default"] = void 0;
  37065. var _cssesc = _interopRequireDefault(cssesc_1);
  37066. var _util = util$6;
  37067. var _node = _interopRequireDefault(nodeExports);
  37068. var _types = types;
  37069. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37070. 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); } }
  37071. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37072. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37073. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37074. var ClassName = /*#__PURE__*/function (_Node) {
  37075. _inheritsLoose(ClassName, _Node);
  37076. function ClassName(opts) {
  37077. var _this;
  37078. _this = _Node.call(this, opts) || this;
  37079. _this.type = _types.CLASS;
  37080. _this._constructed = true;
  37081. return _this;
  37082. }
  37083. var _proto = ClassName.prototype;
  37084. _proto.valueToString = function valueToString() {
  37085. return '.' + _Node.prototype.valueToString.call(this);
  37086. };
  37087. _createClass(ClassName, [{
  37088. key: "value",
  37089. get: function get() {
  37090. return this._value;
  37091. },
  37092. set: function set(v) {
  37093. if (this._constructed) {
  37094. var escaped = (0, _cssesc["default"])(v, {
  37095. isIdentifier: true
  37096. });
  37097. if (escaped !== v) {
  37098. (0, _util.ensureObject)(this, "raws");
  37099. this.raws.value = escaped;
  37100. } else if (this.raws) {
  37101. delete this.raws.value;
  37102. }
  37103. }
  37104. this._value = v;
  37105. }
  37106. }]);
  37107. return ClassName;
  37108. }(_node["default"]);
  37109. exports["default"] = ClassName;
  37110. module.exports = exports.default;
  37111. } (className$1, className$1.exports));
  37112. var classNameExports = className$1.exports;
  37113. var comment$2 = {exports: {}};
  37114. (function (module, exports) {
  37115. exports.__esModule = true;
  37116. exports["default"] = void 0;
  37117. var _node = _interopRequireDefault(nodeExports);
  37118. var _types = types;
  37119. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37120. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37121. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37122. var Comment = /*#__PURE__*/function (_Node) {
  37123. _inheritsLoose(Comment, _Node);
  37124. function Comment(opts) {
  37125. var _this;
  37126. _this = _Node.call(this, opts) || this;
  37127. _this.type = _types.COMMENT;
  37128. return _this;
  37129. }
  37130. return Comment;
  37131. }(_node["default"]);
  37132. exports["default"] = Comment;
  37133. module.exports = exports.default;
  37134. } (comment$2, comment$2.exports));
  37135. var commentExports = comment$2.exports;
  37136. var id$1 = {exports: {}};
  37137. (function (module, exports) {
  37138. exports.__esModule = true;
  37139. exports["default"] = void 0;
  37140. var _node = _interopRequireDefault(nodeExports);
  37141. var _types = types;
  37142. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37143. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37144. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37145. var ID = /*#__PURE__*/function (_Node) {
  37146. _inheritsLoose(ID, _Node);
  37147. function ID(opts) {
  37148. var _this;
  37149. _this = _Node.call(this, opts) || this;
  37150. _this.type = _types.ID;
  37151. return _this;
  37152. }
  37153. var _proto = ID.prototype;
  37154. _proto.valueToString = function valueToString() {
  37155. return '#' + _Node.prototype.valueToString.call(this);
  37156. };
  37157. return ID;
  37158. }(_node["default"]);
  37159. exports["default"] = ID;
  37160. module.exports = exports.default;
  37161. } (id$1, id$1.exports));
  37162. var idExports = id$1.exports;
  37163. var tag$1 = {exports: {}};
  37164. var namespace = {exports: {}};
  37165. (function (module, exports) {
  37166. exports.__esModule = true;
  37167. exports["default"] = void 0;
  37168. var _cssesc = _interopRequireDefault(cssesc_1);
  37169. var _util = util$6;
  37170. var _node = _interopRequireDefault(nodeExports);
  37171. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37172. 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); } }
  37173. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37174. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37175. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37176. var Namespace = /*#__PURE__*/function (_Node) {
  37177. _inheritsLoose(Namespace, _Node);
  37178. function Namespace() {
  37179. return _Node.apply(this, arguments) || this;
  37180. }
  37181. var _proto = Namespace.prototype;
  37182. _proto.qualifiedName = function qualifiedName(value) {
  37183. if (this.namespace) {
  37184. return this.namespaceString + "|" + value;
  37185. } else {
  37186. return value;
  37187. }
  37188. };
  37189. _proto.valueToString = function valueToString() {
  37190. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  37191. };
  37192. _createClass(Namespace, [{
  37193. key: "namespace",
  37194. get: function get() {
  37195. return this._namespace;
  37196. },
  37197. set: function set(namespace) {
  37198. if (namespace === true || namespace === "*" || namespace === "&") {
  37199. this._namespace = namespace;
  37200. if (this.raws) {
  37201. delete this.raws.namespace;
  37202. }
  37203. return;
  37204. }
  37205. var escaped = (0, _cssesc["default"])(namespace, {
  37206. isIdentifier: true
  37207. });
  37208. this._namespace = namespace;
  37209. if (escaped !== namespace) {
  37210. (0, _util.ensureObject)(this, "raws");
  37211. this.raws.namespace = escaped;
  37212. } else if (this.raws) {
  37213. delete this.raws.namespace;
  37214. }
  37215. }
  37216. }, {
  37217. key: "ns",
  37218. get: function get() {
  37219. return this._namespace;
  37220. },
  37221. set: function set(namespace) {
  37222. this.namespace = namespace;
  37223. }
  37224. }, {
  37225. key: "namespaceString",
  37226. get: function get() {
  37227. if (this.namespace) {
  37228. var ns = this.stringifyProperty("namespace");
  37229. if (ns === true) {
  37230. return '';
  37231. } else {
  37232. return ns;
  37233. }
  37234. } else {
  37235. return '';
  37236. }
  37237. }
  37238. }]);
  37239. return Namespace;
  37240. }(_node["default"]);
  37241. exports["default"] = Namespace;
  37242. module.exports = exports.default;
  37243. } (namespace, namespace.exports));
  37244. var namespaceExports = namespace.exports;
  37245. (function (module, exports) {
  37246. exports.__esModule = true;
  37247. exports["default"] = void 0;
  37248. var _namespace = _interopRequireDefault(namespaceExports);
  37249. var _types = types;
  37250. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37251. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37252. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37253. var Tag = /*#__PURE__*/function (_Namespace) {
  37254. _inheritsLoose(Tag, _Namespace);
  37255. function Tag(opts) {
  37256. var _this;
  37257. _this = _Namespace.call(this, opts) || this;
  37258. _this.type = _types.TAG;
  37259. return _this;
  37260. }
  37261. return Tag;
  37262. }(_namespace["default"]);
  37263. exports["default"] = Tag;
  37264. module.exports = exports.default;
  37265. } (tag$1, tag$1.exports));
  37266. var tagExports = tag$1.exports;
  37267. var string$1 = {exports: {}};
  37268. (function (module, exports) {
  37269. exports.__esModule = true;
  37270. exports["default"] = void 0;
  37271. var _node = _interopRequireDefault(nodeExports);
  37272. var _types = types;
  37273. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37274. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37275. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37276. var String = /*#__PURE__*/function (_Node) {
  37277. _inheritsLoose(String, _Node);
  37278. function String(opts) {
  37279. var _this;
  37280. _this = _Node.call(this, opts) || this;
  37281. _this.type = _types.STRING;
  37282. return _this;
  37283. }
  37284. return String;
  37285. }(_node["default"]);
  37286. exports["default"] = String;
  37287. module.exports = exports.default;
  37288. } (string$1, string$1.exports));
  37289. var stringExports = string$1.exports;
  37290. var pseudo$1 = {exports: {}};
  37291. (function (module, exports) {
  37292. exports.__esModule = true;
  37293. exports["default"] = void 0;
  37294. var _container = _interopRequireDefault(containerExports);
  37295. var _types = types;
  37296. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37297. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37298. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37299. var Pseudo = /*#__PURE__*/function (_Container) {
  37300. _inheritsLoose(Pseudo, _Container);
  37301. function Pseudo(opts) {
  37302. var _this;
  37303. _this = _Container.call(this, opts) || this;
  37304. _this.type = _types.PSEUDO;
  37305. return _this;
  37306. }
  37307. var _proto = Pseudo.prototype;
  37308. _proto.toString = function toString() {
  37309. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  37310. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  37311. };
  37312. return Pseudo;
  37313. }(_container["default"]);
  37314. exports["default"] = Pseudo;
  37315. module.exports = exports.default;
  37316. } (pseudo$1, pseudo$1.exports));
  37317. var pseudoExports = pseudo$1.exports;
  37318. var attribute$1 = {};
  37319. /**
  37320. * For Node.js, simply re-export the core `util.deprecate` function.
  37321. */
  37322. var node = require$$0$1.deprecate;
  37323. (function (exports) {
  37324. exports.__esModule = true;
  37325. exports["default"] = void 0;
  37326. exports.unescapeValue = unescapeValue;
  37327. var _cssesc = _interopRequireDefault(cssesc_1);
  37328. var _unesc = _interopRequireDefault(unescExports);
  37329. var _namespace = _interopRequireDefault(namespaceExports);
  37330. var _types = types;
  37331. var _CSSESC_QUOTE_OPTIONS;
  37332. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37333. 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); } }
  37334. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37335. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37336. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37337. var deprecate = node;
  37338. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  37339. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  37340. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  37341. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  37342. function unescapeValue(value) {
  37343. var deprecatedUsage = false;
  37344. var quoteMark = null;
  37345. var unescaped = value;
  37346. var m = unescaped.match(WRAPPED_IN_QUOTES);
  37347. if (m) {
  37348. quoteMark = m[1];
  37349. unescaped = m[2];
  37350. }
  37351. unescaped = (0, _unesc["default"])(unescaped);
  37352. if (unescaped !== value) {
  37353. deprecatedUsage = true;
  37354. }
  37355. return {
  37356. deprecatedUsage: deprecatedUsage,
  37357. unescaped: unescaped,
  37358. quoteMark: quoteMark
  37359. };
  37360. }
  37361. function handleDeprecatedContructorOpts(opts) {
  37362. if (opts.quoteMark !== undefined) {
  37363. return opts;
  37364. }
  37365. if (opts.value === undefined) {
  37366. return opts;
  37367. }
  37368. warnOfDeprecatedConstructor();
  37369. var _unescapeValue = unescapeValue(opts.value),
  37370. quoteMark = _unescapeValue.quoteMark,
  37371. unescaped = _unescapeValue.unescaped;
  37372. if (!opts.raws) {
  37373. opts.raws = {};
  37374. }
  37375. if (opts.raws.value === undefined) {
  37376. opts.raws.value = opts.value;
  37377. }
  37378. opts.value = unescaped;
  37379. opts.quoteMark = quoteMark;
  37380. return opts;
  37381. }
  37382. var Attribute = /*#__PURE__*/function (_Namespace) {
  37383. _inheritsLoose(Attribute, _Namespace);
  37384. function Attribute(opts) {
  37385. var _this;
  37386. if (opts === void 0) {
  37387. opts = {};
  37388. }
  37389. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  37390. _this.type = _types.ATTRIBUTE;
  37391. _this.raws = _this.raws || {};
  37392. Object.defineProperty(_this.raws, 'unquoted', {
  37393. get: deprecate(function () {
  37394. return _this.value;
  37395. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  37396. set: deprecate(function () {
  37397. return _this.value;
  37398. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  37399. });
  37400. _this._constructed = true;
  37401. return _this;
  37402. }
  37403. /**
  37404. * Returns the Attribute's value quoted such that it would be legal to use
  37405. * in the value of a css file. The original value's quotation setting
  37406. * used for stringification is left unchanged. See `setValue(value, options)`
  37407. * if you want to control the quote settings of a new value for the attribute.
  37408. *
  37409. * You can also change the quotation used for the current value by setting quoteMark.
  37410. *
  37411. * Options:
  37412. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  37413. * option is not set, the original value for quoteMark will be used. If
  37414. * indeterminate, a double quote is used. The legal values are:
  37415. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  37416. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  37417. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  37418. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  37419. * over the quoteMark option value.
  37420. * * smart {boolean} - if true, will select a quote mark based on the value
  37421. * and the other options specified here. See the `smartQuoteMark()`
  37422. * method.
  37423. **/
  37424. var _proto = Attribute.prototype;
  37425. _proto.getQuotedValue = function getQuotedValue(options) {
  37426. if (options === void 0) {
  37427. options = {};
  37428. }
  37429. var quoteMark = this._determineQuoteMark(options);
  37430. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  37431. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  37432. return escaped;
  37433. };
  37434. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  37435. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  37436. }
  37437. /**
  37438. * Set the unescaped value with the specified quotation options. The value
  37439. * provided must not include any wrapping quote marks -- those quotes will
  37440. * be interpreted as part of the value and escaped accordingly.
  37441. */;
  37442. _proto.setValue = function setValue(value, options) {
  37443. if (options === void 0) {
  37444. options = {};
  37445. }
  37446. this._value = value;
  37447. this._quoteMark = this._determineQuoteMark(options);
  37448. this._syncRawValue();
  37449. }
  37450. /**
  37451. * Intelligently select a quoteMark value based on the value's contents. If
  37452. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  37453. * mark will be picked that minimizes the number of escapes.
  37454. *
  37455. * If there's no clear winner, the quote mark from these options is used,
  37456. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  37457. * true). If the quoteMark is unspecified, a double quote is used.
  37458. *
  37459. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  37460. * from the quoteValue method.
  37461. */;
  37462. _proto.smartQuoteMark = function smartQuoteMark(options) {
  37463. var v = this.value;
  37464. var numSingleQuotes = v.replace(/[^']/g, '').length;
  37465. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  37466. if (numSingleQuotes + numDoubleQuotes === 0) {
  37467. var escaped = (0, _cssesc["default"])(v, {
  37468. isIdentifier: true
  37469. });
  37470. if (escaped === v) {
  37471. return Attribute.NO_QUOTE;
  37472. } else {
  37473. var pref = this.preferredQuoteMark(options);
  37474. if (pref === Attribute.NO_QUOTE) {
  37475. // pick a quote mark that isn't none and see if it's smaller
  37476. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  37477. var opts = CSSESC_QUOTE_OPTIONS[quote];
  37478. var quoteValue = (0, _cssesc["default"])(v, opts);
  37479. if (quoteValue.length < escaped.length) {
  37480. return quote;
  37481. }
  37482. }
  37483. return pref;
  37484. }
  37485. } else if (numDoubleQuotes === numSingleQuotes) {
  37486. return this.preferredQuoteMark(options);
  37487. } else if (numDoubleQuotes < numSingleQuotes) {
  37488. return Attribute.DOUBLE_QUOTE;
  37489. } else {
  37490. return Attribute.SINGLE_QUOTE;
  37491. }
  37492. }
  37493. /**
  37494. * Selects the preferred quote mark based on the options and the current quote mark value.
  37495. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  37496. * instead.
  37497. */;
  37498. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  37499. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  37500. if (quoteMark === undefined) {
  37501. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  37502. }
  37503. if (quoteMark === undefined) {
  37504. quoteMark = Attribute.DOUBLE_QUOTE;
  37505. }
  37506. return quoteMark;
  37507. };
  37508. _proto._syncRawValue = function _syncRawValue() {
  37509. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  37510. if (rawValue === this._value) {
  37511. if (this.raws) {
  37512. delete this.raws.value;
  37513. }
  37514. } else {
  37515. this.raws.value = rawValue;
  37516. }
  37517. };
  37518. _proto._handleEscapes = function _handleEscapes(prop, value) {
  37519. if (this._constructed) {
  37520. var escaped = (0, _cssesc["default"])(value, {
  37521. isIdentifier: true
  37522. });
  37523. if (escaped !== value) {
  37524. this.raws[prop] = escaped;
  37525. } else {
  37526. delete this.raws[prop];
  37527. }
  37528. }
  37529. };
  37530. _proto._spacesFor = function _spacesFor(name) {
  37531. var attrSpaces = {
  37532. before: '',
  37533. after: ''
  37534. };
  37535. var spaces = this.spaces[name] || {};
  37536. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  37537. return Object.assign(attrSpaces, spaces, rawSpaces);
  37538. };
  37539. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  37540. if (spaceName === void 0) {
  37541. spaceName = name;
  37542. }
  37543. if (concat === void 0) {
  37544. concat = defaultAttrConcat;
  37545. }
  37546. var attrSpaces = this._spacesFor(spaceName);
  37547. return concat(this.stringifyProperty(name), attrSpaces);
  37548. }
  37549. /**
  37550. * returns the offset of the attribute part specified relative to the
  37551. * start of the node of the output string.
  37552. *
  37553. * * "ns" - alias for "namespace"
  37554. * * "namespace" - the namespace if it exists.
  37555. * * "attribute" - the attribute name
  37556. * * "attributeNS" - the start of the attribute or its namespace
  37557. * * "operator" - the match operator of the attribute
  37558. * * "value" - The value (string or identifier)
  37559. * * "insensitive" - the case insensitivity flag;
  37560. * @param part One of the possible values inside an attribute.
  37561. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  37562. */;
  37563. _proto.offsetOf = function offsetOf(name) {
  37564. var count = 1;
  37565. var attributeSpaces = this._spacesFor("attribute");
  37566. count += attributeSpaces.before.length;
  37567. if (name === "namespace" || name === "ns") {
  37568. return this.namespace ? count : -1;
  37569. }
  37570. if (name === "attributeNS") {
  37571. return count;
  37572. }
  37573. count += this.namespaceString.length;
  37574. if (this.namespace) {
  37575. count += 1;
  37576. }
  37577. if (name === "attribute") {
  37578. return count;
  37579. }
  37580. count += this.stringifyProperty("attribute").length;
  37581. count += attributeSpaces.after.length;
  37582. var operatorSpaces = this._spacesFor("operator");
  37583. count += operatorSpaces.before.length;
  37584. var operator = this.stringifyProperty("operator");
  37585. if (name === "operator") {
  37586. return operator ? count : -1;
  37587. }
  37588. count += operator.length;
  37589. count += operatorSpaces.after.length;
  37590. var valueSpaces = this._spacesFor("value");
  37591. count += valueSpaces.before.length;
  37592. var value = this.stringifyProperty("value");
  37593. if (name === "value") {
  37594. return value ? count : -1;
  37595. }
  37596. count += value.length;
  37597. count += valueSpaces.after.length;
  37598. var insensitiveSpaces = this._spacesFor("insensitive");
  37599. count += insensitiveSpaces.before.length;
  37600. if (name === "insensitive") {
  37601. return this.insensitive ? count : -1;
  37602. }
  37603. return -1;
  37604. };
  37605. _proto.toString = function toString() {
  37606. var _this2 = this;
  37607. var selector = [this.rawSpaceBefore, '['];
  37608. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  37609. if (this.operator && (this.value || this.value === '')) {
  37610. selector.push(this._stringFor('operator'));
  37611. selector.push(this._stringFor('value'));
  37612. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  37613. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  37614. attrSpaces.before = " ";
  37615. }
  37616. return defaultAttrConcat(attrValue, attrSpaces);
  37617. }));
  37618. }
  37619. selector.push(']');
  37620. selector.push(this.rawSpaceAfter);
  37621. return selector.join('');
  37622. };
  37623. _createClass(Attribute, [{
  37624. key: "quoted",
  37625. get: function get() {
  37626. var qm = this.quoteMark;
  37627. return qm === "'" || qm === '"';
  37628. },
  37629. set: function set(value) {
  37630. warnOfDeprecatedQuotedAssignment();
  37631. }
  37632. /**
  37633. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  37634. * returns `null` if the value is not quoted.
  37635. * returns `undefined` if the quotation state is unknown (this can happen when
  37636. * the attribute is constructed without specifying a quote mark.)
  37637. */
  37638. }, {
  37639. key: "quoteMark",
  37640. get: function get() {
  37641. return this._quoteMark;
  37642. }
  37643. /**
  37644. * Set the quote mark to be used by this attribute's value.
  37645. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  37646. * value is updated accordingly.
  37647. *
  37648. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  37649. */,
  37650. set: function set(quoteMark) {
  37651. if (!this._constructed) {
  37652. this._quoteMark = quoteMark;
  37653. return;
  37654. }
  37655. if (this._quoteMark !== quoteMark) {
  37656. this._quoteMark = quoteMark;
  37657. this._syncRawValue();
  37658. }
  37659. }
  37660. }, {
  37661. key: "qualifiedAttribute",
  37662. get: function get() {
  37663. return this.qualifiedName(this.raws.attribute || this.attribute);
  37664. }
  37665. }, {
  37666. key: "insensitiveFlag",
  37667. get: function get() {
  37668. return this.insensitive ? 'i' : '';
  37669. }
  37670. }, {
  37671. key: "value",
  37672. get: function get() {
  37673. return this._value;
  37674. },
  37675. set:
  37676. /**
  37677. * Before 3.0, the value had to be set to an escaped value including any wrapped
  37678. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  37679. * is unescaped during parsing and any quote marks are removed.
  37680. *
  37681. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  37682. * a deprecation warning is raised when the new value contains any characters that would
  37683. * require escaping (including if it contains wrapped quotes).
  37684. *
  37685. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  37686. * how the new value is quoted.
  37687. */
  37688. function set(v) {
  37689. if (this._constructed) {
  37690. var _unescapeValue2 = unescapeValue(v),
  37691. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  37692. unescaped = _unescapeValue2.unescaped,
  37693. quoteMark = _unescapeValue2.quoteMark;
  37694. if (deprecatedUsage) {
  37695. warnOfDeprecatedValueAssignment();
  37696. }
  37697. if (unescaped === this._value && quoteMark === this._quoteMark) {
  37698. return;
  37699. }
  37700. this._value = unescaped;
  37701. this._quoteMark = quoteMark;
  37702. this._syncRawValue();
  37703. } else {
  37704. this._value = v;
  37705. }
  37706. }
  37707. }, {
  37708. key: "insensitive",
  37709. get: function get() {
  37710. return this._insensitive;
  37711. }
  37712. /**
  37713. * Set the case insensitive flag.
  37714. * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
  37715. * of the attribute is updated accordingly.
  37716. *
  37717. * @param {true | false} insensitive true if the attribute should match case-insensitively.
  37718. */,
  37719. set: function set(insensitive) {
  37720. if (!insensitive) {
  37721. this._insensitive = false;
  37722. // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
  37723. // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
  37724. if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
  37725. this.raws.insensitiveFlag = undefined;
  37726. }
  37727. }
  37728. this._insensitive = insensitive;
  37729. }
  37730. }, {
  37731. key: "attribute",
  37732. get: function get() {
  37733. return this._attribute;
  37734. },
  37735. set: function set(name) {
  37736. this._handleEscapes("attribute", name);
  37737. this._attribute = name;
  37738. }
  37739. }]);
  37740. return Attribute;
  37741. }(_namespace["default"]);
  37742. exports["default"] = Attribute;
  37743. Attribute.NO_QUOTE = null;
  37744. Attribute.SINGLE_QUOTE = "'";
  37745. Attribute.DOUBLE_QUOTE = '"';
  37746. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  37747. "'": {
  37748. quotes: 'single',
  37749. wrap: true
  37750. },
  37751. '"': {
  37752. quotes: 'double',
  37753. wrap: true
  37754. }
  37755. }, _CSSESC_QUOTE_OPTIONS[null] = {
  37756. isIdentifier: true
  37757. }, _CSSESC_QUOTE_OPTIONS);
  37758. function defaultAttrConcat(attrValue, attrSpaces) {
  37759. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  37760. }
  37761. } (attribute$1));
  37762. var universal$1 = {exports: {}};
  37763. (function (module, exports) {
  37764. exports.__esModule = true;
  37765. exports["default"] = void 0;
  37766. var _namespace = _interopRequireDefault(namespaceExports);
  37767. var _types = types;
  37768. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37769. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37770. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37771. var Universal = /*#__PURE__*/function (_Namespace) {
  37772. _inheritsLoose(Universal, _Namespace);
  37773. function Universal(opts) {
  37774. var _this;
  37775. _this = _Namespace.call(this, opts) || this;
  37776. _this.type = _types.UNIVERSAL;
  37777. _this.value = '*';
  37778. return _this;
  37779. }
  37780. return Universal;
  37781. }(_namespace["default"]);
  37782. exports["default"] = Universal;
  37783. module.exports = exports.default;
  37784. } (universal$1, universal$1.exports));
  37785. var universalExports = universal$1.exports;
  37786. var combinator$2 = {exports: {}};
  37787. (function (module, exports) {
  37788. exports.__esModule = true;
  37789. exports["default"] = void 0;
  37790. var _node = _interopRequireDefault(nodeExports);
  37791. var _types = types;
  37792. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37793. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37794. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37795. var Combinator = /*#__PURE__*/function (_Node) {
  37796. _inheritsLoose(Combinator, _Node);
  37797. function Combinator(opts) {
  37798. var _this;
  37799. _this = _Node.call(this, opts) || this;
  37800. _this.type = _types.COMBINATOR;
  37801. return _this;
  37802. }
  37803. return Combinator;
  37804. }(_node["default"]);
  37805. exports["default"] = Combinator;
  37806. module.exports = exports.default;
  37807. } (combinator$2, combinator$2.exports));
  37808. var combinatorExports = combinator$2.exports;
  37809. var nesting$1 = {exports: {}};
  37810. (function (module, exports) {
  37811. exports.__esModule = true;
  37812. exports["default"] = void 0;
  37813. var _node = _interopRequireDefault(nodeExports);
  37814. var _types = types;
  37815. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37816. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37817. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37818. var Nesting = /*#__PURE__*/function (_Node) {
  37819. _inheritsLoose(Nesting, _Node);
  37820. function Nesting(opts) {
  37821. var _this;
  37822. _this = _Node.call(this, opts) || this;
  37823. _this.type = _types.NESTING;
  37824. _this.value = '&';
  37825. return _this;
  37826. }
  37827. return Nesting;
  37828. }(_node["default"]);
  37829. exports["default"] = Nesting;
  37830. module.exports = exports.default;
  37831. } (nesting$1, nesting$1.exports));
  37832. var nestingExports = nesting$1.exports;
  37833. var sortAscending = {exports: {}};
  37834. (function (module, exports) {
  37835. exports.__esModule = true;
  37836. exports["default"] = sortAscending;
  37837. function sortAscending(list) {
  37838. return list.sort(function (a, b) {
  37839. return a - b;
  37840. });
  37841. }
  37842. module.exports = exports.default;
  37843. } (sortAscending, sortAscending.exports));
  37844. var sortAscendingExports = sortAscending.exports;
  37845. var tokenize = {};
  37846. var tokenTypes = {};
  37847. tokenTypes.__esModule = true;
  37848. 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;
  37849. var ampersand = 38; // `&`.charCodeAt(0);
  37850. tokenTypes.ampersand = ampersand;
  37851. var asterisk = 42; // `*`.charCodeAt(0);
  37852. tokenTypes.asterisk = asterisk;
  37853. var at = 64; // `@`.charCodeAt(0);
  37854. tokenTypes.at = at;
  37855. var comma$1 = 44; // `,`.charCodeAt(0);
  37856. tokenTypes.comma = comma$1;
  37857. var colon = 58; // `:`.charCodeAt(0);
  37858. tokenTypes.colon = colon;
  37859. var semicolon$1 = 59; // `;`.charCodeAt(0);
  37860. tokenTypes.semicolon = semicolon$1;
  37861. var openParenthesis = 40; // `(`.charCodeAt(0);
  37862. tokenTypes.openParenthesis = openParenthesis;
  37863. var closeParenthesis = 41; // `)`.charCodeAt(0);
  37864. tokenTypes.closeParenthesis = closeParenthesis;
  37865. var openSquare = 91; // `[`.charCodeAt(0);
  37866. tokenTypes.openSquare = openSquare;
  37867. var closeSquare = 93; // `]`.charCodeAt(0);
  37868. tokenTypes.closeSquare = closeSquare;
  37869. var dollar = 36; // `$`.charCodeAt(0);
  37870. tokenTypes.dollar = dollar;
  37871. var tilde = 126; // `~`.charCodeAt(0);
  37872. tokenTypes.tilde = tilde;
  37873. var caret = 94; // `^`.charCodeAt(0);
  37874. tokenTypes.caret = caret;
  37875. var plus = 43; // `+`.charCodeAt(0);
  37876. tokenTypes.plus = plus;
  37877. var equals = 61; // `=`.charCodeAt(0);
  37878. tokenTypes.equals = equals;
  37879. var pipe = 124; // `|`.charCodeAt(0);
  37880. tokenTypes.pipe = pipe;
  37881. var greaterThan = 62; // `>`.charCodeAt(0);
  37882. tokenTypes.greaterThan = greaterThan;
  37883. var space = 32; // ` `.charCodeAt(0);
  37884. tokenTypes.space = space;
  37885. var singleQuote = 39; // `'`.charCodeAt(0);
  37886. tokenTypes.singleQuote = singleQuote;
  37887. var doubleQuote = 34; // `"`.charCodeAt(0);
  37888. tokenTypes.doubleQuote = doubleQuote;
  37889. var slash = 47; // `/`.charCodeAt(0);
  37890. tokenTypes.slash = slash;
  37891. var bang = 33; // `!`.charCodeAt(0);
  37892. tokenTypes.bang = bang;
  37893. var backslash = 92; // '\\'.charCodeAt(0);
  37894. tokenTypes.backslash = backslash;
  37895. var cr = 13; // '\r'.charCodeAt(0);
  37896. tokenTypes.cr = cr;
  37897. var feed = 12; // '\f'.charCodeAt(0);
  37898. tokenTypes.feed = feed;
  37899. var newline = 10; // '\n'.charCodeAt(0);
  37900. tokenTypes.newline = newline;
  37901. var tab = 9; // '\t'.charCodeAt(0);
  37902. // Expose aliases primarily for readability.
  37903. tokenTypes.tab = tab;
  37904. var str = singleQuote;
  37905. // No good single character representation!
  37906. tokenTypes.str = str;
  37907. var comment$1 = -1;
  37908. tokenTypes.comment = comment$1;
  37909. var word = -2;
  37910. tokenTypes.word = word;
  37911. var combinator$1 = -3;
  37912. tokenTypes.combinator = combinator$1;
  37913. (function (exports) {
  37914. exports.__esModule = true;
  37915. exports.FIELDS = void 0;
  37916. exports["default"] = tokenize;
  37917. var t = _interopRequireWildcard(tokenTypes);
  37918. var _unescapable, _wordDelimiters;
  37919. 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); }
  37920. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && 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; }
  37921. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  37922. 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);
  37923. var hex = {};
  37924. var hexChars = "0123456789abcdefABCDEF";
  37925. for (var i = 0; i < hexChars.length; i++) {
  37926. hex[hexChars.charCodeAt(i)] = true;
  37927. }
  37928. /**
  37929. * Returns the last index of the bar css word
  37930. * @param {string} css The string in which the word begins
  37931. * @param {number} start The index into the string where word's first letter occurs
  37932. */
  37933. function consumeWord(css, start) {
  37934. var next = start;
  37935. var code;
  37936. do {
  37937. code = css.charCodeAt(next);
  37938. if (wordDelimiters[code]) {
  37939. return next - 1;
  37940. } else if (code === t.backslash) {
  37941. next = consumeEscape(css, next) + 1;
  37942. } else {
  37943. // All other characters are part of the word
  37944. next++;
  37945. }
  37946. } while (next < css.length);
  37947. return next - 1;
  37948. }
  37949. /**
  37950. * Returns the last index of the escape sequence
  37951. * @param {string} css The string in which the sequence begins
  37952. * @param {number} start The index into the string where escape character (`\`) occurs.
  37953. */
  37954. function consumeEscape(css, start) {
  37955. var next = start;
  37956. var code = css.charCodeAt(next + 1);
  37957. if (unescapable[code]) ; else if (hex[code]) {
  37958. var hexDigits = 0;
  37959. // consume up to 6 hex chars
  37960. do {
  37961. next++;
  37962. hexDigits++;
  37963. code = css.charCodeAt(next + 1);
  37964. } while (hex[code] && hexDigits < 6);
  37965. // if fewer than 6 hex chars, a trailing space ends the escape
  37966. if (hexDigits < 6 && code === t.space) {
  37967. next++;
  37968. }
  37969. } else {
  37970. // the next char is part of the current word
  37971. next++;
  37972. }
  37973. return next;
  37974. }
  37975. var FIELDS = {
  37976. TYPE: 0,
  37977. START_LINE: 1,
  37978. START_COL: 2,
  37979. END_LINE: 3,
  37980. END_COL: 4,
  37981. START_POS: 5,
  37982. END_POS: 6
  37983. };
  37984. exports.FIELDS = FIELDS;
  37985. function tokenize(input) {
  37986. var tokens = [];
  37987. var css = input.css.valueOf();
  37988. var _css = css,
  37989. length = _css.length;
  37990. var offset = -1;
  37991. var line = 1;
  37992. var start = 0;
  37993. var end = 0;
  37994. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  37995. function unclosed(what, fix) {
  37996. if (input.safe) {
  37997. // fyi: this is never set to true.
  37998. css += fix;
  37999. next = css.length - 1;
  38000. } else {
  38001. throw input.error('Unclosed ' + what, line, start - offset, start);
  38002. }
  38003. }
  38004. while (start < length) {
  38005. code = css.charCodeAt(start);
  38006. if (code === t.newline) {
  38007. offset = start;
  38008. line += 1;
  38009. }
  38010. switch (code) {
  38011. case t.space:
  38012. case t.tab:
  38013. case t.newline:
  38014. case t.cr:
  38015. case t.feed:
  38016. next = start;
  38017. do {
  38018. next += 1;
  38019. code = css.charCodeAt(next);
  38020. if (code === t.newline) {
  38021. offset = next;
  38022. line += 1;
  38023. }
  38024. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  38025. tokenType = t.space;
  38026. endLine = line;
  38027. endColumn = next - offset - 1;
  38028. end = next;
  38029. break;
  38030. case t.plus:
  38031. case t.greaterThan:
  38032. case t.tilde:
  38033. case t.pipe:
  38034. next = start;
  38035. do {
  38036. next += 1;
  38037. code = css.charCodeAt(next);
  38038. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  38039. tokenType = t.combinator;
  38040. endLine = line;
  38041. endColumn = start - offset;
  38042. end = next;
  38043. break;
  38044. // Consume these characters as single tokens.
  38045. case t.asterisk:
  38046. case t.ampersand:
  38047. case t.bang:
  38048. case t.comma:
  38049. case t.equals:
  38050. case t.dollar:
  38051. case t.caret:
  38052. case t.openSquare:
  38053. case t.closeSquare:
  38054. case t.colon:
  38055. case t.semicolon:
  38056. case t.openParenthesis:
  38057. case t.closeParenthesis:
  38058. next = start;
  38059. tokenType = code;
  38060. endLine = line;
  38061. endColumn = start - offset;
  38062. end = next + 1;
  38063. break;
  38064. case t.singleQuote:
  38065. case t.doubleQuote:
  38066. quote = code === t.singleQuote ? "'" : '"';
  38067. next = start;
  38068. do {
  38069. escaped = false;
  38070. next = css.indexOf(quote, next + 1);
  38071. if (next === -1) {
  38072. unclosed('quote', quote);
  38073. }
  38074. escapePos = next;
  38075. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  38076. escapePos -= 1;
  38077. escaped = !escaped;
  38078. }
  38079. } while (escaped);
  38080. tokenType = t.str;
  38081. endLine = line;
  38082. endColumn = start - offset;
  38083. end = next + 1;
  38084. break;
  38085. default:
  38086. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  38087. next = css.indexOf('*/', start + 2) + 1;
  38088. if (next === 0) {
  38089. unclosed('comment', '*/');
  38090. }
  38091. content = css.slice(start, next + 1);
  38092. lines = content.split('\n');
  38093. last = lines.length - 1;
  38094. if (last > 0) {
  38095. nextLine = line + last;
  38096. nextOffset = next - lines[last].length;
  38097. } else {
  38098. nextLine = line;
  38099. nextOffset = offset;
  38100. }
  38101. tokenType = t.comment;
  38102. line = nextLine;
  38103. endLine = nextLine;
  38104. endColumn = next - nextOffset;
  38105. } else if (code === t.slash) {
  38106. next = start;
  38107. tokenType = code;
  38108. endLine = line;
  38109. endColumn = start - offset;
  38110. end = next + 1;
  38111. } else {
  38112. next = consumeWord(css, start);
  38113. tokenType = t.word;
  38114. endLine = line;
  38115. endColumn = next - offset;
  38116. }
  38117. end = next + 1;
  38118. break;
  38119. }
  38120. // Ensure that the token structure remains consistent
  38121. tokens.push([tokenType,
  38122. // [0] Token type
  38123. line,
  38124. // [1] Starting line
  38125. start - offset,
  38126. // [2] Starting column
  38127. endLine,
  38128. // [3] Ending line
  38129. endColumn,
  38130. // [4] Ending column
  38131. start,
  38132. // [5] Start position / Source index
  38133. end // [6] End position
  38134. ]);
  38135. // Reset offset for the next token
  38136. if (nextOffset) {
  38137. offset = nextOffset;
  38138. nextOffset = null;
  38139. }
  38140. start = end;
  38141. }
  38142. return tokens;
  38143. }
  38144. } (tokenize));
  38145. (function (module, exports) {
  38146. exports.__esModule = true;
  38147. exports["default"] = void 0;
  38148. var _root = _interopRequireDefault(rootExports);
  38149. var _selector = _interopRequireDefault(selectorExports);
  38150. var _className = _interopRequireDefault(classNameExports);
  38151. var _comment = _interopRequireDefault(commentExports);
  38152. var _id = _interopRequireDefault(idExports);
  38153. var _tag = _interopRequireDefault(tagExports);
  38154. var _string = _interopRequireDefault(stringExports);
  38155. var _pseudo = _interopRequireDefault(pseudoExports);
  38156. var _attribute = _interopRequireWildcard(attribute$1);
  38157. var _universal = _interopRequireDefault(universalExports);
  38158. var _combinator = _interopRequireDefault(combinatorExports);
  38159. var _nesting = _interopRequireDefault(nestingExports);
  38160. var _sortAscending = _interopRequireDefault(sortAscendingExports);
  38161. var _tokenize = _interopRequireWildcard(tokenize);
  38162. var tokens = _interopRequireWildcard(tokenTypes);
  38163. var types$1 = _interopRequireWildcard(types);
  38164. var _util = util$6;
  38165. var _WHITESPACE_TOKENS, _Object$assign;
  38166. 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); }
  38167. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && 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; }
  38168. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38169. 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); } }
  38170. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  38171. 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);
  38172. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  38173. function tokenStart(token) {
  38174. return {
  38175. line: token[_tokenize.FIELDS.START_LINE],
  38176. column: token[_tokenize.FIELDS.START_COL]
  38177. };
  38178. }
  38179. function tokenEnd(token) {
  38180. return {
  38181. line: token[_tokenize.FIELDS.END_LINE],
  38182. column: token[_tokenize.FIELDS.END_COL]
  38183. };
  38184. }
  38185. function getSource(startLine, startColumn, endLine, endColumn) {
  38186. return {
  38187. start: {
  38188. line: startLine,
  38189. column: startColumn
  38190. },
  38191. end: {
  38192. line: endLine,
  38193. column: endColumn
  38194. }
  38195. };
  38196. }
  38197. function getTokenSource(token) {
  38198. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  38199. }
  38200. function getTokenSourceSpan(startToken, endToken) {
  38201. if (!startToken) {
  38202. return undefined;
  38203. }
  38204. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  38205. }
  38206. function unescapeProp(node, prop) {
  38207. var value = node[prop];
  38208. if (typeof value !== "string") {
  38209. return;
  38210. }
  38211. if (value.indexOf("\\") !== -1) {
  38212. (0, _util.ensureObject)(node, 'raws');
  38213. node[prop] = (0, _util.unesc)(value);
  38214. if (node.raws[prop] === undefined) {
  38215. node.raws[prop] = value;
  38216. }
  38217. }
  38218. return node;
  38219. }
  38220. function indexesOf(array, item) {
  38221. var i = -1;
  38222. var indexes = [];
  38223. while ((i = array.indexOf(item, i + 1)) !== -1) {
  38224. indexes.push(i);
  38225. }
  38226. return indexes;
  38227. }
  38228. function uniqs() {
  38229. var list = Array.prototype.concat.apply([], arguments);
  38230. return list.filter(function (item, i) {
  38231. return i === list.indexOf(item);
  38232. });
  38233. }
  38234. var Parser = /*#__PURE__*/function () {
  38235. function Parser(rule, options) {
  38236. if (options === void 0) {
  38237. options = {};
  38238. }
  38239. this.rule = rule;
  38240. this.options = Object.assign({
  38241. lossy: false,
  38242. safe: false
  38243. }, options);
  38244. this.position = 0;
  38245. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  38246. this.tokens = (0, _tokenize["default"])({
  38247. css: this.css,
  38248. error: this._errorGenerator(),
  38249. safe: this.options.safe
  38250. });
  38251. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  38252. this.root = new _root["default"]({
  38253. source: rootSource
  38254. });
  38255. this.root.errorGenerator = this._errorGenerator();
  38256. var selector = new _selector["default"]({
  38257. source: {
  38258. start: {
  38259. line: 1,
  38260. column: 1
  38261. }
  38262. }
  38263. });
  38264. this.root.append(selector);
  38265. this.current = selector;
  38266. this.loop();
  38267. }
  38268. var _proto = Parser.prototype;
  38269. _proto._errorGenerator = function _errorGenerator() {
  38270. var _this = this;
  38271. return function (message, errorOptions) {
  38272. if (typeof _this.rule === 'string') {
  38273. return new Error(message);
  38274. }
  38275. return _this.rule.error(message, errorOptions);
  38276. };
  38277. };
  38278. _proto.attribute = function attribute() {
  38279. var attr = [];
  38280. var startingToken = this.currToken;
  38281. this.position++;
  38282. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38283. attr.push(this.currToken);
  38284. this.position++;
  38285. }
  38286. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38287. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38288. }
  38289. var len = attr.length;
  38290. var node = {
  38291. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  38292. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38293. };
  38294. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  38295. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  38296. }
  38297. var pos = 0;
  38298. var spaceBefore = '';
  38299. var commentBefore = '';
  38300. var lastAdded = null;
  38301. var spaceAfterMeaningfulToken = false;
  38302. while (pos < len) {
  38303. var token = attr[pos];
  38304. var content = this.content(token);
  38305. var next = attr[pos + 1];
  38306. switch (token[_tokenize.FIELDS.TYPE]) {
  38307. case tokens.space:
  38308. // if (
  38309. // len === 1 ||
  38310. // pos === 0 && this.content(next) === '|'
  38311. // ) {
  38312. // return this.expected('attribute', token[TOKEN.START_POS], content);
  38313. // }
  38314. spaceAfterMeaningfulToken = true;
  38315. if (this.options.lossy) {
  38316. break;
  38317. }
  38318. if (lastAdded) {
  38319. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  38320. var prevContent = node.spaces[lastAdded].after || '';
  38321. node.spaces[lastAdded].after = prevContent + content;
  38322. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  38323. if (existingComment) {
  38324. node.raws.spaces[lastAdded].after = existingComment + content;
  38325. }
  38326. } else {
  38327. spaceBefore = spaceBefore + content;
  38328. commentBefore = commentBefore + content;
  38329. }
  38330. break;
  38331. case tokens.asterisk:
  38332. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38333. node.operator = content;
  38334. lastAdded = 'operator';
  38335. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  38336. if (spaceBefore) {
  38337. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38338. node.spaces.attribute.before = spaceBefore;
  38339. spaceBefore = '';
  38340. }
  38341. if (commentBefore) {
  38342. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38343. node.raws.spaces.attribute.before = spaceBefore;
  38344. commentBefore = '';
  38345. }
  38346. node.namespace = (node.namespace || "") + content;
  38347. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  38348. if (rawValue) {
  38349. node.raws.namespace += content;
  38350. }
  38351. lastAdded = 'namespace';
  38352. }
  38353. spaceAfterMeaningfulToken = false;
  38354. break;
  38355. case tokens.dollar:
  38356. if (lastAdded === "value") {
  38357. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  38358. node.value += "$";
  38359. if (oldRawValue) {
  38360. node.raws.value = oldRawValue + "$";
  38361. }
  38362. break;
  38363. }
  38364. // Falls through
  38365. case tokens.caret:
  38366. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38367. node.operator = content;
  38368. lastAdded = 'operator';
  38369. }
  38370. spaceAfterMeaningfulToken = false;
  38371. break;
  38372. case tokens.combinator:
  38373. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38374. node.operator = content;
  38375. lastAdded = 'operator';
  38376. }
  38377. if (content !== '|') {
  38378. spaceAfterMeaningfulToken = false;
  38379. break;
  38380. }
  38381. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38382. node.operator = content;
  38383. lastAdded = 'operator';
  38384. } else if (!node.namespace && !node.attribute) {
  38385. node.namespace = true;
  38386. }
  38387. spaceAfterMeaningfulToken = false;
  38388. break;
  38389. case tokens.word:
  38390. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
  38391. // this look-ahead probably fails with comment nodes involved.
  38392. !node.operator && !node.namespace) {
  38393. node.namespace = content;
  38394. lastAdded = 'namespace';
  38395. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  38396. if (spaceBefore) {
  38397. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38398. node.spaces.attribute.before = spaceBefore;
  38399. spaceBefore = '';
  38400. }
  38401. if (commentBefore) {
  38402. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38403. node.raws.spaces.attribute.before = commentBefore;
  38404. commentBefore = '';
  38405. }
  38406. node.attribute = (node.attribute || "") + content;
  38407. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  38408. if (_rawValue) {
  38409. node.raws.attribute += content;
  38410. }
  38411. lastAdded = 'attribute';
  38412. } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
  38413. var _unescaped = (0, _util.unesc)(content);
  38414. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  38415. var oldValue = node.value || '';
  38416. node.value = oldValue + _unescaped;
  38417. node.quoteMark = null;
  38418. if (_unescaped !== content || _oldRawValue) {
  38419. (0, _util.ensureObject)(node, 'raws');
  38420. node.raws.value = (_oldRawValue || oldValue) + content;
  38421. }
  38422. lastAdded = 'value';
  38423. } else {
  38424. var insensitive = content === 'i' || content === "I";
  38425. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  38426. node.insensitive = insensitive;
  38427. if (!insensitive || content === "I") {
  38428. (0, _util.ensureObject)(node, 'raws');
  38429. node.raws.insensitiveFlag = content;
  38430. }
  38431. lastAdded = 'insensitive';
  38432. if (spaceBefore) {
  38433. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  38434. node.spaces.insensitive.before = spaceBefore;
  38435. spaceBefore = '';
  38436. }
  38437. if (commentBefore) {
  38438. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  38439. node.raws.spaces.insensitive.before = commentBefore;
  38440. commentBefore = '';
  38441. }
  38442. } else if (node.value || node.value === '') {
  38443. lastAdded = 'value';
  38444. node.value += content;
  38445. if (node.raws.value) {
  38446. node.raws.value += content;
  38447. }
  38448. }
  38449. }
  38450. spaceAfterMeaningfulToken = false;
  38451. break;
  38452. case tokens.str:
  38453. if (!node.attribute || !node.operator) {
  38454. return this.error("Expected an attribute followed by an operator preceding the string.", {
  38455. index: token[_tokenize.FIELDS.START_POS]
  38456. });
  38457. }
  38458. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  38459. unescaped = _unescapeValue.unescaped,
  38460. quoteMark = _unescapeValue.quoteMark;
  38461. node.value = unescaped;
  38462. node.quoteMark = quoteMark;
  38463. lastAdded = 'value';
  38464. (0, _util.ensureObject)(node, 'raws');
  38465. node.raws.value = content;
  38466. spaceAfterMeaningfulToken = false;
  38467. break;
  38468. case tokens.equals:
  38469. if (!node.attribute) {
  38470. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  38471. }
  38472. if (node.value) {
  38473. return this.error('Unexpected "=" found; an operator was already defined.', {
  38474. index: token[_tokenize.FIELDS.START_POS]
  38475. });
  38476. }
  38477. node.operator = node.operator ? node.operator + content : content;
  38478. lastAdded = 'operator';
  38479. spaceAfterMeaningfulToken = false;
  38480. break;
  38481. case tokens.comment:
  38482. if (lastAdded) {
  38483. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  38484. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  38485. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  38486. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  38487. node.raws.spaces[lastAdded].after = rawLastComment + content;
  38488. } else {
  38489. var lastValue = node[lastAdded] || '';
  38490. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  38491. (0, _util.ensureObject)(node, 'raws');
  38492. node.raws[lastAdded] = rawLastValue + content;
  38493. }
  38494. } else {
  38495. commentBefore = commentBefore + content;
  38496. }
  38497. break;
  38498. default:
  38499. return this.error("Unexpected \"" + content + "\" found.", {
  38500. index: token[_tokenize.FIELDS.START_POS]
  38501. });
  38502. }
  38503. pos++;
  38504. }
  38505. unescapeProp(node, "attribute");
  38506. unescapeProp(node, "namespace");
  38507. this.newNode(new _attribute["default"](node));
  38508. this.position++;
  38509. }
  38510. /**
  38511. * return a node containing meaningless garbage up to (but not including) the specified token position.
  38512. * if the token position is negative, all remaining tokens are consumed.
  38513. *
  38514. * This returns an array containing a single string node if all whitespace,
  38515. * otherwise an array of comment nodes with space before and after.
  38516. *
  38517. * These tokens are not added to the current selector, the caller can add them or use them to amend
  38518. * a previous node's space metadata.
  38519. *
  38520. * In lossy mode, this returns only comments.
  38521. */;
  38522. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  38523. if (stopPosition < 0) {
  38524. stopPosition = this.tokens.length;
  38525. }
  38526. var startPosition = this.position;
  38527. var nodes = [];
  38528. var space = "";
  38529. var lastComment = undefined;
  38530. do {
  38531. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  38532. if (!this.options.lossy) {
  38533. space += this.content();
  38534. }
  38535. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  38536. var spaces = {};
  38537. if (space) {
  38538. spaces.before = space;
  38539. space = "";
  38540. }
  38541. lastComment = new _comment["default"]({
  38542. value: this.content(),
  38543. source: getTokenSource(this.currToken),
  38544. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  38545. spaces: spaces
  38546. });
  38547. nodes.push(lastComment);
  38548. }
  38549. } while (++this.position < stopPosition);
  38550. if (space) {
  38551. if (lastComment) {
  38552. lastComment.spaces.after = space;
  38553. } else if (!this.options.lossy) {
  38554. var firstToken = this.tokens[startPosition];
  38555. var lastToken = this.tokens[this.position - 1];
  38556. nodes.push(new _string["default"]({
  38557. value: '',
  38558. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  38559. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  38560. spaces: {
  38561. before: space,
  38562. after: ''
  38563. }
  38564. }));
  38565. }
  38566. }
  38567. return nodes;
  38568. }
  38569. /**
  38570. *
  38571. * @param {*} nodes
  38572. */;
  38573. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  38574. var _this2 = this;
  38575. if (requiredSpace === void 0) {
  38576. requiredSpace = false;
  38577. }
  38578. var space = "";
  38579. var rawSpace = "";
  38580. nodes.forEach(function (n) {
  38581. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  38582. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  38583. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  38584. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  38585. });
  38586. if (rawSpace === space) {
  38587. rawSpace = undefined;
  38588. }
  38589. var result = {
  38590. space: space,
  38591. rawSpace: rawSpace
  38592. };
  38593. return result;
  38594. };
  38595. _proto.isNamedCombinator = function isNamedCombinator(position) {
  38596. if (position === void 0) {
  38597. position = this.position;
  38598. }
  38599. 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;
  38600. };
  38601. _proto.namedCombinator = function namedCombinator() {
  38602. if (this.isNamedCombinator()) {
  38603. var nameRaw = this.content(this.tokens[this.position + 1]);
  38604. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  38605. var raws = {};
  38606. if (name !== nameRaw) {
  38607. raws.value = "/" + nameRaw + "/";
  38608. }
  38609. var node = new _combinator["default"]({
  38610. value: "/" + name + "/",
  38611. 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]),
  38612. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  38613. raws: raws
  38614. });
  38615. this.position = this.position + 3;
  38616. return node;
  38617. } else {
  38618. this.unexpected();
  38619. }
  38620. };
  38621. _proto.combinator = function combinator() {
  38622. var _this3 = this;
  38623. if (this.content() === '|') {
  38624. return this.namespace();
  38625. }
  38626. // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  38627. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  38628. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma) {
  38629. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  38630. if (nodes.length > 0) {
  38631. var last = this.current.last;
  38632. if (last) {
  38633. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  38634. space = _this$convertWhitespa.space,
  38635. rawSpace = _this$convertWhitespa.rawSpace;
  38636. if (rawSpace !== undefined) {
  38637. last.rawSpaceAfter += rawSpace;
  38638. }
  38639. last.spaces.after += space;
  38640. } else {
  38641. nodes.forEach(function (n) {
  38642. return _this3.newNode(n);
  38643. });
  38644. }
  38645. }
  38646. return;
  38647. }
  38648. var firstToken = this.currToken;
  38649. var spaceOrDescendantSelectorNodes = undefined;
  38650. if (nextSigTokenPos > this.position) {
  38651. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  38652. }
  38653. var node;
  38654. if (this.isNamedCombinator()) {
  38655. node = this.namedCombinator();
  38656. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  38657. node = new _combinator["default"]({
  38658. value: this.content(),
  38659. source: getTokenSource(this.currToken),
  38660. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  38661. });
  38662. this.position++;
  38663. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  38664. this.unexpected();
  38665. }
  38666. if (node) {
  38667. if (spaceOrDescendantSelectorNodes) {
  38668. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  38669. _space = _this$convertWhitespa2.space,
  38670. _rawSpace = _this$convertWhitespa2.rawSpace;
  38671. node.spaces.before = _space;
  38672. node.rawSpaceBefore = _rawSpace;
  38673. }
  38674. } else {
  38675. // descendant combinator
  38676. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  38677. _space2 = _this$convertWhitespa3.space,
  38678. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  38679. if (!_rawSpace2) {
  38680. _rawSpace2 = _space2;
  38681. }
  38682. var spaces = {};
  38683. var raws = {
  38684. spaces: {}
  38685. };
  38686. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  38687. spaces.before = _space2.slice(0, _space2.length - 1);
  38688. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  38689. } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
  38690. spaces.after = _space2.slice(1);
  38691. raws.spaces.after = _rawSpace2.slice(1);
  38692. } else {
  38693. raws.value = _rawSpace2;
  38694. }
  38695. node = new _combinator["default"]({
  38696. value: ' ',
  38697. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  38698. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  38699. spaces: spaces,
  38700. raws: raws
  38701. });
  38702. }
  38703. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  38704. node.spaces.after = this.optionalSpace(this.content());
  38705. this.position++;
  38706. }
  38707. return this.newNode(node);
  38708. };
  38709. _proto.comma = function comma() {
  38710. if (this.position === this.tokens.length - 1) {
  38711. this.root.trailingComma = true;
  38712. this.position++;
  38713. return;
  38714. }
  38715. this.current._inferEndPosition();
  38716. var selector = new _selector["default"]({
  38717. source: {
  38718. start: tokenStart(this.tokens[this.position + 1])
  38719. }
  38720. });
  38721. this.current.parent.append(selector);
  38722. this.current = selector;
  38723. this.position++;
  38724. };
  38725. _proto.comment = function comment() {
  38726. var current = this.currToken;
  38727. this.newNode(new _comment["default"]({
  38728. value: this.content(),
  38729. source: getTokenSource(current),
  38730. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38731. }));
  38732. this.position++;
  38733. };
  38734. _proto.error = function error(message, opts) {
  38735. throw this.root.error(message, opts);
  38736. };
  38737. _proto.missingBackslash = function missingBackslash() {
  38738. return this.error('Expected a backslash preceding the semicolon.', {
  38739. index: this.currToken[_tokenize.FIELDS.START_POS]
  38740. });
  38741. };
  38742. _proto.missingParenthesis = function missingParenthesis() {
  38743. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  38744. };
  38745. _proto.missingSquareBracket = function missingSquareBracket() {
  38746. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38747. };
  38748. _proto.unexpected = function unexpected() {
  38749. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  38750. };
  38751. _proto.unexpectedPipe = function unexpectedPipe() {
  38752. return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
  38753. };
  38754. _proto.namespace = function namespace() {
  38755. var before = this.prevToken && this.content(this.prevToken) || true;
  38756. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  38757. this.position++;
  38758. return this.word(before);
  38759. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  38760. this.position++;
  38761. return this.universal(before);
  38762. }
  38763. this.unexpectedPipe();
  38764. };
  38765. _proto.nesting = function nesting() {
  38766. if (this.nextToken) {
  38767. var nextContent = this.content(this.nextToken);
  38768. if (nextContent === "|") {
  38769. this.position++;
  38770. return;
  38771. }
  38772. }
  38773. var current = this.currToken;
  38774. this.newNode(new _nesting["default"]({
  38775. value: this.content(),
  38776. source: getTokenSource(current),
  38777. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38778. }));
  38779. this.position++;
  38780. };
  38781. _proto.parentheses = function parentheses() {
  38782. var last = this.current.last;
  38783. var unbalanced = 1;
  38784. this.position++;
  38785. if (last && last.type === types$1.PSEUDO) {
  38786. var selector = new _selector["default"]({
  38787. source: {
  38788. start: tokenStart(this.tokens[this.position - 1])
  38789. }
  38790. });
  38791. var cache = this.current;
  38792. last.append(selector);
  38793. this.current = selector;
  38794. while (this.position < this.tokens.length && unbalanced) {
  38795. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  38796. unbalanced++;
  38797. }
  38798. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  38799. unbalanced--;
  38800. }
  38801. if (unbalanced) {
  38802. this.parse();
  38803. } else {
  38804. this.current.source.end = tokenEnd(this.currToken);
  38805. this.current.parent.source.end = tokenEnd(this.currToken);
  38806. this.position++;
  38807. }
  38808. }
  38809. this.current = cache;
  38810. } else {
  38811. // I think this case should be an error. It's used to implement a basic parse of media queries
  38812. // but I don't think it's a good idea.
  38813. var parenStart = this.currToken;
  38814. var parenValue = "(";
  38815. var parenEnd;
  38816. while (this.position < this.tokens.length && unbalanced) {
  38817. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  38818. unbalanced++;
  38819. }
  38820. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  38821. unbalanced--;
  38822. }
  38823. parenEnd = this.currToken;
  38824. parenValue += this.parseParenthesisToken(this.currToken);
  38825. this.position++;
  38826. }
  38827. if (last) {
  38828. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  38829. } else {
  38830. this.newNode(new _string["default"]({
  38831. value: parenValue,
  38832. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  38833. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  38834. }));
  38835. }
  38836. }
  38837. if (unbalanced) {
  38838. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  38839. }
  38840. };
  38841. _proto.pseudo = function pseudo() {
  38842. var _this4 = this;
  38843. var pseudoStr = '';
  38844. var startingToken = this.currToken;
  38845. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  38846. pseudoStr += this.content();
  38847. this.position++;
  38848. }
  38849. if (!this.currToken) {
  38850. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  38851. }
  38852. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  38853. this.splitWord(false, function (first, length) {
  38854. pseudoStr += first;
  38855. _this4.newNode(new _pseudo["default"]({
  38856. value: pseudoStr,
  38857. source: getTokenSourceSpan(startingToken, _this4.currToken),
  38858. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38859. }));
  38860. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  38861. _this4.error('Misplaced parenthesis.', {
  38862. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  38863. });
  38864. }
  38865. });
  38866. } else {
  38867. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  38868. }
  38869. };
  38870. _proto.space = function space() {
  38871. var content = this.content();
  38872. // Handle space before and after the selector
  38873. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  38874. return node.type === 'comment';
  38875. })) {
  38876. this.spaces = this.optionalSpace(content);
  38877. this.position++;
  38878. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  38879. this.current.last.spaces.after = this.optionalSpace(content);
  38880. this.position++;
  38881. } else {
  38882. this.combinator();
  38883. }
  38884. };
  38885. _proto.string = function string() {
  38886. var current = this.currToken;
  38887. this.newNode(new _string["default"]({
  38888. value: this.content(),
  38889. source: getTokenSource(current),
  38890. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38891. }));
  38892. this.position++;
  38893. };
  38894. _proto.universal = function universal(namespace) {
  38895. var nextToken = this.nextToken;
  38896. if (nextToken && this.content(nextToken) === '|') {
  38897. this.position++;
  38898. return this.namespace();
  38899. }
  38900. var current = this.currToken;
  38901. this.newNode(new _universal["default"]({
  38902. value: this.content(),
  38903. source: getTokenSource(current),
  38904. sourceIndex: current[_tokenize.FIELDS.START_POS]
  38905. }), namespace);
  38906. this.position++;
  38907. };
  38908. _proto.splitWord = function splitWord(namespace, firstCallback) {
  38909. var _this5 = this;
  38910. var nextToken = this.nextToken;
  38911. var word = this.content();
  38912. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  38913. this.position++;
  38914. var current = this.content();
  38915. word += current;
  38916. if (current.lastIndexOf('\\') === current.length - 1) {
  38917. var next = this.nextToken;
  38918. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  38919. word += this.requiredSpace(this.content(next));
  38920. this.position++;
  38921. }
  38922. }
  38923. nextToken = this.nextToken;
  38924. }
  38925. var hasClass = indexesOf(word, '.').filter(function (i) {
  38926. // Allow escaped dot within class name
  38927. var escapedDot = word[i - 1] === '\\';
  38928. // Allow decimal numbers percent in @keyframes
  38929. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  38930. return !escapedDot && !isKeyframesPercent;
  38931. });
  38932. var hasId = indexesOf(word, '#').filter(function (i) {
  38933. return word[i - 1] !== '\\';
  38934. });
  38935. // Eliminate Sass interpolations from the list of id indexes
  38936. var interpolations = indexesOf(word, '#{');
  38937. if (interpolations.length) {
  38938. hasId = hasId.filter(function (hashIndex) {
  38939. return !~interpolations.indexOf(hashIndex);
  38940. });
  38941. }
  38942. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  38943. indices.forEach(function (ind, i) {
  38944. var index = indices[i + 1] || word.length;
  38945. var value = word.slice(ind, index);
  38946. if (i === 0 && firstCallback) {
  38947. return firstCallback.call(_this5, value, indices.length);
  38948. }
  38949. var node;
  38950. var current = _this5.currToken;
  38951. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  38952. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  38953. if (~hasClass.indexOf(ind)) {
  38954. var classNameOpts = {
  38955. value: value.slice(1),
  38956. source: source,
  38957. sourceIndex: sourceIndex
  38958. };
  38959. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  38960. } else if (~hasId.indexOf(ind)) {
  38961. var idOpts = {
  38962. value: value.slice(1),
  38963. source: source,
  38964. sourceIndex: sourceIndex
  38965. };
  38966. node = new _id["default"](unescapeProp(idOpts, "value"));
  38967. } else {
  38968. var tagOpts = {
  38969. value: value,
  38970. source: source,
  38971. sourceIndex: sourceIndex
  38972. };
  38973. unescapeProp(tagOpts, "value");
  38974. node = new _tag["default"](tagOpts);
  38975. }
  38976. _this5.newNode(node, namespace);
  38977. // Ensure that the namespace is used only once
  38978. namespace = null;
  38979. });
  38980. this.position++;
  38981. };
  38982. _proto.word = function word(namespace) {
  38983. var nextToken = this.nextToken;
  38984. if (nextToken && this.content(nextToken) === '|') {
  38985. this.position++;
  38986. return this.namespace();
  38987. }
  38988. return this.splitWord(namespace);
  38989. };
  38990. _proto.loop = function loop() {
  38991. while (this.position < this.tokens.length) {
  38992. this.parse(true);
  38993. }
  38994. this.current._inferEndPosition();
  38995. return this.root;
  38996. };
  38997. _proto.parse = function parse(throwOnParenthesis) {
  38998. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  38999. case tokens.space:
  39000. this.space();
  39001. break;
  39002. case tokens.comment:
  39003. this.comment();
  39004. break;
  39005. case tokens.openParenthesis:
  39006. this.parentheses();
  39007. break;
  39008. case tokens.closeParenthesis:
  39009. if (throwOnParenthesis) {
  39010. this.missingParenthesis();
  39011. }
  39012. break;
  39013. case tokens.openSquare:
  39014. this.attribute();
  39015. break;
  39016. case tokens.dollar:
  39017. case tokens.caret:
  39018. case tokens.equals:
  39019. case tokens.word:
  39020. this.word();
  39021. break;
  39022. case tokens.colon:
  39023. this.pseudo();
  39024. break;
  39025. case tokens.comma:
  39026. this.comma();
  39027. break;
  39028. case tokens.asterisk:
  39029. this.universal();
  39030. break;
  39031. case tokens.ampersand:
  39032. this.nesting();
  39033. break;
  39034. case tokens.slash:
  39035. case tokens.combinator:
  39036. this.combinator();
  39037. break;
  39038. case tokens.str:
  39039. this.string();
  39040. break;
  39041. // These cases throw; no break needed.
  39042. case tokens.closeSquare:
  39043. this.missingSquareBracket();
  39044. case tokens.semicolon:
  39045. this.missingBackslash();
  39046. default:
  39047. this.unexpected();
  39048. }
  39049. }
  39050. /**
  39051. * Helpers
  39052. */;
  39053. _proto.expected = function expected(description, index, found) {
  39054. if (Array.isArray(description)) {
  39055. var last = description.pop();
  39056. description = description.join(', ') + " or " + last;
  39057. }
  39058. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  39059. if (!found) {
  39060. return this.error("Expected " + an + " " + description + ".", {
  39061. index: index
  39062. });
  39063. }
  39064. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  39065. index: index
  39066. });
  39067. };
  39068. _proto.requiredSpace = function requiredSpace(space) {
  39069. return this.options.lossy ? ' ' : space;
  39070. };
  39071. _proto.optionalSpace = function optionalSpace(space) {
  39072. return this.options.lossy ? '' : space;
  39073. };
  39074. _proto.lossySpace = function lossySpace(space, required) {
  39075. if (this.options.lossy) {
  39076. return required ? ' ' : '';
  39077. } else {
  39078. return space;
  39079. }
  39080. };
  39081. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  39082. var content = this.content(token);
  39083. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  39084. return this.requiredSpace(content);
  39085. } else {
  39086. return content;
  39087. }
  39088. };
  39089. _proto.newNode = function newNode(node, namespace) {
  39090. if (namespace) {
  39091. if (/^ +$/.test(namespace)) {
  39092. if (!this.options.lossy) {
  39093. this.spaces = (this.spaces || '') + namespace;
  39094. }
  39095. namespace = true;
  39096. }
  39097. node.namespace = namespace;
  39098. unescapeProp(node, "namespace");
  39099. }
  39100. if (this.spaces) {
  39101. node.spaces.before = this.spaces;
  39102. this.spaces = '';
  39103. }
  39104. return this.current.append(node);
  39105. };
  39106. _proto.content = function content(token) {
  39107. if (token === void 0) {
  39108. token = this.currToken;
  39109. }
  39110. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  39111. };
  39112. /**
  39113. * returns the index of the next non-whitespace, non-comment token.
  39114. * returns -1 if no meaningful token is found.
  39115. */
  39116. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  39117. if (startPosition === void 0) {
  39118. startPosition = this.position + 1;
  39119. }
  39120. var searchPosition = startPosition;
  39121. while (searchPosition < this.tokens.length) {
  39122. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  39123. searchPosition++;
  39124. continue;
  39125. } else {
  39126. return searchPosition;
  39127. }
  39128. }
  39129. return -1;
  39130. };
  39131. _createClass(Parser, [{
  39132. key: "currToken",
  39133. get: function get() {
  39134. return this.tokens[this.position];
  39135. }
  39136. }, {
  39137. key: "nextToken",
  39138. get: function get() {
  39139. return this.tokens[this.position + 1];
  39140. }
  39141. }, {
  39142. key: "prevToken",
  39143. get: function get() {
  39144. return this.tokens[this.position - 1];
  39145. }
  39146. }]);
  39147. return Parser;
  39148. }();
  39149. exports["default"] = Parser;
  39150. module.exports = exports.default;
  39151. } (parser, parser.exports));
  39152. var parserExports = parser.exports;
  39153. (function (module, exports) {
  39154. exports.__esModule = true;
  39155. exports["default"] = void 0;
  39156. var _parser = _interopRequireDefault(parserExports);
  39157. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39158. var Processor = /*#__PURE__*/function () {
  39159. function Processor(func, options) {
  39160. this.func = func || function noop() {};
  39161. this.funcRes = null;
  39162. this.options = options;
  39163. }
  39164. var _proto = Processor.prototype;
  39165. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  39166. if (options === void 0) {
  39167. options = {};
  39168. }
  39169. var merged = Object.assign({}, this.options, options);
  39170. if (merged.updateSelector === false) {
  39171. return false;
  39172. } else {
  39173. return typeof rule !== "string";
  39174. }
  39175. };
  39176. _proto._isLossy = function _isLossy(options) {
  39177. if (options === void 0) {
  39178. options = {};
  39179. }
  39180. var merged = Object.assign({}, this.options, options);
  39181. if (merged.lossless === false) {
  39182. return true;
  39183. } else {
  39184. return false;
  39185. }
  39186. };
  39187. _proto._root = function _root(rule, options) {
  39188. if (options === void 0) {
  39189. options = {};
  39190. }
  39191. var parser = new _parser["default"](rule, this._parseOptions(options));
  39192. return parser.root;
  39193. };
  39194. _proto._parseOptions = function _parseOptions(options) {
  39195. return {
  39196. lossy: this._isLossy(options)
  39197. };
  39198. };
  39199. _proto._run = function _run(rule, options) {
  39200. var _this = this;
  39201. if (options === void 0) {
  39202. options = {};
  39203. }
  39204. return new Promise(function (resolve, reject) {
  39205. try {
  39206. var root = _this._root(rule, options);
  39207. Promise.resolve(_this.func(root)).then(function (transform) {
  39208. var string = undefined;
  39209. if (_this._shouldUpdateSelector(rule, options)) {
  39210. string = root.toString();
  39211. rule.selector = string;
  39212. }
  39213. return {
  39214. transform: transform,
  39215. root: root,
  39216. string: string
  39217. };
  39218. }).then(resolve, reject);
  39219. } catch (e) {
  39220. reject(e);
  39221. return;
  39222. }
  39223. });
  39224. };
  39225. _proto._runSync = function _runSync(rule, options) {
  39226. if (options === void 0) {
  39227. options = {};
  39228. }
  39229. var root = this._root(rule, options);
  39230. var transform = this.func(root);
  39231. if (transform && typeof transform.then === "function") {
  39232. throw new Error("Selector processor returned a promise to a synchronous call.");
  39233. }
  39234. var string = undefined;
  39235. if (options.updateSelector && typeof rule !== "string") {
  39236. string = root.toString();
  39237. rule.selector = string;
  39238. }
  39239. return {
  39240. transform: transform,
  39241. root: root,
  39242. string: string
  39243. };
  39244. }
  39245. /**
  39246. * Process rule into a selector AST.
  39247. *
  39248. * @param rule {postcss.Rule | string} The css selector to be processed
  39249. * @param options The options for processing
  39250. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  39251. */;
  39252. _proto.ast = function ast(rule, options) {
  39253. return this._run(rule, options).then(function (result) {
  39254. return result.root;
  39255. });
  39256. }
  39257. /**
  39258. * Process rule into a selector AST synchronously.
  39259. *
  39260. * @param rule {postcss.Rule | string} The css selector to be processed
  39261. * @param options The options for processing
  39262. * @returns {parser.Root} The AST of the selector after processing it.
  39263. */;
  39264. _proto.astSync = function astSync(rule, options) {
  39265. return this._runSync(rule, options).root;
  39266. }
  39267. /**
  39268. * Process a selector into a transformed value asynchronously
  39269. *
  39270. * @param rule {postcss.Rule | string} The css selector to be processed
  39271. * @param options The options for processing
  39272. * @returns {Promise<any>} The value returned by the processor.
  39273. */;
  39274. _proto.transform = function transform(rule, options) {
  39275. return this._run(rule, options).then(function (result) {
  39276. return result.transform;
  39277. });
  39278. }
  39279. /**
  39280. * Process a selector into a transformed value synchronously.
  39281. *
  39282. * @param rule {postcss.Rule | string} The css selector to be processed
  39283. * @param options The options for processing
  39284. * @returns {any} The value returned by the processor.
  39285. */;
  39286. _proto.transformSync = function transformSync(rule, options) {
  39287. return this._runSync(rule, options).transform;
  39288. }
  39289. /**
  39290. * Process a selector into a new selector string asynchronously.
  39291. *
  39292. * @param rule {postcss.Rule | string} The css selector to be processed
  39293. * @param options The options for processing
  39294. * @returns {string} the selector after processing.
  39295. */;
  39296. _proto.process = function process(rule, options) {
  39297. return this._run(rule, options).then(function (result) {
  39298. return result.string || result.root.toString();
  39299. });
  39300. }
  39301. /**
  39302. * Process a selector into a new selector string synchronously.
  39303. *
  39304. * @param rule {postcss.Rule | string} The css selector to be processed
  39305. * @param options The options for processing
  39306. * @returns {string} the selector after processing.
  39307. */;
  39308. _proto.processSync = function processSync(rule, options) {
  39309. var result = this._runSync(rule, options);
  39310. return result.string || result.root.toString();
  39311. };
  39312. return Processor;
  39313. }();
  39314. exports["default"] = Processor;
  39315. module.exports = exports.default;
  39316. } (processor, processor.exports));
  39317. var processorExports = processor.exports;
  39318. var selectors = {};
  39319. var constructors = {};
  39320. constructors.__esModule = true;
  39321. 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;
  39322. var _attribute = _interopRequireDefault(attribute$1);
  39323. var _className = _interopRequireDefault(classNameExports);
  39324. var _combinator = _interopRequireDefault(combinatorExports);
  39325. var _comment = _interopRequireDefault(commentExports);
  39326. var _id = _interopRequireDefault(idExports);
  39327. var _nesting = _interopRequireDefault(nestingExports);
  39328. var _pseudo = _interopRequireDefault(pseudoExports);
  39329. var _root = _interopRequireDefault(rootExports);
  39330. var _selector = _interopRequireDefault(selectorExports);
  39331. var _string = _interopRequireDefault(stringExports);
  39332. var _tag = _interopRequireDefault(tagExports);
  39333. var _universal = _interopRequireDefault(universalExports);
  39334. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39335. var attribute = function attribute(opts) {
  39336. return new _attribute["default"](opts);
  39337. };
  39338. constructors.attribute = attribute;
  39339. var className = function className(opts) {
  39340. return new _className["default"](opts);
  39341. };
  39342. constructors.className = className;
  39343. var combinator = function combinator(opts) {
  39344. return new _combinator["default"](opts);
  39345. };
  39346. constructors.combinator = combinator;
  39347. var comment = function comment(opts) {
  39348. return new _comment["default"](opts);
  39349. };
  39350. constructors.comment = comment;
  39351. var id = function id(opts) {
  39352. return new _id["default"](opts);
  39353. };
  39354. constructors.id = id;
  39355. var nesting = function nesting(opts) {
  39356. return new _nesting["default"](opts);
  39357. };
  39358. constructors.nesting = nesting;
  39359. var pseudo = function pseudo(opts) {
  39360. return new _pseudo["default"](opts);
  39361. };
  39362. constructors.pseudo = pseudo;
  39363. var root = function root(opts) {
  39364. return new _root["default"](opts);
  39365. };
  39366. constructors.root = root;
  39367. var selector = function selector(opts) {
  39368. return new _selector["default"](opts);
  39369. };
  39370. constructors.selector = selector;
  39371. var string = function string(opts) {
  39372. return new _string["default"](opts);
  39373. };
  39374. constructors.string = string;
  39375. var tag = function tag(opts) {
  39376. return new _tag["default"](opts);
  39377. };
  39378. constructors.tag = tag;
  39379. var universal = function universal(opts) {
  39380. return new _universal["default"](opts);
  39381. };
  39382. constructors.universal = universal;
  39383. var guards = {};
  39384. guards.__esModule = true;
  39385. guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  39386. guards.isContainer = isContainer;
  39387. guards.isIdentifier = void 0;
  39388. guards.isNamespace = isNamespace;
  39389. guards.isNesting = void 0;
  39390. guards.isNode = isNode;
  39391. guards.isPseudo = void 0;
  39392. guards.isPseudoClass = isPseudoClass;
  39393. guards.isPseudoElement = isPseudoElement;
  39394. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = void 0;
  39395. var _types = types;
  39396. var _IS_TYPE;
  39397. 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);
  39398. function isNode(node) {
  39399. return typeof node === "object" && IS_TYPE[node.type];
  39400. }
  39401. function isNodeType(type, node) {
  39402. return isNode(node) && node.type === type;
  39403. }
  39404. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  39405. guards.isAttribute = isAttribute;
  39406. var isClassName = isNodeType.bind(null, _types.CLASS);
  39407. guards.isClassName = isClassName;
  39408. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  39409. guards.isCombinator = isCombinator;
  39410. var isComment = isNodeType.bind(null, _types.COMMENT);
  39411. guards.isComment = isComment;
  39412. var isIdentifier = isNodeType.bind(null, _types.ID);
  39413. guards.isIdentifier = isIdentifier;
  39414. var isNesting = isNodeType.bind(null, _types.NESTING);
  39415. guards.isNesting = isNesting;
  39416. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  39417. guards.isPseudo = isPseudo;
  39418. var isRoot = isNodeType.bind(null, _types.ROOT);
  39419. guards.isRoot = isRoot;
  39420. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  39421. guards.isSelector = isSelector;
  39422. var isString = isNodeType.bind(null, _types.STRING);
  39423. guards.isString = isString;
  39424. var isTag = isNodeType.bind(null, _types.TAG);
  39425. guards.isTag = isTag;
  39426. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  39427. guards.isUniversal = isUniversal;
  39428. function isPseudoElement(node) {
  39429. 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");
  39430. }
  39431. function isPseudoClass(node) {
  39432. return isPseudo(node) && !isPseudoElement(node);
  39433. }
  39434. function isContainer(node) {
  39435. return !!(isNode(node) && node.walk);
  39436. }
  39437. function isNamespace(node) {
  39438. return isAttribute(node) || isTag(node);
  39439. }
  39440. (function (exports) {
  39441. exports.__esModule = true;
  39442. var _types = types;
  39443. Object.keys(_types).forEach(function (key) {
  39444. if (key === "default" || key === "__esModule") return;
  39445. if (key in exports && exports[key] === _types[key]) return;
  39446. exports[key] = _types[key];
  39447. });
  39448. var _constructors = constructors;
  39449. Object.keys(_constructors).forEach(function (key) {
  39450. if (key === "default" || key === "__esModule") return;
  39451. if (key in exports && exports[key] === _constructors[key]) return;
  39452. exports[key] = _constructors[key];
  39453. });
  39454. var _guards = guards;
  39455. Object.keys(_guards).forEach(function (key) {
  39456. if (key === "default" || key === "__esModule") return;
  39457. if (key in exports && exports[key] === _guards[key]) return;
  39458. exports[key] = _guards[key];
  39459. });
  39460. } (selectors));
  39461. (function (module, exports) {
  39462. exports.__esModule = true;
  39463. exports["default"] = void 0;
  39464. var _processor = _interopRequireDefault(processorExports);
  39465. var selectors$1 = _interopRequireWildcard(selectors);
  39466. 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); }
  39467. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && 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; }
  39468. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39469. var parser = function parser(processor) {
  39470. return new _processor["default"](processor);
  39471. };
  39472. Object.assign(parser, selectors$1);
  39473. delete parser.__esModule;
  39474. var _default = parser;
  39475. exports["default"] = _default;
  39476. module.exports = exports.default;
  39477. } (dist, dist.exports));
  39478. var distExports = dist.exports;
  39479. var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
  39480. const animationNameRE = /^(-\w+-)?animation-name$/;
  39481. const animationRE = /^(-\w+-)?animation$/;
  39482. const scopedPlugin = (id = "") => {
  39483. const keyframes = /* @__PURE__ */ Object.create(null);
  39484. const shortId = id.replace(/^data-v-/, "");
  39485. return {
  39486. postcssPlugin: "vue-sfc-scoped",
  39487. Rule(rule) {
  39488. processRule(id, rule);
  39489. },
  39490. AtRule(node) {
  39491. if (/-?keyframes$/.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
  39492. keyframes[node.params] = node.params = node.params + "-" + shortId;
  39493. }
  39494. },
  39495. OnceExit(root) {
  39496. if (Object.keys(keyframes).length) {
  39497. root.walkDecls((decl) => {
  39498. if (animationNameRE.test(decl.prop)) {
  39499. decl.value = decl.value.split(",").map((v) => keyframes[v.trim()] || v.trim()).join(",");
  39500. }
  39501. if (animationRE.test(decl.prop)) {
  39502. decl.value = decl.value.split(",").map((v) => {
  39503. const vals = v.trim().split(/\s+/);
  39504. const i = vals.findIndex((val) => keyframes[val]);
  39505. if (i !== -1) {
  39506. vals.splice(i, 1, keyframes[vals[i]]);
  39507. return vals.join(" ");
  39508. } else {
  39509. return v;
  39510. }
  39511. }).join(",");
  39512. }
  39513. });
  39514. }
  39515. }
  39516. };
  39517. };
  39518. const processedRules = /* @__PURE__ */ new WeakSet();
  39519. function processRule(id, rule) {
  39520. if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && /-?keyframes$/.test(rule.parent.name)) {
  39521. return;
  39522. }
  39523. processedRules.add(rule);
  39524. rule.selector = selectorParser((selectorRoot) => {
  39525. selectorRoot.each((selector) => {
  39526. rewriteSelector(id, selector, selectorRoot);
  39527. });
  39528. }).processSync(rule.selector);
  39529. }
  39530. function rewriteSelector(id, selector, selectorRoot, slotted = false) {
  39531. let node = null;
  39532. let shouldInject = true;
  39533. selector.each((n) => {
  39534. if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
  39535. n.value = " ";
  39536. n.spaces.before = n.spaces.after = "";
  39537. warn$1(
  39538. `the >>> and /deep/ combinators have been deprecated. Use :deep() instead.`
  39539. );
  39540. return false;
  39541. }
  39542. if (n.type === "pseudo") {
  39543. const { value } = n;
  39544. if (value === ":deep" || value === "::v-deep") {
  39545. if (n.nodes.length) {
  39546. let last = n;
  39547. n.nodes[0].each((ss) => {
  39548. selector.insertAfter(last, ss);
  39549. last = ss;
  39550. });
  39551. const prev = selector.at(selector.index(n) - 1);
  39552. if (!prev || !isSpaceCombinator(prev)) {
  39553. selector.insertAfter(
  39554. n,
  39555. selectorParser.combinator({
  39556. value: " "
  39557. })
  39558. );
  39559. }
  39560. selector.removeChild(n);
  39561. } else {
  39562. warn$1(
  39563. `${value} usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead of ${value} <inner-selector>.`
  39564. );
  39565. const prev = selector.at(selector.index(n) - 1);
  39566. if (prev && isSpaceCombinator(prev)) {
  39567. selector.removeChild(prev);
  39568. }
  39569. selector.removeChild(n);
  39570. }
  39571. return false;
  39572. }
  39573. if (value === ":slotted" || value === "::v-slotted") {
  39574. rewriteSelector(
  39575. id,
  39576. n.nodes[0],
  39577. selectorRoot,
  39578. true
  39579. /* slotted */
  39580. );
  39581. let last = n;
  39582. n.nodes[0].each((ss) => {
  39583. selector.insertAfter(last, ss);
  39584. last = ss;
  39585. });
  39586. selector.removeChild(n);
  39587. shouldInject = false;
  39588. return false;
  39589. }
  39590. if (value === ":global" || value === "::v-global") {
  39591. selectorRoot.insertAfter(selector, n.nodes[0]);
  39592. selectorRoot.removeChild(selector);
  39593. return false;
  39594. }
  39595. }
  39596. if (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where")) {
  39597. node = n;
  39598. }
  39599. });
  39600. if (node) {
  39601. const { type, value } = node;
  39602. if (type === "pseudo" && (value === ":is" || value === ":where")) {
  39603. node.nodes.forEach(
  39604. (value2) => rewriteSelector(id, value2, selectorRoot, slotted)
  39605. );
  39606. shouldInject = false;
  39607. }
  39608. }
  39609. if (node) {
  39610. node.spaces.after = "";
  39611. } else {
  39612. selector.first.spaces.before = "";
  39613. }
  39614. if (shouldInject) {
  39615. const idToAdd = slotted ? id + "-s" : id;
  39616. selector.insertAfter(
  39617. // If node is null it means we need to inject [id] at the start
  39618. // insertAfter can handle `null` here
  39619. node,
  39620. selectorParser.attribute({
  39621. attribute: idToAdd,
  39622. value: idToAdd,
  39623. raws: {},
  39624. quoteMark: `"`
  39625. })
  39626. );
  39627. }
  39628. }
  39629. function isSpaceCombinator(node) {
  39630. return node.type === "combinator" && /^\s+$/.test(node.value);
  39631. }
  39632. scopedPlugin.postcss = true;
  39633. var scopedPlugin$1 = scopedPlugin;
  39634. var sourceMap$1 = {};
  39635. var sourceMapGenerator = {};
  39636. var base64Vlq = {};
  39637. var base64$1 = {};
  39638. /* -*- Mode: js; js-indent-level: 2; -*- */
  39639. /*
  39640. * Copyright 2011 Mozilla Foundation and contributors
  39641. * Licensed under the New BSD license. See LICENSE or:
  39642. * http://opensource.org/licenses/BSD-3-Clause
  39643. */
  39644. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  39645. /**
  39646. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  39647. */
  39648. base64$1.encode = function (number) {
  39649. if (0 <= number && number < intToCharMap.length) {
  39650. return intToCharMap[number];
  39651. }
  39652. throw new TypeError("Must be between 0 and 63: " + number);
  39653. };
  39654. /**
  39655. * Decode a single base 64 character code digit to an integer. Returns -1 on
  39656. * failure.
  39657. */
  39658. base64$1.decode = function (charCode) {
  39659. var bigA = 65; // 'A'
  39660. var bigZ = 90; // 'Z'
  39661. var littleA = 97; // 'a'
  39662. var littleZ = 122; // 'z'
  39663. var zero = 48; // '0'
  39664. var nine = 57; // '9'
  39665. var plus = 43; // '+'
  39666. var slash = 47; // '/'
  39667. var littleOffset = 26;
  39668. var numberOffset = 52;
  39669. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  39670. if (bigA <= charCode && charCode <= bigZ) {
  39671. return (charCode - bigA);
  39672. }
  39673. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  39674. if (littleA <= charCode && charCode <= littleZ) {
  39675. return (charCode - littleA + littleOffset);
  39676. }
  39677. // 52 - 61: 0123456789
  39678. if (zero <= charCode && charCode <= nine) {
  39679. return (charCode - zero + numberOffset);
  39680. }
  39681. // 62: +
  39682. if (charCode == plus) {
  39683. return 62;
  39684. }
  39685. // 63: /
  39686. if (charCode == slash) {
  39687. return 63;
  39688. }
  39689. // Invalid base64 digit.
  39690. return -1;
  39691. };
  39692. /* -*- Mode: js; js-indent-level: 2; -*- */
  39693. /*
  39694. * Copyright 2011 Mozilla Foundation and contributors
  39695. * Licensed under the New BSD license. See LICENSE or:
  39696. * http://opensource.org/licenses/BSD-3-Clause
  39697. *
  39698. * Based on the Base 64 VLQ implementation in Closure Compiler:
  39699. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  39700. *
  39701. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  39702. * Redistribution and use in source and binary forms, with or without
  39703. * modification, are permitted provided that the following conditions are
  39704. * met:
  39705. *
  39706. * * Redistributions of source code must retain the above copyright
  39707. * notice, this list of conditions and the following disclaimer.
  39708. * * Redistributions in binary form must reproduce the above
  39709. * copyright notice, this list of conditions and the following
  39710. * disclaimer in the documentation and/or other materials provided
  39711. * with the distribution.
  39712. * * Neither the name of Google Inc. nor the names of its
  39713. * contributors may be used to endorse or promote products derived
  39714. * from this software without specific prior written permission.
  39715. *
  39716. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  39717. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39718. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39719. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  39720. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39721. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  39722. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  39723. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  39724. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39725. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39726. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39727. */
  39728. var base64 = base64$1;
  39729. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  39730. // length quantities we use in the source map spec, the first bit is the sign,
  39731. // the next four bits are the actual value, and the 6th bit is the
  39732. // continuation bit. The continuation bit tells us whether there are more
  39733. // digits in this value following this digit.
  39734. //
  39735. // Continuation
  39736. // | Sign
  39737. // | |
  39738. // V V
  39739. // 101011
  39740. var VLQ_BASE_SHIFT = 5;
  39741. // binary: 100000
  39742. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  39743. // binary: 011111
  39744. var VLQ_BASE_MASK = VLQ_BASE - 1;
  39745. // binary: 100000
  39746. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  39747. /**
  39748. * Converts from a two-complement value to a value where the sign bit is
  39749. * placed in the least significant bit. For example, as decimals:
  39750. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  39751. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  39752. */
  39753. function toVLQSigned(aValue) {
  39754. return aValue < 0
  39755. ? ((-aValue) << 1) + 1
  39756. : (aValue << 1) + 0;
  39757. }
  39758. /**
  39759. * Converts to a two-complement value from a value where the sign bit is
  39760. * placed in the least significant bit. For example, as decimals:
  39761. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  39762. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  39763. */
  39764. function fromVLQSigned(aValue) {
  39765. var isNegative = (aValue & 1) === 1;
  39766. var shifted = aValue >> 1;
  39767. return isNegative
  39768. ? -shifted
  39769. : shifted;
  39770. }
  39771. /**
  39772. * Returns the base 64 VLQ encoded value.
  39773. */
  39774. base64Vlq.encode = function base64VLQ_encode(aValue) {
  39775. var encoded = "";
  39776. var digit;
  39777. var vlq = toVLQSigned(aValue);
  39778. do {
  39779. digit = vlq & VLQ_BASE_MASK;
  39780. vlq >>>= VLQ_BASE_SHIFT;
  39781. if (vlq > 0) {
  39782. // There are still more digits in this value, so we must make sure the
  39783. // continuation bit is marked.
  39784. digit |= VLQ_CONTINUATION_BIT;
  39785. }
  39786. encoded += base64.encode(digit);
  39787. } while (vlq > 0);
  39788. return encoded;
  39789. };
  39790. /**
  39791. * Decodes the next base 64 VLQ value from the given string and returns the
  39792. * value and the rest of the string via the out parameter.
  39793. */
  39794. base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  39795. var strLen = aStr.length;
  39796. var result = 0;
  39797. var shift = 0;
  39798. var continuation, digit;
  39799. do {
  39800. if (aIndex >= strLen) {
  39801. throw new Error("Expected more digits in base 64 VLQ value.");
  39802. }
  39803. digit = base64.decode(aStr.charCodeAt(aIndex++));
  39804. if (digit === -1) {
  39805. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  39806. }
  39807. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  39808. digit &= VLQ_BASE_MASK;
  39809. result = result + (digit << shift);
  39810. shift += VLQ_BASE_SHIFT;
  39811. } while (continuation);
  39812. aOutParam.value = fromVLQSigned(result);
  39813. aOutParam.rest = aIndex;
  39814. };
  39815. var util$5 = {};
  39816. /* -*- Mode: js; js-indent-level: 2; -*- */
  39817. (function (exports) {
  39818. /*
  39819. * Copyright 2011 Mozilla Foundation and contributors
  39820. * Licensed under the New BSD license. See LICENSE or:
  39821. * http://opensource.org/licenses/BSD-3-Clause
  39822. */
  39823. /**
  39824. * This is a helper function for getting values from parameter/options
  39825. * objects.
  39826. *
  39827. * @param args The object we are extracting values from
  39828. * @param name The name of the property we are getting.
  39829. * @param defaultValue An optional value to return if the property is missing
  39830. * from the object. If this is not specified and the property is missing, an
  39831. * error will be thrown.
  39832. */
  39833. function getArg(aArgs, aName, aDefaultValue) {
  39834. if (aName in aArgs) {
  39835. return aArgs[aName];
  39836. } else if (arguments.length === 3) {
  39837. return aDefaultValue;
  39838. } else {
  39839. throw new Error('"' + aName + '" is a required argument.');
  39840. }
  39841. }
  39842. exports.getArg = getArg;
  39843. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  39844. var dataUrlRegexp = /^data:.+\,.+$/;
  39845. function urlParse(aUrl) {
  39846. var match = aUrl.match(urlRegexp);
  39847. if (!match) {
  39848. return null;
  39849. }
  39850. return {
  39851. scheme: match[1],
  39852. auth: match[2],
  39853. host: match[3],
  39854. port: match[4],
  39855. path: match[5]
  39856. };
  39857. }
  39858. exports.urlParse = urlParse;
  39859. function urlGenerate(aParsedUrl) {
  39860. var url = '';
  39861. if (aParsedUrl.scheme) {
  39862. url += aParsedUrl.scheme + ':';
  39863. }
  39864. url += '//';
  39865. if (aParsedUrl.auth) {
  39866. url += aParsedUrl.auth + '@';
  39867. }
  39868. if (aParsedUrl.host) {
  39869. url += aParsedUrl.host;
  39870. }
  39871. if (aParsedUrl.port) {
  39872. url += ":" + aParsedUrl.port;
  39873. }
  39874. if (aParsedUrl.path) {
  39875. url += aParsedUrl.path;
  39876. }
  39877. return url;
  39878. }
  39879. exports.urlGenerate = urlGenerate;
  39880. /**
  39881. * Normalizes a path, or the path portion of a URL:
  39882. *
  39883. * - Replaces consecutive slashes with one slash.
  39884. * - Removes unnecessary '.' parts.
  39885. * - Removes unnecessary '<dir>/..' parts.
  39886. *
  39887. * Based on code in the Node.js 'path' core module.
  39888. *
  39889. * @param aPath The path or url to normalize.
  39890. */
  39891. function normalize(aPath) {
  39892. var path = aPath;
  39893. var url = urlParse(aPath);
  39894. if (url) {
  39895. if (!url.path) {
  39896. return aPath;
  39897. }
  39898. path = url.path;
  39899. }
  39900. var isAbsolute = exports.isAbsolute(path);
  39901. var parts = path.split(/\/+/);
  39902. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  39903. part = parts[i];
  39904. if (part === '.') {
  39905. parts.splice(i, 1);
  39906. } else if (part === '..') {
  39907. up++;
  39908. } else if (up > 0) {
  39909. if (part === '') {
  39910. // The first part is blank if the path is absolute. Trying to go
  39911. // above the root is a no-op. Therefore we can remove all '..' parts
  39912. // directly after the root.
  39913. parts.splice(i + 1, up);
  39914. up = 0;
  39915. } else {
  39916. parts.splice(i, 2);
  39917. up--;
  39918. }
  39919. }
  39920. }
  39921. path = parts.join('/');
  39922. if (path === '') {
  39923. path = isAbsolute ? '/' : '.';
  39924. }
  39925. if (url) {
  39926. url.path = path;
  39927. return urlGenerate(url);
  39928. }
  39929. return path;
  39930. }
  39931. exports.normalize = normalize;
  39932. /**
  39933. * Joins two paths/URLs.
  39934. *
  39935. * @param aRoot The root path or URL.
  39936. * @param aPath The path or URL to be joined with the root.
  39937. *
  39938. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  39939. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  39940. * first.
  39941. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  39942. * is updated with the result and aRoot is returned. Otherwise the result
  39943. * is returned.
  39944. * - If aPath is absolute, the result is aPath.
  39945. * - Otherwise the two paths are joined with a slash.
  39946. * - Joining for example 'http://' and 'www.example.com' is also supported.
  39947. */
  39948. function join(aRoot, aPath) {
  39949. if (aRoot === "") {
  39950. aRoot = ".";
  39951. }
  39952. if (aPath === "") {
  39953. aPath = ".";
  39954. }
  39955. var aPathUrl = urlParse(aPath);
  39956. var aRootUrl = urlParse(aRoot);
  39957. if (aRootUrl) {
  39958. aRoot = aRootUrl.path || '/';
  39959. }
  39960. // `join(foo, '//www.example.org')`
  39961. if (aPathUrl && !aPathUrl.scheme) {
  39962. if (aRootUrl) {
  39963. aPathUrl.scheme = aRootUrl.scheme;
  39964. }
  39965. return urlGenerate(aPathUrl);
  39966. }
  39967. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  39968. return aPath;
  39969. }
  39970. // `join('http://', 'www.example.com')`
  39971. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  39972. aRootUrl.host = aPath;
  39973. return urlGenerate(aRootUrl);
  39974. }
  39975. var joined = aPath.charAt(0) === '/'
  39976. ? aPath
  39977. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  39978. if (aRootUrl) {
  39979. aRootUrl.path = joined;
  39980. return urlGenerate(aRootUrl);
  39981. }
  39982. return joined;
  39983. }
  39984. exports.join = join;
  39985. exports.isAbsolute = function (aPath) {
  39986. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  39987. };
  39988. /**
  39989. * Make a path relative to a URL or another path.
  39990. *
  39991. * @param aRoot The root path or URL.
  39992. * @param aPath The path or URL to be made relative to aRoot.
  39993. */
  39994. function relative(aRoot, aPath) {
  39995. if (aRoot === "") {
  39996. aRoot = ".";
  39997. }
  39998. aRoot = aRoot.replace(/\/$/, '');
  39999. // It is possible for the path to be above the root. In this case, simply
  40000. // checking whether the root is a prefix of the path won't work. Instead, we
  40001. // need to remove components from the root one by one, until either we find
  40002. // a prefix that fits, or we run out of components to remove.
  40003. var level = 0;
  40004. while (aPath.indexOf(aRoot + '/') !== 0) {
  40005. var index = aRoot.lastIndexOf("/");
  40006. if (index < 0) {
  40007. return aPath;
  40008. }
  40009. // If the only part of the root that is left is the scheme (i.e. http://,
  40010. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  40011. // have exhausted all components, so the path is not relative to the root.
  40012. aRoot = aRoot.slice(0, index);
  40013. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  40014. return aPath;
  40015. }
  40016. ++level;
  40017. }
  40018. // Make sure we add a "../" for each component we removed from the root.
  40019. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  40020. }
  40021. exports.relative = relative;
  40022. var supportsNullProto = (function () {
  40023. var obj = Object.create(null);
  40024. return !('__proto__' in obj);
  40025. }());
  40026. function identity (s) {
  40027. return s;
  40028. }
  40029. /**
  40030. * Because behavior goes wacky when you set `__proto__` on objects, we
  40031. * have to prefix all the strings in our set with an arbitrary character.
  40032. *
  40033. * See https://github.com/mozilla/source-map/pull/31 and
  40034. * https://github.com/mozilla/source-map/issues/30
  40035. *
  40036. * @param String aStr
  40037. */
  40038. function toSetString(aStr) {
  40039. if (isProtoString(aStr)) {
  40040. return '$' + aStr;
  40041. }
  40042. return aStr;
  40043. }
  40044. exports.toSetString = supportsNullProto ? identity : toSetString;
  40045. function fromSetString(aStr) {
  40046. if (isProtoString(aStr)) {
  40047. return aStr.slice(1);
  40048. }
  40049. return aStr;
  40050. }
  40051. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  40052. function isProtoString(s) {
  40053. if (!s) {
  40054. return false;
  40055. }
  40056. var length = s.length;
  40057. if (length < 9 /* "__proto__".length */) {
  40058. return false;
  40059. }
  40060. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  40061. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  40062. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  40063. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  40064. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  40065. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  40066. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  40067. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  40068. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  40069. return false;
  40070. }
  40071. for (var i = length - 10; i >= 0; i--) {
  40072. if (s.charCodeAt(i) !== 36 /* '$' */) {
  40073. return false;
  40074. }
  40075. }
  40076. return true;
  40077. }
  40078. /**
  40079. * Comparator between two mappings where the original positions are compared.
  40080. *
  40081. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40082. * mappings with the same original source/line/column, but different generated
  40083. * line and column the same. Useful when searching for a mapping with a
  40084. * stubbed out mapping.
  40085. */
  40086. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  40087. var cmp = strcmp(mappingA.source, mappingB.source);
  40088. if (cmp !== 0) {
  40089. return cmp;
  40090. }
  40091. cmp = mappingA.originalLine - mappingB.originalLine;
  40092. if (cmp !== 0) {
  40093. return cmp;
  40094. }
  40095. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40096. if (cmp !== 0 || onlyCompareOriginal) {
  40097. return cmp;
  40098. }
  40099. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40100. if (cmp !== 0) {
  40101. return cmp;
  40102. }
  40103. cmp = mappingA.generatedLine - mappingB.generatedLine;
  40104. if (cmp !== 0) {
  40105. return cmp;
  40106. }
  40107. return strcmp(mappingA.name, mappingB.name);
  40108. }
  40109. exports.compareByOriginalPositions = compareByOriginalPositions;
  40110. /**
  40111. * Comparator between two mappings with deflated source and name indices where
  40112. * the generated positions are compared.
  40113. *
  40114. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40115. * mappings with the same generated line and column, but different
  40116. * source/name/original line and column the same. Useful when searching for a
  40117. * mapping with a stubbed out mapping.
  40118. */
  40119. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  40120. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40121. if (cmp !== 0) {
  40122. return cmp;
  40123. }
  40124. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40125. if (cmp !== 0 || onlyCompareGenerated) {
  40126. return cmp;
  40127. }
  40128. cmp = strcmp(mappingA.source, mappingB.source);
  40129. if (cmp !== 0) {
  40130. return cmp;
  40131. }
  40132. cmp = mappingA.originalLine - mappingB.originalLine;
  40133. if (cmp !== 0) {
  40134. return cmp;
  40135. }
  40136. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40137. if (cmp !== 0) {
  40138. return cmp;
  40139. }
  40140. return strcmp(mappingA.name, mappingB.name);
  40141. }
  40142. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  40143. function strcmp(aStr1, aStr2) {
  40144. if (aStr1 === aStr2) {
  40145. return 0;
  40146. }
  40147. if (aStr1 === null) {
  40148. return 1; // aStr2 !== null
  40149. }
  40150. if (aStr2 === null) {
  40151. return -1; // aStr1 !== null
  40152. }
  40153. if (aStr1 > aStr2) {
  40154. return 1;
  40155. }
  40156. return -1;
  40157. }
  40158. /**
  40159. * Comparator between two mappings with inflated source and name strings where
  40160. * the generated positions are compared.
  40161. */
  40162. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  40163. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40164. if (cmp !== 0) {
  40165. return cmp;
  40166. }
  40167. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40168. if (cmp !== 0) {
  40169. return cmp;
  40170. }
  40171. cmp = strcmp(mappingA.source, mappingB.source);
  40172. if (cmp !== 0) {
  40173. return cmp;
  40174. }
  40175. cmp = mappingA.originalLine - mappingB.originalLine;
  40176. if (cmp !== 0) {
  40177. return cmp;
  40178. }
  40179. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40180. if (cmp !== 0) {
  40181. return cmp;
  40182. }
  40183. return strcmp(mappingA.name, mappingB.name);
  40184. }
  40185. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  40186. /**
  40187. * Strip any JSON XSSI avoidance prefix from the string (as documented
  40188. * in the source maps specification), and then parse the string as
  40189. * JSON.
  40190. */
  40191. function parseSourceMapInput(str) {
  40192. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  40193. }
  40194. exports.parseSourceMapInput = parseSourceMapInput;
  40195. /**
  40196. * Compute the URL of a source given the the source root, the source's
  40197. * URL, and the source map's URL.
  40198. */
  40199. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  40200. sourceURL = sourceURL || '';
  40201. if (sourceRoot) {
  40202. // This follows what Chrome does.
  40203. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  40204. sourceRoot += '/';
  40205. }
  40206. // The spec says:
  40207. // Line 4: An optional source root, useful for relocating source
  40208. // files on a server or removing repeated values in the
  40209. // “sources” entry. This value is prepended to the individual
  40210. // entries in the “source” field.
  40211. sourceURL = sourceRoot + sourceURL;
  40212. }
  40213. // Historically, SourceMapConsumer did not take the sourceMapURL as
  40214. // a parameter. This mode is still somewhat supported, which is why
  40215. // this code block is conditional. However, it's preferable to pass
  40216. // the source map URL to SourceMapConsumer, so that this function
  40217. // can implement the source URL resolution algorithm as outlined in
  40218. // the spec. This block is basically the equivalent of:
  40219. // new URL(sourceURL, sourceMapURL).toString()
  40220. // ... except it avoids using URL, which wasn't available in the
  40221. // older releases of node still supported by this library.
  40222. //
  40223. // The spec says:
  40224. // If the sources are not absolute URLs after prepending of the
  40225. // “sourceRoot”, the sources are resolved relative to the
  40226. // SourceMap (like resolving script src in a html document).
  40227. if (sourceMapURL) {
  40228. var parsed = urlParse(sourceMapURL);
  40229. if (!parsed) {
  40230. throw new Error("sourceMapURL could not be parsed");
  40231. }
  40232. if (parsed.path) {
  40233. // Strip the last path component, but keep the "/".
  40234. var index = parsed.path.lastIndexOf('/');
  40235. if (index >= 0) {
  40236. parsed.path = parsed.path.substring(0, index + 1);
  40237. }
  40238. }
  40239. sourceURL = join(urlGenerate(parsed), sourceURL);
  40240. }
  40241. return normalize(sourceURL);
  40242. }
  40243. exports.computeSourceURL = computeSourceURL;
  40244. } (util$5));
  40245. var arraySet = {};
  40246. /* -*- Mode: js; js-indent-level: 2; -*- */
  40247. /*
  40248. * Copyright 2011 Mozilla Foundation and contributors
  40249. * Licensed under the New BSD license. See LICENSE or:
  40250. * http://opensource.org/licenses/BSD-3-Clause
  40251. */
  40252. var util$4 = util$5;
  40253. var has = Object.prototype.hasOwnProperty;
  40254. var hasNativeMap = typeof Map !== "undefined";
  40255. /**
  40256. * A data structure which is a combination of an array and a set. Adding a new
  40257. * member is O(1), testing for membership is O(1), and finding the index of an
  40258. * element is O(1). Removing elements from the set is not supported. Only
  40259. * strings are supported for membership.
  40260. */
  40261. function ArraySet$2() {
  40262. this._array = [];
  40263. this._set = hasNativeMap ? new Map() : Object.create(null);
  40264. }
  40265. /**
  40266. * Static method for creating ArraySet instances from an existing array.
  40267. */
  40268. ArraySet$2.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  40269. var set = new ArraySet$2();
  40270. for (var i = 0, len = aArray.length; i < len; i++) {
  40271. set.add(aArray[i], aAllowDuplicates);
  40272. }
  40273. return set;
  40274. };
  40275. /**
  40276. * Return how many unique items are in this ArraySet. If duplicates have been
  40277. * added, than those do not count towards the size.
  40278. *
  40279. * @returns Number
  40280. */
  40281. ArraySet$2.prototype.size = function ArraySet_size() {
  40282. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  40283. };
  40284. /**
  40285. * Add the given string to this set.
  40286. *
  40287. * @param String aStr
  40288. */
  40289. ArraySet$2.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  40290. var sStr = hasNativeMap ? aStr : util$4.toSetString(aStr);
  40291. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  40292. var idx = this._array.length;
  40293. if (!isDuplicate || aAllowDuplicates) {
  40294. this._array.push(aStr);
  40295. }
  40296. if (!isDuplicate) {
  40297. if (hasNativeMap) {
  40298. this._set.set(aStr, idx);
  40299. } else {
  40300. this._set[sStr] = idx;
  40301. }
  40302. }
  40303. };
  40304. /**
  40305. * Is the given string a member of this set?
  40306. *
  40307. * @param String aStr
  40308. */
  40309. ArraySet$2.prototype.has = function ArraySet_has(aStr) {
  40310. if (hasNativeMap) {
  40311. return this._set.has(aStr);
  40312. } else {
  40313. var sStr = util$4.toSetString(aStr);
  40314. return has.call(this._set, sStr);
  40315. }
  40316. };
  40317. /**
  40318. * What is the index of the given string in the array?
  40319. *
  40320. * @param String aStr
  40321. */
  40322. ArraySet$2.prototype.indexOf = function ArraySet_indexOf(aStr) {
  40323. if (hasNativeMap) {
  40324. var idx = this._set.get(aStr);
  40325. if (idx >= 0) {
  40326. return idx;
  40327. }
  40328. } else {
  40329. var sStr = util$4.toSetString(aStr);
  40330. if (has.call(this._set, sStr)) {
  40331. return this._set[sStr];
  40332. }
  40333. }
  40334. throw new Error('"' + aStr + '" is not in the set.');
  40335. };
  40336. /**
  40337. * What is the element at the given index?
  40338. *
  40339. * @param Number aIdx
  40340. */
  40341. ArraySet$2.prototype.at = function ArraySet_at(aIdx) {
  40342. if (aIdx >= 0 && aIdx < this._array.length) {
  40343. return this._array[aIdx];
  40344. }
  40345. throw new Error('No element indexed by ' + aIdx);
  40346. };
  40347. /**
  40348. * Returns the array representation of this set (which has the proper indices
  40349. * indicated by indexOf). Note that this is a copy of the internal array used
  40350. * for storing the members so that no one can mess with internal state.
  40351. */
  40352. ArraySet$2.prototype.toArray = function ArraySet_toArray() {
  40353. return this._array.slice();
  40354. };
  40355. arraySet.ArraySet = ArraySet$2;
  40356. var mappingList = {};
  40357. /* -*- Mode: js; js-indent-level: 2; -*- */
  40358. /*
  40359. * Copyright 2014 Mozilla Foundation and contributors
  40360. * Licensed under the New BSD license. See LICENSE or:
  40361. * http://opensource.org/licenses/BSD-3-Clause
  40362. */
  40363. var util$3 = util$5;
  40364. /**
  40365. * Determine whether mappingB is after mappingA with respect to generated
  40366. * position.
  40367. */
  40368. function generatedPositionAfter(mappingA, mappingB) {
  40369. // Optimized for most common case
  40370. var lineA = mappingA.generatedLine;
  40371. var lineB = mappingB.generatedLine;
  40372. var columnA = mappingA.generatedColumn;
  40373. var columnB = mappingB.generatedColumn;
  40374. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  40375. util$3.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  40376. }
  40377. /**
  40378. * A data structure to provide a sorted view of accumulated mappings in a
  40379. * performance conscious manner. It trades a neglibable overhead in general
  40380. * case for a large speedup in case of mappings being added in order.
  40381. */
  40382. function MappingList$1() {
  40383. this._array = [];
  40384. this._sorted = true;
  40385. // Serves as infimum
  40386. this._last = {generatedLine: -1, generatedColumn: 0};
  40387. }
  40388. /**
  40389. * Iterate through internal items. This method takes the same arguments that
  40390. * `Array.prototype.forEach` takes.
  40391. *
  40392. * NOTE: The order of the mappings is NOT guaranteed.
  40393. */
  40394. MappingList$1.prototype.unsortedForEach =
  40395. function MappingList_forEach(aCallback, aThisArg) {
  40396. this._array.forEach(aCallback, aThisArg);
  40397. };
  40398. /**
  40399. * Add the given source mapping.
  40400. *
  40401. * @param Object aMapping
  40402. */
  40403. MappingList$1.prototype.add = function MappingList_add(aMapping) {
  40404. if (generatedPositionAfter(this._last, aMapping)) {
  40405. this._last = aMapping;
  40406. this._array.push(aMapping);
  40407. } else {
  40408. this._sorted = false;
  40409. this._array.push(aMapping);
  40410. }
  40411. };
  40412. /**
  40413. * Returns the flat, sorted array of mappings. The mappings are sorted by
  40414. * generated position.
  40415. *
  40416. * WARNING: This method returns internal data without copying, for
  40417. * performance. The return value must NOT be mutated, and should be treated as
  40418. * an immutable borrow. If you want to take ownership, you must make your own
  40419. * copy.
  40420. */
  40421. MappingList$1.prototype.toArray = function MappingList_toArray() {
  40422. if (!this._sorted) {
  40423. this._array.sort(util$3.compareByGeneratedPositionsInflated);
  40424. this._sorted = true;
  40425. }
  40426. return this._array;
  40427. };
  40428. mappingList.MappingList = MappingList$1;
  40429. /* -*- Mode: js; js-indent-level: 2; -*- */
  40430. /*
  40431. * Copyright 2011 Mozilla Foundation and contributors
  40432. * Licensed under the New BSD license. See LICENSE or:
  40433. * http://opensource.org/licenses/BSD-3-Clause
  40434. */
  40435. var base64VLQ$1 = base64Vlq;
  40436. var util$2 = util$5;
  40437. var ArraySet$1 = arraySet.ArraySet;
  40438. var MappingList = mappingList.MappingList;
  40439. /**
  40440. * An instance of the SourceMapGenerator represents a source map which is
  40441. * being built incrementally. You may pass an object with the following
  40442. * properties:
  40443. *
  40444. * - file: The filename of the generated source.
  40445. * - sourceRoot: A root for all relative URLs in this source map.
  40446. */
  40447. function SourceMapGenerator$2(aArgs) {
  40448. if (!aArgs) {
  40449. aArgs = {};
  40450. }
  40451. this._file = util$2.getArg(aArgs, 'file', null);
  40452. this._sourceRoot = util$2.getArg(aArgs, 'sourceRoot', null);
  40453. this._skipValidation = util$2.getArg(aArgs, 'skipValidation', false);
  40454. this._sources = new ArraySet$1();
  40455. this._names = new ArraySet$1();
  40456. this._mappings = new MappingList();
  40457. this._sourcesContents = null;
  40458. }
  40459. SourceMapGenerator$2.prototype._version = 3;
  40460. /**
  40461. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  40462. *
  40463. * @param aSourceMapConsumer The SourceMap.
  40464. */
  40465. SourceMapGenerator$2.fromSourceMap =
  40466. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  40467. var sourceRoot = aSourceMapConsumer.sourceRoot;
  40468. var generator = new SourceMapGenerator$2({
  40469. file: aSourceMapConsumer.file,
  40470. sourceRoot: sourceRoot
  40471. });
  40472. aSourceMapConsumer.eachMapping(function (mapping) {
  40473. var newMapping = {
  40474. generated: {
  40475. line: mapping.generatedLine,
  40476. column: mapping.generatedColumn
  40477. }
  40478. };
  40479. if (mapping.source != null) {
  40480. newMapping.source = mapping.source;
  40481. if (sourceRoot != null) {
  40482. newMapping.source = util$2.relative(sourceRoot, newMapping.source);
  40483. }
  40484. newMapping.original = {
  40485. line: mapping.originalLine,
  40486. column: mapping.originalColumn
  40487. };
  40488. if (mapping.name != null) {
  40489. newMapping.name = mapping.name;
  40490. }
  40491. }
  40492. generator.addMapping(newMapping);
  40493. });
  40494. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  40495. var sourceRelative = sourceFile;
  40496. if (sourceRoot !== null) {
  40497. sourceRelative = util$2.relative(sourceRoot, sourceFile);
  40498. }
  40499. if (!generator._sources.has(sourceRelative)) {
  40500. generator._sources.add(sourceRelative);
  40501. }
  40502. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  40503. if (content != null) {
  40504. generator.setSourceContent(sourceFile, content);
  40505. }
  40506. });
  40507. return generator;
  40508. };
  40509. /**
  40510. * Add a single mapping from original source line and column to the generated
  40511. * source's line and column for this source map being created. The mapping
  40512. * object should have the following properties:
  40513. *
  40514. * - generated: An object with the generated line and column positions.
  40515. * - original: An object with the original line and column positions.
  40516. * - source: The original source file (relative to the sourceRoot).
  40517. * - name: An optional original token name for this mapping.
  40518. */
  40519. SourceMapGenerator$2.prototype.addMapping =
  40520. function SourceMapGenerator_addMapping(aArgs) {
  40521. var generated = util$2.getArg(aArgs, 'generated');
  40522. var original = util$2.getArg(aArgs, 'original', null);
  40523. var source = util$2.getArg(aArgs, 'source', null);
  40524. var name = util$2.getArg(aArgs, 'name', null);
  40525. if (!this._skipValidation) {
  40526. this._validateMapping(generated, original, source, name);
  40527. }
  40528. if (source != null) {
  40529. source = String(source);
  40530. if (!this._sources.has(source)) {
  40531. this._sources.add(source);
  40532. }
  40533. }
  40534. if (name != null) {
  40535. name = String(name);
  40536. if (!this._names.has(name)) {
  40537. this._names.add(name);
  40538. }
  40539. }
  40540. this._mappings.add({
  40541. generatedLine: generated.line,
  40542. generatedColumn: generated.column,
  40543. originalLine: original != null && original.line,
  40544. originalColumn: original != null && original.column,
  40545. source: source,
  40546. name: name
  40547. });
  40548. };
  40549. /**
  40550. * Set the source content for a source file.
  40551. */
  40552. SourceMapGenerator$2.prototype.setSourceContent =
  40553. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  40554. var source = aSourceFile;
  40555. if (this._sourceRoot != null) {
  40556. source = util$2.relative(this._sourceRoot, source);
  40557. }
  40558. if (aSourceContent != null) {
  40559. // Add the source content to the _sourcesContents map.
  40560. // Create a new _sourcesContents map if the property is null.
  40561. if (!this._sourcesContents) {
  40562. this._sourcesContents = Object.create(null);
  40563. }
  40564. this._sourcesContents[util$2.toSetString(source)] = aSourceContent;
  40565. } else if (this._sourcesContents) {
  40566. // Remove the source file from the _sourcesContents map.
  40567. // If the _sourcesContents map is empty, set the property to null.
  40568. delete this._sourcesContents[util$2.toSetString(source)];
  40569. if (Object.keys(this._sourcesContents).length === 0) {
  40570. this._sourcesContents = null;
  40571. }
  40572. }
  40573. };
  40574. /**
  40575. * Applies the mappings of a sub-source-map for a specific source file to the
  40576. * source map being generated. Each mapping to the supplied source file is
  40577. * rewritten using the supplied source map. Note: The resolution for the
  40578. * resulting mappings is the minimium of this map and the supplied map.
  40579. *
  40580. * @param aSourceMapConsumer The source map to be applied.
  40581. * @param aSourceFile Optional. The filename of the source file.
  40582. * If omitted, SourceMapConsumer's file property will be used.
  40583. * @param aSourceMapPath Optional. The dirname of the path to the source map
  40584. * to be applied. If relative, it is relative to the SourceMapConsumer.
  40585. * This parameter is needed when the two source maps aren't in the same
  40586. * directory, and the source map to be applied contains relative source
  40587. * paths. If so, those relative source paths need to be rewritten
  40588. * relative to the SourceMapGenerator.
  40589. */
  40590. SourceMapGenerator$2.prototype.applySourceMap =
  40591. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  40592. var sourceFile = aSourceFile;
  40593. // If aSourceFile is omitted, we will use the file property of the SourceMap
  40594. if (aSourceFile == null) {
  40595. if (aSourceMapConsumer.file == null) {
  40596. throw new Error(
  40597. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  40598. 'or the source map\'s "file" property. Both were omitted.'
  40599. );
  40600. }
  40601. sourceFile = aSourceMapConsumer.file;
  40602. }
  40603. var sourceRoot = this._sourceRoot;
  40604. // Make "sourceFile" relative if an absolute Url is passed.
  40605. if (sourceRoot != null) {
  40606. sourceFile = util$2.relative(sourceRoot, sourceFile);
  40607. }
  40608. // Applying the SourceMap can add and remove items from the sources and
  40609. // the names array.
  40610. var newSources = new ArraySet$1();
  40611. var newNames = new ArraySet$1();
  40612. // Find mappings for the "sourceFile"
  40613. this._mappings.unsortedForEach(function (mapping) {
  40614. if (mapping.source === sourceFile && mapping.originalLine != null) {
  40615. // Check if it can be mapped by the source map, then update the mapping.
  40616. var original = aSourceMapConsumer.originalPositionFor({
  40617. line: mapping.originalLine,
  40618. column: mapping.originalColumn
  40619. });
  40620. if (original.source != null) {
  40621. // Copy mapping
  40622. mapping.source = original.source;
  40623. if (aSourceMapPath != null) {
  40624. mapping.source = util$2.join(aSourceMapPath, mapping.source);
  40625. }
  40626. if (sourceRoot != null) {
  40627. mapping.source = util$2.relative(sourceRoot, mapping.source);
  40628. }
  40629. mapping.originalLine = original.line;
  40630. mapping.originalColumn = original.column;
  40631. if (original.name != null) {
  40632. mapping.name = original.name;
  40633. }
  40634. }
  40635. }
  40636. var source = mapping.source;
  40637. if (source != null && !newSources.has(source)) {
  40638. newSources.add(source);
  40639. }
  40640. var name = mapping.name;
  40641. if (name != null && !newNames.has(name)) {
  40642. newNames.add(name);
  40643. }
  40644. }, this);
  40645. this._sources = newSources;
  40646. this._names = newNames;
  40647. // Copy sourcesContents of applied map.
  40648. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  40649. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  40650. if (content != null) {
  40651. if (aSourceMapPath != null) {
  40652. sourceFile = util$2.join(aSourceMapPath, sourceFile);
  40653. }
  40654. if (sourceRoot != null) {
  40655. sourceFile = util$2.relative(sourceRoot, sourceFile);
  40656. }
  40657. this.setSourceContent(sourceFile, content);
  40658. }
  40659. }, this);
  40660. };
  40661. /**
  40662. * A mapping can have one of the three levels of data:
  40663. *
  40664. * 1. Just the generated position.
  40665. * 2. The Generated position, original position, and original source.
  40666. * 3. Generated and original position, original source, as well as a name
  40667. * token.
  40668. *
  40669. * To maintain consistency, we validate that any new mapping being added falls
  40670. * in to one of these categories.
  40671. */
  40672. SourceMapGenerator$2.prototype._validateMapping =
  40673. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  40674. aName) {
  40675. // When aOriginal is truthy but has empty values for .line and .column,
  40676. // it is most likely a programmer error. In this case we throw a very
  40677. // specific error message to try to guide them the right way.
  40678. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  40679. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  40680. throw new Error(
  40681. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  40682. 'the original mapping entirely and only map the generated position. If so, pass ' +
  40683. 'null for the original mapping instead of an object with empty or null values.'
  40684. );
  40685. }
  40686. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  40687. && aGenerated.line > 0 && aGenerated.column >= 0
  40688. && !aOriginal && !aSource && !aName) {
  40689. // Case 1.
  40690. return;
  40691. }
  40692. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  40693. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  40694. && aGenerated.line > 0 && aGenerated.column >= 0
  40695. && aOriginal.line > 0 && aOriginal.column >= 0
  40696. && aSource) {
  40697. // Cases 2 and 3.
  40698. return;
  40699. }
  40700. else {
  40701. throw new Error('Invalid mapping: ' + JSON.stringify({
  40702. generated: aGenerated,
  40703. source: aSource,
  40704. original: aOriginal,
  40705. name: aName
  40706. }));
  40707. }
  40708. };
  40709. /**
  40710. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  40711. * specified by the source map format.
  40712. */
  40713. SourceMapGenerator$2.prototype._serializeMappings =
  40714. function SourceMapGenerator_serializeMappings() {
  40715. var previousGeneratedColumn = 0;
  40716. var previousGeneratedLine = 1;
  40717. var previousOriginalColumn = 0;
  40718. var previousOriginalLine = 0;
  40719. var previousName = 0;
  40720. var previousSource = 0;
  40721. var result = '';
  40722. var next;
  40723. var mapping;
  40724. var nameIdx;
  40725. var sourceIdx;
  40726. var mappings = this._mappings.toArray();
  40727. for (var i = 0, len = mappings.length; i < len; i++) {
  40728. mapping = mappings[i];
  40729. next = '';
  40730. if (mapping.generatedLine !== previousGeneratedLine) {
  40731. previousGeneratedColumn = 0;
  40732. while (mapping.generatedLine !== previousGeneratedLine) {
  40733. next += ';';
  40734. previousGeneratedLine++;
  40735. }
  40736. }
  40737. else {
  40738. if (i > 0) {
  40739. if (!util$2.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  40740. continue;
  40741. }
  40742. next += ',';
  40743. }
  40744. }
  40745. next += base64VLQ$1.encode(mapping.generatedColumn
  40746. - previousGeneratedColumn);
  40747. previousGeneratedColumn = mapping.generatedColumn;
  40748. if (mapping.source != null) {
  40749. sourceIdx = this._sources.indexOf(mapping.source);
  40750. next += base64VLQ$1.encode(sourceIdx - previousSource);
  40751. previousSource = sourceIdx;
  40752. // lines are stored 0-based in SourceMap spec version 3
  40753. next += base64VLQ$1.encode(mapping.originalLine - 1
  40754. - previousOriginalLine);
  40755. previousOriginalLine = mapping.originalLine - 1;
  40756. next += base64VLQ$1.encode(mapping.originalColumn
  40757. - previousOriginalColumn);
  40758. previousOriginalColumn = mapping.originalColumn;
  40759. if (mapping.name != null) {
  40760. nameIdx = this._names.indexOf(mapping.name);
  40761. next += base64VLQ$1.encode(nameIdx - previousName);
  40762. previousName = nameIdx;
  40763. }
  40764. }
  40765. result += next;
  40766. }
  40767. return result;
  40768. };
  40769. SourceMapGenerator$2.prototype._generateSourcesContent =
  40770. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  40771. return aSources.map(function (source) {
  40772. if (!this._sourcesContents) {
  40773. return null;
  40774. }
  40775. if (aSourceRoot != null) {
  40776. source = util$2.relative(aSourceRoot, source);
  40777. }
  40778. var key = util$2.toSetString(source);
  40779. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  40780. ? this._sourcesContents[key]
  40781. : null;
  40782. }, this);
  40783. };
  40784. /**
  40785. * Externalize the source map.
  40786. */
  40787. SourceMapGenerator$2.prototype.toJSON =
  40788. function SourceMapGenerator_toJSON() {
  40789. var map = {
  40790. version: this._version,
  40791. sources: this._sources.toArray(),
  40792. names: this._names.toArray(),
  40793. mappings: this._serializeMappings()
  40794. };
  40795. if (this._file != null) {
  40796. map.file = this._file;
  40797. }
  40798. if (this._sourceRoot != null) {
  40799. map.sourceRoot = this._sourceRoot;
  40800. }
  40801. if (this._sourcesContents) {
  40802. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  40803. }
  40804. return map;
  40805. };
  40806. /**
  40807. * Render the source map being generated to a string.
  40808. */
  40809. SourceMapGenerator$2.prototype.toString =
  40810. function SourceMapGenerator_toString() {
  40811. return JSON.stringify(this.toJSON());
  40812. };
  40813. sourceMapGenerator.SourceMapGenerator = SourceMapGenerator$2;
  40814. var sourceMapConsumer = {};
  40815. var binarySearch$1 = {};
  40816. /* -*- Mode: js; js-indent-level: 2; -*- */
  40817. (function (exports) {
  40818. /*
  40819. * Copyright 2011 Mozilla Foundation and contributors
  40820. * Licensed under the New BSD license. See LICENSE or:
  40821. * http://opensource.org/licenses/BSD-3-Clause
  40822. */
  40823. exports.GREATEST_LOWER_BOUND = 1;
  40824. exports.LEAST_UPPER_BOUND = 2;
  40825. /**
  40826. * Recursive implementation of binary search.
  40827. *
  40828. * @param aLow Indices here and lower do not contain the needle.
  40829. * @param aHigh Indices here and higher do not contain the needle.
  40830. * @param aNeedle The element being searched for.
  40831. * @param aHaystack The non-empty array being searched.
  40832. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  40833. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  40834. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  40835. * closest element that is smaller than or greater than the one we are
  40836. * searching for, respectively, if the exact element cannot be found.
  40837. */
  40838. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  40839. // This function terminates when one of the following is true:
  40840. //
  40841. // 1. We find the exact element we are looking for.
  40842. //
  40843. // 2. We did not find the exact element, but we can return the index of
  40844. // the next-closest element.
  40845. //
  40846. // 3. We did not find the exact element, and there is no next-closest
  40847. // element than the one we are searching for, so we return -1.
  40848. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  40849. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  40850. if (cmp === 0) {
  40851. // Found the element we are looking for.
  40852. return mid;
  40853. }
  40854. else if (cmp > 0) {
  40855. // Our needle is greater than aHaystack[mid].
  40856. if (aHigh - mid > 1) {
  40857. // The element is in the upper half.
  40858. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  40859. }
  40860. // The exact needle element was not found in this haystack. Determine if
  40861. // we are in termination case (3) or (2) and return the appropriate thing.
  40862. if (aBias == exports.LEAST_UPPER_BOUND) {
  40863. return aHigh < aHaystack.length ? aHigh : -1;
  40864. } else {
  40865. return mid;
  40866. }
  40867. }
  40868. else {
  40869. // Our needle is less than aHaystack[mid].
  40870. if (mid - aLow > 1) {
  40871. // The element is in the lower half.
  40872. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  40873. }
  40874. // we are in termination case (3) or (2) and return the appropriate thing.
  40875. if (aBias == exports.LEAST_UPPER_BOUND) {
  40876. return mid;
  40877. } else {
  40878. return aLow < 0 ? -1 : aLow;
  40879. }
  40880. }
  40881. }
  40882. /**
  40883. * This is an implementation of binary search which will always try and return
  40884. * the index of the closest element if there is no exact hit. This is because
  40885. * mappings between original and generated line/col pairs are single points,
  40886. * and there is an implicit region between each of them, so a miss just means
  40887. * that you aren't on the very start of a region.
  40888. *
  40889. * @param aNeedle The element you are looking for.
  40890. * @param aHaystack The array that is being searched.
  40891. * @param aCompare A function which takes the needle and an element in the
  40892. * array and returns -1, 0, or 1 depending on whether the needle is less
  40893. * than, equal to, or greater than the element, respectively.
  40894. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  40895. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  40896. * closest element that is smaller than or greater than the one we are
  40897. * searching for, respectively, if the exact element cannot be found.
  40898. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  40899. */
  40900. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  40901. if (aHaystack.length === 0) {
  40902. return -1;
  40903. }
  40904. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  40905. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  40906. if (index < 0) {
  40907. return -1;
  40908. }
  40909. // We have found either the exact element, or the next-closest element than
  40910. // the one we are searching for. However, there may be more than one such
  40911. // element. Make sure we always return the smallest of these.
  40912. while (index - 1 >= 0) {
  40913. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  40914. break;
  40915. }
  40916. --index;
  40917. }
  40918. return index;
  40919. };
  40920. } (binarySearch$1));
  40921. var quickSort$1 = {};
  40922. /* -*- Mode: js; js-indent-level: 2; -*- */
  40923. /*
  40924. * Copyright 2011 Mozilla Foundation and contributors
  40925. * Licensed under the New BSD license. See LICENSE or:
  40926. * http://opensource.org/licenses/BSD-3-Clause
  40927. */
  40928. // It turns out that some (most?) JavaScript engines don't self-host
  40929. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  40930. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  40931. // custom comparator function, calling back and forth between the VM's C++ and
  40932. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  40933. // worse generated code for the comparator function than would be optimal. In
  40934. // fact, when sorting with a comparator, these costs outweigh the benefits of
  40935. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  40936. // a ~3500ms mean speed-up in `bench/bench.html`.
  40937. /**
  40938. * Swap the elements indexed by `x` and `y` in the array `ary`.
  40939. *
  40940. * @param {Array} ary
  40941. * The array.
  40942. * @param {Number} x
  40943. * The index of the first item.
  40944. * @param {Number} y
  40945. * The index of the second item.
  40946. */
  40947. function swap(ary, x, y) {
  40948. var temp = ary[x];
  40949. ary[x] = ary[y];
  40950. ary[y] = temp;
  40951. }
  40952. /**
  40953. * Returns a random integer within the range `low .. high` inclusive.
  40954. *
  40955. * @param {Number} low
  40956. * The lower bound on the range.
  40957. * @param {Number} high
  40958. * The upper bound on the range.
  40959. */
  40960. function randomIntInRange(low, high) {
  40961. return Math.round(low + (Math.random() * (high - low)));
  40962. }
  40963. /**
  40964. * The Quick Sort algorithm.
  40965. *
  40966. * @param {Array} ary
  40967. * An array to sort.
  40968. * @param {function} comparator
  40969. * Function to use to compare two items.
  40970. * @param {Number} p
  40971. * Start index of the array
  40972. * @param {Number} r
  40973. * End index of the array
  40974. */
  40975. function doQuickSort(ary, comparator, p, r) {
  40976. // If our lower bound is less than our upper bound, we (1) partition the
  40977. // array into two pieces and (2) recurse on each half. If it is not, this is
  40978. // the empty array and our base case.
  40979. if (p < r) {
  40980. // (1) Partitioning.
  40981. //
  40982. // The partitioning chooses a pivot between `p` and `r` and moves all
  40983. // elements that are less than or equal to the pivot to the before it, and
  40984. // all the elements that are greater than it after it. The effect is that
  40985. // once partition is done, the pivot is in the exact place it will be when
  40986. // the array is put in sorted order, and it will not need to be moved
  40987. // again. This runs in O(n) time.
  40988. // Always choose a random pivot so that an input array which is reverse
  40989. // sorted does not cause O(n^2) running time.
  40990. var pivotIndex = randomIntInRange(p, r);
  40991. var i = p - 1;
  40992. swap(ary, pivotIndex, r);
  40993. var pivot = ary[r];
  40994. // Immediately after `j` is incremented in this loop, the following hold
  40995. // true:
  40996. //
  40997. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  40998. //
  40999. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  41000. for (var j = p; j < r; j++) {
  41001. if (comparator(ary[j], pivot) <= 0) {
  41002. i += 1;
  41003. swap(ary, i, j);
  41004. }
  41005. }
  41006. swap(ary, i + 1, j);
  41007. var q = i + 1;
  41008. // (2) Recurse on each half.
  41009. doQuickSort(ary, comparator, p, q - 1);
  41010. doQuickSort(ary, comparator, q + 1, r);
  41011. }
  41012. }
  41013. /**
  41014. * Sort the given array in-place with the given comparator function.
  41015. *
  41016. * @param {Array} ary
  41017. * An array to sort.
  41018. * @param {function} comparator
  41019. * Function to use to compare two items.
  41020. */
  41021. quickSort$1.quickSort = function (ary, comparator) {
  41022. doQuickSort(ary, comparator, 0, ary.length - 1);
  41023. };
  41024. /* -*- Mode: js; js-indent-level: 2; -*- */
  41025. /*
  41026. * Copyright 2011 Mozilla Foundation and contributors
  41027. * Licensed under the New BSD license. See LICENSE or:
  41028. * http://opensource.org/licenses/BSD-3-Clause
  41029. */
  41030. var util$1 = util$5;
  41031. var binarySearch = binarySearch$1;
  41032. var ArraySet = arraySet.ArraySet;
  41033. var base64VLQ = base64Vlq;
  41034. var quickSort = quickSort$1.quickSort;
  41035. function SourceMapConsumer$1(aSourceMap, aSourceMapURL) {
  41036. var sourceMap = aSourceMap;
  41037. if (typeof aSourceMap === 'string') {
  41038. sourceMap = util$1.parseSourceMapInput(aSourceMap);
  41039. }
  41040. return sourceMap.sections != null
  41041. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  41042. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  41043. }
  41044. SourceMapConsumer$1.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  41045. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  41046. };
  41047. /**
  41048. * The version of the source mapping spec that we are consuming.
  41049. */
  41050. SourceMapConsumer$1.prototype._version = 3;
  41051. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  41052. // parsed mapping coordinates from the source map's "mappings" attribute. They
  41053. // are lazily instantiated, accessed via the `_generatedMappings` and
  41054. // `_originalMappings` getters respectively, and we only parse the mappings
  41055. // and create these arrays once queried for a source location. We jump through
  41056. // these hoops because there can be many thousands of mappings, and parsing
  41057. // them is expensive, so we only want to do it if we must.
  41058. //
  41059. // Each object in the arrays is of the form:
  41060. //
  41061. // {
  41062. // generatedLine: The line number in the generated code,
  41063. // generatedColumn: The column number in the generated code,
  41064. // source: The path to the original source file that generated this
  41065. // chunk of code,
  41066. // originalLine: The line number in the original source that
  41067. // corresponds to this chunk of generated code,
  41068. // originalColumn: The column number in the original source that
  41069. // corresponds to this chunk of generated code,
  41070. // name: The name of the original symbol which generated this chunk of
  41071. // code.
  41072. // }
  41073. //
  41074. // All properties except for `generatedLine` and `generatedColumn` can be
  41075. // `null`.
  41076. //
  41077. // `_generatedMappings` is ordered by the generated positions.
  41078. //
  41079. // `_originalMappings` is ordered by the original positions.
  41080. SourceMapConsumer$1.prototype.__generatedMappings = null;
  41081. Object.defineProperty(SourceMapConsumer$1.prototype, '_generatedMappings', {
  41082. configurable: true,
  41083. enumerable: true,
  41084. get: function () {
  41085. if (!this.__generatedMappings) {
  41086. this._parseMappings(this._mappings, this.sourceRoot);
  41087. }
  41088. return this.__generatedMappings;
  41089. }
  41090. });
  41091. SourceMapConsumer$1.prototype.__originalMappings = null;
  41092. Object.defineProperty(SourceMapConsumer$1.prototype, '_originalMappings', {
  41093. configurable: true,
  41094. enumerable: true,
  41095. get: function () {
  41096. if (!this.__originalMappings) {
  41097. this._parseMappings(this._mappings, this.sourceRoot);
  41098. }
  41099. return this.__originalMappings;
  41100. }
  41101. });
  41102. SourceMapConsumer$1.prototype._charIsMappingSeparator =
  41103. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  41104. var c = aStr.charAt(index);
  41105. return c === ";" || c === ",";
  41106. };
  41107. /**
  41108. * Parse the mappings in a string in to a data structure which we can easily
  41109. * query (the ordered arrays in the `this.__generatedMappings` and
  41110. * `this.__originalMappings` properties).
  41111. */
  41112. SourceMapConsumer$1.prototype._parseMappings =
  41113. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41114. throw new Error("Subclasses must implement _parseMappings");
  41115. };
  41116. SourceMapConsumer$1.GENERATED_ORDER = 1;
  41117. SourceMapConsumer$1.ORIGINAL_ORDER = 2;
  41118. SourceMapConsumer$1.GREATEST_LOWER_BOUND = 1;
  41119. SourceMapConsumer$1.LEAST_UPPER_BOUND = 2;
  41120. /**
  41121. * Iterate over each mapping between an original source/line/column and a
  41122. * generated line/column in this source map.
  41123. *
  41124. * @param Function aCallback
  41125. * The function that is called with each mapping.
  41126. * @param Object aContext
  41127. * Optional. If specified, this object will be the value of `this` every
  41128. * time that `aCallback` is called.
  41129. * @param aOrder
  41130. * Either `SourceMapConsumer.GENERATED_ORDER` or
  41131. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  41132. * iterate over the mappings sorted by the generated file's line/column
  41133. * order or the original's source/line/column order, respectively. Defaults to
  41134. * `SourceMapConsumer.GENERATED_ORDER`.
  41135. */
  41136. SourceMapConsumer$1.prototype.eachMapping =
  41137. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  41138. var context = aContext || null;
  41139. var order = aOrder || SourceMapConsumer$1.GENERATED_ORDER;
  41140. var mappings;
  41141. switch (order) {
  41142. case SourceMapConsumer$1.GENERATED_ORDER:
  41143. mappings = this._generatedMappings;
  41144. break;
  41145. case SourceMapConsumer$1.ORIGINAL_ORDER:
  41146. mappings = this._originalMappings;
  41147. break;
  41148. default:
  41149. throw new Error("Unknown order of iteration.");
  41150. }
  41151. var sourceRoot = this.sourceRoot;
  41152. mappings.map(function (mapping) {
  41153. var source = mapping.source === null ? null : this._sources.at(mapping.source);
  41154. source = util$1.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  41155. return {
  41156. source: source,
  41157. generatedLine: mapping.generatedLine,
  41158. generatedColumn: mapping.generatedColumn,
  41159. originalLine: mapping.originalLine,
  41160. originalColumn: mapping.originalColumn,
  41161. name: mapping.name === null ? null : this._names.at(mapping.name)
  41162. };
  41163. }, this).forEach(aCallback, context);
  41164. };
  41165. /**
  41166. * Returns all generated line and column information for the original source,
  41167. * line, and column provided. If no column is provided, returns all mappings
  41168. * corresponding to a either the line we are searching for or the next
  41169. * closest line that has any mappings. Otherwise, returns all mappings
  41170. * corresponding to the given line and either the column we are searching for
  41171. * or the next closest column that has any offsets.
  41172. *
  41173. * The only argument is an object with the following properties:
  41174. *
  41175. * - source: The filename of the original source.
  41176. * - line: The line number in the original source. The line number is 1-based.
  41177. * - column: Optional. the column number in the original source.
  41178. * The column number is 0-based.
  41179. *
  41180. * and an array of objects is returned, each with the following properties:
  41181. *
  41182. * - line: The line number in the generated source, or null. The
  41183. * line number is 1-based.
  41184. * - column: The column number in the generated source, or null.
  41185. * The column number is 0-based.
  41186. */
  41187. SourceMapConsumer$1.prototype.allGeneratedPositionsFor =
  41188. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  41189. var line = util$1.getArg(aArgs, 'line');
  41190. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  41191. // returns the index of the closest mapping less than the needle. By
  41192. // setting needle.originalColumn to 0, we thus find the last mapping for
  41193. // the given line, provided such a mapping exists.
  41194. var needle = {
  41195. source: util$1.getArg(aArgs, 'source'),
  41196. originalLine: line,
  41197. originalColumn: util$1.getArg(aArgs, 'column', 0)
  41198. };
  41199. needle.source = this._findSourceIndex(needle.source);
  41200. if (needle.source < 0) {
  41201. return [];
  41202. }
  41203. var mappings = [];
  41204. var index = this._findMapping(needle,
  41205. this._originalMappings,
  41206. "originalLine",
  41207. "originalColumn",
  41208. util$1.compareByOriginalPositions,
  41209. binarySearch.LEAST_UPPER_BOUND);
  41210. if (index >= 0) {
  41211. var mapping = this._originalMappings[index];
  41212. if (aArgs.column === undefined) {
  41213. var originalLine = mapping.originalLine;
  41214. // Iterate until either we run out of mappings, or we run into
  41215. // a mapping for a different line than the one we found. Since
  41216. // mappings are sorted, this is guaranteed to find all mappings for
  41217. // the line we found.
  41218. while (mapping && mapping.originalLine === originalLine) {
  41219. mappings.push({
  41220. line: util$1.getArg(mapping, 'generatedLine', null),
  41221. column: util$1.getArg(mapping, 'generatedColumn', null),
  41222. lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
  41223. });
  41224. mapping = this._originalMappings[++index];
  41225. }
  41226. } else {
  41227. var originalColumn = mapping.originalColumn;
  41228. // Iterate until either we run out of mappings, or we run into
  41229. // a mapping for a different line than the one we were searching for.
  41230. // Since mappings are sorted, this is guaranteed to find all mappings for
  41231. // the line we are searching for.
  41232. while (mapping &&
  41233. mapping.originalLine === line &&
  41234. mapping.originalColumn == originalColumn) {
  41235. mappings.push({
  41236. line: util$1.getArg(mapping, 'generatedLine', null),
  41237. column: util$1.getArg(mapping, 'generatedColumn', null),
  41238. lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
  41239. });
  41240. mapping = this._originalMappings[++index];
  41241. }
  41242. }
  41243. }
  41244. return mappings;
  41245. };
  41246. sourceMapConsumer.SourceMapConsumer = SourceMapConsumer$1;
  41247. /**
  41248. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  41249. * query for information about the original file positions by giving it a file
  41250. * position in the generated source.
  41251. *
  41252. * The first parameter is the raw source map (either as a JSON string, or
  41253. * already parsed to an object). According to the spec, source maps have the
  41254. * following attributes:
  41255. *
  41256. * - version: Which version of the source map spec this map is following.
  41257. * - sources: An array of URLs to the original source files.
  41258. * - names: An array of identifiers which can be referrenced by individual mappings.
  41259. * - sourceRoot: Optional. The URL root from which all sources are relative.
  41260. * - sourcesContent: Optional. An array of contents of the original source files.
  41261. * - mappings: A string of base64 VLQs which contain the actual mappings.
  41262. * - file: Optional. The generated file this source map is associated with.
  41263. *
  41264. * Here is an example source map, taken from the source map spec[0]:
  41265. *
  41266. * {
  41267. * version : 3,
  41268. * file: "out.js",
  41269. * sourceRoot : "",
  41270. * sources: ["foo.js", "bar.js"],
  41271. * names: ["src", "maps", "are", "fun"],
  41272. * mappings: "AA,AB;;ABCDE;"
  41273. * }
  41274. *
  41275. * The second parameter, if given, is a string whose value is the URL
  41276. * at which the source map was found. This URL is used to compute the
  41277. * sources array.
  41278. *
  41279. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  41280. */
  41281. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  41282. var sourceMap = aSourceMap;
  41283. if (typeof aSourceMap === 'string') {
  41284. sourceMap = util$1.parseSourceMapInput(aSourceMap);
  41285. }
  41286. var version = util$1.getArg(sourceMap, 'version');
  41287. var sources = util$1.getArg(sourceMap, 'sources');
  41288. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  41289. // requires the array) to play nice here.
  41290. var names = util$1.getArg(sourceMap, 'names', []);
  41291. var sourceRoot = util$1.getArg(sourceMap, 'sourceRoot', null);
  41292. var sourcesContent = util$1.getArg(sourceMap, 'sourcesContent', null);
  41293. var mappings = util$1.getArg(sourceMap, 'mappings');
  41294. var file = util$1.getArg(sourceMap, 'file', null);
  41295. // Once again, Sass deviates from the spec and supplies the version as a
  41296. // string rather than a number, so we use loose equality checking here.
  41297. if (version != this._version) {
  41298. throw new Error('Unsupported version: ' + version);
  41299. }
  41300. if (sourceRoot) {
  41301. sourceRoot = util$1.normalize(sourceRoot);
  41302. }
  41303. sources = sources
  41304. .map(String)
  41305. // Some source maps produce relative source paths like "./foo.js" instead of
  41306. // "foo.js". Normalize these first so that future comparisons will succeed.
  41307. // See bugzil.la/1090768.
  41308. .map(util$1.normalize)
  41309. // Always ensure that absolute sources are internally stored relative to
  41310. // the source root, if the source root is absolute. Not doing this would
  41311. // be particularly problematic when the source root is a prefix of the
  41312. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  41313. .map(function (source) {
  41314. return sourceRoot && util$1.isAbsolute(sourceRoot) && util$1.isAbsolute(source)
  41315. ? util$1.relative(sourceRoot, source)
  41316. : source;
  41317. });
  41318. // Pass `true` below to allow duplicate names and sources. While source maps
  41319. // are intended to be compressed and deduplicated, the TypeScript compiler
  41320. // sometimes generates source maps with duplicates in them. See Github issue
  41321. // #72 and bugzil.la/889492.
  41322. this._names = ArraySet.fromArray(names.map(String), true);
  41323. this._sources = ArraySet.fromArray(sources, true);
  41324. this._absoluteSources = this._sources.toArray().map(function (s) {
  41325. return util$1.computeSourceURL(sourceRoot, s, aSourceMapURL);
  41326. });
  41327. this.sourceRoot = sourceRoot;
  41328. this.sourcesContent = sourcesContent;
  41329. this._mappings = mappings;
  41330. this._sourceMapURL = aSourceMapURL;
  41331. this.file = file;
  41332. }
  41333. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
  41334. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer$1;
  41335. /**
  41336. * Utility function to find the index of a source. Returns -1 if not
  41337. * found.
  41338. */
  41339. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  41340. var relativeSource = aSource;
  41341. if (this.sourceRoot != null) {
  41342. relativeSource = util$1.relative(this.sourceRoot, relativeSource);
  41343. }
  41344. if (this._sources.has(relativeSource)) {
  41345. return this._sources.indexOf(relativeSource);
  41346. }
  41347. // Maybe aSource is an absolute URL as returned by |sources|. In
  41348. // this case we can't simply undo the transform.
  41349. var i;
  41350. for (i = 0; i < this._absoluteSources.length; ++i) {
  41351. if (this._absoluteSources[i] == aSource) {
  41352. return i;
  41353. }
  41354. }
  41355. return -1;
  41356. };
  41357. /**
  41358. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  41359. *
  41360. * @param SourceMapGenerator aSourceMap
  41361. * The source map that will be consumed.
  41362. * @param String aSourceMapURL
  41363. * The URL at which the source map can be found (optional)
  41364. * @returns BasicSourceMapConsumer
  41365. */
  41366. BasicSourceMapConsumer.fromSourceMap =
  41367. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  41368. var smc = Object.create(BasicSourceMapConsumer.prototype);
  41369. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  41370. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  41371. smc.sourceRoot = aSourceMap._sourceRoot;
  41372. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  41373. smc.sourceRoot);
  41374. smc.file = aSourceMap._file;
  41375. smc._sourceMapURL = aSourceMapURL;
  41376. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  41377. return util$1.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  41378. });
  41379. // Because we are modifying the entries (by converting string sources and
  41380. // names to indices into the sources and names ArraySets), we have to make
  41381. // a copy of the entry or else bad things happen. Shared mutable state
  41382. // strikes again! See github issue #191.
  41383. var generatedMappings = aSourceMap._mappings.toArray().slice();
  41384. var destGeneratedMappings = smc.__generatedMappings = [];
  41385. var destOriginalMappings = smc.__originalMappings = [];
  41386. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  41387. var srcMapping = generatedMappings[i];
  41388. var destMapping = new Mapping;
  41389. destMapping.generatedLine = srcMapping.generatedLine;
  41390. destMapping.generatedColumn = srcMapping.generatedColumn;
  41391. if (srcMapping.source) {
  41392. destMapping.source = sources.indexOf(srcMapping.source);
  41393. destMapping.originalLine = srcMapping.originalLine;
  41394. destMapping.originalColumn = srcMapping.originalColumn;
  41395. if (srcMapping.name) {
  41396. destMapping.name = names.indexOf(srcMapping.name);
  41397. }
  41398. destOriginalMappings.push(destMapping);
  41399. }
  41400. destGeneratedMappings.push(destMapping);
  41401. }
  41402. quickSort(smc.__originalMappings, util$1.compareByOriginalPositions);
  41403. return smc;
  41404. };
  41405. /**
  41406. * The version of the source mapping spec that we are consuming.
  41407. */
  41408. BasicSourceMapConsumer.prototype._version = 3;
  41409. /**
  41410. * The list of original sources.
  41411. */
  41412. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  41413. get: function () {
  41414. return this._absoluteSources.slice();
  41415. }
  41416. });
  41417. /**
  41418. * Provide the JIT with a nice shape / hidden class.
  41419. */
  41420. function Mapping() {
  41421. this.generatedLine = 0;
  41422. this.generatedColumn = 0;
  41423. this.source = null;
  41424. this.originalLine = null;
  41425. this.originalColumn = null;
  41426. this.name = null;
  41427. }
  41428. /**
  41429. * Parse the mappings in a string in to a data structure which we can easily
  41430. * query (the ordered arrays in the `this.__generatedMappings` and
  41431. * `this.__originalMappings` properties).
  41432. */
  41433. BasicSourceMapConsumer.prototype._parseMappings =
  41434. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41435. var generatedLine = 1;
  41436. var previousGeneratedColumn = 0;
  41437. var previousOriginalLine = 0;
  41438. var previousOriginalColumn = 0;
  41439. var previousSource = 0;
  41440. var previousName = 0;
  41441. var length = aStr.length;
  41442. var index = 0;
  41443. var cachedSegments = {};
  41444. var temp = {};
  41445. var originalMappings = [];
  41446. var generatedMappings = [];
  41447. var mapping, str, segment, end, value;
  41448. while (index < length) {
  41449. if (aStr.charAt(index) === ';') {
  41450. generatedLine++;
  41451. index++;
  41452. previousGeneratedColumn = 0;
  41453. }
  41454. else if (aStr.charAt(index) === ',') {
  41455. index++;
  41456. }
  41457. else {
  41458. mapping = new Mapping();
  41459. mapping.generatedLine = generatedLine;
  41460. // Because each offset is encoded relative to the previous one,
  41461. // many segments often have the same encoding. We can exploit this
  41462. // fact by caching the parsed variable length fields of each segment,
  41463. // allowing us to avoid a second parse if we encounter the same
  41464. // segment again.
  41465. for (end = index; end < length; end++) {
  41466. if (this._charIsMappingSeparator(aStr, end)) {
  41467. break;
  41468. }
  41469. }
  41470. str = aStr.slice(index, end);
  41471. segment = cachedSegments[str];
  41472. if (segment) {
  41473. index += str.length;
  41474. } else {
  41475. segment = [];
  41476. while (index < end) {
  41477. base64VLQ.decode(aStr, index, temp);
  41478. value = temp.value;
  41479. index = temp.rest;
  41480. segment.push(value);
  41481. }
  41482. if (segment.length === 2) {
  41483. throw new Error('Found a source, but no line and column');
  41484. }
  41485. if (segment.length === 3) {
  41486. throw new Error('Found a source and line, but no column');
  41487. }
  41488. cachedSegments[str] = segment;
  41489. }
  41490. // Generated column.
  41491. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  41492. previousGeneratedColumn = mapping.generatedColumn;
  41493. if (segment.length > 1) {
  41494. // Original source.
  41495. mapping.source = previousSource + segment[1];
  41496. previousSource += segment[1];
  41497. // Original line.
  41498. mapping.originalLine = previousOriginalLine + segment[2];
  41499. previousOriginalLine = mapping.originalLine;
  41500. // Lines are stored 0-based
  41501. mapping.originalLine += 1;
  41502. // Original column.
  41503. mapping.originalColumn = previousOriginalColumn + segment[3];
  41504. previousOriginalColumn = mapping.originalColumn;
  41505. if (segment.length > 4) {
  41506. // Original name.
  41507. mapping.name = previousName + segment[4];
  41508. previousName += segment[4];
  41509. }
  41510. }
  41511. generatedMappings.push(mapping);
  41512. if (typeof mapping.originalLine === 'number') {
  41513. originalMappings.push(mapping);
  41514. }
  41515. }
  41516. }
  41517. quickSort(generatedMappings, util$1.compareByGeneratedPositionsDeflated);
  41518. this.__generatedMappings = generatedMappings;
  41519. quickSort(originalMappings, util$1.compareByOriginalPositions);
  41520. this.__originalMappings = originalMappings;
  41521. };
  41522. /**
  41523. * Find the mapping that best matches the hypothetical "needle" mapping that
  41524. * we are searching for in the given "haystack" of mappings.
  41525. */
  41526. BasicSourceMapConsumer.prototype._findMapping =
  41527. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  41528. aColumnName, aComparator, aBias) {
  41529. // To return the position we are searching for, we must first find the
  41530. // mapping for the given position and then return the opposite position it
  41531. // points to. Because the mappings are sorted, we can use binary search to
  41532. // find the best mapping.
  41533. if (aNeedle[aLineName] <= 0) {
  41534. throw new TypeError('Line must be greater than or equal to 1, got '
  41535. + aNeedle[aLineName]);
  41536. }
  41537. if (aNeedle[aColumnName] < 0) {
  41538. throw new TypeError('Column must be greater than or equal to 0, got '
  41539. + aNeedle[aColumnName]);
  41540. }
  41541. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  41542. };
  41543. /**
  41544. * Compute the last column for each generated mapping. The last column is
  41545. * inclusive.
  41546. */
  41547. BasicSourceMapConsumer.prototype.computeColumnSpans =
  41548. function SourceMapConsumer_computeColumnSpans() {
  41549. for (var index = 0; index < this._generatedMappings.length; ++index) {
  41550. var mapping = this._generatedMappings[index];
  41551. // Mappings do not contain a field for the last generated columnt. We
  41552. // can come up with an optimistic estimate, however, by assuming that
  41553. // mappings are contiguous (i.e. given two consecutive mappings, the
  41554. // first mapping ends where the second one starts).
  41555. if (index + 1 < this._generatedMappings.length) {
  41556. var nextMapping = this._generatedMappings[index + 1];
  41557. if (mapping.generatedLine === nextMapping.generatedLine) {
  41558. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  41559. continue;
  41560. }
  41561. }
  41562. // The last mapping for each line spans the entire line.
  41563. mapping.lastGeneratedColumn = Infinity;
  41564. }
  41565. };
  41566. /**
  41567. * Returns the original source, line, and column information for the generated
  41568. * source's line and column positions provided. The only argument is an object
  41569. * with the following properties:
  41570. *
  41571. * - line: The line number in the generated source. The line number
  41572. * is 1-based.
  41573. * - column: The column number in the generated source. The column
  41574. * number is 0-based.
  41575. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  41576. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  41577. * closest element that is smaller than or greater than the one we are
  41578. * searching for, respectively, if the exact element cannot be found.
  41579. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  41580. *
  41581. * and an object is returned with the following properties:
  41582. *
  41583. * - source: The original source file, or null.
  41584. * - line: The line number in the original source, or null. The
  41585. * line number is 1-based.
  41586. * - column: The column number in the original source, or null. The
  41587. * column number is 0-based.
  41588. * - name: The original identifier, or null.
  41589. */
  41590. BasicSourceMapConsumer.prototype.originalPositionFor =
  41591. function SourceMapConsumer_originalPositionFor(aArgs) {
  41592. var needle = {
  41593. generatedLine: util$1.getArg(aArgs, 'line'),
  41594. generatedColumn: util$1.getArg(aArgs, 'column')
  41595. };
  41596. var index = this._findMapping(
  41597. needle,
  41598. this._generatedMappings,
  41599. "generatedLine",
  41600. "generatedColumn",
  41601. util$1.compareByGeneratedPositionsDeflated,
  41602. util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
  41603. );
  41604. if (index >= 0) {
  41605. var mapping = this._generatedMappings[index];
  41606. if (mapping.generatedLine === needle.generatedLine) {
  41607. var source = util$1.getArg(mapping, 'source', null);
  41608. if (source !== null) {
  41609. source = this._sources.at(source);
  41610. source = util$1.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  41611. }
  41612. var name = util$1.getArg(mapping, 'name', null);
  41613. if (name !== null) {
  41614. name = this._names.at(name);
  41615. }
  41616. return {
  41617. source: source,
  41618. line: util$1.getArg(mapping, 'originalLine', null),
  41619. column: util$1.getArg(mapping, 'originalColumn', null),
  41620. name: name
  41621. };
  41622. }
  41623. }
  41624. return {
  41625. source: null,
  41626. line: null,
  41627. column: null,
  41628. name: null
  41629. };
  41630. };
  41631. /**
  41632. * Return true if we have the source content for every source in the source
  41633. * map, false otherwise.
  41634. */
  41635. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  41636. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  41637. if (!this.sourcesContent) {
  41638. return false;
  41639. }
  41640. return this.sourcesContent.length >= this._sources.size() &&
  41641. !this.sourcesContent.some(function (sc) { return sc == null; });
  41642. };
  41643. /**
  41644. * Returns the original source content. The only argument is the url of the
  41645. * original source file. Returns null if no original source content is
  41646. * available.
  41647. */
  41648. BasicSourceMapConsumer.prototype.sourceContentFor =
  41649. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  41650. if (!this.sourcesContent) {
  41651. return null;
  41652. }
  41653. var index = this._findSourceIndex(aSource);
  41654. if (index >= 0) {
  41655. return this.sourcesContent[index];
  41656. }
  41657. var relativeSource = aSource;
  41658. if (this.sourceRoot != null) {
  41659. relativeSource = util$1.relative(this.sourceRoot, relativeSource);
  41660. }
  41661. var url;
  41662. if (this.sourceRoot != null
  41663. && (url = util$1.urlParse(this.sourceRoot))) {
  41664. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  41665. // many users. We can help them out when they expect file:// URIs to
  41666. // behave like it would if they were running a local HTTP server. See
  41667. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  41668. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  41669. if (url.scheme == "file"
  41670. && this._sources.has(fileUriAbsPath)) {
  41671. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  41672. }
  41673. if ((!url.path || url.path == "/")
  41674. && this._sources.has("/" + relativeSource)) {
  41675. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  41676. }
  41677. }
  41678. // This function is used recursively from
  41679. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  41680. // don't want to throw if we can't find the source - we just want to
  41681. // return null, so we provide a flag to exit gracefully.
  41682. if (nullOnMissing) {
  41683. return null;
  41684. }
  41685. else {
  41686. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  41687. }
  41688. };
  41689. /**
  41690. * Returns the generated line and column information for the original source,
  41691. * line, and column positions provided. The only argument is an object with
  41692. * the following properties:
  41693. *
  41694. * - source: The filename of the original source.
  41695. * - line: The line number in the original source. The line number
  41696. * is 1-based.
  41697. * - column: The column number in the original source. The column
  41698. * number is 0-based.
  41699. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  41700. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  41701. * closest element that is smaller than or greater than the one we are
  41702. * searching for, respectively, if the exact element cannot be found.
  41703. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  41704. *
  41705. * and an object is returned with the following properties:
  41706. *
  41707. * - line: The line number in the generated source, or null. The
  41708. * line number is 1-based.
  41709. * - column: The column number in the generated source, or null.
  41710. * The column number is 0-based.
  41711. */
  41712. BasicSourceMapConsumer.prototype.generatedPositionFor =
  41713. function SourceMapConsumer_generatedPositionFor(aArgs) {
  41714. var source = util$1.getArg(aArgs, 'source');
  41715. source = this._findSourceIndex(source);
  41716. if (source < 0) {
  41717. return {
  41718. line: null,
  41719. column: null,
  41720. lastColumn: null
  41721. };
  41722. }
  41723. var needle = {
  41724. source: source,
  41725. originalLine: util$1.getArg(aArgs, 'line'),
  41726. originalColumn: util$1.getArg(aArgs, 'column')
  41727. };
  41728. var index = this._findMapping(
  41729. needle,
  41730. this._originalMappings,
  41731. "originalLine",
  41732. "originalColumn",
  41733. util$1.compareByOriginalPositions,
  41734. util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
  41735. );
  41736. if (index >= 0) {
  41737. var mapping = this._originalMappings[index];
  41738. if (mapping.source === needle.source) {
  41739. return {
  41740. line: util$1.getArg(mapping, 'generatedLine', null),
  41741. column: util$1.getArg(mapping, 'generatedColumn', null),
  41742. lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
  41743. };
  41744. }
  41745. }
  41746. return {
  41747. line: null,
  41748. column: null,
  41749. lastColumn: null
  41750. };
  41751. };
  41752. sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
  41753. /**
  41754. * An IndexedSourceMapConsumer instance represents a parsed source map which
  41755. * we can query for information. It differs from BasicSourceMapConsumer in
  41756. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  41757. * input.
  41758. *
  41759. * The first parameter is a raw source map (either as a JSON string, or already
  41760. * parsed to an object). According to the spec for indexed source maps, they
  41761. * have the following attributes:
  41762. *
  41763. * - version: Which version of the source map spec this map is following.
  41764. * - file: Optional. The generated file this source map is associated with.
  41765. * - sections: A list of section definitions.
  41766. *
  41767. * Each value under the "sections" field has two fields:
  41768. * - offset: The offset into the original specified at which this section
  41769. * begins to apply, defined as an object with a "line" and "column"
  41770. * field.
  41771. * - map: A source map definition. This source map could also be indexed,
  41772. * but doesn't have to be.
  41773. *
  41774. * Instead of the "map" field, it's also possible to have a "url" field
  41775. * specifying a URL to retrieve a source map from, but that's currently
  41776. * unsupported.
  41777. *
  41778. * Here's an example source map, taken from the source map spec[0], but
  41779. * modified to omit a section which uses the "url" field.
  41780. *
  41781. * {
  41782. * version : 3,
  41783. * file: "app.js",
  41784. * sections: [{
  41785. * offset: {line:100, column:10},
  41786. * map: {
  41787. * version : 3,
  41788. * file: "section.js",
  41789. * sources: ["foo.js", "bar.js"],
  41790. * names: ["src", "maps", "are", "fun"],
  41791. * mappings: "AAAA,E;;ABCDE;"
  41792. * }
  41793. * }],
  41794. * }
  41795. *
  41796. * The second parameter, if given, is a string whose value is the URL
  41797. * at which the source map was found. This URL is used to compute the
  41798. * sources array.
  41799. *
  41800. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  41801. */
  41802. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  41803. var sourceMap = aSourceMap;
  41804. if (typeof aSourceMap === 'string') {
  41805. sourceMap = util$1.parseSourceMapInput(aSourceMap);
  41806. }
  41807. var version = util$1.getArg(sourceMap, 'version');
  41808. var sections = util$1.getArg(sourceMap, 'sections');
  41809. if (version != this._version) {
  41810. throw new Error('Unsupported version: ' + version);
  41811. }
  41812. this._sources = new ArraySet();
  41813. this._names = new ArraySet();
  41814. var lastOffset = {
  41815. line: -1,
  41816. column: 0
  41817. };
  41818. this._sections = sections.map(function (s) {
  41819. if (s.url) {
  41820. // The url field will require support for asynchronicity.
  41821. // See https://github.com/mozilla/source-map/issues/16
  41822. throw new Error('Support for url field in sections not implemented.');
  41823. }
  41824. var offset = util$1.getArg(s, 'offset');
  41825. var offsetLine = util$1.getArg(offset, 'line');
  41826. var offsetColumn = util$1.getArg(offset, 'column');
  41827. if (offsetLine < lastOffset.line ||
  41828. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  41829. throw new Error('Section offsets must be ordered and non-overlapping.');
  41830. }
  41831. lastOffset = offset;
  41832. return {
  41833. generatedOffset: {
  41834. // The offset fields are 0-based, but we use 1-based indices when
  41835. // encoding/decoding from VLQ.
  41836. generatedLine: offsetLine + 1,
  41837. generatedColumn: offsetColumn + 1
  41838. },
  41839. consumer: new SourceMapConsumer$1(util$1.getArg(s, 'map'), aSourceMapURL)
  41840. }
  41841. });
  41842. }
  41843. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
  41844. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer$1;
  41845. /**
  41846. * The version of the source mapping spec that we are consuming.
  41847. */
  41848. IndexedSourceMapConsumer.prototype._version = 3;
  41849. /**
  41850. * The list of original sources.
  41851. */
  41852. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  41853. get: function () {
  41854. var sources = [];
  41855. for (var i = 0; i < this._sections.length; i++) {
  41856. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  41857. sources.push(this._sections[i].consumer.sources[j]);
  41858. }
  41859. }
  41860. return sources;
  41861. }
  41862. });
  41863. /**
  41864. * Returns the original source, line, and column information for the generated
  41865. * source's line and column positions provided. The only argument is an object
  41866. * with the following properties:
  41867. *
  41868. * - line: The line number in the generated source. The line number
  41869. * is 1-based.
  41870. * - column: The column number in the generated source. The column
  41871. * number is 0-based.
  41872. *
  41873. * and an object is returned with the following properties:
  41874. *
  41875. * - source: The original source file, or null.
  41876. * - line: The line number in the original source, or null. The
  41877. * line number is 1-based.
  41878. * - column: The column number in the original source, or null. The
  41879. * column number is 0-based.
  41880. * - name: The original identifier, or null.
  41881. */
  41882. IndexedSourceMapConsumer.prototype.originalPositionFor =
  41883. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  41884. var needle = {
  41885. generatedLine: util$1.getArg(aArgs, 'line'),
  41886. generatedColumn: util$1.getArg(aArgs, 'column')
  41887. };
  41888. // Find the section containing the generated position we're trying to map
  41889. // to an original position.
  41890. var sectionIndex = binarySearch.search(needle, this._sections,
  41891. function(needle, section) {
  41892. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  41893. if (cmp) {
  41894. return cmp;
  41895. }
  41896. return (needle.generatedColumn -
  41897. section.generatedOffset.generatedColumn);
  41898. });
  41899. var section = this._sections[sectionIndex];
  41900. if (!section) {
  41901. return {
  41902. source: null,
  41903. line: null,
  41904. column: null,
  41905. name: null
  41906. };
  41907. }
  41908. return section.consumer.originalPositionFor({
  41909. line: needle.generatedLine -
  41910. (section.generatedOffset.generatedLine - 1),
  41911. column: needle.generatedColumn -
  41912. (section.generatedOffset.generatedLine === needle.generatedLine
  41913. ? section.generatedOffset.generatedColumn - 1
  41914. : 0),
  41915. bias: aArgs.bias
  41916. });
  41917. };
  41918. /**
  41919. * Return true if we have the source content for every source in the source
  41920. * map, false otherwise.
  41921. */
  41922. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  41923. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  41924. return this._sections.every(function (s) {
  41925. return s.consumer.hasContentsOfAllSources();
  41926. });
  41927. };
  41928. /**
  41929. * Returns the original source content. The only argument is the url of the
  41930. * original source file. Returns null if no original source content is
  41931. * available.
  41932. */
  41933. IndexedSourceMapConsumer.prototype.sourceContentFor =
  41934. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  41935. for (var i = 0; i < this._sections.length; i++) {
  41936. var section = this._sections[i];
  41937. var content = section.consumer.sourceContentFor(aSource, true);
  41938. if (content) {
  41939. return content;
  41940. }
  41941. }
  41942. if (nullOnMissing) {
  41943. return null;
  41944. }
  41945. else {
  41946. throw new Error('"' + aSource + '" is not in the SourceMap.');
  41947. }
  41948. };
  41949. /**
  41950. * Returns the generated line and column information for the original source,
  41951. * line, and column positions provided. The only argument is an object with
  41952. * the following properties:
  41953. *
  41954. * - source: The filename of the original source.
  41955. * - line: The line number in the original source. The line number
  41956. * is 1-based.
  41957. * - column: The column number in the original source. The column
  41958. * number is 0-based.
  41959. *
  41960. * and an object is returned with the following properties:
  41961. *
  41962. * - line: The line number in the generated source, or null. The
  41963. * line number is 1-based.
  41964. * - column: The column number in the generated source, or null.
  41965. * The column number is 0-based.
  41966. */
  41967. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  41968. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  41969. for (var i = 0; i < this._sections.length; i++) {
  41970. var section = this._sections[i];
  41971. // Only consider this section if the requested source is in the list of
  41972. // sources of the consumer.
  41973. if (section.consumer._findSourceIndex(util$1.getArg(aArgs, 'source')) === -1) {
  41974. continue;
  41975. }
  41976. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  41977. if (generatedPosition) {
  41978. var ret = {
  41979. line: generatedPosition.line +
  41980. (section.generatedOffset.generatedLine - 1),
  41981. column: generatedPosition.column +
  41982. (section.generatedOffset.generatedLine === generatedPosition.line
  41983. ? section.generatedOffset.generatedColumn - 1
  41984. : 0)
  41985. };
  41986. return ret;
  41987. }
  41988. }
  41989. return {
  41990. line: null,
  41991. column: null
  41992. };
  41993. };
  41994. /**
  41995. * Parse the mappings in a string in to a data structure which we can easily
  41996. * query (the ordered arrays in the `this.__generatedMappings` and
  41997. * `this.__originalMappings` properties).
  41998. */
  41999. IndexedSourceMapConsumer.prototype._parseMappings =
  42000. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42001. this.__generatedMappings = [];
  42002. this.__originalMappings = [];
  42003. for (var i = 0; i < this._sections.length; i++) {
  42004. var section = this._sections[i];
  42005. var sectionMappings = section.consumer._generatedMappings;
  42006. for (var j = 0; j < sectionMappings.length; j++) {
  42007. var mapping = sectionMappings[j];
  42008. var source = section.consumer._sources.at(mapping.source);
  42009. source = util$1.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  42010. this._sources.add(source);
  42011. source = this._sources.indexOf(source);
  42012. var name = null;
  42013. if (mapping.name) {
  42014. name = section.consumer._names.at(mapping.name);
  42015. this._names.add(name);
  42016. name = this._names.indexOf(name);
  42017. }
  42018. // The mappings coming from the consumer for the section have
  42019. // generated positions relative to the start of the section, so we
  42020. // need to offset them to be relative to the start of the concatenated
  42021. // generated file.
  42022. var adjustedMapping = {
  42023. source: source,
  42024. generatedLine: mapping.generatedLine +
  42025. (section.generatedOffset.generatedLine - 1),
  42026. generatedColumn: mapping.generatedColumn +
  42027. (section.generatedOffset.generatedLine === mapping.generatedLine
  42028. ? section.generatedOffset.generatedColumn - 1
  42029. : 0),
  42030. originalLine: mapping.originalLine,
  42031. originalColumn: mapping.originalColumn,
  42032. name: name
  42033. };
  42034. this.__generatedMappings.push(adjustedMapping);
  42035. if (typeof adjustedMapping.originalLine === 'number') {
  42036. this.__originalMappings.push(adjustedMapping);
  42037. }
  42038. }
  42039. }
  42040. quickSort(this.__generatedMappings, util$1.compareByGeneratedPositionsDeflated);
  42041. quickSort(this.__originalMappings, util$1.compareByOriginalPositions);
  42042. };
  42043. sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  42044. var sourceNode = {};
  42045. /* -*- Mode: js; js-indent-level: 2; -*- */
  42046. /*
  42047. * Copyright 2011 Mozilla Foundation and contributors
  42048. * Licensed under the New BSD license. See LICENSE or:
  42049. * http://opensource.org/licenses/BSD-3-Clause
  42050. */
  42051. var SourceMapGenerator$1 = sourceMapGenerator.SourceMapGenerator;
  42052. var util = util$5;
  42053. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  42054. // operating systems these days (capturing the result).
  42055. var REGEX_NEWLINE = /(\r?\n)/;
  42056. // Newline character code for charCodeAt() comparisons
  42057. var NEWLINE_CODE = 10;
  42058. // Private symbol for identifying `SourceNode`s when multiple versions of
  42059. // the source-map library are loaded. This MUST NOT CHANGE across
  42060. // versions!
  42061. var isSourceNode = "$$$isSourceNode$$$";
  42062. /**
  42063. * SourceNodes provide a way to abstract over interpolating/concatenating
  42064. * snippets of generated JavaScript source code while maintaining the line and
  42065. * column information associated with the original source code.
  42066. *
  42067. * @param aLine The original line number.
  42068. * @param aColumn The original column number.
  42069. * @param aSource The original source's filename.
  42070. * @param aChunks Optional. An array of strings which are snippets of
  42071. * generated JS, or other SourceNodes.
  42072. * @param aName The original identifier.
  42073. */
  42074. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  42075. this.children = [];
  42076. this.sourceContents = {};
  42077. this.line = aLine == null ? null : aLine;
  42078. this.column = aColumn == null ? null : aColumn;
  42079. this.source = aSource == null ? null : aSource;
  42080. this.name = aName == null ? null : aName;
  42081. this[isSourceNode] = true;
  42082. if (aChunks != null) this.add(aChunks);
  42083. }
  42084. /**
  42085. * Creates a SourceNode from generated code and a SourceMapConsumer.
  42086. *
  42087. * @param aGeneratedCode The generated code
  42088. * @param aSourceMapConsumer The SourceMap for the generated code
  42089. * @param aRelativePath Optional. The path that relative sources in the
  42090. * SourceMapConsumer should be relative to.
  42091. */
  42092. SourceNode.fromStringWithSourceMap =
  42093. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  42094. // The SourceNode we want to fill with the generated code
  42095. // and the SourceMap
  42096. var node = new SourceNode();
  42097. // All even indices of this array are one line of the generated code,
  42098. // while all odd indices are the newlines between two adjacent lines
  42099. // (since `REGEX_NEWLINE` captures its match).
  42100. // Processed fragments are accessed by calling `shiftNextLine`.
  42101. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  42102. var remainingLinesIndex = 0;
  42103. var shiftNextLine = function() {
  42104. var lineContents = getNextLine();
  42105. // The last line of a file might not have a newline.
  42106. var newLine = getNextLine() || "";
  42107. return lineContents + newLine;
  42108. function getNextLine() {
  42109. return remainingLinesIndex < remainingLines.length ?
  42110. remainingLines[remainingLinesIndex++] : undefined;
  42111. }
  42112. };
  42113. // We need to remember the position of "remainingLines"
  42114. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  42115. // The generate SourceNodes we need a code range.
  42116. // To extract it current and last mapping is used.
  42117. // Here we store the last mapping.
  42118. var lastMapping = null;
  42119. aSourceMapConsumer.eachMapping(function (mapping) {
  42120. if (lastMapping !== null) {
  42121. // We add the code from "lastMapping" to "mapping":
  42122. // First check if there is a new line in between.
  42123. if (lastGeneratedLine < mapping.generatedLine) {
  42124. // Associate first line with "lastMapping"
  42125. addMappingWithCode(lastMapping, shiftNextLine());
  42126. lastGeneratedLine++;
  42127. lastGeneratedColumn = 0;
  42128. // The remaining code is added without mapping
  42129. } else {
  42130. // There is no new line in between.
  42131. // Associate the code between "lastGeneratedColumn" and
  42132. // "mapping.generatedColumn" with "lastMapping"
  42133. var nextLine = remainingLines[remainingLinesIndex] || '';
  42134. var code = nextLine.substr(0, mapping.generatedColumn -
  42135. lastGeneratedColumn);
  42136. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  42137. lastGeneratedColumn);
  42138. lastGeneratedColumn = mapping.generatedColumn;
  42139. addMappingWithCode(lastMapping, code);
  42140. // No more remaining code, continue
  42141. lastMapping = mapping;
  42142. return;
  42143. }
  42144. }
  42145. // We add the generated code until the first mapping
  42146. // to the SourceNode without any mapping.
  42147. // Each line is added as separate string.
  42148. while (lastGeneratedLine < mapping.generatedLine) {
  42149. node.add(shiftNextLine());
  42150. lastGeneratedLine++;
  42151. }
  42152. if (lastGeneratedColumn < mapping.generatedColumn) {
  42153. var nextLine = remainingLines[remainingLinesIndex] || '';
  42154. node.add(nextLine.substr(0, mapping.generatedColumn));
  42155. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  42156. lastGeneratedColumn = mapping.generatedColumn;
  42157. }
  42158. lastMapping = mapping;
  42159. }, this);
  42160. // We have processed all mappings.
  42161. if (remainingLinesIndex < remainingLines.length) {
  42162. if (lastMapping) {
  42163. // Associate the remaining code in the current line with "lastMapping"
  42164. addMappingWithCode(lastMapping, shiftNextLine());
  42165. }
  42166. // and add the remaining lines without any mapping
  42167. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  42168. }
  42169. // Copy sourcesContent into SourceNode
  42170. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  42171. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  42172. if (content != null) {
  42173. if (aRelativePath != null) {
  42174. sourceFile = util.join(aRelativePath, sourceFile);
  42175. }
  42176. node.setSourceContent(sourceFile, content);
  42177. }
  42178. });
  42179. return node;
  42180. function addMappingWithCode(mapping, code) {
  42181. if (mapping === null || mapping.source === undefined) {
  42182. node.add(code);
  42183. } else {
  42184. var source = aRelativePath
  42185. ? util.join(aRelativePath, mapping.source)
  42186. : mapping.source;
  42187. node.add(new SourceNode(mapping.originalLine,
  42188. mapping.originalColumn,
  42189. source,
  42190. code,
  42191. mapping.name));
  42192. }
  42193. }
  42194. };
  42195. /**
  42196. * Add a chunk of generated JS to this source node.
  42197. *
  42198. * @param aChunk A string snippet of generated JS code, another instance of
  42199. * SourceNode, or an array where each member is one of those things.
  42200. */
  42201. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  42202. if (Array.isArray(aChunk)) {
  42203. aChunk.forEach(function (chunk) {
  42204. this.add(chunk);
  42205. }, this);
  42206. }
  42207. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  42208. if (aChunk) {
  42209. this.children.push(aChunk);
  42210. }
  42211. }
  42212. else {
  42213. throw new TypeError(
  42214. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  42215. );
  42216. }
  42217. return this;
  42218. };
  42219. /**
  42220. * Add a chunk of generated JS to the beginning of this source node.
  42221. *
  42222. * @param aChunk A string snippet of generated JS code, another instance of
  42223. * SourceNode, or an array where each member is one of those things.
  42224. */
  42225. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  42226. if (Array.isArray(aChunk)) {
  42227. for (var i = aChunk.length-1; i >= 0; i--) {
  42228. this.prepend(aChunk[i]);
  42229. }
  42230. }
  42231. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  42232. this.children.unshift(aChunk);
  42233. }
  42234. else {
  42235. throw new TypeError(
  42236. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  42237. );
  42238. }
  42239. return this;
  42240. };
  42241. /**
  42242. * Walk over the tree of JS snippets in this node and its children. The
  42243. * walking function is called once for each snippet of JS and is passed that
  42244. * snippet and the its original associated source's line/column location.
  42245. *
  42246. * @param aFn The traversal function.
  42247. */
  42248. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  42249. var chunk;
  42250. for (var i = 0, len = this.children.length; i < len; i++) {
  42251. chunk = this.children[i];
  42252. if (chunk[isSourceNode]) {
  42253. chunk.walk(aFn);
  42254. }
  42255. else {
  42256. if (chunk !== '') {
  42257. aFn(chunk, { source: this.source,
  42258. line: this.line,
  42259. column: this.column,
  42260. name: this.name });
  42261. }
  42262. }
  42263. }
  42264. };
  42265. /**
  42266. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  42267. * each of `this.children`.
  42268. *
  42269. * @param aSep The separator.
  42270. */
  42271. SourceNode.prototype.join = function SourceNode_join(aSep) {
  42272. var newChildren;
  42273. var i;
  42274. var len = this.children.length;
  42275. if (len > 0) {
  42276. newChildren = [];
  42277. for (i = 0; i < len-1; i++) {
  42278. newChildren.push(this.children[i]);
  42279. newChildren.push(aSep);
  42280. }
  42281. newChildren.push(this.children[i]);
  42282. this.children = newChildren;
  42283. }
  42284. return this;
  42285. };
  42286. /**
  42287. * Call String.prototype.replace on the very right-most source snippet. Useful
  42288. * for trimming whitespace from the end of a source node, etc.
  42289. *
  42290. * @param aPattern The pattern to replace.
  42291. * @param aReplacement The thing to replace the pattern with.
  42292. */
  42293. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  42294. var lastChild = this.children[this.children.length - 1];
  42295. if (lastChild[isSourceNode]) {
  42296. lastChild.replaceRight(aPattern, aReplacement);
  42297. }
  42298. else if (typeof lastChild === 'string') {
  42299. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  42300. }
  42301. else {
  42302. this.children.push(''.replace(aPattern, aReplacement));
  42303. }
  42304. return this;
  42305. };
  42306. /**
  42307. * Set the source content for a source file. This will be added to the SourceMapGenerator
  42308. * in the sourcesContent field.
  42309. *
  42310. * @param aSourceFile The filename of the source file
  42311. * @param aSourceContent The content of the source file
  42312. */
  42313. SourceNode.prototype.setSourceContent =
  42314. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  42315. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  42316. };
  42317. /**
  42318. * Walk over the tree of SourceNodes. The walking function is called for each
  42319. * source file content and is passed the filename and source content.
  42320. *
  42321. * @param aFn The traversal function.
  42322. */
  42323. SourceNode.prototype.walkSourceContents =
  42324. function SourceNode_walkSourceContents(aFn) {
  42325. for (var i = 0, len = this.children.length; i < len; i++) {
  42326. if (this.children[i][isSourceNode]) {
  42327. this.children[i].walkSourceContents(aFn);
  42328. }
  42329. }
  42330. var sources = Object.keys(this.sourceContents);
  42331. for (var i = 0, len = sources.length; i < len; i++) {
  42332. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  42333. }
  42334. };
  42335. /**
  42336. * Return the string representation of this source node. Walks over the tree
  42337. * and concatenates all the various snippets together to one string.
  42338. */
  42339. SourceNode.prototype.toString = function SourceNode_toString() {
  42340. var str = "";
  42341. this.walk(function (chunk) {
  42342. str += chunk;
  42343. });
  42344. return str;
  42345. };
  42346. /**
  42347. * Returns the string representation of this source node along with a source
  42348. * map.
  42349. */
  42350. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  42351. var generated = {
  42352. code: "",
  42353. line: 1,
  42354. column: 0
  42355. };
  42356. var map = new SourceMapGenerator$1(aArgs);
  42357. var sourceMappingActive = false;
  42358. var lastOriginalSource = null;
  42359. var lastOriginalLine = null;
  42360. var lastOriginalColumn = null;
  42361. var lastOriginalName = null;
  42362. this.walk(function (chunk, original) {
  42363. generated.code += chunk;
  42364. if (original.source !== null
  42365. && original.line !== null
  42366. && original.column !== null) {
  42367. if(lastOriginalSource !== original.source
  42368. || lastOriginalLine !== original.line
  42369. || lastOriginalColumn !== original.column
  42370. || lastOriginalName !== original.name) {
  42371. map.addMapping({
  42372. source: original.source,
  42373. original: {
  42374. line: original.line,
  42375. column: original.column
  42376. },
  42377. generated: {
  42378. line: generated.line,
  42379. column: generated.column
  42380. },
  42381. name: original.name
  42382. });
  42383. }
  42384. lastOriginalSource = original.source;
  42385. lastOriginalLine = original.line;
  42386. lastOriginalColumn = original.column;
  42387. lastOriginalName = original.name;
  42388. sourceMappingActive = true;
  42389. } else if (sourceMappingActive) {
  42390. map.addMapping({
  42391. generated: {
  42392. line: generated.line,
  42393. column: generated.column
  42394. }
  42395. });
  42396. lastOriginalSource = null;
  42397. sourceMappingActive = false;
  42398. }
  42399. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  42400. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  42401. generated.line++;
  42402. generated.column = 0;
  42403. // Mappings end at eol
  42404. if (idx + 1 === length) {
  42405. lastOriginalSource = null;
  42406. sourceMappingActive = false;
  42407. } else if (sourceMappingActive) {
  42408. map.addMapping({
  42409. source: original.source,
  42410. original: {
  42411. line: original.line,
  42412. column: original.column
  42413. },
  42414. generated: {
  42415. line: generated.line,
  42416. column: generated.column
  42417. },
  42418. name: original.name
  42419. });
  42420. }
  42421. } else {
  42422. generated.column++;
  42423. }
  42424. }
  42425. });
  42426. this.walkSourceContents(function (sourceFile, sourceContent) {
  42427. map.setSourceContent(sourceFile, sourceContent);
  42428. });
  42429. return { code: generated.code, map: map };
  42430. };
  42431. sourceNode.SourceNode = SourceNode;
  42432. /*
  42433. * Copyright 2009-2011 Mozilla Foundation and contributors
  42434. * Licensed under the New BSD license. See LICENSE.txt or:
  42435. * http://opensource.org/licenses/BSD-3-Clause
  42436. */
  42437. sourceMap$1.SourceMapGenerator = sourceMapGenerator.SourceMapGenerator;
  42438. sourceMap$1.SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
  42439. sourceMap$1.SourceNode = sourceNode.SourceNode;
  42440. var sourceMap = sourceMap$1;
  42441. var SourceMapConsumer = sourceMap.SourceMapConsumer;
  42442. var SourceMapGenerator = sourceMap.SourceMapGenerator;
  42443. var mergeSourceMap = merge;
  42444. /**
  42445. * Merge old source map and new source map and return merged.
  42446. * If old or new source map value is falsy, return another one as it is.
  42447. *
  42448. * @param {object|string} [oldMap] old source map object
  42449. * @param {object|string} [newmap] new source map object
  42450. * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
  42451. */
  42452. function merge(oldMap, newMap) {
  42453. if (!oldMap) return newMap
  42454. if (!newMap) return oldMap
  42455. var oldMapConsumer = new SourceMapConsumer(oldMap);
  42456. var newMapConsumer = new SourceMapConsumer(newMap);
  42457. var mergedMapGenerator = new SourceMapGenerator();
  42458. // iterate on new map and overwrite original position of new map with one of old map
  42459. newMapConsumer.eachMapping(function(m) {
  42460. // pass when `originalLine` is null.
  42461. // It occurs in case that the node does not have origin in original code.
  42462. if (m.originalLine == null) return
  42463. var origPosInOldMap = oldMapConsumer.originalPositionFor({
  42464. line: m.originalLine,
  42465. column: m.originalColumn
  42466. });
  42467. if (origPosInOldMap.source == null) return
  42468. mergedMapGenerator.addMapping({
  42469. original: {
  42470. line: origPosInOldMap.line,
  42471. column: origPosInOldMap.column
  42472. },
  42473. generated: {
  42474. line: m.generatedLine,
  42475. column: m.generatedColumn
  42476. },
  42477. source: origPosInOldMap.source,
  42478. name: origPosInOldMap.name
  42479. });
  42480. });
  42481. var consumers = [oldMapConsumer, newMapConsumer];
  42482. consumers.forEach(function(consumer) {
  42483. consumer.sources.forEach(function(sourceFile) {
  42484. mergedMapGenerator._sources.add(sourceFile);
  42485. var sourceContent = consumer.sourceContentFor(sourceFile);
  42486. if (sourceContent != null) {
  42487. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  42488. }
  42489. });
  42490. });
  42491. mergedMapGenerator._sourceRoot = oldMap.sourceRoot;
  42492. mergedMapGenerator._file = oldMap.file;
  42493. return JSON.parse(mergedMapGenerator.toString())
  42494. }
  42495. var merge$1 = /*@__PURE__*/getDefaultExportFromCjs(mergeSourceMap);
  42496. var __defProp$5 = Object.defineProperty;
  42497. var __defProps$5 = Object.defineProperties;
  42498. var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
  42499. var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
  42500. var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
  42501. var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
  42502. var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  42503. var __spreadValues$5 = (a, b) => {
  42504. for (var prop in b || (b = {}))
  42505. if (__hasOwnProp$5.call(b, prop))
  42506. __defNormalProp$5(a, prop, b[prop]);
  42507. if (__getOwnPropSymbols$5)
  42508. for (var prop of __getOwnPropSymbols$5(b)) {
  42509. if (__propIsEnum$5.call(b, prop))
  42510. __defNormalProp$5(a, prop, b[prop]);
  42511. }
  42512. return a;
  42513. };
  42514. var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
  42515. const scss = (source, map, options, load = require) => {
  42516. const nodeSass = load("sass");
  42517. const finalOptions = __spreadProps$5(__spreadValues$5({}, options), {
  42518. data: getSource(source, options.filename, options.additionalData),
  42519. file: options.filename,
  42520. outFile: options.filename,
  42521. sourceMap: !!map
  42522. });
  42523. try {
  42524. const result = nodeSass.renderSync(finalOptions);
  42525. const dependencies = result.stats.includedFiles;
  42526. if (map) {
  42527. return {
  42528. code: result.css.toString(),
  42529. map: merge$1(map, JSON.parse(result.map.toString())),
  42530. errors: [],
  42531. dependencies
  42532. };
  42533. }
  42534. return { code: result.css.toString(), errors: [], dependencies };
  42535. } catch (e) {
  42536. return { code: "", errors: [e], dependencies: [] };
  42537. }
  42538. };
  42539. const sass = (source, map, options, load) => scss(
  42540. source,
  42541. map,
  42542. __spreadProps$5(__spreadValues$5({}, options), {
  42543. indentedSyntax: true
  42544. }),
  42545. load
  42546. );
  42547. const less = (source, map, options, load = require) => {
  42548. const nodeLess = load("less");
  42549. let result;
  42550. let error = null;
  42551. nodeLess.render(
  42552. getSource(source, options.filename, options.additionalData),
  42553. __spreadProps$5(__spreadValues$5({}, options), { syncImport: true }),
  42554. (err, output) => {
  42555. error = err;
  42556. result = output;
  42557. }
  42558. );
  42559. if (error)
  42560. return { code: "", errors: [error], dependencies: [] };
  42561. const dependencies = result.imports;
  42562. if (map) {
  42563. return {
  42564. code: result.css.toString(),
  42565. map: merge$1(map, result.map),
  42566. errors: [],
  42567. dependencies
  42568. };
  42569. }
  42570. return {
  42571. code: result.css.toString(),
  42572. errors: [],
  42573. dependencies
  42574. };
  42575. };
  42576. const styl = (source, map, options, load = require) => {
  42577. const nodeStylus = load("stylus");
  42578. try {
  42579. const ref = nodeStylus(source, options);
  42580. if (map)
  42581. ref.set("sourcemap", { inline: false, comment: false });
  42582. const result = ref.render();
  42583. const dependencies = ref.deps();
  42584. if (map) {
  42585. return {
  42586. code: result,
  42587. map: merge$1(map, ref.sourcemap),
  42588. errors: [],
  42589. dependencies
  42590. };
  42591. }
  42592. return { code: result, errors: [], dependencies };
  42593. } catch (e) {
  42594. return { code: "", errors: [e], dependencies: [] };
  42595. }
  42596. };
  42597. function getSource(source, filename, additionalData) {
  42598. if (!additionalData)
  42599. return source;
  42600. if (isFunction$1(additionalData)) {
  42601. return additionalData(source, filename);
  42602. }
  42603. return additionalData + source;
  42604. }
  42605. const processors = {
  42606. less,
  42607. sass,
  42608. scss,
  42609. styl,
  42610. stylus: styl
  42611. };
  42612. var __defProp$4 = Object.defineProperty;
  42613. var __defProps$4 = Object.defineProperties;
  42614. var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
  42615. var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
  42616. var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
  42617. var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
  42618. var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  42619. var __spreadValues$4 = (a, b) => {
  42620. for (var prop in b || (b = {}))
  42621. if (__hasOwnProp$4.call(b, prop))
  42622. __defNormalProp$4(a, prop, b[prop]);
  42623. if (__getOwnPropSymbols$4)
  42624. for (var prop of __getOwnPropSymbols$4(b)) {
  42625. if (__propIsEnum$4.call(b, prop))
  42626. __defNormalProp$4(a, prop, b[prop]);
  42627. }
  42628. return a;
  42629. };
  42630. var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
  42631. function compileStyle(options) {
  42632. return doCompileStyle(__spreadProps$4(__spreadValues$4({}, options), {
  42633. isAsync: false
  42634. }));
  42635. }
  42636. function compileStyleAsync(options) {
  42637. return doCompileStyle(__spreadProps$4(__spreadValues$4({}, options), {
  42638. isAsync: true
  42639. }));
  42640. }
  42641. function doCompileStyle(options) {
  42642. const {
  42643. filename,
  42644. id,
  42645. scoped = false,
  42646. trim = true,
  42647. isProd = false,
  42648. modules = false,
  42649. modulesOptions = {},
  42650. preprocessLang,
  42651. postcssOptions,
  42652. postcssPlugins
  42653. } = options;
  42654. const preprocessor = preprocessLang && processors[preprocessLang];
  42655. const preProcessedSource = preprocessor && preprocess(options, preprocessor);
  42656. const map = preProcessedSource ? preProcessedSource.map : options.inMap || options.map;
  42657. const source = preProcessedSource ? preProcessedSource.code : options.source;
  42658. const shortId = id.replace(/^data-v-/, "");
  42659. const longId = `data-v-${shortId}`;
  42660. const plugins = (postcssPlugins || []).slice();
  42661. plugins.unshift(cssVarsPlugin({ id: shortId, isProd }));
  42662. if (trim) {
  42663. plugins.push(trimPlugin$1());
  42664. }
  42665. if (scoped) {
  42666. plugins.push(scopedPlugin$1(longId));
  42667. }
  42668. let cssModules;
  42669. if (modules) {
  42670. {
  42671. throw new Error(
  42672. "[@vue/compiler-sfc] `modules` option is not supported in the browser build."
  42673. );
  42674. }
  42675. }
  42676. const postCSSOptions = __spreadProps$4(__spreadValues$4({}, postcssOptions), {
  42677. to: filename,
  42678. from: filename
  42679. });
  42680. if (map) {
  42681. postCSSOptions.map = {
  42682. inline: false,
  42683. annotation: false,
  42684. prev: map
  42685. };
  42686. }
  42687. let result;
  42688. let code;
  42689. let outMap;
  42690. const dependencies = new Set(
  42691. preProcessedSource ? preProcessedSource.dependencies : []
  42692. );
  42693. dependencies.delete(filename);
  42694. const errors = [];
  42695. if (preProcessedSource && preProcessedSource.errors.length) {
  42696. errors.push(...preProcessedSource.errors);
  42697. }
  42698. const recordPlainCssDependencies = (messages) => {
  42699. messages.forEach((msg) => {
  42700. if (msg.type === "dependency") {
  42701. dependencies.add(msg.file);
  42702. }
  42703. });
  42704. return dependencies;
  42705. };
  42706. try {
  42707. result = postcss$1(plugins).process(source, postCSSOptions);
  42708. if (options.isAsync) {
  42709. return result.then((result2) => ({
  42710. code: result2.css || "",
  42711. map: result2.map && result2.map.toJSON(),
  42712. errors,
  42713. modules: cssModules,
  42714. rawResult: result2,
  42715. dependencies: recordPlainCssDependencies(result2.messages)
  42716. })).catch((error) => ({
  42717. code: "",
  42718. map: void 0,
  42719. errors: [...errors, error],
  42720. rawResult: void 0,
  42721. dependencies
  42722. }));
  42723. }
  42724. recordPlainCssDependencies(result.messages);
  42725. code = result.css;
  42726. outMap = result.map;
  42727. } catch (e) {
  42728. errors.push(e);
  42729. }
  42730. return {
  42731. code: code || ``,
  42732. map: outMap && outMap.toJSON(),
  42733. errors,
  42734. rawResult: result,
  42735. dependencies
  42736. };
  42737. }
  42738. function preprocess(options, preprocessor) {
  42739. if (!options.preprocessCustomRequire) {
  42740. throw new Error(
  42741. `[@vue/compiler-sfc] Style preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor.`
  42742. );
  42743. }
  42744. return preprocessor(
  42745. options.source,
  42746. options.inMap || options.map,
  42747. __spreadValues$4({
  42748. filename: options.filename
  42749. }, options.preprocessOptions),
  42750. options.preprocessCustomRequire
  42751. );
  42752. }
  42753. const comma = ','.charCodeAt(0);
  42754. const semicolon = ';'.charCodeAt(0);
  42755. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  42756. const intToChar = new Uint8Array(64); // 64 possible chars.
  42757. const charToInt = new Uint8Array(128); // z is 122 in ASCII
  42758. for (let i = 0; i < chars.length; i++) {
  42759. const c = chars.charCodeAt(i);
  42760. intToChar[i] = c;
  42761. charToInt[c] = i;
  42762. }
  42763. // Provide a fallback for older environments.
  42764. const td = typeof TextDecoder !== 'undefined'
  42765. ? /* #__PURE__ */ new TextDecoder()
  42766. : typeof Buffer !== 'undefined'
  42767. ? {
  42768. decode(buf) {
  42769. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  42770. return out.toString();
  42771. },
  42772. }
  42773. : {
  42774. decode(buf) {
  42775. let out = '';
  42776. for (let i = 0; i < buf.length; i++) {
  42777. out += String.fromCharCode(buf[i]);
  42778. }
  42779. return out;
  42780. },
  42781. };
  42782. function encode(decoded) {
  42783. const state = new Int32Array(5);
  42784. const bufLength = 1024 * 16;
  42785. const subLength = bufLength - 36;
  42786. const buf = new Uint8Array(bufLength);
  42787. const sub = buf.subarray(0, subLength);
  42788. let pos = 0;
  42789. let out = '';
  42790. for (let i = 0; i < decoded.length; i++) {
  42791. const line = decoded[i];
  42792. if (i > 0) {
  42793. if (pos === bufLength) {
  42794. out += td.decode(buf);
  42795. pos = 0;
  42796. }
  42797. buf[pos++] = semicolon;
  42798. }
  42799. if (line.length === 0)
  42800. continue;
  42801. state[0] = 0;
  42802. for (let j = 0; j < line.length; j++) {
  42803. const segment = line[j];
  42804. // We can push up to 5 ints, each int can take at most 7 chars, and we
  42805. // may push a comma.
  42806. if (pos > subLength) {
  42807. out += td.decode(sub);
  42808. buf.copyWithin(0, subLength, pos);
  42809. pos -= subLength;
  42810. }
  42811. if (j > 0)
  42812. buf[pos++] = comma;
  42813. pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
  42814. if (segment.length === 1)
  42815. continue;
  42816. pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
  42817. pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
  42818. pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
  42819. if (segment.length === 4)
  42820. continue;
  42821. pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
  42822. }
  42823. }
  42824. return out + td.decode(buf.subarray(0, pos));
  42825. }
  42826. function encodeInteger(buf, pos, state, segment, j) {
  42827. const next = segment[j];
  42828. let num = next - state[j];
  42829. state[j] = next;
  42830. num = num < 0 ? (-num << 1) | 1 : num << 1;
  42831. do {
  42832. let clamped = num & 0b011111;
  42833. num >>>= 5;
  42834. if (num > 0)
  42835. clamped |= 0b100000;
  42836. buf[pos++] = intToChar[clamped];
  42837. } while (num > 0);
  42838. return pos;
  42839. }
  42840. class BitSet {
  42841. constructor(arg) {
  42842. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  42843. }
  42844. add(n) {
  42845. this.bits[n >> 5] |= 1 << (n & 31);
  42846. }
  42847. has(n) {
  42848. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  42849. }
  42850. }
  42851. class Chunk {
  42852. constructor(start, end, content) {
  42853. this.start = start;
  42854. this.end = end;
  42855. this.original = content;
  42856. this.intro = '';
  42857. this.outro = '';
  42858. this.content = content;
  42859. this.storeName = false;
  42860. this.edited = false;
  42861. {
  42862. this.previous = null;
  42863. this.next = null;
  42864. }
  42865. }
  42866. appendLeft(content) {
  42867. this.outro += content;
  42868. }
  42869. appendRight(content) {
  42870. this.intro = this.intro + content;
  42871. }
  42872. clone() {
  42873. const chunk = new Chunk(this.start, this.end, this.original);
  42874. chunk.intro = this.intro;
  42875. chunk.outro = this.outro;
  42876. chunk.content = this.content;
  42877. chunk.storeName = this.storeName;
  42878. chunk.edited = this.edited;
  42879. return chunk;
  42880. }
  42881. contains(index) {
  42882. return this.start < index && index < this.end;
  42883. }
  42884. eachNext(fn) {
  42885. let chunk = this;
  42886. while (chunk) {
  42887. fn(chunk);
  42888. chunk = chunk.next;
  42889. }
  42890. }
  42891. eachPrevious(fn) {
  42892. let chunk = this;
  42893. while (chunk) {
  42894. fn(chunk);
  42895. chunk = chunk.previous;
  42896. }
  42897. }
  42898. edit(content, storeName, contentOnly) {
  42899. this.content = content;
  42900. if (!contentOnly) {
  42901. this.intro = '';
  42902. this.outro = '';
  42903. }
  42904. this.storeName = storeName;
  42905. this.edited = true;
  42906. return this;
  42907. }
  42908. prependLeft(content) {
  42909. this.outro = content + this.outro;
  42910. }
  42911. prependRight(content) {
  42912. this.intro = content + this.intro;
  42913. }
  42914. split(index) {
  42915. const sliceIndex = index - this.start;
  42916. const originalBefore = this.original.slice(0, sliceIndex);
  42917. const originalAfter = this.original.slice(sliceIndex);
  42918. this.original = originalBefore;
  42919. const newChunk = new Chunk(index, this.end, originalAfter);
  42920. newChunk.outro = this.outro;
  42921. this.outro = '';
  42922. this.end = index;
  42923. if (this.edited) {
  42924. // after split we should save the edit content record into the correct chunk
  42925. // to make sure sourcemap correct
  42926. // For example:
  42927. // ' test'.trim()
  42928. // split -> ' ' + 'test'
  42929. // ✔️ edit -> '' + 'test'
  42930. // ✖️ edit -> 'test' + ''
  42931. // TODO is this block necessary?...
  42932. newChunk.edit('', false);
  42933. this.content = '';
  42934. } else {
  42935. this.content = originalBefore;
  42936. }
  42937. newChunk.next = this.next;
  42938. if (newChunk.next) newChunk.next.previous = newChunk;
  42939. newChunk.previous = this;
  42940. this.next = newChunk;
  42941. return newChunk;
  42942. }
  42943. toString() {
  42944. return this.intro + this.content + this.outro;
  42945. }
  42946. trimEnd(rx) {
  42947. this.outro = this.outro.replace(rx, '');
  42948. if (this.outro.length) return true;
  42949. const trimmed = this.content.replace(rx, '');
  42950. if (trimmed.length) {
  42951. if (trimmed !== this.content) {
  42952. this.split(this.start + trimmed.length).edit('', undefined, true);
  42953. if (this.edited) {
  42954. // save the change, if it has been edited
  42955. this.edit(trimmed, this.storeName, true);
  42956. }
  42957. }
  42958. return true;
  42959. } else {
  42960. this.edit('', undefined, true);
  42961. this.intro = this.intro.replace(rx, '');
  42962. if (this.intro.length) return true;
  42963. }
  42964. }
  42965. trimStart(rx) {
  42966. this.intro = this.intro.replace(rx, '');
  42967. if (this.intro.length) return true;
  42968. const trimmed = this.content.replace(rx, '');
  42969. if (trimmed.length) {
  42970. if (trimmed !== this.content) {
  42971. const newChunk = this.split(this.end - trimmed.length);
  42972. if (this.edited) {
  42973. // save the change, if it has been edited
  42974. newChunk.edit(trimmed, this.storeName, true);
  42975. }
  42976. this.edit('', undefined, true);
  42977. }
  42978. return true;
  42979. } else {
  42980. this.edit('', undefined, true);
  42981. this.outro = this.outro.replace(rx, '');
  42982. if (this.outro.length) return true;
  42983. }
  42984. }
  42985. }
  42986. function getBtoa() {
  42987. if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
  42988. return (str) => window.btoa(unescape(encodeURIComponent(str)));
  42989. } else if (typeof Buffer === 'function') {
  42990. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  42991. } else {
  42992. return () => {
  42993. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  42994. };
  42995. }
  42996. }
  42997. const btoa = /*#__PURE__*/ getBtoa();
  42998. class SourceMap {
  42999. constructor(properties) {
  43000. this.version = 3;
  43001. this.file = properties.file;
  43002. this.sources = properties.sources;
  43003. this.sourcesContent = properties.sourcesContent;
  43004. this.names = properties.names;
  43005. this.mappings = encode(properties.mappings);
  43006. if (typeof properties.x_google_ignoreList !== 'undefined') {
  43007. this.x_google_ignoreList = properties.x_google_ignoreList;
  43008. }
  43009. }
  43010. toString() {
  43011. return JSON.stringify(this);
  43012. }
  43013. toUrl() {
  43014. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  43015. }
  43016. }
  43017. function guessIndent(code) {
  43018. const lines = code.split('\n');
  43019. const tabbed = lines.filter((line) => /^\t+/.test(line));
  43020. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  43021. if (tabbed.length === 0 && spaced.length === 0) {
  43022. return null;
  43023. }
  43024. // More lines tabbed than spaced? Assume tabs, and
  43025. // default to tabs in the case of a tie (or nothing
  43026. // to go on)
  43027. if (tabbed.length >= spaced.length) {
  43028. return '\t';
  43029. }
  43030. // Otherwise, we need to guess the multiple
  43031. const min = spaced.reduce((previous, current) => {
  43032. const numSpaces = /^ +/.exec(current)[0].length;
  43033. return Math.min(numSpaces, previous);
  43034. }, Infinity);
  43035. return new Array(min + 1).join(' ');
  43036. }
  43037. function getRelativePath(from, to) {
  43038. const fromParts = from.split(/[/\\]/);
  43039. const toParts = to.split(/[/\\]/);
  43040. fromParts.pop(); // get dirname
  43041. while (fromParts[0] === toParts[0]) {
  43042. fromParts.shift();
  43043. toParts.shift();
  43044. }
  43045. if (fromParts.length) {
  43046. let i = fromParts.length;
  43047. while (i--) fromParts[i] = '..';
  43048. }
  43049. return fromParts.concat(toParts).join('/');
  43050. }
  43051. const toString = Object.prototype.toString;
  43052. function isObject(thing) {
  43053. return toString.call(thing) === '[object Object]';
  43054. }
  43055. function getLocator(source) {
  43056. const originalLines = source.split('\n');
  43057. const lineOffsets = [];
  43058. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  43059. lineOffsets.push(pos);
  43060. pos += originalLines[i].length + 1;
  43061. }
  43062. return function locate(index) {
  43063. let i = 0;
  43064. let j = lineOffsets.length;
  43065. while (i < j) {
  43066. const m = (i + j) >> 1;
  43067. if (index < lineOffsets[m]) {
  43068. j = m;
  43069. } else {
  43070. i = m + 1;
  43071. }
  43072. }
  43073. const line = i - 1;
  43074. const column = index - lineOffsets[line];
  43075. return { line, column };
  43076. };
  43077. }
  43078. const wordRegex = /\w/;
  43079. class Mappings {
  43080. constructor(hires) {
  43081. this.hires = hires;
  43082. this.generatedCodeLine = 0;
  43083. this.generatedCodeColumn = 0;
  43084. this.raw = [];
  43085. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  43086. this.pending = null;
  43087. }
  43088. addEdit(sourceIndex, content, loc, nameIndex) {
  43089. if (content.length) {
  43090. let contentLineEnd = content.indexOf('\n', 0);
  43091. let previousContentLineEnd = -1;
  43092. while (contentLineEnd >= 0) {
  43093. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43094. if (nameIndex >= 0) {
  43095. segment.push(nameIndex);
  43096. }
  43097. this.rawSegments.push(segment);
  43098. this.generatedCodeLine += 1;
  43099. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43100. this.generatedCodeColumn = 0;
  43101. previousContentLineEnd = contentLineEnd;
  43102. contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
  43103. }
  43104. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43105. if (nameIndex >= 0) {
  43106. segment.push(nameIndex);
  43107. }
  43108. this.rawSegments.push(segment);
  43109. this.advance(content.slice(previousContentLineEnd + 1));
  43110. } else if (this.pending) {
  43111. this.rawSegments.push(this.pending);
  43112. this.advance(content);
  43113. }
  43114. this.pending = null;
  43115. }
  43116. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  43117. let originalCharIndex = chunk.start;
  43118. let first = true;
  43119. // when iterating each char, check if it's in a word boundary
  43120. let charInHiresBoundary = false;
  43121. while (originalCharIndex < chunk.end) {
  43122. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  43123. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43124. if (this.hires === 'boundary') {
  43125. // in hires "boundary", group segments per word boundary than per char
  43126. if (wordRegex.test(original[originalCharIndex])) {
  43127. // for first char in the boundary found, start the boundary by pushing a segment
  43128. if (!charInHiresBoundary) {
  43129. this.rawSegments.push(segment);
  43130. charInHiresBoundary = true;
  43131. }
  43132. } else {
  43133. // for non-word char, end the boundary by pushing a segment
  43134. this.rawSegments.push(segment);
  43135. charInHiresBoundary = false;
  43136. }
  43137. } else {
  43138. this.rawSegments.push(segment);
  43139. }
  43140. }
  43141. if (original[originalCharIndex] === '\n') {
  43142. loc.line += 1;
  43143. loc.column = 0;
  43144. this.generatedCodeLine += 1;
  43145. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43146. this.generatedCodeColumn = 0;
  43147. first = true;
  43148. } else {
  43149. loc.column += 1;
  43150. this.generatedCodeColumn += 1;
  43151. first = false;
  43152. }
  43153. originalCharIndex += 1;
  43154. }
  43155. this.pending = null;
  43156. }
  43157. advance(str) {
  43158. if (!str) return;
  43159. const lines = str.split('\n');
  43160. if (lines.length > 1) {
  43161. for (let i = 0; i < lines.length - 1; i++) {
  43162. this.generatedCodeLine++;
  43163. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43164. }
  43165. this.generatedCodeColumn = 0;
  43166. }
  43167. this.generatedCodeColumn += lines[lines.length - 1].length;
  43168. }
  43169. }
  43170. const n = '\n';
  43171. const warned = {
  43172. insertLeft: false,
  43173. insertRight: false,
  43174. storeName: false,
  43175. };
  43176. class MagicString {
  43177. constructor(string, options = {}) {
  43178. const chunk = new Chunk(0, string.length, string);
  43179. Object.defineProperties(this, {
  43180. original: { writable: true, value: string },
  43181. outro: { writable: true, value: '' },
  43182. intro: { writable: true, value: '' },
  43183. firstChunk: { writable: true, value: chunk },
  43184. lastChunk: { writable: true, value: chunk },
  43185. lastSearchedChunk: { writable: true, value: chunk },
  43186. byStart: { writable: true, value: {} },
  43187. byEnd: { writable: true, value: {} },
  43188. filename: { writable: true, value: options.filename },
  43189. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  43190. sourcemapLocations: { writable: true, value: new BitSet() },
  43191. storedNames: { writable: true, value: {} },
  43192. indentStr: { writable: true, value: undefined },
  43193. ignoreList: { writable: true, value: options.ignoreList },
  43194. });
  43195. this.byStart[0] = chunk;
  43196. this.byEnd[string.length] = chunk;
  43197. }
  43198. addSourcemapLocation(char) {
  43199. this.sourcemapLocations.add(char);
  43200. }
  43201. append(content) {
  43202. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  43203. this.outro += content;
  43204. return this;
  43205. }
  43206. appendLeft(index, content) {
  43207. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43208. this._split(index);
  43209. const chunk = this.byEnd[index];
  43210. if (chunk) {
  43211. chunk.appendLeft(content);
  43212. } else {
  43213. this.intro += content;
  43214. }
  43215. return this;
  43216. }
  43217. appendRight(index, content) {
  43218. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43219. this._split(index);
  43220. const chunk = this.byStart[index];
  43221. if (chunk) {
  43222. chunk.appendRight(content);
  43223. } else {
  43224. this.outro += content;
  43225. }
  43226. return this;
  43227. }
  43228. clone() {
  43229. const cloned = new MagicString(this.original, { filename: this.filename });
  43230. let originalChunk = this.firstChunk;
  43231. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  43232. while (originalChunk) {
  43233. cloned.byStart[clonedChunk.start] = clonedChunk;
  43234. cloned.byEnd[clonedChunk.end] = clonedChunk;
  43235. const nextOriginalChunk = originalChunk.next;
  43236. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  43237. if (nextClonedChunk) {
  43238. clonedChunk.next = nextClonedChunk;
  43239. nextClonedChunk.previous = clonedChunk;
  43240. clonedChunk = nextClonedChunk;
  43241. }
  43242. originalChunk = nextOriginalChunk;
  43243. }
  43244. cloned.lastChunk = clonedChunk;
  43245. if (this.indentExclusionRanges) {
  43246. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  43247. }
  43248. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  43249. cloned.intro = this.intro;
  43250. cloned.outro = this.outro;
  43251. return cloned;
  43252. }
  43253. generateDecodedMap(options) {
  43254. options = options || {};
  43255. const sourceIndex = 0;
  43256. const names = Object.keys(this.storedNames);
  43257. const mappings = new Mappings(options.hires);
  43258. const locate = getLocator(this.original);
  43259. if (this.intro) {
  43260. mappings.advance(this.intro);
  43261. }
  43262. this.firstChunk.eachNext((chunk) => {
  43263. const loc = locate(chunk.start);
  43264. if (chunk.intro.length) mappings.advance(chunk.intro);
  43265. if (chunk.edited) {
  43266. mappings.addEdit(
  43267. sourceIndex,
  43268. chunk.content,
  43269. loc,
  43270. chunk.storeName ? names.indexOf(chunk.original) : -1,
  43271. );
  43272. } else {
  43273. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  43274. }
  43275. if (chunk.outro.length) mappings.advance(chunk.outro);
  43276. });
  43277. return {
  43278. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  43279. sources: [
  43280. options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
  43281. ],
  43282. sourcesContent: options.includeContent ? [this.original] : undefined,
  43283. names,
  43284. mappings: mappings.raw,
  43285. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
  43286. };
  43287. }
  43288. generateMap(options) {
  43289. return new SourceMap(this.generateDecodedMap(options));
  43290. }
  43291. _ensureindentStr() {
  43292. if (this.indentStr === undefined) {
  43293. this.indentStr = guessIndent(this.original);
  43294. }
  43295. }
  43296. _getRawIndentString() {
  43297. this._ensureindentStr();
  43298. return this.indentStr;
  43299. }
  43300. getIndentString() {
  43301. this._ensureindentStr();
  43302. return this.indentStr === null ? '\t' : this.indentStr;
  43303. }
  43304. indent(indentStr, options) {
  43305. const pattern = /^[^\r\n]/gm;
  43306. if (isObject(indentStr)) {
  43307. options = indentStr;
  43308. indentStr = undefined;
  43309. }
  43310. if (indentStr === undefined) {
  43311. this._ensureindentStr();
  43312. indentStr = this.indentStr || '\t';
  43313. }
  43314. if (indentStr === '') return this; // noop
  43315. options = options || {};
  43316. // Process exclusion ranges
  43317. const isExcluded = {};
  43318. if (options.exclude) {
  43319. const exclusions =
  43320. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  43321. exclusions.forEach((exclusion) => {
  43322. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  43323. isExcluded[i] = true;
  43324. }
  43325. });
  43326. }
  43327. let shouldIndentNextCharacter = options.indentStart !== false;
  43328. const replacer = (match) => {
  43329. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  43330. shouldIndentNextCharacter = true;
  43331. return match;
  43332. };
  43333. this.intro = this.intro.replace(pattern, replacer);
  43334. let charIndex = 0;
  43335. let chunk = this.firstChunk;
  43336. while (chunk) {
  43337. const end = chunk.end;
  43338. if (chunk.edited) {
  43339. if (!isExcluded[charIndex]) {
  43340. chunk.content = chunk.content.replace(pattern, replacer);
  43341. if (chunk.content.length) {
  43342. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  43343. }
  43344. }
  43345. } else {
  43346. charIndex = chunk.start;
  43347. while (charIndex < end) {
  43348. if (!isExcluded[charIndex]) {
  43349. const char = this.original[charIndex];
  43350. if (char === '\n') {
  43351. shouldIndentNextCharacter = true;
  43352. } else if (char !== '\r' && shouldIndentNextCharacter) {
  43353. shouldIndentNextCharacter = false;
  43354. if (charIndex === chunk.start) {
  43355. chunk.prependRight(indentStr);
  43356. } else {
  43357. this._splitChunk(chunk, charIndex);
  43358. chunk = chunk.next;
  43359. chunk.prependRight(indentStr);
  43360. }
  43361. }
  43362. }
  43363. charIndex += 1;
  43364. }
  43365. }
  43366. charIndex = chunk.end;
  43367. chunk = chunk.next;
  43368. }
  43369. this.outro = this.outro.replace(pattern, replacer);
  43370. return this;
  43371. }
  43372. insert() {
  43373. throw new Error(
  43374. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
  43375. );
  43376. }
  43377. insertLeft(index, content) {
  43378. if (!warned.insertLeft) {
  43379. console.warn(
  43380. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
  43381. ); // eslint-disable-line no-console
  43382. warned.insertLeft = true;
  43383. }
  43384. return this.appendLeft(index, content);
  43385. }
  43386. insertRight(index, content) {
  43387. if (!warned.insertRight) {
  43388. console.warn(
  43389. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
  43390. ); // eslint-disable-line no-console
  43391. warned.insertRight = true;
  43392. }
  43393. return this.prependRight(index, content);
  43394. }
  43395. move(start, end, index) {
  43396. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  43397. this._split(start);
  43398. this._split(end);
  43399. this._split(index);
  43400. const first = this.byStart[start];
  43401. const last = this.byEnd[end];
  43402. const oldLeft = first.previous;
  43403. const oldRight = last.next;
  43404. const newRight = this.byStart[index];
  43405. if (!newRight && last === this.lastChunk) return this;
  43406. const newLeft = newRight ? newRight.previous : this.lastChunk;
  43407. if (oldLeft) oldLeft.next = oldRight;
  43408. if (oldRight) oldRight.previous = oldLeft;
  43409. if (newLeft) newLeft.next = first;
  43410. if (newRight) newRight.previous = last;
  43411. if (!first.previous) this.firstChunk = last.next;
  43412. if (!last.next) {
  43413. this.lastChunk = first.previous;
  43414. this.lastChunk.next = null;
  43415. }
  43416. first.previous = newLeft;
  43417. last.next = newRight || null;
  43418. if (!newLeft) this.firstChunk = first;
  43419. if (!newRight) this.lastChunk = last;
  43420. return this;
  43421. }
  43422. overwrite(start, end, content, options) {
  43423. options = options || {};
  43424. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  43425. }
  43426. update(start, end, content, options) {
  43427. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  43428. while (start < 0) start += this.original.length;
  43429. while (end < 0) end += this.original.length;
  43430. if (end > this.original.length) throw new Error('end is out of bounds');
  43431. if (start === end)
  43432. throw new Error(
  43433. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
  43434. );
  43435. this._split(start);
  43436. this._split(end);
  43437. if (options === true) {
  43438. if (!warned.storeName) {
  43439. console.warn(
  43440. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
  43441. ); // eslint-disable-line no-console
  43442. warned.storeName = true;
  43443. }
  43444. options = { storeName: true };
  43445. }
  43446. const storeName = options !== undefined ? options.storeName : false;
  43447. const overwrite = options !== undefined ? options.overwrite : false;
  43448. if (storeName) {
  43449. const original = this.original.slice(start, end);
  43450. Object.defineProperty(this.storedNames, original, {
  43451. writable: true,
  43452. value: true,
  43453. enumerable: true,
  43454. });
  43455. }
  43456. const first = this.byStart[start];
  43457. const last = this.byEnd[end];
  43458. if (first) {
  43459. let chunk = first;
  43460. while (chunk !== last) {
  43461. if (chunk.next !== this.byStart[chunk.end]) {
  43462. throw new Error('Cannot overwrite across a split point');
  43463. }
  43464. chunk = chunk.next;
  43465. chunk.edit('', false);
  43466. }
  43467. first.edit(content, storeName, !overwrite);
  43468. } else {
  43469. // must be inserting at the end
  43470. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  43471. // TODO last chunk in the array may not be the last chunk, if it's moved...
  43472. last.next = newChunk;
  43473. newChunk.previous = last;
  43474. }
  43475. return this;
  43476. }
  43477. prepend(content) {
  43478. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  43479. this.intro = content + this.intro;
  43480. return this;
  43481. }
  43482. prependLeft(index, content) {
  43483. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43484. this._split(index);
  43485. const chunk = this.byEnd[index];
  43486. if (chunk) {
  43487. chunk.prependLeft(content);
  43488. } else {
  43489. this.intro = content + this.intro;
  43490. }
  43491. return this;
  43492. }
  43493. prependRight(index, content) {
  43494. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43495. this._split(index);
  43496. const chunk = this.byStart[index];
  43497. if (chunk) {
  43498. chunk.prependRight(content);
  43499. } else {
  43500. this.outro = content + this.outro;
  43501. }
  43502. return this;
  43503. }
  43504. remove(start, end) {
  43505. while (start < 0) start += this.original.length;
  43506. while (end < 0) end += this.original.length;
  43507. if (start === end) return this;
  43508. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  43509. if (start > end) throw new Error('end must be greater than start');
  43510. this._split(start);
  43511. this._split(end);
  43512. let chunk = this.byStart[start];
  43513. while (chunk) {
  43514. chunk.intro = '';
  43515. chunk.outro = '';
  43516. chunk.edit('');
  43517. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  43518. }
  43519. return this;
  43520. }
  43521. lastChar() {
  43522. if (this.outro.length) return this.outro[this.outro.length - 1];
  43523. let chunk = this.lastChunk;
  43524. do {
  43525. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  43526. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  43527. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  43528. } while ((chunk = chunk.previous));
  43529. if (this.intro.length) return this.intro[this.intro.length - 1];
  43530. return '';
  43531. }
  43532. lastLine() {
  43533. let lineIndex = this.outro.lastIndexOf(n);
  43534. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  43535. let lineStr = this.outro;
  43536. let chunk = this.lastChunk;
  43537. do {
  43538. if (chunk.outro.length > 0) {
  43539. lineIndex = chunk.outro.lastIndexOf(n);
  43540. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  43541. lineStr = chunk.outro + lineStr;
  43542. }
  43543. if (chunk.content.length > 0) {
  43544. lineIndex = chunk.content.lastIndexOf(n);
  43545. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  43546. lineStr = chunk.content + lineStr;
  43547. }
  43548. if (chunk.intro.length > 0) {
  43549. lineIndex = chunk.intro.lastIndexOf(n);
  43550. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  43551. lineStr = chunk.intro + lineStr;
  43552. }
  43553. } while ((chunk = chunk.previous));
  43554. lineIndex = this.intro.lastIndexOf(n);
  43555. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  43556. return this.intro + lineStr;
  43557. }
  43558. slice(start = 0, end = this.original.length) {
  43559. while (start < 0) start += this.original.length;
  43560. while (end < 0) end += this.original.length;
  43561. let result = '';
  43562. // find start chunk
  43563. let chunk = this.firstChunk;
  43564. while (chunk && (chunk.start > start || chunk.end <= start)) {
  43565. // found end chunk before start
  43566. if (chunk.start < end && chunk.end >= end) {
  43567. return result;
  43568. }
  43569. chunk = chunk.next;
  43570. }
  43571. if (chunk && chunk.edited && chunk.start !== start)
  43572. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  43573. const startChunk = chunk;
  43574. while (chunk) {
  43575. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  43576. result += chunk.intro;
  43577. }
  43578. const containsEnd = chunk.start < end && chunk.end >= end;
  43579. if (containsEnd && chunk.edited && chunk.end !== end)
  43580. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  43581. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  43582. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  43583. result += chunk.content.slice(sliceStart, sliceEnd);
  43584. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  43585. result += chunk.outro;
  43586. }
  43587. if (containsEnd) {
  43588. break;
  43589. }
  43590. chunk = chunk.next;
  43591. }
  43592. return result;
  43593. }
  43594. // TODO deprecate this? not really very useful
  43595. snip(start, end) {
  43596. const clone = this.clone();
  43597. clone.remove(0, start);
  43598. clone.remove(end, clone.original.length);
  43599. return clone;
  43600. }
  43601. _split(index) {
  43602. if (this.byStart[index] || this.byEnd[index]) return;
  43603. let chunk = this.lastSearchedChunk;
  43604. const searchForward = index > chunk.end;
  43605. while (chunk) {
  43606. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  43607. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  43608. }
  43609. }
  43610. _splitChunk(chunk, index) {
  43611. if (chunk.edited && chunk.content.length) {
  43612. // zero-length edited chunks are a special case (overlapping replacements)
  43613. const loc = getLocator(this.original)(index);
  43614. throw new Error(
  43615. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
  43616. );
  43617. }
  43618. const newChunk = chunk.split(index);
  43619. this.byEnd[index] = chunk;
  43620. this.byStart[index] = newChunk;
  43621. this.byEnd[newChunk.end] = newChunk;
  43622. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  43623. this.lastSearchedChunk = chunk;
  43624. return true;
  43625. }
  43626. toString() {
  43627. let str = this.intro;
  43628. let chunk = this.firstChunk;
  43629. while (chunk) {
  43630. str += chunk.toString();
  43631. chunk = chunk.next;
  43632. }
  43633. return str + this.outro;
  43634. }
  43635. isEmpty() {
  43636. let chunk = this.firstChunk;
  43637. do {
  43638. if (
  43639. (chunk.intro.length && chunk.intro.trim()) ||
  43640. (chunk.content.length && chunk.content.trim()) ||
  43641. (chunk.outro.length && chunk.outro.trim())
  43642. )
  43643. return false;
  43644. } while ((chunk = chunk.next));
  43645. return true;
  43646. }
  43647. length() {
  43648. let chunk = this.firstChunk;
  43649. let length = 0;
  43650. do {
  43651. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  43652. } while ((chunk = chunk.next));
  43653. return length;
  43654. }
  43655. trimLines() {
  43656. return this.trim('[\\r\\n]');
  43657. }
  43658. trim(charType) {
  43659. return this.trimStart(charType).trimEnd(charType);
  43660. }
  43661. trimEndAborted(charType) {
  43662. const rx = new RegExp((charType || '\\s') + '+$');
  43663. this.outro = this.outro.replace(rx, '');
  43664. if (this.outro.length) return true;
  43665. let chunk = this.lastChunk;
  43666. do {
  43667. const end = chunk.end;
  43668. const aborted = chunk.trimEnd(rx);
  43669. // if chunk was trimmed, we have a new lastChunk
  43670. if (chunk.end !== end) {
  43671. if (this.lastChunk === chunk) {
  43672. this.lastChunk = chunk.next;
  43673. }
  43674. this.byEnd[chunk.end] = chunk;
  43675. this.byStart[chunk.next.start] = chunk.next;
  43676. this.byEnd[chunk.next.end] = chunk.next;
  43677. }
  43678. if (aborted) return true;
  43679. chunk = chunk.previous;
  43680. } while (chunk);
  43681. return false;
  43682. }
  43683. trimEnd(charType) {
  43684. this.trimEndAborted(charType);
  43685. return this;
  43686. }
  43687. trimStartAborted(charType) {
  43688. const rx = new RegExp('^' + (charType || '\\s') + '+');
  43689. this.intro = this.intro.replace(rx, '');
  43690. if (this.intro.length) return true;
  43691. let chunk = this.firstChunk;
  43692. do {
  43693. const end = chunk.end;
  43694. const aborted = chunk.trimStart(rx);
  43695. if (chunk.end !== end) {
  43696. // special case...
  43697. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  43698. this.byEnd[chunk.end] = chunk;
  43699. this.byStart[chunk.next.start] = chunk.next;
  43700. this.byEnd[chunk.next.end] = chunk.next;
  43701. }
  43702. if (aborted) return true;
  43703. chunk = chunk.next;
  43704. } while (chunk);
  43705. return false;
  43706. }
  43707. trimStart(charType) {
  43708. this.trimStartAborted(charType);
  43709. return this;
  43710. }
  43711. hasChanged() {
  43712. return this.original !== this.toString();
  43713. }
  43714. _replaceRegexp(searchValue, replacement) {
  43715. function getReplacement(match, str) {
  43716. if (typeof replacement === 'string') {
  43717. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  43718. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  43719. if (i === '$') return '$';
  43720. if (i === '&') return match[0];
  43721. const num = +i;
  43722. if (num < match.length) return match[+i];
  43723. return `$${i}`;
  43724. });
  43725. } else {
  43726. return replacement(...match, match.index, str, match.groups);
  43727. }
  43728. }
  43729. function matchAll(re, str) {
  43730. let match;
  43731. const matches = [];
  43732. while ((match = re.exec(str))) {
  43733. matches.push(match);
  43734. }
  43735. return matches;
  43736. }
  43737. if (searchValue.global) {
  43738. const matches = matchAll(searchValue, this.original);
  43739. matches.forEach((match) => {
  43740. if (match.index != null)
  43741. this.overwrite(
  43742. match.index,
  43743. match.index + match[0].length,
  43744. getReplacement(match, this.original),
  43745. );
  43746. });
  43747. } else {
  43748. const match = this.original.match(searchValue);
  43749. if (match && match.index != null)
  43750. this.overwrite(
  43751. match.index,
  43752. match.index + match[0].length,
  43753. getReplacement(match, this.original),
  43754. );
  43755. }
  43756. return this;
  43757. }
  43758. _replaceString(string, replacement) {
  43759. const { original } = this;
  43760. const index = original.indexOf(string);
  43761. if (index !== -1) {
  43762. this.overwrite(index, index + string.length, replacement);
  43763. }
  43764. return this;
  43765. }
  43766. replace(searchValue, replacement) {
  43767. if (typeof searchValue === 'string') {
  43768. return this._replaceString(searchValue, replacement);
  43769. }
  43770. return this._replaceRegexp(searchValue, replacement);
  43771. }
  43772. _replaceAllString(string, replacement) {
  43773. const { original } = this;
  43774. const stringLength = string.length;
  43775. for (
  43776. let index = original.indexOf(string);
  43777. index !== -1;
  43778. index = original.indexOf(string, index + stringLength)
  43779. ) {
  43780. this.overwrite(index, index + stringLength, replacement);
  43781. }
  43782. return this;
  43783. }
  43784. replaceAll(searchValue, replacement) {
  43785. if (typeof searchValue === 'string') {
  43786. return this._replaceAllString(searchValue, replacement);
  43787. }
  43788. if (!searchValue.global) {
  43789. throw new TypeError(
  43790. 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
  43791. );
  43792. }
  43793. return this._replaceRegexp(searchValue, replacement);
  43794. }
  43795. }
  43796. var __defProp$3 = Object.defineProperty;
  43797. var __defProps$3 = Object.defineProperties;
  43798. var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
  43799. var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
  43800. var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
  43801. var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
  43802. var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43803. var __spreadValues$3 = (a, b) => {
  43804. for (var prop in b || (b = {}))
  43805. if (__hasOwnProp$3.call(b, prop))
  43806. __defNormalProp$3(a, prop, b[prop]);
  43807. if (__getOwnPropSymbols$3)
  43808. for (var prop of __getOwnPropSymbols$3(b)) {
  43809. if (__propIsEnum$3.call(b, prop))
  43810. __defNormalProp$3(a, prop, b[prop]);
  43811. }
  43812. return a;
  43813. };
  43814. var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
  43815. const CONVERT_SYMBOL = "$";
  43816. const ESCAPE_SYMBOL = "$$";
  43817. const IMPORT_SOURCE = "vue/macros";
  43818. const shorthands = ["ref", "computed", "shallowRef", "toRef", "customRef"];
  43819. const transformCheckRE = /[^\w]\$(?:\$|ref|computed|shallowRef)?\s*(\(|\<)/;
  43820. function shouldTransform(src) {
  43821. return transformCheckRE.test(src);
  43822. }
  43823. function transform(src, {
  43824. filename,
  43825. sourceMap,
  43826. parserPlugins,
  43827. importHelpersFrom = "vue"
  43828. } = {}) {
  43829. const plugins = parserPlugins || [];
  43830. if (filename) {
  43831. if (/\.tsx?$/.test(filename)) {
  43832. plugins.push("typescript");
  43833. }
  43834. if (filename.endsWith("x")) {
  43835. plugins.push("jsx");
  43836. }
  43837. }
  43838. const ast = parse_1$1(src, {
  43839. sourceType: "module",
  43840. plugins
  43841. });
  43842. const s = new MagicString(src);
  43843. const res = transformAST(ast.program, s, 0);
  43844. if (res.importedHelpers.length) {
  43845. s.prepend(
  43846. `import { ${res.importedHelpers.map((h) => `${h} as _${h}`).join(", ")} } from '${importHelpersFrom}'
  43847. `
  43848. );
  43849. }
  43850. return __spreadProps$3(__spreadValues$3({}, res), {
  43851. code: s.toString(),
  43852. map: sourceMap ? s.generateMap({
  43853. source: filename,
  43854. hires: true,
  43855. includeContent: true
  43856. }) : null
  43857. });
  43858. }
  43859. function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
  43860. warnExperimental();
  43861. const userImports = /* @__PURE__ */ Object.create(null);
  43862. for (const node of ast.body) {
  43863. if (node.type !== "ImportDeclaration")
  43864. continue;
  43865. walkImportDeclaration(node);
  43866. }
  43867. let convertSymbol;
  43868. let escapeSymbol;
  43869. for (const { local, imported, source, specifier } of Object.values(
  43870. userImports
  43871. )) {
  43872. if (source === IMPORT_SOURCE) {
  43873. if (imported === ESCAPE_SYMBOL) {
  43874. escapeSymbol = local;
  43875. } else if (imported === CONVERT_SYMBOL) {
  43876. convertSymbol = local;
  43877. } else if (imported !== local) {
  43878. error(
  43879. `macro imports for ref-creating methods do not support aliasing.`,
  43880. specifier
  43881. );
  43882. }
  43883. }
  43884. }
  43885. if (!convertSymbol && !userImports[CONVERT_SYMBOL]) {
  43886. convertSymbol = CONVERT_SYMBOL;
  43887. }
  43888. if (!escapeSymbol && !userImports[ESCAPE_SYMBOL]) {
  43889. escapeSymbol = ESCAPE_SYMBOL;
  43890. }
  43891. const importedHelpers = /* @__PURE__ */ new Set();
  43892. const rootScope = {};
  43893. const scopeStack = [rootScope];
  43894. let currentScope = rootScope;
  43895. let escapeScope;
  43896. const excludedIds = /* @__PURE__ */ new WeakSet();
  43897. const parentStack = [];
  43898. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  43899. if (knownRefs) {
  43900. for (const key of knownRefs) {
  43901. rootScope[key] = {};
  43902. }
  43903. }
  43904. if (knownProps) {
  43905. for (const key in knownProps) {
  43906. const { local, isConst } = knownProps[key];
  43907. rootScope[local] = {
  43908. isProp: true,
  43909. isConst: !!isConst
  43910. };
  43911. propsLocalToPublicMap[local] = key;
  43912. }
  43913. }
  43914. function walkImportDeclaration(node) {
  43915. const source = node.source.value;
  43916. if (source === IMPORT_SOURCE) {
  43917. s.remove(node.start + offset, node.end + offset);
  43918. }
  43919. for (const specifier of node.specifiers) {
  43920. const local = specifier.local.name;
  43921. const imported = specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name || "default";
  43922. userImports[local] = {
  43923. source,
  43924. local,
  43925. imported,
  43926. specifier
  43927. };
  43928. }
  43929. }
  43930. function isRefCreationCall(callee) {
  43931. if (!convertSymbol || currentScope[convertSymbol] !== void 0) {
  43932. return false;
  43933. }
  43934. if (callee === convertSymbol) {
  43935. return convertSymbol;
  43936. }
  43937. if (callee[0] === "$" && shorthands.includes(callee.slice(1))) {
  43938. return callee;
  43939. }
  43940. return false;
  43941. }
  43942. function error(msg, node) {
  43943. const e = new Error(msg);
  43944. e.node = node;
  43945. throw e;
  43946. }
  43947. function helper(msg) {
  43948. importedHelpers.add(msg);
  43949. return `_${msg}`;
  43950. }
  43951. function registerBinding(id, binding) {
  43952. excludedIds.add(id);
  43953. if (currentScope) {
  43954. currentScope[id.name] = binding ? binding : false;
  43955. } else {
  43956. error(
  43957. "registerBinding called without active scope, something is wrong.",
  43958. id
  43959. );
  43960. }
  43961. }
  43962. const registerRefBinding = (id, isConst = false) => registerBinding(id, { isConst });
  43963. let tempVarCount = 0;
  43964. function genTempVar() {
  43965. return `__$temp_${++tempVarCount}`;
  43966. }
  43967. function snip(node) {
  43968. return s.original.slice(node.start + offset, node.end + offset);
  43969. }
  43970. function walkScope(node, isRoot = false) {
  43971. for (const stmt of node.body) {
  43972. if (stmt.type === "VariableDeclaration") {
  43973. walkVariableDeclaration(stmt, isRoot);
  43974. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  43975. if (stmt.declare || !stmt.id)
  43976. continue;
  43977. registerBinding(stmt.id);
  43978. } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
  43979. walkVariableDeclaration(stmt.left);
  43980. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  43981. walkVariableDeclaration(stmt.declaration, isRoot);
  43982. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  43983. walkVariableDeclaration(stmt.body, isRoot);
  43984. }
  43985. }
  43986. }
  43987. function walkVariableDeclaration(stmt, isRoot = false) {
  43988. if (stmt.declare) {
  43989. return;
  43990. }
  43991. for (const decl of stmt.declarations) {
  43992. let refCall;
  43993. const isCall = decl.init && decl.init.type === "CallExpression" && decl.init.callee.type === "Identifier";
  43994. if (isCall && (refCall = isRefCreationCall(decl.init.callee.name))) {
  43995. processRefDeclaration(
  43996. refCall,
  43997. decl.id,
  43998. decl.init,
  43999. stmt.kind === "const"
  44000. );
  44001. } else {
  44002. const isProps = isRoot && isCall && decl.init.callee.name === "defineProps";
  44003. for (const id of extractIdentifiers(decl.id)) {
  44004. if (isProps) {
  44005. excludedIds.add(id);
  44006. } else {
  44007. registerBinding(id);
  44008. }
  44009. }
  44010. }
  44011. }
  44012. }
  44013. function processRefDeclaration(method, id, call, isConst) {
  44014. excludedIds.add(call.callee);
  44015. if (method === convertSymbol) {
  44016. s.remove(call.callee.start + offset, call.callee.end + offset);
  44017. if (id.type === "Identifier") {
  44018. registerRefBinding(id, isConst);
  44019. } else if (id.type === "ObjectPattern") {
  44020. processRefObjectPattern(id, call, isConst);
  44021. } else if (id.type === "ArrayPattern") {
  44022. processRefArrayPattern(id, call, isConst);
  44023. }
  44024. } else {
  44025. if (id.type === "Identifier") {
  44026. registerRefBinding(id, isConst);
  44027. s.overwrite(
  44028. call.start + offset,
  44029. call.start + method.length + offset,
  44030. helper(method.slice(1))
  44031. );
  44032. } else {
  44033. error(`${method}() cannot be used with destructure patterns.`, call);
  44034. }
  44035. }
  44036. }
  44037. function processRefObjectPattern(pattern, call, isConst, tempVar, path = []) {
  44038. if (!tempVar) {
  44039. tempVar = genTempVar();
  44040. s.overwrite(pattern.start + offset, pattern.end + offset, tempVar);
  44041. }
  44042. let nameId;
  44043. for (const p of pattern.properties) {
  44044. let key;
  44045. let defaultValue;
  44046. if (p.type === "ObjectProperty") {
  44047. if (p.key.start === p.value.start) {
  44048. nameId = p.key;
  44049. if (p.value.type === "Identifier") {
  44050. excludedIds.add(p.value);
  44051. } else if (p.value.type === "AssignmentPattern" && p.value.left.type === "Identifier") {
  44052. excludedIds.add(p.value.left);
  44053. defaultValue = p.value.right;
  44054. }
  44055. } else {
  44056. key = p.computed ? p.key : p.key.name;
  44057. if (p.value.type === "Identifier") {
  44058. nameId = p.value;
  44059. } else if (p.value.type === "ObjectPattern") {
  44060. processRefObjectPattern(p.value, call, isConst, tempVar, [
  44061. ...path,
  44062. key
  44063. ]);
  44064. } else if (p.value.type === "ArrayPattern") {
  44065. processRefArrayPattern(p.value, call, isConst, tempVar, [
  44066. ...path,
  44067. key
  44068. ]);
  44069. } else if (p.value.type === "AssignmentPattern") {
  44070. if (p.value.left.type === "Identifier") {
  44071. nameId = p.value.left;
  44072. defaultValue = p.value.right;
  44073. } else if (p.value.left.type === "ObjectPattern") {
  44074. processRefObjectPattern(p.value.left, call, isConst, tempVar, [
  44075. ...path,
  44076. [key, p.value.right]
  44077. ]);
  44078. } else if (p.value.left.type === "ArrayPattern") {
  44079. processRefArrayPattern(p.value.left, call, isConst, tempVar, [
  44080. ...path,
  44081. [key, p.value.right]
  44082. ]);
  44083. } else ;
  44084. }
  44085. }
  44086. } else {
  44087. error(`reactivity destructure does not support rest elements.`, p);
  44088. }
  44089. if (nameId) {
  44090. registerRefBinding(nameId, isConst);
  44091. const source = pathToString(tempVar, path);
  44092. const keyStr = isString$2(key) ? `'${key}'` : key ? snip(key) : `'${nameId.name}'`;
  44093. const defaultStr = defaultValue ? `, ${snip(defaultValue)}` : ``;
  44094. s.appendLeft(
  44095. call.end + offset,
  44096. `,
  44097. ${nameId.name} = ${helper(
  44098. "toRef"
  44099. )}(${source}, ${keyStr}${defaultStr})`
  44100. );
  44101. }
  44102. }
  44103. if (nameId) {
  44104. s.appendLeft(call.end + offset, ";");
  44105. }
  44106. }
  44107. function processRefArrayPattern(pattern, call, isConst, tempVar, path = []) {
  44108. if (!tempVar) {
  44109. tempVar = genTempVar();
  44110. s.overwrite(pattern.start + offset, pattern.end + offset, tempVar);
  44111. }
  44112. let nameId;
  44113. for (let i = 0; i < pattern.elements.length; i++) {
  44114. const e = pattern.elements[i];
  44115. if (!e)
  44116. continue;
  44117. let defaultValue;
  44118. if (e.type === "Identifier") {
  44119. nameId = e;
  44120. } else if (e.type === "AssignmentPattern") {
  44121. nameId = e.left;
  44122. defaultValue = e.right;
  44123. } else if (e.type === "RestElement") {
  44124. error(`reactivity destructure does not support rest elements.`, e);
  44125. } else if (e.type === "ObjectPattern") {
  44126. processRefObjectPattern(e, call, isConst, tempVar, [...path, i]);
  44127. } else if (e.type === "ArrayPattern") {
  44128. processRefArrayPattern(e, call, isConst, tempVar, [...path, i]);
  44129. }
  44130. if (nameId) {
  44131. registerRefBinding(nameId, isConst);
  44132. const source = pathToString(tempVar, path);
  44133. const defaultStr = defaultValue ? `, ${snip(defaultValue)}` : ``;
  44134. s.appendLeft(
  44135. call.end + offset,
  44136. `,
  44137. ${nameId.name} = ${helper(
  44138. "toRef"
  44139. )}(${source}, ${i}${defaultStr})`
  44140. );
  44141. }
  44142. }
  44143. if (nameId) {
  44144. s.appendLeft(call.end + offset, ";");
  44145. }
  44146. }
  44147. function pathToString(source, path) {
  44148. if (path.length) {
  44149. for (const seg of path) {
  44150. if (isArray$3(seg)) {
  44151. source = `(${source}${segToString(seg[0])} || ${snip(seg[1])})`;
  44152. } else {
  44153. source += segToString(seg);
  44154. }
  44155. }
  44156. }
  44157. return source;
  44158. }
  44159. function segToString(seg) {
  44160. if (typeof seg === "number") {
  44161. return `[${seg}]`;
  44162. } else if (typeof seg === "string") {
  44163. return `.${seg}`;
  44164. } else {
  44165. return snip(seg);
  44166. }
  44167. }
  44168. function rewriteId(scope, id, parent, parentStack2) {
  44169. if (hasOwn(scope, id.name)) {
  44170. const binding = scope[id.name];
  44171. if (binding) {
  44172. if (binding.isConst && (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression")) {
  44173. error(`Assignment to constant variable.`, id);
  44174. }
  44175. const { isProp } = binding;
  44176. if (isStaticProperty(parent) && parent.shorthand) {
  44177. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  44178. if (isProp) {
  44179. if (escapeScope) {
  44180. registerEscapedPropBinding(id);
  44181. s.appendLeft(
  44182. id.end + offset,
  44183. `: __props_${propsLocalToPublicMap[id.name]}`
  44184. );
  44185. } else {
  44186. s.appendLeft(
  44187. id.end + offset,
  44188. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  44189. );
  44190. }
  44191. } else {
  44192. s.appendLeft(id.end + offset, `: ${id.name}.value`);
  44193. }
  44194. }
  44195. } else {
  44196. if (isProp) {
  44197. if (escapeScope) {
  44198. registerEscapedPropBinding(id);
  44199. s.overwrite(
  44200. id.start + offset,
  44201. id.end + offset,
  44202. `__props_${propsLocalToPublicMap[id.name]}`
  44203. );
  44204. } else {
  44205. s.overwrite(
  44206. id.start + offset,
  44207. id.end + offset,
  44208. genPropsAccessExp(propsLocalToPublicMap[id.name])
  44209. );
  44210. }
  44211. } else {
  44212. s.appendLeft(id.end + offset, ".value");
  44213. }
  44214. }
  44215. }
  44216. return true;
  44217. }
  44218. return false;
  44219. }
  44220. const propBindingRefs = {};
  44221. function registerEscapedPropBinding(id) {
  44222. if (!propBindingRefs.hasOwnProperty(id.name)) {
  44223. propBindingRefs[id.name] = true;
  44224. const publicKey = propsLocalToPublicMap[id.name];
  44225. s.prependRight(
  44226. offset,
  44227. `const __props_${publicKey} = ${helper(
  44228. `toRef`
  44229. )}(__props, '${publicKey}');
  44230. `
  44231. );
  44232. }
  44233. }
  44234. walkScope(ast, true);
  44235. walk$1(ast, {
  44236. enter(node, parent) {
  44237. parent && parentStack.push(parent);
  44238. if (isFunctionType(node)) {
  44239. scopeStack.push(currentScope = {});
  44240. walkFunctionParams(node, registerBinding);
  44241. if (node.body.type === "BlockStatement") {
  44242. walkScope(node.body);
  44243. }
  44244. return;
  44245. }
  44246. if (node.type === "CatchClause") {
  44247. scopeStack.push(currentScope = {});
  44248. if (node.param && node.param.type === "Identifier") {
  44249. registerBinding(node.param);
  44250. }
  44251. walkScope(node.body);
  44252. return;
  44253. }
  44254. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  44255. scopeStack.push(currentScope = {});
  44256. walkScope(node);
  44257. return;
  44258. }
  44259. if (parent && parent.type.startsWith("TS") && parent.type !== "TSAsExpression" && parent.type !== "TSNonNullExpression" && parent.type !== "TSTypeAssertion") {
  44260. return this.skip();
  44261. }
  44262. if (node.type === "Identifier") {
  44263. const binding = rootScope[node.name];
  44264. if (
  44265. // if inside $$(), skip unless this is a destructured prop binding
  44266. !(escapeScope && (!binding || !binding.isProp)) && isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)
  44267. ) {
  44268. let i = scopeStack.length;
  44269. while (i--) {
  44270. if (rewriteId(scopeStack[i], node, parent, parentStack)) {
  44271. return;
  44272. }
  44273. }
  44274. }
  44275. }
  44276. if (node.type === "CallExpression" && node.callee.type === "Identifier") {
  44277. const callee = node.callee.name;
  44278. const refCall = isRefCreationCall(callee);
  44279. if (refCall && (!parent || parent.type !== "VariableDeclarator")) {
  44280. return error(
  44281. `${refCall} can only be used as the initializer of a variable declaration.`,
  44282. node
  44283. );
  44284. }
  44285. if (escapeSymbol && currentScope[escapeSymbol] === void 0 && callee === escapeSymbol) {
  44286. escapeScope = node;
  44287. s.remove(node.callee.start + offset, node.callee.end + offset);
  44288. if ((parent == null ? void 0 : parent.type) === "ExpressionStatement") {
  44289. let i = (node.leadingComments ? node.leadingComments[0].start : node.start) + offset;
  44290. while (i--) {
  44291. const char = s.original.charAt(i);
  44292. if (char === "\n") {
  44293. s.prependRight(node.start + offset, ";");
  44294. break;
  44295. } else if (!/\s/.test(char)) {
  44296. break;
  44297. }
  44298. }
  44299. }
  44300. }
  44301. }
  44302. },
  44303. leave(node, parent) {
  44304. parent && parentStack.pop();
  44305. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node)) {
  44306. scopeStack.pop();
  44307. currentScope = scopeStack[scopeStack.length - 1] || null;
  44308. }
  44309. if (node === escapeScope) {
  44310. escapeScope = void 0;
  44311. }
  44312. }
  44313. });
  44314. return {
  44315. rootRefs: Object.keys(rootScope).filter((key) => {
  44316. const binding = rootScope[key];
  44317. return binding && !binding.isProp;
  44318. }),
  44319. importedHelpers: [...importedHelpers]
  44320. };
  44321. }
  44322. const hasWarned = {};
  44323. function warnExperimental() {
  44324. if (typeof window !== "undefined") {
  44325. return;
  44326. }
  44327. warnOnce(
  44328. `Reactivity Transform was an experimental feature and has now been deprecated. It will be removed from Vue core in 3.4. If you intend to continue using it, switch to https://vue-macros.sxzz.moe/features/reactivity-transform.html.
  44329. See reason for deprecation here: https://github.com/vuejs/rfcs/discussions/369#discussioncomment-5059028`
  44330. );
  44331. }
  44332. function warnOnce(msg) {
  44333. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  44334. if (!isNodeProd && true && !hasWarned[msg]) {
  44335. hasWarned[msg] = true;
  44336. warn(msg);
  44337. }
  44338. }
  44339. function warn(msg) {
  44340. console.warn(
  44341. `\x1B[1m\x1B[33m[@vue/reactivity-transform]\x1B[0m\x1B[33m ${msg}\x1B[0m
  44342. `
  44343. );
  44344. }
  44345. function analyzeScriptBindings(ast) {
  44346. for (const node of ast) {
  44347. if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ObjectExpression") {
  44348. return analyzeBindingsFromOptions(node.declaration);
  44349. }
  44350. }
  44351. return {};
  44352. }
  44353. function analyzeBindingsFromOptions(node) {
  44354. const bindings = {};
  44355. Object.defineProperty(bindings, "__isScriptSetup", {
  44356. enumerable: false,
  44357. value: false
  44358. });
  44359. for (const property of node.properties) {
  44360. if (property.type === "ObjectProperty" && !property.computed && property.key.type === "Identifier") {
  44361. if (property.key.name === "props") {
  44362. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  44363. bindings[key] = "props";
  44364. }
  44365. } else if (property.key.name === "inject") {
  44366. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  44367. bindings[key] = "options";
  44368. }
  44369. } else if (property.value.type === "ObjectExpression" && (property.key.name === "computed" || property.key.name === "methods")) {
  44370. for (const key of getObjectExpressionKeys(property.value)) {
  44371. bindings[key] = "options";
  44372. }
  44373. }
  44374. } else if (property.type === "ObjectMethod" && property.key.type === "Identifier" && (property.key.name === "setup" || property.key.name === "data")) {
  44375. for (const bodyItem of property.body.body) {
  44376. if (bodyItem.type === "ReturnStatement" && bodyItem.argument && bodyItem.argument.type === "ObjectExpression") {
  44377. for (const key of getObjectExpressionKeys(bodyItem.argument)) {
  44378. bindings[key] = property.key.name === "setup" ? "setup-maybe-ref" : "data";
  44379. }
  44380. }
  44381. }
  44382. }
  44383. }
  44384. return bindings;
  44385. }
  44386. function getObjectExpressionKeys(node) {
  44387. const keys = [];
  44388. for (const prop of node.properties) {
  44389. if (prop.type === "SpreadElement")
  44390. continue;
  44391. const key = resolveObjectKey(prop.key, prop.computed);
  44392. if (key)
  44393. keys.push(String(key));
  44394. }
  44395. return keys;
  44396. }
  44397. function getArrayExpressionKeys(node) {
  44398. const keys = [];
  44399. for (const element of node.elements) {
  44400. if (element && element.type === "StringLiteral") {
  44401. keys.push(element.value);
  44402. }
  44403. }
  44404. return keys;
  44405. }
  44406. function getObjectOrArrayExpressionKeys(value) {
  44407. if (value.type === "ArrayExpression") {
  44408. return getArrayExpressionKeys(value);
  44409. }
  44410. if (value.type === "ObjectExpression") {
  44411. return getObjectExpressionKeys(value);
  44412. }
  44413. return [];
  44414. }
  44415. function rewriteDefault(input, as, parserPlugins) {
  44416. const ast = parse_1$1(input, {
  44417. sourceType: "module",
  44418. plugins: parserPlugins
  44419. }).program.body;
  44420. const s = new MagicString(input);
  44421. rewriteDefaultAST(ast, s, as);
  44422. return s.toString();
  44423. }
  44424. function rewriteDefaultAST(ast, s, as) {
  44425. if (!hasDefaultExport(ast)) {
  44426. s.append(`
  44427. const ${as} = {}`);
  44428. return;
  44429. }
  44430. ast.forEach((node) => {
  44431. if (node.type === "ExportDefaultDeclaration") {
  44432. if (node.declaration.type === "ClassDeclaration" && node.declaration.id) {
  44433. let start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
  44434. s.overwrite(start, node.declaration.id.start, ` class `);
  44435. s.append(`
  44436. const ${as} = ${node.declaration.id.name}`);
  44437. } else {
  44438. s.overwrite(node.start, node.declaration.start, `const ${as} = `);
  44439. }
  44440. } else if (node.type === "ExportNamedDeclaration") {
  44441. for (const specifier of node.specifiers) {
  44442. if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === "default") {
  44443. if (node.source) {
  44444. if (specifier.local.name === "default") {
  44445. s.prepend(
  44446. `import { default as __VUE_DEFAULT__ } from '${node.source.value}'
  44447. `
  44448. );
  44449. const end2 = specifierEnd(s, specifier.local.end, node.end);
  44450. s.remove(specifier.start, end2);
  44451. s.append(`
  44452. const ${as} = __VUE_DEFAULT__`);
  44453. continue;
  44454. } else {
  44455. s.prepend(
  44456. `import { ${s.slice(
  44457. specifier.local.start,
  44458. specifier.local.end
  44459. )} as __VUE_DEFAULT__ } from '${node.source.value}'
  44460. `
  44461. );
  44462. const end2 = specifierEnd(s, specifier.exported.end, node.end);
  44463. s.remove(specifier.start, end2);
  44464. s.append(`
  44465. const ${as} = __VUE_DEFAULT__`);
  44466. continue;
  44467. }
  44468. }
  44469. const end = specifierEnd(s, specifier.end, node.end);
  44470. s.remove(specifier.start, end);
  44471. s.append(`
  44472. const ${as} = ${specifier.local.name}`);
  44473. }
  44474. }
  44475. }
  44476. });
  44477. }
  44478. function hasDefaultExport(ast) {
  44479. for (const stmt of ast) {
  44480. if (stmt.type === "ExportDefaultDeclaration") {
  44481. return true;
  44482. } else if (stmt.type === "ExportNamedDeclaration" && stmt.specifiers.some(
  44483. (spec) => spec.exported.name === "default"
  44484. )) {
  44485. return true;
  44486. }
  44487. }
  44488. return false;
  44489. }
  44490. function specifierEnd(s, end, nodeEnd) {
  44491. let hasCommas = false;
  44492. let oldEnd = end;
  44493. while (end < nodeEnd) {
  44494. if (/\s/.test(s.slice(end, end + 1))) {
  44495. end++;
  44496. } else if (s.slice(end, end + 1) === ",") {
  44497. end++;
  44498. hasCommas = true;
  44499. break;
  44500. } else if (s.slice(end, end + 1) === "}") {
  44501. break;
  44502. }
  44503. }
  44504. return hasCommas ? end : oldEnd;
  44505. }
  44506. var __defProp$2 = Object.defineProperty;
  44507. var __defProps$2 = Object.defineProperties;
  44508. var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
  44509. var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
  44510. var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
  44511. var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
  44512. var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44513. var __spreadValues$2 = (a, b) => {
  44514. for (var prop in b || (b = {}))
  44515. if (__hasOwnProp$2.call(b, prop))
  44516. __defNormalProp$2(a, prop, b[prop]);
  44517. if (__getOwnPropSymbols$2)
  44518. for (var prop of __getOwnPropSymbols$2(b)) {
  44519. if (__propIsEnum$2.call(b, prop))
  44520. __defNormalProp$2(a, prop, b[prop]);
  44521. }
  44522. return a;
  44523. };
  44524. var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
  44525. const normalScriptDefaultVar = `__default__`;
  44526. function processNormalScript(ctx, scopeId) {
  44527. var _a;
  44528. const script = ctx.descriptor.script;
  44529. if (script.lang && !ctx.isJS && !ctx.isTS) {
  44530. return script;
  44531. }
  44532. try {
  44533. let content = script.content;
  44534. let map = script.map;
  44535. const scriptAst = ctx.scriptAst;
  44536. const bindings = analyzeScriptBindings(scriptAst.body);
  44537. const { source, filename, cssVars } = ctx.descriptor;
  44538. const { sourceMap, genDefaultAs, isProd } = ctx.options;
  44539. if (ctx.options.reactivityTransform && shouldTransform(content)) {
  44540. const s = new MagicString(source);
  44541. const startOffset = script.loc.start.offset;
  44542. const endOffset = script.loc.end.offset;
  44543. const { importedHelpers } = transformAST(scriptAst, s, startOffset);
  44544. if (importedHelpers.length) {
  44545. s.prepend(
  44546. `import { ${importedHelpers.map((h) => `${h} as _${h}`).join(", ")} } from 'vue'
  44547. `
  44548. );
  44549. }
  44550. s.remove(0, startOffset);
  44551. s.remove(endOffset, source.length);
  44552. content = s.toString();
  44553. if (sourceMap !== false) {
  44554. map = s.generateMap({
  44555. source: filename,
  44556. hires: true,
  44557. includeContent: true
  44558. });
  44559. }
  44560. }
  44561. if (cssVars.length || genDefaultAs) {
  44562. const defaultVar = genDefaultAs || normalScriptDefaultVar;
  44563. const s = new MagicString(content);
  44564. rewriteDefaultAST(scriptAst.body, s, defaultVar);
  44565. content = s.toString();
  44566. if (cssVars.length && !((_a = ctx.options.templateOptions) == null ? void 0 : _a.ssr)) {
  44567. content += genNormalScriptCssVarsCode(
  44568. cssVars,
  44569. bindings,
  44570. scopeId,
  44571. !!isProd,
  44572. defaultVar
  44573. );
  44574. }
  44575. if (!genDefaultAs) {
  44576. content += `
  44577. export default ${defaultVar}`;
  44578. }
  44579. }
  44580. return __spreadProps$2(__spreadValues$2({}, script), {
  44581. content,
  44582. map,
  44583. bindings,
  44584. scriptAst: scriptAst.body
  44585. });
  44586. } catch (e) {
  44587. return script;
  44588. }
  44589. }
  44590. var _a, _b;
  44591. class ScriptCompileContext {
  44592. constructor(descriptor, options) {
  44593. this.descriptor = descriptor;
  44594. this.options = options;
  44595. this.isCE = false;
  44596. this.source = this.descriptor.source;
  44597. this.filename = this.descriptor.filename;
  44598. this.s = new MagicString(this.source);
  44599. this.startOffset = (_a = this.descriptor.scriptSetup) == null ? void 0 : _a.loc.start.offset;
  44600. this.endOffset = (_b = this.descriptor.scriptSetup) == null ? void 0 : _b.loc.end.offset;
  44601. this.userImports = /* @__PURE__ */ Object.create(null);
  44602. // macros presence check
  44603. this.hasDefinePropsCall = false;
  44604. this.hasDefineEmitCall = false;
  44605. this.hasDefineExposeCall = false;
  44606. this.hasDefaultExportName = false;
  44607. this.hasDefaultExportRender = false;
  44608. this.hasDefineOptionsCall = false;
  44609. this.hasDefineSlotsCall = false;
  44610. this.hasDefineModelCall = false;
  44611. this.propsDestructuredBindings = /* @__PURE__ */ Object.create(null);
  44612. // defineModel
  44613. this.modelDecls = /* @__PURE__ */ Object.create(null);
  44614. // codegen
  44615. this.bindingMetadata = {};
  44616. this.helperImports = /* @__PURE__ */ new Set();
  44617. const { script, scriptSetup } = descriptor;
  44618. const scriptLang = script && script.lang;
  44619. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  44620. this.isJS = scriptLang === "js" || scriptLang === "jsx" || scriptSetupLang === "js" || scriptSetupLang === "jsx";
  44621. this.isTS = scriptLang === "ts" || scriptLang === "tsx" || scriptSetupLang === "ts" || scriptSetupLang === "tsx";
  44622. const customElement = options.customElement;
  44623. const filename = this.descriptor.filename;
  44624. if (customElement) {
  44625. this.isCE = typeof customElement === "boolean" ? customElement : customElement(filename);
  44626. }
  44627. const plugins = resolveParserPlugins(
  44628. scriptLang || scriptSetupLang,
  44629. options.babelParserPlugins
  44630. );
  44631. function parse(input, offset) {
  44632. try {
  44633. return parse_1$1(input, {
  44634. plugins,
  44635. sourceType: "module"
  44636. }).program;
  44637. } catch (e) {
  44638. e.message = `[vue/compiler-sfc] ${e.message}
  44639. ${descriptor.filename}
  44640. ${generateCodeFrame(
  44641. descriptor.source,
  44642. e.pos + offset,
  44643. e.pos + offset + 1
  44644. )}`;
  44645. throw e;
  44646. }
  44647. }
  44648. this.scriptAst = descriptor.script && parse(descriptor.script.content, descriptor.script.loc.start.offset);
  44649. this.scriptSetupAst = descriptor.scriptSetup && parse(descriptor.scriptSetup.content, this.startOffset);
  44650. }
  44651. helper(key) {
  44652. this.helperImports.add(key);
  44653. return `_${key}`;
  44654. }
  44655. getString(node, scriptSetup = true) {
  44656. const block = scriptSetup ? this.descriptor.scriptSetup : this.descriptor.script;
  44657. return block.content.slice(node.start, node.end);
  44658. }
  44659. error(msg, node, scope) {
  44660. const offset = scope ? scope.offset : this.startOffset;
  44661. throw new Error(
  44662. `[@vue/compiler-sfc] ${msg}
  44663. ${(scope || this.descriptor).filename}
  44664. ${generateCodeFrame(
  44665. (scope || this.descriptor).source,
  44666. node.start + offset,
  44667. node.end + offset
  44668. )}`
  44669. );
  44670. }
  44671. }
  44672. function resolveParserPlugins(lang, userPlugins, dts = false) {
  44673. const plugins = [];
  44674. if (lang === "jsx" || lang === "tsx") {
  44675. plugins.push("jsx");
  44676. } else if (userPlugins) {
  44677. userPlugins = userPlugins.filter((p) => p !== "jsx");
  44678. }
  44679. if (lang === "ts" || lang === "tsx") {
  44680. plugins.push(["typescript", { dts }]);
  44681. if (!userPlugins || !userPlugins.includes("decorators")) {
  44682. plugins.push("decorators-legacy");
  44683. }
  44684. }
  44685. if (userPlugins) {
  44686. plugins.push(...userPlugins);
  44687. }
  44688. return plugins;
  44689. }
  44690. var __defProp$1 = Object.defineProperty;
  44691. var __defProps$1 = Object.defineProperties;
  44692. var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
  44693. var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
  44694. var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
  44695. var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
  44696. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44697. var __spreadValues$1 = (a, b) => {
  44698. for (var prop in b || (b = {}))
  44699. if (__hasOwnProp$1.call(b, prop))
  44700. __defNormalProp$1(a, prop, b[prop]);
  44701. if (__getOwnPropSymbols$1)
  44702. for (var prop of __getOwnPropSymbols$1(b)) {
  44703. if (__propIsEnum$1.call(b, prop))
  44704. __defNormalProp$1(a, prop, b[prop]);
  44705. }
  44706. return a;
  44707. };
  44708. var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
  44709. class TypeScope {
  44710. constructor(filename, source, offset = 0, imports = /* @__PURE__ */ Object.create(null), types = /* @__PURE__ */ Object.create(null), declares = /* @__PURE__ */ Object.create(null)) {
  44711. this.filename = filename;
  44712. this.source = source;
  44713. this.offset = offset;
  44714. this.imports = imports;
  44715. this.types = types;
  44716. this.declares = declares;
  44717. this.resolvedImportSources = /* @__PURE__ */ Object.create(null);
  44718. this.exportedTypes = /* @__PURE__ */ Object.create(null);
  44719. this.exportedDeclares = /* @__PURE__ */ Object.create(null);
  44720. }
  44721. }
  44722. function resolveTypeElements(ctx, node, scope, typeParameters) {
  44723. if (node._resolvedElements) {
  44724. return node._resolvedElements;
  44725. }
  44726. return node._resolvedElements = innerResolveTypeElements(
  44727. ctx,
  44728. node,
  44729. node._ownerScope || scope || ctxToScope(ctx),
  44730. typeParameters
  44731. );
  44732. }
  44733. function innerResolveTypeElements(ctx, node, scope, typeParameters) {
  44734. var _a, _b;
  44735. switch (node.type) {
  44736. case "TSTypeLiteral":
  44737. return typeElementsToMap(ctx, node.members, scope, typeParameters);
  44738. case "TSInterfaceDeclaration":
  44739. return resolveInterfaceMembers(ctx, node, scope, typeParameters);
  44740. case "TSTypeAliasDeclaration":
  44741. case "TSParenthesizedType":
  44742. return resolveTypeElements(
  44743. ctx,
  44744. node.typeAnnotation,
  44745. scope,
  44746. typeParameters
  44747. );
  44748. case "TSFunctionType": {
  44749. return { props: {}, calls: [node] };
  44750. }
  44751. case "TSUnionType":
  44752. case "TSIntersectionType":
  44753. return mergeElements(
  44754. node.types.map((t) => resolveTypeElements(ctx, t, scope, typeParameters)),
  44755. node.type
  44756. );
  44757. case "TSMappedType":
  44758. return resolveMappedType(ctx, node, scope);
  44759. case "TSIndexedAccessType": {
  44760. const types = resolveIndexType(ctx, node, scope);
  44761. return mergeElements(
  44762. types.map((t) => resolveTypeElements(ctx, t, t._ownerScope)),
  44763. "TSUnionType"
  44764. );
  44765. }
  44766. case "TSExpressionWithTypeArguments":
  44767. case "TSTypeReference": {
  44768. const typeName = getReferenceName(node);
  44769. if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
  44770. return resolveExtractPropTypes(
  44771. resolveTypeElements(
  44772. ctx,
  44773. node.typeParameters.params[0],
  44774. scope,
  44775. typeParameters
  44776. ),
  44777. scope
  44778. );
  44779. }
  44780. const resolved = resolveTypeReference(ctx, node, scope);
  44781. if (resolved) {
  44782. const typeParams = /* @__PURE__ */ Object.create(null);
  44783. if ((resolved.type === "TSTypeAliasDeclaration" || resolved.type === "TSInterfaceDeclaration") && resolved.typeParameters && node.typeParameters) {
  44784. resolved.typeParameters.params.forEach((p, i) => {
  44785. let param = typeParameters && typeParameters[p.name];
  44786. if (!param)
  44787. param = node.typeParameters.params[i];
  44788. typeParams[p.name] = param;
  44789. });
  44790. }
  44791. return resolveTypeElements(
  44792. ctx,
  44793. resolved,
  44794. resolved._ownerScope,
  44795. typeParams
  44796. );
  44797. } else {
  44798. if (typeof typeName === "string") {
  44799. if (typeParameters && typeParameters[typeName]) {
  44800. return resolveTypeElements(
  44801. ctx,
  44802. typeParameters[typeName],
  44803. scope,
  44804. typeParameters
  44805. );
  44806. }
  44807. if (
  44808. // @ts-ignore
  44809. SupportedBuiltinsSet.has(typeName)
  44810. ) {
  44811. return resolveBuiltin(
  44812. ctx,
  44813. node,
  44814. typeName,
  44815. scope,
  44816. typeParameters
  44817. );
  44818. } else if (typeName === "ReturnType" && node.typeParameters) {
  44819. const ret = resolveReturnType(
  44820. ctx,
  44821. node.typeParameters.params[0],
  44822. scope
  44823. );
  44824. if (ret) {
  44825. return resolveTypeElements(ctx, ret, scope);
  44826. }
  44827. }
  44828. }
  44829. return ctx.error(
  44830. `Unresolvable type reference or unsupported built-in utility type`,
  44831. node,
  44832. scope
  44833. );
  44834. }
  44835. }
  44836. case "TSImportType": {
  44837. if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
  44838. return resolveExtractPropTypes(
  44839. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  44840. scope
  44841. );
  44842. }
  44843. const sourceScope = importSourceToScope(
  44844. ctx,
  44845. node.argument,
  44846. scope,
  44847. node.argument.value
  44848. );
  44849. const resolved = resolveTypeReference(ctx, node, sourceScope);
  44850. if (resolved) {
  44851. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  44852. }
  44853. break;
  44854. }
  44855. case "TSTypeQuery":
  44856. {
  44857. const resolved = resolveTypeReference(ctx, node, scope);
  44858. if (resolved) {
  44859. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  44860. }
  44861. }
  44862. break;
  44863. }
  44864. return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
  44865. }
  44866. function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameters) {
  44867. const res = { props: {} };
  44868. for (const e of elements) {
  44869. if (e.type === "TSPropertySignature" || e.type === "TSMethodSignature") {
  44870. if (typeParameters) {
  44871. scope = createChildScope(scope);
  44872. Object.assign(scope.types, typeParameters);
  44873. }
  44874. e._ownerScope = scope;
  44875. const name = getId(e.key);
  44876. if (name && !e.computed) {
  44877. res.props[name] = e;
  44878. } else if (e.key.type === "TemplateLiteral") {
  44879. for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
  44880. res.props[key] = e;
  44881. }
  44882. } else {
  44883. ctx.error(
  44884. `Unsupported computed key in type referenced by a macro`,
  44885. e.key,
  44886. scope
  44887. );
  44888. }
  44889. } else if (e.type === "TSCallSignatureDeclaration") {
  44890. (res.calls || (res.calls = [])).push(e);
  44891. }
  44892. }
  44893. return res;
  44894. }
  44895. function mergeElements(maps, type) {
  44896. if (maps.length === 1)
  44897. return maps[0];
  44898. const res = { props: {} };
  44899. const { props: baseProps } = res;
  44900. for (const { props, calls } of maps) {
  44901. for (const key in props) {
  44902. if (!hasOwn(baseProps, key)) {
  44903. baseProps[key] = props[key];
  44904. } else {
  44905. baseProps[key] = createProperty(
  44906. baseProps[key].key,
  44907. {
  44908. type,
  44909. // @ts-ignore
  44910. types: [baseProps[key], props[key]]
  44911. },
  44912. baseProps[key]._ownerScope,
  44913. baseProps[key].optional || props[key].optional
  44914. );
  44915. }
  44916. }
  44917. if (calls) {
  44918. (res.calls || (res.calls = [])).push(...calls);
  44919. }
  44920. }
  44921. return res;
  44922. }
  44923. function createProperty(key, typeAnnotation, scope, optional) {
  44924. return {
  44925. type: "TSPropertySignature",
  44926. key,
  44927. kind: "get",
  44928. optional,
  44929. typeAnnotation: {
  44930. type: "TSTypeAnnotation",
  44931. typeAnnotation
  44932. },
  44933. _ownerScope: scope
  44934. };
  44935. }
  44936. function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
  44937. const base = typeElementsToMap(
  44938. ctx,
  44939. node.body.body,
  44940. node._ownerScope,
  44941. typeParameters
  44942. );
  44943. if (node.extends) {
  44944. for (const ext of node.extends) {
  44945. if (ext.leadingComments && ext.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  44946. continue;
  44947. }
  44948. try {
  44949. const { props, calls } = resolveTypeElements(ctx, ext, scope);
  44950. for (const key in props) {
  44951. if (!hasOwn(base.props, key)) {
  44952. base.props[key] = props[key];
  44953. }
  44954. }
  44955. if (calls) {
  44956. ;
  44957. (base.calls || (base.calls = [])).push(...calls);
  44958. }
  44959. } catch (e) {
  44960. ctx.error(
  44961. `Failed to resolve extends base type.
  44962. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
  44963. interface Props extends /* @vue-ignore */ Base {}
  44964. Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
  44965. ext
  44966. );
  44967. }
  44968. }
  44969. }
  44970. return base;
  44971. }
  44972. function resolveMappedType(ctx, node, scope) {
  44973. const res = { props: {} };
  44974. const keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
  44975. for (const key of keys) {
  44976. res.props[key] = createProperty(
  44977. {
  44978. type: "Identifier",
  44979. name: key
  44980. },
  44981. node.typeAnnotation,
  44982. scope,
  44983. !!node.optional
  44984. );
  44985. }
  44986. return res;
  44987. }
  44988. function resolveIndexType(ctx, node, scope) {
  44989. var _a, _b;
  44990. if (node.indexType.type === "TSNumberKeyword") {
  44991. return resolveArrayElementType(ctx, node.objectType, scope);
  44992. }
  44993. const { indexType, objectType } = node;
  44994. const types = [];
  44995. let keys;
  44996. let resolved;
  44997. if (indexType.type === "TSStringKeyword") {
  44998. resolved = resolveTypeElements(ctx, objectType, scope);
  44999. keys = Object.keys(resolved.props);
  45000. } else {
  45001. keys = resolveStringType(ctx, indexType, scope);
  45002. resolved = resolveTypeElements(ctx, objectType, scope);
  45003. }
  45004. for (const key of keys) {
  45005. const targetType = (_b = (_a = resolved.props[key]) == null ? void 0 : _a.typeAnnotation) == null ? void 0 : _b.typeAnnotation;
  45006. if (targetType) {
  45007. targetType._ownerScope = resolved.props[key]._ownerScope;
  45008. types.push(targetType);
  45009. }
  45010. }
  45011. return types;
  45012. }
  45013. function resolveArrayElementType(ctx, node, scope) {
  45014. if (node.type === "TSArrayType") {
  45015. return [node.elementType];
  45016. }
  45017. if (node.type === "TSTupleType") {
  45018. return node.elementTypes.map(
  45019. (t) => t.type === "TSNamedTupleMember" ? t.elementType : t
  45020. );
  45021. }
  45022. if (node.type === "TSTypeReference") {
  45023. if (getReferenceName(node) === "Array" && node.typeParameters) {
  45024. return node.typeParameters.params;
  45025. } else {
  45026. const resolved = resolveTypeReference(ctx, node, scope);
  45027. if (resolved) {
  45028. return resolveArrayElementType(ctx, resolved, scope);
  45029. }
  45030. }
  45031. }
  45032. return ctx.error(
  45033. "Failed to resolve element type from target type",
  45034. node,
  45035. scope
  45036. );
  45037. }
  45038. function resolveStringType(ctx, node, scope) {
  45039. switch (node.type) {
  45040. case "StringLiteral":
  45041. return [node.value];
  45042. case "TSLiteralType":
  45043. return resolveStringType(ctx, node.literal, scope);
  45044. case "TSUnionType":
  45045. return node.types.map((t) => resolveStringType(ctx, t, scope)).flat();
  45046. case "TemplateLiteral": {
  45047. return resolveTemplateKeys(ctx, node, scope);
  45048. }
  45049. case "TSTypeReference": {
  45050. const resolved = resolveTypeReference(ctx, node, scope);
  45051. if (resolved) {
  45052. return resolveStringType(ctx, resolved, scope);
  45053. }
  45054. if (node.typeName.type === "Identifier") {
  45055. const getParam = (index = 0) => resolveStringType(ctx, node.typeParameters.params[index], scope);
  45056. switch (node.typeName.name) {
  45057. case "Extract":
  45058. return getParam(1);
  45059. case "Exclude": {
  45060. const excluded = getParam(1);
  45061. return getParam().filter((s) => !excluded.includes(s));
  45062. }
  45063. case "Uppercase":
  45064. return getParam().map((s) => s.toUpperCase());
  45065. case "Lowercase":
  45066. return getParam().map((s) => s.toLowerCase());
  45067. case "Capitalize":
  45068. return getParam().map(capitalize$1);
  45069. case "Uncapitalize":
  45070. return getParam().map((s) => s[0].toLowerCase() + s.slice(1));
  45071. default:
  45072. ctx.error(
  45073. "Unsupported type when resolving index type",
  45074. node.typeName,
  45075. scope
  45076. );
  45077. }
  45078. }
  45079. }
  45080. }
  45081. return ctx.error("Failed to resolve index type into finite keys", node, scope);
  45082. }
  45083. function resolveTemplateKeys(ctx, node, scope) {
  45084. if (!node.expressions.length) {
  45085. return [node.quasis[0].value.raw];
  45086. }
  45087. const res = [];
  45088. const e = node.expressions[0];
  45089. const q = node.quasis[0];
  45090. const leading = q ? q.value.raw : ``;
  45091. const resolved = resolveStringType(ctx, e, scope);
  45092. const restResolved = resolveTemplateKeys(
  45093. ctx,
  45094. __spreadProps$1(__spreadValues$1({}, node), {
  45095. expressions: node.expressions.slice(1),
  45096. quasis: q ? node.quasis.slice(1) : node.quasis
  45097. }),
  45098. scope
  45099. );
  45100. for (const r of resolved) {
  45101. for (const rr of restResolved) {
  45102. res.push(leading + r + rr);
  45103. }
  45104. }
  45105. return res;
  45106. }
  45107. const SupportedBuiltinsSet = /* @__PURE__ */ new Set([
  45108. "Partial",
  45109. "Required",
  45110. "Readonly",
  45111. "Pick",
  45112. "Omit"
  45113. ]);
  45114. function resolveBuiltin(ctx, node, name, scope, typeParameters) {
  45115. const t = resolveTypeElements(
  45116. ctx,
  45117. node.typeParameters.params[0],
  45118. scope,
  45119. typeParameters
  45120. );
  45121. switch (name) {
  45122. case "Partial": {
  45123. const res2 = { props: {}, calls: t.calls };
  45124. Object.keys(t.props).forEach((key) => {
  45125. res2.props[key] = __spreadProps$1(__spreadValues$1({}, t.props[key]), { optional: true });
  45126. });
  45127. return res2;
  45128. }
  45129. case "Required": {
  45130. const res2 = { props: {}, calls: t.calls };
  45131. Object.keys(t.props).forEach((key) => {
  45132. res2.props[key] = __spreadProps$1(__spreadValues$1({}, t.props[key]), { optional: false });
  45133. });
  45134. return res2;
  45135. }
  45136. case "Readonly":
  45137. return t;
  45138. case "Pick": {
  45139. const picked = resolveStringType(
  45140. ctx,
  45141. node.typeParameters.params[1],
  45142. scope
  45143. );
  45144. const res2 = { props: {}, calls: t.calls };
  45145. for (const key of picked) {
  45146. res2.props[key] = t.props[key];
  45147. }
  45148. return res2;
  45149. }
  45150. case "Omit":
  45151. const omitted = resolveStringType(
  45152. ctx,
  45153. node.typeParameters.params[1],
  45154. scope
  45155. );
  45156. const res = { props: {}, calls: t.calls };
  45157. for (const key in t.props) {
  45158. if (!omitted.includes(key)) {
  45159. res.props[key] = t.props[key];
  45160. }
  45161. }
  45162. return res;
  45163. }
  45164. }
  45165. function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
  45166. if (node._resolvedReference) {
  45167. return node._resolvedReference;
  45168. }
  45169. return node._resolvedReference = innerResolveTypeReference(
  45170. ctx,
  45171. scope || ctxToScope(ctx),
  45172. name || getReferenceName(node),
  45173. node,
  45174. onlyExported
  45175. );
  45176. }
  45177. function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
  45178. if (typeof name === "string") {
  45179. if (scope.imports[name]) {
  45180. return resolveTypeFromImport(ctx, node, name, scope);
  45181. } else {
  45182. const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
  45183. if (lookupSource[name]) {
  45184. return lookupSource[name];
  45185. } else {
  45186. const globalScopes = resolveGlobalScope(ctx);
  45187. if (globalScopes) {
  45188. for (const s of globalScopes) {
  45189. const src = node.type === "TSTypeQuery" ? s.declares : s.types;
  45190. if (src[name]) {
  45191. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
  45192. return src[name];
  45193. }
  45194. }
  45195. }
  45196. }
  45197. }
  45198. } else {
  45199. let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
  45200. if (ns) {
  45201. if (ns.type !== "TSModuleDeclaration") {
  45202. ns = ns._ns;
  45203. }
  45204. if (ns) {
  45205. const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
  45206. return innerResolveTypeReference(
  45207. ctx,
  45208. childScope,
  45209. name.length > 2 ? name.slice(1) : name[name.length - 1],
  45210. node,
  45211. !ns.declare
  45212. );
  45213. }
  45214. }
  45215. }
  45216. }
  45217. function getReferenceName(node) {
  45218. const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
  45219. if ((ref == null ? void 0 : ref.type) === "Identifier") {
  45220. return ref.name;
  45221. } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
  45222. return qualifiedNameToPath(ref);
  45223. } else {
  45224. return "default";
  45225. }
  45226. }
  45227. function qualifiedNameToPath(node) {
  45228. if (node.type === "Identifier") {
  45229. return [node.name];
  45230. } else {
  45231. return [...qualifiedNameToPath(node.left), node.right.name];
  45232. }
  45233. }
  45234. function resolveGlobalScope(ctx) {
  45235. if (ctx.options.globalTypeFiles) {
  45236. const fs = resolveFS(ctx);
  45237. if (!fs) {
  45238. throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
  45239. }
  45240. return ctx.options.globalTypeFiles.map(
  45241. (file) => fileToScope(ctx, normalizePath(file), true)
  45242. );
  45243. }
  45244. }
  45245. let ts;
  45246. let loadTS;
  45247. function registerTS(_loadTS) {
  45248. loadTS = () => {
  45249. try {
  45250. return _loadTS();
  45251. } catch (err) {
  45252. if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
  45253. throw new Error(
  45254. 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "typescript" is installed as a project dependency.'
  45255. );
  45256. } else {
  45257. throw new Error(
  45258. "Failed to load TypeScript for resolving imported types."
  45259. );
  45260. }
  45261. }
  45262. };
  45263. }
  45264. function resolveFS(ctx) {
  45265. if (ctx.fs) {
  45266. return ctx.fs;
  45267. }
  45268. if (!ts && loadTS) {
  45269. ts = loadTS();
  45270. }
  45271. const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
  45272. if (!fs) {
  45273. return;
  45274. }
  45275. return ctx.fs = {
  45276. fileExists(file) {
  45277. if (file.endsWith(".vue.ts")) {
  45278. file = file.replace(/\.ts$/, "");
  45279. }
  45280. return fs.fileExists(file);
  45281. },
  45282. readFile(file) {
  45283. if (file.endsWith(".vue.ts")) {
  45284. file = file.replace(/\.ts$/, "");
  45285. }
  45286. return fs.readFile(file);
  45287. }
  45288. };
  45289. }
  45290. function resolveTypeFromImport(ctx, node, name, scope) {
  45291. const { source, imported } = scope.imports[name];
  45292. const sourceScope = importSourceToScope(ctx, node, scope, source);
  45293. return resolveTypeReference(ctx, node, sourceScope, imported, true);
  45294. }
  45295. function importSourceToScope(ctx, node, scope, source) {
  45296. let fs;
  45297. try {
  45298. fs = resolveFS(ctx);
  45299. } catch (err) {
  45300. return ctx.error(err.message, node, scope);
  45301. }
  45302. if (!fs) {
  45303. return ctx.error(
  45304. `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
  45305. node,
  45306. scope
  45307. );
  45308. }
  45309. let resolved = scope.resolvedImportSources[source];
  45310. if (!resolved) {
  45311. if (source.startsWith("..")) {
  45312. const osSpecificJoinFn = joinPaths;
  45313. const filename = osSpecificJoinFn(dirname$2(scope.filename), source);
  45314. resolved = resolveExt(filename, fs);
  45315. } else if (source.startsWith(".")) {
  45316. const filename = joinPaths(dirname$2(scope.filename), source);
  45317. resolved = resolveExt(filename, fs);
  45318. } else {
  45319. {
  45320. return ctx.error(
  45321. `Type import from non-relative sources is not supported in the browser build.`,
  45322. node,
  45323. scope
  45324. );
  45325. }
  45326. }
  45327. if (resolved) {
  45328. resolved = scope.resolvedImportSources[source] = normalizePath(resolved);
  45329. }
  45330. }
  45331. if (resolved) {
  45332. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
  45333. return fileToScope(ctx, resolved);
  45334. } else {
  45335. return ctx.error(
  45336. `Failed to resolve import source ${JSON.stringify(source)}.`,
  45337. node,
  45338. scope
  45339. );
  45340. }
  45341. }
  45342. function resolveExt(filename, fs) {
  45343. filename = filename.replace(/\.js$/, "");
  45344. const tryResolve = (filename2) => {
  45345. if (fs.fileExists(filename2))
  45346. return filename2;
  45347. };
  45348. return tryResolve(filename) || tryResolve(filename + `.ts`) || tryResolve(filename + `.d.ts`) || tryResolve(joinPaths(filename, `index.ts`)) || tryResolve(joinPaths(filename, `index.d.ts`));
  45349. }
  45350. const tsConfigCache = createCache();
  45351. const tsConfigRefMap = /* @__PURE__ */ new Map();
  45352. const fileToScopeCache = createCache();
  45353. function invalidateTypeCache(filename) {
  45354. filename = normalizePath(filename);
  45355. fileToScopeCache.delete(filename);
  45356. tsConfigCache.delete(filename);
  45357. const affectedConfig = tsConfigRefMap.get(filename);
  45358. if (affectedConfig)
  45359. tsConfigCache.delete(affectedConfig);
  45360. }
  45361. function fileToScope(ctx, filename, asGlobal = false) {
  45362. const cached = fileToScopeCache.get(filename);
  45363. if (cached) {
  45364. return cached;
  45365. }
  45366. const fs = resolveFS(ctx);
  45367. const source = fs.readFile(filename) || "";
  45368. const body = parseFile(filename, source, ctx.options.babelParserPlugins);
  45369. const scope = new TypeScope(filename, source, 0, recordImports(body));
  45370. recordTypes(ctx, body, scope, asGlobal);
  45371. fileToScopeCache.set(filename, scope);
  45372. return scope;
  45373. }
  45374. function parseFile(filename, content, parserPlugins) {
  45375. const ext = extname(filename);
  45376. if (ext === ".ts" || ext === ".tsx") {
  45377. return parse_1$1(content, {
  45378. plugins: resolveParserPlugins(
  45379. ext.slice(1),
  45380. parserPlugins,
  45381. filename.endsWith(".d.ts")
  45382. ),
  45383. sourceType: "module"
  45384. }).program.body;
  45385. } else if (ext === ".vue") {
  45386. const {
  45387. descriptor: { script, scriptSetup }
  45388. } = parse$7(content);
  45389. if (!script && !scriptSetup) {
  45390. return [];
  45391. }
  45392. const scriptOffset = script ? script.loc.start.offset : Infinity;
  45393. const scriptSetupOffset = scriptSetup ? scriptSetup.loc.start.offset : Infinity;
  45394. const firstBlock = scriptOffset < scriptSetupOffset ? script : scriptSetup;
  45395. const secondBlock = scriptOffset < scriptSetupOffset ? scriptSetup : script;
  45396. let scriptContent = " ".repeat(Math.min(scriptOffset, scriptSetupOffset)) + firstBlock.content;
  45397. if (secondBlock) {
  45398. scriptContent += " ".repeat(secondBlock.loc.start.offset - script.loc.end.offset) + secondBlock.content;
  45399. }
  45400. const lang = (script == null ? void 0 : script.lang) || (scriptSetup == null ? void 0 : scriptSetup.lang);
  45401. return parse_1$1(scriptContent, {
  45402. plugins: resolveParserPlugins(lang, parserPlugins),
  45403. sourceType: "module"
  45404. }).program.body;
  45405. }
  45406. return [];
  45407. }
  45408. function ctxToScope(ctx) {
  45409. if (ctx.scope) {
  45410. return ctx.scope;
  45411. }
  45412. const body = "ast" in ctx ? ctx.ast : ctx.scriptAst ? [...ctx.scriptAst.body, ...ctx.scriptSetupAst.body] : ctx.scriptSetupAst.body;
  45413. const scope = new TypeScope(
  45414. ctx.filename,
  45415. ctx.source,
  45416. "startOffset" in ctx ? ctx.startOffset : 0,
  45417. "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body)
  45418. );
  45419. recordTypes(ctx, body, scope);
  45420. return ctx.scope = scope;
  45421. }
  45422. function moduleDeclToScope(ctx, node, parentScope) {
  45423. if (node._resolvedChildScope) {
  45424. return node._resolvedChildScope;
  45425. }
  45426. const scope = createChildScope(parentScope);
  45427. if (node.body.type === "TSModuleDeclaration") {
  45428. const decl = node.body;
  45429. decl._ownerScope = scope;
  45430. const id = getId(decl.id);
  45431. scope.types[id] = scope.exportedTypes[id] = decl;
  45432. } else {
  45433. recordTypes(ctx, node.body.body, scope);
  45434. }
  45435. return node._resolvedChildScope = scope;
  45436. }
  45437. function createChildScope(parentScope) {
  45438. return new TypeScope(
  45439. parentScope.filename,
  45440. parentScope.source,
  45441. parentScope.offset,
  45442. Object.create(parentScope.imports),
  45443. Object.create(parentScope.types),
  45444. Object.create(parentScope.declares)
  45445. );
  45446. }
  45447. const importExportRE = /^Import|^Export/;
  45448. function recordTypes(ctx, body, scope, asGlobal = false) {
  45449. const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
  45450. const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
  45451. for (const stmt of body) {
  45452. if (asGlobal) {
  45453. if (isAmbient) {
  45454. if (stmt.declare) {
  45455. recordType(stmt, types, declares);
  45456. }
  45457. } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
  45458. for (const s of stmt.body.body) {
  45459. recordType(s, types, declares);
  45460. }
  45461. }
  45462. } else {
  45463. recordType(stmt, types, declares);
  45464. }
  45465. }
  45466. if (!asGlobal) {
  45467. for (const stmt of body) {
  45468. if (stmt.type === "ExportNamedDeclaration") {
  45469. if (stmt.declaration) {
  45470. recordType(stmt.declaration, types, declares);
  45471. recordType(stmt.declaration, exportedTypes, exportedDeclares);
  45472. } else {
  45473. for (const spec of stmt.specifiers) {
  45474. if (spec.type === "ExportSpecifier") {
  45475. const local = spec.local.name;
  45476. const exported = getId(spec.exported);
  45477. if (stmt.source) {
  45478. imports[exported] = {
  45479. source: stmt.source.value,
  45480. imported: local
  45481. };
  45482. exportedTypes[exported] = {
  45483. type: "TSTypeReference",
  45484. typeName: {
  45485. type: "Identifier",
  45486. name: local
  45487. },
  45488. _ownerScope: scope
  45489. };
  45490. } else if (types[local]) {
  45491. exportedTypes[exported] = types[local];
  45492. }
  45493. }
  45494. }
  45495. }
  45496. } else if (stmt.type === "ExportAllDeclaration") {
  45497. const sourceScope = importSourceToScope(
  45498. ctx,
  45499. stmt.source,
  45500. scope,
  45501. stmt.source.value
  45502. );
  45503. Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
  45504. } else if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration) {
  45505. if (stmt.declaration.type !== "Identifier") {
  45506. recordType(stmt.declaration, types, declares, "default");
  45507. recordType(
  45508. stmt.declaration,
  45509. exportedTypes,
  45510. exportedDeclares,
  45511. "default"
  45512. );
  45513. } else if (types[stmt.declaration.name]) {
  45514. exportedTypes["default"] = types[stmt.declaration.name];
  45515. }
  45516. }
  45517. }
  45518. }
  45519. for (const key of Object.keys(types)) {
  45520. const node = types[key];
  45521. node._ownerScope = scope;
  45522. if (node._ns)
  45523. node._ns._ownerScope = scope;
  45524. }
  45525. for (const key of Object.keys(declares)) {
  45526. declares[key]._ownerScope = scope;
  45527. }
  45528. }
  45529. function recordType(node, types, declares, overwriteId) {
  45530. switch (node.type) {
  45531. case "TSInterfaceDeclaration":
  45532. case "TSEnumDeclaration":
  45533. case "TSModuleDeclaration": {
  45534. const id = overwriteId || getId(node.id);
  45535. let existing = types[id];
  45536. if (existing) {
  45537. if (node.type === "TSModuleDeclaration") {
  45538. if (existing.type === "TSModuleDeclaration") {
  45539. mergeNamespaces(existing, node);
  45540. } else {
  45541. attachNamespace(existing, node);
  45542. }
  45543. break;
  45544. }
  45545. if (existing.type === "TSModuleDeclaration") {
  45546. types[id] = node;
  45547. attachNamespace(node, existing);
  45548. break;
  45549. }
  45550. if (existing.type !== node.type) {
  45551. break;
  45552. }
  45553. if (node.type === "TSInterfaceDeclaration") {
  45554. existing.body.body.push(...node.body.body);
  45555. } else {
  45556. existing.members.push(...node.members);
  45557. }
  45558. } else {
  45559. types[id] = node;
  45560. }
  45561. break;
  45562. }
  45563. case "ClassDeclaration":
  45564. if (overwriteId || node.id)
  45565. types[overwriteId || getId(node.id)] = node;
  45566. break;
  45567. case "TSTypeAliasDeclaration":
  45568. types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
  45569. break;
  45570. case "TSDeclareFunction":
  45571. if (node.id)
  45572. declares[node.id.name] = node;
  45573. break;
  45574. case "VariableDeclaration": {
  45575. if (node.declare) {
  45576. for (const decl of node.declarations) {
  45577. if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
  45578. declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
  45579. }
  45580. }
  45581. }
  45582. break;
  45583. }
  45584. }
  45585. }
  45586. function mergeNamespaces(to, from) {
  45587. const toBody = to.body;
  45588. const fromBody = from.body;
  45589. if (toBody.type === "TSModuleDeclaration") {
  45590. if (fromBody.type === "TSModuleDeclaration") {
  45591. mergeNamespaces(toBody, fromBody);
  45592. } else {
  45593. fromBody.body.push({
  45594. type: "ExportNamedDeclaration",
  45595. declaration: toBody,
  45596. exportKind: "type",
  45597. specifiers: []
  45598. });
  45599. }
  45600. } else if (fromBody.type === "TSModuleDeclaration") {
  45601. toBody.body.push({
  45602. type: "ExportNamedDeclaration",
  45603. declaration: fromBody,
  45604. exportKind: "type",
  45605. specifiers: []
  45606. });
  45607. } else {
  45608. toBody.body.push(...fromBody.body);
  45609. }
  45610. }
  45611. function attachNamespace(to, ns) {
  45612. if (!to._ns) {
  45613. to._ns = ns;
  45614. } else {
  45615. mergeNamespaces(to._ns, ns);
  45616. }
  45617. }
  45618. function recordImports(body) {
  45619. const imports = /* @__PURE__ */ Object.create(null);
  45620. for (const s of body) {
  45621. recordImport(s, imports);
  45622. }
  45623. return imports;
  45624. }
  45625. function recordImport(node, imports) {
  45626. if (node.type !== "ImportDeclaration") {
  45627. return;
  45628. }
  45629. for (const s of node.specifiers) {
  45630. imports[s.local.name] = {
  45631. imported: getImportedName(s),
  45632. source: node.source.value
  45633. };
  45634. }
  45635. }
  45636. function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)) {
  45637. try {
  45638. switch (node.type) {
  45639. case "TSStringKeyword":
  45640. return ["String"];
  45641. case "TSNumberKeyword":
  45642. return ["Number"];
  45643. case "TSBooleanKeyword":
  45644. return ["Boolean"];
  45645. case "TSObjectKeyword":
  45646. return ["Object"];
  45647. case "TSNullKeyword":
  45648. return ["null"];
  45649. case "TSTypeLiteral":
  45650. case "TSInterfaceDeclaration": {
  45651. const types = /* @__PURE__ */ new Set();
  45652. const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
  45653. for (const m of members) {
  45654. if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
  45655. types.add("Function");
  45656. } else {
  45657. types.add("Object");
  45658. }
  45659. }
  45660. return types.size ? Array.from(types) : ["Object"];
  45661. }
  45662. case "TSPropertySignature":
  45663. if (node.typeAnnotation) {
  45664. return inferRuntimeType(
  45665. ctx,
  45666. node.typeAnnotation.typeAnnotation,
  45667. scope
  45668. );
  45669. }
  45670. case "TSMethodSignature":
  45671. case "TSFunctionType":
  45672. return ["Function"];
  45673. case "TSArrayType":
  45674. case "TSTupleType":
  45675. return ["Array"];
  45676. case "TSLiteralType":
  45677. switch (node.literal.type) {
  45678. case "StringLiteral":
  45679. return ["String"];
  45680. case "BooleanLiteral":
  45681. return ["Boolean"];
  45682. case "NumericLiteral":
  45683. case "BigIntLiteral":
  45684. return ["Number"];
  45685. default:
  45686. return [UNKNOWN_TYPE];
  45687. }
  45688. case "TSTypeReference": {
  45689. const resolved = resolveTypeReference(ctx, node, scope);
  45690. if (resolved) {
  45691. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  45692. }
  45693. if (node.typeName.type === "Identifier") {
  45694. switch (node.typeName.name) {
  45695. case "Array":
  45696. case "Function":
  45697. case "Object":
  45698. case "Set":
  45699. case "Map":
  45700. case "WeakSet":
  45701. case "WeakMap":
  45702. case "Date":
  45703. case "Promise":
  45704. case "Error":
  45705. return [node.typeName.name];
  45706. case "Partial":
  45707. case "Required":
  45708. case "Readonly":
  45709. case "Record":
  45710. case "Pick":
  45711. case "Omit":
  45712. case "InstanceType":
  45713. return ["Object"];
  45714. case "Uppercase":
  45715. case "Lowercase":
  45716. case "Capitalize":
  45717. case "Uncapitalize":
  45718. return ["String"];
  45719. case "Parameters":
  45720. case "ConstructorParameters":
  45721. return ["Array"];
  45722. case "NonNullable":
  45723. if (node.typeParameters && node.typeParameters.params[0]) {
  45724. return inferRuntimeType(
  45725. ctx,
  45726. node.typeParameters.params[0],
  45727. scope
  45728. ).filter((t) => t !== "null");
  45729. }
  45730. break;
  45731. case "Extract":
  45732. if (node.typeParameters && node.typeParameters.params[1]) {
  45733. return inferRuntimeType(
  45734. ctx,
  45735. node.typeParameters.params[1],
  45736. scope
  45737. );
  45738. }
  45739. break;
  45740. case "Exclude":
  45741. case "OmitThisParameter":
  45742. if (node.typeParameters && node.typeParameters.params[0]) {
  45743. return inferRuntimeType(
  45744. ctx,
  45745. node.typeParameters.params[0],
  45746. scope
  45747. );
  45748. }
  45749. break;
  45750. }
  45751. }
  45752. break;
  45753. }
  45754. case "TSParenthesizedType":
  45755. return inferRuntimeType(ctx, node.typeAnnotation, scope);
  45756. case "TSUnionType":
  45757. return flattenTypes(ctx, node.types, scope);
  45758. case "TSIntersectionType": {
  45759. return flattenTypes(ctx, node.types, scope).filter(
  45760. (t) => t !== UNKNOWN_TYPE
  45761. );
  45762. }
  45763. case "TSEnumDeclaration":
  45764. return inferEnumType(node);
  45765. case "TSSymbolKeyword":
  45766. return ["Symbol"];
  45767. case "TSIndexedAccessType": {
  45768. const types = resolveIndexType(ctx, node, scope);
  45769. return flattenTypes(ctx, types, scope);
  45770. }
  45771. case "ClassDeclaration":
  45772. return ["Object"];
  45773. case "TSImportType": {
  45774. const sourceScope = importSourceToScope(
  45775. ctx,
  45776. node.argument,
  45777. scope,
  45778. node.argument.value
  45779. );
  45780. const resolved = resolveTypeReference(ctx, node, sourceScope);
  45781. if (resolved) {
  45782. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  45783. }
  45784. break;
  45785. }
  45786. case "TSTypeQuery": {
  45787. const id = node.exprName;
  45788. if (id.type === "Identifier") {
  45789. const matched = scope.declares[id.name];
  45790. if (matched) {
  45791. return inferRuntimeType(ctx, matched, matched._ownerScope);
  45792. }
  45793. }
  45794. break;
  45795. }
  45796. }
  45797. } catch (e) {
  45798. }
  45799. return [UNKNOWN_TYPE];
  45800. }
  45801. function flattenTypes(ctx, types, scope) {
  45802. if (types.length === 1) {
  45803. return inferRuntimeType(ctx, types[0], scope);
  45804. }
  45805. return [
  45806. ...new Set(
  45807. [].concat(
  45808. ...types.map((t) => inferRuntimeType(ctx, t, scope))
  45809. )
  45810. )
  45811. ];
  45812. }
  45813. function inferEnumType(node) {
  45814. const types = /* @__PURE__ */ new Set();
  45815. for (const m of node.members) {
  45816. if (m.initializer) {
  45817. switch (m.initializer.type) {
  45818. case "StringLiteral":
  45819. types.add("String");
  45820. break;
  45821. case "NumericLiteral":
  45822. types.add("Number");
  45823. break;
  45824. }
  45825. }
  45826. }
  45827. return types.size ? [...types] : ["Number"];
  45828. }
  45829. function resolveExtractPropTypes({ props }, scope) {
  45830. const res = { props: {} };
  45831. for (const key in props) {
  45832. const raw = props[key];
  45833. res.props[key] = reverseInferType(
  45834. raw.key,
  45835. raw.typeAnnotation.typeAnnotation,
  45836. scope
  45837. );
  45838. }
  45839. return res;
  45840. }
  45841. function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
  45842. if (checkObjectSyntax && node.type === "TSTypeLiteral") {
  45843. const typeType = findStaticPropertyType(node, "type");
  45844. if (typeType) {
  45845. const requiredType = findStaticPropertyType(node, "required");
  45846. const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
  45847. return reverseInferType(key, typeType, scope, optional2, false);
  45848. }
  45849. } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
  45850. if (node.typeName.name.endsWith("Constructor")) {
  45851. return createProperty(
  45852. key,
  45853. ctorToType(node.typeName.name),
  45854. scope,
  45855. optional
  45856. );
  45857. } else if (node.typeName.name === "PropType" && node.typeParameters) {
  45858. return createProperty(key, node.typeParameters.params[0], scope, optional);
  45859. }
  45860. }
  45861. if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
  45862. for (const t of node.typeParameters.params) {
  45863. const inferred = reverseInferType(key, t, scope, optional);
  45864. if (inferred)
  45865. return inferred;
  45866. }
  45867. }
  45868. return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
  45869. }
  45870. function ctorToType(ctorType) {
  45871. const ctor = ctorType.slice(0, -11);
  45872. switch (ctor) {
  45873. case "String":
  45874. case "Number":
  45875. case "Boolean":
  45876. return { type: `TS${ctor}Keyword` };
  45877. case "Array":
  45878. case "Function":
  45879. case "Object":
  45880. case "Set":
  45881. case "Map":
  45882. case "WeakSet":
  45883. case "WeakMap":
  45884. case "Date":
  45885. case "Promise":
  45886. return {
  45887. type: "TSTypeReference",
  45888. typeName: { type: "Identifier", name: ctor }
  45889. };
  45890. }
  45891. return { type: `TSNullKeyword` };
  45892. }
  45893. function findStaticPropertyType(node, key) {
  45894. const prop = node.members.find(
  45895. (m) => m.type === "TSPropertySignature" && !m.computed && getId(m.key) === key && m.typeAnnotation
  45896. );
  45897. return prop && prop.typeAnnotation.typeAnnotation;
  45898. }
  45899. function resolveReturnType(ctx, arg, scope) {
  45900. var _a;
  45901. let resolved = arg;
  45902. if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
  45903. resolved = resolveTypeReference(ctx, arg, scope);
  45904. }
  45905. if (!resolved)
  45906. return;
  45907. if (resolved.type === "TSFunctionType") {
  45908. return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
  45909. }
  45910. if (resolved.type === "TSDeclareFunction") {
  45911. return resolved.returnType;
  45912. }
  45913. }
  45914. function resolveUnionType(ctx, node, scope) {
  45915. if (node.type === "TSTypeReference") {
  45916. const resolved = resolveTypeReference(ctx, node, scope);
  45917. if (resolved)
  45918. node = resolved;
  45919. }
  45920. let types;
  45921. if (node.type === "TSUnionType") {
  45922. types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
  45923. } else {
  45924. types = [node];
  45925. }
  45926. return types;
  45927. }
  45928. const DEFINE_MODEL = "defineModel";
  45929. function processDefineModel(ctx, node, declId) {
  45930. if (!isCallOf(node, DEFINE_MODEL)) {
  45931. return false;
  45932. }
  45933. if (!ctx.options.defineModel) {
  45934. warnOnce$4(
  45935. `defineModel() is an experimental feature and disabled by default.
  45936. To enable it, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
  45937. );
  45938. return false;
  45939. }
  45940. warnOnce$4(
  45941. `This project is using defineModel(), which is an experimental feature. It may receive breaking changes or be removed in the future, so use at your own risk.
  45942. To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
  45943. );
  45944. ctx.hasDefineModelCall = true;
  45945. const type = node.typeParameters && node.typeParameters.params[0] || void 0;
  45946. let modelName;
  45947. let options;
  45948. const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0]);
  45949. if (arg0 && arg0.type === "StringLiteral") {
  45950. modelName = arg0.value;
  45951. options = node.arguments[1];
  45952. } else {
  45953. modelName = "modelValue";
  45954. options = arg0;
  45955. }
  45956. if (ctx.modelDecls[modelName]) {
  45957. ctx.error(`duplicate model name ${JSON.stringify(modelName)}`, node);
  45958. }
  45959. const optionsString = options && ctx.getString(options);
  45960. ctx.modelDecls[modelName] = {
  45961. type,
  45962. options: optionsString,
  45963. identifier: declId && declId.type === "Identifier" ? declId.name : void 0
  45964. };
  45965. ctx.bindingMetadata[modelName] = "props";
  45966. let runtimeOptions = "";
  45967. if (options) {
  45968. if (options.type === "ObjectExpression") {
  45969. const local = options.properties.find(
  45970. (p) => p.type === "ObjectProperty" && (p.key.type === "Identifier" && p.key.name === "local" || p.key.type === "StringLiteral" && p.key.value === "local")
  45971. );
  45972. if (local) {
  45973. runtimeOptions = `{ ${ctx.getString(local)} }`;
  45974. } else {
  45975. for (const p of options.properties) {
  45976. if (p.type === "SpreadElement" || p.computed) {
  45977. runtimeOptions = optionsString;
  45978. break;
  45979. }
  45980. }
  45981. }
  45982. } else {
  45983. runtimeOptions = optionsString;
  45984. }
  45985. }
  45986. ctx.s.overwrite(
  45987. ctx.startOffset + node.start,
  45988. ctx.startOffset + node.end,
  45989. `${ctx.helper("useModel")}(__props, ${JSON.stringify(modelName)}${runtimeOptions ? `, ${runtimeOptions}` : ``})`
  45990. );
  45991. return true;
  45992. }
  45993. function genModelProps(ctx) {
  45994. if (!ctx.hasDefineModelCall)
  45995. return;
  45996. const isProd = !!ctx.options.isProd;
  45997. let modelPropsDecl = "";
  45998. for (const [name, { type, options }] of Object.entries(ctx.modelDecls)) {
  45999. let skipCheck = false;
  46000. let runtimeTypes = type && inferRuntimeType(ctx, type);
  46001. if (runtimeTypes) {
  46002. const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE);
  46003. runtimeTypes = runtimeTypes.filter((el) => {
  46004. if (el === UNKNOWN_TYPE)
  46005. return false;
  46006. return isProd ? el === "Boolean" || el === "Function" && options : true;
  46007. });
  46008. skipCheck = !isProd && hasUnknownType && runtimeTypes.length > 0;
  46009. }
  46010. let runtimeType = runtimeTypes && runtimeTypes.length > 0 && toRuntimeTypeString(runtimeTypes) || void 0;
  46011. const codegenOptions = concatStrings([
  46012. runtimeType && `type: ${runtimeType}`,
  46013. skipCheck && "skipCheck: true"
  46014. ]);
  46015. let decl;
  46016. if (runtimeType && options) {
  46017. decl = ctx.isTS ? `{ ${codegenOptions}, ...${options} }` : `Object.assign({ ${codegenOptions} }, ${options})`;
  46018. } else {
  46019. decl = options || (runtimeType ? `{ ${codegenOptions} }` : "{}");
  46020. }
  46021. modelPropsDecl += `
  46022. ${JSON.stringify(name)}: ${decl},`;
  46023. }
  46024. return `{${modelPropsDecl}
  46025. }`;
  46026. }
  46027. const DEFINE_PROPS = "defineProps";
  46028. const WITH_DEFAULTS = "withDefaults";
  46029. function processDefineProps(ctx, node, declId) {
  46030. if (!isCallOf(node, DEFINE_PROPS)) {
  46031. return processWithDefaults(ctx, node, declId);
  46032. }
  46033. if (ctx.hasDefinePropsCall) {
  46034. ctx.error(`duplicate ${DEFINE_PROPS}() call`, node);
  46035. }
  46036. ctx.hasDefinePropsCall = true;
  46037. ctx.propsRuntimeDecl = node.arguments[0];
  46038. if (ctx.propsRuntimeDecl) {
  46039. for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
  46040. if (!(key in ctx.bindingMetadata)) {
  46041. ctx.bindingMetadata[key] = "props";
  46042. }
  46043. }
  46044. }
  46045. if (node.typeParameters) {
  46046. if (ctx.propsRuntimeDecl) {
  46047. ctx.error(
  46048. `${DEFINE_PROPS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46049. node
  46050. );
  46051. }
  46052. ctx.propsTypeDecl = node.typeParameters.params[0];
  46053. }
  46054. if (declId && declId.type === "ObjectPattern") {
  46055. processPropsDestructure(ctx, declId);
  46056. }
  46057. ctx.propsCall = node;
  46058. ctx.propsDecl = declId;
  46059. return true;
  46060. }
  46061. function processWithDefaults(ctx, node, declId) {
  46062. if (!isCallOf(node, WITH_DEFAULTS)) {
  46063. return false;
  46064. }
  46065. if (!processDefineProps(ctx, node.arguments[0], declId)) {
  46066. ctx.error(
  46067. `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,
  46068. node.arguments[0] || node
  46069. );
  46070. }
  46071. if (ctx.propsRuntimeDecl) {
  46072. ctx.error(
  46073. `${WITH_DEFAULTS} can only be used with type-based ${DEFINE_PROPS} declaration.`,
  46074. node
  46075. );
  46076. }
  46077. if (ctx.propsDestructureDecl) {
  46078. ctx.error(
  46079. `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().
  46080. Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...).`,
  46081. node.callee
  46082. );
  46083. }
  46084. ctx.propsRuntimeDefaults = node.arguments[1];
  46085. if (!ctx.propsRuntimeDefaults) {
  46086. ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
  46087. }
  46088. ctx.propsCall = node;
  46089. return true;
  46090. }
  46091. function genRuntimeProps(ctx) {
  46092. let propsDecls;
  46093. if (ctx.propsRuntimeDecl) {
  46094. propsDecls = ctx.getString(ctx.propsRuntimeDecl).trim();
  46095. if (ctx.propsDestructureDecl) {
  46096. const defaults = [];
  46097. for (const key in ctx.propsDestructuredBindings) {
  46098. const d = genDestructuredDefaultValue(ctx, key);
  46099. const finalKey = getEscapedPropName(key);
  46100. if (d)
  46101. defaults.push(
  46102. `${finalKey}: ${d.valueString}${d.needSkipFactory ? `, __skip_${finalKey}: true` : ``}`
  46103. );
  46104. }
  46105. if (defaults.length) {
  46106. propsDecls = `/*#__PURE__*/${ctx.helper(
  46107. `mergeDefaults`
  46108. )}(${propsDecls}, {
  46109. ${defaults.join(",\n ")}
  46110. })`;
  46111. }
  46112. }
  46113. } else if (ctx.propsTypeDecl) {
  46114. propsDecls = genRuntimePropsFromTypes(ctx);
  46115. }
  46116. const modelsDecls = genModelProps(ctx);
  46117. if (propsDecls && modelsDecls) {
  46118. return `/*#__PURE__*/${ctx.helper(
  46119. "mergeModels"
  46120. )}(${propsDecls}, ${modelsDecls})`;
  46121. } else {
  46122. return modelsDecls || propsDecls;
  46123. }
  46124. }
  46125. function genRuntimePropsFromTypes(ctx) {
  46126. const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl);
  46127. if (!props.length) {
  46128. return;
  46129. }
  46130. const propStrings = [];
  46131. const hasStaticDefaults = hasStaticWithDefaults(ctx);
  46132. for (const prop of props) {
  46133. propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults));
  46134. if (!(prop.key in ctx.bindingMetadata)) {
  46135. ctx.bindingMetadata[prop.key] = "props";
  46136. }
  46137. }
  46138. let propsDecls = `{
  46139. ${propStrings.join(",\n ")}
  46140. }`;
  46141. if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
  46142. propsDecls = `/*#__PURE__*/${ctx.helper(
  46143. "mergeDefaults"
  46144. )}(${propsDecls}, ${ctx.getString(ctx.propsRuntimeDefaults)})`;
  46145. }
  46146. return propsDecls;
  46147. }
  46148. function resolveRuntimePropsFromType(ctx, node) {
  46149. const props = [];
  46150. const elements = resolveTypeElements(ctx, node);
  46151. for (const key in elements.props) {
  46152. const e = elements.props[key];
  46153. let type = inferRuntimeType(ctx, e);
  46154. let skipCheck = false;
  46155. if (type.includes(UNKNOWN_TYPE)) {
  46156. if (type.includes("Boolean") || type.includes("Function")) {
  46157. type = type.filter((t) => t !== UNKNOWN_TYPE);
  46158. skipCheck = true;
  46159. } else {
  46160. type = ["null"];
  46161. }
  46162. }
  46163. props.push({
  46164. key,
  46165. required: !e.optional,
  46166. type: type || [`null`],
  46167. skipCheck
  46168. });
  46169. }
  46170. return props;
  46171. }
  46172. function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStaticDefaults) {
  46173. let defaultString;
  46174. const destructured = genDestructuredDefaultValue(ctx, key, type);
  46175. if (destructured) {
  46176. defaultString = `default: ${destructured.valueString}${destructured.needSkipFactory ? `, skipFactory: true` : ``}`;
  46177. } else if (hasStaticDefaults) {
  46178. const prop = ctx.propsRuntimeDefaults.properties.find(
  46179. (node) => {
  46180. if (node.type === "SpreadElement")
  46181. return false;
  46182. return resolveObjectKey(node.key, node.computed) === key;
  46183. }
  46184. );
  46185. if (prop) {
  46186. if (prop.type === "ObjectProperty") {
  46187. defaultString = `default: ${ctx.getString(prop.value)}`;
  46188. } else {
  46189. defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default() ${ctx.getString(prop.body)}`;
  46190. }
  46191. }
  46192. }
  46193. const finalKey = getEscapedPropName(key);
  46194. if (!ctx.options.isProd) {
  46195. return `${finalKey}: { ${concatStrings([
  46196. `type: ${toRuntimeTypeString(type)}`,
  46197. `required: ${required}`,
  46198. skipCheck && "skipCheck: true",
  46199. defaultString
  46200. ])} }`;
  46201. } else if (type.some(
  46202. (el) => el === "Boolean" || (!hasStaticDefaults || defaultString) && el === "Function"
  46203. )) {
  46204. return `${finalKey}: { ${concatStrings([
  46205. `type: ${toRuntimeTypeString(type)}`,
  46206. defaultString
  46207. ])} }`;
  46208. } else {
  46209. if (ctx.isCE) {
  46210. if (defaultString) {
  46211. return `${finalKey}: ${`{ ${defaultString}, type: ${toRuntimeTypeString(
  46212. type
  46213. )} }`}`;
  46214. } else {
  46215. return `${finalKey}: {type: ${toRuntimeTypeString(type)}}`;
  46216. }
  46217. }
  46218. return `${finalKey}: ${defaultString ? `{ ${defaultString} }` : `{}`}`;
  46219. }
  46220. }
  46221. function hasStaticWithDefaults(ctx) {
  46222. return !!(ctx.propsRuntimeDefaults && ctx.propsRuntimeDefaults.type === "ObjectExpression" && ctx.propsRuntimeDefaults.properties.every(
  46223. (node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
  46224. ));
  46225. }
  46226. function genDestructuredDefaultValue(ctx, key, inferredType) {
  46227. const destructured = ctx.propsDestructuredBindings[key];
  46228. const defaultVal = destructured && destructured.default;
  46229. if (defaultVal) {
  46230. const value = ctx.getString(defaultVal);
  46231. const unwrapped = unwrapTSNode(defaultVal);
  46232. if (inferredType && inferredType.length && !inferredType.includes("null")) {
  46233. const valueType = inferValueType(unwrapped);
  46234. if (valueType && !inferredType.includes(valueType)) {
  46235. ctx.error(
  46236. `Default value of prop "${key}" does not match declared type.`,
  46237. unwrapped
  46238. );
  46239. }
  46240. }
  46241. const needSkipFactory = !inferredType && (isFunctionType(unwrapped) || unwrapped.type === "Identifier");
  46242. const needFactoryWrap = !needSkipFactory && !isLiteralNode(unwrapped) && !(inferredType == null ? void 0 : inferredType.includes("Function"));
  46243. return {
  46244. valueString: needFactoryWrap ? `() => (${value})` : value,
  46245. needSkipFactory
  46246. };
  46247. }
  46248. }
  46249. function inferValueType(node) {
  46250. switch (node.type) {
  46251. case "StringLiteral":
  46252. return "String";
  46253. case "NumericLiteral":
  46254. return "Number";
  46255. case "BooleanLiteral":
  46256. return "Boolean";
  46257. case "ObjectExpression":
  46258. return "Object";
  46259. case "ArrayExpression":
  46260. return "Array";
  46261. case "FunctionExpression":
  46262. case "ArrowFunctionExpression":
  46263. return "Function";
  46264. }
  46265. }
  46266. function processPropsDestructure(ctx, declId) {
  46267. if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
  46268. return;
  46269. }
  46270. warnOnce$4(
  46271. `This project is using reactive props destructure, which is an experimental feature. It may receive breaking changes or be removed in the future, so use at your own risk.
  46272. To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/502.`
  46273. );
  46274. ctx.propsDestructureDecl = declId;
  46275. const registerBinding = (key, local, defaultValue) => {
  46276. ctx.propsDestructuredBindings[key] = { local, default: defaultValue };
  46277. if (local !== key) {
  46278. ctx.bindingMetadata[local] = "props-aliased";
  46279. (ctx.bindingMetadata.__propsAliases || (ctx.bindingMetadata.__propsAliases = {}))[local] = key;
  46280. }
  46281. };
  46282. for (const prop of declId.properties) {
  46283. if (prop.type === "ObjectProperty") {
  46284. const propKey = resolveObjectKey(prop.key, prop.computed);
  46285. if (!propKey) {
  46286. ctx.error(
  46287. `${DEFINE_PROPS}() destructure cannot use computed key.`,
  46288. prop.key
  46289. );
  46290. }
  46291. if (prop.value.type === "AssignmentPattern") {
  46292. const { left, right } = prop.value;
  46293. if (left.type !== "Identifier") {
  46294. ctx.error(
  46295. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46296. left
  46297. );
  46298. }
  46299. registerBinding(propKey, left.name, right);
  46300. } else if (prop.value.type === "Identifier") {
  46301. registerBinding(propKey, prop.value.name);
  46302. } else {
  46303. ctx.error(
  46304. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46305. prop.value
  46306. );
  46307. }
  46308. } else {
  46309. ctx.propsDestructureRestId = prop.argument.name;
  46310. ctx.bindingMetadata[ctx.propsDestructureRestId] = "setup-reactive-const";
  46311. }
  46312. }
  46313. }
  46314. function transformDestructuredProps(ctx, vueImportAliases) {
  46315. if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
  46316. return;
  46317. }
  46318. const rootScope = {};
  46319. const scopeStack = [rootScope];
  46320. let currentScope = rootScope;
  46321. const excludedIds = /* @__PURE__ */ new WeakSet();
  46322. const parentStack = [];
  46323. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  46324. for (const key in ctx.propsDestructuredBindings) {
  46325. const { local } = ctx.propsDestructuredBindings[key];
  46326. rootScope[local] = true;
  46327. propsLocalToPublicMap[local] = key;
  46328. }
  46329. function pushScope() {
  46330. scopeStack.push(currentScope = Object.create(currentScope));
  46331. }
  46332. function popScope() {
  46333. scopeStack.pop();
  46334. currentScope = scopeStack[scopeStack.length - 1] || null;
  46335. }
  46336. function registerLocalBinding(id) {
  46337. excludedIds.add(id);
  46338. if (currentScope) {
  46339. currentScope[id.name] = false;
  46340. } else {
  46341. ctx.error(
  46342. "registerBinding called without active scope, something is wrong.",
  46343. id
  46344. );
  46345. }
  46346. }
  46347. function walkScope(node, isRoot = false) {
  46348. for (const stmt of node.body) {
  46349. if (stmt.type === "VariableDeclaration") {
  46350. walkVariableDeclaration(stmt, isRoot);
  46351. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  46352. if (stmt.declare || !stmt.id)
  46353. continue;
  46354. registerLocalBinding(stmt.id);
  46355. } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
  46356. walkVariableDeclaration(stmt.left);
  46357. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  46358. walkVariableDeclaration(stmt.declaration, isRoot);
  46359. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  46360. walkVariableDeclaration(stmt.body, isRoot);
  46361. }
  46362. }
  46363. }
  46364. function walkVariableDeclaration(stmt, isRoot = false) {
  46365. if (stmt.declare) {
  46366. return;
  46367. }
  46368. for (const decl of stmt.declarations) {
  46369. const isDefineProps = isRoot && decl.init && isCallOf(unwrapTSNode(decl.init), "defineProps");
  46370. for (const id of extractIdentifiers(decl.id)) {
  46371. if (isDefineProps) {
  46372. excludedIds.add(id);
  46373. } else {
  46374. registerLocalBinding(id);
  46375. }
  46376. }
  46377. }
  46378. }
  46379. function rewriteId(id, parent, parentStack2) {
  46380. if (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression") {
  46381. ctx.error(`Cannot assign to destructured props as they are readonly.`, id);
  46382. }
  46383. if (isStaticProperty(parent) && parent.shorthand) {
  46384. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  46385. ctx.s.appendLeft(
  46386. id.end + ctx.startOffset,
  46387. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  46388. );
  46389. }
  46390. } else {
  46391. ctx.s.overwrite(
  46392. id.start + ctx.startOffset,
  46393. id.end + ctx.startOffset,
  46394. genPropsAccessExp(propsLocalToPublicMap[id.name])
  46395. );
  46396. }
  46397. }
  46398. function checkUsage(node, method, alias = method) {
  46399. if (isCallOf(node, alias)) {
  46400. const arg = unwrapTSNode(node.arguments[0]);
  46401. if (arg.type === "Identifier" && currentScope[arg.name]) {
  46402. ctx.error(
  46403. `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
  46404. arg
  46405. );
  46406. }
  46407. }
  46408. }
  46409. const ast = ctx.scriptSetupAst;
  46410. walkScope(ast, true);
  46411. walk$1(ast, {
  46412. enter(node, parent) {
  46413. parent && parentStack.push(parent);
  46414. if (parent && parent.type.startsWith("TS") && parent.type !== "TSAsExpression" && parent.type !== "TSNonNullExpression" && parent.type !== "TSTypeAssertion") {
  46415. return this.skip();
  46416. }
  46417. checkUsage(node, "watch", vueImportAliases.watch);
  46418. checkUsage(node, "toRef", vueImportAliases.toRef);
  46419. if (isFunctionType(node)) {
  46420. pushScope();
  46421. walkFunctionParams(node, registerLocalBinding);
  46422. if (node.body.type === "BlockStatement") {
  46423. walkScope(node.body);
  46424. }
  46425. return;
  46426. }
  46427. if (node.type === "CatchClause") {
  46428. pushScope();
  46429. if (node.param && node.param.type === "Identifier") {
  46430. registerLocalBinding(node.param);
  46431. }
  46432. walkScope(node.body);
  46433. return;
  46434. }
  46435. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  46436. pushScope();
  46437. walkScope(node);
  46438. return;
  46439. }
  46440. if (node.type === "Identifier") {
  46441. if (isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)) {
  46442. if (currentScope[node.name]) {
  46443. rewriteId(node, parent, parentStack);
  46444. }
  46445. }
  46446. }
  46447. },
  46448. leave(node, parent) {
  46449. parent && parentStack.pop();
  46450. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node)) {
  46451. popScope();
  46452. }
  46453. }
  46454. });
  46455. }
  46456. const DEFINE_EMITS = "defineEmits";
  46457. function processDefineEmits(ctx, node, declId) {
  46458. if (!isCallOf(node, DEFINE_EMITS)) {
  46459. return false;
  46460. }
  46461. if (ctx.hasDefineEmitCall) {
  46462. ctx.error(`duplicate ${DEFINE_EMITS}() call`, node);
  46463. }
  46464. ctx.hasDefineEmitCall = true;
  46465. ctx.emitsRuntimeDecl = node.arguments[0];
  46466. if (node.typeParameters) {
  46467. if (ctx.emitsRuntimeDecl) {
  46468. ctx.error(
  46469. `${DEFINE_EMITS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46470. node
  46471. );
  46472. }
  46473. ctx.emitsTypeDecl = node.typeParameters.params[0];
  46474. }
  46475. ctx.emitDecl = declId;
  46476. return true;
  46477. }
  46478. function genRuntimeEmits(ctx) {
  46479. let emitsDecl = "";
  46480. if (ctx.emitsRuntimeDecl) {
  46481. emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim();
  46482. } else if (ctx.emitsTypeDecl) {
  46483. const typeDeclaredEmits = extractRuntimeEmits(ctx);
  46484. emitsDecl = typeDeclaredEmits.size ? `[${Array.from(typeDeclaredEmits).map((k) => JSON.stringify(k)).join(", ")}]` : ``;
  46485. }
  46486. if (ctx.hasDefineModelCall) {
  46487. let modelEmitsDecl = `[${Object.keys(ctx.modelDecls).map((n) => JSON.stringify(`update:${n}`)).join(", ")}]`;
  46488. emitsDecl = emitsDecl ? `/*#__PURE__*/${ctx.helper(
  46489. "mergeModels"
  46490. )}(${emitsDecl}, ${modelEmitsDecl})` : modelEmitsDecl;
  46491. }
  46492. return emitsDecl;
  46493. }
  46494. function extractRuntimeEmits(ctx) {
  46495. const emits = /* @__PURE__ */ new Set();
  46496. const node = ctx.emitsTypeDecl;
  46497. if (node.type === "TSFunctionType") {
  46498. extractEventNames(ctx, node.parameters[0], emits);
  46499. return emits;
  46500. }
  46501. const { props, calls } = resolveTypeElements(ctx, node);
  46502. let hasProperty = false;
  46503. for (const key in props) {
  46504. emits.add(key);
  46505. hasProperty = true;
  46506. }
  46507. if (calls) {
  46508. if (hasProperty) {
  46509. ctx.error(
  46510. `defineEmits() type cannot mixed call signature and property syntax.`,
  46511. node
  46512. );
  46513. }
  46514. for (const call of calls) {
  46515. extractEventNames(ctx, call.parameters[0], emits);
  46516. }
  46517. }
  46518. return emits;
  46519. }
  46520. function extractEventNames(ctx, eventName, emits) {
  46521. if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
  46522. const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
  46523. for (const type of types) {
  46524. if (type.type === "TSLiteralType") {
  46525. if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
  46526. emits.add(String(type.literal.value));
  46527. }
  46528. }
  46529. }
  46530. }
  46531. }
  46532. const DEFINE_EXPOSE = "defineExpose";
  46533. function processDefineExpose(ctx, node) {
  46534. if (isCallOf(node, DEFINE_EXPOSE)) {
  46535. if (ctx.hasDefineExposeCall) {
  46536. ctx.error(`duplicate ${DEFINE_EXPOSE}() call`, node);
  46537. }
  46538. ctx.hasDefineExposeCall = true;
  46539. return true;
  46540. }
  46541. return false;
  46542. }
  46543. const DEFINE_SLOTS = "defineSlots";
  46544. function processDefineSlots(ctx, node, declId) {
  46545. if (!isCallOf(node, DEFINE_SLOTS)) {
  46546. return false;
  46547. }
  46548. if (ctx.hasDefineSlotsCall) {
  46549. ctx.error(`duplicate ${DEFINE_SLOTS}() call`, node);
  46550. }
  46551. ctx.hasDefineSlotsCall = true;
  46552. if (node.arguments.length > 0) {
  46553. ctx.error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
  46554. }
  46555. if (declId) {
  46556. ctx.s.overwrite(
  46557. ctx.startOffset + node.start,
  46558. ctx.startOffset + node.end,
  46559. `${ctx.helper("useSlots")}()`
  46560. );
  46561. }
  46562. return true;
  46563. }
  46564. const DEFINE_OPTIONS = "defineOptions";
  46565. function processDefineOptions(ctx, node) {
  46566. if (!isCallOf(node, DEFINE_OPTIONS)) {
  46567. return false;
  46568. }
  46569. if (ctx.hasDefineOptionsCall) {
  46570. ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node);
  46571. }
  46572. if (node.typeParameters) {
  46573. ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
  46574. }
  46575. if (!node.arguments[0])
  46576. return true;
  46577. ctx.hasDefineOptionsCall = true;
  46578. ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0]);
  46579. let propsOption = void 0;
  46580. let emitsOption = void 0;
  46581. let exposeOption = void 0;
  46582. let slotsOption = void 0;
  46583. if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
  46584. for (const prop of ctx.optionsRuntimeDecl.properties) {
  46585. if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
  46586. if (prop.key.name === "props")
  46587. propsOption = prop;
  46588. if (prop.key.name === "emits")
  46589. emitsOption = prop;
  46590. if (prop.key.name === "expose")
  46591. exposeOption = prop;
  46592. if (prop.key.name === "slots")
  46593. slotsOption = prop;
  46594. }
  46595. }
  46596. }
  46597. if (propsOption) {
  46598. ctx.error(
  46599. `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
  46600. propsOption
  46601. );
  46602. }
  46603. if (emitsOption) {
  46604. ctx.error(
  46605. `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,
  46606. emitsOption
  46607. );
  46608. }
  46609. if (exposeOption) {
  46610. ctx.error(
  46611. `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`,
  46612. exposeOption
  46613. );
  46614. }
  46615. if (slotsOption) {
  46616. ctx.error(
  46617. `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
  46618. slotsOption
  46619. );
  46620. }
  46621. return true;
  46622. }
  46623. function processAwait(ctx, node, needSemi, isStatement) {
  46624. const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
  46625. const startOffset = ctx.startOffset;
  46626. const argumentStr = ctx.descriptor.source.slice(
  46627. argumentStart + startOffset,
  46628. node.argument.end + startOffset
  46629. );
  46630. const containsNestedAwait = /\bawait\b/.test(argumentStr);
  46631. ctx.s.overwrite(
  46632. node.start + startOffset,
  46633. argumentStart + startOffset,
  46634. `${needSemi ? `;` : ``}(
  46635. ([__temp,__restore] = ${ctx.helper(
  46636. `withAsyncContext`
  46637. )}(${containsNestedAwait ? `async ` : ``}() => `
  46638. );
  46639. ctx.s.appendLeft(
  46640. node.end + startOffset,
  46641. `)),
  46642. ${isStatement ? `` : `__temp = `}await __temp,
  46643. __restore()${isStatement ? `` : `,
  46644. __temp`}
  46645. )`
  46646. );
  46647. }
  46648. var __defProp = Object.defineProperty;
  46649. var __defProps = Object.defineProperties;
  46650. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  46651. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  46652. var __hasOwnProp = Object.prototype.hasOwnProperty;
  46653. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  46654. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  46655. var __spreadValues = (a, b) => {
  46656. for (var prop in b || (b = {}))
  46657. if (__hasOwnProp.call(b, prop))
  46658. __defNormalProp(a, prop, b[prop]);
  46659. if (__getOwnPropSymbols)
  46660. for (var prop of __getOwnPropSymbols(b)) {
  46661. if (__propIsEnum.call(b, prop))
  46662. __defNormalProp(a, prop, b[prop]);
  46663. }
  46664. return a;
  46665. };
  46666. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  46667. function compileScript(sfc, options) {
  46668. var _a;
  46669. if (!options.id) {
  46670. warnOnce$4(
  46671. `compileScript now requires passing the \`id\` option.
  46672. Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
  46673. );
  46674. }
  46675. const ctx = new ScriptCompileContext(sfc, options);
  46676. const { script, scriptSetup, source, filename } = sfc;
  46677. const hoistStatic = options.hoistStatic !== false && !script;
  46678. const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
  46679. const scriptLang = script && script.lang;
  46680. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  46681. const enableReactivityTransform = !!options.reactivityTransform;
  46682. let refBindings;
  46683. if (!scriptSetup) {
  46684. if (!script) {
  46685. throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
  46686. }
  46687. return processNormalScript(ctx, scopeId);
  46688. }
  46689. if (script && scriptLang !== scriptSetupLang) {
  46690. throw new Error(
  46691. `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
  46692. );
  46693. }
  46694. if (scriptSetupLang && !ctx.isJS && !ctx.isTS) {
  46695. return scriptSetup;
  46696. }
  46697. const scriptBindings = /* @__PURE__ */ Object.create(null);
  46698. const setupBindings = /* @__PURE__ */ Object.create(null);
  46699. let defaultExport;
  46700. let hasAwait = false;
  46701. let hasInlinedSsrRenderFn = false;
  46702. const startOffset = ctx.startOffset;
  46703. const endOffset = ctx.endOffset;
  46704. const scriptStartOffset = script && script.loc.start.offset;
  46705. const scriptEndOffset = script && script.loc.end.offset;
  46706. function hoistNode(node) {
  46707. const start = node.start + startOffset;
  46708. let end = node.end + startOffset;
  46709. if (node.trailingComments && node.trailingComments.length > 0) {
  46710. const lastCommentNode = node.trailingComments[node.trailingComments.length - 1];
  46711. end = lastCommentNode.end + startOffset;
  46712. }
  46713. while (end <= source.length) {
  46714. if (!/\s/.test(source.charAt(end))) {
  46715. break;
  46716. }
  46717. end++;
  46718. }
  46719. ctx.s.move(start, end, 0);
  46720. }
  46721. function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
  46722. let isUsedInTemplate = needTemplateUsageCheck;
  46723. if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
  46724. isUsedInTemplate = isImportUsed(local, sfc);
  46725. }
  46726. ctx.userImports[local] = {
  46727. isType,
  46728. imported,
  46729. local,
  46730. source: source2,
  46731. isFromSetup,
  46732. isUsedInTemplate
  46733. };
  46734. }
  46735. function checkInvalidScopeReference(node, method) {
  46736. if (!node)
  46737. return;
  46738. walkIdentifiers(node, (id) => {
  46739. const binding = setupBindings[id.name];
  46740. if (binding && binding !== "literal-const") {
  46741. ctx.error(
  46742. `\`${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.`,
  46743. id
  46744. );
  46745. }
  46746. });
  46747. }
  46748. const scriptAst = ctx.scriptAst;
  46749. const scriptSetupAst = ctx.scriptSetupAst;
  46750. if (scriptAst) {
  46751. for (const node of scriptAst.body) {
  46752. if (node.type === "ImportDeclaration") {
  46753. for (const specifier of node.specifiers) {
  46754. const imported = getImportedName(specifier);
  46755. registerUserImport(
  46756. node.source.value,
  46757. specifier.local.name,
  46758. imported,
  46759. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  46760. false,
  46761. !options.inlineTemplate
  46762. );
  46763. }
  46764. }
  46765. }
  46766. }
  46767. for (const node of scriptSetupAst.body) {
  46768. if (node.type === "ImportDeclaration") {
  46769. hoistNode(node);
  46770. let removed = 0;
  46771. const removeSpecifier = (i) => {
  46772. const removeLeft = i > removed;
  46773. removed++;
  46774. const current = node.specifiers[i];
  46775. const next = node.specifiers[i + 1];
  46776. ctx.s.remove(
  46777. removeLeft ? node.specifiers[i - 1].end + startOffset : current.start + startOffset,
  46778. next && !removeLeft ? next.start + startOffset : current.end + startOffset
  46779. );
  46780. };
  46781. for (let i = 0; i < node.specifiers.length; i++) {
  46782. const specifier = node.specifiers[i];
  46783. const local = specifier.local.name;
  46784. const imported = getImportedName(specifier);
  46785. const source2 = node.source.value;
  46786. const existing = ctx.userImports[local];
  46787. if (source2 === "vue" && (imported === DEFINE_PROPS || imported === DEFINE_EMITS || imported === DEFINE_EXPOSE)) {
  46788. warnOnce$4(
  46789. `\`${imported}\` is a compiler macro and no longer needs to be imported.`
  46790. );
  46791. removeSpecifier(i);
  46792. } else if (existing) {
  46793. if (existing.source === source2 && existing.imported === imported) {
  46794. removeSpecifier(i);
  46795. } else {
  46796. ctx.error(
  46797. `different imports aliased to same local name.`,
  46798. specifier
  46799. );
  46800. }
  46801. } else {
  46802. registerUserImport(
  46803. source2,
  46804. local,
  46805. imported,
  46806. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  46807. true,
  46808. !options.inlineTemplate
  46809. );
  46810. }
  46811. }
  46812. if (node.specifiers.length && removed === node.specifiers.length) {
  46813. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  46814. }
  46815. }
  46816. }
  46817. const vueImportAliases = {};
  46818. for (const key in ctx.userImports) {
  46819. const { source: source2, imported, local } = ctx.userImports[key];
  46820. if (source2 === "vue")
  46821. vueImportAliases[imported] = local;
  46822. }
  46823. if (script && scriptAst) {
  46824. for (const node of scriptAst.body) {
  46825. if (node.type === "ExportDefaultDeclaration") {
  46826. defaultExport = node;
  46827. let optionProperties;
  46828. if (defaultExport.declaration.type === "ObjectExpression") {
  46829. optionProperties = defaultExport.declaration.properties;
  46830. } else if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.arguments[0] && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
  46831. optionProperties = defaultExport.declaration.arguments[0].properties;
  46832. }
  46833. if (optionProperties) {
  46834. for (const p of optionProperties) {
  46835. if (p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name") {
  46836. ctx.hasDefaultExportName = true;
  46837. }
  46838. if ((p.type === "ObjectMethod" || p.type === "ObjectProperty") && p.key.type === "Identifier" && p.key.name === "render") {
  46839. ctx.hasDefaultExportRender = true;
  46840. }
  46841. }
  46842. }
  46843. const start = node.start + scriptStartOffset;
  46844. const end = node.declaration.start + scriptStartOffset;
  46845. ctx.s.overwrite(start, end, `const ${normalScriptDefaultVar} = `);
  46846. } else if (node.type === "ExportNamedDeclaration") {
  46847. const defaultSpecifier = node.specifiers.find(
  46848. (s) => s.exported.type === "Identifier" && s.exported.name === "default"
  46849. );
  46850. if (defaultSpecifier) {
  46851. defaultExport = node;
  46852. if (node.specifiers.length > 1) {
  46853. ctx.s.remove(
  46854. defaultSpecifier.start + scriptStartOffset,
  46855. defaultSpecifier.end + scriptStartOffset
  46856. );
  46857. } else {
  46858. ctx.s.remove(
  46859. node.start + scriptStartOffset,
  46860. node.end + scriptStartOffset
  46861. );
  46862. }
  46863. if (node.source) {
  46864. ctx.s.prepend(
  46865. `import { ${defaultSpecifier.local.name} as ${normalScriptDefaultVar} } from '${node.source.value}'
  46866. `
  46867. );
  46868. } else {
  46869. ctx.s.appendLeft(
  46870. scriptEndOffset,
  46871. `
  46872. const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
  46873. `
  46874. );
  46875. }
  46876. }
  46877. if (node.declaration) {
  46878. walkDeclaration(
  46879. "script",
  46880. node.declaration,
  46881. scriptBindings,
  46882. vueImportAliases,
  46883. hoistStatic
  46884. );
  46885. }
  46886. } else if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  46887. walkDeclaration(
  46888. "script",
  46889. node,
  46890. scriptBindings,
  46891. vueImportAliases,
  46892. hoistStatic
  46893. );
  46894. }
  46895. }
  46896. if (enableReactivityTransform && shouldTransform(script.content)) {
  46897. const { rootRefs, importedHelpers } = transformAST(
  46898. scriptAst,
  46899. ctx.s,
  46900. scriptStartOffset
  46901. );
  46902. refBindings = rootRefs;
  46903. for (const h of importedHelpers) {
  46904. ctx.helperImports.add(h);
  46905. }
  46906. }
  46907. if (scriptStartOffset > startOffset) {
  46908. if (!/\n$/.test(script.content.trim())) {
  46909. ctx.s.appendLeft(scriptEndOffset, `
  46910. `);
  46911. }
  46912. ctx.s.move(scriptStartOffset, scriptEndOffset, 0);
  46913. }
  46914. }
  46915. for (const node of scriptSetupAst.body) {
  46916. if (node.type === "ExpressionStatement") {
  46917. const expr = unwrapTSNode(node.expression);
  46918. if (processDefineProps(ctx, expr) || processDefineEmits(ctx, expr) || processDefineOptions(ctx, expr) || processDefineSlots(ctx, expr)) {
  46919. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  46920. } else if (processDefineExpose(ctx, expr)) {
  46921. const callee = expr.callee;
  46922. ctx.s.overwrite(
  46923. callee.start + startOffset,
  46924. callee.end + startOffset,
  46925. "__expose"
  46926. );
  46927. } else {
  46928. processDefineModel(ctx, expr);
  46929. }
  46930. }
  46931. if (node.type === "VariableDeclaration" && !node.declare) {
  46932. const total = node.declarations.length;
  46933. let left = total;
  46934. let lastNonRemoved;
  46935. for (let i = 0; i < total; i++) {
  46936. const decl = node.declarations[i];
  46937. const init = decl.init && unwrapTSNode(decl.init);
  46938. if (init) {
  46939. if (processDefineOptions(ctx, init)) {
  46940. ctx.error(
  46941. `${DEFINE_OPTIONS}() has no returning value, it cannot be assigned.`,
  46942. node
  46943. );
  46944. }
  46945. const isDefineProps = processDefineProps(ctx, init, decl.id);
  46946. const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
  46947. !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
  46948. if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
  46949. if (left === 1) {
  46950. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  46951. } else {
  46952. let start = decl.start + startOffset;
  46953. let end = decl.end + startOffset;
  46954. if (i === total - 1) {
  46955. start = node.declarations[lastNonRemoved].end + startOffset;
  46956. } else {
  46957. end = node.declarations[i + 1].start + startOffset;
  46958. }
  46959. ctx.s.remove(start, end);
  46960. left--;
  46961. }
  46962. } else if (isDefineEmits) {
  46963. ctx.s.overwrite(
  46964. startOffset + init.start,
  46965. startOffset + init.end,
  46966. "__emit"
  46967. );
  46968. } else {
  46969. lastNonRemoved = i;
  46970. }
  46971. }
  46972. }
  46973. }
  46974. let isAllLiteral = false;
  46975. if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  46976. isAllLiteral = walkDeclaration(
  46977. "scriptSetup",
  46978. node,
  46979. setupBindings,
  46980. vueImportAliases,
  46981. hoistStatic
  46982. );
  46983. }
  46984. if (hoistStatic && isAllLiteral) {
  46985. hoistNode(node);
  46986. }
  46987. if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
  46988. const scope = [scriptSetupAst.body];
  46989. walk$1(node, {
  46990. enter(child, parent) {
  46991. if (isFunctionType(child)) {
  46992. this.skip();
  46993. }
  46994. if (child.type === "BlockStatement") {
  46995. scope.push(child.body);
  46996. }
  46997. if (child.type === "AwaitExpression") {
  46998. hasAwait = true;
  46999. const currentScope = scope[scope.length - 1];
  47000. const needsSemi = currentScope.some((n, i) => {
  47001. return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
  47002. });
  47003. processAwait(
  47004. ctx,
  47005. child,
  47006. needsSemi,
  47007. parent.type === "ExpressionStatement"
  47008. );
  47009. }
  47010. },
  47011. exit(node2) {
  47012. if (node2.type === "BlockStatement")
  47013. scope.pop();
  47014. }
  47015. });
  47016. }
  47017. if (node.type === "ExportNamedDeclaration" && node.exportKind !== "type" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration") {
  47018. ctx.error(
  47019. `<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.`,
  47020. node
  47021. );
  47022. }
  47023. if (ctx.isTS) {
  47024. if (node.type.startsWith("TS") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "VariableDeclaration" && node.declare) {
  47025. if (node.type !== "TSEnumDeclaration") {
  47026. hoistNode(node);
  47027. }
  47028. }
  47029. }
  47030. }
  47031. if (ctx.propsDestructureDecl) {
  47032. transformDestructuredProps(ctx, vueImportAliases);
  47033. }
  47034. if (enableReactivityTransform && // normal <script> had ref bindings that maybe used in <script setup>
  47035. (refBindings || shouldTransform(scriptSetup.content))) {
  47036. const { rootRefs, importedHelpers } = transformAST(
  47037. scriptSetupAst,
  47038. ctx.s,
  47039. startOffset,
  47040. refBindings
  47041. );
  47042. refBindings = refBindings ? [...refBindings, ...rootRefs] : rootRefs;
  47043. for (const h of importedHelpers) {
  47044. ctx.helperImports.add(h);
  47045. }
  47046. }
  47047. checkInvalidScopeReference(ctx.propsRuntimeDecl, DEFINE_PROPS);
  47048. checkInvalidScopeReference(ctx.propsRuntimeDefaults, DEFINE_PROPS);
  47049. checkInvalidScopeReference(ctx.propsDestructureDecl, DEFINE_PROPS);
  47050. checkInvalidScopeReference(ctx.emitsRuntimeDecl, DEFINE_EMITS);
  47051. checkInvalidScopeReference(ctx.optionsRuntimeDecl, DEFINE_OPTIONS);
  47052. if (script) {
  47053. if (startOffset < scriptStartOffset) {
  47054. ctx.s.remove(0, startOffset);
  47055. ctx.s.remove(endOffset, scriptStartOffset);
  47056. ctx.s.remove(scriptEndOffset, source.length);
  47057. } else {
  47058. ctx.s.remove(0, scriptStartOffset);
  47059. ctx.s.remove(scriptEndOffset, startOffset);
  47060. ctx.s.remove(endOffset, source.length);
  47061. }
  47062. } else {
  47063. ctx.s.remove(0, startOffset);
  47064. ctx.s.remove(endOffset, source.length);
  47065. }
  47066. if (scriptAst) {
  47067. Object.assign(ctx.bindingMetadata, analyzeScriptBindings(scriptAst.body));
  47068. }
  47069. for (const [key, { isType, imported, source: source2 }] of Object.entries(
  47070. ctx.userImports
  47071. )) {
  47072. if (isType)
  47073. continue;
  47074. ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
  47075. }
  47076. for (const key in scriptBindings) {
  47077. ctx.bindingMetadata[key] = scriptBindings[key];
  47078. }
  47079. for (const key in setupBindings) {
  47080. ctx.bindingMetadata[key] = setupBindings[key];
  47081. }
  47082. if (refBindings) {
  47083. for (const key of refBindings) {
  47084. ctx.bindingMetadata[key] = "setup-ref";
  47085. }
  47086. }
  47087. if (sfc.cssVars.length && // no need to do this when targeting SSR
  47088. !((_a = options.templateOptions) == null ? void 0 : _a.ssr)) {
  47089. ctx.helperImports.add(CSS_VARS_HELPER);
  47090. ctx.helperImports.add("unref");
  47091. ctx.s.prependLeft(
  47092. startOffset,
  47093. `
  47094. ${genCssVarsCode(
  47095. sfc.cssVars,
  47096. ctx.bindingMetadata,
  47097. scopeId,
  47098. !!options.isProd
  47099. )}
  47100. `
  47101. );
  47102. }
  47103. let args = `__props`;
  47104. if (ctx.propsTypeDecl) {
  47105. args += `: any`;
  47106. }
  47107. if (ctx.propsDecl) {
  47108. if (ctx.propsDestructureRestId) {
  47109. ctx.s.overwrite(
  47110. startOffset + ctx.propsCall.start,
  47111. startOffset + ctx.propsCall.end,
  47112. `${ctx.helper(`createPropsRestProxy`)}(__props, ${JSON.stringify(
  47113. Object.keys(ctx.propsDestructuredBindings)
  47114. )})`
  47115. );
  47116. ctx.s.overwrite(
  47117. startOffset + ctx.propsDestructureDecl.start,
  47118. startOffset + ctx.propsDestructureDecl.end,
  47119. ctx.propsDestructureRestId
  47120. );
  47121. } else if (!ctx.propsDestructureDecl) {
  47122. ctx.s.overwrite(
  47123. startOffset + ctx.propsCall.start,
  47124. startOffset + ctx.propsCall.end,
  47125. "__props"
  47126. );
  47127. }
  47128. }
  47129. if (hasAwait) {
  47130. const any = ctx.isTS ? `: any` : ``;
  47131. ctx.s.prependLeft(startOffset, `
  47132. let __temp${any}, __restore${any}
  47133. `);
  47134. }
  47135. const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
  47136. if (ctx.emitDecl) {
  47137. destructureElements.push(`emit: __emit`);
  47138. }
  47139. if (destructureElements.length) {
  47140. args += `, { ${destructureElements.join(", ")} }`;
  47141. }
  47142. let returned;
  47143. if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
  47144. const allBindings = __spreadValues(__spreadValues({}, scriptBindings), setupBindings);
  47145. for (const key in ctx.userImports) {
  47146. if (!ctx.userImports[key].isType && ctx.userImports[key].isUsedInTemplate) {
  47147. allBindings[key] = true;
  47148. }
  47149. }
  47150. returned = `{ `;
  47151. for (const key in allBindings) {
  47152. if (allBindings[key] === true && ctx.userImports[key].source !== "vue" && !ctx.userImports[key].source.endsWith(".vue")) {
  47153. returned += `get ${key}() { return ${key} }, `;
  47154. } else if (ctx.bindingMetadata[key] === "setup-let") {
  47155. const setArg = key === "v" ? `_v` : `v`;
  47156. returned += `get ${key}() { return ${key} }, set ${key}(${setArg}) { ${key} = ${setArg} }, `;
  47157. } else {
  47158. returned += `${key}, `;
  47159. }
  47160. }
  47161. returned = returned.replace(/, $/, "") + ` }`;
  47162. } else {
  47163. if (sfc.template && !sfc.template.src) {
  47164. if (options.templateOptions && options.templateOptions.ssr) {
  47165. hasInlinedSsrRenderFn = true;
  47166. }
  47167. const { code, ast, preamble, tips, errors } = compileTemplate(__spreadProps(__spreadValues({
  47168. filename,
  47169. source: sfc.template.content,
  47170. inMap: sfc.template.map
  47171. }, options.templateOptions), {
  47172. id: scopeId,
  47173. scoped: sfc.styles.some((s) => s.scoped),
  47174. isProd: options.isProd,
  47175. ssrCssVars: sfc.cssVars,
  47176. compilerOptions: __spreadProps(__spreadValues({}, options.templateOptions && options.templateOptions.compilerOptions), {
  47177. inline: true,
  47178. isTS: ctx.isTS,
  47179. bindingMetadata: ctx.bindingMetadata
  47180. })
  47181. }));
  47182. if (tips.length) {
  47183. tips.forEach(warnOnce$4);
  47184. }
  47185. const err = errors[0];
  47186. if (typeof err === "string") {
  47187. throw new Error(err);
  47188. } else if (err) {
  47189. if (err.loc) {
  47190. err.message += `
  47191. ` + sfc.filename + "\n" + generateCodeFrame(
  47192. source,
  47193. err.loc.start.offset,
  47194. err.loc.end.offset
  47195. ) + `
  47196. `;
  47197. }
  47198. throw err;
  47199. }
  47200. if (preamble) {
  47201. ctx.s.prepend(preamble);
  47202. }
  47203. if (ast && ast.helpers.has(UNREF)) {
  47204. ctx.helperImports.delete("unref");
  47205. }
  47206. returned = code;
  47207. } else {
  47208. returned = `() => {}`;
  47209. }
  47210. }
  47211. if (!options.inlineTemplate && true) {
  47212. ctx.s.appendRight(
  47213. endOffset,
  47214. `
  47215. const __returned__ = ${returned}
  47216. Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
  47217. return __returned__
  47218. }
  47219. `
  47220. );
  47221. } else {
  47222. ctx.s.appendRight(endOffset, `
  47223. return ${returned}
  47224. }
  47225. `);
  47226. }
  47227. const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
  47228. let runtimeOptions = ``;
  47229. if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
  47230. const match = filename.match(/([^/\\]+)\.\w+$/);
  47231. if (match) {
  47232. runtimeOptions += `
  47233. __name: '${match[1]}',`;
  47234. }
  47235. }
  47236. if (hasInlinedSsrRenderFn) {
  47237. runtimeOptions += `
  47238. __ssrInlineRender: true,`;
  47239. }
  47240. const propsDecl = genRuntimeProps(ctx);
  47241. if (propsDecl)
  47242. runtimeOptions += `
  47243. props: ${propsDecl},`;
  47244. const emitsDecl = genRuntimeEmits(ctx);
  47245. if (emitsDecl)
  47246. runtimeOptions += `
  47247. emits: ${emitsDecl},`;
  47248. let definedOptions = "";
  47249. if (ctx.optionsRuntimeDecl) {
  47250. definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
  47251. }
  47252. const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
  47253. `;
  47254. if (ctx.isTS) {
  47255. const def = (defaultExport ? `
  47256. ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
  47257. ...${definedOptions},` : "");
  47258. ctx.s.prependLeft(
  47259. startOffset,
  47260. `
  47261. ${genDefaultAs} /*#__PURE__*/${ctx.helper(
  47262. `defineComponent`
  47263. )}({${def}${runtimeOptions}
  47264. ${hasAwait ? `async ` : ``}setup(${args}) {
  47265. ${exposeCall}`
  47266. );
  47267. ctx.s.appendRight(endOffset, `})`);
  47268. } else {
  47269. if (defaultExport || definedOptions) {
  47270. ctx.s.prependLeft(
  47271. startOffset,
  47272. `
  47273. ${genDefaultAs} /*#__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
  47274. ${hasAwait ? `async ` : ``}setup(${args}) {
  47275. ${exposeCall}`
  47276. );
  47277. ctx.s.appendRight(endOffset, `})`);
  47278. } else {
  47279. ctx.s.prependLeft(
  47280. startOffset,
  47281. `
  47282. ${genDefaultAs} {${runtimeOptions}
  47283. ${hasAwait ? `async ` : ``}setup(${args}) {
  47284. ${exposeCall}`
  47285. );
  47286. ctx.s.appendRight(endOffset, `}`);
  47287. }
  47288. }
  47289. if (ctx.helperImports.size > 0) {
  47290. ctx.s.prepend(
  47291. `import { ${[...ctx.helperImports].map((h) => `${h} as _${h}`).join(", ")} } from 'vue'
  47292. `
  47293. );
  47294. }
  47295. ctx.s.trim();
  47296. return __spreadProps(__spreadValues({}, scriptSetup), {
  47297. bindings: ctx.bindingMetadata,
  47298. imports: ctx.userImports,
  47299. content: ctx.s.toString(),
  47300. map: options.sourceMap !== false ? ctx.s.generateMap({
  47301. source: filename,
  47302. hires: true,
  47303. includeContent: true
  47304. }) : void 0,
  47305. scriptAst: scriptAst == null ? void 0 : scriptAst.body,
  47306. scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
  47307. deps: ctx.deps ? [...ctx.deps] : void 0
  47308. });
  47309. }
  47310. function registerBinding(bindings, node, type) {
  47311. bindings[node.name] = type;
  47312. }
  47313. function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
  47314. let isAllLiteral = false;
  47315. if (node.type === "VariableDeclaration") {
  47316. const isConst = node.kind === "const";
  47317. isAllLiteral = isConst && node.declarations.every(
  47318. (decl) => decl.id.type === "Identifier" && isStaticNode(decl.init)
  47319. );
  47320. for (const { id, init: _init } of node.declarations) {
  47321. const init = _init && unwrapTSNode(_init);
  47322. const isDefineCall = !!(isConst && isCallOf(
  47323. init,
  47324. (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS
  47325. ));
  47326. if (id.type === "Identifier") {
  47327. let bindingType;
  47328. const userReactiveBinding = userImportAliases["reactive"];
  47329. if ((hoistStatic || from === "script") && (isAllLiteral || isConst && isStaticNode(init))) {
  47330. bindingType = "literal-const";
  47331. } else if (isCallOf(init, userReactiveBinding)) {
  47332. bindingType = isConst ? "setup-reactive-const" : "setup-let";
  47333. } else if (
  47334. // if a declaration is a const literal, we can mark it so that
  47335. // the generated render fn code doesn't need to unref() it
  47336. isDefineCall || isConst && canNeverBeRef(init, userReactiveBinding)
  47337. ) {
  47338. bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
  47339. } else if (isConst) {
  47340. if (isCallOf(
  47341. init,
  47342. (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === DEFINE_MODEL
  47343. )) {
  47344. bindingType = "setup-ref";
  47345. } else {
  47346. bindingType = "setup-maybe-ref";
  47347. }
  47348. } else {
  47349. bindingType = "setup-let";
  47350. }
  47351. registerBinding(bindings, id, bindingType);
  47352. } else {
  47353. if (isCallOf(init, DEFINE_PROPS)) {
  47354. continue;
  47355. }
  47356. if (id.type === "ObjectPattern") {
  47357. walkObjectPattern(id, bindings, isConst, isDefineCall);
  47358. } else if (id.type === "ArrayPattern") {
  47359. walkArrayPattern(id, bindings, isConst, isDefineCall);
  47360. }
  47361. }
  47362. }
  47363. } else if (node.type === "TSEnumDeclaration") {
  47364. isAllLiteral = node.members.every(
  47365. (member) => !member.initializer || isStaticNode(member.initializer)
  47366. );
  47367. bindings[node.id.name] = isAllLiteral ? "literal-const" : "setup-const";
  47368. } else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
  47369. bindings[node.id.name] = "setup-const";
  47370. }
  47371. return isAllLiteral;
  47372. }
  47373. function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
  47374. for (const p of node.properties) {
  47375. if (p.type === "ObjectProperty") {
  47376. if (p.key.type === "Identifier" && p.key === p.value) {
  47377. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47378. registerBinding(bindings, p.key, type);
  47379. } else {
  47380. walkPattern(p.value, bindings, isConst, isDefineCall);
  47381. }
  47382. } else {
  47383. const type = isConst ? "setup-const" : "setup-let";
  47384. registerBinding(bindings, p.argument, type);
  47385. }
  47386. }
  47387. }
  47388. function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
  47389. for (const e of node.elements) {
  47390. e && walkPattern(e, bindings, isConst, isDefineCall);
  47391. }
  47392. }
  47393. function walkPattern(node, bindings, isConst, isDefineCall = false) {
  47394. if (node.type === "Identifier") {
  47395. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47396. registerBinding(bindings, node, type);
  47397. } else if (node.type === "RestElement") {
  47398. const type = isConst ? "setup-const" : "setup-let";
  47399. registerBinding(bindings, node.argument, type);
  47400. } else if (node.type === "ObjectPattern") {
  47401. walkObjectPattern(node, bindings, isConst);
  47402. } else if (node.type === "ArrayPattern") {
  47403. walkArrayPattern(node, bindings, isConst);
  47404. } else if (node.type === "AssignmentPattern") {
  47405. if (node.left.type === "Identifier") {
  47406. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47407. registerBinding(bindings, node.left, type);
  47408. } else {
  47409. walkPattern(node.left, bindings, isConst);
  47410. }
  47411. }
  47412. }
  47413. function canNeverBeRef(node, userReactiveImport) {
  47414. if (isCallOf(node, userReactiveImport)) {
  47415. return true;
  47416. }
  47417. switch (node.type) {
  47418. case "UnaryExpression":
  47419. case "BinaryExpression":
  47420. case "ArrayExpression":
  47421. case "ObjectExpression":
  47422. case "FunctionExpression":
  47423. case "ArrowFunctionExpression":
  47424. case "UpdateExpression":
  47425. case "ClassExpression":
  47426. case "TaggedTemplateExpression":
  47427. return true;
  47428. case "SequenceExpression":
  47429. return canNeverBeRef(
  47430. node.expressions[node.expressions.length - 1],
  47431. userReactiveImport
  47432. );
  47433. default:
  47434. if (isLiteralNode(node)) {
  47435. return true;
  47436. }
  47437. return false;
  47438. }
  47439. }
  47440. function isStaticNode(node) {
  47441. node = unwrapTSNode(node);
  47442. switch (node.type) {
  47443. case "UnaryExpression":
  47444. return isStaticNode(node.argument);
  47445. case "LogicalExpression":
  47446. case "BinaryExpression":
  47447. return isStaticNode(node.left) && isStaticNode(node.right);
  47448. case "ConditionalExpression": {
  47449. return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
  47450. }
  47451. case "SequenceExpression":
  47452. case "TemplateLiteral":
  47453. return node.expressions.every((expr) => isStaticNode(expr));
  47454. case "ParenthesizedExpression":
  47455. return isStaticNode(node.expression);
  47456. case "StringLiteral":
  47457. case "NumericLiteral":
  47458. case "BooleanLiteral":
  47459. case "NullLiteral":
  47460. case "BigIntLiteral":
  47461. return true;
  47462. }
  47463. return false;
  47464. }
  47465. const version = "3.3.11";
  47466. const parseCache = parseCache$1;
  47467. const walk = walk$1;
  47468. export { MagicString, parse_1$1 as babelParse, compileScript, compileStyle, compileStyleAsync, compileTemplate, extractIdentifiers, generateCodeFrame, inferRuntimeType, invalidateTypeCache, isInDestructureAssignment, isStaticProperty, parse$7 as parse, parseCache, registerTS, resolveTypeElements, rewriteDefault, rewriteDefaultAST, shouldTransform as shouldTransformRef, transform as transformRef, transformAST as transformRefAST, version, walk, walkIdentifiers };