index.js 252 KB

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