index.js 244 KB

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