index.js 173 KB

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