index.js 159 KB

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