esprima-next

This is a copy of the esprima-next library. The jsNode build has been modified to work with userscripts.

目前为 2024-09-03 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/506615/1440562/esprima-next.js

  1. /*
  2. This is a copy of the esprima-next library. The jsNode build has been modified to work with userscripts.
  3. */
  4.  
  5. /* eslint-disable no-bitwise */
  6. /* eslint-disable default-case-last */
  7. /* eslint-disable no-self-compare */
  8. /* eslint-disable no-multi-assign */
  9. /* eslint-disable consistent-return */
  10. /* eslint-disable no-unused-vars */
  11. /* eslint-disable no-useless-constructor */
  12. /* eslint-disable strict */
  13. /* eslint-disable default-case */
  14. /* eslint-disable no-void */
  15. /* eslint-disable default-param-last */
  16. /* eslint-disable no-continue */
  17. /* eslint-disable no-case-declarations */
  18. /* eslint-disable no-undef */
  19. /* eslint-disable eqeqeq */
  20. /* eslint-disable no-mixed-operators */
  21. /* eslint-disable class-methods-use-this */
  22. /* eslint-disable no-shadow */
  23. /* eslint-disable no-nested-ternary */
  24. /* eslint-disable no-sequences */
  25. /* eslint-disable no-unused-expressions */
  26. /* eslint-disable no-return-assign */
  27. /* eslint-disable max-len */
  28. /* eslint-disable max-classes-per-file */
  29.  
  30. // eslint-disable-next-line func-names
  31. const esprima = (function() {
  32. 'use strict';
  33.  
  34. const Syntax = {
  35. AssignmentExpression: 'AssignmentExpression',
  36. AssignmentPattern: 'AssignmentPattern',
  37. ArrayExpression: 'ArrayExpression',
  38. ArrayPattern: 'ArrayPattern',
  39. ArrowFunctionExpression: 'ArrowFunctionExpression',
  40. AwaitExpression: 'AwaitExpression',
  41. BlockStatement: 'BlockStatement',
  42. BinaryExpression: 'BinaryExpression',
  43. BreakStatement: 'BreakStatement',
  44. CallExpression: 'CallExpression',
  45. CatchClause: 'CatchClause',
  46. ChainExpression: 'ChainExpression',
  47. ClassBody: 'ClassBody',
  48. ClassDeclaration: 'ClassDeclaration',
  49. ClassExpression: 'ClassExpression',
  50. ConditionalExpression: 'ConditionalExpression',
  51. ContinueStatement: 'ContinueStatement',
  52. Decorator: 'Decorator',
  53. DoWhileStatement: 'DoWhileStatement',
  54. DebuggerStatement: 'DebuggerStatement',
  55. EmptyStatement: 'EmptyStatement',
  56. ExportAllDeclaration: 'ExportAllDeclaration',
  57. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  58. ExportNamedDeclaration: 'ExportNamedDeclaration',
  59. ExportSpecifier: 'ExportSpecifier',
  60. ExpressionStatement: 'ExpressionStatement',
  61. ForStatement: 'ForStatement',
  62. ForOfStatement: 'ForOfStatement',
  63. ForInStatement: 'ForInStatement',
  64. FunctionDeclaration: 'FunctionDeclaration',
  65. FunctionExpression: 'FunctionExpression',
  66. Identifier: 'Identifier',
  67. IfStatement: 'IfStatement',
  68. ImportAttribute: 'ImportAttribute',
  69. ImportExpression: 'ImportExpression',
  70. ImportDeclaration: 'ImportDeclaration',
  71. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  72. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  73. ImportSpecifier: 'ImportSpecifier',
  74. Literal: 'Literal',
  75. LabeledStatement: 'LabeledStatement',
  76. LogicalExpression: 'LogicalExpression',
  77. MemberExpression: 'MemberExpression',
  78. MetaProperty: 'MetaProperty',
  79. MethodDefinition: 'MethodDefinition',
  80. NewExpression: 'NewExpression',
  81. ObjectExpression: 'ObjectExpression',
  82. ObjectPattern: 'ObjectPattern',
  83. Program: 'Program',
  84. Property: 'Property',
  85. PrivateIdentifier: 'PrivateIdentifier',
  86. RestElement: 'RestElement',
  87. ReturnStatement: 'ReturnStatement',
  88. SequenceExpression: 'SequenceExpression',
  89. SpreadElement: 'SpreadElement',
  90. StaticBlock: 'StaticBlock',
  91. Super: 'Super',
  92. SwitchCase: 'SwitchCase',
  93. SwitchStatement: 'SwitchStatement',
  94. TaggedTemplateExpression: 'TaggedTemplateExpression',
  95. TemplateElement: 'TemplateElement',
  96. TemplateLiteral: 'TemplateLiteral',
  97. ThisExpression: 'ThisExpression',
  98. ThrowStatement: 'ThrowStatement',
  99. TryStatement: 'TryStatement',
  100. UnaryExpression: 'UnaryExpression',
  101. UpdateExpression: 'UpdateExpression',
  102. VariableDeclaration: 'VariableDeclaration',
  103. VariableDeclarator: 'VariableDeclarator',
  104. WhileStatement: 'WhileStatement',
  105. WithStatement: 'WithStatement',
  106. YieldExpression: 'YieldExpression'
  107. };
  108.  
  109. class CommentHandler {
  110. attach;
  111. comments;
  112. stack;
  113. leading;
  114. trailing;
  115. constructor() {
  116. this.attach = !1, this.comments = [], this.stack = [], this.leading = [], this.trailing = [];
  117. }
  118.  
  119. insertInnerComments(e, t) {
  120. if (e.type === 'BlockStatement' && e.body.length === 0) {
  121. const s = [];
  122. for (let e = this.leading.length - 1; e >= 0; --e) {
  123. const i = this.leading[e];
  124. t.end.offset >= i.start && (s.unshift(i.comment), this.leading.splice(e, 1), this.trailing.splice(e, 1));
  125. }
  126. s.length && (e.innerComments = s);
  127. }
  128. }
  129.  
  130. findTrailingComments(e) {
  131. let t = [];
  132. if (this.trailing.length > 0) {
  133. for (let s = this.trailing.length - 1; s >= 0; --s) {
  134. const i = this.trailing[s];
  135. i.start >= e.end.offset && t.unshift(i.comment);
  136. }
  137. return this.trailing.length = 0, t;
  138. }
  139. const s = this.stack[this.stack.length - 1];
  140. if (s && s.node.trailingComments) {
  141. const i = s.node.trailingComments[0];
  142. i && i.range[0] >= e.end.offset && (t = s.node.trailingComments, delete s.node.trailingComments);
  143. }
  144. return t;
  145. }
  146.  
  147. findLeadingComments(e) {
  148. const t = [];
  149. let s;
  150. for (; this.stack.length > 0;) {
  151. const t = this.stack[this.stack.length - 1];
  152. if (!(t && t.start >= e.start.offset)) break;
  153. s = t.node, this.stack.pop();
  154. }
  155. if (s) {
  156. for (let i = (s.leadingComments ? s.leadingComments.length : 0) - 1; i >= 0; --i) {
  157. const r = s.leadingComments[i];
  158. r.range[1] <= e.start.offset && (t.unshift(r), s.leadingComments.splice(i, 1));
  159. }
  160. return s.leadingComments && s.leadingComments.length === 0 && delete s.leadingComments, t;
  161. }
  162. for (let s = this.leading.length - 1; s >= 0; --s) {
  163. const i = this.leading[s];
  164. i.start <= e.start.offset && (t.unshift(i.comment), this.leading.splice(s, 1));
  165. }
  166. return t;
  167. }
  168.  
  169. visitNode(e, t) {
  170. if (e.type === 'Program' && e.body.length > 0) return;
  171. this.insertInnerComments(e, t);
  172. const s = this.findTrailingComments(t);
  173. const i = this.findLeadingComments(t);
  174. i.length > 0 && (e.leadingComments = i), s.length > 0 && (e.trailingComments = s), this.stack.push({
  175. node: e,
  176. start: t.start.offset
  177. });
  178. }
  179.  
  180. visitComment(e, t) {
  181. const s = e.type[0] === 'L' ? 'Line' : 'Block';
  182. const i = {
  183. type: s,
  184. value: e.value
  185. };
  186. if (e.range && (i.range = e.range), e.loc && (i.loc = e.loc), this.comments.push(i), this.attach) {
  187. const i = {
  188. comment: {
  189. type: s,
  190. value: e.value,
  191. range: [t.start.offset, t.end.offset]
  192. },
  193. start: t.start.offset
  194. };
  195. e.loc && (i.comment.loc = e.loc), e.type = s, this.leading.push(i), this.trailing.push(i);
  196. }
  197. }
  198.  
  199. visit(e, t) {
  200. e.type === 'LineComment' || e.type === 'BlockComment' ? this.visitComment(e, t) : this.attach && this.visitNode(e, t);
  201. }
  202. }
  203.  
  204. const Regex = {
  205. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7BF\uA7C2-\uA7C6\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB67\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD838[\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDEC0-\uDEEB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,
  206. // eslint-disable-next-line no-misleading-character-class
  207. NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05EF-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u07FD\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D3-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u09FE\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1878\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CD0-\u1CD2\u1CD4-\u1CFA\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7BF\uA7C2-\uA7C6\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB67\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD27\uDD30-\uDD39\uDF00-\uDF1C\uDF27\uDF30-\uDF50\uDFE0-\uDFF6]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD44-\uDD46\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDC9-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3B-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC5E\uDC5F\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDC00-\uDC3A\uDCA0-\uDCE9\uDCFF\uDDA0-\uDDA7\uDDAA-\uDDD7\uDDDA-\uDDE1\uDDE3\uDDE4\uDE00-\uDE3E\uDE47\uDE50-\uDE99\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD8E\uDD90\uDD91\uDD93-\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF6]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF4F-\uDF87\uDF8F-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A\uDD00-\uDD2C\uDD30-\uDD3D\uDD40-\uDD49\uDD4E\uDEC0-\uDEF9]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4B\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
  208. };
  209.  
  210. const Character = {
  211. fromCodePoint: e => (e < 65536 ? String.fromCharCode(e) : String.fromCharCode(55296 + (e - 65536 >> 10)) + String.fromCharCode(56320 + (e - 65536 & 1023))),
  212. isStringWellFormedUnicode(e) {
  213. for (let t = 0; t < e.length; t++) {
  214. let s = e.charCodeAt(t);
  215. if (s >= 55296 && s <= 56319) {
  216. if (t === e.length - 1) return !1;
  217. if (t++, s = e.charCodeAt(t), s < 56320 && s > 57343) return !1;
  218. } else if (s >= 56320 && s <= 57343) return !1;
  219. }
  220. return !0;
  221. },
  222. isWhiteSpace: e => e === 32 || e === 9 || e === 11 || e === 12 || e === 160 || e >= 5760 && [5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8239, 8287, 12288, 65279].indexOf(e) >= 0,
  223. isLineTerminator: e => e === 10 || e === 13 || e === 8232 || e === 8233,
  224. isIdentifierStart: e => e === 36 || e === 95 || e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 92 || e >= 128 && Regex.NonAsciiIdentifierStart.test(Character.fromCodePoint(e)),
  225. isIdentifierPart: e => e === 36 || e === 95 || e >= 65 && e <= 90 || e >= 97 && e <= 122 || e >= 48 && e <= 57 || e === 92 || e >= 128 && Regex.NonAsciiIdentifierPart.test(Character.fromCodePoint(e)),
  226. isDecimalDigit: e => e >= 48 && e <= 57,
  227. isDecimalDigitChar: e => e.length === 1 && Character.isDecimalDigit(e.charCodeAt(0)),
  228. isHexDigit: e => e >= 48 && e <= 57 || e >= 65 && e <= 70 || e >= 97 && e <= 102,
  229. isHexDigitChar: e => e.length === 1 && Character.isHexDigit(e.charCodeAt(0)),
  230. isOctalDigit: e => e >= 48 && e <= 55,
  231. isOctalDigitChar: e => e.length === 1 && Character.isOctalDigit(e.charCodeAt(0))
  232. };
  233.  
  234. class JSXClosingElement {
  235. type;
  236. name;
  237. constructor(e) {
  238. this.type = 'JSXClosingElement', this.name = e;
  239. }
  240. }
  241.  
  242. const JSXClosingFragment = class {
  243. type;
  244. constructor() {
  245. this.type = 'JSXClosingFragment';
  246. }
  247. };
  248.  
  249. const JSXElement = class {
  250. type;
  251. openingElement;
  252. children;
  253. closingElement;
  254. constructor(e, t, s) {
  255. this.type = 'JSXElement', this.openingElement = e, this.children = t, this.closingElement = s;
  256. }
  257. };
  258.  
  259. const JSXEmptyExpression = class {
  260. type;
  261. constructor() {
  262. this.type = 'JSXEmptyExpression';
  263. }
  264. };
  265.  
  266. const JSXExpressionContainer = class {
  267. type;
  268. expression;
  269. constructor(e) {
  270. this.type = 'JSXExpressionContainer', this.expression = e;
  271. }
  272. };
  273.  
  274. const JSXIdentifier = class {
  275. type;
  276. name;
  277. constructor(e) {
  278. this.type = 'JSXIdentifier', this.name = e;
  279. }
  280. };
  281.  
  282. const JSXMemberExpression = class {
  283. type;
  284. object;
  285. property;
  286. constructor(e, t) {
  287. this.type = 'JSXMemberExpression', this.object = e, this.property = t;
  288. }
  289. };
  290.  
  291. const JSXAttribute = class {
  292. type;
  293. name;
  294. value;
  295. constructor(e, t) {
  296. this.type = 'JSXAttribute', this.name = e, this.value = t;
  297. }
  298. };
  299.  
  300. const JSXNamespacedName = class {
  301. type;
  302. namespace;
  303. name;
  304. constructor(e, t) {
  305. this.type = 'JSXNamespacedName', this.namespace = e, this.name = t;
  306. }
  307. };
  308.  
  309. const JSXOpeningElement = class {
  310. type;
  311. name;
  312. selfClosing;
  313. attributes;
  314. constructor(e, t, s) {
  315. this.type = 'JSXOpeningElement', this.name = e, this.selfClosing = t, this.attributes = s;
  316. }
  317. };
  318.  
  319. const JSXOpeningFragment = class {
  320. type;
  321. selfClosing;
  322. constructor(e) {
  323. this.type = 'JSXOpeningFragment', this.selfClosing = e;
  324. }
  325. };
  326.  
  327. const JSXSpreadAttribute = class {
  328. type;
  329. argument;
  330. constructor(e) {
  331. this.type = 'JSXSpreadAttribute', this.argument = e;
  332. }
  333. };
  334.  
  335. const JSXText = class {
  336. type;
  337. value;
  338. raw;
  339. constructor(e, t) {
  340. this.type = 'JSXText', this.value = e, this.raw = t;
  341. }
  342. };
  343.  
  344. const ArrayExpression = class {
  345. type;
  346. elements;
  347. constructor(e) {
  348. this.type = 'ArrayExpression', this.elements = e;
  349. }
  350. };
  351.  
  352. const ArrayPattern = class {
  353. type;
  354. elements;
  355. constructor(e) {
  356. this.type = 'ArrayPattern', this.elements = e;
  357. }
  358. };
  359.  
  360. const ArrowFunctionExpression = class {
  361. type;
  362. id;
  363. params;
  364. body;
  365. generator;
  366. expression;
  367. async;
  368. constructor(e, t, s, i) {
  369. this.type = 'ArrowFunctionExpression', this.id = null, this.params = e, this.body = t, this.generator = !1, this.expression = s, this.async = i;
  370. }
  371. };
  372.  
  373. const AssignmentExpression = class {
  374. type;
  375. operator;
  376. left;
  377. right;
  378. constructor(e, t, s) {
  379. this.type = 'AssignmentExpression', this.operator = e, this.left = t, this.right = s;
  380. }
  381. };
  382.  
  383. const AssignmentPattern = class {
  384. type;
  385. left;
  386. right;
  387. constructor(e, t) {
  388. this.type = 'AssignmentPattern', this.left = e, this.right = t;
  389. }
  390. };
  391.  
  392. const AsyncFunctionDeclaration = class {
  393. type;
  394. id;
  395. params;
  396. body;
  397. generator;
  398. expression;
  399. async;
  400. constructor(e, t, s, i) {
  401. this.type = 'FunctionDeclaration', this.id = e, this.params = t, this.body = s, this.generator = i, this.expression = !1, this.async = !0;
  402. }
  403. };
  404.  
  405. const AwaitExpression = class {
  406. type;
  407. argument;
  408. constructor(e) {
  409. this.type = 'AwaitExpression', this.argument = e;
  410. }
  411. };
  412.  
  413. const BigIntLiteral = class {
  414. type;
  415. value;
  416. raw;
  417. bigint;
  418. constructor(e, t, s) {
  419. this.type = 'Literal', this.value = e, this.raw = t, this.bigint = s;
  420. }
  421. };
  422.  
  423. const BinaryExpression = class {
  424. type;
  425. operator;
  426. left;
  427. right;
  428. constructor(e, t, s) {
  429. this.type = 'BinaryExpression', this.operator = e, this.left = t, this.right = s;
  430. }
  431. };
  432. const BlockStatement = class {
  433. type;
  434. body;
  435. constructor(e) {
  436. this.type = 'BlockStatement', this.body = e;
  437. }
  438. };
  439. const BreakStatement = class {
  440. type;
  441. label;
  442. constructor(e) {
  443. this.type = 'BreakStatement', this.label = e;
  444. }
  445. };
  446. const CallExpression = class {
  447. type;
  448. callee;
  449. arguments;
  450. optional;
  451. constructor(e, t, s) {
  452. this.type = 'CallExpression', this.callee = e, this.arguments = t, this.optional = s;
  453. }
  454. };
  455. const CatchClause = class {
  456. type;
  457. param;
  458. body;
  459. constructor(e, t) {
  460. this.type = 'CatchClause', this.param = e, this.body = t;
  461. }
  462. };
  463. const ChainExpression = class {
  464. type;
  465. expression;
  466. constructor(e) {
  467. this.type = 'ChainExpression', this.expression = e;
  468. }
  469. };
  470. const ClassBody = class {
  471. type;
  472. body;
  473. constructor(e) {
  474. this.type = 'ClassBody', this.body = e;
  475. }
  476. };
  477. const ClassDeclaration = class {
  478. type;
  479. id;
  480. superClass;
  481. body;
  482. decorators;
  483. constructor(e, t, s, i) {
  484. this.type = 'ClassDeclaration', this.id = e, this.superClass = t, this.body = s, this.decorators = i;
  485. }
  486. };
  487. const ClassExpression = class {
  488. type;
  489. id;
  490. superClass;
  491. body;
  492. decorators;
  493. constructor(e, t, s, i) {
  494. this.type = 'ClassExpression', this.id = e, this.superClass = t, this.body = s, this.decorators = i;
  495. }
  496. };
  497. const ConditionalExpression = class {
  498. type;
  499. test;
  500. consequent;
  501. alternate;
  502. constructor(e, t, s) {
  503. this.type = 'ConditionalExpression', this.test = e, this.consequent = t, this.alternate = s;
  504. }
  505. };
  506. const ContinueStatement = class {
  507. type;
  508. label;
  509. constructor(e) {
  510. this.type = 'ContinueStatement', this.label = e;
  511. }
  512. };
  513. const DebuggerStatement = class {
  514. type;
  515. constructor() {
  516. this.type = 'DebuggerStatement';
  517. }
  518. };
  519. const Decorator = class {
  520. type;
  521. expression;
  522. constructor(e) {
  523. this.type = 'Decorator', this.expression = e;
  524. }
  525. };
  526. const Directive = class {
  527. type;
  528. expression;
  529. directive;
  530. constructor(e, t) {
  531. this.type = 'ExpressionStatement', this.expression = e, this.directive = t;
  532. }
  533. };
  534. const DoWhileStatement = class {
  535. type;
  536. body;
  537. test;
  538. constructor(e, t) {
  539. this.type = 'DoWhileStatement', this.body = e, this.test = t;
  540. }
  541. };
  542. const EmptyStatement = class {
  543. type;
  544. constructor() {
  545. this.type = 'EmptyStatement';
  546. }
  547. };
  548. const ExportAllDeclaration = class {
  549. type;
  550. source;
  551. exported;
  552. assertions;
  553. constructor(e, t, s) {
  554. this.type = 'ExportAllDeclaration', this.source = e, this.exported = t, this.assertions = s;
  555. }
  556. };
  557. const ExportDefaultDeclaration = class {
  558. type;
  559. declaration;
  560. constructor(e) {
  561. this.type = 'ExportDefaultDeclaration', this.declaration = e;
  562. }
  563. };
  564. const ExportNamedDeclaration = class {
  565. type;
  566. declaration;
  567. specifiers;
  568. source;
  569. assertions;
  570. constructor(e, t, s, i) {
  571. this.type = 'ExportNamedDeclaration', this.declaration = e, this.specifiers = t, this.source = s, this.assertions = i;
  572. }
  573. };
  574. const ExportSpecifier = class {
  575. type;
  576. exported;
  577. local;
  578. constructor(e, t) {
  579. this.type = 'ExportSpecifier', this.exported = t, this.local = e;
  580. }
  581. };
  582. const ExpressionStatement = class {
  583. type;
  584. expression;
  585. constructor(e) {
  586. this.type = 'ExpressionStatement', this.expression = e;
  587. }
  588. };
  589. const ForInStatement = class {
  590. type;
  591. left;
  592. right;
  593. body;
  594. each;
  595. constructor(e, t, s) {
  596. this.type = 'ForInStatement', this.left = e, this.right = t, this.body = s, this.each = !1;
  597. }
  598. };
  599. const ForOfStatement = class {
  600. type;
  601. await;
  602. left;
  603. right;
  604. body;
  605. constructor(e, t, s, i) {
  606. this.type = 'ForOfStatement', this.await = i, this.left = e, this.right = t, this.body = s;
  607. }
  608. };
  609. const ForStatement = class {
  610. type;
  611. init;
  612. test;
  613. update;
  614. body;
  615. constructor(e, t, s, i) {
  616. this.type = 'ForStatement', this.init = e, this.test = t, this.update = s, this.body = i;
  617. }
  618. };
  619. const FunctionDeclaration = class {
  620. type;
  621. id;
  622. params;
  623. body;
  624. generator;
  625. expression;
  626. async;
  627. constructor(e, t, s, i) {
  628. this.type = 'FunctionDeclaration', this.id = e, this.params = t, this.body = s, this.generator = i, this.expression = !1, this.async = !1;
  629. }
  630. };
  631. const FunctionExpression = class {
  632. type;
  633. id;
  634. params;
  635. body;
  636. generator;
  637. expression;
  638. async;
  639. constructor(e, t, s, i, r) {
  640. this.type = 'FunctionExpression', this.id = e, this.params = t, this.body = s, this.generator = i, this.expression = !1, this.async = r;
  641. }
  642. };
  643. const Identifier = class {
  644. type;
  645. name;
  646. constructor(e) {
  647. this.type = 'Identifier', this.name = e;
  648. }
  649. };
  650. const IfStatement = class {
  651. type;
  652. test;
  653. consequent;
  654. alternate;
  655. constructor(e, t, s) {
  656. this.type = 'IfStatement', this.test = e, this.consequent = t, this.alternate = s;
  657. }
  658. };
  659. const ImportAttribute = class {
  660. type;
  661. key;
  662. value;
  663. constructor(e, t) {
  664. this.type = 'ImportAttribute', this.key = e, this.value = t;
  665. }
  666. };
  667. const ImportExpression = class {
  668. type;
  669. source;
  670. attributes;
  671. constructor(e, t) {
  672. this.type = 'ImportExpression', this.source = e, this.attributes = t;
  673. }
  674. };
  675. const ImportDeclaration = class {
  676. type;
  677. specifiers;
  678. source;
  679. assertions;
  680. constructor(e, t, s) {
  681. this.type = 'ImportDeclaration', this.specifiers = e, this.source = t, this.assertions = s;
  682. }
  683. };
  684. const ImportDefaultSpecifier = class {
  685. type;
  686. local;
  687. constructor(e) {
  688. this.type = 'ImportDefaultSpecifier', this.local = e;
  689. }
  690. };
  691. const ImportNamespaceSpecifier = class {
  692. type;
  693. local;
  694. constructor(e) {
  695. this.type = 'ImportNamespaceSpecifier', this.local = e;
  696. }
  697. };
  698. const ImportSpecifier = class {
  699. type;
  700. local;
  701. imported;
  702. constructor(e, t) {
  703. this.type = 'ImportSpecifier', this.local = e, this.imported = t;
  704. }
  705. };
  706. const LabeledStatement = class {
  707. type;
  708. label;
  709. body;
  710. constructor(e, t) {
  711. this.type = 'LabeledStatement', this.label = e, this.body = t;
  712. }
  713. };
  714. const Literal = class {
  715. type;
  716. value;
  717. raw;
  718. constructor(e, t) {
  719. this.type = 'Literal', this.value = e, this.raw = t;
  720. }
  721. };
  722. const LogicalExpression = class {
  723. type;
  724. operator;
  725. left;
  726. right;
  727. constructor(e, t, s) {
  728. this.type = 'LogicalExpression', this.operator = e, this.left = t, this.right = s;
  729. }
  730. };
  731. const MemberExpression = class {
  732. type;
  733. computed;
  734. object;
  735. property;
  736. optional;
  737. constructor(e, t, s, i) {
  738. this.type = 'MemberExpression', this.computed = e, this.object = t, this.property = s, this.optional = i;
  739. }
  740. };
  741. const MetaProperty = class {
  742. type;
  743. meta;
  744. property;
  745. constructor(e, t) {
  746. this.type = 'MetaProperty', this.meta = e, this.property = t;
  747. }
  748. };
  749. const MethodDefinition = class {
  750. type;
  751. key;
  752. computed;
  753. value;
  754. kind;
  755. static;
  756. decorators;
  757. constructor(e, t, s, i, r, n) {
  758. this.type = 'MethodDefinition', this.key = e, this.computed = t, this.value = s, this.kind = i, this.static = r, this.decorators = n;
  759. }
  760. };
  761. const Module = class {
  762. type;
  763. body;
  764. sourceType;
  765. constructor(e) {
  766. this.type = 'Program', this.body = e, this.sourceType = 'module';
  767. }
  768. };
  769. const NewExpression = class {
  770. type;
  771. callee;
  772. arguments;
  773. constructor(e, t) {
  774. this.type = 'NewExpression', this.callee = e, this.arguments = t;
  775. }
  776. };
  777. const ObjectExpression = class {
  778. type;
  779. properties;
  780. constructor(e) {
  781. this.type = 'ObjectExpression', this.properties = e;
  782. }
  783. };
  784. const ObjectPattern = class {
  785. type;
  786. properties;
  787. constructor(e) {
  788. this.type = 'ObjectPattern', this.properties = e;
  789. }
  790. };
  791. const PrivateIdentifier = class {
  792. type;
  793. name;
  794. constructor(e) {
  795. this.type = 'PrivateIdentifier', this.name = e;
  796. }
  797. };
  798. const Program = class {
  799. type;
  800. body;
  801. sourceType;
  802. constructor(e, t) {
  803. this.type = 'Program', this.sourceType = e, this.body = t;
  804. }
  805. };
  806. const Property = class {
  807. type;
  808. key;
  809. computed;
  810. value;
  811. kind;
  812. method;
  813. shorthand;
  814. constructor(e, t, s, i, r, n) {
  815. this.type = 'Property', this.key = t, this.computed = s, this.value = i, this.kind = e, this.method = r, this.shorthand = n;
  816. }
  817. };
  818. const PropertyDefinition = class {
  819. type;
  820. key;
  821. computed;
  822. value;
  823. static;
  824. decorators;
  825. constructor(e, t, s, i, r) {
  826. this.type = 'Property', this.key = e, this.computed = t, this.value = s, this.static = i, this.decorators = r;
  827. }
  828. };
  829. const RegexLiteral = class {
  830. type;
  831. value;
  832. raw;
  833. regex;
  834. constructor(e, t, s, i) {
  835. this.type = 'Literal', this.value = e, this.raw = t, this.regex = {
  836. pattern: s,
  837. flags: i
  838. };
  839. }
  840. };
  841. const RestElement = class {
  842. type;
  843. argument;
  844. constructor(e) {
  845. this.type = 'RestElement', this.argument = e;
  846. }
  847. };
  848. const ReturnStatement = class {
  849. type;
  850. argument;
  851. constructor(e) {
  852. this.type = 'ReturnStatement', this.argument = e;
  853. }
  854. };
  855. const Script = class {
  856. type;
  857. body;
  858. sourceType;
  859. constructor(e) {
  860. this.type = 'Program', this.body = e, this.sourceType = 'script';
  861. }
  862. };
  863. const SequenceExpression = class {
  864. type;
  865. expressions;
  866. constructor(e) {
  867. this.type = 'SequenceExpression', this.expressions = e;
  868. }
  869. };
  870. const SpreadElement = class {
  871. type;
  872. argument;
  873. constructor(e) {
  874. this.type = 'SpreadElement', this.argument = e;
  875. }
  876. };
  877. const StaticBlock = class {
  878. type;
  879. body;
  880. constructor(e) {
  881. this.type = 'StaticBlock', this.body = e;
  882. }
  883. };
  884. const Super = class {
  885. type;
  886. constructor() {
  887. this.type = 'Super';
  888. }
  889. };
  890. const SwitchCase = class {
  891. type;
  892. test;
  893. consequent;
  894. constructor(e, t) {
  895. this.type = 'SwitchCase', this.test = e, this.consequent = t;
  896. }
  897. };
  898. const SwitchStatement = class {
  899. type;
  900. discriminant;
  901. cases;
  902. constructor(e, t) {
  903. this.type = 'SwitchStatement', this.discriminant = e, this.cases = t;
  904. }
  905. };
  906. const TaggedTemplateExpression = class {
  907. type;
  908. tag;
  909. quasi;
  910. constructor(e, t) {
  911. this.type = 'TaggedTemplateExpression', this.tag = e, this.quasi = t;
  912. }
  913. };
  914. const TemplateElement = class {
  915. type;
  916. value;
  917. tail;
  918. constructor(e, t) {
  919. this.type = 'TemplateElement', this.value = e, this.tail = t;
  920. }
  921. };
  922. const TemplateLiteral = class {
  923. type;
  924. quasis;
  925. expressions;
  926. constructor(e, t) {
  927. this.type = 'TemplateLiteral', this.quasis = e, this.expressions = t;
  928. }
  929. };
  930. const ThisExpression = class {
  931. type;
  932. constructor() {
  933. this.type = 'ThisExpression';
  934. }
  935. };
  936. const ThrowStatement = class {
  937. type;
  938. argument;
  939. constructor(e) {
  940. this.type = 'ThrowStatement', this.argument = e;
  941. }
  942. };
  943. const TryStatement = class {
  944. type;
  945. block;
  946. handler;
  947. finalizer;
  948. constructor(e, t, s) {
  949. this.type = 'TryStatement', this.block = e, this.handler = t, this.finalizer = s;
  950. }
  951. };
  952. const UnaryExpression = class {
  953. type;
  954. operator;
  955. argument;
  956. prefix;
  957. constructor(e, t) {
  958. this.type = 'UnaryExpression', this.operator = e, this.argument = t, this.prefix = !0;
  959. }
  960. };
  961. const UpdateExpression = class {
  962. type;
  963. operator;
  964. argument;
  965. prefix;
  966. constructor(e, t, s) {
  967. this.type = 'UpdateExpression', this.operator = e, this.argument = t, this.prefix = s;
  968. }
  969. };
  970. const VariableDeclaration = class {
  971. type;
  972. declarations;
  973. kind;
  974. constructor(e, t) {
  975. this.type = 'VariableDeclaration', this.declarations = e, this.kind = t;
  976. }
  977. };
  978. const VariableDeclarator = class {
  979. type;
  980. id;
  981. init;
  982. constructor(e, t) {
  983. this.type = 'VariableDeclarator', this.id = e, this.init = t;
  984. }
  985. };
  986. const WhileStatement = class {
  987. type;
  988. test;
  989. body;
  990. constructor(e, t) {
  991. this.type = 'WhileStatement', this.test = e, this.body = t;
  992. }
  993. };
  994. const WithStatement = class {
  995. type;
  996. object;
  997. body;
  998. constructor(e, t) {
  999. this.type = 'WithStatement', this.object = e, this.body = t;
  1000. }
  1001. };
  1002. const YieldExpression = class {
  1003. type;
  1004. argument;
  1005. delegate;
  1006. constructor(e, t) {
  1007. this.type = 'YieldExpression', this.argument = e, this.delegate = t;
  1008. }
  1009. };
  1010.  
  1011. function assert(e, t) {
  1012. if (!e) throw new Error(`ASSERT: ${t}`);
  1013. }
  1014. const ErrorHandler = class {
  1015. errors;
  1016. tolerant;
  1017. constructor() {
  1018. this.errors = [], this.tolerant = !1;
  1019. }
  1020.  
  1021. recordError(e) {
  1022. this.errors.push(e);
  1023. }
  1024.  
  1025. tolerate(e) {
  1026. if (!this.tolerant) throw e;
  1027. this.recordError(e);
  1028. }
  1029.  
  1030. constructError(e, t) {
  1031. let s = new Error(e);
  1032. try {
  1033. throw s;
  1034. } catch (e) {
  1035. Object.create && Object.defineProperty && (s = Object.create(e), Object.defineProperty(s, 'column', {
  1036. value: t
  1037. }));
  1038. }
  1039. return s;
  1040. }
  1041.  
  1042. createError(e, t, s, i) {
  1043. const r = `Line ${t}: ${i}`;
  1044. const n = this.constructError(r, s);
  1045. n.index = e, n.lineNumber = t, n.description = i;
  1046. return n;
  1047. }
  1048.  
  1049. throwError(e, t, s, i) {
  1050. throw this.createError(e, t, s, i);
  1051. }
  1052.  
  1053. tolerateError(e, t, s, i) {
  1054. const r = this.createError(e, t, s, i);
  1055. if (!this.tolerant) throw r;
  1056. this.recordError(r);
  1057. }
  1058. };
  1059. const Messages = {
  1060. AsyncFunctionInSingleStatementContext: 'Async functions can only be declared at the top level or inside a block.',
  1061. BadImportCallArity: 'Unexpected token',
  1062. BadGetterArity: 'Getter must not have any formal parameters',
  1063. BadSetterArity: 'Setter must have exactly one formal parameter',
  1064. BadSetterRestParameter: 'Setter function argument must not be a rest parameter',
  1065. CannotUseImportMetaOutsideAModule: "Cannot use 'import.meta' outside a module",
  1066. ConstructorIsAsync: 'Class constructor may not be an async method',
  1067. ConstructorIsPrivate: 'Class constructor may not be a private method',
  1068. ConstructorSpecialMethod: 'Class constructor may not be an accessor',
  1069. DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
  1070. DefaultRestParameter: 'Unexpected token =',
  1071. DefaultRestProperty: 'Unexpected token =',
  1072. DuplicateBinding: 'Duplicate binding %0',
  1073. DuplicateConstructor: 'A class may only have one constructor',
  1074. DuplicateParameter: 'Duplicate parameter name not allowed in this context',
  1075. DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
  1076. ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer',
  1077. GeneratorInLegacyContext: 'Generator declarations are not allowed in legacy contexts',
  1078. IllegalBreak: 'Illegal break statement',
  1079. IllegalContinue: 'Illegal continue statement',
  1080. IllegalExportDeclaration: 'Unexpected token',
  1081. IllegalImportDeclaration: 'Unexpected token',
  1082. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list",
  1083. IllegalReturn: 'Illegal return statement',
  1084. InvalidEscapedReservedWord: 'Keyword must not contain escaped characters',
  1085. InvalidHexEscapeSequence: 'Invalid hexadecimal escape sequence',
  1086. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  1087. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  1088. InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
  1089. InvalidModuleSpecifier: 'Unexpected token',
  1090. InvalidRegExp: 'Invalid regular expression',
  1091. InvalidTaggedTemplateOnOptionalChain: 'Invalid tagged template on optional chain',
  1092. InvalidUnicodeEscapeSequence: 'Invalid Unicode escape sequence',
  1093. LetInLexicalBinding: 'let is disallowed as a lexically bound name',
  1094. MissingFromClause: 'Unexpected token',
  1095. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  1096. NewlineAfterThrow: 'Illegal newline after throw',
  1097. NoAsAfterImportNamespace: 'Unexpected token',
  1098. NoAsAndFromEscapeSequences: 'The `as` and `from` contextual keywords must not contain Unicode escape sequences.',
  1099. NoCatchOrFinally: 'Missing catch or finally after try',
  1100. NoSemicolonAfterDecorator: 'Decorators must not be followed by a semicolon.',
  1101. NumericSeperatorOneUnderscore: 'Numeric separator must be exactly one underscore',
  1102. NumericSeperatorNotAllowedHere: 'Numeric separator is not allowed here',
  1103. ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
  1104. PropertyAfterRestProperty: 'Unexpected token',
  1105. Redeclaration: "%0 '%1' has already been declared",
  1106. StaticPrototype: 'Classes may not have static property named prototype',
  1107. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  1108. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  1109. StrictFunction: 'In strict mode code, functions can only be declared at top level or inside a block',
  1110. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  1111. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  1112. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  1113. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  1114. StrictModeWith: 'Strict mode code may not include a with statement',
  1115. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  1116. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  1117. StrictReservedWord: 'Use of future reserved word in strict mode',
  1118. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  1119. TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
  1120. TemplateEscape89: '\\8 and \\9 are not allowed in template strings.',
  1121. UnexpectedEOS: 'Unexpected end of input',
  1122. UnexpectedIdentifier: 'Unexpected identifier',
  1123. UnexpectedNumber: 'Unexpected number',
  1124. UnexpectedReserved: 'Unexpected reserved word',
  1125. UnexpectedString: 'Unexpected string',
  1126. UnexpectedSuper: "'super' keyword unexpected here",
  1127. UnexpectedTemplate: 'Unexpected quasi %0',
  1128. UnexpectedToken: 'Unexpected token %0',
  1129. UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
  1130. UnknownLabel: "Undefined label '%0'",
  1131. UnterminatedRegExp: 'Invalid regular expression: missing /'
  1132. };
  1133. const TokenName = {};
  1134.  
  1135. function hexValue(e) {
  1136. return '0123456789abcdef'.indexOf(e.toLowerCase());
  1137. }
  1138.  
  1139. function octalValue(e) {
  1140. return '01234567'.indexOf(e);
  1141. }
  1142. TokenName[1] = 'Boolean', TokenName[2] = '<end>', TokenName[3] = 'Identifier', TokenName[4] = 'Keyword', TokenName[5] = 'Null', TokenName[6] = 'Numeric', TokenName[7] = 'Punctuator', TokenName[8] = 'String', TokenName[9] = 'RegularExpression', TokenName[10] = 'Template';
  1143. const Scanner = class {
  1144. source;
  1145. errorHandler;
  1146. trackComment;
  1147. isModule;
  1148. index;
  1149. lineNumber;
  1150. lineStart;
  1151. curlyStack;
  1152. length;
  1153. constructor(e, t) {
  1154. this.source = e, this.errorHandler = t, this.trackComment = !1, this.isModule = !1, this.length = e.length, this.index = 0, this.lineNumber = e.length > 0 ? 1 : 0, this.lineStart = 0, this.curlyStack = [];
  1155. }
  1156.  
  1157. saveState() {
  1158. return {
  1159. index: this.index,
  1160. lineNumber: this.lineNumber,
  1161. lineStart: this.lineStart,
  1162. curlyStack: this.curlyStack.slice()
  1163. };
  1164. }
  1165.  
  1166. restoreState(e) {
  1167. this.index = e.index, this.lineNumber = e.lineNumber, this.lineStart = e.lineStart, this.curlyStack = e.curlyStack;
  1168. }
  1169.  
  1170. eof() {
  1171. return this.index >= this.length;
  1172. }
  1173.  
  1174. throwUnexpectedToken(e = Messages.UnexpectedTokenIllegal) {
  1175. return this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, e);
  1176. }
  1177.  
  1178. tolerateUnexpectedToken(e = Messages.UnexpectedTokenIllegal) {
  1179. this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, e);
  1180. }
  1181.  
  1182. skipSingleLineComment(e) {
  1183. let t; let s; let
  1184. i = [];
  1185. for (this.trackComment && (i = [], t = this.index - e, s = {
  1186. start: {
  1187. line: this.lineNumber,
  1188. column: this.index - this.lineStart - e
  1189. },
  1190. end: {}
  1191. }); !this.eof();) {
  1192. const r = this.source.charCodeAt(this.index);
  1193. if (++this.index, Character.isLineTerminator(r)) {
  1194. if (this.trackComment) {
  1195. s.end = {
  1196. line: this.lineNumber,
  1197. column: this.index - this.lineStart - 1
  1198. };
  1199. const r = {
  1200. multiLine: !1,
  1201. slice: [t + e, this.index - 1],
  1202. range: [t, this.index - 1],
  1203. loc: s
  1204. };
  1205. i.push(r);
  1206. }
  1207. return r === 13 && this.source.charCodeAt(this.index) === 10 && ++this.index, ++this.lineNumber, this.lineStart = this.index, i;
  1208. }
  1209. }
  1210. if (this.trackComment) {
  1211. s.end = {
  1212. line: this.lineNumber,
  1213. column: this.index - this.lineStart
  1214. };
  1215. const r = {
  1216. multiLine: !1,
  1217. slice: [t + e, this.index],
  1218. range: [t, this.index],
  1219. loc: s
  1220. };
  1221. i.push(r);
  1222. }
  1223. return i;
  1224. }
  1225.  
  1226. skipMultiLineComment() {
  1227. let e; let t; let
  1228. s = [];
  1229. for (this.trackComment && (s = [], e = this.index - 2, t = {
  1230. start: {
  1231. line: this.lineNumber,
  1232. column: this.index - this.lineStart - 2
  1233. },
  1234. end: {}
  1235. }); !this.eof();) {
  1236. const i = this.source.charCodeAt(this.index);
  1237. if (Character.isLineTerminator(i)) i === 13 && this.source.charCodeAt(this.index + 1) === 10 && ++this.index, ++this.lineNumber, ++this.index, this.lineStart = this.index;
  1238. else if (i === 42) {
  1239. if (this.source.charCodeAt(this.index + 1) === 47) {
  1240. if (this.index += 2, this.trackComment) {
  1241. t.end = {
  1242. line: this.lineNumber,
  1243. column: this.index - this.lineStart
  1244. };
  1245. const i = {
  1246. multiLine: !0,
  1247. slice: [e + 2, this.index - 2],
  1248. range: [e, this.index],
  1249. loc: t
  1250. };
  1251. s.push(i);
  1252. }
  1253. return s;
  1254. }++this.index;
  1255. } else ++this.index;
  1256. }
  1257. if (this.trackComment) {
  1258. t.end = {
  1259. line: this.lineNumber,
  1260. column: this.index - this.lineStart
  1261. };
  1262. const i = {
  1263. multiLine: !0,
  1264. slice: [e + 2, this.index],
  1265. range: [e, this.index],
  1266. loc: t
  1267. };
  1268. s.push(i);
  1269. }
  1270. return this.tolerateUnexpectedToken(), s;
  1271. }
  1272.  
  1273. scanComments() {
  1274. let e;
  1275. this.trackComment && (e = []);
  1276. let t = this.index === 0;
  1277. for (; !this.eof();) {
  1278. let s = this.source.charCodeAt(this.index);
  1279. if (Character.isWhiteSpace(s)) ++this.index;
  1280. else if (Character.isLineTerminator(s)) ++this.index, s === 13 && this.source.charCodeAt(this.index) === 10 && ++this.index, ++this.lineNumber, this.lineStart = this.index, t = !0;
  1281. else if (s === 47) {
  1282. if (s = this.source.charCodeAt(this.index + 1), s === 47) {
  1283. this.index += 2;
  1284. const s = this.skipSingleLineComment(2);
  1285. this.trackComment && (e = e.concat(s)), t = !0;
  1286. } else {
  1287. if (s !== 42) break;
  1288. {
  1289. this.index += 2;
  1290. const t = this.skipMultiLineComment();
  1291. this.trackComment && (e = e.concat(t));
  1292. }
  1293. }
  1294. } else if (t && s === 45) {
  1295. if (this.source.charCodeAt(this.index + 1) !== 45 || this.source.charCodeAt(this.index + 2) !== 62) break;
  1296. {
  1297. this.index += 3;
  1298. const t = this.skipSingleLineComment(3);
  1299. this.trackComment && (e = e.concat(t));
  1300. }
  1301. } else {
  1302. if (s !== 60 || this.isModule) break;
  1303. if (this.source.slice(this.index + 1, this.index + 4) !== '!--') break;
  1304. {
  1305. this.index += 4;
  1306. const t = this.skipSingleLineComment(4);
  1307. this.trackComment && (e = e.concat(t));
  1308. }
  1309. }
  1310. }
  1311. return e;
  1312. }
  1313.  
  1314. isFutureReservedWord(e) {
  1315. switch (e) {
  1316. case 'enum':
  1317. case 'export':
  1318. case 'import':
  1319. case 'super':
  1320. return !0;
  1321. default:
  1322. return !1;
  1323. }
  1324. }
  1325.  
  1326. isStrictModeReservedWord(e) {
  1327. switch (e) {
  1328. case 'implements':
  1329. case 'interface':
  1330. case 'package':
  1331. case 'private':
  1332. case 'protected':
  1333. case 'public':
  1334. case 'static':
  1335. case 'yield':
  1336. case 'let':
  1337. return !0;
  1338. default:
  1339. return !1;
  1340. }
  1341. }
  1342.  
  1343. isRestrictedWord(e) {
  1344. return e === 'eval' || e === 'arguments';
  1345. }
  1346.  
  1347. isKeyword(e) {
  1348. switch (e.length) {
  1349. case 2:
  1350. return e === 'if' || e === 'in' || e === 'do';
  1351. case 3:
  1352. return e === 'var' || e === 'for' || e === 'new' || e === 'try' || e === 'let';
  1353. case 4:
  1354. return e === 'this' || e === 'else' || e === 'case' || e === 'void' || e === 'with' || e === 'enum';
  1355. case 5:
  1356. return e === 'while' || e === 'break' || e === 'catch' || e === 'throw' || e === 'const' || e === 'yield' || e === 'class' || e === 'super';
  1357. case 6:
  1358. return e === 'return' || e === 'typeof' || e === 'delete' || e === 'switch' || e === 'export' || e === 'import';
  1359. case 7:
  1360. return e === 'default' || e === 'finally' || e === 'extends';
  1361. case 8:
  1362. return e === 'function' || e === 'continue' || e === 'debugger';
  1363. case 10:
  1364. return e === 'instanceof';
  1365. default:
  1366. return !1;
  1367. }
  1368. }
  1369.  
  1370. codePointAt(e) {
  1371. let t = this.source.charCodeAt(e);
  1372. if (t >= 55296 && t <= 56319) {
  1373. const s = this.source.charCodeAt(e + 1);
  1374. if (s >= 56320 && s <= 57343) {
  1375. t = 1024 * (t - 55296) + s - 56320 + 65536;
  1376. }
  1377. }
  1378. return t;
  1379. }
  1380.  
  1381. scanHexEscape(e) {
  1382. const t = e === 'u' ? 4 : 2;
  1383. let s = 0;
  1384. for (let e = 0; e < t; ++e) {
  1385. if (this.eof() || !Character.isHexDigit(this.source.charCodeAt(this.index))) return null;
  1386. s = 16 * s + hexValue(this.source[this.index++]);
  1387. }
  1388. return String.fromCharCode(s);
  1389. }
  1390.  
  1391. tryToScanUnicodeCodePointEscape() {
  1392. let e = this.source[this.index];
  1393. let t = 0;
  1394. if (e === '}') return null;
  1395. for (; !this.eof() && (e = this.source[this.index++], Character.isHexDigit(e.charCodeAt(0)));) t = 16 * t + hexValue(e);
  1396. return t > 1114111 || e !== '}' ? null : Character.fromCodePoint(t);
  1397. }
  1398.  
  1399. scanUnicodeCodePointEscape() {
  1400. const e = this.tryToScanUnicodeCodePointEscape();
  1401. return e === null ? this.throwUnexpectedToken() : e;
  1402. }
  1403.  
  1404. getIdentifier() {
  1405. const e = this.index++;
  1406. for (; !this.eof();) {
  1407. const t = this.source.charCodeAt(this.index);
  1408. if (t === 92) return this.index = e, this.getComplexIdentifier();
  1409. if (t >= 55296 && t < 57343) return this.index = e, this.getComplexIdentifier();
  1410. if (!Character.isIdentifierPart(t)) break;
  1411. ++this.index;
  1412. }
  1413. return this.source.slice(e, this.index);
  1414. }
  1415.  
  1416. getComplexIdentifier() {
  1417. let e; let t = this.codePointAt(this.index);
  1418. let s = Character.fromCodePoint(t);
  1419. for (this.index += s.length, t === 92 && (this.source.charCodeAt(this.index) !== 117 && this.throwUnexpectedToken(), ++this.index, this.source[this.index] === '{' ? (++this.index, e = this.scanUnicodeCodePointEscape()) : (e = this.scanHexEscape('u'), e !== null && e !== '\\' && Character.isIdentifierStart(e.charCodeAt(0)) || this.throwUnexpectedToken()), s = e); !this.eof() && (t = this.codePointAt(this.index), Character.isIdentifierPart(t));) e = Character.fromCodePoint(t), s += e, this.index += e.length, t === 92 && (s = s.substr(0, s.length - 1), this.source.charCodeAt(this.index) !== 117 && this.throwUnexpectedToken(), ++this.index, this.source[this.index] === '{' ? (++this.index, e = this.scanUnicodeCodePointEscape()) : (e = this.scanHexEscape('u'), e !== null && e !== '\\' && Character.isIdentifierPart(e.charCodeAt(0)) || this.throwUnexpectedToken()), s += e);
  1420. return s;
  1421. }
  1422.  
  1423. octalToDecimal(e) {
  1424. let t = e !== '0';
  1425. let s = octalValue(e);
  1426. return !this.eof() && Character.isOctalDigit(this.source.charCodeAt(this.index)) && (t = !0, s = 8 * s + octalValue(this.source[this.index++]), '0123'.indexOf(e) >= 0 && !this.eof() && Character.isOctalDigit(this.source.charCodeAt(this.index)) && (s = 8 * s + octalValue(this.source[this.index++]))), {
  1427. code: s,
  1428. octal: t
  1429. };
  1430. }
  1431.  
  1432. scanIdentifier() {
  1433. let e;
  1434. const t = this.index;
  1435. const s = this.source.charCodeAt(t) === 92;
  1436. const i = s ? this.getComplexIdentifier() : this.getIdentifier();
  1437. if (e = i.length === 1 ? 3 : this.isKeyword(i) ? 4 : i === 'null' ? 5 : i === 'true' || i === 'false' ? 1 : 3, e !== 3 && t + i.length !== this.index) {
  1438. const e = this.index;
  1439. this.index = t, this.tolerateUnexpectedToken(Messages.InvalidEscapedReservedWord), this.index = e;
  1440. }
  1441. return {
  1442. type: e,
  1443. value: i,
  1444. lineNumber: this.lineNumber,
  1445. lineStart: this.lineStart,
  1446. start: t,
  1447. end: this.index,
  1448. escaped: s
  1449. };
  1450. }
  1451.  
  1452. scanPunctuator() {
  1453. const e = this.index;
  1454. let t = this.source[this.index];
  1455. switch (t) {
  1456. case '(':
  1457. case '{':
  1458. t === '{' && this.curlyStack.push('{'), ++this.index;
  1459. break;
  1460. case '.':
  1461. ++this.index, this.source[this.index] === '.' && this.source[this.index + 1] === '.' && (this.index += 2, t = '...');
  1462. break;
  1463. case '}':
  1464. ++this.index, this.curlyStack.pop();
  1465. break;
  1466. case '?':
  1467. ++this.index, this.source[this.index] === '?' && (++this.index, this.source[this.index] === '=' ? (++this.index, t = '??=') : t = '??'), this.source[this.index] !== '.' || /^\d$/.test(this.source[this.index + 1]) || (++this.index, t = '?.');
  1468. break;
  1469. case '#':
  1470. case ')':
  1471. case ';':
  1472. case ',':
  1473. case '[':
  1474. case ']':
  1475. case ':':
  1476. case '~':
  1477. case '@':
  1478. ++this.index;
  1479. break;
  1480. default:
  1481. t = this.source.substr(this.index, 4), t === '>>>=' ? this.index += 4 : (t = t.substr(0, 3), t === '===' || t === '!==' || t === '>>>' || t === '<<=' || t === '>>=' || t === '**=' || t === '&&=' || t === '||=' ? this.index += 3 : (t = t.substr(0, 2), t === '&&' || t === '||' || t === '==' || t === '!=' || t === '+=' || t === '-=' || t === '*=' || t === '/=' || t === '++' || t === '--' || t === '<<' || t === '>>' || t === '&=' || t === '|=' || t === '^=' || t === '%=' || t === '<=' || t === '>=' || t === '=>' || t === '**' ? this.index += 2 : (t = this.source[this.index], '<>=!+-*%&|^/'.indexOf(t) >= 0 && ++this.index)));
  1482. }
  1483. return this.index === e && this.throwUnexpectedToken(), {
  1484. type: 7,
  1485. value: t,
  1486. lineNumber: this.lineNumber,
  1487. lineStart: this.lineStart,
  1488. start: e,
  1489. end: this.index
  1490. };
  1491. }
  1492.  
  1493. scanHexLiteral(e) {
  1494. const t = this.scanLiteralPart(Character.isHexDigitChar);
  1495. return t.length === 0 && this.throwUnexpectedToken(), this.source[this.index] === 'n' ? (this.index++, {
  1496. type: 6,
  1497. value: BigInt(`0x${t}`),
  1498. lineNumber: this.lineNumber,
  1499. lineStart: this.lineStart,
  1500. start: e,
  1501. end: this.index
  1502. }) : (Character.isIdentifierStart(this.source.charCodeAt(this.index)) && this.throwUnexpectedToken(), {
  1503. type: 6,
  1504. value: parseInt(`0x${t}`, 16),
  1505. lineNumber: this.lineNumber,
  1506. lineStart: this.lineStart,
  1507. start: e,
  1508. end: this.index
  1509. });
  1510. }
  1511.  
  1512. scanBinaryLiteral(e) {
  1513. let t; const
  1514. s = this.scanLiteralPart((e => e === '0' || e === '1'));
  1515. return s.length === 0 && this.throwUnexpectedToken(), this.source[this.index] === 'n' ? (this.index++, {
  1516. type: 6,
  1517. value: BigInt(`0b${s}`),
  1518. lineNumber: this.lineNumber,
  1519. lineStart: this.lineStart,
  1520. start: e,
  1521. end: this.index
  1522. }) : (this.eof() || (t = this.source.charCodeAt(this.index), (Character.isIdentifierStart(t) || Character.isDecimalDigit(t)) && this.throwUnexpectedToken()), {
  1523. type: 6,
  1524. value: parseInt(s, 2),
  1525. lineNumber: this.lineNumber,
  1526. lineStart: this.lineStart,
  1527. start: e,
  1528. end: this.index
  1529. });
  1530. }
  1531.  
  1532. scanOctalLiteral(e, t) {
  1533. let s = '';
  1534. let i = !1;
  1535. return Character.isOctalDigit(e.charCodeAt(0)) ? (i = !0, s = `0${this.source[this.index++]}`) : ++this.index, s += this.scanLiteralPart(Character.isOctalDigitChar), i || s.length !== 0 || this.throwUnexpectedToken(), this.source[this.index] === 'n' ? (this.index++, {
  1536. type: 6,
  1537. value: BigInt(`0o${s}`),
  1538. lineNumber: this.lineNumber,
  1539. lineStart: this.lineStart,
  1540. start: t,
  1541. end: this.index
  1542. }) : ((Character.isIdentifierStart(this.source.charCodeAt(this.index)) || Character.isDecimalDigit(this.source.charCodeAt(this.index))) && this.throwUnexpectedToken(), {
  1543. type: 6,
  1544. value: parseInt(s, 8),
  1545. octal: i,
  1546. lineNumber: this.lineNumber,
  1547. lineStart: this.lineStart,
  1548. start: t,
  1549. end: this.index
  1550. });
  1551. }
  1552.  
  1553. isImplicitOctalLiteral() {
  1554. for (let e = this.index + 1; e < this.length; ++e) {
  1555. const t = this.source[e];
  1556. if (t === '8' || t === '9' || t === 'n') return !1;
  1557. if (!Character.isOctalDigit(t.charCodeAt(0))) return !0;
  1558. }
  1559. return !0;
  1560. }
  1561.  
  1562. scanLiteralPart(e) {
  1563. let t = '';
  1564. for (this.source[this.index] === '_' && this.throwUnexpectedToken(Messages.NumericSeperatorNotAllowedHere); this.source[this.index] && (e(this.source[this.index]) || this.source[this.index] === '_');) this.source[this.index] !== '_' && (t += this.source[this.index]), this.index++, this.source[this.index - 1] === '_' && this.source[this.index] === '_' && this.throwUnexpectedToken(Messages.NumericSeperatorOneUnderscore);
  1565. return this.source[this.index - 1] === '_' && this.throwUnexpectedToken(Messages.NumericSeperatorNotAllowedHere), t;
  1566. }
  1567.  
  1568. scanNumericLiteral() {
  1569. const e = this.index;
  1570. let t = this.source[e];
  1571. assert(Character.isDecimalDigit(t.charCodeAt(0)) || t === '.', 'Numeric literal must start with a decimal digit or a decimal point');
  1572. let s = '';
  1573. if (t !== '.') {
  1574. if (s = this.source[this.index++], t = this.source[this.index], s === '0') {
  1575. if (t === 'x' || t === 'X') return ++this.index, this.scanHexLiteral(e);
  1576. if (t === 'b' || t === 'B') return ++this.index, this.scanBinaryLiteral(e);
  1577. if (t === 'o' || t === 'O') return this.scanOctalLiteral(t, e);
  1578. if (t && Character.isOctalDigit(t.charCodeAt(0)) && this.isImplicitOctalLiteral()) return this.scanOctalLiteral(t, e);
  1579. }
  1580. this.index--, s = this.scanLiteralPart(Character.isDecimalDigitChar), t = this.source[this.index];
  1581. }
  1582. if (t === '.' && (s += this.source[this.index++], s += this.scanLiteralPart(Character.isDecimalDigitChar), t = this.source[this.index]), t === 'e' || t === 'E') s += this.source[this.index++], t = this.source[this.index], t !== '+' && t !== '-' || (s += this.source[this.index++]), Character.isDecimalDigit(this.source.charCodeAt(this.index)) ? s += this.scanLiteralPart(Character.isDecimalDigitChar) : this.throwUnexpectedToken();
  1583. else if (t === 'n') {
  1584. return s.length > 1 && s[0] === '0' && this.throwUnexpectedToken(), this.index++, {
  1585. type: 6,
  1586. value: BigInt(s),
  1587. lineNumber: this.lineNumber,
  1588. lineStart: this.lineStart,
  1589. start: e,
  1590. end: this.index
  1591. };
  1592. }
  1593. return Character.isIdentifierStart(this.source.charCodeAt(this.index)) && this.throwUnexpectedToken(), {
  1594. type: 6,
  1595. value: parseFloat(s),
  1596. lineNumber: this.lineNumber,
  1597. lineStart: this.lineStart,
  1598. start: e,
  1599. end: this.index
  1600. };
  1601. }
  1602.  
  1603. scanStringLiteral() {
  1604. const e = this.index;
  1605. let t = this.source[e];
  1606. assert(t === "'" || t === '"', 'String literal must starts with a quote'), ++this.index;
  1607. let s = !1;
  1608. let i = '';
  1609. for (; !this.eof();) {
  1610. let e = this.source[this.index++];
  1611. if (e === t) {
  1612. t = '';
  1613. break;
  1614. }
  1615. if (e === '\\') {
  1616. if (e = this.source[this.index++], e && Character.isLineTerminator(e.charCodeAt(0))) ++this.lineNumber, e === '\r' && this.source[this.index] === '\n' && ++this.index, this.lineStart = this.index;
  1617. else {
  1618. switch (e) {
  1619. case 'u':
  1620. if (this.source[this.index] === '{') ++this.index, i += this.scanUnicodeCodePointEscape();
  1621. else {
  1622. const t = this.scanHexEscape(e);
  1623. t === null && this.throwUnexpectedToken(), i += t;
  1624. }
  1625. break;
  1626. case 'x':
  1627. const t = this.scanHexEscape(e);
  1628. t === null && this.throwUnexpectedToken(Messages.InvalidHexEscapeSequence), i += t;
  1629. break;
  1630. case 'n':
  1631. i += '\n';
  1632. break;
  1633. case 'r':
  1634. i += '\r';
  1635. break;
  1636. case 't':
  1637. i += '\t';
  1638. break;
  1639. case 'b':
  1640. i += '\b';
  1641. break;
  1642. case 'f':
  1643. i += '\f';
  1644. break;
  1645. case 'v':
  1646. i += '\v';
  1647. break;
  1648. case '8':
  1649. case '9':
  1650. i += e, this.tolerateUnexpectedToken();
  1651. break;
  1652. default:
  1653. if (e && Character.isOctalDigit(e.charCodeAt(0))) {
  1654. const t = this.octalToDecimal(e);
  1655. s = t.octal || s, i += String.fromCharCode(t.code);
  1656. } else i += e;
  1657. }
  1658. }
  1659. } else {
  1660. if (Character.isLineTerminator(e.charCodeAt(0))) break;
  1661. i += e;
  1662. }
  1663. }
  1664. return t !== '' && (this.index = e, this.throwUnexpectedToken()), {
  1665. type: 8,
  1666. value: i,
  1667. octal: s,
  1668. lineNumber: this.lineNumber,
  1669. lineStart: this.lineStart,
  1670. start: e,
  1671. end: this.index
  1672. };
  1673. }
  1674.  
  1675. scanTemplate() {
  1676. let e = '';
  1677. let t = !1;
  1678. const s = this.index;
  1679. const i = this.source[s] === '`';
  1680. let r = !1;
  1681. let n = null;
  1682. let a = 2;
  1683. for (++this.index; !this.eof();) {
  1684. let s = this.source[this.index++];
  1685. if (s === '`') {
  1686. a = 1, r = !0, t = !0;
  1687. break;
  1688. }
  1689. if (s === '$') {
  1690. if (this.source[this.index] === '{') {
  1691. this.curlyStack.push('${'), ++this.index, t = !0;
  1692. break;
  1693. }
  1694. e += s;
  1695. } else {
  1696. if (n !== null) continue;
  1697. if (s === '\\') {
  1698. if (s = this.source[this.index++], Character.isLineTerminator(s.charCodeAt(0))) ++this.lineNumber, s === '\r' && this.source[this.index] === '\n' && ++this.index, this.lineStart = this.index;
  1699. else {
  1700. switch (s) {
  1701. case 'n':
  1702. e += '\n';
  1703. break;
  1704. case 'r':
  1705. e += '\r';
  1706. break;
  1707. case 't':
  1708. e += '\t';
  1709. break;
  1710. case 'u':
  1711. if (this.source[this.index] === '{') {
  1712. ++this.index;
  1713. const t = this.tryToScanUnicodeCodePointEscape();
  1714. t === null ? n = 'u' : e += t;
  1715. } else {
  1716. const t = this.scanHexEscape(s);
  1717. t === null ? n = 'u' : e += t;
  1718. }
  1719. break;
  1720. case 'x':
  1721. const t = this.scanHexEscape(s);
  1722. t === null ? n = 'x' : e += t;
  1723. break;
  1724. case 'b':
  1725. e += '\b';
  1726. break;
  1727. case 'f':
  1728. e += '\f';
  1729. break;
  1730. case 'v':
  1731. e += '\v';
  1732. break;
  1733. default:
  1734. s === '0' ? Character.isDecimalDigit(this.source.charCodeAt(this.index)) ? n = '0' : e += '\0' : Character.isDecimalDigitChar(s) ? n = s : e += s;
  1735. }
  1736. }
  1737. } else Character.isLineTerminator(s.charCodeAt(0)) ? (++this.lineNumber, s === '\r' && this.source[this.index] === '\n' && ++this.index, this.lineStart = this.index, e += '\n') : e += s;
  1738. }
  1739. }
  1740. return t || this.throwUnexpectedToken(), i || this.curlyStack.pop(), {
  1741. type: 10,
  1742. value: this.source.slice(s + 1, this.index - a),
  1743. cooked: n === null ? e : null,
  1744. head: i,
  1745. tail: r,
  1746. notEscapeSequenceHead: n,
  1747. lineNumber: this.lineNumber,
  1748. lineStart: this.lineStart,
  1749. start: s,
  1750. end: this.index
  1751. };
  1752. }
  1753.  
  1754. testRegExp(e, t) {
  1755. let s = e;
  1756. t.indexOf('u') >= 0 && (s = s.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, ((e, t, s) => {
  1757. const i = parseInt(t || s, 16);
  1758. return i > 1114111 && this.throwUnexpectedToken(Messages.InvalidRegExp), i <= 65535 ? String.fromCharCode(i) : '￿';
  1759. })).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, '￿'));
  1760. try {
  1761. RegExp(s);
  1762. } catch (e) {
  1763. this.throwUnexpectedToken(Messages.InvalidRegExp);
  1764. }
  1765. try {
  1766. return new RegExp(e, t);
  1767. } catch (e) {
  1768. return null;
  1769. }
  1770. }
  1771.  
  1772. scanRegExpBody() {
  1773. let e = this.source[this.index];
  1774. assert(e === '/', 'Regular expression literal must start with a slash');
  1775. let t = this.source[this.index++];
  1776. let s = !1;
  1777. let i = !1;
  1778. for (; !this.eof();) {
  1779. if (e = this.source[this.index++], t += e, e === '\\') e = this.source[this.index++], Character.isLineTerminator(e.charCodeAt(0)) && this.throwUnexpectedToken(Messages.UnterminatedRegExp), t += e;
  1780. else if (Character.isLineTerminator(e.charCodeAt(0))) this.throwUnexpectedToken(Messages.UnterminatedRegExp);
  1781. else if (s) e === ']' && (s = !1);
  1782. else {
  1783. if (e === '/') {
  1784. i = !0;
  1785. break;
  1786. }
  1787. e === '[' && (s = !0);
  1788. }
  1789. }
  1790. return i || this.throwUnexpectedToken(Messages.UnterminatedRegExp), t.substr(1, t.length - 2);
  1791. }
  1792.  
  1793. scanRegExpFlags() {
  1794. let e = '';
  1795. let t = '';
  1796. for (; !this.eof();) {
  1797. let s = this.source[this.index];
  1798. if (!Character.isIdentifierPart(s.charCodeAt(0))) break;
  1799. if (++this.index, s !== '\\' || this.eof()) t += s, e += s;
  1800. else if (s = this.source[this.index], s === 'u') {
  1801. ++this.index;
  1802. let s = this.index;
  1803. const i = this.scanHexEscape('u');
  1804. if (i !== null) for (t += i, e += '\\u'; s < this.index; ++s) e += this.source[s];
  1805. else this.index = s, t += 'u', e += '\\u';
  1806. this.tolerateUnexpectedToken();
  1807. } else e += '\\', this.tolerateUnexpectedToken();
  1808. }
  1809. return t;
  1810. }
  1811.  
  1812. scanRegExp() {
  1813. const e = this.index;
  1814. const t = this.scanRegExpBody();
  1815. const s = this.scanRegExpFlags();
  1816. return {
  1817. type: 9,
  1818. value: '',
  1819. pattern: t,
  1820. flags: s,
  1821. regex: this.testRegExp(t, s),
  1822. lineNumber: this.lineNumber,
  1823. lineStart: this.lineStart,
  1824. start: e,
  1825. end: this.index
  1826. };
  1827. }
  1828.  
  1829. lex() {
  1830. if (this.eof()) {
  1831. return {
  1832. type: 2,
  1833. value: '',
  1834. lineNumber: this.lineNumber,
  1835. lineStart: this.lineStart,
  1836. start: this.index,
  1837. end: this.index
  1838. };
  1839. }
  1840. const e = this.source.charCodeAt(this.index);
  1841. return Character.isIdentifierStart(e) ? this.scanIdentifier() : e === 40 || e === 41 || e === 59 ? this.scanPunctuator() : e === 39 || e === 34 ? this.scanStringLiteral() : e === 46 ? Character.isDecimalDigit(this.source.charCodeAt(this.index + 1)) ? this.scanNumericLiteral() : this.scanPunctuator() : Character.isDecimalDigit(e) ? this.scanNumericLiteral() : e === 96 || e === 125 && this.curlyStack[this.curlyStack.length - 1] === '${' ? this.scanTemplate() : e >= 55296 && e < 57343 && Character.isIdentifierStart(this.codePointAt(this.index)) ? this.scanIdentifier() : this.scanPunctuator();
  1842. }
  1843. };
  1844. const ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
  1845. const Parser = class {
  1846. config;
  1847. delegate;
  1848. errorHandler;
  1849. scanner;
  1850. operatorPrecedence;
  1851. lookahead;
  1852. hasLineTerminator;
  1853. context;
  1854. tokens;
  1855. startMarker;
  1856. lastMarker;
  1857. constructor(e, t = {}, s) {
  1858. this.config = {
  1859. range: typeof t.range === 'boolean' && t.range,
  1860. loc: typeof t.loc === 'boolean' && t.loc,
  1861. source: null,
  1862. tokens: typeof t.tokens === 'boolean' && t.tokens,
  1863. comment: typeof t.comment === 'boolean' && t.comment,
  1864. tolerant: typeof t.tolerant === 'boolean' && t.tolerant
  1865. }, this.config.loc && t.source && t.source !== null && (this.config.source = String(t.source)), this.delegate = s, this.errorHandler = new ErrorHandler(), this.errorHandler.tolerant = this.config.tolerant == 1, this.scanner = new Scanner(e, this.errorHandler), this.scanner.trackComment = this.config.comment == 1, this.operatorPrecedence = {
  1866. ')': 0,
  1867. ';': 0,
  1868. ',': 0,
  1869. '=': 0,
  1870. ']': 0,
  1871. '??': 5,
  1872. '||': 6,
  1873. '&&': 7,
  1874. '|': 8,
  1875. '^': 9,
  1876. '&': 10,
  1877. '==': 11,
  1878. '!=': 11,
  1879. '===': 11,
  1880. '!==': 11,
  1881. '<': 12,
  1882. '>': 12,
  1883. '<=': 12,
  1884. '>=': 12,
  1885. '<<': 13,
  1886. '>>': 13,
  1887. '>>>': 13,
  1888. '+': 14,
  1889. '-': 14,
  1890. '*': 15,
  1891. '/': 15,
  1892. '%': 15
  1893. }, this.lookahead = {
  1894. type: 2,
  1895. value: '',
  1896. lineNumber: this.scanner.lineNumber,
  1897. lineStart: 0,
  1898. start: 0,
  1899. end: 0
  1900. }, this.hasLineTerminator = !1, this.context = {
  1901. isModule: !1,
  1902. isAsync: !1,
  1903. allowIn: !0,
  1904. allowStrictDirective: !0,
  1905. allowSuper: !1,
  1906. allowYield: !0,
  1907. firstCoverInitializedNameError: null,
  1908. isAssignmentTarget: !1,
  1909. isBindingElement: !1,
  1910. inConstructor: !1,
  1911. inFunctionBody: !1,
  1912. inIteration: !1,
  1913. inSwitch: !1,
  1914. inClassConstructor: !1,
  1915. labelSet: {},
  1916. strict: !1,
  1917. decorators: null
  1918. }, this.tokens = [], this.startMarker = {
  1919. index: 0,
  1920. line: this.scanner.lineNumber,
  1921. column: 0
  1922. }, this.lastMarker = {
  1923. index: 0,
  1924. line: this.scanner.lineNumber,
  1925. column: 0
  1926. }, this.nextToken(), this.lastMarker = {
  1927. index: this.scanner.index,
  1928. line: this.scanner.lineNumber,
  1929. column: this.scanner.index - this.scanner.lineStart
  1930. };
  1931. }
  1932.  
  1933. throwError(e, ...t) {
  1934. const s = t.slice();
  1935. const i = e.replace(/%(\d)/g, ((e, t) => (assert(t < s.length, 'Message reference must be in range'), s[t])));
  1936. const r = this.lastMarker.index;
  1937. const n = this.lastMarker.line;
  1938. const a = this.lastMarker.column + 1;
  1939. throw this.errorHandler.createError(r, n, a, i);
  1940. }
  1941.  
  1942. tolerateError(e, ...t) {
  1943. const s = t.slice();
  1944. const i = e.replace(/%(\d)/g, ((e, t) => (assert(t < s.length, 'Message reference must be in range'), s[t])));
  1945. const r = this.lastMarker.index;
  1946. const n = this.scanner.lineNumber;
  1947. const a = this.lastMarker.column + 1;
  1948. this.errorHandler.tolerateError(r, n, a, i);
  1949. }
  1950.  
  1951. unexpectedTokenError(e, t) {
  1952. let s; let
  1953. i = t || Messages.UnexpectedToken;
  1954. if (e ? (t || (i = e.type === 2 ? Messages.UnexpectedEOS : e.type === 3 ? Messages.UnexpectedIdentifier : e.type === 6 ? Messages.UnexpectedNumber : e.type === 8 ? Messages.UnexpectedString : e.type === 10 ? Messages.UnexpectedTemplate : Messages.UnexpectedToken, e.type === 4 && (this.scanner.isFutureReservedWord(e.value) ? i = Messages.UnexpectedReserved : this.context.strict && this.scanner.isStrictModeReservedWord(e.value) && (i = Messages.StrictReservedWord))), s = e.value) : s = 'ILLEGAL', i = i.replace('%0', s), e && typeof e.lineNumber === 'number') {
  1955. const t = e.start;
  1956. const s = e.lineNumber;
  1957. const r = this.lastMarker.index - this.lastMarker.column;
  1958. const n = e.start - r + 1;
  1959. return this.errorHandler.createError(t, s, n, i);
  1960. } {
  1961. const e = this.lastMarker.index;
  1962. const t = this.lastMarker.line;
  1963. const s = this.lastMarker.column + 1;
  1964. return this.errorHandler.createError(e, t, s, i);
  1965. }
  1966. }
  1967.  
  1968. throwUnexpectedToken(e, t) {
  1969. throw this.unexpectedTokenError(e, t);
  1970. }
  1971.  
  1972. tolerateUnexpectedToken(e, t) {
  1973. this.errorHandler.tolerate(this.unexpectedTokenError(e, t));
  1974. }
  1975.  
  1976. tolerateInvalidLoopStatement() {
  1977. (this.matchKeyword('class') || this.matchKeyword('function')) && this.tolerateError(Messages.UnexpectedToken, this.lookahead);
  1978. }
  1979.  
  1980. collectComments() {
  1981. if (this.config.comment) {
  1982. const e = this.scanner.scanComments();
  1983. if (e.length > 0 && this.delegate) {
  1984. for (let t = 0; t < e.length; ++t) {
  1985. const s = e[t];
  1986. const i = {
  1987. type: s.multiLine ? 'BlockComment' : 'LineComment',
  1988. value: this.scanner.source.slice(s.slice[0], s.slice[1])
  1989. };
  1990. this.config.range && (i.range = s.range), this.config.loc && (i.loc = s.loc);
  1991. const r = {
  1992. start: {
  1993. line: s.loc.start.line,
  1994. column: s.loc.start.column,
  1995. offset: s.range[0]
  1996. },
  1997. end: {
  1998. line: s.loc.end.line,
  1999. column: s.loc.end.column,
  2000. offset: s.range[1]
  2001. }
  2002. };
  2003. this.delegate(i, r);
  2004. }
  2005. }
  2006. } else this.scanner.scanComments();
  2007. }
  2008.  
  2009. getTokenRaw(e) {
  2010. return this.scanner.source.slice(e.start, e.end);
  2011. }
  2012.  
  2013. convertToken(e) {
  2014. const t = {
  2015. type: TokenName[e.type],
  2016. value: this.getTokenRaw(e)
  2017. };
  2018. if (this.config.range && (t.range = [e.start, e.end]), this.config.loc && (t.loc = {
  2019. start: {
  2020. line: this.startMarker.line,
  2021. column: this.startMarker.column
  2022. },
  2023. end: {
  2024. line: this.scanner.lineNumber,
  2025. column: this.scanner.index - this.scanner.lineStart
  2026. }
  2027. }), e.type === 9) {
  2028. const s = e.pattern;
  2029. const i = e.flags;
  2030. t.regex = {
  2031. pattern: s,
  2032. flags: i
  2033. };
  2034. }
  2035. return t;
  2036. }
  2037.  
  2038. nextToken() {
  2039. const e = this.lookahead;
  2040. this.lastMarker.index = this.scanner.index, this.lastMarker.line = this.scanner.lineNumber, this.lastMarker.column = this.scanner.index - this.scanner.lineStart, this.collectComments(), this.scanner.index !== this.startMarker.index && (this.startMarker.index = this.scanner.index, this.startMarker.line = this.scanner.lineNumber, this.startMarker.column = this.scanner.index - this.scanner.lineStart);
  2041. const t = this.scanner.lex();
  2042. return this.hasLineTerminator = e.lineNumber !== t.lineNumber, t && this.context.strict && t.type === 3 && this.scanner.isStrictModeReservedWord(t.value) && (t.type = 4), this.lookahead = t, this.config.tokens && t.type !== 2 && this.tokens.push(this.convertToken(t)), e;
  2043. }
  2044.  
  2045. nextRegexToken() {
  2046. this.collectComments();
  2047. const e = this.scanner.scanRegExp();
  2048. return this.config.tokens && (this.tokens.pop(), this.tokens.push(this.convertToken(e))), this.lookahead = e, this.nextToken(), e;
  2049. }
  2050.  
  2051. createNode() {
  2052. return {
  2053. index: this.startMarker.index,
  2054. line: this.startMarker.line,
  2055. column: this.startMarker.column
  2056. };
  2057. }
  2058.  
  2059. startNode(e, t = 0) {
  2060. let s = e.start - e.lineStart;
  2061. let i = e.lineNumber;
  2062. return s < 0 && (s += t, i--), {
  2063. index: e.start,
  2064. line: i,
  2065. column: s
  2066. };
  2067. }
  2068.  
  2069. finalize(e, t) {
  2070. if (this.config.range && (t.range = [e.index, this.lastMarker.index]), this.config.loc && (t.loc = {
  2071. start: {
  2072. line: e.line,
  2073. column: e.column
  2074. },
  2075. end: {
  2076. line: this.lastMarker.line,
  2077. column: this.lastMarker.column
  2078. }
  2079. }, this.config.source && (t.loc.source = this.config.source)), this.delegate) {
  2080. const s = {
  2081. start: {
  2082. line: e.line,
  2083. column: e.column,
  2084. offset: e.index
  2085. },
  2086. end: {
  2087. line: this.lastMarker.line,
  2088. column: this.lastMarker.column,
  2089. offset: this.lastMarker.index
  2090. }
  2091. };
  2092. this.delegate(t, s);
  2093. }
  2094. return t;
  2095. }
  2096.  
  2097. expect(e) {
  2098. const t = this.nextToken();
  2099. t.type === 7 && t.value === e || this.throwUnexpectedToken(t);
  2100. }
  2101.  
  2102. expectCommaSeparator() {
  2103. if (this.config.tolerant) {
  2104. const e = this.lookahead;
  2105. e.type === 7 && e.value === ',' ? this.nextToken() : e.type === 7 && e.value === ';' ? (this.nextToken(), this.tolerateUnexpectedToken(e)) : this.tolerateUnexpectedToken(e, Messages.UnexpectedToken);
  2106. } else this.expect(',');
  2107. }
  2108.  
  2109. expectKeyword(e) {
  2110. const t = this.nextToken();
  2111. t.type === 4 && t.value === e || this.throwUnexpectedToken(t);
  2112. }
  2113.  
  2114. match(e) {
  2115. return this.lookahead.type === 7 && this.lookahead.value === e;
  2116. }
  2117.  
  2118. matchKeyword(e) {
  2119. return this.lookahead.type === 4 && this.lookahead.value === e;
  2120. }
  2121.  
  2122. matchContextualKeyword(e) {
  2123. return this.lookahead.type === 3 && this.lookahead.value === e;
  2124. }
  2125.  
  2126. matchAssign() {
  2127. if (this.lookahead.type !== 7) return !1;
  2128. const e = this.lookahead.value;
  2129. return e === '=' || e === '*=' || e === '**=' || e === '/=' || e === '%=' || e === '+=' || e === '-=' || e === '<<=' || e === '>>=' || e === '>>>=' || e === '&=' || e === '^=' || e === '|=' || e === '&&=' || e === '||=' || e === '??=';
  2130. }
  2131.  
  2132. isolateCoverGrammar(e) {
  2133. const t = this.context.isBindingElement;
  2134. const s = this.context.isAssignmentTarget;
  2135. const i = this.context.firstCoverInitializedNameError;
  2136. this.context.isBindingElement = !0, this.context.isAssignmentTarget = !0, this.context.firstCoverInitializedNameError = null;
  2137. const r = e.call(this);
  2138. return this.context.firstCoverInitializedNameError !== null && this.throwUnexpectedToken(this.context.firstCoverInitializedNameError), this.context.isBindingElement = t, this.context.isAssignmentTarget = s, this.context.firstCoverInitializedNameError = i, r;
  2139. }
  2140.  
  2141. inheritCoverGrammar(e) {
  2142. const t = this.context.isBindingElement;
  2143. const s = this.context.isAssignmentTarget;
  2144. const i = this.context.firstCoverInitializedNameError;
  2145. this.context.isBindingElement = !0, this.context.isAssignmentTarget = !0, this.context.firstCoverInitializedNameError = null;
  2146. const r = e.call(this);
  2147. return this.context.isBindingElement = this.context.isBindingElement && t, this.context.isAssignmentTarget = this.context.isAssignmentTarget && s, this.context.firstCoverInitializedNameError = i || this.context.firstCoverInitializedNameError, r;
  2148. }
  2149.  
  2150. consumeSemicolon() {
  2151. this.match(';') ? this.nextToken() : this.hasLineTerminator || (this.lookahead.type === 2 || this.match('}') || this.throwUnexpectedToken(this.lookahead), this.lastMarker.index = this.startMarker.index, this.lastMarker.line = this.startMarker.line, this.lastMarker.column = this.startMarker.column);
  2152. }
  2153.  
  2154. parsePrimaryExpression() {
  2155. const e = this.createNode();
  2156. let t; let s; let
  2157. i;
  2158. switch (this.lookahead.type) {
  2159. case 3:
  2160. (this.context.isModule || this.context.isAsync) && this.lookahead.value === 'await' && this.tolerateUnexpectedToken(this.lookahead), t = this.matchAsyncFunction() ? this.parseFunctionExpression() : this.finalize(e, new Identifier(this.nextToken().value));
  2161. break;
  2162. case 6:
  2163. case 8:
  2164. this.context.strict && this.lookahead.octal && this.tolerateUnexpectedToken(this.lookahead, Messages.StrictOctalLiteral), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, s = this.nextToken(), i = this.getTokenRaw(s), t = typeof s.value === 'bigint' ? this.finalize(e, new BigIntLiteral(s.value, i, s.value.toString())) : this.finalize(e, new Literal(s.value, i));
  2165. break;
  2166. case 1:
  2167. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, s = this.nextToken(), i = this.getTokenRaw(s), t = this.finalize(e, new Literal(s.value === 'true', i));
  2168. break;
  2169. case 5:
  2170. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, s = this.nextToken(), i = this.getTokenRaw(s), t = this.finalize(e, new Literal(null, i));
  2171. break;
  2172. case 10:
  2173. t = this.parseTemplateLiteral({
  2174. isTagged: !1
  2175. });
  2176. break;
  2177. case 7:
  2178. switch (this.lookahead.value) {
  2179. case '(':
  2180. this.context.isBindingElement = !1, t = this.inheritCoverGrammar(this.parseGroupExpression);
  2181. break;
  2182. case '[':
  2183. t = this.inheritCoverGrammar(this.parseArrayInitializer);
  2184. break;
  2185. case '{':
  2186. t = this.inheritCoverGrammar(this.parseObjectInitializer);
  2187. break;
  2188. case '/':
  2189. case '/=':
  2190. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, this.scanner.index = this.startMarker.index, s = this.nextRegexToken(), i = this.getTokenRaw(s), t = this.finalize(e, new RegexLiteral(s.regex, i, s.pattern, s.flags));
  2191. break;
  2192. case '#':
  2193. this.nextToken(), t = this.finalize(e, new PrivateIdentifier(this.nextToken().value));
  2194. break;
  2195. case '@':
  2196. const r = this.parseDecorators();
  2197. this.context.decorators = r;
  2198. this.parsePrimaryExpression();
  2199. this.context.decorators = null, t = this.finalize(e, new PrivateIdentifier(this.nextToken().value));
  2200. break;
  2201. default:
  2202. t = this.throwUnexpectedToken(this.nextToken());
  2203. }
  2204. break;
  2205. case 4:
  2206. !this.context.strict && this.context.allowYield && this.matchKeyword('yield') ? t = this.parseIdentifierName() : !this.context.strict && this.matchKeyword('let') ? t = this.finalize(e, new Identifier(this.nextToken().value)) : (this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, this.matchKeyword('function') ? t = this.parseFunctionExpression() : this.matchKeyword('this') ? (this.nextToken(), t = this.finalize(e, new ThisExpression())) : this.matchKeyword('class') ? t = this.parseClassExpression() : this.matchKeyword('new') ? t = this.parseNewExpression() : this.matchImportCall() ? t = this.parseImportCall() : this.matchImportMeta() ? (this.context.isModule || this.tolerateUnexpectedToken(this.lookahead, Messages.CannotUseImportMetaOutsideAModule), t = this.parseImportMeta()) : t = this.throwUnexpectedToken(this.nextToken()));
  2207. break;
  2208. default:
  2209. t = this.throwUnexpectedToken(this.nextToken());
  2210. }
  2211. return t;
  2212. }
  2213.  
  2214. parseSpreadElement() {
  2215. const e = this.createNode();
  2216. this.expect('...');
  2217. const t = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2218. return this.finalize(e, new SpreadElement(t));
  2219. }
  2220.  
  2221. parseArrayInitializer() {
  2222. const e = this.createNode();
  2223. const t = [];
  2224. for (this.expect('['); !this.match(']');) {
  2225. if (this.match(',')) this.nextToken(), t.push(null);
  2226. else if (this.match('...')) {
  2227. const e = this.parseSpreadElement();
  2228. this.match(']') || (this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, this.expect(',')), t.push(e);
  2229. } else t.push(this.inheritCoverGrammar(this.parseAssignmentExpression)), this.match(']') || this.expect(',');
  2230. }
  2231. return this.expect(']'), this.finalize(e, new ArrayExpression(t));
  2232. }
  2233.  
  2234. parsePropertyMethod(e) {
  2235. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2236. const t = this.context.strict;
  2237. const s = this.context.allowStrictDirective;
  2238. this.context.allowStrictDirective = e.simple;
  2239. const i = this.isolateCoverGrammar(this.parseFunctionSourceElements);
  2240. return this.context.strict && e.firstRestricted && this.tolerateUnexpectedToken(e.firstRestricted, e.message), this.context.strict && e.stricted && this.tolerateUnexpectedToken(e.stricted, e.message), this.context.strict = t, this.context.allowStrictDirective = s, i;
  2241. }
  2242.  
  2243. parsePropertyMethodFunction(e) {
  2244. const t = this.createNode();
  2245. const s = this.context.allowYield;
  2246. this.context.allowYield = !0;
  2247. const i = this.parseFormalParameters();
  2248. const r = this.parsePropertyMethod(i);
  2249. return this.context.allowYield = s, this.finalize(t, new FunctionExpression(null, i.params, r, e, !1));
  2250. }
  2251.  
  2252. parsePropertyMethodAsyncFunction(e) {
  2253. const t = this.createNode();
  2254. const s = this.context.allowYield;
  2255. const i = this.context.isAsync;
  2256. this.context.allowYield = !1, this.context.isAsync = !0;
  2257. const r = this.parseFormalParameters();
  2258. const n = this.parsePropertyMethod(r);
  2259. return this.context.allowYield = s, this.context.isAsync = i, this.finalize(t, new FunctionExpression(null, r.params, n, e, !0));
  2260. }
  2261.  
  2262. parseObjectPropertyKey(e = !1) {
  2263. const t = this.createNode();
  2264. const s = this.nextToken();
  2265. let i;
  2266. switch (s.type) {
  2267. case 8:
  2268. case 6:
  2269. this.context.strict && s.octal && this.tolerateUnexpectedToken(s, Messages.StrictOctalLiteral);
  2270. const r = this.getTokenRaw(s);
  2271. i = typeof s.value === 'bigint' ? this.finalize(t, new BigIntLiteral(s.value, r, s.value.toString())) : this.finalize(t, new Literal(s.value, r));
  2272. break;
  2273. case 3:
  2274. case 1:
  2275. case 5:
  2276. case 4:
  2277. i = this.finalize(t, e ? new PrivateIdentifier(s.value) : new Identifier(s.value));
  2278. break;
  2279. case 7:
  2280. s.value === '[' ? (i = this.isolateCoverGrammar(this.parseAssignmentExpression), this.expect(']')) : i = this.throwUnexpectedToken(s);
  2281. break;
  2282. default:
  2283. i = this.throwUnexpectedToken(s);
  2284. }
  2285. return i;
  2286. }
  2287.  
  2288. isPropertyKey(e, t) {
  2289. return e.type === 'Identifier' && e.name === t || e.type === 'Literal' && e.value === t;
  2290. }
  2291.  
  2292. parseObjectProperty(e) {
  2293. const t = this.createNode();
  2294. const s = this.lookahead;
  2295. let i; let r = null;
  2296. let n = null;
  2297. let a = !1;
  2298. let o = !1;
  2299. let u = !1;
  2300. let h = !1;
  2301. let c = !1;
  2302. if (s.type === 3) {
  2303. const e = s.value;
  2304. this.nextToken(), a = this.match('['), h = !(this.hasLineTerminator || e !== 'async' || this.match(':') || this.match('(') || this.match(',')), c = this.match('*'), c && this.nextToken(), r = h ? this.parseObjectPropertyKey() : this.finalize(t, new Identifier(e));
  2305. } else this.match('*') ? this.nextToken() : (a = this.match('['), r = this.parseObjectPropertyKey());
  2306. const l = this.qualifiedPropertyName(this.lookahead);
  2307. if (s.type === 3 && !h && s.value === 'get' && l) i = 'get', a = this.match('['), r = this.parseObjectPropertyKey(), this.context.allowYield = !1, n = this.parseGetterMethod();
  2308. else if (s.type === 3 && !h && s.value === 'set' && l) i = 'set', a = this.match('['), r = this.parseObjectPropertyKey(), n = this.parseSetterMethod();
  2309. else if (s.type === 7 && s.value === '*' && l) i = 'init', a = this.match('['), r = this.parseObjectPropertyKey(), n = this.parseGeneratorMethod(!1), o = !0;
  2310. else if (r || this.throwUnexpectedToken(this.lookahead), i = 'init', this.match(':') && !h) !a && this.isPropertyKey(r, '__proto__') && (e.value && this.tolerateError(Messages.DuplicateProtoProperty), e.value = !0), this.nextToken(), n = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2311. else if (this.match('(')) n = h ? this.parsePropertyMethodAsyncFunction(c) : this.parsePropertyMethodFunction(c), o = !0;
  2312. else if (s.type === 3) {
  2313. const e = this.finalize(t, new Identifier(s.value));
  2314. if (this.match('=')) {
  2315. this.context.firstCoverInitializedNameError = this.lookahead, this.nextToken(), u = !0;
  2316. const s = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2317. n = this.finalize(t, new AssignmentPattern(e, s));
  2318. } else u = !0, n = e;
  2319. } else this.throwUnexpectedToken(this.nextToken());
  2320. return this.finalize(t, new Property(i, r, a, n, o, u));
  2321. }
  2322.  
  2323. parseObjectInitializer() {
  2324. const e = this.createNode();
  2325. this.expect('{');
  2326. const t = [];
  2327. const s = {
  2328. value: !1
  2329. };
  2330. for (; !this.match('}');) {
  2331. const e = this.match('...') ? this.parseSpreadElement() : this.parseObjectProperty(s);
  2332. t.push(e), this.match('}') || e.method && !this.match(',') || this.expectCommaSeparator();
  2333. }
  2334. return this.expect('}'), this.finalize(e, new ObjectExpression(t));
  2335. }
  2336.  
  2337. throwTemplateLiteralEarlyErrors(e) {
  2338. switch (e.notEscapeSequenceHead) {
  2339. case 'u':
  2340. return this.throwUnexpectedToken(e, Messages.InvalidUnicodeEscapeSequence);
  2341. case 'x':
  2342. return this.throwUnexpectedToken(e, Messages.InvalidHexEscapeSequence);
  2343. case '8':
  2344. case '9':
  2345. return this.throwUnexpectedToken(e, Messages.TemplateEscape89);
  2346. default:
  2347. return this.throwUnexpectedToken(e, Messages.TemplateOctalLiteral);
  2348. }
  2349. }
  2350.  
  2351. parseTemplateHead(e) {
  2352. assert(this.lookahead.head, 'Template literal must start with a template head');
  2353. const t = this.createNode();
  2354. const s = this.nextToken();
  2355. e.isTagged || s.notEscapeSequenceHead === null || this.throwTemplateLiteralEarlyErrors(s);
  2356. const i = s.value;
  2357. const r = s.cooked;
  2358. return this.finalize(t, new TemplateElement({
  2359. raw: i,
  2360. cooked: r
  2361. }, s.tail));
  2362. }
  2363.  
  2364. parseTemplateElement(e) {
  2365. this.lookahead.type !== 10 && this.throwUnexpectedToken();
  2366. const t = this.createNode();
  2367. const s = this.nextToken();
  2368. e.isTagged || s.notEscapeSequenceHead === null || this.throwTemplateLiteralEarlyErrors(s);
  2369. const i = s.value;
  2370. const r = s.cooked;
  2371. return this.finalize(t, new TemplateElement({
  2372. raw: i,
  2373. cooked: r
  2374. }, s.tail));
  2375. }
  2376.  
  2377. parseTemplateLiteral(e) {
  2378. const t = this.createNode();
  2379. const s = [];
  2380. const i = [];
  2381. let r = this.parseTemplateHead(e);
  2382. for (i.push(r); !r.tail;) s.push(this.parseExpression()), r = this.parseTemplateElement(e), i.push(r);
  2383. return this.finalize(t, new TemplateLiteral(i, s));
  2384. }
  2385.  
  2386. reinterpretExpressionAsPattern(e) {
  2387. switch (e.type) {
  2388. case 'Identifier':
  2389. case 'MemberExpression':
  2390. case 'RestElement':
  2391. case 'AssignmentPattern':
  2392. default:
  2393. break;
  2394. case 'SpreadElement':
  2395. e.type = 'RestElement', this.reinterpretExpressionAsPattern(e.argument);
  2396. break;
  2397. case 'ArrayExpression':
  2398. e.type = 'ArrayPattern';
  2399. for (let t = 0; t < e.elements.length; t++) e.elements[t] !== null && this.reinterpretExpressionAsPattern(e.elements[t]);
  2400. break;
  2401. case 'ObjectExpression':
  2402. e.type = 'ObjectPattern';
  2403. for (let t = 0; t < e.properties.length; t++) {
  2404. const s = e.properties[t];
  2405. this.reinterpretExpressionAsPattern(s.type === 'SpreadElement' ? s : s.value);
  2406. }
  2407. break;
  2408. case 'AssignmentExpression':
  2409. e.type = 'AssignmentPattern', delete e.operator, this.reinterpretExpressionAsPattern(e.left);
  2410. }
  2411. }
  2412.  
  2413. parseGroupExpression() {
  2414. let e;
  2415. if (this.expect('('), this.match(')')) {
  2416. this.nextToken(), this.match('=>') || this.expect('=>'), e = {
  2417. type: ArrowParameterPlaceHolder,
  2418. params: [],
  2419. async: !1
  2420. };
  2421. } else {
  2422. const t = this.lookahead;
  2423. const s = [];
  2424. if (this.match('...')) {
  2425. e = this.parseRestElement(s), this.expect(')'), this.match('=>') || this.expect('=>'), e = {
  2426. type: ArrowParameterPlaceHolder,
  2427. params: [e],
  2428. async: !1
  2429. };
  2430. } else {
  2431. let i = !1;
  2432. if (this.context.isBindingElement = !0, e = this.inheritCoverGrammar(this.parseAssignmentExpression), this.match(',')) {
  2433. const r = [];
  2434. for (this.context.isAssignmentTarget = !1, r.push(e); this.lookahead.type !== 2 && this.match(',');) {
  2435. if (this.nextToken(), this.match(')')) {
  2436. this.nextToken();
  2437. for (let e = 0; e < r.length; e++) this.reinterpretExpressionAsPattern(r[e]);
  2438. i = !0, e = {
  2439. type: ArrowParameterPlaceHolder,
  2440. params: r,
  2441. async: !1
  2442. };
  2443. } else if (this.match('...')) {
  2444. this.context.isBindingElement || this.throwUnexpectedToken(this.lookahead), r.push(this.parseRestElement(s)), this.expect(')'), this.match('=>') || this.expect('=>'), this.context.isBindingElement = !1;
  2445. for (let e = 0; e < r.length; e++) this.reinterpretExpressionAsPattern(r[e]);
  2446. i = !0, e = {
  2447. type: ArrowParameterPlaceHolder,
  2448. params: r,
  2449. async: !1
  2450. };
  2451. } else r.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
  2452. if (i) break;
  2453. }
  2454. i || (e = this.finalize(this.startNode(t), new SequenceExpression(r)));
  2455. }
  2456. if (!i) {
  2457. if (this.expect(')'), this.match('=>') && (e.type === 'Identifier' && e.name === 'yield' && (i = !0, e = {
  2458. type: ArrowParameterPlaceHolder,
  2459. params: [e],
  2460. async: !1
  2461. }), !i)) {
  2462. if (this.context.isBindingElement || this.throwUnexpectedToken(this.lookahead), e.type === 'SequenceExpression') for (let t = 0; t < e.expressions.length; t++) this.reinterpretExpressionAsPattern(e.expressions[t]);
  2463. else this.reinterpretExpressionAsPattern(e);
  2464. const t = e.type === 'SequenceExpression' ? e.expressions : [e];
  2465. e = {
  2466. type: ArrowParameterPlaceHolder,
  2467. params: t,
  2468. async: !1
  2469. };
  2470. }
  2471. this.context.isBindingElement = !1;
  2472. }
  2473. }
  2474. }
  2475. return e;
  2476. }
  2477.  
  2478. parseArguments() {
  2479. this.expect('(');
  2480. const e = [];
  2481. if (!this.match(')')) {
  2482. for (;;) {
  2483. const t = this.match('...') ? this.parseSpreadElement() : this.isolateCoverGrammar(this.parseAssignmentExpression);
  2484. if (e.push(t), this.match(')')) break;
  2485. if (this.expectCommaSeparator(), this.match(')')) break;
  2486. }
  2487. }
  2488. return this.expect(')'), e;
  2489. }
  2490.  
  2491. isIdentifierName(e) {
  2492. return e.type === 3 || e.type === 4 || e.type === 1 || e.type === 5;
  2493. }
  2494.  
  2495. parseIdentifierName(e = !1) {
  2496. let t = !1;
  2497. const s = this.createNode();
  2498. let i = this.nextToken();
  2499. return i.value === '#' && e && (i = this.nextToken(), t = !0), this.isIdentifierName(i) || this.throwUnexpectedToken(i), this.finalize(s, t ? new PrivateIdentifier(i.value) : new Identifier(i.value));
  2500. }
  2501.  
  2502. parseNewExpression() {
  2503. const e = this.createNode();
  2504. const t = this.parseIdentifierName();
  2505. let s;
  2506. if (assert(t.name === 'new', 'New expression must start with `new`'), this.match('.')) {
  2507. if (this.nextToken(), this.lookahead.type === 3 && this.context.inFunctionBody && this.lookahead.value === 'target') {
  2508. const e = this.parseIdentifierName();
  2509. s = new MetaProperty(t, e);
  2510. } else this.throwUnexpectedToken(this.lookahead);
  2511. } else if (this.matchKeyword('import')) this.throwUnexpectedToken(this.lookahead);
  2512. else {
  2513. const e = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
  2514. const t = this.match('(') ? this.parseArguments() : [];
  2515. s = new NewExpression(e, t), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2516. }
  2517. return this.finalize(e, s);
  2518. }
  2519.  
  2520. parseAsyncArgument() {
  2521. const e = this.parseAssignmentExpression();
  2522. return this.context.firstCoverInitializedNameError = null, e;
  2523. }
  2524.  
  2525. parseAsyncArguments() {
  2526. this.expect('(');
  2527. const e = [];
  2528. if (!this.match(')')) {
  2529. for (;;) {
  2530. const t = this.match('...') ? this.parseSpreadElement() : this.isolateCoverGrammar(this.parseAsyncArgument);
  2531. if (e.push(t), this.match(')')) break;
  2532. if (this.expectCommaSeparator(), this.match(')')) break;
  2533. }
  2534. }
  2535. return this.expect(')'), e;
  2536. }
  2537.  
  2538. matchImportCall() {
  2539. let e = this.matchKeyword('import');
  2540. if (e) {
  2541. const t = this.scanner.saveState();
  2542. this.scanner.scanComments();
  2543. const s = this.scanner.lex();
  2544. this.scanner.restoreState(t), e = s.type === 7 && s.value === '(';
  2545. }
  2546. return e;
  2547. }
  2548.  
  2549. parseImportCall() {
  2550. const e = this.createNode();
  2551. this.expectKeyword('import'), this.expect('(');
  2552. const t = this.context.isAssignmentTarget;
  2553. this.context.isAssignmentTarget = !0;
  2554. const s = this.parseAssignmentExpression();
  2555. let i = null;
  2556. return this.match(',') && (this.nextToken(), this.match(')') || (i = this.parseAssignmentExpression())), this.context.isAssignmentTarget = t, this.match(')') ? this.nextToken() : (this.match(',') && this.nextToken(), this.expect(')')), this.finalize(e, new ImportExpression(s, i));
  2557. }
  2558.  
  2559. matchImportMeta() {
  2560. let e = this.matchKeyword('import');
  2561. if (e) {
  2562. const t = this.scanner.saveState();
  2563. this.scanner.scanComments();
  2564. const s = this.scanner.lex();
  2565. if (s.type === 7 && s.value === '.') {
  2566. this.scanner.scanComments();
  2567. const t = this.scanner.lex();
  2568. e = t.type === 3 && t.value === 'meta', e && t.end - t.start != 4 && this.tolerateUnexpectedToken(t, Messages.InvalidEscapedReservedWord);
  2569. } else e = !1;
  2570. this.scanner.restoreState(t);
  2571. }
  2572. return e;
  2573. }
  2574.  
  2575. parseImportMeta() {
  2576. const e = this.createNode();
  2577. const t = this.parseIdentifierName();
  2578. this.expect('.');
  2579. const s = this.parseIdentifierName();
  2580. return this.context.isAssignmentTarget = !1, this.finalize(e, new MetaProperty(t, s));
  2581. }
  2582.  
  2583. parseLeftHandSideExpressionAllowCall() {
  2584. const e = this.lookahead;
  2585. const t = this.matchContextualKeyword('async');
  2586. const s = this.context.allowIn;
  2587. let i;
  2588. this.context.allowIn = !0;
  2589. const r = this.matchKeyword('super');
  2590. r && this.context.inFunctionBody ? (i = this.createNode(), this.nextToken(), i = this.finalize(i, new Super()), this.match('(') || this.match('.') || this.match('[') || this.throwUnexpectedToken(this.lookahead)) : i = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression), !r || !this.match('(') || this.context.inClassConstructor && this.context.allowSuper || this.tolerateError(Messages.UnexpectedSuper);
  2591. let n = !1;
  2592. for (;;) {
  2593. let s = !1;
  2594. if (this.match('?.') && (s = !0, n = !0, this.expect('?.')), this.match('(')) {
  2595. const r = t && e.lineNumber === this.lookahead.lineNumber;
  2596. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !1;
  2597. const n = r ? this.parseAsyncArguments() : this.parseArguments();
  2598. if (i.type === 'ImportExpression' && n.length !== 1 && this.tolerateError(Messages.BadImportCallArity), i = this.finalize(this.startNode(e), new CallExpression(i, n, s)), r && this.match('=>')) {
  2599. for (let e = 0; e < n.length; ++e) this.reinterpretExpressionAsPattern(n[e]);
  2600. i = {
  2601. type: ArrowParameterPlaceHolder,
  2602. params: n,
  2603. async: !0
  2604. };
  2605. }
  2606. } else if (this.match('[')) {
  2607. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !s, this.expect('[');
  2608. const t = this.isolateCoverGrammar(this.parseExpression);
  2609. this.expect(']'), i = this.finalize(this.startNode(e), new MemberExpression(!0, i, t, s));
  2610. } else if (this.lookahead.type === 10 && this.lookahead.head) {
  2611. s && this.throwUnexpectedToken(this.lookahead), n && this.throwError(Messages.InvalidTaggedTemplateOnOptionalChain);
  2612. const t = this.parseTemplateLiteral({
  2613. isTagged: !0
  2614. });
  2615. i = this.finalize(this.startNode(e), new TaggedTemplateExpression(i, t));
  2616. } else {
  2617. if (!this.match('.') && !s) break;
  2618. {
  2619. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !s, s || this.expect('.');
  2620. const t = this.parseIdentifierName(!0);
  2621. i = this.finalize(this.startNode(e), new MemberExpression(!1, i, t, s));
  2622. }
  2623. }
  2624. }
  2625. return this.context.allowIn = s, n && (i = this.finalize(this.startNode(e), new ChainExpression(i))), i;
  2626. }
  2627.  
  2628. parseSuper() {
  2629. const e = this.createNode();
  2630. return this.expectKeyword('super'), this.match('[') || this.match('.') || this.throwUnexpectedToken(this.lookahead), this.finalize(e, new Super());
  2631. }
  2632.  
  2633. parseLeftHandSideExpression() {
  2634. assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
  2635. const e = this.startNode(this.lookahead);
  2636. let t = this.matchKeyword('super') && this.context.inFunctionBody ? this.parseSuper() : this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
  2637. let s = !1;
  2638. for (;;) {
  2639. let i = !1;
  2640. if (this.match('?.') && (i = !0, s = !0, this.expect('?.')), this.match('[')) {
  2641. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !i, this.expect('[');
  2642. const s = this.isolateCoverGrammar(this.parseExpression);
  2643. this.expect(']'), t = this.finalize(e, new MemberExpression(!0, t, s, i));
  2644. } else if (this.lookahead.type === 10 && this.lookahead.head) {
  2645. i && this.throwUnexpectedToken(this.lookahead), s && this.throwError(Messages.InvalidTaggedTemplateOnOptionalChain);
  2646. const r = this.parseTemplateLiteral({
  2647. isTagged: !0
  2648. });
  2649. t = this.finalize(e, new TaggedTemplateExpression(t, r));
  2650. } else {
  2651. if (!this.match('.') && !i) break;
  2652. {
  2653. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !i, i || this.expect('.');
  2654. const s = this.parseIdentifierName();
  2655. t = this.finalize(e, new MemberExpression(!1, t, s, i));
  2656. }
  2657. }
  2658. }
  2659. return s && (t = this.finalize(e, new ChainExpression(t))), t;
  2660. }
  2661.  
  2662. parseUpdateExpression() {
  2663. let e;
  2664. const t = this.lookahead;
  2665. if (this.match('++') || this.match('--')) {
  2666. const s = this.startNode(t);
  2667. const i = this.nextToken();
  2668. e = this.inheritCoverGrammar(this.parseUnaryExpression), this.context.strict && e.type === 'Identifier' && this.scanner.isRestrictedWord(e.name) && this.tolerateError(Messages.StrictLHSPrefix), this.context.isAssignmentTarget || this.tolerateError(Messages.InvalidLHSInAssignment);
  2669. const r = !0;
  2670. e = this.finalize(s, new UpdateExpression(i.value, e, r)), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2671. } else if (e = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall), !this.hasLineTerminator && this.lookahead.type === 7 && (this.match('++') || this.match('--'))) {
  2672. this.context.strict && e.type === 'Identifier' && this.scanner.isRestrictedWord(e.name) && this.tolerateError(Messages.StrictLHSPostfix), this.context.isAssignmentTarget || this.tolerateError(Messages.InvalidLHSInAssignment), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2673. const s = this.nextToken().value;
  2674. const i = !1;
  2675. e = this.finalize(this.startNode(t), new UpdateExpression(s, e, i));
  2676. }
  2677. return e;
  2678. }
  2679.  
  2680. parseAwaitExpression() {
  2681. const e = this.createNode();
  2682. this.nextToken();
  2683. const t = this.parseUnaryExpression();
  2684. return this.finalize(e, new AwaitExpression(t));
  2685. }
  2686.  
  2687. parseUnaryExpression() {
  2688. let e;
  2689. if (this.match('+') || this.match('-') || this.match('~') || this.match('!') || this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
  2690. const t = this.startNode(this.lookahead);
  2691. const s = this.nextToken();
  2692. e = this.inheritCoverGrammar(this.parseUnaryExpression), e = this.finalize(t, new UnaryExpression(s.value, e)), this.context.strict && e.operator === 'delete' && e.argument.type === 'Identifier' && this.tolerateError(Messages.StrictDelete), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2693. } else e = (this.context.isModule && !this.context.inFunctionBody || this.context.isAsync) && this.matchContextualKeyword('await') ? this.parseAwaitExpression() : this.parseUpdateExpression();
  2694. return e;
  2695. }
  2696.  
  2697. parseExponentiationExpression() {
  2698. const e = this.lookahead;
  2699. const t = this.match('(');
  2700. let s = this.inheritCoverGrammar(this.parseUnaryExpression);
  2701. if ((s.type !== 'UnaryExpression' || t) && this.match('**')) {
  2702. this.nextToken(), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2703. const t = s;
  2704. const i = this.isolateCoverGrammar(this.parseExponentiationExpression);
  2705. s = this.finalize(this.startNode(e), new BinaryExpression('**', t, i));
  2706. }
  2707. return s;
  2708. }
  2709.  
  2710. binaryPrecedence(e) {
  2711. const t = e.value;
  2712. let s;
  2713. return s = e.type === 7 ? this.operatorPrecedence[t] || 0 : e.type === 4 && (t === 'instanceof' || this.context.allowIn && t === 'in') ? 12 : 0, s;
  2714. }
  2715.  
  2716. parseBinaryExpression() {
  2717. const e = this.lookahead;
  2718. let t = this.inheritCoverGrammar(this.parseExponentiationExpression);
  2719. let s = !0;
  2720. let i = !0;
  2721. const r = e => {
  2722. e.value !== '&&' && e.value !== '||' || (i = !1), e.value === '??' && (s = !1);
  2723. };
  2724. const n = this.lookahead;
  2725. let a = this.binaryPrecedence(n);
  2726. if (a > 0) {
  2727. r(n), this.nextToken(), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2728. const o = [e, this.lookahead];
  2729. let u = t;
  2730. let h = this.isolateCoverGrammar(this.parseExponentiationExpression);
  2731. const c = [u, n.value, h];
  2732. const l = [a];
  2733. for (; a = this.binaryPrecedence(this.lookahead), !(a <= 0);) {
  2734. for ((s || this.lookahead.value !== '&&' && this.lookahead.value !== '||') && (i || this.lookahead.value !== '??') || this.throwUnexpectedToken(this.lookahead), r(this.lookahead); c.length > 2 && a <= l[l.length - 1];) {
  2735. h = c.pop();
  2736. const e = c.pop();
  2737. l.pop(), u = c.pop(), o.pop();
  2738. const t = o[o.length - 1];
  2739. const s = this.startNode(t, t.lineStart);
  2740. const i = e === '||' || e === '&&' || e === '??';
  2741. c.push(this.finalize(s, i ? new LogicalExpression(e, u, h) : new BinaryExpression(e, u, h)));
  2742. }
  2743. c.push(this.nextToken().value), l.push(a), o.push(this.lookahead), c.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
  2744. }
  2745. let p = c.length - 1;
  2746. t = c[p];
  2747. let m = o.pop();
  2748. for (; p > 1;) {
  2749. const e = o.pop();
  2750. const s = m && m.lineStart;
  2751. const i = this.startNode(e, s);
  2752. const r = c[p - 1];
  2753. const n = r === '||' || r === '&&' || r === '??';
  2754. t = this.finalize(i, n ? new LogicalExpression(r, c[p - 2], t) : new BinaryExpression(r, c[p - 2], t)), p -= 2, m = e;
  2755. }
  2756. }
  2757. return t;
  2758. }
  2759.  
  2760. parseConditionalExpression() {
  2761. const e = this.lookahead;
  2762. let t = this.inheritCoverGrammar(this.parseBinaryExpression);
  2763. if (this.match('?')) {
  2764. this.nextToken();
  2765. const s = this.context.allowIn;
  2766. this.context.allowIn = !0;
  2767. const i = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2768. this.context.allowIn = s, this.expect(':');
  2769. const r = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2770. t = this.finalize(this.startNode(e), new ConditionalExpression(t, i, r)), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2771. }
  2772. return t;
  2773. }
  2774.  
  2775. checkPatternParam(e, t) {
  2776. switch (t.type) {
  2777. case 'Identifier':
  2778. this.validateParam(e, t, t.name);
  2779. break;
  2780. case 'RestElement':
  2781. this.checkPatternParam(e, t.argument);
  2782. break;
  2783. case 'AssignmentPattern':
  2784. this.checkPatternParam(e, t.left);
  2785. break;
  2786. case 'ArrayPattern':
  2787. for (let s = 0; s < t.elements.length; s++) t.elements[s] !== null && this.checkPatternParam(e, t.elements[s]);
  2788. break;
  2789. case 'ObjectPattern':
  2790. for (let s = 0; s < t.properties.length; s++) {
  2791. const i = t.properties[s];
  2792. this.checkPatternParam(e, i.type === 'RestElement' ? i : i.value);
  2793. }
  2794. }
  2795. e.simple = e.simple && t instanceof Identifier;
  2796. }
  2797.  
  2798. reinterpretAsCoverFormalsList(e) {
  2799. let t = [e];
  2800. const s = {
  2801. simple: !0,
  2802. paramSet: {}
  2803. };
  2804. let i = !1;
  2805. switch (e.type) {
  2806. case 'Identifier':
  2807. break;
  2808. case ArrowParameterPlaceHolder:
  2809. t = e.params, i = e.async;
  2810. break;
  2811. default:
  2812. return null;
  2813. }
  2814. for (let e = 0; e < t.length; ++e) {
  2815. const r = t[e];
  2816. r.type === 'AssignmentPattern' ? r.right.type === 'YieldExpression' && (r.right.argument && this.throwUnexpectedToken(this.lookahead), r.right.type = 'Identifier', r.right.name = 'yield', delete r.right.argument, delete r.right.delegate) : i && r.type === 'Identifier' && r.name === 'await' && this.throwUnexpectedToken(this.lookahead), this.checkPatternParam(s, r), t[e] = r;
  2817. }
  2818. if (this.context.strict || !this.context.allowYield) {
  2819. for (let e = 0; e < t.length; ++e) {
  2820. t[e].type === 'YieldExpression' && this.throwUnexpectedToken(this.lookahead);
  2821. }
  2822. }
  2823. if (s.hasDuplicateParameterNames) {
  2824. const e = this.context.strict ? s.stricted : s.firstRestricted;
  2825. this.throwUnexpectedToken(e, Messages.DuplicateParameter);
  2826. }
  2827. return {
  2828. simple: s.simple,
  2829. params: t,
  2830. stricted: s.stricted,
  2831. firstRestricted: s.firstRestricted,
  2832. message: s.message
  2833. };
  2834. }
  2835.  
  2836. parseAssignmentExpression() {
  2837. let e;
  2838. if (!this.context.allowYield && this.matchKeyword('yield')) e = this.parseYieldExpression();
  2839. else {
  2840. const t = this.lookahead;
  2841. let s = t;
  2842. if (e = this.parseConditionalExpression(), s.type === 3 && s.lineNumber === this.lookahead.lineNumber && s.value === 'async' && (this.lookahead.type === 3 || this.matchKeyword('yield'))) {
  2843. const t = this.parsePrimaryExpression();
  2844. this.reinterpretExpressionAsPattern(t), e = {
  2845. type: ArrowParameterPlaceHolder,
  2846. params: [t],
  2847. async: !0
  2848. };
  2849. }
  2850. if (e.type === ArrowParameterPlaceHolder || this.match('=>')) {
  2851. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2852. const s = e.async;
  2853. const i = this.reinterpretAsCoverFormalsList(e);
  2854. if (i) {
  2855. this.hasLineTerminator && this.tolerateUnexpectedToken(this.lookahead), this.context.firstCoverInitializedNameError = null;
  2856. const r = this.context.strict;
  2857. const n = this.context.allowStrictDirective;
  2858. this.context.allowStrictDirective = i.simple;
  2859. const a = this.context.allowYield;
  2860. const o = this.context.isAsync;
  2861. this.context.allowYield = !0, this.context.isAsync = s;
  2862. const u = this.startNode(t);
  2863. let h;
  2864. if (this.expect('=>'), this.match('{')) {
  2865. const e = this.context.allowIn;
  2866. this.context.allowIn = !0, h = this.parseFunctionSourceElements(), this.context.allowIn = e;
  2867. } else h = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2868. const c = h.type !== 'BlockStatement';
  2869. this.context.strict && i.firstRestricted && this.throwUnexpectedToken(i.firstRestricted, i.message), this.context.strict && i.stricted && this.tolerateUnexpectedToken(i.stricted, i.message), e = this.finalize(u, new ArrowFunctionExpression(i.params, h, c, s)), this.context.strict = r, this.context.allowStrictDirective = n, this.context.allowYield = a, this.context.isAsync = o;
  2870. }
  2871. } else if (this.matchAssign()) {
  2872. if (this.context.isAssignmentTarget || this.tolerateError(Messages.InvalidLHSInAssignment), this.context.strict && e.type === 'Identifier') {
  2873. const t = e;
  2874. this.scanner.isRestrictedWord(t.name) && this.tolerateUnexpectedToken(s, Messages.StrictLHSAssignment), this.scanner.isStrictModeReservedWord(t.name) && this.tolerateUnexpectedToken(s, Messages.StrictReservedWord);
  2875. }
  2876. this.match('=') ? this.reinterpretExpressionAsPattern(e) : (this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1), s = this.nextToken();
  2877. const i = s.value;
  2878. const r = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2879. e = this.finalize(this.startNode(t), new AssignmentExpression(i, e, r)), this.context.firstCoverInitializedNameError = null;
  2880. }
  2881. }
  2882. return e;
  2883. }
  2884.  
  2885. parseExpression() {
  2886. const e = this.lookahead;
  2887. let t = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2888. if (this.match(',')) {
  2889. const s = [];
  2890. for (s.push(t); this.lookahead.type !== 2 && this.match(',');) this.nextToken(), s.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  2891. t = this.finalize(this.startNode(e), new SequenceExpression(s));
  2892. }
  2893. return t;
  2894. }
  2895.  
  2896. parseStatementListItem() {
  2897. let e;
  2898. if (this.context.isAssignmentTarget = !0, this.context.isBindingElement = !0, this.lookahead.type === 4) {
  2899. switch (this.lookahead.value) {
  2900. case 'export':
  2901. this.context.isModule || this.tolerateUnexpectedToken(this.lookahead, Messages.IllegalExportDeclaration), e = this.parseExportDeclaration();
  2902. break;
  2903. case 'import':
  2904. this.matchImportCall() ? e = this.parseExpressionStatement() : this.matchImportMeta() ? e = this.parseStatement() : (this.context.isModule || this.tolerateUnexpectedToken(this.lookahead, Messages.IllegalImportDeclaration), e = this.parseImportDeclaration());
  2905. break;
  2906. case 'const':
  2907. e = this.parseLexicalDeclaration({
  2908. inFor: !1
  2909. });
  2910. break;
  2911. case 'function':
  2912. e = this.parseFunctionDeclaration();
  2913. break;
  2914. case 'class':
  2915. e = this.parseClassDeclaration();
  2916. break;
  2917. case 'let':
  2918. e = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({
  2919. inFor: !1
  2920. }) : this.parseStatement();
  2921. break;
  2922. default:
  2923. e = this.parseStatement();
  2924. }
  2925. } else e = this.parseStatement();
  2926. return e;
  2927. }
  2928.  
  2929. parseBlock() {
  2930. const e = this.createNode();
  2931. this.expect('{');
  2932. const t = [];
  2933. for (; !this.match('}');) t.push(this.parseStatementListItem());
  2934. return this.expect('}'), this.finalize(e, new BlockStatement(t));
  2935. }
  2936.  
  2937. parseLexicalBinding(e, t) {
  2938. const s = this.createNode();
  2939. const i = this.parsePattern([], e);
  2940. this.context.strict && i.type === 'Identifier' && this.scanner.isRestrictedWord(i.name) && this.tolerateError(Messages.StrictVarName);
  2941. let r = null;
  2942. return e === 'const' ? this.matchKeyword('in') || this.matchContextualKeyword('of') || (this.match('=') ? (this.nextToken(), r = this.isolateCoverGrammar(this.parseAssignmentExpression)) : this.throwError(Messages.DeclarationMissingInitializer, 'const')) : (!t.inFor && i.type !== 'Identifier' || this.match('=')) && (this.expect('='), r = this.isolateCoverGrammar(this.parseAssignmentExpression)), this.finalize(s, new VariableDeclarator(i, r));
  2943. }
  2944.  
  2945. parseBindingList(e, t) {
  2946. const s = [this.parseLexicalBinding(e, t)];
  2947. for (; this.match(',');) this.nextToken(), s.push(this.parseLexicalBinding(e, t));
  2948. return s;
  2949. }
  2950.  
  2951. isLexicalDeclaration() {
  2952. const e = this.scanner.saveState();
  2953. this.scanner.scanComments();
  2954. const t = this.scanner.lex();
  2955. return this.scanner.restoreState(e), t.type === 3 || t.type === 7 && t.value === '[' || t.type === 7 && t.value === '{' || t.type === 4 && t.value === 'let' || t.type === 4 && t.value === 'yield';
  2956. }
  2957.  
  2958. parseLexicalDeclaration(e) {
  2959. const t = this.createNode();
  2960. const s = this.nextToken().value;
  2961. assert(s === 'let' || s === 'const', 'Lexical declaration must be either let or const');
  2962. const i = this.parseBindingList(s, e);
  2963. return this.consumeSemicolon(), this.finalize(t, new VariableDeclaration(i, s));
  2964. }
  2965.  
  2966. isInitializedProperty() {
  2967. const e = this.scanner.saveState();
  2968. this.scanner.scanComments();
  2969. const t = this.scanner.lex();
  2970. return this.scanner.restoreState(e), this.lookahead.type === 3 && t.value === '=';
  2971. }
  2972.  
  2973. isDeclaredProperty() {
  2974. const e = this.scanner.saveState();
  2975. this.scanner.scanComments();
  2976. const t = this.scanner.lex();
  2977. return this.scanner.restoreState(e), this.lookahead.type === 3 && t.value === ';' || this.lookahead.type === 3 && t.lineNumber !== this.startMarker.line;
  2978. }
  2979.  
  2980. parseBindingRestElement(e, t) {
  2981. const s = this.createNode();
  2982. this.expect('...');
  2983. const i = this.parsePattern(e, t);
  2984. return this.finalize(s, new RestElement(i));
  2985. }
  2986.  
  2987. parseArrayPattern(e, t) {
  2988. const s = this.createNode();
  2989. this.expect('[');
  2990. const i = [];
  2991. for (; !this.match(']');) {
  2992. if (this.match(',')) this.nextToken(), i.push(null);
  2993. else {
  2994. if (this.match('...')) {
  2995. i.push(this.parseBindingRestElement(e, t));
  2996. break;
  2997. }
  2998. i.push(this.parsePatternWithDefault(e, t)), this.match(']') || this.expect(',');
  2999. }
  3000. } return this.expect(']'), this.finalize(s, new ArrayPattern(i));
  3001. }
  3002.  
  3003. parsePropertyPattern(e, t) {
  3004. const s = this.createNode();
  3005. let i = !1;
  3006. let r = !1;
  3007. let n; let
  3008. a;
  3009. if (this.lookahead.type === 3) {
  3010. const i = this.lookahead;
  3011. n = this.parseVariableIdentifier();
  3012. const o = this.finalize(s, new Identifier(i.value));
  3013. if (this.match('=')) {
  3014. e.push(i), r = !0, this.nextToken();
  3015. const t = this.parseAssignmentExpression();
  3016. a = this.finalize(this.startNode(i), new AssignmentPattern(o, t));
  3017. } else this.match(':') ? (this.expect(':'), a = this.parsePatternWithDefault(e, t)) : (e.push(i), r = !0, a = o);
  3018. } else i = this.match('['), n = this.parseObjectPropertyKey(), this.expect(':'), a = this.parsePatternWithDefault(e, t);
  3019. return this.finalize(s, new Property('init', n, i, a, !1, r));
  3020. }
  3021.  
  3022. parseRestProperty(e) {
  3023. const t = this.createNode();
  3024. this.expect('...');
  3025. const s = this.parsePattern(e);
  3026. return this.match('=') && this.throwError(Messages.DefaultRestProperty), this.match('}') || this.throwError(Messages.PropertyAfterRestProperty), this.finalize(t, new RestElement(s));
  3027. }
  3028.  
  3029. parseObjectPattern(e, t) {
  3030. const s = this.createNode();
  3031. const i = [];
  3032. for (this.expect('{'); !this.match('}');) i.push(this.match('...') ? this.parseRestProperty(e) : this.parsePropertyPattern(e, t)), this.match('}') || this.expect(',');
  3033. return this.expect('}'), this.finalize(s, new ObjectPattern(i));
  3034. }
  3035.  
  3036. parsePattern(e, t) {
  3037. let s;
  3038. return this.match('[') ? s = this.parseArrayPattern(e, t) : this.match('{') ? s = this.parseObjectPattern(e, t) : (!this.matchKeyword('let') || t !== 'const' && t !== 'let' || this.tolerateUnexpectedToken(this.lookahead, Messages.LetInLexicalBinding), e.push(this.lookahead), s = this.parseVariableIdentifier(t)), s;
  3039. }
  3040.  
  3041. parsePatternWithDefault(e, t) {
  3042. const s = this.lookahead;
  3043. let i = this.parsePattern(e, t);
  3044. if (this.match('=')) {
  3045. this.nextToken();
  3046. const e = this.context.allowYield;
  3047. this.context.allowYield = !0;
  3048. const t = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3049. this.context.allowYield = e, i = this.finalize(this.startNode(s), new AssignmentPattern(i, t));
  3050. }
  3051. return i;
  3052. }
  3053.  
  3054. parseVariableIdentifier(e) {
  3055. const t = this.createNode();
  3056. const s = this.nextToken();
  3057. return s.type === 4 && s.value === 'yield' ? this.context.strict ? this.tolerateUnexpectedToken(s, Messages.StrictReservedWord) : this.context.allowYield || this.throwUnexpectedToken(s) : s.type !== 3 ? this.context.strict && s.type === 4 && this.scanner.isStrictModeReservedWord(s.value) ? this.tolerateUnexpectedToken(s, Messages.StrictReservedWord) : (this.context.strict || s.value !== 'let' || e !== 'var') && this.throwUnexpectedToken(s) : (this.context.isModule || this.context.isAsync) && s.type === 3 && s.value === 'await' && this.tolerateUnexpectedToken(s), this.finalize(t, new Identifier(s.value));
  3058. }
  3059.  
  3060. parseVariableDeclaration(e) {
  3061. const t = this.createNode();
  3062. const s = this.parsePattern([], 'var');
  3063. this.context.strict && s.type === 'Identifier' && this.scanner.isRestrictedWord(s.name) && this.tolerateError(Messages.StrictVarName);
  3064. let i = null;
  3065. return this.match('=') ? (this.nextToken(), i = this.isolateCoverGrammar(this.parseAssignmentExpression)) : s.type === 'Identifier' || e.inFor || this.expect('='), this.finalize(t, new VariableDeclarator(s, i));
  3066. }
  3067.  
  3068. parseVariableDeclarationList(e) {
  3069. const t = {
  3070. inFor: e.inFor
  3071. };
  3072. const s = [];
  3073. for (s.push(this.parseVariableDeclaration(t)); this.match(',');) this.nextToken(), s.push(this.parseVariableDeclaration(t));
  3074. return s;
  3075. }
  3076.  
  3077. parseVariableStatement() {
  3078. const e = this.createNode();
  3079. this.expectKeyword('var');
  3080. const t = this.parseVariableDeclarationList({
  3081. inFor: !1
  3082. });
  3083. return this.consumeSemicolon(), this.finalize(e, new VariableDeclaration(t, 'var'));
  3084. }
  3085.  
  3086. parseEmptyStatement() {
  3087. const e = this.createNode();
  3088. return this.expect(';'), this.finalize(e, new EmptyStatement());
  3089. }
  3090.  
  3091. parseExpressionStatement() {
  3092. const e = this.createNode();
  3093. const t = this.parseExpression();
  3094. return this.consumeSemicolon(), this.finalize(e, new ExpressionStatement(t));
  3095. }
  3096.  
  3097. parseIfClause() {
  3098. return this.context.strict && this.matchKeyword('function') && this.tolerateError(Messages.StrictFunction), this.parseStatement();
  3099. }
  3100.  
  3101. parseIfStatement() {
  3102. const e = this.createNode();
  3103. let t; let
  3104. s = null;
  3105. this.expectKeyword('if'), this.expect('(');
  3106. const i = this.parseExpression();
  3107. return !this.match(')') && this.config.tolerant ? (this.tolerateUnexpectedToken(this.nextToken()), t = this.finalize(this.createNode(), new EmptyStatement())) : (this.expect(')'), t = this.parseIfClause(), this.matchKeyword('else') && (this.nextToken(), s = this.parseIfClause())), this.finalize(e, new IfStatement(i, t, s));
  3108. }
  3109.  
  3110. parseDoWhileStatement() {
  3111. const e = this.createNode();
  3112. this.expectKeyword('do'), this.tolerateInvalidLoopStatement();
  3113. const t = this.context.inIteration;
  3114. this.context.inIteration = !0;
  3115. const s = this.parseStatement();
  3116. this.context.inIteration = t, this.expectKeyword('while'), this.expect('(');
  3117. const i = this.parseExpression();
  3118. return !this.match(')') && this.config.tolerant ? this.tolerateUnexpectedToken(this.nextToken()) : (this.expect(')'), this.match(';') && this.nextToken()), this.finalize(e, new DoWhileStatement(s, i));
  3119. }
  3120.  
  3121. parseWhileStatement() {
  3122. const e = this.createNode();
  3123. let t;
  3124. this.expectKeyword('while'), this.expect('(');
  3125. const s = this.parseExpression();
  3126. if (!this.match(')') && this.config.tolerant) this.tolerateUnexpectedToken(this.nextToken()), t = this.finalize(this.createNode(), new EmptyStatement());
  3127. else {
  3128. this.expect(')');
  3129. const e = this.context.inIteration;
  3130. this.context.inIteration = !0, t = this.parseStatement(), this.context.inIteration = e;
  3131. }
  3132. return this.finalize(e, new WhileStatement(s, t));
  3133. }
  3134.  
  3135. parseForStatement() {
  3136. let e; let t; let s = null;
  3137. let i = null;
  3138. let r = null;
  3139. let n = !0;
  3140. let a = !1;
  3141. const o = this.createNode();
  3142. if (this.expectKeyword('for'), this.matchContextualKeyword('await') && (this.context.isAsync || this.tolerateUnexpectedToken(this.lookahead), a = !0, this.nextToken()), this.expect('('), this.match(';')) this.nextToken();
  3143. else if (this.matchKeyword('var')) {
  3144. s = this.createNode(), this.nextToken();
  3145. const i = this.context.allowIn;
  3146. this.context.allowIn = !1;
  3147. const r = this.parseVariableDeclarationList({
  3148. inFor: !0
  3149. });
  3150. if (this.context.allowIn = i, !a && r.length === 1 && this.matchKeyword('in')) {
  3151. const i = r[0];
  3152. i.init && (i.id.type === 'ArrayPattern' || i.id.type === 'ObjectPattern' || this.context.strict) && this.tolerateError(Messages.ForInOfLoopInitializer, 'for-in'), s = this.finalize(s, new VariableDeclaration(r, 'var')), this.nextToken(), e = s, t = this.parseExpression(), s = null;
  3153. } else r.length === 1 && r[0].init === null && this.matchContextualKeyword('of') ? (s = this.finalize(s, new VariableDeclaration(r, 'var')), this.nextToken(), e = s, t = this.parseAssignmentExpression(), s = null, n = !1) : (s = this.finalize(s, new VariableDeclaration(r, 'var')), this.expect(';'));
  3154. } else if (this.matchKeyword('const') || this.matchKeyword('let')) {
  3155. s = this.createNode();
  3156. const i = this.nextToken().value;
  3157. if (this.context.strict || this.lookahead.value !== 'in') {
  3158. const r = this.context.allowIn;
  3159. this.context.allowIn = !1;
  3160. const a = this.parseBindingList(i, {
  3161. inFor: !0
  3162. });
  3163. this.context.allowIn = r, a.length === 1 && a[0].init === null && this.matchKeyword('in') ? (s = this.finalize(s, new VariableDeclaration(a, i)), this.nextToken(), e = s, t = this.parseExpression(), s = null) : a.length === 1 && a[0].init === null && this.matchContextualKeyword('of') ? (s = this.finalize(s, new VariableDeclaration(a, i)), this.nextToken(), e = s, t = this.parseAssignmentExpression(), s = null, n = !1) : (this.consumeSemicolon(), s = this.finalize(s, new VariableDeclaration(a, i)));
  3164. } else s = this.finalize(s, new Identifier(i)), this.nextToken(), e = s, t = this.parseExpression(), s = null;
  3165. } else {
  3166. const i = this.lookahead;
  3167. const r = this.context.isBindingElement;
  3168. const a = this.context.isAssignmentTarget;
  3169. const o = this.context.firstCoverInitializedNameError;
  3170. const u = this.context.allowIn;
  3171. if (this.context.allowIn = !1, s = this.inheritCoverGrammar(this.parseAssignmentExpression), this.context.allowIn = u, this.matchKeyword('in')) this.context.isAssignmentTarget && s.type !== 'AssignmentExpression' || this.tolerateError(Messages.InvalidLHSInForIn), this.nextToken(), this.reinterpretExpressionAsPattern(s), e = s, t = this.parseExpression(), s = null;
  3172. else if (this.matchContextualKeyword('of')) this.context.isAssignmentTarget && s.type !== 'AssignmentExpression' || this.tolerateError(Messages.InvalidLHSInForLoop), this.nextToken(), this.reinterpretExpressionAsPattern(s), e = s, t = this.parseAssignmentExpression(), s = null, n = !1;
  3173. else {
  3174. if (this.context.isBindingElement = r, this.context.isAssignmentTarget = a, this.context.firstCoverInitializedNameError = o, this.match(',')) {
  3175. const e = [s];
  3176. for (; this.match(',');) this.nextToken(), e.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  3177. s = this.finalize(this.startNode(i), new SequenceExpression(e));
  3178. }
  3179. this.expect(';');
  3180. }
  3181. }
  3182. let u;
  3183. if (void 0 === e && (this.match(';') || (i = this.isolateCoverGrammar(this.parseExpression)), this.expect(';'), this.match(')') || (r = this.isolateCoverGrammar(this.parseExpression))), !this.match(')') && this.config.tolerant) this.tolerateUnexpectedToken(this.nextToken()), u = this.finalize(this.createNode(), new EmptyStatement());
  3184. else {
  3185. this.expect(')'), this.tolerateInvalidLoopStatement();
  3186. const e = this.context.inIteration;
  3187. this.context.inIteration = !0, u = this.isolateCoverGrammar(this.parseStatement), this.context.inIteration = e;
  3188. }
  3189. return void 0 === e ? this.finalize(o, new ForStatement(s, i, r, u)) : n ? this.finalize(o, new ForInStatement(e, t, u)) : this.finalize(o, new ForOfStatement(e, t, u, a));
  3190. }
  3191.  
  3192. parseContinueStatement() {
  3193. const e = this.createNode();
  3194. this.expectKeyword('continue');
  3195. let t = null;
  3196. if (this.lookahead.type === 3 && !this.hasLineTerminator) {
  3197. const e = this.parseVariableIdentifier();
  3198. t = e;
  3199. const s = `$${e.name}`;
  3200. Object.prototype.hasOwnProperty.call(this.context.labelSet, s) || this.throwError(Messages.UnknownLabel, e.name);
  3201. }
  3202. return this.consumeSemicolon(), t !== null || this.context.inIteration || this.throwError(Messages.IllegalContinue), this.finalize(e, new ContinueStatement(t));
  3203. }
  3204.  
  3205. parseBreakStatement() {
  3206. const e = this.createNode();
  3207. this.expectKeyword('break');
  3208. let t = null;
  3209. if (this.lookahead.type === 3 && !this.hasLineTerminator) {
  3210. const e = this.parseVariableIdentifier();
  3211. const s = `$${e.name}`;
  3212. Object.prototype.hasOwnProperty.call(this.context.labelSet, s) || this.throwError(Messages.UnknownLabel, e.name), t = e;
  3213. }
  3214. return this.consumeSemicolon(), t !== null || this.context.inIteration || this.context.inSwitch || this.throwError(Messages.IllegalBreak), this.finalize(e, new BreakStatement(t));
  3215. }
  3216.  
  3217. parseReturnStatement() {
  3218. this.context.inFunctionBody || this.tolerateError(Messages.IllegalReturn);
  3219. const e = this.createNode();
  3220. this.expectKeyword('return');
  3221. const t = !this.match(';') && !this.match('}') && !this.hasLineTerminator && this.lookahead.type !== 2 || this.lookahead.type === 8 || this.lookahead.type === 10 ? this.parseExpression() : null;
  3222. return this.consumeSemicolon(), this.finalize(e, new ReturnStatement(t));
  3223. }
  3224.  
  3225. parseWithStatement() {
  3226. this.context.strict && this.tolerateError(Messages.StrictModeWith);
  3227. const e = this.createNode();
  3228. let t;
  3229. this.expectKeyword('with'), this.expect('(');
  3230. const s = this.parseExpression();
  3231. return !this.match(')') && this.config.tolerant ? (this.tolerateUnexpectedToken(this.nextToken()), t = this.finalize(this.createNode(), new EmptyStatement())) : (this.expect(')'), t = this.parseStatement()), this.finalize(e, new WithStatement(s, t));
  3232. }
  3233.  
  3234. parseSwitchCase() {
  3235. const e = this.createNode();
  3236. let t;
  3237. this.matchKeyword('default') ? (this.nextToken(), t = null) : (this.expectKeyword('case'), t = this.parseExpression()), this.expect(':');
  3238. const s = [];
  3239. for (; !(this.match('}') || this.matchKeyword('default') || this.matchKeyword('case'));) s.push(this.parseStatementListItem());
  3240. return this.finalize(e, new SwitchCase(t, s));
  3241. }
  3242.  
  3243. parseSwitchStatement() {
  3244. const e = this.createNode();
  3245. this.expectKeyword('switch'), this.expect('(');
  3246. const t = this.parseExpression();
  3247. this.expect(')');
  3248. const s = this.context.inSwitch;
  3249. this.context.inSwitch = !0;
  3250. const i = [];
  3251. let r = !1;
  3252. for (this.expect('{'); !this.match('}');) {
  3253. const e = this.parseSwitchCase();
  3254. e.test === null && (r && this.throwError(Messages.MultipleDefaultsInSwitch), r = !0), i.push(e);
  3255. }
  3256. return this.expect('}'), this.context.inSwitch = s, this.finalize(e, new SwitchStatement(t, i));
  3257. }
  3258.  
  3259. parseLabelledStatement() {
  3260. const e = this.createNode();
  3261. const t = this.parseExpression();
  3262. let s;
  3263. if (t.type === 'Identifier' && this.match(':')) {
  3264. this.nextToken();
  3265. const e = t;
  3266. const i = `$${e.name}`;
  3267. let r;
  3268. if (Object.prototype.hasOwnProperty.call(this.context.labelSet, i) && this.throwError(Messages.Redeclaration, 'Label', e.name), this.context.labelSet[i] = !0, this.matchKeyword('class')) this.tolerateUnexpectedToken(this.lookahead), r = this.parseClassDeclaration();
  3269. else if (this.matchKeyword('function')) {
  3270. const e = this.lookahead;
  3271. const t = this.parseFunctionDeclaration();
  3272. this.context.strict ? this.tolerateUnexpectedToken(e, Messages.StrictFunction) : t.generator && this.tolerateUnexpectedToken(e, Messages.GeneratorInLegacyContext), r = t;
  3273. } else r = this.parseStatement();
  3274. delete this.context.labelSet[i], s = new LabeledStatement(e, r);
  3275. } else this.consumeSemicolon(), s = new ExpressionStatement(t);
  3276. return this.finalize(e, s);
  3277. }
  3278.  
  3279. parseThrowStatement() {
  3280. const e = this.createNode();
  3281. this.expectKeyword('throw'), this.hasLineTerminator && this.throwError(Messages.NewlineAfterThrow);
  3282. const t = this.parseExpression();
  3283. return this.consumeSemicolon(), this.finalize(e, new ThrowStatement(t));
  3284. }
  3285.  
  3286. parseCatchClause() {
  3287. const e = this.createNode();
  3288. this.expectKeyword('catch');
  3289. let t = null;
  3290. if (this.match('(')) {
  3291. this.expect('('), this.match(')') && this.throwUnexpectedToken(this.lookahead);
  3292. const e = [];
  3293. t = this.parsePattern(e);
  3294. const s = {};
  3295. for (let t = 0; t < e.length; t++) {
  3296. const i = `$${e[t].value}`;
  3297. Object.prototype.hasOwnProperty.call(s, i) && this.tolerateError(Messages.DuplicateBinding, e[t].value), s[i] = !0;
  3298. }
  3299. this.context.strict && t.type === 'Identifier' && this.scanner.isRestrictedWord(t.name) && this.tolerateError(Messages.StrictCatchVariable), this.expect(')');
  3300. }
  3301. const s = this.parseBlock();
  3302. return this.finalize(e, new CatchClause(t, s));
  3303. }
  3304.  
  3305. parseFinallyClause() {
  3306. return this.expectKeyword('finally'), this.parseBlock();
  3307. }
  3308.  
  3309. parseTryStatement() {
  3310. const e = this.createNode();
  3311. this.expectKeyword('try');
  3312. const t = this.parseBlock();
  3313. const s = this.matchKeyword('catch') ? this.parseCatchClause() : null;
  3314. const i = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
  3315. return s || i || this.throwError(Messages.NoCatchOrFinally), this.finalize(e, new TryStatement(t, s, i));
  3316. }
  3317.  
  3318. parseDebuggerStatement() {
  3319. const e = this.createNode();
  3320. return this.expectKeyword('debugger'), this.consumeSemicolon(), this.finalize(e, new DebuggerStatement());
  3321. }
  3322.  
  3323. parseStatement() {
  3324. let e;
  3325. switch (this.lookahead.type) {
  3326. case 1:
  3327. case 5:
  3328. case 6:
  3329. case 8:
  3330. case 10:
  3331. case 9:
  3332. e = this.parseExpressionStatement();
  3333. break;
  3334. case 7:
  3335. const t = this.lookahead.value;
  3336. e = t === '{' ? this.parseBlock() : t === '(' ? this.parseExpressionStatement() : t === ';' ? this.parseEmptyStatement() : this.parseExpressionStatement();
  3337. break;
  3338. case 3:
  3339. e = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement();
  3340. break;
  3341. case 4:
  3342. switch (this.lookahead.value) {
  3343. case 'break':
  3344. e = this.parseBreakStatement();
  3345. break;
  3346. case 'continue':
  3347. e = this.parseContinueStatement();
  3348. break;
  3349. case 'debugger':
  3350. e = this.parseDebuggerStatement();
  3351. break;
  3352. case 'do':
  3353. e = this.parseDoWhileStatement();
  3354. break;
  3355. case 'for':
  3356. e = this.parseForStatement();
  3357. break;
  3358. case 'function':
  3359. e = this.parseFunctionDeclaration();
  3360. break;
  3361. case 'if':
  3362. e = this.parseIfStatement();
  3363. break;
  3364. case 'return':
  3365. e = this.parseReturnStatement();
  3366. break;
  3367. case 'switch':
  3368. e = this.parseSwitchStatement();
  3369. break;
  3370. case 'throw':
  3371. e = this.parseThrowStatement();
  3372. break;
  3373. case 'try':
  3374. e = this.parseTryStatement();
  3375. break;
  3376. case 'var':
  3377. e = this.parseVariableStatement();
  3378. break;
  3379. case 'while':
  3380. e = this.parseWhileStatement();
  3381. break;
  3382. case 'with':
  3383. e = this.parseWithStatement();
  3384. break;
  3385. default:
  3386. e = this.parseExpressionStatement();
  3387. }
  3388. break;
  3389. default:
  3390. e = this.throwUnexpectedToken(this.lookahead);
  3391. }
  3392. return e;
  3393. }
  3394.  
  3395. parseFunctionSourceElements() {
  3396. const e = this.createNode();
  3397. this.expect('{');
  3398. const t = this.parseDirectivePrologues();
  3399. const s = this.context.labelSet;
  3400. const i = this.context.inIteration;
  3401. const r = this.context.inSwitch;
  3402. const n = this.context.inFunctionBody;
  3403. for (this.context.labelSet = {}, this.context.inIteration = !1, this.context.inSwitch = !1, this.context.inFunctionBody = !0; this.lookahead.type !== 2 && !this.match('}');) t.push(this.parseStatementListItem());
  3404. return this.expect('}'), this.context.labelSet = s, this.context.inIteration = i, this.context.inSwitch = r, this.context.inFunctionBody = n, this.finalize(e, new BlockStatement(t));
  3405. }
  3406.  
  3407. validateParam(e, t, s) {
  3408. const i = `$${s}`;
  3409. this.context.strict ? (this.scanner.isRestrictedWord(s) && (e.stricted = t, e.message = Messages.StrictParamName), Object.prototype.hasOwnProperty.call(e.paramSet, i) && (e.stricted = t, e.hasDuplicateParameterNames = !0)) : e.firstRestricted || (this.scanner.isRestrictedWord(s) ? (e.firstRestricted = t, e.message = Messages.StrictParamName) : this.scanner.isStrictModeReservedWord(s) ? (e.firstRestricted = t, e.message = Messages.StrictReservedWord) : Object.prototype.hasOwnProperty.call(e.paramSet, i) && (e.stricted = t, e.hasDuplicateParameterNames = !0)), typeof Object.defineProperty === 'function' ? Object.defineProperty(e.paramSet, i, {
  3410. value: !0,
  3411. enumerable: !0,
  3412. writable: !0,
  3413. configurable: !0
  3414. }) : e.paramSet[i] = !0;
  3415. }
  3416.  
  3417. parseRestElement(e) {
  3418. const t = this.createNode();
  3419. this.expect('...');
  3420. const s = this.parsePattern(e);
  3421. return this.match('=') && this.throwError(Messages.DefaultRestParameter), this.match(')') || this.throwError(Messages.ParameterAfterRestParameter), this.finalize(t, new RestElement(s));
  3422. }
  3423.  
  3424. parseFormalParameter(e) {
  3425. const t = [];
  3426. const s = this.match('...') ? this.parseRestElement(t) : this.parsePatternWithDefault(t);
  3427. for (let s = 0; s < t.length; s++) this.validateParam(e, t[s], t[s].value);
  3428. e.simple = e.simple && s instanceof Identifier, e.params.push(s);
  3429. }
  3430.  
  3431. parseFormalParameters(e) {
  3432. const t = {
  3433. simple: !0,
  3434. hasDuplicateParameterNames: !1,
  3435. params: [],
  3436. firstRestricted: e
  3437. };
  3438. if (this.expect('('), !this.match(')')) for (t.paramSet = {}; this.lookahead.type !== 2 && (this.parseFormalParameter(t), !this.match(')')) && (this.expect(','), !this.match(')')););
  3439. return this.expect(')'), t.hasDuplicateParameterNames && (this.context.strict || this.context.isAsync || !t.simple) && this.throwError(Messages.DuplicateParameter), {
  3440. simple: t.simple,
  3441. params: t.params,
  3442. stricted: t.stricted,
  3443. firstRestricted: t.firstRestricted,
  3444. message: t.message
  3445. };
  3446. }
  3447.  
  3448. matchAsyncFunction() {
  3449. let e = this.matchContextualKeyword('async');
  3450. if (e) {
  3451. const t = this.scanner.saveState();
  3452. this.scanner.scanComments();
  3453. const s = this.scanner.lex();
  3454. this.scanner.restoreState(t), e = t.lineNumber === s.lineNumber && s.type === 4 && s.value === 'function';
  3455. }
  3456. return e;
  3457. }
  3458.  
  3459. parseFunctionDeclaration(e) {
  3460. const t = this.createNode();
  3461. const s = this.matchContextualKeyword('async');
  3462. s && (this.context.inIteration && this.tolerateError(Messages.AsyncFunctionInSingleStatementContext), this.nextToken()), this.expectKeyword('function');
  3463. const i = this.match('*');
  3464. let r;
  3465. i && this.nextToken();
  3466. let n = null;
  3467. let a = null;
  3468. if (!e || !this.match('(')) {
  3469. const e = this.lookahead;
  3470. n = this.parseVariableIdentifier(), this.context.strict ? this.scanner.isRestrictedWord(e.value) && this.tolerateUnexpectedToken(e, Messages.StrictFunctionName) : this.scanner.isRestrictedWord(e.value) ? (a = e, r = Messages.StrictFunctionName) : this.scanner.isStrictModeReservedWord(e.value) && (a = e, r = Messages.StrictReservedWord);
  3471. }
  3472. const o = this.context.isAsync;
  3473. const u = this.context.allowYield;
  3474. this.context.isAsync = s, this.context.allowYield = !i;
  3475. const h = this.parseFormalParameters(a);
  3476. const c = h.params;
  3477. const l = h.stricted;
  3478. a = h.firstRestricted, h.message && (r = h.message);
  3479. const p = this.context.strict;
  3480. const m = this.context.allowStrictDirective;
  3481. this.context.allowStrictDirective = h.simple;
  3482. const d = this.parseFunctionSourceElements();
  3483. return this.context.strict && a && this.throwUnexpectedToken(a, r), this.context.strict && l && this.tolerateUnexpectedToken(l, r), this.context.strict = p, this.context.allowStrictDirective = m, this.context.isAsync = o, this.context.allowYield = u, s ? this.finalize(t, new AsyncFunctionDeclaration(n, c, d, i)) : this.finalize(t, new FunctionDeclaration(n, c, d, i));
  3484. }
  3485.  
  3486. parseFunctionExpression() {
  3487. const e = this.createNode();
  3488. const t = this.matchContextualKeyword('async');
  3489. t && this.nextToken(), this.expectKeyword('function');
  3490. const s = this.match('*');
  3491. let i;
  3492. s && this.nextToken();
  3493. let r; let
  3494. n = null;
  3495. const a = this.context.isAsync;
  3496. const o = this.context.allowYield;
  3497. if (this.context.isAsync = t, this.context.allowYield = !s, !this.match('(')) {
  3498. const e = this.lookahead;
  3499. n = this.context.strict || s || !this.matchKeyword('yield') ? this.parseVariableIdentifier() : this.parseIdentifierName(), this.context.strict ? this.scanner.isRestrictedWord(e.value) && this.tolerateUnexpectedToken(e, Messages.StrictFunctionName) : this.scanner.isRestrictedWord(e.value) ? (r = e, i = Messages.StrictFunctionName) : this.scanner.isStrictModeReservedWord(e.value) && (r = e, i = Messages.StrictReservedWord);
  3500. }
  3501. const u = this.parseFormalParameters(r);
  3502. const h = u.params;
  3503. const c = u.stricted;
  3504. r = u.firstRestricted, u.message && (i = u.message);
  3505. const l = this.context.strict;
  3506. const p = this.context.allowStrictDirective;
  3507. this.context.allowStrictDirective = u.simple;
  3508. const m = this.parseFunctionSourceElements();
  3509. return this.context.strict && r && this.throwUnexpectedToken(r, i), this.context.strict && c && this.tolerateUnexpectedToken(c, i), this.context.strict = l, this.context.allowStrictDirective = p, this.context.isAsync = a, this.context.allowYield = o, this.finalize(e, new FunctionExpression(n, h, m, s, t));
  3510. }
  3511.  
  3512. parseDirective() {
  3513. const e = this.lookahead;
  3514. const t = this.createNode();
  3515. const s = this.parseExpression();
  3516. const i = s.type === 'Literal' ? this.getTokenRaw(e).slice(1, -1) : null;
  3517. return this.consumeSemicolon(), this.finalize(t, i ? new Directive(s, i) : new ExpressionStatement(s));
  3518. }
  3519.  
  3520. parseDirectivePrologues() {
  3521. let e = null;
  3522. const t = [];
  3523. for (;;) {
  3524. const s = this.lookahead;
  3525. if (s.type !== 8) break;
  3526. const i = this.parseDirective();
  3527. t.push(i);
  3528. const r = i.directive;
  3529. if (typeof r !== 'string') break;
  3530. r === 'use strict' ? (this.context.strict = !0, e && this.tolerateUnexpectedToken(e, Messages.StrictOctalLiteral), this.context.allowStrictDirective || this.tolerateUnexpectedToken(s, Messages.IllegalLanguageModeDirective)) : !e && s.octal && (e = s);
  3531. }
  3532. return t;
  3533. }
  3534.  
  3535. qualifiedPropertyName(e) {
  3536. switch (e.type) {
  3537. case 3:
  3538. case 8:
  3539. case 1:
  3540. case 5:
  3541. case 6:
  3542. case 4:
  3543. return !0;
  3544. case 7:
  3545. return e.value === '[' || e.value === '#';
  3546. }
  3547. return !1;
  3548. }
  3549.  
  3550. parseGetterMethod() {
  3551. const e = this.createNode();
  3552. const t = this.context.allowYield;
  3553. this.context.allowYield = !0;
  3554. const s = this.parseFormalParameters();
  3555. s.params.length > 0 && this.tolerateError(Messages.BadGetterArity);
  3556. const i = this.parsePropertyMethod(s);
  3557. return this.context.allowYield = t, this.finalize(e, new FunctionExpression(null, s.params, i, false, !1));
  3558. }
  3559.  
  3560. parseSetterMethod() {
  3561. const e = this.createNode();
  3562. const t = this.context.allowYield;
  3563. this.context.allowYield = !0;
  3564. const s = this.parseFormalParameters();
  3565. s.params.length !== 1 ? this.tolerateError(Messages.BadSetterArity) : s.params[0] instanceof RestElement && this.tolerateError(Messages.BadSetterRestParameter);
  3566. const i = this.parsePropertyMethod(s);
  3567. return this.context.allowYield = t, this.finalize(e, new FunctionExpression(null, s.params, i, false, !1));
  3568. }
  3569.  
  3570. parseGeneratorMethod(e) {
  3571. const t = this.createNode();
  3572. const s = this.context.allowYield;
  3573. this.context.allowYield = !0;
  3574. const i = this.parseFormalParameters();
  3575. this.context.allowYield = !1;
  3576. const r = this.parsePropertyMethod(i);
  3577. return this.context.allowYield = s, this.finalize(t, new FunctionExpression(null, i.params, r, !0, e));
  3578. }
  3579.  
  3580. isStartOfExpression() {
  3581. let e = !0;
  3582. const t = this.lookahead.value;
  3583. switch (this.lookahead.type) {
  3584. case 7:
  3585. e = t === '[' || t === '(' || t === '{' || t === '+' || t === '-' || t === '!' || t === '~' || t === '++' || t === '--' || t === '/' || t === '/=';
  3586. break;
  3587. case 4:
  3588. e = t === 'class' || t === 'delete' || t === 'function' || t === 'let' || t === 'new' || t === 'super' || t === 'this' || t === 'typeof' || t === 'void' || t === 'yield';
  3589. }
  3590. return e;
  3591. }
  3592.  
  3593. parseYieldExpression() {
  3594. const e = this.createNode();
  3595. this.expectKeyword('yield');
  3596. let t = null;
  3597. let s = !1;
  3598. if (!this.hasLineTerminator) {
  3599. const e = this.context.allowYield;
  3600. this.context.allowYield = !1, s = this.match('*'), s ? (this.nextToken(), t = this.parseAssignmentExpression()) : this.isStartOfExpression() && (t = this.parseAssignmentExpression()), this.context.allowYield = e;
  3601. }
  3602. return this.finalize(e, new YieldExpression(t, s));
  3603. }
  3604.  
  3605. parseStaticBlock() {
  3606. const e = this.createNode();
  3607. this.expect('{');
  3608. const t = [];
  3609. for (; !this.match('}');) t.push(this.parseStatementListItem());
  3610. return this.expect('}'), this.finalize(e, new StaticBlock(t));
  3611. }
  3612.  
  3613. parseDecorator() {
  3614. const e = this.createNode();
  3615. this.expect('@');
  3616. const t = this.context.strict;
  3617. const s = this.context.allowYield;
  3618. const i = this.context.isAsync;
  3619. this.context.strict = !1, this.context.allowYield = !0, this.context.isAsync = !1;
  3620. const r = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  3621. return this.context.strict = t, this.context.allowYield = s, this.context.isAsync = i, this.match(';') && this.throwError(Messages.NoSemicolonAfterDecorator), this.finalize(e, new Decorator(r));
  3622. }
  3623.  
  3624. parseDecorators() {
  3625. let e = null;
  3626. for (; this.match('@');) e == null && (e = []), e.push(this.parseDecorator());
  3627. return e;
  3628. }
  3629.  
  3630. parseClassElement(e) {
  3631. let t = this.lookahead;
  3632. const s = this.createNode();
  3633. const i = this.context.inConstructor;
  3634. let r = '';
  3635. let n = null;
  3636. let a = null;
  3637. let o = !1;
  3638. let u = !1;
  3639. let h = !1;
  3640. let c = !1;
  3641. let l = !1;
  3642. let p = !1;
  3643. const m = this.parseDecorators();
  3644. if (m && (t = this.lookahead), this.match('*')) this.nextToken();
  3645. else {
  3646. o = this.match('['), this.match('#') && (p = !0, this.nextToken(), t = this.lookahead), n = this.parseObjectPropertyKey(p);
  3647. const e = n;
  3648. if (this.context.inConstructor = t.type === 3 && t.value === 'constructor', e.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*')) && (t = this.lookahead, h = !0, o = this.match('['), this.match('*') ? (this.nextToken(), this.match('#') && (p = !0, this.nextToken(), t = this.lookahead)) : (this.match('#') && (p = !0, this.nextToken(), t = this.lookahead), n = this.parseObjectPropertyKey(p))), e.name === 'static' && this.match('{')) return this.parseStaticBlock();
  3649. if (t.type === 3 && !this.hasLineTerminator && t.value === 'async') {
  3650. const e = this.lookahead.value;
  3651. e !== ':' && e !== '(' && (c = !0, l = this.match('*'), l && this.nextToken(), t = this.lookahead, o = this.match('['), this.match('*') ? (this.nextToken(), this.match('#') && (p = !0, this.nextToken())) : (this.match('#') && (p = !0, this.nextToken(), t = this.lookahead), n = this.parseObjectPropertyKey(p)), t.type !== 3 || t.value !== 'constructor' || h || this.tolerateUnexpectedToken(t, Messages.ConstructorIsAsync));
  3652. }
  3653. }
  3654. t.type === 3 && t.value === 'constructor' && p && this.tolerateUnexpectedToken(t, Messages.ConstructorIsPrivate);
  3655. const d = this.qualifiedPropertyName(this.lookahead);
  3656. if (t.type === 3 || t.type === 8 ? t.value === 'get' && d ? (r = 'get', this.match('#') && (p = !0, this.nextToken(), t = this.lookahead), o = this.match('['), n = this.parseObjectPropertyKey(p), this.context.allowYield = !1, a = this.parseGetterMethod()) : t.value === 'set' && d ? (r = 'set', this.match('#') && (p = !0, this.nextToken(), t = this.lookahead), o = this.match('['), n = this.parseObjectPropertyKey(p), a = this.parseSetterMethod()) : this.match('(') || (r = 'property', o = !1, this.match('=') && (this.nextToken(), a = this.isolateCoverGrammar(this.parseAssignmentExpression))) : t.type === 7 && t.value === '*' && d ? (r = 'init', o = this.match('['), n = this.parseObjectPropertyKey(p), a = this.parseGeneratorMethod(c), u = !0) : t.type !== 7 || t.value !== '[' || this.match('(') || (r = 'property', o = !0, this.match('=') && (this.nextToken(), a = this.isolateCoverGrammar(this.parseAssignmentExpression))), !r && n && this.match('(')) {
  3657. const e = this.context.inClassConstructor;
  3658. this.context.inClassConstructor = t.value === 'constructor', r = 'init', a = c ? this.parsePropertyMethodAsyncFunction(l) : this.parsePropertyMethodFunction(l), this.context.inClassConstructor = e, u = !0;
  3659. }
  3660. return r || this.throwUnexpectedToken(this.lookahead), r === 'init' && (r = 'method'), o || (h && this.isPropertyKey(n, 'prototype') && this.throwUnexpectedToken(t, Messages.StaticPrototype), !h && this.isPropertyKey(n, 'constructor') && ((r !== 'method' || !u || a && a.generator) && this.throwUnexpectedToken(t, Messages.ConstructorSpecialMethod), e.value ? this.throwUnexpectedToken(t, Messages.DuplicateConstructor) : e.value = !0, r = 'constructor')), this.context.inConstructor = i, r === 'property' ? (this.consumeSemicolon(), this.finalize(s, new PropertyDefinition(n, o, a, h, m))) : this.finalize(s, new MethodDefinition(n, o, a, r, h, m));
  3661. }
  3662.  
  3663. parseClassElementList() {
  3664. const e = [];
  3665. const t = {
  3666. value: !1
  3667. };
  3668. for (this.expect('{'); !this.match('}');) this.match(';') ? this.nextToken() : e.push(this.parseClassElement(t));
  3669. return this.expect('}'), e;
  3670. }
  3671.  
  3672. parseClassBody() {
  3673. const e = this.createNode();
  3674. const t = this.parseClassElementList();
  3675. return this.finalize(e, new ClassBody(t));
  3676. }
  3677.  
  3678. parseClassDeclaration(e) {
  3679. const t = this.createNode();
  3680. const s = this.context.strict;
  3681. const i = this.context.allowSuper;
  3682. this.context.strict = !0, this.expectKeyword('class');
  3683. const r = e && this.lookahead.type !== 3 ? null : this.parseVariableIdentifier();
  3684. let n = null;
  3685. this.matchKeyword('extends') && (this.nextToken(), n = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall), this.context.allowSuper = !0);
  3686. const a = this.parseClassBody();
  3687. return this.context.allowSuper = i, this.context.strict = s, this.finalize(t, new ClassDeclaration(r, n, a, this.context.decorators));
  3688. }
  3689.  
  3690. parseClassExpression() {
  3691. const e = this.createNode();
  3692. const t = this.context.strict;
  3693. this.context.strict = !0, this.expectKeyword('class');
  3694. const s = this.lookahead.type === 3 ? this.parseVariableIdentifier() : null;
  3695. let i = null;
  3696. this.matchKeyword('extends') && (this.nextToken(), i = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall), this.context.allowSuper = !0);
  3697. const r = this.parseClassBody();
  3698. return this.context.strict = t, this.finalize(e, new ClassExpression(s, i, r, this.context.decorators));
  3699. }
  3700.  
  3701. parseModule() {
  3702. this.context.strict = !0, this.context.isModule = !0, this.scanner.isModule = !0;
  3703. const e = this.createNode();
  3704. const t = this.parseDirectivePrologues();
  3705. for (; this.lookahead.type !== 2;) t.push(this.parseStatementListItem());
  3706. return this.finalize(e, new Module(t));
  3707. }
  3708.  
  3709. parseScript() {
  3710. const e = this.createNode();
  3711. const t = this.parseDirectivePrologues();
  3712. for (; this.lookahead.type !== 2;) t.push(this.parseStatementListItem());
  3713. return this.finalize(e, new Script(t));
  3714. }
  3715.  
  3716. parseImportAttributes() {
  3717. if (this.lookahead.value === 'assert') {
  3718. this.nextToken(), this.expect('{');
  3719. const e = [];
  3720. for (; !this.match('}');) e.push(this.parseImportAttribute()), this.match('}') || this.expectCommaSeparator();
  3721. return this.expect('}'), e;
  3722. }
  3723. return null;
  3724. }
  3725.  
  3726. parseImportAttribute() {
  3727. const e = this.createNode();
  3728. this.lookahead.type !== 3 && this.throwUnexpectedToken(this.nextToken());
  3729. const t = this.parseIdentifierName();
  3730. this.match(':') || this.throwUnexpectedToken(this.nextToken()), this.nextToken();
  3731. const s = this.nextToken();
  3732. const i = this.getTokenRaw(s);
  3733. const r = this.finalize(e, new Literal(s.value, i));
  3734. return this.finalize(e, new ImportAttribute(t, r));
  3735. }
  3736.  
  3737. parseModuleSpecifier() {
  3738. const e = this.createNode();
  3739. this.lookahead.type !== 8 && this.throwError(Messages.InvalidModuleSpecifier);
  3740. const t = this.nextToken();
  3741. const s = this.getTokenRaw(t);
  3742. return Character.isStringWellFormedUnicode(t.value) || this.throwError(Messages.InvalidModuleSpecifier), this.finalize(e, new Literal(t.value, s));
  3743. }
  3744.  
  3745. parseImportSpecifier() {
  3746. const e = this.createNode();
  3747. let t; let
  3748. s;
  3749. return this.lookahead.type === 3 ? (t = this.parseVariableIdentifier(), s = t, this.matchContextualKeyword('as') && (this.nextToken(), s = this.parseVariableIdentifier())) : (t = this.lookahead.type == 8 ? this.parseModuleSpecifier() : this.parseIdentifierName(), s = t, this.matchContextualKeyword('as') ? (this.nextToken(), s = this.parseVariableIdentifier()) : this.throwUnexpectedToken(this.nextToken())), this.finalize(e, new ImportSpecifier(s, t));
  3750. }
  3751.  
  3752. parseNamedImports() {
  3753. this.expect('{');
  3754. const e = [];
  3755. for (; !this.match('}');) e.push(this.parseImportSpecifier()), this.match('}') || this.expect(',');
  3756. return this.expect('}'), e;
  3757. }
  3758.  
  3759. parseImportDefaultSpecifier() {
  3760. const e = this.createNode();
  3761. const t = this.parseIdentifierName();
  3762. return this.finalize(e, new ImportDefaultSpecifier(t));
  3763. }
  3764.  
  3765. parseImportNamespaceSpecifier() {
  3766. const e = this.createNode();
  3767. this.expect('*'), this.matchContextualKeyword('as') || this.throwError(Messages.NoAsAfterImportNamespace), this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken();
  3768. const t = this.parseIdentifierName();
  3769. return this.finalize(e, new ImportNamespaceSpecifier(t));
  3770. }
  3771.  
  3772. parseImportDeclaration() {
  3773. this.context.inFunctionBody && this.throwError(Messages.IllegalImportDeclaration);
  3774. const e = this.createNode();
  3775. let t;
  3776. this.expectKeyword('import');
  3777. let s = [];
  3778. if (this.lookahead.type === 8) t = this.parseModuleSpecifier();
  3779. else {
  3780. if (this.match('{') ? s = s.concat(this.parseNamedImports()) : this.match('*') ? s.push(this.parseImportNamespaceSpecifier()) : this.isIdentifierName(this.lookahead) && !this.matchKeyword('default') ? (s.push(this.parseImportDefaultSpecifier()), this.match(',') && (this.nextToken(), this.match('*') ? s.push(this.parseImportNamespaceSpecifier()) : this.match('{') ? s = s.concat(this.parseNamedImports()) : this.throwUnexpectedToken(this.lookahead))) : this.throwUnexpectedToken(this.nextToken()), !this.matchContextualKeyword('from')) {
  3781. const e = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
  3782. this.throwError(e, this.lookahead.value);
  3783. }
  3784. this.nextToken(), t = this.parseModuleSpecifier();
  3785. }
  3786. const i = this.parseImportAttributes();
  3787. return this.consumeSemicolon(), this.finalize(e, new ImportDeclaration(s, t, i));
  3788. }
  3789.  
  3790. parseExportSpecifier() {
  3791. const e = this.createNode();
  3792. const t = this.lookahead.type == 8 ? this.parseModuleSpecifier() : this.parseIdentifierName();
  3793. let s = t;
  3794. return this.matchContextualKeyword('as') && (this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken(), s = this.lookahead.type == 8 ? this.parseModuleSpecifier() : this.parseIdentifierName()), this.finalize(e, new ExportSpecifier(t, s));
  3795. }
  3796.  
  3797. parseExportDeclaration() {
  3798. this.context.inFunctionBody && this.throwError(Messages.IllegalExportDeclaration);
  3799. const e = this.createNode();
  3800. let t;
  3801. if (this.expectKeyword('export'), this.matchKeyword('default')) {
  3802. if (this.nextToken(), this.matchKeyword('function')) {
  3803. const s = this.parseFunctionDeclaration(!0);
  3804. t = this.finalize(e, new ExportDefaultDeclaration(s));
  3805. } else if (this.matchKeyword('class')) {
  3806. const s = this.parseClassDeclaration(!0);
  3807. t = this.finalize(e, new ExportDefaultDeclaration(s));
  3808. } else if (this.matchContextualKeyword('async')) {
  3809. const s = this.matchAsyncFunction() ? this.parseFunctionDeclaration(!0) : this.parseAssignmentExpression();
  3810. t = this.finalize(e, new ExportDefaultDeclaration(s));
  3811. } else {
  3812. this.matchContextualKeyword('from') && this.throwError(Messages.UnexpectedToken, this.lookahead.value);
  3813. const s = this.match('{') ? this.parseObjectInitializer() : this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
  3814. this.consumeSemicolon(), t = this.finalize(e, new ExportDefaultDeclaration(s));
  3815. }
  3816. } else if (this.match('*')) {
  3817. this.nextToken();
  3818. let s = null;
  3819. if (this.matchContextualKeyword('as') && (this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken(), s = this.lookahead.type == 8 ? this.parseModuleSpecifier() : this.parseIdentifierName()), !this.matchContextualKeyword('from')) {
  3820. const e = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
  3821. this.throwError(e, this.lookahead.value);
  3822. }
  3823. this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken();
  3824. const i = this.parseModuleSpecifier();
  3825. const r = this.parseImportAttributes();
  3826. this.consumeSemicolon(), t = this.finalize(e, new ExportAllDeclaration(i, s, r));
  3827. } else if (this.lookahead.type === 4) {
  3828. let s;
  3829. switch (this.lookahead.value) {
  3830. case 'let':
  3831. case 'const':
  3832. s = this.parseLexicalDeclaration({
  3833. inFor: !1
  3834. });
  3835. break;
  3836. case 'var':
  3837. case 'class':
  3838. case 'function':
  3839. s = this.parseStatementListItem();
  3840. break;
  3841. default:
  3842. this.throwUnexpectedToken(this.lookahead);
  3843. }
  3844. t = this.finalize(e, new ExportNamedDeclaration(s, [], null, null));
  3845. } else if (this.matchAsyncFunction()) {
  3846. const s = this.parseFunctionDeclaration();
  3847. t = this.finalize(e, new ExportNamedDeclaration(s, [], null, null));
  3848. } else {
  3849. const s = [];
  3850. let i = null;
  3851. let r = !1;
  3852. let n = null;
  3853. for (this.expect('{'); !this.match('}');) r = r || this.matchKeyword('default'), s.push(this.parseExportSpecifier()), this.match('}') || this.expect(',');
  3854. if (this.expect('}'), this.matchContextualKeyword('from')) this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken(), i = this.parseModuleSpecifier(), n = this.parseImportAttributes(), this.consumeSemicolon();
  3855. else if (r) {
  3856. const e = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
  3857. this.throwError(e, this.lookahead.value);
  3858. } else n = this.parseImportAttributes(), this.consumeSemicolon();
  3859. t = this.finalize(e, new ExportNamedDeclaration(null, s, i, n));
  3860. }
  3861. return t;
  3862. }
  3863. };
  3864. const XHTMLEntities = {
  3865. quot: '"',
  3866. amp: '&',
  3867. apos: "'",
  3868. gt: '>',
  3869. nbsp: ' ',
  3870. iexcl: '¡',
  3871. cent: '¢',
  3872. pound: '£',
  3873. curren: '¤',
  3874. yen: '¥',
  3875. brvbar: '¦',
  3876. sect: '§',
  3877. uml: '¨',
  3878. copy: '©',
  3879. ordf: 'ª',
  3880. laquo: '«',
  3881. not: '¬',
  3882. shy: '­',
  3883. reg: '®',
  3884. macr: '¯',
  3885. deg: '°',
  3886. plusmn: '±',
  3887. sup2: '²',
  3888. sup3: '³',
  3889. acute: '´',
  3890. micro: 'µ',
  3891. para: '¶',
  3892. middot: '·',
  3893. cedil: '¸',
  3894. sup1: '¹',
  3895. ordm: 'º',
  3896. raquo: '»',
  3897. frac14: '¼',
  3898. frac12: '½',
  3899. frac34: '¾',
  3900. iquest: '¿',
  3901. Agrave: 'À',
  3902. Aacute: 'Á',
  3903. Acirc: 'Â',
  3904. Atilde: 'Ã',
  3905. Auml: 'Ä',
  3906. Aring: 'Å',
  3907. AElig: 'Æ',
  3908. Ccedil: 'Ç',
  3909. Egrave: 'È',
  3910. Eacute: 'É',
  3911. Ecirc: 'Ê',
  3912. Euml: 'Ë',
  3913. Igrave: 'Ì',
  3914. Iacute: 'Í',
  3915. Icirc: 'Î',
  3916. Iuml: 'Ï',
  3917. ETH: 'Ð',
  3918. Ntilde: 'Ñ',
  3919. Ograve: 'Ò',
  3920. Oacute: 'Ó',
  3921. Ocirc: 'Ô',
  3922. Otilde: 'Õ',
  3923. Ouml: 'Ö',
  3924. times: '×',
  3925. Oslash: 'Ø',
  3926. Ugrave: 'Ù',
  3927. Uacute: 'Ú',
  3928. Ucirc: 'Û',
  3929. Uuml: 'Ü',
  3930. Yacute: 'Ý',
  3931. THORN: 'Þ',
  3932. szlig: 'ß',
  3933. agrave: 'à',
  3934. aacute: 'á',
  3935. acirc: 'â',
  3936. atilde: 'ã',
  3937. auml: 'ä',
  3938. aring: 'å',
  3939. aelig: 'æ',
  3940. ccedil: 'ç',
  3941. egrave: 'è',
  3942. eacute: 'é',
  3943. ecirc: 'ê',
  3944. euml: 'ë',
  3945. igrave: 'ì',
  3946. iacute: 'í',
  3947. icirc: 'î',
  3948. iuml: 'ï',
  3949. eth: 'ð',
  3950. ntilde: 'ñ',
  3951. ograve: 'ò',
  3952. oacute: 'ó',
  3953. ocirc: 'ô',
  3954. otilde: 'õ',
  3955. ouml: 'ö',
  3956. divide: '÷',
  3957. oslash: 'ø',
  3958. ugrave: 'ù',
  3959. uacute: 'ú',
  3960. ucirc: 'û',
  3961. uuml: 'ü',
  3962. yacute: 'ý',
  3963. thorn: 'þ',
  3964. yuml: 'ÿ',
  3965. OElig: 'Œ',
  3966. oelig: 'œ',
  3967. Scaron: 'Š',
  3968. scaron: 'š',
  3969. Yuml: 'Ÿ',
  3970. fnof: 'ƒ',
  3971. circ: 'ˆ',
  3972. tilde: '˜',
  3973. Alpha: 'Α',
  3974. Beta: 'Β',
  3975. Gamma: 'Γ',
  3976. Delta: 'Δ',
  3977. Epsilon: 'Ε',
  3978. Zeta: 'Ζ',
  3979. Eta: 'Η',
  3980. Theta: 'Θ',
  3981. Iota: 'Ι',
  3982. Kappa: 'Κ',
  3983. Lambda: 'Λ',
  3984. Mu: 'Μ',
  3985. Nu: 'Ν',
  3986. Xi: 'Ξ',
  3987. Omicron: 'Ο',
  3988. Pi: 'Π',
  3989. Rho: 'Ρ',
  3990. Sigma: 'Σ',
  3991. Tau: 'Τ',
  3992. Upsilon: 'Υ',
  3993. Phi: 'Φ',
  3994. Chi: 'Χ',
  3995. Psi: 'Ψ',
  3996. Omega: 'Ω',
  3997. alpha: 'α',
  3998. beta: 'β',
  3999. gamma: 'γ',
  4000. delta: 'δ',
  4001. epsilon: 'ε',
  4002. zeta: 'ζ',
  4003. eta: 'η',
  4004. theta: 'θ',
  4005. iota: 'ι',
  4006. kappa: 'κ',
  4007. lambda: 'λ',
  4008. mu: 'μ',
  4009. nu: 'ν',
  4010. xi: 'ξ',
  4011. omicron: 'ο',
  4012. pi: 'π',
  4013. rho: 'ρ',
  4014. sigmaf: 'ς',
  4015. sigma: 'σ',
  4016. tau: 'τ',
  4017. upsilon: 'υ',
  4018. phi: 'φ',
  4019. chi: 'χ',
  4020. psi: 'ψ',
  4021. omega: 'ω',
  4022. thetasym: 'ϑ',
  4023. upsih: 'ϒ',
  4024. piv: 'ϖ',
  4025. ensp: ' ',
  4026. emsp: ' ',
  4027. thinsp: ' ',
  4028. zwnj: '‌',
  4029. zwj: '‍',
  4030. lrm: '‎',
  4031. rlm: '‏',
  4032. ndash: '–',
  4033. mdash: '—',
  4034. lsquo: '‘',
  4035. rsquo: '’',
  4036. sbquo: '‚',
  4037. ldquo: '“',
  4038. rdquo: '”',
  4039. bdquo: '„',
  4040. dagger: '†',
  4041. Dagger: '‡',
  4042. bull: '•',
  4043. hellip: '…',
  4044. permil: '‰',
  4045. prime: '′',
  4046. Prime: '″',
  4047. lsaquo: '‹',
  4048. rsaquo: '›',
  4049. oline: '‾',
  4050. frasl: '⁄',
  4051. euro: '€',
  4052. image: 'ℑ',
  4053. weierp: '℘',
  4054. real: 'ℜ',
  4055. trade: '™',
  4056. alefsym: 'ℵ',
  4057. larr: '←',
  4058. uarr: '↑',
  4059. rarr: '→',
  4060. darr: '↓',
  4061. harr: '↔',
  4062. crarr: '↵',
  4063. lArr: '⇐',
  4064. uArr: '⇑',
  4065. rArr: '⇒',
  4066. dArr: '⇓',
  4067. hArr: '⇔',
  4068. forall: '∀',
  4069. part: '∂',
  4070. exist: '∃',
  4071. empty: '∅',
  4072. nabla: '∇',
  4073. isin: '∈',
  4074. notin: '∉',
  4075. ni: '∋',
  4076. prod: '∏',
  4077. sum: '∑',
  4078. minus: '−',
  4079. lowast: '∗',
  4080. radic: '√',
  4081. prop: '∝',
  4082. infin: '∞',
  4083. ang: '∠',
  4084. and: '∧',
  4085. or: '∨',
  4086. cap: '∩',
  4087. cup: '∪',
  4088. int: '∫',
  4089. there4: '∴',
  4090. sim: '∼',
  4091. cong: '≅',
  4092. asymp: '≈',
  4093. ne: '≠',
  4094. equiv: '≡',
  4095. le: '≤',
  4096. ge: '≥',
  4097. sub: '⊂',
  4098. sup: '⊃',
  4099. nsub: '⊄',
  4100. sube: '⊆',
  4101. supe: '⊇',
  4102. oplus: '⊕',
  4103. otimes: '⊗',
  4104. perp: '⊥',
  4105. sdot: '⋅',
  4106. lceil: '⌈',
  4107. rceil: '⌉',
  4108. lfloor: '⌊',
  4109. rfloor: '⌋',
  4110. loz: '◊',
  4111. spades: '♠',
  4112. clubs: '♣',
  4113. hearts: '♥',
  4114. diams: '♦',
  4115. lang: '⟨',
  4116. rang: '⟩'
  4117. };
  4118.  
  4119. function getQualifiedElementName(e) {
  4120. let t;
  4121. switch (e.type) {
  4122. case 'JSXIdentifier':
  4123. t = e.name;
  4124. break;
  4125. case 'JSXNamespacedName':
  4126. const s = e;
  4127. t = `${getQualifiedElementName(s.namespace)}:${getQualifiedElementName(s.name)}`;
  4128. break;
  4129. case 'JSXMemberExpression':
  4130. const i = e;
  4131. t = `${getQualifiedElementName(i.object)}.${getQualifiedElementName(i.property)}`;
  4132. }
  4133. return t;
  4134. }
  4135. TokenName[100] = 'JSXIdentifier', TokenName[101] = 'JSXText';
  4136. const JSXParser = class extends Parser {
  4137. constructor(e, t, s) {
  4138. super(e, t, s);
  4139. }
  4140.  
  4141. parsePrimaryExpression() {
  4142. return this.match('<') ? this.parseJSXRoot() : super.parsePrimaryExpression();
  4143. }
  4144.  
  4145. startJSX() {
  4146. this.scanner.index = this.startMarker.index, this.scanner.lineNumber = this.startMarker.line, this.scanner.lineStart = this.startMarker.index - this.startMarker.column;
  4147. }
  4148.  
  4149. finishJSX() {
  4150. this.nextToken();
  4151. }
  4152.  
  4153. reenterJSX() {
  4154. this.startJSX(), this.expectJSX('}'), this.config.tokens && this.tokens.pop();
  4155. }
  4156.  
  4157. createJSXNode() {
  4158. return this.collectComments(), {
  4159. index: this.scanner.index,
  4160. line: this.scanner.lineNumber,
  4161. column: this.scanner.index - this.scanner.lineStart
  4162. };
  4163. }
  4164.  
  4165. createJSXChildNode() {
  4166. return {
  4167. index: this.scanner.index,
  4168. line: this.scanner.lineNumber,
  4169. column: this.scanner.index - this.scanner.lineStart
  4170. };
  4171. }
  4172.  
  4173. scanXHTMLEntity(e) {
  4174. let t = '&';
  4175. let s = !0;
  4176. let i = !1;
  4177. let r = !1;
  4178. let n = !1;
  4179. for (; !this.scanner.eof() && s && !i;) {
  4180. const a = this.scanner.source[this.scanner.index];
  4181. if (a === e) break;
  4182. if (i = a === ';', t += a, ++this.scanner.index, !i) {
  4183. switch (t.length) {
  4184. case 2:
  4185. r = a === '#';
  4186. break;
  4187. case 3:
  4188. r && (n = a === 'x', s = n || Character.isDecimalDigit(a.charCodeAt(0)), r = r && !n);
  4189. break;
  4190. default:
  4191. s = s && !(r && !Character.isDecimalDigit(a.charCodeAt(0))), s = s && !(n && !Character.isHexDigit(a.charCodeAt(0)));
  4192. }
  4193. }
  4194. }
  4195. if (s && i && t.length > 2) {
  4196. const e = t.substr(1, t.length - 2);
  4197. r && e.length > 1 ? t = String.fromCharCode(parseInt(e.substr(1), 10)) : n && e.length > 2 ? t = String.fromCharCode(parseInt(`0${e.substr(1)}`, 16)) : r || n || !XHTMLEntities[e] || (t = XHTMLEntities[e]);
  4198. }
  4199. return t;
  4200. }
  4201.  
  4202. lexJSX() {
  4203. const e = this.scanner.source.charCodeAt(this.scanner.index);
  4204. if (e === 60 || e === 62 || e === 47 || e === 58 || e === 61 || e === 123 || e === 125) {
  4205. return {
  4206. type: 7,
  4207. value: this.scanner.source[this.scanner.index++],
  4208. lineNumber: this.scanner.lineNumber,
  4209. lineStart: this.scanner.lineStart,
  4210. start: this.scanner.index - 1,
  4211. end: this.scanner.index
  4212. };
  4213. }
  4214. if (e === 34 || e === 39) {
  4215. const e = this.scanner.index;
  4216. const t = this.scanner.source[this.scanner.index++];
  4217. let s = '';
  4218. for (; !this.scanner.eof();) {
  4219. const e = this.scanner.source[this.scanner.index++];
  4220. if (e === t) break;
  4221. s += e === '&' ? this.scanXHTMLEntity(t) : e;
  4222. }
  4223. return {
  4224. type: 8,
  4225. value: s,
  4226. lineNumber: this.scanner.lineNumber,
  4227. lineStart: this.scanner.lineStart,
  4228. start: e,
  4229. end: this.scanner.index
  4230. };
  4231. }
  4232. if (e === 46) {
  4233. const e = this.scanner.source.charCodeAt(this.scanner.index + 1);
  4234. const t = this.scanner.source.charCodeAt(this.scanner.index + 2);
  4235. const s = e === 46 && t === 46 ? '...' : '.';
  4236. const i = this.scanner.index;
  4237. return this.scanner.index += s.length, {
  4238. type: 7,
  4239. value: s,
  4240. lineNumber: this.scanner.lineNumber,
  4241. lineStart: this.scanner.lineStart,
  4242. start: i,
  4243. end: this.scanner.index
  4244. };
  4245. }
  4246. if (e === 96) {
  4247. return {
  4248. type: 10,
  4249. value: '',
  4250. lineNumber: this.scanner.lineNumber,
  4251. lineStart: this.scanner.lineStart,
  4252. start: this.scanner.index,
  4253. end: this.scanner.index
  4254. };
  4255. }
  4256. if (Character.isIdentifierStart(e) && e !== 92) {
  4257. const e = this.scanner.index;
  4258. for (++this.scanner.index; !this.scanner.eof();) {
  4259. const e = this.scanner.source.charCodeAt(this.scanner.index);
  4260. if (Character.isIdentifierPart(e) && e !== 92) ++this.scanner.index;
  4261. else {
  4262. if (e !== 45) break;
  4263. ++this.scanner.index;
  4264. }
  4265. }
  4266. return {
  4267. type: 100,
  4268. value: this.scanner.source.slice(e, this.scanner.index),
  4269. lineNumber: this.scanner.lineNumber,
  4270. lineStart: this.scanner.lineStart,
  4271. start: e,
  4272. end: this.scanner.index
  4273. };
  4274. }
  4275. return this.scanner.lex();
  4276. }
  4277.  
  4278. nextJSXToken() {
  4279. this.collectComments(), this.startMarker.index = this.scanner.index, this.startMarker.line = this.scanner.lineNumber, this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  4280. const e = this.lexJSX();
  4281. return this.lastMarker.index = this.scanner.index, this.lastMarker.line = this.scanner.lineNumber, this.lastMarker.column = this.scanner.index - this.scanner.lineStart, this.config.tokens && this.tokens.push(this.convertToken(e)), e;
  4282. }
  4283.  
  4284. nextJSXText() {
  4285. this.startMarker.index = this.scanner.index, this.startMarker.line = this.scanner.lineNumber, this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  4286. const e = this.scanner.index;
  4287. let t = '';
  4288. for (; !this.scanner.eof();) {
  4289. const e = this.scanner.source[this.scanner.index];
  4290. if (e === '{' || e === '<') break;
  4291. ++this.scanner.index, t += e, Character.isLineTerminator(e.charCodeAt(0)) && (++this.scanner.lineNumber, e === '\r' && this.scanner.source[this.scanner.index] === '\n' && ++this.scanner.index, this.scanner.lineStart = this.scanner.index);
  4292. }
  4293. this.lastMarker.index = this.scanner.index, this.lastMarker.line = this.scanner.lineNumber, this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  4294. const s = {
  4295. type: 101,
  4296. value: t,
  4297. lineNumber: this.scanner.lineNumber,
  4298. lineStart: this.scanner.lineStart,
  4299. start: e,
  4300. end: this.scanner.index
  4301. };
  4302. return t.length > 0 && this.config.tokens && this.tokens.push(this.convertToken(s)), s;
  4303. }
  4304.  
  4305. peekJSXToken() {
  4306. const e = this.scanner.saveState();
  4307. this.scanner.scanComments();
  4308. const t = this.lexJSX();
  4309. return this.scanner.restoreState(e), t;
  4310. }
  4311.  
  4312. expectJSX(e) {
  4313. const t = this.nextJSXToken();
  4314. t.type === 7 && t.value === e || this.throwUnexpectedToken(t);
  4315. }
  4316.  
  4317. matchJSX(e) {
  4318. const t = this.peekJSXToken();
  4319. return t.type === 7 && t.value === e;
  4320. }
  4321.  
  4322. parseJSXIdentifier() {
  4323. const e = this.createJSXNode();
  4324. const t = this.nextJSXToken();
  4325. return t.type !== 100 && this.throwUnexpectedToken(t), this.finalize(e, new JSXIdentifier(t.value));
  4326. }
  4327.  
  4328. parseJSXElementName() {
  4329. const e = this.createJSXNode();
  4330. let t = this.parseJSXIdentifier();
  4331. if (this.matchJSX(':')) {
  4332. const s = t;
  4333. this.expectJSX(':');
  4334. const i = this.parseJSXIdentifier();
  4335. t = this.finalize(e, new JSXNamespacedName(s, i));
  4336. } else if (this.matchJSX('.')) {
  4337. for (; this.matchJSX('.');) {
  4338. const s = t;
  4339. this.expectJSX('.');
  4340. const i = this.parseJSXIdentifier();
  4341. t = this.finalize(e, new JSXMemberExpression(s, i));
  4342. }
  4343. }
  4344. return t;
  4345. }
  4346.  
  4347. parseJSXAttributeName() {
  4348. const e = this.createJSXNode();
  4349. let t;
  4350. const s = this.parseJSXIdentifier();
  4351. if (this.matchJSX(':')) {
  4352. const i = s;
  4353. this.expectJSX(':');
  4354. const r = this.parseJSXIdentifier();
  4355. t = this.finalize(e, new JSXNamespacedName(i, r));
  4356. } else t = s;
  4357. return t;
  4358. }
  4359.  
  4360. parseJSXStringLiteralAttribute() {
  4361. const e = this.createJSXNode();
  4362. const t = this.nextJSXToken();
  4363. t.type !== 8 && this.throwUnexpectedToken(t);
  4364. const s = this.getTokenRaw(t);
  4365. return this.finalize(e, new Literal(t.value, s));
  4366. }
  4367.  
  4368. parseJSXExpressionAttribute() {
  4369. const e = this.createJSXNode();
  4370. this.expectJSX('{'), this.finishJSX(), this.match('}') && this.tolerateError('JSX attributes must only be assigned a non-empty expression');
  4371. const t = this.parseAssignmentExpression();
  4372. return this.reenterJSX(), this.finalize(e, new JSXExpressionContainer(t));
  4373. }
  4374.  
  4375. parseJSXAttributeValue() {
  4376. return this.matchJSX('{') ? this.parseJSXExpressionAttribute() : this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
  4377. }
  4378.  
  4379. parseJSXNameValueAttribute() {
  4380. const e = this.createJSXNode();
  4381. const t = this.parseJSXAttributeName();
  4382. let s = null;
  4383. return this.matchJSX('=') && (this.expectJSX('='), s = this.parseJSXAttributeValue()), this.finalize(e, new JSXAttribute(t, s));
  4384. }
  4385.  
  4386. parseJSXSpreadAttribute() {
  4387. const e = this.createJSXNode();
  4388. this.expectJSX('{'), this.expectJSX('...'), this.finishJSX();
  4389. const t = this.parseAssignmentExpression();
  4390. return this.reenterJSX(), this.finalize(e, new JSXSpreadAttribute(t));
  4391. }
  4392.  
  4393. parseJSXAttributes() {
  4394. const e = [];
  4395. for (; !this.matchJSX('/') && !this.matchJSX('>');) {
  4396. const t = this.matchJSX('{') ? this.parseJSXSpreadAttribute() : this.parseJSXNameValueAttribute();
  4397. e.push(t);
  4398. }
  4399. return e;
  4400. }
  4401.  
  4402. parseJSXOpeningElement() {
  4403. const e = this.createJSXNode();
  4404. if (this.expectJSX('<'), this.matchJSX('>')) return this.expectJSX('>'), this.finalize(e, new JSXOpeningFragment(!1));
  4405. const t = this.parseJSXElementName();
  4406. const s = this.parseJSXAttributes();
  4407. const i = this.matchJSX('/');
  4408. return i && this.expectJSX('/'), this.expectJSX('>'), this.finalize(e, new JSXOpeningElement(t, i, s));
  4409. }
  4410.  
  4411. parseJSXBoundaryElement() {
  4412. const e = this.createJSXNode();
  4413. if (this.expectJSX('<'), this.matchJSX('/')) {
  4414. if (this.expectJSX('/'), this.matchJSX('>')) return this.expectJSX('>'), this.finalize(e, new JSXClosingFragment());
  4415. const t = this.parseJSXElementName();
  4416. return this.expectJSX('>'), this.finalize(e, new JSXClosingElement(t));
  4417. }
  4418. const t = this.parseJSXElementName();
  4419. const s = this.parseJSXAttributes();
  4420. const i = this.matchJSX('/');
  4421. return i && this.expectJSX('/'), this.expectJSX('>'), this.finalize(e, new JSXOpeningElement(t, i, s));
  4422. }
  4423.  
  4424. parseJSXEmptyExpression() {
  4425. const e = this.createJSXChildNode();
  4426. return this.collectComments(), this.lastMarker.index = this.scanner.index, this.lastMarker.line = this.scanner.lineNumber, this.lastMarker.column = this.scanner.index - this.scanner.lineStart, this.finalize(e, new JSXEmptyExpression());
  4427. }
  4428.  
  4429. parseJSXExpressionContainer() {
  4430. const e = this.createJSXNode();
  4431. let t;
  4432. return this.expectJSX('{'), this.matchJSX('}') ? (t = this.parseJSXEmptyExpression(), this.expectJSX('}')) : (this.finishJSX(), t = this.parseAssignmentExpression(), this.reenterJSX()), this.finalize(e, new JSXExpressionContainer(t));
  4433. }
  4434.  
  4435. parseJSXChildren() {
  4436. const e = [];
  4437. for (; !this.scanner.eof();) {
  4438. const t = this.createJSXChildNode();
  4439. const s = this.nextJSXText();
  4440. if (s.start < s.end) {
  4441. const i = this.getTokenRaw(s);
  4442. const r = this.finalize(t, new JSXText(s.value, i));
  4443. e.push(r);
  4444. }
  4445. if (this.scanner.source[this.scanner.index] !== '{') break;
  4446. {
  4447. const t = this.parseJSXExpressionContainer();
  4448. e.push(t);
  4449. }
  4450. }
  4451. return e;
  4452. }
  4453.  
  4454. parseComplexJSXElement(e) {
  4455. const t = [];
  4456. for (; !this.scanner.eof();) {
  4457. e.children = e.children.concat(this.parseJSXChildren());
  4458. const s = this.createJSXChildNode();
  4459. const i = this.parseJSXBoundaryElement();
  4460. if (i.type === 'JSXOpeningElement') {
  4461. const r = i;
  4462. if (r.selfClosing) {
  4463. const t = this.finalize(s, new JSXElement(r, [], null));
  4464. e.children.push(t);
  4465. } else {
  4466. t.push(e), e = {
  4467. node: s,
  4468. opening: r,
  4469. closing: null,
  4470. children: []
  4471. };
  4472. }
  4473. }
  4474. if (i.type === 'JSXClosingElement') {
  4475. e.closing = i;
  4476. const s = getQualifiedElementName(e.opening.name);
  4477. if (s !== getQualifiedElementName(e.closing.name) && this.tolerateError('Expected corresponding JSX closing tag for %0', s), !(t.length > 0)) break;
  4478. {
  4479. const s = this.finalize(e.node, new JSXElement(e.opening, e.children, e.closing));
  4480. (e = t[t.length - 1]).children.push(s), t.pop();
  4481. }
  4482. }
  4483. if (i.type === 'JSXClosingFragment') {
  4484. if (e.closing = i, e.opening.type === 'JSXOpeningFragment') break;
  4485. this.tolerateError('Expected corresponding JSX closing tag for jsx fragment');
  4486. }
  4487. }
  4488. return e;
  4489. }
  4490.  
  4491. parseJSXElement() {
  4492. const e = this.createJSXNode();
  4493. const t = this.parseJSXOpeningElement();
  4494. let s = [];
  4495. let i = null;
  4496. if (!t.selfClosing) {
  4497. const r = this.parseComplexJSXElement({
  4498. node: e,
  4499. opening: t,
  4500. closing: i,
  4501. children: s
  4502. });
  4503. s = r.children, i = r.closing;
  4504. }
  4505. return this.finalize(e, new JSXElement(t, s, i));
  4506. }
  4507.  
  4508. parseJSXRoot() {
  4509. this.config.tokens && this.tokens.pop(), this.startJSX();
  4510. const e = this.parseJSXElement();
  4511. return this.finishJSX(), e;
  4512. }
  4513.  
  4514. isStartOfExpression() {
  4515. return super.isStartOfExpression() || this.match('<');
  4516. }
  4517. };
  4518. const beforeFunctionExpressionTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new', 'return', 'case', 'delete', 'throw', 'void', '=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=', '&=', '|=', '^=', ',', '+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&', '|', '^', '!', '~', '&&', '||', '??', '?', ':', '===', '==', '>=', '<=', '<', '>', '!=', '!=='];
  4519. const Reader = class {
  4520. values;
  4521. curly;
  4522. paren;
  4523. constructor() {
  4524. this.values = [], this.curly = this.paren = -1;
  4525. }
  4526.  
  4527. beforeFunctionExpression(e) {
  4528. return beforeFunctionExpressionTokens.includes(e);
  4529. }
  4530.  
  4531. isRegexStart() {
  4532. const e = this.values[this.values.length - 1];
  4533. let t = e !== null;
  4534. switch (e) {
  4535. case 'this':
  4536. case ']':
  4537. t = !1;
  4538. break;
  4539. case ')':
  4540. const e = this.values[this.paren - 1];
  4541. t = e === 'if' || e === 'while' || e === 'for' || e === 'with';
  4542. break;
  4543. case '}':
  4544. if (t = !0, this.values[this.curly - 3] === 'function') {
  4545. const e = this.values[this.curly - 4];
  4546. t = !!e && !this.beforeFunctionExpression(e);
  4547. } else if (this.values[this.curly - 4] === 'function') {
  4548. const e = this.values[this.curly - 5];
  4549. t = !e || !this.beforeFunctionExpression(e);
  4550. }
  4551. }
  4552. return t;
  4553. }
  4554.  
  4555. push(e) {
  4556. e.type === 7 || e.type === 4 ? (e.value === '{' ? this.curly = this.values.length : e.value === '(' && (this.paren = this.values.length), this.values.push(e.value)) : this.values.push(null);
  4557. }
  4558. };
  4559. const Tokenizer = class {
  4560. errorHandler;
  4561. scanner;
  4562. trackRange;
  4563. trackLoc;
  4564. buffer;
  4565. reader;
  4566. constructor(e, t) {
  4567. this.errorHandler = new ErrorHandler(), this.errorHandler.tolerant = !!t && (typeof t.tolerant === 'boolean' && t.tolerant), this.scanner = new Scanner(e, this.errorHandler), this.scanner.trackComment = !!t && (typeof t.comment === 'boolean' && t.comment), this.trackRange = !!t && (typeof t.range === 'boolean' && t.range), this.trackLoc = !!t && (typeof t.loc === 'boolean' && t.loc), this.buffer = [], this.reader = new Reader();
  4568. }
  4569.  
  4570. errors() {
  4571. return this.errorHandler.errors;
  4572. }
  4573.  
  4574. getNextToken() {
  4575. if (this.buffer.length === 0) {
  4576. const e = this.scanner.scanComments();
  4577. if (this.scanner.trackComment) {
  4578. for (let t = 0; t < e.length; ++t) {
  4579. const s = e[t];
  4580. const i = this.scanner.source.slice(s.slice[0], s.slice[1]);
  4581. const r = {
  4582. type: s.multiLine ? 'BlockComment' : 'LineComment',
  4583. value: i
  4584. };
  4585. this.trackRange && (r.range = s.range), this.trackLoc && (r.loc = s.loc), this.buffer.push(r);
  4586. }
  4587. }
  4588. if (!this.scanner.eof()) {
  4589. let e;
  4590. this.trackLoc && (e = {
  4591. start: {
  4592. line: this.scanner.lineNumber,
  4593. column: this.scanner.index - this.scanner.lineStart
  4594. },
  4595. end: {}
  4596. });
  4597. let t;
  4598. if (this.scanner.source[this.scanner.index] === '/' && this.reader.isRegexStart()) {
  4599. const e = this.scanner.saveState();
  4600. try {
  4601. t = this.scanner.scanRegExp();
  4602. } catch (s) {
  4603. this.scanner.restoreState(e), t = this.scanner.lex();
  4604. }
  4605. } else t = this.scanner.lex();
  4606. this.reader.push(t);
  4607. const s = {
  4608. type: TokenName[t.type],
  4609. value: this.scanner.source.slice(t.start, t.end)
  4610. };
  4611. if (this.trackRange && (s.range = [t.start, t.end]), this.trackLoc && (e.end = {
  4612. line: this.scanner.lineNumber,
  4613. column: this.scanner.index - this.scanner.lineStart
  4614. }, s.loc = e), t.type === 9) {
  4615. const e = t.pattern;
  4616. const i = t.flags;
  4617. s.regex = {
  4618. pattern: e,
  4619. flags: i
  4620. };
  4621. }
  4622. this.buffer.push(s);
  4623. }
  4624. }
  4625. return this.buffer.shift();
  4626. }
  4627. };
  4628. const Visitor = class {
  4629. visit(e) {
  4630. if (e == null) return e;
  4631. switch (e.type) {
  4632. case 'AssignmentExpression':
  4633. return this.visitAssignmentExpression(e);
  4634. case 'AssignmentPattern':
  4635. return this.visitAssignmentPattern(e);
  4636. case 'ArrayExpression':
  4637. return this.visitArrayExpression(e);
  4638. case 'ArrayPattern':
  4639. return this.visitArrayPattern(e);
  4640. case 'ArrowFunctionExpression':
  4641. return this.visitArrowFunctionExpression(e);
  4642. case 'AwaitExpression':
  4643. return this.visitAwaitExpression(e);
  4644. case 'BlockStatement':
  4645. return this.visitBlockStatement(e);
  4646. case 'BinaryExpression':
  4647. return this.visitBinaryExpression(e);
  4648. case 'BreakStatement':
  4649. return this.visitBreakStatement(e);
  4650. case 'CallExpression':
  4651. return this.visitCallExpression(e);
  4652. case 'CatchClause':
  4653. return this.visitCatchClause(e);
  4654. case 'ChainExpression':
  4655. return this.visitChainExpression(e);
  4656. case 'ClassBody':
  4657. return this.visitClassBody(e);
  4658. case 'ClassDeclaration':
  4659. return this.visitClassDeclaration(e);
  4660. case 'ClassExpression':
  4661. return this.visitClassExpression(e);
  4662. case 'ConditionalExpression':
  4663. return this.visitConditionalExpression(e);
  4664. case 'ContinueStatement':
  4665. return this.visitContinueStatement(e);
  4666. case 'Decorator':
  4667. return this.visitDecorator(e);
  4668. case 'DoWhileStatement':
  4669. return this.visitDoWhileStatement(e);
  4670. case 'DebuggerStatement':
  4671. return this.visitDebuggerStatement(e);
  4672. case 'EmptyStatement':
  4673. return this.visitEmptyStatement(e);
  4674. case 'ExportAllDeclaration':
  4675. return this.visitExportAllDeclaration(e);
  4676. case 'ExportDefaultDeclaration':
  4677. return this.visitExportDefaultDeclaration(e);
  4678. case 'ExportNamedDeclaration':
  4679. return this.visitExportNamedDeclaration(e);
  4680. case 'ExportSpecifier':
  4681. return this.visitExportSpecifier(e);
  4682. case 'ExpressionStatement':
  4683. return this.visitExpressionStatement(e);
  4684. case 'ForStatement':
  4685. return this.visitForStatement(e);
  4686. case 'ForOfStatement':
  4687. return this.visitForOfStatement(e);
  4688. case 'ForInStatement':
  4689. return this.visitForInStatement(e);
  4690. case 'FunctionDeclaration':
  4691. return this.visitFunctionDeclaration(e);
  4692. case 'FunctionExpression':
  4693. return this.visitFunctionExpression(e);
  4694. case 'Identifier':
  4695. return this.visitIdentifier(e);
  4696. case 'IfStatement':
  4697. return this.visitIfStatement(e);
  4698. case 'ImportAttribute':
  4699. return this.visitImportAttribute(e);
  4700. case 'ImportExpression':
  4701. return this.visitImportExpression(e);
  4702. case 'ImportDeclaration':
  4703. return this.visitImportDeclaration(e);
  4704. case 'ImportDefaultSpecifier':
  4705. return this.visitImportDefaultSpecifier(e);
  4706. case 'ImportNamespaceSpecifier':
  4707. return this.visitImportNamespaceSpecifier(e);
  4708. case 'ImportSpecifier':
  4709. return this.visitImportSpecifier(e);
  4710. case 'Literal':
  4711. return this.visitLiteral(e);
  4712. case 'LabeledStatement':
  4713. return this.visitLabeledStatement(e);
  4714. case 'LogicalExpression':
  4715. return this.visitLogicalExpression(e);
  4716. case 'MemberExpression':
  4717. return this.visitMemberExpression(e);
  4718. case 'MetaProperty':
  4719. return this.visitMetaProperty(e);
  4720. case 'MethodDefinition':
  4721. return this.visitMethodDefinition(e);
  4722. case 'NewExpression':
  4723. return this.visitNewExpression(e);
  4724. case 'ObjectExpression':
  4725. return this.visitObjectExpression(e);
  4726. case 'ObjectPattern':
  4727. return this.visitObjectPattern(e);
  4728. case 'Program':
  4729. return this.visitProgram(e);
  4730. case 'Property':
  4731. return this.visitProperty(e);
  4732. case 'PrivateIdentifier':
  4733. return this.visitPrivateIdentifier(e);
  4734. case 'RestElement':
  4735. return this.visitRestElement(e);
  4736. case 'ReturnStatement':
  4737. return this.visitReturnStatement(e);
  4738. case 'SequenceExpression':
  4739. return this.visitSequenceExpression(e);
  4740. case 'SpreadElement':
  4741. return this.visitSpreadElement(e);
  4742. case 'StaticBlock':
  4743. return this.visitStaticBlock(e);
  4744. case 'Super':
  4745. return this.visitSuper(e);
  4746. case 'SwitchCase':
  4747. return this.visitSwitchCase(e);
  4748. case 'SwitchStatement':
  4749. return this.visitSwitchStatement(e);
  4750. case 'TaggedTemplateExpression':
  4751. return this.visitTaggedTemplateExpression(e);
  4752. case 'TemplateElement':
  4753. return this.visitTemplateElement(e);
  4754. case 'TemplateLiteral':
  4755. return this.visitTemplateLiteral(e);
  4756. case 'ThisExpression':
  4757. return this.visitThisExpression(e);
  4758. case 'ThrowStatement':
  4759. return this.visitThrowStatement(e);
  4760. case 'TryStatement':
  4761. return this.visitTryStatement(e);
  4762. case 'UnaryExpression':
  4763. return this.visitUnaryExpression(e);
  4764. case 'UpdateExpression':
  4765. return this.visitUpdateExpression(e);
  4766. case 'VariableDeclaration':
  4767. return this.visitVariableDeclaration(e);
  4768. case 'VariableDeclarator':
  4769. return this.visitVariableDeclarator(e);
  4770. case 'WhileStatement':
  4771. return this.visitWhileStatement(e);
  4772. case 'WithStatement':
  4773. return this.visitWithStatement(e);
  4774. case 'YieldExpression':
  4775. return this.visitYieldExpression(e);
  4776. }
  4777. }
  4778.  
  4779. visitNodeList(e) {
  4780. if (e == null) return e;
  4781. let t = null;
  4782. for (let s = 0, i = e.length; s < i; s++) {
  4783. const i = this.visit(e[s]);
  4784. if (t != null) t.push(i);
  4785. else if (i != e[s]) {
  4786. t = [];
  4787. for (let i = 0; i < s; i++) t.push(e[i]);
  4788. t.push(i);
  4789. }
  4790. }
  4791. return t != null ? t : e;
  4792. }
  4793.  
  4794. visitAssignmentExpression(e) {
  4795. const t = this.visit(e.left);
  4796. const s = this.visit(e.right);
  4797. return t !== e.left || s !== e.right ? new AssignmentExpression(e.operator, t, s) : e;
  4798. }
  4799.  
  4800. visitAssignmentPattern(e) {
  4801. const t = this.visit(e.left);
  4802. const s = this.visit(e.right);
  4803. return t !== e.left || s !== e.right ? new AssignmentPattern(t, s) : e;
  4804. }
  4805.  
  4806. visitArrayExpression(e) {
  4807. const t = this.visitNodeList(e.elements);
  4808. return t !== e.elements ? new ArrayExpression(t) : e;
  4809. }
  4810.  
  4811. visitArrayPattern(e) {
  4812. const t = this.visitNodeList(e.elements);
  4813. return t !== e.elements ? new ArrayPattern(t) : e;
  4814. }
  4815.  
  4816. visitArrowFunctionExpression(e) {
  4817. const t = this.visit(e.id);
  4818. const s = this.visitNodeList(e.params);
  4819. const i = this.visit(e.body);
  4820. if (t !== e.id || s !== e.params || i !== e.body) {
  4821. const r = new ArrowFunctionExpression(s, i, e.expression, e.async);
  4822. return r.id = t, r;
  4823. }
  4824. return e;
  4825. }
  4826.  
  4827. visitAwaitExpression(e) {
  4828. const t = this.visit(e.argument);
  4829. return t !== e.argument ? new AwaitExpression(t) : e;
  4830. }
  4831.  
  4832. visitBlockStatement(e) {
  4833. const t = this.visitNodeList(e.body);
  4834. return t !== e.body ? new BlockStatement(t) : e;
  4835. }
  4836.  
  4837. visitBinaryExpression(e) {
  4838. const t = this.visit(e.left);
  4839. const s = this.visit(e.right);
  4840. return t !== e.left || s !== e.right ? new BinaryExpression(e.operator, t, s) : e;
  4841. }
  4842.  
  4843. visitBreakStatement(e) {
  4844. const t = this.visit(e.label);
  4845. return t !== e.label ? new BreakStatement(t) : e;
  4846. }
  4847.  
  4848. visitCallExpression(e) {
  4849. const t = this.visit(e.callee);
  4850. const s = this.visitNodeList(e.arguments);
  4851. return t !== e.callee || s !== e.arguments ? new CallExpression(t, s, e.optional) : e;
  4852. }
  4853.  
  4854. visitCatchClause(e) {
  4855. const t = this.visit(e.param);
  4856. const s = this.visit(e.body);
  4857. return t !== e.param || s !== e.body ? new CatchClause(t, s) : e;
  4858. }
  4859.  
  4860. visitChainExpression(e) {
  4861. const t = this.visit(e.expression);
  4862. return t !== e.expression ? new ChainExpression(t) : e;
  4863. }
  4864.  
  4865. visitClassBody(e) {
  4866. const t = this.visitNodeList(e.body);
  4867. return t !== e.body ? new ClassBody(t) : e;
  4868. }
  4869.  
  4870. visitClassDeclaration(e) {
  4871. const t = this.visit(e.id);
  4872. const s = this.visit(e.superClass);
  4873. const i = this.visit(e.body);
  4874. const r = this.visitNodeList(e.decorators);
  4875. return t !== e.id || s !== e.superClass || i !== e.body || r !== e.decorators ? new ClassDeclaration(t, s, i, r) : e;
  4876. }
  4877.  
  4878. visitClassExpression(e) {
  4879. const t = this.visit(e.id);
  4880. const s = this.visit(e.superClass);
  4881. const i = this.visit(e.body);
  4882. const r = this.visitNodeList(e.decorators);
  4883. return t !== e.id || s !== e.superClass || i !== e.body || r !== e.decorators ? new ClassExpression(t, s, i, r) : e;
  4884. }
  4885.  
  4886. visitConditionalExpression(e) {
  4887. const t = this.visit(e.test);
  4888. const s = this.visit(e.consequent);
  4889. const i = this.visit(e.alternate);
  4890. return t !== e.test || s !== e.consequent || i !== e.alternate ? new ConditionalExpression(t, s, i) : e;
  4891. }
  4892.  
  4893. visitContinueStatement(e) {
  4894. const t = this.visit(e.label);
  4895. return t !== e.label ? new ContinueStatement(t) : e;
  4896. }
  4897.  
  4898. visitDecorator(e) {
  4899. const t = this.visit(e.expression);
  4900. return t !== e.expression ? new Decorator(t) : e;
  4901. }
  4902.  
  4903. visitDoWhileStatement(e) {
  4904. const t = this.visit(e.body);
  4905. const s = this.visit(e.test);
  4906. return t !== e.body || s !== e.test ? new DoWhileStatement(t, s) : e;
  4907. }
  4908.  
  4909. visitDebuggerStatement(e) {
  4910. return e;
  4911. }
  4912.  
  4913. visitEmptyStatement(e) {
  4914. return e;
  4915. }
  4916.  
  4917. visitExportAllDeclaration(e) {
  4918. const t = this.visit(e.source);
  4919. const s = this.visit(e.exported);
  4920. const i = this.visitNodeList(e.assertions);
  4921. return t !== e.source || s !== e.exported || i !== e.assertions ? new ExportAllDeclaration(t, s, i) : e;
  4922. }
  4923.  
  4924. visitExportDefaultDeclaration(e) {
  4925. const t = this.visit(e.declaration);
  4926. return t !== e.declaration ? new ExportDefaultDeclaration(t) : e;
  4927. }
  4928.  
  4929. visitExportNamedDeclaration(e) {
  4930. const t = this.visit(e.declaration);
  4931. const s = this.visitNodeList(e.specifiers);
  4932. const i = this.visit(e.source);
  4933. const r = this.visitNodeList(e.assertions);
  4934. return t !== e.declaration || s !== e.specifiers || i !== e.source || r !== e.assertions ? new ExportNamedDeclaration(t, s, i, r) : e;
  4935. }
  4936.  
  4937. visitExportSpecifier(e) {
  4938. const t = this.visit(e.exported);
  4939. const s = this.visit(e.local);
  4940. return t !== e.exported || s !== e.local ? new ExportSpecifier(t, s) : e;
  4941. }
  4942.  
  4943. visitExpressionStatement(e) {
  4944. const t = this.visit(e.expression);
  4945. return t !== e.expression ? new ExpressionStatement(t) : e;
  4946. }
  4947.  
  4948. visitForStatement(e) {
  4949. const t = this.visit(e.init);
  4950. const s = this.visit(e.test);
  4951. const i = this.visit(e.update);
  4952. const r = this.visit(e.body);
  4953. return t !== e.init || s !== e.test || i !== e.update || r !== e.body ? new ForStatement(t, s, i, r) : e;
  4954. }
  4955.  
  4956. visitForOfStatement(e) {
  4957. const t = this.visit(e.left);
  4958. const s = this.visit(e.right);
  4959. const i = this.visit(e.body);
  4960. return t !== e.left || s !== e.right || i !== e.body ? new ForOfStatement(t, s, i, e.await) : e;
  4961. }
  4962.  
  4963. visitForInStatement(e) {
  4964. const t = this.visit(e.left);
  4965. const s = this.visit(e.right);
  4966. const i = this.visit(e.body);
  4967. return t !== e.left || s !== e.right || i !== e.body ? new ForInStatement(t, s, i) : e;
  4968. }
  4969.  
  4970. visitFunctionDeclaration(e) {
  4971. const t = this.visit(e.id);
  4972. const s = this.visitNodeList(e.params);
  4973. const i = this.visit(e.body);
  4974. return t !== e.id || s !== e.params || i !== e.body ? new FunctionDeclaration(t, s, i, e.generator) : e;
  4975. }
  4976.  
  4977. visitFunctionExpression(e) {
  4978. const t = this.visit(e.id);
  4979. const s = this.visitNodeList(e.params);
  4980. const i = this.visit(e.body);
  4981. return t !== e.id || s !== e.params || i !== e.body ? new FunctionExpression(t, s, i, e.generator, e.async) : e;
  4982. }
  4983.  
  4984. visitIdentifier(e) {
  4985. return e;
  4986. }
  4987.  
  4988. visitIfStatement(e) {
  4989. const t = this.visit(e.test);
  4990. const s = this.visit(e.consequent);
  4991. const i = this.visit(e.alternate);
  4992. return t !== e.test || s !== e.consequent || i !== e.alternate ? new IfStatement(t, s, i) : e;
  4993. }
  4994.  
  4995. visitImportAttribute(e) {
  4996. const t = this.visit(e.key);
  4997. const s = this.visit(e.value);
  4998. return t !== e.key || s !== e.value ? new ImportAttribute(t, s) : e;
  4999. }
  5000.  
  5001. visitImportExpression(e) {
  5002. const t = this.visit(e.source);
  5003. const s = this.visit(e.attributes);
  5004. return t !== e.source || s !== e.attributes ? new ImportExpression(t, s) : e;
  5005. }
  5006.  
  5007. visitImportDeclaration(e) {
  5008. const t = this.visitNodeList(e.specifiers);
  5009. const s = this.visit(e.source);
  5010. const i = this.visitNodeList(e.assertions);
  5011. return t !== e.specifiers || s !== e.source || i !== e.assertions ? new ImportDeclaration(t, s, i) : e;
  5012. }
  5013.  
  5014. visitImportDefaultSpecifier(e) {
  5015. const t = this.visit(e.local);
  5016. return t !== e.local ? new ImportDefaultSpecifier(t) : e;
  5017. }
  5018.  
  5019. visitImportNamespaceSpecifier(e) {
  5020. const t = this.visit(e.local);
  5021. return t !== e.local ? new ImportNamespaceSpecifier(t) : e;
  5022. }
  5023.  
  5024. visitImportSpecifier(e) {
  5025. const t = this.visit(e.local);
  5026. const s = this.visit(e.imported);
  5027. return t !== e.local || s !== e.imported ? new ImportSpecifier(t, s) : e;
  5028. }
  5029.  
  5030. visitLiteral(e) {
  5031. return e;
  5032. }
  5033.  
  5034. visitLabeledStatement(e) {
  5035. const t = this.visit(e.label);
  5036. const s = this.visit(e.body);
  5037. return t !== e.label || s !== e.body ? new LabeledStatement(t, s) : e;
  5038. }
  5039.  
  5040. visitLogicalExpression(e) {
  5041. const t = this.visit(e.left);
  5042. const s = this.visit(e.right);
  5043. return t !== e.left || s !== e.right ? new LogicalExpression(e.operator, t, s) : e;
  5044. }
  5045.  
  5046. visitMemberExpression(e) {
  5047. const t = this.visit(e.object);
  5048. const s = this.visit(e.property);
  5049. return t !== e.object || s !== e.property ? new MemberExpression(e.computed, t, s, e.optional) : e;
  5050. }
  5051.  
  5052. visitMetaProperty(e) {
  5053. const t = this.visit(e.meta);
  5054. const s = this.visit(e.property);
  5055. return t !== e.meta || s !== e.property ? new MetaProperty(t, s) : e;
  5056. }
  5057.  
  5058. visitMethodDefinition(e) {
  5059. const t = this.visit(e.key);
  5060. const s = this.visit(e.value);
  5061. const i = this.visitNodeList(e.decorators);
  5062. return t !== e.key || s !== e.value || i !== e.decorators ? new MethodDefinition(t, e.computed, s, e.kind, e.static, i) : e;
  5063. }
  5064.  
  5065. visitNewExpression(e) {
  5066. const t = this.visit(e.callee);
  5067. const s = this.visitNodeList(e.arguments);
  5068. return t !== e.callee || s !== e.arguments ? new NewExpression(t, s) : e;
  5069. }
  5070.  
  5071. visitObjectExpression(e) {
  5072. const t = this.visitNodeList(e.properties);
  5073. return t !== e.properties ? new ObjectExpression(t) : e;
  5074. }
  5075.  
  5076. visitObjectPattern(e) {
  5077. const t = this.visitNodeList(e.properties);
  5078. return t !== e.properties ? new ObjectPattern(t) : e;
  5079. }
  5080.  
  5081. visitProgram(e) {
  5082. const t = this.visitNodeList(e.body);
  5083. return t !== e.body ? new Program(e.sourceType, t) : e;
  5084. }
  5085.  
  5086. visitProperty(e) {
  5087. const t = this.visit(e.key);
  5088. const s = this.visit(e.value);
  5089. const i = this.visitNodeList(e.decorators);
  5090. return t !== e.key || s !== e.value || i != i ? 'kind' in e ? new Property(e.kind, t, e.computed, s, e.method, e.shorthand) : new PropertyDefinition(t, e.computed, s, e.static, i) : e;
  5091. }
  5092.  
  5093. visitPrivateIdentifier(e) {
  5094. return e;
  5095. }
  5096.  
  5097. visitRestElement(e) {
  5098. const t = this.visit(e.argument);
  5099. return t !== e.argument ? new RestElement(t) : e;
  5100. }
  5101.  
  5102. visitReturnStatement(e) {
  5103. const t = this.visit(e.argument);
  5104. return t !== e.argument ? new ReturnStatement(t) : e;
  5105. }
  5106.  
  5107. visitSequenceExpression(e) {
  5108. const t = this.visitNodeList(e.expressions);
  5109. return t !== e.expressions ? new SequenceExpression(t) : e;
  5110. }
  5111.  
  5112. visitSpreadElement(e) {
  5113. const t = this.visit(e.argument);
  5114. return t !== e.argument ? new SpreadElement(t) : e;
  5115. }
  5116.  
  5117. visitStaticBlock(e) {
  5118. const t = this.visitNodeList(e.body);
  5119. return t !== e.body ? new StaticBlock(t) : e;
  5120. }
  5121.  
  5122. visitSuper(e) {
  5123. return e;
  5124. }
  5125.  
  5126. visitSwitchCase(e) {
  5127. const t = this.visit(e.test);
  5128. const s = this.visitNodeList(e.consequent);
  5129. return t !== e.test || s !== e.consequent ? new SwitchCase(t, s) : e;
  5130. }
  5131.  
  5132. visitSwitchStatement(e) {
  5133. const t = this.visit(e.discriminant);
  5134. const s = this.visitNodeList(e.cases);
  5135. return t !== e.discriminant || s !== e.cases ? new SwitchStatement(t, s) : e;
  5136. }
  5137.  
  5138. visitTaggedTemplateExpression(e) {
  5139. const t = this.visit(e.tag);
  5140. const s = this.visit(e.quasi);
  5141. return t !== e.tag || s !== e.quasi ? new TaggedTemplateExpression(t, s) : e;
  5142. }
  5143.  
  5144. visitTemplateElement(e) {
  5145. return e;
  5146. }
  5147.  
  5148. visitTemplateLiteral(e) {
  5149. const t = this.visitNodeList(e.quasis);
  5150. const s = this.visitNodeList(e.expressions);
  5151. return t !== e.quasis || s !== e.expressions ? new TemplateLiteral(t, s) : e;
  5152. }
  5153.  
  5154. visitThisExpression(e) {
  5155. return e;
  5156. }
  5157.  
  5158. visitThrowStatement(e) {
  5159. const t = this.visit(e.argument);
  5160. return t !== e.argument ? new ThrowStatement(t) : e;
  5161. }
  5162.  
  5163. visitTryStatement(e) {
  5164. const t = this.visit(e.block);
  5165. const s = this.visit(e.handler);
  5166. const i = this.visit(e.finalizer);
  5167. return t !== e.block || s !== e.handler || i !== e.finalizer ? new TryStatement(t, s, i) : e;
  5168. }
  5169.  
  5170. visitUnaryExpression(e) {
  5171. const t = this.visit(e.argument);
  5172. return t !== e.argument ? new UnaryExpression(e.operator, t) : e;
  5173. }
  5174.  
  5175. visitUpdateExpression(e) {
  5176. const t = this.visit(e.argument);
  5177. return t !== e.argument ? new UpdateExpression(e.operator, t, e.prefix) : e;
  5178. }
  5179.  
  5180. visitVariableDeclaration(e) {
  5181. const t = this.visitNodeList(e.declarations);
  5182. return t !== e.declarations ? new VariableDeclaration(t, e.kind) : e;
  5183. }
  5184.  
  5185. visitVariableDeclarator(e) {
  5186. const t = this.visit(e.id);
  5187. const s = this.visit(e.init);
  5188. return t !== e.id || s !== e.init ? new VariableDeclarator(t, s) : e;
  5189. }
  5190.  
  5191. visitWhileStatement(e) {
  5192. const t = this.visit(e.test);
  5193. const s = this.visit(e.body);
  5194. return t !== e.test || s !== e.body ? new WhileStatement(t, s) : e;
  5195. }
  5196.  
  5197. visitWithStatement(e) {
  5198. const t = this.visit(e.object);
  5199. const s = this.visit(e.body);
  5200. return t !== e.object || s !== e.body ? new WithStatement(t, s) : e;
  5201. }
  5202.  
  5203. visitYieldExpression(e) {
  5204. const t = this.visit(e.argument);
  5205. return t !== e.argument ? new YieldExpression(t, e.delegate) : e;
  5206. }
  5207. };
  5208.  
  5209. function parse(e, t, s) {
  5210. let i = null;
  5211. const r = (e, t) => {
  5212. s && s(e, t), i && i.visit(e, t);
  5213. };
  5214. let n = typeof s === 'function' ? r : null;
  5215. let a = !1;
  5216. if (t) {
  5217. a = typeof t.comment === 'boolean' && t.comment;
  5218. const e = typeof t.attachComment === 'boolean' && t.attachComment;
  5219. (a || e) && (i = new CommentHandler(), i.attach = e, t.comment = !0, n = r);
  5220. }
  5221. let o; let
  5222. u = !1;
  5223. t && typeof t.sourceType === 'string' && (u = t.sourceType === 'module'), o = t && typeof t.jsx === 'boolean' && t.jsx ? new JSXParser(e, t, n) : new Parser(e, t, n);
  5224. const h = u ? o.parseModule() : o.parseScript();
  5225. return a && i && (h.comments = i.comments), o.config.tokens && (h.tokens = o.tokens), o.config.tolerant && (h.errors = o.errorHandler.errors), h;
  5226. }
  5227.  
  5228. function parseModule(e, t, s) {
  5229. const i = t || {};
  5230. return i.sourceType = 'module', parse(e, i, s);
  5231. }
  5232.  
  5233. function parseScript(e, t, s) {
  5234. const i = t || {};
  5235. return i.sourceType = 'script', parse(e, i, s);
  5236. }
  5237.  
  5238. function tokenize(e, t, s) {
  5239. const i = new Tokenizer(e, t);
  5240. const r = [];
  5241. try {
  5242. for (;;) {
  5243. let e = i.getNextToken();
  5244. if (!e) break;
  5245. s && (e = s(e)), r.push(e);
  5246. }
  5247. } catch (e) {
  5248. i.errorHandler.tolerate(e);
  5249. }
  5250. return i.errorHandler.tolerant && (r.errors = i.errors()), r;
  5251. }
  5252. const version = '6.0.3';
  5253. // eslint-disable-next-line camelcase
  5254. return {
  5255. parse,
  5256. parseModule,
  5257. parseScript,
  5258. tokenize,
  5259. Syntax,
  5260. version
  5261. };
  5262. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址