index.js 264 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961
  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. class ParseError extends SyntaxError {
  72. constructor(message, code, offset, line, column) {
  73. super(message);
  74. this.code = code;
  75. this.index = offset;
  76. this.lineNumber = line;
  77. this.column = column;
  78. }
  79. static fromCode(code, offset, line, column) {
  80. return new ParseError(code, code, offset, line, column);
  81. }
  82. static normalize(x) {
  83. if (ParseError.isParseError(x)) {
  84. return x;
  85. }
  86. if (isAcornStyleParseError(x)) {
  87. return new ParseError(x.message, undefined, x.pos, x.loc.line, x.loc.column);
  88. }
  89. return null;
  90. }
  91. static isParseError(x) {
  92. return (x instanceof ParseError ||
  93. (typeof x.message === "string" &&
  94. typeof x.index === "number" &&
  95. typeof x.lineNumber === "number" &&
  96. typeof x.column === "number"));
  97. }
  98. }
  99. const NS = Object.freeze({
  100. HTML: "http://www.w3.org/1999/xhtml",
  101. MathML: "http://www.w3.org/1998/Math/MathML",
  102. SVG: "http://www.w3.org/2000/svg",
  103. XLink: "http://www.w3.org/1999/xlink",
  104. XML: "http://www.w3.org/XML/1998/namespace",
  105. XMLNS: "http://www.w3.org/2000/xmlns/",
  106. });
  107. const KEYS = Evk__namespace.unionWith({
  108. VAttribute: ["key", "value"],
  109. VDirectiveKey: ["name", "argument", "modifiers"],
  110. VDocumentFragment: ["children"],
  111. VElement: ["startTag", "children", "endTag"],
  112. VEndTag: [],
  113. VExpressionContainer: ["expression"],
  114. VFilter: ["callee", "arguments"],
  115. VFilterSequenceExpression: ["expression", "filters"],
  116. VForExpression: ["left", "right"],
  117. VIdentifier: [],
  118. VLiteral: [],
  119. VOnExpression: ["body"],
  120. VSlotScopeExpression: ["params"],
  121. VStartTag: ["attributes"],
  122. VText: [],
  123. });
  124. function fallbackKeysFilter(key) {
  125. let value = null;
  126. return (key !== "comments" &&
  127. key !== "leadingComments" &&
  128. key !== "loc" &&
  129. key !== "parent" &&
  130. key !== "range" &&
  131. key !== "tokens" &&
  132. key !== "trailingComments" &&
  133. (value = this[key]) !== null &&
  134. typeof value === "object" &&
  135. (typeof value.type === "string" || Array.isArray(value)));
  136. }
  137. function getFallbackKeys(node) {
  138. return Object.keys(node).filter(fallbackKeysFilter, node);
  139. }
  140. function isNode(x) {
  141. return x !== null && typeof x === "object" && typeof x.type === "string";
  142. }
  143. function traverse(node, parent, visitor) {
  144. let i = 0;
  145. let j = 0;
  146. visitor.enterNode(node, parent);
  147. const keys = (visitor.visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
  148. for (i = 0; i < keys.length; ++i) {
  149. const child = node[keys[i]];
  150. if (Array.isArray(child)) {
  151. for (j = 0; j < child.length; ++j) {
  152. if (isNode(child[j])) {
  153. traverse(child[j], node, visitor);
  154. }
  155. }
  156. }
  157. else if (isNode(child)) {
  158. traverse(child, node, visitor);
  159. }
  160. }
  161. visitor.leaveNode(node, parent);
  162. }
  163. function traverseNodes(node, visitor) {
  164. traverse(node, null, visitor);
  165. }
  166. var index = /*#__PURE__*/Object.freeze({
  167. __proto__: null,
  168. ParseError: ParseError,
  169. NS: NS,
  170. KEYS: KEYS,
  171. traverseNodes: traverseNodes,
  172. getFallbackKeys: getFallbackKeys
  173. });
  174. class LinesAndColumns {
  175. constructor(ltOffsets) {
  176. this.ltOffsets = ltOffsets;
  177. }
  178. getLocFromIndex(index) {
  179. const line = sortedLastIndex__default["default"](this.ltOffsets, index) + 1;
  180. const column = index - (line === 1 ? 0 : this.ltOffsets[line - 2]);
  181. return { line, column };
  182. }
  183. createOffsetLocationCalculator(offset) {
  184. return {
  185. getFixOffset() {
  186. return offset;
  187. },
  188. getLocFromIndex: this.getLocFromIndex.bind(this),
  189. };
  190. }
  191. }
  192. class LocationCalculatorForHtml extends LinesAndColumns {
  193. constructor(gapOffsets, ltOffsets, baseOffset, shiftOffset = 0) {
  194. super(ltOffsets);
  195. this.gapOffsets = gapOffsets;
  196. this.ltOffsets = ltOffsets;
  197. this.baseOffset = baseOffset || 0;
  198. this.baseIndexOfGap =
  199. this.baseOffset === 0
  200. ? 0
  201. : sortedLastIndex__default["default"](gapOffsets, this.baseOffset);
  202. this.shiftOffset = shiftOffset;
  203. }
  204. getSubCalculatorAfter(offset) {
  205. return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset + offset, this.shiftOffset);
  206. }
  207. getSubCalculatorShift(offset) {
  208. return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset, this.shiftOffset + offset);
  209. }
  210. _getGap(index) {
  211. const offsets = this.gapOffsets;
  212. let g0 = sortedLastIndex__default["default"](offsets, index + this.baseOffset);
  213. let pos = index + this.baseOffset + g0 - this.baseIndexOfGap;
  214. while (g0 < offsets.length && offsets[g0] <= pos) {
  215. g0 += 1;
  216. pos += 1;
  217. }
  218. return g0 - this.baseIndexOfGap;
  219. }
  220. getLocation(index) {
  221. return this.getLocFromIndex(this.getOffsetWithGap(index));
  222. }
  223. getOffsetWithGap(index) {
  224. return index + this.getFixOffset(index);
  225. }
  226. getFixOffset(offset) {
  227. const shiftOffset = this.shiftOffset;
  228. const gap = this._getGap(offset + shiftOffset);
  229. return this.baseOffset + gap + shiftOffset;
  230. }
  231. }
  232. const debug = debugFactory__default["default"]("vue-eslint-parser");
  233. function isScriptElement(node) {
  234. return node.type === "VElement" && node.name === "script";
  235. }
  236. function isScriptSetupElement(script) {
  237. return (isScriptElement(script) &&
  238. script.startTag.attributes.some((attr) => !attr.directive && attr.key.name === "setup"));
  239. }
  240. function isTemplateElement(node) {
  241. return node.type === "VElement" && node.name === "template";
  242. }
  243. function isStyleElement(node) {
  244. return node.type === "VElement" && node.name === "style";
  245. }
  246. function getOwnerDocument(leafNode) {
  247. let node = leafNode;
  248. while (node != null && node.type !== "VDocumentFragment") {
  249. node = node.parent;
  250. }
  251. return node;
  252. }
  253. function isLang(attribute) {
  254. return attribute.directive === false && attribute.key.name === "lang";
  255. }
  256. function getLang(element) {
  257. const langAttr = element && element.startTag.attributes.find(isLang);
  258. const lang = langAttr && langAttr.value && langAttr.value.value;
  259. return lang || null;
  260. }
  261. function isParserObject(value) {
  262. return isEnhancedParserObject(value) || isBasicParserObject(value);
  263. }
  264. function isEnhancedParserObject(value) {
  265. return Boolean(value && typeof value.parseForESLint === "function");
  266. }
  267. function isBasicParserObject(value) {
  268. return Boolean(value && typeof value.parse === "function");
  269. }
  270. function isSFCFile(parserOptions) {
  271. if (parserOptions.filePath === "<input>") {
  272. return true;
  273. }
  274. return path__namespace.extname(parserOptions.filePath || "unknown.vue") === ".vue";
  275. }
  276. function getScriptParser(parser, getParserLang) {
  277. if (isParserObject(parser)) {
  278. return parser;
  279. }
  280. if (parser && typeof parser === "object") {
  281. const parserLang = getParserLang();
  282. const parserLangs = parserLang == null
  283. ? []
  284. : typeof parserLang === "string"
  285. ? [parserLang]
  286. : parserLang;
  287. for (const lang of parserLangs) {
  288. const parserForLang = lang && parser[lang];
  289. if (typeof parserForLang === "string" ||
  290. isParserObject(parserForLang)) {
  291. return parserForLang;
  292. }
  293. }
  294. return parser.js;
  295. }
  296. return typeof parser === "string" ? parser : undefined;
  297. }
  298. function getParserLangFromSFC(doc) {
  299. if (doc) {
  300. const scripts = doc.children.filter(isScriptElement);
  301. const script = (scripts.length === 2 && scripts.find(isScriptSetupElement)) ||
  302. scripts[0];
  303. if (script) {
  304. return getLang(script);
  305. }
  306. }
  307. return null;
  308. }
  309. const createRequire = Module__default["default"].createRequire ||
  310. Module__default["default"].createRequireFromPath ||
  311. ((modname) => {
  312. const mod = new Module__default["default"](modname);
  313. mod.filename = modname;
  314. mod.paths = Module__default["default"]._nodeModulePaths(path__default["default"].dirname(modname));
  315. mod._compile("module.exports = require;", modname);
  316. return mod.exports;
  317. });
  318. function isLinterPath(p) {
  319. return (p.includes(`eslint${path__default["default"].sep}lib${path__default["default"].sep}linter${path__default["default"].sep}linter.js`) ||
  320. p.includes(`eslint${path__default["default"].sep}lib${path__default["default"].sep}linter.js`));
  321. }
  322. function getLinterRequire() {
  323. const linterPath = Object.keys(require.cache).find(isLinterPath);
  324. if (linterPath) {
  325. try {
  326. return createRequire(linterPath);
  327. }
  328. catch (_a) {
  329. }
  330. }
  331. return null;
  332. }
  333. let escopeCache = null;
  334. function getEslintScope() {
  335. var _a;
  336. if (!escopeCache) {
  337. escopeCache = (_a = getLinterRequire()) === null || _a === void 0 ? void 0 : _a("eslint-scope");
  338. if (!escopeCache ||
  339. escopeCache.version == null ||
  340. semver.lte(escopeCache.version, escope__namespace.version)) {
  341. escopeCache = escope__namespace;
  342. }
  343. }
  344. return escopeCache;
  345. }
  346. let espreeCache = null;
  347. function getEspreeFromEcmaVersion(ecmaVersion) {
  348. const linterEspree = getEspreeFromLinter();
  349. if (ecmaVersion == null) {
  350. return linterEspree;
  351. }
  352. if (ecmaVersion === "latest") {
  353. return getNewestEspree();
  354. }
  355. if (normalizeEcmaVersion(ecmaVersion) <= getLatestEcmaVersion(linterEspree)) {
  356. return linterEspree;
  357. }
  358. const userEspree = getEspreeFromUser();
  359. if (normalizeEcmaVersion(ecmaVersion) <= getLatestEcmaVersion(userEspree)) {
  360. return userEspree;
  361. }
  362. return linterEspree;
  363. }
  364. function getEspreeFromUser() {
  365. try {
  366. const cwd = process.cwd();
  367. const relativeTo = path__default["default"].join(cwd, "__placeholder__.js");
  368. return createRequire(relativeTo)("espree");
  369. }
  370. catch (_a) {
  371. return getEspreeFromLinter();
  372. }
  373. }
  374. function getEspreeFromLinter() {
  375. var _a;
  376. if (!espreeCache) {
  377. espreeCache = (_a = getLinterRequire()) === null || _a === void 0 ? void 0 : _a("espree");
  378. if (!espreeCache) {
  379. espreeCache = dependencyEspree__namespace;
  380. }
  381. }
  382. return espreeCache;
  383. }
  384. function getNewestEspree() {
  385. let newest = dependencyEspree__namespace;
  386. const linterEspree = getEspreeFromLinter();
  387. if (linterEspree.version != null &&
  388. semver.lte(newest.version, linterEspree.version)) {
  389. newest = linterEspree;
  390. }
  391. const userEspree = getEspreeFromUser();
  392. if (userEspree.version != null && semver.lte(newest.version, userEspree.version)) {
  393. newest = userEspree;
  394. }
  395. return newest;
  396. }
  397. function getEcmaVersionIfUseEspree(parserOptions, getDefault) {
  398. var _a;
  399. if (parserOptions.parser != null && parserOptions.parser !== "espree") {
  400. return undefined;
  401. }
  402. if (parserOptions.ecmaVersion === "latest") {
  403. return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()));
  404. }
  405. if (parserOptions.ecmaVersion == null) {
  406. const defVer = getDefaultEcmaVersion$1();
  407. return (_a = getDefault === null || getDefault === void 0 ? void 0 : getDefault(defVer)) !== null && _a !== void 0 ? _a : defVer;
  408. }
  409. return normalizeEcmaVersion(parserOptions.ecmaVersion);
  410. }
  411. function getDefaultEcmaVersion$1() {
  412. if (semver.lt(getEspreeFromLinter().version, "9.0.0")) {
  413. return 5;
  414. }
  415. return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()));
  416. }
  417. function normalizeEcmaVersion(version) {
  418. if (version > 5 && version < 2015) {
  419. return version + 2009;
  420. }
  421. return version;
  422. }
  423. function getLatestEcmaVersion(espree) {
  424. if (espree.latestEcmaVersion == null) {
  425. for (const { v, latest } of [
  426. { v: "6.1.0", latest: 2020 },
  427. { v: "4.0.0", latest: 2019 },
  428. ]) {
  429. if (semver.lte(v, espree.version)) {
  430. return latest;
  431. }
  432. }
  433. return 2018;
  434. }
  435. return normalizeEcmaVersion(espree.latestEcmaVersion);
  436. }
  437. function isUnique(reference, index, references) {
  438. return (index === 0 || reference.identifier !== references[index - 1].identifier);
  439. }
  440. function hasDefinition(variable) {
  441. return variable.defs.length >= 1;
  442. }
  443. function transformReference(reference) {
  444. const ret = {
  445. id: reference.identifier,
  446. mode: reference.isReadOnly()
  447. ? "r"
  448. : reference.isWriteOnly()
  449. ? "w"
  450. : "rw",
  451. variable: null,
  452. isValueReference: reference.isValueReference,
  453. isTypeReference: reference.isTypeReference,
  454. };
  455. Object.defineProperty(ret, "variable", { enumerable: false });
  456. return ret;
  457. }
  458. function transformVariable(variable) {
  459. const ret = {
  460. id: variable.defs[0].name,
  461. kind: variable.scope.type === "for" ? "v-for" : "scope",
  462. references: [],
  463. };
  464. Object.defineProperty(ret, "references", { enumerable: false });
  465. return ret;
  466. }
  467. function getForScope(scope) {
  468. const child = scope.childScopes[0];
  469. return child.block === scope.block ? child.childScopes[0] : child;
  470. }
  471. function analyzeScope(ast, parserOptions) {
  472. const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022;
  473. const ecmaFeatures = parserOptions.ecmaFeatures || {};
  474. const sourceType = parserOptions.sourceType || "script";
  475. const result = getEslintScope().analyze(ast, {
  476. ignoreEval: true,
  477. nodejsScope: false,
  478. impliedStrict: ecmaFeatures.impliedStrict,
  479. ecmaVersion,
  480. sourceType,
  481. fallback: getFallbackKeys,
  482. });
  483. return result;
  484. }
  485. function analyze(parserResult, parserOptions) {
  486. const scopeManager = parserResult.scopeManager ||
  487. analyzeScope(parserResult.ast, parserOptions);
  488. return scopeManager.globalScope;
  489. }
  490. function analyzeExternalReferences(parserResult, parserOptions) {
  491. const scope = analyze(parserResult, parserOptions);
  492. return scope.through.filter(isUnique).map(transformReference);
  493. }
  494. function analyzeVariablesAndExternalReferences(parserResult, parserOptions) {
  495. const scope = analyze(parserResult, parserOptions);
  496. return {
  497. variables: getForScope(scope)
  498. .variables.filter(hasDefinition)
  499. .map(transformVariable),
  500. references: scope.through.filter(isUnique).map(transformReference),
  501. };
  502. }
  503. function fixLocations(result, locationCalculator) {
  504. fixNodeLocations(result.ast, result.visitorKeys, locationCalculator);
  505. for (const token of result.ast.tokens || []) {
  506. fixLocation(token, locationCalculator);
  507. }
  508. for (const comment of result.ast.comments || []) {
  509. fixLocation(comment, locationCalculator);
  510. }
  511. }
  512. function fixNodeLocations(rootNode, visitorKeys, locationCalculator) {
  513. const traversed = new Map();
  514. traverseNodes(rootNode, {
  515. visitorKeys,
  516. enterNode(node, parent) {
  517. if (!traversed.has(node)) {
  518. traversed.set(node, node);
  519. node.parent = parent;
  520. if (traversed.has(node.range)) {
  521. if (!traversed.has(node.loc)) {
  522. node.loc.start = locationCalculator.getLocFromIndex(node.range[0]);
  523. node.loc.end = locationCalculator.getLocFromIndex(node.range[1]);
  524. traversed.set(node.loc, node);
  525. }
  526. else if (node.start != null || node.end != null) {
  527. const traversedNode = traversed.get(node.range);
  528. if (traversedNode.type === node.type) {
  529. node.start = traversedNode.start;
  530. node.end = traversedNode.end;
  531. }
  532. }
  533. }
  534. else {
  535. fixLocation(node, locationCalculator);
  536. traversed.set(node.range, node);
  537. traversed.set(node.loc, node);
  538. }
  539. }
  540. },
  541. leaveNode() {
  542. },
  543. });
  544. }
  545. function fixLocation(node, locationCalculator) {
  546. const range = node.range;
  547. const loc = node.loc;
  548. const d0 = locationCalculator.getFixOffset(range[0], "start");
  549. const d1 = locationCalculator.getFixOffset(range[1], "end");
  550. if (d0 !== 0) {
  551. range[0] += d0;
  552. if (node.start != null) {
  553. node.start += d0;
  554. }
  555. loc.start = locationCalculator.getLocFromIndex(range[0]);
  556. }
  557. if (d1 !== 0) {
  558. range[1] += d1;
  559. if (node.end != null) {
  560. node.end += d0;
  561. }
  562. loc.end = locationCalculator.getLocFromIndex(range[1]);
  563. }
  564. return node;
  565. }
  566. function fixErrorLocation(error, locationCalculator) {
  567. const diff = locationCalculator.getFixOffset(error.index, "start");
  568. error.index += diff;
  569. const loc = locationCalculator.getLocFromIndex(error.index);
  570. error.lineNumber = loc.line;
  571. error.column = loc.column;
  572. }
  573. const DEFAULT_ECMA_VERSION = 2017;
  574. function getScriptSetupParserOptions(parserOptions) {
  575. const espreeEcmaVersion = getEcmaVersionIfUseEspree(parserOptions, getDefaultEcmaVersion);
  576. return Object.assign(Object.assign({}, parserOptions), { ecmaVersion: espreeEcmaVersion });
  577. }
  578. function getDefaultEcmaVersion(def) {
  579. if (semver.lte("8.0.0", getEspreeFromUser().version)) {
  580. return getEspreeFromUser().latestEcmaVersion;
  581. }
  582. return Math.max(def, DEFAULT_ECMA_VERSION);
  583. }
  584. const ALIAS_ITERATOR = /^([\s\S]*?(?:\s|\)))(\bin\b|\bof\b)([\s\S]*)$/u;
  585. const PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u;
  586. const DUMMY_PARENT$2 = {};
  587. const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/u;
  588. const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u;
  589. function processVForAliasAndIterator(code) {
  590. const match = ALIAS_ITERATOR.exec(code);
  591. if (match != null) {
  592. const aliases = match[1];
  593. const parenMatch = PARENS.exec(aliases);
  594. return {
  595. aliases,
  596. hasParens: Boolean(parenMatch),
  597. aliasesWithBrackets: parenMatch
  598. ? `${parenMatch[1].slice(0, -1)}[${parenMatch[2]}]${parenMatch[3].slice(1)}`
  599. : `[${aliases.slice(0, -1)}]`,
  600. delimiter: match[2] || "",
  601. iterator: match[3],
  602. };
  603. }
  604. return {
  605. aliases: "",
  606. hasParens: false,
  607. aliasesWithBrackets: "",
  608. delimiter: "",
  609. iterator: code,
  610. };
  611. }
  612. function getCommaTokenBeforeNode(tokens, node) {
  613. let tokenIndex = sortedIndexBy__default["default"](tokens, { range: node.range }, (t) => t.range[0]);
  614. while (tokenIndex >= 0) {
  615. const token = tokens[tokenIndex];
  616. if (token.type === "Punctuator" && token.value === ",") {
  617. return token;
  618. }
  619. tokenIndex -= 1;
  620. }
  621. return null;
  622. }
  623. function throwEmptyError(locationCalculator, expected) {
  624. const loc = locationCalculator.getLocation(0);
  625. const err = new ParseError(`Expected to be ${expected}, but got empty.`, undefined, 0, loc.line, loc.column);
  626. fixErrorLocation(err, locationCalculator);
  627. throw err;
  628. }
  629. function throwUnexpectedTokenError(name, token) {
  630. const err = new ParseError(`Unexpected token '${name}'.`, undefined, token.range[0], token.loc.start.line, token.loc.start.column);
  631. throw err;
  632. }
  633. function throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator) {
  634. if (ParseError.isParseError(err)) {
  635. const endOffset = locationCalculator.getOffsetWithGap(code.length);
  636. if (err.index >= endOffset) {
  637. err.message = "Unexpected end of expression.";
  638. }
  639. }
  640. throw err;
  641. }
  642. function parseScriptFragment(code, locationCalculator, parserOptions) {
  643. try {
  644. const result = parseScript$1(code, parserOptions);
  645. fixLocations(result, locationCalculator);
  646. return result;
  647. }
  648. catch (err) {
  649. const perr = ParseError.normalize(err);
  650. if (perr) {
  651. fixErrorLocation(perr, locationCalculator);
  652. throw perr;
  653. }
  654. throw err;
  655. }
  656. }
  657. const validDivisionCharRE = /[\w).+\-_$\]]/u;
  658. function splitFilters(exp) {
  659. const result = [];
  660. let inSingle = false;
  661. let inDouble = false;
  662. let inTemplateString = false;
  663. let inRegex = false;
  664. let curly = 0;
  665. let square = 0;
  666. let paren = 0;
  667. let lastFilterIndex = 0;
  668. let c = 0;
  669. let prev = 0;
  670. for (let i = 0; i < exp.length; i++) {
  671. prev = c;
  672. c = exp.charCodeAt(i);
  673. if (inSingle) {
  674. if (c === 0x27 && prev !== 0x5c) {
  675. inSingle = false;
  676. }
  677. }
  678. else if (inDouble) {
  679. if (c === 0x22 && prev !== 0x5c) {
  680. inDouble = false;
  681. }
  682. }
  683. else if (inTemplateString) {
  684. if (c === 0x60 && prev !== 0x5c) {
  685. inTemplateString = false;
  686. }
  687. }
  688. else if (inRegex) {
  689. if (c === 0x2f && prev !== 0x5c) {
  690. inRegex = false;
  691. }
  692. }
  693. else if (c === 0x7c &&
  694. exp.charCodeAt(i + 1) !== 0x7c &&
  695. exp.charCodeAt(i - 1) !== 0x7c &&
  696. !curly &&
  697. !square &&
  698. !paren) {
  699. result.push(exp.slice(lastFilterIndex, i));
  700. lastFilterIndex = i + 1;
  701. }
  702. else {
  703. switch (c) {
  704. case 0x22:
  705. inDouble = true;
  706. break;
  707. case 0x27:
  708. inSingle = true;
  709. break;
  710. case 0x60:
  711. inTemplateString = true;
  712. break;
  713. case 0x28:
  714. paren++;
  715. break;
  716. case 0x29:
  717. paren--;
  718. break;
  719. case 0x5b:
  720. square++;
  721. break;
  722. case 0x5d:
  723. square--;
  724. break;
  725. case 0x7b:
  726. curly++;
  727. break;
  728. case 0x7d:
  729. curly--;
  730. break;
  731. }
  732. if (c === 0x2f) {
  733. let j = i - 1;
  734. let p;
  735. for (; j >= 0; j--) {
  736. p = exp.charAt(j);
  737. if (p !== " ") {
  738. break;
  739. }
  740. }
  741. if (!p || !validDivisionCharRE.test(p)) {
  742. inRegex = true;
  743. }
  744. }
  745. }
  746. }
  747. result.push(exp.slice(lastFilterIndex));
  748. return result;
  749. }
  750. function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) {
  751. debug('[script] parse expression: "0(%s)"', code);
  752. try {
  753. const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
  754. const { ast } = result;
  755. const tokens = ast.tokens || [];
  756. const comments = ast.comments || [];
  757. const references = analyzeExternalReferences(result, parserOptions);
  758. const statement = ast.body[0];
  759. const callExpression = statement.expression;
  760. const expression = callExpression.arguments[0];
  761. if (!allowEmpty && !expression) {
  762. return throwEmptyError(locationCalculator, "an expression");
  763. }
  764. if (expression && expression.type === "SpreadElement") {
  765. return throwUnexpectedTokenError("...", expression);
  766. }
  767. if (callExpression.arguments[1]) {
  768. const node = callExpression.arguments[1];
  769. return throwUnexpectedTokenError(",", getCommaTokenBeforeNode(tokens, node) || node);
  770. }
  771. tokens.shift();
  772. tokens.shift();
  773. tokens.pop();
  774. return { expression, tokens, comments, references, variables: [] };
  775. }
  776. catch (err) {
  777. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  778. }
  779. }
  780. function parseFilter(code, locationCalculator, parserOptions) {
  781. debug('[script] parse filter: "%s"', code);
  782. try {
  783. const expression = {
  784. type: "VFilter",
  785. parent: null,
  786. range: [0, 0],
  787. loc: {},
  788. callee: null,
  789. arguments: [],
  790. };
  791. const tokens = [];
  792. const comments = [];
  793. const references = [];
  794. const paren = code.indexOf("(");
  795. const calleeCode = paren === -1 ? code : code.slice(0, paren);
  796. const argsCode = paren === -1 ? null : code.slice(paren);
  797. if (calleeCode.trim()) {
  798. const spaces = /^\s*/u.exec(calleeCode)[0];
  799. const subCalculator = locationCalculator.getSubCalculatorShift(spaces.length);
  800. const { ast } = parseScriptFragment(`"${calleeCode.trim()}"`, subCalculator, parserOptions);
  801. const statement = ast.body[0];
  802. const callee = statement.expression;
  803. if (callee.type !== "Literal") {
  804. const { loc, range } = ast.tokens[0];
  805. return throwUnexpectedTokenError('"', {
  806. range: [range[1] - 1, range[1]],
  807. loc: {
  808. start: {
  809. line: loc.end.line,
  810. column: loc.end.column - 1,
  811. },
  812. end: loc.end,
  813. },
  814. });
  815. }
  816. expression.callee = {
  817. type: "Identifier",
  818. parent: expression,
  819. range: [
  820. callee.range[0],
  821. subCalculator.getOffsetWithGap(calleeCode.trim().length),
  822. ],
  823. loc: {
  824. start: callee.loc.start,
  825. end: subCalculator.getLocation(calleeCode.trim().length),
  826. },
  827. name: String(callee.value),
  828. };
  829. tokens.push({
  830. type: "Identifier",
  831. value: calleeCode.trim(),
  832. range: expression.callee.range,
  833. loc: expression.callee.loc,
  834. });
  835. }
  836. else {
  837. return throwEmptyError(locationCalculator, "a filter name");
  838. }
  839. if (argsCode != null) {
  840. const result = parseScriptFragment(`0${argsCode}`, locationCalculator
  841. .getSubCalculatorAfter(paren)
  842. .getSubCalculatorShift(-1), parserOptions);
  843. const { ast } = result;
  844. const statement = ast.body[0];
  845. const callExpression = statement.expression;
  846. ast.tokens.shift();
  847. if (callExpression.type !== "CallExpression" ||
  848. callExpression.callee.type !== "Literal") {
  849. let nestCount = 1;
  850. for (const token of ast.tokens.slice(1)) {
  851. if (nestCount === 0) {
  852. return throwUnexpectedTokenError(token.value, token);
  853. }
  854. if (token.type === "Punctuator" && token.value === "(") {
  855. nestCount += 1;
  856. }
  857. if (token.type === "Punctuator" && token.value === ")") {
  858. nestCount -= 1;
  859. }
  860. }
  861. const token = last__default["default"](ast.tokens);
  862. return throwUnexpectedTokenError(token.value, token);
  863. }
  864. for (const argument of callExpression.arguments) {
  865. argument.parent = expression;
  866. expression.arguments.push(argument);
  867. }
  868. tokens.push(...ast.tokens);
  869. comments.push(...ast.comments);
  870. references.push(...analyzeExternalReferences(result, parserOptions));
  871. }
  872. const firstToken = tokens[0];
  873. const lastToken = last__default["default"](tokens);
  874. expression.range = [firstToken.range[0], lastToken.range[1]];
  875. expression.loc = { start: firstToken.loc.start, end: lastToken.loc.end };
  876. return { expression, tokens, comments, references, variables: [] };
  877. }
  878. catch (err) {
  879. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  880. }
  881. }
  882. function loadParser(parser) {
  883. if (parser !== "espree") {
  884. return require(parser);
  885. }
  886. return getEspreeFromUser();
  887. }
  888. function parseScript$1(code, parserOptions) {
  889. const parser = typeof parserOptions.parser === "string"
  890. ? loadParser(parserOptions.parser)
  891. : isParserObject(parserOptions.parser)
  892. ? parserOptions.parser
  893. : getEspreeFromEcmaVersion(parserOptions.ecmaVersion);
  894. const result = isEnhancedParserObject(parser)
  895. ? parser.parseForESLint(code, parserOptions)
  896. : parser.parse(code, parserOptions);
  897. if (result.ast != null) {
  898. return result;
  899. }
  900. return { ast: result };
  901. }
  902. function parseScriptElement(node, sfcCode, linesAndColumns, originalParserOptions) {
  903. const parserOptions = isScriptSetupElement(node)
  904. ? getScriptSetupParserOptions(originalParserOptions)
  905. : Object.assign(Object.assign({}, originalParserOptions), { ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION });
  906. let code;
  907. let offset;
  908. const textNode = node.children[0];
  909. if (textNode != null && textNode.type === "VText") {
  910. const [scriptStartOffset, scriptEndOffset] = textNode.range;
  911. code = sfcCode.slice(scriptStartOffset, scriptEndOffset);
  912. offset = scriptStartOffset;
  913. }
  914. else {
  915. code = "";
  916. offset = node.startTag.range[1];
  917. }
  918. const locationCalculator = linesAndColumns.createOffsetLocationCalculator(offset);
  919. const result = parseScriptFragment(code, locationCalculator, parserOptions);
  920. if (result.ast.tokens != null) {
  921. const startTag = node.startTag;
  922. const endTag = node.endTag;
  923. result.ast.tokens.unshift({
  924. type: "Punctuator",
  925. range: startTag.range,
  926. loc: startTag.loc,
  927. value: "<script>",
  928. });
  929. if (endTag != null) {
  930. result.ast.tokens.push({
  931. type: "Punctuator",
  932. range: endTag.range,
  933. loc: endTag.loc,
  934. value: "</script>",
  935. });
  936. }
  937. }
  938. return result;
  939. }
  940. function parseExpression(code, locationCalculator, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
  941. var _a, _b;
  942. debug('[script] parse expression: "%s"', code);
  943. const [mainCode, ...filterCodes] = allowFilters && ((_b = (_a = parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.filter) !== null && _b !== void 0 ? _b : true)
  944. ? splitFilters(code)
  945. : [code];
  946. if (filterCodes.length === 0) {
  947. return parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty);
  948. }
  949. const retB = parseExpressionBody(mainCode, locationCalculator, parserOptions);
  950. if (!retB.expression) {
  951. return retB;
  952. }
  953. const ret = retB;
  954. ret.expression = {
  955. type: "VFilterSequenceExpression",
  956. parent: null,
  957. expression: retB.expression,
  958. filters: [],
  959. range: retB.expression.range.slice(0),
  960. loc: Object.assign({}, retB.expression.loc),
  961. };
  962. ret.expression.expression.parent = ret.expression;
  963. let prevLoc = mainCode.length;
  964. for (const filterCode of filterCodes) {
  965. ret.tokens.push(fixLocation({
  966. type: "Punctuator",
  967. value: "|",
  968. range: [prevLoc, prevLoc + 1],
  969. loc: {},
  970. }, locationCalculator));
  971. const retF = parseFilter(filterCode, locationCalculator.getSubCalculatorShift(prevLoc + 1), parserOptions);
  972. if (retF) {
  973. if (retF.expression) {
  974. ret.expression.filters.push(retF.expression);
  975. retF.expression.parent = ret.expression;
  976. }
  977. ret.tokens.push(...retF.tokens);
  978. ret.comments.push(...retF.comments);
  979. ret.references.push(...retF.references);
  980. }
  981. prevLoc += 1 + filterCode.length;
  982. }
  983. const lastToken = last__default["default"](ret.tokens);
  984. ret.expression.range[1] = lastToken.range[1];
  985. ret.expression.loc.end = lastToken.loc.end;
  986. return ret;
  987. }
  988. function parseVForExpression(code, locationCalculator, parserOptions) {
  989. if (code.trim() === "") {
  990. throwEmptyError(locationCalculator, "'<alias> in <expression>'");
  991. }
  992. if (isEcmaVersion5(parserOptions)) {
  993. return parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions);
  994. }
  995. const processed = processVForAliasAndIterator(code);
  996. if (!processed.aliases.trim()) {
  997. return throwEmptyError(locationCalculator, "an alias");
  998. }
  999. try {
  1000. debug('[script] parse v-for expression: "for(%s%s%s);"', processed.aliasesWithBrackets, processed.delimiter, processed.iterator);
  1001. const result = parseScriptFragment(`for(let ${processed.aliasesWithBrackets}${processed.delimiter}${processed.iterator});`, locationCalculator.getSubCalculatorShift(processed.hasParens ? -8 : -9), parserOptions);
  1002. const { ast } = result;
  1003. const tokens = ast.tokens || [];
  1004. const comments = ast.comments || [];
  1005. const scope = analyzeVariablesAndExternalReferences(result, parserOptions);
  1006. const references = scope.references;
  1007. const variables = scope.variables;
  1008. const statement = ast.body[0];
  1009. const varDecl = statement.left;
  1010. const id = varDecl.declarations[0].id;
  1011. const left = id.elements;
  1012. const right = statement.right;
  1013. if (!processed.hasParens && !left.length) {
  1014. return throwEmptyError(locationCalculator, "an alias");
  1015. }
  1016. tokens.shift();
  1017. tokens.shift();
  1018. tokens.shift();
  1019. tokens.pop();
  1020. tokens.pop();
  1021. const closeOffset = statement.left.range[1] - 1;
  1022. const closeIndex = tokens.findIndex((t) => t.range[0] === closeOffset);
  1023. if (processed.hasParens) {
  1024. const open = tokens[0];
  1025. if (open != null) {
  1026. open.value = "(";
  1027. }
  1028. const close = tokens[closeIndex];
  1029. if (close != null) {
  1030. close.value = ")";
  1031. }
  1032. }
  1033. else {
  1034. tokens.splice(closeIndex, 1);
  1035. tokens.shift();
  1036. }
  1037. const firstToken = tokens[0] || statement.left;
  1038. const lastToken = tokens[tokens.length - 1] || statement.right;
  1039. const expression = {
  1040. type: "VForExpression",
  1041. range: [firstToken.range[0], lastToken.range[1]],
  1042. loc: { start: firstToken.loc.start, end: lastToken.loc.end },
  1043. parent: DUMMY_PARENT$2,
  1044. left,
  1045. right,
  1046. };
  1047. for (const l of left) {
  1048. if (l != null) {
  1049. l.parent = expression;
  1050. }
  1051. }
  1052. right.parent = expression;
  1053. return { expression, tokens, comments, references, variables };
  1054. }
  1055. catch (err) {
  1056. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1057. }
  1058. }
  1059. function isEcmaVersion5(parserOptions) {
  1060. const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions);
  1061. return ecmaVersion != null && ecmaVersion <= 5;
  1062. }
  1063. function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions) {
  1064. const processed = processVForAliasAndIterator(code);
  1065. if (!processed.aliases.trim()) {
  1066. return throwEmptyError(locationCalculator, "an alias");
  1067. }
  1068. try {
  1069. const tokens = [];
  1070. const comments = [];
  1071. const parsedAliases = parseVForAliasesForEcmaVersion5(processed.aliasesWithBrackets, locationCalculator.getSubCalculatorShift(processed.hasParens ? 0 : -1), parserOptions);
  1072. if (processed.hasParens) {
  1073. const open = parsedAliases.tokens[0];
  1074. if (open != null) {
  1075. open.value = "(";
  1076. }
  1077. const close = last__default["default"](parsedAliases.tokens);
  1078. if (close != null) {
  1079. close.value = ")";
  1080. }
  1081. }
  1082. else {
  1083. parsedAliases.tokens.shift();
  1084. parsedAliases.tokens.pop();
  1085. }
  1086. tokens.push(...parsedAliases.tokens);
  1087. comments.push(...parsedAliases.comments);
  1088. const { left, variables } = parsedAliases;
  1089. if (!processed.hasParens && !left.length) {
  1090. return throwEmptyError(locationCalculator, "an alias");
  1091. }
  1092. const delimiterStart = processed.aliases.length;
  1093. const delimiterEnd = delimiterStart + processed.delimiter.length;
  1094. tokens.push(fixLocation({
  1095. type: processed.delimiter === "in" ? "Keyword" : "Identifier",
  1096. value: processed.delimiter,
  1097. start: delimiterStart,
  1098. end: delimiterEnd,
  1099. loc: {},
  1100. range: [delimiterStart, delimiterEnd],
  1101. }, locationCalculator));
  1102. const parsedIterator = parseVForIteratorForEcmaVersion5(processed.iterator, locationCalculator.getSubCalculatorShift(delimiterEnd), parserOptions);
  1103. tokens.push(...parsedIterator.tokens);
  1104. comments.push(...parsedIterator.comments);
  1105. const { right, references } = parsedIterator;
  1106. const firstToken = tokens[0];
  1107. const lastToken = last__default["default"](tokens) || firstToken;
  1108. const expression = {
  1109. type: "VForExpression",
  1110. range: [firstToken.range[0], lastToken.range[1]],
  1111. loc: { start: firstToken.loc.start, end: lastToken.loc.end },
  1112. parent: DUMMY_PARENT$2,
  1113. left,
  1114. right,
  1115. };
  1116. for (const l of left) {
  1117. if (l != null) {
  1118. l.parent = expression;
  1119. }
  1120. }
  1121. right.parent = expression;
  1122. return { expression, tokens, comments, references, variables };
  1123. }
  1124. catch (err) {
  1125. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1126. }
  1127. }
  1128. function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions) {
  1129. const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
  1130. const { ast } = result;
  1131. const tokens = ast.tokens || [];
  1132. const comments = ast.comments || [];
  1133. const variables = analyzeExternalReferences(result, parserOptions).map(transformVariable);
  1134. const statement = ast.body[0];
  1135. const callExpression = statement.expression;
  1136. const expression = callExpression.arguments[0];
  1137. const left = expression.elements.filter((e) => {
  1138. if (e == null || e.type === "Identifier") {
  1139. return true;
  1140. }
  1141. const errorToken = tokens.find((t) => e.range[0] <= t.range[0] && t.range[1] <= e.range[1]);
  1142. return throwUnexpectedTokenError(errorToken.value, errorToken);
  1143. });
  1144. tokens.shift();
  1145. tokens.shift();
  1146. tokens.pop();
  1147. return { left, tokens, comments, variables };
  1148. function transformVariable(reference) {
  1149. const ret = {
  1150. id: reference.id,
  1151. kind: "v-for",
  1152. references: [],
  1153. };
  1154. Object.defineProperty(ret, "references", { enumerable: false });
  1155. return ret;
  1156. }
  1157. }
  1158. function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOptions) {
  1159. const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
  1160. const { ast } = result;
  1161. const tokens = ast.tokens || [];
  1162. const comments = ast.comments || [];
  1163. const references = analyzeExternalReferences(result, parserOptions);
  1164. const statement = ast.body[0];
  1165. const callExpression = statement.expression;
  1166. const expression = callExpression.arguments[0];
  1167. if (!expression) {
  1168. return throwEmptyError(locationCalculator, "an expression");
  1169. }
  1170. if (expression && expression.type === "SpreadElement") {
  1171. return throwUnexpectedTokenError("...", expression);
  1172. }
  1173. const right = expression;
  1174. tokens.shift();
  1175. tokens.shift();
  1176. tokens.pop();
  1177. return { right, tokens, comments, references };
  1178. }
  1179. function parseVOnExpression(code, locationCalculator, parserOptions) {
  1180. if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) {
  1181. return parseExpressionBody(code, locationCalculator, parserOptions);
  1182. }
  1183. return parseVOnExpressionBody(code, locationCalculator, parserOptions);
  1184. }
  1185. function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
  1186. debug('[script] parse v-on expression: "void function($event){%s}"', code);
  1187. if (code.trim() === "") {
  1188. throwEmptyError(locationCalculator, "statements");
  1189. }
  1190. try {
  1191. const result = parseScriptFragment(`void function($event){${code}}`, locationCalculator.getSubCalculatorShift(-22), parserOptions);
  1192. const { ast } = result;
  1193. const references = analyzeExternalReferences(result, parserOptions);
  1194. const outermostStatement = ast.body[0];
  1195. const functionDecl = outermostStatement.expression.argument;
  1196. const block = functionDecl.body;
  1197. const body = block.body;
  1198. const firstStatement = first__default["default"](body);
  1199. const lastStatement = last__default["default"](body);
  1200. const expression = {
  1201. type: "VOnExpression",
  1202. range: [
  1203. firstStatement != null
  1204. ? firstStatement.range[0]
  1205. : block.range[0] + 1,
  1206. lastStatement != null
  1207. ? lastStatement.range[1]
  1208. : block.range[1] - 1,
  1209. ],
  1210. loc: {
  1211. start: firstStatement != null
  1212. ? firstStatement.loc.start
  1213. : locationCalculator.getLocation(1),
  1214. end: lastStatement != null
  1215. ? lastStatement.loc.end
  1216. : locationCalculator.getLocation(code.length + 1),
  1217. },
  1218. parent: DUMMY_PARENT$2,
  1219. body,
  1220. };
  1221. const tokens = ast.tokens || [];
  1222. const comments = ast.comments || [];
  1223. for (const b of body) {
  1224. b.parent = expression;
  1225. }
  1226. tokens.splice(0, 6);
  1227. tokens.pop();
  1228. return { expression, tokens, comments, references, variables: [] };
  1229. }
  1230. catch (err) {
  1231. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1232. }
  1233. }
  1234. function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
  1235. debug('[script] parse slot-scope expression: "void function(%s) {}"', code);
  1236. if (code.trim() === "") {
  1237. throwEmptyError(locationCalculator, "an identifier or an array/object pattern");
  1238. }
  1239. try {
  1240. const result = parseScriptFragment(`void function(${code}) {}`, locationCalculator.getSubCalculatorShift(-14), parserOptions);
  1241. const { ast } = result;
  1242. const statement = ast.body[0];
  1243. const rawExpression = statement.expression;
  1244. const functionDecl = rawExpression.argument;
  1245. const params = functionDecl.params;
  1246. if (params.length === 0) {
  1247. return {
  1248. expression: null,
  1249. tokens: [],
  1250. comments: [],
  1251. references: [],
  1252. variables: [],
  1253. };
  1254. }
  1255. const tokens = ast.tokens || [];
  1256. const comments = ast.comments || [];
  1257. const scope = analyzeVariablesAndExternalReferences(result, parserOptions);
  1258. const references = scope.references;
  1259. const variables = scope.variables;
  1260. const firstParam = first__default["default"](params);
  1261. const lastParam = last__default["default"](params);
  1262. const expression = {
  1263. type: "VSlotScopeExpression",
  1264. range: [firstParam.range[0], lastParam.range[1]],
  1265. loc: { start: firstParam.loc.start, end: lastParam.loc.end },
  1266. parent: DUMMY_PARENT$2,
  1267. params: functionDecl.params,
  1268. };
  1269. for (const param of params) {
  1270. param.parent = expression;
  1271. }
  1272. tokens.shift();
  1273. tokens.shift();
  1274. tokens.shift();
  1275. tokens.pop();
  1276. tokens.pop();
  1277. tokens.pop();
  1278. return { expression, tokens, comments, references, variables };
  1279. }
  1280. catch (err) {
  1281. return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
  1282. }
  1283. }
  1284. function replaceTokens(document, node, newTokens) {
  1285. if (document == null) {
  1286. return;
  1287. }
  1288. const index = sortedIndexBy__default["default"](document.tokens, node, byRange0);
  1289. const count = sortedLastIndexBy__default["default"](document.tokens, node, byRange1) - index;
  1290. document.tokens.splice(index, count, ...newTokens);
  1291. }
  1292. function replaceAndSplitTokens(document, node, newTokens) {
  1293. if (document == null) {
  1294. return;
  1295. }
  1296. const index = sortedIndexBy__default["default"](document.tokens, node, byRange0);
  1297. if (document.tokens.length === index ||
  1298. node.range[0] < document.tokens[index].range[0]) {
  1299. const beforeToken = document.tokens[index - 1];
  1300. const value = beforeToken.value;
  1301. const splitOffset = node.range[0] - beforeToken.range[0];
  1302. const afterToken = {
  1303. type: beforeToken.type,
  1304. range: [node.range[0], beforeToken.range[1]],
  1305. loc: {
  1306. start: Object.assign({}, node.loc.start),
  1307. end: Object.assign({}, beforeToken.loc.end),
  1308. },
  1309. value: value.slice(splitOffset),
  1310. };
  1311. beforeToken.range[1] = node.range[0];
  1312. beforeToken.loc.end = Object.assign({}, node.loc.start);
  1313. beforeToken.value = value.slice(0, splitOffset);
  1314. document.tokens.splice(index, 0, afterToken);
  1315. }
  1316. let lastIndex = sortedLastIndexBy__default["default"](document.tokens, node, byRange1);
  1317. if (lastIndex === 0 ||
  1318. node.range[1] < document.tokens[lastIndex].range[1]) {
  1319. const beforeToken = document.tokens[lastIndex];
  1320. const value = beforeToken.value;
  1321. const splitOffset = beforeToken.range[1] -
  1322. beforeToken.range[0] -
  1323. (beforeToken.range[1] - node.range[1]);
  1324. const afterToken = {
  1325. type: beforeToken.type,
  1326. range: [node.range[1], beforeToken.range[1]],
  1327. loc: {
  1328. start: Object.assign({}, node.loc.end),
  1329. end: Object.assign({}, beforeToken.loc.end),
  1330. },
  1331. value: value.slice(splitOffset),
  1332. };
  1333. beforeToken.range[1] = node.range[1];
  1334. beforeToken.loc.end = Object.assign({}, node.loc.end);
  1335. beforeToken.value = value.slice(0, splitOffset);
  1336. document.tokens.splice(lastIndex + 1, 0, afterToken);
  1337. lastIndex++;
  1338. }
  1339. const count = lastIndex - index;
  1340. document.tokens.splice(index, count, ...newTokens);
  1341. }
  1342. function insertComments(document, newComments) {
  1343. if (document == null || newComments.length === 0) {
  1344. return;
  1345. }
  1346. const index = sortedIndexBy__default["default"](document.comments, newComments[0], byRange0);
  1347. document.comments.splice(index, 0, ...newComments);
  1348. }
  1349. function createSimpleToken(type, start, end, value, linesAndColumns) {
  1350. return {
  1351. type,
  1352. range: [start, end],
  1353. loc: {
  1354. start: linesAndColumns.getLocFromIndex(start),
  1355. end: linesAndColumns.getLocFromIndex(end),
  1356. },
  1357. value,
  1358. };
  1359. }
  1360. function byRange0(x) {
  1361. return x.range[0];
  1362. }
  1363. function byRange1(x) {
  1364. return x.range[1];
  1365. }
  1366. function insertError(document, error) {
  1367. if (document == null) {
  1368. return;
  1369. }
  1370. const index = sortedIndexBy__default["default"](document.errors, error, byIndex);
  1371. document.errors.splice(index, 0, error);
  1372. }
  1373. function byIndex(x) {
  1374. return x.index;
  1375. }
  1376. const shorthandSign = /^[.:@#]/u;
  1377. const shorthandNameMap = { ":": "bind", ".": "bind", "@": "on", "#": "slot" };
  1378. const invalidDynamicArgumentNextChar = /^[\s\r\n=/>]$/u;
  1379. function getTagName$1(startTagOrElement, isSFC) {
  1380. return isSFC ? startTagOrElement.rawName : startTagOrElement.name;
  1381. }
  1382. function parseDirectiveKeyStatically(node, document) {
  1383. const { name: text, rawName: rawText, range: [offset], loc: { start: { column, line }, }, } = node;
  1384. const directiveKey = {
  1385. type: "VDirectiveKey",
  1386. range: node.range,
  1387. loc: node.loc,
  1388. parent: node.parent,
  1389. name: null,
  1390. argument: null,
  1391. modifiers: [],
  1392. };
  1393. let i = 0;
  1394. function createIdentifier(start, end, name) {
  1395. return {
  1396. type: "VIdentifier",
  1397. parent: directiveKey,
  1398. range: [offset + start, offset + end],
  1399. loc: {
  1400. start: { column: column + start, line },
  1401. end: { column: column + end, line },
  1402. },
  1403. name: name || text.slice(start, end),
  1404. rawName: rawText.slice(start, end),
  1405. };
  1406. }
  1407. if (shorthandSign.test(text)) {
  1408. const sign = text[0];
  1409. directiveKey.name = createIdentifier(0, 1, shorthandNameMap[sign]);
  1410. i = 1;
  1411. }
  1412. else {
  1413. const colon = text.indexOf(":");
  1414. if (colon !== -1) {
  1415. directiveKey.name = createIdentifier(0, colon);
  1416. i = colon + 1;
  1417. }
  1418. }
  1419. if (directiveKey.name != null && text[i] === "[") {
  1420. const len = text.slice(i).lastIndexOf("]");
  1421. if (len !== -1) {
  1422. directiveKey.argument = createIdentifier(i, i + len + 1);
  1423. i = i + len + 1 + (text[i + len + 1] === "." ? 1 : 0);
  1424. }
  1425. }
  1426. const modifiers = text
  1427. .slice(i)
  1428. .split(".")
  1429. .map((modifierName) => {
  1430. const modifier = createIdentifier(i, i + modifierName.length);
  1431. if (modifierName === "" && i < text.length) {
  1432. insertError(document, new ParseError(`Unexpected token '${text[i]}'`, undefined, offset + i, line, column + i));
  1433. }
  1434. i += modifierName.length + 1;
  1435. return modifier;
  1436. });
  1437. if (directiveKey.name == null) {
  1438. directiveKey.name = modifiers.shift();
  1439. }
  1440. else if (directiveKey.argument == null && modifiers[0].name !== "") {
  1441. directiveKey.argument = modifiers.shift() || null;
  1442. }
  1443. directiveKey.modifiers = modifiers.filter(isNotEmptyModifier);
  1444. if (directiveKey.name.name === "v-") {
  1445. 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));
  1446. }
  1447. if (directiveKey.name.rawName === "." &&
  1448. !directiveKey.modifiers.some(isPropModifier)) {
  1449. const pos = (directiveKey.argument || directiveKey.name).range[1] - offset;
  1450. const propModifier = createIdentifier(pos, pos, "prop");
  1451. directiveKey.modifiers.unshift(propModifier);
  1452. }
  1453. return directiveKey;
  1454. }
  1455. function isPropModifier(node) {
  1456. return node.name === "prop";
  1457. }
  1458. function isNotEmptyModifier(node) {
  1459. return node.name !== "";
  1460. }
  1461. function parseDirectiveKeyTokens(node) {
  1462. const { name, argument, modifiers } = node;
  1463. const shorthand = name.range[1] - name.range[0] === 1;
  1464. const tokens = [];
  1465. if (shorthand) {
  1466. tokens.push({
  1467. type: "Punctuator",
  1468. range: name.range,
  1469. loc: name.loc,
  1470. value: name.rawName,
  1471. });
  1472. }
  1473. else {
  1474. tokens.push({
  1475. type: "HTMLIdentifier",
  1476. range: name.range,
  1477. loc: name.loc,
  1478. value: name.rawName,
  1479. });
  1480. if (argument) {
  1481. tokens.push({
  1482. type: "Punctuator",
  1483. range: [name.range[1], argument.range[0]],
  1484. loc: { start: name.loc.end, end: argument.loc.start },
  1485. value: ":",
  1486. });
  1487. }
  1488. }
  1489. if (argument) {
  1490. tokens.push({
  1491. type: "HTMLIdentifier",
  1492. range: argument.range,
  1493. loc: argument.loc,
  1494. value: argument.rawName,
  1495. });
  1496. }
  1497. let lastNode = argument || name;
  1498. for (const modifier of modifiers) {
  1499. if (modifier.rawName === "") {
  1500. continue;
  1501. }
  1502. tokens.push({
  1503. type: "Punctuator",
  1504. range: [lastNode.range[1], modifier.range[0]],
  1505. loc: { start: lastNode.loc.end, end: modifier.loc.start },
  1506. value: ".",
  1507. }, {
  1508. type: "HTMLIdentifier",
  1509. range: modifier.range,
  1510. loc: modifier.loc,
  1511. value: modifier.rawName,
  1512. });
  1513. lastNode = modifier;
  1514. }
  1515. return tokens;
  1516. }
  1517. function convertDynamicArgument(node, document, parserOptions, locationCalculator) {
  1518. const { argument } = node;
  1519. if (!(argument != null &&
  1520. argument.type === "VIdentifier" &&
  1521. argument.name.startsWith("[") &&
  1522. argument.name.endsWith("]"))) {
  1523. return;
  1524. }
  1525. const { rawName, range, loc } = argument;
  1526. try {
  1527. const { comments, expression, references, tokens } = parseExpression(rawName.slice(1, -1), locationCalculator.getSubCalculatorAfter(range[0] + 1), parserOptions);
  1528. node.argument = {
  1529. type: "VExpressionContainer",
  1530. range,
  1531. loc,
  1532. parent: node,
  1533. expression,
  1534. references,
  1535. };
  1536. if (expression != null) {
  1537. expression.parent = node.argument;
  1538. }
  1539. tokens.unshift(createSimpleToken("Punctuator", range[0], range[0] + 1, "[", locationCalculator));
  1540. tokens.push(createSimpleToken("Punctuator", range[1] - 1, range[1], "]", locationCalculator));
  1541. replaceTokens(document, node.argument, tokens);
  1542. insertComments(document, comments);
  1543. }
  1544. catch (error) {
  1545. debug("[template] Parse error: %s", error);
  1546. if (ParseError.isParseError(error)) {
  1547. node.argument = {
  1548. type: "VExpressionContainer",
  1549. range,
  1550. loc,
  1551. parent: node,
  1552. expression: null,
  1553. references: [],
  1554. };
  1555. insertError(document, error);
  1556. }
  1557. else {
  1558. throw error;
  1559. }
  1560. }
  1561. }
  1562. function createDirectiveKey(node, document, parserOptions, locationCalculator) {
  1563. const directiveKey = parseDirectiveKeyStatically(node, document);
  1564. const tokens = parseDirectiveKeyTokens(directiveKey);
  1565. replaceTokens(document, directiveKey, tokens);
  1566. if (directiveKey.name.name.startsWith("v-")) {
  1567. directiveKey.name.name = directiveKey.name.name.slice(2);
  1568. }
  1569. if (directiveKey.name.rawName.startsWith("v-")) {
  1570. directiveKey.name.rawName = directiveKey.name.rawName.slice(2);
  1571. }
  1572. convertDynamicArgument(directiveKey, document, parserOptions, locationCalculator);
  1573. return directiveKey;
  1574. }
  1575. function parseAttributeValue(code, parserOptions, globalLocationCalculator, node, tagName, directiveKey) {
  1576. const firstChar = code[node.range[0]];
  1577. const quoted = firstChar === '"' || firstChar === "'";
  1578. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(node.range[0] + (quoted ? 1 : 0));
  1579. const directiveName = directiveKey.name.name;
  1580. let result;
  1581. if (quoted && node.value === "") {
  1582. result = {
  1583. expression: null,
  1584. tokens: [],
  1585. comments: [],
  1586. variables: [],
  1587. references: [],
  1588. };
  1589. }
  1590. else if (directiveName === "for") {
  1591. result = parseVForExpression(node.value, locationCalculator, parserOptions);
  1592. }
  1593. else if (directiveName === "on" && directiveKey.argument != null) {
  1594. result = parseVOnExpression(node.value, locationCalculator, parserOptions);
  1595. }
  1596. else if (directiveName === "slot" ||
  1597. directiveName === "slot-scope" ||
  1598. (tagName === "template" && directiveName === "scope")) {
  1599. result = parseSlotScopeExpression(node.value, locationCalculator, parserOptions);
  1600. }
  1601. else if (directiveName === "bind") {
  1602. result = parseExpression(node.value, locationCalculator, parserOptions, { allowFilters: true });
  1603. }
  1604. else {
  1605. result = parseExpression(node.value, locationCalculator, parserOptions);
  1606. }
  1607. if (quoted) {
  1608. result.tokens.unshift(createSimpleToken("Punctuator", node.range[0], node.range[0] + 1, firstChar, globalLocationCalculator));
  1609. result.tokens.push(createSimpleToken("Punctuator", node.range[1] - 1, node.range[1], firstChar, globalLocationCalculator));
  1610. }
  1611. return result;
  1612. }
  1613. function resolveReference(referene, element) {
  1614. let node = element;
  1615. while (node != null && node.type === "VElement") {
  1616. for (const variable of node.variables) {
  1617. if (variable.id.name === referene.id.name) {
  1618. referene.variable = variable;
  1619. variable.references.push(referene);
  1620. return;
  1621. }
  1622. }
  1623. node = node.parent;
  1624. }
  1625. }
  1626. function convertToDirective(code, parserOptions, locationCalculator, node) {
  1627. debug('[template] convert to directive: %s="%s" %j', node.key.name, node.value && node.value.value, node.range);
  1628. const document = getOwnerDocument(node);
  1629. const directive = node;
  1630. directive.directive = true;
  1631. directive.key = createDirectiveKey(node.key, document, parserOptions, locationCalculator);
  1632. const { argument } = directive.key;
  1633. if (argument &&
  1634. argument.type === "VIdentifier" &&
  1635. argument.name.startsWith("[")) {
  1636. const nextChar = code[argument.range[1]];
  1637. if (nextChar == null || invalidDynamicArgumentNextChar.test(nextChar)) {
  1638. const char = nextChar == null ? "EOF" : JSON.stringify(nextChar).slice(1, -1);
  1639. insertError(document, new ParseError(`Dynamic argument cannot contain the '${char}' character.`, undefined, argument.range[1], argument.loc.end.line, argument.loc.end.column));
  1640. }
  1641. }
  1642. if (node.value == null) {
  1643. return;
  1644. }
  1645. try {
  1646. const ret = parseAttributeValue(code, parserOptions, locationCalculator, node.value, getTagName$1(node.parent.parent, isSFCFile(parserOptions)), directive.key);
  1647. directive.value = {
  1648. type: "VExpressionContainer",
  1649. range: node.value.range,
  1650. loc: node.value.loc,
  1651. parent: directive,
  1652. expression: ret.expression,
  1653. references: ret.references,
  1654. };
  1655. if (ret.expression != null) {
  1656. ret.expression.parent = directive.value;
  1657. }
  1658. for (const variable of ret.variables) {
  1659. node.parent.parent.variables.push(variable);
  1660. }
  1661. replaceTokens(document, node.value, ret.tokens);
  1662. insertComments(document, ret.comments);
  1663. }
  1664. catch (err) {
  1665. debug("[template] Parse error: %s", err);
  1666. if (ParseError.isParseError(err)) {
  1667. directive.value = {
  1668. type: "VExpressionContainer",
  1669. range: node.value.range,
  1670. loc: node.value.loc,
  1671. parent: directive,
  1672. expression: null,
  1673. references: [],
  1674. };
  1675. insertError(document, err);
  1676. }
  1677. else {
  1678. throw err;
  1679. }
  1680. }
  1681. }
  1682. function processMustache(parserOptions, globalLocationCalculator, node, mustache) {
  1683. const range = [
  1684. mustache.startToken.range[1],
  1685. mustache.endToken.range[0],
  1686. ];
  1687. debug("[template] convert mustache {{%s}} %j", mustache.value, range);
  1688. const document = getOwnerDocument(node);
  1689. try {
  1690. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(range[0]);
  1691. const ret = parseExpression(mustache.value, locationCalculator, parserOptions, { allowEmpty: true, allowFilters: true });
  1692. node.expression = ret.expression || null;
  1693. node.references = ret.references;
  1694. if (ret.expression != null) {
  1695. ret.expression.parent = node;
  1696. }
  1697. replaceTokens(document, { range }, ret.tokens);
  1698. insertComments(document, ret.comments);
  1699. }
  1700. catch (err) {
  1701. debug("[template] Parse error: %s", err);
  1702. if (ParseError.isParseError(err)) {
  1703. insertError(document, err);
  1704. }
  1705. else {
  1706. throw err;
  1707. }
  1708. }
  1709. }
  1710. function resolveReferences(container) {
  1711. let element = container.parent;
  1712. while (element != null && element.type !== "VElement") {
  1713. element = element.parent;
  1714. }
  1715. if (element != null) {
  1716. for (const reference of container.references) {
  1717. resolveReference(reference, element);
  1718. }
  1719. }
  1720. }
  1721. const SVG_ATTRIBUTE_NAME_MAP = new Map([
  1722. ["attributename", "attributeName"],
  1723. ["attributetype", "attributeType"],
  1724. ["basefrequency", "baseFrequency"],
  1725. ["baseprofile", "baseProfile"],
  1726. ["calcmode", "calcMode"],
  1727. ["clippathunits", "clipPathUnits"],
  1728. ["diffuseconstant", "diffuseConstant"],
  1729. ["edgemode", "edgeMode"],
  1730. ["filterunits", "filterUnits"],
  1731. ["glyphref", "glyphRef"],
  1732. ["gradienttransform", "gradientTransform"],
  1733. ["gradientunits", "gradientUnits"],
  1734. ["kernelmatrix", "kernelMatrix"],
  1735. ["kernelunitlength", "kernelUnitLength"],
  1736. ["keypoints", "keyPoints"],
  1737. ["keysplines", "keySplines"],
  1738. ["keytimes", "keyTimes"],
  1739. ["lengthadjust", "lengthAdjust"],
  1740. ["limitingconeangle", "limitingConeAngle"],
  1741. ["markerheight", "markerHeight"],
  1742. ["markerunits", "markerUnits"],
  1743. ["markerwidth", "markerWidth"],
  1744. ["maskcontentunits", "maskContentUnits"],
  1745. ["maskunits", "maskUnits"],
  1746. ["numoctaves", "numOctaves"],
  1747. ["pathlength", "pathLength"],
  1748. ["patterncontentunits", "patternContentUnits"],
  1749. ["patterntransform", "patternTransform"],
  1750. ["patternunits", "patternUnits"],
  1751. ["pointsatx", "pointsAtX"],
  1752. ["pointsaty", "pointsAtY"],
  1753. ["pointsatz", "pointsAtZ"],
  1754. ["preservealpha", "preserveAlpha"],
  1755. ["preserveaspectratio", "preserveAspectRatio"],
  1756. ["primitiveunits", "primitiveUnits"],
  1757. ["refx", "refX"],
  1758. ["refy", "refY"],
  1759. ["repeatcount", "repeatCount"],
  1760. ["repeatdur", "repeatDur"],
  1761. ["requiredextensions", "requiredExtensions"],
  1762. ["requiredfeatures", "requiredFeatures"],
  1763. ["specularconstant", "specularConstant"],
  1764. ["specularexponent", "specularExponent"],
  1765. ["spreadmethod", "spreadMethod"],
  1766. ["startoffset", "startOffset"],
  1767. ["stddeviation", "stdDeviation"],
  1768. ["stitchtiles", "stitchTiles"],
  1769. ["surfacescale", "surfaceScale"],
  1770. ["systemlanguage", "systemLanguage"],
  1771. ["tablevalues", "tableValues"],
  1772. ["targetx", "targetX"],
  1773. ["targety", "targetY"],
  1774. ["textlength", "textLength"],
  1775. ["viewbox", "viewBox"],
  1776. ["viewtarget", "viewTarget"],
  1777. ["xchannelselector", "xChannelSelector"],
  1778. ["ychannelselector", "yChannelSelector"],
  1779. ["zoomandpan", "zoomAndPan"],
  1780. ]);
  1781. const MATHML_ATTRIBUTE_NAME_MAP = new Map([
  1782. ["definitionurl", "definitionUrl"]
  1783. ]);
  1784. const HTML_VOID_ELEMENT_TAGS = new Set([
  1785. "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta",
  1786. "param", "source", "track", "wbr",
  1787. ]);
  1788. const HTML_CAN_BE_LEFT_OPEN_TAGS = new Set([
  1789. "colgroup", "li", "options", "p", "td", "tfoot", "th", "thead",
  1790. "tr", "source",
  1791. ]);
  1792. const HTML_NON_FHRASING_TAGS = new Set([
  1793. "address", "article", "aside", "base", "blockquote", "body", "caption",
  1794. "col", "colgroup", "dd", "details", "dialog", "div", "dl", "dt", "fieldset",
  1795. "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5",
  1796. "h6", "head", "header", "hgroup", "hr", "html", "legend", "li", "menuitem",
  1797. "meta", "optgroup", "option", "param", "rp", "rt", "source", "style",
  1798. "summary", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track",
  1799. ]);
  1800. const HTML_RCDATA_TAGS = new Set([
  1801. "title", "textarea",
  1802. ]);
  1803. const HTML_RAWTEXT_TAGS = new Set([
  1804. "style", "xmp", "iframe", "noembed", "noframes", "noscript", "script",
  1805. ]);
  1806. const SVG_TAGS$1 = new Set([
  1807. "a", "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor",
  1808. "animateMotion", "animateTransform", "animation", "audio", "canvas",
  1809. "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "discard",
  1810. "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite",
  1811. "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap",
  1812. "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB",
  1813. "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode",
  1814. "feMorphology", "feOffset", "fePointLight", "feSpecularLighting",
  1815. "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face",
  1816. "font-face-format", "font-face-name", "font-face-src", "font-face-uri",
  1817. "foreignObject", "g", "glyph", "glyphRef", "handler", "hatch", "hatchpath",
  1818. "hkern", "iframe", "image", "line", "linearGradient", "listener", "marker",
  1819. "mask", "mesh", "meshgradient", "meshpatch", "meshrow", "metadata",
  1820. "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline",
  1821. "prefetch", "radialGradient", "rect", "script", "set", "solidColor",
  1822. "solidcolor", "stop", "style", "svg", "switch", "symbol", "tbreak", "text",
  1823. "textArea", "textPath", "title", "tref", "tspan", "unknown", "use", "video",
  1824. "view", "vkern",
  1825. ]);
  1826. const SVG_ELEMENT_NAME_MAP = new Map();
  1827. for (const name of SVG_TAGS$1) {
  1828. if (/[A-Z]/.test(name)) {
  1829. SVG_ELEMENT_NAME_MAP.set(name.toLowerCase(), name);
  1830. }
  1831. }
  1832. const DUMMY_PARENT$1 = Object.freeze({});
  1833. function concat(text, token) {
  1834. return text + token.value;
  1835. }
  1836. class IntermediateTokenizer {
  1837. constructor(tokenizer) {
  1838. this.tokenizer = tokenizer;
  1839. this.currentToken = null;
  1840. this.attribute = null;
  1841. this.attributeNames = new Set();
  1842. this.expressionStartToken = null;
  1843. this.expressionTokens = [];
  1844. this.tokens = [];
  1845. this.comments = [];
  1846. }
  1847. get text() {
  1848. return this.tokenizer.text;
  1849. }
  1850. get errors() {
  1851. return this.tokenizer.errors;
  1852. }
  1853. get state() {
  1854. return this.tokenizer.state;
  1855. }
  1856. set state(value) {
  1857. this.tokenizer.state = value;
  1858. }
  1859. get namespace() {
  1860. return this.tokenizer.namespace;
  1861. }
  1862. set namespace(value) {
  1863. this.tokenizer.namespace = value;
  1864. }
  1865. get expressionEnabled() {
  1866. return this.tokenizer.expressionEnabled;
  1867. }
  1868. set expressionEnabled(value) {
  1869. this.tokenizer.expressionEnabled = value;
  1870. }
  1871. nextToken() {
  1872. let token = null;
  1873. let result = null;
  1874. while (result == null && (token = this.tokenizer.nextToken()) != null) {
  1875. result = this[token.type](token);
  1876. }
  1877. if (result == null && token == null && this.currentToken != null) {
  1878. result = this.commit();
  1879. }
  1880. return result;
  1881. }
  1882. commit() {
  1883. assert__default["default"](this.currentToken != null || this.expressionStartToken != null);
  1884. let token = this.currentToken;
  1885. this.currentToken = null;
  1886. this.attribute = null;
  1887. if (this.expressionStartToken != null) {
  1888. const start = this.expressionStartToken;
  1889. const end = last__default["default"](this.expressionTokens) || start;
  1890. const value = this.expressionTokens.reduce(concat, start.value);
  1891. this.expressionStartToken = null;
  1892. this.expressionTokens = [];
  1893. if (token == null) {
  1894. token = {
  1895. type: "Text",
  1896. range: [start.range[0], end.range[1]],
  1897. loc: { start: start.loc.start, end: end.loc.end },
  1898. value,
  1899. };
  1900. }
  1901. else if (token.type === "Text") {
  1902. token.range[1] = end.range[1];
  1903. token.loc.end = end.loc.end;
  1904. token.value += value;
  1905. }
  1906. else {
  1907. throw new Error("unreachable");
  1908. }
  1909. }
  1910. return token;
  1911. }
  1912. reportParseError(token, code) {
  1913. const error = ParseError.fromCode(code, token.range[0], token.loc.start.line, token.loc.start.column);
  1914. this.errors.push(error);
  1915. debug("[html] syntax error:", error.message);
  1916. }
  1917. processComment(token) {
  1918. this.comments.push(token);
  1919. if (this.currentToken != null && this.currentToken.type === "Text") {
  1920. return this.commit();
  1921. }
  1922. return null;
  1923. }
  1924. processText(token) {
  1925. this.tokens.push(token);
  1926. let result = null;
  1927. if (this.expressionStartToken != null) {
  1928. const lastToken = last__default["default"](this.expressionTokens) || this.expressionStartToken;
  1929. if (lastToken.range[1] === token.range[0]) {
  1930. this.expressionTokens.push(token);
  1931. return null;
  1932. }
  1933. result = this.commit();
  1934. }
  1935. else if (this.currentToken != null) {
  1936. if (this.currentToken.type === "Text" &&
  1937. this.currentToken.range[1] === token.range[0]) {
  1938. this.currentToken.value += token.value;
  1939. this.currentToken.range[1] = token.range[1];
  1940. this.currentToken.loc.end = token.loc.end;
  1941. return null;
  1942. }
  1943. result = this.commit();
  1944. }
  1945. assert__default["default"](this.currentToken == null);
  1946. this.currentToken = {
  1947. type: "Text",
  1948. range: [token.range[0], token.range[1]],
  1949. loc: { start: token.loc.start, end: token.loc.end },
  1950. value: token.value,
  1951. };
  1952. return result;
  1953. }
  1954. HTMLAssociation(token) {
  1955. this.tokens.push(token);
  1956. if (this.attribute != null) {
  1957. this.attribute.range[1] = token.range[1];
  1958. this.attribute.loc.end = token.loc.end;
  1959. if (this.currentToken == null ||
  1960. this.currentToken.type !== "StartTag") {
  1961. throw new Error("unreachable");
  1962. }
  1963. this.currentToken.range[1] = token.range[1];
  1964. this.currentToken.loc.end = token.loc.end;
  1965. }
  1966. return null;
  1967. }
  1968. HTMLBogusComment(token) {
  1969. return this.processComment(token);
  1970. }
  1971. HTMLCDataText(token) {
  1972. return this.processText(token);
  1973. }
  1974. HTMLComment(token) {
  1975. return this.processComment(token);
  1976. }
  1977. HTMLEndTagOpen(token) {
  1978. this.tokens.push(token);
  1979. let result = null;
  1980. if (this.currentToken != null || this.expressionStartToken != null) {
  1981. result = this.commit();
  1982. }
  1983. this.currentToken = {
  1984. type: "EndTag",
  1985. range: [token.range[0], token.range[1]],
  1986. loc: { start: token.loc.start, end: token.loc.end },
  1987. name: token.value,
  1988. };
  1989. return result;
  1990. }
  1991. HTMLIdentifier(token) {
  1992. this.tokens.push(token);
  1993. if (this.currentToken == null ||
  1994. this.currentToken.type === "Text" ||
  1995. this.currentToken.type === "Mustache") {
  1996. throw new Error("unreachable");
  1997. }
  1998. if (this.currentToken.type === "EndTag") {
  1999. this.reportParseError(token, "end-tag-with-attributes");
  2000. return null;
  2001. }
  2002. if (this.attributeNames.has(token.value)) {
  2003. this.reportParseError(token, "duplicate-attribute");
  2004. }
  2005. this.attributeNames.add(token.value);
  2006. this.attribute = {
  2007. type: "VAttribute",
  2008. range: [token.range[0], token.range[1]],
  2009. loc: { start: token.loc.start, end: token.loc.end },
  2010. parent: DUMMY_PARENT$1,
  2011. directive: false,
  2012. key: {
  2013. type: "VIdentifier",
  2014. range: [token.range[0], token.range[1]],
  2015. loc: { start: token.loc.start, end: token.loc.end },
  2016. parent: DUMMY_PARENT$1,
  2017. name: token.value,
  2018. rawName: this.text.slice(token.range[0], token.range[1]),
  2019. },
  2020. value: null,
  2021. };
  2022. this.attribute.key.parent = this.attribute;
  2023. this.currentToken.range[1] = token.range[1];
  2024. this.currentToken.loc.end = token.loc.end;
  2025. this.currentToken.attributes.push(this.attribute);
  2026. return null;
  2027. }
  2028. HTMLLiteral(token) {
  2029. this.tokens.push(token);
  2030. if (this.attribute != null) {
  2031. this.attribute.range[1] = token.range[1];
  2032. this.attribute.loc.end = token.loc.end;
  2033. this.attribute.value = {
  2034. type: "VLiteral",
  2035. range: [token.range[0], token.range[1]],
  2036. loc: { start: token.loc.start, end: token.loc.end },
  2037. parent: this.attribute,
  2038. value: token.value,
  2039. };
  2040. if (this.currentToken == null ||
  2041. this.currentToken.type !== "StartTag") {
  2042. throw new Error("unreachable");
  2043. }
  2044. this.currentToken.range[1] = token.range[1];
  2045. this.currentToken.loc.end = token.loc.end;
  2046. }
  2047. return null;
  2048. }
  2049. HTMLRCDataText(token) {
  2050. return this.processText(token);
  2051. }
  2052. HTMLRawText(token) {
  2053. return this.processText(token);
  2054. }
  2055. HTMLSelfClosingTagClose(token) {
  2056. this.tokens.push(token);
  2057. if (this.currentToken == null || this.currentToken.type === "Text") {
  2058. throw new Error("unreachable");
  2059. }
  2060. if (this.currentToken.type === "StartTag") {
  2061. this.currentToken.selfClosing = true;
  2062. }
  2063. else {
  2064. this.reportParseError(token, "end-tag-with-trailing-solidus");
  2065. }
  2066. this.currentToken.range[1] = token.range[1];
  2067. this.currentToken.loc.end = token.loc.end;
  2068. return this.commit();
  2069. }
  2070. HTMLTagClose(token) {
  2071. this.tokens.push(token);
  2072. if (this.currentToken == null || this.currentToken.type === "Text") {
  2073. throw new Error("unreachable");
  2074. }
  2075. this.currentToken.range[1] = token.range[1];
  2076. this.currentToken.loc.end = token.loc.end;
  2077. return this.commit();
  2078. }
  2079. HTMLTagOpen(token) {
  2080. this.tokens.push(token);
  2081. let result = null;
  2082. if (this.currentToken != null || this.expressionStartToken != null) {
  2083. result = this.commit();
  2084. }
  2085. this.currentToken = {
  2086. type: "StartTag",
  2087. range: [token.range[0], token.range[1]],
  2088. loc: { start: token.loc.start, end: token.loc.end },
  2089. name: token.value,
  2090. rawName: this.text.slice(token.range[0] + 1, token.range[1]),
  2091. selfClosing: false,
  2092. attributes: [],
  2093. };
  2094. this.attribute = null;
  2095. this.attributeNames.clear();
  2096. return result;
  2097. }
  2098. HTMLText(token) {
  2099. return this.processText(token);
  2100. }
  2101. HTMLWhitespace(token) {
  2102. return this.processText(token);
  2103. }
  2104. VExpressionStart(token) {
  2105. if (this.expressionStartToken != null) {
  2106. return this.processText(token);
  2107. }
  2108. const separated = this.currentToken != null &&
  2109. this.currentToken.range[1] !== token.range[0];
  2110. const result = separated ? this.commit() : null;
  2111. this.tokens.push(token);
  2112. this.expressionStartToken = token;
  2113. return result;
  2114. }
  2115. VExpressionEnd(token) {
  2116. if (this.expressionStartToken == null) {
  2117. return this.processText(token);
  2118. }
  2119. const start = this.expressionStartToken;
  2120. const end = last__default["default"](this.expressionTokens) || start;
  2121. if (token.range[0] === start.range[1]) {
  2122. this.tokens.pop();
  2123. this.expressionStartToken = null;
  2124. const result = this.processText(start);
  2125. this.processText(token);
  2126. return result;
  2127. }
  2128. if (end.range[1] !== token.range[0]) {
  2129. const result = this.commit();
  2130. this.processText(token);
  2131. return result;
  2132. }
  2133. const value = this.expressionTokens.reduce(concat, "");
  2134. this.tokens.push(token);
  2135. this.expressionStartToken = null;
  2136. this.expressionTokens = [];
  2137. const result = this.currentToken != null ? this.commit() : null;
  2138. this.currentToken = {
  2139. type: "Mustache",
  2140. range: [start.range[0], token.range[1]],
  2141. loc: { start: start.loc.start, end: token.loc.end },
  2142. value,
  2143. startToken: start,
  2144. endToken: token,
  2145. };
  2146. return result || this.commit();
  2147. }
  2148. }
  2149. const DIRECTIVE_NAME = /^(?:v-|[.:@#]).*[^.:@#]$/u;
  2150. const DT_DD = /^d[dt]$/u;
  2151. const DUMMY_PARENT = Object.freeze({});
  2152. function getTagName(startTagOrElement, isSFC) {
  2153. return isSFC ? startTagOrElement.rawName : startTagOrElement.name;
  2154. }
  2155. function isMathMLIntegrationPoint(element, isSFC) {
  2156. if (element.namespace === NS.MathML) {
  2157. const name = getTagName(element, isSFC);
  2158. return (name === "mi" ||
  2159. name === "mo" ||
  2160. name === "mn" ||
  2161. name === "ms" ||
  2162. name === "mtext");
  2163. }
  2164. return false;
  2165. }
  2166. function isHTMLIntegrationPoint(element, isSFC) {
  2167. if (element.namespace === NS.MathML) {
  2168. return (getTagName(element, isSFC) === "annotation-xml" &&
  2169. element.startTag.attributes.some((a) => a.directive === false &&
  2170. a.key.name === "encoding" &&
  2171. a.value != null &&
  2172. (a.value.value === "text/html" ||
  2173. a.value.value === "application/xhtml+xml")));
  2174. }
  2175. if (element.namespace === NS.SVG) {
  2176. const name = getTagName(element, isSFC);
  2177. return name === "foreignObject" || name === "desc" || name === "title";
  2178. }
  2179. return false;
  2180. }
  2181. function adjustElementName(name, namespace) {
  2182. if (namespace === NS.SVG) {
  2183. return SVG_ELEMENT_NAME_MAP.get(name) || name;
  2184. }
  2185. return name;
  2186. }
  2187. function adjustAttributeName(name, namespace) {
  2188. if (namespace === NS.SVG) {
  2189. return SVG_ATTRIBUTE_NAME_MAP.get(name) || name;
  2190. }
  2191. if (namespace === NS.MathML) {
  2192. return MATHML_ATTRIBUTE_NAME_MAP.get(name) || name;
  2193. }
  2194. return name;
  2195. }
  2196. function propagateEndLocation(node) {
  2197. const lastChild = (node.type === "VElement" ? node.endTag : null) || last__default["default"](node.children);
  2198. if (lastChild != null) {
  2199. node.range[1] = lastChild.range[1];
  2200. node.loc.end = lastChild.loc.end;
  2201. }
  2202. }
  2203. class Parser {
  2204. constructor(tokenizer, parserOptions) {
  2205. this.postProcessesForScript = [];
  2206. this.tokenizer = new IntermediateTokenizer(tokenizer);
  2207. this.locationCalculator = new LocationCalculatorForHtml(tokenizer.gaps, tokenizer.lineTerminators);
  2208. this.baseParserOptions = parserOptions;
  2209. this.isSFC = isSFCFile(parserOptions);
  2210. this.document = {
  2211. type: "VDocumentFragment",
  2212. range: [0, 0],
  2213. loc: {
  2214. start: { line: 1, column: 0 },
  2215. end: { line: 1, column: 0 },
  2216. },
  2217. parent: null,
  2218. children: [],
  2219. tokens: this.tokens,
  2220. comments: this.comments,
  2221. errors: this.errors,
  2222. };
  2223. this.elementStack = [];
  2224. this.vPreElement = null;
  2225. this.postProcessesForScript = [];
  2226. }
  2227. get text() {
  2228. return this.tokenizer.text;
  2229. }
  2230. get tokens() {
  2231. return this.tokenizer.tokens;
  2232. }
  2233. get comments() {
  2234. return this.tokenizer.comments;
  2235. }
  2236. get errors() {
  2237. return this.tokenizer.errors;
  2238. }
  2239. get namespace() {
  2240. return this.tokenizer.namespace;
  2241. }
  2242. set namespace(value) {
  2243. this.tokenizer.namespace = value;
  2244. }
  2245. get expressionEnabled() {
  2246. return this.tokenizer.expressionEnabled;
  2247. }
  2248. set expressionEnabled(value) {
  2249. this.tokenizer.expressionEnabled = value;
  2250. }
  2251. get currentNode() {
  2252. return last__default["default"](this.elementStack) || this.document;
  2253. }
  2254. get isInVPreElement() {
  2255. return this.vPreElement != null;
  2256. }
  2257. parse() {
  2258. let token = null;
  2259. while ((token = this.tokenizer.nextToken()) != null) {
  2260. this[token.type](token);
  2261. }
  2262. this.popElementStackUntil(0);
  2263. propagateEndLocation(this.document);
  2264. const doc = this.document;
  2265. const parserOptions = Object.assign(Object.assign({}, this.baseParserOptions), { parser: getScriptParser(this.baseParserOptions.parser, function* () {
  2266. yield "<template>";
  2267. yield getParserLangFromSFC(doc);
  2268. }) });
  2269. for (const proc of this.postProcessesForScript) {
  2270. proc(parserOptions);
  2271. }
  2272. this.postProcessesForScript = [];
  2273. return doc;
  2274. }
  2275. reportParseError(token, code) {
  2276. const error = ParseError.fromCode(code, token.range[0], token.loc.start.line, token.loc.start.column);
  2277. this.errors.push(error);
  2278. debug("[html] syntax error:", error.message);
  2279. }
  2280. popElementStack() {
  2281. assert__default["default"](this.elementStack.length >= 1);
  2282. const element = this.elementStack.pop();
  2283. propagateEndLocation(element);
  2284. const current = this.currentNode;
  2285. this.namespace =
  2286. current.type === "VElement" ? current.namespace : NS.HTML;
  2287. if (this.vPreElement === element) {
  2288. this.vPreElement = null;
  2289. this.expressionEnabled = true;
  2290. }
  2291. if (this.elementStack.length === 0) {
  2292. this.expressionEnabled = false;
  2293. }
  2294. }
  2295. popElementStackUntil(index) {
  2296. while (this.elementStack.length > index) {
  2297. this.popElementStack();
  2298. }
  2299. }
  2300. getTagName(startTagOrElement) {
  2301. return getTagName(startTagOrElement, this.isSFC);
  2302. }
  2303. detectNamespace(token) {
  2304. const name = this.getTagName(token);
  2305. let ns = this.namespace;
  2306. if (ns === NS.MathML || ns === NS.SVG) {
  2307. const element = this.currentNode;
  2308. if (element.type === "VElement") {
  2309. if (element.namespace === NS.MathML &&
  2310. this.getTagName(element) === "annotation-xml" &&
  2311. name === "svg") {
  2312. return NS.SVG;
  2313. }
  2314. if (isHTMLIntegrationPoint(element, this.isSFC) ||
  2315. (isMathMLIntegrationPoint(element, this.isSFC) &&
  2316. name !== "mglyph" &&
  2317. name !== "malignmark")) {
  2318. ns = NS.HTML;
  2319. }
  2320. }
  2321. }
  2322. if (ns === NS.HTML) {
  2323. if (name === "svg") {
  2324. return NS.SVG;
  2325. }
  2326. if (name === "math") {
  2327. return NS.MathML;
  2328. }
  2329. }
  2330. if (name === "template") {
  2331. const xmlns = token.attributes.find((a) => a.key.name === "xmlns");
  2332. const value = xmlns && xmlns.value && xmlns.value.value;
  2333. if (value === NS.HTML || value === NS.MathML || value === NS.SVG) {
  2334. return value;
  2335. }
  2336. }
  2337. return ns;
  2338. }
  2339. closeCurrentElementIfNecessary(token) {
  2340. const element = this.currentNode;
  2341. if (element.type !== "VElement") {
  2342. return;
  2343. }
  2344. const name = this.getTagName(token);
  2345. const elementName = this.getTagName(element);
  2346. if (elementName === "p" && HTML_NON_FHRASING_TAGS.has(name)) {
  2347. this.popElementStack();
  2348. }
  2349. if (elementName === name && HTML_CAN_BE_LEFT_OPEN_TAGS.has(name)) {
  2350. this.popElementStack();
  2351. }
  2352. if (DT_DD.test(elementName) && DT_DD.test(name)) {
  2353. this.popElementStack();
  2354. }
  2355. }
  2356. processAttribute(node, namespace) {
  2357. const tagName = this.getTagName(node.parent.parent);
  2358. const attrName = this.getTagName(node.key);
  2359. if ((this.expressionEnabled ||
  2360. (attrName === "v-pre" && !this.isInVPreElement)) &&
  2361. (DIRECTIVE_NAME.test(attrName) ||
  2362. attrName === "slot-scope" ||
  2363. (tagName === "template" && attrName === "scope"))) {
  2364. this.postProcessesForScript.push((parserOptions) => {
  2365. convertToDirective(this.text, parserOptions, this.locationCalculator, node);
  2366. });
  2367. return;
  2368. }
  2369. node.key.name = adjustAttributeName(node.key.name, namespace);
  2370. const key = this.getTagName(node.key);
  2371. const value = node.value && node.value.value;
  2372. if (key === "xmlns" && value !== namespace) {
  2373. this.reportParseError(node, "x-invalid-namespace");
  2374. }
  2375. else if (key === "xmlns:xlink" && value !== NS.XLink) {
  2376. this.reportParseError(node, "x-invalid-namespace");
  2377. }
  2378. }
  2379. processTemplateText(token, templateTokenizerOption) {
  2380. const TemplateTokenizer = typeof templateTokenizerOption === "function"
  2381. ? templateTokenizerOption
  2382. :
  2383. require(templateTokenizerOption);
  2384. const templateTokenizer = new TemplateTokenizer(token.value, this.text, {
  2385. startingLine: token.loc.start.line,
  2386. startingColumn: token.loc.start.column,
  2387. });
  2388. const rootTokenizer = this.tokenizer;
  2389. this.tokenizer = templateTokenizer;
  2390. let templateToken = null;
  2391. while ((templateToken = templateTokenizer.nextToken()) != null) {
  2392. this[templateToken.type](templateToken);
  2393. }
  2394. this.tokenizer = rootTokenizer;
  2395. const index = sortedIndexBy__default["default"](this.tokenizer.tokens, token, (x) => x.range[0]);
  2396. const count = sortedLastIndexBy__default["default"](this.tokenizer.tokens, token, (x) => x.range[1]) -
  2397. index;
  2398. this.tokenizer.tokens.splice(index, count, ...templateTokenizer.tokens);
  2399. this.tokenizer.comments.push(...templateTokenizer.comments);
  2400. this.tokenizer.errors.push(...templateTokenizer.errors);
  2401. }
  2402. StartTag(token) {
  2403. var _a;
  2404. debug("[html] StartTag %j", token);
  2405. this.closeCurrentElementIfNecessary(token);
  2406. const parent = this.currentNode;
  2407. const namespace = this.detectNamespace(token);
  2408. const element = {
  2409. type: "VElement",
  2410. range: [token.range[0], token.range[1]],
  2411. loc: { start: token.loc.start, end: token.loc.end },
  2412. parent,
  2413. name: adjustElementName(token.name, namespace),
  2414. rawName: token.rawName,
  2415. namespace,
  2416. startTag: {
  2417. type: "VStartTag",
  2418. range: token.range,
  2419. loc: token.loc,
  2420. parent: DUMMY_PARENT,
  2421. selfClosing: token.selfClosing,
  2422. attributes: token.attributes,
  2423. },
  2424. children: [],
  2425. endTag: null,
  2426. variables: [],
  2427. };
  2428. const hasVPre = !this.isInVPreElement &&
  2429. token.attributes.some((a) => this.getTagName(a.key) === "v-pre");
  2430. if (hasVPre) {
  2431. this.expressionEnabled = false;
  2432. }
  2433. parent.children.push(element);
  2434. element.startTag.parent = element;
  2435. for (const attribute of token.attributes) {
  2436. attribute.parent = element.startTag;
  2437. this.processAttribute(attribute, namespace);
  2438. }
  2439. this.postProcessesForScript.push(() => {
  2440. for (const attribute of element.startTag.attributes) {
  2441. if (attribute.directive) {
  2442. if (attribute.key.argument != null &&
  2443. attribute.key.argument.type === "VExpressionContainer") {
  2444. resolveReferences(attribute.key.argument);
  2445. }
  2446. if (attribute.value != null) {
  2447. resolveReferences(attribute.value);
  2448. }
  2449. }
  2450. }
  2451. });
  2452. const isVoid = namespace === NS.HTML &&
  2453. HTML_VOID_ELEMENT_TAGS.has(this.getTagName(element));
  2454. if (token.selfClosing && !isVoid && namespace === NS.HTML) {
  2455. this.reportParseError(token, "non-void-html-element-start-tag-with-trailing-solidus");
  2456. }
  2457. if (token.selfClosing || isVoid) {
  2458. this.expressionEnabled = !this.isInVPreElement;
  2459. return;
  2460. }
  2461. this.elementStack.push(element);
  2462. if (hasVPre) {
  2463. assert__default["default"](this.vPreElement === null);
  2464. this.vPreElement = element;
  2465. }
  2466. this.namespace = namespace;
  2467. if (namespace === NS.HTML) {
  2468. const elementName = this.getTagName(element);
  2469. if (element.parent.type === "VDocumentFragment") {
  2470. const langAttr = element.startTag.attributes.find((a) => !a.directive && a.key.name === "lang");
  2471. const lang = (_a = langAttr === null || langAttr === void 0 ? void 0 : langAttr.value) === null || _a === void 0 ? void 0 : _a.value;
  2472. if (elementName === "template") {
  2473. this.expressionEnabled = true;
  2474. if (lang && lang !== "html") {
  2475. this.tokenizer.state = "RAWTEXT";
  2476. this.expressionEnabled = false;
  2477. }
  2478. }
  2479. else if (this.isSFC) {
  2480. if (!lang || lang !== "html") {
  2481. this.tokenizer.state = "RAWTEXT";
  2482. }
  2483. }
  2484. else {
  2485. if (HTML_RCDATA_TAGS.has(elementName)) {
  2486. this.tokenizer.state = "RCDATA";
  2487. }
  2488. if (HTML_RAWTEXT_TAGS.has(elementName)) {
  2489. this.tokenizer.state = "RAWTEXT";
  2490. }
  2491. }
  2492. }
  2493. else {
  2494. if (HTML_RCDATA_TAGS.has(elementName)) {
  2495. this.tokenizer.state = "RCDATA";
  2496. }
  2497. if (HTML_RAWTEXT_TAGS.has(elementName)) {
  2498. this.tokenizer.state = "RAWTEXT";
  2499. }
  2500. }
  2501. }
  2502. }
  2503. EndTag(token) {
  2504. debug("[html] EndTag %j", token);
  2505. const i = findLastIndex__default["default"](this.elementStack, (el) => el.name.toLowerCase() === token.name);
  2506. if (i === -1) {
  2507. this.reportParseError(token, "x-invalid-end-tag");
  2508. return;
  2509. }
  2510. const element = this.elementStack[i];
  2511. element.endTag = {
  2512. type: "VEndTag",
  2513. range: token.range,
  2514. loc: token.loc,
  2515. parent: element,
  2516. };
  2517. this.popElementStackUntil(i);
  2518. }
  2519. Text(token) {
  2520. var _a, _b;
  2521. debug("[html] Text %j", token);
  2522. const parent = this.currentNode;
  2523. if (token.value &&
  2524. parent.type === "VElement" &&
  2525. parent.name === "template" &&
  2526. parent.parent.type === "VDocumentFragment") {
  2527. const langAttribute = parent.startTag.attributes.find((a) => a.key.name === "lang");
  2528. const lang = (_a = langAttribute === null || langAttribute === void 0 ? void 0 : langAttribute.value) === null || _a === void 0 ? void 0 : _a.value;
  2529. if (lang && lang !== "html") {
  2530. const templateTokenizerOption = (_b = this.baseParserOptions.templateTokenizer) === null || _b === void 0 ? void 0 : _b[lang];
  2531. if (templateTokenizerOption) {
  2532. this.processTemplateText(token, templateTokenizerOption);
  2533. return;
  2534. }
  2535. }
  2536. }
  2537. parent.children.push({
  2538. type: "VText",
  2539. range: token.range,
  2540. loc: token.loc,
  2541. parent,
  2542. value: token.value,
  2543. });
  2544. }
  2545. Mustache(token) {
  2546. debug("[html] Mustache %j", token);
  2547. const parent = this.currentNode;
  2548. const container = {
  2549. type: "VExpressionContainer",
  2550. range: token.range,
  2551. loc: token.loc,
  2552. parent,
  2553. expression: null,
  2554. references: [],
  2555. };
  2556. parent.children.push(container);
  2557. this.postProcessesForScript.push((parserOptions) => {
  2558. processMustache(parserOptions, this.locationCalculator, container, token);
  2559. resolveReferences(container);
  2560. });
  2561. }
  2562. }
  2563. 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]]);
  2564. 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] } }];
  2565. const EOF = -1;
  2566. const NULL = 0x00;
  2567. const TABULATION = 0x09;
  2568. const CARRIAGE_RETURN = 0x0D;
  2569. const LINE_FEED = 0x0A;
  2570. const FORM_FEED = 0x0C;
  2571. const SPACE = 0x20;
  2572. const EXCLAMATION_MARK = 0x21;
  2573. const QUOTATION_MARK = 0x22;
  2574. const NUMBER_SIGN = 0x23;
  2575. const AMPERSAND = 0x26;
  2576. const APOSTROPHE = 0x27;
  2577. const LEFT_PARENTHESIS = 0x28;
  2578. const RIGHT_PARENTHESIS = 0x29;
  2579. const ASTERISK = 0x2A;
  2580. const HYPHEN_MINUS = 0x2D;
  2581. const SOLIDUS = 0x2F;
  2582. const DIGIT_0 = 0x30;
  2583. const DIGIT_9 = 0x39;
  2584. const COLON = 0x3a;
  2585. const SEMICOLON = 0x3B;
  2586. const LESS_THAN_SIGN = 0x3C;
  2587. const EQUALS_SIGN = 0x3D;
  2588. const GREATER_THAN_SIGN = 0x3E;
  2589. const QUESTION_MARK = 0x3F;
  2590. const LATIN_CAPITAL_A = 0x41;
  2591. const LATIN_CAPITAL_D = 0x44;
  2592. const LATIN_CAPITAL_F = 0x46;
  2593. const LATIN_CAPITAL_X = 0x58;
  2594. const LATIN_CAPITAL_Z = 0x5A;
  2595. const LEFT_SQUARE_BRACKET = 0x5B;
  2596. const REVERSE_SOLIDUS = 0x5C;
  2597. const RIGHT_SQUARE_BRACKET = 0x5D;
  2598. const GRAVE_ACCENT = 0x60;
  2599. const LATIN_SMALL_A = 0x61;
  2600. const LATIN_SMALL_F = 0x66;
  2601. const LATIN_SMALL_X = 0x78;
  2602. const LATIN_SMALL_Z = 0x7A;
  2603. const LEFT_CURLY_BRACKET = 0x7B;
  2604. const RIGHT_CURLY_BRACKET = 0x7D;
  2605. const NULL_REPLACEMENT = 0xFFFD;
  2606. function isWhitespace(cp) {
  2607. return cp === TABULATION || cp === LINE_FEED || cp === FORM_FEED || cp === CARRIAGE_RETURN || cp === SPACE;
  2608. }
  2609. function isUpperLetter(cp) {
  2610. return cp >= LATIN_CAPITAL_A && cp <= LATIN_CAPITAL_Z;
  2611. }
  2612. function isLowerLetter(cp) {
  2613. return cp >= LATIN_SMALL_A && cp <= LATIN_SMALL_Z;
  2614. }
  2615. function isLetter(cp) {
  2616. return isLowerLetter(cp) || isUpperLetter(cp);
  2617. }
  2618. function isDigit(cp) {
  2619. return cp >= DIGIT_0 && cp <= DIGIT_9;
  2620. }
  2621. function isUpperHexDigit(cp) {
  2622. return cp >= LATIN_CAPITAL_A && cp <= LATIN_CAPITAL_F;
  2623. }
  2624. function isLowerHexDigit(cp) {
  2625. return cp >= LATIN_SMALL_A && cp <= LATIN_SMALL_F;
  2626. }
  2627. function isHexDigit(cp) {
  2628. return isDigit(cp) || isUpperHexDigit(cp) || isLowerHexDigit(cp);
  2629. }
  2630. function isControl(cp) {
  2631. return (cp >= 0 && cp <= 0x1F) || (cp >= 0x7F && cp <= 0x9F);
  2632. }
  2633. function isSurrogate(cp) {
  2634. return cp >= 0xD800 && cp <= 0xDFFF;
  2635. }
  2636. function isSurrogatePair(cp) {
  2637. return cp >= 0xDC00 && cp <= 0xDFFF;
  2638. }
  2639. function isNonCharacter(cp) {
  2640. return ((cp >= 0xFDD0 && cp <= 0xFDEF) ||
  2641. ((cp & 0xFFFE) === 0xFFFE && cp <= 0x10FFFF));
  2642. }
  2643. function toLowerCodePoint(cp) {
  2644. return cp + 0x0020;
  2645. }
  2646. class Tokenizer {
  2647. constructor(text, parserOptions) {
  2648. this.vExpressionScriptState = null;
  2649. debug("[html] the source code length: %d", text.length);
  2650. this.text = text;
  2651. this.gaps = [];
  2652. this.lineTerminators = [];
  2653. this.parserOptions = parserOptions || {};
  2654. this.lastCodePoint = this.lastCodePointRaw = NULL;
  2655. this.offset = -1;
  2656. this.column = -1;
  2657. this.line = 1;
  2658. this.state = "DATA";
  2659. this.returnState = "DATA";
  2660. this.reconsuming = false;
  2661. this.buffer = [];
  2662. this.crStartOffset = -1;
  2663. this.crCode = 0;
  2664. this.errors = [];
  2665. this.committedToken = null;
  2666. this.provisionalToken = null;
  2667. this.currentToken = null;
  2668. this.lastTagOpenToken = null;
  2669. this.tokenStartOffset = -1;
  2670. this.tokenStartColumn = -1;
  2671. this.tokenStartLine = 1;
  2672. this.namespace = NS.HTML;
  2673. this.expressionEnabled = false;
  2674. }
  2675. nextToken() {
  2676. let cp = this.lastCodePoint;
  2677. while (this.committedToken == null &&
  2678. (cp !== EOF || this.reconsuming)) {
  2679. if (this.provisionalToken != null && !this.isProvisionalState()) {
  2680. this.commitProvisionalToken();
  2681. if (this.committedToken != null) {
  2682. break;
  2683. }
  2684. }
  2685. if (this.reconsuming) {
  2686. this.reconsuming = false;
  2687. cp = this.lastCodePoint;
  2688. }
  2689. else {
  2690. cp = this.consumeNextCodePoint();
  2691. }
  2692. debug("[html] parse", cp, this.state);
  2693. this.state = this[this.state](cp);
  2694. }
  2695. {
  2696. const token = this.consumeCommittedToken();
  2697. if (token != null) {
  2698. return token;
  2699. }
  2700. }
  2701. assert__default["default"](cp === EOF);
  2702. if (this.currentToken != null) {
  2703. this.endToken();
  2704. const token = this.consumeCommittedToken();
  2705. if (token != null) {
  2706. return token;
  2707. }
  2708. }
  2709. return this.currentToken;
  2710. }
  2711. consumeCommittedToken() {
  2712. const token = this.committedToken;
  2713. this.committedToken = null;
  2714. return token;
  2715. }
  2716. consumeNextCodePoint() {
  2717. if (this.offset >= this.text.length) {
  2718. this.lastCodePoint = this.lastCodePointRaw = EOF;
  2719. return EOF;
  2720. }
  2721. this.offset += this.lastCodePoint >= 0x10000 ? 2 : 1;
  2722. if (this.offset >= this.text.length) {
  2723. this.advanceLocation();
  2724. this.lastCodePoint = this.lastCodePointRaw = EOF;
  2725. return EOF;
  2726. }
  2727. const cp = this.text.codePointAt(this.offset);
  2728. if (isSurrogate(this.text.charCodeAt(this.offset)) &&
  2729. !isSurrogatePair(this.text.charCodeAt(this.offset + 1))) {
  2730. this.reportParseError("surrogate-in-input-stream");
  2731. }
  2732. if (isNonCharacter(cp)) {
  2733. this.reportParseError("noncharacter-in-input-stream");
  2734. }
  2735. if (isControl(cp) && !isWhitespace(cp) && cp !== NULL) {
  2736. this.reportParseError("control-character-in-input-stream");
  2737. }
  2738. if (this.lastCodePointRaw === CARRIAGE_RETURN && cp === LINE_FEED) {
  2739. this.lastCodePoint = this.lastCodePointRaw = LINE_FEED;
  2740. this.gaps.push(this.offset);
  2741. return this.consumeNextCodePoint();
  2742. }
  2743. this.advanceLocation();
  2744. this.lastCodePoint = this.lastCodePointRaw = cp;
  2745. if (cp === CARRIAGE_RETURN) {
  2746. this.lastCodePoint = LINE_FEED;
  2747. return LINE_FEED;
  2748. }
  2749. return cp;
  2750. }
  2751. advanceLocation() {
  2752. if (this.lastCodePointRaw === LINE_FEED) {
  2753. this.lineTerminators.push(this.offset);
  2754. this.line += 1;
  2755. this.column = 0;
  2756. }
  2757. else {
  2758. this.column += this.lastCodePoint >= 0x10000 ? 2 : 1;
  2759. }
  2760. }
  2761. reconsumeAs(state) {
  2762. this.reconsuming = true;
  2763. return state;
  2764. }
  2765. reportParseError(code) {
  2766. const error = ParseError.fromCode(code, this.offset, this.line, this.column);
  2767. this.errors.push(error);
  2768. debug("[html] syntax error:", error.message);
  2769. }
  2770. setStartTokenMark() {
  2771. this.tokenStartOffset = this.offset;
  2772. this.tokenStartLine = this.line;
  2773. this.tokenStartColumn = this.column;
  2774. }
  2775. clearStartTokenMark() {
  2776. this.tokenStartOffset = -1;
  2777. }
  2778. startToken(type) {
  2779. if (this.tokenStartOffset === -1) {
  2780. this.setStartTokenMark();
  2781. }
  2782. const offset = this.tokenStartOffset;
  2783. const line = this.tokenStartLine;
  2784. const column = this.tokenStartColumn;
  2785. if (this.currentToken != null) {
  2786. this.endToken();
  2787. }
  2788. this.tokenStartOffset = -1;
  2789. const token = (this.currentToken = {
  2790. type,
  2791. range: [offset, -1],
  2792. loc: {
  2793. start: { line, column },
  2794. end: { line: -1, column: -1 },
  2795. },
  2796. value: "",
  2797. });
  2798. debug("[html] start token: %d %s", offset, token.type);
  2799. return this.currentToken;
  2800. }
  2801. endToken() {
  2802. if (this.currentToken == null) {
  2803. throw new Error("Invalid state");
  2804. }
  2805. if (this.tokenStartOffset === -1) {
  2806. this.setStartTokenMark();
  2807. }
  2808. const token = this.currentToken;
  2809. const offset = this.tokenStartOffset;
  2810. const line = this.tokenStartLine;
  2811. const column = this.tokenStartColumn;
  2812. const provisional = this.isProvisionalState();
  2813. this.currentToken = null;
  2814. this.tokenStartOffset = -1;
  2815. token.range[1] = offset;
  2816. token.loc.end.line = line;
  2817. token.loc.end.column = column;
  2818. if (token.range[0] === offset && !provisional) {
  2819. debug("[html] abandon token: %j %s %j", token.range, token.type, token.value);
  2820. return null;
  2821. }
  2822. if (provisional) {
  2823. if (this.provisionalToken != null) {
  2824. this.commitProvisionalToken();
  2825. }
  2826. this.provisionalToken = token;
  2827. debug("[html] provisional-commit token: %j %s %j", token.range, token.type, token.value);
  2828. }
  2829. else {
  2830. this.commitToken(token);
  2831. }
  2832. return token;
  2833. }
  2834. commitToken(token) {
  2835. assert__default["default"](this.committedToken == null, "Invalid state: the commited token existed already.");
  2836. debug("[html] commit token: %j %j %s %j", token.range, token.loc, token.type, token.value);
  2837. this.committedToken = token;
  2838. if (token.type === "HTMLTagOpen") {
  2839. this.lastTagOpenToken = token;
  2840. }
  2841. }
  2842. isProvisionalState() {
  2843. return (this.state.startsWith("RCDATA_") ||
  2844. this.state.startsWith("RAWTEXT_"));
  2845. }
  2846. commitProvisionalToken() {
  2847. assert__default["default"](this.provisionalToken != null, "Invalid state: the provisional token was not found.");
  2848. const token = this.provisionalToken;
  2849. this.provisionalToken = null;
  2850. if (token.range[0] < token.range[1]) {
  2851. this.commitToken(token);
  2852. }
  2853. }
  2854. rollbackProvisionalToken() {
  2855. assert__default["default"](this.currentToken != null);
  2856. assert__default["default"](this.provisionalToken != null);
  2857. const token = this.currentToken;
  2858. debug("[html] rollback token: %d %s", token.range[0], token.type);
  2859. this.currentToken = this.provisionalToken;
  2860. this.provisionalToken = null;
  2861. }
  2862. appendTokenValue(cp, expected) {
  2863. const token = this.currentToken;
  2864. if (token == null || (expected != null && token.type !== expected)) {
  2865. const msg1 = expected ? `"${expected}" type` : "any token";
  2866. const msg2 = token ? `"${token.type}" type` : "no token";
  2867. throw new Error(`Tokenizer: Invalid state. Expected ${msg1}, but got ${msg2}.`);
  2868. }
  2869. token.value += String.fromCodePoint(cp);
  2870. }
  2871. isAppropriateEndTagOpen() {
  2872. return (this.currentToken != null &&
  2873. this.lastTagOpenToken != null &&
  2874. this.currentToken.type === "HTMLEndTagOpen" &&
  2875. this.currentToken.value === this.lastTagOpenToken.value);
  2876. }
  2877. DATA(cp) {
  2878. this.clearStartTokenMark();
  2879. while (true) {
  2880. const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLText";
  2881. if (this.currentToken != null && this.currentToken.type !== type) {
  2882. this.endToken();
  2883. return this.reconsumeAs(this.state);
  2884. }
  2885. if (this.currentToken == null) {
  2886. this.startToken(type);
  2887. }
  2888. if (cp === AMPERSAND) {
  2889. this.returnState = "DATA";
  2890. return "CHARACTER_REFERENCE";
  2891. }
  2892. if (cp === LESS_THAN_SIGN) {
  2893. this.setStartTokenMark();
  2894. return "TAG_OPEN";
  2895. }
  2896. if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
  2897. this.setStartTokenMark();
  2898. this.returnState = "DATA";
  2899. return "V_EXPRESSION_START";
  2900. }
  2901. if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
  2902. this.setStartTokenMark();
  2903. this.returnState = "DATA";
  2904. return "V_EXPRESSION_END";
  2905. }
  2906. if (cp === EOF) {
  2907. return "DATA";
  2908. }
  2909. if (cp === NULL) {
  2910. this.reportParseError("unexpected-null-character");
  2911. }
  2912. this.appendTokenValue(cp, type);
  2913. cp = this.consumeNextCodePoint();
  2914. }
  2915. }
  2916. RCDATA(cp) {
  2917. this.clearStartTokenMark();
  2918. while (true) {
  2919. const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLRCDataText";
  2920. if (this.currentToken != null && this.currentToken.type !== type) {
  2921. this.endToken();
  2922. return this.reconsumeAs(this.state);
  2923. }
  2924. if (this.currentToken == null) {
  2925. this.startToken(type);
  2926. }
  2927. if (cp === AMPERSAND) {
  2928. this.returnState = "RCDATA";
  2929. return "CHARACTER_REFERENCE";
  2930. }
  2931. if (cp === LESS_THAN_SIGN) {
  2932. this.setStartTokenMark();
  2933. return "RCDATA_LESS_THAN_SIGN";
  2934. }
  2935. if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
  2936. this.setStartTokenMark();
  2937. this.returnState = "RCDATA";
  2938. return "V_EXPRESSION_START";
  2939. }
  2940. if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
  2941. this.setStartTokenMark();
  2942. this.returnState = "RCDATA";
  2943. return "V_EXPRESSION_END";
  2944. }
  2945. if (cp === EOF) {
  2946. return "DATA";
  2947. }
  2948. if (cp === NULL) {
  2949. this.reportParseError("unexpected-null-character");
  2950. cp = NULL_REPLACEMENT;
  2951. }
  2952. this.appendTokenValue(cp, type);
  2953. cp = this.consumeNextCodePoint();
  2954. }
  2955. }
  2956. RAWTEXT(cp) {
  2957. this.clearStartTokenMark();
  2958. while (true) {
  2959. const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLRawText";
  2960. if (this.currentToken != null && this.currentToken.type !== type) {
  2961. this.endToken();
  2962. return this.reconsumeAs(this.state);
  2963. }
  2964. if (this.currentToken == null) {
  2965. this.startToken(type);
  2966. }
  2967. if (cp === LESS_THAN_SIGN) {
  2968. this.setStartTokenMark();
  2969. return "RAWTEXT_LESS_THAN_SIGN";
  2970. }
  2971. if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
  2972. this.setStartTokenMark();
  2973. this.returnState = "RAWTEXT";
  2974. return "V_EXPRESSION_START";
  2975. }
  2976. if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
  2977. this.setStartTokenMark();
  2978. this.returnState = "RAWTEXT";
  2979. return "V_EXPRESSION_END";
  2980. }
  2981. if (cp === EOF) {
  2982. return "DATA";
  2983. }
  2984. if (cp === NULL) {
  2985. this.reportParseError("unexpected-null-character");
  2986. cp = NULL_REPLACEMENT;
  2987. }
  2988. this.appendTokenValue(cp, type);
  2989. cp = this.consumeNextCodePoint();
  2990. }
  2991. }
  2992. TAG_OPEN(cp) {
  2993. if (cp === EXCLAMATION_MARK) {
  2994. return "MARKUP_DECLARATION_OPEN";
  2995. }
  2996. if (cp === SOLIDUS) {
  2997. return "END_TAG_OPEN";
  2998. }
  2999. if (isLetter(cp)) {
  3000. this.startToken("HTMLTagOpen");
  3001. return this.reconsumeAs("TAG_NAME");
  3002. }
  3003. if (cp === QUESTION_MARK) {
  3004. this.reportParseError("unexpected-question-mark-instead-of-tag-name");
  3005. this.startToken("HTMLBogusComment");
  3006. return this.reconsumeAs("BOGUS_COMMENT");
  3007. }
  3008. if (cp === EOF) {
  3009. this.clearStartTokenMark();
  3010. this.reportParseError("eof-before-tag-name");
  3011. this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
  3012. return "DATA";
  3013. }
  3014. this.reportParseError("invalid-first-character-of-tag-name");
  3015. this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
  3016. return this.reconsumeAs("DATA");
  3017. }
  3018. END_TAG_OPEN(cp) {
  3019. if (isLetter(cp)) {
  3020. this.startToken("HTMLEndTagOpen");
  3021. return this.reconsumeAs("TAG_NAME");
  3022. }
  3023. if (cp === GREATER_THAN_SIGN) {
  3024. this.endToken();
  3025. this.reportParseError("missing-end-tag-name");
  3026. return "DATA";
  3027. }
  3028. if (cp === EOF) {
  3029. this.clearStartTokenMark();
  3030. this.reportParseError("eof-before-tag-name");
  3031. this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
  3032. this.appendTokenValue(SOLIDUS, "HTMLText");
  3033. return "DATA";
  3034. }
  3035. this.reportParseError("invalid-first-character-of-tag-name");
  3036. this.startToken("HTMLBogusComment");
  3037. return this.reconsumeAs("BOGUS_COMMENT");
  3038. }
  3039. TAG_NAME(cp) {
  3040. while (true) {
  3041. if (isWhitespace(cp)) {
  3042. this.endToken();
  3043. return "BEFORE_ATTRIBUTE_NAME";
  3044. }
  3045. if (cp === SOLIDUS) {
  3046. this.endToken();
  3047. this.setStartTokenMark();
  3048. return "SELF_CLOSING_START_TAG";
  3049. }
  3050. if (cp === GREATER_THAN_SIGN) {
  3051. this.startToken("HTMLTagClose");
  3052. return "DATA";
  3053. }
  3054. if (cp === EOF) {
  3055. this.reportParseError("eof-in-tag");
  3056. return "DATA";
  3057. }
  3058. if (cp === NULL) {
  3059. this.reportParseError("unexpected-null-character");
  3060. cp = NULL_REPLACEMENT;
  3061. }
  3062. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, null);
  3063. cp = this.consumeNextCodePoint();
  3064. }
  3065. }
  3066. RCDATA_LESS_THAN_SIGN(cp) {
  3067. if (cp === SOLIDUS) {
  3068. this.buffer = [];
  3069. return "RCDATA_END_TAG_OPEN";
  3070. }
  3071. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
  3072. return this.reconsumeAs("RCDATA");
  3073. }
  3074. RCDATA_END_TAG_OPEN(cp) {
  3075. if (isLetter(cp)) {
  3076. this.startToken("HTMLEndTagOpen");
  3077. return this.reconsumeAs("RCDATA_END_TAG_NAME");
  3078. }
  3079. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
  3080. this.appendTokenValue(SOLIDUS, "HTMLRCDataText");
  3081. return this.reconsumeAs("RCDATA");
  3082. }
  3083. RCDATA_END_TAG_NAME(cp) {
  3084. while (true) {
  3085. if (isWhitespace(cp) && this.isAppropriateEndTagOpen()) {
  3086. this.endToken();
  3087. return "BEFORE_ATTRIBUTE_NAME";
  3088. }
  3089. if (cp === SOLIDUS && this.isAppropriateEndTagOpen()) {
  3090. this.endToken();
  3091. this.setStartTokenMark();
  3092. return "SELF_CLOSING_START_TAG";
  3093. }
  3094. if (cp === GREATER_THAN_SIGN && this.isAppropriateEndTagOpen()) {
  3095. this.startToken("HTMLTagClose");
  3096. return "DATA";
  3097. }
  3098. if (!isLetter(cp)) {
  3099. this.rollbackProvisionalToken();
  3100. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
  3101. this.appendTokenValue(SOLIDUS, "HTMLRCDataText");
  3102. for (const cp1 of this.buffer) {
  3103. this.appendTokenValue(cp1, "HTMLRCDataText");
  3104. }
  3105. return this.reconsumeAs("RCDATA");
  3106. }
  3107. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLEndTagOpen");
  3108. this.buffer.push(cp);
  3109. cp = this.consumeNextCodePoint();
  3110. }
  3111. }
  3112. RAWTEXT_LESS_THAN_SIGN(cp) {
  3113. if (cp === SOLIDUS) {
  3114. this.buffer = [];
  3115. return "RAWTEXT_END_TAG_OPEN";
  3116. }
  3117. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
  3118. return this.reconsumeAs("RAWTEXT");
  3119. }
  3120. RAWTEXT_END_TAG_OPEN(cp) {
  3121. if (isLetter(cp)) {
  3122. this.startToken("HTMLEndTagOpen");
  3123. return this.reconsumeAs("RAWTEXT_END_TAG_NAME");
  3124. }
  3125. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
  3126. this.appendTokenValue(SOLIDUS, "HTMLRawText");
  3127. return this.reconsumeAs("RAWTEXT");
  3128. }
  3129. RAWTEXT_END_TAG_NAME(cp) {
  3130. while (true) {
  3131. if (cp === SOLIDUS && this.isAppropriateEndTagOpen()) {
  3132. this.endToken();
  3133. this.setStartTokenMark();
  3134. return "SELF_CLOSING_START_TAG";
  3135. }
  3136. if (cp === GREATER_THAN_SIGN && this.isAppropriateEndTagOpen()) {
  3137. this.startToken("HTMLTagClose");
  3138. return "DATA";
  3139. }
  3140. if (isWhitespace(cp) && this.isAppropriateEndTagOpen()) {
  3141. this.endToken();
  3142. return "BEFORE_ATTRIBUTE_NAME";
  3143. }
  3144. if (!isLetter(cp) && !maybeValidCustomBlock.call(this, cp)) {
  3145. this.rollbackProvisionalToken();
  3146. this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
  3147. this.appendTokenValue(SOLIDUS, "HTMLRawText");
  3148. for (const cp1 of this.buffer) {
  3149. this.appendTokenValue(cp1, "HTMLRawText");
  3150. }
  3151. return this.reconsumeAs("RAWTEXT");
  3152. }
  3153. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLEndTagOpen");
  3154. this.buffer.push(cp);
  3155. cp = this.consumeNextCodePoint();
  3156. }
  3157. function maybeValidCustomBlock(nextCp) {
  3158. return (this.currentToken &&
  3159. this.lastTagOpenToken &&
  3160. this.lastTagOpenToken.value.startsWith(this.currentToken.value + String.fromCodePoint(nextCp)));
  3161. }
  3162. }
  3163. BEFORE_ATTRIBUTE_NAME(cp) {
  3164. while (isWhitespace(cp)) {
  3165. cp = this.consumeNextCodePoint();
  3166. }
  3167. if (cp === SOLIDUS || cp === GREATER_THAN_SIGN || cp === EOF) {
  3168. return this.reconsumeAs("AFTER_ATTRIBUTE_NAME");
  3169. }
  3170. if (cp === EQUALS_SIGN) {
  3171. this.reportParseError("unexpected-equals-sign-before-attribute-name");
  3172. this.startToken("HTMLIdentifier");
  3173. this.appendTokenValue(cp, "HTMLIdentifier");
  3174. return "ATTRIBUTE_NAME";
  3175. }
  3176. this.startToken("HTMLIdentifier");
  3177. return this.reconsumeAs("ATTRIBUTE_NAME");
  3178. }
  3179. ATTRIBUTE_NAME(cp) {
  3180. while (true) {
  3181. if (isWhitespace(cp) ||
  3182. cp === SOLIDUS ||
  3183. cp === GREATER_THAN_SIGN ||
  3184. cp === EOF) {
  3185. this.endToken();
  3186. return this.reconsumeAs("AFTER_ATTRIBUTE_NAME");
  3187. }
  3188. if (cp === EQUALS_SIGN) {
  3189. this.startToken("HTMLAssociation");
  3190. return "BEFORE_ATTRIBUTE_VALUE";
  3191. }
  3192. if (cp === NULL) {
  3193. this.reportParseError("unexpected-null-character");
  3194. cp = NULL_REPLACEMENT;
  3195. }
  3196. if (cp === QUOTATION_MARK ||
  3197. cp === APOSTROPHE ||
  3198. cp === LESS_THAN_SIGN) {
  3199. this.reportParseError("unexpected-character-in-attribute-name");
  3200. }
  3201. this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLIdentifier");
  3202. cp = this.consumeNextCodePoint();
  3203. }
  3204. }
  3205. AFTER_ATTRIBUTE_NAME(cp) {
  3206. while (isWhitespace(cp)) {
  3207. cp = this.consumeNextCodePoint();
  3208. }
  3209. if (cp === SOLIDUS) {
  3210. this.setStartTokenMark();
  3211. return "SELF_CLOSING_START_TAG";
  3212. }
  3213. if (cp === EQUALS_SIGN) {
  3214. this.startToken("HTMLAssociation");
  3215. return "BEFORE_ATTRIBUTE_VALUE";
  3216. }
  3217. if (cp === GREATER_THAN_SIGN) {
  3218. this.startToken("HTMLTagClose");
  3219. return "DATA";
  3220. }
  3221. if (cp === EOF) {
  3222. this.reportParseError("eof-in-tag");
  3223. return "DATA";
  3224. }
  3225. this.startToken("HTMLIdentifier");
  3226. return this.reconsumeAs("ATTRIBUTE_NAME");
  3227. }
  3228. BEFORE_ATTRIBUTE_VALUE(cp) {
  3229. this.endToken();
  3230. while (isWhitespace(cp)) {
  3231. cp = this.consumeNextCodePoint();
  3232. }
  3233. if (cp === GREATER_THAN_SIGN) {
  3234. this.reportParseError("missing-attribute-value");
  3235. this.startToken("HTMLTagClose");
  3236. return "DATA";
  3237. }
  3238. this.startToken("HTMLLiteral");
  3239. if (cp === QUOTATION_MARK) {
  3240. return "ATTRIBUTE_VALUE_DOUBLE_QUOTED";
  3241. }
  3242. if (cp === APOSTROPHE) {
  3243. return "ATTRIBUTE_VALUE_SINGLE_QUOTED";
  3244. }
  3245. return this.reconsumeAs("ATTRIBUTE_VALUE_UNQUOTED");
  3246. }
  3247. ATTRIBUTE_VALUE_DOUBLE_QUOTED(cp) {
  3248. while (true) {
  3249. if (cp === QUOTATION_MARK) {
  3250. return "AFTER_ATTRIBUTE_VALUE_QUOTED";
  3251. }
  3252. if (cp === AMPERSAND) {
  3253. this.returnState = "ATTRIBUTE_VALUE_DOUBLE_QUOTED";
  3254. return "CHARACTER_REFERENCE";
  3255. }
  3256. if (cp === NULL) {
  3257. this.reportParseError("unexpected-null-character");
  3258. cp = NULL_REPLACEMENT;
  3259. }
  3260. if (cp === EOF) {
  3261. this.reportParseError("eof-in-tag");
  3262. return "DATA";
  3263. }
  3264. this.appendTokenValue(cp, "HTMLLiteral");
  3265. cp = this.consumeNextCodePoint();
  3266. }
  3267. }
  3268. ATTRIBUTE_VALUE_SINGLE_QUOTED(cp) {
  3269. while (true) {
  3270. if (cp === APOSTROPHE) {
  3271. return "AFTER_ATTRIBUTE_VALUE_QUOTED";
  3272. }
  3273. if (cp === AMPERSAND) {
  3274. this.returnState = "ATTRIBUTE_VALUE_SINGLE_QUOTED";
  3275. return "CHARACTER_REFERENCE";
  3276. }
  3277. if (cp === NULL) {
  3278. this.reportParseError("unexpected-null-character");
  3279. cp = NULL_REPLACEMENT;
  3280. }
  3281. if (cp === EOF) {
  3282. this.reportParseError("eof-in-tag");
  3283. return "DATA";
  3284. }
  3285. this.appendTokenValue(cp, "HTMLLiteral");
  3286. cp = this.consumeNextCodePoint();
  3287. }
  3288. }
  3289. ATTRIBUTE_VALUE_UNQUOTED(cp) {
  3290. while (true) {
  3291. if (isWhitespace(cp)) {
  3292. this.endToken();
  3293. return "BEFORE_ATTRIBUTE_NAME";
  3294. }
  3295. if (cp === AMPERSAND) {
  3296. this.returnState = "ATTRIBUTE_VALUE_UNQUOTED";
  3297. return "CHARACTER_REFERENCE";
  3298. }
  3299. if (cp === GREATER_THAN_SIGN) {
  3300. this.startToken("HTMLTagClose");
  3301. return "DATA";
  3302. }
  3303. if (cp === NULL) {
  3304. this.reportParseError("unexpected-null-character");
  3305. cp = NULL_REPLACEMENT;
  3306. }
  3307. if (cp === QUOTATION_MARK ||
  3308. cp === APOSTROPHE ||
  3309. cp === LESS_THAN_SIGN ||
  3310. cp === EQUALS_SIGN ||
  3311. cp === GRAVE_ACCENT) {
  3312. this.reportParseError("unexpected-character-in-unquoted-attribute-value");
  3313. }
  3314. if (cp === EOF) {
  3315. this.reportParseError("eof-in-tag");
  3316. return "DATA";
  3317. }
  3318. this.appendTokenValue(cp, "HTMLLiteral");
  3319. cp = this.consumeNextCodePoint();
  3320. }
  3321. }
  3322. AFTER_ATTRIBUTE_VALUE_QUOTED(cp) {
  3323. this.endToken();
  3324. if (isWhitespace(cp)) {
  3325. return "BEFORE_ATTRIBUTE_NAME";
  3326. }
  3327. if (cp === SOLIDUS) {
  3328. this.setStartTokenMark();
  3329. return "SELF_CLOSING_START_TAG";
  3330. }
  3331. if (cp === GREATER_THAN_SIGN) {
  3332. this.startToken("HTMLTagClose");
  3333. return "DATA";
  3334. }
  3335. if (cp === EOF) {
  3336. this.reportParseError("eof-in-tag");
  3337. return "DATA";
  3338. }
  3339. this.reportParseError("missing-whitespace-between-attributes");
  3340. return this.reconsumeAs("BEFORE_ATTRIBUTE_NAME");
  3341. }
  3342. SELF_CLOSING_START_TAG(cp) {
  3343. if (cp === GREATER_THAN_SIGN) {
  3344. this.startToken("HTMLSelfClosingTagClose");
  3345. return "DATA";
  3346. }
  3347. if (cp === EOF) {
  3348. this.reportParseError("eof-in-tag");
  3349. return "DATA";
  3350. }
  3351. this.reportParseError("unexpected-solidus-in-tag");
  3352. this.clearStartTokenMark();
  3353. return this.reconsumeAs("BEFORE_ATTRIBUTE_NAME");
  3354. }
  3355. BOGUS_COMMENT(cp) {
  3356. while (true) {
  3357. if (cp === GREATER_THAN_SIGN) {
  3358. return "DATA";
  3359. }
  3360. if (cp === EOF) {
  3361. return "DATA";
  3362. }
  3363. if (cp === NULL) {
  3364. cp = NULL_REPLACEMENT;
  3365. }
  3366. this.appendTokenValue(cp, null);
  3367. cp = this.consumeNextCodePoint();
  3368. }
  3369. }
  3370. MARKUP_DECLARATION_OPEN(cp) {
  3371. if (cp === HYPHEN_MINUS && this.text[this.offset + 1] === "-") {
  3372. this.offset += 1;
  3373. this.column += 1;
  3374. this.startToken("HTMLComment");
  3375. return "COMMENT_START";
  3376. }
  3377. if (cp === LATIN_CAPITAL_D &&
  3378. this.text.slice(this.offset + 1, this.offset + 7) === "OCTYPE") {
  3379. this.startToken("HTMLBogusComment");
  3380. this.appendTokenValue(cp, "HTMLBogusComment");
  3381. return "BOGUS_COMMENT";
  3382. }
  3383. if (cp === LEFT_SQUARE_BRACKET &&
  3384. this.text.slice(this.offset + 1, this.offset + 7) === "CDATA[") {
  3385. this.offset += 6;
  3386. this.column += 6;
  3387. if (this.namespace === NS.HTML) {
  3388. this.reportParseError("cdata-in-html-content");
  3389. this.startToken("HTMLBogusComment").value = "[CDATA[";
  3390. return "BOGUS_COMMENT";
  3391. }
  3392. this.startToken("HTMLCDataText");
  3393. return "CDATA_SECTION";
  3394. }
  3395. this.reportParseError("incorrectly-opened-comment");
  3396. this.startToken("HTMLBogusComment");
  3397. return this.reconsumeAs("BOGUS_COMMENT");
  3398. }
  3399. COMMENT_START(cp) {
  3400. if (cp === HYPHEN_MINUS) {
  3401. return "COMMENT_START_DASH";
  3402. }
  3403. if (cp === GREATER_THAN_SIGN) {
  3404. this.reportParseError("abrupt-closing-of-empty-comment");
  3405. return "DATA";
  3406. }
  3407. return this.reconsumeAs("COMMENT");
  3408. }
  3409. COMMENT_START_DASH(cp) {
  3410. if (cp === HYPHEN_MINUS) {
  3411. return "COMMENT_END";
  3412. }
  3413. if (cp === GREATER_THAN_SIGN) {
  3414. this.reportParseError("abrupt-closing-of-empty-comment");
  3415. return "DATA";
  3416. }
  3417. if (cp === EOF) {
  3418. this.reportParseError("eof-in-comment");
  3419. return "DATA";
  3420. }
  3421. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3422. return this.reconsumeAs("COMMENT");
  3423. }
  3424. COMMENT(cp) {
  3425. while (true) {
  3426. if (cp === LESS_THAN_SIGN) {
  3427. this.appendTokenValue(LESS_THAN_SIGN, "HTMLComment");
  3428. return "COMMENT_LESS_THAN_SIGN";
  3429. }
  3430. if (cp === HYPHEN_MINUS) {
  3431. return "COMMENT_END_DASH";
  3432. }
  3433. if (cp === NULL) {
  3434. this.reportParseError("unexpected-null-character");
  3435. cp = NULL_REPLACEMENT;
  3436. }
  3437. if (cp === EOF) {
  3438. this.reportParseError("eof-in-comment");
  3439. return "DATA";
  3440. }
  3441. this.appendTokenValue(cp, "HTMLComment");
  3442. cp = this.consumeNextCodePoint();
  3443. }
  3444. }
  3445. COMMENT_LESS_THAN_SIGN(cp) {
  3446. while (true) {
  3447. if (cp === EXCLAMATION_MARK) {
  3448. this.appendTokenValue(cp, "HTMLComment");
  3449. return "COMMENT_LESS_THAN_SIGN_BANG";
  3450. }
  3451. if (cp !== LESS_THAN_SIGN) {
  3452. return this.reconsumeAs("COMMENT");
  3453. }
  3454. this.appendTokenValue(cp, "HTMLComment");
  3455. cp = this.consumeNextCodePoint();
  3456. }
  3457. }
  3458. COMMENT_LESS_THAN_SIGN_BANG(cp) {
  3459. if (cp === HYPHEN_MINUS) {
  3460. return "COMMENT_LESS_THAN_SIGN_BANG_DASH";
  3461. }
  3462. return this.reconsumeAs("COMMENT");
  3463. }
  3464. COMMENT_LESS_THAN_SIGN_BANG_DASH(cp) {
  3465. if (cp === HYPHEN_MINUS) {
  3466. return "COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH";
  3467. }
  3468. return this.reconsumeAs("COMMENT_END_DASH");
  3469. }
  3470. COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH(cp) {
  3471. if (cp !== GREATER_THAN_SIGN && cp !== EOF) {
  3472. this.reportParseError("nested-comment");
  3473. }
  3474. return this.reconsumeAs("COMMENT_END");
  3475. }
  3476. COMMENT_END_DASH(cp) {
  3477. if (cp === HYPHEN_MINUS) {
  3478. return "COMMENT_END";
  3479. }
  3480. if (cp === EOF) {
  3481. this.reportParseError("eof-in-comment");
  3482. return "DATA";
  3483. }
  3484. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3485. return this.reconsumeAs("COMMENT");
  3486. }
  3487. COMMENT_END(cp) {
  3488. while (true) {
  3489. if (cp === GREATER_THAN_SIGN) {
  3490. return "DATA";
  3491. }
  3492. if (cp === EXCLAMATION_MARK) {
  3493. return "COMMENT_END_BANG";
  3494. }
  3495. if (cp === EOF) {
  3496. this.reportParseError("eof-in-comment");
  3497. return "DATA";
  3498. }
  3499. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3500. if (cp !== HYPHEN_MINUS) {
  3501. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3502. return this.reconsumeAs("COMMENT");
  3503. }
  3504. cp = this.consumeNextCodePoint();
  3505. }
  3506. }
  3507. COMMENT_END_BANG(cp) {
  3508. if (cp === HYPHEN_MINUS) {
  3509. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3510. this.appendTokenValue(EXCLAMATION_MARK, "HTMLComment");
  3511. return "COMMENT_END_DASH";
  3512. }
  3513. if (cp === GREATER_THAN_SIGN) {
  3514. this.reportParseError("incorrectly-closed-comment");
  3515. return "DATA";
  3516. }
  3517. if (cp === EOF) {
  3518. this.reportParseError("eof-in-comment");
  3519. return "DATA";
  3520. }
  3521. this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
  3522. this.appendTokenValue(EXCLAMATION_MARK, "HTMLComment");
  3523. return this.reconsumeAs("COMMENT");
  3524. }
  3525. CDATA_SECTION(cp) {
  3526. while (true) {
  3527. if (cp === RIGHT_SQUARE_BRACKET) {
  3528. return "CDATA_SECTION_BRACKET";
  3529. }
  3530. if (cp === EOF) {
  3531. this.reportParseError("eof-in-cdata");
  3532. return "DATA";
  3533. }
  3534. this.appendTokenValue(cp, "HTMLCDataText");
  3535. cp = this.consumeNextCodePoint();
  3536. }
  3537. }
  3538. CDATA_SECTION_BRACKET(cp) {
  3539. if (cp === RIGHT_SQUARE_BRACKET) {
  3540. return "CDATA_SECTION_END";
  3541. }
  3542. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3543. return this.reconsumeAs("CDATA_SECTION");
  3544. }
  3545. CDATA_SECTION_END(cp) {
  3546. while (true) {
  3547. if (cp === GREATER_THAN_SIGN) {
  3548. return "DATA";
  3549. }
  3550. if (cp !== RIGHT_SQUARE_BRACKET) {
  3551. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3552. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3553. return this.reconsumeAs("CDATA_SECTION");
  3554. }
  3555. this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
  3556. cp = this.consumeNextCodePoint();
  3557. }
  3558. }
  3559. CHARACTER_REFERENCE(cp) {
  3560. this.crStartOffset = this.offset - 1;
  3561. this.buffer = [AMPERSAND];
  3562. if (isDigit(cp) || isLetter(cp)) {
  3563. return this.reconsumeAs("NAMED_CHARACTER_REFERENCE");
  3564. }
  3565. if (cp === NUMBER_SIGN) {
  3566. this.buffer.push(cp);
  3567. return "NUMERIC_CHARACTER_REFERENCE";
  3568. }
  3569. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  3570. }
  3571. NAMED_CHARACTER_REFERENCE(cp) {
  3572. for (const entitySet of entitySets) {
  3573. const length = entitySet.length;
  3574. const entities = entitySet.entities;
  3575. const text = this.text.slice(this.offset, this.offset + length);
  3576. const codepoints = entities[text];
  3577. if (codepoints == null) {
  3578. continue;
  3579. }
  3580. const semi = text.endsWith(";");
  3581. const next = this.text.codePointAt(this.offset + 1);
  3582. this.offset += length - 1;
  3583. this.column += length - 1;
  3584. if (this.returnState.startsWith("ATTR") &&
  3585. !semi &&
  3586. next != null &&
  3587. (next === EQUALS_SIGN || isLetter(next) || isDigit(next))) {
  3588. for (const cp1 of text) {
  3589. this.buffer.push(cp1.codePointAt(0));
  3590. }
  3591. }
  3592. else {
  3593. if (!semi) {
  3594. this.reportParseError("missing-semicolon-after-character-reference");
  3595. }
  3596. this.buffer = codepoints;
  3597. }
  3598. return "CHARACTER_REFERENCE_END";
  3599. }
  3600. for (const cp0 of this.buffer) {
  3601. this.appendTokenValue(cp0, null);
  3602. }
  3603. this.appendTokenValue(cp, null);
  3604. return "AMBIGUOUS_AMPERSAND";
  3605. }
  3606. AMBIGUOUS_AMPERSAND(cp) {
  3607. while (isDigit(cp) || isLetter(cp)) {
  3608. this.appendTokenValue(cp, null);
  3609. cp = this.consumeNextCodePoint();
  3610. }
  3611. if (cp === SEMICOLON) {
  3612. this.reportParseError("unknown-named-character-reference");
  3613. }
  3614. return this.reconsumeAs(this.returnState);
  3615. }
  3616. NUMERIC_CHARACTER_REFERENCE(cp) {
  3617. this.crCode = 0;
  3618. if (cp === LATIN_SMALL_X || cp === LATIN_CAPITAL_X) {
  3619. this.buffer.push(cp);
  3620. return "HEXADEMICAL_CHARACTER_REFERENCE_START";
  3621. }
  3622. return this.reconsumeAs("DECIMAL_CHARACTER_REFERENCE_START");
  3623. }
  3624. HEXADEMICAL_CHARACTER_REFERENCE_START(cp) {
  3625. if (isHexDigit(cp)) {
  3626. return this.reconsumeAs("HEXADEMICAL_CHARACTER_REFERENCE");
  3627. }
  3628. this.reportParseError("absence-of-digits-in-numeric-character-reference");
  3629. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  3630. }
  3631. DECIMAL_CHARACTER_REFERENCE_START(cp) {
  3632. if (isDigit(cp)) {
  3633. return this.reconsumeAs("DECIMAL_CHARACTER_REFERENCE");
  3634. }
  3635. this.reportParseError("absence-of-digits-in-numeric-character-reference");
  3636. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  3637. }
  3638. HEXADEMICAL_CHARACTER_REFERENCE(cp) {
  3639. while (true) {
  3640. if (isDigit(cp)) {
  3641. this.crCode = 16 * this.crCode + (cp - 0x30);
  3642. }
  3643. else if (isUpperHexDigit(cp)) {
  3644. this.crCode = 16 * this.crCode + (cp - 0x37);
  3645. }
  3646. else if (isLowerHexDigit(cp)) {
  3647. this.crCode = 16 * this.crCode + (cp - 0x57);
  3648. }
  3649. else {
  3650. if (cp === SEMICOLON) {
  3651. return "NUMERIC_CHARACTER_REFERENCE_END";
  3652. }
  3653. this.reportParseError("missing-semicolon-after-character-reference");
  3654. return this.reconsumeAs("NUMERIC_CHARACTER_REFERENCE_END");
  3655. }
  3656. cp = this.consumeNextCodePoint();
  3657. }
  3658. }
  3659. DECIMAL_CHARACTER_REFERENCE(cp) {
  3660. while (true) {
  3661. if (isDigit(cp)) {
  3662. this.crCode = 10 * this.crCode + (cp - 0x30);
  3663. }
  3664. else {
  3665. if (cp === SEMICOLON) {
  3666. return "NUMERIC_CHARACTER_REFERENCE_END";
  3667. }
  3668. this.reportParseError("missing-semicolon-after-character-reference");
  3669. return this.reconsumeAs("NUMERIC_CHARACTER_REFERENCE_END");
  3670. }
  3671. cp = this.consumeNextCodePoint();
  3672. }
  3673. }
  3674. NUMERIC_CHARACTER_REFERENCE_END(_cp) {
  3675. let code = this.crCode;
  3676. if (code === 0) {
  3677. this.reportParseError("null-character-reference");
  3678. code = NULL_REPLACEMENT;
  3679. }
  3680. else if (code > 0x10ffff) {
  3681. this.reportParseError("character-reference-outside-unicode-range");
  3682. code = NULL_REPLACEMENT;
  3683. }
  3684. else if (isSurrogate(code)) {
  3685. this.reportParseError("surrogate-character-reference");
  3686. code = NULL_REPLACEMENT;
  3687. }
  3688. else if (isNonCharacter(code)) {
  3689. this.reportParseError("noncharacter-character-reference");
  3690. }
  3691. else if (code === 0x0d || (isControl(code) && !isWhitespace(code))) {
  3692. this.reportParseError("control-character-reference");
  3693. code = alternativeCR.get(code) || code;
  3694. }
  3695. this.buffer = [code];
  3696. return this.reconsumeAs("CHARACTER_REFERENCE_END");
  3697. }
  3698. CHARACTER_REFERENCE_END(_cp) {
  3699. assert__default["default"](this.currentToken != null);
  3700. const token = this.currentToken;
  3701. const len0 = token.value.length;
  3702. for (const cp1 of this.buffer) {
  3703. this.appendTokenValue(cp1, null);
  3704. }
  3705. const newLength = token.value.length - len0;
  3706. for (let i = this.crStartOffset + newLength; i < this.offset; ++i) {
  3707. this.gaps.push(i);
  3708. }
  3709. return this.reconsumeAs(this.returnState);
  3710. }
  3711. V_EXPRESSION_START(cp) {
  3712. var _a, _b;
  3713. if (cp === LEFT_CURLY_BRACKET) {
  3714. this.startToken("VExpressionStart");
  3715. this.appendTokenValue(LEFT_CURLY_BRACKET, null);
  3716. this.appendTokenValue(LEFT_CURLY_BRACKET, null);
  3717. if (!((_b = (_a = this.parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.interpolationAsNonHTML) !== null && _b !== void 0 ? _b : true)) {
  3718. return this.returnState;
  3719. }
  3720. const closeIndex = this.text.indexOf("}}", this.offset + 1);
  3721. if (closeIndex === -1) {
  3722. this.reportParseError("x-missing-interpolation-end");
  3723. return this.returnState;
  3724. }
  3725. this.vExpressionScriptState = {
  3726. state: this.returnState,
  3727. };
  3728. return "V_EXPRESSION_DATA";
  3729. }
  3730. this.appendTokenValue(LEFT_CURLY_BRACKET, null);
  3731. return this.reconsumeAs(this.returnState);
  3732. }
  3733. V_EXPRESSION_DATA(cp) {
  3734. this.clearStartTokenMark();
  3735. const state = this.vExpressionScriptState.state;
  3736. while (true) {
  3737. const type = isWhitespace(cp)
  3738. ? "HTMLWhitespace"
  3739. : state === "RCDATA"
  3740. ? "HTMLRawText"
  3741. : state === "RAWTEXT"
  3742. ? "HTMLRCDataText"
  3743. : "HTMLText";
  3744. if (this.currentToken != null && this.currentToken.type !== type) {
  3745. this.endToken();
  3746. return this.reconsumeAs(this.state);
  3747. }
  3748. if (this.currentToken == null) {
  3749. this.startToken(type);
  3750. }
  3751. if (cp === AMPERSAND && state !== "RAWTEXT") {
  3752. this.returnState = "V_EXPRESSION_DATA";
  3753. return "CHARACTER_REFERENCE";
  3754. }
  3755. if (cp === RIGHT_CURLY_BRACKET) {
  3756. this.setStartTokenMark();
  3757. this.returnState = "V_EXPRESSION_DATA";
  3758. return "V_EXPRESSION_END";
  3759. }
  3760. if (cp === EOF) {
  3761. this.reportParseError("x-missing-interpolation-end");
  3762. return "DATA";
  3763. }
  3764. if (cp === NULL) {
  3765. this.reportParseError("unexpected-null-character");
  3766. }
  3767. this.appendTokenValue(cp, type);
  3768. cp = this.consumeNextCodePoint();
  3769. }
  3770. }
  3771. V_EXPRESSION_END(cp) {
  3772. if (cp === RIGHT_CURLY_BRACKET) {
  3773. this.startToken("VExpressionEnd");
  3774. this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
  3775. this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
  3776. return this.vExpressionScriptState
  3777. ? this.vExpressionScriptState.state
  3778. : this.returnState;
  3779. }
  3780. this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
  3781. return this.reconsumeAs(this.returnState);
  3782. }
  3783. }
  3784. function getPossibleTypes(parsedSelector) {
  3785. switch (parsedSelector.type) {
  3786. case "identifier":
  3787. return [parsedSelector.value];
  3788. case "matches": {
  3789. const typesForComponents = parsedSelector.selectors.map(getPossibleTypes);
  3790. if (typesForComponents.every(Boolean)) {
  3791. return union__default["default"](...typesForComponents);
  3792. }
  3793. return null;
  3794. }
  3795. case "compound": {
  3796. const typesForComponents = parsedSelector.selectors.map(getPossibleTypes).filter(Boolean);
  3797. if (!typesForComponents.length) {
  3798. return null;
  3799. }
  3800. return intersection__default["default"](...typesForComponents);
  3801. }
  3802. case "child":
  3803. case "descendant":
  3804. case "sibling":
  3805. case "adjacent":
  3806. return getPossibleTypes(parsedSelector.right);
  3807. default:
  3808. return null;
  3809. }
  3810. }
  3811. function countClassAttributes(parsedSelector) {
  3812. switch (parsedSelector.type) {
  3813. case "child":
  3814. case "descendant":
  3815. case "sibling":
  3816. case "adjacent":
  3817. return countClassAttributes(parsedSelector.left) + countClassAttributes(parsedSelector.right);
  3818. case "compound":
  3819. case "not":
  3820. case "matches":
  3821. return parsedSelector.selectors.reduce((sum, childSelector) => sum + countClassAttributes(childSelector), 0);
  3822. case "attribute":
  3823. case "field":
  3824. case "nth-child":
  3825. case "nth-last-child":
  3826. return 1;
  3827. default:
  3828. return 0;
  3829. }
  3830. }
  3831. function countIdentifiers(parsedSelector) {
  3832. switch (parsedSelector.type) {
  3833. case "child":
  3834. case "descendant":
  3835. case "sibling":
  3836. case "adjacent":
  3837. return countIdentifiers(parsedSelector.left) + countIdentifiers(parsedSelector.right);
  3838. case "compound":
  3839. case "not":
  3840. case "matches":
  3841. return parsedSelector.selectors.reduce((sum, childSelector) => sum + countIdentifiers(childSelector), 0);
  3842. case "identifier":
  3843. return 1;
  3844. default:
  3845. return 0;
  3846. }
  3847. }
  3848. function compareSpecificity(selectorA, selectorB) {
  3849. return selectorA.attributeCount - selectorB.attributeCount ||
  3850. selectorA.identifierCount - selectorB.identifierCount ||
  3851. (selectorA.rawSelector <= selectorB.rawSelector ? -1 : 1);
  3852. }
  3853. function tryParseSelector(rawSelector) {
  3854. try {
  3855. return esquery__default["default"].parse(rawSelector.replace(/:exit$/, ""));
  3856. }
  3857. catch (err) {
  3858. if (typeof err.offset === "number") {
  3859. throw new Error(`Syntax error in selector "${rawSelector}" at position ${err.offset}: ${err.message}`);
  3860. }
  3861. throw err;
  3862. }
  3863. }
  3864. const parseSelector = memoize__default["default"](rawSelector => {
  3865. const parsedSelector = tryParseSelector(rawSelector);
  3866. return {
  3867. rawSelector,
  3868. isExit: rawSelector.endsWith(":exit"),
  3869. parsedSelector,
  3870. listenerTypes: getPossibleTypes(parsedSelector),
  3871. attributeCount: countClassAttributes(parsedSelector),
  3872. identifierCount: countIdentifiers(parsedSelector),
  3873. };
  3874. });
  3875. class NodeEventGenerator {
  3876. constructor(emitter, esqueryOptions) {
  3877. this.emitter = emitter;
  3878. this.esqueryOptions = esqueryOptions;
  3879. this.currentAncestry = [];
  3880. this.enterSelectorsByNodeType = new Map();
  3881. this.exitSelectorsByNodeType = new Map();
  3882. this.anyTypeEnterSelectors = [];
  3883. this.anyTypeExitSelectors = [];
  3884. const eventNames = typeof emitter.eventNames === "function"
  3885. ? emitter.eventNames()
  3886. : Object.keys(emitter._events);
  3887. for (const rawSelector of eventNames) {
  3888. if (typeof rawSelector === "symbol") {
  3889. continue;
  3890. }
  3891. const selector = parseSelector(rawSelector);
  3892. if (selector.listenerTypes) {
  3893. for (const nodeType of selector.listenerTypes) {
  3894. const typeMap = selector.isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType;
  3895. let selectors = typeMap.get(nodeType);
  3896. if (selectors == null) {
  3897. typeMap.set(nodeType, (selectors = []));
  3898. }
  3899. selectors.push(selector);
  3900. }
  3901. }
  3902. else {
  3903. (selector.isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors).push(selector);
  3904. }
  3905. }
  3906. this.anyTypeEnterSelectors.sort(compareSpecificity);
  3907. this.anyTypeExitSelectors.sort(compareSpecificity);
  3908. for (const selectorList of this.enterSelectorsByNodeType.values()) {
  3909. selectorList.sort(compareSpecificity);
  3910. }
  3911. for (const selectorList of this.exitSelectorsByNodeType.values()) {
  3912. selectorList.sort(compareSpecificity);
  3913. }
  3914. }
  3915. applySelector(node, selector) {
  3916. if (esquery__default["default"].matches(node, selector.parsedSelector, this.currentAncestry, this.esqueryOptions)) {
  3917. this.emitter.emit(selector.rawSelector, node);
  3918. }
  3919. }
  3920. applySelectors(node, isExit) {
  3921. const selectorsByNodeType = (isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType).get(node.type) || [];
  3922. const anyTypeSelectors = isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors;
  3923. let selectorsByTypeIndex = 0;
  3924. let anyTypeSelectorsIndex = 0;
  3925. while (selectorsByTypeIndex < selectorsByNodeType.length || anyTypeSelectorsIndex < anyTypeSelectors.length) {
  3926. if (selectorsByTypeIndex >= selectorsByNodeType.length ||
  3927. (anyTypeSelectorsIndex < anyTypeSelectors.length && compareSpecificity(anyTypeSelectors[anyTypeSelectorsIndex], selectorsByNodeType[selectorsByTypeIndex]) < 0)) {
  3928. this.applySelector(node, anyTypeSelectors[anyTypeSelectorsIndex++]);
  3929. }
  3930. else {
  3931. this.applySelector(node, selectorsByNodeType[selectorsByTypeIndex++]);
  3932. }
  3933. }
  3934. }
  3935. enterNode(node) {
  3936. if (node.parent) {
  3937. this.currentAncestry.unshift(node.parent);
  3938. }
  3939. this.applySelectors(node, false);
  3940. }
  3941. leaveNode(node) {
  3942. this.applySelectors(node, true);
  3943. this.currentAncestry.shift();
  3944. }
  3945. }
  3946. function getStartLocation(token) {
  3947. return token.range[0];
  3948. }
  3949. function search(tokens, location) {
  3950. return sortedIndexBy__default["default"](tokens, { range: [location] }, getStartLocation);
  3951. }
  3952. function getFirstIndex(tokens, indexMap, startLoc) {
  3953. if (startLoc in indexMap) {
  3954. return indexMap[startLoc];
  3955. }
  3956. if ((startLoc - 1) in indexMap) {
  3957. const index = indexMap[startLoc - 1];
  3958. const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
  3959. if (token && token.range[0] >= startLoc) {
  3960. return index;
  3961. }
  3962. return index + 1;
  3963. }
  3964. return 0;
  3965. }
  3966. function getLastIndex(tokens, indexMap, endLoc) {
  3967. if (endLoc in indexMap) {
  3968. return indexMap[endLoc] - 1;
  3969. }
  3970. if ((endLoc - 1) in indexMap) {
  3971. const index = indexMap[endLoc - 1];
  3972. const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
  3973. if (token && token.range[1] > endLoc) {
  3974. return index - 1;
  3975. }
  3976. return index;
  3977. }
  3978. return tokens.length - 1;
  3979. }
  3980. class Cursor {
  3981. constructor() {
  3982. this.current = null;
  3983. }
  3984. getOneToken() {
  3985. return this.moveNext() ? this.current : null;
  3986. }
  3987. getAllTokens() {
  3988. const tokens = [];
  3989. while (this.moveNext()) {
  3990. tokens.push(this.current);
  3991. }
  3992. return tokens;
  3993. }
  3994. }
  3995. class BackwardTokenCommentCursor extends Cursor {
  3996. constructor(tokens, comments, indexMap, startLoc, endLoc) {
  3997. super();
  3998. this.tokens = tokens;
  3999. this.comments = comments;
  4000. this.tokenIndex = getLastIndex(tokens, indexMap, endLoc);
  4001. this.commentIndex = search(comments, endLoc) - 1;
  4002. this.border = startLoc;
  4003. }
  4004. moveNext() {
  4005. const token = (this.tokenIndex >= 0) ? this.tokens[this.tokenIndex] : null;
  4006. const comment = (this.commentIndex >= 0) ? this.comments[this.commentIndex] : null;
  4007. if (token && (!comment || token.range[1] > comment.range[1])) {
  4008. this.current = token;
  4009. this.tokenIndex -= 1;
  4010. }
  4011. else if (comment) {
  4012. this.current = comment;
  4013. this.commentIndex -= 1;
  4014. }
  4015. else {
  4016. this.current = null;
  4017. }
  4018. return this.current != null && (this.border === -1 || this.current.range[0] >= this.border);
  4019. }
  4020. }
  4021. class BackwardTokenCursor extends Cursor {
  4022. constructor(tokens, _comments, indexMap, startLoc, endLoc) {
  4023. super();
  4024. this.tokens = tokens;
  4025. this.index = getLastIndex(tokens, indexMap, endLoc);
  4026. this.indexEnd = getFirstIndex(tokens, indexMap, startLoc);
  4027. }
  4028. moveNext() {
  4029. if (this.index >= this.indexEnd) {
  4030. this.current = this.tokens[this.index];
  4031. this.index -= 1;
  4032. return true;
  4033. }
  4034. return false;
  4035. }
  4036. getOneToken() {
  4037. return (this.index >= this.indexEnd) ? this.tokens[this.index] : null;
  4038. }
  4039. }
  4040. class DecorativeCursor extends Cursor {
  4041. constructor(cursor) {
  4042. super();
  4043. this.cursor = cursor;
  4044. }
  4045. moveNext() {
  4046. const retv = this.cursor.moveNext();
  4047. this.current = this.cursor.current;
  4048. return retv;
  4049. }
  4050. }
  4051. class FilterCursor extends DecorativeCursor {
  4052. constructor(cursor, predicate) {
  4053. super(cursor);
  4054. this.predicate = predicate;
  4055. }
  4056. moveNext() {
  4057. const predicate = this.predicate;
  4058. while (super.moveNext()) {
  4059. if (predicate(this.current)) {
  4060. return true;
  4061. }
  4062. }
  4063. return false;
  4064. }
  4065. }
  4066. class ForwardTokenCommentCursor extends Cursor {
  4067. constructor(tokens, comments, indexMap, startLoc, endLoc) {
  4068. super();
  4069. this.tokens = tokens;
  4070. this.comments = comments;
  4071. this.tokenIndex = getFirstIndex(tokens, indexMap, startLoc);
  4072. this.commentIndex = search(comments, startLoc);
  4073. this.border = endLoc;
  4074. }
  4075. moveNext() {
  4076. const token = (this.tokenIndex < this.tokens.length) ? this.tokens[this.tokenIndex] : null;
  4077. const comment = (this.commentIndex < this.comments.length) ? this.comments[this.commentIndex] : null;
  4078. if (token && (!comment || token.range[0] < comment.range[0])) {
  4079. this.current = token;
  4080. this.tokenIndex += 1;
  4081. }
  4082. else if (comment) {
  4083. this.current = comment;
  4084. this.commentIndex += 1;
  4085. }
  4086. else {
  4087. this.current = null;
  4088. }
  4089. return this.current != null && (this.border === -1 || this.current.range[1] <= this.border);
  4090. }
  4091. }
  4092. class ForwardTokenCursor extends Cursor {
  4093. constructor(tokens, _comments, indexMap, startLoc, endLoc) {
  4094. super();
  4095. this.tokens = tokens;
  4096. this.index = getFirstIndex(tokens, indexMap, startLoc);
  4097. this.indexEnd = getLastIndex(tokens, indexMap, endLoc);
  4098. }
  4099. moveNext() {
  4100. if (this.index <= this.indexEnd) {
  4101. this.current = this.tokens[this.index];
  4102. this.index += 1;
  4103. return true;
  4104. }
  4105. return false;
  4106. }
  4107. getOneToken() {
  4108. return (this.index <= this.indexEnd) ? this.tokens[this.index] : null;
  4109. }
  4110. getAllTokens() {
  4111. return this.tokens.slice(this.index, this.indexEnd + 1);
  4112. }
  4113. }
  4114. class LimitCursor extends DecorativeCursor {
  4115. constructor(cursor, count) {
  4116. super(cursor);
  4117. this.count = count;
  4118. }
  4119. moveNext() {
  4120. if (this.count > 0) {
  4121. this.count -= 1;
  4122. return super.moveNext();
  4123. }
  4124. return false;
  4125. }
  4126. }
  4127. class SkipCursor extends DecorativeCursor {
  4128. constructor(cursor, count) {
  4129. super(cursor);
  4130. this.count = count;
  4131. }
  4132. moveNext() {
  4133. while (this.count > 0) {
  4134. this.count -= 1;
  4135. if (!super.moveNext()) {
  4136. return false;
  4137. }
  4138. }
  4139. return super.moveNext();
  4140. }
  4141. }
  4142. class CursorFactory {
  4143. constructor(TokenCursor, TokenCommentCursor) {
  4144. this.TokenCursor = TokenCursor;
  4145. this.TokenCommentCursor = TokenCommentCursor;
  4146. }
  4147. createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments) {
  4148. const TokenCursor = includeComments ? this.TokenCommentCursor : this.TokenCursor;
  4149. return new TokenCursor(tokens, comments, indexMap, startLoc, endLoc);
  4150. }
  4151. createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, count) {
  4152. let cursor = this.createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments);
  4153. if (filter) {
  4154. cursor = new FilterCursor(cursor, filter);
  4155. }
  4156. if (skip >= 1) {
  4157. cursor = new SkipCursor(cursor, skip);
  4158. }
  4159. if (count >= 0) {
  4160. cursor = new LimitCursor(cursor, count);
  4161. }
  4162. return cursor;
  4163. }
  4164. }
  4165. const forward = new CursorFactory(ForwardTokenCursor, ForwardTokenCommentCursor);
  4166. const backward = new CursorFactory(BackwardTokenCursor, BackwardTokenCommentCursor);
  4167. class PaddedTokenCursor extends ForwardTokenCursor {
  4168. constructor(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
  4169. super(tokens, comments, indexMap, startLoc, endLoc);
  4170. this.index = Math.max(0, this.index - beforeCount);
  4171. this.indexEnd = Math.min(tokens.length - 1, this.indexEnd + afterCount);
  4172. }
  4173. }
  4174. function isCommentToken(token) {
  4175. return token.type === "Line" || token.type === "Block" || token.type === "Shebang";
  4176. }
  4177. function createIndexMap(tokens, comments) {
  4178. const map = Object.create(null);
  4179. let tokenIndex = 0;
  4180. let commentIndex = 0;
  4181. let nextStart = 0;
  4182. let range = null;
  4183. while (tokenIndex < tokens.length || commentIndex < comments.length) {
  4184. nextStart = (commentIndex < comments.length) ? comments[commentIndex].range[0] : Number.MAX_SAFE_INTEGER;
  4185. while (tokenIndex < tokens.length && (range = tokens[tokenIndex].range)[0] < nextStart) {
  4186. map[range[0]] = tokenIndex;
  4187. map[range[1] - 1] = tokenIndex;
  4188. tokenIndex += 1;
  4189. }
  4190. nextStart = (tokenIndex < tokens.length) ? tokens[tokenIndex].range[0] : Number.MAX_SAFE_INTEGER;
  4191. while (commentIndex < comments.length && (range = comments[commentIndex].range)[0] < nextStart) {
  4192. map[range[0]] = tokenIndex;
  4193. map[range[1] - 1] = tokenIndex;
  4194. commentIndex += 1;
  4195. }
  4196. }
  4197. return map;
  4198. }
  4199. function createCursorWithSkip(factory, tokens, comments, indexMap, startLoc, endLoc, opts) {
  4200. let includeComments = false;
  4201. let skip = 0;
  4202. let filter = null;
  4203. if (typeof opts === "number") {
  4204. skip = opts | 0;
  4205. }
  4206. else if (typeof opts === "function") {
  4207. filter = opts;
  4208. }
  4209. else if (opts) {
  4210. includeComments = Boolean(opts.includeComments);
  4211. skip = opts.skip || 0;
  4212. filter = opts.filter || null;
  4213. }
  4214. assert__default["default"](skip >= 0, "options.skip should be zero or a positive integer.");
  4215. assert__default["default"](!filter || typeof filter === "function", "options.filter should be a function.");
  4216. return factory.createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, -1);
  4217. }
  4218. function createCursorWithCount(factory, tokens, comments, indexMap, startLoc, endLoc, opts) {
  4219. let includeComments = false;
  4220. let count = 0;
  4221. let countExists = false;
  4222. let filter = null;
  4223. if (typeof opts === "number") {
  4224. count = opts | 0;
  4225. countExists = true;
  4226. }
  4227. else if (typeof opts === "function") {
  4228. filter = opts;
  4229. }
  4230. else if (opts) {
  4231. includeComments = Boolean(opts.includeComments);
  4232. count = opts.count || 0;
  4233. countExists = typeof opts.count === "number";
  4234. filter = opts.filter || null;
  4235. }
  4236. assert__default["default"](count >= 0, "options.count should be zero or a positive integer.");
  4237. assert__default["default"](!filter || typeof filter === "function", "options.filter should be a function.");
  4238. return factory.createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, 0, countExists ? count : -1);
  4239. }
  4240. function createCursorWithPadding(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
  4241. if (typeof beforeCount === "undefined" && typeof afterCount === "undefined") {
  4242. return new ForwardTokenCursor(tokens, comments, indexMap, startLoc, endLoc);
  4243. }
  4244. if (typeof beforeCount === "number" || typeof beforeCount === "undefined") {
  4245. return new PaddedTokenCursor(tokens, comments, indexMap, startLoc, endLoc, beforeCount || 0, afterCount || 0);
  4246. }
  4247. return createCursorWithCount(forward, tokens, comments, indexMap, startLoc, endLoc, beforeCount);
  4248. }
  4249. function getAdjacentCommentTokensFromCursor(cursor) {
  4250. const tokens = [];
  4251. let currentToken = cursor.getOneToken();
  4252. while (currentToken && isCommentToken(currentToken)) {
  4253. tokens.push(currentToken);
  4254. currentToken = cursor.getOneToken();
  4255. }
  4256. return tokens;
  4257. }
  4258. class TokenStore {
  4259. constructor(tokens, comments) {
  4260. this._tokens = tokens;
  4261. this._comments = comments;
  4262. this._indexMap = createIndexMap(tokens, comments);
  4263. }
  4264. getTokenByRangeStart(offset, options) {
  4265. const includeComments = Boolean(options && options.includeComments);
  4266. const token = forward.createBaseCursor(this._tokens, this._comments, this._indexMap, offset, -1, includeComments).getOneToken();
  4267. if (token && token.range[0] === offset) {
  4268. return token;
  4269. }
  4270. return null;
  4271. }
  4272. getFirstToken(node, options) {
  4273. return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getOneToken();
  4274. }
  4275. getLastToken(node, options) {
  4276. return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getOneToken();
  4277. }
  4278. getTokenBefore(node, options) {
  4279. return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, -1, node.range[0], options).getOneToken();
  4280. }
  4281. getTokenAfter(node, options) {
  4282. return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, node.range[1], -1, options).getOneToken();
  4283. }
  4284. getFirstTokenBetween(left, right, options) {
  4285. return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getOneToken();
  4286. }
  4287. getLastTokenBetween(left, right, options) {
  4288. return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getOneToken();
  4289. }
  4290. getTokenOrCommentBefore(node, skip) {
  4291. return this.getTokenBefore(node, { includeComments: true, skip });
  4292. }
  4293. getTokenOrCommentAfter(node, skip) {
  4294. return this.getTokenAfter(node, { includeComments: true, skip });
  4295. }
  4296. getFirstTokens(node, options) {
  4297. return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getAllTokens();
  4298. }
  4299. getLastTokens(node, options) {
  4300. return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getAllTokens().reverse();
  4301. }
  4302. getTokensBefore(node, options) {
  4303. return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, -1, node.range[0], options).getAllTokens().reverse();
  4304. }
  4305. getTokensAfter(node, options) {
  4306. return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, node.range[1], -1, options).getAllTokens();
  4307. }
  4308. getFirstTokensBetween(left, right, options) {
  4309. return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getAllTokens();
  4310. }
  4311. getLastTokensBetween(left, right, options) {
  4312. return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getAllTokens().reverse();
  4313. }
  4314. getTokens(node, beforeCount, afterCount) {
  4315. return createCursorWithPadding(this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], beforeCount, afterCount).getAllTokens();
  4316. }
  4317. getTokensBetween(left, right, padding) {
  4318. return createCursorWithPadding(this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], padding, typeof padding === "number" ? padding : undefined).getAllTokens();
  4319. }
  4320. commentsExistBetween(left, right) {
  4321. const index = search(this._comments, left.range[1]);
  4322. return (index < this._comments.length &&
  4323. this._comments[index].range[1] <= right.range[0]);
  4324. }
  4325. getCommentsBefore(nodeOrToken) {
  4326. const cursor = createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, -1, nodeOrToken.range[0], { includeComments: true });
  4327. return getAdjacentCommentTokensFromCursor(cursor).reverse();
  4328. }
  4329. getCommentsAfter(nodeOrToken) {
  4330. const cursor = createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, nodeOrToken.range[1], -1, { includeComments: true });
  4331. return getAdjacentCommentTokensFromCursor(cursor);
  4332. }
  4333. getCommentsInside(node) {
  4334. return this.getTokens(node, {
  4335. includeComments: true,
  4336. filter: isCommentToken,
  4337. });
  4338. }
  4339. }
  4340. function isVElement(node) {
  4341. return node.type === "VElement";
  4342. }
  4343. function getCustomBlocks(document) {
  4344. return document
  4345. ? document.children
  4346. .filter(isVElement)
  4347. .filter((block) => block.name !== "script" &&
  4348. block.name !== "template" &&
  4349. block.name !== "style")
  4350. : [];
  4351. }
  4352. function parseCustomBlockElement(node, parser, globalLocationCalculator, parserOptions) {
  4353. const text = node.children[0];
  4354. const { code, range, loc } = text != null && text.type === "VText"
  4355. ? {
  4356. code: text.value,
  4357. range: text.range,
  4358. loc: text.loc,
  4359. }
  4360. : {
  4361. code: "",
  4362. range: [
  4363. node.startTag.range[1],
  4364. node.endTag.range[0],
  4365. ],
  4366. loc: {
  4367. start: node.startTag.loc.end,
  4368. end: node.endTag.loc.start,
  4369. },
  4370. };
  4371. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(range[0]);
  4372. try {
  4373. return parseCustomBlockFragment(code, parser, locationCalculator, parserOptions);
  4374. }
  4375. catch (e) {
  4376. if (!(e instanceof Error)) {
  4377. throw e;
  4378. }
  4379. return {
  4380. error: e,
  4381. ast: {
  4382. type: "Program",
  4383. sourceType: "module",
  4384. loc: {
  4385. start: Object.assign({}, loc.start),
  4386. end: Object.assign({}, loc.end),
  4387. },
  4388. range: [...range],
  4389. body: [],
  4390. tokens: [],
  4391. comments: [],
  4392. },
  4393. };
  4394. }
  4395. }
  4396. function parseCustomBlockFragment(code, parser, locationCalculator, parserOptions) {
  4397. try {
  4398. 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));
  4399. fixLocations(result, locationCalculator);
  4400. return result;
  4401. }
  4402. catch (err) {
  4403. const perr = ParseError.normalize(err);
  4404. if (perr) {
  4405. fixErrorLocation(perr, locationCalculator);
  4406. throw perr;
  4407. }
  4408. throw err;
  4409. }
  4410. }
  4411. function parseBlock(code, parser, parserOptions) {
  4412. const result = isEnhancedParserObject(parser)
  4413. ? parser.parseForESLint(code, parserOptions)
  4414. : parser.parse(code, parserOptions);
  4415. if (result.ast != null) {
  4416. return result;
  4417. }
  4418. return { ast: result };
  4419. }
  4420. function createCustomBlockSharedContext({ text, customBlock, parsedResult, globalLocationCalculator, parserOptions, }) {
  4421. let sourceCode;
  4422. let scopeManager;
  4423. let currentNode;
  4424. return {
  4425. serCurrentNode(node) {
  4426. currentNode = node;
  4427. },
  4428. context: {
  4429. getAncestors: () => getAncestors(currentNode),
  4430. getDeclaredVariables: (...args) => getScopeManager().getDeclaredVariables(...args),
  4431. getScope: () => getScope(getScopeManager(), currentNode),
  4432. markVariableAsUsed: (name) => markVariableAsUsed(getScopeManager(), currentNode, parserOptions, name),
  4433. parserServices: Object.assign(Object.assign({ customBlock,
  4434. parseCustomBlockElement(parser, options) {
  4435. return parseCustomBlockElement(customBlock, parser, globalLocationCalculator, Object.assign(Object.assign({}, parserOptions), options));
  4436. } }, (parsedResult.services || {})), (parsedResult.error
  4437. ? { parseError: parsedResult.error }
  4438. : {})),
  4439. getSourceCode,
  4440. },
  4441. };
  4442. function getSourceCode() {
  4443. return (sourceCode ||
  4444. (sourceCode = new (require("eslint").SourceCode)({
  4445. text,
  4446. ast: parsedResult.ast,
  4447. parserServices: parsedResult.services,
  4448. scopeManager: getScopeManager(),
  4449. visitorKeys: parsedResult.visitorKeys,
  4450. })));
  4451. }
  4452. function getScopeManager() {
  4453. if (parsedResult.scopeManager || scopeManager) {
  4454. return parsedResult.scopeManager || scopeManager;
  4455. }
  4456. const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022;
  4457. const ecmaFeatures = parserOptions.ecmaFeatures || {};
  4458. const sourceType = parserOptions.sourceType || "script";
  4459. scopeManager = getEslintScope().analyze(parsedResult.ast, {
  4460. ignoreEval: true,
  4461. nodejsScope: false,
  4462. impliedStrict: ecmaFeatures.impliedStrict,
  4463. ecmaVersion,
  4464. sourceType,
  4465. fallback: getFallbackKeys,
  4466. });
  4467. return scopeManager;
  4468. }
  4469. }
  4470. function getAncestors(node) {
  4471. const ancestorsStartingAtParent = [];
  4472. for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
  4473. ancestorsStartingAtParent.push(ancestor);
  4474. }
  4475. return ancestorsStartingAtParent.reverse();
  4476. }
  4477. function getScope(scopeManager, currentNode) {
  4478. const inner = currentNode.type !== "Program";
  4479. for (let node = currentNode; node; node = node.parent || null) {
  4480. const scope = scopeManager.acquire(node, inner);
  4481. if (scope) {
  4482. if (scope.type === "function-expression-name") {
  4483. return scope.childScopes[0];
  4484. }
  4485. return scope;
  4486. }
  4487. }
  4488. return scopeManager.scopes[0];
  4489. }
  4490. function markVariableAsUsed(scopeManager, currentNode, parserOptions, name) {
  4491. const hasGlobalReturn = parserOptions.ecmaFeatures && parserOptions.ecmaFeatures.globalReturn;
  4492. const specialScope = hasGlobalReturn || parserOptions.sourceType === "module";
  4493. const currentScope = getScope(scopeManager, currentNode);
  4494. const initialScope = currentScope.type === "global" && specialScope
  4495. ? currentScope.childScopes[0]
  4496. : currentScope;
  4497. for (let scope = initialScope; scope; scope = scope.upper) {
  4498. const variable = scope.variables.find((scopeVar) => scopeVar.name === name);
  4499. if (variable) {
  4500. variable.eslintUsed = true;
  4501. return true;
  4502. }
  4503. }
  4504. return false;
  4505. }
  4506. function define(sourceText, rootAST, document, globalLocationCalculator, { parserOptions }) {
  4507. const templateBodyEmitters = new Map();
  4508. const stores = new WeakMap();
  4509. const documentEmitters = new Map();
  4510. const customBlocksEmitters = new Map();
  4511. const isSFC = isSFCFile(parserOptions);
  4512. return {
  4513. defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor, options) {
  4514. var _a;
  4515. if (scriptVisitor == null) {
  4516. scriptVisitor = {};
  4517. }
  4518. if (rootAST.templateBody == null) {
  4519. return scriptVisitor;
  4520. }
  4521. const templateBodyTriggerSelector = (_a = options === null || options === void 0 ? void 0 : options.templateBodyTriggerSelector) !== null && _a !== void 0 ? _a : "Program:exit";
  4522. let emitter = templateBodyEmitters.get(templateBodyTriggerSelector);
  4523. if (emitter == null) {
  4524. emitter = new EventEmitter__default["default"]();
  4525. emitter.setMaxListeners(0);
  4526. templateBodyEmitters.set(templateBodyTriggerSelector, emitter);
  4527. const programExitHandler = scriptVisitor[templateBodyTriggerSelector];
  4528. scriptVisitor[templateBodyTriggerSelector] = (node) => {
  4529. try {
  4530. if (typeof programExitHandler === "function") {
  4531. programExitHandler(node);
  4532. }
  4533. const generator = new NodeEventGenerator(emitter, {
  4534. visitorKeys: KEYS,
  4535. fallback: getFallbackKeys,
  4536. });
  4537. traverseNodes(rootAST.templateBody, generator);
  4538. }
  4539. finally {
  4540. scriptVisitor[templateBodyTriggerSelector] =
  4541. programExitHandler;
  4542. templateBodyEmitters.delete(templateBodyTriggerSelector);
  4543. }
  4544. };
  4545. }
  4546. for (const selector of Object.keys(templateBodyVisitor)) {
  4547. emitter.on(selector, templateBodyVisitor[selector]);
  4548. }
  4549. return scriptVisitor;
  4550. },
  4551. defineDocumentVisitor(documentVisitor, options) {
  4552. var _a;
  4553. const scriptVisitor = {};
  4554. if (!document) {
  4555. return scriptVisitor;
  4556. }
  4557. const documentTriggerSelector = (_a = options === null || options === void 0 ? void 0 : options.triggerSelector) !== null && _a !== void 0 ? _a : "Program:exit";
  4558. let emitter = documentEmitters.get(documentTriggerSelector);
  4559. if (emitter == null) {
  4560. emitter = new EventEmitter__default["default"]();
  4561. emitter.setMaxListeners(0);
  4562. documentEmitters.set(documentTriggerSelector, emitter);
  4563. const programExitHandler = scriptVisitor[documentTriggerSelector];
  4564. scriptVisitor[documentTriggerSelector] = (node) => {
  4565. try {
  4566. if (typeof programExitHandler === "function") {
  4567. programExitHandler(node);
  4568. }
  4569. const generator = new NodeEventGenerator(emitter, {
  4570. visitorKeys: KEYS,
  4571. fallback: getFallbackKeys,
  4572. });
  4573. traverseNodes(document, generator);
  4574. }
  4575. finally {
  4576. scriptVisitor[documentTriggerSelector] =
  4577. programExitHandler;
  4578. documentEmitters.delete(documentTriggerSelector);
  4579. }
  4580. };
  4581. }
  4582. for (const selector of Object.keys(documentVisitor)) {
  4583. emitter.on(selector, documentVisitor[selector]);
  4584. }
  4585. return scriptVisitor;
  4586. },
  4587. defineCustomBlocksVisitor(context, parser, rule, scriptVisitor) {
  4588. var _a;
  4589. if (scriptVisitor == null) {
  4590. scriptVisitor = {};
  4591. }
  4592. if (!isSFC) {
  4593. return scriptVisitor;
  4594. }
  4595. parserOptions = Object.assign({}, parserOptions);
  4596. const customBlocks = getCustomBlocks(document).filter((block) => block.endTag &&
  4597. !block.startTag.attributes.some((attr) => !attr.directive && attr.key.name === "src"));
  4598. if (!customBlocks.length || globalLocationCalculator == null) {
  4599. return {};
  4600. }
  4601. const key = (_a = parser.parseForESLint) !== null && _a !== void 0 ? _a : parser.parse;
  4602. let factories = customBlocksEmitters.get(key);
  4603. if (factories == null) {
  4604. factories = [];
  4605. customBlocksEmitters.set(key, factories);
  4606. const visitorFactories = factories;
  4607. const programExitHandler = scriptVisitor["Program:exit"];
  4608. scriptVisitor["Program:exit"] = (node) => {
  4609. try {
  4610. if (typeof programExitHandler === "function") {
  4611. programExitHandler(node);
  4612. }
  4613. for (const customBlock of customBlocks) {
  4614. const lang = getLang(customBlock);
  4615. const activeVisitorFactories = visitorFactories.filter((f) => f.test(lang, customBlock));
  4616. if (!activeVisitorFactories.length) {
  4617. continue;
  4618. }
  4619. const parsedResult = parseCustomBlockElement(customBlock, parser, globalLocationCalculator, parserOptions);
  4620. const { serCurrentNode, context: customBlockContext, } = createCustomBlockSharedContext({
  4621. text: sourceText,
  4622. customBlock,
  4623. parsedResult,
  4624. globalLocationCalculator,
  4625. parserOptions,
  4626. });
  4627. const emitter = new EventEmitter__default["default"]();
  4628. emitter.setMaxListeners(0);
  4629. for (const factory of activeVisitorFactories) {
  4630. const ctx = Object.assign({}, customBlockContext);
  4631. ctx.__proto__ = factory.context;
  4632. const visitor = factory.create(ctx);
  4633. for (const selector of Object.keys(visitor || {})) {
  4634. emitter.on(selector, visitor[selector]);
  4635. }
  4636. }
  4637. const generator = new NodeEventGenerator(emitter, {
  4638. visitorKeys: parsedResult.visitorKeys,
  4639. fallback: getFallbackKeys,
  4640. });
  4641. traverseNodes(parsedResult.ast, {
  4642. visitorKeys: parsedResult.visitorKeys,
  4643. enterNode(n) {
  4644. serCurrentNode(n);
  4645. generator.enterNode(n);
  4646. },
  4647. leaveNode(n) {
  4648. serCurrentNode(n);
  4649. generator.leaveNode(n);
  4650. },
  4651. });
  4652. }
  4653. }
  4654. finally {
  4655. scriptVisitor["Program:exit"] = programExitHandler;
  4656. customBlocksEmitters.delete(key);
  4657. }
  4658. };
  4659. }
  4660. const target = rule.target;
  4661. const test = typeof target === "function"
  4662. ? target
  4663. : Array.isArray(target)
  4664. ? (lang) => Boolean(lang && target.includes(lang))
  4665. : (lang) => target === lang;
  4666. factories.push({
  4667. context,
  4668. test,
  4669. create: rule.create,
  4670. });
  4671. return scriptVisitor;
  4672. },
  4673. getTemplateBodyTokenStore() {
  4674. const key = document || stores;
  4675. let store = stores.get(key);
  4676. if (!store) {
  4677. store =
  4678. document != null
  4679. ? new TokenStore(document.tokens, document.comments)
  4680. : new TokenStore([], []);
  4681. stores.set(key, store);
  4682. }
  4683. return store;
  4684. },
  4685. getDocumentFragment() {
  4686. return document;
  4687. },
  4688. };
  4689. }
  4690. class CodeBlocks {
  4691. constructor() {
  4692. this.remapBlocks = [];
  4693. this.splitPunctuators = [];
  4694. this.code = "";
  4695. }
  4696. get length() {
  4697. return this.code.length;
  4698. }
  4699. append(codeLet, originalOffset) {
  4700. const rangeStart = this.code.length;
  4701. this.code += codeLet.trimRight();
  4702. this.remapBlocks.push({
  4703. range: [rangeStart, this.code.length],
  4704. offset: originalOffset - rangeStart,
  4705. });
  4706. }
  4707. appendSplitPunctuators(punctuator) {
  4708. this.splitPunctuators.push(this.code.length, this.code.length + 1);
  4709. this.code += `\n${punctuator}\n`;
  4710. }
  4711. appendCodeBlocks(codeBlocks) {
  4712. const start = this.code.length;
  4713. this.code += codeBlocks.code;
  4714. this.remapBlocks.push(...codeBlocks.remapBlocks.map((b) => ({
  4715. range: [b.range[0] + start, b.range[1] + start],
  4716. offset: b.offset - start,
  4717. })));
  4718. this.splitPunctuators.push(...codeBlocks.splitPunctuators.map((s) => s + start));
  4719. }
  4720. }
  4721. class RestoreASTCallbacks {
  4722. constructor() {
  4723. this.callbacks = [];
  4724. }
  4725. addCallback(originalOffsetStart, range, callback) {
  4726. this.callbacks.push({
  4727. range: [
  4728. originalOffsetStart + range[0],
  4729. originalOffsetStart + range[1],
  4730. ],
  4731. callback,
  4732. });
  4733. }
  4734. restore(program, scriptSetupStatements, linesAndColumns) {
  4735. if (this.callbacks.length === 0) {
  4736. return;
  4737. }
  4738. const callbacks = new Set(this.callbacks);
  4739. for (const statement of scriptSetupStatements) {
  4740. for (const cb of callbacks) {
  4741. if (cb.range[0] <= statement.range[0] &&
  4742. statement.range[1] <= cb.range[1]) {
  4743. const restored = cb.callback(statement);
  4744. if (restored) {
  4745. const removeIndex = program.body.indexOf(statement);
  4746. if (removeIndex >= 0) {
  4747. program.body.splice(removeIndex, 1);
  4748. program.body.push(restored.statement);
  4749. program.tokens.push(...restored.tokens);
  4750. restored.statement.parent = program;
  4751. callbacks.delete(cb);
  4752. break;
  4753. }
  4754. }
  4755. }
  4756. }
  4757. }
  4758. if (callbacks.size) {
  4759. const [cb] = callbacks;
  4760. const loc = linesAndColumns.getLocFromIndex(cb.range[0]);
  4761. throw new ParseError("Could not parse <script setup>. Failed to restore ExportNamedDeclaration.", undefined, cb.range[0], loc.line, loc.column);
  4762. }
  4763. }
  4764. }
  4765. function parseScript(code, parserOptions, locationCalculator) {
  4766. try {
  4767. return parseScript$1(code, parserOptions);
  4768. }
  4769. catch (err) {
  4770. const perr = ParseError.normalize(err);
  4771. if (perr) {
  4772. fixErrorLocation(perr, locationCalculator);
  4773. throw perr;
  4774. }
  4775. throw err;
  4776. }
  4777. }
  4778. function parseScriptSetupElements(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, originalParserOptions) {
  4779. const parserOptions = getScriptSetupParserOptions(originalParserOptions);
  4780. const scriptSetupModuleCodeBlocks = getScriptSetupModuleCodeBlocks(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, parserOptions);
  4781. if (!scriptSetupModuleCodeBlocks) {
  4782. return parseScriptFragment("", linesAndColumns.createOffsetLocationCalculator(scriptSetupElement.startTag.range[1]), parserOptions);
  4783. }
  4784. const locationCalculator = {
  4785. getFixOffset(offset, kind) {
  4786. const test = kind === "start"
  4787. ? (block) => offset < block.range[1]
  4788. : (block) => offset <= block.range[1];
  4789. for (const block of scriptSetupModuleCodeBlocks.codeBlocks
  4790. .remapBlocks) {
  4791. if (test(block)) {
  4792. return block.offset;
  4793. }
  4794. }
  4795. return offset;
  4796. },
  4797. getLocFromIndex: linesAndColumns.getLocFromIndex.bind(linesAndColumns),
  4798. };
  4799. const result = parseScript(scriptSetupModuleCodeBlocks.codeBlocks.code, parserOptions, locationCalculator);
  4800. const scriptSetupStatements = remapAST(result, scriptSetupModuleCodeBlocks);
  4801. remapLocationAndTokens(result, scriptSetupModuleCodeBlocks, locationCalculator);
  4802. if (scriptSetupModuleCodeBlocks.restoreASTCallbacks) {
  4803. scriptSetupModuleCodeBlocks.restoreASTCallbacks.restore(result.ast, scriptSetupStatements, linesAndColumns);
  4804. }
  4805. if (result.ast.tokens != null) {
  4806. for (const node of [scriptSetupElement, scriptElement]) {
  4807. const startTag = node.startTag;
  4808. const endTag = node.endTag;
  4809. result.ast.tokens.unshift({
  4810. type: "Punctuator",
  4811. range: startTag.range,
  4812. loc: startTag.loc,
  4813. value: "<script>",
  4814. });
  4815. if (endTag != null) {
  4816. result.ast.tokens.push({
  4817. type: "Punctuator",
  4818. range: endTag.range,
  4819. loc: endTag.loc,
  4820. value: "</script>",
  4821. });
  4822. }
  4823. }
  4824. result.ast.tokens.sort((a, b) => a.range[0] - b.range[0]);
  4825. }
  4826. result.ast.body.sort((a, b) => a.range[0] - b.range[0]);
  4827. const programStartOffset = result.ast.body.reduce((start, node) => Math.min(start, node.range[0]), result.ast.range[0]);
  4828. result.ast.range[0] = programStartOffset;
  4829. result.ast.loc.start =
  4830. locationCalculator.getLocFromIndex(programStartOffset);
  4831. if (result.ast.start != null) {
  4832. result.ast.start = [scriptSetupElement, scriptElement].reduce((start, node) => {
  4833. const textNode = node.children[0];
  4834. return Math.min(start, textNode != null && textNode.type === "VText"
  4835. ? textNode.range[0]
  4836. : node.startTag.range[1]);
  4837. }, result.ast.start);
  4838. }
  4839. const programEndOffset = result.ast.body.reduce((end, node) => Math.max(end, node.range[1]), 0);
  4840. result.ast.range[1] = programEndOffset;
  4841. result.ast.loc.end = locationCalculator.getLocFromIndex(programEndOffset);
  4842. if (result.ast.end != null) {
  4843. result.ast.end = [scriptSetupElement, scriptElement].reduce((end, node) => {
  4844. var _a, _b;
  4845. const textNode = node.children[0];
  4846. return Math.max(end, textNode != null && textNode.type === "VText"
  4847. ? textNode.range[1]
  4848. : (_b = (_a = node.endTag) === null || _a === void 0 ? void 0 : _a.range[0]) !== null && _b !== void 0 ? _b : node.range[1]);
  4849. }, 0);
  4850. }
  4851. return result;
  4852. }
  4853. function getScriptSetupModuleCodeBlocks(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, parserOptions) {
  4854. const scriptSetupCodeBlocks = getScriptSetupCodeBlocks(scriptSetupElement, sfcCode, linesAndColumns, parserOptions);
  4855. const textNode = scriptElement.children[0];
  4856. if (textNode == null || textNode.type !== "VText") {
  4857. return scriptSetupCodeBlocks;
  4858. }
  4859. const [scriptStartOffset, scriptEndOffset] = textNode.range;
  4860. const codeBlocks = new CodeBlocks();
  4861. codeBlocks.append(sfcCode.slice(scriptStartOffset, scriptEndOffset), scriptStartOffset);
  4862. if (scriptSetupCodeBlocks == null) {
  4863. return { codeBlocks };
  4864. }
  4865. codeBlocks.appendSplitPunctuators(";");
  4866. const scriptSetupOffset = codeBlocks.length;
  4867. codeBlocks.appendCodeBlocks(scriptSetupCodeBlocks.codeBlocks);
  4868. return {
  4869. codeBlocks,
  4870. scriptSetupBlockRange: [
  4871. scriptSetupCodeBlocks.scriptSetupBlockRange[0] + scriptSetupOffset,
  4872. scriptSetupCodeBlocks.scriptSetupBlockRange[1] + scriptSetupOffset,
  4873. ],
  4874. restoreASTCallbacks: scriptSetupCodeBlocks.restoreASTCallbacks,
  4875. };
  4876. }
  4877. function getScriptSetupCodeBlocks(node, sfcCode, linesAndColumns, parserOptions) {
  4878. const textNode = node.children[0];
  4879. if (textNode == null || textNode.type !== "VText") {
  4880. return null;
  4881. }
  4882. const [scriptSetupStartOffset, scriptSetupEndOffset] = textNode.range;
  4883. const scriptCode = sfcCode.slice(scriptSetupStartOffset, scriptSetupEndOffset);
  4884. const offsetLocationCalculator = linesAndColumns.createOffsetLocationCalculator(scriptSetupStartOffset);
  4885. const result = parseScript(scriptCode, parserOptions, offsetLocationCalculator);
  4886. const { ast } = result;
  4887. const importCodeBlocks = new CodeBlocks();
  4888. const statementCodeBlocks = new CodeBlocks();
  4889. const exportDefaultCodeBlocks = new CodeBlocks();
  4890. const restoreASTCallbacks = new RestoreASTCallbacks();
  4891. let astOffset = 0;
  4892. function processAppend(codeBlocks, start, end) {
  4893. if (start < end) {
  4894. codeBlocks.append(scriptCode.slice(start, end), scriptSetupStartOffset + start);
  4895. astOffset = end;
  4896. }
  4897. }
  4898. function processStatementCodeBlock(start) {
  4899. if (astOffset < start) {
  4900. processAppend(statementCodeBlocks, astOffset, start);
  4901. statementCodeBlocks.appendSplitPunctuators(";");
  4902. }
  4903. }
  4904. function processModuleCodeBlock(codeBlocks, start, end) {
  4905. processAppend(codeBlocks, start, end);
  4906. codeBlocks.appendSplitPunctuators(";");
  4907. }
  4908. for (const body of ast.body) {
  4909. if (body.type === "ImportDeclaration" ||
  4910. body.type === "ExportAllDeclaration" ||
  4911. (body.type === "ExportNamedDeclaration" && body.source != null)) {
  4912. const [start, end] = getNodeFullRange(body);
  4913. processStatementCodeBlock(start);
  4914. processModuleCodeBlock(importCodeBlocks, start, end);
  4915. }
  4916. else if (body.type === "ExportDefaultDeclaration") {
  4917. const [start, end] = getNodeFullRange(body);
  4918. processStatementCodeBlock(start);
  4919. processModuleCodeBlock(exportDefaultCodeBlocks, start, end);
  4920. }
  4921. else if (body.type === "ExportNamedDeclaration") {
  4922. const [start, end] = getNodeFullRange(body);
  4923. processStatementCodeBlock(start);
  4924. const tokens = ast.tokens;
  4925. const exportTokenIndex = tokens.findIndex((t) => t.range[0] === body.range[0]);
  4926. const exportToken = tokens[exportTokenIndex];
  4927. if (exportToken && exportToken.value === "export") {
  4928. processAppend(statementCodeBlocks, astOffset, exportToken.range[0]);
  4929. if (body.declaration) {
  4930. processModuleCodeBlock(statementCodeBlocks, exportToken.range[1], end);
  4931. restoreASTCallbacks.addCallback(scriptSetupStartOffset, [start, end], (statement) => {
  4932. if (statement.type !== body.declaration.type) {
  4933. return null;
  4934. }
  4935. fixNodeLocations(body, result.visitorKeys, offsetLocationCalculator);
  4936. fixLocation(exportToken, offsetLocationCalculator);
  4937. body.declaration = statement;
  4938. statement.parent = body;
  4939. return {
  4940. statement: body,
  4941. tokens: [exportToken],
  4942. };
  4943. });
  4944. }
  4945. else {
  4946. statementCodeBlocks.appendSplitPunctuators("(");
  4947. const restoreTokens = [exportToken];
  4948. let startOffset = exportToken.range[1];
  4949. for (const spec of body.specifiers) {
  4950. if (spec.local.range[0] < spec.exported.range[0]) {
  4951. const localTokenIndex = tokens.findIndex((t) => t.range[0] === spec.local.range[0], exportTokenIndex);
  4952. checkToken(tokens[localTokenIndex], spec.local.name);
  4953. const asToken = tokens[localTokenIndex + 1];
  4954. checkToken(asToken, "as");
  4955. restoreTokens.push(asToken);
  4956. const exportedToken = tokens[localTokenIndex + 2];
  4957. checkToken(exportedToken, spec.exported.type === "Identifier"
  4958. ? spec.exported.name
  4959. : spec.exported.raw);
  4960. restoreTokens.push(exportedToken);
  4961. processAppend(statementCodeBlocks, startOffset, asToken.range[0]);
  4962. processAppend(statementCodeBlocks, asToken.range[1], exportedToken.range[0]);
  4963. startOffset = exportedToken.range[1];
  4964. }
  4965. }
  4966. processAppend(statementCodeBlocks, startOffset, end);
  4967. statementCodeBlocks.appendSplitPunctuators(")");
  4968. statementCodeBlocks.appendSplitPunctuators(";");
  4969. restoreASTCallbacks.addCallback(scriptSetupStartOffset, [start, end], (statement) => {
  4970. if (statement.type !== "ExpressionStatement" ||
  4971. statement.expression.type !== "ObjectExpression") {
  4972. return null;
  4973. }
  4974. const locals = [];
  4975. for (const prop of statement.expression
  4976. .properties) {
  4977. if (prop.type !== "Property" ||
  4978. prop.value.type !== "Identifier") {
  4979. return null;
  4980. }
  4981. locals.push(prop.value);
  4982. }
  4983. if (body.specifiers.length !== locals.length) {
  4984. return null;
  4985. }
  4986. const map = new Map();
  4987. for (let index = 0; index < body.specifiers.length; index++) {
  4988. const spec = body.specifiers[index];
  4989. const local = locals[index];
  4990. map.set(spec, local);
  4991. }
  4992. fixNodeLocations(body, result.visitorKeys, offsetLocationCalculator);
  4993. for (const token of restoreTokens) {
  4994. fixLocation(token, offsetLocationCalculator);
  4995. }
  4996. for (const [spec, local] of map) {
  4997. spec.local = local;
  4998. local.parent = spec;
  4999. }
  5000. return {
  5001. statement: body,
  5002. tokens: restoreTokens,
  5003. };
  5004. });
  5005. }
  5006. }
  5007. else {
  5008. processModuleCodeBlock(statementCodeBlocks, start, end);
  5009. }
  5010. }
  5011. }
  5012. processStatementCodeBlock(scriptSetupEndOffset);
  5013. const codeBlocks = new CodeBlocks();
  5014. codeBlocks.appendCodeBlocks(importCodeBlocks);
  5015. const scriptSetupBlockRangeStart = codeBlocks.length;
  5016. codeBlocks.appendSplitPunctuators("{");
  5017. codeBlocks.appendCodeBlocks(statementCodeBlocks);
  5018. codeBlocks.appendSplitPunctuators("}");
  5019. const scriptSetupBlockRangeEnd = codeBlocks.length;
  5020. codeBlocks.appendCodeBlocks(exportDefaultCodeBlocks);
  5021. return {
  5022. codeBlocks,
  5023. scriptSetupBlockRange: [
  5024. scriptSetupBlockRangeStart,
  5025. scriptSetupBlockRangeEnd,
  5026. ],
  5027. restoreASTCallbacks,
  5028. };
  5029. function getNodeFullRange(n) {
  5030. let start = n.range[0];
  5031. let end = n.range[1];
  5032. traverseNodes(n, {
  5033. visitorKeys: result.visitorKeys,
  5034. enterNode(c) {
  5035. start = Math.min(start, c.range[0]);
  5036. end = Math.max(end, c.range[1]);
  5037. },
  5038. leaveNode() {
  5039. },
  5040. });
  5041. return [start, end];
  5042. }
  5043. function checkToken(token, value) {
  5044. if (token.value === value) {
  5045. return;
  5046. }
  5047. 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);
  5048. fixErrorLocation(perr, offsetLocationCalculator);
  5049. throw perr;
  5050. }
  5051. }
  5052. function remapAST(result, { scriptSetupBlockRange, codeBlocks }) {
  5053. if (!scriptSetupBlockRange) {
  5054. return [];
  5055. }
  5056. let scriptSetupBlock = null;
  5057. const scriptSetupStatements = [];
  5058. for (let index = result.ast.body.length - 1; index >= 0; index--) {
  5059. const body = result.ast.body[index];
  5060. if (body.type === "BlockStatement") {
  5061. if (scriptSetupBlockRange[0] <= body.range[0] &&
  5062. body.range[1] <= scriptSetupBlockRange[1]) {
  5063. if (scriptSetupBlock) {
  5064. throw new Error(`Unexpected state error: An unexpected block statement was found. ${JSON.stringify(body.loc)}`);
  5065. }
  5066. scriptSetupBlock = body;
  5067. scriptSetupStatements.push(...body.body.filter((b) => !isSplitPunctuatorsEmptyStatement(b)));
  5068. result.ast.body.splice(index, 1, ...scriptSetupStatements);
  5069. }
  5070. }
  5071. else if (body.type === "EmptyStatement") {
  5072. if (isSplitPunctuatorsEmptyStatement(body)) {
  5073. result.ast.body.splice(index, 1);
  5074. }
  5075. }
  5076. }
  5077. if (result.scopeManager && scriptSetupBlock) {
  5078. const blockScope = result.scopeManager.acquire(scriptSetupBlock, true);
  5079. remapScope(result.scopeManager, blockScope);
  5080. }
  5081. return scriptSetupStatements;
  5082. function isSplitPunctuatorsEmptyStatement(body) {
  5083. return (body.type === "EmptyStatement" &&
  5084. codeBlocks.splitPunctuators.includes(body.range[1] - 1));
  5085. }
  5086. function remapScope(scopeManager, blockScope) {
  5087. const moduleScope = blockScope.upper;
  5088. for (const reference of blockScope.references) {
  5089. reference.from = moduleScope;
  5090. moduleScope.references.push(reference);
  5091. }
  5092. for (const variable of blockScope.variables) {
  5093. variable.scope = moduleScope;
  5094. const alreadyVariable = moduleScope.variables.find((v) => v.name === variable.name);
  5095. if (alreadyVariable) {
  5096. alreadyVariable.defs.push(...variable.defs);
  5097. alreadyVariable.identifiers.push(...variable.identifiers);
  5098. alreadyVariable.references.push(...variable.references);
  5099. for (const reference of variable.references) {
  5100. reference.resolved = alreadyVariable;
  5101. }
  5102. }
  5103. else {
  5104. moduleScope.variables.push(variable);
  5105. moduleScope.set.set(variable.name, variable);
  5106. }
  5107. }
  5108. const upper = blockScope.upper;
  5109. if (upper) {
  5110. const index = upper.childScopes.indexOf(blockScope);
  5111. if (index >= 0) {
  5112. upper.childScopes.splice(index, 1);
  5113. }
  5114. }
  5115. const index = scopeManager.scopes.indexOf(blockScope);
  5116. if (index >= 0) {
  5117. scopeManager.scopes.splice(index, 1);
  5118. }
  5119. }
  5120. }
  5121. function remapLocationAndTokens(result, { codeBlocks }, locationCalculator) {
  5122. const tokens = result.ast.tokens || [];
  5123. const endMap = new Map();
  5124. const buffer = [];
  5125. for (let index = tokens.length - 1; index >= 0; index--) {
  5126. const token = tokens[index];
  5127. if (token.range[0] + 1 === token.range[1] &&
  5128. codeBlocks.splitPunctuators.includes(token.range[0])) {
  5129. tokens.splice(index, 1);
  5130. buffer.push(token.range[1]);
  5131. continue;
  5132. }
  5133. else {
  5134. for (const end of buffer) {
  5135. endMap.set(end, token.range[1]);
  5136. }
  5137. buffer.length = 0;
  5138. }
  5139. }
  5140. traverseNodes(result.ast, {
  5141. visitorKeys: result.visitorKeys,
  5142. enterNode(node) {
  5143. const rangeEnd = endMap.get(node.range[1]);
  5144. if (rangeEnd != null) {
  5145. node.range[1] = rangeEnd;
  5146. }
  5147. if (node.end) {
  5148. const end = endMap.get(node.end);
  5149. if (end != null) {
  5150. node.end = rangeEnd;
  5151. }
  5152. }
  5153. },
  5154. leaveNode() {
  5155. },
  5156. });
  5157. fixLocations(result, locationCalculator);
  5158. }
  5159. class CSSTokenizer {
  5160. constructor(text, startOffset, options) {
  5161. var _a;
  5162. debug("[css] the source code length: %d", text.length);
  5163. this.text = text;
  5164. this.options = {
  5165. inlineComment: (_a = options === null || options === void 0 ? void 0 : options.inlineComment) !== null && _a !== void 0 ? _a : false,
  5166. };
  5167. this.cp = NULL;
  5168. this.offset = startOffset - 1;
  5169. this.nextOffset = startOffset;
  5170. this.reconsuming = false;
  5171. }
  5172. nextToken() {
  5173. let cp;
  5174. if (this.reconsuming) {
  5175. cp = this.cp;
  5176. this.reconsuming = false;
  5177. }
  5178. else {
  5179. cp = this.consumeNextCodePoint();
  5180. }
  5181. while (isWhitespace(cp)) {
  5182. cp = this.consumeNextCodePoint();
  5183. }
  5184. if (cp === EOF) {
  5185. return null;
  5186. }
  5187. const start = this.offset;
  5188. return this.consumeNextToken(cp, start);
  5189. }
  5190. nextCodePoint() {
  5191. if (this.nextOffset >= this.text.length) {
  5192. return EOF;
  5193. }
  5194. return this.text.codePointAt(this.nextOffset);
  5195. }
  5196. consumeNextCodePoint() {
  5197. if (this.offset >= this.text.length) {
  5198. this.cp = EOF;
  5199. return EOF;
  5200. }
  5201. this.offset = this.nextOffset;
  5202. if (this.offset >= this.text.length) {
  5203. this.cp = EOF;
  5204. return EOF;
  5205. }
  5206. let cp = this.text.codePointAt(this.offset);
  5207. if (cp === CARRIAGE_RETURN) {
  5208. this.nextOffset = this.offset + 1;
  5209. if (this.text.codePointAt(this.nextOffset) === LINE_FEED) {
  5210. this.nextOffset++;
  5211. }
  5212. cp = LINE_FEED;
  5213. }
  5214. else {
  5215. this.nextOffset = this.offset + (cp >= 0x10000 ? 2 : 1);
  5216. }
  5217. this.cp = cp;
  5218. return cp;
  5219. }
  5220. consumeNextToken(cp, start) {
  5221. if (cp === SOLIDUS) {
  5222. const nextCp = this.nextCodePoint();
  5223. if (nextCp === ASTERISK) {
  5224. return this.consumeComment(start);
  5225. }
  5226. if (nextCp === SOLIDUS && this.options.inlineComment) {
  5227. return this.consumeInlineComment(start);
  5228. }
  5229. }
  5230. if (isQuote(cp)) {
  5231. return this.consumeString(start, cp);
  5232. }
  5233. if (isPunctuator(cp)) {
  5234. return {
  5235. type: "Punctuator",
  5236. range: [start, start + 1],
  5237. value: String.fromCodePoint(cp),
  5238. };
  5239. }
  5240. return this.consumeWord(start);
  5241. }
  5242. consumeWord(start) {
  5243. let cp = this.consumeNextCodePoint();
  5244. while (!isWhitespace(cp) && !isPunctuator(cp) && !isQuote(cp)) {
  5245. cp = this.consumeNextCodePoint();
  5246. }
  5247. this.reconsuming = true;
  5248. const range = [start, this.offset];
  5249. const text = this.text;
  5250. let value;
  5251. return {
  5252. type: "Word",
  5253. range,
  5254. get value() {
  5255. return (value !== null && value !== void 0 ? value : (value = text.slice(...range)));
  5256. },
  5257. };
  5258. }
  5259. consumeString(start, quote) {
  5260. let valueEndOffset = null;
  5261. let cp = this.consumeNextCodePoint();
  5262. while (cp !== EOF) {
  5263. if (cp === quote) {
  5264. valueEndOffset = this.offset;
  5265. break;
  5266. }
  5267. if (cp === REVERSE_SOLIDUS) {
  5268. this.consumeNextCodePoint();
  5269. }
  5270. cp = this.consumeNextCodePoint();
  5271. }
  5272. const text = this.text;
  5273. let value;
  5274. const valueRange = [
  5275. start + 1,
  5276. valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
  5277. ];
  5278. return {
  5279. type: "Quoted",
  5280. range: [start, this.nextOffset],
  5281. valueRange,
  5282. get value() {
  5283. return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
  5284. },
  5285. quote: String.fromCodePoint(quote),
  5286. };
  5287. }
  5288. consumeComment(start) {
  5289. this.consumeNextCodePoint();
  5290. let valueEndOffset = null;
  5291. let cp = this.consumeNextCodePoint();
  5292. while (cp !== EOF) {
  5293. if (cp === ASTERISK) {
  5294. cp = this.consumeNextCodePoint();
  5295. if (cp === SOLIDUS) {
  5296. valueEndOffset = this.offset - 1;
  5297. break;
  5298. }
  5299. }
  5300. cp = this.consumeNextCodePoint();
  5301. }
  5302. const valueRange = [
  5303. start + 2,
  5304. valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
  5305. ];
  5306. const text = this.text;
  5307. let value;
  5308. return {
  5309. type: "Block",
  5310. range: [start, this.nextOffset],
  5311. valueRange,
  5312. get value() {
  5313. return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
  5314. },
  5315. };
  5316. }
  5317. consumeInlineComment(start) {
  5318. this.consumeNextCodePoint();
  5319. let valueEndOffset = null;
  5320. let cp = this.consumeNextCodePoint();
  5321. while (cp !== EOF) {
  5322. if (cp === LINE_FEED) {
  5323. valueEndOffset = this.offset - 1;
  5324. break;
  5325. }
  5326. cp = this.consumeNextCodePoint();
  5327. }
  5328. const valueRange = [
  5329. start + 2,
  5330. valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
  5331. ];
  5332. const text = this.text;
  5333. let value;
  5334. return {
  5335. type: "Line",
  5336. range: [start, this.nextOffset],
  5337. valueRange,
  5338. get value() {
  5339. return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
  5340. },
  5341. };
  5342. }
  5343. }
  5344. function isPunctuator(cp) {
  5345. return (cp === COLON ||
  5346. cp === SEMICOLON ||
  5347. cp === LEFT_PARENTHESIS ||
  5348. cp === RIGHT_PARENTHESIS ||
  5349. cp === LEFT_CURLY_BRACKET ||
  5350. cp === RIGHT_CURLY_BRACKET ||
  5351. cp === LEFT_SQUARE_BRACKET ||
  5352. cp === RIGHT_SQUARE_BRACKET ||
  5353. cp === SOLIDUS ||
  5354. cp === ASTERISK);
  5355. }
  5356. function isQuote(cp) {
  5357. return cp === APOSTROPHE || cp === QUOTATION_MARK;
  5358. }
  5359. class CSSTokenScanner {
  5360. constructor(text, options) {
  5361. this.reconsuming = [];
  5362. this.tokenizer = new CSSTokenizer(text, 0, options);
  5363. }
  5364. nextToken() {
  5365. return this.reconsuming.shift() || this.tokenizer.nextToken();
  5366. }
  5367. reconsume(...tokens) {
  5368. this.reconsuming.push(...tokens);
  5369. }
  5370. }
  5371. function parseStyleElements(elements, globalLocationCalculator, originalParserOptions) {
  5372. const parserOptions = Object.assign(Object.assign({}, originalParserOptions), { ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION });
  5373. for (const style of elements) {
  5374. style.style = true;
  5375. parseStyleElement(style, globalLocationCalculator, parserOptions, {
  5376. inlineComment: (getLang(style) || "css") !== "css",
  5377. });
  5378. }
  5379. }
  5380. function parseStyleElement(style, globalLocationCalculator, parserOptions, cssOptions) {
  5381. if (style.children.length !== 1) {
  5382. return;
  5383. }
  5384. const textNode = style.children[0];
  5385. if (textNode.type !== "VText") {
  5386. return;
  5387. }
  5388. const code = textNode.value;
  5389. if (!/v-bind\s*(?:\(|\/)/u.test(code)) {
  5390. return;
  5391. }
  5392. const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(textNode.range[0]);
  5393. const document = getOwnerDocument(style);
  5394. parseStyle(document, style, code, locationCalculator, parserOptions, cssOptions);
  5395. }
  5396. function parseStyle(document, style, code, locationCalculator, parserOptions, cssOptions) {
  5397. let textStart = 0;
  5398. for (const { range, exprRange, quote, openingParenOffset, comments, } of iterateVBind(code, cssOptions)) {
  5399. insertComments(document, comments.map((c) => createSimpleToken(c.type, locationCalculator.getOffsetWithGap(c.range[0]), locationCalculator.getOffsetWithGap(c.range[1]), c.value, locationCalculator)));
  5400. const container = {
  5401. type: "VExpressionContainer",
  5402. range: [
  5403. locationCalculator.getOffsetWithGap(range[0]),
  5404. locationCalculator.getOffsetWithGap(range[1]),
  5405. ],
  5406. loc: {
  5407. start: locationCalculator.getLocation(range[0]),
  5408. end: locationCalculator.getLocation(range[1]),
  5409. },
  5410. parent: style,
  5411. expression: null,
  5412. references: [],
  5413. };
  5414. const openingParenStart = locationCalculator.getOffsetWithGap(openingParenOffset);
  5415. const beforeTokens = [
  5416. createSimpleToken("HTMLRawText", container.range[0], container.range[0] + 6, "v-bind", locationCalculator),
  5417. createSimpleToken("Punctuator", openingParenStart, openingParenStart + 1, "(", locationCalculator),
  5418. ];
  5419. const afterTokens = [
  5420. createSimpleToken("Punctuator", container.range[1] - 1, container.range[1], ")", locationCalculator),
  5421. ];
  5422. if (quote) {
  5423. const openStart = locationCalculator.getOffsetWithGap(exprRange[0] - 1);
  5424. beforeTokens.push(createSimpleToken("Punctuator", openStart, openStart + 1, quote, locationCalculator));
  5425. const closeStart = locationCalculator.getOffsetWithGap(exprRange[1]);
  5426. afterTokens.unshift(createSimpleToken("Punctuator", closeStart, closeStart + 1, quote, locationCalculator));
  5427. }
  5428. const beforeLast = beforeTokens[beforeTokens.length - 1];
  5429. replaceAndSplitTokens(document, {
  5430. range: [container.range[0], beforeLast.range[1]],
  5431. loc: { start: container.loc.start, end: beforeLast.loc.end },
  5432. }, beforeTokens);
  5433. const afterFirst = afterTokens[0];
  5434. replaceAndSplitTokens(document, {
  5435. range: [afterFirst.range[0], container.range[1]],
  5436. loc: { start: afterFirst.loc.start, end: container.loc.end },
  5437. }, afterTokens);
  5438. const lastChild = style.children[style.children.length - 1];
  5439. style.children.push(container);
  5440. if (lastChild.type === "VText") {
  5441. const newTextNode = {
  5442. type: "VText",
  5443. range: [container.range[1], lastChild.range[1]],
  5444. loc: {
  5445. start: Object.assign({}, container.loc.end),
  5446. end: Object.assign({}, lastChild.loc.end),
  5447. },
  5448. parent: style,
  5449. value: code.slice(range[1]),
  5450. };
  5451. style.children.push(newTextNode);
  5452. lastChild.range[1] = container.range[0];
  5453. lastChild.loc.end = Object.assign({}, container.loc.start);
  5454. lastChild.value = code.slice(textStart, range[0]);
  5455. textStart = range[1];
  5456. }
  5457. try {
  5458. const ret = parseExpression(code.slice(...exprRange), locationCalculator.getSubCalculatorShift(exprRange[0]), parserOptions, { allowEmpty: false, allowFilters: false });
  5459. if (ret.expression) {
  5460. ret.expression.parent = container;
  5461. container.expression = ret.expression;
  5462. container.references = ret.references;
  5463. }
  5464. replaceAndSplitTokens(document, {
  5465. range: [beforeLast.range[1], afterFirst.range[0]],
  5466. loc: {
  5467. start: beforeLast.loc.end,
  5468. end: afterFirst.loc.start,
  5469. },
  5470. }, ret.tokens);
  5471. insertComments(document, ret.comments);
  5472. for (const variable of ret.variables) {
  5473. style.variables.push(variable);
  5474. }
  5475. resolveReferences(container);
  5476. }
  5477. catch (err) {
  5478. debug("[style] Parse error: %s", err);
  5479. if (ParseError.isParseError(err)) {
  5480. insertError(document, err);
  5481. }
  5482. else {
  5483. throw err;
  5484. }
  5485. }
  5486. }
  5487. }
  5488. function* iterateVBind(code, cssOptions) {
  5489. const tokenizer = new CSSTokenScanner(code, cssOptions);
  5490. let token;
  5491. while ((token = tokenizer.nextToken())) {
  5492. if (token.type !== "Word" || token.value !== "v-bind") {
  5493. continue;
  5494. }
  5495. const openingParen = findVBindOpeningParen(tokenizer);
  5496. if (!openingParen) {
  5497. continue;
  5498. }
  5499. const arg = parseVBindArg(tokenizer);
  5500. if (!arg) {
  5501. continue;
  5502. }
  5503. yield {
  5504. range: [token.range[0], arg.closingParen.range[1]],
  5505. exprRange: arg.exprRange,
  5506. quote: arg.quote,
  5507. openingParenOffset: openingParen.openingParen.range[0],
  5508. comments: [...openingParen.comments, ...arg.comments],
  5509. };
  5510. }
  5511. }
  5512. function findVBindOpeningParen(tokenizer) {
  5513. const comments = [];
  5514. let token;
  5515. while ((token = tokenizer.nextToken())) {
  5516. if (token.type === "Punctuator" && token.value === "(") {
  5517. return {
  5518. openingParen: token,
  5519. comments,
  5520. };
  5521. }
  5522. else if (isComment(token)) {
  5523. comments.push(token);
  5524. continue;
  5525. }
  5526. tokenizer.reconsume(...comments, token);
  5527. return null;
  5528. }
  5529. return null;
  5530. }
  5531. function parseVBindArg(tokenizer) {
  5532. const tokensBuffer = [];
  5533. const comments = [];
  5534. const tokens = [];
  5535. const closeTokenStack = [];
  5536. let token;
  5537. while ((token = tokenizer.nextToken())) {
  5538. if (token.type === "Punctuator") {
  5539. if (token.value === ")" && !closeTokenStack.length) {
  5540. if (tokens.length === 1 &&
  5541. tokens[0].type === "Quoted") {
  5542. const quotedToken = tokens[0];
  5543. return {
  5544. exprRange: quotedToken.valueRange,
  5545. quote: quotedToken.quote,
  5546. closingParen: token,
  5547. comments,
  5548. };
  5549. }
  5550. const startToken = tokensBuffer[0] || token;
  5551. return {
  5552. exprRange: [startToken.range[0], token.range[0]],
  5553. quote: null,
  5554. closingParen: token,
  5555. comments: [],
  5556. };
  5557. }
  5558. if (token.value === closeTokenStack[0]) {
  5559. closeTokenStack.shift();
  5560. }
  5561. else if (token.value === "(") {
  5562. closeTokenStack.unshift(")");
  5563. }
  5564. }
  5565. tokensBuffer.push(token);
  5566. if (isComment(token)) {
  5567. comments.push(token);
  5568. }
  5569. else {
  5570. tokens.push(token);
  5571. }
  5572. }
  5573. tokenizer.reconsume(...tokensBuffer);
  5574. return null;
  5575. }
  5576. function isComment(token) {
  5577. return token.type === "Block" || token.type === "Line";
  5578. }
  5579. const BUILTIN_COMPONENTS = new Set([
  5580. "template",
  5581. "slot",
  5582. "component",
  5583. "Component",
  5584. "transition",
  5585. "Transition",
  5586. "transition-group",
  5587. "TransitionGroup",
  5588. "keep-alive",
  5589. "KeepAlive",
  5590. "teleport",
  5591. "Teleport",
  5592. "suspense",
  5593. "Suspense",
  5594. ]);
  5595. const BUILTIN_DIRECTIVES = new Set([
  5596. "bind",
  5597. "on",
  5598. "text",
  5599. "html",
  5600. "show",
  5601. "if",
  5602. "else",
  5603. "else-if",
  5604. "for",
  5605. "model",
  5606. "slot",
  5607. "pre",
  5608. "cloak",
  5609. "once",
  5610. "memo",
  5611. "is",
  5612. ]);
  5613. const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer," +
  5614. "header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption," +
  5615. "figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code," +
  5616. "data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup," +
  5617. "time,u,var,wbr,area,audio,map,track,video,embed,object,param,source," +
  5618. "canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td," +
  5619. "th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup," +
  5620. "option,output,progress,select,textarea,details,dialog,menu," +
  5621. "summary,template,blockquote,iframe,tfoot";
  5622. const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile," +
  5623. "defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer," +
  5624. "feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap," +
  5625. "feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR," +
  5626. "feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset," +
  5627. "fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter," +
  5628. "foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask," +
  5629. "mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern," +
  5630. "polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol," +
  5631. "text,textPath,title,tspan,unknown,use,view";
  5632. const NATIVE_TAGS = new Set([...HTML_TAGS.split(","), ...SVG_TAGS.split(",")]);
  5633. const COMPILER_MACROS_AT_ROOT = new Set([
  5634. "defineProps",
  5635. "defineEmits",
  5636. "defineExpose",
  5637. "withDefaults",
  5638. ]);
  5639. function camelize(str) {
  5640. return str.replace(/-(\w)/gu, (_, c) => (c ? c.toUpperCase() : ""));
  5641. }
  5642. function capitalize(str) {
  5643. return str[0].toUpperCase() + str.slice(1);
  5644. }
  5645. function analyzeScriptSetupScope(scopeManager, templateBody, df, _parserOptions) {
  5646. analyzeUsedInTemplateVariables(scopeManager, templateBody, df);
  5647. analyzeCompilerMacrosVariables(scopeManager);
  5648. }
  5649. function extractVariables(scopeManager) {
  5650. const scriptVariables = new Map();
  5651. const globalScope = scopeManager.globalScope;
  5652. if (!globalScope) {
  5653. return scriptVariables;
  5654. }
  5655. for (const variable of globalScope.variables) {
  5656. scriptVariables.set(variable.name, variable);
  5657. }
  5658. const moduleScope = globalScope.childScopes.find((scope) => scope.type === "module");
  5659. for (const variable of (moduleScope && moduleScope.variables) || []) {
  5660. scriptVariables.set(variable.name, variable);
  5661. }
  5662. return scriptVariables;
  5663. }
  5664. function analyzeUsedInTemplateVariables(scopeManager, templateBody, df) {
  5665. const scriptVariables = extractVariables(scopeManager);
  5666. const markedVariables = new Set();
  5667. function markSetupReferenceVariableAsUsed(name) {
  5668. if (scriptVariables.has(name)) {
  5669. markVariableAsUsed(name);
  5670. return true;
  5671. }
  5672. const camelName = camelize(name);
  5673. if (scriptVariables.has(camelName)) {
  5674. markVariableAsUsed(camelName);
  5675. return true;
  5676. }
  5677. const pascalName = capitalize(camelName);
  5678. if (scriptVariables.has(pascalName)) {
  5679. markVariableAsUsed(pascalName);
  5680. return true;
  5681. }
  5682. return false;
  5683. }
  5684. function markVariableAsUsed(nameOrRef) {
  5685. let name;
  5686. let isValueReference;
  5687. let isTypeReference;
  5688. if (typeof nameOrRef === "string") {
  5689. name = nameOrRef;
  5690. }
  5691. else {
  5692. name = nameOrRef.id.name;
  5693. isValueReference = nameOrRef.isValueReference;
  5694. isTypeReference = nameOrRef.isTypeReference;
  5695. }
  5696. const variable = scriptVariables.get(name);
  5697. if (!variable || variable.identifiers.length === 0) {
  5698. return;
  5699. }
  5700. if (markedVariables.has(name)) {
  5701. return;
  5702. }
  5703. markedVariables.add(name);
  5704. const reference = new (getEslintScope().Reference)();
  5705. reference.vueUsedInTemplate = true;
  5706. reference.from = variable.scope;
  5707. reference.identifier = variable.identifiers[0];
  5708. reference.isWrite = () => false;
  5709. reference.isWriteOnly = () => false;
  5710. reference.isRead = () => true;
  5711. reference.isReadOnly = () => true;
  5712. reference.isReadWrite = () => false;
  5713. reference.isValueReference = isValueReference;
  5714. reference.isTypeReference = isTypeReference;
  5715. variable.references.push(reference);
  5716. reference.resolved = variable;
  5717. }
  5718. function processVExpressionContainer(node) {
  5719. for (const reference of node.references.filter((ref) => ref.variable == null)) {
  5720. markVariableAsUsed(reference);
  5721. }
  5722. }
  5723. function processVElement(node) {
  5724. if ((node.rawName === node.name && NATIVE_TAGS.has(node.rawName)) ||
  5725. BUILTIN_COMPONENTS.has(node.rawName)) {
  5726. return;
  5727. }
  5728. if (!markSetupReferenceVariableAsUsed(node.rawName)) {
  5729. const dotIndex = node.rawName.indexOf(".");
  5730. if (dotIndex > 0) {
  5731. markSetupReferenceVariableAsUsed(node.rawName.slice(0, dotIndex));
  5732. }
  5733. }
  5734. }
  5735. function processVAttribute(node) {
  5736. if (node.directive) {
  5737. if (BUILTIN_DIRECTIVES.has(node.key.name.name)) {
  5738. return;
  5739. }
  5740. markSetupReferenceVariableAsUsed(`v-${node.key.name.rawName}`);
  5741. }
  5742. else if (node.key.name === "ref" && node.value) {
  5743. markVariableAsUsed(node.value.value);
  5744. }
  5745. }
  5746. if (templateBody) {
  5747. traverseNodes(templateBody, {
  5748. enterNode(node) {
  5749. if (node.type === "VExpressionContainer") {
  5750. processVExpressionContainer(node);
  5751. }
  5752. else if (node.type === "VElement") {
  5753. processVElement(node);
  5754. }
  5755. else if (node.type === "VAttribute") {
  5756. processVAttribute(node);
  5757. }
  5758. },
  5759. leaveNode() {
  5760. },
  5761. });
  5762. }
  5763. for (const child of df.children) {
  5764. if (child.type === "VElement" && child.name === "style") {
  5765. for (const node of child.children) {
  5766. if (node.type === "VExpressionContainer") {
  5767. processVExpressionContainer(node);
  5768. }
  5769. }
  5770. }
  5771. }
  5772. }
  5773. function analyzeCompilerMacrosVariables(scopeManager) {
  5774. const globalScope = scopeManager.globalScope;
  5775. if (!globalScope) {
  5776. return;
  5777. }
  5778. const compilerMacroVariables = new Map();
  5779. function addCompilerMacroVariable(reference) {
  5780. const name = reference.identifier.name;
  5781. let variable = compilerMacroVariables.get(name);
  5782. if (!variable) {
  5783. variable = new (getEslintScope().Variable)();
  5784. variable.name = name;
  5785. variable.scope = globalScope;
  5786. globalScope.variables.push(variable);
  5787. globalScope.set.set(name, variable);
  5788. compilerMacroVariables.set(name, variable);
  5789. }
  5790. reference.resolved = variable;
  5791. variable.references.push(reference);
  5792. }
  5793. const newThrough = [];
  5794. for (const reference of globalScope.through) {
  5795. if (COMPILER_MACROS_AT_ROOT.has(reference.identifier.name)) {
  5796. if (reference.from.type === "global" ||
  5797. reference.from.type === "module") {
  5798. addCompilerMacroVariable(reference);
  5799. continue;
  5800. }
  5801. }
  5802. newThrough.push(reference);
  5803. }
  5804. globalScope.through = newThrough;
  5805. }
  5806. const STARTS_WITH_LT = /^\s*</u;
  5807. function isVueFile(code, options) {
  5808. const filePath = options.filePath || "unknown.js";
  5809. return path__namespace.extname(filePath) === ".vue" || STARTS_WITH_LT.test(code);
  5810. }
  5811. function parseForESLint(code, parserOptions) {
  5812. const options = Object.assign({
  5813. comment: true,
  5814. loc: true,
  5815. range: true,
  5816. tokens: true,
  5817. }, parserOptions || {});
  5818. let result;
  5819. let document;
  5820. let locationCalculator;
  5821. if (!isVueFile(code, options)) {
  5822. result = parseAsScript(code, options);
  5823. document = null;
  5824. locationCalculator = null;
  5825. }
  5826. else {
  5827. ({ result, document, locationCalculator } = parseAsSFC(code, options));
  5828. }
  5829. result.services = Object.assign(result.services || {}, define(code, result.ast, document, locationCalculator, {
  5830. parserOptions: options,
  5831. }));
  5832. return result;
  5833. }
  5834. function parse(code, options) {
  5835. return parseForESLint(code, options).ast;
  5836. }
  5837. function parseAsSFC(code, options) {
  5838. var _a, _b, _c;
  5839. const optionsForTemplate = Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION });
  5840. const skipParsingScript = options.parser === false;
  5841. const tokenizer = new Tokenizer(code, optionsForTemplate);
  5842. const rootAST = new Parser(tokenizer, optionsForTemplate).parse();
  5843. const locationCalculator = new LocationCalculatorForHtml(tokenizer.gaps, tokenizer.lineTerminators);
  5844. const scripts = rootAST.children.filter(isScriptElement);
  5845. const template = rootAST.children.find(isTemplateElement);
  5846. const templateLang = getLang(template) || "html";
  5847. const hasTemplateTokenizer = (_a = options === null || options === void 0 ? void 0 : options.templateTokenizer) === null || _a === void 0 ? void 0 : _a[templateLang];
  5848. const concreteInfo = {
  5849. tokens: rootAST.tokens,
  5850. comments: rootAST.comments,
  5851. errors: rootAST.errors,
  5852. };
  5853. const templateBody = template != null && (templateLang === "html" || hasTemplateTokenizer)
  5854. ? Object.assign(template, concreteInfo)
  5855. : undefined;
  5856. const scriptParser = getScriptParser(options.parser, () => getParserLangFromSFC(rootAST));
  5857. let result;
  5858. let scriptSetup;
  5859. if (skipParsingScript || !scripts.length) {
  5860. result = parseScript$1("", Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, parser: scriptParser }));
  5861. }
  5862. else if (scripts.length === 2 &&
  5863. (scriptSetup = scripts.find(isScriptSetupElement))) {
  5864. result = parseScriptSetupElements(scriptSetup, scripts.find((e) => e !== scriptSetup), code, new LinesAndColumns(tokenizer.lineTerminators), Object.assign(Object.assign({}, options), { parser: scriptParser }));
  5865. }
  5866. else {
  5867. result = parseScriptElement(scripts[0], code, new LinesAndColumns(tokenizer.lineTerminators), Object.assign(Object.assign({}, options), { parser: scriptParser }));
  5868. }
  5869. if ((_c = (_b = options.vueFeatures) === null || _b === void 0 ? void 0 : _b.styleCSSVariableInjection) !== null && _c !== void 0 ? _c : true) {
  5870. const styles = rootAST.children.filter(isStyleElement);
  5871. parseStyleElements(styles, locationCalculator, Object.assign(Object.assign({}, options), { parser: getScriptParser(options.parser, function* () {
  5872. yield "<template>";
  5873. yield getParserLangFromSFC(rootAST);
  5874. }) }));
  5875. }
  5876. result.ast.templateBody = templateBody;
  5877. if (options.eslintScopeManager) {
  5878. if (scripts.some(isScriptSetupElement)) {
  5879. if (!result.scopeManager) {
  5880. result.scopeManager = analyzeScope(result.ast, options);
  5881. }
  5882. analyzeScriptSetupScope(result.scopeManager, templateBody, rootAST);
  5883. }
  5884. }
  5885. return {
  5886. result,
  5887. locationCalculator,
  5888. document: rootAST,
  5889. };
  5890. }
  5891. function parseAsScript(code, options) {
  5892. return parseScript$1(code, Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, parser: getScriptParser(options.parser, () => {
  5893. const ext = (path__namespace.extname(options.filePath || "unknown.js").toLowerCase() ||
  5894. "")
  5895. .slice(1);
  5896. if (/^[jt]sx$/u.test(ext)) {
  5897. return [ext, ext.slice(0, -1)];
  5898. }
  5899. return ext;
  5900. }) }));
  5901. }
  5902. exports.AST = index;
  5903. exports.parse = parse;
  5904. exports.parseForESLint = parseForESLint;
  5905. //# sourceMappingURL=index.js.map