index.js 180 KB

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