index.js 278 KB

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