index.js 283 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. 'use strict';
  6. Object.defineProperty(exports, '__esModule', { value: true });
  7. var path = require('path');
  8. var Evk = require('eslint-visitor-keys');
  9. var sortedLastIndex = require('lodash/sortedLastIndex');
  10. var assert = require('assert');
  11. var last = require('lodash/last');
  12. var findLastIndex = require('lodash/findLastIndex');
  13. var debugFactory = require('debug');
  14. var first = require('lodash/first');
  15. var sortedIndexBy = require('lodash/sortedIndexBy');
  16. var escope = require('eslint-scope');
  17. var Module = require('module');
  18. var semver = require('semver');
  19. var dependencyEspree = require('espree');
  20. var sortedLastIndexBy = require('lodash/sortedLastIndexBy');
  21. var EventEmitter = require('events');
  22. var esquery = require('esquery');
  23. var union = require('lodash/union');
  24. var intersection = require('lodash/intersection');
  25. var memoize = require('lodash/memoize');
  26. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  27. function _interopNamespace(e) {
  28. if (e && e.__esModule) return e;
  29. var n = Object.create(null);
  30. if (e) {
  31. Object.keys(e).forEach(function (k) {
  32. if (k !== 'default') {
  33. var d = Object.getOwnPropertyDescriptor(e, k);
  34. Object.defineProperty(n, k, d.get ? d : {
  35. enumerable: true,
  36. get: function () { return e[k]; }
  37. });
  38. }
  39. });
  40. }
  41. n["default"] = e;
  42. return Object.freeze(n);
  43. }
  44. var path__namespace = /*#__PURE__*/_interopNamespace(path);
  45. var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
  46. var Evk__namespace = /*#__PURE__*/_interopNamespace(Evk);
  47. var sortedLastIndex__default = /*#__PURE__*/_interopDefaultLegacy(sortedLastIndex);
  48. var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
  49. var last__default = /*#__PURE__*/_interopDefaultLegacy(last);
  50. var findLastIndex__default = /*#__PURE__*/_interopDefaultLegacy(findLastIndex);
  51. var debugFactory__default = /*#__PURE__*/_interopDefaultLegacy(debugFactory);
  52. var first__default = /*#__PURE__*/_interopDefaultLegacy(first);
  53. var sortedIndexBy__default = /*#__PURE__*/_interopDefaultLegacy(sortedIndexBy);
  54. var escope__namespace = /*#__PURE__*/_interopNamespace(escope);
  55. var Module__default = /*#__PURE__*/_interopDefaultLegacy(Module);
  56. var dependencyEspree__namespace = /*#__PURE__*/_interopNamespace(dependencyEspree);
  57. var sortedLastIndexBy__default = /*#__PURE__*/_interopDefaultLegacy(sortedLastIndexBy);
  58. var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
  59. var esquery__default = /*#__PURE__*/_interopDefaultLegacy(esquery);
  60. var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
  61. var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
  62. var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);
  63. function isAcornStyleParseError(x) {
  64. return (typeof x.message === "string" &&
  65. typeof x.pos === "number" &&
  66. typeof x.loc === "object" &&
  67. x.loc !== null &&
  68. typeof x.loc.line === "number" &&
  69. typeof x.loc.column === "number");
  70. }
  71. function isTSError(x) {
  72. return (!(x instanceof ParseError) &&
  73. typeof x.message === "string" &&
  74. typeof x.index === "number" &&
  75. typeof x.lineNumber === "number" &&
  76. typeof x.column === "number" &&
  77. x.name === "TSError");
  78. }
  79. class ParseError extends SyntaxError {
  80. constructor(message, code, offset, line, column) {
  81. super(message);
  82. this.code = code;
  83. this.index = offset;
  84. this.lineNumber = line;
  85. this.column = column;
  86. }
  87. static fromCode(code, offset, line, column) {
  88. return new ParseError(code, code, offset, line, column);
  89. }
  90. static normalize(x) {
  91. if (isTSError(x)) {
  92. return new ParseError(x.message, undefined, x.index, x.lineNumber, x.column);
  93. }
  94. if (ParseError.isParseError(x)) {
  95. return x;
  96. }
  97. if (isAcornStyleParseError(x)) {
  98. return new ParseError(x.message, undefined, x.pos, x.loc.line, x.loc.column);
  99. }
  100. return null;
  101. }
  102. static isParseError(x) {
  103. return (x instanceof ParseError ||
  104. (typeof x.message === "string" &&
  105. typeof x.index === "number" &&
  106. typeof x.lineNumber === "number" &&
  107. typeof x.column === "number"));
  108. }
  109. }
  110. const NS = Object.freeze({
  111. HTML: "http://www.w3.org/1999/xhtml",
  112. MathML: "http://www.w3.org/1998/Math/MathML",
  113. SVG: "http://www.w3.org/2000/svg",
  114. XLink: "http://www.w3.org/1999/xlink",
  115. XML: "http://www.w3.org/XML/1998/namespace",
  116. XMLNS: "http://www.w3.org/2000/xmlns/",
  117. });
  118. const KEYS = Evk__namespace.unionWith({
  119. VAttribute: ["key", "value"],
  120. VDirectiveKey: ["name", "argument", "modifiers"],
  121. VDocumentFragment: ["children"],
  122. VElement: ["startTag", "children", "endTag"],
  123. VEndTag: [],
  124. VExpressionContainer: ["expression"],
  125. VFilter: ["callee", "arguments"],
  126. VFilterSequenceExpression: ["expression", "filters"],
  127. VForExpression: ["left", "right"],
  128. VIdentifier: [],
  129. VLiteral: [],
  130. VOnExpression: ["body"],
  131. VSlotScopeExpression: ["params"],
  132. VStartTag: ["attributes"],
  133. VText: [],
  134. });
  135. function fallbackKeysFilter(key) {
  136. let value = null;
  137. return (key !== "comments" &&
  138. key !== "leadingComments" &&
  139. key !== "loc" &&
  140. key !== "parent" &&
  141. key !== "range" &&
  142. key !== "tokens" &&
  143. key !== "trailingComments" &&
  144. (value = this[key]) !== null &&
  145. typeof value === "object" &&
  146. (typeof value.type === "string" || Array.isArray(value)));
  147. }
  148. function getFallbackKeys(node) {
  149. return Object.keys(node).filter(fallbackKeysFilter, node);
  150. }
  151. function isNode(x) {
  152. return x !== null && typeof x === "object" && typeof x.type === "string";
  153. }
  154. function traverse(node, parent, visitor) {
  155. let i = 0;
  156. let j = 0;
  157. visitor.enterNode(node, parent);
  158. const keys = (visitor.visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
  159. for (i = 0; i < keys.length; ++i) {
  160. const child = node[keys[i]];
  161. if (Array.isArray(child)) {
  162. for (j = 0; j < child.length; ++j) {
  163. if (isNode(child[j])) {
  164. traverse(child[j], node, visitor);
  165. }
  166. }
  167. }
  168. else if (isNode(child)) {
  169. traverse(child, node, visitor);
  170. }
  171. }
  172. visitor.leaveNode(node, parent);
  173. }
  174. function traverseNodes(node, visitor) {
  175. traverse(node, null, visitor);
  176. }
  177. var index = /*#__PURE__*/Object.freeze({
  178. __proto__: null,
  179. ParseError: ParseError,
  180. NS: NS,
  181. KEYS: KEYS,
  182. traverseNodes: traverseNodes,
  183. getFallbackKeys: getFallbackKeys
  184. });
  185. class LinesAndColumns {
  186. constructor(ltOffsets) {
  187. this.ltOffsets = ltOffsets;
  188. }
  189. getLocFromIndex(index) {
  190. const line = sortedLastIndex__default["default"](this.ltOffsets, index) + 1;
  191. const column = index - (line === 1 ? 0 : this.ltOffsets[line - 2]);
  192. return { line, column };
  193. }
  194. createOffsetLocationCalculator(offset) {
  195. return {
  196. getFixOffset() {
  197. return offset;
  198. },
  199. getLocFromIndex: this.getLocFromIndex.bind(this),
  200. };
  201. }
  202. }
  203. class LocationCalculatorForHtml extends LinesAndColumns {
  204. constructor(gapOffsets, ltOffsets, baseOffset, shiftOffset = 0) {
  205. super(ltOffsets);
  206. this.gapOffsets = gapOffsets;
  207. this.ltOffsets = ltOffsets;
  208. this.baseOffset = baseOffset || 0;
  209. this.baseIndexOfGap =
  210. this.baseOffset === 0
  211. ? 0
  212. : sortedLastIndex__default["default"](gapOffsets, this.baseOffset);
  213. this.shiftOffset = shiftOffset;
  214. }
  215. getSubCalculatorAfter(offset) {
  216. return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset + offset, this.shiftOffset);
  217. }
  218. getSubCalculatorShift(offset) {
  219. return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset, this.shiftOffset + offset);
  220. }
  221. _getGap(index) {
  222. const offsets = this.gapOffsets;
  223. let g0 = sortedLastIndex__default["default"](offsets, index + this.baseOffset);
  224. let pos = index + this.baseOffset + g0 - this.baseIndexOfGap;
  225. while (g0 < offsets.length && offsets[g0] <= pos) {
  226. g0 += 1;
  227. pos += 1;
  228. }
  229. return g0 - this.baseIndexOfGap;
  230. }
  231. getLocation(index) {
  232. return this.getLocFromIndex(this.getOffsetWithGap(index));
  233. }
  234. getOffsetWithGap(index) {
  235. return index + this.getFixOffset(index);
  236. }
  237. getFixOffset(offset) {
  238. const shiftOffset = this.shiftOffset;
  239. const gap = this._getGap(offset + shiftOffset);
  240. return this.baseOffset + gap + shiftOffset;
  241. }
  242. }
  243. const debug = debugFactory__default["default"]("vue-eslint-parser");
  244. function isScriptElement(node) {
  245. return node.type === "VElement" && node.name === "script";
  246. }
  247. function isScriptSetupElement(script) {
  248. return (isScriptElement(script) &&
  249. script.startTag.attributes.some((attr) => !attr.directive && attr.key.name === "setup"));
  250. }
  251. function isTemplateElement(node) {
  252. return node.type === "VElement" && node.name === "template";
  253. }
  254. function isStyleElement(node) {
  255. return node.type === "VElement" && node.name === "style";
  256. }
  257. function getOwnerDocument(leafNode) {
  258. let node = leafNode;
  259. while (node != null && node.type !== "VDocumentFragment") {
  260. node = node.parent;
  261. }
  262. return node;
  263. }
  264. function isLang(attribute) {
  265. return attribute.directive === false && attribute.key.name === "lang";
  266. }
  267. function getLang(element) {
  268. const langAttr = element && element.startTag.attributes.find(isLang);
  269. const lang = langAttr && langAttr.value && langAttr.value.value;
  270. return lang || null;
  271. }
  272. function isTSLang(element) {
  273. const lang = getLang(element);
  274. return lang === "ts" || lang === "tsx";
  275. }
  276. function findGenericDirective(element) {
  277. return (element.startTag.attributes.find((attr) => {
  278. var _a, _b;
  279. return attr.directive &&
  280. ((_b = (_a = attr.value) === null || _a === void 0 ? void 0 : _a.expression) === null || _b === void 0 ? void 0 : _b.type) === "VGenericExpression";
  281. }) || null);
  282. }
  283. function isParserObject(value) {
  284. return isEnhancedParserObject(value) || isBasicParserObject(value);
  285. }
  286. function isEnhancedParserObject(value) {
  287. return Boolean(value && typeof value.parseForESLint === "function");
  288. }
  289. function isBasicParserObject(value) {
  290. return Boolean(value && typeof value.parse === "function");
  291. }
  292. function isSFCFile(parserOptions) {
  293. if (parserOptions.filePath === "<input>") {
  294. return true;
  295. }
  296. return path__namespace.extname(parserOptions.filePath || "unknown.vue") === ".vue";
  297. }
  298. function getScriptParser(parser, getParserLang) {
  299. if (isParserObject(parser)) {
  300. return parser;
  301. }
  302. if (parser && typeof parser === "object") {
  303. const parserLang = getParserLang();
  304. const parserLangs = parserLang == null
  305. ? []
  306. : typeof parserLang === "string"
  307. ? [parserLang]
  308. : parserLang;
  309. for (const lang of parserLangs) {
  310. const parserForLang = lang && parser[lang];
  311. if (typeof parserForLang === "string" ||
  312. isParserObject(parserForLang)) {
  313. return parserForLang;
  314. }
  315. }
  316. return parser.js;
  317. }
  318. return typeof parser === "string" ? parser : undefined;
  319. }
  320. function getParserLangFromSFC(doc) {
  321. if (doc) {
  322. const scripts = doc.children.filter(isScriptElement);
  323. const script = (scripts.length === 2 && scripts.find(isScriptSetupElement)) ||
  324. scripts[0];
  325. if (script) {
  326. return getLang(script);
  327. }
  328. }
  329. return null;
  330. }
  331. const createRequire = Module__default["default"].createRequire ||
  332. Module__default["default"].createRequireFromPath ||
  333. ((modname) => {
  334. const mod = new Module__default["default"](modname);
  335. mod.filename = modname;
  336. mod.paths = Module__default["default"]._nodeModulePaths(path__default["default"].dirname(modname));
  337. mod._compile("module.exports = require;", modname);
  338. return mod.exports;
  339. });
  340. function isLinterPath(p) {
  341. return (p.includes(`eslint${path__default["default"].sep}lib${path__default["default"].sep}linter${path__default["default"].sep}linter.js`) ||
  342. p.includes(`eslint${path__default["default"].sep}lib${path__default["default"].sep}linter.js`));
  343. }
  344. function getLinterRequire() {
  345. const linterPath = Object.keys(require.cache).find(isLinterPath);
  346. if (linterPath) {
  347. try {
  348. return createRequire(linterPath);
  349. }
  350. catch (_a) {
  351. }
  352. }
  353. return null;
  354. }
  355. let escopeCache = null;
  356. function getEslintScope() {
  357. var _a;
  358. if (!escopeCache) {
  359. escopeCache = (_a = getLinterRequire()) === null || _a === void 0 ? void 0 : _a("eslint-scope");
  360. if (!escopeCache ||
  361. escopeCache.version == null ||
  362. semver.lte(escopeCache.version, escope__namespace.version)) {
  363. escopeCache = escope__namespace;
  364. }
  365. }
  366. return escopeCache;
  367. }
  368. let espreeCache = null;
  369. function getEspreeFromEcmaVersion(ecmaVersion) {
  370. const linterEspree = getEspreeFromLinter();
  371. if (ecmaVersion == null) {
  372. return linterEspree;
  373. }
  374. if (ecmaVersion === "latest") {
  375. return getNewestEspree();
  376. }
  377. if (normalizeEcmaVersion(ecmaVersion) <= getLatestEcmaVersion(linterEspree)) {
  378. return linterEspree;
  379. }
  380. const userEspree = getEspreeFromUser();
  381. if (normalizeEcmaVersion(ecmaVersion) <= getLatestEcmaVersion(userEspree)) {
  382. return userEspree;
  383. }
  384. return linterEspree;
  385. }
  386. function getEspreeFromUser() {
  387. try {
  388. const cwd = process.cwd();
  389. const relativeTo = path__default["default"].join(cwd, "__placeholder__.js");
  390. return createRequire(relativeTo)("espree");
  391. }
  392. catch (_a) {
  393. return getEspreeFromLinter();
  394. }
  395. }
  396. function getEspreeFromLinter() {
  397. var _a;
  398. if (!espreeCache) {
  399. espreeCache = (_a = getLinterRequire()) === null || _a === void 0 ? void 0 : _a("espree");
  400. if (!espreeCache) {
  401. espreeCache = dependencyEspree__namespace;
  402. }
  403. }
  404. return espreeCache;
  405. }
  406. function getNewestEspree() {
  407. let newest = dependencyEspree__namespace;
  408. const linterEspree = getEspreeFromLinter();
  409. if (linterEspree.version != null &&
  410. semver.lte(newest.version, linterEspree.version)) {
  411. newest = linterEspree;
  412. }
  413. const userEspree = getEspreeFromUser();
  414. if (userEspree.version != null && semver.lte(newest.version, userEspree.version)) {
  415. newest = userEspree;
  416. }
  417. return newest;
  418. }
  419. function getEcmaVersionIfUseEspree(parserOptions, getDefault) {
  420. var _a;
  421. if (parserOptions.parser != null && parserOptions.parser !== "espree") {
  422. return undefined;
  423. }
  424. if (parserOptions.ecmaVersion === "latest") {
  425. return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()));
  426. }
  427. if (parserOptions.ecmaVersion == null) {
  428. const defVer = getDefaultEcmaVersion$1();
  429. return (_a = getDefault === null || getDefault === void 0 ? void 0 : getDefault(defVer)) !== null && _a !== void 0 ? _a : defVer;
  430. }
  431. return normalizeEcmaVersion(parserOptions.ecmaVersion);
  432. }
  433. function getDefaultEcmaVersion$1() {
  434. if (semver.lt(getEspreeFromLinter().version, "9.0.0")) {
  435. return 5;
  436. }
  437. return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()));
  438. }
  439. function normalizeEcmaVersion(version) {
  440. if (version > 5 && version < 2015) {
  441. return version + 2009;
  442. }
  443. return version;
  444. }
  445. function getLatestEcmaVersion(espree) {
  446. if (espree.latestEcmaVersion == null) {
  447. for (const { v, latest } of [
  448. { v: "6.1.0", latest: 2020 },
  449. { v: "4.0.0", latest: 2019 },
  450. ]) {
  451. if (semver.lte(v, espree.version)) {
  452. return latest;
  453. }
  454. }
  455. return 2018;
  456. }
  457. return normalizeEcmaVersion(espree.latestEcmaVersion);
  458. }
  459. function isUnique(reference, index, references) {
  460. return (index === 0 || reference.identifier !== references[index - 1].identifier);
  461. }
  462. function hasDefinition(variable) {
  463. return variable.defs.length >= 1;
  464. }
  465. function transformReference(reference) {
  466. const ret = {
  467. id: reference.identifier,
  468. mode: reference.isReadOnly()
  469. ? "r"
  470. : reference.isWriteOnly()
  471. ? "w"
  472. : "rw",
  473. variable: null,
  474. isValueReference: reference.isValueReference,
  475. isTypeReference: reference.isTypeReference,
  476. };
  477. Object.defineProperty(ret, "variable", { enumerable: false });
  478. return ret;
  479. }
  480. function transformVariable(variable, kind) {
  481. const ret = {
  482. id: variable.defs[0].name,
  483. kind,
  484. references: [],
  485. };
  486. Object.defineProperty(ret, "references", { enumerable: false });
  487. return ret;
  488. }
  489. function getForScope(scope) {
  490. const child = scope.childScopes[0];
  491. return child.block === scope.block ? child.childScopes[0] : child;
  492. }
  493. function analyzeScope(ast, parserOptions) {
  494. const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022;
  495. const ecmaFeatures = parserOptions.ecmaFeatures || {};
  496. const sourceType = parserOptions.sourceType || "script";
  497. const result = getEslintScope().analyze(ast, {
  498. ignoreEval: true,
  499. nodejsScope: false,
  500. impliedStrict: ecmaFeatures.impliedStrict,
  501. ecmaVersion,
  502. sourceType,
  503. fallback: getFallbackKeys,
  504. });
  505. return result;
  506. }
  507. function analyze(parserResult, parserOptions) {
  508. const scopeManager = parserResult.scopeManager ||
  509. analyzeScope(parserResult.ast, parserOptions);
  510. return scopeManager.globalScope;
  511. }
  512. function analyzeExternalReferences(parserResult, parserOptions) {
  513. const scope = analyze(parserResult, parserOptions);
  514. return scope.through.filter(isUnique).map(transformReference);
  515. }
  516. function analyzeVariablesAndExternalReferences(parserResult, kind, parserOptions) {
  517. const scope = analyze(parserResult, parserOptions);
  518. return {
  519. variables: getForScope(scope)
  520. .variables.filter(hasDefinition)
  521. .map((v) => transformVariable(v, kind)),
  522. references: scope.through.filter(isUnique).map(transformReference),
  523. };
  524. }
  525. function fixLocations(result, locationCalculator) {
  526. fixNodeLocations(result.ast, result.visitorKeys, locationCalculator);
  527. for (const token of result.ast.tokens || []) {
  528. fixLocation(token, locationCalculator);
  529. }
  530. for (const comment of result.ast.comments || []) {
  531. fixLocation(comment, locationCalculator);
  532. }
  533. }
  534. function fixNodeLocations(rootNode, visitorKeys, locationCalculator) {
  535. const traversed = new Map();
  536. traverseNodes(rootNode, {
  537. visitorKeys,
  538. enterNode(node, parent) {
  539. if (!traversed.has(node)) {
  540. traversed.set(node, node);
  541. node.parent = parent;
  542. if (traversed.has(node.range)) {
  543. if (!traversed.has(node.loc)) {
  544. node.loc.start = locationCalculator.getLocFromIndex(node.range[0]);
  545. node.loc.end = locationCalculator.getLocFromIndex(node.range[1]);
  546. traversed.set(node.loc, node);
  547. }
  548. else if (node.start != null || node.end != null) {
  549. const traversedNode = traversed.get(node.range);
  550. if (traversedNode.type === node.type) {
  551. node.start = traversedNode.start;
  552. node.end = traversedNode.end;
  553. }
  554. }
  555. }
  556. else {
  557. fixLocation(node, locationCalculator);
  558. traversed.set(node.range, node);
  559. traversed.set(node.loc, node);
  560. }
  561. }
  562. },
  563. leaveNode() {
  564. },
  565. });
  566. }
  567. function fixLocation(node, locationCalculator) {
  568. const range = node.range;
  569. const loc = node.loc;
  570. const d0 = locationCalculator.getFixOffset(range[0], "start");
  571. const d1 = locationCalculator.getFixOffset(range[1], "end");
  572. if (d0 !== 0) {
  573. range[0] += d0;
  574. if (node.start != null) {
  575. node.start += d0;
  576. }
  577. loc.start = locationCalculator.getLocFromIndex(range[0]);
  578. }
  579. if (d1 !== 0) {
  580. range[1] += d1;
  581. if (node.end != null) {
  582. node.end += d0;
  583. }
  584. loc.end = locationCalculator.getLocFromIndex(range[1]);
  585. }
  586. return node;
  587. }
  588. function fixErrorLocation(error, locationCalculator) {
  589. const diff = locationCalculator.getFixOffset(error.index, "start");
  590. error.index += diff;
  591. const loc = locationCalculator.getLocFromIndex(error.index);
  592. error.lineNumber = loc.line;
  593. error.column = loc.column;
  594. }
  595. const DEFAULT_ECMA_VERSION = 2017;
  596. function getScriptSetupParserOptions(parserOptions) {
  597. const espreeEcmaVersion = getEcmaVersionIfUseEspree(parserOptions, getDefaultEcmaVersion);
  598. return Object.assign(Object.assign({}, parserOptions), { ecmaVersion: espreeEcmaVersion });
  599. }
  600. function getDefaultEcmaVersion(def) {
  601. if (semver.lte("8.0.0", getEspreeFromUser().version)) {
  602. return getEspreeFromUser().latestEcmaVersion;
  603. }
  604. return Math.max(def, DEFAULT_ECMA_VERSION);
  605. }
  606. function extractGeneric(element) {
  607. const genericAttr = findGenericDirective(element);
  608. if (!genericAttr) {
  609. return null;
  610. }
  611. const genericNode = genericAttr.value.expression;
  612. const defineTypes = genericNode.params.map((t, i) => ({
  613. node: t,
  614. define: `type ${t.name.name} = ${getConstraint(t, genericNode.rawParams[i])}`,
  615. }));
  616. return {
  617. node: genericNode,
  618. defineTypes,
  619. postprocess({ result, getTypeBlock, isRemoveTarget, getTypeDefScope }) {
  620. var _a;
  621. const node = (_a = getTypeBlock === null || getTypeBlock === void 0 ? void 0 : getTypeBlock(result.ast)) !== null && _a !== void 0 ? _a : result.ast;
  622. removeTypeDeclarations(node, isRemoveTarget);
  623. if (result.ast.tokens) {
  624. removeTypeDeclarationTokens(result.ast.tokens, isRemoveTarget);
  625. }
  626. if (result.ast.comments) {
  627. removeTypeDeclarationTokens(result.ast.comments, isRemoveTarget);
  628. }
  629. if (result.scopeManager) {
  630. const typeDefScope = getTypeDefScope(result.scopeManager);
  631. restoreScope(result.scopeManager, typeDefScope, isRemoveTarget);
  632. }
  633. },
  634. };
  635. function removeTypeDeclarations(node, isRemoveTarget) {
  636. for (let index = node.body.length - 1; index >= 0; index--) {
  637. if (isRemoveTarget(node.body[index])) {
  638. node.body.splice(index, 1);
  639. }
  640. }
  641. }
  642. function removeTypeDeclarationTokens(tokens, isRemoveTarget) {
  643. for (let index = tokens.length - 1; index >= 0; index--) {
  644. if (isRemoveTarget(tokens[index])) {
  645. tokens.splice(index, 1);
  646. }
  647. }
  648. }
  649. function restoreScope(scopeManager, typeDefScope, isRemoveTarget) {
  650. for (const variable of [...typeDefScope.variables]) {
  651. let def = variable.defs.find((d) => isRemoveTarget(d.name));
  652. while (def) {
  653. removeVariableDef(variable, def, typeDefScope);
  654. def = variable.defs.find((d) => isRemoveTarget(d.name));
  655. }
  656. }
  657. for (const reference of [...typeDefScope.references]) {
  658. if (isRemoveTarget(reference.identifier)) {
  659. removeReference(reference, typeDefScope);
  660. }
  661. }
  662. for (const scope of [...scopeManager.scopes]) {
  663. if (isRemoveTarget(scope.block)) {
  664. removeScope(scopeManager, scope);
  665. }
  666. }
  667. }
  668. }
  669. function getConstraint(node, rawParam) {
  670. if (!node.constraint) {
  671. return "unknown";
  672. }
  673. let index = rawParam.indexOf(node.name.name) + node.name.name.length;
  674. let startIndex = null;
  675. while (index < rawParam.length) {
  676. if (startIndex == null) {
  677. if (rawParam.startsWith("extends", index)) {
  678. startIndex = index = index + 7;
  679. continue;
  680. }
  681. }
  682. else if (rawParam[index] === "=") {
  683. if (rawParam[index + 1] === ">") {
  684. index += 2;
  685. continue;
  686. }
  687. return rawParam.slice(startIndex, index);
  688. }
  689. if (rawParam.startsWith("//", index)) {
  690. const lfIndex = rawParam.indexOf("\n", index);
  691. if (lfIndex >= 0) {
  692. index = lfIndex + 1;
  693. continue;
  694. }
  695. return "unknown";
  696. }
  697. if (rawParam.startsWith("/*", index)) {
  698. const endIndex = rawParam.indexOf("*/", index);
  699. if (endIndex >= 0) {
  700. index = endIndex + 2;
  701. continue;
  702. }
  703. return "unknown";
  704. }
  705. index++;
  706. }
  707. if (startIndex == null) {
  708. return "unknown";
  709. }
  710. return rawParam.slice(startIndex);
  711. }
  712. function removeVariableDef(variable, def, scope) {
  713. const defIndex = variable.defs.indexOf(def);
  714. if (defIndex < 0) {
  715. return;
  716. }
  717. variable.defs.splice(defIndex, 1);
  718. if (variable.defs.length === 0) {
  719. referencesToThrough(variable.references, scope);
  720. variable.references.forEach((r) => {
  721. if (r.init) {
  722. r.init = false;
  723. }
  724. r.resolved = null;
  725. });
  726. scope.variables.splice(scope.variables.indexOf(variable), 1);
  727. const name = variable.name;
  728. if (variable === scope.set.get(name)) {
  729. scope.set.delete(name);
  730. }
  731. }
  732. else {
  733. const idIndex = variable.identifiers.indexOf(def.name);
  734. if (idIndex >= 0) {
  735. variable.identifiers.splice(idIndex, 1);
  736. }
  737. }
  738. }
  739. function referencesToThrough(references, baseScope) {
  740. let scope = baseScope;
  741. while (scope) {
  742. addAllReferences(scope.through, references);
  743. scope = scope.upper;
  744. }
  745. }
  746. function addAllReferences(list, elements) {
  747. list.push(...elements);
  748. list.sort((a, b) => a.identifier.range[0] - b.identifier.range[0]);
  749. }
  750. function removeReference(reference, baseScope) {
  751. if (reference.resolved) {
  752. if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
  753. const varIndex = baseScope.variables.indexOf(reference.resolved);
  754. if (varIndex >= 0) {
  755. baseScope.variables.splice(varIndex, 1);
  756. }
  757. const name = reference.identifier.name;
  758. if (reference.resolved === baseScope.set.get(name)) {
  759. baseScope.set.delete(name);
  760. }
  761. }
  762. else {
  763. const refIndex = reference.resolved.references.indexOf(reference);
  764. if (refIndex >= 0) {
  765. reference.resolved.references.splice(refIndex, 1);
  766. }
  767. }
  768. }
  769. let scope = baseScope;
  770. while (scope) {
  771. const refIndex = scope.references.indexOf(reference);
  772. if (refIndex >= 0) {
  773. scope.references.splice(refIndex, 1);
  774. }
  775. const throughIndex = scope.through.indexOf(reference);
  776. if (throughIndex >= 0) {
  777. scope.through.splice(throughIndex, 1);
  778. }
  779. scope = scope.upper;
  780. }
  781. }
  782. function removeScope(scopeManager, scope) {
  783. for (const childScope of scope.childScopes) {
  784. removeScope(scopeManager, childScope);
  785. }
  786. while (scope.references[0]) {
  787. removeReference(scope.references[0], scope);
  788. }
  789. const upper = scope.upper;
  790. if (upper) {
  791. const index = upper.childScopes.indexOf(scope);
  792. if (index >= 0) {
  793. upper.childScopes.splice(index, 1);
  794. }
  795. }
  796. const index = scopeManager.scopes.indexOf(scope);
  797. if (index >= 0) {
  798. scopeManager.scopes.splice(index, 1);
  799. }
  800. }
  801. const ALIAS_ITERATOR = /^([\s\S]*?(?:\s|\)))(\bin\b|\bof\b)([\s\S]*)$/u;
  802. const PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u;
  803. const DUMMY_PARENT$2 = {};
  804. const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u;
  805. const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u;
  806. function processVForAliasAndIterator(code) {
  807. const match = ALIAS_ITERATOR.exec(code);
  808. if (match != null) {
  809. const aliases = match[1];
  810. const parenMatch = PARENS.exec(aliases);
  811. return {
  812. aliases,
  813. hasParens: Boolean(parenMatch),
  814. aliasesWithBrackets: parenMatch
  815. ? `${parenMatch[1].slice(0, -1)}[${parenMatch[2]}]${parenMatch[3].slice(1)}`
  816. : `[${aliases.slice(0, -1)}]`,
  817. delimiter: match[2] || "",
  818. iterator: match[3],
  819. };
  820. }
  821. return {
  822. aliases: "",
  823. hasParens: false,
  824. aliasesWithBrackets: "",
  825. delimiter: "",
  826. iterator: code,
  827. };
  828. }
  829. function getCommaTokenBeforeNode(tokens, node) {
  830. let tokenIndex = sortedIndexBy__default["default"](tokens, { range: node.range }, (t) => t.range[0]);
  831. while (tokenIndex >= 0) {
  832. const token = tokens[tokenIndex];
  833. if (token.type === "Punctuator" && token.value === ",") {
  834. return token;
  835. }
  836. tokenIndex -= 1;
  837. }
  838. return null;
  839. }
  840. function throwEmptyError(locationCalculator, expected) {
  841. const loc = locationCalculator.getLocation(0);
  842. const err = new ParseError(`Expected to be ${expected}, but got empty.`, undefined, 0, loc.line, loc.column);
  843. fixErrorLocation(err, locationCalculator);
  844. throw err;
  845. }
  846. function throwUnexpectedTokenError(name, token) {
  847. const err = new ParseError(`Unexpected token '${name}'.`, undefined, token.range[0], token.loc.start.line, token.loc.start.column);
  848. throw err;
  849. }
  850. function throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator) {
  851. if (ParseError.isParseError(err)) {
  852. const endOffset = locationCalculator.getOffsetWithGap(code.length);
  853. if (err.index >= endOffset) {
  854. err.message = "Unexpected end of expression.";
  855. }
  856. }
  857. throw err;
  858. }
  859. function parseScriptFragment(code, locationCalculator, parserOptions) {
  860. return parseScriptFragmentWithOption(code, locationCalculator, parserOptions);
  861. }
  862. function parseScriptFragmentWithOption(code, locationCalculator, parserOptions, processOptions) {
  863. var _a;
  864. try {
  865. const result = parseScript$1(code, parserOptions);
  866. (_a = processOptions === null || processOptions === void 0 ? void 0 : processOptions.preFixLocationProcess) === null || _a === void 0 ? void 0 : _a.call(processOptions, result);
  867. fixLocations(result, locationCalculator);
  868. return result;
  869. }
  870. catch (err) {
  871. const perr = ParseError.normalize(err);
  872. if (perr) {
  873. fixErrorLocation(perr, locationCalculator);
  874. throw perr;
  875. }
  876. throw err;
  877. }
  878. }
  879. const validDivisionCharRE = /[\w).+\-_$\]]/u;
  880. function splitFilters(exp) {
  881. const result = [];
  882. let inSingle = false;
  883. let inDouble = false;
  884. let inTemplateString = false;
  885. let inRegex = false;
  886. let curly = 0;
  887. let square = 0;
  888. let paren = 0;
  889. let lastFilterIndex = 0;
  890. let c = 0;
  891. let prev = 0;
  892. for (let i = 0; i < exp.length; i++) {
  893. prev = c;
  894. c = exp.charCodeAt(i);
  895. if (inSingle) {
  896. if (c === 0x27 && prev !== 0x5c) {
  897. inSingle = false;
  898. }
  899. }
  900. else if (inDouble) {
  901. if (c === 0x22 && prev !== 0x5c) {
  902. inDouble = false;
  903. }
  904. }
  905. else if (inTemplateString) {
  906. if (c === 0x60 && prev !== 0x5c) {
  907. inTemplateString = false;
  908. }
  909. }
  910. else if (inRegex) {
  911. if (c === 0x2f && prev !== 0x5c) {
  912. inRegex = false;
  913. }
  914. }
  915. else if (c === 0x7c &&
  916. exp.charCodeAt(i + 1) !== 0x7c &&
  917. exp.charCodeAt(i - 1) !== 0x7c &&
  918. !curly &&
  919. !square &&
  920. !paren) {
  921. result.push(exp.slice(lastFilterIndex, i));
  922. lastFilterIndex = i + 1;
  923. }
  924. else {
  925. switch (c) {
  926. case 0x22:
  927. inDouble = true;
  928. break;
  929. case 0x27:
  930. inSingle = true;
  931. break;
  932. case 0x60:
  933. inTemplateString = true;
  934. break;
  935. case 0x28:
  936. paren++;
  937. break;
  938. case 0x29:
  939. paren--;
  940. break;
  941. case 0x5b:
  942. square++;
  943. break;
  944. case 0x5d:
  945. square--;
  946. break;
  947. case 0x7b:
  948. curly++;
  949. break;
  950. case 0x7d:
  951. curly--;
  952. break;
  953. }
  954. if (c === 0x2f) {
  955. let j = i - 1;
  956. let p;
  957. for (; j >= 0; j--) {
  958. p = exp.charAt(j);
  959. if (p !== " ") {
  960. break;
  961. }
  962. }
  963. if (!p || !validDivisionCharRE.test(p)) {
  964. inRegex = true;
  965. }
  966. }
  967. }
  968. }
  969. result.push(exp.slice(lastFilterIndex));
  970. return result;
  971. }
  972. function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) {
  973. debug('[script] parse expression: "0(%s)"', code);
  974. try {
  975. const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
  976. const { ast } = result;
  977. const tokens = ast.tokens || [];
  978. const comments = ast.comments || [];
  979. const references = analyzeExternalReferences(result, parserOptions);
  980. const statement = ast.body[0];
  981. const callExpression = statement.expression;
  982. const expression = callExpression.arguments[0];
  983. if (!allowEmpty && !expression) {
  984. return throwEmptyError(locationCalculator, "an expression");
  985. }
  986. if (expression && expression.type === "SpreadElement") {
  987. return throwUnexpectedTokenError("...", expression);
  988. }
  989. if (callExpression.arguments[1]) {
  990. const node = callExpression.arguments[1];
  991. return throwUnexpectedTokenError(",", getCommaTokenBeforeNode(tokens, node) || node);
  992. }
  993. tokens.shift();
  994. tokens.shift();
  995. tokens.pop();
  996. return { expression, tokens, comments, references, variables: [] };
  997. }
  998. catch (err) {
  999. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1000. }
  1001. }
  1002. function parseFilter(code, locationCalculator, parserOptions) {
  1003. debug('[script] parse filter: "%s"', code);
  1004. try {
  1005. const expression = {
  1006. type: "VFilter",
  1007. parent: null,
  1008. range: [0, 0],
  1009. loc: {},
  1010. callee: null,
  1011. arguments: [],
  1012. };
  1013. const tokens = [];
  1014. const comments = [];
  1015. const references = [];
  1016. const paren = code.indexOf("(");
  1017. const calleeCode = paren === -1 ? code : code.slice(0, paren);
  1018. const argsCode = paren === -1 ? null : code.slice(paren);
  1019. if (calleeCode.trim()) {
  1020. const spaces = /^\s*/u.exec(calleeCode)[0];
  1021. const subCalculator = locationCalculator.getSubCalculatorShift(spaces.length);
  1022. const { ast } = parseScriptFragment(`"${calleeCode.trim()}"`, subCalculator, parserOptions);
  1023. const statement = ast.body[0];
  1024. const callee = statement.expression;
  1025. if (callee.type !== "Literal") {
  1026. const { loc, range } = ast.tokens[0];
  1027. return throwUnexpectedTokenError('"', {
  1028. range: [range[1] - 1, range[1]],
  1029. loc: {
  1030. start: {
  1031. line: loc.end.line,
  1032. column: loc.end.column - 1,
  1033. },
  1034. end: loc.end,
  1035. },
  1036. });
  1037. }
  1038. expression.callee = {
  1039. type: "Identifier",
  1040. parent: expression,
  1041. range: [
  1042. callee.range[0],
  1043. subCalculator.getOffsetWithGap(calleeCode.trim().length),
  1044. ],
  1045. loc: {
  1046. start: callee.loc.start,
  1047. end: subCalculator.getLocation(calleeCode.trim().length),
  1048. },
  1049. name: String(callee.value),
  1050. };
  1051. tokens.push({
  1052. type: "Identifier",
  1053. value: calleeCode.trim(),
  1054. range: expression.callee.range,
  1055. loc: expression.callee.loc,
  1056. });
  1057. }
  1058. else {
  1059. return throwEmptyError(locationCalculator, "a filter name");
  1060. }
  1061. if (argsCode != null) {
  1062. const result = parseScriptFragment(`0${argsCode}`, locationCalculator
  1063. .getSubCalculatorAfter(paren)
  1064. .getSubCalculatorShift(-1), parserOptions);
  1065. const { ast } = result;
  1066. const statement = ast.body[0];
  1067. const callExpression = statement.expression;
  1068. ast.tokens.shift();
  1069. if (callExpression.type !== "CallExpression" ||
  1070. callExpression.callee.type !== "Literal") {
  1071. let nestCount = 1;
  1072. for (const token of ast.tokens.slice(1)) {
  1073. if (nestCount === 0) {
  1074. return throwUnexpectedTokenError(token.value, token);
  1075. }
  1076. if (token.type === "Punctuator" && token.value === "(") {
  1077. nestCount += 1;
  1078. }
  1079. if (token.type === "Punctuator" && token.value === ")") {
  1080. nestCount -= 1;
  1081. }
  1082. }
  1083. const token = last__default["default"](ast.tokens);
  1084. return throwUnexpectedTokenError(token.value, token);
  1085. }
  1086. for (const argument of callExpression.arguments) {
  1087. argument.parent = expression;
  1088. expression.arguments.push(argument);
  1089. }
  1090. tokens.push(...ast.tokens);
  1091. comments.push(...ast.comments);
  1092. references.push(...analyzeExternalReferences(result, parserOptions));
  1093. }
  1094. const firstToken = tokens[0];
  1095. const lastToken = last__default["default"](tokens);
  1096. expression.range = [firstToken.range[0], lastToken.range[1]];
  1097. expression.loc = { start: firstToken.loc.start, end: lastToken.loc.end };
  1098. return { expression, tokens, comments, references, variables: [] };
  1099. }
  1100. catch (err) {
  1101. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1102. }
  1103. }
  1104. function loadParser(parser) {
  1105. if (parser !== "espree") {
  1106. return require(parser);
  1107. }
  1108. return getEspreeFromUser();
  1109. }
  1110. function parseScript$1(code, parserOptions) {
  1111. const parser = typeof parserOptions.parser === "string"
  1112. ? loadParser(parserOptions.parser)
  1113. : isParserObject(parserOptions.parser)
  1114. ? parserOptions.parser
  1115. : getEspreeFromEcmaVersion(parserOptions.ecmaVersion);
  1116. const result = isEnhancedParserObject(parser)
  1117. ? parser.parseForESLint(code, parserOptions)
  1118. : parser.parse(code, parserOptions);
  1119. if (result.ast != null) {
  1120. return result;
  1121. }
  1122. return { ast: result };
  1123. }
  1124. function parseScriptElement(node, sfcCode, linesAndColumns, originalParserOptions) {
  1125. var _a, _b;
  1126. const parserOptions = isScriptSetupElement(node)
  1127. ? getScriptSetupParserOptions(originalParserOptions)
  1128. : Object.assign(Object.assign({}, originalParserOptions), { ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION });
  1129. let generic = null;
  1130. let code;
  1131. let offset;
  1132. const textNode = node.children[0];
  1133. if (textNode != null && textNode.type === "VText") {
  1134. const [scriptStartOffset, scriptEndOffset] = textNode.range;
  1135. code = sfcCode.slice(scriptStartOffset, scriptEndOffset);
  1136. offset = scriptStartOffset;
  1137. generic = extractGeneric(node);
  1138. if (generic) {
  1139. const defineTypesCode = `${generic.defineTypes
  1140. .map((e) => e.define)
  1141. .join(";")};\n`;
  1142. code = defineTypesCode + code;
  1143. offset -= defineTypesCode.length;
  1144. }
  1145. }
  1146. else {
  1147. code = "";
  1148. offset = node.startTag.range[1];
  1149. }
  1150. const locationCalculator = linesAndColumns.createOffsetLocationCalculator(offset);
  1151. const result = parseScriptFragment(code, locationCalculator, parserOptions);
  1152. if (generic) {
  1153. generic.postprocess({
  1154. result,
  1155. isRemoveTarget(nodeOrToken) {
  1156. return nodeOrToken.range[1] <= textNode.range[0];
  1157. },
  1158. getTypeDefScope(scopeManager) {
  1159. var _a;
  1160. return ((_a = scopeManager.globalScope.childScopes.find((s) => s.type === "module")) !== null && _a !== void 0 ? _a : scopeManager.globalScope);
  1161. },
  1162. });
  1163. const startToken = [
  1164. result.ast.body[0],
  1165. (_a = result.ast.tokens) === null || _a === void 0 ? void 0 : _a[0],
  1166. (_b = result.ast.comments) === null || _b === void 0 ? void 0 : _b[0],
  1167. ]
  1168. .filter((e) => Boolean(e))
  1169. .sort((a, b) => a.range[0] - b.range[0])
  1170. .find((t) => Boolean(t));
  1171. if (startToken && result.ast.range[0] !== startToken.range[0]) {
  1172. result.ast.range[0] = startToken.range[0];
  1173. if (result.ast.start != null) {
  1174. result.ast.start = startToken.start;
  1175. }
  1176. result.ast.loc.start = Object.assign({}, startToken.loc.start);
  1177. }
  1178. }
  1179. if (result.ast.tokens != null) {
  1180. const startTag = node.startTag;
  1181. const endTag = node.endTag;
  1182. result.ast.tokens.unshift({
  1183. type: "Punctuator",
  1184. range: startTag.range,
  1185. loc: startTag.loc,
  1186. value: "<script>",
  1187. });
  1188. if (endTag != null) {
  1189. result.ast.tokens.push({
  1190. type: "Punctuator",
  1191. range: endTag.range,
  1192. loc: endTag.loc,
  1193. value: "</script>",
  1194. });
  1195. }
  1196. }
  1197. return result;
  1198. }
  1199. function parseExpression(code, locationCalculator, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
  1200. var _a, _b;
  1201. debug('[script] parse expression: "%s"', code);
  1202. const [mainCode, ...filterCodes] = allowFilters && ((_b = (_a = parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.filter) !== null && _b !== void 0 ? _b : true)
  1203. ? splitFilters(code)
  1204. : [code];
  1205. if (filterCodes.length === 0) {
  1206. return parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty);
  1207. }
  1208. const retB = parseExpressionBody(mainCode, locationCalculator, parserOptions);
  1209. if (!retB.expression) {
  1210. return retB;
  1211. }
  1212. const ret = retB;
  1213. ret.expression = {
  1214. type: "VFilterSequenceExpression",
  1215. parent: null,
  1216. expression: retB.expression,
  1217. filters: [],
  1218. range: retB.expression.range.slice(0),
  1219. loc: Object.assign({}, retB.expression.loc),
  1220. };
  1221. ret.expression.expression.parent = ret.expression;
  1222. let prevLoc = mainCode.length;
  1223. for (const filterCode of filterCodes) {
  1224. ret.tokens.push(fixLocation({
  1225. type: "Punctuator",
  1226. value: "|",
  1227. range: [prevLoc, prevLoc + 1],
  1228. loc: {},
  1229. }, locationCalculator));
  1230. const retF = parseFilter(filterCode, locationCalculator.getSubCalculatorShift(prevLoc + 1), parserOptions);
  1231. if (retF) {
  1232. if (retF.expression) {
  1233. ret.expression.filters.push(retF.expression);
  1234. retF.expression.parent = ret.expression;
  1235. }
  1236. ret.tokens.push(...retF.tokens);
  1237. ret.comments.push(...retF.comments);
  1238. ret.references.push(...retF.references);
  1239. }
  1240. prevLoc += 1 + filterCode.length;
  1241. }
  1242. const lastToken = last__default["default"](ret.tokens);
  1243. ret.expression.range[1] = lastToken.range[1];
  1244. ret.expression.loc.end = lastToken.loc.end;
  1245. return ret;
  1246. }
  1247. function parseVForExpression(code, locationCalculator, parserOptions) {
  1248. if (code.trim() === "") {
  1249. throwEmptyError(locationCalculator, "'<alias> in <expression>'");
  1250. }
  1251. if (isEcmaVersion5(parserOptions)) {
  1252. return parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions);
  1253. }
  1254. const processed = processVForAliasAndIterator(code);
  1255. if (!processed.aliases.trim()) {
  1256. return throwEmptyError(locationCalculator, "an alias");
  1257. }
  1258. try {
  1259. debug('[script] parse v-for expression: "for(%s%s%s);"', processed.aliasesWithBrackets, processed.delimiter, processed.iterator);
  1260. const result = parseScriptFragment(`for(let ${processed.aliasesWithBrackets}${processed.delimiter}${processed.iterator});`, locationCalculator.getSubCalculatorShift(processed.hasParens ? -8 : -9), parserOptions);
  1261. const { ast } = result;
  1262. const tokens = ast.tokens || [];
  1263. const comments = ast.comments || [];
  1264. const scope = analyzeVariablesAndExternalReferences(result, "v-for", parserOptions);
  1265. const references = scope.references;
  1266. const variables = scope.variables;
  1267. const statement = ast.body[0];
  1268. const varDecl = statement.left;
  1269. const id = varDecl.declarations[0].id;
  1270. const left = id.elements;
  1271. const right = statement.right;
  1272. if (!processed.hasParens && !left.length) {
  1273. return throwEmptyError(locationCalculator, "an alias");
  1274. }
  1275. tokens.shift();
  1276. tokens.shift();
  1277. tokens.shift();
  1278. tokens.pop();
  1279. tokens.pop();
  1280. const closeOffset = statement.left.range[1] - 1;
  1281. const closeIndex = tokens.findIndex((t) => t.range[0] === closeOffset);
  1282. if (processed.hasParens) {
  1283. const open = tokens[0];
  1284. if (open != null) {
  1285. open.value = "(";
  1286. }
  1287. const close = tokens[closeIndex];
  1288. if (close != null) {
  1289. close.value = ")";
  1290. }
  1291. }
  1292. else {
  1293. tokens.splice(closeIndex, 1);
  1294. tokens.shift();
  1295. }
  1296. const firstToken = tokens[0] || statement.left;
  1297. const lastToken = tokens[tokens.length - 1] || statement.right;
  1298. const expression = {
  1299. type: "VForExpression",
  1300. range: [firstToken.range[0], lastToken.range[1]],
  1301. loc: { start: firstToken.loc.start, end: lastToken.loc.end },
  1302. parent: DUMMY_PARENT$2,
  1303. left,
  1304. right,
  1305. };
  1306. for (const l of left) {
  1307. if (l != null) {
  1308. l.parent = expression;
  1309. }
  1310. }
  1311. right.parent = expression;
  1312. return { expression, tokens, comments, references, variables };
  1313. }
  1314. catch (err) {
  1315. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1316. }
  1317. }
  1318. function isEcmaVersion5(parserOptions) {
  1319. const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions);
  1320. return ecmaVersion != null && ecmaVersion <= 5;
  1321. }
  1322. function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions) {
  1323. const processed = processVForAliasAndIterator(code);
  1324. if (!processed.aliases.trim()) {
  1325. return throwEmptyError(locationCalculator, "an alias");
  1326. }
  1327. try {
  1328. const tokens = [];
  1329. const comments = [];
  1330. const parsedAliases = parseVForAliasesForEcmaVersion5(processed.aliasesWithBrackets, locationCalculator.getSubCalculatorShift(processed.hasParens ? 0 : -1), parserOptions);
  1331. if (processed.hasParens) {
  1332. const open = parsedAliases.tokens[0];
  1333. if (open != null) {
  1334. open.value = "(";
  1335. }
  1336. const close = last__default["default"](parsedAliases.tokens);
  1337. if (close != null) {
  1338. close.value = ")";
  1339. }
  1340. }
  1341. else {
  1342. parsedAliases.tokens.shift();
  1343. parsedAliases.tokens.pop();
  1344. }
  1345. tokens.push(...parsedAliases.tokens);
  1346. comments.push(...parsedAliases.comments);
  1347. const { left, variables } = parsedAliases;
  1348. if (!processed.hasParens && !left.length) {
  1349. return throwEmptyError(locationCalculator, "an alias");
  1350. }
  1351. const delimiterStart = processed.aliases.length;
  1352. const delimiterEnd = delimiterStart + processed.delimiter.length;
  1353. tokens.push(fixLocation({
  1354. type: processed.delimiter === "in" ? "Keyword" : "Identifier",
  1355. value: processed.delimiter,
  1356. start: delimiterStart,
  1357. end: delimiterEnd,
  1358. loc: {},
  1359. range: [delimiterStart, delimiterEnd],
  1360. }, locationCalculator));
  1361. const parsedIterator = parseVForIteratorForEcmaVersion5(processed.iterator, locationCalculator.getSubCalculatorShift(delimiterEnd), parserOptions);
  1362. tokens.push(...parsedIterator.tokens);
  1363. comments.push(...parsedIterator.comments);
  1364. const { right, references } = parsedIterator;
  1365. const firstToken = tokens[0];
  1366. const lastToken = last__default["default"](tokens) || firstToken;
  1367. const expression = {
  1368. type: "VForExpression",
  1369. range: [firstToken.range[0], lastToken.range[1]],
  1370. loc: { start: firstToken.loc.start, end: lastToken.loc.end },
  1371. parent: DUMMY_PARENT$2,
  1372. left,
  1373. right,
  1374. };
  1375. for (const l of left) {
  1376. if (l != null) {
  1377. l.parent = expression;
  1378. }
  1379. }
  1380. right.parent = expression;
  1381. return { expression, tokens, comments, references, variables };
  1382. }
  1383. catch (err) {
  1384. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1385. }
  1386. }
  1387. function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions) {
  1388. const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
  1389. const { ast } = result;
  1390. const tokens = ast.tokens || [];
  1391. const comments = ast.comments || [];
  1392. const variables = analyzeExternalReferences(result, parserOptions).map(transformVariable);
  1393. const statement = ast.body[0];
  1394. const callExpression = statement.expression;
  1395. const expression = callExpression.arguments[0];
  1396. const left = expression.elements.filter((e) => {
  1397. if (e == null || e.type === "Identifier") {
  1398. return true;
  1399. }
  1400. const errorToken = tokens.find((t) => e.range[0] <= t.range[0] && t.range[1] <= e.range[1]);
  1401. return throwUnexpectedTokenError(errorToken.value, errorToken);
  1402. });
  1403. tokens.shift();
  1404. tokens.shift();
  1405. tokens.pop();
  1406. return { left, tokens, comments, variables };
  1407. function transformVariable(reference) {
  1408. const ret = {
  1409. id: reference.id,
  1410. kind: "v-for",
  1411. references: [],
  1412. };
  1413. Object.defineProperty(ret, "references", { enumerable: false });
  1414. return ret;
  1415. }
  1416. }
  1417. function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOptions) {
  1418. const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
  1419. const { ast } = result;
  1420. const tokens = ast.tokens || [];
  1421. const comments = ast.comments || [];
  1422. const references = analyzeExternalReferences(result, parserOptions);
  1423. const statement = ast.body[0];
  1424. const callExpression = statement.expression;
  1425. const expression = callExpression.arguments[0];
  1426. if (!expression) {
  1427. return throwEmptyError(locationCalculator, "an expression");
  1428. }
  1429. if (expression && expression.type === "SpreadElement") {
  1430. return throwUnexpectedTokenError("...", expression);
  1431. }
  1432. const right = expression;
  1433. tokens.shift();
  1434. tokens.shift();
  1435. tokens.pop();
  1436. return { right, tokens, comments, references };
  1437. }
  1438. function parseVOnExpression(code, locationCalculator, parserOptions) {
  1439. if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) {
  1440. return parseExpressionBody(code, locationCalculator, parserOptions);
  1441. }
  1442. return parseVOnExpressionBody(code, locationCalculator, parserOptions);
  1443. }
  1444. function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
  1445. debug('[script] parse v-on expression: "void function($event){%s}"', code);
  1446. if (code.trim() === "") {
  1447. throwEmptyError(locationCalculator, "statements");
  1448. }
  1449. try {
  1450. const result = parseScriptFragment(`void function($event){${code}}`, locationCalculator.getSubCalculatorShift(-22), parserOptions);
  1451. const { ast } = result;
  1452. const references = analyzeExternalReferences(result, parserOptions);
  1453. const outermostStatement = ast.body[0];
  1454. const functionDecl = outermostStatement.expression.argument;
  1455. const block = functionDecl.body;
  1456. const body = block.body;
  1457. const firstStatement = first__default["default"](body);
  1458. const lastStatement = last__default["default"](body);
  1459. const expression = {
  1460. type: "VOnExpression",
  1461. range: [
  1462. firstStatement != null
  1463. ? firstStatement.range[0]
  1464. : block.range[0] + 1,
  1465. lastStatement != null
  1466. ? lastStatement.range[1]
  1467. : block.range[1] - 1,
  1468. ],
  1469. loc: {
  1470. start: firstStatement != null
  1471. ? firstStatement.loc.start
  1472. : locationCalculator.getLocation(1),
  1473. end: lastStatement != null
  1474. ? lastStatement.loc.end
  1475. : locationCalculator.getLocation(code.length + 1),
  1476. },
  1477. parent: DUMMY_PARENT$2,
  1478. body,
  1479. };
  1480. const tokens = ast.tokens || [];
  1481. const comments = ast.comments || [];
  1482. for (const b of body) {
  1483. b.parent = expression;
  1484. }
  1485. tokens.splice(0, 6);
  1486. tokens.pop();
  1487. return { expression, tokens, comments, references, variables: [] };
  1488. }
  1489. catch (err) {
  1490. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1491. }
  1492. }
  1493. function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
  1494. debug('[script] parse slot-scope expression: "void function(%s) {}"', code);
  1495. if (code.trim() === "") {
  1496. throwEmptyError(locationCalculator, "an identifier or an array/object pattern");
  1497. }
  1498. try {
  1499. const result = parseScriptFragment(`void function(${code}) {}`, locationCalculator.getSubCalculatorShift(-14), parserOptions);
  1500. const { ast } = result;
  1501. const statement = ast.body[0];
  1502. const rawExpression = statement.expression;
  1503. const functionDecl = rawExpression.argument;
  1504. const params = functionDecl.params;
  1505. if (params.length === 0) {
  1506. return {
  1507. expression: null,
  1508. tokens: [],
  1509. comments: [],
  1510. references: [],
  1511. variables: [],
  1512. };
  1513. }
  1514. const tokens = ast.tokens || [];
  1515. const comments = ast.comments || [];
  1516. const scope = analyzeVariablesAndExternalReferences(result, "scope", parserOptions);
  1517. const references = scope.references;
  1518. const variables = scope.variables;
  1519. const firstParam = first__default["default"](params);
  1520. const lastParam = last__default["default"](params);
  1521. const expression = {
  1522. type: "VSlotScopeExpression",
  1523. range: [firstParam.range[0], lastParam.range[1]],
  1524. loc: { start: firstParam.loc.start, end: lastParam.loc.end },
  1525. parent: DUMMY_PARENT$2,
  1526. params: functionDecl.params,
  1527. };
  1528. for (const param of params) {
  1529. param.parent = expression;
  1530. }
  1531. tokens.shift();
  1532. tokens.shift();
  1533. tokens.shift();
  1534. tokens.pop();
  1535. tokens.pop();
  1536. tokens.pop();
  1537. return { expression, tokens, comments, references, variables };
  1538. }
  1539. catch (err) {
  1540. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1541. }
  1542. }
  1543. function parseGenericExpression(code, locationCalculator, parserOptions) {
  1544. debug('[script] parse generic definition: "void function<%s>() {}"', code);
  1545. if (code.trim() === "") {
  1546. throwEmptyError(locationCalculator, "a type parameter");
  1547. }
  1548. function getParams(result) {
  1549. const { ast } = result;
  1550. const statement = ast.body[0];
  1551. const rawExpression = statement.expression;
  1552. const classDecl = rawExpression.argument;
  1553. const typeParameters = classDecl
  1554. .typeParameters;
  1555. return typeParameters === null || typeParameters === void 0 ? void 0 : typeParameters.params;
  1556. }
  1557. try {
  1558. const rawParams = [];
  1559. const scriptLet = `void function<${code}>(){}`;
  1560. const result = parseScriptFragmentWithOption(scriptLet, locationCalculator.getSubCalculatorShift(-14), Object.assign(Object.assign({}, parserOptions), { project: undefined }), {
  1561. preFixLocationProcess(preResult) {
  1562. const params = getParams(preResult);
  1563. if (params) {
  1564. for (const param of params) {
  1565. rawParams.push(scriptLet.slice(param.range[0], param.range[1]));
  1566. }
  1567. }
  1568. },
  1569. });
  1570. const { ast } = result;
  1571. const params = getParams(result);
  1572. if (!params || params.length === 0) {
  1573. return {
  1574. expression: null,
  1575. tokens: [],
  1576. comments: [],
  1577. references: [],
  1578. variables: [],
  1579. };
  1580. }
  1581. const tokens = ast.tokens || [];
  1582. const comments = ast.comments || [];
  1583. const scope = analyzeVariablesAndExternalReferences(result, "generic", parserOptions);
  1584. const references = scope.references;
  1585. const variables = scope.variables;
  1586. const firstParam = first__default["default"](params);
  1587. const lastParam = last__default["default"](params);
  1588. const expression = {
  1589. type: "VGenericExpression",
  1590. range: [firstParam.range[0], lastParam.range[1]],
  1591. loc: { start: firstParam.loc.start, end: lastParam.loc.end },
  1592. parent: DUMMY_PARENT$2,
  1593. params,
  1594. rawParams,
  1595. };
  1596. for (const param of params) {
  1597. ;
  1598. param.parent = expression;
  1599. }
  1600. tokens.shift();
  1601. tokens.shift();
  1602. tokens.shift();
  1603. tokens.pop();
  1604. tokens.pop();
  1605. tokens.pop();
  1606. tokens.pop();
  1607. tokens.pop();
  1608. return { expression, tokens, comments, references, variables };
  1609. }
  1610. catch (err) {
  1611. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1612. }
  1613. }
  1614. function replaceTokens(document, node, newTokens) {
  1615. if (document == null) {
  1616. return;
  1617. }
  1618. const index = sortedIndexBy__default["default"](document.tokens, node, byRange0);
  1619. const count = sortedLastIndexBy__default["default"](document.tokens, node, byRange1) - index;
  1620. document.tokens.splice(index, count, ...newTokens);
  1621. }
  1622. function replaceAndSplitTokens(document, node, newTokens) {
  1623. if (document == null) {
  1624. return;
  1625. }
  1626. const index = sortedIndexBy__default["default"](document.tokens, node, byRange0);
  1627. if (document.tokens.length === index ||
  1628. node.range[0] < document.tokens[index].range[0]) {
  1629. const beforeToken = document.tokens[index - 1];
  1630. const value = beforeToken.value;
  1631. const splitOffset = node.range[0] - beforeToken.range[0];
  1632. const afterToken = {
  1633. type: beforeToken.type,
  1634. range: [node.range[0], beforeToken.range[1]],
  1635. loc: {
  1636. start: Object.assign({}, node.loc.start),
  1637. end: Object.assign({}, beforeToken.loc.end),
  1638. },
  1639. value: value.slice(splitOffset),
  1640. };
  1641. beforeToken.range[1] = node.range[0];
  1642. beforeToken.loc.end = Object.assign({}, node.loc.start);
  1643. beforeToken.value = value.slice(0, splitOffset);
  1644. document.tokens.splice(index, 0, afterToken);
  1645. }
  1646. let lastIndex = sortedLastIndexBy__default["default"](document.tokens, node, byRange1);
  1647. if (lastIndex === 0 ||
  1648. node.range[1] < document.tokens[lastIndex].range[1]) {
  1649. const beforeToken = document.tokens[lastIndex];
  1650. const value = beforeToken.value;
  1651. const splitOffset = beforeToken.range[1] -
  1652. beforeToken.range[0] -
  1653. (beforeToken.range[1] - node.range[1]);
  1654. const afterToken = {
  1655. type: beforeToken.type,
  1656. range: [node.range[1], beforeToken.range[1]],
  1657. loc: {
  1658. start: Object.assign({}, node.loc.end),
  1659. end: Object.assign({}, beforeToken.loc.end),
  1660. },
  1661. value: value.slice(splitOffset),
  1662. };
  1663. beforeToken.range[1] = node.range[1];
  1664. beforeToken.loc.end = Object.assign({}, node.loc.end);
  1665. beforeToken.value = value.slice(0, splitOffset);
  1666. document.tokens.splice(lastIndex + 1, 0, afterToken);
  1667. lastIndex++;
  1668. }
  1669. const count = lastIndex - index;
  1670. document.tokens.splice(index, count, ...newTokens);
  1671. }
  1672. function insertComments(document, newComments) {
  1673. if (document == null || newComments.length === 0) {
  1674. return;
  1675. }
  1676. const index = sortedIndexBy__default["default"](document.comments, newComments[0], byRange0);
  1677. document.comments.splice(index, 0, ...newComments);
  1678. }
  1679. function createSimpleToken(type, start, end, value, linesAndColumns) {
  1680. return {
  1681. type,
  1682. range: [start, end],
  1683. loc: {
  1684. start: linesAndColumns.getLocFromIndex(start),
  1685. end: linesAndColumns.getLocFromIndex(end),
  1686. },
  1687. value,
  1688. };
  1689. }
  1690. function byRange0(x) {
  1691. return x.range[0];
  1692. }
  1693. function byRange1(x) {
  1694. return x.range[1];
  1695. }
  1696. function insertError(document, error) {
  1697. if (document == null) {
  1698. return;
  1699. }
  1700. const index = sortedIndexBy__default["default"](document.errors, error, byIndex);
  1701. document.errors.splice(index, 0, error);
  1702. }
  1703. function byIndex(x) {
  1704. return x.index;
  1705. }
  1706. function camelize(str) {
  1707. return str.replace(/-(\w)/gu, (_, c) => (c ? c.toUpperCase() : ""));
  1708. }
  1709. const shorthandSign = /^[.:@#]/u;
  1710. const shorthandNameMap = { ":": "bind", ".": "bind", "@": "on", "#": "slot" };
  1711. const invalidDynamicArgumentNextChar = /^[\s\r\n=/>]$/u;
  1712. function getTagName$1(startTagOrElement, isSFC) {
  1713. return isSFC ? startTagOrElement.rawName : startTagOrElement.name;
  1714. }
  1715. function parseDirectiveKeyStatically(node, document) {
  1716. const { name: text, rawName: rawText, range: [offset], loc: { start: { column, line }, }, } = node;
  1717. const directiveKey = {
  1718. type: "VDirectiveKey",
  1719. range: node.range,
  1720. loc: node.loc,
  1721. parent: node.parent,
  1722. name: null,
  1723. argument: null,
  1724. modifiers: [],
  1725. };
  1726. let i = 0;
  1727. function createIdentifier(start, end, name) {
  1728. return {
  1729. type: "VIdentifier",
  1730. parent: directiveKey,
  1731. range: [offset + start, offset + end],
  1732. loc: {
  1733. start: { column: column + start, line },
  1734. end: { column: column + end, line },
  1735. },
  1736. name: name || text.slice(start, end),
  1737. rawName: rawText.slice(start, end),
  1738. };
  1739. }
  1740. if (shorthandSign.test(text)) {
  1741. const sign = text[0];
  1742. directiveKey.name = createIdentifier(0, 1, shorthandNameMap[sign]);
  1743. i = 1;
  1744. }
  1745. else {
  1746. const colon = text.indexOf(":");
  1747. if (colon !== -1) {
  1748. directiveKey.name = createIdentifier(0, colon);
  1749. i = colon + 1;
  1750. }
  1751. }
  1752. if (directiveKey.name != null && text[i] === "[") {
  1753. const len = text.slice(i).lastIndexOf("]");
  1754. if (len !== -1) {
  1755. directiveKey.argument = createIdentifier(i, i + len + 1);
  1756. i = i + len + 1 + (text[i + len + 1] === "." ? 1 : 0);
  1757. }
  1758. }
  1759. const modifiers = text
  1760. .slice(i)
  1761. .split(".")
  1762. .map((modifierName) => {
  1763. const modifier = createIdentifier(i, i + modifierName.length);
  1764. if (modifierName === "" && i < text.length) {
  1765. insertError(document, new ParseError(`Unexpected token '${text[i]}'`, undefined, offset + i, line, column + i));
  1766. }
  1767. i += modifierName.length + 1;
  1768. return modifier;
  1769. });
  1770. if (directiveKey.name == null) {
  1771. directiveKey.name = modifiers.shift();
  1772. }
  1773. else if (directiveKey.argument == null && modifiers[0].name !== "") {
  1774. directiveKey.argument = modifiers.shift() || null;
  1775. }
  1776. directiveKey.modifiers = modifiers.filter(isNotEmptyModifier);
  1777. if (directiveKey.name.name === "v-") {
  1778. insertError(document, new ParseError(`Unexpected token '${text[directiveKey.name.range[1] - offset]}'`, undefined, directiveKey.name.range[1], directiveKey.name.loc.end.line, directiveKey.name.loc.end.column));
  1779. }
  1780. if (directiveKey.name.rawName === "." &&
  1781. !directiveKey.modifiers.some(isPropModifier)) {
  1782. const pos = (directiveKey.argument || directiveKey.name).range[1] - offset;
  1783. const propModifier = createIdentifier(pos, pos, "prop");
  1784. directiveKey.modifiers.unshift(propModifier);
  1785. }
  1786. return directiveKey;
  1787. }
  1788. function isPropModifier(node) {
  1789. return node.name === "prop";
  1790. }
  1791. function isNotEmptyModifier(node) {
  1792. return node.name !== "";
  1793. }
  1794. function parseDirectiveKeyTokens(node) {
  1795. const { name, argument, modifiers } = node;
  1796. const shorthand = name.range[1] - name.range[0] === 1;
  1797. const tokens = [];
  1798. if (shorthand) {
  1799. tokens.push({
  1800. type: "Punctuator",
  1801. range: name.range,
  1802. loc: name.loc,
  1803. value: name.rawName,
  1804. });
  1805. }
  1806. else {
  1807. tokens.push({
  1808. type: "HTMLIdentifier",
  1809. range: name.range,
  1810. loc: name.loc,
  1811. value: name.rawName,
  1812. });
  1813. if (argument) {
  1814. tokens.push({
  1815. type: "Punctuator",
  1816. range: [name.range[1], argument.range[0]],
  1817. loc: { start: name.loc.end, end: argument.loc.start },
  1818. value: ":",
  1819. });
  1820. }
  1821. }
  1822. if (argument) {
  1823. tokens.push({
  1824. type: "HTMLIdentifier",
  1825. range: argument.range,
  1826. loc: argument.loc,
  1827. value: argument.rawName,
  1828. });
  1829. }
  1830. let lastNode = argument || name;
  1831. for (const modifier of modifiers) {
  1832. if (modifier.rawName === "") {
  1833. continue;
  1834. }
  1835. tokens.push({
  1836. type: "Punctuator",
  1837. range: [lastNode.range[1], modifier.range[0]],
  1838. loc: { start: lastNode.loc.end, end: modifier.loc.start },
  1839. value: ".",
  1840. }, {
  1841. type: "HTMLIdentifier",
  1842. range: modifier.range,
  1843. loc: modifier.loc,
  1844. value: modifier.rawName,
  1845. });
  1846. lastNode = modifier;
  1847. }
  1848. return tokens;
  1849. }
  1850. function convertDynamicArgument(node, document, parserOptions, locationCalculator) {
  1851. const { argument } = node;
  1852. if (!(argument != null &&
  1853. argument.type === "VIdentifier" &&
  1854. argument.name.startsWith("[") &&
  1855. argument.name.endsWith("]"))) {
  1856. return;
  1857. }
  1858. const { rawName, range, loc } = argument;
  1859. try {
  1860. const { comments, expression, references, tokens } = parseExpression(rawName.slice(1, -1), locationCalculator.getSubCalculatorAfter(range[0] + 1), parserOptions);
  1861. node.argument = {
  1862. type: "VExpressionContainer",
  1863. range,
  1864. loc,
  1865. parent: node,
  1866. expression,
  1867. references,
  1868. };
  1869. if (expression != null) {
  1870. expression.parent = node.argument;
  1871. }
  1872. tokens.unshift(createSimpleToken("Punctuator", range[0], range[0] + 1, "[", locationCalculator));
  1873. tokens.push(createSimpleToken("Punctuator", range[1] - 1, range[1], "]", locationCalculator));
  1874. replaceTokens(document, node.argument, tokens);
  1875. insertComments(document, comments);
  1876. }
  1877. catch (error) {
  1878. debug("[template] Parse error: %s", error);
  1879. if (ParseError.isParseError(error)) {
  1880. node.argument = {
  1881. type: "VExpressionContainer",
  1882. range,
  1883. loc,
  1884. parent: node,
  1885. expression: null,
  1886. references: [],
  1887. };
  1888. insertError(document, error);
  1889. }
  1890. else {
  1891. throw error;
  1892. }
  1893. }
  1894. }
  1895. function createDirectiveKey(node, document, parserOptions, locationCalculator) {
  1896. const directiveKey = parseDirectiveKeyStatically(node, document);
  1897. const tokens = parseDirectiveKeyTokens(directiveKey);
  1898. replaceTokens(document, directiveKey, tokens);
  1899. if (directiveKey.name.name.startsWith("v-")) {
  1900. directiveKey.name.name = directiveKey.name.name.slice(2);
  1901. }
  1902. if (directiveKey.name.rawName.startsWith("v-")) {
  1903. directiveKey.name.rawName = directiveKey.name.rawName.slice(2);
  1904. }
  1905. convertDynamicArgument(directiveKey, document, parserOptions, locationCalculator);
  1906. return directiveKey;
  1907. }
  1908. function parseAttributeValue(code, parserOptions, scriptParserOptions, globalLocationCalculator, node, element, directiveKey) {
  1909. const firstChar = code[node.range[0]];
  1910. const quoted = firstChar === '"' || firstChar === "'";
  1911. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(node.range[0] + (quoted ? 1 : 0));
  1912. const directiveKind = getStandardDirectiveKind(parserOptions, element, directiveKey);
  1913. let result;
  1914. if (quoted && node.value === "") {
  1915. result = {
  1916. expression: null,
  1917. tokens: [],
  1918. comments: [],
  1919. variables: [],
  1920. references: [],
  1921. };
  1922. }
  1923. else if (directiveKind === "for") {
  1924. result = parseVForExpression(node.value, locationCalculator, parserOptions);
  1925. }
  1926. else if (directiveKind === "on" && directiveKey.argument != null) {
  1927. result = parseVOnExpression(node.value, locationCalculator, parserOptions);
  1928. }
  1929. else if (directiveKind === "slot") {
  1930. result = parseSlotScopeExpression(node.value, locationCalculator, parserOptions);
  1931. }
  1932. else if (directiveKind === "bind") {
  1933. result = parseExpression(node.value, locationCalculator, parserOptions, { allowFilters: true });
  1934. }
  1935. else if (directiveKind === "generic") {
  1936. result = parseGenericExpression(node.value, locationCalculator, scriptParserOptions);
  1937. }
  1938. else {
  1939. result = parseExpression(node.value, locationCalculator, parserOptions);
  1940. }
  1941. if (quoted) {
  1942. result.tokens.unshift(createSimpleToken("Punctuator", node.range[0], node.range[0] + 1, firstChar, globalLocationCalculator));
  1943. result.tokens.push(createSimpleToken("Punctuator", node.range[1] - 1, node.range[1], firstChar, globalLocationCalculator));
  1944. }
  1945. return result;
  1946. }
  1947. function getStandardDirectiveKind(parserOptions, element, directiveKey) {
  1948. const directiveName = directiveKey.name.name;
  1949. if (directiveName === "for") {
  1950. return "for";
  1951. }
  1952. else if (directiveName === "on") {
  1953. return "on";
  1954. }
  1955. else if (directiveName === "slot" ||
  1956. directiveName === "slot-scope" ||
  1957. (directiveName === "scope" &&
  1958. getTagName$1(element, isSFCFile(parserOptions)) === "template")) {
  1959. return "slot";
  1960. }
  1961. else if (directiveName === "bind") {
  1962. return "bind";
  1963. }
  1964. else if (directiveName === "generic" &&
  1965. element.parent.type === "VDocumentFragment" &&
  1966. getTagName$1(element, isSFCFile(parserOptions)) === "script" &&
  1967. isScriptSetupElement(element) &&
  1968. isTSLang(element)) {
  1969. return "generic";
  1970. }
  1971. return null;
  1972. }
  1973. function resolveReference(referene, element) {
  1974. let node = element;
  1975. while (node != null && node.type === "VElement") {
  1976. for (const variable of node.variables) {
  1977. if (variable.id.name === referene.id.name) {
  1978. referene.variable = variable;
  1979. variable.references.push(referene);
  1980. return;
  1981. }
  1982. }
  1983. node = node.parent;
  1984. }
  1985. }
  1986. function convertToDirective(code, parserOptions, scriptParserOptions, locationCalculator, node) {
  1987. debug('[template] convert to directive: %s="%s" %j', node.key.name, node.value && node.value.value, node.range);
  1988. const document = getOwnerDocument(node);
  1989. const directive = node;
  1990. directive.directive = true;
  1991. directive.key = createDirectiveKey(node.key, document, parserOptions, locationCalculator);
  1992. const { argument } = directive.key;
  1993. if (argument &&
  1994. argument.type === "VIdentifier" &&
  1995. argument.name.startsWith("[")) {
  1996. const nextChar = code[argument.range[1]];
  1997. if (nextChar == null || invalidDynamicArgumentNextChar.test(nextChar)) {
  1998. const char = nextChar == null ? "EOF" : JSON.stringify(nextChar).slice(1, -1);
  1999. insertError(document, new ParseError(`Dynamic argument cannot contain the '${char}' character.`, undefined, argument.range[1], argument.loc.end.line, argument.loc.end.column));
  2000. }
  2001. }
  2002. if (node.value == null) {
  2003. if (directive.key.name.name === "bind") {
  2004. convertForVBindSameNameShorthandValue(directive, parserOptions, locationCalculator);
  2005. }
  2006. return;
  2007. }
  2008. try {
  2009. const ret = parseAttributeValue(code, parserOptions, scriptParserOptions, locationCalculator, node.value, node.parent.parent, directive.key);
  2010. directive.value = {
  2011. type: "VExpressionContainer",
  2012. range: node.value.range,
  2013. loc: node.value.loc,
  2014. parent: directive,
  2015. expression: ret.expression,
  2016. references: ret.references,
  2017. };
  2018. if (ret.expression != null) {
  2019. ret.expression.parent = directive.value;
  2020. }
  2021. for (const variable of ret.variables) {
  2022. node.parent.parent.variables.push(variable);
  2023. }
  2024. replaceTokens(document, node.value, ret.tokens);
  2025. insertComments(document, ret.comments);
  2026. }
  2027. catch (err) {
  2028. debug("[template] Parse error: %s", err);
  2029. if (ParseError.isParseError(err)) {
  2030. directive.value = {
  2031. type: "VExpressionContainer",
  2032. range: node.value.range,
  2033. loc: node.value.loc,
  2034. parent: directive,
  2035. expression: null,
  2036. references: [],
  2037. };
  2038. insertError(document, err);
  2039. }
  2040. else {
  2041. throw err;
  2042. }
  2043. }
  2044. }
  2045. function convertForVBindSameNameShorthandValue(directive, parserOptions, locationCalculator) {
  2046. if (directive.key.name.name !== "bind" ||
  2047. directive.key.argument == null ||
  2048. directive.key.argument.type !== "VIdentifier") {
  2049. return;
  2050. }
  2051. const vId = directive.key.argument;
  2052. const camelName = camelize(vId.rawName);
  2053. let result = null;
  2054. try {
  2055. result = parseScriptFragment(camelName, locationCalculator.getSubCalculatorAfter(vId.range[0]), parserOptions);
  2056. }
  2057. catch (err) {
  2058. debug("[template] Parse error: %s", err);
  2059. }
  2060. if (result == null ||
  2061. result.ast.body.length !== 1 ||
  2062. result.ast.body[0].type !== "ExpressionStatement" ||
  2063. result.ast.body[0].expression.type !== "Identifier") {
  2064. return;
  2065. }
  2066. const id = result.ast.body[0].expression;
  2067. id.range[1] = vId.range[1];
  2068. id.loc.end = Object.assign({}, vId.loc.end);
  2069. if (id.end != null) {
  2070. id.end = vId.end;
  2071. }
  2072. directive.value = {
  2073. type: "VExpressionContainer",
  2074. range: [...vId.range],
  2075. loc: {
  2076. start: Object.assign({}, vId.loc.start),
  2077. end: Object.assign({}, vId.loc.end),
  2078. },
  2079. parent: directive,
  2080. expression: id,
  2081. references: [
  2082. {
  2083. id,
  2084. mode: "r",
  2085. variable: null,
  2086. },
  2087. ],
  2088. };
  2089. id.parent = directive.value;
  2090. }
  2091. function processMustache(parserOptions, globalLocationCalculator, node, mustache) {
  2092. const range = [
  2093. mustache.startToken.range[1],
  2094. mustache.endToken.range[0],
  2095. ];
  2096. debug("[template] convert mustache {{%s}} %j", mustache.value, range);
  2097. const document = getOwnerDocument(node);
  2098. try {
  2099. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(range[0]);
  2100. const ret = parseExpression(mustache.value, locationCalculator, parserOptions, { allowEmpty: true, allowFilters: true });
  2101. node.expression = ret.expression || null;
  2102. node.references = ret.references;
  2103. if (ret.expression != null) {
  2104. ret.expression.parent = node;
  2105. }
  2106. replaceTokens(document, { range }, ret.tokens);
  2107. insertComments(document, ret.comments);
  2108. }
  2109. catch (err) {
  2110. debug("[template] Parse error: %s", err);
  2111. if (ParseError.isParseError(err)) {
  2112. insertError(document, err);
  2113. }
  2114. else {
  2115. throw err;
  2116. }
  2117. }
  2118. }
  2119. function resolveReferences(container) {
  2120. let element = container.parent;
  2121. while (element != null && element.type !== "VElement") {
  2122. element = element.parent;
  2123. }
  2124. if (element != null) {
  2125. for (const reference of container.references) {
  2126. resolveReference(reference, element);
  2127. }
  2128. }
  2129. }
  2130. const SVG_ATTRIBUTE_NAME_MAP = new Map([
  2131. ["attributename", "attributeName"],
  2132. ["attributetype", "attributeType"],
  2133. ["basefrequency", "baseFrequency"],
  2134. ["baseprofile", "baseProfile"],
  2135. ["calcmode", "calcMode"],
  2136. ["clippathunits", "clipPathUnits"],
  2137. ["diffuseconstant", "diffuseConstant"],
  2138. ["edgemode", "edgeMode"],
  2139. ["filterunits", "filterUnits"],
  2140. ["glyphref", "glyphRef"],
  2141. ["gradienttransform", "gradientTransform"],
  2142. ["gradientunits", "gradientUnits"],
  2143. ["kernelmatrix", "kernelMatrix"],
  2144. ["kernelunitlength", "kernelUnitLength"],
  2145. ["keypoints", "keyPoints"],
  2146. ["keysplines", "keySplines"],
  2147. ["keytimes", "keyTimes"],
  2148. ["lengthadjust", "lengthAdjust"],
  2149. ["limitingconeangle", "limitingConeAngle"],
  2150. ["markerheight", "markerHeight"],
  2151. ["markerunits", "markerUnits"],
  2152. ["markerwidth", "markerWidth"],
  2153. ["maskcontentunits", "maskContentUnits"],
  2154. ["maskunits", "maskUnits"],
  2155. ["numoctaves", "numOctaves"],
  2156. ["pathlength", "pathLength"],
  2157. ["patterncontentunits", "patternContentUnits"],
  2158. ["patterntransform", "patternTransform"],
  2159. ["patternunits", "patternUnits"],
  2160. ["pointsatx", "pointsAtX"],
  2161. ["pointsaty", "pointsAtY"],
  2162. ["pointsatz", "pointsAtZ"],
  2163. ["preservealpha", "preserveAlpha"],
  2164. ["preserveaspectratio", "preserveAspectRatio"],
  2165. ["primitiveunits", "primitiveUnits"],
  2166. ["refx", "refX"],
  2167. ["refy", "refY"],
  2168. ["repeatcount", "repeatCount"],
  2169. ["repeatdur", "repeatDur"],
  2170. ["requiredextensions", "requiredExtensions"],
  2171. ["requiredfeatures", "requiredFeatures"],
  2172. ["specularconstant", "specularConstant"],
  2173. ["specularexponent", "specularExponent"],
  2174. ["spreadmethod", "spreadMethod"],
  2175. ["startoffset", "startOffset"],
  2176. ["stddeviation", "stdDeviation"],
  2177. ["stitchtiles", "stitchTiles"],
  2178. ["surfacescale", "surfaceScale"],
  2179. ["systemlanguage", "systemLanguage"],
  2180. ["tablevalues", "tableValues"],
  2181. ["targetx", "targetX"],
  2182. ["targety", "targetY"],
  2183. ["textlength", "textLength"],
  2184. ["viewbox", "viewBox"],
  2185. ["viewtarget", "viewTarget"],
  2186. ["xchannelselector", "xChannelSelector"],
  2187. ["ychannelselector", "yChannelSelector"],
  2188. ["zoomandpan", "zoomAndPan"],
  2189. ]);
  2190. const MATHML_ATTRIBUTE_NAME_MAP = new Map([
  2191. ["definitionurl", "definitionUrl"]
  2192. ]);
  2193. const HTML_VOID_ELEMENT_TAGS = new Set([
  2194. "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta",
  2195. "param", "source", "track", "wbr",
  2196. ]);
  2197. const HTML_CAN_BE_LEFT_OPEN_TAGS = new Set([
  2198. "colgroup", "li", "options", "p", "td", "tfoot", "th", "thead",
  2199. "tr", "source",
  2200. ]);
  2201. const HTML_NON_FHRASING_TAGS = new Set([
  2202. "address", "article", "aside", "base", "blockquote", "body", "caption",
  2203. "col", "colgroup", "dd", "details", "dialog", "div", "dl", "dt", "fieldset",
  2204. "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5",
  2205. "h6", "head", "header", "hgroup", "hr", "html", "legend", "li", "menuitem",
  2206. "meta", "optgroup", "option", "param", "rp", "rt", "source", "style",
  2207. "summary", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track",
  2208. ]);
  2209. const HTML_RCDATA_TAGS = new Set([
  2210. "title", "textarea",
  2211. ]);
  2212. const HTML_RAWTEXT_TAGS = new Set([
  2213. "style", "xmp", "iframe", "noembed", "noframes", "noscript", "script",
  2214. ]);
  2215. const SVG_TAGS$1 = new Set([
  2216. "a", "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor",
  2217. "animateMotion", "animateTransform", "animation", "audio", "canvas",
  2218. "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "discard",
  2219. "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite",
  2220. "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap",
  2221. "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB",
  2222. "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode",
  2223. "feMorphology", "feOffset", "fePointLight", "feSpecularLighting",
  2224. "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face",
  2225. "font-face-format", "font-face-name", "font-face-src", "font-face-uri",
  2226. "foreignObject", "g", "glyph", "glyphRef", "handler", "hatch", "hatchpath",
  2227. "hkern", "iframe", "image", "line", "linearGradient", "listener", "marker",
  2228. "mask", "mesh", "meshgradient", "meshpatch", "meshrow", "metadata",
  2229. "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline",
  2230. "prefetch", "radialGradient", "rect", "script", "set", "solidColor",
  2231. "solidcolor", "stop", "style", "svg", "switch", "symbol", "tbreak", "text",
  2232. "textArea", "textPath", "title", "tref", "tspan", "unknown", "use", "video",
  2233. "view", "vkern",
  2234. ]);
  2235. const SVG_ELEMENT_NAME_MAP = new Map();
  2236. for (const name of SVG_TAGS$1) {
  2237. if (/[A-Z]/.test(name)) {
  2238. SVG_ELEMENT_NAME_MAP.set(name.toLowerCase(), name);
  2239. }
  2240. }
  2241. const DUMMY_PARENT$1 = Object.freeze({});
  2242. function concat(text, token) {
  2243. return text + token.value;
  2244. }
  2245. class IntermediateTokenizer {
  2246. constructor(tokenizer) {
  2247. this.tokenizer = tokenizer;
  2248. this.currentToken = null;
  2249. this.attribute = null;
  2250. this.attributeNames = new Set();
  2251. this.expressionStartToken = null;
  2252. this.expressionTokens = [];
  2253. this.tokens = [];
  2254. this.comments = [];
  2255. }
  2256. get text() {
  2257. return this.tokenizer.text;
  2258. }
  2259. get errors() {
  2260. return this.tokenizer.errors;
  2261. }
  2262. get state() {
  2263. return this.tokenizer.state;
  2264. }
  2265. set state(value) {
  2266. this.tokenizer.state = value;
  2267. }
  2268. get namespace() {
  2269. return this.tokenizer.namespace;
  2270. }
  2271. set namespace(value) {
  2272. this.tokenizer.namespace = value;
  2273. }
  2274. get expressionEnabled() {
  2275. return this.tokenizer.expressionEnabled;
  2276. }
  2277. set expressionEnabled(value) {
  2278. this.tokenizer.expressionEnabled = value;
  2279. }
  2280. nextToken() {
  2281. let token = null;
  2282. let result = null;
  2283. while (result == null && (token = this.tokenizer.nextToken()) != null) {
  2284. result = this[token.type](token);
  2285. }
  2286. if (result == null && token == null && this.currentToken != null) {
  2287. result = this.commit();
  2288. }
  2289. return result;
  2290. }
  2291. commit() {
  2292. assert__default["default"](this.currentToken != null || this.expressionStartToken != null);
  2293. let token = this.currentToken;
  2294. this.currentToken = null;
  2295. this.attribute = null;
  2296. if (this.expressionStartToken != null) {
  2297. const start = this.expressionStartToken;
  2298. const end = last__default["default"](this.expressionTokens) || start;
  2299. const value = this.expressionTokens.reduce(concat, start.value);
  2300. this.expressionStartToken = null;
  2301. this.expressionTokens = [];
  2302. if (token == null) {
  2303. token = {
  2304. type: "Text",
  2305. range: [start.range[0], end.range[1]],
  2306. loc: { start: start.loc.start, end: end.loc.end },
  2307. value,
  2308. };
  2309. }
  2310. else if (token.type === "Text") {
  2311. token.range[1] = end.range[1];
  2312. token.loc.end = end.loc.end;
  2313. token.value += value;
  2314. }
  2315. else {
  2316. throw new Error("unreachable");
  2317. }
  2318. }
  2319. return token;
  2320. }
  2321. reportParseError(token, code) {
  2322. const error = ParseError.fromCode(code, token.range[0], token.loc.start.line, token.loc.start.column);
  2323. this.errors.push(error);
  2324. debug("[html] syntax error:", error.message);
  2325. }
  2326. processComment(token) {
  2327. this.comments.push(token);
  2328. if (this.currentToken != null && this.currentToken.type === "Text") {
  2329. return this.commit();
  2330. }
  2331. return null;
  2332. }
  2333. processText(token) {
  2334. this.tokens.push(token);
  2335. let result = null;
  2336. if (this.expressionStartToken != null) {
  2337. const lastToken = last__default["default"](this.expressionTokens) || this.expressionStartToken;
  2338. if (lastToken.range[1] === token.range[0]) {
  2339. this.expressionTokens.push(token);
  2340. return null;
  2341. }
  2342. result = this.commit();
  2343. }
  2344. else if (this.currentToken != null) {
  2345. if (this.currentToken.type === "Text" &&
  2346. this.currentToken.range[1] === token.range[0]) {
  2347. this.currentToken.value += token.value;
  2348. this.currentToken.range[1] = token.range[1];
  2349. this.currentToken.loc.end = token.loc.end;
  2350. return null;
  2351. }
  2352. result = this.commit();
  2353. }
  2354. assert__default["default"](this.currentToken == null);
  2355. this.currentToken = {
  2356. type: "Text",
  2357. range: [token.range[0], token.range[1]],
  2358. loc: { start: token.loc.start, end: token.loc.end },
  2359. value: token.value,
  2360. };
  2361. return result;
  2362. }
  2363. HTMLAssociation(token) {
  2364. this.tokens.push(token);
  2365. if (this.attribute != null) {
  2366. this.attribute.range[1] = token.range[1];
  2367. this.attribute.loc.end = token.loc.end;
  2368. if (this.currentToken == null ||
  2369. this.currentToken.type !== "StartTag") {
  2370. throw new Error("unreachable");
  2371. }
  2372. this.currentToken.range[1] = token.range[1];
  2373. this.currentToken.loc.end = token.loc.end;
  2374. }
  2375. return null;
  2376. }
  2377. HTMLBogusComment(token) {
  2378. return this.processComment(token);
  2379. }
  2380. HTMLCDataText(token) {
  2381. return this.processText(token);
  2382. }
  2383. HTMLComment(token) {
  2384. return this.processComment(token);
  2385. }
  2386. HTMLEndTagOpen(token) {
  2387. this.tokens.push(token);
  2388. let result = null;
  2389. if (this.currentToken != null || this.expressionStartToken != null) {
  2390. result = this.commit();
  2391. }
  2392. this.currentToken = {
  2393. type: "EndTag",
  2394. range: [token.range[0], token.range[1]],
  2395. loc: { start: token.loc.start, end: token.loc.end },
  2396. name: token.value,
  2397. };
  2398. return result;
  2399. }
  2400. HTMLIdentifier(token) {
  2401. this.tokens.push(token);
  2402. if (this.currentToken == null ||
  2403. this.currentToken.type === "Text" ||
  2404. this.currentToken.type === "Mustache") {
  2405. throw new Error("unreachable");
  2406. }
  2407. if (this.currentToken.type === "EndTag") {
  2408. this.reportParseError(token, "end-tag-with-attributes");
  2409. return null;
  2410. }
  2411. if (this.attributeNames.has(token.value)) {
  2412. this.reportParseError(token, "duplicate-attribute");
  2413. }
  2414. this.attributeNames.add(token.value);
  2415. this.attribute = {
  2416. type: "VAttribute",
  2417. range: [token.range[0], token.range[1]],
  2418. loc: { start: token.loc.start, end: token.loc.end },
  2419. parent: DUMMY_PARENT$1,
  2420. directive: false,
  2421. key: {
  2422. type: "VIdentifier",
  2423. range: [token.range[0], token.range[1]],
  2424. loc: { start: token.loc.start, end: token.loc.end },
  2425. parent: DUMMY_PARENT$1,
  2426. name: token.value,
  2427. rawName: this.text.slice(token.range[0], token.range[1]),
  2428. },
  2429. value: null,
  2430. };
  2431. this.attribute.key.parent = this.attribute;
  2432. this.currentToken.range[1] = token.range[1];
  2433. this.currentToken.loc.end = token.loc.end;
  2434. this.currentToken.attributes.push(this.attribute);
  2435. return null;
  2436. }
  2437. HTMLLiteral(token) {
  2438. this.tokens.push(token);
  2439. if (this.attribute != null) {
  2440. this.attribute.range[1] = token.range[1];
  2441. this.attribute.loc.end = token.loc.end;
  2442. this.attribute.value = {
  2443. type: "VLiteral",
  2444. range: [token.range[0], token.range[1]],
  2445. loc: { start: token.loc.start, end: token.loc.end },
  2446. parent: this.attribute,
  2447. value: token.value,
  2448. };
  2449. if (this.currentToken == null ||
  2450. this.currentToken.type !== "StartTag") {
  2451. throw new Error("unreachable");
  2452. }
  2453. this.currentToken.range[1] = token.range[1];
  2454. this.currentToken.loc.end = token.loc.end;
  2455. }
  2456. return null;
  2457. }
  2458. HTMLRCDataText(token) {
  2459. return this.processText(token);
  2460. }
  2461. HTMLRawText(token) {
  2462. return this.processText(token);
  2463. }
  2464. HTMLSelfClosingTagClose(token) {
  2465. this.tokens.push(token);
  2466. if (this.currentToken == null || this.currentToken.type === "Text") {
  2467. throw new Error("unreachable");
  2468. }
  2469. if (this.currentToken.type === "StartTag") {
  2470. this.currentToken.selfClosing = true;
  2471. }
  2472. else {
  2473. this.reportParseError(token, "end-tag-with-trailing-solidus");
  2474. }
  2475. this.currentToken.range[1] = token.range[1];
  2476. this.currentToken.loc.end = token.loc.end;
  2477. return this.commit();
  2478. }
  2479. HTMLTagClose(token) {
  2480. this.tokens.push(token);
  2481. if (this.currentToken == null || this.currentToken.type === "Text") {
  2482. throw new Error("unreachable");
  2483. }
  2484. this.currentToken.range[1] = token.range[1];
  2485. this.currentToken.loc.end = token.loc.end;
  2486. return this.commit();
  2487. }
  2488. HTMLTagOpen(token) {
  2489. this.tokens.push(token);
  2490. let result = null;
  2491. if (this.currentToken != null || this.expressionStartToken != null) {
  2492. result = this.commit();
  2493. }
  2494. this.currentToken = {
  2495. type: "StartTag",
  2496. range: [token.range[0], token.range[1]],
  2497. loc: { start: token.loc.start, end: token.loc.end },
  2498. name: token.value,
  2499. rawName: this.text.slice(token.range[0] + 1, token.range[1]),
  2500. selfClosing: false,
  2501. attributes: [],
  2502. };
  2503. this.attribute = null;
  2504. this.attributeNames.clear();
  2505. return result;
  2506. }
  2507. HTMLText(token) {
  2508. return this.processText(token);
  2509. }
  2510. HTMLWhitespace(token) {
  2511. return this.processText(token);
  2512. }
  2513. VExpressionStart(token) {
  2514. if (this.expressionStartToken != null) {
  2515. return this.processText(token);
  2516. }
  2517. const separated = this.currentToken != null &&
  2518. this.currentToken.range[1] !== token.range[0];
  2519. const result = separated ? this.commit() : null;
  2520. this.tokens.push(token);
  2521. this.expressionStartToken = token;
  2522. return result;
  2523. }
  2524. VExpressionEnd(token) {
  2525. if (this.expressionStartToken == null) {
  2526. return this.processText(token);
  2527. }
  2528. const start = this.expressionStartToken;
  2529. const end = last__default["default"](this.expressionTokens) || start;
  2530. if (token.range[0] === start.range[1]) {
  2531. this.tokens.pop();
  2532. this.expressionStartToken = null;
  2533. const result = this.processText(start);
  2534. this.processText(token);
  2535. return result;
  2536. }
  2537. if (end.range[1] !== token.range[0]) {
  2538. const result = this.commit();
  2539. this.processText(token);
  2540. return result;
  2541. }
  2542. const value = this.expressionTokens.reduce(concat, "");
  2543. this.tokens.push(token);
  2544. this.expressionStartToken = null;
  2545. this.expressionTokens = [];
  2546. const result = this.currentToken != null ? this.commit() : null;
  2547. this.currentToken = {
  2548. type: "Mustache",
  2549. range: [start.range[0], token.range[1]],
  2550. loc: { start: start.loc.start, end: token.loc.end },
  2551. value,
  2552. startToken: start,
  2553. endToken: token,
  2554. };
  2555. return result || this.commit();
  2556. }
  2557. }
  2558. const DIRECTIVE_NAME = /^(?:v-|[.:@#]).*[^.:@#]$/u;
  2559. const DT_DD = /^d[dt]$/u;
  2560. const DUMMY_PARENT = Object.freeze({});
  2561. function getTagName(startTagOrElement, isSFC) {
  2562. return isSFC ? startTagOrElement.rawName : startTagOrElement.name;
  2563. }
  2564. function isMathMLIntegrationPoint(element, isSFC) {
  2565. if (element.namespace === NS.MathML) {
  2566. const name = getTagName(element, isSFC);
  2567. return (name === "mi" ||
  2568. name === "mo" ||
  2569. name === "mn" ||
  2570. name === "ms" ||
  2571. name === "mtext");
  2572. }
  2573. return false;
  2574. }
  2575. function isHTMLIntegrationPoint(element, isSFC) {
  2576. if (element.namespace === NS.MathML) {
  2577. return (getTagName(element, isSFC) === "annotation-xml" &&
  2578. element.startTag.attributes.some((a) => a.directive === false &&
  2579. a.key.name === "encoding" &&
  2580. a.value != null &&
  2581. (a.value.value === "text/html" ||
  2582. a.value.value === "application/xhtml+xml")));
  2583. }
  2584. if (element.namespace === NS.SVG) {
  2585. const name = getTagName(element, isSFC);
  2586. return name === "foreignObject" || name === "desc" || name === "title";
  2587. }
  2588. return false;
  2589. }
  2590. function adjustElementName(name, namespace) {
  2591. if (namespace === NS.SVG) {
  2592. return SVG_ELEMENT_NAME_MAP.get(name) || name;
  2593. }
  2594. return name;
  2595. }
  2596. function adjustAttributeName(name, namespace) {
  2597. if (namespace === NS.SVG) {
  2598. return SVG_ATTRIBUTE_NAME_MAP.get(name) || name;
  2599. }
  2600. if (namespace === NS.MathML) {
  2601. return MATHML_ATTRIBUTE_NAME_MAP.get(name) || name;
  2602. }
  2603. return name;
  2604. }
  2605. function propagateEndLocation(node) {
  2606. const lastChild = (node.type === "VElement" ? node.endTag : null) || last__default["default"](node.children);
  2607. if (lastChild != null) {
  2608. node.range[1] = lastChild.range[1];
  2609. node.loc.end = lastChild.loc.end;
  2610. }
  2611. }
  2612. class Parser {
  2613. constructor(tokenizer, parserOptions) {
  2614. this.postProcessesForScript = [];
  2615. this.tokenizer = new IntermediateTokenizer(tokenizer);
  2616. this.locationCalculator = new LocationCalculatorForHtml(tokenizer.gaps, tokenizer.lineTerminators);
  2617. this.baseParserOptions = parserOptions;
  2618. this.isSFC = isSFCFile(parserOptions);
  2619. this.document = {
  2620. type: "VDocumentFragment",
  2621. range: [0, 0],
  2622. loc: {
  2623. start: { line: 1, column: 0 },
  2624. end: { line: 1, column: 0 },
  2625. },
  2626. parent: null,
  2627. children: [],
  2628. tokens: this.tokens,
  2629. comments: this.comments,
  2630. errors: this.errors,
  2631. };
  2632. this.elementStack = [];
  2633. this.vPreElement = null;
  2634. this.postProcessesForScript = [];
  2635. }
  2636. get text() {
  2637. return this.tokenizer.text;
  2638. }
  2639. get tokens() {
  2640. return this.tokenizer.tokens;
  2641. }
  2642. get comments() {
  2643. return this.tokenizer.comments;
  2644. }
  2645. get errors() {
  2646. return this.tokenizer.errors;
  2647. }
  2648. get namespace() {
  2649. return this.tokenizer.namespace;
  2650. }
  2651. set namespace(value) {
  2652. this.tokenizer.namespace = value;
  2653. }
  2654. get expressionEnabled() {
  2655. return this.tokenizer.expressionEnabled;
  2656. }
  2657. set expressionEnabled(value) {
  2658. this.tokenizer.expressionEnabled = value;
  2659. }
  2660. get currentNode() {
  2661. return last__default["default"](this.elementStack) || this.document;
  2662. }
  2663. get isInVPreElement() {
  2664. return this.vPreElement != null;
  2665. }
  2666. parse() {
  2667. let token = null;
  2668. while ((token = this.tokenizer.nextToken()) != null) {
  2669. this[token.type](token);
  2670. }
  2671. this.popElementStackUntil(0);
  2672. propagateEndLocation(this.document);
  2673. const doc = this.document;
  2674. const htmlParserOptions = Object.assign(Object.assign({}, this.baseParserOptions), { parser: getScriptParser(this.baseParserOptions.parser, function* () {
  2675. yield "<template>";
  2676. yield getParserLangFromSFC(doc);
  2677. }) });
  2678. const scriptParserOptions = Object.assign(Object.assign({}, this.baseParserOptions), { parser: getScriptParser(this.baseParserOptions.parser, () => getParserLangFromSFC(doc)) });
  2679. for (const proc of this.postProcessesForScript) {
  2680. proc(htmlParserOptions, scriptParserOptions);
  2681. }
  2682. this.postProcessesForScript = [];
  2683. return doc;
  2684. }
  2685. reportParseError(token, code) {
  2686. const error = ParseError.fromCode(code, token.range[0], token.loc.start.line, token.loc.start.column);
  2687. this.errors.push(error);
  2688. debug("[html] syntax error:", error.message);
  2689. }
  2690. popElementStack() {
  2691. assert__default["default"](this.elementStack.length >= 1);
  2692. const element = this.elementStack.pop();
  2693. propagateEndLocation(element);
  2694. const current = this.currentNode;
  2695. this.namespace =
  2696. current.type === "VElement" ? current.namespace : NS.HTML;
  2697. if (this.vPreElement === element) {
  2698. this.vPreElement = null;
  2699. this.expressionEnabled = true;
  2700. }
  2701. if (this.elementStack.length === 0) {
  2702. this.expressionEnabled = false;
  2703. }
  2704. }
  2705. popElementStackUntil(index) {
  2706. while (this.elementStack.length > index) {
  2707. this.popElementStack();
  2708. }
  2709. }
  2710. getTagName(startTagOrElement) {
  2711. return getTagName(startTagOrElement, this.isSFC);
  2712. }
  2713. detectNamespace(token) {
  2714. const name = this.getTagName(token);
  2715. let ns = this.namespace;
  2716. if (ns === NS.MathML || ns === NS.SVG) {
  2717. const element = this.currentNode;
  2718. if (element.type === "VElement") {
  2719. if (element.namespace === NS.MathML &&
  2720. this.getTagName(element) === "annotation-xml" &&
  2721. name === "svg") {
  2722. return NS.SVG;
  2723. }
  2724. if (isHTMLIntegrationPoint(element, this.isSFC) ||
  2725. (isMathMLIntegrationPoint(element, this.isSFC) &&
  2726. name !== "mglyph" &&
  2727. name !== "malignmark")) {
  2728. ns = NS.HTML;
  2729. }
  2730. }
  2731. }
  2732. if (ns === NS.HTML) {
  2733. if (name === "svg") {
  2734. return NS.SVG;
  2735. }
  2736. if (name === "math") {
  2737. return NS.MathML;
  2738. }
  2739. }
  2740. if (name === "template") {
  2741. const xmlns = token.attributes.find((a) => a.key.name === "xmlns");
  2742. const value = xmlns && xmlns.value && xmlns.value.value;
  2743. if (value === NS.HTML || value === NS.MathML || value === NS.SVG) {
  2744. return value;
  2745. }
  2746. }
  2747. return ns;
  2748. }
  2749. closeCurrentElementIfNecessary(token) {
  2750. const element = this.currentNode;
  2751. if (element.type !== "VElement") {
  2752. return;
  2753. }
  2754. const name = this.getTagName(token);
  2755. const elementName = this.getTagName(element);
  2756. if (elementName === "p" && HTML_NON_FHRASING_TAGS.has(name)) {
  2757. this.popElementStack();
  2758. }
  2759. if (elementName === name && HTML_CAN_BE_LEFT_OPEN_TAGS.has(name)) {
  2760. this.popElementStack();
  2761. }
  2762. if (DT_DD.test(elementName) && DT_DD.test(name)) {
  2763. this.popElementStack();
  2764. }
  2765. }
  2766. processAttribute(node, namespace) {
  2767. if (this.needConvertToDirective(node)) {
  2768. this.postProcessesForScript.push((parserOptions, scriptParserOptions) => {
  2769. convertToDirective(this.text, parserOptions, scriptParserOptions, this.locationCalculator, node);
  2770. });
  2771. return;
  2772. }
  2773. node.key.name = adjustAttributeName(node.key.name, namespace);
  2774. const key = this.getTagName(node.key);
  2775. const value = node.value && node.value.value;
  2776. if (key === "xmlns" && value !== namespace) {
  2777. this.reportParseError(node, "x-invalid-namespace");
  2778. }
  2779. else if (key === "xmlns:xlink" && value !== NS.XLink) {
  2780. this.reportParseError(node, "x-invalid-namespace");
  2781. }
  2782. }
  2783. needConvertToDirective(node) {
  2784. const element = node.parent.parent;
  2785. const tagName = this.getTagName(element);
  2786. const attrName = this.getTagName(node.key);
  2787. if (attrName === "generic" &&
  2788. element.parent.type === "VDocumentFragment" &&
  2789. isScriptSetupElement(element) &&
  2790. isTSLang(element)) {
  2791. return true;
  2792. }
  2793. const expressionEnabled = this.expressionEnabled ||
  2794. (attrName === "v-pre" && !this.isInVPreElement);
  2795. if (!expressionEnabled) {
  2796. return false;
  2797. }
  2798. return (DIRECTIVE_NAME.test(attrName) ||
  2799. attrName === "slot-scope" ||
  2800. (tagName === "template" && attrName === "scope"));
  2801. }
  2802. processTemplateText(token, templateTokenizerOption) {
  2803. const TemplateTokenizer = typeof templateTokenizerOption === "function"
  2804. ? templateTokenizerOption
  2805. :
  2806. require(templateTokenizerOption);
  2807. const templateTokenizer = new TemplateTokenizer(token.value, this.text, {
  2808. startingLine: token.loc.start.line,
  2809. startingColumn: token.loc.start.column,
  2810. });
  2811. const rootTokenizer = this.tokenizer;
  2812. this.tokenizer = templateTokenizer;
  2813. let templateToken = null;
  2814. while ((templateToken = templateTokenizer.nextToken()) != null) {
  2815. this[templateToken.type](templateToken);
  2816. }
  2817. this.tokenizer = rootTokenizer;
  2818. const index = sortedIndexBy__default["default"](this.tokenizer.tokens, token, (x) => x.range[0]);
  2819. const count = sortedLastIndexBy__default["default"](this.tokenizer.tokens, token, (x) => x.range[1]) -
  2820. index;
  2821. this.tokenizer.tokens.splice(index, count, ...templateTokenizer.tokens);
  2822. this.tokenizer.comments.push(...templateTokenizer.comments);
  2823. this.tokenizer.errors.push(...templateTokenizer.errors);
  2824. }
  2825. StartTag(token) {
  2826. var _a;
  2827. debug("[html] StartTag %j", token);
  2828. this.closeCurrentElementIfNecessary(token);
  2829. const parent = this.currentNode;
  2830. const namespace = this.detectNamespace(token);
  2831. const element = {
  2832. type: "VElement",
  2833. range: [token.range[0], token.range[1]],
  2834. loc: { start: token.loc.start, end: token.loc.end },
  2835. parent,
  2836. name: adjustElementName(token.name, namespace),
  2837. rawName: token.rawName,
  2838. namespace,
  2839. startTag: {
  2840. type: "VStartTag",
  2841. range: token.range,
  2842. loc: token.loc,
  2843. parent: DUMMY_PARENT,
  2844. selfClosing: token.selfClosing,
  2845. attributes: token.attributes,
  2846. },
  2847. children: [],
  2848. endTag: null,
  2849. variables: [],
  2850. };
  2851. const hasVPre = !this.isInVPreElement &&
  2852. token.attributes.some((a) => this.getTagName(a.key) === "v-pre");
  2853. if (hasVPre) {
  2854. this.expressionEnabled = false;
  2855. }
  2856. parent.children.push(element);
  2857. element.startTag.parent = element;
  2858. for (const attribute of token.attributes) {
  2859. attribute.parent = element.startTag;
  2860. this.processAttribute(attribute, namespace);
  2861. }
  2862. this.postProcessesForScript.push(() => {
  2863. for (const attribute of element.startTag.attributes) {
  2864. if (attribute.directive) {
  2865. if (attribute.key.argument != null &&
  2866. attribute.key.argument.type === "VExpressionContainer") {
  2867. resolveReferences(attribute.key.argument);
  2868. }
  2869. if (attribute.value != null) {
  2870. resolveReferences(attribute.value);
  2871. }
  2872. }
  2873. }
  2874. });
  2875. const isVoid = namespace === NS.HTML &&
  2876. HTML_VOID_ELEMENT_TAGS.has(this.getTagName(element));
  2877. if (token.selfClosing && !isVoid && namespace === NS.HTML) {
  2878. this.reportParseError(token, "non-void-html-element-start-tag-with-trailing-solidus");
  2879. }
  2880. if (token.selfClosing || isVoid) {
  2881. this.expressionEnabled = !this.isInVPreElement;
  2882. return;
  2883. }
  2884. this.elementStack.push(element);
  2885. if (hasVPre) {
  2886. assert__default["default"](this.vPreElement === null);
  2887. this.vPreElement = element;
  2888. }
  2889. this.namespace = namespace;
  2890. if (namespace === NS.HTML) {
  2891. const elementName = this.getTagName(element);
  2892. if (element.parent.type === "VDocumentFragment") {
  2893. const langAttr = element.startTag.attributes.find((a) => !a.directive && a.key.name === "lang");
  2894. const lang = (_a = langAttr === null || langAttr === void 0 ? void 0 : langAttr.value) === null || _a === void 0 ? void 0 : _a.value;
  2895. if (elementName === "template") {
  2896. this.expressionEnabled = true;
  2897. if (lang && lang !== "html") {
  2898. this.tokenizer.state = "RAWTEXT";
  2899. this.expressionEnabled = false;
  2900. }
  2901. }
  2902. else if (this.isSFC) {
  2903. if (!lang || lang !== "html") {
  2904. this.tokenizer.state = "RAWTEXT";
  2905. }
  2906. }
  2907. else {
  2908. if (HTML_RCDATA_TAGS.has(elementName)) {
  2909. this.tokenizer.state = "RCDATA";
  2910. }
  2911. if (HTML_RAWTEXT_TAGS.has(elementName)) {
  2912. this.tokenizer.state = "RAWTEXT";
  2913. }
  2914. }
  2915. }
  2916. else {
  2917. if (HTML_RCDATA_TAGS.has(elementName)) {
  2918. this.tokenizer.state = "RCDATA";
  2919. }
  2920. if (HTML_RAWTEXT_TAGS.has(elementName)) {
  2921. this.tokenizer.state = "RAWTEXT";
  2922. }
  2923. }
  2924. }
  2925. }
  2926. EndTag(token) {
  2927. debug("[html] EndTag %j", token);
  2928. const i = findLastIndex__default["default"](this.elementStack, (el) => el.name.toLowerCase() === token.name);
  2929. if (i === -1) {
  2930. this.reportParseError(token, "x-invalid-end-tag");
  2931. return;
  2932. }
  2933. const element = this.elementStack[i];
  2934. element.endTag = {
  2935. type: "VEndTag",
  2936. range: token.range,
  2937. loc: token.loc,
  2938. parent: element,
  2939. };
  2940. this.popElementStackUntil(i);
  2941. }
  2942. Text(token) {
  2943. var _a, _b;
  2944. debug("[html] Text %j", token);
  2945. const parent = this.currentNode;
  2946. if (token.value &&
  2947. parent.type === "VElement" &&
  2948. parent.name === "template" &&
  2949. parent.parent.type === "VDocumentFragment") {
  2950. const langAttribute = parent.startTag.attributes.find((a) => a.key.name === "lang");
  2951. const lang = (_a = langAttribute === null || langAttribute === void 0 ? void 0 : langAttribute.value) === null || _a === void 0 ? void 0 : _a.value;
  2952. if (lang && lang !== "html") {
  2953. const templateTokenizerOption = (_b = this.baseParserOptions.templateTokenizer) === null || _b === void 0 ? void 0 : _b[lang];
  2954. if (templateTokenizerOption) {
  2955. this.processTemplateText(token, templateTokenizerOption);
  2956. return;
  2957. }
  2958. }
  2959. }
  2960. parent.children.push({
  2961. type: "VText",
  2962. range: token.range,
  2963. loc: token.loc,
  2964. parent,
  2965. value: token.value,
  2966. });
  2967. }
  2968. Mustache(token) {
  2969. debug("[html] Mustache %j", token);
  2970. const parent = this.currentNode;
  2971. const container = {
  2972. type: "VExpressionContainer",
  2973. range: token.range,
  2974. loc: token.loc,
  2975. parent,
  2976. expression: null,
  2977. references: [],
  2978. };
  2979. parent.children.push(container);
  2980. this.postProcessesForScript.push((parserOptions) => {
  2981. processMustache(parserOptions, this.locationCalculator, container, token);
  2982. resolveReferences(container);
  2983. });
  2984. }
  2985. }
  2986. const alternativeCR = new Map([[128, 8364], [130, 8218], [131, 402], [132, 8222], [133, 8230], [134, 8224], [135, 8225], [136, 710], [137, 8240], [138, 352], [139, 8249], [140, 338], [142, 381], [145, 8216], [146, 8217], [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732], [153, 8482], [154, 353], [155, 8250], [156, 339], [158, 382], [159, 376]]);
  2987. const entitySets = [{ "length": 32, "entities": { "CounterClockwiseContourIntegral;": [8755] } }, { "length": 25, "entities": { "ClockwiseContourIntegral;": [8754], "DoubleLongLeftRightArrow;": [10234] } }, { "length": 24, "entities": { "NotNestedGreaterGreater;": [10914, 824] } }, { "length": 23, "entities": { "DiacriticalDoubleAcute;": [733], "NotSquareSupersetEqual;": [8931] } }, { "length": 22, "entities": { "CloseCurlyDoubleQuote;": [8221], "DoubleContourIntegral;": [8751], "FilledVerySmallSquare;": [9642], "NegativeVeryThinSpace;": [8203], "NotPrecedesSlantEqual;": [8928], "NotRightTriangleEqual;": [8941], "NotSucceedsSlantEqual;": [8929] } }, { "length": 21, "entities": { "CapitalDifferentialD;": [8517], "DoubleLeftRightArrow;": [8660], "DoubleLongRightArrow;": [10233], "EmptyVerySmallSquare;": [9643], "NestedGreaterGreater;": [8811], "NotDoubleVerticalBar;": [8742], "NotGreaterSlantEqual;": [10878, 824], "NotLeftTriangleEqual;": [8940], "NotSquareSubsetEqual;": [8930], "OpenCurlyDoubleQuote;": [8220], "ReverseUpEquilibrium;": [10607] } }, { "length": 20, "entities": { "DoubleLongLeftArrow;": [10232], "DownLeftRightVector;": [10576], "LeftArrowRightArrow;": [8646], "NegativeMediumSpace;": [8203], "NotGreaterFullEqual;": [8807, 824], "NotRightTriangleBar;": [10704, 824], "RightArrowLeftArrow;": [8644], "SquareSupersetEqual;": [8850], "leftrightsquigarrow;": [8621] } }, { "length": 19, "entities": { "DownRightTeeVector;": [10591], "DownRightVectorBar;": [10583], "LongLeftRightArrow;": [10231], "Longleftrightarrow;": [10234], "NegativeThickSpace;": [8203], "NotLeftTriangleBar;": [10703, 824], "PrecedesSlantEqual;": [8828], "ReverseEquilibrium;": [8651], "RightDoubleBracket;": [10215], "RightDownTeeVector;": [10589], "RightDownVectorBar;": [10581], "RightTriangleEqual;": [8885], "SquareIntersection;": [8851], "SucceedsSlantEqual;": [8829], "blacktriangleright;": [9656], "longleftrightarrow;": [10231] } }, { "length": 18, "entities": { "DoubleUpDownArrow;": [8661], "DoubleVerticalBar;": [8741], "DownLeftTeeVector;": [10590], "DownLeftVectorBar;": [10582], "FilledSmallSquare;": [9724], "GreaterSlantEqual;": [10878], "LeftDoubleBracket;": [10214], "LeftDownTeeVector;": [10593], "LeftDownVectorBar;": [10585], "LeftTriangleEqual;": [8884], "NegativeThinSpace;": [8203], "NotGreaterGreater;": [8811, 824], "NotLessSlantEqual;": [10877, 824], "NotNestedLessLess;": [10913, 824], "NotReverseElement;": [8716], "NotSquareSuperset;": [8848, 824], "NotTildeFullEqual;": [8775], "RightAngleBracket;": [10217], "RightUpDownVector;": [10575], "SquareSubsetEqual;": [8849], "VerticalSeparator;": [10072], "blacktriangledown;": [9662], "blacktriangleleft;": [9666], "leftrightharpoons;": [8651], "rightleftharpoons;": [8652], "twoheadrightarrow;": [8608] } }, { "length": 17, "entities": { "DiacriticalAcute;": [180], "DiacriticalGrave;": [96], "DiacriticalTilde;": [732], "DoubleRightArrow;": [8658], "DownArrowUpArrow;": [8693], "EmptySmallSquare;": [9723], "GreaterEqualLess;": [8923], "GreaterFullEqual;": [8807], "LeftAngleBracket;": [10216], "LeftUpDownVector;": [10577], "LessEqualGreater;": [8922], "NonBreakingSpace;": [160], "NotPrecedesEqual;": [10927, 824], "NotRightTriangle;": [8939], "NotSucceedsEqual;": [10928, 824], "NotSucceedsTilde;": [8831, 824], "NotSupersetEqual;": [8841], "RightTriangleBar;": [10704], "RightUpTeeVector;": [10588], "RightUpVectorBar;": [10580], "UnderParenthesis;": [9181], "UpArrowDownArrow;": [8645], "circlearrowright;": [8635], "downharpoonright;": [8642], "ntrianglerighteq;": [8941], "rightharpoondown;": [8641], "rightrightarrows;": [8649], "twoheadleftarrow;": [8606], "vartriangleright;": [8883] } }, { "length": 16, "entities": { "CloseCurlyQuote;": [8217], "ContourIntegral;": [8750], "DoubleDownArrow;": [8659], "DoubleLeftArrow;": [8656], "DownRightVector;": [8641], "LeftRightVector;": [10574], "LeftTriangleBar;": [10703], "LeftUpTeeVector;": [10592], "LeftUpVectorBar;": [10584], "LowerRightArrow;": [8600], "NotGreaterEqual;": [8817], "NotGreaterTilde;": [8821], "NotHumpDownHump;": [8782, 824], "NotLeftTriangle;": [8938], "NotSquareSubset;": [8847, 824], "OverParenthesis;": [9180], "RightDownVector;": [8642], "ShortRightArrow;": [8594], "UpperRightArrow;": [8599], "bigtriangledown;": [9661], "circlearrowleft;": [8634], "curvearrowright;": [8631], "downharpoonleft;": [8643], "leftharpoondown;": [8637], "leftrightarrows;": [8646], "nLeftrightarrow;": [8654], "nleftrightarrow;": [8622], "ntrianglelefteq;": [8940], "rightleftarrows;": [8644], "rightsquigarrow;": [8605], "rightthreetimes;": [8908], "straightepsilon;": [1013], "trianglerighteq;": [8885], "vartriangleleft;": [8882] } }, { "length": 15, "entities": { "DiacriticalDot;": [729], "DoubleRightTee;": [8872], "DownLeftVector;": [8637], "GreaterGreater;": [10914], "HorizontalLine;": [9472], "InvisibleComma;": [8291], "InvisibleTimes;": [8290], "LeftDownVector;": [8643], "LeftRightArrow;": [8596], "Leftrightarrow;": [8660], "LessSlantEqual;": [10877], "LongRightArrow;": [10230], "Longrightarrow;": [10233], "LowerLeftArrow;": [8601], "NestedLessLess;": [8810], "NotGreaterLess;": [8825], "NotLessGreater;": [8824], "NotSubsetEqual;": [8840], "NotVerticalBar;": [8740], "OpenCurlyQuote;": [8216], "ReverseElement;": [8715], "RightTeeVector;": [10587], "RightVectorBar;": [10579], "ShortDownArrow;": [8595], "ShortLeftArrow;": [8592], "SquareSuperset;": [8848], "TildeFullEqual;": [8773], "UpperLeftArrow;": [8598], "ZeroWidthSpace;": [8203], "curvearrowleft;": [8630], "doublebarwedge;": [8966], "downdownarrows;": [8650], "hookrightarrow;": [8618], "leftleftarrows;": [8647], "leftrightarrow;": [8596], "leftthreetimes;": [8907], "longrightarrow;": [10230], "looparrowright;": [8620], "nshortparallel;": [8742], "ntriangleright;": [8939], "rightarrowtail;": [8611], "rightharpoonup;": [8640], "trianglelefteq;": [8884], "upharpoonright;": [8638] } }, { "length": 14, "entities": { "ApplyFunction;": [8289], "DifferentialD;": [8518], "DoubleLeftTee;": [10980], "DoubleUpArrow;": [8657], "LeftTeeVector;": [10586], "LeftVectorBar;": [10578], "LessFullEqual;": [8806], "LongLeftArrow;": [10229], "Longleftarrow;": [10232], "NotEqualTilde;": [8770, 824], "NotTildeEqual;": [8772], "NotTildeTilde;": [8777], "Poincareplane;": [8460], "PrecedesEqual;": [10927], "PrecedesTilde;": [8830], "RightArrowBar;": [8677], "RightTeeArrow;": [8614], "RightTriangle;": [8883], "RightUpVector;": [8638], "SucceedsEqual;": [10928], "SucceedsTilde;": [8831], "SupersetEqual;": [8839], "UpEquilibrium;": [10606], "VerticalTilde;": [8768], "VeryThinSpace;": [8202], "bigtriangleup;": [9651], "blacktriangle;": [9652], "divideontimes;": [8903], "fallingdotseq;": [8786], "hookleftarrow;": [8617], "leftarrowtail;": [8610], "leftharpoonup;": [8636], "longleftarrow;": [10229], "looparrowleft;": [8619], "measuredangle;": [8737], "ntriangleleft;": [8938], "shortparallel;": [8741], "smallsetminus;": [8726], "triangleright;": [9657], "upharpoonleft;": [8639], "varsubsetneqq;": [10955, 65024], "varsupsetneqq;": [10956, 65024] } }, { "length": 13, "entities": { "DownArrowBar;": [10515], "DownTeeArrow;": [8615], "ExponentialE;": [8519], "GreaterEqual;": [8805], "GreaterTilde;": [8819], "HilbertSpace;": [8459], "HumpDownHump;": [8782], "Intersection;": [8898], "LeftArrowBar;": [8676], "LeftTeeArrow;": [8612], "LeftTriangle;": [8882], "LeftUpVector;": [8639], "NotCongruent;": [8802], "NotHumpEqual;": [8783, 824], "NotLessEqual;": [8816], "NotLessTilde;": [8820], "Proportional;": [8733], "RightCeiling;": [8969], "RoundImplies;": [10608], "ShortUpArrow;": [8593], "SquareSubset;": [8847], "UnderBracket;": [9141], "VerticalLine;": [124], "blacklozenge;": [10731], "exponentiale;": [8519], "risingdotseq;": [8787], "triangledown;": [9663], "triangleleft;": [9667], "varsubsetneq;": [8842, 65024], "varsupsetneq;": [8843, 65024] } }, { "length": 12, "entities": { "CircleMinus;": [8854], "CircleTimes;": [8855], "Equilibrium;": [8652], "GreaterLess;": [8823], "LeftCeiling;": [8968], "LessGreater;": [8822], "MediumSpace;": [8287], "NotLessLess;": [8810, 824], "NotPrecedes;": [8832], "NotSucceeds;": [8833], "NotSuperset;": [8835, 8402], "OverBracket;": [9140], "RightVector;": [8640], "Rrightarrow;": [8667], "RuleDelayed;": [10740], "SmallCircle;": [8728], "SquareUnion;": [8852], "SubsetEqual;": [8838], "UpDownArrow;": [8597], "Updownarrow;": [8661], "VerticalBar;": [8739], "backepsilon;": [1014], "blacksquare;": [9642], "circledcirc;": [8858], "circleddash;": [8861], "curlyeqprec;": [8926], "curlyeqsucc;": [8927], "diamondsuit;": [9830], "eqslantless;": [10901], "expectation;": [8496], "nRightarrow;": [8655], "nrightarrow;": [8603], "preccurlyeq;": [8828], "precnapprox;": [10937], "quaternions;": [8461], "straightphi;": [981], "succcurlyeq;": [8829], "succnapprox;": [10938], "thickapprox;": [8776], "updownarrow;": [8597] } }, { "length": 11, "entities": { "Bernoullis;": [8492], "CirclePlus;": [8853], "EqualTilde;": [8770], "Fouriertrf;": [8497], "ImaginaryI;": [8520], "Laplacetrf;": [8466], "LeftVector;": [8636], "Lleftarrow;": [8666], "NotElement;": [8713], "NotGreater;": [8815], "Proportion;": [8759], "RightArrow;": [8594], "RightFloor;": [8971], "Rightarrow;": [8658], "ThickSpace;": [8287, 8202], "TildeEqual;": [8771], "TildeTilde;": [8776], "UnderBrace;": [9183], "UpArrowBar;": [10514], "UpTeeArrow;": [8613], "circledast;": [8859], "complement;": [8705], "curlywedge;": [8911], "eqslantgtr;": [10902], "gtreqqless;": [10892], "lessapprox;": [10885], "lesseqqgtr;": [10891], "lmoustache;": [9136], "longmapsto;": [10236], "mapstodown;": [8615], "mapstoleft;": [8612], "nLeftarrow;": [8653], "nleftarrow;": [8602], "nsubseteqq;": [10949, 824], "nsupseteqq;": [10950, 824], "precapprox;": [10935], "rightarrow;": [8594], "rmoustache;": [9137], "sqsubseteq;": [8849], "sqsupseteq;": [8850], "subsetneqq;": [10955], "succapprox;": [10936], "supsetneqq;": [10956], "upuparrows;": [8648], "varepsilon;": [1013], "varnothing;": [8709] } }, { "length": 10, "entities": { "Backslash;": [8726], "CenterDot;": [183], "CircleDot;": [8857], "Congruent;": [8801], "Coproduct;": [8720], "DoubleDot;": [168], "DownArrow;": [8595], "DownBreve;": [785], "Downarrow;": [8659], "HumpEqual;": [8783], "LeftArrow;": [8592], "LeftFloor;": [8970], "Leftarrow;": [8656], "LessTilde;": [8818], "Mellintrf;": [8499], "MinusPlus;": [8723], "NotCupCap;": [8813], "NotExists;": [8708], "NotSubset;": [8834, 8402], "OverBrace;": [9182], "PlusMinus;": [177], "Therefore;": [8756], "ThinSpace;": [8201], "TripleDot;": [8411], "UnionPlus;": [8846], "backprime;": [8245], "backsimeq;": [8909], "bigotimes;": [10754], "centerdot;": [183], "checkmark;": [10003], "complexes;": [8450], "dotsquare;": [8865], "downarrow;": [8595], "gtrapprox;": [10886], "gtreqless;": [8923], "gvertneqq;": [8809, 65024], "heartsuit;": [9829], "leftarrow;": [8592], "lesseqgtr;": [8922], "lvertneqq;": [8808, 65024], "ngeqslant;": [10878, 824], "nleqslant;": [10877, 824], "nparallel;": [8742], "nshortmid;": [8740], "nsubseteq;": [8840], "nsupseteq;": [8841], "pitchfork;": [8916], "rationals;": [8474], "spadesuit;": [9824], "subseteqq;": [10949], "subsetneq;": [8842], "supseteqq;": [10950], "supsetneq;": [8843], "therefore;": [8756], "triangleq;": [8796], "varpropto;": [8733] } }, { "length": 9, "entities": { "DDotrahd;": [10513], "DotEqual;": [8784], "Integral;": [8747], "LessLess;": [10913], "NotEqual;": [8800], "NotTilde;": [8769], "PartialD;": [8706], "Precedes;": [8826], "RightTee;": [8866], "Succeeds;": [8827], "SuchThat;": [8715], "Superset;": [8835], "Uarrocir;": [10569], "UnderBar;": [95], "andslope;": [10840], "angmsdaa;": [10664], "angmsdab;": [10665], "angmsdac;": [10666], "angmsdad;": [10667], "angmsdae;": [10668], "angmsdaf;": [10669], "angmsdag;": [10670], "angmsdah;": [10671], "angrtvbd;": [10653], "approxeq;": [8778], "awconint;": [8755], "backcong;": [8780], "barwedge;": [8965], "bbrktbrk;": [9142], "bigoplus;": [10753], "bigsqcup;": [10758], "biguplus;": [10756], "bigwedge;": [8896], "boxminus;": [8863], "boxtimes;": [8864], "bsolhsub;": [10184], "capbrcup;": [10825], "circledR;": [174], "circledS;": [9416], "cirfnint;": [10768], "clubsuit;": [9827], "cupbrcap;": [10824], "curlyvee;": [8910], "cwconint;": [8754], "doteqdot;": [8785], "dotminus;": [8760], "drbkarow;": [10512], "dzigrarr;": [10239], "elinters;": [9191], "emptyset;": [8709], "eqvparsl;": [10725], "fpartint;": [10765], "geqslant;": [10878], "gesdotol;": [10884], "gnapprox;": [10890], "hksearow;": [10533], "hkswarow;": [10534], "imagline;": [8464], "imagpart;": [8465], "infintie;": [10717], "integers;": [8484], "intercal;": [8890], "intlarhk;": [10775], "laemptyv;": [10676], "ldrushar;": [10571], "leqslant;": [10877], "lesdotor;": [10883], "llcorner;": [8990], "lnapprox;": [10889], "lrcorner;": [8991], "lurdshar;": [10570], "mapstoup;": [8613], "multimap;": [8888], "naturals;": [8469], "ncongdot;": [10861, 824], "notindot;": [8949, 824], "otimesas;": [10806], "parallel;": [8741], "plusacir;": [10787], "pointint;": [10773], "precneqq;": [10933], "precnsim;": [8936], "profalar;": [9006], "profline;": [8978], "profsurf;": [8979], "raemptyv;": [10675], "realpart;": [8476], "rppolint;": [10770], "rtriltri;": [10702], "scpolint;": [10771], "setminus;": [8726], "shortmid;": [8739], "smeparsl;": [10724], "sqsubset;": [8847], "sqsupset;": [8848], "subseteq;": [8838], "succneqq;": [10934], "succnsim;": [8937], "supseteq;": [8839], "thetasym;": [977], "thicksim;": [8764], "timesbar;": [10801], "triangle;": [9653], "triminus;": [10810], "trpezium;": [9186], "ulcorner;": [8988], "urcorner;": [8989], "varkappa;": [1008], "varsigma;": [962], "vartheta;": [977] } }, { "length": 8, "entities": { "Because;": [8757], "Cayleys;": [8493], "Cconint;": [8752], "Cedilla;": [184], "Diamond;": [8900], "DownTee;": [8868], "Element;": [8712], "Epsilon;": [917], "Implies;": [8658], "LeftTee;": [8867], "NewLine;": [10], "NoBreak;": [8288], "NotLess;": [8814], "Omicron;": [927], "OverBar;": [8254], "Product;": [8719], "UpArrow;": [8593], "Uparrow;": [8657], "Upsilon;": [933], "alefsym;": [8501], "angrtvb;": [8894], "angzarr;": [9084], "asympeq;": [8781], "backsim;": [8765], "because;": [8757], "bemptyv;": [10672], "between;": [8812], "bigcirc;": [9711], "bigodot;": [10752], "bigstar;": [9733], "bnequiv;": [8801, 8421], "boxplus;": [8862], "ccupssm;": [10832], "cemptyv;": [10674], "cirscir;": [10690], "coloneq;": [8788], "congdot;": [10861], "cudarrl;": [10552], "cudarrr;": [10549], "cularrp;": [10557], "curarrm;": [10556], "dbkarow;": [10511], "ddagger;": [8225], "ddotseq;": [10871], "demptyv;": [10673], "diamond;": [8900], "digamma;": [989], "dotplus;": [8724], "dwangle;": [10662], "epsilon;": [949], "eqcolon;": [8789], "equivDD;": [10872], "gesdoto;": [10882], "gtquest;": [10876], "gtrless;": [8823], "harrcir;": [10568], "intprod;": [10812], "isindot;": [8949], "larrbfs;": [10527], "larrsim;": [10611], "lbrksld;": [10639], "lbrkslu;": [10637], "ldrdhar;": [10599], "lesdoto;": [10881], "lessdot;": [8918], "lessgtr;": [8822], "lesssim;": [8818], "lotimes;": [10804], "lozenge;": [9674], "ltquest;": [10875], "luruhar;": [10598], "maltese;": [10016], "minusdu;": [10794], "napprox;": [8777], "natural;": [9838], "nearrow;": [8599], "nexists;": [8708], "notinva;": [8713], "notinvb;": [8951], "notinvc;": [8950], "notniva;": [8716], "notnivb;": [8958], "notnivc;": [8957], "npolint;": [10772], "npreceq;": [10927, 824], "nsqsube;": [8930], "nsqsupe;": [8931], "nsubset;": [8834, 8402], "nsucceq;": [10928, 824], "nsupset;": [8835, 8402], "nvinfin;": [10718], "nvltrie;": [8884, 8402], "nvrtrie;": [8885, 8402], "nwarrow;": [8598], "olcross;": [10683], "omicron;": [959], "orderof;": [8500], "orslope;": [10839], "pertenk;": [8241], "planckh;": [8462], "pluscir;": [10786], "plussim;": [10790], "plustwo;": [10791], "precsim;": [8830], "quatint;": [10774], "questeq;": [8799], "rarrbfs;": [10528], "rarrsim;": [10612], "rbrksld;": [10638], "rbrkslu;": [10640], "rdldhar;": [10601], "realine;": [8475], "rotimes;": [10805], "ruluhar;": [10600], "searrow;": [8600], "simplus;": [10788], "simrarr;": [10610], "subedot;": [10947], "submult;": [10945], "subplus;": [10943], "subrarr;": [10617], "succsim;": [8831], "supdsub;": [10968], "supedot;": [10948], "suphsol;": [10185], "suphsub;": [10967], "suplarr;": [10619], "supmult;": [10946], "supplus;": [10944], "swarrow;": [8601], "topfork;": [10970], "triplus;": [10809], "tritime;": [10811], "uparrow;": [8593], "upsilon;": [965], "uwangle;": [10663], "vzigzag;": [10650], "zigrarr;": [8669] } }, { "length": 7, "entities": { "Aacute;": [193], "Abreve;": [258], "Agrave;": [192], "Assign;": [8788], "Atilde;": [195], "Barwed;": [8966], "Bumpeq;": [8782], "Cacute;": [262], "Ccaron;": [268], "Ccedil;": [199], "Colone;": [10868], "Conint;": [8751], "CupCap;": [8781], "Dagger;": [8225], "Dcaron;": [270], "DotDot;": [8412], "Dstrok;": [272], "Eacute;": [201], "Ecaron;": [282], "Egrave;": [200], "Exists;": [8707], "ForAll;": [8704], "Gammad;": [988], "Gbreve;": [286], "Gcedil;": [290], "HARDcy;": [1066], "Hstrok;": [294], "Iacute;": [205], "Igrave;": [204], "Itilde;": [296], "Jsercy;": [1032], "Kcedil;": [310], "Lacute;": [313], "Lambda;": [923], "Lcaron;": [317], "Lcedil;": [315], "Lmidot;": [319], "Lstrok;": [321], "Nacute;": [323], "Ncaron;": [327], "Ncedil;": [325], "Ntilde;": [209], "Oacute;": [211], "Odblac;": [336], "Ograve;": [210], "Oslash;": [216], "Otilde;": [213], "Otimes;": [10807], "Racute;": [340], "Rarrtl;": [10518], "Rcaron;": [344], "Rcedil;": [342], "SHCHcy;": [1065], "SOFTcy;": [1068], "Sacute;": [346], "Scaron;": [352], "Scedil;": [350], "Square;": [9633], "Subset;": [8912], "Supset;": [8913], "Tcaron;": [356], "Tcedil;": [354], "Tstrok;": [358], "Uacute;": [218], "Ubreve;": [364], "Udblac;": [368], "Ugrave;": [217], "Utilde;": [360], "Vdashl;": [10982], "Verbar;": [8214], "Vvdash;": [8874], "Yacute;": [221], "Zacute;": [377], "Zcaron;": [381], "aacute;": [225], "abreve;": [259], "agrave;": [224], "andand;": [10837], "angmsd;": [8737], "angsph;": [8738], "apacir;": [10863], "approx;": [8776], "atilde;": [227], "barvee;": [8893], "barwed;": [8965], "becaus;": [8757], "bernou;": [8492], "bigcap;": [8898], "bigcup;": [8899], "bigvee;": [8897], "bkarow;": [10509], "bottom;": [8869], "bowtie;": [8904], "boxbox;": [10697], "bprime;": [8245], "brvbar;": [166], "bullet;": [8226], "bumpeq;": [8783], "cacute;": [263], "capand;": [10820], "capcap;": [10827], "capcup;": [10823], "capdot;": [10816], "ccaron;": [269], "ccedil;": [231], "circeq;": [8791], "cirmid;": [10991], "colone;": [8788], "commat;": [64], "compfn;": [8728], "conint;": [8750], "coprod;": [8720], "copysr;": [8471], "cularr;": [8630], "cupcap;": [10822], "cupcup;": [10826], "cupdot;": [8845], "curarr;": [8631], "curren;": [164], "cylcty;": [9005], "dagger;": [8224], "daleth;": [8504], "dcaron;": [271], "dfisht;": [10623], "divide;": [247], "divonx;": [8903], "dlcorn;": [8990], "dlcrop;": [8973], "dollar;": [36], "drcorn;": [8991], "drcrop;": [8972], "dstrok;": [273], "eacute;": [233], "easter;": [10862], "ecaron;": [283], "ecolon;": [8789], "egrave;": [232], "egsdot;": [10904], "elsdot;": [10903], "emptyv;": [8709], "emsp13;": [8196], "emsp14;": [8197], "eparsl;": [10723], "eqcirc;": [8790], "equals;": [61], "equest;": [8799], "female;": [9792], "ffilig;": [64259], "ffllig;": [64260], "forall;": [8704], "frac12;": [189], "frac13;": [8531], "frac14;": [188], "frac15;": [8533], "frac16;": [8537], "frac18;": [8539], "frac23;": [8532], "frac25;": [8534], "frac34;": [190], "frac35;": [8535], "frac38;": [8540], "frac45;": [8536], "frac56;": [8538], "frac58;": [8541], "frac78;": [8542], "gacute;": [501], "gammad;": [989], "gbreve;": [287], "gesdot;": [10880], "gesles;": [10900], "gtlPar;": [10645], "gtrarr;": [10616], "gtrdot;": [8919], "gtrsim;": [8819], "hairsp;": [8202], "hamilt;": [8459], "hardcy;": [1098], "hearts;": [9829], "hellip;": [8230], "hercon;": [8889], "homtht;": [8763], "horbar;": [8213], "hslash;": [8463], "hstrok;": [295], "hybull;": [8259], "hyphen;": [8208], "iacute;": [237], "igrave;": [236], "iiiint;": [10764], "iinfin;": [10716], "incare;": [8453], "inodot;": [305], "intcal;": [8890], "iquest;": [191], "isinsv;": [8947], "itilde;": [297], "jsercy;": [1112], "kappav;": [1008], "kcedil;": [311], "kgreen;": [312], "lAtail;": [10523], "lacute;": [314], "lagran;": [8466], "lambda;": [955], "langle;": [10216], "larrfs;": [10525], "larrhk;": [8617], "larrlp;": [8619], "larrpl;": [10553], "larrtl;": [8610], "latail;": [10521], "lbrace;": [123], "lbrack;": [91], "lcaron;": [318], "lcedil;": [316], "ldquor;": [8222], "lesdot;": [10879], "lesges;": [10899], "lfisht;": [10620], "lfloor;": [8970], "lharul;": [10602], "llhard;": [10603], "lmidot;": [320], "lmoust;": [9136], "loplus;": [10797], "lowast;": [8727], "lowbar;": [95], "lparlt;": [10643], "lrhard;": [10605], "lsaquo;": [8249], "lsquor;": [8218], "lstrok;": [322], "lthree;": [8907], "ltimes;": [8905], "ltlarr;": [10614], "ltrPar;": [10646], "mapsto;": [8614], "marker;": [9646], "mcomma;": [10793], "midast;": [42], "midcir;": [10992], "middot;": [183], "minusb;": [8863], "minusd;": [8760], "mnplus;": [8723], "models;": [8871], "mstpos;": [8766], "nVDash;": [8879], "nVdash;": [8878], "nacute;": [324], "nbumpe;": [8783, 824], "ncaron;": [328], "ncedil;": [326], "nearhk;": [10532], "nequiv;": [8802], "nesear;": [10536], "nexist;": [8708], "nltrie;": [8940], "notinE;": [8953, 824], "nparsl;": [11005, 8421], "nprcue;": [8928], "nrarrc;": [10547, 824], "nrarrw;": [8605, 824], "nrtrie;": [8941], "nsccue;": [8929], "nsimeq;": [8772], "ntilde;": [241], "numero;": [8470], "nvDash;": [8877], "nvHarr;": [10500], "nvdash;": [8876], "nvlArr;": [10498], "nvrArr;": [10499], "nwarhk;": [10531], "nwnear;": [10535], "oacute;": [243], "odblac;": [337], "odsold;": [10684], "ograve;": [242], "ominus;": [8854], "origof;": [8886], "oslash;": [248], "otilde;": [245], "otimes;": [8855], "parsim;": [10995], "percnt;": [37], "period;": [46], "permil;": [8240], "phmmat;": [8499], "planck;": [8463], "plankv;": [8463], "plusdo;": [8724], "plusdu;": [10789], "plusmn;": [177], "preceq;": [10927], "primes;": [8473], "prnsim;": [8936], "propto;": [8733], "prurel;": [8880], "puncsp;": [8200], "qprime;": [8279], "rAtail;": [10524], "racute;": [341], "rangle;": [10217], "rarrap;": [10613], "rarrfs;": [10526], "rarrhk;": [8618], "rarrlp;": [8620], "rarrpl;": [10565], "rarrtl;": [8611], "ratail;": [10522], "rbrace;": [125], "rbrack;": [93], "rcaron;": [345], "rcedil;": [343], "rdquor;": [8221], "rfisht;": [10621], "rfloor;": [8971], "rharul;": [10604], "rmoust;": [9137], "roplus;": [10798], "rpargt;": [10644], "rsaquo;": [8250], "rsquor;": [8217], "rthree;": [8908], "rtimes;": [8906], "sacute;": [347], "scaron;": [353], "scedil;": [351], "scnsim;": [8937], "searhk;": [10533], "seswar;": [10537], "sfrown;": [8994], "shchcy;": [1097], "sigmaf;": [962], "sigmav;": [962], "simdot;": [10858], "smashp;": [10803], "softcy;": [1100], "solbar;": [9023], "spades;": [9824], "sqcaps;": [8851, 65024], "sqcups;": [8852, 65024], "sqsube;": [8849], "sqsupe;": [8850], "square;": [9633], "squarf;": [9642], "ssetmn;": [8726], "ssmile;": [8995], "sstarf;": [8902], "subdot;": [10941], "subset;": [8834], "subsim;": [10951], "subsub;": [10965], "subsup;": [10963], "succeq;": [10928], "supdot;": [10942], "supset;": [8835], "supsim;": [10952], "supsub;": [10964], "supsup;": [10966], "swarhk;": [10534], "swnwar;": [10538], "target;": [8982], "tcaron;": [357], "tcedil;": [355], "telrec;": [8981], "there4;": [8756], "thetav;": [977], "thinsp;": [8201], "thksim;": [8764], "timesb;": [8864], "timesd;": [10800], "topbot;": [9014], "topcir;": [10993], "tprime;": [8244], "tridot;": [9708], "tstrok;": [359], "uacute;": [250], "ubreve;": [365], "udblac;": [369], "ufisht;": [10622], "ugrave;": [249], "ulcorn;": [8988], "ulcrop;": [8975], "urcorn;": [8989], "urcrop;": [8974], "utilde;": [361], "vangrt;": [10652], "varphi;": [981], "varrho;": [1009], "veebar;": [8891], "vellip;": [8942], "verbar;": [124], "vsubnE;": [10955, 65024], "vsubne;": [8842, 65024], "vsupnE;": [10956, 65024], "vsupne;": [8843, 65024], "wedbar;": [10847], "wedgeq;": [8793], "weierp;": [8472], "wreath;": [8768], "xoplus;": [10753], "xotime;": [10754], "xsqcup;": [10758], "xuplus;": [10756], "xwedge;": [8896], "yacute;": [253], "zacute;": [378], "zcaron;": [382], "zeetrf;": [8488] } }, { "length": 6, "entities": { "AElig;": [198], "Aacute": [193], "Acirc;": [194], "Agrave": [192], "Alpha;": [913], "Amacr;": [256], "Aogon;": [260], "Aring;": [197], "Atilde": [195], "Breve;": [728], "Ccedil": [199], "Ccirc;": [264], "Colon;": [8759], "Cross;": [10799], "Dashv;": [10980], "Delta;": [916], "Eacute": [201], "Ecirc;": [202], "Egrave": [200], "Emacr;": [274], "Eogon;": [280], "Equal;": [10869], "Gamma;": [915], "Gcirc;": [284], "Hacek;": [711], "Hcirc;": [292], "IJlig;": [306], "Iacute": [205], "Icirc;": [206], "Igrave": [204], "Imacr;": [298], "Iogon;": [302], "Iukcy;": [1030], "Jcirc;": [308], "Jukcy;": [1028], "Kappa;": [922], "Ntilde": [209], "OElig;": [338], "Oacute": [211], "Ocirc;": [212], "Ograve": [210], "Omacr;": [332], "Omega;": [937], "Oslash": [216], "Otilde": [213], "Prime;": [8243], "RBarr;": [10512], "Scirc;": [348], "Sigma;": [931], "THORN;": [222], "TRADE;": [8482], "TSHcy;": [1035], "Theta;": [920], "Tilde;": [8764], "Uacute": [218], "Ubrcy;": [1038], "Ucirc;": [219], "Ugrave": [217], "Umacr;": [362], "Union;": [8899], "Uogon;": [370], "UpTee;": [8869], "Uring;": [366], "VDash;": [8875], "Vdash;": [8873], "Wcirc;": [372], "Wedge;": [8896], "Yacute": [221], "Ycirc;": [374], "aacute": [225], "acirc;": [226], "acute;": [180], "aelig;": [230], "agrave": [224], "aleph;": [8501], "alpha;": [945], "amacr;": [257], "amalg;": [10815], "angle;": [8736], "angrt;": [8735], "angst;": [197], "aogon;": [261], "aring;": [229], "asymp;": [8776], "atilde": [227], "awint;": [10769], "bcong;": [8780], "bdquo;": [8222], "bepsi;": [1014], "blank;": [9251], "blk12;": [9618], "blk14;": [9617], "blk34;": [9619], "block;": [9608], "boxDL;": [9559], "boxDR;": [9556], "boxDl;": [9558], "boxDr;": [9555], "boxHD;": [9574], "boxHU;": [9577], "boxHd;": [9572], "boxHu;": [9575], "boxUL;": [9565], "boxUR;": [9562], "boxUl;": [9564], "boxUr;": [9561], "boxVH;": [9580], "boxVL;": [9571], "boxVR;": [9568], "boxVh;": [9579], "boxVl;": [9570], "boxVr;": [9567], "boxdL;": [9557], "boxdR;": [9554], "boxdl;": [9488], "boxdr;": [9484], "boxhD;": [9573], "boxhU;": [9576], "boxhd;": [9516], "boxhu;": [9524], "boxuL;": [9563], "boxuR;": [9560], "boxul;": [9496], "boxur;": [9492], "boxvH;": [9578], "boxvL;": [9569], "boxvR;": [9566], "boxvh;": [9532], "boxvl;": [9508], "boxvr;": [9500], "breve;": [728], "brvbar": [166], "bsemi;": [8271], "bsime;": [8909], "bsolb;": [10693], "bumpE;": [10926], "bumpe;": [8783], "caret;": [8257], "caron;": [711], "ccaps;": [10829], "ccedil": [231], "ccirc;": [265], "ccups;": [10828], "cedil;": [184], "check;": [10003], "clubs;": [9827], "colon;": [58], "comma;": [44], "crarr;": [8629], "cross;": [10007], "csube;": [10961], "csupe;": [10962], "ctdot;": [8943], "cuepr;": [8926], "cuesc;": [8927], "cupor;": [10821], "curren": [164], "cuvee;": [8910], "cuwed;": [8911], "cwint;": [8753], "dashv;": [8867], "dblac;": [733], "ddarr;": [8650], "delta;": [948], "dharl;": [8643], "dharr;": [8642], "diams;": [9830], "disin;": [8946], "divide": [247], "doteq;": [8784], "dtdot;": [8945], "dtrif;": [9662], "duarr;": [8693], "duhar;": [10607], "eDDot;": [10871], "eacute": [233], "ecirc;": [234], "efDot;": [8786], "egrave": [232], "emacr;": [275], "empty;": [8709], "eogon;": [281], "eplus;": [10865], "epsiv;": [1013], "eqsim;": [8770], "equiv;": [8801], "erDot;": [8787], "erarr;": [10609], "esdot;": [8784], "exist;": [8707], "fflig;": [64256], "filig;": [64257], "fjlig;": [102, 106], "fllig;": [64258], "fltns;": [9649], "forkv;": [10969], "frac12": [189], "frac14": [188], "frac34": [190], "frasl;": [8260], "frown;": [8994], "gamma;": [947], "gcirc;": [285], "gescc;": [10921], "gimel;": [8503], "gneqq;": [8809], "gnsim;": [8935], "grave;": [96], "gsime;": [10894], "gsiml;": [10896], "gtcir;": [10874], "gtdot;": [8919], "harrw;": [8621], "hcirc;": [293], "hoarr;": [8703], "iacute": [237], "icirc;": [238], "iexcl;": [161], "igrave": [236], "iiint;": [8749], "iiota;": [8489], "ijlig;": [307], "imacr;": [299], "image;": [8465], "imath;": [305], "imped;": [437], "infin;": [8734], "iogon;": [303], "iprod;": [10812], "iquest": [191], "isinE;": [8953], "isins;": [8948], "isinv;": [8712], "iukcy;": [1110], "jcirc;": [309], "jmath;": [567], "jukcy;": [1108], "kappa;": [954], "lAarr;": [8666], "lBarr;": [10510], "langd;": [10641], "laquo;": [171], "larrb;": [8676], "lates;": [10925, 65024], "lbarr;": [10508], "lbbrk;": [10098], "lbrke;": [10635], "lceil;": [8968], "ldquo;": [8220], "lescc;": [10920], "lhard;": [8637], "lharu;": [8636], "lhblk;": [9604], "llarr;": [8647], "lltri;": [9722], "lneqq;": [8808], "lnsim;": [8934], "loang;": [10220], "loarr;": [8701], "lobrk;": [10214], "lopar;": [10629], "lrarr;": [8646], "lrhar;": [8651], "lrtri;": [8895], "lsime;": [10893], "lsimg;": [10895], "lsquo;": [8216], "ltcir;": [10873], "ltdot;": [8918], "ltrie;": [8884], "ltrif;": [9666], "mDDot;": [8762], "mdash;": [8212], "micro;": [181], "middot": [183], "minus;": [8722], "mumap;": [8888], "nabla;": [8711], "napid;": [8779, 824], "napos;": [329], "natur;": [9838], "nbump;": [8782, 824], "ncong;": [8775], "ndash;": [8211], "neArr;": [8663], "nearr;": [8599], "nedot;": [8784, 824], "nesim;": [8770, 824], "ngeqq;": [8807, 824], "ngsim;": [8821], "nhArr;": [8654], "nharr;": [8622], "nhpar;": [10994], "nlArr;": [8653], "nlarr;": [8602], "nleqq;": [8806, 824], "nless;": [8814], "nlsim;": [8820], "nltri;": [8938], "notin;": [8713], "notni;": [8716], "npart;": [8706, 824], "nprec;": [8832], "nrArr;": [8655], "nrarr;": [8603], "nrtri;": [8939], "nsime;": [8772], "nsmid;": [8740], "nspar;": [8742], "nsubE;": [10949, 824], "nsube;": [8840], "nsucc;": [8833], "nsupE;": [10950, 824], "nsupe;": [8841], "ntilde": [241], "numsp;": [8199], "nvsim;": [8764, 8402], "nwArr;": [8662], "nwarr;": [8598], "oacute": [243], "ocirc;": [244], "odash;": [8861], "oelig;": [339], "ofcir;": [10687], "ograve": [242], "ohbar;": [10677], "olarr;": [8634], "olcir;": [10686], "oline;": [8254], "omacr;": [333], "omega;": [969], "operp;": [10681], "oplus;": [8853], "orarr;": [8635], "order;": [8500], "oslash": [248], "otilde": [245], "ovbar;": [9021], "parsl;": [11005], "phone;": [9742], "plusb;": [8862], "pluse;": [10866], "plusmn": [177], "pound;": [163], "prcue;": [8828], "prime;": [8242], "prnap;": [10937], "prsim;": [8830], "quest;": [63], "rAarr;": [8667], "rBarr;": [10511], "radic;": [8730], "rangd;": [10642], "range;": [10661], "raquo;": [187], "rarrb;": [8677], "rarrc;": [10547], "rarrw;": [8605], "ratio;": [8758], "rbarr;": [10509], "rbbrk;": [10099], "rbrke;": [10636], "rceil;": [8969], "rdquo;": [8221], "reals;": [8477], "rhard;": [8641], "rharu;": [8640], "rlarr;": [8644], "rlhar;": [8652], "rnmid;": [10990], "roang;": [10221], "roarr;": [8702], "robrk;": [10215], "ropar;": [10630], "rrarr;": [8649], "rsquo;": [8217], "rtrie;": [8885], "rtrif;": [9656], "sbquo;": [8218], "sccue;": [8829], "scirc;": [349], "scnap;": [10938], "scsim;": [8831], "sdotb;": [8865], "sdote;": [10854], "seArr;": [8664], "searr;": [8600], "setmn;": [8726], "sharp;": [9839], "sigma;": [963], "simeq;": [8771], "simgE;": [10912], "simlE;": [10911], "simne;": [8774], "slarr;": [8592], "smile;": [8995], "smtes;": [10924, 65024], "sqcap;": [8851], "sqcup;": [8852], "sqsub;": [8847], "sqsup;": [8848], "srarr;": [8594], "starf;": [9733], "strns;": [175], "subnE;": [10955], "subne;": [8842], "supnE;": [10956], "supne;": [8843], "swArr;": [8665], "swarr;": [8601], "szlig;": [223], "theta;": [952], "thkap;": [8776], "thorn;": [254], "tilde;": [732], "times;": [215], "trade;": [8482], "trisb;": [10701], "tshcy;": [1115], "twixt;": [8812], "uacute": [250], "ubrcy;": [1118], "ucirc;": [251], "udarr;": [8645], "udhar;": [10606], "ugrave": [249], "uharl;": [8639], "uharr;": [8638], "uhblk;": [9600], "ultri;": [9720], "umacr;": [363], "uogon;": [371], "uplus;": [8846], "upsih;": [978], "uring;": [367], "urtri;": [9721], "utdot;": [8944], "utrif;": [9652], "uuarr;": [8648], "vBarv;": [10985], "vDash;": [8872], "varpi;": [982], "vdash;": [8866], "veeeq;": [8794], "vltri;": [8882], "vnsub;": [8834, 8402], "vnsup;": [8835, 8402], "vprop;": [8733], "vrtri;": [8883], "wcirc;": [373], "wedge;": [8743], "xcirc;": [9711], "xdtri;": [9661], "xhArr;": [10234], "xharr;": [10231], "xlArr;": [10232], "xlarr;": [10229], "xodot;": [10752], "xrArr;": [10233], "xrarr;": [10230], "xutri;": [9651], "yacute": [253], "ycirc;": [375] } }, { "length": 5, "entities": { "AElig": [198], "Acirc": [194], "Aopf;": [120120], "Aring": [197], "Ascr;": [119964], "Auml;": [196], "Barv;": [10983], "Beta;": [914], "Bopf;": [120121], "Bscr;": [8492], "CHcy;": [1063], "COPY;": [169], "Cdot;": [266], "Copf;": [8450], "Cscr;": [119966], "DJcy;": [1026], "DScy;": [1029], "DZcy;": [1039], "Darr;": [8609], "Dopf;": [120123], "Dscr;": [119967], "Ecirc": [202], "Edot;": [278], "Eopf;": [120124], "Escr;": [8496], "Esim;": [10867], "Euml;": [203], "Fopf;": [120125], "Fscr;": [8497], "GJcy;": [1027], "Gdot;": [288], "Gopf;": [120126], "Gscr;": [119970], "Hopf;": [8461], "Hscr;": [8459], "IEcy;": [1045], "IOcy;": [1025], "Icirc": [206], "Idot;": [304], "Iopf;": [120128], "Iota;": [921], "Iscr;": [8464], "Iuml;": [207], "Jopf;": [120129], "Jscr;": [119973], "KHcy;": [1061], "KJcy;": [1036], "Kopf;": [120130], "Kscr;": [119974], "LJcy;": [1033], "Lang;": [10218], "Larr;": [8606], "Lopf;": [120131], "Lscr;": [8466], "Mopf;": [120132], "Mscr;": [8499], "NJcy;": [1034], "Nopf;": [8469], "Nscr;": [119977], "Ocirc": [212], "Oopf;": [120134], "Oscr;": [119978], "Ouml;": [214], "Popf;": [8473], "Pscr;": [119979], "QUOT;": [34], "Qopf;": [8474], "Qscr;": [119980], "Rang;": [10219], "Rarr;": [8608], "Ropf;": [8477], "Rscr;": [8475], "SHcy;": [1064], "Sopf;": [120138], "Sqrt;": [8730], "Sscr;": [119982], "Star;": [8902], "THORN": [222], "TScy;": [1062], "Topf;": [120139], "Tscr;": [119983], "Uarr;": [8607], "Ucirc": [219], "Uopf;": [120140], "Upsi;": [978], "Uscr;": [119984], "Uuml;": [220], "Vbar;": [10987], "Vert;": [8214], "Vopf;": [120141], "Vscr;": [119985], "Wopf;": [120142], "Wscr;": [119986], "Xopf;": [120143], "Xscr;": [119987], "YAcy;": [1071], "YIcy;": [1031], "YUcy;": [1070], "Yopf;": [120144], "Yscr;": [119988], "Yuml;": [376], "ZHcy;": [1046], "Zdot;": [379], "Zeta;": [918], "Zopf;": [8484], "Zscr;": [119989], "acirc": [226], "acute": [180], "aelig": [230], "andd;": [10844], "andv;": [10842], "ange;": [10660], "aopf;": [120146], "apid;": [8779], "apos;": [39], "aring": [229], "ascr;": [119990], "auml;": [228], "bNot;": [10989], "bbrk;": [9141], "beta;": [946], "beth;": [8502], "bnot;": [8976], "bopf;": [120147], "boxH;": [9552], "boxV;": [9553], "boxh;": [9472], "boxv;": [9474], "bscr;": [119991], "bsim;": [8765], "bsol;": [92], "bull;": [8226], "bump;": [8782], "caps;": [8745, 65024], "cdot;": [267], "cedil": [184], "cent;": [162], "chcy;": [1095], "cirE;": [10691], "circ;": [710], "cire;": [8791], "comp;": [8705], "cong;": [8773], "copf;": [120148], "copy;": [169], "cscr;": [119992], "csub;": [10959], "csup;": [10960], "cups;": [8746, 65024], "dArr;": [8659], "dHar;": [10597], "darr;": [8595], "dash;": [8208], "diam;": [8900], "djcy;": [1106], "dopf;": [120149], "dscr;": [119993], "dscy;": [1109], "dsol;": [10742], "dtri;": [9663], "dzcy;": [1119], "eDot;": [8785], "ecir;": [8790], "ecirc": [234], "edot;": [279], "emsp;": [8195], "ensp;": [8194], "eopf;": [120150], "epar;": [8917], "epsi;": [949], "escr;": [8495], "esim;": [8770], "euml;": [235], "euro;": [8364], "excl;": [33], "flat;": [9837], "fnof;": [402], "fopf;": [120151], "fork;": [8916], "fscr;": [119995], "gdot;": [289], "geqq;": [8807], "gesl;": [8923, 65024], "gjcy;": [1107], "gnap;": [10890], "gneq;": [10888], "gopf;": [120152], "gscr;": [8458], "gsim;": [8819], "gtcc;": [10919], "gvnE;": [8809, 65024], "hArr;": [8660], "half;": [189], "harr;": [8596], "hbar;": [8463], "hopf;": [120153], "hscr;": [119997], "icirc": [238], "iecy;": [1077], "iexcl": [161], "imof;": [8887], "iocy;": [1105], "iopf;": [120154], "iota;": [953], "iscr;": [119998], "isin;": [8712], "iuml;": [239], "jopf;": [120155], "jscr;": [119999], "khcy;": [1093], "kjcy;": [1116], "kopf;": [120156], "kscr;": [120000], "lArr;": [8656], "lHar;": [10594], "lang;": [10216], "laquo": [171], "larr;": [8592], "late;": [10925], "lcub;": [123], "ldca;": [10550], "ldsh;": [8626], "leqq;": [8806], "lesg;": [8922, 65024], "ljcy;": [1113], "lnap;": [10889], "lneq;": [10887], "lopf;": [120157], "lozf;": [10731], "lpar;": [40], "lscr;": [120001], "lsim;": [8818], "lsqb;": [91], "ltcc;": [10918], "ltri;": [9667], "lvnE;": [8808, 65024], "macr;": [175], "male;": [9794], "malt;": [10016], "micro": [181], "mlcp;": [10971], "mldr;": [8230], "mopf;": [120158], "mscr;": [120002], "nGtv;": [8811, 824], "nLtv;": [8810, 824], "nang;": [8736, 8402], "napE;": [10864, 824], "nbsp;": [160], "ncap;": [10819], "ncup;": [10818], "ngeq;": [8817], "nges;": [10878, 824], "ngtr;": [8815], "nisd;": [8954], "njcy;": [1114], "nldr;": [8229], "nleq;": [8816], "nles;": [10877, 824], "nmid;": [8740], "nopf;": [120159], "npar;": [8742], "npre;": [10927, 824], "nsce;": [10928, 824], "nscr;": [120003], "nsim;": [8769], "nsub;": [8836], "nsup;": [8837], "ntgl;": [8825], "ntlg;": [8824], "nvap;": [8781, 8402], "nvge;": [8805, 8402], "nvgt;": [62, 8402], "nvle;": [8804, 8402], "nvlt;": [60, 8402], "oast;": [8859], "ocir;": [8858], "ocirc": [244], "odiv;": [10808], "odot;": [8857], "ogon;": [731], "oint;": [8750], "omid;": [10678], "oopf;": [120160], "opar;": [10679], "ordf;": [170], "ordm;": [186], "oror;": [10838], "oscr;": [8500], "osol;": [8856], "ouml;": [246], "para;": [182], "part;": [8706], "perp;": [8869], "phiv;": [981], "plus;": [43], "popf;": [120161], "pound": [163], "prap;": [10935], "prec;": [8826], "prnE;": [10933], "prod;": [8719], "prop;": [8733], "pscr;": [120005], "qint;": [10764], "qopf;": [120162], "qscr;": [120006], "quot;": [34], "rArr;": [8658], "rHar;": [10596], "race;": [8765, 817], "rang;": [10217], "raquo": [187], "rarr;": [8594], "rcub;": [125], "rdca;": [10551], "rdsh;": [8627], "real;": [8476], "rect;": [9645], "rhov;": [1009], "ring;": [730], "ropf;": [120163], "rpar;": [41], "rscr;": [120007], "rsqb;": [93], "rtri;": [9657], "scap;": [10936], "scnE;": [10934], "sdot;": [8901], "sect;": [167], "semi;": [59], "sext;": [10038], "shcy;": [1096], "sime;": [8771], "simg;": [10910], "siml;": [10909], "smid;": [8739], "smte;": [10924], "solb;": [10692], "sopf;": [120164], "spar;": [8741], "squf;": [9642], "sscr;": [120008], "star;": [9734], "subE;": [10949], "sube;": [8838], "succ;": [8827], "sung;": [9834], "sup1;": [185], "sup2;": [178], "sup3;": [179], "supE;": [10950], "supe;": [8839], "szlig": [223], "tbrk;": [9140], "tdot;": [8411], "thorn": [254], "times": [215], "tint;": [8749], "toea;": [10536], "topf;": [120165], "tosa;": [10537], "trie;": [8796], "tscr;": [120009], "tscy;": [1094], "uArr;": [8657], "uHar;": [10595], "uarr;": [8593], "ucirc": [251], "uopf;": [120166], "upsi;": [965], "uscr;": [120010], "utri;": [9653], "uuml;": [252], "vArr;": [8661], "vBar;": [10984], "varr;": [8597], "vert;": [124], "vopf;": [120167], "vscr;": [120011], "wopf;": [120168], "wscr;": [120012], "xcap;": [8898], "xcup;": [8899], "xmap;": [10236], "xnis;": [8955], "xopf;": [120169], "xscr;": [120013], "xvee;": [8897], "yacy;": [1103], "yicy;": [1111], "yopf;": [120170], "yscr;": [120014], "yucy;": [1102], "yuml;": [255], "zdot;": [380], "zeta;": [950], "zhcy;": [1078], "zopf;": [120171], "zscr;": [120015], "zwnj;": [8204] } }, { "length": 4, "entities": { "AMP;": [38], "Acy;": [1040], "Afr;": [120068], "And;": [10835], "Auml": [196], "Bcy;": [1041], "Bfr;": [120069], "COPY": [169], "Cap;": [8914], "Cfr;": [8493], "Chi;": [935], "Cup;": [8915], "Dcy;": [1044], "Del;": [8711], "Dfr;": [120071], "Dot;": [168], "ENG;": [330], "ETH;": [208], "Ecy;": [1069], "Efr;": [120072], "Eta;": [919], "Euml": [203], "Fcy;": [1060], "Ffr;": [120073], "Gcy;": [1043], "Gfr;": [120074], "Hat;": [94], "Hfr;": [8460], "Icy;": [1048], "Ifr;": [8465], "Int;": [8748], "Iuml": [207], "Jcy;": [1049], "Jfr;": [120077], "Kcy;": [1050], "Kfr;": [120078], "Lcy;": [1051], "Lfr;": [120079], "Lsh;": [8624], "Map;": [10501], "Mcy;": [1052], "Mfr;": [120080], "Ncy;": [1053], "Nfr;": [120081], "Not;": [10988], "Ocy;": [1054], "Ofr;": [120082], "Ouml": [214], "Pcy;": [1055], "Pfr;": [120083], "Phi;": [934], "Psi;": [936], "QUOT": [34], "Qfr;": [120084], "REG;": [174], "Rcy;": [1056], "Rfr;": [8476], "Rho;": [929], "Rsh;": [8625], "Scy;": [1057], "Sfr;": [120086], "Sub;": [8912], "Sum;": [8721], "Sup;": [8913], "Tab;": [9], "Tau;": [932], "Tcy;": [1058], "Tfr;": [120087], "Ucy;": [1059], "Ufr;": [120088], "Uuml": [220], "Vcy;": [1042], "Vee;": [8897], "Vfr;": [120089], "Wfr;": [120090], "Xfr;": [120091], "Ycy;": [1067], "Yfr;": [120092], "Zcy;": [1047], "Zfr;": [8488], "acE;": [8766, 819], "acd;": [8767], "acy;": [1072], "afr;": [120094], "amp;": [38], "and;": [8743], "ang;": [8736], "apE;": [10864], "ape;": [8778], "ast;": [42], "auml": [228], "bcy;": [1073], "bfr;": [120095], "bne;": [61, 8421], "bot;": [8869], "cap;": [8745], "cent": [162], "cfr;": [120096], "chi;": [967], "cir;": [9675], "copy": [169], "cup;": [8746], "dcy;": [1076], "deg;": [176], "dfr;": [120097], "die;": [168], "div;": [247], "dot;": [729], "ecy;": [1101], "efr;": [120098], "egs;": [10902], "ell;": [8467], "els;": [10901], "eng;": [331], "eta;": [951], "eth;": [240], "euml": [235], "fcy;": [1092], "ffr;": [120099], "gEl;": [10892], "gap;": [10886], "gcy;": [1075], "gel;": [8923], "geq;": [8805], "ges;": [10878], "gfr;": [120100], "ggg;": [8921], "glE;": [10898], "gla;": [10917], "glj;": [10916], "gnE;": [8809], "gne;": [10888], "hfr;": [120101], "icy;": [1080], "iff;": [8660], "ifr;": [120102], "int;": [8747], "iuml": [239], "jcy;": [1081], "jfr;": [120103], "kcy;": [1082], "kfr;": [120104], "lEg;": [10891], "lap;": [10885], "lat;": [10923], "lcy;": [1083], "leg;": [8922], "leq;": [8804], "les;": [10877], "lfr;": [120105], "lgE;": [10897], "lnE;": [8808], "lne;": [10887], "loz;": [9674], "lrm;": [8206], "lsh;": [8624], "macr": [175], "map;": [8614], "mcy;": [1084], "mfr;": [120106], "mho;": [8487], "mid;": [8739], "nGg;": [8921, 824], "nGt;": [8811, 8402], "nLl;": [8920, 824], "nLt;": [8810, 8402], "nap;": [8777], "nbsp": [160], "ncy;": [1085], "nfr;": [120107], "ngE;": [8807, 824], "nge;": [8817], "ngt;": [8815], "nis;": [8956], "niv;": [8715], "nlE;": [8806, 824], "nle;": [8816], "nlt;": [8814], "not;": [172], "npr;": [8832], "nsc;": [8833], "num;": [35], "ocy;": [1086], "ofr;": [120108], "ogt;": [10689], "ohm;": [937], "olt;": [10688], "ord;": [10845], "ordf": [170], "ordm": [186], "orv;": [10843], "ouml": [246], "par;": [8741], "para": [182], "pcy;": [1087], "pfr;": [120109], "phi;": [966], "piv;": [982], "prE;": [10931], "pre;": [10927], "psi;": [968], "qfr;": [120110], "quot": [34], "rcy;": [1088], "reg;": [174], "rfr;": [120111], "rho;": [961], "rlm;": [8207], "rsh;": [8625], "scE;": [10932], "sce;": [10928], "scy;": [1089], "sect": [167], "sfr;": [120112], "shy;": [173], "sim;": [8764], "smt;": [10922], "sol;": [47], "squ;": [9633], "sub;": [8834], "sum;": [8721], "sup1": [185], "sup2": [178], "sup3": [179], "sup;": [8835], "tau;": [964], "tcy;": [1090], "tfr;": [120113], "top;": [8868], "ucy;": [1091], "ufr;": [120114], "uml;": [168], "uuml": [252], "vcy;": [1074], "vee;": [8744], "vfr;": [120115], "wfr;": [120116], "xfr;": [120117], "ycy;": [1099], "yen;": [165], "yfr;": [120118], "yuml": [255], "zcy;": [1079], "zfr;": [120119], "zwj;": [8205] } }, { "length": 3, "entities": { "AMP": [38], "DD;": [8517], "ETH": [208], "GT;": [62], "Gg;": [8921], "Gt;": [8811], "Im;": [8465], "LT;": [60], "Ll;": [8920], "Lt;": [8810], "Mu;": [924], "Nu;": [925], "Or;": [10836], "Pi;": [928], "Pr;": [10939], "REG": [174], "Re;": [8476], "Sc;": [10940], "Xi;": [926], "ac;": [8766], "af;": [8289], "amp": [38], "ap;": [8776], "dd;": [8518], "deg": [176], "ee;": [8519], "eg;": [10906], "el;": [10905], "eth": [240], "gE;": [8807], "ge;": [8805], "gg;": [8811], "gl;": [8823], "gt;": [62], "ic;": [8291], "ii;": [8520], "in;": [8712], "it;": [8290], "lE;": [8806], "le;": [8804], "lg;": [8822], "ll;": [8810], "lt;": [60], "mp;": [8723], "mu;": [956], "ne;": [8800], "ni;": [8715], "not": [172], "nu;": [957], "oS;": [9416], "or;": [8744], "pi;": [960], "pm;": [177], "pr;": [8826], "reg": [174], "rx;": [8478], "sc;": [8827], "shy": [173], "uml": [168], "wp;": [8472], "wr;": [8768], "xi;": [958], "yen": [165] } }, { "length": 2, "entities": { "GT": [62], "LT": [60], "gt": [62], "lt": [60] } }];
  2988. const EOF = -1;
  2989. const NULL = 0x00;
  2990. const TABULATION = 0x09;
  2991. const CARRIAGE_RETURN = 0x0D;
  2992. const LINE_FEED = 0x0A;
  2993. const FORM_FEED = 0x0C;
  2994. const SPACE = 0x20;
  2995. const EXCLAMATION_MARK = 0x21;
  2996. const QUOTATION_MARK = 0x22;
  2997. const NUMBER_SIGN = 0x23;
  2998. const AMPERSAND = 0x26;
  2999. const APOSTROPHE = 0x27;
  3000. const LEFT_PARENTHESIS = 0x28;
  3001. const RIGHT_PARENTHESIS = 0x29;
  3002. const ASTERISK = 0x2A;
  3003. const HYPHEN_MINUS = 0x2D;
  3004. const SOLIDUS = 0x2F;
  3005. const DIGIT_0 = 0x30;
  3006. const DIGIT_9 = 0x39;
  3007. const COLON = 0x3a;
  3008. const SEMICOLON = 0x3B;
  3009. const LESS_THAN_SIGN = 0x3C;
  3010. const EQUALS_SIGN = 0x3D;
  3011. const GREATER_THAN_SIGN = 0x3E;
  3012. const QUESTION_MARK = 0x3F;
  3013. const LATIN_CAPITAL_A = 0x41;
  3014. const LATIN_CAPITAL_D = 0x44;
  3015. const LATIN_CAPITAL_F = 0x46;
  3016. const LATIN_CAPITAL_X = 0x58;
  3017. const LATIN_CAPITAL_Z = 0x5A;
  3018. const LEFT_SQUARE_BRACKET = 0x5B;
  3019. const REVERSE_SOLIDUS = 0x5C;
  3020. const RIGHT_SQUARE_BRACKET = 0x5D;
  3021. const GRAVE_ACCENT = 0x60;
  3022. const LATIN_SMALL_A = 0x61;
  3023. const LATIN_SMALL_F = 0x66;
  3024. const LATIN_SMALL_X = 0x78;
  3025. const LATIN_SMALL_Z = 0x7A;
  3026. const LEFT_CURLY_BRACKET = 0x7B;
  3027. const RIGHT_CURLY_BRACKET = 0x7D;
  3028. const NULL_REPLACEMENT = 0xFFFD;
  3029. function isWhitespace(cp) {
  3030. return cp === TABULATION || cp === LINE_FEED || cp === FORM_FEED || cp === CARRIAGE_RETURN || cp === SPACE;
  3031. }
  3032. function isUpperLetter(cp) {
  3033. return cp >= LATIN_CAPITAL_A && cp <= LATIN_CAPITAL_Z;
  3034. }
  3035. function isLowerLetter(cp) {
  3036. return cp >= LATIN_SMALL_A && cp <= LATIN_SMALL_Z;
  3037. }
  3038. function isLetter(cp) {
  3039. return isLowerLetter(cp) || isUpperLetter(cp);
  3040. }
  3041. function isDigit(cp) {
  3042. return cp >= DIGIT_0 && cp <= DIGIT_9;
  3043. }
  3044. function isUpperHexDigit(cp) {
  3045. return cp >= LATIN_CAPITAL_A && cp <= LATIN_CAPITAL_F;
  3046. }
  3047. function isLowerHexDigit(cp) {
  3048. return cp >= LATIN_SMALL_A && cp <= LATIN_SMALL_F;
  3049. }
  3050. function isHexDigit(cp) {
  3051. return isDigit(cp) || isUpperHexDigit(cp) || isLowerHexDigit(cp);
  3052. }
  3053. function isControl(cp) {
  3054. return (cp >= 0 && cp <= 0x1F) || (cp >= 0x7F && cp <= 0x9F);
  3055. }
  3056. function isSurrogate(cp) {
  3057. return cp >= 0xD800 && cp <= 0xDFFF;
  3058. }
  3059. function isSurrogatePair(cp) {
  3060. return cp >= 0xDC00 && cp <= 0xDFFF;
  3061. }
  3062. function isNonCharacter(cp) {
  3063. return ((cp >= 0xFDD0 && cp <= 0xFDEF) ||
  3064. ((cp & 0xFFFE) === 0xFFFE && cp <= 0x10FFFF));
  3065. }
  3066. function toLowerCodePoint(cp) {
  3067. return cp + 0x0020;
  3068. }
  3069. class Tokenizer {
  3070. constructor(text, parserOptions) {
  3071. this.vExpressionScriptState = null;
  3072. debug("[html] the source code length: %d", text.length);
  3073. this.text = text;
  3074. this.gaps = [];
  3075. this.lineTerminators = [];
  3076. this.parserOptions = parserOptions || {};
  3077. this.lastCodePoint = this.lastCodePointRaw = NULL;
  3078. this.offset = -1;
  3079. this.column = -1;
  3080. this.line = 1;
  3081. this.state = "DATA";
  3082. this.returnState = "DATA";
  3083. this.reconsuming = false;
  3084. this.buffer = [];
  3085. this.crStartOffset = -1;
  3086. this.crCode = 0;
  3087. this.errors = [];
  3088. this.committedToken = null;
  3089. this.provisionalToken = null;
  3090. this.currentToken = null;
  3091. this.lastTagOpenToken = null;
  3092. this.tokenStartOffset = -1;
  3093. this.tokenStartColumn = -1;
  3094. this.tokenStartLine = 1;
  3095. this.namespace = NS.HTML;
  3096. this.expressionEnabled = false;
  3097. }
  3098. nextToken() {
  3099. let cp = this.lastCodePoint;
  3100. while (this.committedToken == null &&
  3101. (cp !== EOF || this.reconsuming)) {
  3102. if (this.provisionalToken != null && !this.isProvisionalState()) {
  3103. this.commitProvisionalToken();
  3104. if (this.committedToken != null) {
  3105. break;
  3106. }
  3107. }
  3108. if (this.reconsuming) {
  3109. this.reconsuming = false;
  3110. cp = this.lastCodePoint;
  3111. }
  3112. else {
  3113. cp = this.consumeNextCodePoint();
  3114. }
  3115. debug("[html] parse", cp, this.state);
  3116. this.state = this[this.state](cp);
  3117. }
  3118. {
  3119. const token = this.consumeCommittedToken();
  3120. if (token != null) {
  3121. return token;
  3122. }
  3123. }
  3124. assert__default["default"](cp === EOF);
  3125. if (this.currentToken != null) {
  3126. this.endToken();
  3127. const token = this.consumeCommittedToken();
  3128. if (token != null) {
  3129. return token;
  3130. }
  3131. }
  3132. return this.currentToken;
  3133. }
  3134. consumeCommittedToken() {
  3135. const token = this.committedToken;
  3136. this.committedToken = null;
  3137. return token;
  3138. }
  3139. consumeNextCodePoint() {
  3140. if (this.offset >= this.text.length) {
  3141. this.lastCodePoint = this.lastCodePointRaw = EOF;
  3142. return EOF;
  3143. }
  3144. this.offset += this.lastCodePoint >= 0x10000 ? 2 : 1;
  3145. if (this.offset >= this.text.length) {
  3146. this.advanceLocation();
  3147. this.lastCodePoint = this.lastCodePointRaw = EOF;
  3148. return EOF;
  3149. }
  3150. const cp = this.text.codePointAt(this.offset);
  3151. if (isSurrogate(this.text.charCodeAt(this.offset)) &&
  3152. !isSurrogatePair(this.text.charCodeAt(this.offset + 1))) {
  3153. this.reportParseError("surrogate-in-input-stream");
  3154. }
  3155. if (isNonCharacter(cp)) {
  3156. this.reportParseError("noncharacter-in-input-stream");
  3157. }
  3158. if (isControl(cp) && !isWhitespace(cp) && cp !== NULL) {
  3159. this.reportParseError("control-character-in-input-stream");
  3160. }
  3161. if (this.lastCodePointRaw === CARRIAGE_RETURN && cp === LINE_FEED) {
  3162. this.lastCodePoint = this.lastCodePointRaw = LINE_FEED;
  3163. this.gaps.push(this.offset);
  3164. return this.consumeNextCodePoint();
  3165. }
  3166. this.advanceLocation();
  3167. this.lastCodePoint = this.lastCodePointRaw = cp;
  3168. if (cp === CARRIAGE_RETURN) {
  3169. this.lastCodePoint = LINE_FEED;
  3170. return LINE_FEED;
  3171. }
  3172. return cp;
  3173. }
  3174. advanceLocation() {
  3175. if (this.lastCodePointRaw === LINE_FEED) {
  3176. this.lineTerminators.push(this.offset);
  3177. this.line += 1;
  3178. this.column = 0;
  3179. }
  3180. else {
  3181. this.column += this.lastCodePoint >= 0x10000 ? 2 : 1;
  3182. }
  3183. }
  3184. reconsumeAs(state) {
  3185. this.reconsuming = true;
  3186. return state;
  3187. }
  3188. reportParseError(code) {
  3189. const error = ParseError.fromCode(code, this.offset, this.line, this.column);
  3190. this.errors.push(error);
  3191. debug("[html] syntax error:", error.message);
  3192. }
  3193. setStartTokenMark() {
  3194. this.tokenStartOffset = this.offset;
  3195. this.tokenStartLine = this.line;
  3196. this.tokenStartColumn = this.column;
  3197. }
  3198. clearStartTokenMark() {
  3199. this.tokenStartOffset = -1;
  3200. }
  3201. startToken(type) {
  3202. if (this.tokenStartOffset === -1) {
  3203. this.setStartTokenMark();
  3204. }
  3205. const offset = this.tokenStartOffset;
  3206. const line = this.tokenStartLine;
  3207. const column = this.tokenStartColumn;
  3208. if (this.currentToken != null) {
  3209. this.endToken();
  3210. }
  3211. this.tokenStartOffset = -1;
  3212. const token = (this.currentToken = {
  3213. type,
  3214. range: [offset, -1],
  3215. loc: {
  3216. start: { line, column },
  3217. end: { line: -1, column: -1 },
  3218. },
  3219. value: "",
  3220. });
  3221. debug("[html] start token: %d %s", offset, token.type);
  3222. return this.currentToken;
  3223. }
  3224. endToken() {
  3225. if (this.currentToken == null) {
  3226. throw new Error("Invalid state");
  3227. }
  3228. if (this.tokenStartOffset === -1) {
  3229. this.setStartTokenMark();
  3230. }
  3231. const token = this.currentToken;
  3232. const offset = this.tokenStartOffset;
  3233. const line = this.tokenStartLine;
  3234. const column = this.tokenStartColumn;
  3235. const provisional = this.isProvisionalState();
  3236. this.currentToken = null;
  3237. this.tokenStartOffset = -1;
  3238. token.range[1] = offset;
  3239. token.loc.end.line = line;
  3240. token.loc.end.column = column;
  3241. if (token.range[0] === offset && !provisional) {
  3242. debug("[html] abandon token: %j %s %j", token.range, token.type, token.value);
  3243. return null;
  3244. }
  3245. if (provisional) {
  3246. if (this.provisionalToken != null) {
  3247. this.commitProvisionalToken();
  3248. }
  3249. this.provisionalToken = token;
  3250. debug("[html] provisional-commit token: %j %s %j", token.range, token.type, token.value);
  3251. }
  3252. else {
  3253. this.commitToken(token);
  3254. }
  3255. return token;
  3256. }
  3257. commitToken(token) {
  3258. assert__default["default"](this.committedToken == null, "Invalid state: the commited token existed already.");
  3259. debug("[html] commit token: %j %j %s %j", token.range, token.loc, token.type, token.value);
  3260. this.committedToken = token;
  3261. if (token.type === "HTMLTagOpen") {
  3262. this.lastTagOpenToken = token;
  3263. }
  3264. }
  3265. isProvisionalState() {
  3266. return (this.state.startsWith("RCDATA_") ||
  3267. this.state.startsWith("RAWTEXT_"));
  3268. }
  3269. commitProvisionalToken() {
  3270. assert__default["default"](this.provisionalToken != null, "Invalid state: the provisional token was not found.");
  3271. const token = this.provisionalToken;
  3272. this.provisionalToken = null;
  3273. if (token.range[0] < token.range[1]) {
  3274. this.commitToken(token);
  3275. }
  3276. }
  3277. rollbackProvisionalToken() {
  3278. assert__default["default"](this.currentToken != null);
  3279. assert__default["default"](this.provisionalToken != null);
  3280. const token = this.currentToken;
  3281. debug("[html] rollback token: %d %s", token.range[0], token.type);
  3282. this.currentToken = this.provisionalToken;
  3283. this.provisionalToken = null;
  3284. }
  3285. appendTokenValue(cp, expected) {
  3286. const token = this.currentToken;
  3287. if (token == null || (expected != null && token.type !== expected)) {
  3288. const msg1 = expected ? `"${expected}" type` : "any token";
  3289. const msg2 = token ? `"${token.type}" type` : "no token";
  3290. throw new Error(`Tokenizer: Invalid state. Expected ${msg1}, but got ${msg2}.`);
  3291. }
  3292. token.value += String.fromCodePoint(cp);
  3293. }
  3294. isAppropriateEndTagOpen() {
  3295. return (this.currentToken != null &&
  3296. this.lastTagOpenToken != null &&
  3297. this.currentToken.type === "HTMLEndTagOpen" &&
  3298. this.currentToken.value === this.lastTagOpenToken.value);
  3299. }
  3300. DATA(cp) {
  3301. this.clearStartTokenMark();
  3302. while (true) {
  3303. const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLText";
  3304. if (this.currentToken != null && this.currentToken.type !== type) {
  3305. this.endToken();
  3306. return this.reconsumeAs(this.state);
  3307. }
  3308. if (this.currentToken == null) {
  3309. this.startToken(type);
  3310. }
  3311. if (cp === AMPERSAND) {
  3312. this.returnState = "DATA";
  3313. return "CHARACTER_REFERENCE";
  3314. }
  3315. if (cp === LESS_THAN_SIGN) {
  3316. this.setStartTokenMark();
  3317. return "TAG_OPEN";
  3318. }
  3319. if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
  3320. this.setStartTokenMark();
  3321. this.returnState = "DATA";
  3322. return "V_EXPRESSION_START";
  3323. }
  3324. if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
  3325. this.setStartTokenMark();
  3326. this.returnState = "DATA";
  3327. return "V_EXPRESSION_END";
  3328. }
  3329. if (cp === EOF) {
  3330. return "DATA";
  3331. }
  3332. if (cp === NULL) {
  3333. this.reportParseError("unexpected-null-character");
  3334. }
  3335. this.appendTokenValue(cp, type);
  3336. cp = this.consumeNextCodePoint();
  3337. }
  3338. }
  3339. RCDATA(cp) {
  3340. this.clearStartTokenMark();
  3341. while (true) {
  3342. const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLRCDataText";
  3343. if (this.currentToken != null && this.currentToken.type !== type) {
  3344. this.endToken();
  3345. return this.reconsumeAs(this.state);
  3346. }
  3347. if (this.currentToken == null) {
  3348. this.startToken(type);
  3349. }
  3350. if (cp === AMPERSAND) {
  3351. this.returnState = "RCDATA";
  3352. return "CHARACTER_REFERENCE";
  3353. }
  3354. if (cp === LESS_THAN_SIGN) {
  3355. this.setStartTokenMark();
  3356. return "RCDATA_LESS_THAN_SIGN";
  3357. }
  3358. if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
  3359. this.setStartTokenMark();
  3360. this.returnState = "RCDATA";
  3361. return "V_EXPRESSION_START";
  3362. }
  3363. if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
  3364. this.setStartTokenMark();
  3365. this.returnState = "RCDATA";
  3366. return "V_EXPRESSION_END";
  3367. }
  3368. if (cp === EOF) {
  3369. return "DATA";
  3370. }
  3371. if (cp === NULL) {
  3372. this.reportParseError("unexpected-null-character");
  3373. cp = NULL_REPLACEMENT;
  3374. }
  3375. this.appendTokenValue(cp, type);
  3376. cp = this.consumeNextCodePoint();
  3377. }
  3378. }
  3379. RAWTEXT(cp) {
  3380. this.clearStartTokenMark();
  3381. while (true) {
  3382. const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLRawText";
  3383. if (this.currentToken != null && this.currentToken.type !== type) {
  3384. this.endToken();
  3385. return this.reconsumeAs(this.state);
  3386. }
  3387. if (this.currentToken == null) {
  3388. this.startToken(type);
  3389. }
  3390. if (cp === LESS_THAN_SIGN) {
  3391. this.setStartTokenMark();
  3392. return "RAWTEXT_LESS_THAN_SIGN";
  3393. }
  3394. if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
  3395. this.setStartTokenMark();
  3396. this.returnState = "RAWTEXT";
  3397. return "V_EXPRESSION_START";
  3398. }
  3399. if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
  3400. this.setStartTokenMark();
  3401. this.returnState = "RAWTEXT";
  3402. return "V_EXPRESSION_END";
  3403. }
  3404. if (cp === EOF) {
  3405. return "DATA";
  3406. }
  3407. if (cp === NULL) {
  3408. this.reportParseError("unexpected-null-character");
  3409. cp = NULL_REPLACEMENT;
  3410. }
  3411. this.appendTokenValue(cp, type);
  3412. cp = this.consumeNextCodePoint();
  3413. }
  3414. }
  3415. TAG_OPEN(cp) {
  3416. if (cp === EXCLAMATION_MARK) {
  3417. return "MARKUP_DECLARATION_OPEN";
  3418. }
  3419. if (cp === SOLIDUS) {
  3420. return "END_TAG_OPEN";
  3421. }
  3422. if (isLetter(cp)) {
  3423. this.startToken("HTMLTagOpen");
  3424. return this.reconsumeAs("TAG_NAME");
  3425. }
  3426. if (cp === QUESTION_MARK) {
  3427. this.reportParseError("unexpected-question-mark-instead-of-tag-name");
  3428. this.startToken("HTMLBogusComment");
  3429. return this.reconsumeAs("BOGUS_COMMENT");
  3430. }
  3431. if (cp === EOF) {
  3432. this.clearStartTokenMark();
  3433. this.reportParseError("eof-before-tag-name");
  3434. this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
  3435. return "DATA";
  3436. }
  3437. this.reportParseError("invalid-first-character-of-tag-name");
  3438. this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
  3439. return this.reconsumeAs("DATA");
  3440. }
  3441. END_TAG_OPEN(cp) {
  3442. if (isLetter(cp)) {
  3443. this.startToken("HTMLEndTagOpen");
  3444. return this.reconsumeAs("TAG_NAME");
  3445. }
  3446. if (cp === GREATER_THAN_SIGN) {
  3447. this.endToken();
  3448. this.reportParseError("missing-end-tag-name");
  3449. return "DATA";
  3450. }
  3451. if (cp === EOF) {
  3452. this.clearStartTokenMark();
  3453. this.reportParseError("eof-before-tag-name");
  3454. this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
  3455. this.appendTokenValue(SOLIDUS, "HTMLText");
  3456. return "DATA";
  3457. }
  3458. this.reportParseError("invalid-first-character-of-tag-name");
  3459. this.startToken("HTMLBogusComment");
  3460. return this.reconsumeAs("BOGUS_COMMENT");
  3461. }
  3462. TAG_NAME(cp) {
  3463. while (true) {
  3464. if (isWhitespace(cp)) {
  3465. this.endToken();
  3466. return "BEFORE_ATTRIBUTE_NAME";
  3467. }
  3468. if (cp === SOLIDUS) {
  3469. this.endToken();
  3470. this.setStartTokenMark();
  3471. return "SELF_CLOSING_START_TAG";
  3472. }
  3473. if (cp === GREATER_THAN_SIGN) {
  3474. this.startToken("HTMLTagClose");
  3475. return "DATA";
  3476. }
  3477. if (cp === EOF) {
  3478. this.reportParseError("eof-in-tag");
  3479. return "DATA";
  3480. }
  3481. if (cp === NULL) {
  3482. this.reportParseError("unexpected-null-character");
  3483. cp = NULL_REPLACEMENT;
  3484. }
  3485. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, null);
  3486. cp = this.consumeNextCodePoint();
  3487. }
  3488. }
  3489. RCDATA_LESS_THAN_SIGN(cp) {
  3490. if (cp === SOLIDUS) {
  3491. this.buffer = [];
  3492. return "RCDATA_END_TAG_OPEN";
  3493. }
  3494. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
  3495. return this.reconsumeAs("RCDATA");
  3496. }
  3497. RCDATA_END_TAG_OPEN(cp) {
  3498. if (isLetter(cp)) {
  3499. this.startToken("HTMLEndTagOpen");
  3500. return this.reconsumeAs("RCDATA_END_TAG_NAME");
  3501. }
  3502. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
  3503. this.appendTokenValue(SOLIDUS, "HTMLRCDataText");
  3504. return this.reconsumeAs("RCDATA");
  3505. }
  3506. RCDATA_END_TAG_NAME(cp) {
  3507. while (true) {
  3508. if (isWhitespace(cp) && this.isAppropriateEndTagOpen()) {
  3509. this.endToken();
  3510. return "BEFORE_ATTRIBUTE_NAME";
  3511. }
  3512. if (cp === SOLIDUS && this.isAppropriateEndTagOpen()) {
  3513. this.endToken();
  3514. this.setStartTokenMark();
  3515. return "SELF_CLOSING_START_TAG";
  3516. }
  3517. if (cp === GREATER_THAN_SIGN && this.isAppropriateEndTagOpen()) {
  3518. this.startToken("HTMLTagClose");
  3519. return "DATA";
  3520. }
  3521. if (!isLetter(cp)) {
  3522. this.rollbackProvisionalToken();
  3523. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
  3524. this.appendTokenValue(SOLIDUS, "HTMLRCDataText");
  3525. for (const cp1 of this.buffer) {
  3526. this.appendTokenValue(cp1, "HTMLRCDataText");
  3527. }
  3528. return this.reconsumeAs("RCDATA");
  3529. }
  3530. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLEndTagOpen");
  3531. this.buffer.push(cp);
  3532. cp = this.consumeNextCodePoint();
  3533. }
  3534. }
  3535. RAWTEXT_LESS_THAN_SIGN(cp) {
  3536. if (cp === SOLIDUS) {
  3537. this.buffer = [];
  3538. return "RAWTEXT_END_TAG_OPEN";
  3539. }
  3540. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
  3541. return this.reconsumeAs("RAWTEXT");
  3542. }
  3543. RAWTEXT_END_TAG_OPEN(cp) {
  3544. if (isLetter(cp)) {
  3545. this.startToken("HTMLEndTagOpen");
  3546. return this.reconsumeAs("RAWTEXT_END_TAG_NAME");
  3547. }
  3548. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
  3549. this.appendTokenValue(SOLIDUS, "HTMLRawText");
  3550. return this.reconsumeAs("RAWTEXT");
  3551. }
  3552. RAWTEXT_END_TAG_NAME(cp) {
  3553. while (true) {
  3554. if (cp === SOLIDUS && this.isAppropriateEndTagOpen()) {
  3555. this.endToken();
  3556. this.setStartTokenMark();
  3557. return "SELF_CLOSING_START_TAG";
  3558. }
  3559. if (cp === GREATER_THAN_SIGN && this.isAppropriateEndTagOpen()) {
  3560. this.startToken("HTMLTagClose");
  3561. return "DATA";
  3562. }
  3563. if (isWhitespace(cp) && this.isAppropriateEndTagOpen()) {
  3564. this.endToken();
  3565. return "BEFORE_ATTRIBUTE_NAME";
  3566. }
  3567. if (!isLetter(cp) && !maybeValidCustomBlock.call(this, cp)) {
  3568. this.rollbackProvisionalToken();
  3569. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
  3570. this.appendTokenValue(SOLIDUS, "HTMLRawText");
  3571. for (const cp1 of this.buffer) {
  3572. this.appendTokenValue(cp1, "HTMLRawText");
  3573. }
  3574. return this.reconsumeAs("RAWTEXT");
  3575. }
  3576. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLEndTagOpen");
  3577. this.buffer.push(cp);
  3578. cp = this.consumeNextCodePoint();
  3579. }
  3580. function maybeValidCustomBlock(nextCp) {
  3581. return (this.currentToken &&
  3582. this.lastTagOpenToken &&
  3583. this.lastTagOpenToken.value.startsWith(this.currentToken.value + String.fromCodePoint(nextCp)));
  3584. }
  3585. }
  3586. BEFORE_ATTRIBUTE_NAME(cp) {
  3587. while (isWhitespace(cp)) {
  3588. cp = this.consumeNextCodePoint();
  3589. }
  3590. if (cp === SOLIDUS || cp === GREATER_THAN_SIGN || cp === EOF) {
  3591. return this.reconsumeAs("AFTER_ATTRIBUTE_NAME");
  3592. }
  3593. if (cp === EQUALS_SIGN) {
  3594. this.reportParseError("unexpected-equals-sign-before-attribute-name");
  3595. this.startToken("HTMLIdentifier");
  3596. this.appendTokenValue(cp, "HTMLIdentifier");
  3597. return "ATTRIBUTE_NAME";
  3598. }
  3599. this.startToken("HTMLIdentifier");
  3600. return this.reconsumeAs("ATTRIBUTE_NAME");
  3601. }
  3602. ATTRIBUTE_NAME(cp) {
  3603. while (true) {
  3604. if (isWhitespace(cp) ||
  3605. cp === SOLIDUS ||
  3606. cp === GREATER_THAN_SIGN ||
  3607. cp === EOF) {
  3608. this.endToken();
  3609. return this.reconsumeAs("AFTER_ATTRIBUTE_NAME");
  3610. }
  3611. if (cp === EQUALS_SIGN) {
  3612. this.startToken("HTMLAssociation");
  3613. return "BEFORE_ATTRIBUTE_VALUE";
  3614. }
  3615. if (cp === NULL) {
  3616. this.reportParseError("unexpected-null-character");
  3617. cp = NULL_REPLACEMENT;
  3618. }
  3619. if (cp === QUOTATION_MARK ||
  3620. cp === APOSTROPHE ||
  3621. cp === LESS_THAN_SIGN) {
  3622. this.reportParseError("unexpected-character-in-attribute-name");
  3623. }
  3624. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLIdentifier");
  3625. cp = this.consumeNextCodePoint();
  3626. }
  3627. }
  3628. AFTER_ATTRIBUTE_NAME(cp) {
  3629. while (isWhitespace(cp)) {
  3630. cp = this.consumeNextCodePoint();
  3631. }
  3632. if (cp === SOLIDUS) {
  3633. this.setStartTokenMark();
  3634. return "SELF_CLOSING_START_TAG";
  3635. }
  3636. if (cp === EQUALS_SIGN) {
  3637. this.startToken("HTMLAssociation");
  3638. return "BEFORE_ATTRIBUTE_VALUE";
  3639. }
  3640. if (cp === GREATER_THAN_SIGN) {
  3641. this.startToken("HTMLTagClose");
  3642. return "DATA";
  3643. }
  3644. if (cp === EOF) {
  3645. this.reportParseError("eof-in-tag");
  3646. return "DATA";
  3647. }
  3648. this.startToken("HTMLIdentifier");
  3649. return this.reconsumeAs("ATTRIBUTE_NAME");
  3650. }
  3651. BEFORE_ATTRIBUTE_VALUE(cp) {
  3652. this.endToken();
  3653. while (isWhitespace(cp)) {
  3654. cp = this.consumeNextCodePoint();
  3655. }
  3656. if (cp === GREATER_THAN_SIGN) {
  3657. this.reportParseError("missing-attribute-value");
  3658. this.startToken("HTMLTagClose");
  3659. return "DATA";
  3660. }
  3661. this.startToken("HTMLLiteral");
  3662. if (cp === QUOTATION_MARK) {
  3663. return "ATTRIBUTE_VALUE_DOUBLE_QUOTED";
  3664. }
  3665. if (cp === APOSTROPHE) {
  3666. return "ATTRIBUTE_VALUE_SINGLE_QUOTED";
  3667. }
  3668. return this.reconsumeAs("ATTRIBUTE_VALUE_UNQUOTED");
  3669. }
  3670. ATTRIBUTE_VALUE_DOUBLE_QUOTED(cp) {
  3671. while (true) {
  3672. if (cp === QUOTATION_MARK) {
  3673. return "AFTER_ATTRIBUTE_VALUE_QUOTED";
  3674. }
  3675. if (cp === AMPERSAND) {
  3676. this.returnState = "ATTRIBUTE_VALUE_DOUBLE_QUOTED";
  3677. return "CHARACTER_REFERENCE";
  3678. }
  3679. if (cp === NULL) {
  3680. this.reportParseError("unexpected-null-character");
  3681. cp = NULL_REPLACEMENT;
  3682. }
  3683. if (cp === EOF) {
  3684. this.reportParseError("eof-in-tag");
  3685. return "DATA";
  3686. }
  3687. this.appendTokenValue(cp, "HTMLLiteral");
  3688. cp = this.consumeNextCodePoint();
  3689. }
  3690. }
  3691. ATTRIBUTE_VALUE_SINGLE_QUOTED(cp) {
  3692. while (true) {
  3693. if (cp === APOSTROPHE) {
  3694. return "AFTER_ATTRIBUTE_VALUE_QUOTED";
  3695. }
  3696. if (cp === AMPERSAND) {
  3697. this.returnState = "ATTRIBUTE_VALUE_SINGLE_QUOTED";
  3698. return "CHARACTER_REFERENCE";
  3699. }
  3700. if (cp === NULL) {
  3701. this.reportParseError("unexpected-null-character");
  3702. cp = NULL_REPLACEMENT;
  3703. }
  3704. if (cp === EOF) {
  3705. this.reportParseError("eof-in-tag");
  3706. return "DATA";
  3707. }
  3708. this.appendTokenValue(cp, "HTMLLiteral");
  3709. cp = this.consumeNextCodePoint();
  3710. }
  3711. }
  3712. ATTRIBUTE_VALUE_UNQUOTED(cp) {
  3713. while (true) {
  3714. if (isWhitespace(cp)) {
  3715. this.endToken();
  3716. return "BEFORE_ATTRIBUTE_NAME";
  3717. }
  3718. if (cp === AMPERSAND) {
  3719. this.returnState = "ATTRIBUTE_VALUE_UNQUOTED";
  3720. return "CHARACTER_REFERENCE";
  3721. }
  3722. if (cp === GREATER_THAN_SIGN) {
  3723. this.startToken("HTMLTagClose");
  3724. return "DATA";
  3725. }
  3726. if (cp === NULL) {
  3727. this.reportParseError("unexpected-null-character");
  3728. cp = NULL_REPLACEMENT;
  3729. }
  3730. if (cp === QUOTATION_MARK ||
  3731. cp === APOSTROPHE ||
  3732. cp === LESS_THAN_SIGN ||
  3733. cp === EQUALS_SIGN ||
  3734. cp === GRAVE_ACCENT) {
  3735. this.reportParseError("unexpected-character-in-unquoted-attribute-value");
  3736. }
  3737. if (cp === EOF) {
  3738. this.reportParseError("eof-in-tag");
  3739. return "DATA";
  3740. }
  3741. this.appendTokenValue(cp, "HTMLLiteral");
  3742. cp = this.consumeNextCodePoint();
  3743. }
  3744. }
  3745. AFTER_ATTRIBUTE_VALUE_QUOTED(cp) {
  3746. this.endToken();
  3747. if (isWhitespace(cp)) {
  3748. return "BEFORE_ATTRIBUTE_NAME";
  3749. }
  3750. if (cp === SOLIDUS) {
  3751. this.setStartTokenMark();
  3752. return "SELF_CLOSING_START_TAG";
  3753. }
  3754. if (cp === GREATER_THAN_SIGN) {
  3755. this.startToken("HTMLTagClose");
  3756. return "DATA";
  3757. }
  3758. if (cp === EOF) {
  3759. this.reportParseError("eof-in-tag");
  3760. return "DATA";
  3761. }
  3762. this.reportParseError("missing-whitespace-between-attributes");
  3763. return this.reconsumeAs("BEFORE_ATTRIBUTE_NAME");
  3764. }
  3765. SELF_CLOSING_START_TAG(cp) {
  3766. if (cp === GREATER_THAN_SIGN) {
  3767. this.startToken("HTMLSelfClosingTagClose");
  3768. return "DATA";
  3769. }
  3770. if (cp === EOF) {
  3771. this.reportParseError("eof-in-tag");
  3772. return "DATA";
  3773. }
  3774. this.reportParseError("unexpected-solidus-in-tag");
  3775. this.clearStartTokenMark();
  3776. return this.reconsumeAs("BEFORE_ATTRIBUTE_NAME");
  3777. }
  3778. BOGUS_COMMENT(cp) {
  3779. while (true) {
  3780. if (cp === GREATER_THAN_SIGN) {
  3781. return "DATA";
  3782. }
  3783. if (cp === EOF) {
  3784. return "DATA";
  3785. }
  3786. if (cp === NULL) {
  3787. cp = NULL_REPLACEMENT;
  3788. }
  3789. this.appendTokenValue(cp, null);
  3790. cp = this.consumeNextCodePoint();
  3791. }
  3792. }
  3793. MARKUP_DECLARATION_OPEN(cp) {
  3794. if (cp === HYPHEN_MINUS && this.text[this.offset + 1] === "-") {
  3795. this.offset += 1;
  3796. this.column += 1;
  3797. this.startToken("HTMLComment");
  3798. return "COMMENT_START";
  3799. }
  3800. if (cp === LATIN_CAPITAL_D &&
  3801. this.text.slice(this.offset + 1, this.offset + 7) === "OCTYPE") {
  3802. this.startToken("HTMLBogusComment");
  3803. this.appendTokenValue(cp, "HTMLBogusComment");
  3804. return "BOGUS_COMMENT";
  3805. }
  3806. if (cp === LEFT_SQUARE_BRACKET &&
  3807. this.text.slice(this.offset + 1, this.offset + 7) === "CDATA[") {
  3808. this.offset += 6;
  3809. this.column += 6;
  3810. if (this.namespace === NS.HTML) {
  3811. this.reportParseError("cdata-in-html-content");
  3812. this.startToken("HTMLBogusComment").value = "[CDATA[";
  3813. return "BOGUS_COMMENT";
  3814. }
  3815. this.startToken("HTMLCDataText");
  3816. return "CDATA_SECTION";
  3817. }
  3818. this.reportParseError("incorrectly-opened-comment");
  3819. this.startToken("HTMLBogusComment");
  3820. return this.reconsumeAs("BOGUS_COMMENT");
  3821. }
  3822. COMMENT_START(cp) {
  3823. if (cp === HYPHEN_MINUS) {
  3824. return "COMMENT_START_DASH";
  3825. }
  3826. if (cp === GREATER_THAN_SIGN) {
  3827. this.reportParseError("abrupt-closing-of-empty-comment");
  3828. return "DATA";
  3829. }
  3830. return this.reconsumeAs("COMMENT");
  3831. }
  3832. COMMENT_START_DASH(cp) {
  3833. if (cp === HYPHEN_MINUS) {
  3834. return "COMMENT_END";
  3835. }
  3836. if (cp === GREATER_THAN_SIGN) {
  3837. this.reportParseError("abrupt-closing-of-empty-comment");
  3838. return "DATA";
  3839. }
  3840. if (cp === EOF) {
  3841. this.reportParseError("eof-in-comment");
  3842. return "DATA";
  3843. }
  3844. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3845. return this.reconsumeAs("COMMENT");
  3846. }
  3847. COMMENT(cp) {
  3848. while (true) {
  3849. if (cp === LESS_THAN_SIGN) {
  3850. this.appendTokenValue(LESS_THAN_SIGN, "HTMLComment");
  3851. return "COMMENT_LESS_THAN_SIGN";
  3852. }
  3853. if (cp === HYPHEN_MINUS) {
  3854. return "COMMENT_END_DASH";
  3855. }
  3856. if (cp === NULL) {
  3857. this.reportParseError("unexpected-null-character");
  3858. cp = NULL_REPLACEMENT;
  3859. }
  3860. if (cp === EOF) {
  3861. this.reportParseError("eof-in-comment");
  3862. return "DATA";
  3863. }
  3864. this.appendTokenValue(cp, "HTMLComment");
  3865. cp = this.consumeNextCodePoint();
  3866. }
  3867. }
  3868. COMMENT_LESS_THAN_SIGN(cp) {
  3869. while (true) {
  3870. if (cp === EXCLAMATION_MARK) {
  3871. this.appendTokenValue(cp, "HTMLComment");
  3872. return "COMMENT_LESS_THAN_SIGN_BANG";
  3873. }
  3874. if (cp !== LESS_THAN_SIGN) {
  3875. return this.reconsumeAs("COMMENT");
  3876. }
  3877. this.appendTokenValue(cp, "HTMLComment");
  3878. cp = this.consumeNextCodePoint();
  3879. }
  3880. }
  3881. COMMENT_LESS_THAN_SIGN_BANG(cp) {
  3882. if (cp === HYPHEN_MINUS) {
  3883. return "COMMENT_LESS_THAN_SIGN_BANG_DASH";
  3884. }
  3885. return this.reconsumeAs("COMMENT");
  3886. }
  3887. COMMENT_LESS_THAN_SIGN_BANG_DASH(cp) {
  3888. if (cp === HYPHEN_MINUS) {
  3889. return "COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH";
  3890. }
  3891. return this.reconsumeAs("COMMENT_END_DASH");
  3892. }
  3893. COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH(cp) {
  3894. if (cp !== GREATER_THAN_SIGN && cp !== EOF) {
  3895. this.reportParseError("nested-comment");
  3896. }
  3897. return this.reconsumeAs("COMMENT_END");
  3898. }
  3899. COMMENT_END_DASH(cp) {
  3900. if (cp === HYPHEN_MINUS) {
  3901. return "COMMENT_END";
  3902. }
  3903. if (cp === EOF) {
  3904. this.reportParseError("eof-in-comment");
  3905. return "DATA";
  3906. }
  3907. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3908. return this.reconsumeAs("COMMENT");
  3909. }
  3910. COMMENT_END(cp) {
  3911. while (true) {
  3912. if (cp === GREATER_THAN_SIGN) {
  3913. return "DATA";
  3914. }
  3915. if (cp === EXCLAMATION_MARK) {
  3916. return "COMMENT_END_BANG";
  3917. }
  3918. if (cp === EOF) {
  3919. this.reportParseError("eof-in-comment");
  3920. return "DATA";
  3921. }
  3922. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3923. if (cp !== HYPHEN_MINUS) {
  3924. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3925. return this.reconsumeAs("COMMENT");
  3926. }
  3927. cp = this.consumeNextCodePoint();
  3928. }
  3929. }
  3930. COMMENT_END_BANG(cp) {
  3931. if (cp === HYPHEN_MINUS) {
  3932. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3933. this.appendTokenValue(EXCLAMATION_MARK, "HTMLComment");
  3934. return "COMMENT_END_DASH";
  3935. }
  3936. if (cp === GREATER_THAN_SIGN) {
  3937. this.reportParseError("incorrectly-closed-comment");
  3938. return "DATA";
  3939. }
  3940. if (cp === EOF) {
  3941. this.reportParseError("eof-in-comment");
  3942. return "DATA";
  3943. }
  3944. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3945. this.appendTokenValue(EXCLAMATION_MARK, "HTMLComment");
  3946. return this.reconsumeAs("COMMENT");
  3947. }
  3948. CDATA_SECTION(cp) {
  3949. while (true) {
  3950. if (cp === RIGHT_SQUARE_BRACKET) {
  3951. return "CDATA_SECTION_BRACKET";
  3952. }
  3953. if (cp === EOF) {
  3954. this.reportParseError("eof-in-cdata");
  3955. return "DATA";
  3956. }
  3957. this.appendTokenValue(cp, "HTMLCDataText");
  3958. cp = this.consumeNextCodePoint();
  3959. }
  3960. }
  3961. CDATA_SECTION_BRACKET(cp) {
  3962. if (cp === RIGHT_SQUARE_BRACKET) {
  3963. return "CDATA_SECTION_END";
  3964. }
  3965. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3966. return this.reconsumeAs("CDATA_SECTION");
  3967. }
  3968. CDATA_SECTION_END(cp) {
  3969. while (true) {
  3970. if (cp === GREATER_THAN_SIGN) {
  3971. return "DATA";
  3972. }
  3973. if (cp !== RIGHT_SQUARE_BRACKET) {
  3974. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3975. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3976. return this.reconsumeAs("CDATA_SECTION");
  3977. }
  3978. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3979. cp = this.consumeNextCodePoint();
  3980. }
  3981. }
  3982. CHARACTER_REFERENCE(cp) {
  3983. this.crStartOffset = this.offset - 1;
  3984. this.buffer = [AMPERSAND];
  3985. if (isDigit(cp) || isLetter(cp)) {
  3986. return this.reconsumeAs("NAMED_CHARACTER_REFERENCE");
  3987. }
  3988. if (cp === NUMBER_SIGN) {
  3989. this.buffer.push(cp);
  3990. return "NUMERIC_CHARACTER_REFERENCE";
  3991. }
  3992. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  3993. }
  3994. NAMED_CHARACTER_REFERENCE(cp) {
  3995. for (const entitySet of entitySets) {
  3996. const length = entitySet.length;
  3997. const entities = entitySet.entities;
  3998. const text = this.text.slice(this.offset, this.offset + length);
  3999. const codepoints = entities[text];
  4000. if (codepoints == null) {
  4001. continue;
  4002. }
  4003. const semi = text.endsWith(";");
  4004. const next = this.text.codePointAt(this.offset + 1);
  4005. this.offset += length - 1;
  4006. this.column += length - 1;
  4007. if (this.returnState.startsWith("ATTR") &&
  4008. !semi &&
  4009. next != null &&
  4010. (next === EQUALS_SIGN || isLetter(next) || isDigit(next))) {
  4011. for (const cp1 of text) {
  4012. this.buffer.push(cp1.codePointAt(0));
  4013. }
  4014. }
  4015. else {
  4016. if (!semi) {
  4017. this.reportParseError("missing-semicolon-after-character-reference");
  4018. }
  4019. this.buffer = codepoints;
  4020. }
  4021. return "CHARACTER_REFERENCE_END";
  4022. }
  4023. for (const cp0 of this.buffer) {
  4024. this.appendTokenValue(cp0, null);
  4025. }
  4026. this.appendTokenValue(cp, null);
  4027. return "AMBIGUOUS_AMPERSAND";
  4028. }
  4029. AMBIGUOUS_AMPERSAND(cp) {
  4030. while (isDigit(cp) || isLetter(cp)) {
  4031. this.appendTokenValue(cp, null);
  4032. cp = this.consumeNextCodePoint();
  4033. }
  4034. if (cp === SEMICOLON) {
  4035. this.reportParseError("unknown-named-character-reference");
  4036. }
  4037. return this.reconsumeAs(this.returnState);
  4038. }
  4039. NUMERIC_CHARACTER_REFERENCE(cp) {
  4040. this.crCode = 0;
  4041. if (cp === LATIN_SMALL_X || cp === LATIN_CAPITAL_X) {
  4042. this.buffer.push(cp);
  4043. return "HEXADEMICAL_CHARACTER_REFERENCE_START";
  4044. }
  4045. return this.reconsumeAs("DECIMAL_CHARACTER_REFERENCE_START");
  4046. }
  4047. HEXADEMICAL_CHARACTER_REFERENCE_START(cp) {
  4048. if (isHexDigit(cp)) {
  4049. return this.reconsumeAs("HEXADEMICAL_CHARACTER_REFERENCE");
  4050. }
  4051. this.reportParseError("absence-of-digits-in-numeric-character-reference");
  4052. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  4053. }
  4054. DECIMAL_CHARACTER_REFERENCE_START(cp) {
  4055. if (isDigit(cp)) {
  4056. return this.reconsumeAs("DECIMAL_CHARACTER_REFERENCE");
  4057. }
  4058. this.reportParseError("absence-of-digits-in-numeric-character-reference");
  4059. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  4060. }
  4061. HEXADEMICAL_CHARACTER_REFERENCE(cp) {
  4062. while (true) {
  4063. if (isDigit(cp)) {
  4064. this.crCode = 16 * this.crCode + (cp - 0x30);
  4065. }
  4066. else if (isUpperHexDigit(cp)) {
  4067. this.crCode = 16 * this.crCode + (cp - 0x37);
  4068. }
  4069. else if (isLowerHexDigit(cp)) {
  4070. this.crCode = 16 * this.crCode + (cp - 0x57);
  4071. }
  4072. else {
  4073. if (cp === SEMICOLON) {
  4074. return "NUMERIC_CHARACTER_REFERENCE_END";
  4075. }
  4076. this.reportParseError("missing-semicolon-after-character-reference");
  4077. return this.reconsumeAs("NUMERIC_CHARACTER_REFERENCE_END");
  4078. }
  4079. cp = this.consumeNextCodePoint();
  4080. }
  4081. }
  4082. DECIMAL_CHARACTER_REFERENCE(cp) {
  4083. while (true) {
  4084. if (isDigit(cp)) {
  4085. this.crCode = 10 * this.crCode + (cp - 0x30);
  4086. }
  4087. else {
  4088. if (cp === SEMICOLON) {
  4089. return "NUMERIC_CHARACTER_REFERENCE_END";
  4090. }
  4091. this.reportParseError("missing-semicolon-after-character-reference");
  4092. return this.reconsumeAs("NUMERIC_CHARACTER_REFERENCE_END");
  4093. }
  4094. cp = this.consumeNextCodePoint();
  4095. }
  4096. }
  4097. NUMERIC_CHARACTER_REFERENCE_END(_cp) {
  4098. let code = this.crCode;
  4099. if (code === 0) {
  4100. this.reportParseError("null-character-reference");
  4101. code = NULL_REPLACEMENT;
  4102. }
  4103. else if (code > 0x10ffff) {
  4104. this.reportParseError("character-reference-outside-unicode-range");
  4105. code = NULL_REPLACEMENT;
  4106. }
  4107. else if (isSurrogate(code)) {
  4108. this.reportParseError("surrogate-character-reference");
  4109. code = NULL_REPLACEMENT;
  4110. }
  4111. else if (isNonCharacter(code)) {
  4112. this.reportParseError("noncharacter-character-reference");
  4113. }
  4114. else if (code === 0x0d || (isControl(code) && !isWhitespace(code))) {
  4115. this.reportParseError("control-character-reference");
  4116. code = alternativeCR.get(code) || code;
  4117. }
  4118. this.buffer = [code];
  4119. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  4120. }
  4121. CHARACTER_REFERENCE_END(_cp) {
  4122. assert__default["default"](this.currentToken != null);
  4123. const token = this.currentToken;
  4124. const len0 = token.value.length;
  4125. for (const cp1 of this.buffer) {
  4126. this.appendTokenValue(cp1, null);
  4127. }
  4128. const newLength = token.value.length - len0;
  4129. for (let i = this.crStartOffset + newLength; i < this.offset; ++i) {
  4130. this.gaps.push(i);
  4131. }
  4132. return this.reconsumeAs(this.returnState);
  4133. }
  4134. V_EXPRESSION_START(cp) {
  4135. var _a, _b;
  4136. if (cp === LEFT_CURLY_BRACKET) {
  4137. this.startToken("VExpressionStart");
  4138. this.appendTokenValue(LEFT_CURLY_BRACKET, null);
  4139. this.appendTokenValue(LEFT_CURLY_BRACKET, null);
  4140. if (!((_b = (_a = this.parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.interpolationAsNonHTML) !== null && _b !== void 0 ? _b : true)) {
  4141. return this.returnState;
  4142. }
  4143. const closeIndex = this.text.indexOf("}}", this.offset + 1);
  4144. if (closeIndex === -1) {
  4145. this.reportParseError("x-missing-interpolation-end");
  4146. return this.returnState;
  4147. }
  4148. this.vExpressionScriptState = {
  4149. state: this.returnState,
  4150. };
  4151. return "V_EXPRESSION_DATA";
  4152. }
  4153. this.appendTokenValue(LEFT_CURLY_BRACKET, null);
  4154. return this.reconsumeAs(this.returnState);
  4155. }
  4156. V_EXPRESSION_DATA(cp) {
  4157. this.clearStartTokenMark();
  4158. const state = this.vExpressionScriptState.state;
  4159. while (true) {
  4160. const type = isWhitespace(cp)
  4161. ? "HTMLWhitespace"
  4162. : state === "RCDATA"
  4163. ? "HTMLRawText"
  4164. : state === "RAWTEXT"
  4165. ? "HTMLRCDataText"
  4166. : "HTMLText";
  4167. if (this.currentToken != null && this.currentToken.type !== type) {
  4168. this.endToken();
  4169. return this.reconsumeAs(this.state);
  4170. }
  4171. if (this.currentToken == null) {
  4172. this.startToken(type);
  4173. }
  4174. if (cp === AMPERSAND && state !== "RAWTEXT") {
  4175. this.returnState = "V_EXPRESSION_DATA";
  4176. return "CHARACTER_REFERENCE";
  4177. }
  4178. if (cp === RIGHT_CURLY_BRACKET) {
  4179. this.setStartTokenMark();
  4180. this.returnState = "V_EXPRESSION_DATA";
  4181. return "V_EXPRESSION_END";
  4182. }
  4183. if (cp === EOF) {
  4184. this.reportParseError("x-missing-interpolation-end");
  4185. return "DATA";
  4186. }
  4187. if (cp === NULL) {
  4188. this.reportParseError("unexpected-null-character");
  4189. }
  4190. this.appendTokenValue(cp, type);
  4191. cp = this.consumeNextCodePoint();
  4192. }
  4193. }
  4194. V_EXPRESSION_END(cp) {
  4195. if (cp === RIGHT_CURLY_BRACKET) {
  4196. this.startToken("VExpressionEnd");
  4197. this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
  4198. this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
  4199. return this.vExpressionScriptState
  4200. ? this.vExpressionScriptState.state
  4201. : this.returnState;
  4202. }
  4203. this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
  4204. return this.reconsumeAs(this.returnState);
  4205. }
  4206. }
  4207. function getPossibleTypes(parsedSelector) {
  4208. switch (parsedSelector.type) {
  4209. case "identifier":
  4210. return [parsedSelector.value];
  4211. case "matches": {
  4212. const typesForComponents = parsedSelector.selectors.map(getPossibleTypes);
  4213. if (typesForComponents.every(Boolean)) {
  4214. return union__default["default"](...typesForComponents);
  4215. }
  4216. return null;
  4217. }
  4218. case "compound": {
  4219. const typesForComponents = parsedSelector.selectors.map(getPossibleTypes).filter(Boolean);
  4220. if (!typesForComponents.length) {
  4221. return null;
  4222. }
  4223. return intersection__default["default"](...typesForComponents);
  4224. }
  4225. case "child":
  4226. case "descendant":
  4227. case "sibling":
  4228. case "adjacent":
  4229. return getPossibleTypes(parsedSelector.right);
  4230. default:
  4231. return null;
  4232. }
  4233. }
  4234. function countClassAttributes(parsedSelector) {
  4235. switch (parsedSelector.type) {
  4236. case "child":
  4237. case "descendant":
  4238. case "sibling":
  4239. case "adjacent":
  4240. return countClassAttributes(parsedSelector.left) + countClassAttributes(parsedSelector.right);
  4241. case "compound":
  4242. case "not":
  4243. case "matches":
  4244. return parsedSelector.selectors.reduce((sum, childSelector) => sum + countClassAttributes(childSelector), 0);
  4245. case "attribute":
  4246. case "field":
  4247. case "nth-child":
  4248. case "nth-last-child":
  4249. return 1;
  4250. default:
  4251. return 0;
  4252. }
  4253. }
  4254. function countIdentifiers(parsedSelector) {
  4255. switch (parsedSelector.type) {
  4256. case "child":
  4257. case "descendant":
  4258. case "sibling":
  4259. case "adjacent":
  4260. return countIdentifiers(parsedSelector.left) + countIdentifiers(parsedSelector.right);
  4261. case "compound":
  4262. case "not":
  4263. case "matches":
  4264. return parsedSelector.selectors.reduce((sum, childSelector) => sum + countIdentifiers(childSelector), 0);
  4265. case "identifier":
  4266. return 1;
  4267. default:
  4268. return 0;
  4269. }
  4270. }
  4271. function compareSpecificity(selectorA, selectorB) {
  4272. return selectorA.attributeCount - selectorB.attributeCount ||
  4273. selectorA.identifierCount - selectorB.identifierCount ||
  4274. (selectorA.rawSelector <= selectorB.rawSelector ? -1 : 1);
  4275. }
  4276. function tryParseSelector(rawSelector) {
  4277. try {
  4278. return esquery__default["default"].parse(rawSelector.replace(/:exit$/, ""));
  4279. }
  4280. catch (err) {
  4281. if (typeof err.offset === "number") {
  4282. throw new Error(`Syntax error in selector "${rawSelector}" at position ${err.offset}: ${err.message}`);
  4283. }
  4284. throw err;
  4285. }
  4286. }
  4287. const parseSelector = memoize__default["default"](rawSelector => {
  4288. const parsedSelector = tryParseSelector(rawSelector);
  4289. return {
  4290. rawSelector,
  4291. isExit: rawSelector.endsWith(":exit"),
  4292. parsedSelector,
  4293. listenerTypes: getPossibleTypes(parsedSelector),
  4294. attributeCount: countClassAttributes(parsedSelector),
  4295. identifierCount: countIdentifiers(parsedSelector),
  4296. };
  4297. });
  4298. class NodeEventGenerator {
  4299. constructor(emitter, esqueryOptions) {
  4300. this.emitter = emitter;
  4301. this.esqueryOptions = esqueryOptions;
  4302. this.currentAncestry = [];
  4303. this.enterSelectorsByNodeType = new Map();
  4304. this.exitSelectorsByNodeType = new Map();
  4305. this.anyTypeEnterSelectors = [];
  4306. this.anyTypeExitSelectors = [];
  4307. const eventNames = typeof emitter.eventNames === "function"
  4308. ? emitter.eventNames()
  4309. : Object.keys(emitter._events);
  4310. for (const rawSelector of eventNames) {
  4311. if (typeof rawSelector === "symbol") {
  4312. continue;
  4313. }
  4314. const selector = parseSelector(rawSelector);
  4315. if (selector.listenerTypes) {
  4316. for (const nodeType of selector.listenerTypes) {
  4317. const typeMap = selector.isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType;
  4318. let selectors = typeMap.get(nodeType);
  4319. if (selectors == null) {
  4320. typeMap.set(nodeType, (selectors = []));
  4321. }
  4322. selectors.push(selector);
  4323. }
  4324. }
  4325. else {
  4326. (selector.isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors).push(selector);
  4327. }
  4328. }
  4329. this.anyTypeEnterSelectors.sort(compareSpecificity);
  4330. this.anyTypeExitSelectors.sort(compareSpecificity);
  4331. for (const selectorList of this.enterSelectorsByNodeType.values()) {
  4332. selectorList.sort(compareSpecificity);
  4333. }
  4334. for (const selectorList of this.exitSelectorsByNodeType.values()) {
  4335. selectorList.sort(compareSpecificity);
  4336. }
  4337. }
  4338. applySelector(node, selector) {
  4339. if (esquery__default["default"].matches(node, selector.parsedSelector, this.currentAncestry, this.esqueryOptions)) {
  4340. this.emitter.emit(selector.rawSelector, node);
  4341. }
  4342. }
  4343. applySelectors(node, isExit) {
  4344. const selectorsByNodeType = (isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType).get(node.type) || [];
  4345. const anyTypeSelectors = isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors;
  4346. let selectorsByTypeIndex = 0;
  4347. let anyTypeSelectorsIndex = 0;
  4348. while (selectorsByTypeIndex < selectorsByNodeType.length || anyTypeSelectorsIndex < anyTypeSelectors.length) {
  4349. if (selectorsByTypeIndex >= selectorsByNodeType.length ||
  4350. (anyTypeSelectorsIndex < anyTypeSelectors.length && compareSpecificity(anyTypeSelectors[anyTypeSelectorsIndex], selectorsByNodeType[selectorsByTypeIndex]) < 0)) {
  4351. this.applySelector(node, anyTypeSelectors[anyTypeSelectorsIndex++]);
  4352. }
  4353. else {
  4354. this.applySelector(node, selectorsByNodeType[selectorsByTypeIndex++]);
  4355. }
  4356. }
  4357. }
  4358. enterNode(node) {
  4359. if (node.parent) {
  4360. this.currentAncestry.unshift(node.parent);
  4361. }
  4362. this.applySelectors(node, false);
  4363. }
  4364. leaveNode(node) {
  4365. this.applySelectors(node, true);
  4366. this.currentAncestry.shift();
  4367. }
  4368. }
  4369. function getStartLocation(token) {
  4370. return token.range[0];
  4371. }
  4372. function search(tokens, location) {
  4373. return sortedIndexBy__default["default"](tokens, { range: [location] }, getStartLocation);
  4374. }
  4375. function getFirstIndex(tokens, indexMap, startLoc) {
  4376. if (startLoc in indexMap) {
  4377. return indexMap[startLoc];
  4378. }
  4379. if ((startLoc - 1) in indexMap) {
  4380. const index = indexMap[startLoc - 1];
  4381. const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
  4382. if (token && token.range[0] >= startLoc) {
  4383. return index;
  4384. }
  4385. return index + 1;
  4386. }
  4387. return 0;
  4388. }
  4389. function getLastIndex(tokens, indexMap, endLoc) {
  4390. if (endLoc in indexMap) {
  4391. return indexMap[endLoc] - 1;
  4392. }
  4393. if ((endLoc - 1) in indexMap) {
  4394. const index = indexMap[endLoc - 1];
  4395. const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
  4396. if (token && token.range[1] > endLoc) {
  4397. return index - 1;
  4398. }
  4399. return index;
  4400. }
  4401. return tokens.length - 1;
  4402. }
  4403. class Cursor {
  4404. constructor() {
  4405. this.current = null;
  4406. }
  4407. getOneToken() {
  4408. return this.moveNext() ? this.current : null;
  4409. }
  4410. getAllTokens() {
  4411. const tokens = [];
  4412. while (this.moveNext()) {
  4413. tokens.push(this.current);
  4414. }
  4415. return tokens;
  4416. }
  4417. }
  4418. class BackwardTokenCommentCursor extends Cursor {
  4419. constructor(tokens, comments, indexMap, startLoc, endLoc) {
  4420. super();
  4421. this.tokens = tokens;
  4422. this.comments = comments;
  4423. this.tokenIndex = getLastIndex(tokens, indexMap, endLoc);
  4424. this.commentIndex = search(comments, endLoc) - 1;
  4425. this.border = startLoc;
  4426. }
  4427. moveNext() {
  4428. const token = (this.tokenIndex >= 0) ? this.tokens[this.tokenIndex] : null;
  4429. const comment = (this.commentIndex >= 0) ? this.comments[this.commentIndex] : null;
  4430. if (token && (!comment || token.range[1] > comment.range[1])) {
  4431. this.current = token;
  4432. this.tokenIndex -= 1;
  4433. }
  4434. else if (comment) {
  4435. this.current = comment;
  4436. this.commentIndex -= 1;
  4437. }
  4438. else {
  4439. this.current = null;
  4440. }
  4441. return this.current != null && (this.border === -1 || this.current.range[0] >= this.border);
  4442. }
  4443. }
  4444. class BackwardTokenCursor extends Cursor {
  4445. constructor(tokens, _comments, indexMap, startLoc, endLoc) {
  4446. super();
  4447. this.tokens = tokens;
  4448. this.index = getLastIndex(tokens, indexMap, endLoc);
  4449. this.indexEnd = getFirstIndex(tokens, indexMap, startLoc);
  4450. }
  4451. moveNext() {
  4452. if (this.index >= this.indexEnd) {
  4453. this.current = this.tokens[this.index];
  4454. this.index -= 1;
  4455. return true;
  4456. }
  4457. return false;
  4458. }
  4459. getOneToken() {
  4460. return (this.index >= this.indexEnd) ? this.tokens[this.index] : null;
  4461. }
  4462. }
  4463. class DecorativeCursor extends Cursor {
  4464. constructor(cursor) {
  4465. super();
  4466. this.cursor = cursor;
  4467. }
  4468. moveNext() {
  4469. const retv = this.cursor.moveNext();
  4470. this.current = this.cursor.current;
  4471. return retv;
  4472. }
  4473. }
  4474. class FilterCursor extends DecorativeCursor {
  4475. constructor(cursor, predicate) {
  4476. super(cursor);
  4477. this.predicate = predicate;
  4478. }
  4479. moveNext() {
  4480. const predicate = this.predicate;
  4481. while (super.moveNext()) {
  4482. if (predicate(this.current)) {
  4483. return true;
  4484. }
  4485. }
  4486. return false;
  4487. }
  4488. }
  4489. class ForwardTokenCommentCursor extends Cursor {
  4490. constructor(tokens, comments, indexMap, startLoc, endLoc) {
  4491. super();
  4492. this.tokens = tokens;
  4493. this.comments = comments;
  4494. this.tokenIndex = getFirstIndex(tokens, indexMap, startLoc);
  4495. this.commentIndex = search(comments, startLoc);
  4496. this.border = endLoc;
  4497. }
  4498. moveNext() {
  4499. const token = (this.tokenIndex < this.tokens.length) ? this.tokens[this.tokenIndex] : null;
  4500. const comment = (this.commentIndex < this.comments.length) ? this.comments[this.commentIndex] : null;
  4501. if (token && (!comment || token.range[0] < comment.range[0])) {
  4502. this.current = token;
  4503. this.tokenIndex += 1;
  4504. }
  4505. else if (comment) {
  4506. this.current = comment;
  4507. this.commentIndex += 1;
  4508. }
  4509. else {
  4510. this.current = null;
  4511. }
  4512. return this.current != null && (this.border === -1 || this.current.range[1] <= this.border);
  4513. }
  4514. }
  4515. class ForwardTokenCursor extends Cursor {
  4516. constructor(tokens, _comments, indexMap, startLoc, endLoc) {
  4517. super();
  4518. this.tokens = tokens;
  4519. this.index = getFirstIndex(tokens, indexMap, startLoc);
  4520. this.indexEnd = getLastIndex(tokens, indexMap, endLoc);
  4521. }
  4522. moveNext() {
  4523. if (this.index <= this.indexEnd) {
  4524. this.current = this.tokens[this.index];
  4525. this.index += 1;
  4526. return true;
  4527. }
  4528. return false;
  4529. }
  4530. getOneToken() {
  4531. return (this.index <= this.indexEnd) ? this.tokens[this.index] : null;
  4532. }
  4533. getAllTokens() {
  4534. return this.tokens.slice(this.index, this.indexEnd + 1);
  4535. }
  4536. }
  4537. class LimitCursor extends DecorativeCursor {
  4538. constructor(cursor, count) {
  4539. super(cursor);
  4540. this.count = count;
  4541. }
  4542. moveNext() {
  4543. if (this.count > 0) {
  4544. this.count -= 1;
  4545. return super.moveNext();
  4546. }
  4547. return false;
  4548. }
  4549. }
  4550. class SkipCursor extends DecorativeCursor {
  4551. constructor(cursor, count) {
  4552. super(cursor);
  4553. this.count = count;
  4554. }
  4555. moveNext() {
  4556. while (this.count > 0) {
  4557. this.count -= 1;
  4558. if (!super.moveNext()) {
  4559. return false;
  4560. }
  4561. }
  4562. return super.moveNext();
  4563. }
  4564. }
  4565. class CursorFactory {
  4566. constructor(TokenCursor, TokenCommentCursor) {
  4567. this.TokenCursor = TokenCursor;
  4568. this.TokenCommentCursor = TokenCommentCursor;
  4569. }
  4570. createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments) {
  4571. const TokenCursor = includeComments ? this.TokenCommentCursor : this.TokenCursor;
  4572. return new TokenCursor(tokens, comments, indexMap, startLoc, endLoc);
  4573. }
  4574. createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, count) {
  4575. let cursor = this.createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments);
  4576. if (filter) {
  4577. cursor = new FilterCursor(cursor, filter);
  4578. }
  4579. if (skip >= 1) {
  4580. cursor = new SkipCursor(cursor, skip);
  4581. }
  4582. if (count >= 0) {
  4583. cursor = new LimitCursor(cursor, count);
  4584. }
  4585. return cursor;
  4586. }
  4587. }
  4588. const forward = new CursorFactory(ForwardTokenCursor, ForwardTokenCommentCursor);
  4589. const backward = new CursorFactory(BackwardTokenCursor, BackwardTokenCommentCursor);
  4590. class PaddedTokenCursor extends ForwardTokenCursor {
  4591. constructor(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
  4592. super(tokens, comments, indexMap, startLoc, endLoc);
  4593. this.index = Math.max(0, this.index - beforeCount);
  4594. this.indexEnd = Math.min(tokens.length - 1, this.indexEnd + afterCount);
  4595. }
  4596. }
  4597. function isCommentToken(token) {
  4598. return token.type === "Line" || token.type === "Block" || token.type === "Shebang";
  4599. }
  4600. function createIndexMap(tokens, comments) {
  4601. const map = Object.create(null);
  4602. let tokenIndex = 0;
  4603. let commentIndex = 0;
  4604. let nextStart = 0;
  4605. let range = null;
  4606. while (tokenIndex < tokens.length || commentIndex < comments.length) {
  4607. nextStart = (commentIndex < comments.length) ? comments[commentIndex].range[0] : Number.MAX_SAFE_INTEGER;
  4608. while (tokenIndex < tokens.length && (range = tokens[tokenIndex].range)[0] < nextStart) {
  4609. map[range[0]] = tokenIndex;
  4610. map[range[1] - 1] = tokenIndex;
  4611. tokenIndex += 1;
  4612. }
  4613. nextStart = (tokenIndex < tokens.length) ? tokens[tokenIndex].range[0] : Number.MAX_SAFE_INTEGER;
  4614. while (commentIndex < comments.length && (range = comments[commentIndex].range)[0] < nextStart) {
  4615. map[range[0]] = tokenIndex;
  4616. map[range[1] - 1] = tokenIndex;
  4617. commentIndex += 1;
  4618. }
  4619. }
  4620. return map;
  4621. }
  4622. function createCursorWithSkip(factory, tokens, comments, indexMap, startLoc, endLoc, opts) {
  4623. let includeComments = false;
  4624. let skip = 0;
  4625. let filter = null;
  4626. if (typeof opts === "number") {
  4627. skip = opts | 0;
  4628. }
  4629. else if (typeof opts === "function") {
  4630. filter = opts;
  4631. }
  4632. else if (opts) {
  4633. includeComments = Boolean(opts.includeComments);
  4634. skip = opts.skip || 0;
  4635. filter = opts.filter || null;
  4636. }
  4637. assert__default["default"](skip >= 0, "options.skip should be zero or a positive integer.");
  4638. assert__default["default"](!filter || typeof filter === "function", "options.filter should be a function.");
  4639. return factory.createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, -1);
  4640. }
  4641. function createCursorWithCount(factory, tokens, comments, indexMap, startLoc, endLoc, opts) {
  4642. let includeComments = false;
  4643. let count = 0;
  4644. let countExists = false;
  4645. let filter = null;
  4646. if (typeof opts === "number") {
  4647. count = opts | 0;
  4648. countExists = true;
  4649. }
  4650. else if (typeof opts === "function") {
  4651. filter = opts;
  4652. }
  4653. else if (opts) {
  4654. includeComments = Boolean(opts.includeComments);
  4655. count = opts.count || 0;
  4656. countExists = typeof opts.count === "number";
  4657. filter = opts.filter || null;
  4658. }
  4659. assert__default["default"](count >= 0, "options.count should be zero or a positive integer.");
  4660. assert__default["default"](!filter || typeof filter === "function", "options.filter should be a function.");
  4661. return factory.createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, 0, countExists ? count : -1);
  4662. }
  4663. function createCursorWithPadding(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
  4664. if (typeof beforeCount === "undefined" && typeof afterCount === "undefined") {
  4665. return new ForwardTokenCursor(tokens, comments, indexMap, startLoc, endLoc);
  4666. }
  4667. if (typeof beforeCount === "number" || typeof beforeCount === "undefined") {
  4668. return new PaddedTokenCursor(tokens, comments, indexMap, startLoc, endLoc, beforeCount || 0, afterCount || 0);
  4669. }
  4670. return createCursorWithCount(forward, tokens, comments, indexMap, startLoc, endLoc, beforeCount);
  4671. }
  4672. function getAdjacentCommentTokensFromCursor(cursor) {
  4673. const tokens = [];
  4674. let currentToken = cursor.getOneToken();
  4675. while (currentToken && isCommentToken(currentToken)) {
  4676. tokens.push(currentToken);
  4677. currentToken = cursor.getOneToken();
  4678. }
  4679. return tokens;
  4680. }
  4681. class TokenStore {
  4682. constructor(tokens, comments) {
  4683. this._tokens = tokens;
  4684. this._comments = comments;
  4685. this._indexMap = createIndexMap(tokens, comments);
  4686. }
  4687. getTokenByRangeStart(offset, options) {
  4688. const includeComments = Boolean(options && options.includeComments);
  4689. const token = forward.createBaseCursor(this._tokens, this._comments, this._indexMap, offset, -1, includeComments).getOneToken();
  4690. if (token && token.range[0] === offset) {
  4691. return token;
  4692. }
  4693. return null;
  4694. }
  4695. getFirstToken(node, options) {
  4696. return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getOneToken();
  4697. }
  4698. getLastToken(node, options) {
  4699. return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getOneToken();
  4700. }
  4701. getTokenBefore(node, options) {
  4702. return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, -1, node.range[0], options).getOneToken();
  4703. }
  4704. getTokenAfter(node, options) {
  4705. return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, node.range[1], -1, options).getOneToken();
  4706. }
  4707. getFirstTokenBetween(left, right, options) {
  4708. return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getOneToken();
  4709. }
  4710. getLastTokenBetween(left, right, options) {
  4711. return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getOneToken();
  4712. }
  4713. getTokenOrCommentBefore(node, skip) {
  4714. return this.getTokenBefore(node, { includeComments: true, skip });
  4715. }
  4716. getTokenOrCommentAfter(node, skip) {
  4717. return this.getTokenAfter(node, { includeComments: true, skip });
  4718. }
  4719. getFirstTokens(node, options) {
  4720. return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getAllTokens();
  4721. }
  4722. getLastTokens(node, options) {
  4723. return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getAllTokens().reverse();
  4724. }
  4725. getTokensBefore(node, options) {
  4726. return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, -1, node.range[0], options).getAllTokens().reverse();
  4727. }
  4728. getTokensAfter(node, options) {
  4729. return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, node.range[1], -1, options).getAllTokens();
  4730. }
  4731. getFirstTokensBetween(left, right, options) {
  4732. return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getAllTokens();
  4733. }
  4734. getLastTokensBetween(left, right, options) {
  4735. return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getAllTokens().reverse();
  4736. }
  4737. getTokens(node, beforeCount, afterCount) {
  4738. return createCursorWithPadding(this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], beforeCount, afterCount).getAllTokens();
  4739. }
  4740. getTokensBetween(left, right, padding) {
  4741. return createCursorWithPadding(this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], padding, typeof padding === "number" ? padding : undefined).getAllTokens();
  4742. }
  4743. commentsExistBetween(left, right) {
  4744. const index = search(this._comments, left.range[1]);
  4745. return (index < this._comments.length &&
  4746. this._comments[index].range[1] <= right.range[0]);
  4747. }
  4748. getCommentsBefore(nodeOrToken) {
  4749. const cursor = createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, -1, nodeOrToken.range[0], { includeComments: true });
  4750. return getAdjacentCommentTokensFromCursor(cursor).reverse();
  4751. }
  4752. getCommentsAfter(nodeOrToken) {
  4753. const cursor = createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, nodeOrToken.range[1], -1, { includeComments: true });
  4754. return getAdjacentCommentTokensFromCursor(cursor);
  4755. }
  4756. getCommentsInside(node) {
  4757. return this.getTokens(node, {
  4758. includeComments: true,
  4759. filter: isCommentToken,
  4760. });
  4761. }
  4762. }
  4763. function isVElement(node) {
  4764. return node.type === "VElement";
  4765. }
  4766. function getCustomBlocks(document) {
  4767. return document
  4768. ? document.children
  4769. .filter(isVElement)
  4770. .filter((block) => block.name !== "script" &&
  4771. block.name !== "template" &&
  4772. block.name !== "style")
  4773. : [];
  4774. }
  4775. function parseCustomBlockElement(node, parser, globalLocationCalculator, parserOptions) {
  4776. const text = node.children[0];
  4777. const { code, range, loc } = text != null && text.type === "VText"
  4778. ? {
  4779. code: text.value,
  4780. range: text.range,
  4781. loc: text.loc,
  4782. }
  4783. : {
  4784. code: "",
  4785. range: [
  4786. node.startTag.range[1],
  4787. node.endTag.range[0],
  4788. ],
  4789. loc: {
  4790. start: node.startTag.loc.end,
  4791. end: node.endTag.loc.start,
  4792. },
  4793. };
  4794. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(range[0]);
  4795. try {
  4796. return parseCustomBlockFragment(code, parser, locationCalculator, parserOptions);
  4797. }
  4798. catch (e) {
  4799. if (!(e instanceof Error)) {
  4800. throw e;
  4801. }
  4802. return {
  4803. error: e,
  4804. ast: {
  4805. type: "Program",
  4806. sourceType: "module",
  4807. loc: {
  4808. start: Object.assign({}, loc.start),
  4809. end: Object.assign({}, loc.end),
  4810. },
  4811. range: [...range],
  4812. body: [],
  4813. tokens: [],
  4814. comments: [],
  4815. },
  4816. };
  4817. }
  4818. }
  4819. function parseCustomBlockFragment(code, parser, locationCalculator, parserOptions) {
  4820. try {
  4821. const result = parseBlock(code, parser, Object.assign({ ecmaVersion: DEFAULT_ECMA_VERSION, loc: true, range: true, raw: true, tokens: true, comment: true, eslintVisitorKeys: true, eslintScopeManager: true }, parserOptions));
  4822. fixLocations(result, locationCalculator);
  4823. return result;
  4824. }
  4825. catch (err) {
  4826. const perr = ParseError.normalize(err);
  4827. if (perr) {
  4828. fixErrorLocation(perr, locationCalculator);
  4829. throw perr;
  4830. }
  4831. throw err;
  4832. }
  4833. }
  4834. function parseBlock(code, parser, parserOptions) {
  4835. const result = isEnhancedParserObject(parser)
  4836. ? parser.parseForESLint(code, parserOptions)
  4837. : parser.parse(code, parserOptions);
  4838. if (result.ast != null) {
  4839. return result;
  4840. }
  4841. return { ast: result };
  4842. }
  4843. function createCustomBlockSharedContext({ text, customBlock, parsedResult, globalLocationCalculator, parserOptions, }) {
  4844. let sourceCode;
  4845. let currentNode;
  4846. return {
  4847. serCurrentNode(node) {
  4848. currentNode = node;
  4849. },
  4850. context: {
  4851. getAncestors: () => getSourceCode().getAncestors(currentNode),
  4852. getDeclaredVariables: (...args) => getSourceCode().getDeclaredVariables(...args),
  4853. getScope: () => getSourceCode().getScope(currentNode),
  4854. markVariableAsUsed: (name) => getSourceCode().markVariableAsUsed(name, currentNode),
  4855. get parserServices() {
  4856. return getSourceCode().parserServices;
  4857. },
  4858. getSourceCode,
  4859. get sourceCode() {
  4860. return getSourceCode();
  4861. },
  4862. },
  4863. };
  4864. function getSourceCode() {
  4865. if (sourceCode) {
  4866. return sourceCode;
  4867. }
  4868. const scopeManager = getScopeManager();
  4869. const originalSourceCode = new (require("eslint").SourceCode)({
  4870. text,
  4871. ast: parsedResult.ast,
  4872. parserServices: Object.assign(Object.assign({ customBlock,
  4873. parseCustomBlockElement(parser, options) {
  4874. return parseCustomBlockElement(customBlock, parser, globalLocationCalculator, Object.assign(Object.assign({}, parserOptions), options));
  4875. } }, (parsedResult.services || {})), (parsedResult.error
  4876. ? { parseError: parsedResult.error }
  4877. : {})),
  4878. scopeManager,
  4879. visitorKeys: parsedResult.visitorKeys,
  4880. });
  4881. const polyfills = {
  4882. markVariableAsUsed: (name, node) => markVariableAsUsed(scopeManager, node, parsedResult.ast, name),
  4883. getScope: (node) => getScope(scopeManager, node),
  4884. getAncestors: (node) => getAncestors(node),
  4885. getDeclaredVariables: (...args) => scopeManager.getDeclaredVariables(...args),
  4886. };
  4887. return (sourceCode = new Proxy(originalSourceCode, {
  4888. get(_target, prop) {
  4889. return originalSourceCode[prop] || polyfills[prop];
  4890. },
  4891. }));
  4892. }
  4893. function getScopeManager() {
  4894. if (parsedResult.scopeManager) {
  4895. return parsedResult.scopeManager;
  4896. }
  4897. const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022;
  4898. const ecmaFeatures = parserOptions.ecmaFeatures || {};
  4899. const sourceType = parserOptions.sourceType || "script";
  4900. return getEslintScope().analyze(parsedResult.ast, {
  4901. ignoreEval: true,
  4902. nodejsScope: false,
  4903. impliedStrict: ecmaFeatures.impliedStrict,
  4904. ecmaVersion,
  4905. sourceType,
  4906. fallback: getFallbackKeys,
  4907. });
  4908. }
  4909. }
  4910. function getAncestors(node) {
  4911. const ancestorsStartingAtParent = [];
  4912. for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
  4913. ancestorsStartingAtParent.push(ancestor);
  4914. }
  4915. return ancestorsStartingAtParent.reverse();
  4916. }
  4917. function getScope(scopeManager, currentNode) {
  4918. const inner = currentNode.type !== "Program";
  4919. for (let node = currentNode; node; node = node.parent || null) {
  4920. const scope = scopeManager.acquire(node, inner);
  4921. if (scope) {
  4922. if (scope.type === "function-expression-name") {
  4923. return scope.childScopes[0];
  4924. }
  4925. return scope;
  4926. }
  4927. }
  4928. return scopeManager.scopes[0];
  4929. }
  4930. function markVariableAsUsed(scopeManager, currentNode, program, name) {
  4931. const currentScope = getScope(scopeManager, currentNode);
  4932. let initialScope = currentScope;
  4933. if (currentScope.type === "global" &&
  4934. currentScope.childScopes.length > 0 &&
  4935. currentScope.childScopes[0].block === program) {
  4936. initialScope = currentScope.childScopes[0];
  4937. }
  4938. for (let scope = initialScope; scope; scope = scope.upper) {
  4939. const variable = scope.variables.find((scopeVar) => scopeVar.name === name);
  4940. if (variable) {
  4941. variable.eslintUsed = true;
  4942. return true;
  4943. }
  4944. }
  4945. return false;
  4946. }
  4947. function define(sourceText, rootAST, document, globalLocationCalculator, { parserOptions }) {
  4948. const templateBodyEmitters = new Map();
  4949. const stores = new WeakMap();
  4950. const documentEmitters = new Map();
  4951. const customBlocksEmitters = new Map();
  4952. const isSFC = isSFCFile(parserOptions);
  4953. return {
  4954. defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor, options) {
  4955. var _a;
  4956. if (scriptVisitor == null) {
  4957. scriptVisitor = {};
  4958. }
  4959. if (rootAST.templateBody == null) {
  4960. return scriptVisitor;
  4961. }
  4962. const templateBodyTriggerSelector = (_a = options === null || options === void 0 ? void 0 : options.templateBodyTriggerSelector) !== null && _a !== void 0 ? _a : "Program:exit";
  4963. let emitter = templateBodyEmitters.get(templateBodyTriggerSelector);
  4964. if (emitter == null) {
  4965. emitter = new EventEmitter__default["default"]();
  4966. emitter.setMaxListeners(0);
  4967. templateBodyEmitters.set(templateBodyTriggerSelector, emitter);
  4968. const programExitHandler = scriptVisitor[templateBodyTriggerSelector];
  4969. scriptVisitor[templateBodyTriggerSelector] = (node) => {
  4970. try {
  4971. if (typeof programExitHandler === "function") {
  4972. programExitHandler(node);
  4973. }
  4974. const generator = new NodeEventGenerator(emitter, {
  4975. visitorKeys: KEYS,
  4976. fallback: getFallbackKeys,
  4977. });
  4978. traverseNodes(rootAST.templateBody, generator);
  4979. }
  4980. finally {
  4981. scriptVisitor[templateBodyTriggerSelector] =
  4982. programExitHandler;
  4983. templateBodyEmitters.delete(templateBodyTriggerSelector);
  4984. }
  4985. };
  4986. }
  4987. for (const selector of Object.keys(templateBodyVisitor)) {
  4988. emitter.on(selector, templateBodyVisitor[selector]);
  4989. }
  4990. return scriptVisitor;
  4991. },
  4992. defineDocumentVisitor(documentVisitor, options) {
  4993. var _a;
  4994. const scriptVisitor = {};
  4995. if (!document) {
  4996. return scriptVisitor;
  4997. }
  4998. const documentTriggerSelector = (_a = options === null || options === void 0 ? void 0 : options.triggerSelector) !== null && _a !== void 0 ? _a : "Program:exit";
  4999. let emitter = documentEmitters.get(documentTriggerSelector);
  5000. if (emitter == null) {
  5001. emitter = new EventEmitter__default["default"]();
  5002. emitter.setMaxListeners(0);
  5003. documentEmitters.set(documentTriggerSelector, emitter);
  5004. const programExitHandler = scriptVisitor[documentTriggerSelector];
  5005. scriptVisitor[documentTriggerSelector] = (node) => {
  5006. try {
  5007. if (typeof programExitHandler === "function") {
  5008. programExitHandler(node);
  5009. }
  5010. const generator = new NodeEventGenerator(emitter, {
  5011. visitorKeys: KEYS,
  5012. fallback: getFallbackKeys,
  5013. });
  5014. traverseNodes(document, generator);
  5015. }
  5016. finally {
  5017. scriptVisitor[documentTriggerSelector] =
  5018. programExitHandler;
  5019. documentEmitters.delete(documentTriggerSelector);
  5020. }
  5021. };
  5022. }
  5023. for (const selector of Object.keys(documentVisitor)) {
  5024. emitter.on(selector, documentVisitor[selector]);
  5025. }
  5026. return scriptVisitor;
  5027. },
  5028. defineCustomBlocksVisitor(context, parser, rule, scriptVisitor) {
  5029. var _a;
  5030. if (scriptVisitor == null) {
  5031. scriptVisitor = {};
  5032. }
  5033. if (!isSFC) {
  5034. return scriptVisitor;
  5035. }
  5036. parserOptions = Object.assign({}, parserOptions);
  5037. const customBlocks = getCustomBlocks(document).filter((block) => block.endTag &&
  5038. !block.startTag.attributes.some((attr) => !attr.directive && attr.key.name === "src"));
  5039. if (!customBlocks.length || globalLocationCalculator == null) {
  5040. return {};
  5041. }
  5042. const key = (_a = parser.parseForESLint) !== null && _a !== void 0 ? _a : parser.parse;
  5043. let factories = customBlocksEmitters.get(key);
  5044. if (factories == null) {
  5045. factories = [];
  5046. customBlocksEmitters.set(key, factories);
  5047. const visitorFactories = factories;
  5048. const programExitHandler = scriptVisitor["Program:exit"];
  5049. scriptVisitor["Program:exit"] = (node) => {
  5050. try {
  5051. if (typeof programExitHandler === "function") {
  5052. programExitHandler(node);
  5053. }
  5054. for (const customBlock of customBlocks) {
  5055. const lang = getLang(customBlock);
  5056. const activeVisitorFactories = visitorFactories.filter((f) => f.test(lang, customBlock));
  5057. if (!activeVisitorFactories.length) {
  5058. continue;
  5059. }
  5060. const parsedResult = parseCustomBlockElement(customBlock, parser, globalLocationCalculator, parserOptions);
  5061. const { serCurrentNode, context: customBlockContext, } = createCustomBlockSharedContext({
  5062. text: sourceText,
  5063. customBlock,
  5064. parsedResult,
  5065. globalLocationCalculator,
  5066. parserOptions,
  5067. });
  5068. const emitter = new EventEmitter__default["default"]();
  5069. emitter.setMaxListeners(0);
  5070. for (const factory of activeVisitorFactories) {
  5071. const ctx = Object.assign({}, customBlockContext);
  5072. ctx.__proto__ = factory.context;
  5073. const visitor = factory.create(ctx);
  5074. for (const selector of Object.keys(visitor || {})) {
  5075. emitter.on(selector, visitor[selector]);
  5076. }
  5077. }
  5078. const generator = new NodeEventGenerator(emitter, {
  5079. visitorKeys: parsedResult.visitorKeys,
  5080. fallback: getFallbackKeys,
  5081. });
  5082. traverseNodes(parsedResult.ast, {
  5083. visitorKeys: parsedResult.visitorKeys,
  5084. enterNode(n) {
  5085. serCurrentNode(n);
  5086. generator.enterNode(n);
  5087. },
  5088. leaveNode(n) {
  5089. serCurrentNode(n);
  5090. generator.leaveNode(n);
  5091. },
  5092. });
  5093. }
  5094. }
  5095. finally {
  5096. scriptVisitor["Program:exit"] = programExitHandler;
  5097. customBlocksEmitters.delete(key);
  5098. }
  5099. };
  5100. }
  5101. const target = rule.target;
  5102. const test = typeof target === "function"
  5103. ? target
  5104. : Array.isArray(target)
  5105. ? (lang) => Boolean(lang && target.includes(lang))
  5106. : (lang) => target === lang;
  5107. factories.push({
  5108. context,
  5109. test,
  5110. create: rule.create,
  5111. });
  5112. return scriptVisitor;
  5113. },
  5114. getTemplateBodyTokenStore() {
  5115. const key = document || stores;
  5116. let store = stores.get(key);
  5117. if (!store) {
  5118. store =
  5119. document != null
  5120. ? new TokenStore(document.tokens, document.comments)
  5121. : new TokenStore([], []);
  5122. stores.set(key, store);
  5123. }
  5124. return store;
  5125. },
  5126. getDocumentFragment() {
  5127. return document;
  5128. },
  5129. };
  5130. }
  5131. class CodeBlocks {
  5132. constructor() {
  5133. this.remapBlocks = [];
  5134. this.splitPunctuators = [];
  5135. this.code = "";
  5136. }
  5137. get length() {
  5138. return this.code.length;
  5139. }
  5140. append(codeLet, originalOffset) {
  5141. const rangeStart = this.code.length;
  5142. this.code += codeLet.trimEnd();
  5143. this.remapBlocks.push({
  5144. range: [rangeStart, this.code.length],
  5145. offset: originalOffset - rangeStart,
  5146. });
  5147. }
  5148. appendSplitPunctuators(punctuator) {
  5149. this.splitPunctuators.push(this.code.length, this.code.length + 1);
  5150. this.code += `\n${punctuator}\n`;
  5151. }
  5152. appendCodeBlocks(codeBlocks) {
  5153. const start = this.code.length;
  5154. this.code += codeBlocks.code;
  5155. this.remapBlocks.push(...codeBlocks.remapBlocks.map((b) => ({
  5156. range: [b.range[0] + start, b.range[1] + start],
  5157. offset: b.offset - start,
  5158. })));
  5159. this.splitPunctuators.push(...codeBlocks.splitPunctuators.map((s) => s + start));
  5160. }
  5161. }
  5162. class RestoreASTCallbacks {
  5163. constructor() {
  5164. this.callbacks = [];
  5165. }
  5166. addCallback(originalOffsetStart, range, callback) {
  5167. this.callbacks.push({
  5168. range: [
  5169. originalOffsetStart + range[0],
  5170. originalOffsetStart + range[1],
  5171. ],
  5172. callback,
  5173. });
  5174. }
  5175. restore(program, scriptSetupStatements, linesAndColumns) {
  5176. if (this.callbacks.length === 0) {
  5177. return;
  5178. }
  5179. const callbacks = new Set(this.callbacks);
  5180. for (const statement of scriptSetupStatements) {
  5181. for (const cb of callbacks) {
  5182. if (cb.range[0] <= statement.range[0] &&
  5183. statement.range[1] <= cb.range[1]) {
  5184. const restored = cb.callback(statement);
  5185. if (restored) {
  5186. const removeIndex = program.body.indexOf(statement);
  5187. if (removeIndex >= 0) {
  5188. program.body.splice(removeIndex, 1);
  5189. program.body.push(restored.statement);
  5190. program.tokens.push(...restored.tokens);
  5191. restored.statement.parent = program;
  5192. callbacks.delete(cb);
  5193. break;
  5194. }
  5195. }
  5196. }
  5197. }
  5198. }
  5199. if (callbacks.size) {
  5200. const [cb] = callbacks;
  5201. const loc = linesAndColumns.getLocFromIndex(cb.range[0]);
  5202. throw new ParseError("Could not parse <script setup>. Failed to restore ExportNamedDeclaration.", undefined, cb.range[0], loc.line, loc.column);
  5203. }
  5204. }
  5205. }
  5206. function parseScript(code, parserOptions, locationCalculatorForError) {
  5207. try {
  5208. return parseScript$1(code, parserOptions);
  5209. }
  5210. catch (err) {
  5211. const perr = ParseError.normalize(err);
  5212. if (perr) {
  5213. fixErrorLocation(perr, locationCalculatorForError);
  5214. throw perr;
  5215. }
  5216. throw err;
  5217. }
  5218. }
  5219. function parseScriptSetupElements(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, originalParserOptions) {
  5220. const parserOptions = getScriptSetupParserOptions(originalParserOptions);
  5221. const scriptSetupModuleCodeBlocks = getScriptSetupModuleCodeBlocks(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, parserOptions);
  5222. if (!scriptSetupModuleCodeBlocks) {
  5223. return parseScriptFragment("", linesAndColumns.createOffsetLocationCalculator(scriptSetupElement.startTag.range[1]), parserOptions);
  5224. }
  5225. const locationCalculator = {
  5226. getFixOffset(offset, kind) {
  5227. const test = kind === "start"
  5228. ? (block) => block.range[0] <= offset && offset < block.range[1]
  5229. : (block) => block.range[0] < offset && offset <= block.range[1];
  5230. for (const block of scriptSetupModuleCodeBlocks.codeBlocks
  5231. .remapBlocks) {
  5232. if (test(block)) {
  5233. return block.offset;
  5234. }
  5235. }
  5236. return offset;
  5237. },
  5238. getLocFromIndex: linesAndColumns.getLocFromIndex.bind(linesAndColumns),
  5239. };
  5240. const result = parseScript(scriptSetupModuleCodeBlocks.codeBlocks.code, parserOptions, locationCalculator);
  5241. if (scriptSetupModuleCodeBlocks.postprocess) {
  5242. scriptSetupModuleCodeBlocks.postprocess(result, {
  5243. scriptSetupBlockRange: scriptSetupModuleCodeBlocks.scriptSetupBlockRange,
  5244. });
  5245. }
  5246. const scriptSetupStatements = remapAST(result, scriptSetupModuleCodeBlocks);
  5247. remapLocationAndTokens(result, scriptSetupModuleCodeBlocks, locationCalculator);
  5248. if (scriptSetupModuleCodeBlocks.restoreASTCallbacks) {
  5249. scriptSetupModuleCodeBlocks.restoreASTCallbacks.restore(result.ast, scriptSetupStatements, linesAndColumns);
  5250. }
  5251. if (result.ast.tokens != null) {
  5252. for (const node of [scriptSetupElement, scriptElement]) {
  5253. const startTag = node.startTag;
  5254. const endTag = node.endTag;
  5255. result.ast.tokens.unshift({
  5256. type: "Punctuator",
  5257. range: startTag.range,
  5258. loc: startTag.loc,
  5259. value: "<script>",
  5260. });
  5261. if (endTag != null) {
  5262. result.ast.tokens.push({
  5263. type: "Punctuator",
  5264. range: endTag.range,
  5265. loc: endTag.loc,
  5266. value: "</script>",
  5267. });
  5268. }
  5269. }
  5270. result.ast.tokens.sort((a, b) => a.range[0] - b.range[0]);
  5271. }
  5272. result.ast.body.sort((a, b) => a.range[0] - b.range[0]);
  5273. const programStartOffset = result.ast.body.reduce((start, node) => Math.min(start, node.range[0]), result.ast.range[0]);
  5274. result.ast.range[0] = programStartOffset;
  5275. result.ast.loc.start =
  5276. locationCalculator.getLocFromIndex(programStartOffset);
  5277. if (result.ast.start != null) {
  5278. result.ast.start = [scriptSetupElement, scriptElement].reduce((start, node) => {
  5279. const textNode = node.children[0];
  5280. return Math.min(start, textNode != null && textNode.type === "VText"
  5281. ? textNode.range[0]
  5282. : node.startTag.range[1]);
  5283. }, result.ast.start);
  5284. }
  5285. const programEndOffset = result.ast.body.reduce((end, node) => Math.max(end, node.range[1]), 0);
  5286. result.ast.range[1] = programEndOffset;
  5287. result.ast.loc.end = locationCalculator.getLocFromIndex(programEndOffset);
  5288. if (result.ast.end != null) {
  5289. result.ast.end = [scriptSetupElement, scriptElement].reduce((end, node) => {
  5290. var _a, _b;
  5291. const textNode = node.children[0];
  5292. return Math.max(end, textNode != null && textNode.type === "VText"
  5293. ? textNode.range[1]
  5294. : (_b = (_a = node.endTag) === null || _a === void 0 ? void 0 : _a.range[0]) !== null && _b !== void 0 ? _b : node.range[1]);
  5295. }, 0);
  5296. }
  5297. return result;
  5298. }
  5299. function getScriptSetupModuleCodeBlocks(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, parserOptions) {
  5300. const scriptSetupCodeBlocks = getScriptSetupCodeBlocks(scriptSetupElement, sfcCode, linesAndColumns, parserOptions);
  5301. const textNode = scriptElement.children[0];
  5302. if (textNode == null || textNode.type !== "VText") {
  5303. return scriptSetupCodeBlocks;
  5304. }
  5305. const [scriptStartOffset, scriptEndOffset] = textNode.range;
  5306. const codeBlocks = new CodeBlocks();
  5307. codeBlocks.append(sfcCode.slice(scriptStartOffset, scriptEndOffset), scriptStartOffset);
  5308. if (scriptSetupCodeBlocks == null) {
  5309. return { codeBlocks };
  5310. }
  5311. codeBlocks.appendSplitPunctuators(";");
  5312. const scriptSetupOffset = codeBlocks.length;
  5313. codeBlocks.appendCodeBlocks(scriptSetupCodeBlocks.codeBlocks);
  5314. return {
  5315. codeBlocks,
  5316. scriptSetupBlockRange: [
  5317. scriptSetupCodeBlocks.scriptSetupBlockRange[0] + scriptSetupOffset,
  5318. scriptSetupCodeBlocks.scriptSetupBlockRange[1] + scriptSetupOffset,
  5319. ],
  5320. postprocess: scriptSetupCodeBlocks.postprocess,
  5321. restoreASTCallbacks: scriptSetupCodeBlocks.restoreASTCallbacks,
  5322. };
  5323. }
  5324. function getScriptSetupCodeBlocks(node, sfcCode, linesAndColumns, parserOptions) {
  5325. const textNode = node.children[0];
  5326. if (textNode == null || textNode.type !== "VText") {
  5327. return null;
  5328. }
  5329. const [scriptSetupStartOffset, scriptSetupEndOffset] = textNode.range;
  5330. const scriptCode = sfcCode.slice(scriptSetupStartOffset, scriptSetupEndOffset);
  5331. const offsetLocationCalculator = linesAndColumns.createOffsetLocationCalculator(scriptSetupStartOffset);
  5332. const result = parseScript(scriptCode, parserOptions, offsetLocationCalculator);
  5333. const { ast } = result;
  5334. const importCodeBlocks = new CodeBlocks();
  5335. const statementCodeBlocks = new CodeBlocks();
  5336. const exportDefaultCodeBlocks = new CodeBlocks();
  5337. const restoreASTCallbacks = new RestoreASTCallbacks();
  5338. let usedOffset = 0;
  5339. function append(codeBlocks, start, end) {
  5340. if (start < end) {
  5341. codeBlocks.append(scriptCode.slice(start, end), scriptSetupStartOffset + start);
  5342. usedOffset = end;
  5343. return true;
  5344. }
  5345. return false;
  5346. }
  5347. function appendRangeAsStatement(codeBlocks, start, end) {
  5348. if (append(codeBlocks, start, end)) {
  5349. codeBlocks.appendSplitPunctuators(";");
  5350. }
  5351. }
  5352. function transformExportNamed(body) {
  5353. const [start, end] = getNodeFullRange(body);
  5354. appendRangeAsStatement(statementCodeBlocks, usedOffset, start);
  5355. const tokens = ast.tokens;
  5356. const exportTokenIndex = tokens.findIndex((t) => t.range[0] === body.range[0]);
  5357. const exportToken = tokens[exportTokenIndex];
  5358. if (exportToken && exportToken.value === "export") {
  5359. append(statementCodeBlocks, usedOffset, exportToken.range[0]);
  5360. if (body.declaration) {
  5361. appendRangeAsStatement(statementCodeBlocks, exportToken.range[1], end);
  5362. restoreASTCallbacks.addCallback(scriptSetupStartOffset, [start, end], (statement) => {
  5363. if (statement.type !== body.declaration.type) {
  5364. return null;
  5365. }
  5366. fixNodeLocations(body, result.visitorKeys, offsetLocationCalculator);
  5367. fixLocation(exportToken, offsetLocationCalculator);
  5368. body.declaration = statement;
  5369. statement.parent = body;
  5370. return {
  5371. statement: body,
  5372. tokens: [exportToken],
  5373. };
  5374. });
  5375. }
  5376. else {
  5377. statementCodeBlocks.appendSplitPunctuators("(");
  5378. const restoreTokens = [exportToken];
  5379. let startOffset = exportToken.range[1];
  5380. for (const spec of body.specifiers) {
  5381. if (spec.local.range[0] < spec.exported.range[0]) {
  5382. const localTokenIndex = tokens.findIndex((t) => t.range[0] === spec.local.range[0], exportTokenIndex);
  5383. checkToken(tokens[localTokenIndex], spec.local.name);
  5384. const asToken = tokens[localTokenIndex + 1];
  5385. checkToken(asToken, "as");
  5386. restoreTokens.push(asToken);
  5387. const exportedToken = tokens[localTokenIndex + 2];
  5388. checkToken(exportedToken, spec.exported.type === "Identifier"
  5389. ? spec.exported.name
  5390. : spec.exported.raw);
  5391. restoreTokens.push(exportedToken);
  5392. append(statementCodeBlocks, startOffset, asToken.range[0]);
  5393. append(statementCodeBlocks, asToken.range[1], exportedToken.range[0]);
  5394. startOffset = exportedToken.range[1];
  5395. }
  5396. }
  5397. append(statementCodeBlocks, startOffset, end);
  5398. statementCodeBlocks.appendSplitPunctuators(")");
  5399. statementCodeBlocks.appendSplitPunctuators(";");
  5400. restoreASTCallbacks.addCallback(scriptSetupStartOffset, [start, end], (statement) => {
  5401. if (statement.type !== "ExpressionStatement" ||
  5402. statement.expression.type !== "ObjectExpression") {
  5403. return null;
  5404. }
  5405. const locals = [];
  5406. for (const prop of statement.expression.properties) {
  5407. if (prop.type !== "Property" ||
  5408. prop.value.type !== "Identifier") {
  5409. return null;
  5410. }
  5411. locals.push(prop.value);
  5412. }
  5413. if (body.specifiers.length !== locals.length) {
  5414. return null;
  5415. }
  5416. const map = new Map();
  5417. for (let index = 0; index < body.specifiers.length; index++) {
  5418. const spec = body.specifiers[index];
  5419. const local = locals[index];
  5420. map.set(spec, local);
  5421. }
  5422. fixNodeLocations(body, result.visitorKeys, offsetLocationCalculator);
  5423. for (const token of restoreTokens) {
  5424. fixLocation(token, offsetLocationCalculator);
  5425. }
  5426. for (const [spec, local] of map) {
  5427. spec.local = local;
  5428. local.parent = spec;
  5429. }
  5430. return {
  5431. statement: body,
  5432. tokens: restoreTokens,
  5433. };
  5434. });
  5435. }
  5436. }
  5437. else {
  5438. appendRangeAsStatement(statementCodeBlocks, usedOffset, end);
  5439. }
  5440. }
  5441. for (const body of ast.body) {
  5442. if (body.type === "ImportDeclaration" ||
  5443. body.type === "ExportAllDeclaration" ||
  5444. (body.type === "ExportNamedDeclaration" && body.source != null)) {
  5445. const [start, end] = getNodeFullRange(body);
  5446. appendRangeAsStatement(statementCodeBlocks, usedOffset, start);
  5447. appendRangeAsStatement(importCodeBlocks, start, end);
  5448. }
  5449. else if (body.type === "ExportDefaultDeclaration") {
  5450. const [start, end] = getNodeFullRange(body);
  5451. appendRangeAsStatement(statementCodeBlocks, usedOffset, start);
  5452. appendRangeAsStatement(exportDefaultCodeBlocks, start, end);
  5453. }
  5454. else if (body.type === "ExportNamedDeclaration") {
  5455. transformExportNamed(body);
  5456. }
  5457. }
  5458. appendRangeAsStatement(statementCodeBlocks, usedOffset, scriptSetupEndOffset);
  5459. const codeBlocks = new CodeBlocks();
  5460. let postprocess = () => {
  5461. };
  5462. codeBlocks.appendCodeBlocks(importCodeBlocks);
  5463. const scriptSetupBlockRangeStart = codeBlocks.length;
  5464. codeBlocks.appendSplitPunctuators("{");
  5465. const generic = extractGeneric(node);
  5466. if (generic) {
  5467. const defineGenericTypeRangeStart = codeBlocks.length;
  5468. for (const defineType of generic.defineTypes) {
  5469. codeBlocks.append(defineType.define, defineType.node.range[0]);
  5470. codeBlocks.appendSplitPunctuators(";");
  5471. }
  5472. const defineGenericTypeRangeEnd = codeBlocks.length;
  5473. postprocess = (eslintResult, context) => {
  5474. const diffOffset = context.scriptSetupBlockRange[0] - scriptSetupBlockRangeStart;
  5475. const defineGenericTypeRange = [
  5476. defineGenericTypeRangeStart + diffOffset,
  5477. defineGenericTypeRangeEnd + diffOffset,
  5478. ];
  5479. function isTypeBlock(block) {
  5480. return (block.type === "BlockStatement" &&
  5481. context.scriptSetupBlockRange[0] <= block.range[0] &&
  5482. block.range[1] <= context.scriptSetupBlockRange[1]);
  5483. }
  5484. generic.postprocess({
  5485. result: eslintResult,
  5486. getTypeBlock: (program) => program.body.find(isTypeBlock),
  5487. isRemoveTarget(nodeOrToken) {
  5488. return (defineGenericTypeRange[0] <= nodeOrToken.range[0] &&
  5489. nodeOrToken.range[1] <= defineGenericTypeRange[1]);
  5490. },
  5491. getTypeDefScope(scopeManager) {
  5492. var _a;
  5493. const moduleScope = (_a = scopeManager.globalScope.childScopes.find((s) => s.type === "module")) !== null && _a !== void 0 ? _a : scopeManager.globalScope;
  5494. return moduleScope.childScopes.find((scope) => isTypeBlock(scope.block));
  5495. },
  5496. });
  5497. };
  5498. }
  5499. codeBlocks.appendCodeBlocks(statementCodeBlocks);
  5500. codeBlocks.appendSplitPunctuators("}");
  5501. const scriptSetupBlockRangeEnd = codeBlocks.length;
  5502. codeBlocks.appendCodeBlocks(exportDefaultCodeBlocks);
  5503. return {
  5504. codeBlocks,
  5505. scriptSetupBlockRange: [
  5506. scriptSetupBlockRangeStart,
  5507. scriptSetupBlockRangeEnd,
  5508. ],
  5509. postprocess,
  5510. restoreASTCallbacks,
  5511. };
  5512. function getNodeFullRange(n) {
  5513. let start = n.range[0];
  5514. let end = n.range[1];
  5515. traverseNodes(n, {
  5516. visitorKeys: result.visitorKeys,
  5517. enterNode(c) {
  5518. start = Math.min(start, c.range[0]);
  5519. end = Math.max(end, c.range[1]);
  5520. },
  5521. leaveNode() {
  5522. },
  5523. });
  5524. return [start, end];
  5525. }
  5526. function checkToken(token, value) {
  5527. if (token.value === value) {
  5528. return;
  5529. }
  5530. const perr = new ParseError(`Could not parse <script setup>. Expected "${value}", but it was "${token.value}".`, undefined, token.range[0], token.loc.start.line, token.loc.start.column);
  5531. fixErrorLocation(perr, offsetLocationCalculator);
  5532. throw perr;
  5533. }
  5534. }
  5535. function remapAST(result, { scriptSetupBlockRange, codeBlocks }) {
  5536. if (!scriptSetupBlockRange) {
  5537. return [];
  5538. }
  5539. let scriptSetupBlock = null;
  5540. const scriptSetupStatements = [];
  5541. for (let index = result.ast.body.length - 1; index >= 0; index--) {
  5542. const body = result.ast.body[index];
  5543. if (body.type === "BlockStatement") {
  5544. if (scriptSetupBlockRange[0] <= body.range[0] &&
  5545. body.range[1] <= scriptSetupBlockRange[1]) {
  5546. if (scriptSetupBlock) {
  5547. throw new Error(`Unexpected state error: An unexpected block statement was found. ${JSON.stringify(body.loc)}`);
  5548. }
  5549. scriptSetupBlock = body;
  5550. scriptSetupStatements.push(...body.body.filter((b) => !isSplitPunctuatorsEmptyStatement(b)));
  5551. result.ast.body.splice(index, 1, ...scriptSetupStatements);
  5552. }
  5553. }
  5554. else if (body.type === "EmptyStatement") {
  5555. if (isSplitPunctuatorsEmptyStatement(body)) {
  5556. result.ast.body.splice(index, 1);
  5557. }
  5558. }
  5559. }
  5560. if (result.scopeManager && scriptSetupBlock) {
  5561. const blockScope = result.scopeManager.acquire(scriptSetupBlock, true);
  5562. remapScope(result.scopeManager, blockScope);
  5563. }
  5564. return scriptSetupStatements;
  5565. function isSplitPunctuatorsEmptyStatement(body) {
  5566. return (body.type === "EmptyStatement" &&
  5567. codeBlocks.splitPunctuators.includes(body.range[1] - 1));
  5568. }
  5569. function remapScope(scopeManager, blockScope) {
  5570. const moduleScope = blockScope.upper;
  5571. for (const reference of blockScope.references) {
  5572. reference.from = moduleScope;
  5573. moduleScope.references.push(reference);
  5574. }
  5575. for (const variable of blockScope.variables) {
  5576. variable.scope = moduleScope;
  5577. const alreadyVariable = moduleScope.variables.find((v) => v.name === variable.name);
  5578. if (alreadyVariable) {
  5579. alreadyVariable.defs.push(...variable.defs);
  5580. alreadyVariable.identifiers.push(...variable.identifiers);
  5581. alreadyVariable.references.push(...variable.references);
  5582. for (const reference of variable.references) {
  5583. reference.resolved = alreadyVariable;
  5584. }
  5585. }
  5586. else {
  5587. moduleScope.variables.push(variable);
  5588. moduleScope.set.set(variable.name, variable);
  5589. }
  5590. }
  5591. const upper = blockScope.upper;
  5592. if (upper) {
  5593. const index = upper.childScopes.indexOf(blockScope);
  5594. if (index >= 0) {
  5595. upper.childScopes.splice(index, 1);
  5596. }
  5597. }
  5598. const index = scopeManager.scopes.indexOf(blockScope);
  5599. if (index >= 0) {
  5600. scopeManager.scopes.splice(index, 1);
  5601. }
  5602. }
  5603. }
  5604. function remapLocationAndTokens(result, { codeBlocks }, locationCalculator) {
  5605. const tokens = result.ast.tokens || [];
  5606. const endMap = new Map();
  5607. const buffer = [];
  5608. for (let index = tokens.length - 1; index >= 0; index--) {
  5609. const token = tokens[index];
  5610. if (token.range[0] + 1 === token.range[1] &&
  5611. codeBlocks.splitPunctuators.includes(token.range[0])) {
  5612. tokens.splice(index, 1);
  5613. buffer.push(token.range[1]);
  5614. continue;
  5615. }
  5616. else {
  5617. for (const end of buffer) {
  5618. endMap.set(end, token.range[1]);
  5619. }
  5620. buffer.length = 0;
  5621. }
  5622. }
  5623. traverseNodes(result.ast, {
  5624. visitorKeys: result.visitorKeys,
  5625. enterNode(node) {
  5626. const rangeEnd = endMap.get(node.range[1]);
  5627. if (rangeEnd != null) {
  5628. node.range[1] = rangeEnd;
  5629. }
  5630. if (node.end) {
  5631. const end = endMap.get(node.end);
  5632. if (end != null) {
  5633. node.end = rangeEnd;
  5634. }
  5635. }
  5636. },
  5637. leaveNode() {
  5638. },
  5639. });
  5640. fixLocations(result, locationCalculator);
  5641. }
  5642. class CSSTokenizer {
  5643. constructor(text, startOffset, options) {
  5644. var _a;
  5645. debug("[css] the source code length: %d", text.length);
  5646. this.text = text;
  5647. this.options = {
  5648. inlineComment: (_a = options === null || options === void 0 ? void 0 : options.inlineComment) !== null && _a !== void 0 ? _a : false,
  5649. };
  5650. this.cp = NULL;
  5651. this.offset = startOffset - 1;
  5652. this.nextOffset = startOffset;
  5653. this.reconsuming = false;
  5654. }
  5655. nextToken() {
  5656. let cp;
  5657. if (this.reconsuming) {
  5658. cp = this.cp;
  5659. this.reconsuming = false;
  5660. }
  5661. else {
  5662. cp = this.consumeNextCodePoint();
  5663. }
  5664. while (isWhitespace(cp)) {
  5665. cp = this.consumeNextCodePoint();
  5666. }
  5667. if (cp === EOF) {
  5668. return null;
  5669. }
  5670. const start = this.offset;
  5671. return this.consumeNextToken(cp, start);
  5672. }
  5673. nextCodePoint() {
  5674. if (this.nextOffset >= this.text.length) {
  5675. return EOF;
  5676. }
  5677. return this.text.codePointAt(this.nextOffset);
  5678. }
  5679. consumeNextCodePoint() {
  5680. if (this.offset >= this.text.length) {
  5681. this.cp = EOF;
  5682. return EOF;
  5683. }
  5684. this.offset = this.nextOffset;
  5685. if (this.offset >= this.text.length) {
  5686. this.cp = EOF;
  5687. return EOF;
  5688. }
  5689. let cp = this.text.codePointAt(this.offset);
  5690. if (cp === CARRIAGE_RETURN) {
  5691. this.nextOffset = this.offset + 1;
  5692. if (this.text.codePointAt(this.nextOffset) === LINE_FEED) {
  5693. this.nextOffset++;
  5694. }
  5695. cp = LINE_FEED;
  5696. }
  5697. else {
  5698. this.nextOffset = this.offset + (cp >= 0x10000 ? 2 : 1);
  5699. }
  5700. this.cp = cp;
  5701. return cp;
  5702. }
  5703. consumeNextToken(cp, start) {
  5704. if (cp === SOLIDUS) {
  5705. const nextCp = this.nextCodePoint();
  5706. if (nextCp === ASTERISK) {
  5707. return this.consumeComment(start);
  5708. }
  5709. if (nextCp === SOLIDUS && this.options.inlineComment) {
  5710. return this.consumeInlineComment(start);
  5711. }
  5712. }
  5713. if (isQuote(cp)) {
  5714. return this.consumeString(start, cp);
  5715. }
  5716. if (isPunctuator(cp)) {
  5717. return {
  5718. type: "Punctuator",
  5719. range: [start, start + 1],
  5720. value: String.fromCodePoint(cp),
  5721. };
  5722. }
  5723. return this.consumeWord(start);
  5724. }
  5725. consumeWord(start) {
  5726. let cp = this.consumeNextCodePoint();
  5727. while (!isWhitespace(cp) && !isPunctuator(cp) && !isQuote(cp)) {
  5728. cp = this.consumeNextCodePoint();
  5729. }
  5730. this.reconsuming = true;
  5731. const range = [start, this.offset];
  5732. const text = this.text;
  5733. let value;
  5734. return {
  5735. type: "Word",
  5736. range,
  5737. get value() {
  5738. return (value !== null && value !== void 0 ? value : (value = text.slice(...range)));
  5739. },
  5740. };
  5741. }
  5742. consumeString(start, quote) {
  5743. let valueEndOffset = null;
  5744. let cp = this.consumeNextCodePoint();
  5745. while (cp !== EOF) {
  5746. if (cp === quote) {
  5747. valueEndOffset = this.offset;
  5748. break;
  5749. }
  5750. if (cp === REVERSE_SOLIDUS) {
  5751. this.consumeNextCodePoint();
  5752. }
  5753. cp = this.consumeNextCodePoint();
  5754. }
  5755. const text = this.text;
  5756. let value;
  5757. const valueRange = [
  5758. start + 1,
  5759. valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
  5760. ];
  5761. return {
  5762. type: "Quoted",
  5763. range: [start, this.nextOffset],
  5764. valueRange,
  5765. get value() {
  5766. return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
  5767. },
  5768. quote: String.fromCodePoint(quote),
  5769. };
  5770. }
  5771. consumeComment(start) {
  5772. this.consumeNextCodePoint();
  5773. let valueEndOffset = null;
  5774. let cp = this.consumeNextCodePoint();
  5775. while (cp !== EOF) {
  5776. if (cp === ASTERISK) {
  5777. cp = this.consumeNextCodePoint();
  5778. if (cp === SOLIDUS) {
  5779. valueEndOffset = this.offset - 1;
  5780. break;
  5781. }
  5782. }
  5783. cp = this.consumeNextCodePoint();
  5784. }
  5785. const valueRange = [
  5786. start + 2,
  5787. valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
  5788. ];
  5789. const text = this.text;
  5790. let value;
  5791. return {
  5792. type: "Block",
  5793. range: [start, this.nextOffset],
  5794. valueRange,
  5795. get value() {
  5796. return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
  5797. },
  5798. };
  5799. }
  5800. consumeInlineComment(start) {
  5801. this.consumeNextCodePoint();
  5802. let valueEndOffset = null;
  5803. let cp = this.consumeNextCodePoint();
  5804. while (cp !== EOF) {
  5805. if (cp === LINE_FEED) {
  5806. valueEndOffset = this.offset - 1;
  5807. break;
  5808. }
  5809. cp = this.consumeNextCodePoint();
  5810. }
  5811. const valueRange = [
  5812. start + 2,
  5813. valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
  5814. ];
  5815. const text = this.text;
  5816. let value;
  5817. return {
  5818. type: "Line",
  5819. range: [start, this.nextOffset],
  5820. valueRange,
  5821. get value() {
  5822. return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
  5823. },
  5824. };
  5825. }
  5826. }
  5827. function isPunctuator(cp) {
  5828. return (cp === COLON ||
  5829. cp === SEMICOLON ||
  5830. cp === LEFT_PARENTHESIS ||
  5831. cp === RIGHT_PARENTHESIS ||
  5832. cp === LEFT_CURLY_BRACKET ||
  5833. cp === RIGHT_CURLY_BRACKET ||
  5834. cp === LEFT_SQUARE_BRACKET ||
  5835. cp === RIGHT_SQUARE_BRACKET ||
  5836. cp === SOLIDUS ||
  5837. cp === ASTERISK);
  5838. }
  5839. function isQuote(cp) {
  5840. return cp === APOSTROPHE || cp === QUOTATION_MARK;
  5841. }
  5842. class CSSTokenScanner {
  5843. constructor(text, options) {
  5844. this.reconsuming = [];
  5845. this.tokenizer = new CSSTokenizer(text, 0, options);
  5846. }
  5847. nextToken() {
  5848. return this.reconsuming.shift() || this.tokenizer.nextToken();
  5849. }
  5850. reconsume(...tokens) {
  5851. this.reconsuming.push(...tokens);
  5852. }
  5853. }
  5854. function parseStyleElements(elements, globalLocationCalculator, originalParserOptions) {
  5855. const parserOptions = Object.assign(Object.assign({}, originalParserOptions), { ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION });
  5856. for (const style of elements) {
  5857. style.style = true;
  5858. parseStyleElement(style, globalLocationCalculator, parserOptions, {
  5859. inlineComment: (getLang(style) || "css") !== "css",
  5860. });
  5861. }
  5862. }
  5863. function parseStyleElement(style, globalLocationCalculator, parserOptions, cssOptions) {
  5864. if (style.children.length !== 1) {
  5865. return;
  5866. }
  5867. const textNode = style.children[0];
  5868. if (textNode.type !== "VText") {
  5869. return;
  5870. }
  5871. const code = textNode.value;
  5872. if (!/v-bind\s*(?:\(|\/)/u.test(code)) {
  5873. return;
  5874. }
  5875. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(textNode.range[0]);
  5876. const document = getOwnerDocument(style);
  5877. parseStyle(document, style, code, locationCalculator, parserOptions, cssOptions);
  5878. }
  5879. function parseStyle(document, style, code, locationCalculator, parserOptions, cssOptions) {
  5880. let textStart = 0;
  5881. for (const { range, exprRange, quote, openingParenOffset, comments, } of iterateVBind(code, cssOptions)) {
  5882. insertComments(document, comments.map((c) => createSimpleToken(c.type, locationCalculator.getOffsetWithGap(c.range[0]), locationCalculator.getOffsetWithGap(c.range[1]), c.value, locationCalculator)));
  5883. const container = {
  5884. type: "VExpressionContainer",
  5885. range: [
  5886. locationCalculator.getOffsetWithGap(range[0]),
  5887. locationCalculator.getOffsetWithGap(range[1]),
  5888. ],
  5889. loc: {
  5890. start: locationCalculator.getLocation(range[0]),
  5891. end: locationCalculator.getLocation(range[1]),
  5892. },
  5893. parent: style,
  5894. expression: null,
  5895. references: [],
  5896. };
  5897. const openingParenStart = locationCalculator.getOffsetWithGap(openingParenOffset);
  5898. const beforeTokens = [
  5899. createSimpleToken("HTMLRawText", container.range[0], container.range[0] + 6, "v-bind", locationCalculator),
  5900. createSimpleToken("Punctuator", openingParenStart, openingParenStart + 1, "(", locationCalculator),
  5901. ];
  5902. const afterTokens = [
  5903. createSimpleToken("Punctuator", container.range[1] - 1, container.range[1], ")", locationCalculator),
  5904. ];
  5905. if (quote) {
  5906. const openStart = locationCalculator.getOffsetWithGap(exprRange[0] - 1);
  5907. beforeTokens.push(createSimpleToken("Punctuator", openStart, openStart + 1, quote, locationCalculator));
  5908. const closeStart = locationCalculator.getOffsetWithGap(exprRange[1]);
  5909. afterTokens.unshift(createSimpleToken("Punctuator", closeStart, closeStart + 1, quote, locationCalculator));
  5910. }
  5911. const beforeLast = beforeTokens[beforeTokens.length - 1];
  5912. replaceAndSplitTokens(document, {
  5913. range: [container.range[0], beforeLast.range[1]],
  5914. loc: { start: container.loc.start, end: beforeLast.loc.end },
  5915. }, beforeTokens);
  5916. const afterFirst = afterTokens[0];
  5917. replaceAndSplitTokens(document, {
  5918. range: [afterFirst.range[0], container.range[1]],
  5919. loc: { start: afterFirst.loc.start, end: container.loc.end },
  5920. }, afterTokens);
  5921. const lastChild = style.children[style.children.length - 1];
  5922. style.children.push(container);
  5923. if (lastChild.type === "VText") {
  5924. const newTextNode = {
  5925. type: "VText",
  5926. range: [container.range[1], lastChild.range[1]],
  5927. loc: {
  5928. start: Object.assign({}, container.loc.end),
  5929. end: Object.assign({}, lastChild.loc.end),
  5930. },
  5931. parent: style,
  5932. value: code.slice(range[1]),
  5933. };
  5934. style.children.push(newTextNode);
  5935. lastChild.range[1] = container.range[0];
  5936. lastChild.loc.end = Object.assign({}, container.loc.start);
  5937. lastChild.value = code.slice(textStart, range[0]);
  5938. textStart = range[1];
  5939. }
  5940. try {
  5941. const ret = parseExpression(code.slice(...exprRange), locationCalculator.getSubCalculatorShift(exprRange[0]), parserOptions, { allowEmpty: false, allowFilters: false });
  5942. if (ret.expression) {
  5943. ret.expression.parent = container;
  5944. container.expression = ret.expression;
  5945. container.references = ret.references;
  5946. }
  5947. replaceAndSplitTokens(document, {
  5948. range: [beforeLast.range[1], afterFirst.range[0]],
  5949. loc: {
  5950. start: beforeLast.loc.end,
  5951. end: afterFirst.loc.start,
  5952. },
  5953. }, ret.tokens);
  5954. insertComments(document, ret.comments);
  5955. for (const variable of ret.variables) {
  5956. style.variables.push(variable);
  5957. }
  5958. resolveReferences(container);
  5959. }
  5960. catch (err) {
  5961. debug("[style] Parse error: %s", err);
  5962. if (ParseError.isParseError(err)) {
  5963. insertError(document, err);
  5964. }
  5965. else {
  5966. throw err;
  5967. }
  5968. }
  5969. }
  5970. }
  5971. function* iterateVBind(code, cssOptions) {
  5972. const tokenizer = new CSSTokenScanner(code, cssOptions);
  5973. let token;
  5974. while ((token = tokenizer.nextToken())) {
  5975. if (token.type !== "Word" || token.value !== "v-bind") {
  5976. continue;
  5977. }
  5978. const openingParen = findVBindOpeningParen(tokenizer);
  5979. if (!openingParen) {
  5980. continue;
  5981. }
  5982. const arg = parseVBindArg(tokenizer);
  5983. if (!arg) {
  5984. continue;
  5985. }
  5986. yield {
  5987. range: [token.range[0], arg.closingParen.range[1]],
  5988. exprRange: arg.exprRange,
  5989. quote: arg.quote,
  5990. openingParenOffset: openingParen.openingParen.range[0],
  5991. comments: [...openingParen.comments, ...arg.comments],
  5992. };
  5993. }
  5994. }
  5995. function findVBindOpeningParen(tokenizer) {
  5996. const comments = [];
  5997. let token;
  5998. while ((token = tokenizer.nextToken())) {
  5999. if (token.type === "Punctuator" && token.value === "(") {
  6000. return {
  6001. openingParen: token,
  6002. comments,
  6003. };
  6004. }
  6005. else if (isComment(token)) {
  6006. comments.push(token);
  6007. continue;
  6008. }
  6009. tokenizer.reconsume(...comments, token);
  6010. return null;
  6011. }
  6012. return null;
  6013. }
  6014. function parseVBindArg(tokenizer) {
  6015. const tokensBuffer = [];
  6016. const comments = [];
  6017. const tokens = [];
  6018. const closeTokenStack = [];
  6019. let token;
  6020. while ((token = tokenizer.nextToken())) {
  6021. if (token.type === "Punctuator") {
  6022. if (token.value === ")" && !closeTokenStack.length) {
  6023. if (tokens.length === 1 &&
  6024. tokens[0].type === "Quoted") {
  6025. const quotedToken = tokens[0];
  6026. return {
  6027. exprRange: quotedToken.valueRange,
  6028. quote: quotedToken.quote,
  6029. closingParen: token,
  6030. comments,
  6031. };
  6032. }
  6033. const startToken = tokensBuffer[0] || token;
  6034. return {
  6035. exprRange: [startToken.range[0], token.range[0]],
  6036. quote: null,
  6037. closingParen: token,
  6038. comments: [],
  6039. };
  6040. }
  6041. if (token.value === closeTokenStack[0]) {
  6042. closeTokenStack.shift();
  6043. }
  6044. else if (token.value === "(") {
  6045. closeTokenStack.unshift(")");
  6046. }
  6047. }
  6048. tokensBuffer.push(token);
  6049. if (isComment(token)) {
  6050. comments.push(token);
  6051. }
  6052. else {
  6053. tokens.push(token);
  6054. }
  6055. }
  6056. tokenizer.reconsume(...tokensBuffer);
  6057. return null;
  6058. }
  6059. function isComment(token) {
  6060. return token.type === "Block" || token.type === "Line";
  6061. }
  6062. const BUILTIN_COMPONENTS = new Set([
  6063. "template",
  6064. "slot",
  6065. "component",
  6066. "Component",
  6067. "transition",
  6068. "Transition",
  6069. "transition-group",
  6070. "TransitionGroup",
  6071. "keep-alive",
  6072. "KeepAlive",
  6073. "teleport",
  6074. "Teleport",
  6075. "suspense",
  6076. "Suspense",
  6077. ]);
  6078. const BUILTIN_DIRECTIVES = new Set([
  6079. "bind",
  6080. "on",
  6081. "text",
  6082. "html",
  6083. "show",
  6084. "if",
  6085. "else",
  6086. "else-if",
  6087. "for",
  6088. "model",
  6089. "slot",
  6090. "pre",
  6091. "cloak",
  6092. "once",
  6093. "memo",
  6094. "is",
  6095. ]);
  6096. const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer," +
  6097. "header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption," +
  6098. "figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code," +
  6099. "data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup," +
  6100. "time,u,var,wbr,area,audio,map,track,video,embed,object,param,source," +
  6101. "canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td," +
  6102. "th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup," +
  6103. "option,output,progress,select,textarea,details,dialog,menu," +
  6104. "summary,template,blockquote,iframe,tfoot";
  6105. const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile," +
  6106. "defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer," +
  6107. "feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap," +
  6108. "feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR," +
  6109. "feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset," +
  6110. "fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter," +
  6111. "foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask," +
  6112. "mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern," +
  6113. "polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol," +
  6114. "text,textPath,title,tspan,unknown,use,view";
  6115. const NATIVE_TAGS = new Set([...HTML_TAGS.split(","), ...SVG_TAGS.split(",")]);
  6116. const COMPILER_MACROS_AT_ROOT = new Set([
  6117. "defineProps",
  6118. "defineEmits",
  6119. "defineExpose",
  6120. "withDefaults",
  6121. "defineOptions",
  6122. "defineSlots",
  6123. "defineModel",
  6124. ]);
  6125. function capitalize(str) {
  6126. return str[0].toUpperCase() + str.slice(1);
  6127. }
  6128. function analyzeScriptSetupScope(scopeManager, templateBody, df, parserOptions) {
  6129. analyzeUsedInTemplateVariables(scopeManager, templateBody, df);
  6130. analyzeScriptSetupVariables(scopeManager, df, parserOptions);
  6131. }
  6132. function extractVariables(scopeManager) {
  6133. const scriptVariables = new Map();
  6134. const globalScope = scopeManager.globalScope;
  6135. if (!globalScope) {
  6136. return scriptVariables;
  6137. }
  6138. for (const variable of globalScope.variables) {
  6139. scriptVariables.set(variable.name, variable);
  6140. }
  6141. const moduleScope = globalScope.childScopes.find((scope) => scope.type === "module");
  6142. for (const variable of (moduleScope && moduleScope.variables) || []) {
  6143. scriptVariables.set(variable.name, variable);
  6144. }
  6145. return scriptVariables;
  6146. }
  6147. function analyzeUsedInTemplateVariables(scopeManager, templateBody, df) {
  6148. const scriptVariables = extractVariables(scopeManager);
  6149. const markedVariables = new Set();
  6150. function markSetupReferenceVariableAsUsed(name) {
  6151. if (scriptVariables.has(name)) {
  6152. markVariableAsUsed(name);
  6153. return true;
  6154. }
  6155. const camelName = camelize(name);
  6156. if (scriptVariables.has(camelName)) {
  6157. markVariableAsUsed(camelName);
  6158. return true;
  6159. }
  6160. const pascalName = capitalize(camelName);
  6161. if (scriptVariables.has(pascalName)) {
  6162. markVariableAsUsed(pascalName);
  6163. return true;
  6164. }
  6165. return false;
  6166. }
  6167. function markVariableAsUsed(nameOrRef) {
  6168. let name;
  6169. let isValueReference;
  6170. let isTypeReference;
  6171. if (typeof nameOrRef === "string") {
  6172. name = nameOrRef;
  6173. }
  6174. else {
  6175. name = nameOrRef.id.name;
  6176. isValueReference = nameOrRef.isValueReference;
  6177. isTypeReference = nameOrRef.isTypeReference;
  6178. }
  6179. const variable = scriptVariables.get(name);
  6180. if (!variable || variable.identifiers.length === 0) {
  6181. return;
  6182. }
  6183. if (markedVariables.has(name)) {
  6184. return;
  6185. }
  6186. markedVariables.add(name);
  6187. const reference = new (getEslintScope().Reference)();
  6188. reference.vueUsedInTemplate = true;
  6189. reference.from = variable.scope;
  6190. reference.identifier = variable.identifiers[0];
  6191. reference.isWrite = () => false;
  6192. reference.isWriteOnly = () => false;
  6193. reference.isRead = () => true;
  6194. reference.isReadOnly = () => true;
  6195. reference.isReadWrite = () => false;
  6196. reference.isValueReference = isValueReference;
  6197. reference.isTypeReference = isTypeReference;
  6198. variable.references.push(reference);
  6199. reference.resolved = variable;
  6200. if (reference.isTypeReference) {
  6201. variable.eslintUsed = true;
  6202. }
  6203. }
  6204. function processVExpressionContainer(node) {
  6205. for (const reference of node.references.filter((ref) => ref.variable == null)) {
  6206. markVariableAsUsed(reference);
  6207. }
  6208. }
  6209. function processVElement(node) {
  6210. if ((node.rawName === node.name && NATIVE_TAGS.has(node.rawName)) ||
  6211. BUILTIN_COMPONENTS.has(node.rawName)) {
  6212. return;
  6213. }
  6214. if (!markSetupReferenceVariableAsUsed(node.rawName)) {
  6215. const dotIndex = node.rawName.indexOf(".");
  6216. if (dotIndex > 0) {
  6217. markSetupReferenceVariableAsUsed(node.rawName.slice(0, dotIndex));
  6218. }
  6219. }
  6220. }
  6221. function processVAttribute(node) {
  6222. if (node.directive) {
  6223. if (BUILTIN_DIRECTIVES.has(node.key.name.name)) {
  6224. return;
  6225. }
  6226. markSetupReferenceVariableAsUsed(`v-${node.key.name.rawName}`);
  6227. }
  6228. else if (node.key.name === "ref" && node.value) {
  6229. markVariableAsUsed(node.value.value);
  6230. }
  6231. }
  6232. if (templateBody) {
  6233. traverseNodes(templateBody, {
  6234. enterNode(node) {
  6235. if (node.type === "VExpressionContainer") {
  6236. processVExpressionContainer(node);
  6237. }
  6238. else if (node.type === "VElement") {
  6239. processVElement(node);
  6240. }
  6241. else if (node.type === "VAttribute") {
  6242. processVAttribute(node);
  6243. }
  6244. },
  6245. leaveNode() {
  6246. },
  6247. });
  6248. }
  6249. for (const child of df.children) {
  6250. if (child.type === "VElement") {
  6251. if (isScriptSetupElement(child)) {
  6252. const generic = findGenericDirective(child);
  6253. if (generic) {
  6254. processVExpressionContainer(generic.value);
  6255. }
  6256. }
  6257. else if (child.name === "style") {
  6258. for (const node of child.children) {
  6259. if (node.type === "VExpressionContainer") {
  6260. processVExpressionContainer(node);
  6261. }
  6262. }
  6263. }
  6264. }
  6265. }
  6266. }
  6267. function analyzeScriptSetupVariables(scopeManager, df, parserOptions) {
  6268. var _a;
  6269. const globalScope = scopeManager.globalScope;
  6270. if (!globalScope) {
  6271. return;
  6272. }
  6273. const customMacros = new Set(((_a = parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.customMacros) &&
  6274. Array.isArray(parserOptions.vueFeatures.customMacros)
  6275. ? parserOptions.vueFeatures.customMacros
  6276. : []);
  6277. const genericDefineNames = new Set();
  6278. const scriptElements = df.children.filter(isScriptElement);
  6279. const scriptSetupElement = scriptElements.find(isScriptSetupElement);
  6280. if (scriptSetupElement && findGenericDirective(scriptSetupElement)) {
  6281. for (const variable of scriptSetupElement.variables) {
  6282. if (variable.kind === "generic") {
  6283. genericDefineNames.add(variable.id.name);
  6284. }
  6285. }
  6286. }
  6287. const newThrough = [];
  6288. for (const reference of globalScope.through) {
  6289. if (COMPILER_MACROS_AT_ROOT.has(reference.identifier.name) ||
  6290. customMacros.has(reference.identifier.name)) {
  6291. if (reference.from.type === "global" ||
  6292. reference.from.type === "module") {
  6293. addCompilerMacroVariable(reference);
  6294. continue;
  6295. }
  6296. }
  6297. if (genericDefineNames.has(reference.identifier.name)) {
  6298. addGenericVariable(reference);
  6299. continue;
  6300. }
  6301. newThrough.push(reference);
  6302. }
  6303. globalScope.through = newThrough;
  6304. function addCompilerMacroVariable(reference) {
  6305. addVariable(globalScope, reference);
  6306. }
  6307. function addGenericVariable(reference) {
  6308. addVariable(globalScope, reference);
  6309. }
  6310. }
  6311. function addVariable(scope, reference) {
  6312. const name = reference.identifier.name;
  6313. let variable = scope.set.get(name);
  6314. if (!variable) {
  6315. variable = new (getEslintScope().Variable)();
  6316. variable.name = name;
  6317. variable.scope = scope;
  6318. scope.variables.push(variable);
  6319. scope.set.set(name, variable);
  6320. }
  6321. reference.resolved = variable;
  6322. variable.references.push(reference);
  6323. }
  6324. const STARTS_WITH_LT = /^\s*</u;
  6325. function isVueFile(code, options) {
  6326. const filePath = options.filePath || "unknown.js";
  6327. return path__namespace.extname(filePath) === ".vue" || STARTS_WITH_LT.test(code);
  6328. }
  6329. function parseForESLint(code, parserOptions) {
  6330. const options = Object.assign({
  6331. comment: true,
  6332. loc: true,
  6333. range: true,
  6334. tokens: true,
  6335. }, parserOptions || {});
  6336. let result;
  6337. let document;
  6338. let locationCalculator;
  6339. if (!isVueFile(code, options)) {
  6340. result = parseAsScript(code, options);
  6341. document = null;
  6342. locationCalculator = null;
  6343. }
  6344. else {
  6345. ({ result, document, locationCalculator } = parseAsSFC(code, options));
  6346. }
  6347. result.services = Object.assign(result.services || {}, define(code, result.ast, document, locationCalculator, {
  6348. parserOptions: options,
  6349. }));
  6350. return result;
  6351. }
  6352. function parse(code, options) {
  6353. return parseForESLint(code, options).ast;
  6354. }
  6355. function parseAsSFC(code, options) {
  6356. var _a, _b, _c;
  6357. const optionsForTemplate = Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION });
  6358. const skipParsingScript = options.parser === false;
  6359. const tokenizer = new Tokenizer(code, optionsForTemplate);
  6360. const rootAST = new Parser(tokenizer, optionsForTemplate).parse();
  6361. const locationCalculator = new LocationCalculatorForHtml(tokenizer.gaps, tokenizer.lineTerminators);
  6362. const scripts = rootAST.children.filter(isScriptElement);
  6363. const template = rootAST.children.find(isTemplateElement);
  6364. const templateLang = getLang(template) || "html";
  6365. const hasTemplateTokenizer = (_a = options === null || options === void 0 ? void 0 : options.templateTokenizer) === null || _a === void 0 ? void 0 : _a[templateLang];
  6366. const concreteInfo = {
  6367. tokens: rootAST.tokens,
  6368. comments: rootAST.comments,
  6369. errors: rootAST.errors,
  6370. };
  6371. const templateBody = template != null && (templateLang === "html" || hasTemplateTokenizer)
  6372. ? Object.assign(template, concreteInfo)
  6373. : undefined;
  6374. const scriptParser = getScriptParser(options.parser, () => getParserLangFromSFC(rootAST));
  6375. let result;
  6376. let scriptSetup;
  6377. if (skipParsingScript || !scripts.length) {
  6378. result = parseScript$1("", Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, parser: scriptParser }));
  6379. }
  6380. else if (scripts.length === 2 &&
  6381. (scriptSetup = scripts.find(isScriptSetupElement))) {
  6382. result = parseScriptSetupElements(scriptSetup, scripts.find((e) => e !== scriptSetup), code, new LinesAndColumns(tokenizer.lineTerminators), Object.assign(Object.assign({}, options), { parser: scriptParser }));
  6383. }
  6384. else {
  6385. result = parseScriptElement(scripts[0], code, new LinesAndColumns(tokenizer.lineTerminators), Object.assign(Object.assign({}, options), { parser: scriptParser }));
  6386. }
  6387. if ((_c = (_b = options.vueFeatures) === null || _b === void 0 ? void 0 : _b.styleCSSVariableInjection) !== null && _c !== void 0 ? _c : true) {
  6388. const styles = rootAST.children.filter(isStyleElement);
  6389. parseStyleElements(styles, locationCalculator, Object.assign(Object.assign({}, options), { parser: getScriptParser(options.parser, function* () {
  6390. yield "<template>";
  6391. yield getParserLangFromSFC(rootAST);
  6392. }) }));
  6393. }
  6394. result.ast.templateBody = templateBody;
  6395. if (options.eslintScopeManager) {
  6396. if (scripts.some(isScriptSetupElement)) {
  6397. if (!result.scopeManager) {
  6398. result.scopeManager = analyzeScope(result.ast, options);
  6399. }
  6400. analyzeScriptSetupScope(result.scopeManager, templateBody, rootAST, options);
  6401. }
  6402. }
  6403. return {
  6404. result,
  6405. locationCalculator,
  6406. document: rootAST,
  6407. };
  6408. }
  6409. function parseAsScript(code, options) {
  6410. return parseScript$1(code, Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, parser: getScriptParser(options.parser, () => {
  6411. const ext = (path__namespace.extname(options.filePath || "unknown.js").toLowerCase() ||
  6412. "")
  6413. .slice(1);
  6414. if (/^[jt]sx$/u.test(ext)) {
  6415. return [ext, ext.slice(0, -1)];
  6416. }
  6417. return ext;
  6418. }) }));
  6419. }
  6420. const meta = {
  6421. name: "vue-eslint-parser",
  6422. version: "9.4.3",
  6423. };
  6424. exports.AST = index;
  6425. exports.meta = meta;
  6426. exports.parse = parse;
  6427. exports.parseForESLint = parseForESLint;
  6428. //# sourceMappingURL=index.js.map