index.js 181 KB

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