Path: blob/main/third_party/terser/terser.js
6162 views
(function (global, factory) {1typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :2typeof define === 'function' && define.amd ? define(['exports'], factory) :3(global = global || self, factory(global.Terser = {}));4}(this, (function (exports) { 'use strict';56/***********************************************************************78A JavaScript tokenizer / parser / beautifier / compressor.9https://github.com/mishoo/UglifyJS21011-------------------------------- (C) ---------------------------------1213Author: Mihai Bazon14<[email protected]>15http://mihai.bazon.net/blog1617Distributed under the BSD license:1819Copyright 2012 (c) Mihai Bazon <[email protected]>2021Redistribution and use in source and binary forms, with or without22modification, are permitted provided that the following conditions23are met:2425* Redistributions of source code must retain the above26copyright notice, this list of conditions and the following27disclaimer.2829* Redistributions in binary form must reproduce the above30copyright notice, this list of conditions and the following31disclaimer in the documentation and/or other materials32provided with the distribution.3334THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY35EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE36IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR37PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE38LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,39OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,40PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR41PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY42THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR43TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF44THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF45SUCH DAMAGE.4647***********************************************************************/4849function characters(str) {50return str.split("");51}5253class DefaultsError extends Error {54constructor(msg, defs) {55super();5657this.name = "DefaultsError";58this.message = msg;59this.defs = defs;60}61}6263function defaults(args, defs, croak) {64if (args === true) {65args = {};66} else if (args != null && typeof args === "object") {67args = {...args};68}6970const ret = args || {};7172if (croak) for (const i in ret) if (HOP(ret, i) && !HOP(defs, i)) {73throw new DefaultsError("`" + i + "` is not a supported option", defs);74}7576for (const i in defs) if (HOP(defs, i)) {77if (!args || !HOP(args, i)) {78ret[i] = defs[i];79} else if (i === "ecma") {80let ecma = args[i] | 0;81if (ecma > 5 && ecma < 2015) ecma += 2009;82ret[i] = ecma;83} else {84ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];85}86}8788return ret;89}9091function noop() {}92function return_false() { return false; }93function return_true() { return true; }94function return_this() { return this; }9596var MAP = (function() {97function MAP(a, tw, allow_splicing = true) {98const new_a = [];99100for (let i = 0; i < a.length; ++i) {101let item = a[i];102let ret = item.transform(tw, allow_splicing);103104if (ret instanceof AST_Node) {105new_a.push(ret);106} else if (ret instanceof Splice) {107new_a.push(...ret.v);108}109}110111return new_a;112}113114MAP.splice = function(val) { return new Splice(val); };115MAP.skip = {};116function Splice(val) { this.v = val; }117return MAP;118})();119120function make_node(ctor, orig, props) {121if (!props) props = {};122if (orig) {123if (!props.start) props.start = orig.start;124if (!props.end) props.end = orig.end;125}126return new ctor(props);127}128129function push_uniq(array, el) {130if (!array.includes(el))131array.push(el);132}133134function string_template(text, props) {135return text.replace(/{(.+?)}/g, function(str, p) {136return props && props[p];137});138}139140function mergeSort(array, cmp) {141if (array.length < 2) return array.slice();142function merge(a, b) {143var r = [], ai = 0, bi = 0, i = 0;144while (ai < a.length && bi < b.length) {145cmp(a[ai], b[bi]) <= 0146? r[i++] = a[ai++]147: r[i++] = b[bi++];148}149if (ai < a.length) r.push.apply(r, a.slice(ai));150if (bi < b.length) r.push.apply(r, b.slice(bi));151return r;152}153function _ms(a) {154if (a.length <= 1)155return a;156var m = Math.floor(a.length / 2), left = a.slice(0, m), right = a.slice(m);157left = _ms(left);158right = _ms(right);159return merge(left, right);160}161return _ms(array);162}163164function makePredicate(words) {165if (!Array.isArray(words)) words = words.split(" ");166167return new Set(words.sort());168}169170function HOP(obj, prop) {171return Object.prototype.hasOwnProperty.call(obj, prop);172}173174function keep_name(keep_setting, name) {175return keep_setting === true176|| (keep_setting instanceof RegExp && keep_setting.test(name));177}178179var lineTerminatorEscape = {180"\0": "0",181"\n": "n",182"\r": "r",183"\u2028": "u2028",184"\u2029": "u2029",185};186function regexp_source_fix(source) {187// V8 does not escape line terminators in regexp patterns in node 12188// We'll also remove literal \0189return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {190var escaped = source[offset - 1] == "\\"191&& (source[offset - 2] != "\\"192|| /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1)));193return (escaped ? "" : "\\") + lineTerminatorEscape[match];194});195}196197const all_flags = "dgimsuyv";198function sort_regexp_flags(flags) {199const existing_flags = new Set(flags.split(""));200let out = "";201for (const flag of all_flags) {202if (existing_flags.has(flag)) {203out += flag;204existing_flags.delete(flag);205}206}207if (existing_flags.size) {208// Flags Terser doesn't know about209existing_flags.forEach(flag => { out += flag; });210}211return out;212}213214function set_annotation(node, annotation) {215node._annotations |= annotation;216}217218/***********************************************************************219220A JavaScript tokenizer / parser / beautifier / compressor.221https://github.com/mishoo/UglifyJS2222223-------------------------------- (C) ---------------------------------224225Author: Mihai Bazon226<[email protected]>227http://mihai.bazon.net/blog228229Distributed under the BSD license:230231Copyright 2012 (c) Mihai Bazon <[email protected]>232Parser based on parse-js (http://marijn.haverbeke.nl/parse-js/).233234Redistribution and use in source and binary forms, with or without235modification, are permitted provided that the following conditions236are met:237238* Redistributions of source code must retain the above239copyright notice, this list of conditions and the following240disclaimer.241242* Redistributions in binary form must reproduce the above243copyright notice, this list of conditions and the following244disclaimer in the documentation and/or other materials245provided with the distribution.246247THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY248EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE249IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR250PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE251LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,252OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,253PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR254PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY255THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR256TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF257THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF258SUCH DAMAGE.259260***********************************************************************/261262var LATEST_RAW = ""; // Only used for numbers and template strings263var TEMPLATE_RAWS = new Map(); // Raw template strings264265var KEYWORDS = "break case catch class const continue debugger default delete do else export extends finally for function if in instanceof let new return switch throw try typeof var void while with";266var KEYWORDS_ATOM = "false null true";267var RESERVED_WORDS = "enum import super this " + KEYWORDS_ATOM + " " + KEYWORDS;268var ALL_RESERVED_WORDS = "implements interface package private protected public static " + RESERVED_WORDS;269var KEYWORDS_BEFORE_EXPRESSION = "return new delete throw else case yield await";270271KEYWORDS = makePredicate(KEYWORDS);272RESERVED_WORDS = makePredicate(RESERVED_WORDS);273KEYWORDS_BEFORE_EXPRESSION = makePredicate(KEYWORDS_BEFORE_EXPRESSION);274KEYWORDS_ATOM = makePredicate(KEYWORDS_ATOM);275ALL_RESERVED_WORDS = makePredicate(ALL_RESERVED_WORDS);276277var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));278279var RE_NUM_LITERAL = /[0-9a-f]/i;280var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;281var RE_OCT_NUMBER = /^0[0-7]+$/;282var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;283var RE_BIN_NUMBER = /^0b[01]+$/i;284var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;285var RE_BIG_INT = /^(0[xob])?[0-9a-f]+n$/i;286287var OPERATORS = makePredicate([288"in",289"instanceof",290"typeof",291"new",292"void",293"delete",294"++",295"--",296"+",297"-",298"!",299"~",300"&",301"|",302"^",303"*",304"**",305"/",306"%",307">>",308"<<",309">>>",310"<",311">",312"<=",313">=",314"==",315"===",316"!=",317"!==",318"?",319"=",320"+=",321"-=",322"||=",323"&&=",324"??=",325"/=",326"*=",327"**=",328"%=",329">>=",330"<<=",331">>>=",332"|=",333"^=",334"&=",335"&&",336"??",337"||",338]);339340var WHITESPACE_CHARS = makePredicate(characters(" \u00a0\n\r\t\f\u000b\u200b\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\uFEFF"));341342var NEWLINE_CHARS = makePredicate(characters("\n\r\u2028\u2029"));343344var PUNC_AFTER_EXPRESSION = makePredicate(characters(";]),:"));345346var PUNC_BEFORE_EXPRESSION = makePredicate(characters("[{(,;:"));347348var PUNC_CHARS = makePredicate(characters("[]{}(),;:"));349350/* -----[ Tokenizer ]----- */351352// surrogate safe regexps adapted from https://github.com/mathiasbynens/unicode-8.0.0/tree/89b412d8a71ecca9ed593d9e9fa073ab64acfebe/Binary_Property353var UNICODE = {354ID_Start: /[$A-Z_a-z\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\u0561-\u0587\u05D0-\u05EA\u05F0-\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\u08A0-\u08B4\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\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\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\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-\u1877\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\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\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-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\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-\uAB65\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\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\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-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\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[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\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]|\uD83A[\uDC00-\uDCC4]|\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]|\uD87E[\uDC00-\uDE1D]/,355ID_Continue: /(?:[$0-9A-Z_a-z\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\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\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\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\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-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\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\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\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\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\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-\u1877\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\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\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-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\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-\uAB65\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\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\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-\uDE33\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]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\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\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\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[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\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]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\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]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF])+/,356};357358try {359UNICODE = {360// https://262.ecma-international.org/13.0/#prod-IdentifierStartChar361// $, _, ID_Start362ID_Start: new RegExp("[_$\\p{ID_Start}]", "u"),363// https://262.ecma-international.org/13.0/#prod-IdentifierPartChar364// $, zero-width-joiner, zero-width-non-joiner, ID_Continue365ID_Continue: new RegExp("[$\\u200C\\u200D\\p{ID_Continue}]+", "u"),366};367} catch(e) {368// Could not use modern JS \p{...}. UNICODE is already defined above so let's continue369}370371function get_full_char(str, pos) {372if (is_surrogate_pair_head(str.charCodeAt(pos))) {373if (is_surrogate_pair_tail(str.charCodeAt(pos + 1))) {374return str.charAt(pos) + str.charAt(pos + 1);375}376} else if (is_surrogate_pair_tail(str.charCodeAt(pos))) {377if (is_surrogate_pair_head(str.charCodeAt(pos - 1))) {378return str.charAt(pos - 1) + str.charAt(pos);379}380}381return str.charAt(pos);382}383384function get_full_char_code(str, pos) {385// https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates386if (is_surrogate_pair_head(str.charCodeAt(pos))) {387return 0x10000 + (str.charCodeAt(pos) - 0xd800 << 10) + str.charCodeAt(pos + 1) - 0xdc00;388}389return str.charCodeAt(pos);390}391392function get_full_char_length(str) {393var surrogates = 0;394395for (var i = 0; i < str.length; i++) {396if (is_surrogate_pair_head(str.charCodeAt(i)) && is_surrogate_pair_tail(str.charCodeAt(i + 1))) {397surrogates++;398i++;399}400}401402return str.length - surrogates;403}404405function from_char_code(code) {406// Based on https://github.com/mathiasbynens/String.fromCodePoint/blob/master/fromcodepoint.js407if (code > 0xFFFF) {408code -= 0x10000;409return (String.fromCharCode((code >> 10) + 0xD800) +410String.fromCharCode((code % 0x400) + 0xDC00));411}412return String.fromCharCode(code);413}414415function is_surrogate_pair_head(code) {416return code >= 0xd800 && code <= 0xdbff;417}418419function is_surrogate_pair_tail(code) {420return code >= 0xdc00 && code <= 0xdfff;421}422423function is_digit(code) {424return code >= 48 && code <= 57;425}426427function is_identifier_start(ch) {428return UNICODE.ID_Start.test(ch);429}430431function is_identifier_char(ch) {432return UNICODE.ID_Continue.test(ch);433}434435const BASIC_IDENT = /^[a-z_$][a-z0-9_$]*$/i;436437function is_basic_identifier_string(str) {438return BASIC_IDENT.test(str);439}440441function is_identifier_string(str, allow_surrogates) {442if (BASIC_IDENT.test(str)) {443return true;444}445if (!allow_surrogates && /[\ud800-\udfff]/.test(str)) {446return false;447}448var match = UNICODE.ID_Start.exec(str);449if (!match || match.index !== 0) {450return false;451}452453str = str.slice(match[0].length);454if (!str) {455return true;456}457458match = UNICODE.ID_Continue.exec(str);459return !!match && match[0].length === str.length;460}461462function parse_js_number(num, allow_e = true) {463if (!allow_e && num.includes("e")) {464return NaN;465}466if (RE_HEX_NUMBER.test(num)) {467return parseInt(num.substr(2), 16);468} else if (RE_OCT_NUMBER.test(num)) {469return parseInt(num.substr(1), 8);470} else if (RE_ES6_OCT_NUMBER.test(num)) {471return parseInt(num.substr(2), 8);472} else if (RE_BIN_NUMBER.test(num)) {473return parseInt(num.substr(2), 2);474} else if (RE_DEC_NUMBER.test(num)) {475return parseFloat(num);476} else {477var val = parseFloat(num);478if (val == num) return val;479}480}481482class JS_Parse_Error extends Error {483constructor(message, filename, line, col, pos) {484super();485486this.name = "SyntaxError";487this.message = message;488this.filename = filename;489this.line = line;490this.col = col;491this.pos = pos;492}493}494495function js_error(message, filename, line, col, pos) {496throw new JS_Parse_Error(message, filename, line, col, pos);497}498499function is_token(token, type, val) {500return token.type == type && (val == null || token.value == val);501}502503var EX_EOF = {};504505function tokenizer($TEXT, filename, html5_comments, shebang) {506var S = {507text : $TEXT,508filename : filename,509pos : 0,510tokpos : 0,511line : 1,512tokline : 0,513col : 0,514tokcol : 0,515newline_before : false,516regex_allowed : false,517brace_counter : 0,518template_braces : [],519comments_before : [],520directives : {},521directive_stack : []522};523524function peek() { return get_full_char(S.text, S.pos); }525526// Used because parsing ?. involves a lookahead for a digit527function is_option_chain_op() {528const must_be_dot = S.text.charCodeAt(S.pos + 1) === 46;529if (!must_be_dot) return false;530531const cannot_be_digit = S.text.charCodeAt(S.pos + 2);532return cannot_be_digit < 48 || cannot_be_digit > 57;533}534535function next(signal_eof, in_string) {536var ch = get_full_char(S.text, S.pos++);537if (signal_eof && !ch)538throw EX_EOF;539if (NEWLINE_CHARS.has(ch)) {540S.newline_before = S.newline_before || !in_string;541++S.line;542S.col = 0;543if (ch == "\r" && peek() == "\n") {544// treat a \r\n sequence as a single \n545++S.pos;546ch = "\n";547}548} else {549if (ch.length > 1) {550++S.pos;551++S.col;552}553++S.col;554}555return ch;556}557558function forward(i) {559while (i--) next();560}561562function looking_at(str) {563return S.text.substr(S.pos, str.length) == str;564}565566function find_eol() {567var text = S.text;568for (var i = S.pos, n = S.text.length; i < n; ++i) {569var ch = text[i];570if (NEWLINE_CHARS.has(ch))571return i;572}573return -1;574}575576function find(what, signal_eof) {577var pos = S.text.indexOf(what, S.pos);578if (signal_eof && pos == -1) throw EX_EOF;579return pos;580}581582function start_token() {583S.tokline = S.line;584S.tokcol = S.col;585S.tokpos = S.pos;586}587588var prev_was_dot = false;589var previous_token = null;590function token(type, value, is_comment) {591S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX.has(value)) ||592(type == "keyword" && KEYWORDS_BEFORE_EXPRESSION.has(value)) ||593(type == "punc" && PUNC_BEFORE_EXPRESSION.has(value))) ||594(type == "arrow");595if (type == "punc" && (value == "." || value == "?.")) {596prev_was_dot = true;597} else if (!is_comment) {598prev_was_dot = false;599}600const line = S.tokline;601const col = S.tokcol;602const pos = S.tokpos;603const nlb = S.newline_before;604const file = filename;605let comments_before = [];606let comments_after = [];607608if (!is_comment) {609comments_before = S.comments_before;610comments_after = S.comments_before = [];611}612S.newline_before = false;613const tok = new AST_Token(type, value, line, col, pos, nlb, comments_before, comments_after, file);614615if (!is_comment) previous_token = tok;616return tok;617}618619function skip_whitespace() {620while (WHITESPACE_CHARS.has(peek()))621next();622}623624function read_while(pred) {625var ret = "", ch, i = 0;626while ((ch = peek()) && pred(ch, i++))627ret += next();628return ret;629}630631function parse_error(err) {632js_error(err, filename, S.tokline, S.tokcol, S.tokpos);633}634635function read_num(prefix) {636var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".", is_big_int = false, numeric_separator = false;637var num = read_while(function(ch, i) {638if (is_big_int) return false;639640var code = ch.charCodeAt(0);641switch (code) {642case 95: // _643return (numeric_separator = true);644case 98: case 66: // bB645return (has_x = true); // Can occur in hex sequence, don't return false yet646case 111: case 79: // oO647case 120: case 88: // xX648return has_x ? false : (has_x = true);649case 101: case 69: // eE650return has_x ? true : has_e ? false : (has_e = after_e = true);651case 45: // -652return after_e || (i == 0 && !prefix);653case 43: // +654return after_e;655case (after_e = false, 46): // .656return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;657}658659if (ch === "n") {660is_big_int = true;661662return true;663}664665return RE_NUM_LITERAL.test(ch);666});667if (prefix) num = prefix + num;668669LATEST_RAW = num;670671if (RE_OCT_NUMBER.test(num) && next_token.has_directive("use strict")) {672parse_error("Legacy octal literals are not allowed in strict mode");673}674if (numeric_separator) {675if (num.endsWith("_")) {676parse_error("Numeric separators are not allowed at the end of numeric literals");677} else if (num.includes("__")) {678parse_error("Only one underscore is allowed as numeric separator");679}680num = num.replace(/_/g, "");681}682if (num.endsWith("n")) {683const without_n = num.slice(0, -1);684const allow_e = RE_HEX_NUMBER.test(without_n);685const valid = parse_js_number(without_n, allow_e);686if (!has_dot && RE_BIG_INT.test(num) && !isNaN(valid))687return token("big_int", without_n);688parse_error("Invalid or unexpected token");689}690var valid = parse_js_number(num);691if (!isNaN(valid)) {692return token("num", valid);693} else {694parse_error("Invalid syntax: " + num);695}696}697698function is_octal(ch) {699return ch >= "0" && ch <= "7";700}701702function read_escaped_char(in_string, strict_hex, template_string) {703var ch = next(true, in_string);704switch (ch.charCodeAt(0)) {705case 110 : return "\n";706case 114 : return "\r";707case 116 : return "\t";708case 98 : return "\b";709case 118 : return "\u000b"; // \v710case 102 : return "\f";711case 120 : return String.fromCharCode(hex_bytes(2, strict_hex)); // \x712case 117 : // \u713if (peek() == "{") {714next(true);715if (peek() === "}")716parse_error("Expecting hex-character between {}");717while (peek() == "0") next(true); // No significance718var result, length = find("}", true) - S.pos;719// Avoid 32 bit integer overflow (1 << 32 === 1)720// We know first character isn't 0 and thus out of range anyway721if (length > 6 || (result = hex_bytes(length, strict_hex)) > 0x10FFFF) {722parse_error("Unicode reference out of bounds");723}724next(true);725return from_char_code(result);726}727return String.fromCharCode(hex_bytes(4, strict_hex));728case 10 : return ""; // newline729case 13 : // \r730if (peek() == "\n") { // DOS newline731next(true, in_string);732return "";733}734}735if (is_octal(ch)) {736if (template_string && strict_hex) {737const represents_null_character = ch === "0" && !is_octal(peek());738if (!represents_null_character) {739parse_error("Octal escape sequences are not allowed in template strings");740}741}742return read_octal_escape_sequence(ch, strict_hex);743}744return ch;745}746747function read_octal_escape_sequence(ch, strict_octal) {748// Read749var p = peek();750if (p >= "0" && p <= "7") {751ch += next(true);752if (ch[0] <= "3" && (p = peek()) >= "0" && p <= "7")753ch += next(true);754}755756// Parse757if (ch === "0") return "\0";758if (ch.length > 0 && next_token.has_directive("use strict") && strict_octal)759parse_error("Legacy octal escape sequences are not allowed in strict mode");760return String.fromCharCode(parseInt(ch, 8));761}762763function hex_bytes(n, strict_hex) {764var num = 0;765for (; n > 0; --n) {766if (!strict_hex && isNaN(parseInt(peek(), 16))) {767return parseInt(num, 16) || "";768}769var digit = next(true);770if (isNaN(parseInt(digit, 16)))771parse_error("Invalid hex-character pattern in string");772num += digit;773}774return parseInt(num, 16);775}776777var read_string = with_eof_error("Unterminated string constant", function() {778const start_pos = S.pos;779var quote = next(), ret = [];780for (;;) {781var ch = next(true, true);782if (ch == "\\") ch = read_escaped_char(true, true);783else if (ch == "\r" || ch == "\n") parse_error("Unterminated string constant");784else if (ch == quote) break;785ret.push(ch);786}787var tok = token("string", ret.join(""));788LATEST_RAW = S.text.slice(start_pos, S.pos);789tok.quote = quote;790return tok;791});792793var read_template_characters = with_eof_error("Unterminated template", function(begin) {794if (begin) {795S.template_braces.push(S.brace_counter);796}797var content = "", raw = "", ch, tok;798next(true, true);799while ((ch = next(true, true)) != "`") {800if (ch == "\r") {801if (peek() == "\n") ++S.pos;802ch = "\n";803} else if (ch == "$" && peek() == "{") {804next(true, true);805S.brace_counter++;806tok = token(begin ? "template_head" : "template_substitution", content);807TEMPLATE_RAWS.set(tok, raw);808tok.template_end = false;809return tok;810}811812raw += ch;813if (ch == "\\") {814var tmp = S.pos;815var prev_is_tag = previous_token && (previous_token.type === "name" || previous_token.type === "punc" && (previous_token.value === ")" || previous_token.value === "]"));816ch = read_escaped_char(true, !prev_is_tag, true);817raw += S.text.substr(tmp, S.pos - tmp);818}819820content += ch;821}822S.template_braces.pop();823tok = token(begin ? "template_head" : "template_substitution", content);824TEMPLATE_RAWS.set(tok, raw);825tok.template_end = true;826return tok;827});828829function skip_line_comment(type) {830var regex_allowed = S.regex_allowed;831var i = find_eol(), ret;832if (i == -1) {833ret = S.text.substr(S.pos);834S.pos = S.text.length;835} else {836ret = S.text.substring(S.pos, i);837S.pos = i;838}839S.col = S.tokcol + (S.pos - S.tokpos);840S.comments_before.push(token(type, ret, true));841S.regex_allowed = regex_allowed;842return next_token;843}844845var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function() {846var regex_allowed = S.regex_allowed;847var i = find("*/", true);848var text = S.text.substring(S.pos, i).replace(/\r\n|\r|\u2028|\u2029/g, "\n");849// update stream position850forward(get_full_char_length(text) /* text length doesn't count \r\n as 2 char while S.pos - i does */ + 2);851S.comments_before.push(token("comment2", text, true));852S.newline_before = S.newline_before || text.includes("\n");853S.regex_allowed = regex_allowed;854return next_token;855});856857var read_name = with_eof_error("Unterminated identifier name", function() {858var name = [], ch, escaped = false;859var read_escaped_identifier_char = function() {860escaped = true;861next();862if (peek() !== "u") {863parse_error("Expecting UnicodeEscapeSequence -- uXXXX or u{XXXX}");864}865return read_escaped_char(false, true);866};867868// Read first character (ID_Start)869if ((ch = peek()) === "\\") {870ch = read_escaped_identifier_char();871if (!is_identifier_start(ch)) {872parse_error("First identifier char is an invalid identifier char");873}874} else if (is_identifier_start(ch)) {875next();876} else {877return "";878}879880name.push(ch);881882// Read ID_Continue883while ((ch = peek()) != null) {884if ((ch = peek()) === "\\") {885ch = read_escaped_identifier_char();886if (!is_identifier_char(ch)) {887parse_error("Invalid escaped identifier char");888}889} else {890if (!is_identifier_char(ch)) {891break;892}893next();894}895name.push(ch);896}897const name_str = name.join("");898if (RESERVED_WORDS.has(name_str) && escaped) {899parse_error("Escaped characters are not allowed in keywords");900}901return name_str;902});903904var read_regexp = with_eof_error("Unterminated regular expression", function(source) {905var prev_backslash = false, ch, in_class = false;906while ((ch = next(true))) if (NEWLINE_CHARS.has(ch)) {907parse_error("Unexpected line terminator");908} else if (prev_backslash) {909source += "\\" + ch;910prev_backslash = false;911} else if (ch == "[") {912in_class = true;913source += ch;914} else if (ch == "]" && in_class) {915in_class = false;916source += ch;917} else if (ch == "/" && !in_class) {918break;919} else if (ch == "\\") {920prev_backslash = true;921} else {922source += ch;923}924const flags = read_name();925return token("regexp", "/" + source + "/" + flags);926});927928function read_operator(prefix) {929function grow(op) {930if (!peek()) return op;931var bigger = op + peek();932if (OPERATORS.has(bigger)) {933next();934return grow(bigger);935} else {936return op;937}938}939return token("operator", grow(prefix || next()));940}941942function handle_slash() {943next();944switch (peek()) {945case "/":946next();947return skip_line_comment("comment1");948case "*":949next();950return skip_multiline_comment();951}952return S.regex_allowed ? read_regexp("") : read_operator("/");953}954955function handle_eq_sign() {956next();957if (peek() === ">") {958next();959return token("arrow", "=>");960} else {961return read_operator("=");962}963}964965function handle_dot() {966next();967if (is_digit(peek().charCodeAt(0))) {968return read_num(".");969}970if (peek() === ".") {971next(); // Consume second dot972next(); // Consume third dot973return token("expand", "...");974}975976return token("punc", ".");977}978979function read_word() {980var word = read_name();981if (prev_was_dot) return token("name", word);982return KEYWORDS_ATOM.has(word) ? token("atom", word)983: !KEYWORDS.has(word) ? token("name", word)984: OPERATORS.has(word) ? token("operator", word)985: token("keyword", word);986}987988function read_private_word() {989next();990return token("privatename", read_name());991}992993function with_eof_error(eof_error, cont) {994return function(x) {995try {996return cont(x);997} catch(ex) {998if (ex === EX_EOF) parse_error(eof_error);999else throw ex;1000}1001};1002}10031004function next_token(force_regexp) {1005if (force_regexp != null)1006return read_regexp(force_regexp);1007if (shebang && S.pos == 0 && looking_at("#!")) {1008start_token();1009forward(2);1010skip_line_comment("comment5");1011}1012for (;;) {1013skip_whitespace();1014start_token();1015if (html5_comments) {1016if (looking_at("<!--")) {1017forward(4);1018skip_line_comment("comment3");1019continue;1020}1021if (looking_at("-->") && S.newline_before) {1022forward(3);1023skip_line_comment("comment4");1024continue;1025}1026}1027var ch = peek();1028if (!ch) return token("eof");1029var code = ch.charCodeAt(0);1030switch (code) {1031case 34: case 39: return read_string();1032case 46: return handle_dot();1033case 47: {1034var tok = handle_slash();1035if (tok === next_token) continue;1036return tok;1037}1038case 61: return handle_eq_sign();1039case 63: {1040if (!is_option_chain_op()) break; // Handled below10411042next(); // ?1043next(); // .10441045return token("punc", "?.");1046}1047case 96: return read_template_characters(true);1048case 123:1049S.brace_counter++;1050break;1051case 125:1052S.brace_counter--;1053if (S.template_braces.length > 01054&& S.template_braces[S.template_braces.length - 1] === S.brace_counter)1055return read_template_characters(false);1056break;1057}1058if (is_digit(code)) return read_num();1059if (PUNC_CHARS.has(ch)) return token("punc", next());1060if (OPERATOR_CHARS.has(ch)) return read_operator();1061if (code == 92 || is_identifier_start(ch)) return read_word();1062if (code == 35) return read_private_word();1063break;1064}1065parse_error("Unexpected character '" + ch + "'");1066}10671068next_token.next = next;1069next_token.peek = peek;10701071next_token.context = function(nc) {1072if (nc) S = nc;1073return S;1074};10751076next_token.add_directive = function(directive) {1077S.directive_stack[S.directive_stack.length - 1].push(directive);10781079if (S.directives[directive] === undefined) {1080S.directives[directive] = 1;1081} else {1082S.directives[directive]++;1083}1084};10851086next_token.push_directives_stack = function() {1087S.directive_stack.push([]);1088};10891090next_token.pop_directives_stack = function() {1091var directives = S.directive_stack[S.directive_stack.length - 1];10921093for (var i = 0; i < directives.length; i++) {1094S.directives[directives[i]]--;1095}10961097S.directive_stack.pop();1098};10991100next_token.has_directive = function(directive) {1101return S.directives[directive] > 0;1102};11031104return next_token;11051106}11071108/* -----[ Parser (constants) ]----- */11091110var UNARY_PREFIX = makePredicate([1111"typeof",1112"void",1113"delete",1114"--",1115"++",1116"!",1117"~",1118"-",1119"+"1120]);11211122var UNARY_POSTFIX = makePredicate([ "--", "++" ]);11231124var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "??=", "&&=", "||=", "/=", "*=", "**=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);11251126var LOGICAL_ASSIGNMENT = makePredicate([ "??=", "&&=", "||=" ]);11271128var PRECEDENCE = (function(a, ret) {1129for (var i = 0; i < a.length; ++i) {1130var b = a[i];1131for (var j = 0; j < b.length; ++j) {1132ret[b[j]] = i + 1;1133}1134}1135return ret;1136})(1137[1138["||"],1139["??"],1140["&&"],1141["|"],1142["^"],1143["&"],1144["==", "===", "!=", "!=="],1145["<", ">", "<=", ">=", "in", "instanceof"],1146[">>", "<<", ">>>"],1147["+", "-"],1148["*", "/", "%"],1149["**"]1150],1151{}1152);11531154var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "big_int", "string", "regexp", "name"]);11551156/* -----[ Parser ]----- */11571158function parse($TEXT, options) {1159// maps start tokens to count of comments found outside of their parens1160// Example: /* I count */ ( /* I don't */ foo() )1161// Useful because comments_before property of call with parens outside1162// contains both comments inside and outside these parens. Used to find the1163// right #__PURE__ comments for an expression1164const outer_comments_before_counts = new WeakMap();11651166options = defaults(options, {1167bare_returns : false,1168ecma : null, // Legacy1169expression : false,1170filename : null,1171html5_comments : true,1172module : false,1173shebang : true,1174strict : false,1175toplevel : null,1176}, true);11771178var S = {1179input : (typeof $TEXT == "string"1180? tokenizer($TEXT, options.filename,1181options.html5_comments, options.shebang)1182: $TEXT),1183token : null,1184prev : null,1185peeked : null,1186in_function : 0,1187in_async : -1,1188in_generator : -1,1189in_directives : true,1190in_loop : 0,1191labels : []1192};11931194S.token = next();11951196function is(type, value) {1197return is_token(S.token, type, value);1198}11991200function peek() { return S.peeked || (S.peeked = S.input()); }12011202function next() {1203S.prev = S.token;12041205if (!S.peeked) peek();1206S.token = S.peeked;1207S.peeked = null;1208S.in_directives = S.in_directives && (1209S.token.type == "string" || is("punc", ";")1210);1211return S.token;1212}12131214function prev() {1215return S.prev;1216}12171218function croak(msg, line, col, pos) {1219var ctx = S.input.context();1220js_error(msg,1221ctx.filename,1222line != null ? line : ctx.tokline,1223col != null ? col : ctx.tokcol,1224pos != null ? pos : ctx.tokpos);1225}12261227function token_error(token, msg) {1228croak(msg, token.line, token.col);1229}12301231function unexpected(token) {1232if (token == null)1233token = S.token;1234token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");1235}12361237function expect_token(type, val) {1238if (is(type, val)) {1239return next();1240}1241token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");1242}12431244function expect(punc) { return expect_token("punc", punc); }12451246function has_newline_before(token) {1247return token.nlb || !token.comments_before.every((comment) => !comment.nlb);1248}12491250function can_insert_semicolon() {1251return !options.strict1252&& (is("eof") || is("punc", "}") || has_newline_before(S.token));1253}12541255function is_in_generator() {1256return S.in_generator === S.in_function;1257}12581259function is_in_async() {1260return S.in_async === S.in_function;1261}12621263function can_await() {1264return (1265S.in_async === S.in_function1266|| S.in_function === 0 && S.input.has_directive("use strict")1267);1268}12691270function semicolon(optional) {1271if (is("punc", ";")) next();1272else if (!optional && !can_insert_semicolon()) unexpected();1273}12741275function parenthesised() {1276expect("(");1277var exp = expression(true);1278expect(")");1279return exp;1280}12811282function embed_tokens(parser) {1283return function _embed_tokens_wrapper(...args) {1284const start = S.token;1285const expr = parser(...args);1286expr.start = start;1287expr.end = prev();1288return expr;1289};1290}12911292function handle_regexp() {1293if (is("operator", "/") || is("operator", "/=")) {1294S.peeked = null;1295S.token = S.input(S.token.value.substr(1)); // force regexp1296}1297}12981299var statement = embed_tokens(function statement(is_export_default, is_for_body, is_if_body) {1300handle_regexp();1301switch (S.token.type) {1302case "string":1303if (S.in_directives) {1304var token = peek();1305if (!LATEST_RAW.includes("\\")1306&& (is_token(token, "punc", ";")1307|| is_token(token, "punc", "}")1308|| has_newline_before(token)1309|| is_token(token, "eof"))) {1310S.input.add_directive(S.token.value);1311} else {1312S.in_directives = false;1313}1314}1315var dir = S.in_directives, stat = simple_statement();1316return dir && stat.body instanceof AST_String ? new AST_Directive(stat.body) : stat;1317case "template_head":1318case "num":1319case "big_int":1320case "regexp":1321case "operator":1322case "atom":1323return simple_statement();13241325case "name":1326case "privatename":1327if(is("privatename") && !S.in_class)1328croak("Private field must be used in an enclosing class");13291330if (S.token.value == "async" && is_token(peek(), "keyword", "function")) {1331next();1332next();1333if (is_for_body) {1334croak("functions are not allowed as the body of a loop");1335}1336return function_(AST_Defun, false, true, is_export_default);1337}1338if (S.token.value == "import" && !is_token(peek(), "punc", "(") && !is_token(peek(), "punc", ".")) {1339next();1340var node = import_statement();1341semicolon();1342return node;1343}1344return is_token(peek(), "punc", ":")1345? labeled_statement()1346: simple_statement();13471348case "punc":1349switch (S.token.value) {1350case "{":1351return new AST_BlockStatement({1352start : S.token,1353body : block_(),1354end : prev()1355});1356case "[":1357case "(":1358return simple_statement();1359case ";":1360S.in_directives = false;1361next();1362return new AST_EmptyStatement();1363default:1364unexpected();1365}13661367case "keyword":1368switch (S.token.value) {1369case "break":1370next();1371return break_cont(AST_Break);13721373case "continue":1374next();1375return break_cont(AST_Continue);13761377case "debugger":1378next();1379semicolon();1380return new AST_Debugger();13811382case "do":1383next();1384var body = in_loop(statement);1385expect_token("keyword", "while");1386var condition = parenthesised();1387semicolon(true);1388return new AST_Do({1389body : body,1390condition : condition1391});13921393case "while":1394next();1395return new AST_While({1396condition : parenthesised(),1397body : in_loop(function() { return statement(false, true); })1398});13991400case "for":1401next();1402return for_();14031404case "class":1405next();1406if (is_for_body) {1407croak("classes are not allowed as the body of a loop");1408}1409if (is_if_body) {1410croak("classes are not allowed as the body of an if");1411}1412return class_(AST_DefClass, is_export_default);14131414case "function":1415next();1416if (is_for_body) {1417croak("functions are not allowed as the body of a loop");1418}1419return function_(AST_Defun, false, false, is_export_default);14201421case "if":1422next();1423return if_();14241425case "return":1426if (S.in_function == 0 && !options.bare_returns)1427croak("'return' outside of function");1428next();1429var value = null;1430if (is("punc", ";")) {1431next();1432} else if (!can_insert_semicolon()) {1433value = expression(true);1434semicolon();1435}1436return new AST_Return({1437value: value1438});14391440case "switch":1441next();1442return new AST_Switch({1443expression : parenthesised(),1444body : in_loop(switch_body_)1445});14461447case "throw":1448next();1449if (has_newline_before(S.token))1450croak("Illegal newline after 'throw'");1451var value = expression(true);1452semicolon();1453return new AST_Throw({1454value: value1455});14561457case "try":1458next();1459return try_();14601461case "var":1462next();1463var node = var_();1464semicolon();1465return node;14661467case "let":1468next();1469var node = let_();1470semicolon();1471return node;14721473case "const":1474next();1475var node = const_();1476semicolon();1477return node;14781479case "with":1480if (S.input.has_directive("use strict")) {1481croak("Strict mode may not include a with statement");1482}1483next();1484return new AST_With({1485expression : parenthesised(),1486body : statement()1487});14881489case "export":1490if (!is_token(peek(), "punc", "(")) {1491next();1492var node = export_statement();1493if (is("punc", ";")) semicolon();1494return node;1495}1496}1497}1498unexpected();1499});15001501function labeled_statement() {1502var label = as_symbol(AST_Label);1503if (label.name === "await" && is_in_async()) {1504token_error(S.prev, "await cannot be used as label inside async function");1505}1506if (S.labels.some((l) => l.name === label.name)) {1507// ECMA-262, 12.12: An ECMAScript program is considered1508// syntactically incorrect if it contains a1509// LabelledStatement that is enclosed by a1510// LabelledStatement with the same Identifier as label.1511croak("Label " + label.name + " defined twice");1512}1513expect(":");1514S.labels.push(label);1515var stat = statement();1516S.labels.pop();1517if (!(stat instanceof AST_IterationStatement)) {1518// check for `continue` that refers to this label.1519// those should be reported as syntax errors.1520// https://github.com/mishoo/UglifyJS2/issues/2871521label.references.forEach(function(ref) {1522if (ref instanceof AST_Continue) {1523ref = ref.label.start;1524croak("Continue label `" + label.name + "` refers to non-IterationStatement.",1525ref.line, ref.col, ref.pos);1526}1527});1528}1529return new AST_LabeledStatement({ body: stat, label: label });1530}15311532function simple_statement(tmp) {1533return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) });1534}15351536function break_cont(type) {1537var label = null, ldef;1538if (!can_insert_semicolon()) {1539label = as_symbol(AST_LabelRef, true);1540}1541if (label != null) {1542ldef = S.labels.find((l) => l.name === label.name);1543if (!ldef)1544croak("Undefined label " + label.name);1545label.thedef = ldef;1546} else if (S.in_loop == 0)1547croak(type.TYPE + " not inside a loop or switch");1548semicolon();1549var stat = new type({ label: label });1550if (ldef) ldef.references.push(stat);1551return stat;1552}15531554function for_() {1555var for_await_error = "`for await` invalid in this context";1556var await_tok = S.token;1557if (await_tok.type == "name" && await_tok.value == "await") {1558if (!can_await()) {1559token_error(await_tok, for_await_error);1560}1561next();1562} else {1563await_tok = false;1564}1565expect("(");1566var init = null;1567if (!is("punc", ";")) {1568init =1569is("keyword", "var") ? (next(), var_(true)) :1570is("keyword", "let") ? (next(), let_(true)) :1571is("keyword", "const") ? (next(), const_(true)) :1572expression(true, true);1573var is_in = is("operator", "in");1574var is_of = is("name", "of");1575if (await_tok && !is_of) {1576token_error(await_tok, for_await_error);1577}1578if (is_in || is_of) {1579if (init instanceof AST_Definitions) {1580if (init.definitions.length > 1)1581token_error(init.start, "Only one variable declaration allowed in for..in loop");1582} else if (!(is_assignable(init) || (init = to_destructuring(init)) instanceof AST_Destructuring)) {1583token_error(init.start, "Invalid left-hand side in for..in loop");1584}1585next();1586if (is_in) {1587return for_in(init);1588} else {1589return for_of(init, !!await_tok);1590}1591}1592} else if (await_tok) {1593token_error(await_tok, for_await_error);1594}1595return regular_for(init);1596}15971598function regular_for(init) {1599expect(";");1600var test = is("punc", ";") ? null : expression(true);1601expect(";");1602var step = is("punc", ")") ? null : expression(true);1603expect(")");1604return new AST_For({1605init : init,1606condition : test,1607step : step,1608body : in_loop(function() { return statement(false, true); })1609});1610}16111612function for_of(init, is_await) {1613var lhs = init instanceof AST_Definitions ? init.definitions[0].name : null;1614var obj = expression(true);1615expect(")");1616return new AST_ForOf({1617await : is_await,1618init : init,1619name : lhs,1620object : obj,1621body : in_loop(function() { return statement(false, true); })1622});1623}16241625function for_in(init) {1626var obj = expression(true);1627expect(")");1628return new AST_ForIn({1629init : init,1630object : obj,1631body : in_loop(function() { return statement(false, true); })1632});1633}16341635var arrow_function = function(start, argnames, is_async) {1636if (has_newline_before(S.token)) {1637croak("Unexpected newline before arrow (=>)");1638}16391640expect_token("arrow", "=>");16411642var body = _function_body(is("punc", "{"), false, is_async);16431644var end =1645body instanceof Array && body.length ? body[body.length - 1].end :1646body instanceof Array ? start :1647body.end;16481649return new AST_Arrow({1650start : start,1651end : end,1652async : is_async,1653argnames : argnames,1654body : body1655});1656};16571658var function_ = function(ctor, is_generator_property, is_async, is_export_default) {1659var in_statement = ctor === AST_Defun;1660var is_generator = is("operator", "*");1661if (is_generator) {1662next();1663}16641665var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;1666if (in_statement && !name) {1667if (is_export_default) {1668ctor = AST_Function;1669} else {1670unexpected();1671}1672}16731674if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))1675unexpected(prev());16761677var args = [];1678var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);1679return new ctor({1680start : args.start,1681end : body.end,1682is_generator: is_generator,1683async : is_async,1684name : name,1685argnames: args,1686body : body1687});1688};16891690class UsedParametersTracker {1691constructor(is_parameter, strict, duplicates_ok = false) {1692this.is_parameter = is_parameter;1693this.duplicates_ok = duplicates_ok;1694this.parameters = new Set();1695this.duplicate = null;1696this.default_assignment = false;1697this.spread = false;1698this.strict_mode = !!strict;1699}1700add_parameter(token) {1701if (this.parameters.has(token.value)) {1702if (this.duplicate === null) {1703this.duplicate = token;1704}1705this.check_strict();1706} else {1707this.parameters.add(token.value);1708if (this.is_parameter) {1709switch (token.value) {1710case "arguments":1711case "eval":1712case "yield":1713if (this.strict_mode) {1714token_error(token, "Unexpected " + token.value + " identifier as parameter inside strict mode");1715}1716break;1717default:1718if (RESERVED_WORDS.has(token.value)) {1719unexpected();1720}1721}1722}1723}1724}1725mark_default_assignment(token) {1726if (this.default_assignment === false) {1727this.default_assignment = token;1728}1729}1730mark_spread(token) {1731if (this.spread === false) {1732this.spread = token;1733}1734}1735mark_strict_mode() {1736this.strict_mode = true;1737}1738is_strict() {1739return this.default_assignment !== false || this.spread !== false || this.strict_mode;1740}1741check_strict() {1742if (this.is_strict() && this.duplicate !== null && !this.duplicates_ok) {1743token_error(this.duplicate, "Parameter " + this.duplicate.value + " was used already");1744}1745}1746}17471748function parameters(params) {1749var used_parameters = new UsedParametersTracker(true, S.input.has_directive("use strict"));17501751expect("(");17521753while (!is("punc", ")")) {1754var param = parameter(used_parameters);1755params.push(param);17561757if (!is("punc", ")")) {1758expect(",");1759}17601761if (param instanceof AST_Expansion) {1762break;1763}1764}17651766next();1767}17681769function parameter(used_parameters, symbol_type) {1770var param;1771var expand = false;1772if (used_parameters === undefined) {1773used_parameters = new UsedParametersTracker(true, S.input.has_directive("use strict"));1774}1775if (is("expand", "...")) {1776expand = S.token;1777used_parameters.mark_spread(S.token);1778next();1779}1780param = binding_element(used_parameters, symbol_type);17811782if (is("operator", "=") && expand === false) {1783used_parameters.mark_default_assignment(S.token);1784next();1785param = new AST_DefaultAssign({1786start: param.start,1787left: param,1788operator: "=",1789right: expression(false),1790end: S.token1791});1792}17931794if (expand !== false) {1795if (!is("punc", ")")) {1796unexpected();1797}1798param = new AST_Expansion({1799start: expand,1800expression: param,1801end: expand1802});1803}1804used_parameters.check_strict();18051806return param;1807}18081809function binding_element(used_parameters, symbol_type) {1810var elements = [];1811var first = true;1812var is_expand = false;1813var expand_token;1814var first_token = S.token;1815if (used_parameters === undefined) {1816const strict = S.input.has_directive("use strict");1817const duplicates_ok = symbol_type === AST_SymbolVar;1818used_parameters = new UsedParametersTracker(false, strict, duplicates_ok);1819}1820symbol_type = symbol_type === undefined ? AST_SymbolFunarg : symbol_type;1821if (is("punc", "[")) {1822next();1823while (!is("punc", "]")) {1824if (first) {1825first = false;1826} else {1827expect(",");1828}18291830if (is("expand", "...")) {1831is_expand = true;1832expand_token = S.token;1833used_parameters.mark_spread(S.token);1834next();1835}1836if (is("punc")) {1837switch (S.token.value) {1838case ",":1839elements.push(new AST_Hole({1840start: S.token,1841end: S.token1842}));1843continue;1844case "]": // Trailing comma after last element1845break;1846case "[":1847case "{":1848elements.push(binding_element(used_parameters, symbol_type));1849break;1850default:1851unexpected();1852}1853} else if (is("name")) {1854used_parameters.add_parameter(S.token);1855elements.push(as_symbol(symbol_type));1856} else {1857croak("Invalid function parameter");1858}1859if (is("operator", "=") && is_expand === false) {1860used_parameters.mark_default_assignment(S.token);1861next();1862elements[elements.length - 1] = new AST_DefaultAssign({1863start: elements[elements.length - 1].start,1864left: elements[elements.length - 1],1865operator: "=",1866right: expression(false),1867end: S.token1868});1869}1870if (is_expand) {1871if (!is("punc", "]")) {1872croak("Rest element must be last element");1873}1874elements[elements.length - 1] = new AST_Expansion({1875start: expand_token,1876expression: elements[elements.length - 1],1877end: expand_token1878});1879}1880}1881expect("]");1882used_parameters.check_strict();1883return new AST_Destructuring({1884start: first_token,1885names: elements,1886is_array: true,1887end: prev()1888});1889} else if (is("punc", "{")) {1890next();1891while (!is("punc", "}")) {1892if (first) {1893first = false;1894} else {1895expect(",");1896}1897if (is("expand", "...")) {1898is_expand = true;1899expand_token = S.token;1900used_parameters.mark_spread(S.token);1901next();1902}1903if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].includes(peek().value)) {1904used_parameters.add_parameter(S.token);1905var start = prev();1906var value = as_symbol(symbol_type);1907if (is_expand) {1908elements.push(new AST_Expansion({1909start: expand_token,1910expression: value,1911end: value.end,1912}));1913} else {1914elements.push(new AST_ObjectKeyVal({1915start: start,1916key: value.name,1917value: value,1918end: value.end,1919}));1920}1921} else if (is("punc", "}")) {1922continue; // Allow trailing hole1923} else {1924var property_token = S.token;1925var property = as_property_name();1926if (property === null) {1927unexpected(prev());1928} else if (prev().type === "name" && !is("punc", ":")) {1929elements.push(new AST_ObjectKeyVal({1930start: prev(),1931key: property,1932value: new symbol_type({1933start: prev(),1934name: property,1935end: prev()1936}),1937end: prev()1938}));1939} else {1940expect(":");1941elements.push(new AST_ObjectKeyVal({1942start: property_token,1943quote: property_token.quote,1944key: property,1945value: binding_element(used_parameters, symbol_type),1946end: prev()1947}));1948}1949}1950if (is_expand) {1951if (!is("punc", "}")) {1952croak("Rest element must be last element");1953}1954} else if (is("operator", "=")) {1955used_parameters.mark_default_assignment(S.token);1956next();1957elements[elements.length - 1].value = new AST_DefaultAssign({1958start: elements[elements.length - 1].value.start,1959left: elements[elements.length - 1].value,1960operator: "=",1961right: expression(false),1962end: S.token1963});1964}1965}1966expect("}");1967used_parameters.check_strict();1968return new AST_Destructuring({1969start: first_token,1970names: elements,1971is_array: false,1972end: prev()1973});1974} else if (is("name")) {1975used_parameters.add_parameter(S.token);1976return as_symbol(symbol_type);1977} else {1978croak("Invalid function parameter");1979}1980}19811982function params_or_seq_(allow_arrows, maybe_sequence) {1983var spread_token;1984var invalid_sequence;1985var trailing_comma;1986var a = [];1987expect("(");1988while (!is("punc", ")")) {1989if (spread_token) unexpected(spread_token);1990if (is("expand", "...")) {1991spread_token = S.token;1992if (maybe_sequence) invalid_sequence = S.token;1993next();1994a.push(new AST_Expansion({1995start: prev(),1996expression: expression(),1997end: S.token,1998}));1999} else {2000a.push(expression());2001}2002if (!is("punc", ")")) {2003expect(",");2004if (is("punc", ")")) {2005trailing_comma = prev();2006if (maybe_sequence) invalid_sequence = trailing_comma;2007}2008}2009}2010expect(")");2011if (allow_arrows && is("arrow", "=>")) {2012if (spread_token && trailing_comma) unexpected(trailing_comma);2013} else if (invalid_sequence) {2014unexpected(invalid_sequence);2015}2016return a;2017}20182019function _function_body(block, generator, is_async, name, args) {2020var loop = S.in_loop;2021var labels = S.labels;2022var current_generator = S.in_generator;2023var current_async = S.in_async;2024++S.in_function;2025if (generator)2026S.in_generator = S.in_function;2027if (is_async)2028S.in_async = S.in_function;2029if (args) parameters(args);2030if (block)2031S.in_directives = true;2032S.in_loop = 0;2033S.labels = [];2034if (block) {2035S.input.push_directives_stack();2036var a = block_();2037if (name) _verify_symbol(name);2038if (args) args.forEach(_verify_symbol);2039S.input.pop_directives_stack();2040} else {2041var a = [new AST_Return({2042start: S.token,2043value: expression(false),2044end: S.token2045})];2046}2047--S.in_function;2048S.in_loop = loop;2049S.labels = labels;2050S.in_generator = current_generator;2051S.in_async = current_async;2052return a;2053}20542055function _await_expression() {2056// Previous token must be "await" and not be interpreted as an identifier2057if (!can_await()) {2058croak("Unexpected await expression outside async function",2059S.prev.line, S.prev.col, S.prev.pos);2060}2061// the await expression is parsed as a unary expression in Babel2062return new AST_Await({2063start: prev(),2064end: S.token,2065expression : maybe_unary(true),2066});2067}20682069function _yield_expression() {2070// Previous token must be keyword yield and not be interpret as an identifier2071if (!is_in_generator()) {2072croak("Unexpected yield expression outside generator function",2073S.prev.line, S.prev.col, S.prev.pos);2074}2075var start = S.token;2076var star = false;2077var has_expression = true;20782079// Attempt to get expression or star (and then the mandatory expression)2080// behind yield on the same line.2081//2082// If nothing follows on the same line of the yieldExpression,2083// it should default to the value `undefined` for yield to return.2084// In that case, the `undefined` stored as `null` in ast.2085//2086// Note 1: It isn't allowed for yield* to close without an expression2087// Note 2: If there is a nlb between yield and star, it is interpret as2088// yield <explicit undefined> <inserted automatic semicolon> *2089if (can_insert_semicolon() ||2090(is("punc") && PUNC_AFTER_EXPRESSION.has(S.token.value))) {2091has_expression = false;20922093} else if (is("operator", "*")) {2094star = true;2095next();2096}20972098return new AST_Yield({2099start : start,2100is_star : star,2101expression : has_expression ? expression() : null,2102end : prev()2103});2104}21052106function if_() {2107var cond = parenthesised(), body = statement(false, false, true), belse = null;2108if (is("keyword", "else")) {2109next();2110belse = statement(false, false, true);2111}2112return new AST_If({2113condition : cond,2114body : body,2115alternative : belse2116});2117}21182119function block_() {2120expect("{");2121var a = [];2122while (!is("punc", "}")) {2123if (is("eof")) unexpected();2124a.push(statement());2125}2126next();2127return a;2128}21292130function switch_body_() {2131expect("{");2132var a = [], cur = null, branch = null, tmp;2133while (!is("punc", "}")) {2134if (is("eof")) unexpected();2135if (is("keyword", "case")) {2136if (branch) branch.end = prev();2137cur = [];2138branch = new AST_Case({2139start : (tmp = S.token, next(), tmp),2140expression : expression(true),2141body : cur2142});2143a.push(branch);2144expect(":");2145} else if (is("keyword", "default")) {2146if (branch) branch.end = prev();2147cur = [];2148branch = new AST_Default({2149start : (tmp = S.token, next(), expect(":"), tmp),2150body : cur2151});2152a.push(branch);2153} else {2154if (!cur) unexpected();2155cur.push(statement());2156}2157}2158if (branch) branch.end = prev();2159next();2160return a;2161}21622163function try_() {2164var body, bcatch = null, bfinally = null;2165body = new AST_TryBlock({2166start : S.token,2167body : block_(),2168end : prev(),2169});2170if (is("keyword", "catch")) {2171var start = S.token;2172next();2173if (is("punc", "{")) {2174var name = null;2175} else {2176expect("(");2177var name = parameter(undefined, AST_SymbolCatch);2178expect(")");2179}2180bcatch = new AST_Catch({2181start : start,2182argname : name,2183body : block_(),2184end : prev()2185});2186}2187if (is("keyword", "finally")) {2188var start = S.token;2189next();2190bfinally = new AST_Finally({2191start : start,2192body : block_(),2193end : prev()2194});2195}2196if (!bcatch && !bfinally)2197croak("Missing catch/finally blocks");2198return new AST_Try({2199body : body,2200bcatch : bcatch,2201bfinally : bfinally2202});2203}22042205/**2206* var2207* vardef1 = 2,2208* vardef2 = 3;2209*/2210function vardefs(no_in, kind) {2211var var_defs = [];2212var def;2213for (;;) {2214var sym_type =2215kind === "var" ? AST_SymbolVar :2216kind === "const" ? AST_SymbolConst :2217kind === "let" ? AST_SymbolLet : null;2218// var { a } = b2219if (is("punc", "{") || is("punc", "[")) {2220def = new AST_VarDef({2221start: S.token,2222name: binding_element(undefined, sym_type),2223value: is("operator", "=") ? (expect_token("operator", "="), expression(false, no_in)) : null,2224end: prev()2225});2226} else {2227def = new AST_VarDef({2228start : S.token,2229name : as_symbol(sym_type),2230value : is("operator", "=")2231? (next(), expression(false, no_in))2232: !no_in && kind === "const"2233? croak("Missing initializer in const declaration") : null,2234end : prev()2235});2236if (def.name.name == "import") croak("Unexpected token: import");2237}2238var_defs.push(def);2239if (!is("punc", ","))2240break;2241next();2242}2243return var_defs;2244}22452246var var_ = function(no_in) {2247return new AST_Var({2248start : prev(),2249definitions : vardefs(no_in, "var"),2250end : prev()2251});2252};22532254var let_ = function(no_in) {2255return new AST_Let({2256start : prev(),2257definitions : vardefs(no_in, "let"),2258end : prev()2259});2260};22612262var const_ = function(no_in) {2263return new AST_Const({2264start : prev(),2265definitions : vardefs(no_in, "const"),2266end : prev()2267});2268};22692270var new_ = function(allow_calls) {2271var start = S.token;2272expect_token("operator", "new");2273if (is("punc", ".")) {2274next();2275expect_token("name", "target");2276return subscripts(new AST_NewTarget({2277start : start,2278end : prev()2279}), allow_calls);2280}2281var newexp = expr_atom(false), args;2282if (is("punc", "(")) {2283next();2284args = expr_list(")", true);2285} else {2286args = [];2287}2288var call = new AST_New({2289start : start,2290expression : newexp,2291args : args,2292end : prev()2293});2294annotate(call);2295return subscripts(call, allow_calls);2296};22972298function as_atom_node() {2299var tok = S.token, ret;2300switch (tok.type) {2301case "name":2302ret = _make_symbol(AST_SymbolRef);2303break;2304case "num":2305ret = new AST_Number({2306start: tok,2307end: tok,2308value: tok.value,2309raw: LATEST_RAW2310});2311break;2312case "big_int":2313ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });2314break;2315case "string":2316ret = new AST_String({2317start : tok,2318end : tok,2319value : tok.value,2320quote : tok.quote2321});2322annotate(ret);2323break;2324case "regexp":2325const [_, source, flags] = tok.value.match(/^\/(.*)\/(\w*)$/);23262327ret = new AST_RegExp({ start: tok, end: tok, value: { source, flags } });2328break;2329case "atom":2330switch (tok.value) {2331case "false":2332ret = new AST_False({ start: tok, end: tok });2333break;2334case "true":2335ret = new AST_True({ start: tok, end: tok });2336break;2337case "null":2338ret = new AST_Null({ start: tok, end: tok });2339break;2340}2341break;2342}2343next();2344return ret;2345}23462347function to_fun_args(ex, default_seen_above) {2348var insert_default = function(ex, default_value) {2349if (default_value) {2350return new AST_DefaultAssign({2351start: ex.start,2352left: ex,2353operator: "=",2354right: default_value,2355end: default_value.end2356});2357}2358return ex;2359};2360if (ex instanceof AST_Object) {2361return insert_default(new AST_Destructuring({2362start: ex.start,2363end: ex.end,2364is_array: false,2365names: ex.properties.map(prop => to_fun_args(prop))2366}), default_seen_above);2367} else if (ex instanceof AST_ObjectKeyVal) {2368ex.value = to_fun_args(ex.value);2369return insert_default(ex, default_seen_above);2370} else if (ex instanceof AST_Hole) {2371return ex;2372} else if (ex instanceof AST_Destructuring) {2373ex.names = ex.names.map(name => to_fun_args(name));2374return insert_default(ex, default_seen_above);2375} else if (ex instanceof AST_SymbolRef) {2376return insert_default(new AST_SymbolFunarg({2377name: ex.name,2378start: ex.start,2379end: ex.end2380}), default_seen_above);2381} else if (ex instanceof AST_Expansion) {2382ex.expression = to_fun_args(ex.expression);2383return insert_default(ex, default_seen_above);2384} else if (ex instanceof AST_Array) {2385return insert_default(new AST_Destructuring({2386start: ex.start,2387end: ex.end,2388is_array: true,2389names: ex.elements.map(elm => to_fun_args(elm))2390}), default_seen_above);2391} else if (ex instanceof AST_Assign) {2392return insert_default(to_fun_args(ex.left, ex.right), default_seen_above);2393} else if (ex instanceof AST_DefaultAssign) {2394ex.left = to_fun_args(ex.left);2395return ex;2396} else {2397croak("Invalid function parameter", ex.start.line, ex.start.col);2398}2399}24002401var expr_atom = function(allow_calls, allow_arrows) {2402if (is("operator", "new")) {2403return new_(allow_calls);2404}2405if (is("name", "import") && is_token(peek(), "punc", ".")) {2406return import_meta(allow_calls);2407}2408var start = S.token;2409var peeked;2410var async = is("name", "async")2411&& (peeked = peek()).value != "["2412&& peeked.type != "arrow"2413&& as_atom_node();2414if (is("punc")) {2415switch (S.token.value) {2416case "(":2417if (async && !allow_calls) break;2418var exprs = params_or_seq_(allow_arrows, !async);2419if (allow_arrows && is("arrow", "=>")) {2420return arrow_function(start, exprs.map(e => to_fun_args(e)), !!async);2421}2422var ex = async ? new AST_Call({2423expression: async,2424args: exprs2425}) : exprs.length == 1 ? exprs[0] : new AST_Sequence({2426expressions: exprs2427});2428if (ex.start) {2429const outer_comments_before = start.comments_before.length;2430outer_comments_before_counts.set(start, outer_comments_before);2431ex.start.comments_before.unshift(...start.comments_before);2432start.comments_before = ex.start.comments_before;2433if (outer_comments_before == 0 && start.comments_before.length > 0) {2434var comment = start.comments_before[0];2435if (!comment.nlb) {2436comment.nlb = start.nlb;2437start.nlb = false;2438}2439}2440start.comments_after = ex.start.comments_after;2441}2442ex.start = start;2443var end = prev();2444if (ex.end) {2445end.comments_before = ex.end.comments_before;2446ex.end.comments_after.push(...end.comments_after);2447end.comments_after = ex.end.comments_after;2448}2449ex.end = end;2450if (ex instanceof AST_Call) annotate(ex);2451return subscripts(ex, allow_calls);2452case "[":2453return subscripts(array_(), allow_calls);2454case "{":2455return subscripts(object_or_destructuring_(), allow_calls);2456}2457if (!async) unexpected();2458}2459if (allow_arrows && is("name") && is_token(peek(), "arrow")) {2460var param = new AST_SymbolFunarg({2461name: S.token.value,2462start: start,2463end: start,2464});2465next();2466return arrow_function(start, [param], !!async);2467}2468if (is("keyword", "function")) {2469next();2470var func = function_(AST_Function, false, !!async);2471func.start = start;2472func.end = prev();2473return subscripts(func, allow_calls);2474}2475if (async) return subscripts(async, allow_calls);2476if (is("keyword", "class")) {2477next();2478var cls = class_(AST_ClassExpression);2479cls.start = start;2480cls.end = prev();2481return subscripts(cls, allow_calls);2482}2483if (is("template_head")) {2484return subscripts(template_string(), allow_calls);2485}2486if (is("privatename")) {2487if(!S.in_class) {2488croak("Private field must be used in an enclosing class");2489}24902491const start = S.token;2492const key = new AST_SymbolPrivateProperty({2493start,2494name: start.value,2495end: start2496});2497next();2498expect_token("operator", "in");24992500const private_in = new AST_PrivateIn({2501start,2502key,2503value: subscripts(as_atom_node(), allow_calls),2504end: prev()2505});25062507return subscripts(private_in, allow_calls);2508}2509if (ATOMIC_START_TOKEN.has(S.token.type)) {2510return subscripts(as_atom_node(), allow_calls);2511}2512unexpected();2513};25142515function template_string() {2516var segments = [], start = S.token;25172518segments.push(new AST_TemplateSegment({2519start: S.token,2520raw: TEMPLATE_RAWS.get(S.token),2521value: S.token.value,2522end: S.token2523}));25242525while (!S.token.template_end) {2526next();2527handle_regexp();2528segments.push(expression(true));25292530segments.push(new AST_TemplateSegment({2531start: S.token,2532raw: TEMPLATE_RAWS.get(S.token),2533value: S.token.value,2534end: S.token2535}));2536}2537next();25382539return new AST_TemplateString({2540start: start,2541segments: segments,2542end: S.token2543});2544}25452546function expr_list(closing, allow_trailing_comma, allow_empty) {2547var first = true, a = [];2548while (!is("punc", closing)) {2549if (first) first = false; else expect(",");2550if (allow_trailing_comma && is("punc", closing)) break;2551if (is("punc", ",") && allow_empty) {2552a.push(new AST_Hole({ start: S.token, end: S.token }));2553} else if (is("expand", "...")) {2554next();2555a.push(new AST_Expansion({start: prev(), expression: expression(),end: S.token}));2556} else {2557a.push(expression(false));2558}2559}2560next();2561return a;2562}25632564var array_ = embed_tokens(function() {2565expect("[");2566return new AST_Array({2567elements: expr_list("]", !options.strict, true)2568});2569});25702571var create_accessor = embed_tokens((is_generator, is_async) => {2572return function_(AST_Accessor, is_generator, is_async);2573});25742575var object_or_destructuring_ = embed_tokens(function object_or_destructuring_() {2576var start = S.token, first = true, a = [];2577expect("{");2578while (!is("punc", "}")) {2579if (first) first = false; else expect(",");2580if (!options.strict && is("punc", "}"))2581// allow trailing comma2582break;25832584start = S.token;2585if (start.type == "expand") {2586next();2587a.push(new AST_Expansion({2588start: start,2589expression: expression(false),2590end: prev(),2591}));2592continue;2593}2594if(is("privatename")) {2595croak("private fields are not allowed in an object");2596}2597var name = as_property_name();2598var value;25992600// Check property and fetch value2601if (!is("punc", ":")) {2602var concise = concise_method_or_getset(name, start);2603if (concise) {2604a.push(concise);2605continue;2606}26072608value = new AST_SymbolRef({2609start: prev(),2610name: name,2611end: prev()2612});2613} else if (name === null) {2614unexpected(prev());2615} else {2616next(); // `:` - see first condition2617value = expression(false);2618}26192620// Check for default value and alter value accordingly if necessary2621if (is("operator", "=")) {2622next();2623value = new AST_Assign({2624start: start,2625left: value,2626operator: "=",2627right: expression(false),2628logical: false,2629end: prev()2630});2631}26322633// Create property2634const kv = new AST_ObjectKeyVal({2635start: start,2636quote: start.quote,2637key: name instanceof AST_Node ? name : "" + name,2638value: value,2639end: prev()2640});2641a.push(annotate(kv));2642}2643next();2644return new AST_Object({ properties: a });2645});26462647function class_(KindOfClass, is_export_default) {2648var start, method, class_name, extends_, a = [];26492650S.input.push_directives_stack(); // Push directive stack, but not scope stack2651S.input.add_directive("use strict");26522653if (S.token.type == "name" && S.token.value != "extends") {2654class_name = as_symbol(KindOfClass === AST_DefClass ? AST_SymbolDefClass : AST_SymbolClass);2655}26562657if (KindOfClass === AST_DefClass && !class_name) {2658if (is_export_default) {2659KindOfClass = AST_ClassExpression;2660} else {2661unexpected();2662}2663}26642665if (S.token.value == "extends") {2666next();2667extends_ = expression(true);2668}26692670expect("{");2671// mark in class feild,2672const save_in_class = S.in_class;2673S.in_class = true;2674while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.2675while (!is("punc", "}")) {2676start = S.token;2677method = concise_method_or_getset(as_property_name(), start, true);2678if (!method) { unexpected(); }2679a.push(method);2680while (is("punc", ";")) { next(); }2681}2682// mark in class feild,2683S.in_class = save_in_class;26842685S.input.pop_directives_stack();26862687next();26882689return new KindOfClass({2690start: start,2691name: class_name,2692extends: extends_,2693properties: a,2694end: prev(),2695});2696}26972698function concise_method_or_getset(name, start, is_class) {2699const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => {2700if (typeof name === "string" || typeof name === "number") {2701return new SymbolClass({2702start,2703name: "" + name,2704end: prev()2705});2706} else if (name === null) {2707unexpected();2708}2709return name;2710};27112712const is_not_method_start = () =>2713!is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("punc", ";") && !is("operator", "=");27142715var is_async = false;2716var is_static = false;2717var is_generator = false;2718var is_private = false;2719var accessor_type = null;27202721if (is_class && name === "static" && is_not_method_start()) {2722const static_block = class_static_block();2723if (static_block != null) {2724return static_block;2725}2726is_static = true;2727name = as_property_name();2728}2729if (name === "async" && is_not_method_start()) {2730is_async = true;2731name = as_property_name();2732}2733if (prev().type === "operator" && prev().value === "*") {2734is_generator = true;2735name = as_property_name();2736}2737if ((name === "get" || name === "set") && is_not_method_start()) {2738accessor_type = name;2739name = as_property_name();2740}2741if (prev().type === "privatename") {2742is_private = true;2743}27442745const property_token = prev();27462747if (accessor_type != null) {2748if (!is_private) {2749const AccessorClass = accessor_type === "get"2750? AST_ObjectGetter2751: AST_ObjectSetter;27522753name = get_symbol_ast(name);2754return annotate(new AccessorClass({2755start,2756static: is_static,2757key: name,2758quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined,2759value: create_accessor(),2760end: prev()2761}));2762} else {2763const AccessorClass = accessor_type === "get"2764? AST_PrivateGetter2765: AST_PrivateSetter;27662767return annotate(new AccessorClass({2768start,2769static: is_static,2770key: get_symbol_ast(name),2771value: create_accessor(),2772end: prev(),2773}));2774}2775}27762777if (is("punc", "(")) {2778name = get_symbol_ast(name);2779const AST_MethodVariant = is_private2780? AST_PrivateMethod2781: AST_ConciseMethod;2782var node = new AST_MethodVariant({2783start : start,2784static : is_static,2785is_generator: is_generator,2786async : is_async,2787key : name,2788quote : name instanceof AST_SymbolMethod ?2789property_token.quote : undefined,2790value : create_accessor(is_generator, is_async),2791end : prev()2792});2793return annotate(node);2794}27952796if (is_class) {2797const key = get_symbol_ast(name, AST_SymbolClassProperty);2798const quote = key instanceof AST_SymbolClassProperty2799? property_token.quote2800: undefined;2801const AST_ClassPropertyVariant = is_private2802? AST_ClassPrivateProperty2803: AST_ClassProperty;2804if (is("operator", "=")) {2805next();2806return annotate(2807new AST_ClassPropertyVariant({2808start,2809static: is_static,2810quote,2811key,2812value: expression(false),2813end: prev()2814})2815);2816} else if (2817is("name")2818|| is("privatename")2819|| is("operator", "*")2820|| is("punc", ";")2821|| is("punc", "}")2822) {2823return annotate(2824new AST_ClassPropertyVariant({2825start,2826static: is_static,2827quote,2828key,2829end: prev()2830})2831);2832}2833}2834}28352836function class_static_block() {2837if (!is("punc", "{")) {2838return null;2839}28402841const start = S.token;2842const body = [];28432844next();28452846while (!is("punc", "}")) {2847body.push(statement());2848}28492850next();28512852return new AST_ClassStaticBlock({ start, body, end: prev() });2853}28542855function maybe_import_assertion() {2856if (is("name", "assert") && !has_newline_before(S.token)) {2857next();2858return object_or_destructuring_();2859}2860return null;2861}28622863function import_statement() {2864var start = prev();28652866var imported_name;2867var imported_names;2868if (is("name")) {2869imported_name = as_symbol(AST_SymbolImport);2870}28712872if (is("punc", ",")) {2873next();2874}28752876imported_names = map_names(true);28772878if (imported_names || imported_name) {2879expect_token("name", "from");2880}2881var mod_str = S.token;2882if (mod_str.type !== "string") {2883unexpected();2884}2885next();28862887const assert_clause = maybe_import_assertion();28882889return new AST_Import({2890start,2891imported_name,2892imported_names,2893module_name: new AST_String({2894start: mod_str,2895value: mod_str.value,2896quote: mod_str.quote,2897end: mod_str,2898}),2899assert_clause,2900end: S.token,2901});2902}29032904function import_meta(allow_calls) {2905var start = S.token;2906expect_token("name", "import");2907expect_token("punc", ".");2908expect_token("name", "meta");2909return subscripts(new AST_ImportMeta({2910start: start,2911end: prev()2912}), allow_calls);2913}29142915function map_name(is_import) {2916function make_symbol(type, quote) {2917return new type({2918name: as_property_name(),2919quote: quote || undefined,2920start: prev(),2921end: prev()2922});2923}29242925var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;2926var type = is_import ? AST_SymbolImport : AST_SymbolExport;2927var start = S.token;2928var foreign_name;2929var name;29302931if (is_import) {2932foreign_name = make_symbol(foreign_type, start.quote);2933} else {2934name = make_symbol(type, start.quote);2935}2936if (is("name", "as")) {2937next(); // The "as" word2938if (is_import) {2939name = make_symbol(type);2940} else {2941foreign_name = make_symbol(foreign_type, S.token.quote);2942}2943} else if (is_import) {2944name = new type(foreign_name);2945} else {2946foreign_name = new foreign_type(name);2947}29482949return new AST_NameMapping({2950start: start,2951foreign_name: foreign_name,2952name: name,2953end: prev(),2954});2955}29562957function map_nameAsterisk(is_import, import_or_export_foreign_name) {2958var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;2959var type = is_import ? AST_SymbolImport : AST_SymbolExport;2960var start = S.token;2961var name, foreign_name;2962var end = prev();29632964if (is_import) {2965name = import_or_export_foreign_name;2966} else {2967foreign_name = import_or_export_foreign_name;2968}29692970name = name || new type({2971start: start,2972name: "*",2973end: end,2974});29752976foreign_name = foreign_name || new foreign_type({2977start: start,2978name: "*",2979end: end,2980});29812982return new AST_NameMapping({2983start: start,2984foreign_name: foreign_name,2985name: name,2986end: end,2987});2988}29892990function map_names(is_import) {2991var names;2992if (is("punc", "{")) {2993next();2994names = [];2995while (!is("punc", "}")) {2996names.push(map_name(is_import));2997if (is("punc", ",")) {2998next();2999}3000}3001next();3002} else if (is("operator", "*")) {3003var name;3004next();3005if (is("name", "as")) {3006next(); // The "as" word3007name = is_import ? as_symbol(AST_SymbolImport) : as_symbol_or_string(AST_SymbolExportForeign);3008}3009names = [map_nameAsterisk(is_import, name)];3010}3011return names;3012}30133014function export_statement() {3015var start = S.token;3016var is_default;3017var exported_names;30183019if (is("keyword", "default")) {3020is_default = true;3021next();3022} else if (exported_names = map_names(false)) {3023if (is("name", "from")) {3024next();30253026var mod_str = S.token;3027if (mod_str.type !== "string") {3028unexpected();3029}3030next();30313032const assert_clause = maybe_import_assertion();30333034return new AST_Export({3035start: start,3036is_default: is_default,3037exported_names: exported_names,3038module_name: new AST_String({3039start: mod_str,3040value: mod_str.value,3041quote: mod_str.quote,3042end: mod_str,3043}),3044end: prev(),3045assert_clause3046});3047} else {3048return new AST_Export({3049start: start,3050is_default: is_default,3051exported_names: exported_names,3052end: prev(),3053});3054}3055}30563057var node;3058var exported_value;3059var exported_definition;3060if (is("punc", "{")3061|| is_default3062&& (is("keyword", "class") || is("keyword", "function"))3063&& is_token(peek(), "punc")) {3064exported_value = expression(false);3065semicolon();3066} else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {3067unexpected(node.start);3068} else if (3069node instanceof AST_Definitions3070|| node instanceof AST_Defun3071|| node instanceof AST_DefClass3072) {3073exported_definition = node;3074} else if (3075node instanceof AST_ClassExpression3076|| node instanceof AST_Function3077) {3078exported_value = node;3079} else if (node instanceof AST_SimpleStatement) {3080exported_value = node.body;3081} else {3082unexpected(node.start);3083}30843085return new AST_Export({3086start: start,3087is_default: is_default,3088exported_value: exported_value,3089exported_definition: exported_definition,3090end: prev(),3091assert_clause: null3092});3093}30943095function as_property_name() {3096var tmp = S.token;3097switch (tmp.type) {3098case "punc":3099if (tmp.value === "[") {3100next();3101var ex = expression(false);3102expect("]");3103return ex;3104} else unexpected(tmp);3105case "operator":3106if (tmp.value === "*") {3107next();3108return null;3109}3110if (!["delete", "in", "instanceof", "new", "typeof", "void"].includes(tmp.value)) {3111unexpected(tmp);3112}3113/* falls through */3114case "name":3115case "privatename":3116case "string":3117case "num":3118case "big_int":3119case "keyword":3120case "atom":3121next();3122return tmp.value;3123default:3124unexpected(tmp);3125}3126}31273128function as_name() {3129var tmp = S.token;3130if (tmp.type != "name" && tmp.type != "privatename") unexpected();3131next();3132return tmp.value;3133}31343135function _make_symbol(type) {3136var name = S.token.value;3137return new (name == "this" ? AST_This :3138name == "super" ? AST_Super :3139type)({3140name : String(name),3141start : S.token,3142end : S.token3143});3144}31453146function _verify_symbol(sym) {3147var name = sym.name;3148if (is_in_generator() && name == "yield") {3149token_error(sym.start, "Yield cannot be used as identifier inside generators");3150}3151if (S.input.has_directive("use strict")) {3152if (name == "yield") {3153token_error(sym.start, "Unexpected yield identifier inside strict mode");3154}3155if (sym instanceof AST_SymbolDeclaration && (name == "arguments" || name == "eval")) {3156token_error(sym.start, "Unexpected " + name + " in strict mode");3157}3158}3159}31603161function as_symbol(type, noerror) {3162if (!is("name")) {3163if (!noerror) croak("Name expected");3164return null;3165}3166var sym = _make_symbol(type);3167_verify_symbol(sym);3168next();3169return sym;3170}31713172function as_symbol_or_string(type) {3173if (!is("name")) {3174if (!is("string")) {3175croak("Name or string expected");3176}3177var tok = S.token;3178var ret = new type({3179start : tok,3180end : tok,3181name : tok.value,3182quote : tok.quote3183});3184next();3185return ret;3186}3187var sym = _make_symbol(type);3188_verify_symbol(sym);3189next();3190return sym;3191}31923193// Annotate AST_Call, AST_Lambda or AST_New with the special comments3194function annotate(node, before_token = node.start) {3195var comments = before_token.comments_before;3196const comments_outside_parens = outer_comments_before_counts.get(before_token);3197var i = comments_outside_parens != null ? comments_outside_parens : comments.length;3198while (--i >= 0) {3199var comment = comments[i];3200if (/[@#]__/.test(comment.value)) {3201if (/[@#]__PURE__/.test(comment.value)) {3202set_annotation(node, _PURE);3203break;3204}3205if (/[@#]__INLINE__/.test(comment.value)) {3206set_annotation(node, _INLINE);3207break;3208}3209if (/[@#]__NOINLINE__/.test(comment.value)) {3210set_annotation(node, _NOINLINE);3211break;3212}3213if (/[@#]__KEY__/.test(comment.value)) {3214set_annotation(node, _KEY);3215break;3216}3217if (/[@#]__MANGLE_PROP__/.test(comment.value)) {3218set_annotation(node, _MANGLEPROP);3219break;3220}3221}3222}3223return node;3224}32253226var subscripts = function(expr, allow_calls, is_chain) {3227var start = expr.start;3228if (is("punc", ".")) {3229next();3230if(is("privatename") && !S.in_class)3231croak("Private field must be used in an enclosing class");3232const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;3233return subscripts(new AST_DotVariant({3234start : start,3235expression : expr,3236optional : false,3237property : as_name(),3238end : prev()3239}), allow_calls, is_chain);3240}3241if (is("punc", "[")) {3242next();3243var prop = expression(true);3244expect("]");3245return subscripts(new AST_Sub({3246start : start,3247expression : expr,3248optional : false,3249property : prop,3250end : prev()3251}), allow_calls, is_chain);3252}3253if (allow_calls && is("punc", "(")) {3254next();3255var call = new AST_Call({3256start : start,3257expression : expr,3258optional : false,3259args : call_args(),3260end : prev()3261});3262annotate(call);3263return subscripts(call, true, is_chain);3264}32653266if (is("punc", "?.")) {3267next();32683269let chain_contents;32703271if (allow_calls && is("punc", "(")) {3272next();32733274const call = new AST_Call({3275start,3276optional: true,3277expression: expr,3278args: call_args(),3279end: prev()3280});3281annotate(call);32823283chain_contents = subscripts(call, true, true);3284} else if (is("name") || is("privatename")) {3285if(is("privatename") && !S.in_class)3286croak("Private field must be used in an enclosing class");3287const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;3288chain_contents = subscripts(new AST_DotVariant({3289start,3290expression: expr,3291optional: true,3292property: as_name(),3293end: prev()3294}), allow_calls, true);3295} else if (is("punc", "[")) {3296next();3297const property = expression(true);3298expect("]");3299chain_contents = subscripts(new AST_Sub({3300start,3301expression: expr,3302optional: true,3303property,3304end: prev()3305}), allow_calls, true);3306}33073308if (!chain_contents) unexpected();33093310if (chain_contents instanceof AST_Chain) return chain_contents;33113312return new AST_Chain({3313start,3314expression: chain_contents,3315end: prev()3316});3317}33183319if (is("template_head")) {3320if (is_chain) {3321// a?.b`c` is a syntax error3322unexpected();3323}33243325return subscripts(new AST_PrefixedTemplateString({3326start: start,3327prefix: expr,3328template_string: template_string(),3329end: prev()3330}), allow_calls);3331}3332return expr;3333};33343335function call_args() {3336var args = [];3337while (!is("punc", ")")) {3338if (is("expand", "...")) {3339next();3340args.push(new AST_Expansion({3341start: prev(),3342expression: expression(false),3343end: prev()3344}));3345} else {3346args.push(expression(false));3347}3348if (!is("punc", ")")) {3349expect(",");3350}3351}3352next();3353return args;3354}33553356var maybe_unary = function(allow_calls, allow_arrows) {3357var start = S.token;3358if (start.type == "name" && start.value == "await" && can_await()) {3359next();3360return _await_expression();3361}3362if (is("operator") && UNARY_PREFIX.has(start.value)) {3363next();3364handle_regexp();3365var ex = make_unary(AST_UnaryPrefix, start, maybe_unary(allow_calls));3366ex.start = start;3367ex.end = prev();3368return ex;3369}3370var val = expr_atom(allow_calls, allow_arrows);3371while (is("operator") && UNARY_POSTFIX.has(S.token.value) && !has_newline_before(S.token)) {3372if (val instanceof AST_Arrow) unexpected();3373val = make_unary(AST_UnaryPostfix, S.token, val);3374val.start = start;3375val.end = S.token;3376next();3377}3378return val;3379};33803381function make_unary(ctor, token, expr) {3382var op = token.value;3383switch (op) {3384case "++":3385case "--":3386if (!is_assignable(expr))3387croak("Invalid use of " + op + " operator", token.line, token.col, token.pos);3388break;3389case "delete":3390if (expr instanceof AST_SymbolRef && S.input.has_directive("use strict"))3391croak("Calling delete on expression not allowed in strict mode", expr.start.line, expr.start.col, expr.start.pos);3392break;3393}3394return new ctor({ operator: op, expression: expr });3395}33963397var expr_op = function(left, min_prec, no_in) {3398var op = is("operator") ? S.token.value : null;3399if (op == "in" && no_in) op = null;3400if (op == "**" && left instanceof AST_UnaryPrefix3401/* unary token in front not allowed - parenthesis required */3402&& !is_token(left.start, "punc", "(")3403&& left.operator !== "--" && left.operator !== "++")3404unexpected(left.start);3405var prec = op != null ? PRECEDENCE[op] : null;3406if (prec != null && (prec > min_prec || (op === "**" && min_prec === prec))) {3407next();3408var right = expr_op(maybe_unary(true), prec, no_in);3409return expr_op(new AST_Binary({3410start : left.start,3411left : left,3412operator : op,3413right : right,3414end : right.end3415}), min_prec, no_in);3416}3417return left;3418};34193420function expr_ops(no_in) {3421return expr_op(maybe_unary(true, true), 0, no_in);3422}34233424var maybe_conditional = function(no_in) {3425var start = S.token;3426var expr = expr_ops(no_in);3427if (is("operator", "?")) {3428next();3429var yes = expression(false);3430expect(":");3431return new AST_Conditional({3432start : start,3433condition : expr,3434consequent : yes,3435alternative : expression(false, no_in),3436end : prev()3437});3438}3439return expr;3440};34413442function is_assignable(expr) {3443return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef;3444}34453446function to_destructuring(node) {3447if (node instanceof AST_Object) {3448node = new AST_Destructuring({3449start: node.start,3450names: node.properties.map(to_destructuring),3451is_array: false,3452end: node.end3453});3454} else if (node instanceof AST_Array) {3455var names = [];34563457for (var i = 0; i < node.elements.length; i++) {3458// Only allow expansion as last element3459if (node.elements[i] instanceof AST_Expansion) {3460if (i + 1 !== node.elements.length) {3461token_error(node.elements[i].start, "Spread must the be last element in destructuring array");3462}3463node.elements[i].expression = to_destructuring(node.elements[i].expression);3464}34653466names.push(to_destructuring(node.elements[i]));3467}34683469node = new AST_Destructuring({3470start: node.start,3471names: names,3472is_array: true,3473end: node.end3474});3475} else if (node instanceof AST_ObjectProperty) {3476node.value = to_destructuring(node.value);3477} else if (node instanceof AST_Assign) {3478node = new AST_DefaultAssign({3479start: node.start,3480left: node.left,3481operator: "=",3482right: node.right,3483end: node.end3484});3485}3486return node;3487}34883489// In ES6, AssignmentExpression can also be an ArrowFunction3490var maybe_assign = function(no_in) {3491handle_regexp();3492var start = S.token;34933494if (start.type == "name" && start.value == "yield") {3495if (is_in_generator()) {3496next();3497return _yield_expression();3498} else if (S.input.has_directive("use strict")) {3499token_error(S.token, "Unexpected yield identifier inside strict mode");3500}3501}35023503var left = maybe_conditional(no_in);3504var val = S.token.value;35053506if (is("operator") && ASSIGNMENT.has(val)) {3507if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {3508next();35093510return new AST_Assign({3511start : start,3512left : left,3513operator : val,3514right : maybe_assign(no_in),3515logical : LOGICAL_ASSIGNMENT.has(val),3516end : prev()3517});3518}3519croak("Invalid assignment");3520}3521return left;3522};35233524var expression = function(commas, no_in) {3525var start = S.token;3526var exprs = [];3527while (true) {3528exprs.push(maybe_assign(no_in));3529if (!commas || !is("punc", ",")) break;3530next();3531commas = true;3532}3533return exprs.length == 1 ? exprs[0] : new AST_Sequence({3534start : start,3535expressions : exprs,3536end : peek()3537});3538};35393540function in_loop(cont) {3541++S.in_loop;3542var ret = cont();3543--S.in_loop;3544return ret;3545}35463547if (options.expression) {3548return expression(true);3549}35503551return (function parse_toplevel() {3552var start = S.token;3553var body = [];3554S.input.push_directives_stack();3555if (options.module) S.input.add_directive("use strict");3556while (!is("eof")) {3557body.push(statement());3558}3559S.input.pop_directives_stack();3560var end = prev();3561var toplevel = options.toplevel;3562if (toplevel) {3563toplevel.body = toplevel.body.concat(body);3564toplevel.end = end;3565} else {3566toplevel = new AST_Toplevel({ start: start, body: body, end: end });3567}3568TEMPLATE_RAWS = new Map();3569return toplevel;3570})();35713572}35733574/***********************************************************************35753576A JavaScript tokenizer / parser / beautifier / compressor.3577https://github.com/mishoo/UglifyJS235783579-------------------------------- (C) ---------------------------------35803581Author: Mihai Bazon3582<[email protected]>3583http://mihai.bazon.net/blog35843585Distributed under the BSD license:35863587Copyright 2012 (c) Mihai Bazon <[email protected]>35883589Redistribution and use in source and binary forms, with or without3590modification, are permitted provided that the following conditions3591are met:35923593* Redistributions of source code must retain the above3594copyright notice, this list of conditions and the following3595disclaimer.35963597* Redistributions in binary form must reproduce the above3598copyright notice, this list of conditions and the following3599disclaimer in the documentation and/or other materials3600provided with the distribution.36013602THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY3603EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE3604IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR3605PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE3606LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,3607OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,3608PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR3609PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY3610THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR3611TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF3612THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF3613SUCH DAMAGE.36143615***********************************************************************/36163617function DEFNODE(type, props, ctor, methods, base = AST_Node) {3618if (!props) props = [];3619else props = props.split(/\s+/);3620var self_props = props;3621if (base && base.PROPS)3622props = props.concat(base.PROPS);3623const proto = base && Object.create(base.prototype);3624if (proto) {3625ctor.prototype = proto;3626ctor.BASE = base;3627}3628if (base) base.SUBCLASSES.push(ctor);3629ctor.prototype.CTOR = ctor;3630ctor.prototype.constructor = ctor;3631ctor.PROPS = props || null;3632ctor.SELF_PROPS = self_props;3633ctor.SUBCLASSES = [];3634if (type) {3635ctor.prototype.TYPE = ctor.TYPE = type;3636}3637if (methods) for (let i in methods) if (HOP(methods, i)) {3638if (i[0] === "$") {3639ctor[i.substr(1)] = methods[i];3640} else {3641ctor.prototype[i] = methods[i];3642}3643}3644ctor.DEFMETHOD = function(name, method) {3645this.prototype[name] = method;3646};3647return ctor;3648}36493650const has_tok_flag = (tok, flag) => Boolean(tok.flags & flag);3651const set_tok_flag = (tok, flag, truth) => {3652if (truth) {3653tok.flags |= flag;3654} else {3655tok.flags &= ~flag;3656}3657};36583659const TOK_FLAG_NLB = 0b0001;3660const TOK_FLAG_QUOTE_SINGLE = 0b0010;3661const TOK_FLAG_QUOTE_EXISTS = 0b0100;3662const TOK_FLAG_TEMPLATE_END = 0b1000;36633664class AST_Token {3665constructor(type, value, line, col, pos, nlb, comments_before, comments_after, file) {3666this.flags = (nlb ? 1 : 0);36673668this.type = type;3669this.value = value;3670this.line = line;3671this.col = col;3672this.pos = pos;3673this.comments_before = comments_before;3674this.comments_after = comments_after;3675this.file = file;36763677Object.seal(this);3678}36793680// Return a string summary of the token for node.js console.log3681[Symbol.for("nodejs.util.inspect.custom")](_depth, options) {3682const special = str => options.stylize(str, "special");3683const quote = typeof this.value === "string" && this.value.includes("`") ? "'" : "`";3684const value = `${quote}${this.value}${quote}`;3685return `${special("[AST_Token")} ${value} at ${this.line}:${this.col}${special("]")}`;3686}36873688get nlb() {3689return has_tok_flag(this, TOK_FLAG_NLB);3690}36913692set nlb(new_nlb) {3693set_tok_flag(this, TOK_FLAG_NLB, new_nlb);3694}36953696get quote() {3697return !has_tok_flag(this, TOK_FLAG_QUOTE_EXISTS)3698? ""3699: (has_tok_flag(this, TOK_FLAG_QUOTE_SINGLE) ? "'" : '"');3700}37013702set quote(quote_type) {3703set_tok_flag(this, TOK_FLAG_QUOTE_SINGLE, quote_type === "'");3704set_tok_flag(this, TOK_FLAG_QUOTE_EXISTS, !!quote_type);3705}37063707get template_end() {3708return has_tok_flag(this, TOK_FLAG_TEMPLATE_END);3709}37103711set template_end(new_template_end) {3712set_tok_flag(this, TOK_FLAG_TEMPLATE_END, new_template_end);3713}3714}37153716var AST_Node = DEFNODE("Node", "start end", function AST_Node(props) {3717if (props) {3718this.start = props.start;3719this.end = props.end;3720}37213722this.flags = 0;3723}, {3724_clone: function(deep) {3725if (deep) {3726var self = this.clone();3727return self.transform(new TreeTransformer(function(node) {3728if (node !== self) {3729return node.clone(true);3730}3731}));3732}3733return new this.CTOR(this);3734},3735clone: function(deep) {3736return this._clone(deep);3737},3738$documentation: "Base class of all AST nodes",3739$propdoc: {3740start: "[AST_Token] The first token of this node",3741end: "[AST_Token] The last token of this node"3742},3743_walk: function(visitor) {3744return visitor._visit(this);3745},3746walk: function(visitor) {3747return this._walk(visitor); // not sure the indirection will be any help3748},3749_children_backwards: () => {}3750}, null);37513752/* -----[ statements ]----- */37533754var AST_Statement = DEFNODE("Statement", null, function AST_Statement(props) {3755if (props) {3756this.start = props.start;3757this.end = props.end;3758}37593760this.flags = 0;3761}, {3762$documentation: "Base class of all statements",3763});37643765var AST_Debugger = DEFNODE("Debugger", null, function AST_Debugger(props) {3766if (props) {3767this.start = props.start;3768this.end = props.end;3769}37703771this.flags = 0;3772}, {3773$documentation: "Represents a debugger statement",3774}, AST_Statement);37753776var AST_Directive = DEFNODE("Directive", "value quote", function AST_Directive(props) {3777if (props) {3778this.value = props.value;3779this.quote = props.quote;3780this.start = props.start;3781this.end = props.end;3782}37833784this.flags = 0;3785}, {3786$documentation: "Represents a directive, like \"use strict\";",3787$propdoc: {3788value: "[string] The value of this directive as a plain string (it's not an AST_String!)",3789quote: "[string] the original quote character"3790},3791}, AST_Statement);37923793var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", function AST_SimpleStatement(props) {3794if (props) {3795this.body = props.body;3796this.start = props.start;3797this.end = props.end;3798}37993800this.flags = 0;3801}, {3802$documentation: "A statement consisting of an expression, i.e. a = 1 + 2",3803$propdoc: {3804body: "[AST_Node] an expression node (should not be instanceof AST_Statement)"3805},3806_walk: function(visitor) {3807return visitor._visit(this, function() {3808this.body._walk(visitor);3809});3810},3811_children_backwards(push) {3812push(this.body);3813}3814}, AST_Statement);38153816// XXX Emscripten localmod: Add a node type for a parenthesized expression so that we can retain3817// Closure annotations that need a form "/**annotation*/(expression)"3818var AST_ParenthesizedExpression = DEFNODE("ParenthesizedExpression", "body", function AST_ParenthesizedExpression(props) {3819if (props) {3820this.body = props.body;3821this.start = props.start;3822this.end = props.end;3823}38243825this.flags = 0;3826}, {3827$documentation: "An explicitly parenthesized expression, i.e. a = (1 + 2)",3828$propdoc: {3829body: "[AST_Node] an expression node (should not be instanceof AST_Statement)"3830},3831_walk: function(visitor) {3832return visitor._visit(this, function() {3833this.body._walk(visitor);3834});3835}3836}, AST_Statement);3837// XXX End of Emscripten localmod38383839function walk_body(node, visitor) {3840const body = node.body;3841for (var i = 0, len = body.length; i < len; i++) {3842body[i]._walk(visitor);3843}3844}38453846function clone_block_scope(deep) {3847var clone = this._clone(deep);3848if (this.block_scope) {3849clone.block_scope = this.block_scope.clone();3850}3851return clone;3852}38533854var AST_Block = DEFNODE("Block", "body block_scope", function AST_Block(props) {3855if (props) {3856this.body = props.body;3857this.block_scope = props.block_scope;3858this.start = props.start;3859this.end = props.end;3860}38613862this.flags = 0;3863}, {3864$documentation: "A body of statements (usually braced)",3865$propdoc: {3866body: "[AST_Statement*] an array of statements",3867block_scope: "[AST_Scope] the block scope"3868},3869_walk: function(visitor) {3870return visitor._visit(this, function() {3871walk_body(this, visitor);3872});3873},3874_children_backwards(push) {3875let i = this.body.length;3876while (i--) push(this.body[i]);3877},3878clone: clone_block_scope3879}, AST_Statement);38803881var AST_BlockStatement = DEFNODE("BlockStatement", null, function AST_BlockStatement(props) {3882if (props) {3883this.body = props.body;3884this.block_scope = props.block_scope;3885this.start = props.start;3886this.end = props.end;3887}38883889this.flags = 0;3890}, {3891$documentation: "A block statement",3892}, AST_Block);38933894var AST_EmptyStatement = DEFNODE("EmptyStatement", null, function AST_EmptyStatement(props) {3895if (props) {3896this.start = props.start;3897this.end = props.end;3898}38993900this.flags = 0;3901}, {3902$documentation: "The empty statement (empty block or simply a semicolon)"3903}, AST_Statement);39043905var AST_StatementWithBody = DEFNODE("StatementWithBody", "body", function AST_StatementWithBody(props) {3906if (props) {3907this.body = props.body;3908this.start = props.start;3909this.end = props.end;3910}39113912this.flags = 0;3913}, {3914$documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`",3915$propdoc: {3916body: "[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement"3917}3918}, AST_Statement);39193920var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", function AST_LabeledStatement(props) {3921if (props) {3922this.label = props.label;3923this.body = props.body;3924this.start = props.start;3925this.end = props.end;3926}39273928this.flags = 0;3929}, {3930$documentation: "Statement with a label",3931$propdoc: {3932label: "[AST_Label] a label definition"3933},3934_walk: function(visitor) {3935return visitor._visit(this, function() {3936this.label._walk(visitor);3937this.body._walk(visitor);3938});3939},3940_children_backwards(push) {3941push(this.body);3942push(this.label);3943},3944clone: function(deep) {3945var node = this._clone(deep);3946if (deep) {3947var label = node.label;3948var def = this.label;3949node.walk(new TreeWalker(function(node) {3950if (node instanceof AST_LoopControl3951&& node.label && node.label.thedef === def) {3952node.label.thedef = label;3953label.references.push(node);3954}3955}));3956}3957return node;3958}3959}, AST_StatementWithBody);39603961var AST_IterationStatement = DEFNODE(3962"IterationStatement",3963"block_scope",3964function AST_IterationStatement(props) {3965if (props) {3966this.block_scope = props.block_scope;3967this.body = props.body;3968this.start = props.start;3969this.end = props.end;3970}39713972this.flags = 0;3973},3974{3975$documentation: "Internal class. All loops inherit from it.",3976$propdoc: {3977block_scope: "[AST_Scope] the block scope for this iteration statement."3978},3979clone: clone_block_scope3980},3981AST_StatementWithBody3982);39833984var AST_DWLoop = DEFNODE("DWLoop", "condition", function AST_DWLoop(props) {3985if (props) {3986this.condition = props.condition;3987this.block_scope = props.block_scope;3988this.body = props.body;3989this.start = props.start;3990this.end = props.end;3991}39923993this.flags = 0;3994}, {3995$documentation: "Base class for do/while statements",3996$propdoc: {3997condition: "[AST_Node] the loop condition. Should not be instanceof AST_Statement"3998}3999}, AST_IterationStatement);40004001var AST_Do = DEFNODE("Do", null, function AST_Do(props) {4002if (props) {4003this.condition = props.condition;4004this.block_scope = props.block_scope;4005this.body = props.body;4006this.start = props.start;4007this.end = props.end;4008}40094010this.flags = 0;4011}, {4012$documentation: "A `do` statement",4013_walk: function(visitor) {4014return visitor._visit(this, function() {4015this.body._walk(visitor);4016this.condition._walk(visitor);4017});4018},4019_children_backwards(push) {4020push(this.condition);4021push(this.body);4022}4023}, AST_DWLoop);40244025var AST_While = DEFNODE("While", null, function AST_While(props) {4026if (props) {4027this.condition = props.condition;4028this.block_scope = props.block_scope;4029this.body = props.body;4030this.start = props.start;4031this.end = props.end;4032}40334034this.flags = 0;4035}, {4036$documentation: "A `while` statement",4037_walk: function(visitor) {4038return visitor._visit(this, function() {4039this.condition._walk(visitor);4040this.body._walk(visitor);4041});4042},4043_children_backwards(push) {4044push(this.body);4045push(this.condition);4046},4047}, AST_DWLoop);40484049var AST_For = DEFNODE("For", "init condition step", function AST_For(props) {4050if (props) {4051this.init = props.init;4052this.condition = props.condition;4053this.step = props.step;4054this.block_scope = props.block_scope;4055this.body = props.body;4056this.start = props.start;4057this.end = props.end;4058}40594060this.flags = 0;4061}, {4062$documentation: "A `for` statement",4063$propdoc: {4064init: "[AST_Node?] the `for` initialization code, or null if empty",4065condition: "[AST_Node?] the `for` termination clause, or null if empty",4066step: "[AST_Node?] the `for` update clause, or null if empty"4067},4068_walk: function(visitor) {4069return visitor._visit(this, function() {4070if (this.init) this.init._walk(visitor);4071if (this.condition) this.condition._walk(visitor);4072if (this.step) this.step._walk(visitor);4073this.body._walk(visitor);4074});4075},4076_children_backwards(push) {4077push(this.body);4078if (this.step) push(this.step);4079if (this.condition) push(this.condition);4080if (this.init) push(this.init);4081},4082}, AST_IterationStatement);40834084var AST_ForIn = DEFNODE("ForIn", "init object", function AST_ForIn(props) {4085if (props) {4086this.init = props.init;4087this.object = props.object;4088this.block_scope = props.block_scope;4089this.body = props.body;4090this.start = props.start;4091this.end = props.end;4092}40934094this.flags = 0;4095}, {4096$documentation: "A `for ... in` statement",4097$propdoc: {4098init: "[AST_Node] the `for/in` initialization code",4099object: "[AST_Node] the object that we're looping through"4100},4101_walk: function(visitor) {4102return visitor._visit(this, function() {4103this.init._walk(visitor);4104this.object._walk(visitor);4105this.body._walk(visitor);4106});4107},4108_children_backwards(push) {4109push(this.body);4110if (this.object) push(this.object);4111if (this.init) push(this.init);4112},4113}, AST_IterationStatement);41144115var AST_ForOf = DEFNODE("ForOf", "await", function AST_ForOf(props) {4116if (props) {4117this.await = props.await;4118this.init = props.init;4119this.object = props.object;4120this.block_scope = props.block_scope;4121this.body = props.body;4122this.start = props.start;4123this.end = props.end;4124}41254126this.flags = 0;4127}, {4128$documentation: "A `for ... of` statement",4129}, AST_ForIn);41304131var AST_With = DEFNODE("With", "expression", function AST_With(props) {4132if (props) {4133this.expression = props.expression;4134this.body = props.body;4135this.start = props.start;4136this.end = props.end;4137}41384139this.flags = 0;4140}, {4141$documentation: "A `with` statement",4142$propdoc: {4143expression: "[AST_Node] the `with` expression"4144},4145_walk: function(visitor) {4146return visitor._visit(this, function() {4147this.expression._walk(visitor);4148this.body._walk(visitor);4149});4150},4151_children_backwards(push) {4152push(this.body);4153push(this.expression);4154},4155}, AST_StatementWithBody);41564157/* -----[ scope and functions ]----- */41584159var AST_Scope = DEFNODE(4160"Scope",4161"variables uses_with uses_eval parent_scope enclosed cname",4162function AST_Scope(props) {4163if (props) {4164this.variables = props.variables;4165this.uses_with = props.uses_with;4166this.uses_eval = props.uses_eval;4167this.parent_scope = props.parent_scope;4168this.enclosed = props.enclosed;4169this.cname = props.cname;4170this.body = props.body;4171this.block_scope = props.block_scope;4172this.start = props.start;4173this.end = props.end;4174}41754176this.flags = 0;4177},4178{4179$documentation: "Base class for all statements introducing a lexical scope",4180$propdoc: {4181variables: "[Map/S] a map of name -> SymbolDef for all variables/functions defined in this scope",4182uses_with: "[boolean/S] tells whether this scope uses the `with` statement",4183uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`",4184parent_scope: "[AST_Scope?/S] link to the parent scope",4185enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",4186cname: "[integer/S] current index for mangling variables (used internally by the mangler)",4187},4188get_defun_scope: function() {4189var self = this;4190while (self.is_block_scope()) {4191self = self.parent_scope;4192}4193return self;4194},4195clone: function(deep, toplevel) {4196var node = this._clone(deep);4197if (deep && this.variables && toplevel && !this._block_scope) {4198node.figure_out_scope({}, {4199toplevel: toplevel,4200parent_scope: this.parent_scope4201});4202} else {4203if (this.variables) node.variables = new Map(this.variables);4204if (this.enclosed) node.enclosed = this.enclosed.slice();4205if (this._block_scope) node._block_scope = this._block_scope;4206}4207return node;4208},4209pinned: function() {4210return this.uses_eval || this.uses_with;4211}4212},4213AST_Block4214);42154216var AST_Toplevel = DEFNODE("Toplevel", "globals", function AST_Toplevel(props) {4217if (props) {4218this.globals = props.globals;4219this.variables = props.variables;4220this.uses_with = props.uses_with;4221this.uses_eval = props.uses_eval;4222this.parent_scope = props.parent_scope;4223this.enclosed = props.enclosed;4224this.cname = props.cname;4225this.body = props.body;4226this.block_scope = props.block_scope;4227this.start = props.start;4228this.end = props.end;4229}42304231this.flags = 0;4232}, {4233$documentation: "The toplevel scope",4234$propdoc: {4235globals: "[Map/S] a map of name -> SymbolDef for all undeclared names",4236},4237wrap_commonjs: function(name) {4238var body = this.body;4239var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";4240wrapped_tl = parse(wrapped_tl);4241wrapped_tl = wrapped_tl.transform(new TreeTransformer(function(node) {4242if (node instanceof AST_Directive && node.value == "$ORIG") {4243return MAP.splice(body);4244}4245}));4246return wrapped_tl;4247},4248wrap_enclose: function(args_values) {4249if (typeof args_values != "string") args_values = "";4250var index = args_values.indexOf(":");4251if (index < 0) index = args_values.length;4252var body = this.body;4253return parse([4254"(function(",4255args_values.slice(0, index),4256'){"$ORIG"})(',4257args_values.slice(index + 1),4258")"4259].join("")).transform(new TreeTransformer(function(node) {4260if (node instanceof AST_Directive && node.value == "$ORIG") {4261return MAP.splice(body);4262}4263}));4264}4265}, AST_Scope);42664267var AST_Expansion = DEFNODE("Expansion", "expression", function AST_Expansion(props) {4268if (props) {4269this.expression = props.expression;4270this.start = props.start;4271this.end = props.end;4272}42734274this.flags = 0;4275}, {4276$documentation: "An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list",4277$propdoc: {4278expression: "[AST_Node] the thing to be expanded"4279},4280_walk: function(visitor) {4281return visitor._visit(this, function() {4282this.expression.walk(visitor);4283});4284},4285_children_backwards(push) {4286push(this.expression);4287},4288});42894290var AST_Lambda = DEFNODE(4291"Lambda",4292"name argnames uses_arguments is_generator async",4293function AST_Lambda(props) {4294if (props) {4295this.name = props.name;4296this.argnames = props.argnames;4297this.uses_arguments = props.uses_arguments;4298this.is_generator = props.is_generator;4299this.async = props.async;4300this.variables = props.variables;4301this.uses_with = props.uses_with;4302this.uses_eval = props.uses_eval;4303this.parent_scope = props.parent_scope;4304this.enclosed = props.enclosed;4305this.cname = props.cname;4306this.body = props.body;4307this.block_scope = props.block_scope;4308this.start = props.start;4309this.end = props.end;4310}43114312this.flags = 0;4313},4314{4315$documentation: "Base class for functions",4316$propdoc: {4317name: "[AST_SymbolDeclaration?] the name of this function",4318argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding arguments",4319uses_arguments: "[boolean/S] tells whether this function accesses the arguments array",4320is_generator: "[boolean] is this a generator method",4321async: "[boolean] is this method async",4322},4323args_as_names: function () {4324var out = [];4325for (var i = 0; i < this.argnames.length; i++) {4326if (this.argnames[i] instanceof AST_Destructuring) {4327out.push(...this.argnames[i].all_symbols());4328} else {4329out.push(this.argnames[i]);4330}4331}4332return out;4333},4334_walk: function(visitor) {4335return visitor._visit(this, function() {4336if (this.name) this.name._walk(visitor);4337var argnames = this.argnames;4338for (var i = 0, len = argnames.length; i < len; i++) {4339argnames[i]._walk(visitor);4340}4341walk_body(this, visitor);4342});4343},4344_children_backwards(push) {4345let i = this.body.length;4346while (i--) push(this.body[i]);43474348i = this.argnames.length;4349while (i--) push(this.argnames[i]);43504351if (this.name) push(this.name);4352},4353is_braceless() {4354return this.body[0] instanceof AST_Return && this.body[0].value;4355},4356// Default args and expansion don't count, so .argnames.length doesn't cut it4357length_property() {4358let length = 0;43594360for (const arg of this.argnames) {4361if (arg instanceof AST_SymbolFunarg || arg instanceof AST_Destructuring) {4362length++;4363}4364}43654366return length;4367}4368},4369AST_Scope4370);43714372var AST_Accessor = DEFNODE("Accessor", null, function AST_Accessor(props) {4373if (props) {4374this.name = props.name;4375this.argnames = props.argnames;4376this.uses_arguments = props.uses_arguments;4377this.is_generator = props.is_generator;4378this.async = props.async;4379this.variables = props.variables;4380this.uses_with = props.uses_with;4381this.uses_eval = props.uses_eval;4382this.parent_scope = props.parent_scope;4383this.enclosed = props.enclosed;4384this.cname = props.cname;4385this.body = props.body;4386this.block_scope = props.block_scope;4387this.start = props.start;4388this.end = props.end;4389}43904391this.flags = 0;4392}, {4393$documentation: "A setter/getter function. The `name` property is always null."4394}, AST_Lambda);43954396var AST_Function = DEFNODE("Function", null, function AST_Function(props) {4397if (props) {4398this.name = props.name;4399this.argnames = props.argnames;4400this.uses_arguments = props.uses_arguments;4401this.is_generator = props.is_generator;4402this.async = props.async;4403this.variables = props.variables;4404this.uses_with = props.uses_with;4405this.uses_eval = props.uses_eval;4406this.parent_scope = props.parent_scope;4407this.enclosed = props.enclosed;4408this.cname = props.cname;4409this.body = props.body;4410this.block_scope = props.block_scope;4411this.start = props.start;4412this.end = props.end;4413}44144415this.flags = 0;4416}, {4417$documentation: "A function expression"4418}, AST_Lambda);44194420var AST_Arrow = DEFNODE("Arrow", null, function AST_Arrow(props) {4421if (props) {4422this.name = props.name;4423this.argnames = props.argnames;4424this.uses_arguments = props.uses_arguments;4425this.is_generator = props.is_generator;4426this.async = props.async;4427this.variables = props.variables;4428this.uses_with = props.uses_with;4429this.uses_eval = props.uses_eval;4430this.parent_scope = props.parent_scope;4431this.enclosed = props.enclosed;4432this.cname = props.cname;4433this.body = props.body;4434this.block_scope = props.block_scope;4435this.start = props.start;4436this.end = props.end;4437}44384439this.flags = 0;4440}, {4441$documentation: "An ES6 Arrow function ((a) => b)"4442}, AST_Lambda);44434444var AST_Defun = DEFNODE("Defun", null, function AST_Defun(props) {4445if (props) {4446this.name = props.name;4447this.argnames = props.argnames;4448this.uses_arguments = props.uses_arguments;4449this.is_generator = props.is_generator;4450this.async = props.async;4451this.variables = props.variables;4452this.uses_with = props.uses_with;4453this.uses_eval = props.uses_eval;4454this.parent_scope = props.parent_scope;4455this.enclosed = props.enclosed;4456this.cname = props.cname;4457this.body = props.body;4458this.block_scope = props.block_scope;4459this.start = props.start;4460this.end = props.end;4461}44624463this.flags = 0;4464}, {4465$documentation: "A function definition"4466}, AST_Lambda);44674468/* -----[ DESTRUCTURING ]----- */4469var AST_Destructuring = DEFNODE("Destructuring", "names is_array", function AST_Destructuring(props) {4470if (props) {4471this.names = props.names;4472this.is_array = props.is_array;4473this.start = props.start;4474this.end = props.end;4475}44764477this.flags = 0;4478}, {4479$documentation: "A destructuring of several names. Used in destructuring assignment and with destructuring function argument names",4480$propdoc: {4481"names": "[AST_Node*] Array of properties or elements",4482"is_array": "[Boolean] Whether the destructuring represents an object or array"4483},4484_walk: function(visitor) {4485return visitor._visit(this, function() {4486this.names.forEach(function(name) {4487name._walk(visitor);4488});4489});4490},4491_children_backwards(push) {4492let i = this.names.length;4493while (i--) push(this.names[i]);4494},4495all_symbols: function() {4496var out = [];4497walk(this, node => {4498if (node instanceof AST_SymbolDeclaration) {4499out.push(node);4500}4501if (node instanceof AST_Lambda) {4502return true;4503}4504});4505return out;4506}4507});45084509var AST_PrefixedTemplateString = DEFNODE(4510"PrefixedTemplateString",4511"template_string prefix",4512function AST_PrefixedTemplateString(props) {4513if (props) {4514this.template_string = props.template_string;4515this.prefix = props.prefix;4516this.start = props.start;4517this.end = props.end;4518}45194520this.flags = 0;4521},4522{4523$documentation: "A templatestring with a prefix, such as String.raw`foobarbaz`",4524$propdoc: {4525template_string: "[AST_TemplateString] The template string",4526prefix: "[AST_Node] The prefix, which will get called."4527},4528_walk: function(visitor) {4529return visitor._visit(this, function () {4530this.prefix._walk(visitor);4531this.template_string._walk(visitor);4532});4533},4534_children_backwards(push) {4535push(this.template_string);4536push(this.prefix);4537},4538}4539);45404541var AST_TemplateString = DEFNODE("TemplateString", "segments", function AST_TemplateString(props) {4542if (props) {4543this.segments = props.segments;4544this.start = props.start;4545this.end = props.end;4546}45474548this.flags = 0;4549}, {4550$documentation: "A template string literal",4551$propdoc: {4552segments: "[AST_Node*] One or more segments, starting with AST_TemplateSegment. AST_Node may follow AST_TemplateSegment, but each AST_Node must be followed by AST_TemplateSegment."4553},4554_walk: function(visitor) {4555return visitor._visit(this, function() {4556this.segments.forEach(function(seg) {4557seg._walk(visitor);4558});4559});4560},4561_children_backwards(push) {4562let i = this.segments.length;4563while (i--) push(this.segments[i]);4564}4565});45664567var AST_TemplateSegment = DEFNODE("TemplateSegment", "value raw", function AST_TemplateSegment(props) {4568if (props) {4569this.value = props.value;4570this.raw = props.raw;4571this.start = props.start;4572this.end = props.end;4573}45744575this.flags = 0;4576}, {4577$documentation: "A segment of a template string literal",4578$propdoc: {4579value: "Content of the segment",4580raw: "Raw source of the segment",4581}4582});45834584/* -----[ JUMPS ]----- */45854586var AST_Jump = DEFNODE("Jump", null, function AST_Jump(props) {4587if (props) {4588this.start = props.start;4589this.end = props.end;4590}45914592this.flags = 0;4593}, {4594$documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"4595}, AST_Statement);45964597/** Base class for “exits” (`return` and `throw`) */4598var AST_Exit = DEFNODE("Exit", "value", function AST_Exit(props) {4599if (props) {4600this.value = props.value;4601this.start = props.start;4602this.end = props.end;4603}46044605this.flags = 0;4606}, {4607$documentation: "Base class for “exits” (`return` and `throw`)",4608$propdoc: {4609value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"4610},4611_walk: function(visitor) {4612return visitor._visit(this, this.value && function() {4613this.value._walk(visitor);4614});4615},4616_children_backwards(push) {4617if (this.value) push(this.value);4618},4619}, AST_Jump);46204621var AST_Return = DEFNODE("Return", null, function AST_Return(props) {4622if (props) {4623this.value = props.value;4624this.start = props.start;4625this.end = props.end;4626}46274628this.flags = 0;4629}, {4630$documentation: "A `return` statement"4631}, AST_Exit);46324633var AST_Throw = DEFNODE("Throw", null, function AST_Throw(props) {4634if (props) {4635this.value = props.value;4636this.start = props.start;4637this.end = props.end;4638}46394640this.flags = 0;4641}, {4642$documentation: "A `throw` statement"4643}, AST_Exit);46444645var AST_LoopControl = DEFNODE("LoopControl", "label", function AST_LoopControl(props) {4646if (props) {4647this.label = props.label;4648this.start = props.start;4649this.end = props.end;4650}46514652this.flags = 0;4653}, {4654$documentation: "Base class for loop control statements (`break` and `continue`)",4655$propdoc: {4656label: "[AST_LabelRef?] the label, or null if none",4657},4658_walk: function(visitor) {4659return visitor._visit(this, this.label && function() {4660this.label._walk(visitor);4661});4662},4663_children_backwards(push) {4664if (this.label) push(this.label);4665},4666}, AST_Jump);46674668var AST_Break = DEFNODE("Break", null, function AST_Break(props) {4669if (props) {4670this.label = props.label;4671this.start = props.start;4672this.end = props.end;4673}46744675this.flags = 0;4676}, {4677$documentation: "A `break` statement"4678}, AST_LoopControl);46794680var AST_Continue = DEFNODE("Continue", null, function AST_Continue(props) {4681if (props) {4682this.label = props.label;4683this.start = props.start;4684this.end = props.end;4685}46864687this.flags = 0;4688}, {4689$documentation: "A `continue` statement"4690}, AST_LoopControl);46914692var AST_Await = DEFNODE("Await", "expression", function AST_Await(props) {4693if (props) {4694this.expression = props.expression;4695this.start = props.start;4696this.end = props.end;4697}46984699this.flags = 0;4700}, {4701$documentation: "An `await` statement",4702$propdoc: {4703expression: "[AST_Node] the mandatory expression being awaited",4704},4705_walk: function(visitor) {4706return visitor._visit(this, function() {4707this.expression._walk(visitor);4708});4709},4710_children_backwards(push) {4711push(this.expression);4712},4713});47144715var AST_Yield = DEFNODE("Yield", "expression is_star", function AST_Yield(props) {4716if (props) {4717this.expression = props.expression;4718this.is_star = props.is_star;4719this.start = props.start;4720this.end = props.end;4721}47224723this.flags = 0;4724}, {4725$documentation: "A `yield` statement",4726$propdoc: {4727expression: "[AST_Node?] the value returned or thrown by this statement; could be null (representing undefined) but only when is_star is set to false",4728is_star: "[Boolean] Whether this is a yield or yield* statement"4729},4730_walk: function(visitor) {4731return visitor._visit(this, this.expression && function() {4732this.expression._walk(visitor);4733});4734},4735_children_backwards(push) {4736if (this.expression) push(this.expression);4737}4738});47394740/* -----[ IF ]----- */47414742var AST_If = DEFNODE("If", "condition alternative", function AST_If(props) {4743if (props) {4744this.condition = props.condition;4745this.alternative = props.alternative;4746this.body = props.body;4747this.start = props.start;4748this.end = props.end;4749}47504751this.flags = 0;4752}, {4753$documentation: "A `if` statement",4754$propdoc: {4755condition: "[AST_Node] the `if` condition",4756alternative: "[AST_Statement?] the `else` part, or null if not present"4757},4758_walk: function(visitor) {4759return visitor._visit(this, function() {4760this.condition._walk(visitor);4761this.body._walk(visitor);4762if (this.alternative) this.alternative._walk(visitor);4763});4764},4765_children_backwards(push) {4766if (this.alternative) {4767push(this.alternative);4768}4769push(this.body);4770push(this.condition);4771}4772}, AST_StatementWithBody);47734774/* -----[ SWITCH ]----- */47754776var AST_Switch = DEFNODE("Switch", "expression", function AST_Switch(props) {4777if (props) {4778this.expression = props.expression;4779this.body = props.body;4780this.block_scope = props.block_scope;4781this.start = props.start;4782this.end = props.end;4783}47844785this.flags = 0;4786}, {4787$documentation: "A `switch` statement",4788$propdoc: {4789expression: "[AST_Node] the `switch` “discriminant”"4790},4791_walk: function(visitor) {4792return visitor._visit(this, function() {4793this.expression._walk(visitor);4794walk_body(this, visitor);4795});4796},4797_children_backwards(push) {4798let i = this.body.length;4799while (i--) push(this.body[i]);4800push(this.expression);4801}4802}, AST_Block);48034804var AST_SwitchBranch = DEFNODE("SwitchBranch", null, function AST_SwitchBranch(props) {4805if (props) {4806this.body = props.body;4807this.block_scope = props.block_scope;4808this.start = props.start;4809this.end = props.end;4810}48114812this.flags = 0;4813}, {4814$documentation: "Base class for `switch` branches",4815}, AST_Block);48164817var AST_Default = DEFNODE("Default", null, function AST_Default(props) {4818if (props) {4819this.body = props.body;4820this.block_scope = props.block_scope;4821this.start = props.start;4822this.end = props.end;4823}48244825this.flags = 0;4826}, {4827$documentation: "A `default` switch branch",4828}, AST_SwitchBranch);48294830var AST_Case = DEFNODE("Case", "expression", function AST_Case(props) {4831if (props) {4832this.expression = props.expression;4833this.body = props.body;4834this.block_scope = props.block_scope;4835this.start = props.start;4836this.end = props.end;4837}48384839this.flags = 0;4840}, {4841$documentation: "A `case` switch branch",4842$propdoc: {4843expression: "[AST_Node] the `case` expression"4844},4845_walk: function(visitor) {4846return visitor._visit(this, function() {4847this.expression._walk(visitor);4848walk_body(this, visitor);4849});4850},4851_children_backwards(push) {4852let i = this.body.length;4853while (i--) push(this.body[i]);4854push(this.expression);4855},4856}, AST_SwitchBranch);48574858/* -----[ EXCEPTIONS ]----- */48594860var AST_Try = DEFNODE("Try", "body bcatch bfinally", function AST_Try(props) {4861if (props) {4862this.body = props.body;4863this.bcatch = props.bcatch;4864this.bfinally = props.bfinally;4865this.start = props.start;4866this.end = props.end;4867}48684869this.flags = 0;4870}, {4871$documentation: "A `try` statement",4872$propdoc: {4873body: "[AST_TryBlock] the try block",4874bcatch: "[AST_Catch?] the catch block, or null if not present",4875bfinally: "[AST_Finally?] the finally block, or null if not present"4876},4877_walk: function(visitor) {4878return visitor._visit(this, function() {4879this.body._walk(visitor);4880if (this.bcatch) this.bcatch._walk(visitor);4881if (this.bfinally) this.bfinally._walk(visitor);4882});4883},4884_children_backwards(push) {4885if (this.bfinally) push(this.bfinally);4886if (this.bcatch) push(this.bcatch);4887push(this.body);4888},4889}, AST_Statement);48904891var AST_TryBlock = DEFNODE("TryBlock", null, function AST_TryBlock(props) {4892if (props) {4893this.body = props.body;4894this.block_scope = props.block_scope;4895this.start = props.start;4896this.end = props.end;4897}48984899this.flags = 0;4900}, {4901$documentation: "The `try` block of a try statement"4902}, AST_Block);49034904var AST_Catch = DEFNODE("Catch", "argname", function AST_Catch(props) {4905if (props) {4906this.argname = props.argname;4907this.body = props.body;4908this.block_scope = props.block_scope;4909this.start = props.start;4910this.end = props.end;4911}49124913this.flags = 0;4914}, {4915$documentation: "A `catch` node; only makes sense as part of a `try` statement",4916$propdoc: {4917argname: "[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception"4918},4919_walk: function(visitor) {4920return visitor._visit(this, function() {4921if (this.argname) this.argname._walk(visitor);4922walk_body(this, visitor);4923});4924},4925_children_backwards(push) {4926let i = this.body.length;4927while (i--) push(this.body[i]);4928if (this.argname) push(this.argname);4929},4930}, AST_Block);49314932var AST_Finally = DEFNODE("Finally", null, function AST_Finally(props) {4933if (props) {4934this.body = props.body;4935this.block_scope = props.block_scope;4936this.start = props.start;4937this.end = props.end;4938}49394940this.flags = 0;4941}, {4942$documentation: "A `finally` node; only makes sense as part of a `try` statement"4943}, AST_Block);49444945/* -----[ VAR/CONST ]----- */49464947var AST_Definitions = DEFNODE("Definitions", "definitions", function AST_Definitions(props) {4948if (props) {4949this.definitions = props.definitions;4950this.start = props.start;4951this.end = props.end;4952}49534954this.flags = 0;4955}, {4956$documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)",4957$propdoc: {4958definitions: "[AST_VarDef*] array of variable definitions"4959},4960_walk: function(visitor) {4961return visitor._visit(this, function() {4962var definitions = this.definitions;4963for (var i = 0, len = definitions.length; i < len; i++) {4964definitions[i]._walk(visitor);4965}4966});4967},4968_children_backwards(push) {4969let i = this.definitions.length;4970while (i--) push(this.definitions[i]);4971},4972}, AST_Statement);49734974var AST_Var = DEFNODE("Var", null, function AST_Var(props) {4975if (props) {4976this.definitions = props.definitions;4977this.start = props.start;4978this.end = props.end;4979}49804981this.flags = 0;4982}, {4983$documentation: "A `var` statement"4984}, AST_Definitions);49854986var AST_Let = DEFNODE("Let", null, function AST_Let(props) {4987if (props) {4988this.definitions = props.definitions;4989this.start = props.start;4990this.end = props.end;4991}49924993this.flags = 0;4994}, {4995$documentation: "A `let` statement"4996}, AST_Definitions);49974998var AST_Const = DEFNODE("Const", null, function AST_Const(props) {4999if (props) {5000this.definitions = props.definitions;5001this.start = props.start;5002this.end = props.end;5003}50045005this.flags = 0;5006}, {5007$documentation: "A `const` statement"5008}, AST_Definitions);50095010var AST_VarDef = DEFNODE("VarDef", "name value", function AST_VarDef(props) {5011if (props) {5012this.name = props.name;5013this.value = props.value;5014this.start = props.start;5015this.end = props.end;5016}50175018this.flags = 0;5019}, {5020$documentation: "A variable declaration; only appears in a AST_Definitions node",5021$propdoc: {5022name: "[AST_Destructuring|AST_SymbolConst|AST_SymbolLet|AST_SymbolVar] name of the variable",5023value: "[AST_Node?] initializer, or null of there's no initializer"5024},5025_walk: function(visitor) {5026return visitor._visit(this, function() {5027this.name._walk(visitor);5028if (this.value) this.value._walk(visitor);5029});5030},5031_children_backwards(push) {5032if (this.value) push(this.value);5033push(this.name);5034},5035declarations_as_names() {5036if (this.name instanceof AST_SymbolDeclaration) {5037return [this];5038} else {5039return this.name.all_symbols();5040}5041}5042});50435044var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", function AST_NameMapping(props) {5045if (props) {5046this.foreign_name = props.foreign_name;5047this.name = props.name;5048this.start = props.start;5049this.end = props.end;5050}50515052this.flags = 0;5053}, {5054$documentation: "The part of the export/import statement that declare names from a module.",5055$propdoc: {5056foreign_name: "[AST_SymbolExportForeign|AST_SymbolImportForeign] The name being exported/imported (as specified in the module)",5057name: "[AST_SymbolExport|AST_SymbolImport] The name as it is visible to this module."5058},5059_walk: function (visitor) {5060return visitor._visit(this, function() {5061this.foreign_name._walk(visitor);5062this.name._walk(visitor);5063});5064},5065_children_backwards(push) {5066push(this.name);5067push(this.foreign_name);5068},5069});50705071var AST_Import = DEFNODE(5072"Import",5073"imported_name imported_names module_name assert_clause",5074function AST_Import(props) {5075if (props) {5076this.imported_name = props.imported_name;5077this.imported_names = props.imported_names;5078this.module_name = props.module_name;5079this.assert_clause = props.assert_clause;5080this.start = props.start;5081this.end = props.end;5082}50835084this.flags = 0;5085},5086{5087$documentation: "An `import` statement",5088$propdoc: {5089imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",5090imported_names: "[AST_NameMapping*] The names of non-default imported variables",5091module_name: "[AST_String] String literal describing where this module came from",5092assert_clause: "[AST_Object?] The import assertion"5093},5094_walk: function(visitor) {5095return visitor._visit(this, function() {5096if (this.imported_name) {5097this.imported_name._walk(visitor);5098}5099if (this.imported_names) {5100this.imported_names.forEach(function(name_import) {5101name_import._walk(visitor);5102});5103}5104this.module_name._walk(visitor);5105});5106},5107_children_backwards(push) {5108push(this.module_name);5109if (this.imported_names) {5110let i = this.imported_names.length;5111while (i--) push(this.imported_names[i]);5112}5113if (this.imported_name) push(this.imported_name);5114},5115}5116);51175118var AST_ImportMeta = DEFNODE("ImportMeta", null, function AST_ImportMeta(props) {5119if (props) {5120this.start = props.start;5121this.end = props.end;5122}51235124this.flags = 0;5125}, {5126$documentation: "A reference to import.meta",5127});51285129var AST_Export = DEFNODE(5130"Export",5131"exported_definition exported_value is_default exported_names module_name assert_clause",5132function AST_Export(props) {5133if (props) {5134this.exported_definition = props.exported_definition;5135this.exported_value = props.exported_value;5136this.is_default = props.is_default;5137this.exported_names = props.exported_names;5138this.module_name = props.module_name;5139this.assert_clause = props.assert_clause;5140this.start = props.start;5141this.end = props.end;5142}51435144this.flags = 0;5145},5146{5147$documentation: "An `export` statement",5148$propdoc: {5149exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition",5150exported_value: "[AST_Node?] An exported value",5151exported_names: "[AST_NameMapping*?] List of exported names",5152module_name: "[AST_String?] Name of the file to load exports from",5153is_default: "[Boolean] Whether this is the default exported value of this module",5154assert_clause: "[AST_Object?] The import assertion"5155},5156_walk: function (visitor) {5157return visitor._visit(this, function () {5158if (this.exported_definition) {5159this.exported_definition._walk(visitor);5160}5161if (this.exported_value) {5162this.exported_value._walk(visitor);5163}5164if (this.exported_names) {5165this.exported_names.forEach(function(name_export) {5166name_export._walk(visitor);5167});5168}5169if (this.module_name) {5170this.module_name._walk(visitor);5171}5172});5173},5174_children_backwards(push) {5175if (this.module_name) push(this.module_name);5176if (this.exported_names) {5177let i = this.exported_names.length;5178while (i--) push(this.exported_names[i]);5179}5180if (this.exported_value) push(this.exported_value);5181if (this.exported_definition) push(this.exported_definition);5182}5183},5184AST_Statement5185);51865187/* -----[ OTHER ]----- */51885189var AST_Call = DEFNODE(5190"Call",5191"expression args optional _annotations",5192function AST_Call(props) {5193if (props) {5194this.expression = props.expression;5195this.args = props.args;5196this.optional = props.optional;5197this._annotations = props._annotations;5198this.start = props.start;5199this.end = props.end;5200this.initialize();5201}52025203this.flags = 0;5204},5205{5206$documentation: "A function call expression",5207$propdoc: {5208expression: "[AST_Node] expression to invoke as function",5209args: "[AST_Node*] array of arguments",5210optional: "[boolean] whether this is an optional call (IE ?.() )",5211_annotations: "[number] bitfield containing information about the call"5212},5213initialize() {5214if (this._annotations == null) this._annotations = 0;5215},5216_walk(visitor) {5217return visitor._visit(this, function() {5218var args = this.args;5219for (var i = 0, len = args.length; i < len; i++) {5220args[i]._walk(visitor);5221}5222this.expression._walk(visitor); // TODO why do we need to crawl this last?5223});5224},5225_children_backwards(push) {5226let i = this.args.length;5227while (i--) push(this.args[i]);5228push(this.expression);5229},5230}5231);52325233var AST_New = DEFNODE("New", null, function AST_New(props) {5234if (props) {5235this.expression = props.expression;5236this.args = props.args;5237this.optional = props.optional;5238this._annotations = props._annotations;5239this.start = props.start;5240this.end = props.end;5241this.initialize();5242}52435244this.flags = 0;5245}, {5246$documentation: "An object instantiation. Derives from a function call since it has exactly the same properties"5247}, AST_Call);52485249var AST_Sequence = DEFNODE("Sequence", "expressions", function AST_Sequence(props) {5250if (props) {5251this.expressions = props.expressions;5252this.start = props.start;5253this.end = props.end;5254}52555256this.flags = 0;5257}, {5258$documentation: "A sequence expression (comma-separated expressions)",5259$propdoc: {5260expressions: "[AST_Node*] array of expressions (at least two)"5261},5262_walk: function(visitor) {5263return visitor._visit(this, function() {5264this.expressions.forEach(function(node) {5265node._walk(visitor);5266});5267});5268},5269_children_backwards(push) {5270let i = this.expressions.length;5271while (i--) push(this.expressions[i]);5272},5273});52745275var AST_PropAccess = DEFNODE(5276"PropAccess",5277"expression property optional",5278function AST_PropAccess(props) {5279if (props) {5280this.expression = props.expression;5281this.property = props.property;5282this.optional = props.optional;5283this.start = props.start;5284this.end = props.end;5285}52865287this.flags = 0;5288},5289{5290$documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`",5291$propdoc: {5292expression: "[AST_Node] the “container” expression",5293property: "[AST_Node|string] the property to access. For AST_Dot & AST_DotHash this is always a plain string, while for AST_Sub it's an arbitrary AST_Node",52945295optional: "[boolean] whether this is an optional property access (IE ?.)"5296}5297}5298);52995300var AST_Dot = DEFNODE("Dot", "quote", function AST_Dot(props) {5301if (props) {5302this.quote = props.quote;5303this.expression = props.expression;5304this.property = props.property;5305this.optional = props.optional;5306this.start = props.start;5307this.end = props.end;5308}53095310this.flags = 0;5311}, {5312$documentation: "A dotted property access expression",5313$propdoc: {5314quote: "[string] the original quote character when transformed from AST_Sub",5315},5316_walk: function(visitor) {5317return visitor._visit(this, function() {5318this.expression._walk(visitor);5319});5320},5321_children_backwards(push) {5322push(this.expression);5323},5324}, AST_PropAccess);53255326var AST_DotHash = DEFNODE("DotHash", "", function AST_DotHash(props) {5327if (props) {5328this.expression = props.expression;5329this.property = props.property;5330this.optional = props.optional;5331this.start = props.start;5332this.end = props.end;5333}53345335this.flags = 0;5336}, {5337$documentation: "A dotted property access to a private property",5338_walk: function(visitor) {5339return visitor._visit(this, function() {5340this.expression._walk(visitor);5341});5342},5343_children_backwards(push) {5344push(this.expression);5345},5346}, AST_PropAccess);53475348var AST_Sub = DEFNODE("Sub", null, function AST_Sub(props) {5349if (props) {5350this.expression = props.expression;5351this.property = props.property;5352this.optional = props.optional;5353this.start = props.start;5354this.end = props.end;5355}53565357this.flags = 0;5358}, {5359$documentation: "Index-style property access, i.e. `a[\"foo\"]`",5360_walk: function(visitor) {5361return visitor._visit(this, function() {5362this.expression._walk(visitor);5363this.property._walk(visitor);5364});5365},5366_children_backwards(push) {5367push(this.property);5368push(this.expression);5369},5370}, AST_PropAccess);53715372var AST_Chain = DEFNODE("Chain", "expression", function AST_Chain(props) {5373if (props) {5374this.expression = props.expression;5375this.start = props.start;5376this.end = props.end;5377}53785379this.flags = 0;5380}, {5381$documentation: "A chain expression like a?.b?.(c)?.[d]",5382$propdoc: {5383expression: "[AST_Call|AST_Dot|AST_DotHash|AST_Sub] chain element."5384},5385_walk: function (visitor) {5386return visitor._visit(this, function() {5387this.expression._walk(visitor);5388});5389},5390_children_backwards(push) {5391push(this.expression);5392},5393});53945395var AST_Unary = DEFNODE("Unary", "operator expression", function AST_Unary(props) {5396if (props) {5397this.operator = props.operator;5398this.expression = props.expression;5399this.start = props.start;5400this.end = props.end;5401}54025403this.flags = 0;5404}, {5405$documentation: "Base class for unary expressions",5406$propdoc: {5407operator: "[string] the operator",5408expression: "[AST_Node] expression that this unary operator applies to"5409},5410_walk: function(visitor) {5411return visitor._visit(this, function() {5412this.expression._walk(visitor);5413});5414},5415_children_backwards(push) {5416push(this.expression);5417},5418});54195420var AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, function AST_UnaryPrefix(props) {5421if (props) {5422this.operator = props.operator;5423this.expression = props.expression;5424this.start = props.start;5425this.end = props.end;5426}54275428this.flags = 0;5429}, {5430$documentation: "Unary prefix expression, i.e. `typeof i` or `++i`"5431}, AST_Unary);54325433var AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, function AST_UnaryPostfix(props) {5434if (props) {5435this.operator = props.operator;5436this.expression = props.expression;5437this.start = props.start;5438this.end = props.end;5439}54405441this.flags = 0;5442}, {5443$documentation: "Unary postfix expression, i.e. `i++`"5444}, AST_Unary);54455446var AST_Binary = DEFNODE("Binary", "operator left right", function AST_Binary(props) {5447if (props) {5448this.operator = props.operator;5449this.left = props.left;5450this.right = props.right;5451this.start = props.start;5452this.end = props.end;5453}54545455this.flags = 0;5456}, {5457$documentation: "Binary expression, i.e. `a + b`",5458$propdoc: {5459left: "[AST_Node] left-hand side expression",5460operator: "[string] the operator",5461right: "[AST_Node] right-hand side expression"5462},5463_walk: function(visitor) {5464return visitor._visit(this, function() {5465this.left._walk(visitor);5466this.right._walk(visitor);5467});5468},5469_children_backwards(push) {5470push(this.right);5471push(this.left);5472},5473});54745475var AST_Conditional = DEFNODE(5476"Conditional",5477"condition consequent alternative",5478function AST_Conditional(props) {5479if (props) {5480this.condition = props.condition;5481this.consequent = props.consequent;5482this.alternative = props.alternative;5483this.start = props.start;5484this.end = props.end;5485}54865487this.flags = 0;5488},5489{5490$documentation: "Conditional expression using the ternary operator, i.e. `a ? b : c`",5491$propdoc: {5492condition: "[AST_Node]",5493consequent: "[AST_Node]",5494alternative: "[AST_Node]"5495},5496_walk: function(visitor) {5497return visitor._visit(this, function() {5498this.condition._walk(visitor);5499this.consequent._walk(visitor);5500this.alternative._walk(visitor);5501});5502},5503_children_backwards(push) {5504push(this.alternative);5505push(this.consequent);5506push(this.condition);5507},5508}5509);55105511var AST_Assign = DEFNODE("Assign", "logical", function AST_Assign(props) {5512if (props) {5513this.logical = props.logical;5514this.operator = props.operator;5515this.left = props.left;5516this.right = props.right;5517this.start = props.start;5518this.end = props.end;5519}55205521this.flags = 0;5522}, {5523$documentation: "An assignment expression — `a = b + 5`",5524$propdoc: {5525logical: "Whether it's a logical assignment"5526}5527}, AST_Binary);55285529var AST_DefaultAssign = DEFNODE("DefaultAssign", null, function AST_DefaultAssign(props) {5530if (props) {5531this.operator = props.operator;5532this.left = props.left;5533this.right = props.right;5534this.start = props.start;5535this.end = props.end;5536}55375538this.flags = 0;5539}, {5540$documentation: "A default assignment expression like in `(a = 3) => a`"5541}, AST_Binary);55425543/* -----[ LITERALS ]----- */55445545var AST_Array = DEFNODE("Array", "elements", function AST_Array(props) {5546if (props) {5547this.elements = props.elements;5548this.start = props.start;5549this.end = props.end;5550}55515552this.flags = 0;5553}, {5554$documentation: "An array literal",5555$propdoc: {5556elements: "[AST_Node*] array of elements"5557},5558_walk: function(visitor) {5559return visitor._visit(this, function() {5560var elements = this.elements;5561for (var i = 0, len = elements.length; i < len; i++) {5562elements[i]._walk(visitor);5563}5564});5565},5566_children_backwards(push) {5567let i = this.elements.length;5568while (i--) push(this.elements[i]);5569},5570});55715572var AST_Object = DEFNODE("Object", "properties", function AST_Object(props) {5573if (props) {5574this.properties = props.properties;5575this.start = props.start;5576this.end = props.end;5577}55785579this.flags = 0;5580}, {5581$documentation: "An object literal",5582$propdoc: {5583properties: "[AST_ObjectProperty*] array of properties"5584},5585_walk: function(visitor) {5586return visitor._visit(this, function() {5587var properties = this.properties;5588for (var i = 0, len = properties.length; i < len; i++) {5589properties[i]._walk(visitor);5590}5591});5592},5593_children_backwards(push) {5594let i = this.properties.length;5595while (i--) push(this.properties[i]);5596},5597});55985599var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_ObjectProperty(props) {5600if (props) {5601this.key = props.key;5602this.value = props.value;5603this.start = props.start;5604this.end = props.end;5605this._annotations = props._annotations;5606}56075608this.flags = 0;5609}, {5610$documentation: "Base class for literal object properties",5611$propdoc: {5612key: "[string|AST_Node] property name. For ObjectKeyVal this is a string. For getters, setters and computed property this is an AST_Node.",5613value: "[AST_Node] property value. For getters and setters this is an AST_Accessor."5614},5615_walk: function(visitor) {5616return visitor._visit(this, function() {5617if (this.key instanceof AST_Node)5618this.key._walk(visitor);5619this.value._walk(visitor);5620});5621},5622_children_backwards(push) {5623push(this.value);5624if (this.key instanceof AST_Node) push(this.key);5625}5626});56275628var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", function AST_ObjectKeyVal(props) {5629if (props) {5630this.quote = props.quote;5631this.key = props.key;5632this.value = props.value;5633this.start = props.start;5634this.end = props.end;5635this._annotations = props._annotations;5636}56375638this.flags = 0;5639}, {5640$documentation: "A key: value object property",5641$propdoc: {5642quote: "[string] the original quote character"5643},5644computed_key() {5645return this.key instanceof AST_Node;5646}5647}, AST_ObjectProperty);56485649var AST_PrivateSetter = DEFNODE("PrivateSetter", "static", function AST_PrivateSetter(props) {5650if (props) {5651this.static = props.static;5652this.key = props.key;5653this.value = props.value;5654this.start = props.start;5655this.end = props.end;5656}56575658this.flags = 0;5659}, {5660$propdoc: {5661static: "[boolean] whether this is a static private setter"5662},5663$documentation: "A private setter property",5664computed_key() {5665return false;5666}5667}, AST_ObjectProperty);56685669var AST_PrivateGetter = DEFNODE("PrivateGetter", "static", function AST_PrivateGetter(props) {5670if (props) {5671this.static = props.static;5672this.key = props.key;5673this.value = props.value;5674this.start = props.start;5675this.end = props.end;5676}56775678this.flags = 0;5679}, {5680$propdoc: {5681static: "[boolean] whether this is a static private getter"5682},5683$documentation: "A private getter property",5684computed_key() {5685return false;5686}5687}, AST_ObjectProperty);56885689var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", function AST_ObjectSetter(props) {5690if (props) {5691this.quote = props.quote;5692this.static = props.static;5693this.key = props.key;5694this.value = props.value;5695this.start = props.start;5696this.end = props.end;5697this._annotations = props._annotations;5698}56995700this.flags = 0;5701}, {5702$propdoc: {5703quote: "[string|undefined] the original quote character, if any",5704static: "[boolean] whether this is a static setter (classes only)"5705},5706$documentation: "An object setter property",5707computed_key() {5708return !(this.key instanceof AST_SymbolMethod);5709}5710}, AST_ObjectProperty);57115712var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_ObjectGetter(props) {5713if (props) {5714this.quote = props.quote;5715this.static = props.static;5716this.key = props.key;5717this.value = props.value;5718this.start = props.start;5719this.end = props.end;5720this._annotations = props._annotations;5721}57225723this.flags = 0;5724}, {5725$propdoc: {5726quote: "[string|undefined] the original quote character, if any",5727static: "[boolean] whether this is a static getter (classes only)"5728},5729$documentation: "An object getter property",5730computed_key() {5731return !(this.key instanceof AST_SymbolMethod);5732}5733}, AST_ObjectProperty);57345735var AST_ConciseMethod = DEFNODE(5736"ConciseMethod",5737"quote static is_generator async",5738function AST_ConciseMethod(props) {5739if (props) {5740this.quote = props.quote;5741this.static = props.static;5742this.is_generator = props.is_generator;5743this.async = props.async;5744this.key = props.key;5745this.value = props.value;5746this.start = props.start;5747this.end = props.end;5748this._annotations = props._annotations;5749}57505751this.flags = 0;5752},5753{5754$propdoc: {5755quote: "[string|undefined] the original quote character, if any",5756static: "[boolean] is this method static (classes only)",5757is_generator: "[boolean] is this a generator method",5758async: "[boolean] is this method async",5759},5760$documentation: "An ES6 concise method inside an object or class",5761computed_key() {5762return !(this.key instanceof AST_SymbolMethod);5763}5764},5765AST_ObjectProperty5766);57675768var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {5769if (props) {5770this.quote = props.quote;5771this.static = props.static;5772this.is_generator = props.is_generator;5773this.async = props.async;5774this.key = props.key;5775this.value = props.value;5776this.start = props.start;5777this.end = props.end;5778}57795780this.flags = 0;5781}, {5782$documentation: "A private class method inside a class",5783}, AST_ConciseMethod);57845785var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(props) {5786if (props) {5787this.name = props.name;5788this.extends = props.extends;5789this.properties = props.properties;5790this.variables = props.variables;5791this.uses_with = props.uses_with;5792this.uses_eval = props.uses_eval;5793this.parent_scope = props.parent_scope;5794this.enclosed = props.enclosed;5795this.cname = props.cname;5796this.body = props.body;5797this.block_scope = props.block_scope;5798this.start = props.start;5799this.end = props.end;5800}58015802this.flags = 0;5803}, {5804$propdoc: {5805name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",5806extends: "[AST_Node]? optional parent class",5807properties: "[AST_ObjectProperty*] array of properties"5808},5809$documentation: "An ES6 class",5810_walk: function(visitor) {5811return visitor._visit(this, function() {5812if (this.name) {5813this.name._walk(visitor);5814}5815if (this.extends) {5816this.extends._walk(visitor);5817}5818this.properties.forEach((prop) => prop._walk(visitor));5819});5820},5821_children_backwards(push) {5822let i = this.properties.length;5823while (i--) push(this.properties[i]);5824if (this.extends) push(this.extends);5825if (this.name) push(this.name);5826},5827/** go through the bits that are executed instantly, not when the class is `new`'d. Doesn't walk the name. */5828visit_nondeferred_class_parts(visitor) {5829if (this.extends) {5830this.extends._walk(visitor);5831}5832this.properties.forEach((prop) => {5833if (prop instanceof AST_ClassStaticBlock) {5834prop._walk(visitor);5835return;5836}5837if (prop.computed_key()) {5838visitor.push(prop);5839prop.key._walk(visitor);5840visitor.pop();5841}5842if ((prop instanceof AST_ClassPrivateProperty || prop instanceof AST_ClassProperty) && prop.static && prop.value) {5843visitor.push(prop);5844prop.value._walk(visitor);5845visitor.pop();5846}5847});5848},5849/** go through the bits that are executed later, when the class is `new`'d or a static method is called */5850visit_deferred_class_parts(visitor) {5851this.properties.forEach((prop) => {5852if (prop instanceof AST_ConciseMethod) {5853prop.walk(visitor);5854} else if (prop instanceof AST_ClassProperty && !prop.static && prop.value) {5855visitor.push(prop);5856prop.value._walk(visitor);5857visitor.pop();5858}5859});5860},5861}, AST_Scope /* TODO a class might have a scope but it's not a scope */);58625863var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_ClassProperty(props) {5864if (props) {5865this.static = props.static;5866this.quote = props.quote;5867this.key = props.key;5868this.value = props.value;5869this.start = props.start;5870this.end = props.end;5871this._annotations = props._annotations;5872}58735874this.flags = 0;5875}, {5876$documentation: "A class property",5877$propdoc: {5878static: "[boolean] whether this is a static key",5879quote: "[string] which quote is being used"5880},5881_walk: function(visitor) {5882return visitor._visit(this, function() {5883if (this.key instanceof AST_Node)5884this.key._walk(visitor);5885if (this.value instanceof AST_Node)5886this.value._walk(visitor);5887});5888},5889_children_backwards(push) {5890if (this.value instanceof AST_Node) push(this.value);5891if (this.key instanceof AST_Node) push(this.key);5892},5893computed_key() {5894return !(this.key instanceof AST_SymbolClassProperty);5895}5896}, AST_ObjectProperty);58975898var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) {5899if (props) {5900this.static = props.static;5901this.quote = props.quote;5902this.key = props.key;5903this.value = props.value;5904this.start = props.start;5905this.end = props.end;5906}59075908this.flags = 0;5909}, {5910$documentation: "A class property for a private property",5911}, AST_ClassProperty);59125913var AST_PrivateIn = DEFNODE("PrivateIn", "key value", function AST_PrivateIn(props) {5914if (props) {5915this.key = props.key;5916this.value = props.value;5917this.start = props.start;5918this.end = props.end;5919}59205921this.flags = 0;5922}, {5923$documentation: "An `in` binop when the key is private, eg #x in this",5924_walk: function(visitor) {5925return visitor._visit(this, function() {5926this.key._walk(visitor);5927this.value._walk(visitor);5928});5929},5930_children_backwards(push) {5931push(this.value);5932push(this.key);5933},5934});59355936var AST_DefClass = DEFNODE("DefClass", null, function AST_DefClass(props) {5937if (props) {5938this.name = props.name;5939this.extends = props.extends;5940this.properties = props.properties;5941this.variables = props.variables;5942this.uses_with = props.uses_with;5943this.uses_eval = props.uses_eval;5944this.parent_scope = props.parent_scope;5945this.enclosed = props.enclosed;5946this.cname = props.cname;5947this.body = props.body;5948this.block_scope = props.block_scope;5949this.start = props.start;5950this.end = props.end;5951}59525953this.flags = 0;5954}, {5955$documentation: "A class definition",5956}, AST_Class);59575958var AST_ClassStaticBlock = DEFNODE("ClassStaticBlock", "body block_scope", function AST_ClassStaticBlock (props) {5959this.body = props.body;5960this.block_scope = props.block_scope;5961this.start = props.start;5962this.end = props.end;5963}, {5964$documentation: "A block containing statements to be executed in the context of the class",5965$propdoc: {5966body: "[AST_Statement*] an array of statements",5967},5968_walk: function(visitor) {5969return visitor._visit(this, function() {5970walk_body(this, visitor);5971});5972},5973_children_backwards(push) {5974let i = this.body.length;5975while (i--) push(this.body[i]);5976},5977clone: clone_block_scope,5978computed_key: () => false5979}, AST_Scope);59805981var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExpression(props) {5982if (props) {5983this.name = props.name;5984this.extends = props.extends;5985this.properties = props.properties;5986this.variables = props.variables;5987this.uses_with = props.uses_with;5988this.uses_eval = props.uses_eval;5989this.parent_scope = props.parent_scope;5990this.enclosed = props.enclosed;5991this.cname = props.cname;5992this.body = props.body;5993this.block_scope = props.block_scope;5994this.start = props.start;5995this.end = props.end;5996}59975998this.flags = 0;5999}, {6000$documentation: "A class expression."6001}, AST_Class);60026003var AST_Symbol = DEFNODE("Symbol", "scope name thedef", function AST_Symbol(props) {6004if (props) {6005this.scope = props.scope;6006this.name = props.name;6007this.thedef = props.thedef;6008this.start = props.start;6009this.end = props.end;6010}60116012this.flags = 0;6013}, {6014$propdoc: {6015name: "[string] name of this symbol",6016scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",6017thedef: "[SymbolDef/S] the definition of this symbol"6018},6019$documentation: "Base class for all symbols"6020});60216022var AST_NewTarget = DEFNODE("NewTarget", null, function AST_NewTarget(props) {6023if (props) {6024this.start = props.start;6025this.end = props.end;6026}60276028this.flags = 0;6029}, {6030$documentation: "A reference to new.target"6031});60326033var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", function AST_SymbolDeclaration(props) {6034if (props) {6035this.init = props.init;6036this.scope = props.scope;6037this.name = props.name;6038this.thedef = props.thedef;6039this.start = props.start;6040this.end = props.end;6041}60426043this.flags = 0;6044}, {6045$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",6046}, AST_Symbol);60476048var AST_SymbolVar = DEFNODE("SymbolVar", null, function AST_SymbolVar(props) {6049if (props) {6050this.init = props.init;6051this.scope = props.scope;6052this.name = props.name;6053this.thedef = props.thedef;6054this.start = props.start;6055this.end = props.end;6056}60576058this.flags = 0;6059}, {6060$documentation: "Symbol defining a variable",6061}, AST_SymbolDeclaration);60626063var AST_SymbolBlockDeclaration = DEFNODE(6064"SymbolBlockDeclaration",6065null,6066function AST_SymbolBlockDeclaration(props) {6067if (props) {6068this.init = props.init;6069this.scope = props.scope;6070this.name = props.name;6071this.thedef = props.thedef;6072this.start = props.start;6073this.end = props.end;6074}60756076this.flags = 0;6077},6078{6079$documentation: "Base class for block-scoped declaration symbols"6080},6081AST_SymbolDeclaration6082);60836084var AST_SymbolConst = DEFNODE("SymbolConst", null, function AST_SymbolConst(props) {6085if (props) {6086this.init = props.init;6087this.scope = props.scope;6088this.name = props.name;6089this.thedef = props.thedef;6090this.start = props.start;6091this.end = props.end;6092}60936094this.flags = 0;6095}, {6096$documentation: "A constant declaration"6097}, AST_SymbolBlockDeclaration);60986099var AST_SymbolLet = DEFNODE("SymbolLet", null, function AST_SymbolLet(props) {6100if (props) {6101this.init = props.init;6102this.scope = props.scope;6103this.name = props.name;6104this.thedef = props.thedef;6105this.start = props.start;6106this.end = props.end;6107}61086109this.flags = 0;6110}, {6111$documentation: "A block-scoped `let` declaration"6112}, AST_SymbolBlockDeclaration);61136114var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, function AST_SymbolFunarg(props) {6115if (props) {6116this.init = props.init;6117this.scope = props.scope;6118this.name = props.name;6119this.thedef = props.thedef;6120this.start = props.start;6121this.end = props.end;6122}61236124this.flags = 0;6125}, {6126$documentation: "Symbol naming a function argument",6127}, AST_SymbolVar);61286129var AST_SymbolDefun = DEFNODE("SymbolDefun", null, function AST_SymbolDefun(props) {6130if (props) {6131this.init = props.init;6132this.scope = props.scope;6133this.name = props.name;6134this.thedef = props.thedef;6135this.start = props.start;6136this.end = props.end;6137}61386139this.flags = 0;6140}, {6141$documentation: "Symbol defining a function",6142}, AST_SymbolDeclaration);61436144var AST_SymbolMethod = DEFNODE("SymbolMethod", null, function AST_SymbolMethod(props) {6145if (props) {6146this.scope = props.scope;6147this.name = props.name;6148this.thedef = props.thedef;6149this.start = props.start;6150this.end = props.end;6151}61526153this.flags = 0;6154}, {6155$documentation: "Symbol in an object defining a method",6156}, AST_Symbol);61576158var AST_SymbolClassProperty = DEFNODE("SymbolClassProperty", null, function AST_SymbolClassProperty(props) {6159if (props) {6160this.scope = props.scope;6161this.name = props.name;6162this.thedef = props.thedef;6163this.start = props.start;6164this.end = props.end;6165}61666167this.flags = 0;6168}, {6169$documentation: "Symbol for a class property",6170}, AST_Symbol);61716172var AST_SymbolLambda = DEFNODE("SymbolLambda", null, function AST_SymbolLambda(props) {6173if (props) {6174this.init = props.init;6175this.scope = props.scope;6176this.name = props.name;6177this.thedef = props.thedef;6178this.start = props.start;6179this.end = props.end;6180}61816182this.flags = 0;6183}, {6184$documentation: "Symbol naming a function expression",6185}, AST_SymbolDeclaration);61866187var AST_SymbolDefClass = DEFNODE("SymbolDefClass", null, function AST_SymbolDefClass(props) {6188if (props) {6189this.init = props.init;6190this.scope = props.scope;6191this.name = props.name;6192this.thedef = props.thedef;6193this.start = props.start;6194this.end = props.end;6195}61966197this.flags = 0;6198}, {6199$documentation: "Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class."6200}, AST_SymbolBlockDeclaration);62016202var AST_SymbolClass = DEFNODE("SymbolClass", null, function AST_SymbolClass(props) {6203if (props) {6204this.init = props.init;6205this.scope = props.scope;6206this.name = props.name;6207this.thedef = props.thedef;6208this.start = props.start;6209this.end = props.end;6210}62116212this.flags = 0;6213}, {6214$documentation: "Symbol naming a class's name. Lexically scoped to the class."6215}, AST_SymbolDeclaration);62166217var AST_SymbolCatch = DEFNODE("SymbolCatch", null, function AST_SymbolCatch(props) {6218if (props) {6219this.init = props.init;6220this.scope = props.scope;6221this.name = props.name;6222this.thedef = props.thedef;6223this.start = props.start;6224this.end = props.end;6225}62266227this.flags = 0;6228}, {6229$documentation: "Symbol naming the exception in catch",6230}, AST_SymbolBlockDeclaration);62316232var AST_SymbolImport = DEFNODE("SymbolImport", null, function AST_SymbolImport(props) {6233if (props) {6234this.init = props.init;6235this.scope = props.scope;6236this.name = props.name;6237this.thedef = props.thedef;6238this.start = props.start;6239this.end = props.end;6240}62416242this.flags = 0;6243}, {6244$documentation: "Symbol referring to an imported name",6245}, AST_SymbolBlockDeclaration);62466247var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, function AST_SymbolImportForeign(props) {6248if (props) {6249this.scope = props.scope;6250this.name = props.name;6251this.thedef = props.thedef;6252this.quote = props.quote;6253this.start = props.start;6254this.end = props.end;6255}62566257this.flags = 0;6258}, {6259$documentation: "A symbol imported from a module, but it is defined in the other module, and its real name is irrelevant for this module's purposes",6260}, AST_Symbol);62616262var AST_Label = DEFNODE("Label", "references", function AST_Label(props) {6263if (props) {6264this.references = props.references;6265this.scope = props.scope;6266this.name = props.name;6267this.thedef = props.thedef;6268this.start = props.start;6269this.end = props.end;6270this.initialize();6271}62726273this.flags = 0;6274}, {6275$documentation: "Symbol naming a label (declaration)",6276$propdoc: {6277references: "[AST_LoopControl*] a list of nodes referring to this label"6278},6279initialize: function() {6280this.references = [];6281this.thedef = this;6282}6283}, AST_Symbol);62846285var AST_SymbolRef = DEFNODE("SymbolRef", null, function AST_SymbolRef(props) {6286if (props) {6287this.scope = props.scope;6288this.name = props.name;6289this.thedef = props.thedef;6290this.start = props.start;6291this.end = props.end;6292}62936294this.flags = 0;6295}, {6296$documentation: "Reference to some symbol (not definition/declaration)",6297}, AST_Symbol);62986299var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(props) {6300if (props) {6301this.scope = props.scope;6302this.name = props.name;6303this.thedef = props.thedef;6304this.quote = props.quote;6305this.start = props.start;6306this.end = props.end;6307}63086309this.flags = 0;6310}, {6311$documentation: "Symbol referring to a name to export",6312}, AST_SymbolRef);63136314var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, function AST_SymbolExportForeign(props) {6315if (props) {6316this.scope = props.scope;6317this.name = props.name;6318this.thedef = props.thedef;6319this.quote = props.quote;6320this.start = props.start;6321this.end = props.end;6322}63236324this.flags = 0;6325}, {6326$documentation: "A symbol exported from this module, but it is used in the other module, and its real name is irrelevant for this module's purposes",6327}, AST_Symbol);63286329var AST_LabelRef = DEFNODE("LabelRef", null, function AST_LabelRef(props) {6330if (props) {6331this.scope = props.scope;6332this.name = props.name;6333this.thedef = props.thedef;6334this.start = props.start;6335this.end = props.end;6336}63376338this.flags = 0;6339}, {6340$documentation: "Reference to a label symbol",6341}, AST_Symbol);63426343var AST_SymbolPrivateProperty = DEFNODE("SymbolPrivateProperty", null, function AST_SymbolPrivateProperty(props) {6344if (props) {6345this.scope = props.scope;6346this.name = props.name;6347this.thedef = props.thedef;6348this.start = props.start;6349this.end = props.end;6350}63516352this.flags = 0;6353}, {6354$documentation: "A symbol that refers to a private property",6355}, AST_Symbol);63566357var AST_This = DEFNODE("This", null, function AST_This(props) {6358if (props) {6359this.scope = props.scope;6360this.name = props.name;6361this.thedef = props.thedef;6362this.start = props.start;6363this.end = props.end;6364}63656366this.flags = 0;6367}, {6368$documentation: "The `this` symbol",6369}, AST_Symbol);63706371var AST_Super = DEFNODE("Super", null, function AST_Super(props) {6372if (props) {6373this.scope = props.scope;6374this.name = props.name;6375this.thedef = props.thedef;6376this.start = props.start;6377this.end = props.end;6378}63796380this.flags = 0;6381}, {6382$documentation: "The `super` symbol",6383}, AST_This);63846385var AST_Constant = DEFNODE("Constant", null, function AST_Constant(props) {6386if (props) {6387this.start = props.start;6388this.end = props.end;6389}63906391this.flags = 0;6392}, {6393$documentation: "Base class for all constants",6394getValue: function() {6395return this.value;6396}6397});63986399var AST_String = DEFNODE("String", "value quote", function AST_String(props) {6400if (props) {6401this.value = props.value;6402this.quote = props.quote;6403this.start = props.start;6404this.end = props.end;6405this._annotations = props._annotations;6406}64076408this.flags = 0;6409}, {6410$documentation: "A string literal",6411$propdoc: {6412value: "[string] the contents of this string",6413quote: "[string] the original quote character"6414}6415}, AST_Constant);64166417var AST_Number = DEFNODE("Number", "value raw", function AST_Number(props) {6418if (props) {6419this.value = props.value;6420this.raw = props.raw;6421this.start = props.start;6422this.end = props.end;6423}64246425this.flags = 0;6426}, {6427$documentation: "A number literal",6428$propdoc: {6429value: "[number] the numeric value",6430raw: "[string] numeric value as string"6431}6432}, AST_Constant);64336434var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {6435if (props) {6436this.value = props.value;6437this.start = props.start;6438this.end = props.end;6439}64406441this.flags = 0;6442}, {6443$documentation: "A big int literal",6444$propdoc: {6445value: "[string] big int value"6446}6447}, AST_Constant);64486449var AST_RegExp = DEFNODE("RegExp", "value", function AST_RegExp(props) {6450if (props) {6451this.value = props.value;6452this.start = props.start;6453this.end = props.end;6454}64556456this.flags = 0;6457}, {6458$documentation: "A regexp literal",6459$propdoc: {6460value: "[RegExp] the actual regexp",6461}6462}, AST_Constant);64636464var AST_Atom = DEFNODE("Atom", null, function AST_Atom(props) {6465if (props) {6466this.start = props.start;6467this.end = props.end;6468}64696470this.flags = 0;6471}, {6472$documentation: "Base class for atoms",6473}, AST_Constant);64746475var AST_Null = DEFNODE("Null", null, function AST_Null(props) {6476if (props) {6477this.start = props.start;6478this.end = props.end;6479}64806481this.flags = 0;6482}, {6483$documentation: "The `null` atom",6484value: null6485}, AST_Atom);64866487var AST_NaN = DEFNODE("NaN", null, function AST_NaN(props) {6488if (props) {6489this.start = props.start;6490this.end = props.end;6491}64926493this.flags = 0;6494}, {6495$documentation: "The impossible value",6496value: 0/06497}, AST_Atom);64986499var AST_Undefined = DEFNODE("Undefined", null, function AST_Undefined(props) {6500if (props) {6501this.start = props.start;6502this.end = props.end;6503}65046505this.flags = 0;6506}, {6507$documentation: "The `undefined` value",6508value: (function() {}())6509}, AST_Atom);65106511var AST_Hole = DEFNODE("Hole", null, function AST_Hole(props) {6512if (props) {6513this.start = props.start;6514this.end = props.end;6515}65166517this.flags = 0;6518}, {6519$documentation: "A hole in an array",6520value: (function() {}())6521}, AST_Atom);65226523var AST_Infinity = DEFNODE("Infinity", null, function AST_Infinity(props) {6524if (props) {6525this.start = props.start;6526this.end = props.end;6527}65286529this.flags = 0;6530}, {6531$documentation: "The `Infinity` value",6532value: 1/06533}, AST_Atom);65346535var AST_Boolean = DEFNODE("Boolean", null, function AST_Boolean(props) {6536if (props) {6537this.start = props.start;6538this.end = props.end;6539}65406541this.flags = 0;6542}, {6543$documentation: "Base class for booleans",6544}, AST_Atom);65456546var AST_False = DEFNODE("False", null, function AST_False(props) {6547if (props) {6548this.start = props.start;6549this.end = props.end;6550}65516552this.flags = 0;6553}, {6554$documentation: "The `false` atom",6555value: false6556}, AST_Boolean);65576558var AST_True = DEFNODE("True", null, function AST_True(props) {6559if (props) {6560this.start = props.start;6561this.end = props.end;6562}65636564this.flags = 0;6565}, {6566$documentation: "The `true` atom",6567value: true6568}, AST_Boolean);65696570/* -----[ Walk function ]---- */65716572/**6573* Walk nodes in depth-first search fashion.6574* Callback can return `walk_abort` symbol to stop iteration.6575* It can also return `true` to stop iteration just for child nodes.6576* Iteration can be stopped and continued by passing the `to_visit` argument,6577* which is given to the callback in the second argument.6578**/6579function walk(node, cb, to_visit = [node]) {6580const push = to_visit.push.bind(to_visit);6581while (to_visit.length) {6582const node = to_visit.pop();6583const ret = cb(node, to_visit);65846585if (ret) {6586if (ret === walk_abort) return true;6587continue;6588}65896590node._children_backwards(push);6591}6592return false;6593}65946595const walk_abort = Symbol("abort walk");65966597/* -----[ TreeWalker ]----- */65986599class TreeWalker {6600constructor(callback) {6601this.visit = callback;6602this.stack = [];6603this.directives = Object.create(null);6604}66056606_visit(node, descend) {6607this.push(node);6608var ret = this.visit(node, descend ? function() {6609descend.call(node);6610} : noop);6611if (!ret && descend) {6612descend.call(node);6613}6614this.pop();6615return ret;6616}66176618parent(n) {6619return this.stack[this.stack.length - 2 - (n || 0)];6620}66216622push(node) {6623if (node instanceof AST_Lambda) {6624this.directives = Object.create(this.directives);6625} else if (node instanceof AST_Directive && !this.directives[node.value]) {6626this.directives[node.value] = node;6627} else if (node instanceof AST_Class) {6628this.directives = Object.create(this.directives);6629if (!this.directives["use strict"]) {6630this.directives["use strict"] = node;6631}6632}6633this.stack.push(node);6634}66356636pop() {6637var node = this.stack.pop();6638if (node instanceof AST_Lambda || node instanceof AST_Class) {6639this.directives = Object.getPrototypeOf(this.directives);6640}6641}66426643self() {6644return this.stack[this.stack.length - 1];6645}66466647find_parent(type) {6648var stack = this.stack;6649for (var i = stack.length; --i >= 0;) {6650var x = stack[i];6651if (x instanceof type) return x;6652}6653}66546655find_scope() {6656var stack = this.stack;6657for (var i = stack.length; --i >= 0;) {6658const p = stack[i];6659if (p instanceof AST_Toplevel) return p;6660if (p instanceof AST_Lambda) return p;6661if (p.block_scope) return p.block_scope;6662}6663}66646665has_directive(type) {6666var dir = this.directives[type];6667if (dir) return dir;6668var node = this.stack[this.stack.length - 1];6669if (node instanceof AST_Scope && node.body) {6670for (var i = 0; i < node.body.length; ++i) {6671var st = node.body[i];6672if (!(st instanceof AST_Directive)) break;6673if (st.value == type) return st;6674}6675}6676}66776678loopcontrol_target(node) {6679var stack = this.stack;6680if (node.label) for (var i = stack.length; --i >= 0;) {6681var x = stack[i];6682if (x instanceof AST_LabeledStatement && x.label.name == node.label.name)6683return x.body;6684} else for (var i = stack.length; --i >= 0;) {6685var x = stack[i];6686if (x instanceof AST_IterationStatement6687|| node instanceof AST_Break && x instanceof AST_Switch)6688return x;6689}6690}6691}66926693// Tree transformer helpers.6694class TreeTransformer extends TreeWalker {6695constructor(before, after) {6696super();6697this.before = before;6698this.after = after;6699}6700}67016702const _PURE = 0b00000001;6703const _INLINE = 0b00000010;6704const _NOINLINE = 0b00000100;6705const _KEY = 0b00001000;6706const _MANGLEPROP = 0b00010000;67076708// XXX Emscripten: export TreeWalker for walking through AST in acorn-optimizer.mjs.6709exports.TreeWalker = TreeWalker;67106711/***********************************************************************67126713A JavaScript tokenizer / parser / beautifier / compressor.6714https://github.com/mishoo/UglifyJS267156716-------------------------------- (C) ---------------------------------67176718Author: Mihai Bazon6719<[email protected]>6720http://mihai.bazon.net/blog67216722Distributed under the BSD license:67236724Copyright 2012 (c) Mihai Bazon <[email protected]>67256726Redistribution and use in source and binary forms, with or without6727modification, are permitted provided that the following conditions6728are met:67296730* Redistributions of source code must retain the above6731copyright notice, this list of conditions and the following6732disclaimer.67336734* Redistributions in binary form must reproduce the above6735copyright notice, this list of conditions and the following6736disclaimer in the documentation and/or other materials6737provided with the distribution.67386739THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY6740EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE6741IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR6742PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE6743LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,6744OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,6745PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR6746PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY6747THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR6748TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF6749THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF6750SUCH DAMAGE.67516752***********************************************************************/67536754function def_transform(node, descend) {6755node.DEFMETHOD("transform", function(tw, in_list) {6756let transformed = undefined;6757tw.push(this);6758if (tw.before) transformed = tw.before(this, descend, in_list);6759if (transformed === undefined) {6760transformed = this;6761descend(transformed, tw);6762if (tw.after) {6763const after_ret = tw.after(transformed, in_list);6764if (after_ret !== undefined) transformed = after_ret;6765}6766}6767tw.pop();6768return transformed;6769});6770}67716772def_transform(AST_Node, noop);67736774def_transform(AST_LabeledStatement, function(self, tw) {6775self.label = self.label.transform(tw);6776self.body = self.body.transform(tw);6777});67786779def_transform(AST_SimpleStatement, function(self, tw) {6780self.body = self.body.transform(tw);6781});67826783def_transform(AST_Block, function(self, tw) {6784self.body = MAP(self.body, tw);6785});67866787def_transform(AST_Do, function(self, tw) {6788self.body = self.body.transform(tw);6789self.condition = self.condition.transform(tw);6790});67916792def_transform(AST_While, function(self, tw) {6793self.condition = self.condition.transform(tw);6794self.body = self.body.transform(tw);6795});67966797def_transform(AST_For, function(self, tw) {6798if (self.init) self.init = self.init.transform(tw);6799if (self.condition) self.condition = self.condition.transform(tw);6800if (self.step) self.step = self.step.transform(tw);6801self.body = self.body.transform(tw);6802});68036804def_transform(AST_ForIn, function(self, tw) {6805self.init = self.init.transform(tw);6806self.object = self.object.transform(tw);6807self.body = self.body.transform(tw);6808});68096810def_transform(AST_With, function(self, tw) {6811self.expression = self.expression.transform(tw);6812self.body = self.body.transform(tw);6813});68146815def_transform(AST_Exit, function(self, tw) {6816if (self.value) self.value = self.value.transform(tw);6817});68186819def_transform(AST_LoopControl, function(self, tw) {6820if (self.label) self.label = self.label.transform(tw);6821});68226823def_transform(AST_If, function(self, tw) {6824self.condition = self.condition.transform(tw);6825self.body = self.body.transform(tw);6826if (self.alternative) self.alternative = self.alternative.transform(tw);6827});68286829def_transform(AST_Switch, function(self, tw) {6830self.expression = self.expression.transform(tw);6831self.body = MAP(self.body, tw);6832});68336834def_transform(AST_Case, function(self, tw) {6835self.expression = self.expression.transform(tw);6836self.body = MAP(self.body, tw);6837});68386839def_transform(AST_Try, function(self, tw) {6840self.body = self.body.transform(tw);6841if (self.bcatch) self.bcatch = self.bcatch.transform(tw);6842if (self.bfinally) self.bfinally = self.bfinally.transform(tw);6843});68446845def_transform(AST_Catch, function(self, tw) {6846if (self.argname) self.argname = self.argname.transform(tw);6847self.body = MAP(self.body, tw);6848});68496850def_transform(AST_Definitions, function(self, tw) {6851self.definitions = MAP(self.definitions, tw);6852});68536854def_transform(AST_VarDef, function(self, tw) {6855self.name = self.name.transform(tw);6856if (self.value) self.value = self.value.transform(tw);6857});68586859def_transform(AST_Destructuring, function(self, tw) {6860self.names = MAP(self.names, tw);6861});68626863def_transform(AST_Lambda, function(self, tw) {6864if (self.name) self.name = self.name.transform(tw);6865self.argnames = MAP(self.argnames, tw, /* allow_splicing */ false);6866if (self.body instanceof AST_Node) {6867self.body = self.body.transform(tw);6868} else {6869self.body = MAP(self.body, tw);6870}6871});68726873def_transform(AST_Call, function(self, tw) {6874self.expression = self.expression.transform(tw);6875self.args = MAP(self.args, tw, /* allow_splicing */ false);6876});68776878def_transform(AST_Sequence, function(self, tw) {6879const result = MAP(self.expressions, tw);6880self.expressions = result.length6881? result6882: [new AST_Number({ value: 0 })];6883});68846885def_transform(AST_PropAccess, function(self, tw) {6886self.expression = self.expression.transform(tw);6887});68886889def_transform(AST_Sub, function(self, tw) {6890self.expression = self.expression.transform(tw);6891self.property = self.property.transform(tw);6892});68936894def_transform(AST_Chain, function(self, tw) {6895self.expression = self.expression.transform(tw);6896});68976898def_transform(AST_Yield, function(self, tw) {6899if (self.expression) self.expression = self.expression.transform(tw);6900});69016902def_transform(AST_Await, function(self, tw) {6903self.expression = self.expression.transform(tw);6904});69056906def_transform(AST_Unary, function(self, tw) {6907self.expression = self.expression.transform(tw);6908});69096910def_transform(AST_Binary, function(self, tw) {6911self.left = self.left.transform(tw);6912self.right = self.right.transform(tw);6913});69146915def_transform(AST_PrivateIn, function(self, tw) {6916self.key = self.key.transform(tw);6917self.value = self.value.transform(tw);6918});69196920def_transform(AST_Conditional, function(self, tw) {6921self.condition = self.condition.transform(tw);6922self.consequent = self.consequent.transform(tw);6923self.alternative = self.alternative.transform(tw);6924});69256926def_transform(AST_Array, function(self, tw) {6927self.elements = MAP(self.elements, tw);6928});69296930def_transform(AST_Object, function(self, tw) {6931self.properties = MAP(self.properties, tw);6932});69336934def_transform(AST_ObjectProperty, function(self, tw) {6935if (self.key instanceof AST_Node) {6936self.key = self.key.transform(tw);6937}6938if (self.value) self.value = self.value.transform(tw);6939});69406941def_transform(AST_Class, function(self, tw) {6942if (self.name) self.name = self.name.transform(tw);6943if (self.extends) self.extends = self.extends.transform(tw);6944self.properties = MAP(self.properties, tw);6945});69466947def_transform(AST_ClassStaticBlock, function(self, tw) {6948self.body = MAP(self.body, tw);6949});69506951def_transform(AST_Expansion, function(self, tw) {6952self.expression = self.expression.transform(tw);6953});69546955def_transform(AST_NameMapping, function(self, tw) {6956self.foreign_name = self.foreign_name.transform(tw);6957self.name = self.name.transform(tw);6958});69596960def_transform(AST_Import, function(self, tw) {6961if (self.imported_name) self.imported_name = self.imported_name.transform(tw);6962if (self.imported_names) MAP(self.imported_names, tw);6963self.module_name = self.module_name.transform(tw);6964});69656966def_transform(AST_Export, function(self, tw) {6967if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw);6968if (self.exported_value) self.exported_value = self.exported_value.transform(tw);6969if (self.exported_names) MAP(self.exported_names, tw);6970if (self.module_name) self.module_name = self.module_name.transform(tw);6971});69726973def_transform(AST_TemplateString, function(self, tw) {6974self.segments = MAP(self.segments, tw);6975});69766977def_transform(AST_PrefixedTemplateString, function(self, tw) {6978self.prefix = self.prefix.transform(tw);6979self.template_string = self.template_string.transform(tw);6980});69816982/***********************************************************************69836984A JavaScript tokenizer / parser / beautifier / compressor.6985https://github.com/mishoo/UglifyJS269866987-------------------------------- (C) ---------------------------------69886989Author: Mihai Bazon6990<[email protected]>6991http://mihai.bazon.net/blog69926993Distributed under the BSD license:69946995Copyright 2012 (c) Mihai Bazon <[email protected]>69966997Redistribution and use in source and binary forms, with or without6998modification, are permitted provided that the following conditions6999are met:70007001* Redistributions of source code must retain the above7002copyright notice, this list of conditions and the following7003disclaimer.70047005* Redistributions in binary form must reproduce the above7006copyright notice, this list of conditions and the following7007disclaimer in the documentation and/or other materials7008provided with the distribution.70097010THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY7011EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE7012IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR7013PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE7014LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,7015OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,7016PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR7017PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY7018THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR7019TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF7020THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF7021SUCH DAMAGE.70227023***********************************************************************/70247025(function() {70267027var normalize_directives = function(body) {7028var in_directive = true;70297030for (var i = 0; i < body.length; i++) {7031if (in_directive && body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {7032body[i] = new AST_Directive({7033start: body[i].start,7034end: body[i].end,7035value: body[i].body.value7036});7037} else if (in_directive && !(body[i] instanceof AST_Statement && body[i].body instanceof AST_String)) {7038in_directive = false;7039}7040}70417042return body;7043};70447045const assert_clause_from_moz = (assertions) => {7046if (assertions && assertions.length > 0) {7047return new AST_Object({7048start: my_start_token(assertions),7049end: my_end_token(assertions),7050properties: assertions.map((assertion_kv) =>7051new AST_ObjectKeyVal({7052start: my_start_token(assertion_kv),7053end: my_end_token(assertion_kv),7054key: assertion_kv.key.name || assertion_kv.key.value,7055value: from_moz(assertion_kv.value)7056})7057)7058});7059}7060return null;7061};70627063var MOZ_TO_ME = {7064Program: function(M) {7065return new AST_Toplevel({7066start: my_start_token(M),7067end: my_end_token(M),7068body: normalize_directives(M.body.map(from_moz))7069});7070},70717072ArrayPattern: function(M) {7073return new AST_Destructuring({7074start: my_start_token(M),7075end: my_end_token(M),7076names: M.elements.map(function(elm) {7077if (elm === null) {7078return new AST_Hole();7079}7080return from_moz(elm);7081}),7082is_array: true7083});7084},70857086ObjectPattern: function(M) {7087return new AST_Destructuring({7088start: my_start_token(M),7089end: my_end_token(M),7090names: M.properties.map(from_moz),7091is_array: false7092});7093},70947095AssignmentPattern: function(M) {7096return new AST_DefaultAssign({7097start: my_start_token(M),7098end: my_end_token(M),7099left: from_moz(M.left),7100operator: "=",7101right: from_moz(M.right)7102});7103},71047105SpreadElement: function(M) {7106return new AST_Expansion({7107start: my_start_token(M),7108end: my_end_token(M),7109expression: from_moz(M.argument)7110});7111},71127113RestElement: function(M) {7114return new AST_Expansion({7115start: my_start_token(M),7116end: my_end_token(M),7117expression: from_moz(M.argument)7118});7119},71207121TemplateElement: function(M) {7122return new AST_TemplateSegment({7123start: my_start_token(M),7124end: my_end_token(M),7125value: M.value.cooked,7126raw: M.value.raw7127});7128},71297130TemplateLiteral: function(M) {7131var segments = [];7132for (var i = 0; i < M.quasis.length; i++) {7133segments.push(from_moz(M.quasis[i]));7134if (M.expressions[i]) {7135segments.push(from_moz(M.expressions[i]));7136}7137}7138return new AST_TemplateString({7139start: my_start_token(M),7140end: my_end_token(M),7141segments: segments7142});7143},71447145TaggedTemplateExpression: function(M) {7146return new AST_PrefixedTemplateString({7147start: my_start_token(M),7148end: my_end_token(M),7149template_string: from_moz(M.quasi),7150prefix: from_moz(M.tag)7151});7152},71537154FunctionDeclaration: function(M) {7155return new AST_Defun({7156start: my_start_token(M),7157end: my_end_token(M),7158name: from_moz(M.id),7159argnames: M.params.map(from_moz),7160is_generator: M.generator,7161async: M.async,7162body: normalize_directives(from_moz(M.body).body)7163});7164},71657166FunctionExpression: function(M) {7167return new AST_Function({7168start: my_start_token(M),7169end: my_end_token(M),7170name: from_moz(M.id),7171argnames: M.params.map(from_moz),7172is_generator: M.generator,7173async: M.async,7174body: normalize_directives(from_moz(M.body).body)7175});7176},71777178ArrowFunctionExpression: function(M) {7179const body = M.body.type === "BlockStatement"7180? from_moz(M.body).body7181: [make_node(AST_Return, {}, { value: from_moz(M.body) })];7182return new AST_Arrow({7183start: my_start_token(M),7184end: my_end_token(M),7185argnames: M.params.map(from_moz),7186body,7187async: M.async,7188});7189},71907191ExpressionStatement: function(M) {7192return new AST_SimpleStatement({7193start: my_start_token(M),7194end: my_end_token(M),7195body: from_moz(M.expression)7196});7197},71987199// XXX Emscripten localmod: Add a node type for a parenthesized expression so that we can retain7200// Closure annotations that need a form "/**annotation*/(expression)"7201ParenthesizedExpression: function(M) {7202return new AST_ParenthesizedExpression({7203start: my_start_token(M),7204end: my_end_token(M),7205body: from_moz(M.expression)7206});7207},7208// XXX End Emscripten localmod72097210TryStatement: function(M) {7211var handlers = M.handlers || [M.handler];7212if (handlers.length > 1 || M.guardedHandlers && M.guardedHandlers.length) {7213throw new Error("Multiple catch clauses are not supported.");7214}7215return new AST_Try({7216start : my_start_token(M),7217end : my_end_token(M),7218body : new AST_TryBlock(from_moz(M.block)),7219bcatch : from_moz(handlers[0]),7220bfinally : M.finalizer ? new AST_Finally(from_moz(M.finalizer)) : null7221});7222},72237224Property: function(M) {7225var key = M.key;7226var args = {7227start : my_start_token(key || M.value),7228end : my_end_token(M.value),7229key : key.type == "Identifier" ? key.name : key.value,7230value : from_moz(M.value)7231};7232if (M.computed) {7233args.key = from_moz(M.key);7234}7235if (M.method) {7236args.is_generator = M.value.generator;7237args.async = M.value.async;7238if (!M.computed) {7239args.key = new AST_SymbolMethod({ name: args.key });7240} else {7241args.key = from_moz(M.key);7242}7243return new AST_ConciseMethod(args);7244}7245if (M.kind == "init") {7246if (key.type != "Identifier" && key.type != "Literal") {7247args.key = from_moz(key);7248}7249return new AST_ObjectKeyVal(args);7250}7251if (typeof args.key === "string" || typeof args.key === "number") {7252args.key = new AST_SymbolMethod({7253name: args.key7254});7255}7256args.value = new AST_Accessor(args.value);7257if (M.kind == "get") return new AST_ObjectGetter(args);7258if (M.kind == "set") return new AST_ObjectSetter(args);7259if (M.kind == "method") {7260args.async = M.value.async;7261args.is_generator = M.value.generator;7262args.quote = M.computed ? "\"" : null;7263return new AST_ConciseMethod(args);7264}7265},72667267MethodDefinition: function(M) {7268const is_private = M.key.type === "PrivateIdentifier";7269const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value });72707271var args = {7272start : my_start_token(M),7273end : my_end_token(M),7274key,7275value : from_moz(M.value),7276static : M.static,7277};7278if (M.kind == "get") {7279return new (is_private ? AST_PrivateGetter : AST_ObjectGetter)(args);7280}7281if (M.kind == "set") {7282return new (is_private ? AST_PrivateSetter : AST_ObjectSetter)(args);7283}7284args.is_generator = M.value.generator;7285args.async = M.value.async;7286return new (is_private ? AST_PrivateMethod : AST_ConciseMethod)(args);7287},72887289FieldDefinition: function(M) {7290let key;7291if (M.computed) {7292key = from_moz(M.key);7293} else {7294if (M.key.type !== "Identifier") throw new Error("Non-Identifier key in FieldDefinition");7295key = from_moz(M.key);7296}7297return new AST_ClassProperty({7298start : my_start_token(M),7299end : my_end_token(M),7300key,7301value : from_moz(M.value),7302static : M.static,7303});7304},73057306PropertyDefinition: function(M) {7307let key;7308if (M.computed) {7309key = from_moz(M.key);7310} else if (M.key.type === "PrivateIdentifier") {7311return new AST_ClassPrivateProperty({7312start : my_start_token(M),7313end : my_end_token(M),7314key : from_moz(M.key),7315value : from_moz(M.value),7316static : M.static,7317});7318} else {7319if (M.key.type !== "Identifier") {7320throw new Error("Non-Identifier key in PropertyDefinition");7321}7322key = from_moz(M.key);7323}73247325return new AST_ClassProperty({7326start : my_start_token(M),7327end : my_end_token(M),7328key,7329value : from_moz(M.value),7330static : M.static,7331});7332},73337334PrivateIdentifier: function (M) {7335return new AST_SymbolPrivateProperty({7336start: my_start_token(M),7337end: my_end_token(M),7338name: M.name7339});7340},73417342StaticBlock: function(M) {7343return new AST_ClassStaticBlock({7344start : my_start_token(M),7345end : my_end_token(M),7346body : M.body.map(from_moz),7347});7348},73497350ArrayExpression: function(M) {7351return new AST_Array({7352start : my_start_token(M),7353end : my_end_token(M),7354elements : M.elements.map(function(elem) {7355return elem === null ? new AST_Hole() : from_moz(elem);7356})7357});7358},73597360ObjectExpression: function(M) {7361return new AST_Object({7362start : my_start_token(M),7363end : my_end_token(M),7364properties : M.properties.map(function(prop) {7365if (prop.type === "SpreadElement") {7366return from_moz(prop);7367}7368prop.type = "Property";7369// XXX EMSCRIPTEN preserve quoted properties7370// https://github.com/mishoo/UglifyJS2/pull/33237371var ret = from_moz(prop);7372if (prop.key.type === "Literal" &&7373(prop.key.raw[0] === '"' || prop.key.raw[0] === "'")) {7374ret.quote = true;7375}7376return ret;7377})7378});7379},73807381SequenceExpression: function(M) {7382return new AST_Sequence({7383start : my_start_token(M),7384end : my_end_token(M),7385expressions: M.expressions.map(from_moz)7386});7387},73887389MemberExpression: function(M) {7390if (M.property.type === "PrivateIdentifier") {7391return new AST_DotHash({7392start : my_start_token(M),7393end : my_end_token(M),7394property : M.property.name,7395expression : from_moz(M.object),7396optional : M.optional || false7397});7398}7399return new (M.computed ? AST_Sub : AST_Dot)({7400start : my_start_token(M),7401end : my_end_token(M),7402property : M.computed ? from_moz(M.property) : M.property.name,7403expression : from_moz(M.object),7404optional : M.optional || false7405});7406},74077408ChainExpression: function(M) {7409return new AST_Chain({7410start : my_start_token(M),7411end : my_end_token(M),7412expression : from_moz(M.expression)7413});7414},74157416SwitchCase: function(M) {7417return new (M.test ? AST_Case : AST_Default)({7418start : my_start_token(M),7419end : my_end_token(M),7420expression : from_moz(M.test),7421body : M.consequent.map(from_moz)7422});7423},74247425VariableDeclaration: function(M) {7426return new (M.kind === "const" ? AST_Const :7427M.kind === "let" ? AST_Let : AST_Var)({7428start : my_start_token(M),7429end : my_end_token(M),7430definitions : M.declarations.map(from_moz)7431});7432},74337434ImportDeclaration: function(M) {7435var imported_name = null;7436var imported_names = null;7437M.specifiers.forEach(function (specifier) {7438if (specifier.type === "ImportSpecifier" || specifier.type === "ImportNamespaceSpecifier") {7439if (!imported_names) { imported_names = []; }7440imported_names.push(from_moz(specifier));7441} else if (specifier.type === "ImportDefaultSpecifier") {7442imported_name = from_moz(specifier);7443}7444});7445return new AST_Import({7446start : my_start_token(M),7447end : my_end_token(M),7448imported_name: imported_name,7449imported_names : imported_names,7450module_name : from_moz(M.source),7451assert_clause: assert_clause_from_moz(M.assertions)7452});7453},74547455ImportSpecifier: function(M) {7456return new AST_NameMapping({7457start: my_start_token(M),7458end: my_end_token(M),7459foreign_name: from_moz(M.imported),7460name: from_moz(M.local)7461});7462},74637464ImportDefaultSpecifier: function(M) {7465return from_moz(M.local);7466},74677468ImportNamespaceSpecifier: function(M) {7469return new AST_NameMapping({7470start: my_start_token(M),7471end: my_end_token(M),7472foreign_name: new AST_SymbolImportForeign({ name: "*" }),7473name: from_moz(M.local)7474});7475},74767477ExportAllDeclaration: function(M) {7478var foreign_name = M.exported == null ?7479new AST_SymbolExportForeign({ name: "*" }) :7480from_moz(M.exported);7481return new AST_Export({7482start: my_start_token(M),7483end: my_end_token(M),7484exported_names: [7485new AST_NameMapping({7486name: new AST_SymbolExportForeign({ name: "*" }),7487foreign_name: foreign_name7488})7489],7490module_name: from_moz(M.source),7491assert_clause: assert_clause_from_moz(M.assertions)7492});7493},74947495ExportNamedDeclaration: function(M) {7496return new AST_Export({7497start: my_start_token(M),7498end: my_end_token(M),7499exported_definition: from_moz(M.declaration),7500exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(function (specifier) {7501return from_moz(specifier);7502}) : null,7503module_name: from_moz(M.source),7504assert_clause: assert_clause_from_moz(M.assertions)7505});7506},75077508ExportDefaultDeclaration: function(M) {7509return new AST_Export({7510start: my_start_token(M),7511end: my_end_token(M),7512exported_value: from_moz(M.declaration),7513is_default: true7514});7515},75167517ExportSpecifier: function(M) {7518return new AST_NameMapping({7519foreign_name: from_moz(M.exported),7520name: from_moz(M.local)7521});7522},75237524Literal: function(M) {7525var val = M.value, args = {7526start : my_start_token(M),7527end : my_end_token(M)7528};7529var rx = M.regex;7530if (rx && rx.pattern) {7531// RegExpLiteral as per ESTree AST spec7532args.value = {7533source: rx.pattern,7534flags: rx.flags7535};7536return new AST_RegExp(args);7537} else if (rx) {7538// support legacy RegExp7539const rx_source = M.raw || val;7540const match = rx_source.match(/^\/(.*)\/(\w*)$/);7541if (!match) throw new Error("Invalid regex source " + rx_source);7542const [_, source, flags] = match;7543args.value = { source, flags };7544return new AST_RegExp(args);7545}7546if (val === null) return new AST_Null(args);7547switch (typeof val) {7548case "string":7549args.quote = "\"";7550var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];7551if (p.type == "ImportSpecifier") {7552args.name = val;7553return new AST_SymbolImportForeign(args);7554} else if (p.type == "ExportSpecifier") {7555args.name = val;7556if (M == p.exported) {7557return new AST_SymbolExportForeign(args);7558} else {7559return new AST_SymbolExport(args);7560}7561} else if (p.type == "ExportAllDeclaration" && M == p.exported) {7562args.name = val;7563return new AST_SymbolExportForeign(args);7564}7565args.value = val;7566return new AST_String(args);7567case "number":7568args.value = val;7569args.raw = M.raw || val.toString();7570return new AST_Number(args);7571case "boolean":7572return new (val ? AST_True : AST_False)(args);7573case "bigint":7574args.value = val;7575return new AST_BigInt(args);7576case "undefined":7577return undefined;7578default:7579throw new Error("Unhandled value type: " + typeof val);7580}7581},75827583MetaProperty: function(M) {7584if (M.meta.name === "new" && M.property.name === "target") {7585return new AST_NewTarget({7586start: my_start_token(M),7587end: my_end_token(M)7588});7589} else if (M.meta.name === "import" && M.property.name === "meta") {7590return new AST_ImportMeta({7591start: my_start_token(M),7592end: my_end_token(M)7593});7594}7595},75967597Identifier: function(M) {7598var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];7599return new ( p.type == "LabeledStatement" ? AST_Label7600: p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : p.kind == "let" ? AST_SymbolLet : AST_SymbolVar)7601: /Import.*Specifier/.test(p.type) ? (p.local === M ? AST_SymbolImport : AST_SymbolImportForeign)7602: p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)7603: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)7604: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)7605: p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef7606: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)7607: p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)7608: p.type == "PropertyDefinition" || p.type === "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)7609: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)7610: p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)7611: p.type == "CatchClause" ? AST_SymbolCatch7612: p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef7613: AST_SymbolRef)({7614start : my_start_token(M),7615end : my_end_token(M),7616name : M.name7617});7618},76197620BigIntLiteral(M) {7621return new AST_BigInt({7622start : my_start_token(M),7623end : my_end_token(M),7624value : M.value7625});7626},76277628EmptyStatement: function(M) {7629return new AST_EmptyStatement({7630start: my_start_token(M),7631end: my_end_token(M)7632});7633},76347635BlockStatement: function(M) {7636return new AST_BlockStatement({7637start: my_start_token(M),7638end: my_end_token(M),7639body: M.body.map(from_moz)7640});7641},76427643IfStatement: function(M) {7644return new AST_If({7645start: my_start_token(M),7646end: my_end_token(M),7647condition: from_moz(M.test),7648body: from_moz(M.consequent),7649alternative: from_moz(M.alternate)7650});7651},76527653LabeledStatement: function(M) {7654return new AST_LabeledStatement({7655start: my_start_token(M),7656end: my_end_token(M),7657label: from_moz(M.label),7658body: from_moz(M.body)7659});7660},76617662BreakStatement: function(M) {7663return new AST_Break({7664start: my_start_token(M),7665end: my_end_token(M),7666label: from_moz(M.label)7667});7668},76697670ContinueStatement: function(M) {7671return new AST_Continue({7672start: my_start_token(M),7673end: my_end_token(M),7674label: from_moz(M.label)7675});7676},76777678WithStatement: function(M) {7679return new AST_With({7680start: my_start_token(M),7681end: my_end_token(M),7682expression: from_moz(M.object),7683body: from_moz(M.body)7684});7685},76867687SwitchStatement: function(M) {7688return new AST_Switch({7689start: my_start_token(M),7690end: my_end_token(M),7691expression: from_moz(M.discriminant),7692body: M.cases.map(from_moz)7693});7694},76957696ReturnStatement: function(M) {7697return new AST_Return({7698start: my_start_token(M),7699end: my_end_token(M),7700value: from_moz(M.argument)7701});7702},77037704ThrowStatement: function(M) {7705return new AST_Throw({7706start: my_start_token(M),7707end: my_end_token(M),7708value: from_moz(M.argument)7709});7710},77117712WhileStatement: function(M) {7713return new AST_While({7714start: my_start_token(M),7715end: my_end_token(M),7716condition: from_moz(M.test),7717body: from_moz(M.body)7718});7719},77207721DoWhileStatement: function(M) {7722return new AST_Do({7723start: my_start_token(M),7724end: my_end_token(M),7725condition: from_moz(M.test),7726body: from_moz(M.body)7727});7728},77297730ForStatement: function(M) {7731return new AST_For({7732start: my_start_token(M),7733end: my_end_token(M),7734init: from_moz(M.init),7735condition: from_moz(M.test),7736step: from_moz(M.update),7737body: from_moz(M.body)7738});7739},77407741ForInStatement: function(M) {7742return new AST_ForIn({7743start: my_start_token(M),7744end: my_end_token(M),7745init: from_moz(M.left),7746object: from_moz(M.right),7747body: from_moz(M.body)7748});7749},77507751ForOfStatement: function(M) {7752return new AST_ForOf({7753start: my_start_token(M),7754end: my_end_token(M),7755init: from_moz(M.left),7756object: from_moz(M.right),7757body: from_moz(M.body),7758await: M.await7759});7760},77617762AwaitExpression: function(M) {7763return new AST_Await({7764start: my_start_token(M),7765end: my_end_token(M),7766expression: from_moz(M.argument)7767});7768},77697770YieldExpression: function(M) {7771return new AST_Yield({7772start: my_start_token(M),7773end: my_end_token(M),7774expression: from_moz(M.argument),7775is_star: M.delegate7776});7777},77787779DebuggerStatement: function(M) {7780return new AST_Debugger({7781start: my_start_token(M),7782end: my_end_token(M)7783});7784},77857786VariableDeclarator: function(M) {7787return new AST_VarDef({7788start: my_start_token(M),7789end: my_end_token(M),7790name: from_moz(M.id),7791value: from_moz(M.init)7792});7793},77947795CatchClause: function(M) {7796return new AST_Catch({7797start: my_start_token(M),7798end: my_end_token(M),7799argname: from_moz(M.param),7800body: from_moz(M.body).body7801});7802},78037804ThisExpression: function(M) {7805return new AST_This({7806start: my_start_token(M),7807end: my_end_token(M)7808});7809},78107811Super: function(M) {7812return new AST_Super({7813start: my_start_token(M),7814end: my_end_token(M)7815});7816},78177818BinaryExpression: function(M) {7819if (M.left.type === "PrivateIdentifier") {7820return new AST_PrivateIn({7821start: my_start_token(M),7822end: my_end_token(M),7823key: new AST_SymbolPrivateProperty({7824start: my_start_token(M.left),7825end: my_end_token(M.left),7826name: M.left.name7827}),7828value: from_moz(M.right),7829});7830}7831return new AST_Binary({7832start: my_start_token(M),7833end: my_end_token(M),7834operator: M.operator,7835left: from_moz(M.left),7836right: from_moz(M.right)7837});7838},78397840LogicalExpression: function(M) {7841return new AST_Binary({7842start: my_start_token(M),7843end: my_end_token(M),7844operator: M.operator,7845left: from_moz(M.left),7846right: from_moz(M.right)7847});7848},78497850AssignmentExpression: function(M) {7851return new AST_Assign({7852start: my_start_token(M),7853end: my_end_token(M),7854operator: M.operator,7855left: from_moz(M.left),7856right: from_moz(M.right)7857});7858},78597860ConditionalExpression: function(M) {7861return new AST_Conditional({7862start: my_start_token(M),7863end: my_end_token(M),7864condition: from_moz(M.test),7865consequent: from_moz(M.consequent),7866alternative: from_moz(M.alternate)7867});7868},78697870NewExpression: function(M) {7871return new AST_New({7872start: my_start_token(M),7873end: my_end_token(M),7874expression: from_moz(M.callee),7875args: M.arguments.map(from_moz)7876});7877},78787879CallExpression: function(M) {7880return new AST_Call({7881start: my_start_token(M),7882end: my_end_token(M),7883expression: from_moz(M.callee),7884optional: M.optional,7885args: M.arguments.map(from_moz)7886});7887},78887889ImportExpression: function(M) {7890let import_token = my_start_token(M);7891return new AST_Call({7892start : import_token,7893end : my_end_token(M),7894expression : new AST_SymbolRef({7895start : import_token,7896end : import_token,7897name : "import"7898}),7899args : [from_moz(M.source)]7900});7901}7902};79037904MOZ_TO_ME.UpdateExpression =7905MOZ_TO_ME.UnaryExpression = function To_Moz_Unary(M) {7906var prefix = "prefix" in M ? M.prefix7907: M.type == "UnaryExpression" ? true : false;7908return new (prefix ? AST_UnaryPrefix : AST_UnaryPostfix)({7909start : my_start_token(M),7910end : my_end_token(M),7911operator : M.operator,7912expression : from_moz(M.argument)7913});7914};79157916MOZ_TO_ME.ClassDeclaration =7917MOZ_TO_ME.ClassExpression = function From_Moz_Class(M) {7918return new (M.type === "ClassDeclaration" ? AST_DefClass : AST_ClassExpression)({7919start : my_start_token(M),7920end : my_end_token(M),7921name : from_moz(M.id),7922extends : from_moz(M.superClass),7923properties: M.body.body.map(from_moz)7924});7925};79267927def_to_moz(AST_EmptyStatement, function To_Moz_EmptyStatement() {7928return {7929type: "EmptyStatement"7930};7931});7932def_to_moz(AST_BlockStatement, function To_Moz_BlockStatement(M) {7933return {7934type: "BlockStatement",7935body: M.body.map(to_moz)7936};7937});7938def_to_moz(AST_If, function To_Moz_IfStatement(M) {7939return {7940type: "IfStatement",7941test: to_moz(M.condition),7942consequent: to_moz(M.body),7943alternate: to_moz(M.alternative)7944};7945});7946def_to_moz(AST_LabeledStatement, function To_Moz_LabeledStatement(M) {7947return {7948type: "LabeledStatement",7949label: to_moz(M.label),7950body: to_moz(M.body)7951};7952});7953def_to_moz(AST_Break, function To_Moz_BreakStatement(M) {7954return {7955type: "BreakStatement",7956label: to_moz(M.label)7957};7958});7959def_to_moz(AST_Continue, function To_Moz_ContinueStatement(M) {7960return {7961type: "ContinueStatement",7962label: to_moz(M.label)7963};7964});7965def_to_moz(AST_With, function To_Moz_WithStatement(M) {7966return {7967type: "WithStatement",7968object: to_moz(M.expression),7969body: to_moz(M.body)7970};7971});7972def_to_moz(AST_Switch, function To_Moz_SwitchStatement(M) {7973return {7974type: "SwitchStatement",7975discriminant: to_moz(M.expression),7976cases: M.body.map(to_moz)7977};7978});7979def_to_moz(AST_Return, function To_Moz_ReturnStatement(M) {7980return {7981type: "ReturnStatement",7982argument: to_moz(M.value)7983};7984});7985def_to_moz(AST_Throw, function To_Moz_ThrowStatement(M) {7986return {7987type: "ThrowStatement",7988argument: to_moz(M.value)7989};7990});7991def_to_moz(AST_While, function To_Moz_WhileStatement(M) {7992return {7993type: "WhileStatement",7994test: to_moz(M.condition),7995body: to_moz(M.body)7996};7997});7998def_to_moz(AST_Do, function To_Moz_DoWhileStatement(M) {7999return {8000type: "DoWhileStatement",8001test: to_moz(M.condition),8002body: to_moz(M.body)8003};8004});8005def_to_moz(AST_For, function To_Moz_ForStatement(M) {8006return {8007type: "ForStatement",8008init: to_moz(M.init),8009test: to_moz(M.condition),8010update: to_moz(M.step),8011body: to_moz(M.body)8012};8013});8014def_to_moz(AST_ForIn, function To_Moz_ForInStatement(M) {8015return {8016type: "ForInStatement",8017left: to_moz(M.init),8018right: to_moz(M.object),8019body: to_moz(M.body)8020};8021});8022def_to_moz(AST_ForOf, function To_Moz_ForOfStatement(M) {8023return {8024type: "ForOfStatement",8025left: to_moz(M.init),8026right: to_moz(M.object),8027body: to_moz(M.body),8028await: M.await8029};8030});8031def_to_moz(AST_Await, function To_Moz_AwaitExpression(M) {8032return {8033type: "AwaitExpression",8034argument: to_moz(M.expression)8035};8036});8037def_to_moz(AST_Yield, function To_Moz_YieldExpression(M) {8038return {8039type: "YieldExpression",8040argument: to_moz(M.expression),8041delegate: M.is_star8042};8043});8044def_to_moz(AST_Debugger, function To_Moz_DebuggerStatement() {8045return {8046type: "DebuggerStatement"8047};8048});8049def_to_moz(AST_VarDef, function To_Moz_VariableDeclarator(M) {8050return {8051type: "VariableDeclarator",8052id: to_moz(M.name),8053init: to_moz(M.value)8054};8055});8056def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {8057return {8058type: "CatchClause",8059param: to_moz(M.argname),8060body: to_moz_block(M)8061};8062});80638064def_to_moz(AST_This, function To_Moz_ThisExpression() {8065return {8066type: "ThisExpression"8067};8068});8069def_to_moz(AST_Super, function To_Moz_Super() {8070return {8071type: "Super"8072};8073});8074def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {8075return {8076type: "BinaryExpression",8077operator: M.operator,8078left: to_moz(M.left),8079right: to_moz(M.right)8080};8081});8082def_to_moz(AST_Binary, function To_Moz_LogicalExpression(M) {8083return {8084type: "LogicalExpression",8085operator: M.operator,8086left: to_moz(M.left),8087right: to_moz(M.right)8088};8089});8090def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {8091return {8092type: "AssignmentExpression",8093operator: M.operator,8094left: to_moz(M.left),8095right: to_moz(M.right)8096};8097});8098def_to_moz(AST_Conditional, function To_Moz_ConditionalExpression(M) {8099return {8100type: "ConditionalExpression",8101test: to_moz(M.condition),8102consequent: to_moz(M.consequent),8103alternate: to_moz(M.alternative)8104};8105});8106def_to_moz(AST_New, function To_Moz_NewExpression(M) {8107return {8108type: "NewExpression",8109callee: to_moz(M.expression),8110arguments: M.args.map(to_moz)8111};8112});8113def_to_moz(AST_Call, function To_Moz_CallExpression(M) {8114return {8115type: "CallExpression",8116callee: to_moz(M.expression),8117optional: M.optional,8118arguments: M.args.map(to_moz)8119};8120});81218122def_to_moz(AST_Toplevel, function To_Moz_Program(M) {8123return to_moz_scope("Program", M);8124});81258126def_to_moz(AST_Expansion, function To_Moz_Spread(M) {8127return {8128type: to_moz_in_destructuring() ? "RestElement" : "SpreadElement",8129argument: to_moz(M.expression)8130};8131});81328133def_to_moz(AST_PrefixedTemplateString, function To_Moz_TaggedTemplateExpression(M) {8134return {8135type: "TaggedTemplateExpression",8136tag: to_moz(M.prefix),8137quasi: to_moz(M.template_string)8138};8139});81408141def_to_moz(AST_TemplateString, function To_Moz_TemplateLiteral(M) {8142var quasis = [];8143var expressions = [];8144for (var i = 0; i < M.segments.length; i++) {8145if (i % 2 !== 0) {8146expressions.push(to_moz(M.segments[i]));8147} else {8148quasis.push({8149type: "TemplateElement",8150value: {8151raw: M.segments[i].raw,8152cooked: M.segments[i].value8153},8154tail: i === M.segments.length - 18155});8156}8157}8158return {8159type: "TemplateLiteral",8160quasis: quasis,8161expressions: expressions8162};8163});81648165def_to_moz(AST_Defun, function To_Moz_FunctionDeclaration(M) {8166return {8167type: "FunctionDeclaration",8168id: to_moz(M.name),8169params: M.argnames.map(to_moz),8170generator: M.is_generator,8171async: M.async,8172body: to_moz_scope("BlockStatement", M)8173};8174});81758176def_to_moz(AST_Function, function To_Moz_FunctionExpression(M, parent) {8177var is_generator = parent.is_generator !== undefined ?8178parent.is_generator : M.is_generator;8179return {8180type: "FunctionExpression",8181id: to_moz(M.name),8182params: M.argnames.map(to_moz),8183generator: is_generator,8184async: M.async,8185body: to_moz_scope("BlockStatement", M)8186};8187});81888189def_to_moz(AST_Arrow, function To_Moz_ArrowFunctionExpression(M) {8190var body = {8191type: "BlockStatement",8192body: M.body.map(to_moz)8193};8194return {8195type: "ArrowFunctionExpression",8196params: M.argnames.map(to_moz),8197async: M.async,8198body: body8199};8200});82018202def_to_moz(AST_Destructuring, function To_Moz_ObjectPattern(M) {8203if (M.is_array) {8204return {8205type: "ArrayPattern",8206elements: M.names.map(to_moz)8207};8208}8209return {8210type: "ObjectPattern",8211properties: M.names.map(to_moz)8212};8213});82148215def_to_moz(AST_Directive, function To_Moz_Directive(M) {8216return {8217type: "ExpressionStatement",8218expression: {8219type: "Literal",8220value: M.value,8221raw: M.print_to_string()8222},8223directive: M.value8224};8225});82268227def_to_moz(AST_SimpleStatement, function To_Moz_ExpressionStatement(M) {8228return {8229type: "ExpressionStatement",8230expression: to_moz(M.body)8231};8232});82338234def_to_moz(AST_SwitchBranch, function To_Moz_SwitchCase(M) {8235return {8236type: "SwitchCase",8237test: to_moz(M.expression),8238consequent: M.body.map(to_moz)8239};8240});82418242def_to_moz(AST_Try, function To_Moz_TryStatement(M) {8243return {8244type: "TryStatement",8245block: to_moz_block(M.body),8246handler: to_moz(M.bcatch),8247guardedHandlers: [],8248finalizer: to_moz(M.bfinally)8249};8250});82518252def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {8253return {8254type: "CatchClause",8255param: to_moz(M.argname),8256guard: null,8257body: to_moz_block(M)8258};8259});82608261def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {8262return {8263type: "VariableDeclaration",8264kind:8265M instanceof AST_Const ? "const" :8266M instanceof AST_Let ? "let" : "var",8267declarations: M.definitions.map(to_moz)8268};8269});82708271const assert_clause_to_moz = assert_clause => {8272const assertions = [];8273if (assert_clause) {8274for (const { key, value } of assert_clause.properties) {8275const key_moz = is_basic_identifier_string(key)8276? { type: "Identifier", name: key }8277: { type: "Literal", value: key, raw: JSON.stringify(key) };8278assertions.push({8279type: "ImportAttribute",8280key: key_moz,8281value: to_moz(value)8282});8283}8284}8285return assertions;8286};82878288def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {8289if (M.exported_names) {8290var first_exported = M.exported_names[0];8291var first_exported_name = first_exported.name;8292if (first_exported_name.name === "*" && !first_exported_name.quote) {8293var foreign_name = first_exported.foreign_name;8294var exported = foreign_name.name === "*" && !foreign_name.quote8295? null8296: to_moz(foreign_name);8297return {8298type: "ExportAllDeclaration",8299source: to_moz(M.module_name),8300exported: exported,8301assertions: assert_clause_to_moz(M.assert_clause)8302};8303}8304return {8305type: "ExportNamedDeclaration",8306specifiers: M.exported_names.map(function (name_mapping) {8307return {8308type: "ExportSpecifier",8309exported: to_moz(name_mapping.foreign_name),8310local: to_moz(name_mapping.name)8311};8312}),8313declaration: to_moz(M.exported_definition),8314source: to_moz(M.module_name),8315assertions: assert_clause_to_moz(M.assert_clause)8316};8317}8318return {8319type: M.is_default ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",8320declaration: to_moz(M.exported_value || M.exported_definition)8321};8322});83238324def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) {8325var specifiers = [];8326if (M.imported_name) {8327specifiers.push({8328type: "ImportDefaultSpecifier",8329local: to_moz(M.imported_name)8330});8331}8332if (M.imported_names) {8333var first_imported_foreign_name = M.imported_names[0].foreign_name;8334if (first_imported_foreign_name.name === "*" && !first_imported_foreign_name.quote) {8335specifiers.push({8336type: "ImportNamespaceSpecifier",8337local: to_moz(M.imported_names[0].name)8338});8339} else {8340M.imported_names.forEach(function(name_mapping) {8341specifiers.push({8342type: "ImportSpecifier",8343local: to_moz(name_mapping.name),8344imported: to_moz(name_mapping.foreign_name)8345});8346});8347}8348}8349return {8350type: "ImportDeclaration",8351specifiers: specifiers,8352source: to_moz(M.module_name),8353assertions: assert_clause_to_moz(M.assert_clause)8354};8355});83568357def_to_moz(AST_ImportMeta, function To_Moz_MetaProperty() {8358return {8359type: "MetaProperty",8360meta: {8361type: "Identifier",8362name: "import"8363},8364property: {8365type: "Identifier",8366name: "meta"8367}8368};8369});83708371def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) {8372return {8373type: "SequenceExpression",8374expressions: M.expressions.map(to_moz)8375};8376});83778378def_to_moz(AST_DotHash, function To_Moz_PrivateMemberExpression(M) {8379return {8380type: "MemberExpression",8381object: to_moz(M.expression),8382computed: false,8383property: {8384type: "PrivateIdentifier",8385name: M.property8386},8387optional: M.optional8388};8389});83908391def_to_moz(AST_PropAccess, function To_Moz_MemberExpression(M) {8392var isComputed = M instanceof AST_Sub;8393return {8394type: "MemberExpression",8395object: to_moz(M.expression),8396computed: isComputed,8397property: isComputed ? to_moz(M.property) : {type: "Identifier", name: M.property},8398optional: M.optional8399};8400});84018402def_to_moz(AST_Chain, function To_Moz_ChainExpression(M) {8403return {8404type: "ChainExpression",8405expression: to_moz(M.expression)8406};8407});84088409def_to_moz(AST_Unary, function To_Moz_Unary(M) {8410return {8411type: M.operator == "++" || M.operator == "--" ? "UpdateExpression" : "UnaryExpression",8412operator: M.operator,8413prefix: M instanceof AST_UnaryPrefix,8414argument: to_moz(M.expression)8415};8416});84178418def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {8419if (M.operator == "=" && to_moz_in_destructuring()) {8420return {8421type: "AssignmentPattern",8422left: to_moz(M.left),8423right: to_moz(M.right)8424};8425}84268427const type = M.operator == "&&" || M.operator == "||" || M.operator === "??"8428? "LogicalExpression"8429: "BinaryExpression";84308431return {8432type,8433left: to_moz(M.left),8434operator: M.operator,8435right: to_moz(M.right)8436};8437});84388439def_to_moz(AST_PrivateIn, function To_Moz_BinaryExpression_PrivateIn(M) {8440return {8441type: "BinaryExpression",8442left: { type: "PrivateIdentifier", name: M.key.name },8443operator: "in",8444right: to_moz(M.value),8445};8446});84478448def_to_moz(AST_Array, function To_Moz_ArrayExpression(M) {8449return {8450type: "ArrayExpression",8451elements: M.elements.map(to_moz)8452};8453});84548455def_to_moz(AST_Object, function To_Moz_ObjectExpression(M) {8456return {8457type: "ObjectExpression",8458properties: M.properties.map(to_moz)8459};8460});84618462def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {8463var key = M.key instanceof AST_Node ? to_moz(M.key) : {8464type: "Identifier",8465value: M.key8466};8467if (typeof M.key === "number") {8468key = {8469type: "Literal",8470value: Number(M.key)8471};8472}8473if (typeof M.key === "string") {8474key = {8475type: "Identifier",8476name: M.key8477};8478}8479var kind;8480var string_or_num = typeof M.key === "string" || typeof M.key === "number";8481var computed = string_or_num ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;8482if (M instanceof AST_ObjectKeyVal) {8483kind = "init";8484computed = !string_or_num;8485} else8486if (M instanceof AST_ObjectGetter) {8487kind = "get";8488} else8489if (M instanceof AST_ObjectSetter) {8490kind = "set";8491}8492if (M instanceof AST_PrivateGetter || M instanceof AST_PrivateSetter) {8493const kind = M instanceof AST_PrivateGetter ? "get" : "set";8494return {8495type: "MethodDefinition",8496computed: false,8497kind: kind,8498static: M.static,8499key: {8500type: "PrivateIdentifier",8501name: M.key.name8502},8503value: to_moz(M.value)8504};8505}8506if (M instanceof AST_ClassPrivateProperty) {8507return {8508type: "PropertyDefinition",8509key: {8510type: "PrivateIdentifier",8511name: M.key.name8512},8513value: to_moz(M.value),8514computed: false,8515static: M.static8516};8517}8518if (M instanceof AST_ClassProperty) {8519return {8520type: "PropertyDefinition",8521key,8522value: to_moz(M.value),8523computed,8524static: M.static8525};8526}8527if (parent instanceof AST_Class) {8528return {8529type: "MethodDefinition",8530computed: computed,8531kind: kind,8532static: M.static,8533key: to_moz(M.key),8534value: to_moz(M.value)8535};8536}8537return {8538type: "Property",8539computed: computed,8540kind: kind,8541key: key,8542value: to_moz(M.value)8543};8544});85458546def_to_moz(AST_ConciseMethod, function To_Moz_MethodDefinition(M, parent) {8547if (parent instanceof AST_Object) {8548return {8549type: "Property",8550computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,8551kind: "init",8552method: true,8553shorthand: false,8554key: to_moz(M.key),8555value: to_moz(M.value)8556};8557}85588559const key = M instanceof AST_PrivateMethod8560? {8561type: "PrivateIdentifier",8562name: M.key.name8563}8564: to_moz(M.key);85658566return {8567type: "MethodDefinition",8568kind: M.key === "constructor" ? "constructor" : "method",8569key,8570value: to_moz(M.value),8571computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,8572static: M.static,8573};8574});85758576def_to_moz(AST_Class, function To_Moz_Class(M) {8577var type = M instanceof AST_ClassExpression ? "ClassExpression" : "ClassDeclaration";8578return {8579type: type,8580superClass: to_moz(M.extends),8581id: M.name ? to_moz(M.name) : null,8582body: {8583type: "ClassBody",8584body: M.properties.map(to_moz)8585}8586};8587});85888589def_to_moz(AST_ClassStaticBlock, function To_Moz_StaticBlock(M) {8590return {8591type: "StaticBlock",8592body: M.body.map(to_moz),8593};8594});85958596def_to_moz(AST_NewTarget, function To_Moz_MetaProperty() {8597return {8598type: "MetaProperty",8599meta: {8600type: "Identifier",8601name: "new"8602},8603property: {8604type: "Identifier",8605name: "target"8606}8607};8608});86098610def_to_moz(AST_Symbol, function To_Moz_Identifier(M, parent) {8611if (8612(M instanceof AST_SymbolMethod && parent.quote) ||8613((8614M instanceof AST_SymbolImportForeign ||8615M instanceof AST_SymbolExportForeign ||8616M instanceof AST_SymbolExport8617) && M.quote)8618) {8619return {8620type: "Literal",8621value: M.name8622};8623}8624var def = M.definition();8625return {8626type: "Identifier",8627name: def ? def.mangled_name || def.name : M.name8628};8629});86308631def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {8632const pattern = M.value.source;8633const flags = M.value.flags;8634return {8635type: "Literal",8636value: null,8637raw: M.print_to_string(),8638regex: { pattern, flags }8639};8640});86418642def_to_moz(AST_Constant, function To_Moz_Literal(M) {8643var value = M.value;8644return {8645type: "Literal",8646value: value,8647raw: M.raw || M.print_to_string()8648};8649});86508651def_to_moz(AST_Atom, function To_Moz_Atom(M) {8652return {8653type: "Identifier",8654name: String(M.value)8655};8656});86578658def_to_moz(AST_BigInt, M => ({8659type: "BigIntLiteral",8660value: M.value8661}));86628663AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);8664AST_Null.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);8665AST_Hole.DEFMETHOD("to_mozilla_ast", function To_Moz_ArrayHole() { return null; });86668667AST_Block.DEFMETHOD("to_mozilla_ast", AST_BlockStatement.prototype.to_mozilla_ast);8668AST_Lambda.DEFMETHOD("to_mozilla_ast", AST_Function.prototype.to_mozilla_ast);86698670/* -----[ tools ]----- */86718672function my_start_token(moznode) {8673var loc = moznode.loc, start = loc && loc.start;8674var range = moznode.range;8675return new AST_Token(8676"",8677"",8678start && start.line || 0,8679start && start.column || 0,8680range ? range [0] : moznode.start,8681false,8682[],8683[],8684loc && loc.source,8685);8686}86878688function my_end_token(moznode) {8689var loc = moznode.loc, end = loc && loc.end;8690var range = moznode.range;8691return new AST_Token(8692"",8693"",8694end && end.line || 0,8695end && end.column || 0,8696range ? range [0] : moznode.end,8697false,8698[],8699[],8700loc && loc.source,8701);8702}87038704var FROM_MOZ_STACK = null;87058706function from_moz(node) {8707FROM_MOZ_STACK.push(node);8708var ret = node != null ? MOZ_TO_ME[node.type](node) : null;8709FROM_MOZ_STACK.pop();8710return ret;8711}87128713AST_Node.from_mozilla_ast = function(node) {8714var save_stack = FROM_MOZ_STACK;8715FROM_MOZ_STACK = [];8716var ast = from_moz(node);8717FROM_MOZ_STACK = save_stack;8718return ast;8719};87208721function set_moz_loc(mynode, moznode) {8722var start = mynode.start;8723var end = mynode.end;8724if (!(start && end)) {8725return moznode;8726}8727if (start.pos != null && end.endpos != null) {8728moznode.range = [start.pos, end.endpos];8729}8730if (start.line) {8731moznode.loc = {8732start: {line: start.line, column: start.col},8733end: end.endline ? {line: end.endline, column: end.endcol} : null8734};8735if (start.file) {8736moznode.loc.source = start.file;8737}8738}8739return moznode;8740}87418742function def_to_moz(mytype, handler) {8743mytype.DEFMETHOD("to_mozilla_ast", function(parent) {8744return set_moz_loc(this, handler(this, parent));8745});8746}87478748var TO_MOZ_STACK = null;87498750function to_moz(node) {8751if (TO_MOZ_STACK === null) { TO_MOZ_STACK = []; }8752TO_MOZ_STACK.push(node);8753var ast = node != null ? node.to_mozilla_ast(TO_MOZ_STACK[TO_MOZ_STACK.length - 2]) : null;8754TO_MOZ_STACK.pop();8755if (TO_MOZ_STACK.length === 0) { TO_MOZ_STACK = null; }8756return ast;8757}87588759function to_moz_in_destructuring() {8760var i = TO_MOZ_STACK.length;8761while (i--) {8762if (TO_MOZ_STACK[i] instanceof AST_Destructuring) {8763return true;8764}8765}8766return false;8767}87688769function to_moz_block(node) {8770return {8771type: "BlockStatement",8772body: node.body.map(to_moz)8773};8774}87758776function to_moz_scope(type, node) {8777var body = node.body.map(to_moz);8778if (node.body[0] instanceof AST_SimpleStatement && node.body[0].body instanceof AST_String) {8779body.unshift(to_moz(new AST_EmptyStatement(node.body[0])));8780}8781return {8782type: type,8783body: body8784};8785}8786})();87878788// return true if the node at the top of the stack (that means the8789// innermost node in the current output) is lexically the first in8790// a statement.8791function first_in_statement(stack) {8792let node = stack.parent(-1);8793for (let i = 0, p; p = stack.parent(i); i++) {8794if (p instanceof AST_Statement && p.body === node)8795return true;8796if ((p instanceof AST_Sequence && p.expressions[0] === node) ||8797(p.TYPE === "Call" && p.expression === node) ||8798(p instanceof AST_PrefixedTemplateString && p.prefix === node) ||8799(p instanceof AST_Dot && p.expression === node) ||8800(p instanceof AST_Sub && p.expression === node) ||8801(p instanceof AST_Chain && p.expression === node) ||8802(p instanceof AST_Conditional && p.condition === node) ||8803(p instanceof AST_Binary && p.left === node) ||8804(p instanceof AST_UnaryPostfix && p.expression === node)8805) {8806node = p;8807} else {8808return false;8809}8810}8811}88128813// Returns whether the leftmost item in the expression is an object8814function left_is_object(node) {8815if (node instanceof AST_Object) return true;8816if (node instanceof AST_Sequence) return left_is_object(node.expressions[0]);8817if (node.TYPE === "Call") return left_is_object(node.expression);8818if (node instanceof AST_PrefixedTemplateString) return left_is_object(node.prefix);8819if (node instanceof AST_Dot || node instanceof AST_Sub) return left_is_object(node.expression);8820if (node instanceof AST_Chain) return left_is_object(node.expression);8821if (node instanceof AST_Conditional) return left_is_object(node.condition);8822if (node instanceof AST_Binary) return left_is_object(node.left);8823if (node instanceof AST_UnaryPostfix) return left_is_object(node.expression);8824return false;8825}88268827/***********************************************************************88288829A JavaScript tokenizer / parser / beautifier / compressor.8830https://github.com/mishoo/UglifyJS288318832-------------------------------- (C) ---------------------------------88338834Author: Mihai Bazon8835<[email protected]>8836http://mihai.bazon.net/blog88378838Distributed under the BSD license:88398840Copyright 2012 (c) Mihai Bazon <[email protected]>88418842Redistribution and use in source and binary forms, with or without8843modification, are permitted provided that the following conditions8844are met:88458846* Redistributions of source code must retain the above8847copyright notice, this list of conditions and the following8848disclaimer.88498850* Redistributions in binary form must reproduce the above8851copyright notice, this list of conditions and the following8852disclaimer in the documentation and/or other materials8853provided with the distribution.88548855THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY8856EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE8857IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR8858PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE8859LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,8860OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,8861PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR8862PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY8863THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR8864TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF8865THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF8866SUCH DAMAGE.88678868***********************************************************************/88698870const EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;8871const CODE_LINE_BREAK = 10;8872const CODE_SPACE = 32;88738874const r_annotation = /[@#]__(PURE|INLINE|NOINLINE)__/g;88758876function is_some_comments(comment) {8877// multiline comment8878return (8879(comment.type === "comment2" || comment.type === "comment1")8880&& /@preserve|@copyright|@lic|@cc_on|^\**!/i.test(comment.value)8881);8882}88838884class Rope {8885constructor() {8886this.committed = "";8887this.current = "";8888}88898890append(str) {8891this.current += str;8892}88938894insertAt(char, index) {8895const { committed, current } = this;8896if (index < committed.length) {8897this.committed = committed.slice(0, index) + char + committed.slice(index);8898} else if (index === committed.length) {8899this.committed += char;8900} else {8901index -= committed.length;8902this.committed += current.slice(0, index) + char;8903this.current = current.slice(index);8904}8905}89068907charAt(index) {8908const { committed } = this;8909if (index < committed.length) return committed[index];8910return this.current[index - committed.length];8911}89128913curLength() {8914return this.current.length;8915}89168917length() {8918return this.committed.length + this.current.length;8919}89208921toString() {8922return this.committed + this.current;8923}8924}89258926function OutputStream(options) {89278928var readonly = !options;8929options = defaults(options, {8930ascii_only : false,8931beautify : false,8932braces : false,8933comments : "some",8934ecma : 5,8935ie8 : false,8936indent_level : 4,8937indent_start : 0,8938inline_script : true,8939keep_numbers : false,8940keep_quoted_props : false,8941max_line_len : false,8942preamble : null,8943preserve_annotations : false,8944quote_keys : false,8945quote_style : 0,8946safari10 : false,8947semicolons : true,8948shebang : true,8949shorthand : undefined,8950source_map : null,8951webkit : false,8952width : 80,8953wrap_iife : false,8954wrap_func_args : true,89558956_destroy_ast : false8957}, true);89588959if (options.shorthand === undefined)8960options.shorthand = options.ecma > 5;89618962// Convert comment option to RegExp if necessary and set up comments filter8963var comment_filter = return_false; // Default case, throw all comments away8964if (options.comments) {8965let comments = options.comments;8966if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {8967var regex_pos = options.comments.lastIndexOf("/");8968comments = new RegExp(8969options.comments.substr(1, regex_pos - 1),8970options.comments.substr(regex_pos + 1)8971);8972}8973if (comments instanceof RegExp) {8974comment_filter = function(comment) {8975return comment.type != "comment5" && comments.test(comment.value);8976};8977} else if (typeof comments === "function") {8978comment_filter = function(comment) {8979return comment.type != "comment5" && comments(this, comment);8980};8981} else if (comments === "some") {8982comment_filter = is_some_comments;8983} else { // NOTE includes "all" option8984comment_filter = return_true;8985}8986}89878988var indentation = 0;8989var current_col = 0;8990var current_line = 1;8991var current_pos = 0;8992var OUTPUT = new Rope();8993let printed_comments = new Set();89948995var to_utf8 = options.ascii_only ? function(str, identifier = false, regexp = false) {8996if (options.ecma >= 2015 && !options.safari10 && !regexp) {8997str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {8998var code = get_full_char_code(ch, 0).toString(16);8999return "\\u{" + code + "}";9000});9001}9002return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {9003var code = ch.charCodeAt(0).toString(16);9004if (code.length <= 2 && !identifier) {9005while (code.length < 2) code = "0" + code;9006return "\\x" + code;9007} else {9008while (code.length < 4) code = "0" + code;9009return "\\u" + code;9010}9011});9012} : function(str) {9013return str.replace(/[\ud800-\udbff][\udc00-\udfff]|([\ud800-\udbff]|[\udc00-\udfff])/g, function(match, lone) {9014if (lone) {9015return "\\u" + lone.charCodeAt(0).toString(16);9016}9017return match;9018});9019};90209021function make_string(str, quote) {9022var dq = 0, sq = 0;9023str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,9024function(s, i) {9025switch (s) {9026case '"': ++dq; return '"';9027case "'": ++sq; return "'";9028case "\\": return "\\\\";9029case "\n": return "\\n";9030case "\r": return "\\r";9031case "\t": return "\\t";9032case "\b": return "\\b";9033case "\f": return "\\f";9034case "\x0B": return options.ie8 ? "\\x0B" : "\\v";9035case "\u2028": return "\\u2028";9036case "\u2029": return "\\u2029";9037case "\ufeff": return "\\ufeff";9038case "\0":9039return /[0-9]/.test(get_full_char(str, i+1)) ? "\\x00" : "\\0";9040}9041return s;9042});9043function quote_single() {9044return "'" + str.replace(/\x27/g, "\\'") + "'";9045}9046function quote_double() {9047return '"' + str.replace(/\x22/g, '\\"') + '"';9048}9049function quote_template() {9050return "`" + str.replace(/`/g, "\\`") + "`";9051}9052str = to_utf8(str);9053if (quote === "`") return quote_template();9054switch (options.quote_style) {9055case 1:9056return quote_single();9057case 2:9058return quote_double();9059case 3:9060return quote == "'" ? quote_single() : quote_double();9061default:9062return dq > sq ? quote_single() : quote_double();9063}9064}90659066function encode_string(str, quote) {9067var ret = make_string(str, quote);9068if (options.inline_script) {9069ret = ret.replace(/<\x2f(script)([>\/\t\n\f\r ])/gi, "<\\/$1$2");9070ret = ret.replace(/\x3c!--/g, "\\x3c!--");9071ret = ret.replace(/--\x3e/g, "--\\x3e");9072}9073return ret;9074}90759076function make_name(name) {9077name = name.toString();9078name = to_utf8(name, true);9079return name;9080}90819082function make_indent(back) {9083return " ".repeat(options.indent_start + indentation - back * options.indent_level);9084}90859086/* -----[ beautification/minification ]----- */90879088var has_parens = false;9089var might_need_space = false;9090var might_need_semicolon = false;9091var might_add_newline = 0;9092var need_newline_indented = false;9093var need_space = false;9094var newline_insert = -1;9095var last = "";9096var mapping_token, mapping_name, mappings = options.source_map && [];90979098var do_add_mapping = mappings ? function() {9099mappings.forEach(function(mapping) {9100try {9101let { name, token } = mapping;9102if (token.type == "name" || token.type === "privatename") {9103name = token.value;9104} else if (name instanceof AST_Symbol) {9105name = token.type === "string" ? token.value : name.name;9106}9107options.source_map.add(9108mapping.token.file,9109mapping.line, mapping.col,9110mapping.token.line, mapping.token.col,9111is_basic_identifier_string(name) ? name : undefined9112);9113} catch(ex) {9114// Ignore bad mapping9115}9116});9117mappings = [];9118} : noop;91199120var ensure_line_len = options.max_line_len ? function() {9121if (current_col > options.max_line_len) {9122if (might_add_newline) {9123OUTPUT.insertAt("\n", might_add_newline);9124const curLength = OUTPUT.curLength();9125if (mappings) {9126var delta = curLength - current_col;9127mappings.forEach(function(mapping) {9128mapping.line++;9129mapping.col += delta;9130});9131}9132current_line++;9133current_pos++;9134current_col = curLength;9135}9136}9137if (might_add_newline) {9138might_add_newline = 0;9139do_add_mapping();9140}9141} : noop;91429143var requireSemicolonChars = makePredicate("( [ + * / - , . `");91449145function print(str) {9146str = String(str);9147var ch = get_full_char(str, 0);9148if (need_newline_indented && ch) {9149need_newline_indented = false;9150if (ch !== "\n") {9151print("\n");9152indent();9153}9154}9155if (need_space && ch) {9156need_space = false;9157if (!/[\s;})]/.test(ch)) {9158space();9159}9160}9161newline_insert = -1;9162var prev = last.charAt(last.length - 1);9163if (might_need_semicolon) {9164might_need_semicolon = false;91659166if (prev === ":" && ch === "}" || (!ch || !";}".includes(ch)) && prev !== ";") {9167if (options.semicolons || requireSemicolonChars.has(ch)) {9168OUTPUT.append(";");9169current_col++;9170current_pos++;9171} else {9172ensure_line_len();9173if (current_col > 0) {9174OUTPUT.append("\n");9175current_pos++;9176current_line++;9177current_col = 0;9178}91799180if (/^\s+$/.test(str)) {9181// reset the semicolon flag, since we didn't print one9182// now and might still have to later9183might_need_semicolon = true;9184}9185}91869187if (!options.beautify)9188might_need_space = false;9189}9190}91919192if (might_need_space) {9193if ((is_identifier_char(prev)9194&& (is_identifier_char(ch) || ch == "\\"))9195|| (ch == "/" && ch == prev)9196|| ((ch == "+" || ch == "-") && ch == last)9197) {9198OUTPUT.append(" ");9199current_col++;9200current_pos++;9201}9202might_need_space = false;9203}92049205if (mapping_token) {9206mappings.push({9207token: mapping_token,9208name: mapping_name,9209line: current_line,9210col: current_col9211});9212mapping_token = false;9213if (!might_add_newline) do_add_mapping();9214}92159216OUTPUT.append(str);9217has_parens = str[str.length - 1] == "(";9218current_pos += str.length;9219var a = str.split(/\r?\n/), n = a.length - 1;9220current_line += n;9221current_col += a[0].length;9222if (n > 0) {9223ensure_line_len();9224current_col = a[n].length;9225}9226last = str;9227}92289229var star = function() {9230print("*");9231};92329233var space = options.beautify ? function() {9234print(" ");9235} : function() {9236might_need_space = true;9237};92389239var indent = options.beautify ? function(half) {9240if (options.beautify) {9241print(make_indent(half ? 0.5 : 0));9242}9243} : noop;92449245var with_indent = options.beautify ? function(col, cont) {9246if (col === true) col = next_indent();9247var save_indentation = indentation;9248indentation = col;9249var ret = cont();9250indentation = save_indentation;9251return ret;9252} : function(col, cont) { return cont(); };92539254var newline = options.beautify ? function() {9255if (newline_insert < 0) return print("\n");9256if (OUTPUT.charAt(newline_insert) != "\n") {9257OUTPUT.insertAt("\n", newline_insert);9258current_pos++;9259current_line++;9260}9261newline_insert++;9262} : options.max_line_len ? function() {9263ensure_line_len();9264might_add_newline = OUTPUT.length();9265} : noop;92669267var semicolon = options.beautify ? function() {9268print(";");9269} : function() {9270might_need_semicolon = true;9271};92729273function force_semicolon() {9274might_need_semicolon = false;9275print(";");9276}92779278function next_indent() {9279return indentation + options.indent_level;9280}92819282function with_block(cont) {9283var ret;9284print("{");9285newline();9286with_indent(next_indent(), function() {9287ret = cont();9288});9289indent();9290print("}");9291return ret;9292}92939294function with_parens(cont) {9295print("(");9296//XXX: still nice to have that for argument lists9297//var ret = with_indent(current_col, cont);9298var ret = cont();9299print(")");9300return ret;9301}93029303function with_square(cont) {9304print("[");9305//var ret = with_indent(current_col, cont);9306var ret = cont();9307print("]");9308return ret;9309}93109311function comma() {9312print(",");9313space();9314}93159316function colon() {9317print(":");9318space();9319}93209321var add_mapping = mappings ? function(token, name) {9322mapping_token = token;9323mapping_name = name;9324} : noop;93259326function get() {9327if (might_add_newline) {9328ensure_line_len();9329}9330return OUTPUT.toString();9331}93329333function has_nlb() {9334const output = OUTPUT.toString();9335let n = output.length - 1;9336while (n >= 0) {9337const code = output.charCodeAt(n);9338if (code === CODE_LINE_BREAK) {9339return true;9340}93419342if (code !== CODE_SPACE) {9343return false;9344}9345n--;9346}9347return true;9348}93499350function filter_comment(comment) {9351if (!options.preserve_annotations) {9352comment = comment.replace(r_annotation, " ");9353}9354if (/^\s*$/.test(comment)) {9355return "";9356}9357return comment.replace(/(<\s*\/\s*)(script)/i, "<\\/$2");9358}93599360function prepend_comments(node) {9361var self = this;9362var start = node.start;9363if (!start) return;9364var printed_comments = self.printed_comments;93659366// There cannot be a newline between return/yield and its value.9367const keyword_with_value =9368node instanceof AST_Exit && node.value9369|| (node instanceof AST_Await || node instanceof AST_Yield)9370&& node.expression;93719372if (9373start.comments_before9374&& printed_comments.has(start.comments_before)9375) {9376if (keyword_with_value) {9377start.comments_before = [];9378} else {9379return;9380}9381}93829383var comments = start.comments_before;9384if (!comments) {9385comments = start.comments_before = [];9386}9387printed_comments.add(comments);93889389if (keyword_with_value) {9390var tw = new TreeWalker(function(node) {9391var parent = tw.parent();9392if (parent instanceof AST_Exit9393|| parent instanceof AST_Await9394|| parent instanceof AST_Yield9395|| parent instanceof AST_Binary && parent.left === node9396|| parent.TYPE == "Call" && parent.expression === node9397|| parent instanceof AST_Conditional && parent.condition === node9398|| parent instanceof AST_Dot && parent.expression === node9399|| parent instanceof AST_Sequence && parent.expressions[0] === node9400|| parent instanceof AST_Sub && parent.expression === node9401|| parent instanceof AST_UnaryPostfix) {9402if (!node.start) return;9403var text = node.start.comments_before;9404if (text && !printed_comments.has(text)) {9405printed_comments.add(text);9406comments = comments.concat(text);9407}9408} else {9409return true;9410}9411});9412tw.push(node);9413keyword_with_value.walk(tw);9414}94159416if (current_pos == 0) {9417if (comments.length > 0 && options.shebang && comments[0].type === "comment5"9418&& !printed_comments.has(comments[0])) {9419print("#!" + comments.shift().value + "\n");9420indent();9421}9422var preamble = options.preamble;9423if (preamble) {9424print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));9425}9426}94279428comments = comments.filter(comment_filter, node).filter(c => !printed_comments.has(c));9429if (comments.length == 0) return;9430var last_nlb = has_nlb();9431comments.forEach(function(c, i) {9432printed_comments.add(c);9433if (!last_nlb) {9434if (c.nlb) {9435print("\n");9436indent();9437last_nlb = true;9438} else if (i > 0) {9439space();9440}9441}94429443if (/comment[134]/.test(c.type)) {9444var value = filter_comment(c.value);9445if (value) {9446print("//" + value + "\n");9447indent();9448}9449last_nlb = true;9450} else if (c.type == "comment2") {9451var value = filter_comment(c.value);9452if (value) {9453print("/*" + value + "*/");9454}9455last_nlb = false;9456}9457});9458if (!last_nlb) {9459if (start.nlb) {9460print("\n");9461indent();9462} else {9463space();9464}9465}9466}94679468function append_comments(node, tail) {9469var self = this;9470var token = node.end;9471if (!token) return;9472var printed_comments = self.printed_comments;9473var comments = token[tail ? "comments_before" : "comments_after"];9474if (!comments || printed_comments.has(comments)) return;9475if (!(node instanceof AST_Statement || comments.every((c) =>9476!/comment[134]/.test(c.type)9477))) return;9478printed_comments.add(comments);9479var insert = OUTPUT.length();9480comments.filter(comment_filter, node).forEach(function(c, i) {9481if (printed_comments.has(c)) return;9482printed_comments.add(c);9483need_space = false;9484if (need_newline_indented) {9485print("\n");9486indent();9487need_newline_indented = false;9488} else if (c.nlb && (i > 0 || !has_nlb())) {9489print("\n");9490indent();9491} else if (i > 0 || !tail) {9492space();9493}9494if (/comment[134]/.test(c.type)) {9495const value = filter_comment(c.value);9496if (value) {9497print("//" + value);9498}9499need_newline_indented = true;9500} else if (c.type == "comment2") {9501const value = filter_comment(c.value);9502if (value) {9503print("/*" + value + "*/");9504}9505need_space = true;9506}9507});9508if (OUTPUT.length() > insert) newline_insert = insert;9509}95109511/**9512* When output.option("_destroy_ast") is enabled, destroy the function.9513* Call this after printing it.9514*/9515const gc_scope =9516options["_destroy_ast"]9517? function gc_scope(scope) {9518scope.body.length = 0;9519scope.argnames.length = 0;9520}9521: noop;95229523var stack = [];9524return {9525get : get,9526toString : get,9527indent : indent,9528in_directive : false,9529use_asm : null,9530active_scope : null,9531indentation : function() { return indentation; },9532current_width : function() { return current_col - indentation; },9533should_break : function() { return options.width && this.current_width() >= options.width; },9534has_parens : function() { return has_parens; },9535newline : newline,9536print : print,9537star : star,9538space : space,9539comma : comma,9540colon : colon,9541last : function() { return last; },9542semicolon : semicolon,9543force_semicolon : force_semicolon,9544to_utf8 : to_utf8,9545print_name : function(name) { print(make_name(name)); },9546print_string : function(str, quote, escape_directive) {9547var encoded = encode_string(str, quote);9548if (escape_directive === true && !encoded.includes("\\")) {9549// Insert semicolons to break directive prologue9550if (!EXPECT_DIRECTIVE.test(OUTPUT.toString())) {9551force_semicolon();9552}9553force_semicolon();9554}9555print(encoded);9556},9557print_template_string_chars: function(str) {9558var encoded = encode_string(str, "`").replace(/\${/g, "\\${");9559return print(encoded.substr(1, encoded.length - 2));9560},9561encode_string : encode_string,9562next_indent : next_indent,9563with_indent : with_indent,9564with_block : with_block,9565with_parens : with_parens,9566with_square : with_square,9567add_mapping : add_mapping,9568option : function(opt) { return options[opt]; },9569gc_scope,9570printed_comments: printed_comments,9571prepend_comments: readonly ? noop : prepend_comments,9572append_comments : readonly || comment_filter === return_false ? noop : append_comments,9573line : function() { return current_line; },9574col : function() { return current_col; },9575pos : function() { return current_pos; },9576push_node : function(node) { stack.push(node); },9577pop_node : function() { return stack.pop(); },9578parent : function(n) {9579return stack[stack.length - 2 - (n || 0)];9580}9581};95829583}95849585/* -----[ code generators ]----- */95869587(function() {95889589/* -----[ utils ]----- */95909591function DEFPRINT(nodetype, generator) {9592nodetype.DEFMETHOD("_codegen", generator);9593}95949595AST_Node.DEFMETHOD("print", function(output, force_parens) {9596var self = this, generator = self._codegen;9597if (self instanceof AST_Scope) {9598output.active_scope = self;9599} else if (!output.use_asm && self instanceof AST_Directive && self.value == "use asm") {9600output.use_asm = output.active_scope;9601}9602function doit() {9603output.prepend_comments(self);9604self.add_source_map(output);9605generator(self, output);9606output.append_comments(self);9607}9608output.push_node(self);9609if (force_parens || self.needs_parens(output)) {9610output.with_parens(doit);9611} else {9612doit();9613}9614output.pop_node();9615if (self === output.use_asm) {9616output.use_asm = null;9617}9618});9619AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);96209621AST_Node.DEFMETHOD("print_to_string", function(options) {9622var output = OutputStream(options);9623this.print(output);9624return output.get();9625});96269627/* -----[ PARENTHESES ]----- */96289629function PARENS(nodetype, func) {9630if (Array.isArray(nodetype)) {9631nodetype.forEach(function(nodetype) {9632PARENS(nodetype, func);9633});9634} else {9635nodetype.DEFMETHOD("needs_parens", func);9636}9637}96389639PARENS(AST_Node, return_false);96409641// a function expression needs parens around it when it's provably9642// the first token to appear in a statement.9643PARENS(AST_Function, function(output) {9644if (!output.has_parens() && first_in_statement(output)) {9645return true;9646}96479648if (output.option("webkit")) {9649var p = output.parent();9650if (p instanceof AST_PropAccess && p.expression === this) {9651return true;9652}9653}96549655if (output.option("wrap_iife")) {9656var p = output.parent();9657if (p instanceof AST_Call && p.expression === this) {9658return true;9659}9660}96619662if (output.option("wrap_func_args")) {9663var p = output.parent();9664if (p instanceof AST_Call && p.args.includes(this)) {9665return true;9666}9667}96689669return false;9670});96719672PARENS(AST_Arrow, function(output) {9673var p = output.parent();96749675if (9676output.option("wrap_func_args")9677&& p instanceof AST_Call9678&& p.args.includes(this)9679) {9680return true;9681}9682return p instanceof AST_PropAccess && p.expression === this;9683});96849685// same goes for an object literal (as in AST_Function), because9686// otherwise {...} would be interpreted as a block of code.9687PARENS(AST_Object, function(output) {9688return !output.has_parens() && first_in_statement(output);9689});96909691PARENS(AST_ClassExpression, first_in_statement);96929693PARENS(AST_Unary, function(output) {9694var p = output.parent();9695return p instanceof AST_PropAccess && p.expression === this9696|| p instanceof AST_Call && p.expression === this9697|| p instanceof AST_Binary9698&& p.operator === "**"9699&& this instanceof AST_UnaryPrefix9700&& p.left === this9701&& this.operator !== "++"9702&& this.operator !== "--";9703});97049705PARENS(AST_Await, function(output) {9706var p = output.parent();9707return p instanceof AST_PropAccess && p.expression === this9708|| p instanceof AST_Call && p.expression === this9709|| p instanceof AST_Binary && p.operator === "**" && p.left === this9710|| output.option("safari10") && p instanceof AST_UnaryPrefix;9711});97129713PARENS(AST_Sequence, function(output) {9714var p = output.parent();9715return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)9716|| p instanceof AST_Unary // !(foo, bar, baz)9717|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 89718|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 49719|| p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 29720|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]9721|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 29722|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)9723* ==> 20 (side effect, set a := 10 and b := 20) */9724|| p instanceof AST_Arrow // x => (x, x)9725|| p instanceof AST_DefaultAssign // x => (x = (0, function(){}))9726|| p instanceof AST_Expansion // [...(a, b)]9727|| p instanceof AST_ForOf && this === p.object // for (e of (foo, bar)) {}9728|| p instanceof AST_Yield // yield (foo, bar)9729|| p instanceof AST_Export // export default (foo, bar)9730;9731});97329733PARENS(AST_Binary, function(output) {9734var p = output.parent();9735// (foo && bar)()9736if (p instanceof AST_Call && p.expression === this)9737return true;9738// typeof (foo && bar)9739if (p instanceof AST_Unary)9740return true;9741// (foo && bar)["prop"], (foo && bar).prop9742if (p instanceof AST_PropAccess && p.expression === this)9743return true;9744// this deals with precedence: 3 * (2 + 1)9745if (p instanceof AST_Binary) {9746const po = p.operator;9747const so = this.operator;97489749if (so === "??" && (po === "||" || po === "&&")) {9750return true;9751}97529753if (po === "??" && (so === "||" || so === "&&")) {9754return true;9755}97569757const pp = PRECEDENCE[po];9758const sp = PRECEDENCE[so];9759if (pp > sp9760|| (pp == sp9761&& (this === p.right || po == "**"))) {9762return true;9763}9764}9765});97669767PARENS(AST_Yield, function(output) {9768var p = output.parent();9769// (yield 1) + (yield 2)9770// a = yield 39771if (p instanceof AST_Binary && p.operator !== "=")9772return true;9773// (yield 1)()9774// new (yield 1)()9775if (p instanceof AST_Call && p.expression === this)9776return true;9777// (yield 1) ? yield 2 : yield 39778if (p instanceof AST_Conditional && p.condition === this)9779return true;9780// -(yield 4)9781if (p instanceof AST_Unary)9782return true;9783// (yield x).foo9784// (yield x)['foo']9785if (p instanceof AST_PropAccess && p.expression === this)9786return true;9787});97889789PARENS(AST_Chain, function(output) {9790var p = output.parent();9791if (!(p instanceof AST_Call || p instanceof AST_PropAccess)) return false;9792return p.expression === this;9793});97949795PARENS(AST_PropAccess, function(output) {9796var p = output.parent();9797if (p instanceof AST_New && p.expression === this) {9798// i.e. new (foo.bar().baz)9799//9800// if there's one call into this subtree, then we need9801// parens around it too, otherwise the call will be9802// interpreted as passing the arguments to the upper New9803// expression.9804return walk(this, node => {9805if (node instanceof AST_Scope) return true;9806if (node instanceof AST_Call) {9807return walk_abort; // makes walk() return true.9808}9809});9810}9811});98129813PARENS(AST_Call, function(output) {9814var p = output.parent(), p1;9815if (p instanceof AST_New && p.expression === this9816|| p instanceof AST_Export && p.is_default && this.expression instanceof AST_Function)9817return true;98189819// workaround for Safari bug.9820// https://bugs.webkit.org/show_bug.cgi?id=1235069821return this.expression instanceof AST_Function9822&& p instanceof AST_PropAccess9823&& p.expression === this9824&& (p1 = output.parent(1)) instanceof AST_Assign9825&& p1.left === p;9826});98279828PARENS(AST_New, function(output) {9829var p = output.parent();9830if (this.args.length === 09831&& (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]()9832|| p instanceof AST_Call && p.expression === this9833|| p instanceof AST_PrefixedTemplateString && p.prefix === this)) // (new foo)(bar)9834return true;9835});98369837PARENS(AST_Number, function(output) {9838var p = output.parent();9839if (p instanceof AST_PropAccess && p.expression === this) {9840var value = this.getValue();9841if (value < 0 || /^0/.test(make_num(value))) {9842return true;9843}9844}9845});98469847PARENS(AST_BigInt, function(output) {9848var p = output.parent();9849if (p instanceof AST_PropAccess && p.expression === this) {9850var value = this.getValue();9851if (value.startsWith("-")) {9852return true;9853}9854}9855});98569857PARENS([ AST_Assign, AST_Conditional ], function(output) {9858var p = output.parent();9859// !(a = false) → true9860if (p instanceof AST_Unary)9861return true;9862// 1 + (a = 2) + 3 → 6, side effect setting a = 29863if (p instanceof AST_Binary && !(p instanceof AST_Assign))9864return true;9865// (a = func)() —or— new (a = Object)()9866if (p instanceof AST_Call && p.expression === this)9867return true;9868// (a = foo) ? bar : baz9869if (p instanceof AST_Conditional && p.condition === this)9870return true;9871// (a = foo)["prop"] —or— (a = foo).prop9872if (p instanceof AST_PropAccess && p.expression === this)9873return true;9874// ({a, b} = {a: 1, b: 2}), a destructuring assignment9875if (this instanceof AST_Assign && this.left instanceof AST_Destructuring && this.left.is_array === false)9876return true;9877});98789879/* -----[ PRINTERS ]----- */98809881DEFPRINT(AST_Directive, function(self, output) {9882output.print_string(self.value, self.quote);9883output.semicolon();9884});98859886DEFPRINT(AST_Expansion, function (self, output) {9887output.print("...");9888self.expression.print(output);9889});98909891DEFPRINT(AST_Destructuring, function (self, output) {9892output.print(self.is_array ? "[" : "{");9893var len = self.names.length;9894self.names.forEach(function (name, i) {9895if (i > 0) output.comma();9896name.print(output);9897// If the final element is a hole, we need to make sure it9898// doesn't look like a trailing comma, by inserting an actual9899// trailing comma.9900if (i == len - 1 && name instanceof AST_Hole) output.comma();9901});9902output.print(self.is_array ? "]" : "}");9903});99049905DEFPRINT(AST_Debugger, function(self, output) {9906output.print("debugger");9907output.semicolon();9908});99099910/* -----[ statements ]----- */99119912function display_body(body, is_toplevel, output, allow_directives) {9913var last = body.length - 1;9914output.in_directive = allow_directives;9915body.forEach(function(stmt, i) {9916if (output.in_directive === true && !(stmt instanceof AST_Directive ||9917stmt instanceof AST_EmptyStatement ||9918(stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String)9919)) {9920output.in_directive = false;9921}9922if (!(stmt instanceof AST_EmptyStatement)) {9923output.indent();9924stmt.print(output);9925if (!(i == last && is_toplevel)) {9926output.newline();9927if (is_toplevel) output.newline();9928}9929}9930if (output.in_directive === true &&9931stmt instanceof AST_SimpleStatement &&9932stmt.body instanceof AST_String9933) {9934output.in_directive = false;9935}9936});9937output.in_directive = false;9938}99399940AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {9941print_maybe_braced_body(this.body, output);9942});99439944DEFPRINT(AST_Statement, function(self, output) {9945self.body.print(output);9946output.semicolon();9947});9948DEFPRINT(AST_Toplevel, function(self, output) {9949display_body(self.body, true, output, true);9950output.print("");9951});9952DEFPRINT(AST_LabeledStatement, function(self, output) {9953self.label.print(output);9954output.colon();9955self.body.print(output);9956});9957DEFPRINT(AST_SimpleStatement, function(self, output) {9958self.body.print(output);9959output.semicolon();9960});9961// XXX Emscripten localmod: Add a node type for a parenthesized expression so that we can retain9962// Closure annotations that need a form "/**annotation*/(expression)"9963DEFPRINT(AST_ParenthesizedExpression, function(self, output) {9964output.print('(');9965self.body.print(output);9966output.print(')');9967});9968// XXX End Emscripten localmod9969function print_braced_empty(self, output) {9970output.print("{");9971output.with_indent(output.next_indent(), function() {9972output.append_comments(self, true);9973});9974output.add_mapping(self.end);9975output.print("}");9976}9977function print_braced(self, output, allow_directives) {9978if (self.body.length > 0) {9979output.with_block(function() {9980display_body(self.body, false, output, allow_directives);9981output.add_mapping(self.end);9982});9983} else print_braced_empty(self, output);9984}9985DEFPRINT(AST_BlockStatement, function(self, output) {9986print_braced(self, output);9987});9988DEFPRINT(AST_EmptyStatement, function(self, output) {9989output.semicolon();9990});9991DEFPRINT(AST_Do, function(self, output) {9992output.print("do");9993output.space();9994make_block(self.body, output);9995output.space();9996output.print("while");9997output.space();9998output.with_parens(function() {9999self.condition.print(output);10000});10001output.semicolon();10002});10003DEFPRINT(AST_While, function(self, output) {10004output.print("while");10005output.space();10006output.with_parens(function() {10007self.condition.print(output);10008});10009output.space();10010self._do_print_body(output);10011});10012DEFPRINT(AST_For, function(self, output) {10013output.print("for");10014output.space();10015output.with_parens(function() {10016if (self.init) {10017if (self.init instanceof AST_Definitions) {10018self.init.print(output);10019} else {10020parenthesize_for_noin(self.init, output, true);10021}10022output.print(";");10023output.space();10024} else {10025output.print(";");10026}10027if (self.condition) {10028self.condition.print(output);10029output.print(";");10030output.space();10031} else {10032output.print(";");10033}10034if (self.step) {10035self.step.print(output);10036}10037});10038output.space();10039self._do_print_body(output);10040});10041DEFPRINT(AST_ForIn, function(self, output) {10042output.print("for");10043if (self.await) {10044output.space();10045output.print("await");10046}10047output.space();10048output.with_parens(function() {10049self.init.print(output);10050output.space();10051output.print(self instanceof AST_ForOf ? "of" : "in");10052output.space();10053self.object.print(output);10054});10055output.space();10056self._do_print_body(output);10057});10058DEFPRINT(AST_With, function(self, output) {10059output.print("with");10060output.space();10061output.with_parens(function() {10062self.expression.print(output);10063});10064output.space();10065self._do_print_body(output);10066});1006710068/* -----[ functions ]----- */10069AST_Lambda.DEFMETHOD("_do_print", function(output, nokeyword) {10070var self = this;10071if (!nokeyword) {10072if (self.async) {10073output.print("async");10074output.space();10075}10076output.print("function");10077if (self.is_generator) {10078output.star();10079}10080if (self.name) {10081output.space();10082}10083}10084if (self.name instanceof AST_Symbol) {10085self.name.print(output);10086} else if (nokeyword && self.name instanceof AST_Node) {10087output.with_square(function() {10088self.name.print(output); // Computed method name10089});10090}10091output.with_parens(function() {10092self.argnames.forEach(function(arg, i) {10093if (i) output.comma();10094arg.print(output);10095});10096});10097output.space();10098print_braced(self, output, true);10099});10100DEFPRINT(AST_Lambda, function(self, output) {10101self._do_print(output);10102output.gc_scope(self);10103});1010410105DEFPRINT(AST_PrefixedTemplateString, function(self, output) {10106var tag = self.prefix;10107var parenthesize_tag = tag instanceof AST_Lambda10108|| tag instanceof AST_Binary10109|| tag instanceof AST_Conditional10110|| tag instanceof AST_Sequence10111|| tag instanceof AST_Unary10112|| tag instanceof AST_Dot && tag.expression instanceof AST_Object;10113if (parenthesize_tag) output.print("(");10114self.prefix.print(output);10115if (parenthesize_tag) output.print(")");10116self.template_string.print(output);10117});10118DEFPRINT(AST_TemplateString, function(self, output) {10119var is_tagged = output.parent() instanceof AST_PrefixedTemplateString;1012010121output.print("`");10122for (var i = 0; i < self.segments.length; i++) {10123if (!(self.segments[i] instanceof AST_TemplateSegment)) {10124output.print("${");10125self.segments[i].print(output);10126output.print("}");10127} else if (is_tagged) {10128output.print(self.segments[i].raw);10129} else {10130output.print_template_string_chars(self.segments[i].value);10131}10132}10133output.print("`");10134});10135DEFPRINT(AST_TemplateSegment, function(self, output) {10136output.print_template_string_chars(self.value);10137});1013810139AST_Arrow.DEFMETHOD("_do_print", function(output) {10140var self = this;10141var parent = output.parent();10142var needs_parens = (parent instanceof AST_Binary && !(parent instanceof AST_Assign)) ||10143parent instanceof AST_Unary ||10144(parent instanceof AST_Call && self === parent.expression);10145if (needs_parens) { output.print("("); }10146if (self.async) {10147output.print("async");10148output.space();10149}10150if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol) {10151self.argnames[0].print(output);10152} else {10153output.with_parens(function() {10154self.argnames.forEach(function(arg, i) {10155if (i) output.comma();10156arg.print(output);10157});10158});10159}10160output.space();10161output.print("=>");10162output.space();10163const first_statement = self.body[0];10164if (10165self.body.length === 110166&& first_statement instanceof AST_Return10167) {10168const returned = first_statement.value;10169if (!returned) {10170output.print("{}");10171} else if (left_is_object(returned)) {10172output.print("(");10173returned.print(output);10174output.print(")");10175} else {10176returned.print(output);10177}10178} else {10179print_braced(self, output);10180}10181if (needs_parens) { output.print(")"); }10182output.gc_scope(self);10183});1018410185/* -----[ exits ]----- */10186AST_Exit.DEFMETHOD("_do_print", function(output, kind) {10187output.print(kind);10188if (this.value) {10189output.space();10190const comments = this.value.start.comments_before;10191if (comments && comments.length && !output.printed_comments.has(comments)) {10192output.print("(");10193this.value.print(output);10194output.print(")");10195} else {10196this.value.print(output);10197}10198}10199output.semicolon();10200});10201DEFPRINT(AST_Return, function(self, output) {10202self._do_print(output, "return");10203});10204DEFPRINT(AST_Throw, function(self, output) {10205self._do_print(output, "throw");10206});1020710208/* -----[ yield ]----- */1020910210DEFPRINT(AST_Yield, function(self, output) {10211var star = self.is_star ? "*" : "";10212output.print("yield" + star);10213if (self.expression) {10214output.space();10215self.expression.print(output);10216}10217});1021810219DEFPRINT(AST_Await, function(self, output) {10220output.print("await");10221output.space();10222var e = self.expression;10223var parens = !(10224e instanceof AST_Call10225|| e instanceof AST_SymbolRef10226|| e instanceof AST_PropAccess10227|| e instanceof AST_Unary10228|| e instanceof AST_Constant10229|| e instanceof AST_Await10230|| e instanceof AST_Object10231);10232if (parens) output.print("(");10233self.expression.print(output);10234if (parens) output.print(")");10235});1023610237/* -----[ loop control ]----- */10238AST_LoopControl.DEFMETHOD("_do_print", function(output, kind) {10239output.print(kind);10240if (this.label) {10241output.space();10242this.label.print(output);10243}10244output.semicolon();10245});10246DEFPRINT(AST_Break, function(self, output) {10247self._do_print(output, "break");10248});10249DEFPRINT(AST_Continue, function(self, output) {10250self._do_print(output, "continue");10251});1025210253/* -----[ if ]----- */10254function make_then(self, output) {10255var b = self.body;10256if (output.option("braces")10257|| output.option("ie8") && b instanceof AST_Do)10258return make_block(b, output);10259// The squeezer replaces "block"-s that contain only a single10260// statement with the statement itself; technically, the AST10261// is correct, but this can create problems when we output an10262// IF having an ELSE clause where the THEN clause ends in an10263// IF *without* an ELSE block (then the outer ELSE would refer10264// to the inner IF). This function checks for this case and10265// adds the block braces if needed.10266if (!b) return output.force_semicolon();10267while (true) {10268if (b instanceof AST_If) {10269if (!b.alternative) {10270make_block(self.body, output);10271return;10272}10273b = b.alternative;10274} else if (b instanceof AST_StatementWithBody) {10275b = b.body;10276} else break;10277}10278print_maybe_braced_body(self.body, output);10279}10280DEFPRINT(AST_If, function(self, output) {10281output.print("if");10282output.space();10283output.with_parens(function() {10284self.condition.print(output);10285});10286output.space();10287if (self.alternative) {10288make_then(self, output);10289output.space();10290output.print("else");10291output.space();10292if (self.alternative instanceof AST_If)10293self.alternative.print(output);10294else10295print_maybe_braced_body(self.alternative, output);10296} else {10297self._do_print_body(output);10298}10299});1030010301/* -----[ switch ]----- */10302DEFPRINT(AST_Switch, function(self, output) {10303output.print("switch");10304output.space();10305output.with_parens(function() {10306self.expression.print(output);10307});10308output.space();10309var last = self.body.length - 1;10310if (last < 0) print_braced_empty(self, output);10311else output.with_block(function() {10312self.body.forEach(function(branch, i) {10313output.indent(true);10314branch.print(output);10315if (i < last && branch.body.length > 0)10316output.newline();10317});10318});10319});10320AST_SwitchBranch.DEFMETHOD("_do_print_body", function(output) {10321output.newline();10322this.body.forEach(function(stmt) {10323output.indent();10324stmt.print(output);10325output.newline();10326});10327});10328DEFPRINT(AST_Default, function(self, output) {10329output.print("default:");10330self._do_print_body(output);10331});10332DEFPRINT(AST_Case, function(self, output) {10333output.print("case");10334output.space();10335self.expression.print(output);10336output.print(":");10337self._do_print_body(output);10338});1033910340/* -----[ exceptions ]----- */10341DEFPRINT(AST_Try, function(self, output) {10342output.print("try");10343output.space();10344self.body.print(output);10345if (self.bcatch) {10346output.space();10347self.bcatch.print(output);10348}10349if (self.bfinally) {10350output.space();10351self.bfinally.print(output);10352}10353});10354DEFPRINT(AST_TryBlock, function(self, output) {10355print_braced(self, output);10356});10357DEFPRINT(AST_Catch, function(self, output) {10358output.print("catch");10359if (self.argname) {10360output.space();10361output.with_parens(function() {10362self.argname.print(output);10363});10364}10365output.space();10366print_braced(self, output);10367});10368DEFPRINT(AST_Finally, function(self, output) {10369output.print("finally");10370output.space();10371print_braced(self, output);10372});1037310374/* -----[ var/const ]----- */10375AST_Definitions.DEFMETHOD("_do_print", function(output, kind) {10376output.print(kind);10377output.space();10378this.definitions.forEach(function(def, i) {10379if (i) output.comma();10380def.print(output);10381});10382var p = output.parent();10383var in_for = p instanceof AST_For || p instanceof AST_ForIn;10384var output_semicolon = !in_for || p && p.init !== this;10385if (output_semicolon)10386output.semicolon();10387});10388DEFPRINT(AST_Let, function(self, output) {10389self._do_print(output, "let");10390});10391DEFPRINT(AST_Var, function(self, output) {10392self._do_print(output, "var");10393});10394DEFPRINT(AST_Const, function(self, output) {10395self._do_print(output, "const");10396});10397DEFPRINT(AST_Import, function(self, output) {10398output.print("import");10399output.space();10400if (self.imported_name) {10401self.imported_name.print(output);10402}10403if (self.imported_name && self.imported_names) {10404output.print(",");10405output.space();10406}10407if (self.imported_names) {10408if (self.imported_names.length === 1 &&10409self.imported_names[0].foreign_name.name === "*" &&10410!self.imported_names[0].foreign_name.quote) {10411self.imported_names[0].print(output);10412} else {10413output.print("{");10414self.imported_names.forEach(function (name_import, i) {10415output.space();10416name_import.print(output);10417if (i < self.imported_names.length - 1) {10418output.print(",");10419}10420});10421output.space();10422output.print("}");10423}10424}10425if (self.imported_name || self.imported_names) {10426output.space();10427output.print("from");10428output.space();10429}10430self.module_name.print(output);10431if (self.assert_clause) {10432output.print("assert");10433self.assert_clause.print(output);10434}10435output.semicolon();10436});10437DEFPRINT(AST_ImportMeta, function(self, output) {10438output.print("import.meta");10439});1044010441DEFPRINT(AST_NameMapping, function(self, output) {10442var is_import = output.parent() instanceof AST_Import;10443var definition = self.name.definition();10444var foreign_name = self.foreign_name;10445var names_are_different =10446(definition && definition.mangled_name || self.name.name) !==10447foreign_name.name;10448if (!names_are_different &&10449foreign_name.name === "*" &&10450foreign_name.quote != self.name.quote) {10451// export * as "*"10452names_are_different = true;10453}10454var foreign_name_is_name = foreign_name.quote == null;10455if (names_are_different) {10456if (is_import) {10457if (foreign_name_is_name) {10458output.print(foreign_name.name);10459} else {10460output.print_string(foreign_name.name, foreign_name.quote);10461}10462} else {10463if (self.name.quote == null) {10464self.name.print(output);10465} else {10466output.print_string(self.name.name, self.name.quote);10467}1046810469}10470output.space();10471output.print("as");10472output.space();10473if (is_import) {10474self.name.print(output);10475} else {10476if (foreign_name_is_name) {10477output.print(foreign_name.name);10478} else {10479output.print_string(foreign_name.name, foreign_name.quote);10480}10481}10482} else {10483if (self.name.quote == null) {10484self.name.print(output);10485} else {10486output.print_string(self.name.name, self.name.quote);10487}10488}10489});1049010491DEFPRINT(AST_Export, function(self, output) {10492output.print("export");10493output.space();10494if (self.is_default) {10495output.print("default");10496output.space();10497}10498if (self.exported_names) {10499if (self.exported_names.length === 1 &&10500self.exported_names[0].name.name === "*" &&10501!self.exported_names[0].name.quote) {10502self.exported_names[0].print(output);10503} else {10504output.print("{");10505self.exported_names.forEach(function(name_export, i) {10506output.space();10507name_export.print(output);10508if (i < self.exported_names.length - 1) {10509output.print(",");10510}10511});10512output.space();10513output.print("}");10514}10515} else if (self.exported_value) {10516self.exported_value.print(output);10517} else if (self.exported_definition) {10518self.exported_definition.print(output);10519if (self.exported_definition instanceof AST_Definitions) return;10520}10521if (self.module_name) {10522output.space();10523output.print("from");10524output.space();10525self.module_name.print(output);10526}10527if (self.assert_clause) {10528output.print("assert");10529self.assert_clause.print(output);10530}10531if (self.exported_value10532&& !(self.exported_value instanceof AST_Defun ||10533self.exported_value instanceof AST_Function ||10534self.exported_value instanceof AST_Class)10535|| self.module_name10536|| self.exported_names10537) {10538output.semicolon();10539}10540});1054110542function parenthesize_for_noin(node, output, noin) {10543var parens = false;10544// need to take some precautions here:10545// https://github.com/mishoo/UglifyJS2/issues/6010546if (noin) {10547parens = walk(node, node => {10548// Don't go into scopes -- except arrow functions:10549// https://github.com/terser/terser/issues/1019#issuecomment-87764260710550if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) {10551return true;10552}10553if (10554node instanceof AST_Binary && node.operator == "in"10555|| node instanceof AST_PrivateIn10556) {10557return walk_abort; // makes walk() return true10558}10559});10560}10561node.print(output, parens);10562}1056310564DEFPRINT(AST_VarDef, function(self, output) {10565self.name.print(output);10566if (self.value) {10567output.space();10568output.print("=");10569output.space();10570var p = output.parent(1);10571var noin = p instanceof AST_For || p instanceof AST_ForIn;10572parenthesize_for_noin(self.value, output, noin);10573}10574});1057510576/* -----[ other expressions ]----- */10577DEFPRINT(AST_Call, function(self, output) {10578self.expression.print(output);10579if (self instanceof AST_New && self.args.length === 0)10580return;10581if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {10582output.add_mapping(self.start);10583}10584if (self.optional) output.print("?.");10585output.with_parens(function() {10586self.args.forEach(function(expr, i) {10587if (i) output.comma();10588expr.print(output);10589});10590});10591});10592DEFPRINT(AST_New, function(self, output) {10593output.print("new");10594output.space();10595AST_Call.prototype._codegen(self, output);10596});1059710598AST_Sequence.DEFMETHOD("_do_print", function(output) {10599this.expressions.forEach(function(node, index) {10600if (index > 0) {10601output.comma();10602if (output.should_break()) {10603output.newline();10604output.indent();10605}10606}10607node.print(output);10608});10609});10610DEFPRINT(AST_Sequence, function(self, output) {10611self._do_print(output);10612// var p = output.parent();10613// if (p instanceof AST_Statement) {10614// output.with_indent(output.next_indent(), function(){10615// self._do_print(output);10616// });10617// } else {10618// self._do_print(output);10619// }10620});10621DEFPRINT(AST_Dot, function(self, output) {10622var expr = self.expression;10623expr.print(output);10624var prop = self.property;10625var print_computed = ALL_RESERVED_WORDS.has(prop)10626? output.option("ie8")10627: !is_identifier_string(10628prop,10629output.option("ecma") >= 2015 && !output.option("safari10")10630);1063110632if (self.optional) output.print("?.");1063310634if (print_computed) {10635output.print("[");10636output.add_mapping(self.end);10637output.print_string(prop);10638output.print("]");10639} else {10640if (expr instanceof AST_Number && expr.getValue() >= 0) {10641if (!/[xa-f.)]/i.test(output.last())) {10642output.print(".");10643}10644}10645if (!self.optional) output.print(".");10646// the name after dot would be mapped about here.10647output.add_mapping(self.end);10648output.print_name(prop);10649}10650});10651DEFPRINT(AST_DotHash, function(self, output) {10652var expr = self.expression;10653expr.print(output);10654var prop = self.property;1065510656if (self.optional) output.print("?");10657output.print(".#");10658output.add_mapping(self.end);10659output.print_name(prop);10660});10661DEFPRINT(AST_Sub, function(self, output) {10662self.expression.print(output);10663if (self.optional) output.print("?.");10664output.print("[");10665self.property.print(output);10666output.print("]");10667});10668DEFPRINT(AST_Chain, function(self, output) {10669self.expression.print(output);10670});10671DEFPRINT(AST_UnaryPrefix, function(self, output) {10672var op = self.operator;10673output.print(op);10674if (/^[a-z]/i.test(op)10675|| (/[+-]$/.test(op)10676&& self.expression instanceof AST_UnaryPrefix10677&& /^[+-]/.test(self.expression.operator))) {10678output.space();10679}10680self.expression.print(output);10681});10682DEFPRINT(AST_UnaryPostfix, function(self, output) {10683self.expression.print(output);10684output.print(self.operator);10685});10686DEFPRINT(AST_Binary, function(self, output) {10687var op = self.operator;10688self.left.print(output);10689if (op[0] == ">" /* ">>" ">>>" ">" ">=" */10690&& self.left instanceof AST_UnaryPostfix10691&& self.left.operator == "--") {10692// space is mandatory to avoid outputting -->10693output.print(" ");10694} else {10695// the space is optional depending on "beautify"10696output.space();10697}10698output.print(op);10699if ((op == "<" || op == "<<")10700&& self.right instanceof AST_UnaryPrefix10701&& self.right.operator == "!"10702&& self.right.expression instanceof AST_UnaryPrefix10703&& self.right.expression.operator == "--") {10704// space is mandatory to avoid outputting <!--10705output.print(" ");10706} else {10707// the space is optional depending on "beautify"10708output.space();10709}10710self.right.print(output);10711});10712DEFPRINT(AST_Conditional, function(self, output) {10713self.condition.print(output);10714output.space();10715output.print("?");10716output.space();10717self.consequent.print(output);10718output.space();10719output.colon();10720self.alternative.print(output);10721});1072210723/* -----[ literals ]----- */10724DEFPRINT(AST_Array, function(self, output) {10725output.with_square(function() {10726var a = self.elements, len = a.length;10727if (len > 0) output.space();10728a.forEach(function(exp, i) {10729if (i) output.comma();10730exp.print(output);10731// If the final element is a hole, we need to make sure it10732// doesn't look like a trailing comma, by inserting an actual10733// trailing comma.10734if (i === len - 1 && exp instanceof AST_Hole)10735output.comma();10736});10737if (len > 0) output.space();10738});10739});10740DEFPRINT(AST_Object, function(self, output) {10741if (self.properties.length > 0) output.with_block(function() {10742self.properties.forEach(function(prop, i) {10743if (i) {10744output.print(",");10745output.newline();10746}10747output.indent();10748prop.print(output);10749});10750output.newline();10751});10752else print_braced_empty(self, output);10753});10754DEFPRINT(AST_Class, function(self, output) {10755output.print("class");10756output.space();10757if (self.name) {10758self.name.print(output);10759output.space();10760}10761if (self.extends) {10762var parens = (10763!(self.extends instanceof AST_SymbolRef)10764&& !(self.extends instanceof AST_PropAccess)10765&& !(self.extends instanceof AST_ClassExpression)10766&& !(self.extends instanceof AST_Function)10767);10768output.print("extends");10769if (parens) {10770output.print("(");10771} else {10772output.space();10773}10774self.extends.print(output);10775if (parens) {10776output.print(")");10777} else {10778output.space();10779}10780}10781if (self.properties.length > 0) output.with_block(function() {10782self.properties.forEach(function(prop, i) {10783if (i) {10784output.newline();10785}10786output.indent();10787prop.print(output);10788});10789output.newline();10790});10791else output.print("{}");10792});10793DEFPRINT(AST_NewTarget, function(self, output) {10794output.print("new.target");10795});1079610797/** Prints a prop name. Returns whether it can be used as a shorthand. */10798function print_property_name(key, quote, output) {10799if (output.option("quote_keys")) {10800output.print_string(key);10801return false;10802}10803if ("" + +key == key && key >= 0) {10804if (output.option("keep_numbers")) {10805output.print(key);10806return false;10807}10808output.print(make_num(key));10809return false;10810}10811var print_string = ALL_RESERVED_WORDS.has(key)10812? output.option("ie8")10813: (10814output.option("ecma") < 2015 || output.option("safari10")10815? !is_basic_identifier_string(key)10816: !is_identifier_string(key, true)10817);10818if (print_string || (quote && output.option("keep_quoted_props"))) {10819output.print_string(key, quote);10820return false;10821}10822output.print_name(key);10823return true;10824}1082510826DEFPRINT(AST_ObjectKeyVal, function(self, output) {10827function get_name(self) {10828var def = self.definition();10829return def ? def.mangled_name || def.name : self.name;10830}1083110832const try_shorthand = output.option("shorthand") && !(self.key instanceof AST_Node);10833if (10834try_shorthand10835&& self.value instanceof AST_Symbol10836&& get_name(self.value) === self.key10837&& !ALL_RESERVED_WORDS.has(self.key)10838) {10839const was_shorthand = print_property_name(self.key, self.quote, output);10840if (!was_shorthand) {10841output.colon();10842self.value.print(output);10843}10844} else if (10845try_shorthand10846&& self.value instanceof AST_DefaultAssign10847&& self.value.left instanceof AST_Symbol10848&& get_name(self.value.left) === self.key10849) {10850const was_shorthand = print_property_name(self.key, self.quote, output);10851if (!was_shorthand) {10852output.colon();10853self.value.left.print(output);10854}10855output.space();10856output.print("=");10857output.space();10858self.value.right.print(output);10859} else {10860if (!(self.key instanceof AST_Node)) {10861print_property_name(self.key, self.quote, output);10862} else {10863output.with_square(function() {10864self.key.print(output);10865});10866}10867output.colon();10868self.value.print(output);10869}10870});10871DEFPRINT(AST_ClassPrivateProperty, (self, output) => {10872if (self.static) {10873output.print("static");10874output.space();10875}1087610877output.print("#");1087810879print_property_name(self.key.name, self.quote, output);1088010881if (self.value) {10882output.print("=");10883self.value.print(output);10884}1088510886output.semicolon();10887});10888DEFPRINT(AST_ClassProperty, (self, output) => {10889if (self.static) {10890output.print("static");10891output.space();10892}1089310894if (self.key instanceof AST_SymbolClassProperty) {10895print_property_name(self.key.name, self.quote, output);10896} else {10897output.print("[");10898self.key.print(output);10899output.print("]");10900}1090110902if (self.value) {10903output.print("=");10904self.value.print(output);10905}1090610907output.semicolon();10908});10909AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, is_private, output) {10910var self = this;10911if (self.static) {10912output.print("static");10913output.space();10914}10915if (type) {10916output.print(type);10917output.space();10918}10919if (self.key instanceof AST_SymbolMethod) {10920if (is_private) output.print("#");10921print_property_name(self.key.name, self.quote, output);10922} else {10923output.with_square(function() {10924self.key.print(output);10925});10926}10927self.value._do_print(output, true);10928});10929DEFPRINT(AST_ObjectSetter, function(self, output) {10930self._print_getter_setter("set", false, output);10931});10932DEFPRINT(AST_ObjectGetter, function(self, output) {10933self._print_getter_setter("get", false, output);10934});10935DEFPRINT(AST_PrivateSetter, function(self, output) {10936self._print_getter_setter("set", true, output);10937});10938DEFPRINT(AST_PrivateGetter, function(self, output) {10939self._print_getter_setter("get", true, output);10940});10941DEFPRINT(AST_PrivateMethod, function(self, output) {10942var type;10943if (self.is_generator && self.async) {10944type = "async*";10945} else if (self.is_generator) {10946type = "*";10947} else if (self.async) {10948type = "async";10949}10950self._print_getter_setter(type, true, output);10951});10952DEFPRINT(AST_PrivateIn, function(self, output) {10953self.key.print(output);10954output.space();10955output.print("in");10956output.space();10957self.value.print(output);10958});10959DEFPRINT(AST_SymbolPrivateProperty, function(self, output) {10960output.print("#" + self.name);10961});10962DEFPRINT(AST_ConciseMethod, function(self, output) {10963var type;10964if (self.is_generator && self.async) {10965type = "async*";10966} else if (self.is_generator) {10967type = "*";10968} else if (self.async) {10969type = "async";10970}10971self._print_getter_setter(type, false, output);10972});10973DEFPRINT(AST_ClassStaticBlock, function (self, output) {10974output.print("static");10975output.space();10976print_braced(self, output);10977});10978AST_Symbol.DEFMETHOD("_do_print", function(output) {10979var def = this.definition();10980output.print_name(def ? def.mangled_name || def.name : this.name);10981});10982DEFPRINT(AST_Symbol, function (self, output) {10983self._do_print(output);10984});10985DEFPRINT(AST_Hole, noop);10986DEFPRINT(AST_This, function(self, output) {10987output.print("this");10988});10989DEFPRINT(AST_Super, function(self, output) {10990output.print("super");10991});10992DEFPRINT(AST_Constant, function(self, output) {10993output.print(self.getValue());10994});10995DEFPRINT(AST_String, function(self, output) {10996output.print_string(self.getValue(), self.quote, output.in_directive);10997});10998DEFPRINT(AST_Number, function(self, output) {10999if ((output.option("keep_numbers") || output.use_asm) && self.raw) {11000output.print(self.raw);11001} else {11002output.print(make_num(self.getValue()));11003}11004});11005DEFPRINT(AST_BigInt, function(self, output) {11006output.print(self.getValue() + "n");11007});1100811009const r_slash_script = /(<\s*\/\s*script)/i;11010const slash_script_replace = (_, $1) => $1.replace("/", "\\/");11011DEFPRINT(AST_RegExp, function(self, output) {11012let { source, flags } = self.getValue();11013source = regexp_source_fix(source);11014flags = flags ? sort_regexp_flags(flags) : "";11015source = source.replace(r_slash_script, slash_script_replace);1101611017output.print(output.to_utf8(`/${source}/${flags}`, false, true));1101811019const parent = output.parent();11020if (11021parent instanceof AST_Binary11022&& /^\w/.test(parent.operator)11023&& parent.left === self11024) {11025output.print(" ");11026}11027});1102811029/** if, for, while, may or may not have braces surrounding its body */11030function print_maybe_braced_body(stat, output) {11031if (output.option("braces")) {11032make_block(stat, output);11033} else {11034if (!stat || stat instanceof AST_EmptyStatement)11035output.force_semicolon();11036else if (stat instanceof AST_Let || stat instanceof AST_Const || stat instanceof AST_Class)11037make_block(stat, output);11038else11039stat.print(output);11040}11041}1104211043function best_of(a) {11044var best = a[0], len = best.length;11045for (var i = 1; i < a.length; ++i) {11046if (a[i].length < len) {11047best = a[i];11048len = best.length;11049}11050}11051return best;11052}1105311054function make_num(num) {11055var str = num.toString(10).replace(/^0\./, ".").replace("e+", "e");11056var candidates = [ str ];11057if (Math.floor(num) === num) {11058if (num < 0) {11059candidates.push("-0x" + (-num).toString(16).toLowerCase());11060} else {11061candidates.push("0x" + num.toString(16).toLowerCase());11062}11063}11064var match, len, digits;11065if (match = /^\.0+/.exec(str)) {11066len = match[0].length;11067digits = str.slice(len);11068candidates.push(digits + "e-" + (digits.length + len - 1));11069} else if (match = /0+$/.exec(str)) {11070len = match[0].length;11071candidates.push(str.slice(0, -len) + "e" + len);11072} else if (match = /^(\d)\.(\d+)e(-?\d+)$/.exec(str)) {11073candidates.push(match[1] + match[2] + "e" + (match[3] - match[2].length));11074}11075return best_of(candidates);11076}1107711078function make_block(stmt, output) {11079if (!stmt || stmt instanceof AST_EmptyStatement)11080output.print("{}");11081else if (stmt instanceof AST_BlockStatement)11082stmt.print(output);11083else output.with_block(function() {11084output.indent();11085stmt.print(output);11086output.newline();11087});11088}1108911090/* -----[ source map generators ]----- */1109111092function DEFMAP(nodetype, generator) {11093nodetype.forEach(function(nodetype) {11094nodetype.DEFMETHOD("add_source_map", generator);11095});11096}1109711098DEFMAP([11099// We could easily add info for ALL nodes, but it seems to me that11100// would be quite wasteful, hence this noop in the base class.11101AST_Node,11102// since the label symbol will mark it11103AST_LabeledStatement,11104AST_Toplevel,11105], noop);1110611107// XXX: I'm not exactly sure if we need it for all of these nodes,11108// or if we should add even more.11109DEFMAP([11110AST_Array,11111AST_BlockStatement,11112AST_Catch,11113AST_Class,11114AST_Constant,11115AST_Debugger,11116AST_Definitions,11117AST_Directive,11118AST_Finally,11119AST_Jump,11120AST_Lambda,11121AST_New,11122AST_Object,11123AST_StatementWithBody,11124AST_Symbol,11125AST_Switch,11126AST_SwitchBranch,11127AST_TemplateString,11128AST_TemplateSegment,11129AST_Try,11130], function(output) {11131output.add_mapping(this.start);11132});1113311134DEFMAP([11135AST_ObjectGetter,11136AST_ObjectSetter,11137AST_PrivateGetter,11138AST_PrivateSetter,11139], function(output) {11140output.add_mapping(this.key.end, this.key.name);11141});1114211143DEFMAP([ AST_ObjectProperty ], function(output) {11144output.add_mapping(this.start, this.key);11145});11146})();1114711148/***********************************************************************1114911150A JavaScript tokenizer / parser / beautifier / compressor.11151https://github.com/mishoo/UglifyJS21115211153-------------------------------- (C) ---------------------------------1115411155Author: Mihai Bazon11156<[email protected]>11157http://mihai.bazon.net/blog1115811159Distributed under the BSD license:1116011161Copyright 2012 (c) Mihai Bazon <[email protected]>1116211163Redistribution and use in source and binary forms, with or without11164modification, are permitted provided that the following conditions11165are met:1116611167* Redistributions of source code must retain the above11168copyright notice, this list of conditions and the following11169disclaimer.1117011171* Redistributions in binary form must reproduce the above11172copyright notice, this list of conditions and the following11173disclaimer in the documentation and/or other materials11174provided with the distribution.1117511176THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY11177EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE11178IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR11179PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE11180LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,11181OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,11182PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR11183PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY11184THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR11185TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF11186THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF11187SUCH DAMAGE.1118811189***********************************************************************/1119011191const MASK_EXPORT_DONT_MANGLE = 1 << 0;11192const MASK_EXPORT_WANT_MANGLE = 1 << 1;1119311194let function_defs = null;11195let unmangleable_names = null;11196/**11197* When defined, there is a function declaration somewhere that's inside of a block.11198* See https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-block-level-function-declarations-web-legacy-compatibility-semantics11199*/11200let scopes_with_block_defuns = null;1120111202class SymbolDef {11203constructor(scope, orig, init) {11204this.name = orig.name;11205this.orig = [ orig ];11206this.init = init;11207this.eliminated = 0;11208this.assignments = 0;11209this.scope = scope;11210this.replaced = 0;11211this.global = false;11212this.export = 0;11213this.mangled_name = null;11214this.undeclared = false;11215this.id = SymbolDef.next_id++;11216this.chained = false;11217this.direct_access = false;11218this.escaped = 0;11219this.recursive_refs = 0;11220this.references = [];11221this.should_replace = undefined;11222this.single_use = false;11223this.fixed = false;11224Object.seal(this);11225}11226fixed_value() {11227if (!this.fixed || this.fixed instanceof AST_Node) return this.fixed;11228return this.fixed();11229}11230unmangleable(options) {11231if (!options) options = {};1123211233if (11234function_defs &&11235function_defs.has(this.id) &&11236keep_name(options.keep_fnames, this.orig[0].name)11237) return true;1123811239return this.global && !options.toplevel11240|| (this.export & MASK_EXPORT_DONT_MANGLE)11241|| this.undeclared11242|| !options.eval && this.scope.pinned()11243|| (this.orig[0] instanceof AST_SymbolLambda11244|| this.orig[0] instanceof AST_SymbolDefun) && keep_name(options.keep_fnames, this.orig[0].name)11245|| this.orig[0] instanceof AST_SymbolMethod11246|| (this.orig[0] instanceof AST_SymbolClass11247|| this.orig[0] instanceof AST_SymbolDefClass) && keep_name(options.keep_classnames, this.orig[0].name);11248}11249mangle(options) {11250const cache = options.cache && options.cache.props;11251if (this.global && cache && cache.has(this.name)) {11252this.mangled_name = cache.get(this.name);11253} else if (!this.mangled_name && !this.unmangleable(options)) {11254var s = this.scope;11255var sym = this.orig[0];11256if (options.ie8 && sym instanceof AST_SymbolLambda)11257s = s.parent_scope;11258const redefinition = redefined_catch_def(this);11259this.mangled_name = redefinition11260? redefinition.mangled_name || redefinition.name11261: s.next_mangled(options, this);11262if (this.global && cache) {11263cache.set(this.name, this.mangled_name);11264}11265}11266}11267}1126811269SymbolDef.next_id = 1;1127011271function redefined_catch_def(def) {11272if (def.orig[0] instanceof AST_SymbolCatch11273&& def.scope.is_block_scope()11274) {11275return def.scope.get_defun_scope().variables.get(def.name);11276}11277}1127811279AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null, toplevel = this } = {}) {11280options = defaults(options, {11281cache: null,11282ie8: false,11283safari10: false,11284});1128511286if (!(toplevel instanceof AST_Toplevel)) {11287throw new Error("Invalid toplevel scope");11288}1128911290// pass 1: setup scope chaining and handle definitions11291var scope = this.parent_scope = parent_scope;11292var labels = new Map();11293var defun = null;11294var in_destructuring = null;11295var for_scopes = [];11296var tw = new TreeWalker((node, descend) => {11297if (node.is_block_scope()) {11298const save_scope = scope;11299node.block_scope = scope = new AST_Scope(node);11300scope._block_scope = true;11301scope.init_scope_vars(save_scope);11302scope.uses_with = save_scope.uses_with;11303scope.uses_eval = save_scope.uses_eval;1130411305if (options.safari10) {11306if (node instanceof AST_For || node instanceof AST_ForIn || node instanceof AST_ForOf) {11307for_scopes.push(scope);11308}11309}1131011311if (node instanceof AST_Switch) {11312// XXX: HACK! Ensure the switch expression gets the correct scope (the parent scope) and the body gets the contained scope11313// AST_Switch has a scope within the body, but it itself "is a block scope"11314// This means the switched expression has to belong to the outer scope11315// while the body inside belongs to the switch itself.11316// This is pretty nasty and warrants an AST change11317const the_block_scope = scope;11318scope = save_scope;11319node.expression.walk(tw);11320scope = the_block_scope;11321for (let i = 0; i < node.body.length; i++) {11322node.body[i].walk(tw);11323}11324} else {11325descend();11326}11327scope = save_scope;11328return true;11329}11330if (node instanceof AST_Destructuring) {11331const save_destructuring = in_destructuring;11332in_destructuring = node;11333descend();11334in_destructuring = save_destructuring;11335return true;11336}11337if (node instanceof AST_Scope) {11338node.init_scope_vars(scope);11339var save_scope = scope;11340var save_defun = defun;11341var save_labels = labels;11342defun = scope = node;11343labels = new Map();11344descend();11345scope = save_scope;11346defun = save_defun;11347labels = save_labels;11348return true; // don't descend again in TreeWalker11349}11350if (node instanceof AST_LabeledStatement) {11351var l = node.label;11352if (labels.has(l.name)) {11353throw new Error(string_template("Label {name} defined twice", l));11354}11355labels.set(l.name, l);11356descend();11357labels.delete(l.name);11358return true; // no descend again11359}11360if (node instanceof AST_With) {11361for (var s = scope; s; s = s.parent_scope)11362s.uses_with = true;11363return;11364}11365if (node instanceof AST_Symbol) {11366node.scope = scope;11367}11368if (node instanceof AST_Label) {11369node.thedef = node;11370node.references = [];11371}11372if (node instanceof AST_SymbolLambda) {11373defun.def_function(node, node.name == "arguments" ? undefined : defun);11374} else if (node instanceof AST_SymbolDefun) {11375// Careful here, the scope where this should be defined is11376// the parent scope. The reason is that we enter a new11377// scope when we encounter the AST_Defun node (which is11378// instanceof AST_Scope) but we get to the symbol a bit11379// later.11380const closest_scope = defun.parent_scope;1138111382// In strict mode, function definitions are block-scoped11383node.scope = tw.directives["use strict"]11384? closest_scope11385: closest_scope.get_defun_scope();1138611387mark_export(node.scope.def_function(node, defun), 1);11388} else if (node instanceof AST_SymbolClass) {11389mark_export(defun.def_variable(node, defun), 1);11390} else if (node instanceof AST_SymbolImport) {11391scope.def_variable(node);11392} else if (node instanceof AST_SymbolDefClass) {11393// This deals with the name of the class being available11394// inside the class.11395mark_export((node.scope = defun.parent_scope).def_function(node, defun), 1);11396} else if (11397node instanceof AST_SymbolVar11398|| node instanceof AST_SymbolLet11399|| node instanceof AST_SymbolConst11400|| node instanceof AST_SymbolCatch11401) {11402var def;11403if (node instanceof AST_SymbolBlockDeclaration) {11404def = scope.def_variable(node, null);11405} else {11406def = defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);11407}11408if (!def.orig.every((sym) => {11409if (sym === node) return true;11410if (node instanceof AST_SymbolBlockDeclaration) {11411return sym instanceof AST_SymbolLambda;11412}11413return !(sym instanceof AST_SymbolLet || sym instanceof AST_SymbolConst);11414})) {11415js_error(11416`"${node.name}" is redeclared`,11417node.start.file,11418node.start.line,11419node.start.col,11420node.start.pos11421);11422}11423if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2);11424if (defun !== scope) {11425node.mark_enclosed();11426var def = scope.find_variable(node);11427if (node.thedef !== def) {11428node.thedef = def;11429node.reference();11430}11431}11432} else if (node instanceof AST_LabelRef) {11433var sym = labels.get(node.name);11434if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", {11435name: node.name,11436line: node.start.line,11437col: node.start.col11438}));11439node.thedef = sym;11440}11441if (!(scope instanceof AST_Toplevel) && (node instanceof AST_Export || node instanceof AST_Import)) {11442js_error(11443`"${node.TYPE}" statement may only appear at the top level`,11444node.start.file,11445node.start.line,11446node.start.col,11447node.start.pos11448);11449}11450});11451this.walk(tw);1145211453function mark_export(def, level) {11454if (in_destructuring) {11455var i = 0;11456do {11457level++;11458} while (tw.parent(i++) !== in_destructuring);11459}11460var node = tw.parent(level);11461if (def.export = node instanceof AST_Export ? MASK_EXPORT_DONT_MANGLE : 0) {11462var exported = node.exported_definition;11463if ((exported instanceof AST_Defun || exported instanceof AST_DefClass) && node.is_default) {11464def.export = MASK_EXPORT_WANT_MANGLE;11465}11466}11467}1146811469// pass 2: find back references and eval11470const is_toplevel = this instanceof AST_Toplevel;11471if (is_toplevel) {11472this.globals = new Map();11473}1147411475var tw = new TreeWalker(node => {11476if (node instanceof AST_LoopControl && node.label) {11477node.label.thedef.references.push(node);11478return true;11479}11480if (node instanceof AST_SymbolRef) {11481var name = node.name;11482if (name == "eval" && tw.parent() instanceof AST_Call) {11483for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {11484s.uses_eval = true;11485}11486}11487var sym;11488if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name11489|| !(sym = node.scope.find_variable(name))) {1149011491sym = toplevel.def_global(node);11492if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;11493} else if (sym.scope instanceof AST_Lambda && name == "arguments") {11494sym.scope.get_defun_scope().uses_arguments = true;11495}11496node.thedef = sym;11497node.reference();11498if (node.scope.is_block_scope()11499&& !(sym.orig[0] instanceof AST_SymbolBlockDeclaration)) {11500node.scope = node.scope.get_defun_scope();11501}11502return true;11503}11504// ensure mangling works if catch reuses a scope variable11505var def;11506if (node instanceof AST_SymbolCatch && (def = redefined_catch_def(node.definition()))) {11507var s = node.scope;11508while (s) {11509push_uniq(s.enclosed, def);11510if (s === def.scope) break;11511s = s.parent_scope;11512}11513}11514});11515this.walk(tw);1151611517// pass 3: work around IE8 and Safari catch scope bugs11518if (options.ie8 || options.safari10) {11519walk(this, node => {11520if (node instanceof AST_SymbolCatch) {11521var name = node.name;11522var refs = node.thedef.references;11523var scope = node.scope.get_defun_scope();11524var def = scope.find_variable(name)11525|| toplevel.globals.get(name)11526|| scope.def_variable(node);11527refs.forEach(function(ref) {11528ref.thedef = def;11529ref.reference();11530});11531node.thedef = def;11532node.reference();11533return true;11534}11535});11536}1153711538// pass 4: add symbol definitions to loop scopes11539// Safari/Webkit bug workaround - loop init let variable shadowing argument.11540// https://github.com/mishoo/UglifyJS2/issues/175311541// https://bugs.webkit.org/show_bug.cgi?id=17104111542if (options.safari10) {11543for (const scope of for_scopes) {11544scope.parent_scope.variables.forEach(function(def) {11545push_uniq(scope.enclosed, def);11546});11547}11548}11549});1155011551AST_Toplevel.DEFMETHOD("def_global", function(node) {11552var globals = this.globals, name = node.name;11553if (globals.has(name)) {11554return globals.get(name);11555} else {11556var g = new SymbolDef(this, node);11557g.undeclared = true;11558g.global = true;11559globals.set(name, g);11560return g;11561}11562});1156311564AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {11565this.variables = new Map(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)11566this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement11567this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`11568this.parent_scope = parent_scope; // the parent scope11569this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes11570this.cname = -1; // the current index for mangling functions/variables11571});1157211573AST_Scope.DEFMETHOD("conflicting_def", function (name) {11574return (11575this.enclosed.find(def => def.name === name)11576|| this.variables.has(name)11577|| (this.parent_scope && this.parent_scope.conflicting_def(name))11578);11579});1158011581AST_Scope.DEFMETHOD("conflicting_def_shallow", function (name) {11582return (11583this.enclosed.find(def => def.name === name)11584|| this.variables.has(name)11585);11586});1158711588AST_Scope.DEFMETHOD("add_child_scope", function (scope) {11589// `scope` is going to be moved into `this` right now.11590// Update the required scopes' information1159111592if (scope.parent_scope === this) return;1159311594scope.parent_scope = this;1159511596// Propagate to this.uses_arguments from arrow functions11597if ((scope instanceof AST_Arrow) && !this.uses_arguments) {11598this.uses_arguments = walk(scope, node => {11599if (11600node instanceof AST_SymbolRef11601&& node.scope instanceof AST_Lambda11602&& node.name === "arguments"11603) {11604return walk_abort;11605}1160611607if (node instanceof AST_Lambda && !(node instanceof AST_Arrow)) {11608return true;11609}11610});11611}1161211613this.uses_with = this.uses_with || scope.uses_with;11614this.uses_eval = this.uses_eval || scope.uses_eval;1161511616const scope_ancestry = (() => {11617const ancestry = [];11618let cur = this;11619do {11620ancestry.push(cur);11621} while ((cur = cur.parent_scope));11622ancestry.reverse();11623return ancestry;11624})();1162511626const new_scope_enclosed_set = new Set(scope.enclosed);11627const to_enclose = [];11628for (const scope_topdown of scope_ancestry) {11629to_enclose.forEach(e => push_uniq(scope_topdown.enclosed, e));11630for (const def of scope_topdown.variables.values()) {11631if (new_scope_enclosed_set.has(def)) {11632push_uniq(to_enclose, def);11633push_uniq(scope_topdown.enclosed, def);11634}11635}11636}11637});1163811639function find_scopes_visible_from(scopes) {11640const found_scopes = new Set();1164111642for (const scope of new Set(scopes)) {11643(function bubble_up(scope) {11644if (scope == null || found_scopes.has(scope)) return;1164511646found_scopes.add(scope);1164711648bubble_up(scope.parent_scope);11649})(scope);11650}1165111652return [...found_scopes];11653}1165411655// Creates a symbol during compression11656AST_Scope.DEFMETHOD("create_symbol", function(SymClass, {11657source,11658tentative_name,11659scope,11660conflict_scopes = [scope],11661init = null11662} = {}) {11663let symbol_name;1166411665conflict_scopes = find_scopes_visible_from(conflict_scopes);1166611667if (tentative_name) {11668// Implement hygiene (no new names are conflicting with existing names)11669tentative_name =11670symbol_name =11671tentative_name.replace(/(?:^[^a-z_$]|[^a-z0-9_$])/ig, "_");1167211673let i = 0;11674while (conflict_scopes.find(s => s.conflicting_def_shallow(symbol_name))) {11675symbol_name = tentative_name + "$" + i++;11676}11677}1167811679if (!symbol_name) {11680throw new Error("No symbol name could be generated in create_symbol()");11681}1168211683const symbol = make_node(SymClass, source, {11684name: symbol_name,11685scope11686});1168711688this.def_variable(symbol, init || null);1168911690symbol.mark_enclosed();1169111692return symbol;11693});116941169511696AST_Node.DEFMETHOD("is_block_scope", return_false);11697AST_Class.DEFMETHOD("is_block_scope", return_false);11698AST_Lambda.DEFMETHOD("is_block_scope", return_false);11699AST_Toplevel.DEFMETHOD("is_block_scope", return_false);11700AST_SwitchBranch.DEFMETHOD("is_block_scope", return_false);11701AST_Block.DEFMETHOD("is_block_scope", return_true);11702AST_Scope.DEFMETHOD("is_block_scope", function () {11703return this._block_scope || false;11704});11705AST_IterationStatement.DEFMETHOD("is_block_scope", return_true);1170611707AST_Lambda.DEFMETHOD("init_scope_vars", function() {11708AST_Scope.prototype.init_scope_vars.apply(this, arguments);11709this.uses_arguments = false;11710this.def_variable(new AST_SymbolFunarg({11711name: "arguments",11712start: this.start,11713end: this.end11714}));11715});1171611717AST_Arrow.DEFMETHOD("init_scope_vars", function() {11718AST_Scope.prototype.init_scope_vars.apply(this, arguments);11719this.uses_arguments = false;11720});1172111722AST_Symbol.DEFMETHOD("mark_enclosed", function() {11723var def = this.definition();11724var s = this.scope;11725while (s) {11726push_uniq(s.enclosed, def);11727if (s === def.scope) break;11728s = s.parent_scope;11729}11730});1173111732AST_Symbol.DEFMETHOD("reference", function() {11733this.definition().references.push(this);11734this.mark_enclosed();11735});1173611737AST_Scope.DEFMETHOD("find_variable", function(name) {11738if (name instanceof AST_Symbol) name = name.name;11739return this.variables.get(name)11740|| (this.parent_scope && this.parent_scope.find_variable(name));11741});1174211743AST_Scope.DEFMETHOD("def_function", function(symbol, init) {11744var def = this.def_variable(symbol, init);11745if (!def.init || def.init instanceof AST_Defun) def.init = init;11746return def;11747});1174811749AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {11750var def = this.variables.get(symbol.name);11751if (def) {11752def.orig.push(symbol);11753if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {11754def.init = init;11755}11756} else {11757def = new SymbolDef(this, symbol, init);11758this.variables.set(symbol.name, def);11759def.global = !this.parent_scope;11760}11761return symbol.thedef = def;11762});1176311764function next_mangled(scope, options) {11765let defun_scope;11766if (11767scopes_with_block_defuns11768&& (defun_scope = scope.get_defun_scope())11769&& scopes_with_block_defuns.has(defun_scope)11770) {11771scope = defun_scope;11772}1177311774var ext = scope.enclosed;11775var nth_identifier = options.nth_identifier;11776out: while (true) {11777var m = nth_identifier.get(++scope.cname);11778if (ALL_RESERVED_WORDS.has(m)) continue; // skip over "do"1177911780// https://github.com/mishoo/UglifyJS2/issues/242 -- do not11781// shadow a name reserved from mangling.11782if (options.reserved.has(m)) continue;1178311784// Functions with short names might collide with base54 output11785// and therefore cause collisions when keep_fnames is true.11786if (unmangleable_names && unmangleable_names.has(m)) continue out;1178711788// we must ensure that the mangled name does not shadow a name11789// from some parent scope that is referenced in this or in11790// inner scopes.11791for (let i = ext.length; --i >= 0;) {11792const def = ext[i];11793const name = def.mangled_name || (def.unmangleable(options) && def.name);11794if (m == name) continue out;11795}11796return m;11797}11798}1179911800AST_Scope.DEFMETHOD("next_mangled", function(options) {11801return next_mangled(this, options);11802});1180311804AST_Toplevel.DEFMETHOD("next_mangled", function(options) {11805let name;11806const mangled_names = this.mangled_names;11807do {11808name = next_mangled(this, options);11809} while (mangled_names.has(name));11810return name;11811});1181211813AST_Function.DEFMETHOD("next_mangled", function(options, def) {11814// #179, #32611815// in Safari strict mode, something like (function x(x){...}) is a syntax error;11816// a function expression's argument cannot shadow the function expression's name1181711818var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();1181911820// the function's mangled_name is null when keep_fnames is true11821var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;1182211823while (true) {11824var name = next_mangled(this, options);11825if (!tricky_name || tricky_name != name)11826return name;11827}11828});1182911830AST_Symbol.DEFMETHOD("unmangleable", function(options) {11831var def = this.definition();11832return !def || def.unmangleable(options);11833});1183411835// labels are always mangleable11836AST_Label.DEFMETHOD("unmangleable", return_false);1183711838AST_Symbol.DEFMETHOD("unreferenced", function() {11839return !this.definition().references.length && !this.scope.pinned();11840});1184111842AST_Symbol.DEFMETHOD("definition", function() {11843return this.thedef;11844});1184511846AST_Symbol.DEFMETHOD("global", function() {11847return this.thedef.global;11848});1184911850/**11851* Format the mangler options (if any) into their appropriate types11852*/11853function format_mangler_options(options) {11854options = defaults(options, {11855eval : false,11856nth_identifier : base54,11857ie8 : false,11858keep_classnames: false,11859keep_fnames : false,11860module : false,11861reserved : [],11862toplevel : false,11863});11864if (options.module) options.toplevel = true;11865if (!Array.isArray(options.reserved)11866&& !(options.reserved instanceof Set)11867) {11868options.reserved = [];11869}11870options.reserved = new Set(options.reserved);11871// Never mangle arguments11872options.reserved.add("arguments");11873return options;11874}1187511876AST_Toplevel.DEFMETHOD("mangle_names", function(options) {11877options = format_mangler_options(options);11878var nth_identifier = options.nth_identifier;1187911880// We only need to mangle declaration nodes. Special logic wired11881// into the code generator will display the mangled name if it's11882// present (and for AST_SymbolRef-s it'll use the mangled name of11883// the AST_SymbolDeclaration that it points to).11884var lname = -1;11885var to_mangle = [];1188611887if (options.keep_fnames) {11888function_defs = new Set();11889}1189011891const mangled_names = this.mangled_names = new Set();11892unmangleable_names = new Set();1189311894if (options.cache) {11895this.globals.forEach(collect);11896if (options.cache.props) {11897options.cache.props.forEach(function(mangled_name) {11898mangled_names.add(mangled_name);11899});11900}11901}1190211903var tw = new TreeWalker(function(node, descend) {11904if (node instanceof AST_LabeledStatement) {11905// lname is incremented when we get to the AST_Label11906var save_nesting = lname;11907descend();11908lname = save_nesting;11909return true; // don't descend again in TreeWalker11910}11911if (11912node instanceof AST_Defun11913&& !(tw.parent() instanceof AST_Scope)11914) {11915scopes_with_block_defuns = scopes_with_block_defuns || new Set();11916scopes_with_block_defuns.add(node.parent_scope.get_defun_scope());11917}11918if (node instanceof AST_Scope) {11919node.variables.forEach(collect);11920return;11921}11922if (node.is_block_scope()) {11923node.block_scope.variables.forEach(collect);11924return;11925}11926if (11927function_defs11928&& node instanceof AST_VarDef11929&& node.value instanceof AST_Lambda11930&& !node.value.name11931&& keep_name(options.keep_fnames, node.name.name)11932) {11933function_defs.add(node.name.definition().id);11934return;11935}11936if (node instanceof AST_Label) {11937let name;11938do {11939name = nth_identifier.get(++lname);11940} while (ALL_RESERVED_WORDS.has(name));11941node.mangled_name = name;11942return true;11943}11944if (!(options.ie8 || options.safari10) && node instanceof AST_SymbolCatch) {11945to_mangle.push(node.definition());11946return;11947}11948});1194911950this.walk(tw);1195111952if (options.keep_fnames || options.keep_classnames) {11953// Collect a set of short names which are unmangleable,11954// for use in avoiding collisions in next_mangled.11955to_mangle.forEach(def => {11956if (def.name.length < 6 && def.unmangleable(options)) {11957unmangleable_names.add(def.name);11958}11959});11960}1196111962to_mangle.forEach(def => { def.mangle(options); });1196311964function_defs = null;11965unmangleable_names = null;11966scopes_with_block_defuns = null;1196711968function collect(symbol) {11969if (symbol.export & MASK_EXPORT_DONT_MANGLE) {11970unmangleable_names.add(symbol.name);11971} else if (!options.reserved.has(symbol.name)) {11972to_mangle.push(symbol);11973}11974}11975});1197611977AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {11978const cache = options.cache && options.cache.props;11979const avoid = new Set();11980options.reserved.forEach(to_avoid);11981this.globals.forEach(add_def);11982this.walk(new TreeWalker(function(node) {11983if (node instanceof AST_Scope) node.variables.forEach(add_def);11984if (node instanceof AST_SymbolCatch) add_def(node.definition());11985}));11986return avoid;1198711988function to_avoid(name) {11989avoid.add(name);11990}1199111992function add_def(def) {11993var name = def.name;11994if (def.global && cache && cache.has(name)) name = cache.get(name);11995else if (!def.unmangleable(options)) return;11996to_avoid(name);11997}11998});1199912000AST_Toplevel.DEFMETHOD("expand_names", function(options) {12001options = format_mangler_options(options);12002var nth_identifier = options.nth_identifier;12003if (nth_identifier.reset && nth_identifier.sort) {12004nth_identifier.reset();12005nth_identifier.sort();12006}12007var avoid = this.find_colliding_names(options);12008var cname = 0;12009this.globals.forEach(rename);12010this.walk(new TreeWalker(function(node) {12011if (node instanceof AST_Scope) node.variables.forEach(rename);12012if (node instanceof AST_SymbolCatch) rename(node.definition());12013}));1201412015function next_name() {12016var name;12017do {12018name = nth_identifier.get(cname++);12019} while (avoid.has(name) || ALL_RESERVED_WORDS.has(name));12020return name;12021}1202212023function rename(def) {12024if (def.global && options.cache) return;12025if (def.unmangleable(options)) return;12026if (options.reserved.has(def.name)) return;12027const redefinition = redefined_catch_def(def);12028const name = def.name = redefinition ? redefinition.name : next_name();12029def.orig.forEach(function(sym) {12030sym.name = name;12031});12032def.references.forEach(function(sym) {12033sym.name = name;12034});12035}12036});1203712038AST_Node.DEFMETHOD("tail_node", return_this);12039AST_Sequence.DEFMETHOD("tail_node", function() {12040return this.expressions[this.expressions.length - 1];12041});1204212043AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {12044options = format_mangler_options(options);12045var nth_identifier = options.nth_identifier;12046if (!nth_identifier.reset || !nth_identifier.consider || !nth_identifier.sort) {12047// If the identifier mangler is invariant, skip computing character frequency.12048return;12049}12050nth_identifier.reset();1205112052try {12053AST_Node.prototype.print = function(stream, force_parens) {12054this._print(stream, force_parens);12055if (this instanceof AST_Symbol && !this.unmangleable(options)) {12056nth_identifier.consider(this.name, -1);12057} else if (options.properties) {12058if (this instanceof AST_DotHash) {12059nth_identifier.consider("#" + this.property, -1);12060} else if (this instanceof AST_Dot) {12061nth_identifier.consider(this.property, -1);12062} else if (this instanceof AST_Sub) {12063skip_string(this.property);12064}12065}12066};12067nth_identifier.consider(this.print_to_string(), 1);12068} finally {12069AST_Node.prototype.print = AST_Node.prototype._print;12070}12071nth_identifier.sort();1207212073function skip_string(node) {12074if (node instanceof AST_String) {12075nth_identifier.consider(node.value, -1);12076} else if (node instanceof AST_Conditional) {12077skip_string(node.consequent);12078skip_string(node.alternative);12079} else if (node instanceof AST_Sequence) {12080skip_string(node.tail_node());12081}12082}12083});1208412085const base54 = (() => {12086const leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split("");12087const digits = "0123456789".split("");12088let chars;12089let frequency;12090function reset() {12091frequency = new Map();12092leading.forEach(function(ch) {12093frequency.set(ch, 0);12094});12095digits.forEach(function(ch) {12096frequency.set(ch, 0);12097});12098}12099function consider(str, delta) {12100for (var i = str.length; --i >= 0;) {12101frequency.set(str[i], frequency.get(str[i]) + delta);12102}12103}12104function compare(a, b) {12105return frequency.get(b) - frequency.get(a);12106}12107function sort() {12108chars = mergeSort(leading, compare).concat(mergeSort(digits, compare));12109}12110// Ensure this is in a usable initial state.12111reset();12112sort();12113function base54(num) {12114var ret = "", base = 54;12115num++;12116do {12117num--;12118ret += chars[num % base];12119num = Math.floor(num / base);12120base = 64;12121} while (num > 0);12122return ret;12123}1212412125return {12126get: base54,12127consider,12128reset,12129sort12130};12131})();1213212133exports.AST_Node = AST_Node;12134exports.AST_Token = AST_Token;1213512136})));121371213812139