ESTreeProcessor

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

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

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

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

QingJ © 2025

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