index.js 202 KB

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