ESTreeProcessor

Compiles a string containing Javascript to an ESTree object and/or executes an ESTree object in Javascript

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

  1. // ==UserScript==
  2. // @name ESTreeProcessor
  3. // @namespace https://github.com/mapomatic
  4. // @version 2.1.1
  5. // @description Compiles a string containing Javascript to an ESTree object and/or executes an ESTree object in Javascript
  6. // @author MapOMatic
  7. // @match *://*/*
  8. // @license GNU GPLv3
  9. // ==/UserScript==
  10.  
  11. // TODO:
  12. // - Add support for classes
  13. // - Probably a lot more I haven't discovered yet.
  14.  
  15. /* eslint-disable */
  16. const ESTreeProcessor = (function() {
  17. 'use strict';
  18.  
  19. // Update this when you make any changes to ESTreeProcessor.
  20. const VERSION = '2.1.1';
  21.  
  22. // This is a copy of the esprima-next library. The Node.js build has been modified to work with userscripts.
  23. // The following copyright notice applies to the espima-next library.
  24.  
  25. // Copyright JS Foundation and other contributors, https://js.foundation/
  26.  
  27. // Redistribution and use in source and binary forms, with or without
  28. // modification, are permitted provided that the following conditions are met:
  29.  
  30. // * Redistributions of source code must retain the above copyright
  31. // notice, this list of conditions and the following disclaimer.
  32. // * Redistributions in binary form must reproduce the above copyright
  33. // notice, this list of conditions and the following disclaimer in the
  34. // documentation and/or other materials provided with the distribution.
  35.  
  36. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  37. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  39. // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  40. // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  41. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  45. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.  
  47. const esprima = (function() {
  48. 'use strict';
  49.  
  50. const Syntax = {
  51. AssignmentExpression: 'AssignmentExpression',
  52. AssignmentPattern: 'AssignmentPattern',
  53. ArrayExpression: 'ArrayExpression',
  54. ArrayPattern: 'ArrayPattern',
  55. ArrowFunctionExpression: 'ArrowFunctionExpression',
  56. AwaitExpression: 'AwaitExpression',
  57. BlockStatement: 'BlockStatement',
  58. BinaryExpression: 'BinaryExpression',
  59. BreakStatement: 'BreakStatement',
  60. CallExpression: 'CallExpression',
  61. CatchClause: 'CatchClause',
  62. ChainExpression: 'ChainExpression',
  63. ClassBody: 'ClassBody',
  64. ClassDeclaration: 'ClassDeclaration',
  65. ClassExpression: 'ClassExpression',
  66. ConditionalExpression: 'ConditionalExpression',
  67. ContinueStatement: 'ContinueStatement',
  68. Decorator: 'Decorator',
  69. DoWhileStatement: 'DoWhileStatement',
  70. DebuggerStatement: 'DebuggerStatement',
  71. EmptyStatement: 'EmptyStatement',
  72. ExportAllDeclaration: 'ExportAllDeclaration',
  73. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  74. ExportNamedDeclaration: 'ExportNamedDeclaration',
  75. ExportSpecifier: 'ExportSpecifier',
  76. ExpressionStatement: 'ExpressionStatement',
  77. ForStatement: 'ForStatement',
  78. ForOfStatement: 'ForOfStatement',
  79. ForInStatement: 'ForInStatement',
  80. FunctionDeclaration: 'FunctionDeclaration',
  81. FunctionExpression: 'FunctionExpression',
  82. Identifier: 'Identifier',
  83. IfStatement: 'IfStatement',
  84. ImportAttribute: 'ImportAttribute',
  85. ImportExpression: 'ImportExpression',
  86. ImportDeclaration: 'ImportDeclaration',
  87. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  88. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  89. ImportSpecifier: 'ImportSpecifier',
  90. Literal: 'Literal',
  91. LabeledStatement: 'LabeledStatement',
  92. LogicalExpression: 'LogicalExpression',
  93. MemberExpression: 'MemberExpression',
  94. MetaProperty: 'MetaProperty',
  95. MethodDefinition: 'MethodDefinition',
  96. NewExpression: 'NewExpression',
  97. ObjectExpression: 'ObjectExpression',
  98. ObjectPattern: 'ObjectPattern',
  99. Program: 'Program',
  100. Property: 'Property',
  101. PrivateIdentifier: 'PrivateIdentifier',
  102. RestElement: 'RestElement',
  103. ReturnStatement: 'ReturnStatement',
  104. SequenceExpression: 'SequenceExpression',
  105. SpreadElement: 'SpreadElement',
  106. StaticBlock: 'StaticBlock',
  107. Super: 'Super',
  108. SwitchCase: 'SwitchCase',
  109. SwitchStatement: 'SwitchStatement',
  110. TaggedTemplateExpression: 'TaggedTemplateExpression',
  111. TemplateElement: 'TemplateElement',
  112. TemplateLiteral: 'TemplateLiteral',
  113. ThisExpression: 'ThisExpression',
  114. ThrowStatement: 'ThrowStatement',
  115. TryStatement: 'TryStatement',
  116. UnaryExpression: 'UnaryExpression',
  117. UpdateExpression: 'UpdateExpression',
  118. VariableDeclaration: 'VariableDeclaration',
  119. VariableDeclarator: 'VariableDeclarator',
  120. WhileStatement: 'WhileStatement',
  121. WithStatement: 'WithStatement',
  122. YieldExpression: 'YieldExpression'
  123. };
  124.  
  125. class CommentHandler {
  126. attach;
  127. comments;
  128. stack;
  129. leading;
  130. trailing;
  131. constructor() {
  132. this.attach = !1, this.comments = [], this.stack = [], this.leading = [], this.trailing = [];
  133. }
  134.  
  135. insertInnerComments(e, t) {
  136. if (e.type === 'BlockStatement' && e.body.length === 0) {
  137. const s = [];
  138. for (let e = this.leading.length - 1; e >= 0; --e) {
  139. const i = this.leading[e];
  140. t.end.offset >= i.start && (s.unshift(i.comment), this.leading.splice(e, 1), this.trailing.splice(e, 1));
  141. }
  142. s.length && (e.innerComments = s);
  143. }
  144. }
  145.  
  146. findTrailingComments(e) {
  147. let t = [];
  148. if (this.trailing.length > 0) {
  149. for (let s = this.trailing.length - 1; s >= 0; --s) {
  150. const i = this.trailing[s];
  151. i.start >= e.end.offset && t.unshift(i.comment);
  152. }
  153. return this.trailing.length = 0, t;
  154. }
  155. const s = this.stack[this.stack.length - 1];
  156. if (s && s.node.trailingComments) {
  157. const i = s.node.trailingComments[0];
  158. i && i.range[0] >= e.end.offset && (t = s.node.trailingComments, delete s.node.trailingComments);
  159. }
  160. return t;
  161. }
  162.  
  163. findLeadingComments(e) {
  164. const t = [];
  165. let s;
  166. for (; this.stack.length > 0;) {
  167. const t = this.stack[this.stack.length - 1];
  168. if (!(t && t.start >= e.start.offset)) break;
  169. s = t.node, this.stack.pop();
  170. }
  171. if (s) {
  172. for (let i = (s.leadingComments ? s.leadingComments.length : 0) - 1; i >= 0; --i) {
  173. const r = s.leadingComments[i];
  174. r.range[1] <= e.start.offset && (t.unshift(r), s.leadingComments.splice(i, 1));
  175. }
  176. return s.leadingComments && s.leadingComments.length === 0 && delete s.leadingComments, t;
  177. }
  178. for (let s = this.leading.length - 1; s >= 0; --s) {
  179. const i = this.leading[s];
  180. i.start <= e.start.offset && (t.unshift(i.comment), this.leading.splice(s, 1));
  181. }
  182. return t;
  183. }
  184.  
  185. visitNode(e, t) {
  186. if (e.type === 'Program' && e.body.length > 0) return;
  187. this.insertInnerComments(e, t);
  188. const s = this.findTrailingComments(t);
  189. const i = this.findLeadingComments(t);
  190. i.length > 0 && (e.leadingComments = i), s.length > 0 && (e.trailingComments = s), this.stack.push({
  191. node: e,
  192. start: t.start.offset
  193. });
  194. }
  195.  
  196. visitComment(e, t) {
  197. const s = e.type[0] === 'L' ? 'Line' : 'Block';
  198. const i = {
  199. type: s,
  200. value: e.value
  201. };
  202. if (e.range && (i.range = e.range), e.loc && (i.loc = e.loc), this.comments.push(i), this.attach) {
  203. const i = {
  204. comment: {
  205. type: s,
  206. value: e.value,
  207. range: [t.start.offset, t.end.offset]
  208. },
  209. start: t.start.offset
  210. };
  211. e.loc && (i.comment.loc = e.loc), e.type = s, this.leading.push(i), this.trailing.push(i);
  212. }
  213. }
  214.  
  215. visit(e, t) {
  216. e.type === 'LineComment' || e.type === 'BlockComment' ? this.visitComment(e, t) : this.attach && this.visitNode(e, t);
  217. }
  218. }
  219.  
  220. const Regex = {
  221. 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]/,
  222. // eslint-disable-next-line no-misleading-character-class
  223. 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]/
  224. };
  225.  
  226. const Character = {
  227. fromCodePoint: e => (e < 65536 ? String.fromCharCode(e) : String.fromCharCode(55296 + (e - 65536 >> 10)) + String.fromCharCode(56320 + (e - 65536 & 1023))),
  228. isStringWellFormedUnicode(e) {
  229. for (let t = 0; t < e.length; t++) {
  230. let s = e.charCodeAt(t);
  231. if (s >= 55296 && s <= 56319) {
  232. if (t === e.length - 1) return !1;
  233. if (t++, s = e.charCodeAt(t), s < 56320 && s > 57343) return !1;
  234. } else if (s >= 56320 && s <= 57343) return !1;
  235. }
  236. return !0;
  237. },
  238. 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,
  239. isLineTerminator: e => e === 10 || e === 13 || e === 8232 || e === 8233,
  240. isIdentifierStart: e => e === 36 || e === 95 || e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 92 || e >= 128 && Regex.NonAsciiIdentifierStart.test(Character.fromCodePoint(e)),
  241. 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)),
  242. isDecimalDigit: e => e >= 48 && e <= 57,
  243. isDecimalDigitChar: e => e.length === 1 && Character.isDecimalDigit(e.charCodeAt(0)),
  244. isHexDigit: e => e >= 48 && e <= 57 || e >= 65 && e <= 70 || e >= 97 && e <= 102,
  245. isHexDigitChar: e => e.length === 1 && Character.isHexDigit(e.charCodeAt(0)),
  246. isOctalDigit: e => e >= 48 && e <= 55,
  247. isOctalDigitChar: e => e.length === 1 && Character.isOctalDigit(e.charCodeAt(0))
  248. };
  249.  
  250. class JSXClosingElement {
  251. type;
  252. name;
  253. constructor(e) {
  254. this.type = 'JSXClosingElement', this.name = e;
  255. }
  256. }
  257.  
  258. const JSXClosingFragment = class {
  259. type;
  260. constructor() {
  261. this.type = 'JSXClosingFragment';
  262. }
  263. };
  264.  
  265. const JSXElement = class {
  266. type;
  267. openingElement;
  268. children;
  269. closingElement;
  270. constructor(e, t, s) {
  271. this.type = 'JSXElement', this.openingElement = e, this.children = t, this.closingElement = s;
  272. }
  273. };
  274.  
  275. const JSXEmptyExpression = class {
  276. type;
  277. constructor() {
  278. this.type = 'JSXEmptyExpression';
  279. }
  280. };
  281.  
  282. const JSXExpressionContainer = class {
  283. type;
  284. expression;
  285. constructor(e) {
  286. this.type = 'JSXExpressionContainer', this.expression = e;
  287. }
  288. };
  289.  
  290. const JSXIdentifier = class {
  291. type;
  292. name;
  293. constructor(e) {
  294. this.type = 'JSXIdentifier', this.name = e;
  295. }
  296. };
  297.  
  298. const JSXMemberExpression = class {
  299. type;
  300. object;
  301. property;
  302. constructor(e, t) {
  303. this.type = 'JSXMemberExpression', this.object = e, this.property = t;
  304. }
  305. };
  306.  
  307. const JSXAttribute = class {
  308. type;
  309. name;
  310. value;
  311. constructor(e, t) {
  312. this.type = 'JSXAttribute', this.name = e, this.value = t;
  313. }
  314. };
  315.  
  316. const JSXNamespacedName = class {
  317. type;
  318. namespace;
  319. name;
  320. constructor(e, t) {
  321. this.type = 'JSXNamespacedName', this.namespace = e, this.name = t;
  322. }
  323. };
  324.  
  325. const JSXOpeningElement = class {
  326. type;
  327. name;
  328. selfClosing;
  329. attributes;
  330. constructor(e, t, s) {
  331. this.type = 'JSXOpeningElement', this.name = e, this.selfClosing = t, this.attributes = s;
  332. }
  333. };
  334.  
  335. const JSXOpeningFragment = class {
  336. type;
  337. selfClosing;
  338. constructor(e) {
  339. this.type = 'JSXOpeningFragment', this.selfClosing = e;
  340. }
  341. };
  342.  
  343. const JSXSpreadAttribute = class {
  344. type;
  345. argument;
  346. constructor(e) {
  347. this.type = 'JSXSpreadAttribute', this.argument = e;
  348. }
  349. };
  350.  
  351. const JSXText = class {
  352. type;
  353. value;
  354. raw;
  355. constructor(e, t) {
  356. this.type = 'JSXText', this.value = e, this.raw = t;
  357. }
  358. };
  359.  
  360. const ArrayExpression = class {
  361. type;
  362. elements;
  363. constructor(e) {
  364. this.type = 'ArrayExpression', this.elements = e;
  365. }
  366. };
  367.  
  368. const ArrayPattern = class {
  369. type;
  370. elements;
  371. constructor(e) {
  372. this.type = 'ArrayPattern', this.elements = e;
  373. }
  374. };
  375.  
  376. const ArrowFunctionExpression = class {
  377. type;
  378. id;
  379. params;
  380. body;
  381. generator;
  382. expression;
  383. async;
  384. constructor(e, t, s, i) {
  385. this.type = 'ArrowFunctionExpression', this.id = null, this.params = e, this.body = t, this.generator = !1, this.expression = s, this.async = i;
  386. }
  387. };
  388.  
  389. const AssignmentExpression = class {
  390. type;
  391. operator;
  392. left;
  393. right;
  394. constructor(e, t, s) {
  395. this.type = 'AssignmentExpression', this.operator = e, this.left = t, this.right = s;
  396. }
  397. };
  398.  
  399. const AssignmentPattern = class {
  400. type;
  401. left;
  402. right;
  403. constructor(e, t) {
  404. this.type = 'AssignmentPattern', this.left = e, this.right = t;
  405. }
  406. };
  407.  
  408. const AsyncFunctionDeclaration = class {
  409. type;
  410. id;
  411. params;
  412. body;
  413. generator;
  414. expression;
  415. async;
  416. constructor(e, t, s, i) {
  417. this.type = 'FunctionDeclaration', this.id = e, this.params = t, this.body = s, this.generator = i, this.expression = !1, this.async = !0;
  418. }
  419. };
  420.  
  421. const AwaitExpression = class {
  422. type;
  423. argument;
  424. constructor(e) {
  425. this.type = 'AwaitExpression', this.argument = e;
  426. }
  427. };
  428.  
  429. const BigIntLiteral = class {
  430. type;
  431. value;
  432. raw;
  433. bigint;
  434. constructor(e, t, s) {
  435. this.type = 'Literal', this.value = e, this.raw = t, this.bigint = s;
  436. }
  437. };
  438.  
  439. const BinaryExpression = class {
  440. type;
  441. operator;
  442. left;
  443. right;
  444. constructor(e, t, s) {
  445. this.type = 'BinaryExpression', this.operator = e, this.left = t, this.right = s;
  446. }
  447. };
  448. const BlockStatement = class {
  449. type;
  450. body;
  451. constructor(e) {
  452. this.type = 'BlockStatement', this.body = e;
  453. }
  454. };
  455. const BreakStatement = class {
  456. type;
  457. label;
  458. constructor(e) {
  459. this.type = 'BreakStatement', this.label = e;
  460. }
  461. };
  462. const CallExpression = class {
  463. type;
  464. callee;
  465. arguments;
  466. optional;
  467. constructor(e, t, s) {
  468. this.type = 'CallExpression', this.callee = e, this.arguments = t, this.optional = s;
  469. }
  470. };
  471. const CatchClause = class {
  472. type;
  473. param;
  474. body;
  475. constructor(e, t) {
  476. this.type = 'CatchClause', this.param = e, this.body = t;
  477. }
  478. };
  479. const ChainExpression = class {
  480. type;
  481. expression;
  482. constructor(e) {
  483. this.type = 'ChainExpression', this.expression = e;
  484. }
  485. };
  486. const ClassBody = class {
  487. type;
  488. body;
  489. constructor(e) {
  490. this.type = 'ClassBody', this.body = e;
  491. }
  492. };
  493. const ClassDeclaration = class {
  494. type;
  495. id;
  496. superClass;
  497. body;
  498. decorators;
  499. constructor(e, t, s, i) {
  500. this.type = 'ClassDeclaration', this.id = e, this.superClass = t, this.body = s, this.decorators = i;
  501. }
  502. };
  503. const ClassExpression = class {
  504. type;
  505. id;
  506. superClass;
  507. body;
  508. decorators;
  509. constructor(e, t, s, i) {
  510. this.type = 'ClassExpression', this.id = e, this.superClass = t, this.body = s, this.decorators = i;
  511. }
  512. };
  513. const ConditionalExpression = class {
  514. type;
  515. test;
  516. consequent;
  517. alternate;
  518. constructor(e, t, s) {
  519. this.type = 'ConditionalExpression', this.test = e, this.consequent = t, this.alternate = s;
  520. }
  521. };
  522. const ContinueStatement = class {
  523. type;
  524. label;
  525. constructor(e) {
  526. this.type = 'ContinueStatement', this.label = e;
  527. }
  528. };
  529. const DebuggerStatement = class {
  530. type;
  531. constructor() {
  532. this.type = 'DebuggerStatement';
  533. }
  534. };
  535. const Decorator = class {
  536. type;
  537. expression;
  538. constructor(e) {
  539. this.type = 'Decorator', this.expression = e;
  540. }
  541. };
  542. const Directive = class {
  543. type;
  544. expression;
  545. directive;
  546. constructor(e, t) {
  547. this.type = 'ExpressionStatement', this.expression = e, this.directive = t;
  548. }
  549. };
  550. const DoWhileStatement = class {
  551. type;
  552. body;
  553. test;
  554. constructor(e, t) {
  555. this.type = 'DoWhileStatement', this.body = e, this.test = t;
  556. }
  557. };
  558. const EmptyStatement = class {
  559. type;
  560. constructor() {
  561. this.type = 'EmptyStatement';
  562. }
  563. };
  564. const ExportAllDeclaration = class {
  565. type;
  566. source;
  567. exported;
  568. assertions;
  569. constructor(e, t, s) {
  570. this.type = 'ExportAllDeclaration', this.source = e, this.exported = t, this.assertions = s;
  571. }
  572. };
  573. const ExportDefaultDeclaration = class {
  574. type;
  575. declaration;
  576. constructor(e) {
  577. this.type = 'ExportDefaultDeclaration', this.declaration = e;
  578. }
  579. };
  580. const ExportNamedDeclaration = class {
  581. type;
  582. declaration;
  583. specifiers;
  584. source;
  585. assertions;
  586. constructor(e, t, s, i) {
  587. this.type = 'ExportNamedDeclaration', this.declaration = e, this.specifiers = t, this.source = s, this.assertions = i;
  588. }
  589. };
  590. const ExportSpecifier = class {
  591. type;
  592. exported;
  593. local;
  594. constructor(e, t) {
  595. this.type = 'ExportSpecifier', this.exported = t, this.local = e;
  596. }
  597. };
  598. const ExpressionStatement = class {
  599. type;
  600. expression;
  601. constructor(e) {
  602. this.type = 'ExpressionStatement', this.expression = e;
  603. }
  604. };
  605. const ForInStatement = class {
  606. type;
  607. left;
  608. right;
  609. body;
  610. each;
  611. constructor(e, t, s) {
  612. this.type = 'ForInStatement', this.left = e, this.right = t, this.body = s, this.each = !1;
  613. }
  614. };
  615. const ForOfStatement = class {
  616. type;
  617. await;
  618. left;
  619. right;
  620. body;
  621. constructor(e, t, s, i) {
  622. this.type = 'ForOfStatement', this.await = i, this.left = e, this.right = t, this.body = s;
  623. }
  624. };
  625. const ForStatement = class {
  626. type;
  627. init;
  628. test;
  629. update;
  630. body;
  631. constructor(e, t, s, i) {
  632. this.type = 'ForStatement', this.init = e, this.test = t, this.update = s, this.body = i;
  633. }
  634. };
  635. const FunctionDeclaration = class {
  636. type;
  637. id;
  638. params;
  639. body;
  640. generator;
  641. expression;
  642. async;
  643. constructor(e, t, s, i) {
  644. this.type = 'FunctionDeclaration', this.id = e, this.params = t, this.body = s, this.generator = i, this.expression = !1, this.async = !1;
  645. }
  646. };
  647. const FunctionExpression = class {
  648. type;
  649. id;
  650. params;
  651. body;
  652. generator;
  653. expression;
  654. async;
  655. constructor(e, t, s, i, r) {
  656. this.type = 'FunctionExpression', this.id = e, this.params = t, this.body = s, this.generator = i, this.expression = !1, this.async = r;
  657. }
  658. };
  659. const Identifier = class {
  660. type;
  661. name;
  662. constructor(e) {
  663. this.type = 'Identifier', this.name = e;
  664. }
  665. };
  666. const IfStatement = class {
  667. type;
  668. test;
  669. consequent;
  670. alternate;
  671. constructor(e, t, s) {
  672. this.type = 'IfStatement', this.test = e, this.consequent = t, this.alternate = s;
  673. }
  674. };
  675. const ImportAttribute = class {
  676. type;
  677. key;
  678. value;
  679. constructor(e, t) {
  680. this.type = 'ImportAttribute', this.key = e, this.value = t;
  681. }
  682. };
  683. const ImportExpression = class {
  684. type;
  685. source;
  686. attributes;
  687. constructor(e, t) {
  688. this.type = 'ImportExpression', this.source = e, this.attributes = t;
  689. }
  690. };
  691. const ImportDeclaration = class {
  692. type;
  693. specifiers;
  694. source;
  695. assertions;
  696. constructor(e, t, s) {
  697. this.type = 'ImportDeclaration', this.specifiers = e, this.source = t, this.assertions = s;
  698. }
  699. };
  700. const ImportDefaultSpecifier = class {
  701. type;
  702. local;
  703. constructor(e) {
  704. this.type = 'ImportDefaultSpecifier', this.local = e;
  705. }
  706. };
  707. const ImportNamespaceSpecifier = class {
  708. type;
  709. local;
  710. constructor(e) {
  711. this.type = 'ImportNamespaceSpecifier', this.local = e;
  712. }
  713. };
  714. const ImportSpecifier = class {
  715. type;
  716. local;
  717. imported;
  718. constructor(e, t) {
  719. this.type = 'ImportSpecifier', this.local = e, this.imported = t;
  720. }
  721. };
  722. const LabeledStatement = class {
  723. type;
  724. label;
  725. body;
  726. constructor(e, t) {
  727. this.type = 'LabeledStatement', this.label = e, this.body = t;
  728. }
  729. };
  730. const Literal = class {
  731. type;
  732. value;
  733. raw;
  734. constructor(e, t) {
  735. this.type = 'Literal', this.value = e, this.raw = t;
  736. }
  737. };
  738. const LogicalExpression = class {
  739. type;
  740. operator;
  741. left;
  742. right;
  743. constructor(e, t, s) {
  744. this.type = 'LogicalExpression', this.operator = e, this.left = t, this.right = s;
  745. }
  746. };
  747. const MemberExpression = class {
  748. type;
  749. computed;
  750. object;
  751. property;
  752. optional;
  753. constructor(e, t, s, i) {
  754. this.type = 'MemberExpression', this.computed = e, this.object = t, this.property = s, this.optional = i;
  755. }
  756. };
  757. const MetaProperty = class {
  758. type;
  759. meta;
  760. property;
  761. constructor(e, t) {
  762. this.type = 'MetaProperty', this.meta = e, this.property = t;
  763. }
  764. };
  765. const MethodDefinition = class {
  766. type;
  767. key;
  768. computed;
  769. value;
  770. kind;
  771. static;
  772. decorators;
  773. constructor(e, t, s, i, r, n) {
  774. this.type = 'MethodDefinition', this.key = e, this.computed = t, this.value = s, this.kind = i, this.static = r, this.decorators = n;
  775. }
  776. };
  777. const Module = class {
  778. type;
  779. body;
  780. sourceType;
  781. constructor(e) {
  782. this.type = 'Program', this.body = e, this.sourceType = 'module';
  783. }
  784. };
  785. const NewExpression = class {
  786. type;
  787. callee;
  788. arguments;
  789. constructor(e, t) {
  790. this.type = 'NewExpression', this.callee = e, this.arguments = t;
  791. }
  792. };
  793. const ObjectExpression = class {
  794. type;
  795. properties;
  796. constructor(e) {
  797. this.type = 'ObjectExpression', this.properties = e;
  798. }
  799. };
  800. const ObjectPattern = class {
  801. type;
  802. properties;
  803. constructor(e) {
  804. this.type = 'ObjectPattern', this.properties = e;
  805. }
  806. };
  807. const PrivateIdentifier = class {
  808. type;
  809. name;
  810. constructor(e) {
  811. this.type = 'PrivateIdentifier', this.name = e;
  812. }
  813. };
  814. const Program = class {
  815. type;
  816. body;
  817. sourceType;
  818. constructor(e, t) {
  819. this.type = 'Program', this.sourceType = e, this.body = t;
  820. }
  821. };
  822. const Property = class {
  823. type;
  824. key;
  825. computed;
  826. value;
  827. kind;
  828. method;
  829. shorthand;
  830. constructor(e, t, s, i, r, n) {
  831. this.type = 'Property', this.key = t, this.computed = s, this.value = i, this.kind = e, this.method = r, this.shorthand = n;
  832. }
  833. };
  834. const PropertyDefinition = class {
  835. type;
  836. key;
  837. computed;
  838. value;
  839. static;
  840. decorators;
  841. constructor(e, t, s, i, r) {
  842. this.type = 'Property', this.key = e, this.computed = t, this.value = s, this.static = i, this.decorators = r;
  843. }
  844. };
  845. const RegexLiteral = class {
  846. type;
  847. value;
  848. raw;
  849. regex;
  850. constructor(e, t, s, i) {
  851. this.type = 'Literal', this.value = e, this.raw = t, this.regex = {
  852. pattern: s,
  853. flags: i
  854. };
  855. }
  856. };
  857. const RestElement = class {
  858. type;
  859. argument;
  860. constructor(e) {
  861. this.type = 'RestElement', this.argument = e;
  862. }
  863. };
  864. const ReturnStatement = class {
  865. type;
  866. argument;
  867. constructor(e) {
  868. this.type = 'ReturnStatement', this.argument = e;
  869. }
  870. };
  871. const Script = class {
  872. type;
  873. body;
  874. sourceType;
  875. constructor(e) {
  876. this.type = 'Program', this.body = e, this.sourceType = 'script';
  877. }
  878. };
  879. const SequenceExpression = class {
  880. type;
  881. expressions;
  882. constructor(e) {
  883. this.type = 'SequenceExpression', this.expressions = e;
  884. }
  885. };
  886. const SpreadElement = class {
  887. type;
  888. argument;
  889. constructor(e) {
  890. this.type = 'SpreadElement', this.argument = e;
  891. }
  892. };
  893. const StaticBlock = class {
  894. type;
  895. body;
  896. constructor(e) {
  897. this.type = 'StaticBlock', this.body = e;
  898. }
  899. };
  900. const Super = class {
  901. type;
  902. constructor() {
  903. this.type = 'Super';
  904. }
  905. };
  906. const SwitchCase = class {
  907. type;
  908. test;
  909. consequent;
  910. constructor(e, t) {
  911. this.type = 'SwitchCase', this.test = e, this.consequent = t;
  912. }
  913. };
  914. const SwitchStatement = class {
  915. type;
  916. discriminant;
  917. cases;
  918. constructor(e, t) {
  919. this.type = 'SwitchStatement', this.discriminant = e, this.cases = t;
  920. }
  921. };
  922. const TaggedTemplateExpression = class {
  923. type;
  924. tag;
  925. quasi;
  926. constructor(e, t) {
  927. this.type = 'TaggedTemplateExpression', this.tag = e, this.quasi = t;
  928. }
  929. };
  930. const TemplateElement = class {
  931. type;
  932. value;
  933. tail;
  934. constructor(e, t) {
  935. this.type = 'TemplateElement', this.value = e, this.tail = t;
  936. }
  937. };
  938. const TemplateLiteral = class {
  939. type;
  940. quasis;
  941. expressions;
  942. constructor(e, t) {
  943. this.type = 'TemplateLiteral', this.quasis = e, this.expressions = t;
  944. }
  945. };
  946. const ThisExpression = class {
  947. type;
  948. constructor() {
  949. this.type = 'ThisExpression';
  950. }
  951. };
  952. const ThrowStatement = class {
  953. type;
  954. argument;
  955. constructor(e) {
  956. this.type = 'ThrowStatement', this.argument = e;
  957. }
  958. };
  959. const TryStatement = class {
  960. type;
  961. block;
  962. handler;
  963. finalizer;
  964. constructor(e, t, s) {
  965. this.type = 'TryStatement', this.block = e, this.handler = t, this.finalizer = s;
  966. }
  967. };
  968. const UnaryExpression = class {
  969. type;
  970. operator;
  971. argument;
  972. prefix;
  973. constructor(e, t) {
  974. this.type = 'UnaryExpression', this.operator = e, this.argument = t, this.prefix = !0;
  975. }
  976. };
  977. const UpdateExpression = class {
  978. type;
  979. operator;
  980. argument;
  981. prefix;
  982. constructor(e, t, s) {
  983. this.type = 'UpdateExpression', this.operator = e, this.argument = t, this.prefix = s;
  984. }
  985. };
  986. const VariableDeclaration = class {
  987. type;
  988. declarations;
  989. kind;
  990. constructor(e, t) {
  991. this.type = 'VariableDeclaration', this.declarations = e, this.kind = t;
  992. }
  993. };
  994. const VariableDeclarator = class {
  995. type;
  996. id;
  997. init;
  998. constructor(e, t) {
  999. this.type = 'VariableDeclarator', this.id = e, this.init = t;
  1000. }
  1001. };
  1002. const WhileStatement = class {
  1003. type;
  1004. test;
  1005. body;
  1006. constructor(e, t) {
  1007. this.type = 'WhileStatement', this.test = e, this.body = t;
  1008. }
  1009. };
  1010. const WithStatement = class {
  1011. type;
  1012. object;
  1013. body;
  1014. constructor(e, t) {
  1015. this.type = 'WithStatement', this.object = e, this.body = t;
  1016. }
  1017. };
  1018. const YieldExpression = class {
  1019. type;
  1020. argument;
  1021. delegate;
  1022. constructor(e, t) {
  1023. this.type = 'YieldExpression', this.argument = e, this.delegate = t;
  1024. }
  1025. };
  1026.  
  1027. function assert(e, t) {
  1028. if (!e) throw new Error(`ASSERT: ${t}`);
  1029. }
  1030. const ErrorHandler = class {
  1031. errors;
  1032. tolerant;
  1033. constructor() {
  1034. this.errors = [], this.tolerant = !1;
  1035. }
  1036.  
  1037. recordError(e) {
  1038. this.errors.push(e);
  1039. }
  1040.  
  1041. tolerate(e) {
  1042. if (!this.tolerant) throw e;
  1043. this.recordError(e);
  1044. }
  1045.  
  1046. constructError(e, t) {
  1047. let s = new Error(e);
  1048. try {
  1049. throw s;
  1050. } catch (e) {
  1051. Object.create && Object.defineProperty && (s = Object.create(e), Object.defineProperty(s, 'column', {
  1052. value: t
  1053. }));
  1054. }
  1055. return s;
  1056. }
  1057.  
  1058. createError(e, t, s, i) {
  1059. const r = `Line ${t}: ${i}`;
  1060. const n = this.constructError(r, s);
  1061. n.index = e, n.lineNumber = t, n.description = i;
  1062. return n;
  1063. }
  1064.  
  1065. throwError(e, t, s, i) {
  1066. throw this.createError(e, t, s, i);
  1067. }
  1068.  
  1069. tolerateError(e, t, s, i) {
  1070. const r = this.createError(e, t, s, i);
  1071. if (!this.tolerant) throw r;
  1072. this.recordError(r);
  1073. }
  1074. };
  1075. const Messages = {
  1076. AsyncFunctionInSingleStatementContext: 'Async functions can only be declared at the top level or inside a block.',
  1077. BadImportCallArity: 'Unexpected token',
  1078. BadGetterArity: 'Getter must not have any formal parameters',
  1079. BadSetterArity: 'Setter must have exactly one formal parameter',
  1080. BadSetterRestParameter: 'Setter function argument must not be a rest parameter',
  1081. CannotUseImportMetaOutsideAModule: "Cannot use 'import.meta' outside a module",
  1082. ConstructorIsAsync: 'Class constructor may not be an async method',
  1083. ConstructorIsPrivate: 'Class constructor may not be a private method',
  1084. ConstructorSpecialMethod: 'Class constructor may not be an accessor',
  1085. DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
  1086. DefaultRestParameter: 'Unexpected token =',
  1087. DefaultRestProperty: 'Unexpected token =',
  1088. DuplicateBinding: 'Duplicate binding %0',
  1089. DuplicateConstructor: 'A class may only have one constructor',
  1090. DuplicateParameter: 'Duplicate parameter name not allowed in this context',
  1091. DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
  1092. ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer',
  1093. GeneratorInLegacyContext: 'Generator declarations are not allowed in legacy contexts',
  1094. IllegalBreak: 'Illegal break statement',
  1095. IllegalContinue: 'Illegal continue statement',
  1096. IllegalExportDeclaration: 'Unexpected token',
  1097. IllegalImportDeclaration: 'Unexpected token',
  1098. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list",
  1099. IllegalReturn: 'Illegal return statement',
  1100. InvalidEscapedReservedWord: 'Keyword must not contain escaped characters',
  1101. InvalidHexEscapeSequence: 'Invalid hexadecimal escape sequence',
  1102. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  1103. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  1104. InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
  1105. InvalidModuleSpecifier: 'Unexpected token',
  1106. InvalidRegExp: 'Invalid regular expression',
  1107. InvalidTaggedTemplateOnOptionalChain: 'Invalid tagged template on optional chain',
  1108. InvalidUnicodeEscapeSequence: 'Invalid Unicode escape sequence',
  1109. LetInLexicalBinding: 'let is disallowed as a lexically bound name',
  1110. MissingFromClause: 'Unexpected token',
  1111. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  1112. NewlineAfterThrow: 'Illegal newline after throw',
  1113. NoAsAfterImportNamespace: 'Unexpected token',
  1114. NoAsAndFromEscapeSequences: 'The `as` and `from` contextual keywords must not contain Unicode escape sequences.',
  1115. NoCatchOrFinally: 'Missing catch or finally after try',
  1116. NoSemicolonAfterDecorator: 'Decorators must not be followed by a semicolon.',
  1117. NumericSeperatorOneUnderscore: 'Numeric separator must be exactly one underscore',
  1118. NumericSeperatorNotAllowedHere: 'Numeric separator is not allowed here',
  1119. ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
  1120. PropertyAfterRestProperty: 'Unexpected token',
  1121. Redeclaration: "%0 '%1' has already been declared",
  1122. StaticPrototype: 'Classes may not have static property named prototype',
  1123. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  1124. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  1125. StrictFunction: 'In strict mode code, functions can only be declared at top level or inside a block',
  1126. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  1127. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  1128. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  1129. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  1130. StrictModeWith: 'Strict mode code may not include a with statement',
  1131. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  1132. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  1133. StrictReservedWord: 'Use of future reserved word in strict mode',
  1134. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  1135. TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
  1136. TemplateEscape89: '\\8 and \\9 are not allowed in template strings.',
  1137. UnexpectedEOS: 'Unexpected end of input',
  1138. UnexpectedIdentifier: 'Unexpected identifier',
  1139. UnexpectedNumber: 'Unexpected number',
  1140. UnexpectedReserved: 'Unexpected reserved word',
  1141. UnexpectedString: 'Unexpected string',
  1142. UnexpectedSuper: "'super' keyword unexpected here",
  1143. UnexpectedTemplate: 'Unexpected quasi %0',
  1144. UnexpectedToken: 'Unexpected token %0',
  1145. UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
  1146. UnknownLabel: "Undefined label '%0'",
  1147. UnterminatedRegExp: 'Invalid regular expression: missing /'
  1148. };
  1149. const TokenName = {};
  1150.  
  1151. function hexValue(e) {
  1152. return '0123456789abcdef'.indexOf(e.toLowerCase());
  1153. }
  1154.  
  1155. function octalValue(e) {
  1156. return '01234567'.indexOf(e);
  1157. }
  1158. 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';
  1159. const Scanner = class {
  1160. source;
  1161. errorHandler;
  1162. trackComment;
  1163. isModule;
  1164. index;
  1165. lineNumber;
  1166. lineStart;
  1167. curlyStack;
  1168. length;
  1169. constructor(e, t) {
  1170. 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 = [];
  1171. }
  1172.  
  1173. saveState() {
  1174. return {
  1175. index: this.index,
  1176. lineNumber: this.lineNumber,
  1177. lineStart: this.lineStart,
  1178. curlyStack: this.curlyStack.slice()
  1179. };
  1180. }
  1181.  
  1182. restoreState(e) {
  1183. this.index = e.index, this.lineNumber = e.lineNumber, this.lineStart = e.lineStart, this.curlyStack = e.curlyStack;
  1184. }
  1185.  
  1186. eof() {
  1187. return this.index >= this.length;
  1188. }
  1189.  
  1190. throwUnexpectedToken(e = Messages.UnexpectedTokenIllegal) {
  1191. return this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, e);
  1192. }
  1193.  
  1194. tolerateUnexpectedToken(e = Messages.UnexpectedTokenIllegal) {
  1195. this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, e);
  1196. }
  1197.  
  1198. skipSingleLineComment(e) {
  1199. let t; let s; let
  1200. i = [];
  1201. for (this.trackComment && (i = [], t = this.index - e, s = {
  1202. start: {
  1203. line: this.lineNumber,
  1204. column: this.index - this.lineStart - e
  1205. },
  1206. end: {}
  1207. }); !this.eof();) {
  1208. const r = this.source.charCodeAt(this.index);
  1209. if (++this.index, Character.isLineTerminator(r)) {
  1210. if (this.trackComment) {
  1211. s.end = {
  1212. line: this.lineNumber,
  1213. column: this.index - this.lineStart - 1
  1214. };
  1215. const r = {
  1216. multiLine: !1,
  1217. slice: [t + e, this.index - 1],
  1218. range: [t, this.index - 1],
  1219. loc: s
  1220. };
  1221. i.push(r);
  1222. }
  1223. return r === 13 && this.source.charCodeAt(this.index) === 10 && ++this.index, ++this.lineNumber, this.lineStart = this.index, i;
  1224. }
  1225. }
  1226. if (this.trackComment) {
  1227. s.end = {
  1228. line: this.lineNumber,
  1229. column: this.index - this.lineStart
  1230. };
  1231. const r = {
  1232. multiLine: !1,
  1233. slice: [t + e, this.index],
  1234. range: [t, this.index],
  1235. loc: s
  1236. };
  1237. i.push(r);
  1238. }
  1239. return i;
  1240. }
  1241.  
  1242. skipMultiLineComment() {
  1243. let e; let t; let
  1244. s = [];
  1245. for (this.trackComment && (s = [], e = this.index - 2, t = {
  1246. start: {
  1247. line: this.lineNumber,
  1248. column: this.index - this.lineStart - 2
  1249. },
  1250. end: {}
  1251. }); !this.eof();) {
  1252. const i = this.source.charCodeAt(this.index);
  1253. if (Character.isLineTerminator(i)) i === 13 && this.source.charCodeAt(this.index + 1) === 10 && ++this.index, ++this.lineNumber, ++this.index, this.lineStart = this.index;
  1254. else if (i === 42) {
  1255. if (this.source.charCodeAt(this.index + 1) === 47) {
  1256. if (this.index += 2, this.trackComment) {
  1257. t.end = {
  1258. line: this.lineNumber,
  1259. column: this.index - this.lineStart
  1260. };
  1261. const i = {
  1262. multiLine: !0,
  1263. slice: [e + 2, this.index - 2],
  1264. range: [e, this.index],
  1265. loc: t
  1266. };
  1267. s.push(i);
  1268. }
  1269. return s;
  1270. }++this.index;
  1271. } else ++this.index;
  1272. }
  1273. if (this.trackComment) {
  1274. t.end = {
  1275. line: this.lineNumber,
  1276. column: this.index - this.lineStart
  1277. };
  1278. const i = {
  1279. multiLine: !0,
  1280. slice: [e + 2, this.index],
  1281. range: [e, this.index],
  1282. loc: t
  1283. };
  1284. s.push(i);
  1285. }
  1286. return this.tolerateUnexpectedToken(), s;
  1287. }
  1288.  
  1289. scanComments() {
  1290. let e;
  1291. this.trackComment && (e = []);
  1292. let t = this.index === 0;
  1293. for (; !this.eof();) {
  1294. let s = this.source.charCodeAt(this.index);
  1295. if (Character.isWhiteSpace(s)) ++this.index;
  1296. 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;
  1297. else if (s === 47) {
  1298. if (s = this.source.charCodeAt(this.index + 1), s === 47) {
  1299. this.index += 2;
  1300. const s = this.skipSingleLineComment(2);
  1301. this.trackComment && (e = e.concat(s)), t = !0;
  1302. } else {
  1303. if (s !== 42) break;
  1304. {
  1305. this.index += 2;
  1306. const t = this.skipMultiLineComment();
  1307. this.trackComment && (e = e.concat(t));
  1308. }
  1309. }
  1310. } else if (t && s === 45) {
  1311. if (this.source.charCodeAt(this.index + 1) !== 45 || this.source.charCodeAt(this.index + 2) !== 62) break;
  1312. {
  1313. this.index += 3;
  1314. const t = this.skipSingleLineComment(3);
  1315. this.trackComment && (e = e.concat(t));
  1316. }
  1317. } else {
  1318. if (s !== 60 || this.isModule) break;
  1319. if (this.source.slice(this.index + 1, this.index + 4) !== '!--') break;
  1320. {
  1321. this.index += 4;
  1322. const t = this.skipSingleLineComment(4);
  1323. this.trackComment && (e = e.concat(t));
  1324. }
  1325. }
  1326. }
  1327. return e;
  1328. }
  1329.  
  1330. isFutureReservedWord(e) {
  1331. switch (e) {
  1332. case 'enum':
  1333. case 'export':
  1334. case 'import':
  1335. case 'super':
  1336. return !0;
  1337. default:
  1338. return !1;
  1339. }
  1340. }
  1341.  
  1342. isStrictModeReservedWord(e) {
  1343. switch (e) {
  1344. case 'implements':
  1345. case 'interface':
  1346. case 'package':
  1347. case 'private':
  1348. case 'protected':
  1349. case 'public':
  1350. case 'static':
  1351. case 'yield':
  1352. case 'let':
  1353. return !0;
  1354. default:
  1355. return !1;
  1356. }
  1357. }
  1358.  
  1359. isRestrictedWord(e) {
  1360. return e === 'eval' || e === 'arguments';
  1361. }
  1362.  
  1363. isKeyword(e) {
  1364. switch (e.length) {
  1365. case 2:
  1366. return e === 'if' || e === 'in' || e === 'do';
  1367. case 3:
  1368. return e === 'var' || e === 'for' || e === 'new' || e === 'try' || e === 'let';
  1369. case 4:
  1370. return e === 'this' || e === 'else' || e === 'case' || e === 'void' || e === 'with' || e === 'enum';
  1371. case 5:
  1372. return e === 'while' || e === 'break' || e === 'catch' || e === 'throw' || e === 'const' || e === 'yield' || e === 'class' || e === 'super';
  1373. case 6:
  1374. return e === 'return' || e === 'typeof' || e === 'delete' || e === 'switch' || e === 'export' || e === 'import';
  1375. case 7:
  1376. return e === 'default' || e === 'finally' || e === 'extends';
  1377. case 8:
  1378. return e === 'function' || e === 'continue' || e === 'debugger';
  1379. case 10:
  1380. return e === 'instanceof';
  1381. default:
  1382. return !1;
  1383. }
  1384. }
  1385.  
  1386. codePointAt(e) {
  1387. let t = this.source.charCodeAt(e);
  1388. if (t >= 55296 && t <= 56319) {
  1389. const s = this.source.charCodeAt(e + 1);
  1390. if (s >= 56320 && s <= 57343) {
  1391. t = 1024 * (t - 55296) + s - 56320 + 65536;
  1392. }
  1393. }
  1394. return t;
  1395. }
  1396.  
  1397. scanHexEscape(e) {
  1398. const t = e === 'u' ? 4 : 2;
  1399. let s = 0;
  1400. for (let e = 0; e < t; ++e) {
  1401. if (this.eof() || !Character.isHexDigit(this.source.charCodeAt(this.index))) return null;
  1402. s = 16 * s + hexValue(this.source[this.index++]);
  1403. }
  1404. return String.fromCharCode(s);
  1405. }
  1406.  
  1407. tryToScanUnicodeCodePointEscape() {
  1408. let e = this.source[this.index];
  1409. let t = 0;
  1410. if (e === '}') return null;
  1411. for (; !this.eof() && (e = this.source[this.index++], Character.isHexDigit(e.charCodeAt(0)));) t = 16 * t + hexValue(e);
  1412. return t > 1114111 || e !== '}' ? null : Character.fromCodePoint(t);
  1413. }
  1414.  
  1415. scanUnicodeCodePointEscape() {
  1416. const e = this.tryToScanUnicodeCodePointEscape();
  1417. return e === null ? this.throwUnexpectedToken() : e;
  1418. }
  1419.  
  1420. getIdentifier() {
  1421. const e = this.index++;
  1422. for (; !this.eof();) {
  1423. const t = this.source.charCodeAt(this.index);
  1424. if (t === 92) return this.index = e, this.getComplexIdentifier();
  1425. if (t >= 55296 && t < 57343) return this.index = e, this.getComplexIdentifier();
  1426. if (!Character.isIdentifierPart(t)) break;
  1427. ++this.index;
  1428. }
  1429. return this.source.slice(e, this.index);
  1430. }
  1431.  
  1432. getComplexIdentifier() {
  1433. let e; let t = this.codePointAt(this.index);
  1434. let s = Character.fromCodePoint(t);
  1435. 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);
  1436. return s;
  1437. }
  1438.  
  1439. octalToDecimal(e) {
  1440. let t = e !== '0';
  1441. let s = octalValue(e);
  1442. 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++]))), {
  1443. code: s,
  1444. octal: t
  1445. };
  1446. }
  1447.  
  1448. scanIdentifier() {
  1449. let e;
  1450. const t = this.index;
  1451. const s = this.source.charCodeAt(t) === 92;
  1452. const i = s ? this.getComplexIdentifier() : this.getIdentifier();
  1453. 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) {
  1454. const e = this.index;
  1455. this.index = t, this.tolerateUnexpectedToken(Messages.InvalidEscapedReservedWord), this.index = e;
  1456. }
  1457. return {
  1458. type: e,
  1459. value: i,
  1460. lineNumber: this.lineNumber,
  1461. lineStart: this.lineStart,
  1462. start: t,
  1463. end: this.index,
  1464. escaped: s
  1465. };
  1466. }
  1467.  
  1468. scanPunctuator() {
  1469. const e = this.index;
  1470. let t = this.source[this.index];
  1471. switch (t) {
  1472. case '(':
  1473. case '{':
  1474. t === '{' && this.curlyStack.push('{'), ++this.index;
  1475. break;
  1476. case '.':
  1477. ++this.index, this.source[this.index] === '.' && this.source[this.index + 1] === '.' && (this.index += 2, t = '...');
  1478. break;
  1479. case '}':
  1480. ++this.index, this.curlyStack.pop();
  1481. break;
  1482. case '?':
  1483. ++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 = '?.');
  1484. break;
  1485. case '#':
  1486. case ')':
  1487. case ';':
  1488. case ',':
  1489. case '[':
  1490. case ']':
  1491. case ':':
  1492. case '~':
  1493. case '@':
  1494. ++this.index;
  1495. break;
  1496. default:
  1497. 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)));
  1498. }
  1499. return this.index === e && this.throwUnexpectedToken(), {
  1500. type: 7,
  1501. value: t,
  1502. lineNumber: this.lineNumber,
  1503. lineStart: this.lineStart,
  1504. start: e,
  1505. end: this.index
  1506. };
  1507. }
  1508.  
  1509. scanHexLiteral(e) {
  1510. const t = this.scanLiteralPart(Character.isHexDigitChar);
  1511. return t.length === 0 && this.throwUnexpectedToken(), this.source[this.index] === 'n' ? (this.index++, {
  1512. type: 6,
  1513. value: BigInt(`0x${t}`),
  1514. lineNumber: this.lineNumber,
  1515. lineStart: this.lineStart,
  1516. start: e,
  1517. end: this.index
  1518. }) : (Character.isIdentifierStart(this.source.charCodeAt(this.index)) && this.throwUnexpectedToken(), {
  1519. type: 6,
  1520. value: parseInt(`0x${t}`, 16),
  1521. lineNumber: this.lineNumber,
  1522. lineStart: this.lineStart,
  1523. start: e,
  1524. end: this.index
  1525. });
  1526. }
  1527.  
  1528. scanBinaryLiteral(e) {
  1529. let t; const
  1530. s = this.scanLiteralPart((e => e === '0' || e === '1'));
  1531. return s.length === 0 && this.throwUnexpectedToken(), this.source[this.index] === 'n' ? (this.index++, {
  1532. type: 6,
  1533. value: BigInt(`0b${s}`),
  1534. lineNumber: this.lineNumber,
  1535. lineStart: this.lineStart,
  1536. start: e,
  1537. end: this.index
  1538. }) : (this.eof() || (t = this.source.charCodeAt(this.index), (Character.isIdentifierStart(t) || Character.isDecimalDigit(t)) && this.throwUnexpectedToken()), {
  1539. type: 6,
  1540. value: parseInt(s, 2),
  1541. lineNumber: this.lineNumber,
  1542. lineStart: this.lineStart,
  1543. start: e,
  1544. end: this.index
  1545. });
  1546. }
  1547.  
  1548. scanOctalLiteral(e, t) {
  1549. let s = '';
  1550. let i = !1;
  1551. 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++, {
  1552. type: 6,
  1553. value: BigInt(`0o${s}`),
  1554. lineNumber: this.lineNumber,
  1555. lineStart: this.lineStart,
  1556. start: t,
  1557. end: this.index
  1558. }) : ((Character.isIdentifierStart(this.source.charCodeAt(this.index)) || Character.isDecimalDigit(this.source.charCodeAt(this.index))) && this.throwUnexpectedToken(), {
  1559. type: 6,
  1560. value: parseInt(s, 8),
  1561. octal: i,
  1562. lineNumber: this.lineNumber,
  1563. lineStart: this.lineStart,
  1564. start: t,
  1565. end: this.index
  1566. });
  1567. }
  1568.  
  1569. isImplicitOctalLiteral() {
  1570. for (let e = this.index + 1; e < this.length; ++e) {
  1571. const t = this.source[e];
  1572. if (t === '8' || t === '9' || t === 'n') return !1;
  1573. if (!Character.isOctalDigit(t.charCodeAt(0))) return !0;
  1574. }
  1575. return !0;
  1576. }
  1577.  
  1578. scanLiteralPart(e) {
  1579. let t = '';
  1580. 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);
  1581. return this.source[this.index - 1] === '_' && this.throwUnexpectedToken(Messages.NumericSeperatorNotAllowedHere), t;
  1582. }
  1583.  
  1584. scanNumericLiteral() {
  1585. const e = this.index;
  1586. let t = this.source[e];
  1587. assert(Character.isDecimalDigit(t.charCodeAt(0)) || t === '.', 'Numeric literal must start with a decimal digit or a decimal point');
  1588. let s = '';
  1589. if (t !== '.') {
  1590. if (s = this.source[this.index++], t = this.source[this.index], s === '0') {
  1591. if (t === 'x' || t === 'X') return ++this.index, this.scanHexLiteral(e);
  1592. if (t === 'b' || t === 'B') return ++this.index, this.scanBinaryLiteral(e);
  1593. if (t === 'o' || t === 'O') return this.scanOctalLiteral(t, e);
  1594. if (t && Character.isOctalDigit(t.charCodeAt(0)) && this.isImplicitOctalLiteral()) return this.scanOctalLiteral(t, e);
  1595. }
  1596. this.index--, s = this.scanLiteralPart(Character.isDecimalDigitChar), t = this.source[this.index];
  1597. }
  1598. 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();
  1599. else if (t === 'n') {
  1600. return s.length > 1 && s[0] === '0' && this.throwUnexpectedToken(), this.index++, {
  1601. type: 6,
  1602. value: BigInt(s),
  1603. lineNumber: this.lineNumber,
  1604. lineStart: this.lineStart,
  1605. start: e,
  1606. end: this.index
  1607. };
  1608. }
  1609. return Character.isIdentifierStart(this.source.charCodeAt(this.index)) && this.throwUnexpectedToken(), {
  1610. type: 6,
  1611. value: parseFloat(s),
  1612. lineNumber: this.lineNumber,
  1613. lineStart: this.lineStart,
  1614. start: e,
  1615. end: this.index
  1616. };
  1617. }
  1618.  
  1619. scanStringLiteral() {
  1620. const e = this.index;
  1621. let t = this.source[e];
  1622. assert(t === "'" || t === '"', 'String literal must starts with a quote'), ++this.index;
  1623. let s = !1;
  1624. let i = '';
  1625. for (; !this.eof();) {
  1626. let e = this.source[this.index++];
  1627. if (e === t) {
  1628. t = '';
  1629. break;
  1630. }
  1631. if (e === '\\') {
  1632. 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;
  1633. else {
  1634. switch (e) {
  1635. case 'u':
  1636. if (this.source[this.index] === '{') ++this.index, i += this.scanUnicodeCodePointEscape();
  1637. else {
  1638. const t = this.scanHexEscape(e);
  1639. t === null && this.throwUnexpectedToken(), i += t;
  1640. }
  1641. break;
  1642. case 'x':
  1643. const t = this.scanHexEscape(e);
  1644. t === null && this.throwUnexpectedToken(Messages.InvalidHexEscapeSequence), i += t;
  1645. break;
  1646. case 'n':
  1647. i += '\n';
  1648. break;
  1649. case 'r':
  1650. i += '\r';
  1651. break;
  1652. case 't':
  1653. i += '\t';
  1654. break;
  1655. case 'b':
  1656. i += '\b';
  1657. break;
  1658. case 'f':
  1659. i += '\f';
  1660. break;
  1661. case 'v':
  1662. i += '\v';
  1663. break;
  1664. case '8':
  1665. case '9':
  1666. i += e, this.tolerateUnexpectedToken();
  1667. break;
  1668. default:
  1669. if (e && Character.isOctalDigit(e.charCodeAt(0))) {
  1670. const t = this.octalToDecimal(e);
  1671. s = t.octal || s, i += String.fromCharCode(t.code);
  1672. } else i += e;
  1673. }
  1674. }
  1675. } else {
  1676. if (Character.isLineTerminator(e.charCodeAt(0))) break;
  1677. i += e;
  1678. }
  1679. }
  1680. return t !== '' && (this.index = e, this.throwUnexpectedToken()), {
  1681. type: 8,
  1682. value: i,
  1683. octal: s,
  1684. lineNumber: this.lineNumber,
  1685. lineStart: this.lineStart,
  1686. start: e,
  1687. end: this.index
  1688. };
  1689. }
  1690.  
  1691. scanTemplate() {
  1692. let e = '';
  1693. let t = !1;
  1694. const s = this.index;
  1695. const i = this.source[s] === '`';
  1696. let r = !1;
  1697. let n = null;
  1698. let a = 2;
  1699. for (++this.index; !this.eof();) {
  1700. let s = this.source[this.index++];
  1701. if (s === '`') {
  1702. a = 1, r = !0, t = !0;
  1703. break;
  1704. }
  1705. if (s === '$') {
  1706. if (this.source[this.index] === '{') {
  1707. this.curlyStack.push('${'), ++this.index, t = !0;
  1708. break;
  1709. }
  1710. e += s;
  1711. } else {
  1712. if (n !== null) continue;
  1713. if (s === '\\') {
  1714. 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;
  1715. else {
  1716. switch (s) {
  1717. case 'n':
  1718. e += '\n';
  1719. break;
  1720. case 'r':
  1721. e += '\r';
  1722. break;
  1723. case 't':
  1724. e += '\t';
  1725. break;
  1726. case 'u':
  1727. if (this.source[this.index] === '{') {
  1728. ++this.index;
  1729. const t = this.tryToScanUnicodeCodePointEscape();
  1730. t === null ? n = 'u' : e += t;
  1731. } else {
  1732. const t = this.scanHexEscape(s);
  1733. t === null ? n = 'u' : e += t;
  1734. }
  1735. break;
  1736. case 'x':
  1737. const t = this.scanHexEscape(s);
  1738. t === null ? n = 'x' : e += t;
  1739. break;
  1740. case 'b':
  1741. e += '\b';
  1742. break;
  1743. case 'f':
  1744. e += '\f';
  1745. break;
  1746. case 'v':
  1747. e += '\v';
  1748. break;
  1749. default:
  1750. s === '0' ? Character.isDecimalDigit(this.source.charCodeAt(this.index)) ? n = '0' : e += '\0' : Character.isDecimalDigitChar(s) ? n = s : e += s;
  1751. }
  1752. }
  1753. } 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;
  1754. }
  1755. }
  1756. return t || this.throwUnexpectedToken(), i || this.curlyStack.pop(), {
  1757. type: 10,
  1758. value: this.source.slice(s + 1, this.index - a),
  1759. cooked: n === null ? e : null,
  1760. head: i,
  1761. tail: r,
  1762. notEscapeSequenceHead: n,
  1763. lineNumber: this.lineNumber,
  1764. lineStart: this.lineStart,
  1765. start: s,
  1766. end: this.index
  1767. };
  1768. }
  1769.  
  1770. testRegExp(e, t) {
  1771. let s = e;
  1772. t.indexOf('u') >= 0 && (s = s.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, ((e, t, s) => {
  1773. const i = parseInt(t || s, 16);
  1774. return i > 1114111 && this.throwUnexpectedToken(Messages.InvalidRegExp), i <= 65535 ? String.fromCharCode(i) : '￿';
  1775. })).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, '￿'));
  1776. try {
  1777. RegExp(s);
  1778. } catch (e) {
  1779. this.throwUnexpectedToken(Messages.InvalidRegExp);
  1780. }
  1781. try {
  1782. return new RegExp(e, t);
  1783. } catch (e) {
  1784. return null;
  1785. }
  1786. }
  1787.  
  1788. scanRegExpBody() {
  1789. let e = this.source[this.index];
  1790. assert(e === '/', 'Regular expression literal must start with a slash');
  1791. let t = this.source[this.index++];
  1792. let s = !1;
  1793. let i = !1;
  1794. for (; !this.eof();) {
  1795. 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;
  1796. else if (Character.isLineTerminator(e.charCodeAt(0))) this.throwUnexpectedToken(Messages.UnterminatedRegExp);
  1797. else if (s) e === ']' && (s = !1);
  1798. else {
  1799. if (e === '/') {
  1800. i = !0;
  1801. break;
  1802. }
  1803. e === '[' && (s = !0);
  1804. }
  1805. }
  1806. return i || this.throwUnexpectedToken(Messages.UnterminatedRegExp), t.substr(1, t.length - 2);
  1807. }
  1808.  
  1809. scanRegExpFlags() {
  1810. let e = '';
  1811. let t = '';
  1812. for (; !this.eof();) {
  1813. let s = this.source[this.index];
  1814. if (!Character.isIdentifierPart(s.charCodeAt(0))) break;
  1815. if (++this.index, s !== '\\' || this.eof()) t += s, e += s;
  1816. else if (s = this.source[this.index], s === 'u') {
  1817. ++this.index;
  1818. let s = this.index;
  1819. const i = this.scanHexEscape('u');
  1820. if (i !== null) for (t += i, e += '\\u'; s < this.index; ++s) e += this.source[s];
  1821. else this.index = s, t += 'u', e += '\\u';
  1822. this.tolerateUnexpectedToken();
  1823. } else e += '\\', this.tolerateUnexpectedToken();
  1824. }
  1825. return t;
  1826. }
  1827.  
  1828. scanRegExp() {
  1829. const e = this.index;
  1830. const t = this.scanRegExpBody();
  1831. const s = this.scanRegExpFlags();
  1832. return {
  1833. type: 9,
  1834. value: '',
  1835. pattern: t,
  1836. flags: s,
  1837. regex: this.testRegExp(t, s),
  1838. lineNumber: this.lineNumber,
  1839. lineStart: this.lineStart,
  1840. start: e,
  1841. end: this.index
  1842. };
  1843. }
  1844.  
  1845. lex() {
  1846. if (this.eof()) {
  1847. return {
  1848. type: 2,
  1849. value: '',
  1850. lineNumber: this.lineNumber,
  1851. lineStart: this.lineStart,
  1852. start: this.index,
  1853. end: this.index
  1854. };
  1855. }
  1856. const e = this.source.charCodeAt(this.index);
  1857. 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();
  1858. }
  1859. };
  1860. const ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
  1861. const Parser = class {
  1862. config;
  1863. delegate;
  1864. errorHandler;
  1865. scanner;
  1866. operatorPrecedence;
  1867. lookahead;
  1868. hasLineTerminator;
  1869. context;
  1870. tokens;
  1871. startMarker;
  1872. lastMarker;
  1873. constructor(e, t = {}, s) {
  1874. this.config = {
  1875. range: typeof t.range === 'boolean' && t.range,
  1876. loc: typeof t.loc === 'boolean' && t.loc,
  1877. source: null,
  1878. tokens: typeof t.tokens === 'boolean' && t.tokens,
  1879. comment: typeof t.comment === 'boolean' && t.comment,
  1880. tolerant: typeof t.tolerant === 'boolean' && t.tolerant
  1881. }, 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 = {
  1882. ')': 0,
  1883. ';': 0,
  1884. ',': 0,
  1885. '=': 0,
  1886. ']': 0,
  1887. '??': 5,
  1888. '||': 6,
  1889. '&&': 7,
  1890. '|': 8,
  1891. '^': 9,
  1892. '&': 10,
  1893. '==': 11,
  1894. '!=': 11,
  1895. '===': 11,
  1896. '!==': 11,
  1897. '<': 12,
  1898. '>': 12,
  1899. '<=': 12,
  1900. '>=': 12,
  1901. '<<': 13,
  1902. '>>': 13,
  1903. '>>>': 13,
  1904. '+': 14,
  1905. '-': 14,
  1906. '*': 15,
  1907. '/': 15,
  1908. '%': 15
  1909. }, this.lookahead = {
  1910. type: 2,
  1911. value: '',
  1912. lineNumber: this.scanner.lineNumber,
  1913. lineStart: 0,
  1914. start: 0,
  1915. end: 0
  1916. }, this.hasLineTerminator = !1, this.context = {
  1917. isModule: !1,
  1918. isAsync: !1,
  1919. allowIn: !0,
  1920. allowStrictDirective: !0,
  1921. allowSuper: !1,
  1922. allowYield: !0,
  1923. firstCoverInitializedNameError: null,
  1924. isAssignmentTarget: !1,
  1925. isBindingElement: !1,
  1926. inConstructor: !1,
  1927. inFunctionBody: !1,
  1928. inIteration: !1,
  1929. inSwitch: !1,
  1930. inClassConstructor: !1,
  1931. labelSet: {},
  1932. strict: !1,
  1933. decorators: null
  1934. }, this.tokens = [], this.startMarker = {
  1935. index: 0,
  1936. line: this.scanner.lineNumber,
  1937. column: 0
  1938. }, this.lastMarker = {
  1939. index: 0,
  1940. line: this.scanner.lineNumber,
  1941. column: 0
  1942. }, this.nextToken(), this.lastMarker = {
  1943. index: this.scanner.index,
  1944. line: this.scanner.lineNumber,
  1945. column: this.scanner.index - this.scanner.lineStart
  1946. };
  1947. }
  1948.  
  1949. throwError(e, ...t) {
  1950. const s = t.slice();
  1951. const i = e.replace(/%(\d)/g, ((e, t) => (assert(t < s.length, 'Message reference must be in range'), s[t])));
  1952. const r = this.lastMarker.index;
  1953. const n = this.lastMarker.line;
  1954. const a = this.lastMarker.column + 1;
  1955. throw this.errorHandler.createError(r, n, a, i);
  1956. }
  1957.  
  1958. tolerateError(e, ...t) {
  1959. const s = t.slice();
  1960. const i = e.replace(/%(\d)/g, ((e, t) => (assert(t < s.length, 'Message reference must be in range'), s[t])));
  1961. const r = this.lastMarker.index;
  1962. const n = this.scanner.lineNumber;
  1963. const a = this.lastMarker.column + 1;
  1964. this.errorHandler.tolerateError(r, n, a, i);
  1965. }
  1966.  
  1967. unexpectedTokenError(e, t) {
  1968. let s; let
  1969. i = t || Messages.UnexpectedToken;
  1970. 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') {
  1971. const t = e.start;
  1972. const s = e.lineNumber;
  1973. const r = this.lastMarker.index - this.lastMarker.column;
  1974. const n = e.start - r + 1;
  1975. return this.errorHandler.createError(t, s, n, i);
  1976. } {
  1977. const e = this.lastMarker.index;
  1978. const t = this.lastMarker.line;
  1979. const s = this.lastMarker.column + 1;
  1980. return this.errorHandler.createError(e, t, s, i);
  1981. }
  1982. }
  1983.  
  1984. throwUnexpectedToken(e, t) {
  1985. throw this.unexpectedTokenError(e, t);
  1986. }
  1987.  
  1988. tolerateUnexpectedToken(e, t) {
  1989. this.errorHandler.tolerate(this.unexpectedTokenError(e, t));
  1990. }
  1991.  
  1992. tolerateInvalidLoopStatement() {
  1993. (this.matchKeyword('class') || this.matchKeyword('function')) && this.tolerateError(Messages.UnexpectedToken, this.lookahead);
  1994. }
  1995.  
  1996. collectComments() {
  1997. if (this.config.comment) {
  1998. const e = this.scanner.scanComments();
  1999. if (e.length > 0 && this.delegate) {
  2000. for (let t = 0; t < e.length; ++t) {
  2001. const s = e[t];
  2002. const i = {
  2003. type: s.multiLine ? 'BlockComment' : 'LineComment',
  2004. value: this.scanner.source.slice(s.slice[0], s.slice[1])
  2005. };
  2006. this.config.range && (i.range = s.range), this.config.loc && (i.loc = s.loc);
  2007. const r = {
  2008. start: {
  2009. line: s.loc.start.line,
  2010. column: s.loc.start.column,
  2011. offset: s.range[0]
  2012. },
  2013. end: {
  2014. line: s.loc.end.line,
  2015. column: s.loc.end.column,
  2016. offset: s.range[1]
  2017. }
  2018. };
  2019. this.delegate(i, r);
  2020. }
  2021. }
  2022. } else this.scanner.scanComments();
  2023. }
  2024.  
  2025. getTokenRaw(e) {
  2026. return this.scanner.source.slice(e.start, e.end);
  2027. }
  2028.  
  2029. convertToken(e) {
  2030. const t = {
  2031. type: TokenName[e.type],
  2032. value: this.getTokenRaw(e)
  2033. };
  2034. if (this.config.range && (t.range = [e.start, e.end]), this.config.loc && (t.loc = {
  2035. start: {
  2036. line: this.startMarker.line,
  2037. column: this.startMarker.column
  2038. },
  2039. end: {
  2040. line: this.scanner.lineNumber,
  2041. column: this.scanner.index - this.scanner.lineStart
  2042. }
  2043. }), e.type === 9) {
  2044. const s = e.pattern;
  2045. const i = e.flags;
  2046. t.regex = {
  2047. pattern: s,
  2048. flags: i
  2049. };
  2050. }
  2051. return t;
  2052. }
  2053.  
  2054. nextToken() {
  2055. const e = this.lookahead;
  2056. 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);
  2057. const t = this.scanner.lex();
  2058. 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;
  2059. }
  2060.  
  2061. nextRegexToken() {
  2062. this.collectComments();
  2063. const e = this.scanner.scanRegExp();
  2064. return this.config.tokens && (this.tokens.pop(), this.tokens.push(this.convertToken(e))), this.lookahead = e, this.nextToken(), e;
  2065. }
  2066.  
  2067. createNode() {
  2068. return {
  2069. index: this.startMarker.index,
  2070. line: this.startMarker.line,
  2071. column: this.startMarker.column
  2072. };
  2073. }
  2074.  
  2075. startNode(e, t = 0) {
  2076. let s = e.start - e.lineStart;
  2077. let i = e.lineNumber;
  2078. return s < 0 && (s += t, i--), {
  2079. index: e.start,
  2080. line: i,
  2081. column: s
  2082. };
  2083. }
  2084.  
  2085. finalize(e, t) {
  2086. if (this.config.range && (t.range = [e.index, this.lastMarker.index]), this.config.loc && (t.loc = {
  2087. start: {
  2088. line: e.line,
  2089. column: e.column
  2090. },
  2091. end: {
  2092. line: this.lastMarker.line,
  2093. column: this.lastMarker.column
  2094. }
  2095. }, this.config.source && (t.loc.source = this.config.source)), this.delegate) {
  2096. const s = {
  2097. start: {
  2098. line: e.line,
  2099. column: e.column,
  2100. offset: e.index
  2101. },
  2102. end: {
  2103. line: this.lastMarker.line,
  2104. column: this.lastMarker.column,
  2105. offset: this.lastMarker.index
  2106. }
  2107. };
  2108. this.delegate(t, s);
  2109. }
  2110. return t;
  2111. }
  2112.  
  2113. expect(e) {
  2114. const t = this.nextToken();
  2115. t.type === 7 && t.value === e || this.throwUnexpectedToken(t);
  2116. }
  2117.  
  2118. expectCommaSeparator() {
  2119. if (this.config.tolerant) {
  2120. const e = this.lookahead;
  2121. e.type === 7 && e.value === ',' ? this.nextToken() : e.type === 7 && e.value === ';' ? (this.nextToken(), this.tolerateUnexpectedToken(e)) : this.tolerateUnexpectedToken(e, Messages.UnexpectedToken);
  2122. } else this.expect(',');
  2123. }
  2124.  
  2125. expectKeyword(e) {
  2126. const t = this.nextToken();
  2127. t.type === 4 && t.value === e || this.throwUnexpectedToken(t);
  2128. }
  2129.  
  2130. match(e) {
  2131. return this.lookahead.type === 7 && this.lookahead.value === e;
  2132. }
  2133.  
  2134. matchKeyword(e) {
  2135. return this.lookahead.type === 4 && this.lookahead.value === e;
  2136. }
  2137.  
  2138. matchContextualKeyword(e) {
  2139. return this.lookahead.type === 3 && this.lookahead.value === e;
  2140. }
  2141.  
  2142. matchAssign() {
  2143. if (this.lookahead.type !== 7) return !1;
  2144. const e = this.lookahead.value;
  2145. return e === '=' || e === '*=' || e === '**=' || e === '/=' || e === '%=' || e === '+=' || e === '-=' || e === '<<=' || e === '>>=' || e === '>>>=' || e === '&=' || e === '^=' || e === '|=' || e === '&&=' || e === '||=' || e === '??=';
  2146. }
  2147.  
  2148. isolateCoverGrammar(e) {
  2149. const t = this.context.isBindingElement;
  2150. const s = this.context.isAssignmentTarget;
  2151. const i = this.context.firstCoverInitializedNameError;
  2152. this.context.isBindingElement = !0, this.context.isAssignmentTarget = !0, this.context.firstCoverInitializedNameError = null;
  2153. const r = e.call(this);
  2154. return this.context.firstCoverInitializedNameError !== null && this.throwUnexpectedToken(this.context.firstCoverInitializedNameError), this.context.isBindingElement = t, this.context.isAssignmentTarget = s, this.context.firstCoverInitializedNameError = i, r;
  2155. }
  2156.  
  2157. inheritCoverGrammar(e) {
  2158. const t = this.context.isBindingElement;
  2159. const s = this.context.isAssignmentTarget;
  2160. const i = this.context.firstCoverInitializedNameError;
  2161. this.context.isBindingElement = !0, this.context.isAssignmentTarget = !0, this.context.firstCoverInitializedNameError = null;
  2162. const r = e.call(this);
  2163. return this.context.isBindingElement = this.context.isBindingElement && t, this.context.isAssignmentTarget = this.context.isAssignmentTarget && s, this.context.firstCoverInitializedNameError = i || this.context.firstCoverInitializedNameError, r;
  2164. }
  2165.  
  2166. consumeSemicolon() {
  2167. 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);
  2168. }
  2169.  
  2170. parsePrimaryExpression() {
  2171. const e = this.createNode();
  2172. let t; let s; let
  2173. i;
  2174. switch (this.lookahead.type) {
  2175. case 3:
  2176. (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));
  2177. break;
  2178. case 6:
  2179. case 8:
  2180. 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));
  2181. break;
  2182. case 1:
  2183. 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));
  2184. break;
  2185. case 5:
  2186. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, s = this.nextToken(), i = this.getTokenRaw(s), t = this.finalize(e, new Literal(null, i));
  2187. break;
  2188. case 10:
  2189. t = this.parseTemplateLiteral({
  2190. isTagged: !1
  2191. });
  2192. break;
  2193. case 7:
  2194. switch (this.lookahead.value) {
  2195. case '(':
  2196. this.context.isBindingElement = !1, t = this.inheritCoverGrammar(this.parseGroupExpression);
  2197. break;
  2198. case '[':
  2199. t = this.inheritCoverGrammar(this.parseArrayInitializer);
  2200. break;
  2201. case '{':
  2202. t = this.inheritCoverGrammar(this.parseObjectInitializer);
  2203. break;
  2204. case '/':
  2205. case '/=':
  2206. 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));
  2207. break;
  2208. case '#':
  2209. this.nextToken(), t = this.finalize(e, new PrivateIdentifier(this.nextToken().value));
  2210. break;
  2211. case '@':
  2212. const r = this.parseDecorators();
  2213. this.context.decorators = r;
  2214. this.parsePrimaryExpression();
  2215. this.context.decorators = null, t = this.finalize(e, new PrivateIdentifier(this.nextToken().value));
  2216. break;
  2217. default:
  2218. t = this.throwUnexpectedToken(this.nextToken());
  2219. }
  2220. break;
  2221. case 4:
  2222. !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()));
  2223. break;
  2224. default:
  2225. t = this.throwUnexpectedToken(this.nextToken());
  2226. }
  2227. return t;
  2228. }
  2229.  
  2230. parseSpreadElement() {
  2231. const e = this.createNode();
  2232. this.expect('...');
  2233. const t = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2234. return this.finalize(e, new SpreadElement(t));
  2235. }
  2236.  
  2237. parseArrayInitializer() {
  2238. const e = this.createNode();
  2239. const t = [];
  2240. for (this.expect('['); !this.match(']');) {
  2241. if (this.match(',')) this.nextToken(), t.push(null);
  2242. else if (this.match('...')) {
  2243. const e = this.parseSpreadElement();
  2244. this.match(']') || (this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1, this.expect(',')), t.push(e);
  2245. } else t.push(this.inheritCoverGrammar(this.parseAssignmentExpression)), this.match(']') || this.expect(',');
  2246. }
  2247. return this.expect(']'), this.finalize(e, new ArrayExpression(t));
  2248. }
  2249.  
  2250. parsePropertyMethod(e) {
  2251. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2252. const t = this.context.strict;
  2253. const s = this.context.allowStrictDirective;
  2254. this.context.allowStrictDirective = e.simple;
  2255. const i = this.isolateCoverGrammar(this.parseFunctionSourceElements);
  2256. 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;
  2257. }
  2258.  
  2259. parsePropertyMethodFunction(e) {
  2260. const t = this.createNode();
  2261. const s = this.context.allowYield;
  2262. this.context.allowYield = !0;
  2263. const i = this.parseFormalParameters();
  2264. const r = this.parsePropertyMethod(i);
  2265. return this.context.allowYield = s, this.finalize(t, new FunctionExpression(null, i.params, r, e, !1));
  2266. }
  2267.  
  2268. parsePropertyMethodAsyncFunction(e) {
  2269. const t = this.createNode();
  2270. const s = this.context.allowYield;
  2271. const i = this.context.isAsync;
  2272. this.context.allowYield = !1, this.context.isAsync = !0;
  2273. const r = this.parseFormalParameters();
  2274. const n = this.parsePropertyMethod(r);
  2275. return this.context.allowYield = s, this.context.isAsync = i, this.finalize(t, new FunctionExpression(null, r.params, n, e, !0));
  2276. }
  2277.  
  2278. parseObjectPropertyKey(e = !1) {
  2279. const t = this.createNode();
  2280. const s = this.nextToken();
  2281. let i;
  2282. switch (s.type) {
  2283. case 8:
  2284. case 6:
  2285. this.context.strict && s.octal && this.tolerateUnexpectedToken(s, Messages.StrictOctalLiteral);
  2286. const r = this.getTokenRaw(s);
  2287. i = typeof s.value === 'bigint' ? this.finalize(t, new BigIntLiteral(s.value, r, s.value.toString())) : this.finalize(t, new Literal(s.value, r));
  2288. break;
  2289. case 3:
  2290. case 1:
  2291. case 5:
  2292. case 4:
  2293. i = this.finalize(t, e ? new PrivateIdentifier(s.value) : new Identifier(s.value));
  2294. break;
  2295. case 7:
  2296. s.value === '[' ? (i = this.isolateCoverGrammar(this.parseAssignmentExpression), this.expect(']')) : i = this.throwUnexpectedToken(s);
  2297. break;
  2298. default:
  2299. i = this.throwUnexpectedToken(s);
  2300. }
  2301. return i;
  2302. }
  2303.  
  2304. isPropertyKey(e, t) {
  2305. return e.type === 'Identifier' && e.name === t || e.type === 'Literal' && e.value === t;
  2306. }
  2307.  
  2308. parseObjectProperty(e) {
  2309. const t = this.createNode();
  2310. const s = this.lookahead;
  2311. let i; let r = null;
  2312. let n = null;
  2313. let a = !1;
  2314. let o = !1;
  2315. let u = !1;
  2316. let h = !1;
  2317. let c = !1;
  2318. if (s.type === 3) {
  2319. const e = s.value;
  2320. 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));
  2321. } else this.match('*') ? this.nextToken() : (a = this.match('['), r = this.parseObjectPropertyKey());
  2322. const l = this.qualifiedPropertyName(this.lookahead);
  2323. if (s.type === 3 && !h && s.value === 'get' && l) i = 'get', a = this.match('['), r = this.parseObjectPropertyKey(), this.context.allowYield = !1, n = this.parseGetterMethod();
  2324. else if (s.type === 3 && !h && s.value === 'set' && l) i = 'set', a = this.match('['), r = this.parseObjectPropertyKey(), n = this.parseSetterMethod();
  2325. else if (s.type === 7 && s.value === '*' && l) i = 'init', a = this.match('['), r = this.parseObjectPropertyKey(), n = this.parseGeneratorMethod(!1), o = !0;
  2326. 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);
  2327. else if (this.match('(')) n = h ? this.parsePropertyMethodAsyncFunction(c) : this.parsePropertyMethodFunction(c), o = !0;
  2328. else if (s.type === 3) {
  2329. const e = this.finalize(t, new Identifier(s.value));
  2330. if (this.match('=')) {
  2331. this.context.firstCoverInitializedNameError = this.lookahead, this.nextToken(), u = !0;
  2332. const s = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2333. n = this.finalize(t, new AssignmentPattern(e, s));
  2334. } else u = !0, n = e;
  2335. } else this.throwUnexpectedToken(this.nextToken());
  2336. return this.finalize(t, new Property(i, r, a, n, o, u));
  2337. }
  2338.  
  2339. parseObjectInitializer() {
  2340. const e = this.createNode();
  2341. this.expect('{');
  2342. const t = [];
  2343. const s = {
  2344. value: !1
  2345. };
  2346. for (; !this.match('}');) {
  2347. const e = this.match('...') ? this.parseSpreadElement() : this.parseObjectProperty(s);
  2348. t.push(e), this.match('}') || e.method && !this.match(',') || this.expectCommaSeparator();
  2349. }
  2350. return this.expect('}'), this.finalize(e, new ObjectExpression(t));
  2351. }
  2352.  
  2353. throwTemplateLiteralEarlyErrors(e) {
  2354. switch (e.notEscapeSequenceHead) {
  2355. case 'u':
  2356. return this.throwUnexpectedToken(e, Messages.InvalidUnicodeEscapeSequence);
  2357. case 'x':
  2358. return this.throwUnexpectedToken(e, Messages.InvalidHexEscapeSequence);
  2359. case '8':
  2360. case '9':
  2361. return this.throwUnexpectedToken(e, Messages.TemplateEscape89);
  2362. default:
  2363. return this.throwUnexpectedToken(e, Messages.TemplateOctalLiteral);
  2364. }
  2365. }
  2366.  
  2367. parseTemplateHead(e) {
  2368. assert(this.lookahead.head, 'Template literal must start with a template head');
  2369. const t = this.createNode();
  2370. const s = this.nextToken();
  2371. e.isTagged || s.notEscapeSequenceHead === null || this.throwTemplateLiteralEarlyErrors(s);
  2372. const i = s.value;
  2373. const r = s.cooked;
  2374. return this.finalize(t, new TemplateElement({
  2375. raw: i,
  2376. cooked: r
  2377. }, s.tail));
  2378. }
  2379.  
  2380. parseTemplateElement(e) {
  2381. this.lookahead.type !== 10 && this.throwUnexpectedToken();
  2382. const t = this.createNode();
  2383. const s = this.nextToken();
  2384. e.isTagged || s.notEscapeSequenceHead === null || this.throwTemplateLiteralEarlyErrors(s);
  2385. const i = s.value;
  2386. const r = s.cooked;
  2387. return this.finalize(t, new TemplateElement({
  2388. raw: i,
  2389. cooked: r
  2390. }, s.tail));
  2391. }
  2392.  
  2393. parseTemplateLiteral(e) {
  2394. const t = this.createNode();
  2395. const s = [];
  2396. const i = [];
  2397. let r = this.parseTemplateHead(e);
  2398. for (i.push(r); !r.tail;) s.push(this.parseExpression()), r = this.parseTemplateElement(e), i.push(r);
  2399. return this.finalize(t, new TemplateLiteral(i, s));
  2400. }
  2401.  
  2402. reinterpretExpressionAsPattern(e) {
  2403. switch (e.type) {
  2404. case 'Identifier':
  2405. case 'MemberExpression':
  2406. case 'RestElement':
  2407. case 'AssignmentPattern':
  2408. default:
  2409. break;
  2410. case 'SpreadElement':
  2411. e.type = 'RestElement', this.reinterpretExpressionAsPattern(e.argument);
  2412. break;
  2413. case 'ArrayExpression':
  2414. e.type = 'ArrayPattern';
  2415. for (let t = 0; t < e.elements.length; t++) e.elements[t] !== null && this.reinterpretExpressionAsPattern(e.elements[t]);
  2416. break;
  2417. case 'ObjectExpression':
  2418. e.type = 'ObjectPattern';
  2419. for (let t = 0; t < e.properties.length; t++) {
  2420. const s = e.properties[t];
  2421. this.reinterpretExpressionAsPattern(s.type === 'SpreadElement' ? s : s.value);
  2422. }
  2423. break;
  2424. case 'AssignmentExpression':
  2425. e.type = 'AssignmentPattern', delete e.operator, this.reinterpretExpressionAsPattern(e.left);
  2426. }
  2427. }
  2428.  
  2429. parseGroupExpression() {
  2430. let e;
  2431. if (this.expect('('), this.match(')')) {
  2432. this.nextToken(), this.match('=>') || this.expect('=>'), e = {
  2433. type: ArrowParameterPlaceHolder,
  2434. params: [],
  2435. async: !1
  2436. };
  2437. } else {
  2438. const t = this.lookahead;
  2439. const s = [];
  2440. if (this.match('...')) {
  2441. e = this.parseRestElement(s), this.expect(')'), this.match('=>') || this.expect('=>'), e = {
  2442. type: ArrowParameterPlaceHolder,
  2443. params: [e],
  2444. async: !1
  2445. };
  2446. } else {
  2447. let i = !1;
  2448. if (this.context.isBindingElement = !0, e = this.inheritCoverGrammar(this.parseAssignmentExpression), this.match(',')) {
  2449. const r = [];
  2450. for (this.context.isAssignmentTarget = !1, r.push(e); this.lookahead.type !== 2 && this.match(',');) {
  2451. if (this.nextToken(), this.match(')')) {
  2452. this.nextToken();
  2453. for (let e = 0; e < r.length; e++) this.reinterpretExpressionAsPattern(r[e]);
  2454. i = !0, e = {
  2455. type: ArrowParameterPlaceHolder,
  2456. params: r,
  2457. async: !1
  2458. };
  2459. } else if (this.match('...')) {
  2460. this.context.isBindingElement || this.throwUnexpectedToken(this.lookahead), r.push(this.parseRestElement(s)), this.expect(')'), this.match('=>') || this.expect('=>'), this.context.isBindingElement = !1;
  2461. for (let e = 0; e < r.length; e++) this.reinterpretExpressionAsPattern(r[e]);
  2462. i = !0, e = {
  2463. type: ArrowParameterPlaceHolder,
  2464. params: r,
  2465. async: !1
  2466. };
  2467. } else r.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
  2468. if (i) break;
  2469. }
  2470. i || (e = this.finalize(this.startNode(t), new SequenceExpression(r)));
  2471. }
  2472. if (!i) {
  2473. if (this.expect(')'), this.match('=>') && (e.type === 'Identifier' && e.name === 'yield' && (i = !0, e = {
  2474. type: ArrowParameterPlaceHolder,
  2475. params: [e],
  2476. async: !1
  2477. }), !i)) {
  2478. 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]);
  2479. else this.reinterpretExpressionAsPattern(e);
  2480. const t = e.type === 'SequenceExpression' ? e.expressions : [e];
  2481. e = {
  2482. type: ArrowParameterPlaceHolder,
  2483. params: t,
  2484. async: !1
  2485. };
  2486. }
  2487. this.context.isBindingElement = !1;
  2488. }
  2489. }
  2490. }
  2491. return e;
  2492. }
  2493.  
  2494. parseArguments() {
  2495. this.expect('(');
  2496. const e = [];
  2497. if (!this.match(')')) {
  2498. for (;;) {
  2499. const t = this.match('...') ? this.parseSpreadElement() : this.isolateCoverGrammar(this.parseAssignmentExpression);
  2500. if (e.push(t), this.match(')')) break;
  2501. if (this.expectCommaSeparator(), this.match(')')) break;
  2502. }
  2503. }
  2504. return this.expect(')'), e;
  2505. }
  2506.  
  2507. isIdentifierName(e) {
  2508. return e.type === 3 || e.type === 4 || e.type === 1 || e.type === 5;
  2509. }
  2510.  
  2511. parseIdentifierName(e = !1) {
  2512. let t = !1;
  2513. const s = this.createNode();
  2514. let i = this.nextToken();
  2515. 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));
  2516. }
  2517.  
  2518. parseNewExpression() {
  2519. const e = this.createNode();
  2520. const t = this.parseIdentifierName();
  2521. let s;
  2522. if (assert(t.name === 'new', 'New expression must start with `new`'), this.match('.')) {
  2523. if (this.nextToken(), this.lookahead.type === 3 && this.context.inFunctionBody && this.lookahead.value === 'target') {
  2524. const e = this.parseIdentifierName();
  2525. s = new MetaProperty(t, e);
  2526. } else this.throwUnexpectedToken(this.lookahead);
  2527. } else if (this.matchKeyword('import')) this.throwUnexpectedToken(this.lookahead);
  2528. else {
  2529. const e = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
  2530. const t = this.match('(') ? this.parseArguments() : [];
  2531. s = new NewExpression(e, t), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2532. }
  2533. return this.finalize(e, s);
  2534. }
  2535.  
  2536. parseAsyncArgument() {
  2537. const e = this.parseAssignmentExpression();
  2538. return this.context.firstCoverInitializedNameError = null, e;
  2539. }
  2540.  
  2541. parseAsyncArguments() {
  2542. this.expect('(');
  2543. const e = [];
  2544. if (!this.match(')')) {
  2545. for (;;) {
  2546. const t = this.match('...') ? this.parseSpreadElement() : this.isolateCoverGrammar(this.parseAsyncArgument);
  2547. if (e.push(t), this.match(')')) break;
  2548. if (this.expectCommaSeparator(), this.match(')')) break;
  2549. }
  2550. }
  2551. return this.expect(')'), e;
  2552. }
  2553.  
  2554. matchImportCall() {
  2555. let e = this.matchKeyword('import');
  2556. if (e) {
  2557. const t = this.scanner.saveState();
  2558. this.scanner.scanComments();
  2559. const s = this.scanner.lex();
  2560. this.scanner.restoreState(t), e = s.type === 7 && s.value === '(';
  2561. }
  2562. return e;
  2563. }
  2564.  
  2565. parseImportCall() {
  2566. const e = this.createNode();
  2567. this.expectKeyword('import'), this.expect('(');
  2568. const t = this.context.isAssignmentTarget;
  2569. this.context.isAssignmentTarget = !0;
  2570. const s = this.parseAssignmentExpression();
  2571. let i = null;
  2572. 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));
  2573. }
  2574.  
  2575. matchImportMeta() {
  2576. let e = this.matchKeyword('import');
  2577. if (e) {
  2578. const t = this.scanner.saveState();
  2579. this.scanner.scanComments();
  2580. const s = this.scanner.lex();
  2581. if (s.type === 7 && s.value === '.') {
  2582. this.scanner.scanComments();
  2583. const t = this.scanner.lex();
  2584. e = t.type === 3 && t.value === 'meta', e && t.end - t.start != 4 && this.tolerateUnexpectedToken(t, Messages.InvalidEscapedReservedWord);
  2585. } else e = !1;
  2586. this.scanner.restoreState(t);
  2587. }
  2588. return e;
  2589. }
  2590.  
  2591. parseImportMeta() {
  2592. const e = this.createNode();
  2593. const t = this.parseIdentifierName();
  2594. this.expect('.');
  2595. const s = this.parseIdentifierName();
  2596. return this.context.isAssignmentTarget = !1, this.finalize(e, new MetaProperty(t, s));
  2597. }
  2598.  
  2599. parseLeftHandSideExpressionAllowCall() {
  2600. const e = this.lookahead;
  2601. const t = this.matchContextualKeyword('async');
  2602. const s = this.context.allowIn;
  2603. let i;
  2604. this.context.allowIn = !0;
  2605. const r = this.matchKeyword('super');
  2606. 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);
  2607. let n = !1;
  2608. for (;;) {
  2609. let s = !1;
  2610. if (this.match('?.') && (s = !0, n = !0, this.expect('?.')), this.match('(')) {
  2611. const r = t && e.lineNumber === this.lookahead.lineNumber;
  2612. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !1;
  2613. const n = r ? this.parseAsyncArguments() : this.parseArguments();
  2614. 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('=>')) {
  2615. for (let e = 0; e < n.length; ++e) this.reinterpretExpressionAsPattern(n[e]);
  2616. i = {
  2617. type: ArrowParameterPlaceHolder,
  2618. params: n,
  2619. async: !0
  2620. };
  2621. }
  2622. } else if (this.match('[')) {
  2623. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !s, this.expect('[');
  2624. const t = this.isolateCoverGrammar(this.parseExpression);
  2625. this.expect(']'), i = this.finalize(this.startNode(e), new MemberExpression(!0, i, t, s));
  2626. } else if (this.lookahead.type === 10 && this.lookahead.head) {
  2627. s && this.throwUnexpectedToken(this.lookahead), n && this.throwError(Messages.InvalidTaggedTemplateOnOptionalChain);
  2628. const t = this.parseTemplateLiteral({
  2629. isTagged: !0
  2630. });
  2631. i = this.finalize(this.startNode(e), new TaggedTemplateExpression(i, t));
  2632. } else {
  2633. if (!this.match('.') && !s) break;
  2634. {
  2635. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !s, s || this.expect('.');
  2636. const t = this.parseIdentifierName(!0);
  2637. i = this.finalize(this.startNode(e), new MemberExpression(!1, i, t, s));
  2638. }
  2639. }
  2640. }
  2641. return this.context.allowIn = s, n && (i = this.finalize(this.startNode(e), new ChainExpression(i))), i;
  2642. }
  2643.  
  2644. parseSuper() {
  2645. const e = this.createNode();
  2646. return this.expectKeyword('super'), this.match('[') || this.match('.') || this.throwUnexpectedToken(this.lookahead), this.finalize(e, new Super());
  2647. }
  2648.  
  2649. parseLeftHandSideExpression() {
  2650. assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
  2651. const e = this.startNode(this.lookahead);
  2652. let t = this.matchKeyword('super') && this.context.inFunctionBody ? this.parseSuper() : this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
  2653. let s = !1;
  2654. for (;;) {
  2655. let i = !1;
  2656. if (this.match('?.') && (i = !0, s = !0, this.expect('?.')), this.match('[')) {
  2657. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !i, this.expect('[');
  2658. const s = this.isolateCoverGrammar(this.parseExpression);
  2659. this.expect(']'), t = this.finalize(e, new MemberExpression(!0, t, s, i));
  2660. } else if (this.lookahead.type === 10 && this.lookahead.head) {
  2661. i && this.throwUnexpectedToken(this.lookahead), s && this.throwError(Messages.InvalidTaggedTemplateOnOptionalChain);
  2662. const r = this.parseTemplateLiteral({
  2663. isTagged: !0
  2664. });
  2665. t = this.finalize(e, new TaggedTemplateExpression(t, r));
  2666. } else {
  2667. if (!this.match('.') && !i) break;
  2668. {
  2669. this.context.isBindingElement = !1, this.context.isAssignmentTarget = !i, i || this.expect('.');
  2670. const s = this.parseIdentifierName();
  2671. t = this.finalize(e, new MemberExpression(!1, t, s, i));
  2672. }
  2673. }
  2674. }
  2675. return s && (t = this.finalize(e, new ChainExpression(t))), t;
  2676. }
  2677.  
  2678. parseUpdateExpression() {
  2679. let e;
  2680. const t = this.lookahead;
  2681. if (this.match('++') || this.match('--')) {
  2682. const s = this.startNode(t);
  2683. const i = this.nextToken();
  2684. 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);
  2685. const r = !0;
  2686. e = this.finalize(s, new UpdateExpression(i.value, e, r)), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2687. } else if (e = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall), !this.hasLineTerminator && this.lookahead.type === 7 && (this.match('++') || this.match('--'))) {
  2688. 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;
  2689. const s = this.nextToken().value;
  2690. const i = !1;
  2691. e = this.finalize(this.startNode(t), new UpdateExpression(s, e, i));
  2692. }
  2693. return e;
  2694. }
  2695.  
  2696. parseAwaitExpression() {
  2697. const e = this.createNode();
  2698. this.nextToken();
  2699. const t = this.parseUnaryExpression();
  2700. return this.finalize(e, new AwaitExpression(t));
  2701. }
  2702.  
  2703. parseUnaryExpression() {
  2704. let e;
  2705. if (this.match('+') || this.match('-') || this.match('~') || this.match('!') || this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
  2706. const t = this.startNode(this.lookahead);
  2707. const s = this.nextToken();
  2708. 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;
  2709. } else e = (this.context.isModule && !this.context.inFunctionBody || this.context.isAsync) && this.matchContextualKeyword('await') ? this.parseAwaitExpression() : this.parseUpdateExpression();
  2710. return e;
  2711. }
  2712.  
  2713. parseExponentiationExpression() {
  2714. const e = this.lookahead;
  2715. const t = this.match('(');
  2716. let s = this.inheritCoverGrammar(this.parseUnaryExpression);
  2717. if ((s.type !== 'UnaryExpression' || t) && this.match('**')) {
  2718. this.nextToken(), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2719. const t = s;
  2720. const i = this.isolateCoverGrammar(this.parseExponentiationExpression);
  2721. s = this.finalize(this.startNode(e), new BinaryExpression('**', t, i));
  2722. }
  2723. return s;
  2724. }
  2725.  
  2726. binaryPrecedence(e) {
  2727. const t = e.value;
  2728. let s;
  2729. return s = e.type === 7 ? this.operatorPrecedence[t] || 0 : e.type === 4 && (t === 'instanceof' || this.context.allowIn && t === 'in') ? 12 : 0, s;
  2730. }
  2731.  
  2732. parseBinaryExpression() {
  2733. const e = this.lookahead;
  2734. let t = this.inheritCoverGrammar(this.parseExponentiationExpression);
  2735. let s = !0;
  2736. let i = !0;
  2737. const r = e => {
  2738. e.value !== '&&' && e.value !== '||' || (i = !1), e.value === '??' && (s = !1);
  2739. };
  2740. const n = this.lookahead;
  2741. let a = this.binaryPrecedence(n);
  2742. if (a > 0) {
  2743. r(n), this.nextToken(), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2744. const o = [e, this.lookahead];
  2745. let u = t;
  2746. let h = this.isolateCoverGrammar(this.parseExponentiationExpression);
  2747. const c = [u, n.value, h];
  2748. const l = [a];
  2749. for (; a = this.binaryPrecedence(this.lookahead), !(a <= 0);) {
  2750. 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];) {
  2751. h = c.pop();
  2752. const e = c.pop();
  2753. l.pop(), u = c.pop(), o.pop();
  2754. const t = o[o.length - 1];
  2755. const s = this.startNode(t, t.lineStart);
  2756. const i = e === '||' || e === '&&' || e === '??';
  2757. c.push(this.finalize(s, i ? new LogicalExpression(e, u, h) : new BinaryExpression(e, u, h)));
  2758. }
  2759. c.push(this.nextToken().value), l.push(a), o.push(this.lookahead), c.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
  2760. }
  2761. let p = c.length - 1;
  2762. t = c[p];
  2763. let m = o.pop();
  2764. for (; p > 1;) {
  2765. const e = o.pop();
  2766. const s = m && m.lineStart;
  2767. const i = this.startNode(e, s);
  2768. const r = c[p - 1];
  2769. const n = r === '||' || r === '&&' || r === '??';
  2770. t = this.finalize(i, n ? new LogicalExpression(r, c[p - 2], t) : new BinaryExpression(r, c[p - 2], t)), p -= 2, m = e;
  2771. }
  2772. }
  2773. return t;
  2774. }
  2775.  
  2776. parseConditionalExpression() {
  2777. const e = this.lookahead;
  2778. let t = this.inheritCoverGrammar(this.parseBinaryExpression);
  2779. if (this.match('?')) {
  2780. this.nextToken();
  2781. const s = this.context.allowIn;
  2782. this.context.allowIn = !0;
  2783. const i = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2784. this.context.allowIn = s, this.expect(':');
  2785. const r = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2786. t = this.finalize(this.startNode(e), new ConditionalExpression(t, i, r)), this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2787. }
  2788. return t;
  2789. }
  2790.  
  2791. checkPatternParam(e, t) {
  2792. switch (t.type) {
  2793. case 'Identifier':
  2794. this.validateParam(e, t, t.name);
  2795. break;
  2796. case 'RestElement':
  2797. this.checkPatternParam(e, t.argument);
  2798. break;
  2799. case 'AssignmentPattern':
  2800. this.checkPatternParam(e, t.left);
  2801. break;
  2802. case 'ArrayPattern':
  2803. for (let s = 0; s < t.elements.length; s++) t.elements[s] !== null && this.checkPatternParam(e, t.elements[s]);
  2804. break;
  2805. case 'ObjectPattern':
  2806. for (let s = 0; s < t.properties.length; s++) {
  2807. const i = t.properties[s];
  2808. this.checkPatternParam(e, i.type === 'RestElement' ? i : i.value);
  2809. }
  2810. }
  2811. e.simple = e.simple && t instanceof Identifier;
  2812. }
  2813.  
  2814. reinterpretAsCoverFormalsList(e) {
  2815. let t = [e];
  2816. const s = {
  2817. simple: !0,
  2818. paramSet: {}
  2819. };
  2820. let i = !1;
  2821. switch (e.type) {
  2822. case 'Identifier':
  2823. break;
  2824. case ArrowParameterPlaceHolder:
  2825. t = e.params, i = e.async;
  2826. break;
  2827. default:
  2828. return null;
  2829. }
  2830. for (let e = 0; e < t.length; ++e) {
  2831. const r = t[e];
  2832. 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;
  2833. }
  2834. if (this.context.strict || !this.context.allowYield) {
  2835. for (let e = 0; e < t.length; ++e) {
  2836. t[e].type === 'YieldExpression' && this.throwUnexpectedToken(this.lookahead);
  2837. }
  2838. }
  2839. if (s.hasDuplicateParameterNames) {
  2840. const e = this.context.strict ? s.stricted : s.firstRestricted;
  2841. this.throwUnexpectedToken(e, Messages.DuplicateParameter);
  2842. }
  2843. return {
  2844. simple: s.simple,
  2845. params: t,
  2846. stricted: s.stricted,
  2847. firstRestricted: s.firstRestricted,
  2848. message: s.message
  2849. };
  2850. }
  2851.  
  2852. parseAssignmentExpression() {
  2853. let e;
  2854. if (!this.context.allowYield && this.matchKeyword('yield')) e = this.parseYieldExpression();
  2855. else {
  2856. const t = this.lookahead;
  2857. let s = t;
  2858. if (e = this.parseConditionalExpression(), s.type === 3 && s.lineNumber === this.lookahead.lineNumber && s.value === 'async' && (this.lookahead.type === 3 || this.matchKeyword('yield'))) {
  2859. const t = this.parsePrimaryExpression();
  2860. this.reinterpretExpressionAsPattern(t), e = {
  2861. type: ArrowParameterPlaceHolder,
  2862. params: [t],
  2863. async: !0
  2864. };
  2865. }
  2866. if (e.type === ArrowParameterPlaceHolder || this.match('=>')) {
  2867. this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1;
  2868. const s = e.async;
  2869. const i = this.reinterpretAsCoverFormalsList(e);
  2870. if (i) {
  2871. this.hasLineTerminator && this.tolerateUnexpectedToken(this.lookahead), this.context.firstCoverInitializedNameError = null;
  2872. const r = this.context.strict;
  2873. const n = this.context.allowStrictDirective;
  2874. this.context.allowStrictDirective = i.simple;
  2875. const a = this.context.allowYield;
  2876. const o = this.context.isAsync;
  2877. this.context.allowYield = !0, this.context.isAsync = s;
  2878. const u = this.startNode(t);
  2879. let h;
  2880. if (this.expect('=>'), this.match('{')) {
  2881. const e = this.context.allowIn;
  2882. this.context.allowIn = !0, h = this.parseFunctionSourceElements(), this.context.allowIn = e;
  2883. } else h = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2884. const c = h.type !== 'BlockStatement';
  2885. 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;
  2886. }
  2887. } else if (this.matchAssign()) {
  2888. if (this.context.isAssignmentTarget || this.tolerateError(Messages.InvalidLHSInAssignment), this.context.strict && e.type === 'Identifier') {
  2889. const t = e;
  2890. this.scanner.isRestrictedWord(t.name) && this.tolerateUnexpectedToken(s, Messages.StrictLHSAssignment), this.scanner.isStrictModeReservedWord(t.name) && this.tolerateUnexpectedToken(s, Messages.StrictReservedWord);
  2891. }
  2892. this.match('=') ? this.reinterpretExpressionAsPattern(e) : (this.context.isAssignmentTarget = !1, this.context.isBindingElement = !1), s = this.nextToken();
  2893. const i = s.value;
  2894. const r = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2895. e = this.finalize(this.startNode(t), new AssignmentExpression(i, e, r)), this.context.firstCoverInitializedNameError = null;
  2896. }
  2897. }
  2898. return e;
  2899. }
  2900.  
  2901. parseExpression() {
  2902. const e = this.lookahead;
  2903. let t = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2904. if (this.match(',')) {
  2905. const s = [];
  2906. for (s.push(t); this.lookahead.type !== 2 && this.match(',');) this.nextToken(), s.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  2907. t = this.finalize(this.startNode(e), new SequenceExpression(s));
  2908. }
  2909. return t;
  2910. }
  2911.  
  2912. parseStatementListItem() {
  2913. let e;
  2914. if (this.context.isAssignmentTarget = !0, this.context.isBindingElement = !0, this.lookahead.type === 4) {
  2915. switch (this.lookahead.value) {
  2916. case 'export':
  2917. this.context.isModule || this.tolerateUnexpectedToken(this.lookahead, Messages.IllegalExportDeclaration), e = this.parseExportDeclaration();
  2918. break;
  2919. case 'import':
  2920. this.matchImportCall() ? e = this.parseExpressionStatement() : this.matchImportMeta() ? e = this.parseStatement() : (this.context.isModule || this.tolerateUnexpectedToken(this.lookahead, Messages.IllegalImportDeclaration), e = this.parseImportDeclaration());
  2921. break;
  2922. case 'const':
  2923. e = this.parseLexicalDeclaration({
  2924. inFor: !1
  2925. });
  2926. break;
  2927. case 'function':
  2928. e = this.parseFunctionDeclaration();
  2929. break;
  2930. case 'class':
  2931. e = this.parseClassDeclaration();
  2932. break;
  2933. case 'let':
  2934. e = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({
  2935. inFor: !1
  2936. }) : this.parseStatement();
  2937. break;
  2938. default:
  2939. e = this.parseStatement();
  2940. }
  2941. } else e = this.parseStatement();
  2942. return e;
  2943. }
  2944.  
  2945. parseBlock() {
  2946. const e = this.createNode();
  2947. this.expect('{');
  2948. const t = [];
  2949. for (; !this.match('}');) t.push(this.parseStatementListItem());
  2950. return this.expect('}'), this.finalize(e, new BlockStatement(t));
  2951. }
  2952.  
  2953. parseLexicalBinding(e, t) {
  2954. const s = this.createNode();
  2955. const i = this.parsePattern([], e);
  2956. this.context.strict && i.type === 'Identifier' && this.scanner.isRestrictedWord(i.name) && this.tolerateError(Messages.StrictVarName);
  2957. let r = null;
  2958. 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));
  2959. }
  2960.  
  2961. parseBindingList(e, t) {
  2962. const s = [this.parseLexicalBinding(e, t)];
  2963. for (; this.match(',');) this.nextToken(), s.push(this.parseLexicalBinding(e, t));
  2964. return s;
  2965. }
  2966.  
  2967. isLexicalDeclaration() {
  2968. const e = this.scanner.saveState();
  2969. this.scanner.scanComments();
  2970. const t = this.scanner.lex();
  2971. 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';
  2972. }
  2973.  
  2974. parseLexicalDeclaration(e) {
  2975. const t = this.createNode();
  2976. const s = this.nextToken().value;
  2977. assert(s === 'let' || s === 'const', 'Lexical declaration must be either let or const');
  2978. const i = this.parseBindingList(s, e);
  2979. return this.consumeSemicolon(), this.finalize(t, new VariableDeclaration(i, s));
  2980. }
  2981.  
  2982. isInitializedProperty() {
  2983. const e = this.scanner.saveState();
  2984. this.scanner.scanComments();
  2985. const t = this.scanner.lex();
  2986. return this.scanner.restoreState(e), this.lookahead.type === 3 && t.value === '=';
  2987. }
  2988.  
  2989. isDeclaredProperty() {
  2990. const e = this.scanner.saveState();
  2991. this.scanner.scanComments();
  2992. const t = this.scanner.lex();
  2993. return this.scanner.restoreState(e), this.lookahead.type === 3 && t.value === ';' || this.lookahead.type === 3 && t.lineNumber !== this.startMarker.line;
  2994. }
  2995.  
  2996. parseBindingRestElement(e, t) {
  2997. const s = this.createNode();
  2998. this.expect('...');
  2999. const i = this.parsePattern(e, t);
  3000. return this.finalize(s, new RestElement(i));
  3001. }
  3002.  
  3003. parseArrayPattern(e, t) {
  3004. const s = this.createNode();
  3005. this.expect('[');
  3006. const i = [];
  3007. for (; !this.match(']');) {
  3008. if (this.match(',')) this.nextToken(), i.push(null);
  3009. else {
  3010. if (this.match('...')) {
  3011. i.push(this.parseBindingRestElement(e, t));
  3012. break;
  3013. }
  3014. i.push(this.parsePatternWithDefault(e, t)), this.match(']') || this.expect(',');
  3015. }
  3016. } return this.expect(']'), this.finalize(s, new ArrayPattern(i));
  3017. }
  3018.  
  3019. parsePropertyPattern(e, t) {
  3020. const s = this.createNode();
  3021. let i = !1;
  3022. let r = !1;
  3023. let n; let
  3024. a;
  3025. if (this.lookahead.type === 3) {
  3026. const i = this.lookahead;
  3027. n = this.parseVariableIdentifier();
  3028. const o = this.finalize(s, new Identifier(i.value));
  3029. if (this.match('=')) {
  3030. e.push(i), r = !0, this.nextToken();
  3031. const t = this.parseAssignmentExpression();
  3032. a = this.finalize(this.startNode(i), new AssignmentPattern(o, t));
  3033. } else this.match(':') ? (this.expect(':'), a = this.parsePatternWithDefault(e, t)) : (e.push(i), r = !0, a = o);
  3034. } else i = this.match('['), n = this.parseObjectPropertyKey(), this.expect(':'), a = this.parsePatternWithDefault(e, t);
  3035. return this.finalize(s, new Property('init', n, i, a, !1, r));
  3036. }
  3037.  
  3038. parseRestProperty(e) {
  3039. const t = this.createNode();
  3040. this.expect('...');
  3041. const s = this.parsePattern(e);
  3042. return this.match('=') && this.throwError(Messages.DefaultRestProperty), this.match('}') || this.throwError(Messages.PropertyAfterRestProperty), this.finalize(t, new RestElement(s));
  3043. }
  3044.  
  3045. parseObjectPattern(e, t) {
  3046. const s = this.createNode();
  3047. const i = [];
  3048. for (this.expect('{'); !this.match('}');) i.push(this.match('...') ? this.parseRestProperty(e) : this.parsePropertyPattern(e, t)), this.match('}') || this.expect(',');
  3049. return this.expect('}'), this.finalize(s, new ObjectPattern(i));
  3050. }
  3051.  
  3052. parsePattern(e, t) {
  3053. let s;
  3054. 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;
  3055. }
  3056.  
  3057. parsePatternWithDefault(e, t) {
  3058. const s = this.lookahead;
  3059. let i = this.parsePattern(e, t);
  3060. if (this.match('=')) {
  3061. this.nextToken();
  3062. const e = this.context.allowYield;
  3063. this.context.allowYield = !0;
  3064. const t = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3065. this.context.allowYield = e, i = this.finalize(this.startNode(s), new AssignmentPattern(i, t));
  3066. }
  3067. return i;
  3068. }
  3069.  
  3070. parseVariableIdentifier(e) {
  3071. const t = this.createNode();
  3072. const s = this.nextToken();
  3073. 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));
  3074. }
  3075.  
  3076. parseVariableDeclaration(e) {
  3077. const t = this.createNode();
  3078. const s = this.parsePattern([], 'var');
  3079. this.context.strict && s.type === 'Identifier' && this.scanner.isRestrictedWord(s.name) && this.tolerateError(Messages.StrictVarName);
  3080. let i = null;
  3081. return this.match('=') ? (this.nextToken(), i = this.isolateCoverGrammar(this.parseAssignmentExpression)) : s.type === 'Identifier' || e.inFor || this.expect('='), this.finalize(t, new VariableDeclarator(s, i));
  3082. }
  3083.  
  3084. parseVariableDeclarationList(e) {
  3085. const t = {
  3086. inFor: e.inFor
  3087. };
  3088. const s = [];
  3089. for (s.push(this.parseVariableDeclaration(t)); this.match(',');) this.nextToken(), s.push(this.parseVariableDeclaration(t));
  3090. return s;
  3091. }
  3092.  
  3093. parseVariableStatement() {
  3094. const e = this.createNode();
  3095. this.expectKeyword('var');
  3096. const t = this.parseVariableDeclarationList({
  3097. inFor: !1
  3098. });
  3099. return this.consumeSemicolon(), this.finalize(e, new VariableDeclaration(t, 'var'));
  3100. }
  3101.  
  3102. parseEmptyStatement() {
  3103. const e = this.createNode();
  3104. return this.expect(';'), this.finalize(e, new EmptyStatement());
  3105. }
  3106.  
  3107. parseExpressionStatement() {
  3108. const e = this.createNode();
  3109. const t = this.parseExpression();
  3110. return this.consumeSemicolon(), this.finalize(e, new ExpressionStatement(t));
  3111. }
  3112.  
  3113. parseIfClause() {
  3114. return this.context.strict && this.matchKeyword('function') && this.tolerateError(Messages.StrictFunction), this.parseStatement();
  3115. }
  3116.  
  3117. parseIfStatement() {
  3118. const e = this.createNode();
  3119. let t; let
  3120. s = null;
  3121. this.expectKeyword('if'), this.expect('(');
  3122. const i = this.parseExpression();
  3123. 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));
  3124. }
  3125.  
  3126. parseDoWhileStatement() {
  3127. const e = this.createNode();
  3128. this.expectKeyword('do'), this.tolerateInvalidLoopStatement();
  3129. const t = this.context.inIteration;
  3130. this.context.inIteration = !0;
  3131. const s = this.parseStatement();
  3132. this.context.inIteration = t, this.expectKeyword('while'), this.expect('(');
  3133. const i = this.parseExpression();
  3134. return !this.match(')') && this.config.tolerant ? this.tolerateUnexpectedToken(this.nextToken()) : (this.expect(')'), this.match(';') && this.nextToken()), this.finalize(e, new DoWhileStatement(s, i));
  3135. }
  3136.  
  3137. parseWhileStatement() {
  3138. const e = this.createNode();
  3139. let t;
  3140. this.expectKeyword('while'), this.expect('(');
  3141. const s = this.parseExpression();
  3142. if (!this.match(')') && this.config.tolerant) this.tolerateUnexpectedToken(this.nextToken()), t = this.finalize(this.createNode(), new EmptyStatement());
  3143. else {
  3144. this.expect(')');
  3145. const e = this.context.inIteration;
  3146. this.context.inIteration = !0, t = this.parseStatement(), this.context.inIteration = e;
  3147. }
  3148. return this.finalize(e, new WhileStatement(s, t));
  3149. }
  3150.  
  3151. parseForStatement() {
  3152. let e; let t; let s = null;
  3153. let i = null;
  3154. let r = null;
  3155. let n = !0;
  3156. let a = !1;
  3157. const o = this.createNode();
  3158. if (this.expectKeyword('for'), this.matchContextualKeyword('await') && (this.context.isAsync || this.tolerateUnexpectedToken(this.lookahead), a = !0, this.nextToken()), this.expect('('), this.match(';')) this.nextToken();
  3159. else if (this.matchKeyword('var')) {
  3160. s = this.createNode(), this.nextToken();
  3161. const i = this.context.allowIn;
  3162. this.context.allowIn = !1;
  3163. const r = this.parseVariableDeclarationList({
  3164. inFor: !0
  3165. });
  3166. if (this.context.allowIn = i, !a && r.length === 1 && this.matchKeyword('in')) {
  3167. const i = r[0];
  3168. 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;
  3169. } 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(';'));
  3170. } else if (this.matchKeyword('const') || this.matchKeyword('let')) {
  3171. s = this.createNode();
  3172. const i = this.nextToken().value;
  3173. if (this.context.strict || this.lookahead.value !== 'in') {
  3174. const r = this.context.allowIn;
  3175. this.context.allowIn = !1;
  3176. const a = this.parseBindingList(i, {
  3177. inFor: !0
  3178. });
  3179. 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)));
  3180. } else s = this.finalize(s, new Identifier(i)), this.nextToken(), e = s, t = this.parseExpression(), s = null;
  3181. } else {
  3182. const i = this.lookahead;
  3183. const r = this.context.isBindingElement;
  3184. const a = this.context.isAssignmentTarget;
  3185. const o = this.context.firstCoverInitializedNameError;
  3186. const u = this.context.allowIn;
  3187. 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;
  3188. 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;
  3189. else {
  3190. if (this.context.isBindingElement = r, this.context.isAssignmentTarget = a, this.context.firstCoverInitializedNameError = o, this.match(',')) {
  3191. const e = [s];
  3192. for (; this.match(',');) this.nextToken(), e.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  3193. s = this.finalize(this.startNode(i), new SequenceExpression(e));
  3194. }
  3195. this.expect(';');
  3196. }
  3197. }
  3198. let u;
  3199. 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());
  3200. else {
  3201. this.expect(')'), this.tolerateInvalidLoopStatement();
  3202. const e = this.context.inIteration;
  3203. this.context.inIteration = !0, u = this.isolateCoverGrammar(this.parseStatement), this.context.inIteration = e;
  3204. }
  3205. 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));
  3206. }
  3207.  
  3208. parseContinueStatement() {
  3209. const e = this.createNode();
  3210. this.expectKeyword('continue');
  3211. let t = null;
  3212. if (this.lookahead.type === 3 && !this.hasLineTerminator) {
  3213. const e = this.parseVariableIdentifier();
  3214. t = e;
  3215. const s = `$${e.name}`;
  3216. Object.prototype.hasOwnProperty.call(this.context.labelSet, s) || this.throwError(Messages.UnknownLabel, e.name);
  3217. }
  3218. return this.consumeSemicolon(), t !== null || this.context.inIteration || this.throwError(Messages.IllegalContinue), this.finalize(e, new ContinueStatement(t));
  3219. }
  3220.  
  3221. parseBreakStatement() {
  3222. const e = this.createNode();
  3223. this.expectKeyword('break');
  3224. let t = null;
  3225. if (this.lookahead.type === 3 && !this.hasLineTerminator) {
  3226. const e = this.parseVariableIdentifier();
  3227. const s = `$${e.name}`;
  3228. Object.prototype.hasOwnProperty.call(this.context.labelSet, s) || this.throwError(Messages.UnknownLabel, e.name), t = e;
  3229. }
  3230. return this.consumeSemicolon(), t !== null || this.context.inIteration || this.context.inSwitch || this.throwError(Messages.IllegalBreak), this.finalize(e, new BreakStatement(t));
  3231. }
  3232.  
  3233. parseReturnStatement() {
  3234. this.context.inFunctionBody || this.tolerateError(Messages.IllegalReturn);
  3235. const e = this.createNode();
  3236. this.expectKeyword('return');
  3237. const t = !this.match(';') && !this.match('}') && !this.hasLineTerminator && this.lookahead.type !== 2 || this.lookahead.type === 8 || this.lookahead.type === 10 ? this.parseExpression() : null;
  3238. return this.consumeSemicolon(), this.finalize(e, new ReturnStatement(t));
  3239. }
  3240.  
  3241. parseWithStatement() {
  3242. this.context.strict && this.tolerateError(Messages.StrictModeWith);
  3243. const e = this.createNode();
  3244. let t;
  3245. this.expectKeyword('with'), this.expect('(');
  3246. const s = this.parseExpression();
  3247. 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));
  3248. }
  3249.  
  3250. parseSwitchCase() {
  3251. const e = this.createNode();
  3252. let t;
  3253. this.matchKeyword('default') ? (this.nextToken(), t = null) : (this.expectKeyword('case'), t = this.parseExpression()), this.expect(':');
  3254. const s = [];
  3255. for (; !(this.match('}') || this.matchKeyword('default') || this.matchKeyword('case'));) s.push(this.parseStatementListItem());
  3256. return this.finalize(e, new SwitchCase(t, s));
  3257. }
  3258.  
  3259. parseSwitchStatement() {
  3260. const e = this.createNode();
  3261. this.expectKeyword('switch'), this.expect('(');
  3262. const t = this.parseExpression();
  3263. this.expect(')');
  3264. const s = this.context.inSwitch;
  3265. this.context.inSwitch = !0;
  3266. const i = [];
  3267. let r = !1;
  3268. for (this.expect('{'); !this.match('}');) {
  3269. const e = this.parseSwitchCase();
  3270. e.test === null && (r && this.throwError(Messages.MultipleDefaultsInSwitch), r = !0), i.push(e);
  3271. }
  3272. return this.expect('}'), this.context.inSwitch = s, this.finalize(e, new SwitchStatement(t, i));
  3273. }
  3274.  
  3275. parseLabelledStatement() {
  3276. const e = this.createNode();
  3277. const t = this.parseExpression();
  3278. let s;
  3279. if (t.type === 'Identifier' && this.match(':')) {
  3280. this.nextToken();
  3281. const e = t;
  3282. const i = `$${e.name}`;
  3283. let r;
  3284. 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();
  3285. else if (this.matchKeyword('function')) {
  3286. const e = this.lookahead;
  3287. const t = this.parseFunctionDeclaration();
  3288. this.context.strict ? this.tolerateUnexpectedToken(e, Messages.StrictFunction) : t.generator && this.tolerateUnexpectedToken(e, Messages.GeneratorInLegacyContext), r = t;
  3289. } else r = this.parseStatement();
  3290. delete this.context.labelSet[i], s = new LabeledStatement(e, r);
  3291. } else this.consumeSemicolon(), s = new ExpressionStatement(t);
  3292. return this.finalize(e, s);
  3293. }
  3294.  
  3295. parseThrowStatement() {
  3296. const e = this.createNode();
  3297. this.expectKeyword('throw'), this.hasLineTerminator && this.throwError(Messages.NewlineAfterThrow);
  3298. const t = this.parseExpression();
  3299. return this.consumeSemicolon(), this.finalize(e, new ThrowStatement(t));
  3300. }
  3301.  
  3302. parseCatchClause() {
  3303. const e = this.createNode();
  3304. this.expectKeyword('catch');
  3305. let t = null;
  3306. if (this.match('(')) {
  3307. this.expect('('), this.match(')') && this.throwUnexpectedToken(this.lookahead);
  3308. const e = [];
  3309. t = this.parsePattern(e);
  3310. const s = {};
  3311. for (let t = 0; t < e.length; t++) {
  3312. const i = `$${e[t].value}`;
  3313. Object.prototype.hasOwnProperty.call(s, i) && this.tolerateError(Messages.DuplicateBinding, e[t].value), s[i] = !0;
  3314. }
  3315. this.context.strict && t.type === 'Identifier' && this.scanner.isRestrictedWord(t.name) && this.tolerateError(Messages.StrictCatchVariable), this.expect(')');
  3316. }
  3317. const s = this.parseBlock();
  3318. return this.finalize(e, new CatchClause(t, s));
  3319. }
  3320.  
  3321. parseFinallyClause() {
  3322. return this.expectKeyword('finally'), this.parseBlock();
  3323. }
  3324.  
  3325. parseTryStatement() {
  3326. const e = this.createNode();
  3327. this.expectKeyword('try');
  3328. const t = this.parseBlock();
  3329. const s = this.matchKeyword('catch') ? this.parseCatchClause() : null;
  3330. const i = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
  3331. return s || i || this.throwError(Messages.NoCatchOrFinally), this.finalize(e, new TryStatement(t, s, i));
  3332. }
  3333.  
  3334. parseDebuggerStatement() {
  3335. const e = this.createNode();
  3336. return this.expectKeyword('debugger'), this.consumeSemicolon(), this.finalize(e, new DebuggerStatement());
  3337. }
  3338.  
  3339. parseStatement() {
  3340. let e;
  3341. switch (this.lookahead.type) {
  3342. case 1:
  3343. case 5:
  3344. case 6:
  3345. case 8:
  3346. case 10:
  3347. case 9:
  3348. e = this.parseExpressionStatement();
  3349. break;
  3350. case 7:
  3351. const t = this.lookahead.value;
  3352. e = t === '{' ? this.parseBlock() : t === '(' ? this.parseExpressionStatement() : t === ';' ? this.parseEmptyStatement() : this.parseExpressionStatement();
  3353. break;
  3354. case 3:
  3355. e = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement();
  3356. break;
  3357. case 4:
  3358. switch (this.lookahead.value) {
  3359. case 'break':
  3360. e = this.parseBreakStatement();
  3361. break;
  3362. case 'continue':
  3363. e = this.parseContinueStatement();
  3364. break;
  3365. case 'debugger':
  3366. e = this.parseDebuggerStatement();
  3367. break;
  3368. case 'do':
  3369. e = this.parseDoWhileStatement();
  3370. break;
  3371. case 'for':
  3372. e = this.parseForStatement();
  3373. break;
  3374. case 'function':
  3375. e = this.parseFunctionDeclaration();
  3376. break;
  3377. case 'if':
  3378. e = this.parseIfStatement();
  3379. break;
  3380. case 'return':
  3381. e = this.parseReturnStatement();
  3382. break;
  3383. case 'switch':
  3384. e = this.parseSwitchStatement();
  3385. break;
  3386. case 'throw':
  3387. e = this.parseThrowStatement();
  3388. break;
  3389. case 'try':
  3390. e = this.parseTryStatement();
  3391. break;
  3392. case 'var':
  3393. e = this.parseVariableStatement();
  3394. break;
  3395. case 'while':
  3396. e = this.parseWhileStatement();
  3397. break;
  3398. case 'with':
  3399. e = this.parseWithStatement();
  3400. break;
  3401. default:
  3402. e = this.parseExpressionStatement();
  3403. }
  3404. break;
  3405. default:
  3406. e = this.throwUnexpectedToken(this.lookahead);
  3407. }
  3408. return e;
  3409. }
  3410.  
  3411. parseFunctionSourceElements() {
  3412. const e = this.createNode();
  3413. this.expect('{');
  3414. const t = this.parseDirectivePrologues();
  3415. const s = this.context.labelSet;
  3416. const i = this.context.inIteration;
  3417. const r = this.context.inSwitch;
  3418. const n = this.context.inFunctionBody;
  3419. 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());
  3420. 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));
  3421. }
  3422.  
  3423. validateParam(e, t, s) {
  3424. const i = `$${s}`;
  3425. 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, {
  3426. value: !0,
  3427. enumerable: !0,
  3428. writable: !0,
  3429. configurable: !0
  3430. }) : e.paramSet[i] = !0;
  3431. }
  3432.  
  3433. parseRestElement(e) {
  3434. const t = this.createNode();
  3435. this.expect('...');
  3436. const s = this.parsePattern(e);
  3437. return this.match('=') && this.throwError(Messages.DefaultRestParameter), this.match(')') || this.throwError(Messages.ParameterAfterRestParameter), this.finalize(t, new RestElement(s));
  3438. }
  3439.  
  3440. parseFormalParameter(e) {
  3441. const t = [];
  3442. const s = this.match('...') ? this.parseRestElement(t) : this.parsePatternWithDefault(t);
  3443. for (let s = 0; s < t.length; s++) this.validateParam(e, t[s], t[s].value);
  3444. e.simple = e.simple && s instanceof Identifier, e.params.push(s);
  3445. }
  3446.  
  3447. parseFormalParameters(e) {
  3448. const t = {
  3449. simple: !0,
  3450. hasDuplicateParameterNames: !1,
  3451. params: [],
  3452. firstRestricted: e
  3453. };
  3454. if (this.expect('('), !this.match(')')) for (t.paramSet = {}; this.lookahead.type !== 2 && (this.parseFormalParameter(t), !this.match(')')) && (this.expect(','), !this.match(')')););
  3455. return this.expect(')'), t.hasDuplicateParameterNames && (this.context.strict || this.context.isAsync || !t.simple) && this.throwError(Messages.DuplicateParameter), {
  3456. simple: t.simple,
  3457. params: t.params,
  3458. stricted: t.stricted,
  3459. firstRestricted: t.firstRestricted,
  3460. message: t.message
  3461. };
  3462. }
  3463.  
  3464. matchAsyncFunction() {
  3465. let e = this.matchContextualKeyword('async');
  3466. if (e) {
  3467. const t = this.scanner.saveState();
  3468. this.scanner.scanComments();
  3469. const s = this.scanner.lex();
  3470. this.scanner.restoreState(t), e = t.lineNumber === s.lineNumber && s.type === 4 && s.value === 'function';
  3471. }
  3472. return e;
  3473. }
  3474.  
  3475. parseFunctionDeclaration(e) {
  3476. const t = this.createNode();
  3477. const s = this.matchContextualKeyword('async');
  3478. s && (this.context.inIteration && this.tolerateError(Messages.AsyncFunctionInSingleStatementContext), this.nextToken()), this.expectKeyword('function');
  3479. const i = this.match('*');
  3480. let r;
  3481. i && this.nextToken();
  3482. let n = null;
  3483. let a = null;
  3484. if (!e || !this.match('(')) {
  3485. const e = this.lookahead;
  3486. 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);
  3487. }
  3488. const o = this.context.isAsync;
  3489. const u = this.context.allowYield;
  3490. this.context.isAsync = s, this.context.allowYield = !i;
  3491. const h = this.parseFormalParameters(a);
  3492. const c = h.params;
  3493. const l = h.stricted;
  3494. a = h.firstRestricted, h.message && (r = h.message);
  3495. const p = this.context.strict;
  3496. const m = this.context.allowStrictDirective;
  3497. this.context.allowStrictDirective = h.simple;
  3498. const d = this.parseFunctionSourceElements();
  3499. 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));
  3500. }
  3501.  
  3502. parseFunctionExpression() {
  3503. const e = this.createNode();
  3504. const t = this.matchContextualKeyword('async');
  3505. t && this.nextToken(), this.expectKeyword('function');
  3506. const s = this.match('*');
  3507. let i;
  3508. s && this.nextToken();
  3509. let r; let
  3510. n = null;
  3511. const a = this.context.isAsync;
  3512. const o = this.context.allowYield;
  3513. if (this.context.isAsync = t, this.context.allowYield = !s, !this.match('(')) {
  3514. const e = this.lookahead;
  3515. 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);
  3516. }
  3517. const u = this.parseFormalParameters(r);
  3518. const h = u.params;
  3519. const c = u.stricted;
  3520. r = u.firstRestricted, u.message && (i = u.message);
  3521. const l = this.context.strict;
  3522. const p = this.context.allowStrictDirective;
  3523. this.context.allowStrictDirective = u.simple;
  3524. const m = this.parseFunctionSourceElements();
  3525. 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));
  3526. }
  3527.  
  3528. parseDirective() {
  3529. const e = this.lookahead;
  3530. const t = this.createNode();
  3531. const s = this.parseExpression();
  3532. const i = s.type === 'Literal' ? this.getTokenRaw(e).slice(1, -1) : null;
  3533. return this.consumeSemicolon(), this.finalize(t, i ? new Directive(s, i) : new ExpressionStatement(s));
  3534. }
  3535.  
  3536. parseDirectivePrologues() {
  3537. let e = null;
  3538. const t = [];
  3539. for (;;) {
  3540. const s = this.lookahead;
  3541. if (s.type !== 8) break;
  3542. const i = this.parseDirective();
  3543. t.push(i);
  3544. const r = i.directive;
  3545. if (typeof r !== 'string') break;
  3546. 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);
  3547. }
  3548. return t;
  3549. }
  3550.  
  3551. qualifiedPropertyName(e) {
  3552. switch (e.type) {
  3553. case 3:
  3554. case 8:
  3555. case 1:
  3556. case 5:
  3557. case 6:
  3558. case 4:
  3559. return !0;
  3560. case 7:
  3561. return e.value === '[' || e.value === '#';
  3562. }
  3563. return !1;
  3564. }
  3565.  
  3566. parseGetterMethod() {
  3567. const e = this.createNode();
  3568. const t = this.context.allowYield;
  3569. this.context.allowYield = !0;
  3570. const s = this.parseFormalParameters();
  3571. s.params.length > 0 && this.tolerateError(Messages.BadGetterArity);
  3572. const i = this.parsePropertyMethod(s);
  3573. return this.context.allowYield = t, this.finalize(e, new FunctionExpression(null, s.params, i, false, !1));
  3574. }
  3575.  
  3576. parseSetterMethod() {
  3577. const e = this.createNode();
  3578. const t = this.context.allowYield;
  3579. this.context.allowYield = !0;
  3580. const s = this.parseFormalParameters();
  3581. s.params.length !== 1 ? this.tolerateError(Messages.BadSetterArity) : s.params[0] instanceof RestElement && this.tolerateError(Messages.BadSetterRestParameter);
  3582. const i = this.parsePropertyMethod(s);
  3583. return this.context.allowYield = t, this.finalize(e, new FunctionExpression(null, s.params, i, false, !1));
  3584. }
  3585.  
  3586. parseGeneratorMethod(e) {
  3587. const t = this.createNode();
  3588. const s = this.context.allowYield;
  3589. this.context.allowYield = !0;
  3590. const i = this.parseFormalParameters();
  3591. this.context.allowYield = !1;
  3592. const r = this.parsePropertyMethod(i);
  3593. return this.context.allowYield = s, this.finalize(t, new FunctionExpression(null, i.params, r, !0, e));
  3594. }
  3595.  
  3596. isStartOfExpression() {
  3597. let e = !0;
  3598. const t = this.lookahead.value;
  3599. switch (this.lookahead.type) {
  3600. case 7:
  3601. e = t === '[' || t === '(' || t === '{' || t === '+' || t === '-' || t === '!' || t === '~' || t === '++' || t === '--' || t === '/' || t === '/=';
  3602. break;
  3603. case 4:
  3604. e = t === 'class' || t === 'delete' || t === 'function' || t === 'let' || t === 'new' || t === 'super' || t === 'this' || t === 'typeof' || t === 'void' || t === 'yield';
  3605. }
  3606. return e;
  3607. }
  3608.  
  3609. parseYieldExpression() {
  3610. const e = this.createNode();
  3611. this.expectKeyword('yield');
  3612. let t = null;
  3613. let s = !1;
  3614. if (!this.hasLineTerminator) {
  3615. const e = this.context.allowYield;
  3616. this.context.allowYield = !1, s = this.match('*'), s ? (this.nextToken(), t = this.parseAssignmentExpression()) : this.isStartOfExpression() && (t = this.parseAssignmentExpression()), this.context.allowYield = e;
  3617. }
  3618. return this.finalize(e, new YieldExpression(t, s));
  3619. }
  3620.  
  3621. parseStaticBlock() {
  3622. const e = this.createNode();
  3623. this.expect('{');
  3624. const t = [];
  3625. for (; !this.match('}');) t.push(this.parseStatementListItem());
  3626. return this.expect('}'), this.finalize(e, new StaticBlock(t));
  3627. }
  3628.  
  3629. parseDecorator() {
  3630. const e = this.createNode();
  3631. this.expect('@');
  3632. const t = this.context.strict;
  3633. const s = this.context.allowYield;
  3634. const i = this.context.isAsync;
  3635. this.context.strict = !1, this.context.allowYield = !0, this.context.isAsync = !1;
  3636. const r = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  3637. 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));
  3638. }
  3639.  
  3640. parseDecorators() {
  3641. let e = null;
  3642. for (; this.match('@');) e == null && (e = []), e.push(this.parseDecorator());
  3643. return e;
  3644. }
  3645.  
  3646. parseClassElement(e) {
  3647. let t = this.lookahead;
  3648. const s = this.createNode();
  3649. const i = this.context.inConstructor;
  3650. let r = '';
  3651. let n = null;
  3652. let a = null;
  3653. let o = !1;
  3654. let u = !1;
  3655. let h = !1;
  3656. let c = !1;
  3657. let l = !1;
  3658. let p = !1;
  3659. const m = this.parseDecorators();
  3660. if (m && (t = this.lookahead), this.match('*')) this.nextToken();
  3661. else {
  3662. o = this.match('['), this.match('#') && (p = !0, this.nextToken(), t = this.lookahead), n = this.parseObjectPropertyKey(p);
  3663. const e = n;
  3664. 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();
  3665. if (t.type === 3 && !this.hasLineTerminator && t.value === 'async') {
  3666. const e = this.lookahead.value;
  3667. 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));
  3668. }
  3669. }
  3670. t.type === 3 && t.value === 'constructor' && p && this.tolerateUnexpectedToken(t, Messages.ConstructorIsPrivate);
  3671. const d = this.qualifiedPropertyName(this.lookahead);
  3672. 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('(')) {
  3673. const e = this.context.inClassConstructor;
  3674. this.context.inClassConstructor = t.value === 'constructor', r = 'init', a = c ? this.parsePropertyMethodAsyncFunction(l) : this.parsePropertyMethodFunction(l), this.context.inClassConstructor = e, u = !0;
  3675. }
  3676. 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));
  3677. }
  3678.  
  3679. parseClassElementList() {
  3680. const e = [];
  3681. const t = {
  3682. value: !1
  3683. };
  3684. for (this.expect('{'); !this.match('}');) this.match(';') ? this.nextToken() : e.push(this.parseClassElement(t));
  3685. return this.expect('}'), e;
  3686. }
  3687.  
  3688. parseClassBody() {
  3689. const e = this.createNode();
  3690. const t = this.parseClassElementList();
  3691. return this.finalize(e, new ClassBody(t));
  3692. }
  3693.  
  3694. parseClassDeclaration(e) {
  3695. const t = this.createNode();
  3696. const s = this.context.strict;
  3697. const i = this.context.allowSuper;
  3698. this.context.strict = !0, this.expectKeyword('class');
  3699. const r = e && this.lookahead.type !== 3 ? null : this.parseVariableIdentifier();
  3700. let n = null;
  3701. this.matchKeyword('extends') && (this.nextToken(), n = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall), this.context.allowSuper = !0);
  3702. const a = this.parseClassBody();
  3703. return this.context.allowSuper = i, this.context.strict = s, this.finalize(t, new ClassDeclaration(r, n, a, this.context.decorators));
  3704. }
  3705.  
  3706. parseClassExpression() {
  3707. const e = this.createNode();
  3708. const t = this.context.strict;
  3709. this.context.strict = !0, this.expectKeyword('class');
  3710. const s = this.lookahead.type === 3 ? this.parseVariableIdentifier() : null;
  3711. let i = null;
  3712. this.matchKeyword('extends') && (this.nextToken(), i = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall), this.context.allowSuper = !0);
  3713. const r = this.parseClassBody();
  3714. return this.context.strict = t, this.finalize(e, new ClassExpression(s, i, r, this.context.decorators));
  3715. }
  3716.  
  3717. parseModule() {
  3718. this.context.strict = !0, this.context.isModule = !0, this.scanner.isModule = !0;
  3719. const e = this.createNode();
  3720. const t = this.parseDirectivePrologues();
  3721. for (; this.lookahead.type !== 2;) t.push(this.parseStatementListItem());
  3722. return this.finalize(e, new Module(t));
  3723. }
  3724.  
  3725. parseScript() {
  3726. const e = this.createNode();
  3727. const t = this.parseDirectivePrologues();
  3728. for (; this.lookahead.type !== 2;) t.push(this.parseStatementListItem());
  3729. return this.finalize(e, new Script(t));
  3730. }
  3731.  
  3732. parseImportAttributes() {
  3733. if (this.lookahead.value === 'assert') {
  3734. this.nextToken(), this.expect('{');
  3735. const e = [];
  3736. for (; !this.match('}');) e.push(this.parseImportAttribute()), this.match('}') || this.expectCommaSeparator();
  3737. return this.expect('}'), e;
  3738. }
  3739. return null;
  3740. }
  3741.  
  3742. parseImportAttribute() {
  3743. const e = this.createNode();
  3744. this.lookahead.type !== 3 && this.throwUnexpectedToken(this.nextToken());
  3745. const t = this.parseIdentifierName();
  3746. this.match(':') || this.throwUnexpectedToken(this.nextToken()), this.nextToken();
  3747. const s = this.nextToken();
  3748. const i = this.getTokenRaw(s);
  3749. const r = this.finalize(e, new Literal(s.value, i));
  3750. return this.finalize(e, new ImportAttribute(t, r));
  3751. }
  3752.  
  3753. parseModuleSpecifier() {
  3754. const e = this.createNode();
  3755. this.lookahead.type !== 8 && this.throwError(Messages.InvalidModuleSpecifier);
  3756. const t = this.nextToken();
  3757. const s = this.getTokenRaw(t);
  3758. return Character.isStringWellFormedUnicode(t.value) || this.throwError(Messages.InvalidModuleSpecifier), this.finalize(e, new Literal(t.value, s));
  3759. }
  3760.  
  3761. parseImportSpecifier() {
  3762. const e = this.createNode();
  3763. let t; let
  3764. s;
  3765. 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));
  3766. }
  3767.  
  3768. parseNamedImports() {
  3769. this.expect('{');
  3770. const e = [];
  3771. for (; !this.match('}');) e.push(this.parseImportSpecifier()), this.match('}') || this.expect(',');
  3772. return this.expect('}'), e;
  3773. }
  3774.  
  3775. parseImportDefaultSpecifier() {
  3776. const e = this.createNode();
  3777. const t = this.parseIdentifierName();
  3778. return this.finalize(e, new ImportDefaultSpecifier(t));
  3779. }
  3780.  
  3781. parseImportNamespaceSpecifier() {
  3782. const e = this.createNode();
  3783. this.expect('*'), this.matchContextualKeyword('as') || this.throwError(Messages.NoAsAfterImportNamespace), this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken();
  3784. const t = this.parseIdentifierName();
  3785. return this.finalize(e, new ImportNamespaceSpecifier(t));
  3786. }
  3787.  
  3788. parseImportDeclaration() {
  3789. this.context.inFunctionBody && this.throwError(Messages.IllegalImportDeclaration);
  3790. const e = this.createNode();
  3791. let t;
  3792. this.expectKeyword('import');
  3793. let s = [];
  3794. if (this.lookahead.type === 8) t = this.parseModuleSpecifier();
  3795. else {
  3796. 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')) {
  3797. const e = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
  3798. this.throwError(e, this.lookahead.value);
  3799. }
  3800. this.nextToken(), t = this.parseModuleSpecifier();
  3801. }
  3802. const i = this.parseImportAttributes();
  3803. return this.consumeSemicolon(), this.finalize(e, new ImportDeclaration(s, t, i));
  3804. }
  3805.  
  3806. parseExportSpecifier() {
  3807. const e = this.createNode();
  3808. const t = this.lookahead.type == 8 ? this.parseModuleSpecifier() : this.parseIdentifierName();
  3809. let s = t;
  3810. 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));
  3811. }
  3812.  
  3813. parseExportDeclaration() {
  3814. this.context.inFunctionBody && this.throwError(Messages.IllegalExportDeclaration);
  3815. const e = this.createNode();
  3816. let t;
  3817. if (this.expectKeyword('export'), this.matchKeyword('default')) {
  3818. if (this.nextToken(), this.matchKeyword('function')) {
  3819. const s = this.parseFunctionDeclaration(!0);
  3820. t = this.finalize(e, new ExportDefaultDeclaration(s));
  3821. } else if (this.matchKeyword('class')) {
  3822. const s = this.parseClassDeclaration(!0);
  3823. t = this.finalize(e, new ExportDefaultDeclaration(s));
  3824. } else if (this.matchContextualKeyword('async')) {
  3825. const s = this.matchAsyncFunction() ? this.parseFunctionDeclaration(!0) : this.parseAssignmentExpression();
  3826. t = this.finalize(e, new ExportDefaultDeclaration(s));
  3827. } else {
  3828. this.matchContextualKeyword('from') && this.throwError(Messages.UnexpectedToken, this.lookahead.value);
  3829. const s = this.match('{') ? this.parseObjectInitializer() : this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
  3830. this.consumeSemicolon(), t = this.finalize(e, new ExportDefaultDeclaration(s));
  3831. }
  3832. } else if (this.match('*')) {
  3833. this.nextToken();
  3834. let s = null;
  3835. 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')) {
  3836. const e = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
  3837. this.throwError(e, this.lookahead.value);
  3838. }
  3839. this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken();
  3840. const i = this.parseModuleSpecifier();
  3841. const r = this.parseImportAttributes();
  3842. this.consumeSemicolon(), t = this.finalize(e, new ExportAllDeclaration(i, s, r));
  3843. } else if (this.lookahead.type === 4) {
  3844. let s;
  3845. switch (this.lookahead.value) {
  3846. case 'let':
  3847. case 'const':
  3848. s = this.parseLexicalDeclaration({
  3849. inFor: !1
  3850. });
  3851. break;
  3852. case 'var':
  3853. case 'class':
  3854. case 'function':
  3855. s = this.parseStatementListItem();
  3856. break;
  3857. default:
  3858. this.throwUnexpectedToken(this.lookahead);
  3859. }
  3860. t = this.finalize(e, new ExportNamedDeclaration(s, [], null, null));
  3861. } else if (this.matchAsyncFunction()) {
  3862. const s = this.parseFunctionDeclaration();
  3863. t = this.finalize(e, new ExportNamedDeclaration(s, [], null, null));
  3864. } else {
  3865. const s = [];
  3866. let i = null;
  3867. let r = !1;
  3868. let n = null;
  3869. for (this.expect('{'); !this.match('}');) r = r || this.matchKeyword('default'), s.push(this.parseExportSpecifier()), this.match('}') || this.expect(',');
  3870. if (this.expect('}'), this.matchContextualKeyword('from')) this.lookahead.escaped && this.throwError(Messages.NoAsAndFromEscapeSequences), this.nextToken(), i = this.parseModuleSpecifier(), n = this.parseImportAttributes(), this.consumeSemicolon();
  3871. else if (r) {
  3872. const e = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause;
  3873. this.throwError(e, this.lookahead.value);
  3874. } else n = this.parseImportAttributes(), this.consumeSemicolon();
  3875. t = this.finalize(e, new ExportNamedDeclaration(null, s, i, n));
  3876. }
  3877. return t;
  3878. }
  3879. };
  3880. const XHTMLEntities = {
  3881. quot: '"',
  3882. amp: '&',
  3883. apos: "'",
  3884. gt: '>',
  3885. nbsp: ' ',
  3886. iexcl: '¡',
  3887. cent: '¢',
  3888. pound: '£',
  3889. curren: '¤',
  3890. yen: '¥',
  3891. brvbar: '¦',
  3892. sect: '§',
  3893. uml: '¨',
  3894. copy: '©',
  3895. ordf: 'ª',
  3896. laquo: '«',
  3897. not: '¬',
  3898. shy: '­',
  3899. reg: '®',
  3900. macr: '¯',
  3901. deg: '°',
  3902. plusmn: '±',
  3903. sup2: '²',
  3904. sup3: '³',
  3905. acute: '´',
  3906. micro: 'µ',
  3907. para: '¶',
  3908. middot: '·',
  3909. cedil: '¸',
  3910. sup1: '¹',
  3911. ordm: 'º',
  3912. raquo: '»',
  3913. frac14: '¼',
  3914. frac12: '½',
  3915. frac34: '¾',
  3916. iquest: '¿',
  3917. Agrave: 'À',
  3918. Aacute: 'Á',
  3919. Acirc: 'Â',
  3920. Atilde: 'Ã',
  3921. Auml: 'Ä',
  3922. Aring: 'Å',
  3923. AElig: 'Æ',
  3924. Ccedil: 'Ç',
  3925. Egrave: 'È',
  3926. Eacute: 'É',
  3927. Ecirc: 'Ê',
  3928. Euml: 'Ë',
  3929. Igrave: 'Ì',
  3930. Iacute: 'Í',
  3931. Icirc: 'Î',
  3932. Iuml: 'Ï',
  3933. ETH: 'Ð',
  3934. Ntilde: 'Ñ',
  3935. Ograve: 'Ò',
  3936. Oacute: 'Ó',
  3937. Ocirc: 'Ô',
  3938. Otilde: 'Õ',
  3939. Ouml: 'Ö',
  3940. times: '×',
  3941. Oslash: 'Ø',
  3942. Ugrave: 'Ù',
  3943. Uacute: 'Ú',
  3944. Ucirc: 'Û',
  3945. Uuml: 'Ü',
  3946. Yacute: 'Ý',
  3947. THORN: 'Þ',
  3948. szlig: 'ß',
  3949. agrave: 'à',
  3950. aacute: 'á',
  3951. acirc: 'â',
  3952. atilde: 'ã',
  3953. auml: 'ä',
  3954. aring: 'å',
  3955. aelig: 'æ',
  3956. ccedil: 'ç',
  3957. egrave: 'è',
  3958. eacute: 'é',
  3959. ecirc: 'ê',
  3960. euml: 'ë',
  3961. igrave: 'ì',
  3962. iacute: 'í',
  3963. icirc: 'î',
  3964. iuml: 'ï',
  3965. eth: 'ð',
  3966. ntilde: 'ñ',
  3967. ograve: 'ò',
  3968. oacute: 'ó',
  3969. ocirc: 'ô',
  3970. otilde: 'õ',
  3971. ouml: 'ö',
  3972. divide: '÷',
  3973. oslash: 'ø',
  3974. ugrave: 'ù',
  3975. uacute: 'ú',
  3976. ucirc: 'û',
  3977. uuml: 'ü',
  3978. yacute: 'ý',
  3979. thorn: 'þ',
  3980. yuml: 'ÿ',
  3981. OElig: 'Œ',
  3982. oelig: 'œ',
  3983. Scaron: 'Š',
  3984. scaron: 'š',
  3985. Yuml: 'Ÿ',
  3986. fnof: 'ƒ',
  3987. circ: 'ˆ',
  3988. tilde: '˜',
  3989. Alpha: 'Α',
  3990. Beta: 'Β',
  3991. Gamma: 'Γ',
  3992. Delta: 'Δ',
  3993. Epsilon: 'Ε',
  3994. Zeta: 'Ζ',
  3995. Eta: 'Η',
  3996. Theta: 'Θ',
  3997. Iota: 'Ι',
  3998. Kappa: 'Κ',
  3999. Lambda: 'Λ',
  4000. Mu: 'Μ',
  4001. Nu: 'Ν',
  4002. Xi: 'Ξ',
  4003. Omicron: 'Ο',
  4004. Pi: 'Π',
  4005. Rho: 'Ρ',
  4006. Sigma: 'Σ',
  4007. Tau: 'Τ',
  4008. Upsilon: 'Υ',
  4009. Phi: 'Φ',
  4010. Chi: 'Χ',
  4011. Psi: 'Ψ',
  4012. Omega: 'Ω',
  4013. alpha: 'α',
  4014. beta: 'β',
  4015. gamma: 'γ',
  4016. delta: 'δ',
  4017. epsilon: 'ε',
  4018. zeta: 'ζ',
  4019. eta: 'η',
  4020. theta: 'θ',
  4021. iota: 'ι',
  4022. kappa: 'κ',
  4023. lambda: 'λ',
  4024. mu: 'μ',
  4025. nu: 'ν',
  4026. xi: 'ξ',
  4027. omicron: 'ο',
  4028. pi: 'π',
  4029. rho: 'ρ',
  4030. sigmaf: 'ς',
  4031. sigma: 'σ',
  4032. tau: 'τ',
  4033. upsilon: 'υ',
  4034. phi: 'φ',
  4035. chi: 'χ',
  4036. psi: 'ψ',
  4037. omega: 'ω',
  4038. thetasym: 'ϑ',
  4039. upsih: 'ϒ',
  4040. piv: 'ϖ',
  4041. ensp: ' ',
  4042. emsp: ' ',
  4043. thinsp: ' ',
  4044. zwnj: '‌',
  4045. zwj: '‍',
  4046. lrm: '‎',
  4047. rlm: '‏',
  4048. ndash: '–',
  4049. mdash: '—',
  4050. lsquo: '‘',
  4051. rsquo: '’',
  4052. sbquo: '‚',
  4053. ldquo: '“',
  4054. rdquo: '”',
  4055. bdquo: '„',
  4056. dagger: '†',
  4057. Dagger: '‡',
  4058. bull: '•',
  4059. hellip: '…',
  4060. permil: '‰',
  4061. prime: '′',
  4062. Prime: '″',
  4063. lsaquo: '‹',
  4064. rsaquo: '›',
  4065. oline: '‾',
  4066. frasl: '⁄',
  4067. euro: '€',
  4068. image: 'ℑ',
  4069. weierp: '℘',
  4070. real: 'ℜ',
  4071. trade: '™',
  4072. alefsym: 'ℵ',
  4073. larr: '←',
  4074. uarr: '↑',
  4075. rarr: '→',
  4076. darr: '↓',
  4077. harr: '↔',
  4078. crarr: '↵',
  4079. lArr: '⇐',
  4080. uArr: '⇑',
  4081. rArr: '⇒',
  4082. dArr: '⇓',
  4083. hArr: '⇔',
  4084. forall: '∀',
  4085. part: '∂',
  4086. exist: '∃',
  4087. empty: '∅',
  4088. nabla: '∇',
  4089. isin: '∈',
  4090. notin: '∉',
  4091. ni: '∋',
  4092. prod: '∏',
  4093. sum: '∑',
  4094. minus: '−',
  4095. lowast: '∗',
  4096. radic: '√',
  4097. prop: '∝',
  4098. infin: '∞',
  4099. ang: '∠',
  4100. and: '∧',
  4101. or: '∨',
  4102. cap: '∩',
  4103. cup: '∪',
  4104. int: '∫',
  4105. there4: '∴',
  4106. sim: '∼',
  4107. cong: '≅',
  4108. asymp: '≈',
  4109. ne: '≠',
  4110. equiv: '≡',
  4111. le: '≤',
  4112. ge: '≥',
  4113. sub: '⊂',
  4114. sup: '⊃',
  4115. nsub: '⊄',
  4116. sube: '⊆',
  4117. supe: '⊇',
  4118. oplus: '⊕',
  4119. otimes: '⊗',
  4120. perp: '⊥',
  4121. sdot: '⋅',
  4122. lceil: '⌈',
  4123. rceil: '⌉',
  4124. lfloor: '⌊',
  4125. rfloor: '⌋',
  4126. loz: '◊',
  4127. spades: '♠',
  4128. clubs: '♣',
  4129. hearts: '♥',
  4130. diams: '♦',
  4131. lang: '⟨',
  4132. rang: '⟩'
  4133. };
  4134.  
  4135. function getQualifiedElementName(e) {
  4136. let t;
  4137. switch (e.type) {
  4138. case 'JSXIdentifier':
  4139. t = e.name;
  4140. break;
  4141. case 'JSXNamespacedName':
  4142. const s = e;
  4143. t = `${getQualifiedElementName(s.namespace)}:${getQualifiedElementName(s.name)}`;
  4144. break;
  4145. case 'JSXMemberExpression':
  4146. const i = e;
  4147. t = `${getQualifiedElementName(i.object)}.${getQualifiedElementName(i.property)}`;
  4148. }
  4149. return t;
  4150. }
  4151. TokenName[100] = 'JSXIdentifier', TokenName[101] = 'JSXText';
  4152. const JSXParser = class extends Parser {
  4153. constructor(e, t, s) {
  4154. super(e, t, s);
  4155. }
  4156.  
  4157. parsePrimaryExpression() {
  4158. return this.match('<') ? this.parseJSXRoot() : super.parsePrimaryExpression();
  4159. }
  4160.  
  4161. startJSX() {
  4162. this.scanner.index = this.startMarker.index, this.scanner.lineNumber = this.startMarker.line, this.scanner.lineStart = this.startMarker.index - this.startMarker.column;
  4163. }
  4164.  
  4165. finishJSX() {
  4166. this.nextToken();
  4167. }
  4168.  
  4169. reenterJSX() {
  4170. this.startJSX(), this.expectJSX('}'), this.config.tokens && this.tokens.pop();
  4171. }
  4172.  
  4173. createJSXNode() {
  4174. return this.collectComments(), {
  4175. index: this.scanner.index,
  4176. line: this.scanner.lineNumber,
  4177. column: this.scanner.index - this.scanner.lineStart
  4178. };
  4179. }
  4180.  
  4181. createJSXChildNode() {
  4182. return {
  4183. index: this.scanner.index,
  4184. line: this.scanner.lineNumber,
  4185. column: this.scanner.index - this.scanner.lineStart
  4186. };
  4187. }
  4188.  
  4189. scanXHTMLEntity(e) {
  4190. let t = '&';
  4191. let s = !0;
  4192. let i = !1;
  4193. let r = !1;
  4194. let n = !1;
  4195. for (; !this.scanner.eof() && s && !i;) {
  4196. const a = this.scanner.source[this.scanner.index];
  4197. if (a === e) break;
  4198. if (i = a === ';', t += a, ++this.scanner.index, !i) {
  4199. switch (t.length) {
  4200. case 2:
  4201. r = a === '#';
  4202. break;
  4203. case 3:
  4204. r && (n = a === 'x', s = n || Character.isDecimalDigit(a.charCodeAt(0)), r = r && !n);
  4205. break;
  4206. default:
  4207. s = s && !(r && !Character.isDecimalDigit(a.charCodeAt(0))), s = s && !(n && !Character.isHexDigit(a.charCodeAt(0)));
  4208. }
  4209. }
  4210. }
  4211. if (s && i && t.length > 2) {
  4212. const e = t.substr(1, t.length - 2);
  4213. 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]);
  4214. }
  4215. return t;
  4216. }
  4217.  
  4218. lexJSX() {
  4219. const e = this.scanner.source.charCodeAt(this.scanner.index);
  4220. if (e === 60 || e === 62 || e === 47 || e === 58 || e === 61 || e === 123 || e === 125) {
  4221. return {
  4222. type: 7,
  4223. value: this.scanner.source[this.scanner.index++],
  4224. lineNumber: this.scanner.lineNumber,
  4225. lineStart: this.scanner.lineStart,
  4226. start: this.scanner.index - 1,
  4227. end: this.scanner.index
  4228. };
  4229. }
  4230. if (e === 34 || e === 39) {
  4231. const e = this.scanner.index;
  4232. const t = this.scanner.source[this.scanner.index++];
  4233. let s = '';
  4234. for (; !this.scanner.eof();) {
  4235. const e = this.scanner.source[this.scanner.index++];
  4236. if (e === t) break;
  4237. s += e === '&' ? this.scanXHTMLEntity(t) : e;
  4238. }
  4239. return {
  4240. type: 8,
  4241. value: s,
  4242. lineNumber: this.scanner.lineNumber,
  4243. lineStart: this.scanner.lineStart,
  4244. start: e,
  4245. end: this.scanner.index
  4246. };
  4247. }
  4248. if (e === 46) {
  4249. const e = this.scanner.source.charCodeAt(this.scanner.index + 1);
  4250. const t = this.scanner.source.charCodeAt(this.scanner.index + 2);
  4251. const s = e === 46 && t === 46 ? '...' : '.';
  4252. const i = this.scanner.index;
  4253. return this.scanner.index += s.length, {
  4254. type: 7,
  4255. value: s,
  4256. lineNumber: this.scanner.lineNumber,
  4257. lineStart: this.scanner.lineStart,
  4258. start: i,
  4259. end: this.scanner.index
  4260. };
  4261. }
  4262. if (e === 96) {
  4263. return {
  4264. type: 10,
  4265. value: '',
  4266. lineNumber: this.scanner.lineNumber,
  4267. lineStart: this.scanner.lineStart,
  4268. start: this.scanner.index,
  4269. end: this.scanner.index
  4270. };
  4271. }
  4272. if (Character.isIdentifierStart(e) && e !== 92) {
  4273. const e = this.scanner.index;
  4274. for (++this.scanner.index; !this.scanner.eof();) {
  4275. const e = this.scanner.source.charCodeAt(this.scanner.index);
  4276. if (Character.isIdentifierPart(e) && e !== 92) ++this.scanner.index;
  4277. else {
  4278. if (e !== 45) break;
  4279. ++this.scanner.index;
  4280. }
  4281. }
  4282. return {
  4283. type: 100,
  4284. value: this.scanner.source.slice(e, this.scanner.index),
  4285. lineNumber: this.scanner.lineNumber,
  4286. lineStart: this.scanner.lineStart,
  4287. start: e,
  4288. end: this.scanner.index
  4289. };
  4290. }
  4291. return this.scanner.lex();
  4292. }
  4293.  
  4294. nextJSXToken() {
  4295. this.collectComments(), this.startMarker.index = this.scanner.index, this.startMarker.line = this.scanner.lineNumber, this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  4296. const e = this.lexJSX();
  4297. 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;
  4298. }
  4299.  
  4300. nextJSXText() {
  4301. this.startMarker.index = this.scanner.index, this.startMarker.line = this.scanner.lineNumber, this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  4302. const e = this.scanner.index;
  4303. let t = '';
  4304. for (; !this.scanner.eof();) {
  4305. const e = this.scanner.source[this.scanner.index];
  4306. if (e === '{' || e === '<') break;
  4307. ++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);
  4308. }
  4309. this.lastMarker.index = this.scanner.index, this.lastMarker.line = this.scanner.lineNumber, this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  4310. const s = {
  4311. type: 101,
  4312. value: t,
  4313. lineNumber: this.scanner.lineNumber,
  4314. lineStart: this.scanner.lineStart,
  4315. start: e,
  4316. end: this.scanner.index
  4317. };
  4318. return t.length > 0 && this.config.tokens && this.tokens.push(this.convertToken(s)), s;
  4319. }
  4320.  
  4321. peekJSXToken() {
  4322. const e = this.scanner.saveState();
  4323. this.scanner.scanComments();
  4324. const t = this.lexJSX();
  4325. return this.scanner.restoreState(e), t;
  4326. }
  4327.  
  4328. expectJSX(e) {
  4329. const t = this.nextJSXToken();
  4330. t.type === 7 && t.value === e || this.throwUnexpectedToken(t);
  4331. }
  4332.  
  4333. matchJSX(e) {
  4334. const t = this.peekJSXToken();
  4335. return t.type === 7 && t.value === e;
  4336. }
  4337.  
  4338. parseJSXIdentifier() {
  4339. const e = this.createJSXNode();
  4340. const t = this.nextJSXToken();
  4341. return t.type !== 100 && this.throwUnexpectedToken(t), this.finalize(e, new JSXIdentifier(t.value));
  4342. }
  4343.  
  4344. parseJSXElementName() {
  4345. const e = this.createJSXNode();
  4346. let t = this.parseJSXIdentifier();
  4347. if (this.matchJSX(':')) {
  4348. const s = t;
  4349. this.expectJSX(':');
  4350. const i = this.parseJSXIdentifier();
  4351. t = this.finalize(e, new JSXNamespacedName(s, i));
  4352. } else if (this.matchJSX('.')) {
  4353. for (; this.matchJSX('.');) {
  4354. const s = t;
  4355. this.expectJSX('.');
  4356. const i = this.parseJSXIdentifier();
  4357. t = this.finalize(e, new JSXMemberExpression(s, i));
  4358. }
  4359. }
  4360. return t;
  4361. }
  4362.  
  4363. parseJSXAttributeName() {
  4364. const e = this.createJSXNode();
  4365. let t;
  4366. const s = this.parseJSXIdentifier();
  4367. if (this.matchJSX(':')) {
  4368. const i = s;
  4369. this.expectJSX(':');
  4370. const r = this.parseJSXIdentifier();
  4371. t = this.finalize(e, new JSXNamespacedName(i, r));
  4372. } else t = s;
  4373. return t;
  4374. }
  4375.  
  4376. parseJSXStringLiteralAttribute() {
  4377. const e = this.createJSXNode();
  4378. const t = this.nextJSXToken();
  4379. t.type !== 8 && this.throwUnexpectedToken(t);
  4380. const s = this.getTokenRaw(t);
  4381. return this.finalize(e, new Literal(t.value, s));
  4382. }
  4383.  
  4384. parseJSXExpressionAttribute() {
  4385. const e = this.createJSXNode();
  4386. this.expectJSX('{'), this.finishJSX(), this.match('}') && this.tolerateError('JSX attributes must only be assigned a non-empty expression');
  4387. const t = this.parseAssignmentExpression();
  4388. return this.reenterJSX(), this.finalize(e, new JSXExpressionContainer(t));
  4389. }
  4390.  
  4391. parseJSXAttributeValue() {
  4392. return this.matchJSX('{') ? this.parseJSXExpressionAttribute() : this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
  4393. }
  4394.  
  4395. parseJSXNameValueAttribute() {
  4396. const e = this.createJSXNode();
  4397. const t = this.parseJSXAttributeName();
  4398. let s = null;
  4399. return this.matchJSX('=') && (this.expectJSX('='), s = this.parseJSXAttributeValue()), this.finalize(e, new JSXAttribute(t, s));
  4400. }
  4401.  
  4402. parseJSXSpreadAttribute() {
  4403. const e = this.createJSXNode();
  4404. this.expectJSX('{'), this.expectJSX('...'), this.finishJSX();
  4405. const t = this.parseAssignmentExpression();
  4406. return this.reenterJSX(), this.finalize(e, new JSXSpreadAttribute(t));
  4407. }
  4408.  
  4409. parseJSXAttributes() {
  4410. const e = [];
  4411. for (; !this.matchJSX('/') && !this.matchJSX('>');) {
  4412. const t = this.matchJSX('{') ? this.parseJSXSpreadAttribute() : this.parseJSXNameValueAttribute();
  4413. e.push(t);
  4414. }
  4415. return e;
  4416. }
  4417.  
  4418. parseJSXOpeningElement() {
  4419. const e = this.createJSXNode();
  4420. if (this.expectJSX('<'), this.matchJSX('>')) return this.expectJSX('>'), this.finalize(e, new JSXOpeningFragment(!1));
  4421. const t = this.parseJSXElementName();
  4422. const s = this.parseJSXAttributes();
  4423. const i = this.matchJSX('/');
  4424. return i && this.expectJSX('/'), this.expectJSX('>'), this.finalize(e, new JSXOpeningElement(t, i, s));
  4425. }
  4426.  
  4427. parseJSXBoundaryElement() {
  4428. const e = this.createJSXNode();
  4429. if (this.expectJSX('<'), this.matchJSX('/')) {
  4430. if (this.expectJSX('/'), this.matchJSX('>')) return this.expectJSX('>'), this.finalize(e, new JSXClosingFragment());
  4431. const t = this.parseJSXElementName();
  4432. return this.expectJSX('>'), this.finalize(e, new JSXClosingElement(t));
  4433. }
  4434. const t = this.parseJSXElementName();
  4435. const s = this.parseJSXAttributes();
  4436. const i = this.matchJSX('/');
  4437. return i && this.expectJSX('/'), this.expectJSX('>'), this.finalize(e, new JSXOpeningElement(t, i, s));
  4438. }
  4439.  
  4440. parseJSXEmptyExpression() {
  4441. const e = this.createJSXChildNode();
  4442. 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());
  4443. }
  4444.  
  4445. parseJSXExpressionContainer() {
  4446. const e = this.createJSXNode();
  4447. let t;
  4448. return this.expectJSX('{'), this.matchJSX('}') ? (t = this.parseJSXEmptyExpression(), this.expectJSX('}')) : (this.finishJSX(), t = this.parseAssignmentExpression(), this.reenterJSX()), this.finalize(e, new JSXExpressionContainer(t));
  4449. }
  4450.  
  4451. parseJSXChildren() {
  4452. const e = [];
  4453. for (; !this.scanner.eof();) {
  4454. const t = this.createJSXChildNode();
  4455. const s = this.nextJSXText();
  4456. if (s.start < s.end) {
  4457. const i = this.getTokenRaw(s);
  4458. const r = this.finalize(t, new JSXText(s.value, i));
  4459. e.push(r);
  4460. }
  4461. if (this.scanner.source[this.scanner.index] !== '{') break;
  4462. {
  4463. const t = this.parseJSXExpressionContainer();
  4464. e.push(t);
  4465. }
  4466. }
  4467. return e;
  4468. }
  4469.  
  4470. parseComplexJSXElement(e) {
  4471. const t = [];
  4472. for (; !this.scanner.eof();) {
  4473. e.children = e.children.concat(this.parseJSXChildren());
  4474. const s = this.createJSXChildNode();
  4475. const i = this.parseJSXBoundaryElement();
  4476. if (i.type === 'JSXOpeningElement') {
  4477. const r = i;
  4478. if (r.selfClosing) {
  4479. const t = this.finalize(s, new JSXElement(r, [], null));
  4480. e.children.push(t);
  4481. } else {
  4482. t.push(e), e = {
  4483. node: s,
  4484. opening: r,
  4485. closing: null,
  4486. children: []
  4487. };
  4488. }
  4489. }
  4490. if (i.type === 'JSXClosingElement') {
  4491. e.closing = i;
  4492. const s = getQualifiedElementName(e.opening.name);
  4493. if (s !== getQualifiedElementName(e.closing.name) && this.tolerateError('Expected corresponding JSX closing tag for %0', s), !(t.length > 0)) break;
  4494. {
  4495. const s = this.finalize(e.node, new JSXElement(e.opening, e.children, e.closing));
  4496. (e = t[t.length - 1]).children.push(s), t.pop();
  4497. }
  4498. }
  4499. if (i.type === 'JSXClosingFragment') {
  4500. if (e.closing = i, e.opening.type === 'JSXOpeningFragment') break;
  4501. this.tolerateError('Expected corresponding JSX closing tag for jsx fragment');
  4502. }
  4503. }
  4504. return e;
  4505. }
  4506.  
  4507. parseJSXElement() {
  4508. const e = this.createJSXNode();
  4509. const t = this.parseJSXOpeningElement();
  4510. let s = [];
  4511. let i = null;
  4512. if (!t.selfClosing) {
  4513. const r = this.parseComplexJSXElement({
  4514. node: e,
  4515. opening: t,
  4516. closing: i,
  4517. children: s
  4518. });
  4519. s = r.children, i = r.closing;
  4520. }
  4521. return this.finalize(e, new JSXElement(t, s, i));
  4522. }
  4523.  
  4524. parseJSXRoot() {
  4525. this.config.tokens && this.tokens.pop(), this.startJSX();
  4526. const e = this.parseJSXElement();
  4527. return this.finishJSX(), e;
  4528. }
  4529.  
  4530. isStartOfExpression() {
  4531. return super.isStartOfExpression() || this.match('<');
  4532. }
  4533. };
  4534. const beforeFunctionExpressionTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new', 'return', 'case', 'delete', 'throw', 'void', '=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=', '&=', '|=', '^=', ',', '+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&', '|', '^', '!', '~', '&&', '||', '??', '?', ':', '===', '==', '>=', '<=', '<', '>', '!=', '!=='];
  4535. const Reader = class {
  4536. values;
  4537. curly;
  4538. paren;
  4539. constructor() {
  4540. this.values = [], this.curly = this.paren = -1;
  4541. }
  4542.  
  4543. beforeFunctionExpression(e) {
  4544. return beforeFunctionExpressionTokens.includes(e);
  4545. }
  4546.  
  4547. isRegexStart() {
  4548. const e = this.values[this.values.length - 1];
  4549. let t = e !== null;
  4550. switch (e) {
  4551. case 'this':
  4552. case ']':
  4553. t = !1;
  4554. break;
  4555. case ')':
  4556. const e = this.values[this.paren - 1];
  4557. t = e === 'if' || e === 'while' || e === 'for' || e === 'with';
  4558. break;
  4559. case '}':
  4560. if (t = !0, this.values[this.curly - 3] === 'function') {
  4561. const e = this.values[this.curly - 4];
  4562. t = !!e && !this.beforeFunctionExpression(e);
  4563. } else if (this.values[this.curly - 4] === 'function') {
  4564. const e = this.values[this.curly - 5];
  4565. t = !e || !this.beforeFunctionExpression(e);
  4566. }
  4567. }
  4568. return t;
  4569. }
  4570.  
  4571. push(e) {
  4572. 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);
  4573. }
  4574. };
  4575. const Tokenizer = class {
  4576. errorHandler;
  4577. scanner;
  4578. trackRange;
  4579. trackLoc;
  4580. buffer;
  4581. reader;
  4582. constructor(e, t) {
  4583. 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();
  4584. }
  4585.  
  4586. errors() {
  4587. return this.errorHandler.errors;
  4588. }
  4589.  
  4590. getNextToken() {
  4591. if (this.buffer.length === 0) {
  4592. const e = this.scanner.scanComments();
  4593. if (this.scanner.trackComment) {
  4594. for (let t = 0; t < e.length; ++t) {
  4595. const s = e[t];
  4596. const i = this.scanner.source.slice(s.slice[0], s.slice[1]);
  4597. const r = {
  4598. type: s.multiLine ? 'BlockComment' : 'LineComment',
  4599. value: i
  4600. };
  4601. this.trackRange && (r.range = s.range), this.trackLoc && (r.loc = s.loc), this.buffer.push(r);
  4602. }
  4603. }
  4604. if (!this.scanner.eof()) {
  4605. let e;
  4606. this.trackLoc && (e = {
  4607. start: {
  4608. line: this.scanner.lineNumber,
  4609. column: this.scanner.index - this.scanner.lineStart
  4610. },
  4611. end: {}
  4612. });
  4613. let t;
  4614. if (this.scanner.source[this.scanner.index] === '/' && this.reader.isRegexStart()) {
  4615. const e = this.scanner.saveState();
  4616. try {
  4617. t = this.scanner.scanRegExp();
  4618. } catch (s) {
  4619. this.scanner.restoreState(e), t = this.scanner.lex();
  4620. }
  4621. } else t = this.scanner.lex();
  4622. this.reader.push(t);
  4623. const s = {
  4624. type: TokenName[t.type],
  4625. value: this.scanner.source.slice(t.start, t.end)
  4626. };
  4627. if (this.trackRange && (s.range = [t.start, t.end]), this.trackLoc && (e.end = {
  4628. line: this.scanner.lineNumber,
  4629. column: this.scanner.index - this.scanner.lineStart
  4630. }, s.loc = e), t.type === 9) {
  4631. const e = t.pattern;
  4632. const i = t.flags;
  4633. s.regex = {
  4634. pattern: e,
  4635. flags: i
  4636. };
  4637. }
  4638. this.buffer.push(s);
  4639. }
  4640. }
  4641. return this.buffer.shift();
  4642. }
  4643. };
  4644. const Visitor = class {
  4645. visit(e) {
  4646. if (e == null) return e;
  4647. switch (e.type) {
  4648. case 'AssignmentExpression':
  4649. return this.visitAssignmentExpression(e);
  4650. case 'AssignmentPattern':
  4651. return this.visitAssignmentPattern(e);
  4652. case 'ArrayExpression':
  4653. return this.visitArrayExpression(e);
  4654. case 'ArrayPattern':
  4655. return this.visitArrayPattern(e);
  4656. case 'ArrowFunctionExpression':
  4657. return this.visitArrowFunctionExpression(e);
  4658. case 'AwaitExpression':
  4659. return this.visitAwaitExpression(e);
  4660. case 'BlockStatement':
  4661. return this.visitBlockStatement(e);
  4662. case 'BinaryExpression':
  4663. return this.visitBinaryExpression(e);
  4664. case 'BreakStatement':
  4665. return this.visitBreakStatement(e);
  4666. case 'CallExpression':
  4667. return this.visitCallExpression(e);
  4668. case 'CatchClause':
  4669. return this.visitCatchClause(e);
  4670. case 'ChainExpression':
  4671. return this.visitChainExpression(e);
  4672. case 'ClassBody':
  4673. return this.visitClassBody(e);
  4674. case 'ClassDeclaration':
  4675. return this.visitClassDeclaration(e);
  4676. case 'ClassExpression':
  4677. return this.visitClassExpression(e);
  4678. case 'ConditionalExpression':
  4679. return this.visitConditionalExpression(e);
  4680. case 'ContinueStatement':
  4681. return this.visitContinueStatement(e);
  4682. case 'Decorator':
  4683. return this.visitDecorator(e);
  4684. case 'DoWhileStatement':
  4685. return this.visitDoWhileStatement(e);
  4686. case 'DebuggerStatement':
  4687. return this.visitDebuggerStatement(e);
  4688. case 'EmptyStatement':
  4689. return this.visitEmptyStatement(e);
  4690. case 'ExportAllDeclaration':
  4691. return this.visitExportAllDeclaration(e);
  4692. case 'ExportDefaultDeclaration':
  4693. return this.visitExportDefaultDeclaration(e);
  4694. case 'ExportNamedDeclaration':
  4695. return this.visitExportNamedDeclaration(e);
  4696. case 'ExportSpecifier':
  4697. return this.visitExportSpecifier(e);
  4698. case 'ExpressionStatement':
  4699. return this.visitExpressionStatement(e);
  4700. case 'ForStatement':
  4701. return this.visitForStatement(e);
  4702. case 'ForOfStatement':
  4703. return this.visitForOfStatement(e);
  4704. case 'ForInStatement':
  4705. return this.visitForInStatement(e);
  4706. case 'FunctionDeclaration':
  4707. return this.visitFunctionDeclaration(e);
  4708. case 'FunctionExpression':
  4709. return this.visitFunctionExpression(e);
  4710. case 'Identifier':
  4711. return this.visitIdentifier(e);
  4712. case 'IfStatement':
  4713. return this.visitIfStatement(e);
  4714. case 'ImportAttribute':
  4715. return this.visitImportAttribute(e);
  4716. case 'ImportExpression':
  4717. return this.visitImportExpression(e);
  4718. case 'ImportDeclaration':
  4719. return this.visitImportDeclaration(e);
  4720. case 'ImportDefaultSpecifier':
  4721. return this.visitImportDefaultSpecifier(e);
  4722. case 'ImportNamespaceSpecifier':
  4723. return this.visitImportNamespaceSpecifier(e);
  4724. case 'ImportSpecifier':
  4725. return this.visitImportSpecifier(e);
  4726. case 'Literal':
  4727. return this.visitLiteral(e);
  4728. case 'LabeledStatement':
  4729. return this.visitLabeledStatement(e);
  4730. case 'LogicalExpression':
  4731. return this.visitLogicalExpression(e);
  4732. case 'MemberExpression':
  4733. return this.visitMemberExpression(e);
  4734. case 'MetaProperty':
  4735. return this.visitMetaProperty(e);
  4736. case 'MethodDefinition':
  4737. return this.visitMethodDefinition(e);
  4738. case 'NewExpression':
  4739. return this.visitNewExpression(e);
  4740. case 'ObjectExpression':
  4741. return this.visitObjectExpression(e);
  4742. case 'ObjectPattern':
  4743. return this.visitObjectPattern(e);
  4744. case 'Program':
  4745. return this.visitProgram(e);
  4746. case 'Property':
  4747. return this.visitProperty(e);
  4748. case 'PrivateIdentifier':
  4749. return this.visitPrivateIdentifier(e);
  4750. case 'RestElement':
  4751. return this.visitRestElement(e);
  4752. case 'ReturnStatement':
  4753. return this.visitReturnStatement(e);
  4754. case 'SequenceExpression':
  4755. return this.visitSequenceExpression(e);
  4756. case 'SpreadElement':
  4757. return this.visitSpreadElement(e);
  4758. case 'StaticBlock':
  4759. return this.visitStaticBlock(e);
  4760. case 'Super':
  4761. return this.visitSuper(e);
  4762. case 'SwitchCase':
  4763. return this.visitSwitchCase(e);
  4764. case 'SwitchStatement':
  4765. return this.visitSwitchStatement(e);
  4766. case 'TaggedTemplateExpression':
  4767. return this.visitTaggedTemplateExpression(e);
  4768. case 'TemplateElement':
  4769. return this.visitTemplateElement(e);
  4770. case 'TemplateLiteral':
  4771. return this.visitTemplateLiteral(e);
  4772. case 'ThisExpression':
  4773. return this.visitThisExpression(e);
  4774. case 'ThrowStatement':
  4775. return this.visitThrowStatement(e);
  4776. case 'TryStatement':
  4777. return this.visitTryStatement(e);
  4778. case 'UnaryExpression':
  4779. return this.visitUnaryExpression(e);
  4780. case 'UpdateExpression':
  4781. return this.visitUpdateExpression(e);
  4782. case 'VariableDeclaration':
  4783. return this.visitVariableDeclaration(e);
  4784. case 'VariableDeclarator':
  4785. return this.visitVariableDeclarator(e);
  4786. case 'WhileStatement':
  4787. return this.visitWhileStatement(e);
  4788. case 'WithStatement':
  4789. return this.visitWithStatement(e);
  4790. case 'YieldExpression':
  4791. return this.visitYieldExpression(e);
  4792. }
  4793. }
  4794.  
  4795. visitNodeList(e) {
  4796. if (e == null) return e;
  4797. let t = null;
  4798. for (let s = 0, i = e.length; s < i; s++) {
  4799. const i = this.visit(e[s]);
  4800. if (t != null) t.push(i);
  4801. else if (i != e[s]) {
  4802. t = [];
  4803. for (let i = 0; i < s; i++) t.push(e[i]);
  4804. t.push(i);
  4805. }
  4806. }
  4807. return t != null ? t : e;
  4808. }
  4809.  
  4810. visitAssignmentExpression(e) {
  4811. const t = this.visit(e.left);
  4812. const s = this.visit(e.right);
  4813. return t !== e.left || s !== e.right ? new AssignmentExpression(e.operator, t, s) : e;
  4814. }
  4815.  
  4816. visitAssignmentPattern(e) {
  4817. const t = this.visit(e.left);
  4818. const s = this.visit(e.right);
  4819. return t !== e.left || s !== e.right ? new AssignmentPattern(t, s) : e;
  4820. }
  4821.  
  4822. visitArrayExpression(e) {
  4823. const t = this.visitNodeList(e.elements);
  4824. return t !== e.elements ? new ArrayExpression(t) : e;
  4825. }
  4826.  
  4827. visitArrayPattern(e) {
  4828. const t = this.visitNodeList(e.elements);
  4829. return t !== e.elements ? new ArrayPattern(t) : e;
  4830. }
  4831.  
  4832. visitArrowFunctionExpression(e) {
  4833. const t = this.visit(e.id);
  4834. const s = this.visitNodeList(e.params);
  4835. const i = this.visit(e.body);
  4836. if (t !== e.id || s !== e.params || i !== e.body) {
  4837. const r = new ArrowFunctionExpression(s, i, e.expression, e.async);
  4838. return r.id = t, r;
  4839. }
  4840. return e;
  4841. }
  4842.  
  4843. visitAwaitExpression(e) {
  4844. const t = this.visit(e.argument);
  4845. return t !== e.argument ? new AwaitExpression(t) : e;
  4846. }
  4847.  
  4848. visitBlockStatement(e) {
  4849. const t = this.visitNodeList(e.body);
  4850. return t !== e.body ? new BlockStatement(t) : e;
  4851. }
  4852.  
  4853. visitBinaryExpression(e) {
  4854. const t = this.visit(e.left);
  4855. const s = this.visit(e.right);
  4856. return t !== e.left || s !== e.right ? new BinaryExpression(e.operator, t, s) : e;
  4857. }
  4858.  
  4859. visitBreakStatement(e) {
  4860. const t = this.visit(e.label);
  4861. return t !== e.label ? new BreakStatement(t) : e;
  4862. }
  4863.  
  4864. visitCallExpression(e) {
  4865. const t = this.visit(e.callee);
  4866. const s = this.visitNodeList(e.arguments);
  4867. return t !== e.callee || s !== e.arguments ? new CallExpression(t, s, e.optional) : e;
  4868. }
  4869.  
  4870. visitCatchClause(e) {
  4871. const t = this.visit(e.param);
  4872. const s = this.visit(e.body);
  4873. return t !== e.param || s !== e.body ? new CatchClause(t, s) : e;
  4874. }
  4875.  
  4876. visitChainExpression(e) {
  4877. const t = this.visit(e.expression);
  4878. return t !== e.expression ? new ChainExpression(t) : e;
  4879. }
  4880.  
  4881. visitClassBody(e) {
  4882. const t = this.visitNodeList(e.body);
  4883. return t !== e.body ? new ClassBody(t) : e;
  4884. }
  4885.  
  4886. visitClassDeclaration(e) {
  4887. const t = this.visit(e.id);
  4888. const s = this.visit(e.superClass);
  4889. const i = this.visit(e.body);
  4890. const r = this.visitNodeList(e.decorators);
  4891. return t !== e.id || s !== e.superClass || i !== e.body || r !== e.decorators ? new ClassDeclaration(t, s, i, r) : e;
  4892. }
  4893.  
  4894. visitClassExpression(e) {
  4895. const t = this.visit(e.id);
  4896. const s = this.visit(e.superClass);
  4897. const i = this.visit(e.body);
  4898. const r = this.visitNodeList(e.decorators);
  4899. return t !== e.id || s !== e.superClass || i !== e.body || r !== e.decorators ? new ClassExpression(t, s, i, r) : e;
  4900. }
  4901.  
  4902. visitConditionalExpression(e) {
  4903. const t = this.visit(e.test);
  4904. const s = this.visit(e.consequent);
  4905. const i = this.visit(e.alternate);
  4906. return t !== e.test || s !== e.consequent || i !== e.alternate ? new ConditionalExpression(t, s, i) : e;
  4907. }
  4908.  
  4909. visitContinueStatement(e) {
  4910. const t = this.visit(e.label);
  4911. return t !== e.label ? new ContinueStatement(t) : e;
  4912. }
  4913.  
  4914. visitDecorator(e) {
  4915. const t = this.visit(e.expression);
  4916. return t !== e.expression ? new Decorator(t) : e;
  4917. }
  4918.  
  4919. visitDoWhileStatement(e) {
  4920. const t = this.visit(e.body);
  4921. const s = this.visit(e.test);
  4922. return t !== e.body || s !== e.test ? new DoWhileStatement(t, s) : e;
  4923. }
  4924.  
  4925. visitDebuggerStatement(e) {
  4926. return e;
  4927. }
  4928.  
  4929. visitEmptyStatement(e) {
  4930. return e;
  4931. }
  4932.  
  4933. visitExportAllDeclaration(e) {
  4934. const t = this.visit(e.source);
  4935. const s = this.visit(e.exported);
  4936. const i = this.visitNodeList(e.assertions);
  4937. return t !== e.source || s !== e.exported || i !== e.assertions ? new ExportAllDeclaration(t, s, i) : e;
  4938. }
  4939.  
  4940. visitExportDefaultDeclaration(e) {
  4941. const t = this.visit(e.declaration);
  4942. return t !== e.declaration ? new ExportDefaultDeclaration(t) : e;
  4943. }
  4944.  
  4945. visitExportNamedDeclaration(e) {
  4946. const t = this.visit(e.declaration);
  4947. const s = this.visitNodeList(e.specifiers);
  4948. const i = this.visit(e.source);
  4949. const r = this.visitNodeList(e.assertions);
  4950. return t !== e.declaration || s !== e.specifiers || i !== e.source || r !== e.assertions ? new ExportNamedDeclaration(t, s, i, r) : e;
  4951. }
  4952.  
  4953. visitExportSpecifier(e) {
  4954. const t = this.visit(e.exported);
  4955. const s = this.visit(e.local);
  4956. return t !== e.exported || s !== e.local ? new ExportSpecifier(t, s) : e;
  4957. }
  4958.  
  4959. visitExpressionStatement(e) {
  4960. const t = this.visit(e.expression);
  4961. return t !== e.expression ? new ExpressionStatement(t) : e;
  4962. }
  4963.  
  4964. visitForStatement(e) {
  4965. const t = this.visit(e.init);
  4966. const s = this.visit(e.test);
  4967. const i = this.visit(e.update);
  4968. const r = this.visit(e.body);
  4969. return t !== e.init || s !== e.test || i !== e.update || r !== e.body ? new ForStatement(t, s, i, r) : e;
  4970. }
  4971.  
  4972. visitForOfStatement(e) {
  4973. const t = this.visit(e.left);
  4974. const s = this.visit(e.right);
  4975. const i = this.visit(e.body);
  4976. return t !== e.left || s !== e.right || i !== e.body ? new ForOfStatement(t, s, i, e.await) : e;
  4977. }
  4978.  
  4979. visitForInStatement(e) {
  4980. const t = this.visit(e.left);
  4981. const s = this.visit(e.right);
  4982. const i = this.visit(e.body);
  4983. return t !== e.left || s !== e.right || i !== e.body ? new ForInStatement(t, s, i) : e;
  4984. }
  4985.  
  4986. visitFunctionDeclaration(e) {
  4987. const t = this.visit(e.id);
  4988. const s = this.visitNodeList(e.params);
  4989. const i = this.visit(e.body);
  4990. return t !== e.id || s !== e.params || i !== e.body ? new FunctionDeclaration(t, s, i, e.generator) : e;
  4991. }
  4992.  
  4993. visitFunctionExpression(e) {
  4994. const t = this.visit(e.id);
  4995. const s = this.visitNodeList(e.params);
  4996. const i = this.visit(e.body);
  4997. return t !== e.id || s !== e.params || i !== e.body ? new FunctionExpression(t, s, i, e.generator, e.async) : e;
  4998. }
  4999.  
  5000. visitIdentifier(e) {
  5001. return e;
  5002. }
  5003.  
  5004. visitIfStatement(e) {
  5005. const t = this.visit(e.test);
  5006. const s = this.visit(e.consequent);
  5007. const i = this.visit(e.alternate);
  5008. return t !== e.test || s !== e.consequent || i !== e.alternate ? new IfStatement(t, s, i) : e;
  5009. }
  5010.  
  5011. visitImportAttribute(e) {
  5012. const t = this.visit(e.key);
  5013. const s = this.visit(e.value);
  5014. return t !== e.key || s !== e.value ? new ImportAttribute(t, s) : e;
  5015. }
  5016.  
  5017. visitImportExpression(e) {
  5018. const t = this.visit(e.source);
  5019. const s = this.visit(e.attributes);
  5020. return t !== e.source || s !== e.attributes ? new ImportExpression(t, s) : e;
  5021. }
  5022.  
  5023. visitImportDeclaration(e) {
  5024. const t = this.visitNodeList(e.specifiers);
  5025. const s = this.visit(e.source);
  5026. const i = this.visitNodeList(e.assertions);
  5027. return t !== e.specifiers || s !== e.source || i !== e.assertions ? new ImportDeclaration(t, s, i) : e;
  5028. }
  5029.  
  5030. visitImportDefaultSpecifier(e) {
  5031. const t = this.visit(e.local);
  5032. return t !== e.local ? new ImportDefaultSpecifier(t) : e;
  5033. }
  5034.  
  5035. visitImportNamespaceSpecifier(e) {
  5036. const t = this.visit(e.local);
  5037. return t !== e.local ? new ImportNamespaceSpecifier(t) : e;
  5038. }
  5039.  
  5040. visitImportSpecifier(e) {
  5041. const t = this.visit(e.local);
  5042. const s = this.visit(e.imported);
  5043. return t !== e.local || s !== e.imported ? new ImportSpecifier(t, s) : e;
  5044. }
  5045.  
  5046. visitLiteral(e) {
  5047. return e;
  5048. }
  5049.  
  5050. visitLabeledStatement(e) {
  5051. const t = this.visit(e.label);
  5052. const s = this.visit(e.body);
  5053. return t !== e.label || s !== e.body ? new LabeledStatement(t, s) : e;
  5054. }
  5055.  
  5056. visitLogicalExpression(e) {
  5057. const t = this.visit(e.left);
  5058. const s = this.visit(e.right);
  5059. return t !== e.left || s !== e.right ? new LogicalExpression(e.operator, t, s) : e;
  5060. }
  5061.  
  5062. visitMemberExpression(e) {
  5063. const t = this.visit(e.object);
  5064. const s = this.visit(e.property);
  5065. return t !== e.object || s !== e.property ? new MemberExpression(e.computed, t, s, e.optional) : e;
  5066. }
  5067.  
  5068. visitMetaProperty(e) {
  5069. const t = this.visit(e.meta);
  5070. const s = this.visit(e.property);
  5071. return t !== e.meta || s !== e.property ? new MetaProperty(t, s) : e;
  5072. }
  5073.  
  5074. visitMethodDefinition(e) {
  5075. const t = this.visit(e.key);
  5076. const s = this.visit(e.value);
  5077. const i = this.visitNodeList(e.decorators);
  5078. return t !== e.key || s !== e.value || i !== e.decorators ? new MethodDefinition(t, e.computed, s, e.kind, e.static, i) : e;
  5079. }
  5080.  
  5081. visitNewExpression(e) {
  5082. const t = this.visit(e.callee);
  5083. const s = this.visitNodeList(e.arguments);
  5084. return t !== e.callee || s !== e.arguments ? new NewExpression(t, s) : e;
  5085. }
  5086.  
  5087. visitObjectExpression(e) {
  5088. const t = this.visitNodeList(e.properties);
  5089. return t !== e.properties ? new ObjectExpression(t) : e;
  5090. }
  5091.  
  5092. visitObjectPattern(e) {
  5093. const t = this.visitNodeList(e.properties);
  5094. return t !== e.properties ? new ObjectPattern(t) : e;
  5095. }
  5096.  
  5097. visitProgram(e) {
  5098. const t = this.visitNodeList(e.body);
  5099. return t !== e.body ? new Program(e.sourceType, t) : e;
  5100. }
  5101.  
  5102. visitProperty(e) {
  5103. const t = this.visit(e.key);
  5104. const s = this.visit(e.value);
  5105. const i = this.visitNodeList(e.decorators);
  5106. 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;
  5107. }
  5108.  
  5109. visitPrivateIdentifier(e) {
  5110. return e;
  5111. }
  5112.  
  5113. visitRestElement(e) {
  5114. const t = this.visit(e.argument);
  5115. return t !== e.argument ? new RestElement(t) : e;
  5116. }
  5117.  
  5118. visitReturnStatement(e) {
  5119. const t = this.visit(e.argument);
  5120. return t !== e.argument ? new ReturnStatement(t) : e;
  5121. }
  5122.  
  5123. visitSequenceExpression(e) {
  5124. const t = this.visitNodeList(e.expressions);
  5125. return t !== e.expressions ? new SequenceExpression(t) : e;
  5126. }
  5127.  
  5128. visitSpreadElement(e) {
  5129. const t = this.visit(e.argument);
  5130. return t !== e.argument ? new SpreadElement(t) : e;
  5131. }
  5132.  
  5133. visitStaticBlock(e) {
  5134. const t = this.visitNodeList(e.body);
  5135. return t !== e.body ? new StaticBlock(t) : e;
  5136. }
  5137.  
  5138. visitSuper(e) {
  5139. return e;
  5140. }
  5141.  
  5142. visitSwitchCase(e) {
  5143. const t = this.visit(e.test);
  5144. const s = this.visitNodeList(e.consequent);
  5145. return t !== e.test || s !== e.consequent ? new SwitchCase(t, s) : e;
  5146. }
  5147.  
  5148. visitSwitchStatement(e) {
  5149. const t = this.visit(e.discriminant);
  5150. const s = this.visitNodeList(e.cases);
  5151. return t !== e.discriminant || s !== e.cases ? new SwitchStatement(t, s) : e;
  5152. }
  5153.  
  5154. visitTaggedTemplateExpression(e) {
  5155. const t = this.visit(e.tag);
  5156. const s = this.visit(e.quasi);
  5157. return t !== e.tag || s !== e.quasi ? new TaggedTemplateExpression(t, s) : e;
  5158. }
  5159.  
  5160. visitTemplateElement(e) {
  5161. return e;
  5162. }
  5163.  
  5164. visitTemplateLiteral(e) {
  5165. const t = this.visitNodeList(e.quasis);
  5166. const s = this.visitNodeList(e.expressions);
  5167. return t !== e.quasis || s !== e.expressions ? new TemplateLiteral(t, s) : e;
  5168. }
  5169.  
  5170. visitThisExpression(e) {
  5171. return e;
  5172. }
  5173.  
  5174. visitThrowStatement(e) {
  5175. const t = this.visit(e.argument);
  5176. return t !== e.argument ? new ThrowStatement(t) : e;
  5177. }
  5178.  
  5179. visitTryStatement(e) {
  5180. const t = this.visit(e.block);
  5181. const s = this.visit(e.handler);
  5182. const i = this.visit(e.finalizer);
  5183. return t !== e.block || s !== e.handler || i !== e.finalizer ? new TryStatement(t, s, i) : e;
  5184. }
  5185.  
  5186. visitUnaryExpression(e) {
  5187. const t = this.visit(e.argument);
  5188. return t !== e.argument ? new UnaryExpression(e.operator, t) : e;
  5189. }
  5190.  
  5191. visitUpdateExpression(e) {
  5192. const t = this.visit(e.argument);
  5193. return t !== e.argument ? new UpdateExpression(e.operator, t, e.prefix) : e;
  5194. }
  5195.  
  5196. visitVariableDeclaration(e) {
  5197. const t = this.visitNodeList(e.declarations);
  5198. return t !== e.declarations ? new VariableDeclaration(t, e.kind) : e;
  5199. }
  5200.  
  5201. visitVariableDeclarator(e) {
  5202. const t = this.visit(e.id);
  5203. const s = this.visit(e.init);
  5204. return t !== e.id || s !== e.init ? new VariableDeclarator(t, s) : e;
  5205. }
  5206.  
  5207. visitWhileStatement(e) {
  5208. const t = this.visit(e.test);
  5209. const s = this.visit(e.body);
  5210. return t !== e.test || s !== e.body ? new WhileStatement(t, s) : e;
  5211. }
  5212.  
  5213. visitWithStatement(e) {
  5214. const t = this.visit(e.object);
  5215. const s = this.visit(e.body);
  5216. return t !== e.object || s !== e.body ? new WithStatement(t, s) : e;
  5217. }
  5218.  
  5219. visitYieldExpression(e) {
  5220. const t = this.visit(e.argument);
  5221. return t !== e.argument ? new YieldExpression(t, e.delegate) : e;
  5222. }
  5223. };
  5224.  
  5225. function parse(e, t, s) {
  5226. let i = null;
  5227. const r = (e, t) => {
  5228. s && s(e, t), i && i.visit(e, t);
  5229. };
  5230. let n = typeof s === 'function' ? r : null;
  5231. let a = !1;
  5232. if (t) {
  5233. a = typeof t.comment === 'boolean' && t.comment;
  5234. const e = typeof t.attachComment === 'boolean' && t.attachComment;
  5235. (a || e) && (i = new CommentHandler(), i.attach = e, t.comment = !0, n = r);
  5236. }
  5237. let o; let
  5238. u = !1;
  5239. 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);
  5240. const h = u ? o.parseModule() : o.parseScript();
  5241. return a && i && (h.comments = i.comments), o.config.tokens && (h.tokens = o.tokens), o.config.tolerant && (h.errors = o.errorHandler.errors), h;
  5242. }
  5243.  
  5244. function parseModule(e, t, s) {
  5245. const i = t || {};
  5246. return i.sourceType = 'module', parse(e, i, s);
  5247. }
  5248.  
  5249. function parseScript(e, t, s) {
  5250. const i = t || {};
  5251. return i.sourceType = 'script', parse(e, i, s);
  5252. }
  5253.  
  5254. function tokenize(e, t, s) {
  5255. const i = new Tokenizer(e, t);
  5256. const r = [];
  5257. try {
  5258. for (;;) {
  5259. let e = i.getNextToken();
  5260. if (!e) break;
  5261. s && (e = s(e)), r.push(e);
  5262. }
  5263. } catch (e) {
  5264. i.errorHandler.tolerate(e);
  5265. }
  5266. return i.errorHandler.tolerant && (r.errors = i.errors()), r;
  5267. }
  5268. const version = '6.0.3';
  5269. // eslint-disable-next-line camelcase
  5270. return {
  5271. parse,
  5272. parseModule,
  5273. parseScript,
  5274. tokenize,
  5275. Syntax,
  5276. version
  5277. };
  5278. })();
  5279. /* eslint-enable */
  5280.  
  5281. /* eslint-disable no-bitwise */
  5282. /* eslint-disable eqeqeq */
  5283. /* eslint-disable max-classes-per-file */
  5284. /* eslint-disable no-multi-assign */
  5285.  
  5286. const ScopeType = {
  5287. Global: 'Global',
  5288. Function: 'Function',
  5289. Block: 'Block'
  5290. };
  5291.  
  5292. const VariableType = {
  5293. Let: 'Let',
  5294. Const: 'Const',
  5295. Var: 'Var'
  5296. };
  5297.  
  5298. class Scope {
  5299. /** @type {Scope} */
  5300. parent;
  5301. variables = {};
  5302. /** @type {string} */
  5303. type;
  5304.  
  5305. constructor(type, parent) {
  5306. this.type = type;
  5307. this.parent = parent;
  5308. this.variables = {};
  5309. }
  5310.  
  5311. declare(type, name, value = undefined) {
  5312. this.checkAlreadyDeclared(name, type);
  5313. switch (type) {
  5314. case VariableType.Let:
  5315. this.variables[name] = { type, value };
  5316. break;
  5317. case VariableType.Const:
  5318. this.variables[name] = { type, value };
  5319. break;
  5320. case VariableType.Var: {
  5321. let scope = this;
  5322. while (scope) {
  5323. if (scope.type === ScopeType.Function || scope.type === ScopeType.Global) {
  5324. scope.variables[name] = { type, value };
  5325. scope = undefined;
  5326. } else {
  5327. scope = scope.parent;
  5328. }
  5329. }
  5330. break;
  5331. }
  5332. default:
  5333. throw new SyntaxError(`Unexpected variable declaration type: ${type}`);
  5334. }
  5335. }
  5336.  
  5337. checkAlreadyDeclared(name, type) {
  5338. let scope = this;
  5339. while (scope) {
  5340. if (scope.variables.hasOwnProperty(name)) {
  5341. if (type === VariableType.Const || type === VariableType.Let
  5342. || scope.variables[name].type !== VariableType.Var) {
  5343. throw new SyntaxError(`Identifier '${name}' has already been declared`);
  5344. }
  5345. }
  5346. if (scope.type === ScopeType.Function || scope.type === ScopeType.Global) {
  5347. scope = undefined;
  5348. } else {
  5349. scope = scope.parent;
  5350. }
  5351. }
  5352. }
  5353.  
  5354. setValue(name, value) {
  5355. const reference = this.getReference(name, true);
  5356. if (!reference) {
  5357. throw new ReferenceError(`${name} is not defined.`);
  5358. }
  5359. if (reference.type === VariableType.Const) {
  5360. throw new TypeError(`Assignment to constant variable: ${name}`);
  5361. }
  5362. return (reference.value = value);
  5363. }
  5364.  
  5365. getValue(name) {
  5366. const reference = this.getReference(name);
  5367. return reference?.value;
  5368. }
  5369.  
  5370. getReference(name) {
  5371. let scope = this;
  5372. while (scope) {
  5373. if (scope.variables.hasOwnProperty(name)) {
  5374. return scope.variables[name];
  5375. }
  5376. if (scope.type === ScopeType.Global) {
  5377. scope = undefined;
  5378. } else {
  5379. scope = scope.parent;
  5380. }
  5381. }
  5382. return undefined;
  5383. }
  5384.  
  5385. createChildScope(type) {
  5386. return new Scope(type, this);
  5387. }
  5388. }
  5389.  
  5390. class FlowStopper {}
  5391. class Break extends FlowStopper {}
  5392. class Continue extends FlowStopper {}
  5393. class Return extends FlowStopper {
  5394. value;
  5395. constructor(value) {
  5396. super();
  5397. this.value = value;
  5398. }
  5399. }
  5400. class Debugger {}
  5401. class ChainIsNullish {}
  5402.  
  5403. // eslint-disable-next-line no-shadow
  5404. class Interpreter {
  5405. static execute(esTree, globalVariables) {
  5406. const scope = new Scope(ScopeType.Global);
  5407.  
  5408. // Add global variables
  5409. Object.keys(globalVariables).forEach(key => {
  5410. scope.declare(VariableType.Let, key, globalVariables[key]);
  5411. });
  5412.  
  5413. return { output: this.processNode(esTree, scope), variables: scope };
  5414. }
  5415.  
  5416. static processorMap = {
  5417. [esprima.Syntax.Program]: Interpreter.processProgram.bind(Interpreter),
  5418. [esprima.Syntax.ExpressionStatement]: (n, s) => Interpreter.processNode(n.expression, s),
  5419. [esprima.Syntax.Literal]: Interpreter.processLiteral.bind(Interpreter),
  5420. [esprima.Syntax.MemberExpression]: Interpreter.processMemberExpression.bind(Interpreter),
  5421. [esprima.Syntax.BinaryExpression]: Interpreter.processBinaryExpression.bind(Interpreter),
  5422. [esprima.Syntax.VariableDeclaration]: Interpreter.processVariableDeclaration.bind(Interpreter),
  5423. [esprima.Syntax.VariableDeclarator]: Interpreter.processVariableDeclarator.bind(Interpreter),
  5424. [esprima.Syntax.CallExpression]: Interpreter.processCallExpression.bind(Interpreter),
  5425. [esprima.Syntax.AssignmentExpression]: Interpreter.processAssigmentExpression.bind(Interpreter),
  5426. [esprima.Syntax.Identifier]: Interpreter.processIdentifier.bind(Interpreter),
  5427. [esprima.Syntax.IfStatement]: Interpreter.processIfStatement.bind(Interpreter),
  5428. [esprima.Syntax.BlockStatement]: Interpreter.processBlockStatement.bind(Interpreter),
  5429. [esprima.Syntax.EmptyStatement]: () => {}, // do nothing
  5430. [esprima.Syntax.TemplateLiteral]: Interpreter.processTemplateLiteral.bind(Interpreter),
  5431. [esprima.Syntax.NewExpression]: Interpreter.processNewExpression.bind(Interpreter),
  5432. [esprima.Syntax.FunctionDeclaration]: Interpreter.processFunctionDeclaration.bind(Interpreter),
  5433. [esprima.Syntax.ReturnStatement]: Interpreter.processReturnStatement.bind(Interpreter),
  5434. [esprima.Syntax.LogicalExpression]: Interpreter.processLogicalExpression.bind(Interpreter),
  5435. [esprima.Syntax.UnaryExpression]: Interpreter.processUnaryExpression.bind(Interpreter),
  5436. [esprima.Syntax.ArrayExpression]: Interpreter.processArrayExpression.bind(Interpreter),
  5437. [esprima.Syntax.ConditionalExpression]: Interpreter.processConditionalExpression.bind(Interpreter),
  5438. [esprima.Syntax.ObjectExpression]: Interpreter.processObjectExpression.bind(Interpreter),
  5439. [esprima.Syntax.FunctionExpression]: Interpreter.processFunctionExpression.bind(Interpreter),
  5440. [esprima.Syntax.ArrowFunctionExpression]: Interpreter.processArrowFunctionExpression.bind(Interpreter),
  5441. [esprima.Syntax.ChainExpression]: Interpreter.processChainExpression.bind(Interpreter),
  5442. [esprima.Syntax.UpdateExpression]: Interpreter.processUpdateExpression.bind(Interpreter),
  5443. [esprima.Syntax.ForStatement]: Interpreter.processForStatement.bind(Interpreter),
  5444. [esprima.Syntax.TryStatement]: Interpreter.processTryStatement.bind(Interpreter),
  5445. [esprima.Syntax.BreakStatement]: Interpreter.processBreakStatement.bind(Interpreter),
  5446. [esprima.Syntax.ContinueStatement]: Interpreter.processContinueStatement.bind(Interpreter),
  5447. [esprima.Syntax.DebuggerStatement]: Interpreter.processDebuggerStatement.bind(Interpreter),
  5448. [esprima.Syntax.SwitchStatement]: Interpreter.processSwitchStatement.bind(Interpreter),
  5449. [esprima.Syntax.SpreadElement]: Interpreter.processSpreadElement.bind(Interpreter)
  5450. };
  5451.  
  5452. static processNode(node, scope) {
  5453. const processor = this.processorMap[node.type];
  5454. if (!processor) {
  5455. throw new SyntaxError(`Unexpected node type: ${node.type}`);
  5456. }
  5457.  
  5458. return processor(node, scope);
  5459. }
  5460.  
  5461. static processSwitchStatement(node, scope) {
  5462. const discriminant = this.processNode(node.discriminant, scope);
  5463. let matchIndex = -1;
  5464. let defaultIndex = -1;
  5465. for (let i = 0; i < node.cases.length && matchIndex === -1; i++) {
  5466. const switchCase = node.cases[i];
  5467. if (!switchCase.test) {
  5468. defaultIndex = i;
  5469. } else if (this.processNode(switchCase.test, scope) === discriminant) {
  5470. matchIndex = i;
  5471. }
  5472. }
  5473. if (matchIndex === -1) matchIndex = defaultIndex;
  5474.  
  5475. let returnValue;
  5476. if (matchIndex > -1) {
  5477. const switchScope = scope.createChildScope(ScopeType.Block);
  5478. for (let i = matchIndex; i < node.cases.length && !(returnValue instanceof FlowStopper); i++) {
  5479. let result;
  5480. const switchCase = node.cases[i];
  5481. for (let j = 0; j < switchCase.consequent.length && !(result instanceof FlowStopper); j++) {
  5482. result = this.processNode(switchCase.consequent[j], switchScope);
  5483. if (!(result instanceof Break || result instanceof Continue)) {
  5484. returnValue = result;
  5485. }
  5486. }
  5487. }
  5488. }
  5489. return returnValue;
  5490. }
  5491.  
  5492. static processDebuggerStatement() {
  5493. // eslint-disable-next-line no-debugger
  5494. debugger;
  5495. return new Debugger();
  5496. }
  5497.  
  5498. static processTryStatement(node, scope) {
  5499. let returnValue;
  5500. try {
  5501. returnValue = this.processNode(node.block, scope);
  5502. } catch (e) {
  5503. // Based on research, I think a Function scope is appropriate here but not certain.
  5504. const catchScope = scope.createChildScope(ScopeType.Function);
  5505. node.handler.param.returnName = true;
  5506. catchScope.declare(VariableType.Var, this.processNode(node.handler.param, catchScope), e);
  5507. this.processNode(node.handler.body, catchScope);
  5508. } finally {
  5509. if (node.finalizer) {
  5510. this.processNode(node.finalizer, scope);
  5511. }
  5512. }
  5513. return returnValue;
  5514. }
  5515.  
  5516. static processObjectExpression(node, scope) {
  5517. const returnValue = {};
  5518. node.properties.forEach(property => {
  5519. property.key.returnName = !node.computed;
  5520. const key = this.processNode(property.key, scope);
  5521. returnValue[key] = this.processNode(property.value, scope);
  5522. });
  5523. return returnValue;
  5524. }
  5525.  
  5526. static processConditionalExpression(node, scope) {
  5527. const returnValue = this.processNode(node.test, scope) ? this.processNode(node.consequent, scope) : this.processNode(node.alternate, scope);
  5528. return returnValue;
  5529. }
  5530.  
  5531. static processArrayExpression(node, scope) {
  5532. const returnValue = node.elements.map(element => this.processNode(element, scope));
  5533. return returnValue;
  5534. }
  5535.  
  5536. static setScopeValue(targetNode, value, scope) {
  5537. switch (targetNode.type) {
  5538. case esprima.Syntax.MemberExpression: {
  5539. const object = this.processNode(targetNode.object, scope);
  5540. targetNode.property.returnName = true;
  5541. const propertyName = this.processNode(targetNode.property, scope);
  5542. object[propertyName] = value;
  5543. break;
  5544. }
  5545. case esprima.Syntax.Identifier:
  5546. scope.setValue(targetNode.name, value);
  5547. break;
  5548. default:
  5549. throw new SyntaxError(`Unexpected target node type in setValue(): ${targetNode.type}`);
  5550. }
  5551. return value;
  5552. }
  5553.  
  5554. static processUpdateExpression(node, scope) {
  5555. const oldValue = this.processNode(node.argument, scope);
  5556. let newValue;
  5557. switch (node.operator) {
  5558. case '++':
  5559. newValue = this.setScopeValue(node.argument, oldValue + 1, scope);
  5560. break;
  5561. case '--':
  5562. newValue = this.setScopeValue(node.argument, oldValue - 1, scope);
  5563. break;
  5564. default:
  5565. throw new SyntaxError(`Unexpected update expression operator: ${node.operator}`);
  5566. }
  5567. return node.prefix ? newValue : oldValue;
  5568. }
  5569.  
  5570. static processForStatement(node, scope) {
  5571. let returnValue;
  5572. this.processNode(node.init, scope);
  5573. while (this.processNode(node.test, scope)) {
  5574. returnValue = this.processNode(node.body, scope);
  5575. if (returnValue instanceof FlowStopper) {
  5576. if (returnValue instanceof Return) {
  5577. returnValue = returnValue.value;
  5578. }
  5579. break;
  5580. }
  5581. this.processNode(node.update, scope);
  5582. }
  5583. return returnValue;
  5584. }
  5585.  
  5586. static processUnaryExpression(node, scope) {
  5587. let returnValue;
  5588. switch (node.operator) {
  5589. case '!':
  5590. returnValue = !this.processNode(node.argument, scope);
  5591. break;
  5592. case '~':
  5593. returnValue = ~this.processNode(node.argument, scope);
  5594. break;
  5595. case '-':
  5596. returnValue = -this.processNode(node.argument, scope);
  5597. break;
  5598. case 'typeof':
  5599. returnValue = typeof this.processNode(node.argument, scope);
  5600. break;
  5601. default:
  5602. throw new SyntaxError(`Unexpected unary expression operator: ${node.operator}`);
  5603. }
  5604. return returnValue;
  5605. }
  5606.  
  5607. static processLogicalExpression(node, scope) {
  5608. let returnValue;
  5609. switch (node.operator) {
  5610. case '&&':
  5611. returnValue = this.processNode(node.left, scope) && this.processNode(node.right, scope);
  5612. break;
  5613. case '||':
  5614. returnValue = this.processNode(node.left, scope) || this.processNode(node.right, scope);
  5615. break;
  5616. case '??':
  5617. returnValue = this.processNode(node.left, scope) ?? this.processNode(node.right, scope);
  5618. break;
  5619. default:
  5620. throw new SyntaxError(`Unexpected logical expression operator: ${node.operator}`);
  5621. }
  5622. return returnValue;
  5623. }
  5624.  
  5625. static processReturnStatement(node, scope) {
  5626. const returnValue = node.argument && this.processNode(node.argument, scope);
  5627. return new Return(returnValue);
  5628. }
  5629.  
  5630. static processContinueStatement() {
  5631. return new Continue();
  5632. }
  5633.  
  5634. static processBreakStatement() {
  5635. return new Break();
  5636. }
  5637.  
  5638. /**
  5639. *
  5640. * @param {*} node
  5641. * @param {Scope} scope
  5642. * @returns
  5643. */
  5644. static processArrowFunctionExpression(node, scope) {
  5645. const func = (...args) => {
  5646. const esTreeArgs = args.map(arg => {
  5647. const argNode = {
  5648. type: esprima.Syntax.Literal,
  5649. value: arg
  5650. };
  5651. return argNode;
  5652. });
  5653.  
  5654. const funcScope = scope.createChildScope(ScopeType.Function);
  5655. for (let i = 0; i < Math.min(esTreeArgs.length, node.params.length); i++) {
  5656. const param = node.params[i];
  5657. param.returnName = true;
  5658. funcScope.declare(
  5659. VariableType.Var,
  5660. this.processNode(param, funcScope),
  5661. this.processNode(esTreeArgs[i], funcScope)
  5662. );
  5663. }
  5664. let returnValue = this.processNode(node.body, funcScope);
  5665. if (returnValue instanceof Return) {
  5666. returnValue = returnValue.value;
  5667. }
  5668. return returnValue;
  5669. };
  5670. return func;
  5671. }
  5672.  
  5673. static processChainExpression(node, scope) {
  5674. let returnValue;
  5675. switch (node.expression.type) {
  5676. case esprima.Syntax.CallExpression:
  5677. case esprima.Syntax.MemberExpression: {
  5678. returnValue = this.processNode(node.expression, scope);
  5679. break;
  5680. }
  5681. default:
  5682. throw new SyntaxError(`Unexpected chain expression type: ${node.expression.type}`);
  5683. }
  5684. if (returnValue instanceof ChainIsNullish) returnValue = undefined;
  5685. return returnValue;
  5686. }
  5687.  
  5688. static processFunctionDeclaration(node, scope) {
  5689. const func = (...args) => {
  5690. const esTreeArgs = args.map(arg => {
  5691. const argNode = {
  5692. type: esprima.Syntax.Literal,
  5693. value: arg
  5694. };
  5695. return argNode;
  5696. });
  5697.  
  5698. const funcScope = scope.createChildScope(ScopeType.Function);
  5699. for (let i = 0; i < Math.min(esTreeArgs.length, node.params.length); i++) {
  5700. const param = node.params[i];
  5701. param.returnName = true;
  5702. funcScope.declare(
  5703. VariableType.Var,
  5704. this.processNode(param, funcScope),
  5705. this.processNode(esTreeArgs[i], funcScope)
  5706. );
  5707. }
  5708. let returnValue = this.processNode(node.body, funcScope);
  5709. if (returnValue instanceof Return) {
  5710. returnValue = returnValue.value;
  5711. }
  5712. return returnValue;
  5713. };
  5714. if (node.id) {
  5715. node.id.returnName = true;
  5716. const funcName = this.processNode(node.id, scope);
  5717. scope.declare(VariableType.Var, funcName, func);
  5718. }
  5719. return func;
  5720. }
  5721.  
  5722. static processFunctionExpression(node, scope) {
  5723. const func = (...args) => {
  5724. const esTreeArgs = args.map(arg => {
  5725. const argNode = {
  5726. type: esprima.Syntax.Literal,
  5727. value: arg
  5728. };
  5729. return argNode;
  5730. });
  5731.  
  5732. const funcScope = scope.createChildScope(ScopeType.Function);
  5733. for (let i = 0; i < Math.min(esTreeArgs.length, node.params.length); i++) {
  5734. const param = node.params[i];
  5735. param.returnName = true;
  5736. funcScope.declare(
  5737. VariableType.Var,
  5738. this.processNode(param, funcScope),
  5739. this.processNode(esTreeArgs[i], funcScope)
  5740. );
  5741. }
  5742. let returnValue = this.processNode(node.body, funcScope);
  5743. if (returnValue instanceof Return) {
  5744. returnValue = returnValue.value;
  5745. }
  5746. return returnValue;
  5747. };
  5748. return func;
  5749. }
  5750.  
  5751. static processProgram(node, scope) {
  5752. let returnValue;
  5753. node.body.forEach(childNode => {
  5754. returnValue = this.processNode(childNode, scope);
  5755. });
  5756. return returnValue;
  5757. }
  5758.  
  5759. static processNewExpression(node, scope) {
  5760. const args = node.arguments.map(argument => this.processNode(argument, scope));
  5761. return Reflect.construct(this.processNode(node.callee, scope), args);
  5762. }
  5763.  
  5764. static processTemplateLiteral(node, scope) {
  5765. let returnValue = '';
  5766. for (let i = 0; i < node.quasis.length; i++) {
  5767. returnValue += node.quasis[i].value.cooked;
  5768. if (!node.quasis[i].tail) {
  5769. returnValue += this.processNode(node.expressions[i], scope);
  5770. }
  5771. }
  5772. return returnValue;
  5773. }
  5774.  
  5775. static processBlockStatement(node, scope) {
  5776. let returnValue;
  5777. // TODO: I don't think we need to ignore the block scope in a function declaration. Test it.
  5778. // switch (context.type) {
  5779. // case esprima.Syntax.FunctionDeclaration:
  5780. // break;
  5781. // default:
  5782. const blockScope = scope.createChildScope(ScopeType.Block);
  5783. // }
  5784.  
  5785. for (let i = 0; i < node.body.length; i++) {
  5786. const childNode = node.body[i];
  5787. const result = this.processNode(childNode, blockScope);
  5788. if (result instanceof FlowStopper) {
  5789. if (result instanceof Return) {
  5790. returnValue = result;
  5791. }
  5792. break;
  5793. } else if (result instanceof Debugger) {
  5794. // do nothing
  5795. } else {
  5796. returnValue = result;
  5797. }
  5798. }
  5799.  
  5800. return returnValue;
  5801. }
  5802.  
  5803. static processIfStatement(node, scope) {
  5804. let returnValue;
  5805. const test = this.processNode(node.test, scope);
  5806. if (test) {
  5807. returnValue = this.processNode(node.consequent, scope);
  5808. } else if (node.alternate) {
  5809. returnValue = this.processNode(node.alternate, scope);
  5810. }
  5811. return returnValue;
  5812. }
  5813.  
  5814. static processLiteral(node) {
  5815. return node.value;
  5816. }
  5817.  
  5818. static processIdentifier(node, scope) {
  5819. let returnValue;
  5820. if (node.returnName) {
  5821. returnValue = node.name;
  5822. } else {
  5823. returnValue = scope.getValue(node.name);
  5824. }
  5825. return returnValue;
  5826. }
  5827.  
  5828. /**
  5829. *
  5830. * @param {*} expression
  5831. * @param {Scope} scope
  5832. * @returns
  5833. */
  5834. static getMemberExpressionObject(expression, scope) {
  5835. let returnValue;
  5836. switch (expression.object.type) {
  5837. case esprima.Syntax.Identifier: {
  5838. returnValue = scope.getValue(expression.object.name);
  5839. break;
  5840. }
  5841. case esprima.Syntax.CallExpression:
  5842. case esprima.Syntax.MemberExpression: {
  5843. const object = this.processNode(expression.object, scope);
  5844. returnValue = object;
  5845. break;
  5846. }
  5847. default:
  5848. throw new SyntaxError(`Unexpected member expression object type: ${expression.object.type}`);
  5849. }
  5850. return returnValue;
  5851. }
  5852.  
  5853. static processMemberExpression(node, scope) {
  5854. let returnValue;
  5855. const object = this.getMemberExpressionObject(node, scope);
  5856.  
  5857. if (object == null && node.optional) {
  5858. returnValue = new ChainIsNullish();
  5859. } else if (object != null || (object == null && !node.optional)) {
  5860. node.property.returnName = !node.computed;
  5861. const propertyName = this.processNode(node.property, scope);
  5862. // if (object[propertyName] == null) {
  5863. // console.warn(`Object does not contain this property: ${propertyName}`);
  5864. // }
  5865. returnValue = object[propertyName];
  5866. }
  5867. return returnValue;
  5868. }
  5869.  
  5870. static doBinaryExpression(node, func, scope) {
  5871. return func(this.processNode(node.left, scope), this.processNode(node.right, scope));
  5872. }
  5873.  
  5874. static add(left, right) {
  5875. return left + right;
  5876. }
  5877.  
  5878. static subtract(left, right) {
  5879. return left - right;
  5880. }
  5881.  
  5882. static multiply(left, right) {
  5883. return left * right;
  5884. }
  5885.  
  5886. static divide(left, right) {
  5887. return left / right;
  5888. }
  5889.  
  5890. static mod(left, right) {
  5891. return left % right;
  5892. }
  5893.  
  5894. static power(left, right) {
  5895. return left ** right;
  5896. }
  5897.  
  5898. static processBinaryExpression(node, scope) {
  5899. let returnValue;
  5900. const process = operation => this.doBinaryExpression(node, operation, scope);
  5901. switch (node.operator) {
  5902. case '+':
  5903. returnValue = process(this.add);
  5904. break;
  5905. case '-':
  5906. returnValue = process(this.subtract);
  5907. break;
  5908. case '*':
  5909. returnValue = process(this.multiply);
  5910. break;
  5911. case '/':
  5912. returnValue = process(this.divide);
  5913. break;
  5914. case '%':
  5915. returnValue = process(this.mod);
  5916. break;
  5917. case '**':
  5918. returnValue = process(this.power);
  5919. break;
  5920. case '>':
  5921. returnValue = process((left, right) => left > right);
  5922. break;
  5923. case '<':
  5924. returnValue = process((left, right) => left < right);
  5925. break;
  5926. case '==':
  5927. returnValue = process((left, right) => left == right);
  5928. break;
  5929. case '===':
  5930. returnValue = process((left, right) => left === right);
  5931. break;
  5932. case '>=':
  5933. returnValue = process((left, right) => left >= right);
  5934. break;
  5935. case '<=':
  5936. returnValue = process((left, right) => left <= right);
  5937. break;
  5938. case '!=':
  5939. returnValue = process((left, right) => left != right);
  5940. break;
  5941. case '!==':
  5942. returnValue = process((left, right) => left !== right);
  5943. break;
  5944. case '^':
  5945. returnValue = process(this.bitwiseXOR);
  5946. break;
  5947. case '|':
  5948. returnValue = process(this.bitwiseOR);
  5949. break;
  5950. case '&':
  5951. returnValue = process(this.bitwiseAND);
  5952. break;
  5953. case '>>':
  5954. returnValue = process(this.bitwiseRightShift);
  5955. break;
  5956. case '<<':
  5957. returnValue = process(this.bitwiseLeftShift);
  5958. break;
  5959. case '>>>':
  5960. returnValue = process(this.bitwiseUnsignedRightShift);
  5961. break;
  5962. default:
  5963. throw new SyntaxError(`Unexpected binary expression operator: ${node.operator}`);
  5964. }
  5965. return returnValue;
  5966. }
  5967.  
  5968. static processVariableDeclaration(node, scope) {
  5969. switch (node.kind) {
  5970. case 'let':
  5971. case 'const':
  5972. case 'var':
  5973. node.declarations.forEach(declaration => {
  5974. declaration.kind = node.kind;
  5975. this.processNode(declaration, scope);
  5976. });
  5977. break;
  5978. default:
  5979. throw new SyntaxError(`Unexpected variable declaration kind: ${node.type}`);
  5980. }
  5981. // I believe declarations always return undefined
  5982. }
  5983.  
  5984. /**
  5985. *
  5986. * @param {*} node
  5987. * @param {Scope} scope
  5988. */
  5989. static processVariableDeclarator(node, scope) {
  5990. switch (node.id.type) {
  5991. case esprima.Syntax.Identifier: {
  5992. node.id.returnName = true;
  5993. const name = this.processNode(node.id, scope);
  5994. const value = node.init ? this.processNode(node.init, scope) : undefined;
  5995. let declarationType;
  5996. switch (node.kind) {
  5997. case 'let':
  5998. declarationType = VariableType.Let;
  5999. break;
  6000. case 'const':
  6001. declarationType = VariableType.Const;
  6002. break;
  6003. case 'var':
  6004. declarationType = VariableType.Var;
  6005. break;
  6006. default:
  6007. throw new TypeError(`Unexpected variable declaration kind: ${node.kind}`);
  6008. }
  6009. scope.declare(declarationType, name, value);
  6010. break;
  6011. }
  6012. case esprima.Syntax.ObjectPattern: {
  6013. const object = this.processNode(node.init, scope);
  6014. node.id.properties.forEach(property => {
  6015. property.key.returnName = true;
  6016. const name = this.processNode(property.key, scope);
  6017. property.value.returnName = true;
  6018. const valueName = this.processNode(property.value, scope);
  6019. const value = object[valueName];
  6020. let declarationType;
  6021. switch (node.kind) {
  6022. case 'let':
  6023. declarationType = VariableType.Let;
  6024. break;
  6025. case 'const':
  6026. declarationType = VariableType.Const;
  6027. break;
  6028. case 'var':
  6029. declarationType = VariableType.Var;
  6030. break;
  6031. default:
  6032. throw new TypeError(`Unexpected variable declaration kind: ${node.kind}`);
  6033. }
  6034. scope.declare(declarationType, name, value);
  6035. });
  6036. break;
  6037. }
  6038. default:
  6039. throw new SyntaxError(`Unexpected variable declarator id type: ${node.id.type}`);
  6040. }
  6041. }
  6042.  
  6043. /**
  6044. *
  6045. * @param {*} node
  6046. * @param {Scope} scope
  6047. * @returns
  6048. */
  6049. static processCallExpression(node, scope) {
  6050. // TODO: This code doesn't pass the sniff test. Need to work on it.
  6051. const { callee } = node;
  6052. let methodToCall;
  6053. let calleeObject;
  6054. let returnValue;
  6055. switch (callee.type) {
  6056. case esprima.Syntax.MemberExpression: {
  6057. calleeObject = this.processNode(callee.object, scope);
  6058. if (calleeObject == null) {
  6059. if (callee.optional) {
  6060. returnValue = new ChainIsNullish();
  6061. } else {
  6062. throw new SyntaxError('Callee object not found in call expression.');
  6063. }
  6064. } else if (calleeObject instanceof ChainIsNullish) {
  6065. returnValue = new ChainIsNullish();
  6066. } else {
  6067. methodToCall = calleeObject[callee.property.name];
  6068. }
  6069. break;
  6070. }
  6071. case esprima.Syntax.Identifier:
  6072. methodToCall = scope.getValue(callee.name);
  6073. break;
  6074. default:
  6075. throw new SyntaxError(`Unexpected callee type in call expression: ${callee.type}`);
  6076. }
  6077.  
  6078. if (!(returnValue instanceof ChainIsNullish)) {
  6079. if (methodToCall == null) {
  6080. if (node.optional) {
  6081. returnValue = new ChainIsNullish();
  6082. } else {
  6083. let methodName;
  6084. switch (callee.type) {
  6085. case esprima.Syntax.Identifier:
  6086. methodName = callee.name;
  6087. break;
  6088. case esprima.Syntax.MemberExpression:
  6089. callee.property.returnName = true;
  6090. methodName = this.processNode(callee.property);
  6091. break;
  6092. default:
  6093. }
  6094. throw new SyntaxError(`Method not found: ${methodName}`);
  6095. }
  6096. } else {
  6097. const args = node.arguments.map(arg => this.processNode(arg, scope));
  6098. // if (!methodToCall) debugger;
  6099. returnValue = methodToCall.call(calleeObject, ...args);
  6100. }
  6101. }
  6102. return returnValue;
  6103. }
  6104.  
  6105. static doAssignmentExpression(node, func, scope) {
  6106. let returnValue;
  6107. let leftValue;
  6108. switch (node.left.type) {
  6109. case esprima.Syntax.Identifier: {
  6110. leftValue = scope.getValue(node.left.name);
  6111. returnValue = this.setScopeValue(node.left, func(leftValue, this.processNode(node.right, scope)), scope);
  6112. break;
  6113. }
  6114. case esprima.Syntax.MemberExpression: {
  6115. const object = this.getMemberExpressionObject(node.left, scope);
  6116. const propertyName = this.processNode(node.left.property, scope);
  6117. leftValue = object[propertyName];
  6118. returnValue = (object[propertyName] = func(leftValue, this.processNode(node.right, scope)));
  6119. break;
  6120. }
  6121. default:
  6122. throw new SyntaxError(`Unexpected type on left side of assignment expression: ${node.left.type}`);
  6123. }
  6124. return returnValue;
  6125. }
  6126.  
  6127. static nullishCoalesce(left, right) {
  6128. return left ?? right;
  6129. }
  6130.  
  6131. static or(left, right) {
  6132. return left || right;
  6133. }
  6134.  
  6135. static and(left, right) {
  6136. return left && right;
  6137. }
  6138.  
  6139. static bitwiseAND(left, right) {
  6140. return left & right;
  6141. }
  6142.  
  6143. static bitwiseOR(left, right) {
  6144. return left | right;
  6145. }
  6146.  
  6147. static bitwiseXOR(left, right) {
  6148. return left ^ right;
  6149. }
  6150.  
  6151. static bitwiseLeftShift(left, right) {
  6152. return left << right;
  6153. }
  6154.  
  6155. static bitwiseRightShift(left, right) {
  6156. return left >> right;
  6157. }
  6158.  
  6159. static bitwiseUnsignedRightShift(left, right) {
  6160. return left >>> right;
  6161. }
  6162.  
  6163. static processAssigmentExpression(node, scope) {
  6164. let returnValue;
  6165. const assign = operation => this.doAssignmentExpression(node, operation, scope);
  6166. switch (node.operator) {
  6167. case '=':
  6168. returnValue = this.setScopeValue(node.left, this.processNode(node.right, scope), scope);
  6169. break;
  6170. case '+=':
  6171. returnValue = assign(this.add);
  6172. break;
  6173. case '-=':
  6174. returnValue = assign(this.subtract);
  6175. break;
  6176. case '*=':
  6177. returnValue = assign(this.multiply);
  6178. break;
  6179. case '/=':
  6180. returnValue = assign(this.divide);
  6181. break;
  6182. case '%=':
  6183. returnValue = assign(this.mod);
  6184. break;
  6185. case '**=':
  6186. returnValue = assign(this.power);
  6187. break;
  6188. case '??=':
  6189. returnValue = assign(this.nullishCoalesce);
  6190. break;
  6191. case '||=':
  6192. returnValue = assign(this.or);
  6193. break;
  6194. case '&&=':
  6195. returnValue = assign(this.and);
  6196. break;
  6197. case '<<=':
  6198. returnValue = assign(this.bitwiseLeftShift);
  6199. break;
  6200. case '>>=':
  6201. returnValue = assign(this.bitwiseRightShift);
  6202. break;
  6203. case '>>>=':
  6204. returnValue = assign(this.bitwiseUnsignedRightShift);
  6205. break;
  6206. case '&=':
  6207. returnValue = assign(this.bitwiseAND);
  6208. break;
  6209. case '|=':
  6210. returnValue = assign(this.bitwiseOR);
  6211. break;
  6212. case '^=':
  6213. returnValue = assign(this.bitwiseXOR);
  6214. break;
  6215. default:
  6216. throw new SyntaxError(`Unexpected assigment expression operator: ${node.operator}`);
  6217. }
  6218. return returnValue;
  6219. }
  6220.  
  6221. static processSpreadElement(node, scope) {
  6222. const returnValue = [...this.processNode(node.argument, scope)];
  6223. return returnValue;
  6224. }
  6225. }
  6226.  
  6227. return { compile: esprima.parseScript, execute: Interpreter.execute.bind(Interpreter), version: VERSION };
  6228. })();

QingJ © 2025

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