You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21955 lines
780 KiB

4 years ago
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('source-map')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'source-map'], factory) :
  4. (global = global || self, factory(global.Terser = {}, global.sourceMap));
  5. }(this, function (exports, MOZ_SourceMap) { 'use strict';
  6. MOZ_SourceMap = MOZ_SourceMap && MOZ_SourceMap.hasOwnProperty('default') ? MOZ_SourceMap['default'] : MOZ_SourceMap;
  7. /***********************************************************************
  8. A JavaScript tokenizer / parser / beautifier / compressor.
  9. https://github.com/mishoo/UglifyJS2
  10. -------------------------------- (C) ---------------------------------
  11. Author: Mihai Bazon
  12. <mihai.bazon@gmail.com>
  13. http://mihai.bazon.net/blog
  14. Distributed under the BSD license:
  15. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  16. Redistribution and use in source and binary forms, with or without
  17. modification, are permitted provided that the following conditions
  18. are met:
  19. * Redistributions of source code must retain the above
  20. copyright notice, this list of conditions and the following
  21. disclaimer.
  22. * Redistributions in binary form must reproduce the above
  23. copyright notice, this list of conditions and the following
  24. disclaimer in the documentation and/or other materials
  25. provided with the distribution.
  26. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  27. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  30. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  31. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  32. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  35. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  36. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  37. SUCH DAMAGE.
  38. ***********************************************************************/
  39. function characters(str) {
  40. return str.split("");
  41. }
  42. function member(name, array) {
  43. return array.includes(name);
  44. }
  45. function find_if(func, array) {
  46. for (var i = 0, n = array.length; i < n; ++i) {
  47. if (func(array[i]))
  48. return array[i];
  49. }
  50. }
  51. function repeat_string(str, i) {
  52. if (i <= 0) return "";
  53. if (i == 1) return str;
  54. var d = repeat_string(str, i >> 1);
  55. d += d;
  56. if (i & 1) d += str;
  57. return d;
  58. }
  59. function configure_error_stack(fn) {
  60. Object.defineProperty(fn.prototype, "stack", {
  61. get: function() {
  62. var err = new Error(this.message);
  63. err.name = this.name;
  64. try {
  65. throw err;
  66. } catch(e) {
  67. return e.stack;
  68. }
  69. }
  70. });
  71. }
  72. function DefaultsError(msg, defs) {
  73. this.message = msg;
  74. this.defs = defs;
  75. }
  76. DefaultsError.prototype = Object.create(Error.prototype);
  77. DefaultsError.prototype.constructor = DefaultsError;
  78. DefaultsError.prototype.name = "DefaultsError";
  79. configure_error_stack(DefaultsError);
  80. DefaultsError.croak = function(msg, defs) {
  81. throw new DefaultsError(msg, defs);
  82. };
  83. function defaults(args, defs, croak) {
  84. if (args === true)
  85. args = {};
  86. var ret = args || {};
  87. if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i))
  88. DefaultsError.croak("`" + i + "` is not a supported option", defs);
  89. for (var i in defs) if (HOP(defs, i)) {
  90. ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
  91. }
  92. return ret;
  93. }
  94. function merge(obj, ext) {
  95. var count = 0;
  96. for (var i in ext) if (HOP(ext, i)) {
  97. obj[i] = ext[i];
  98. count++;
  99. }
  100. return count;
  101. }
  102. function noop() {}
  103. function return_false() { return false; }
  104. function return_true() { return true; }
  105. function return_this() { return this; }
  106. function return_null() { return null; }
  107. var MAP = (function() {
  108. function MAP(a, f, backwards) {
  109. var ret = [], top = [], i;
  110. function doit() {
  111. var val = f(a[i], i);
  112. var is_last = val instanceof Last;
  113. if (is_last) val = val.v;
  114. if (val instanceof AtTop) {
  115. val = val.v;
  116. if (val instanceof Splice) {
  117. top.push.apply(top, backwards ? val.v.slice().reverse() : val.v);
  118. } else {
  119. top.push(val);
  120. }
  121. } else if (val !== skip) {
  122. if (val instanceof Splice) {
  123. ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
  124. } else {
  125. ret.push(val);
  126. }
  127. }
  128. return is_last;
  129. }
  130. if (a instanceof Array) {
  131. if (backwards) {
  132. for (i = a.length; --i >= 0;) if (doit()) break;
  133. ret.reverse();
  134. top.reverse();
  135. } else {
  136. for (i = 0; i < a.length; ++i) if (doit()) break;
  137. }
  138. } else {
  139. for (i in a) if (HOP(a, i)) if (doit()) break;
  140. }
  141. return top.concat(ret);
  142. }
  143. MAP.at_top = function(val) { return new AtTop(val); };
  144. MAP.splice = function(val) { return new Splice(val); };
  145. MAP.last = function(val) { return new Last(val); };
  146. var skip = MAP.skip = {};
  147. function AtTop(val) { this.v = val; }
  148. function Splice(val) { this.v = val; }
  149. function Last(val) { this.v = val; }
  150. return MAP;
  151. })();
  152. function push_uniq(array, el) {
  153. if (!array.includes(el))
  154. array.push(el);
  155. }
  156. function string_template(text, props) {
  157. return text.replace(/{(.+?)}/g, function(str, p) {
  158. return props && props[p];
  159. });
  160. }
  161. function remove(array, el) {
  162. for (var i = array.length; --i >= 0;) {
  163. if (array[i] === el) array.splice(i, 1);
  164. }
  165. }
  166. function mergeSort(array, cmp) {
  167. if (array.length < 2) return array.slice();
  168. function merge(a, b) {
  169. var r = [], ai = 0, bi = 0, i = 0;
  170. while (ai < a.length && bi < b.length) {
  171. cmp(a[ai], b[bi]) <= 0
  172. ? r[i++] = a[ai++]
  173. : r[i++] = b[bi++];
  174. }
  175. if (ai < a.length) r.push.apply(r, a.slice(ai));
  176. if (bi < b.length) r.push.apply(r, b.slice(bi));
  177. return r;
  178. }
  179. function _ms(a) {
  180. if (a.length <= 1)
  181. return a;
  182. var m = Math.floor(a.length / 2), left = a.slice(0, m), right = a.slice(m);
  183. left = _ms(left);
  184. right = _ms(right);
  185. return merge(left, right);
  186. }
  187. return _ms(array);
  188. }
  189. // this function is taken from Acorn [1], written by Marijn Haverbeke
  190. // [1] https://github.com/marijnh/acorn
  191. function makePredicate(words) {
  192. if (!(words instanceof Array)) words = words.split(" ");
  193. var f = "", cats = [];
  194. out: for (var i = 0; i < words.length; ++i) {
  195. for (var j = 0; j < cats.length; ++j)
  196. if (cats[j][0].length == words[i].length) {
  197. cats[j].push(words[i]);
  198. continue out;
  199. }
  200. cats.push([words[i]]);
  201. }
  202. function quote(word) {
  203. return JSON.stringify(word).replace(/[\u2028\u2029]/g, function(s) {
  204. switch (s) {
  205. case "\u2028": return "\\u2028";
  206. case "\u2029": return "\\u2029";
  207. }
  208. return s;
  209. });
  210. }
  211. function compareTo(arr) {
  212. if (arr.length == 1) return f += "return str === " + quote(arr[0]) + ";";
  213. f += "switch(str){";
  214. for (var i = 0; i < arr.length; ++i) f += "case " + quote(arr[i]) + ":";
  215. f += "return true}return false;";
  216. }
  217. // When there are more than three length categories, an outer
  218. // switch first dispatches on the lengths, to save on comparisons.
  219. if (cats.length > 3) {
  220. cats.sort(function(a, b) {return b.length - a.length;});
  221. f += "switch(str.length){";
  222. for (var i = 0; i < cats.length; ++i) {
  223. var cat = cats[i];
  224. f += "case " + cat[0].length + ":";
  225. compareTo(cat);
  226. }
  227. f += "}";
  228. // Otherwise, simply generate a flat `switch` statement.
  229. } else {
  230. compareTo(words);
  231. }
  232. return new Function("str", f);
  233. }
  234. function all(array, predicate) {
  235. for (var i = array.length; --i >= 0;)
  236. if (!predicate(array[i]))
  237. return false;
  238. return true;
  239. }
  240. function Dictionary() {
  241. this._values = Object.create(null);
  242. this._size = 0;
  243. }
  244. Dictionary.prototype = {
  245. set: function(key, val) {
  246. if (!this.has(key)) ++this._size;
  247. this._values["$" + key] = val;
  248. return this;
  249. },
  250. add: function(key, val) {
  251. if (this.has(key)) {
  252. this.get(key).push(val);
  253. } else {
  254. this.set(key, [ val ]);
  255. }
  256. return this;
  257. },
  258. get: function(key) { return this._values["$" + key]; },
  259. del: function(key) {
  260. if (this.has(key)) {
  261. --this._size;
  262. delete this._values["$" + key];
  263. }
  264. return this;
  265. },
  266. has: function(key) { return ("$" + key) in this._values; },
  267. each: function(f) {
  268. for (var i in this._values)
  269. f(this._values[i], i.substr(1));
  270. },
  271. size: function() {
  272. return this._size;
  273. },
  274. map: function(f) {
  275. var ret = [];
  276. for (var i in this._values)
  277. ret.push(f(this._values[i], i.substr(1)));
  278. return ret;
  279. },
  280. clone: function() {
  281. var ret = new Dictionary();
  282. for (var i in this._values)
  283. ret._values[i] = this._values[i];
  284. ret._size = this._size;
  285. return ret;
  286. },
  287. toObject: function() { return this._values; }
  288. };
  289. Dictionary.fromObject = function(obj) {
  290. var dict = new Dictionary();
  291. dict._size = merge(dict._values, obj);
  292. return dict;
  293. };
  294. function HOP(obj, prop) {
  295. return Object.prototype.hasOwnProperty.call(obj, prop);
  296. }
  297. // return true if the node at the top of the stack (that means the
  298. // innermost node in the current output) is lexically the first in
  299. // a statement.
  300. function first_in_statement(stack) {
  301. var node = stack.parent(-1);
  302. for (var i = 0, p; p = stack.parent(i); i++) {
  303. if (p instanceof AST_Statement && p.body === node)
  304. return true;
  305. if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
  306. (p.TYPE == "Call" && p.expression === node ) ||
  307. (p instanceof AST_Dot && p.expression === node ) ||
  308. (p instanceof AST_Sub && p.expression === node ) ||
  309. (p instanceof AST_Conditional && p.condition === node ) ||
  310. (p instanceof AST_Binary && p.left === node ) ||
  311. (p instanceof AST_UnaryPostfix && p.expression === node )
  312. ) {
  313. node = p;
  314. } else {
  315. return false;
  316. }
  317. }
  318. }
  319. function keep_name(keep_setting, name) {
  320. return keep_setting === true
  321. || (keep_setting instanceof RegExp && keep_setting.test(name));
  322. }
  323. /***********************************************************************
  324. A JavaScript tokenizer / parser / beautifier / compressor.
  325. https://github.com/mishoo/UglifyJS2
  326. -------------------------------- (C) ---------------------------------
  327. Author: Mihai Bazon
  328. <mihai.bazon@gmail.com>
  329. http://mihai.bazon.net/blog
  330. Distributed under the BSD license:
  331. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  332. Parser based on parse-js (http://marijn.haverbeke.nl/parse-js/).
  333. Redistribution and use in source and binary forms, with or without
  334. modification, are permitted provided that the following conditions
  335. are met:
  336. * Redistributions of source code must retain the above
  337. copyright notice, this list of conditions and the following
  338. disclaimer.
  339. * Redistributions in binary form must reproduce the above
  340. copyright notice, this list of conditions and the following
  341. disclaimer in the documentation and/or other materials
  342. provided with the distribution.
  343. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  344. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  345. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  346. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  347. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  348. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  349. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  350. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  351. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  352. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  353. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  354. SUCH DAMAGE.
  355. ***********************************************************************/
  356. var 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";
  357. var KEYWORDS_ATOM = "false null true";
  358. var RESERVED_WORDS = "enum implements import interface package private protected public static super this " + KEYWORDS_ATOM + " " + KEYWORDS;
  359. var KEYWORDS_BEFORE_EXPRESSION = "return new delete throw else case yield await";
  360. KEYWORDS = makePredicate(KEYWORDS);
  361. RESERVED_WORDS = makePredicate(RESERVED_WORDS);
  362. KEYWORDS_BEFORE_EXPRESSION = makePredicate(KEYWORDS_BEFORE_EXPRESSION);
  363. KEYWORDS_ATOM = makePredicate(KEYWORDS_ATOM);
  364. var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
  365. var RE_NUM_LITERAL = /[0-9a-f]/i;
  366. var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
  367. var RE_OCT_NUMBER = /^0[0-7]+$/;
  368. var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
  369. var RE_BIN_NUMBER = /^0b[01]+$/i;
  370. var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;
  371. var OPERATORS = makePredicate([
  372. "in",
  373. "instanceof",
  374. "typeof",
  375. "new",
  376. "void",
  377. "delete",
  378. "++",
  379. "--",
  380. "+",
  381. "-",
  382. "!",
  383. "~",
  384. "&",
  385. "|",
  386. "^",
  387. "*",
  388. "**",
  389. "/",
  390. "%",
  391. ">>",
  392. "<<",
  393. ">>>",
  394. "<",
  395. ">",
  396. "<=",
  397. ">=",
  398. "==",
  399. "===",
  400. "!=",
  401. "!==",
  402. "?",
  403. "=",
  404. "+=",
  405. "-=",
  406. "/=",
  407. "*=",
  408. "**=",
  409. "%=",
  410. ">>=",
  411. "<<=",
  412. ">>>=",
  413. "|=",
  414. "^=",
  415. "&=",
  416. "&&",
  417. "||"
  418. ]);
  419. var 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"));
  420. var NEWLINE_CHARS = makePredicate(characters("\n\r\u2028\u2029"));
  421. var PUNC_AFTER_EXPRESSION = makePredicate(characters(";]),:"));
  422. var PUNC_BEFORE_EXPRESSION = makePredicate(characters("[{(,;:"));
  423. var PUNC_CHARS = makePredicate(characters("[]{}(),;:"));
  424. /* -----[ Tokenizer ]----- */
  425. // surrogate safe regexps adapted from https://github.com/mathiasbynens/unicode-8.0.0/tree/89b412d8a71ecca9ed593d9e9fa073ab64acfebe/Binary_Property
  426. var UNICODE = {
  427. ID_Start: /[A-Za-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-\uF
  428. ID_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\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\
  429. };
  430. function get_full_char(str, pos) {
  431. var char = str.charAt(pos);
  432. if (is_surrogate_pair_head(char)) {
  433. var next = str.charAt(pos + 1);
  434. if (is_surrogate_pair_tail(next)) {
  435. return char + next;
  436. }
  437. }
  438. if (is_surrogate_pair_tail(char)) {
  439. var prev = str.charAt(pos - 1);
  440. if (is_surrogate_pair_head(prev)) {
  441. return prev + char;
  442. }
  443. }
  444. return char;
  445. }
  446. function get_full_char_code(str, pos) {
  447. // https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates
  448. if (is_surrogate_pair_head(str.charAt(pos))) {
  449. return 0x10000 + (str.charCodeAt(pos) - 0xd800 << 10) + str.charCodeAt(pos + 1) - 0xdc00;
  450. }
  451. return str.charCodeAt(pos);
  452. }
  453. function get_full_char_length(str) {
  454. var surrogates = 0;
  455. for (var i = 0; i < str.length; i++) {
  456. if (is_surrogate_pair_head(str.charCodeAt(i))) {
  457. if (is_surrogate_pair_tail(str.charCodeAt(i + 1))) {
  458. surrogates++;
  459. i++;
  460. }
  461. }
  462. }
  463. return str.length - surrogates;
  464. }
  465. function from_char_code(code) {
  466. // Based on https://github.com/mathiasbynens/String.fromCodePoint/blob/master/fromcodepoint.js
  467. if (code > 0xFFFF) {
  468. code -= 0x10000;
  469. return (String.fromCharCode((code >> 10) + 0xD800) +
  470. String.fromCharCode((code % 0x400) + 0xDC00));
  471. }
  472. return String.fromCharCode(code);
  473. }
  474. function is_surrogate_pair_head(code) {
  475. if (typeof code === "string")
  476. code = code.charCodeAt(0);
  477. return code >= 0xd800 && code <= 0xdbff;
  478. }
  479. function is_surrogate_pair_tail(code) {
  480. if (typeof code === "string")
  481. code = code.charCodeAt(0);
  482. return code >= 0xdc00 && code <= 0xdfff;
  483. }
  484. function is_digit(code) {
  485. return code >= 48 && code <= 57;
  486. }
  487. function is_identifier(name) {
  488. return typeof name === "string" && !RESERVED_WORDS(name);
  489. }
  490. function is_identifier_start(ch) {
  491. var code = ch.charCodeAt(0);
  492. return UNICODE.ID_Start.test(ch) || code == 36 || code == 95;
  493. }
  494. function is_identifier_char(ch) {
  495. var code = ch.charCodeAt(0);
  496. return UNICODE.ID_Continue.test(ch)
  497. || code == 36
  498. || code == 95
  499. || code == 8204 // \u200c: zero-width non-joiner <ZWNJ>
  500. || code == 8205 // \u200d: zero-width joiner <ZWJ> (in my ECMA-262 PDF, this is also 200c)
  501. ;
  502. }
  503. function is_identifier_string(str) {
  504. return /^[a-z_$][a-z0-9_$]*$/i.test(str);
  505. }
  506. function parse_js_number(num) {
  507. if (RE_HEX_NUMBER.test(num)) {
  508. return parseInt(num.substr(2), 16);
  509. } else if (RE_OCT_NUMBER.test(num)) {
  510. return parseInt(num.substr(1), 8);
  511. } else if (RE_ES6_OCT_NUMBER.test(num)) {
  512. return parseInt(num.substr(2), 8);
  513. } else if (RE_BIN_NUMBER.test(num)) {
  514. return parseInt(num.substr(2), 2);
  515. } else if (RE_DEC_NUMBER.test(num)) {
  516. return parseFloat(num);
  517. } else {
  518. var val = parseFloat(num);
  519. if (val == num) return val;
  520. }
  521. }
  522. function JS_Parse_Error(message, filename, line, col, pos) {
  523. this.message = message;
  524. this.filename = filename;
  525. this.line = line;
  526. this.col = col;
  527. this.pos = pos;
  528. }
  529. JS_Parse_Error.prototype = Object.create(Error.prototype);
  530. JS_Parse_Error.prototype.constructor = JS_Parse_Error;
  531. JS_Parse_Error.prototype.name = "SyntaxError";
  532. configure_error_stack(JS_Parse_Error);
  533. function js_error(message, filename, line, col, pos) {
  534. throw new JS_Parse_Error(message, filename, line, col, pos);
  535. }
  536. function is_token(token, type, val) {
  537. return token.type == type && (val == null || token.value == val);
  538. }
  539. var EX_EOF = {};
  540. function tokenizer($TEXT, filename, html5_comments, shebang) {
  541. var S = {
  542. text : $TEXT,
  543. filename : filename,
  544. pos : 0,
  545. tokpos : 0,
  546. line : 1,
  547. tokline : 0,
  548. col : 0,
  549. tokcol : 0,
  550. newline_before : false,
  551. regex_allowed : false,
  552. brace_counter : 0,
  553. template_braces : [],
  554. comments_before : [],
  555. directives : {},
  556. directive_stack : []
  557. };
  558. function peek() { return get_full_char(S.text, S.pos); }
  559. function next(signal_eof, in_string) {
  560. var ch = get_full_char(S.text, S.pos++);
  561. if (signal_eof && !ch)
  562. throw EX_EOF;
  563. if (NEWLINE_CHARS(ch)) {
  564. S.newline_before = S.newline_before || !in_string;
  565. ++S.line;
  566. S.col = 0;
  567. if (!in_string && ch == "\r" && peek() == "\n") {
  568. // treat a \r\n sequence as a single \n
  569. ++S.pos;
  570. ch = "\n";
  571. }
  572. } else {
  573. if (ch.length > 1) {
  574. ++S.pos;
  575. ++S.col;
  576. }
  577. ++S.col;
  578. }
  579. return ch;
  580. }
  581. function forward(i) {
  582. while (i-- > 0) next();
  583. }
  584. function looking_at(str) {
  585. return S.text.substr(S.pos, str.length) == str;
  586. }
  587. function find_eol() {
  588. var text = S.text;
  589. for (var i = S.pos, n = S.text.length; i < n; ++i) {
  590. var ch = text[i];
  591. if (NEWLINE_CHARS(ch))
  592. return i;
  593. }
  594. return -1;
  595. }
  596. function find(what, signal_eof) {
  597. var pos = S.text.indexOf(what, S.pos);
  598. if (signal_eof && pos == -1) throw EX_EOF;
  599. return pos;
  600. }
  601. function start_token() {
  602. S.tokline = S.line;
  603. S.tokcol = S.col;
  604. S.tokpos = S.pos;
  605. }
  606. var prev_was_dot = false;
  607. var previous_token = null;
  608. function token(type, value, is_comment) {
  609. S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX(value)) ||
  610. (type == "keyword" && KEYWORDS_BEFORE_EXPRESSION(value)) ||
  611. (type == "punc" && PUNC_BEFORE_EXPRESSION(value))) ||
  612. (type == "arrow");
  613. if (type == "punc" && value == ".") {
  614. prev_was_dot = true;
  615. } else if (!is_comment) {
  616. prev_was_dot = false;
  617. }
  618. var ret = {
  619. type : type,
  620. value : value,
  621. line : S.tokline,
  622. col : S.tokcol,
  623. pos : S.tokpos,
  624. endline : S.line,
  625. endcol : S.col,
  626. endpos : S.pos,
  627. nlb : S.newline_before,
  628. file : filename
  629. };
  630. if (/^(?:num|string|regexp)$/i.test(type)) {
  631. ret.raw = $TEXT.substring(ret.pos, ret.endpos);
  632. }
  633. if (!is_comment) {
  634. ret.comments_before = S.comments_before;
  635. ret.comments_after = S.comments_before = [];
  636. }
  637. S.newline_before = false;
  638. ret = new AST_Token(ret);
  639. if (!is_comment) previous_token = ret;
  640. return ret;
  641. }
  642. function skip_whitespace() {
  643. while (WHITESPACE_CHARS(peek()))
  644. next();
  645. }
  646. function read_while(pred) {
  647. var ret = "", ch, i = 0;
  648. while ((ch = peek()) && pred(ch, i++))
  649. ret += next();
  650. return ret;
  651. }
  652. function parse_error(err) {
  653. js_error(err, filename, S.tokline, S.tokcol, S.tokpos);
  654. }
  655. function read_num(prefix) {
  656. var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".";
  657. var num = read_while(function(ch, i) {
  658. var code = ch.charCodeAt(0);
  659. switch (code) {
  660. case 98: case 66: // bB
  661. return (has_x = true); // Can occur in hex sequence, don't return false yet
  662. case 111: case 79: // oO
  663. case 120: case 88: // xX
  664. return has_x ? false : (has_x = true);
  665. case 101: case 69: // eE
  666. return has_x ? true : has_e ? false : (has_e = after_e = true);
  667. case 45: // -
  668. return after_e || (i == 0 && !prefix);
  669. case 43: // +
  670. return after_e;
  671. case (after_e = false, 46): // .
  672. return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
  673. }
  674. return RE_NUM_LITERAL.test(ch);
  675. });
  676. if (prefix) num = prefix + num;
  677. if (RE_OCT_NUMBER.test(num) && next_token.has_directive("use strict")) {
  678. parse_error("Legacy octal literals are not allowed in strict mode");
  679. }
  680. var valid = parse_js_number(num);
  681. if (!isNaN(valid)) {
  682. return token("num", valid);
  683. } else {
  684. parse_error("Invalid syntax: " + num);
  685. }
  686. }
  687. function read_escaped_char(in_string, strict_hex, template_string) {
  688. var ch = next(true, in_string);
  689. switch (ch.charCodeAt(0)) {
  690. case 110 : return "\n";
  691. case 114 : return "\r";
  692. case 116 : return "\t";
  693. case 98 : return "\b";
  694. case 118 : return "\u000b"; // \v
  695. case 102 : return "\f";
  696. case 120 : return String.fromCharCode(hex_bytes(2, strict_hex)); // \x
  697. case 117 : // \u
  698. if (peek() == "{") {
  699. next(true);
  700. if (peek() === "}")
  701. parse_error("Expecting hex-character between {}");
  702. while (peek() == "0") next(true); // No significance
  703. var result, length = find("}", true) - S.pos;
  704. // Avoid 32 bit integer overflow (1 << 32 === 1)
  705. // We know first character isn't 0 and thus out of range anyway
  706. if (length > 6 || (result = hex_bytes(length, strict_hex)) > 0x10FFFF) {
  707. parse_error("Unicode reference out of bounds");
  708. }
  709. next(true);
  710. return from_char_code(result);
  711. }
  712. return String.fromCharCode(hex_bytes(4, strict_hex));
  713. case 10 : return ""; // newline
  714. case 13 : // \r
  715. if (peek() == "\n") { // DOS newline
  716. next(true, in_string);
  717. return "";
  718. }
  719. }
  720. if (ch >= "0" && ch <= "7") {
  721. if (template_string && strict_hex) {
  722. parse_error("Octal escape sequences are not allowed in template strings");
  723. }
  724. return read_octal_escape_sequence(ch, strict_hex);
  725. }
  726. return ch;
  727. }
  728. function read_octal_escape_sequence(ch, strict_octal) {
  729. // Read
  730. var p = peek();
  731. if (p >= "0" && p <= "7") {
  732. ch += next(true);
  733. if (ch[0] <= "3" && (p = peek()) >= "0" && p <= "7")
  734. ch += next(true);
  735. }
  736. // Parse
  737. if (ch === "0") return "\0";
  738. if (ch.length > 0 && next_token.has_directive("use strict") && strict_octal)
  739. parse_error("Legacy octal escape sequences are not allowed in strict mode");
  740. return String.fromCharCode(parseInt(ch, 8));
  741. }
  742. function hex_bytes(n, strict_hex) {
  743. var num = 0;
  744. for (; n > 0; --n) {
  745. if (!strict_hex && isNaN(parseInt(peek(), 16))) {
  746. return parseInt(num, 16) || "";
  747. }
  748. var digit = next(true);
  749. if (isNaN(parseInt(digit, 16)))
  750. parse_error("Invalid hex-character pattern in string");
  751. num += digit;
  752. }
  753. return parseInt(num, 16);
  754. }
  755. var read_string = with_eof_error("Unterminated string constant", function(quote_char) {
  756. var quote = next(), ret = "";
  757. for (;;) {
  758. var ch = next(true, true);
  759. if (ch == "\\") ch = read_escaped_char(true, true);
  760. else if (NEWLINE_CHARS(ch)) parse_error("Unterminated string constant");
  761. else if (ch == quote) break;
  762. ret += ch;
  763. }
  764. var tok = token("string", ret);
  765. tok.quote = quote_char;
  766. return tok;
  767. });
  768. var read_template_characters = with_eof_error("Unterminated template", function(begin) {
  769. if (begin) {
  770. S.template_braces.push(S.brace_counter);
  771. }
  772. var content = "", raw = "", ch, tok;
  773. next(true, true);
  774. while ((ch = next(true, true)) != "`") {
  775. if (ch == "\r") {
  776. if (peek() == "\n") ++S.pos;
  777. ch = "\n";
  778. } else if (ch == "$" && peek() == "{") {
  779. next(true, true);
  780. S.brace_counter++;
  781. tok = token(begin ? "template_head" : "template_substitution", content);
  782. tok.begin = begin;
  783. tok.raw = raw;
  784. tok.end = false;
  785. return tok;
  786. }
  787. raw += ch;
  788. if (ch == "\\") {
  789. var tmp = S.pos;
  790. var prev_is_tag = previous_token && (previous_token.type === "name" || previous_token.type === "punc" && (previous_token.value === ")" || previous_token.value === "]"));
  791. ch = read_escaped_char(true, !prev_is_tag, true);
  792. raw += S.text.substr(tmp, S.pos - tmp);
  793. }
  794. content += ch;
  795. }
  796. S.template_braces.pop();
  797. tok = token(begin ? "template_head" : "template_substitution", content);
  798. tok.begin = begin;
  799. tok.raw = raw;
  800. tok.end = true;
  801. return tok;
  802. });
  803. function skip_line_comment(type) {
  804. var regex_allowed = S.regex_allowed;
  805. var i = find_eol(), ret;
  806. if (i == -1) {
  807. ret = S.text.substr(S.pos);
  808. S.pos = S.text.length;
  809. } else {
  810. ret = S.text.substring(S.pos, i);
  811. S.pos = i;
  812. }
  813. S.col = S.tokcol + (S.pos - S.tokpos);
  814. S.comments_before.push(token(type, ret, true));
  815. S.regex_allowed = regex_allowed;
  816. return next_token;
  817. }
  818. var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function() {
  819. var regex_allowed = S.regex_allowed;
  820. var i = find("*/", true);
  821. var text = S.text.substring(S.pos, i).replace(/\r\n|\r|\u2028|\u2029/g, "\n");
  822. // update stream position
  823. forward(get_full_char_length(text) /* text length doesn't count \r\n as 2 char while S.pos - i does */ + 2);
  824. S.comments_before.push(token("comment2", text, true));
  825. S.newline_before = S.newline_before || text.includes("\n");
  826. S.regex_allowed = regex_allowed;
  827. return next_token;
  828. });
  829. var read_name = with_eof_error("Unterminated identifier name", function() {
  830. var name = "", ch, escaped = false;
  831. var read_escaped_identifier_char = function() {
  832. escaped = true;
  833. next();
  834. if (peek() !== "u") {
  835. parse_error("Expecting UnicodeEscapeSequence -- uXXXX or u{XXXX}");
  836. }
  837. return read_escaped_char(false, true);
  838. };
  839. // Read first character (ID_Start)
  840. if ((name = peek()) === "\\") {
  841. name = read_escaped_identifier_char();
  842. if (!is_identifier_start(name)) {
  843. parse_error("First identifier char is an invalid identifier char");
  844. }
  845. } else if (is_identifier_start(name)) {
  846. next();
  847. } else {
  848. return "";
  849. }
  850. // Read ID_Continue
  851. while ((ch = peek()) != null) {
  852. if ((ch = peek()) === "\\") {
  853. ch = read_escaped_identifier_char();
  854. if (!is_identifier_char(ch)) {
  855. parse_error("Invalid escaped identifier char");
  856. }
  857. } else {
  858. if (!is_identifier_char(ch)) {
  859. break;
  860. }
  861. next();
  862. }
  863. name += ch;
  864. }
  865. if (RESERVED_WORDS(name) && escaped) {
  866. parse_error("Escaped characters are not allowed in keywords");
  867. }
  868. return name;
  869. });
  870. var read_regexp = with_eof_error("Unterminated regular expression", function(source) {
  871. var prev_backslash = false, ch, in_class = false;
  872. while ((ch = next(true))) if (NEWLINE_CHARS(ch)) {
  873. parse_error("Unexpected line terminator");
  874. } else if (prev_backslash) {
  875. source += "\\" + ch;
  876. prev_backslash = false;
  877. } else if (ch == "[") {
  878. in_class = true;
  879. source += ch;
  880. } else if (ch == "]" && in_class) {
  881. in_class = false;
  882. source += ch;
  883. } else if (ch == "/" && !in_class) {
  884. break;
  885. } else if (ch == "\\") {
  886. prev_backslash = true;
  887. } else {
  888. source += ch;
  889. }
  890. var mods = read_name();
  891. try {
  892. var regexp = new RegExp(source, mods);
  893. regexp.raw_source = "/" + source + "/" + mods;
  894. return token("regexp", regexp);
  895. } catch(e) {
  896. parse_error(e.message);
  897. }
  898. });
  899. function read_operator(prefix) {
  900. function grow(op) {
  901. if (!peek()) return op;
  902. var bigger = op + peek();
  903. if (OPERATORS(bigger)) {
  904. next();
  905. return grow(bigger);
  906. } else {
  907. return op;
  908. }
  909. }
  910. return token("operator", grow(prefix || next()));
  911. }
  912. function handle_slash() {
  913. next();
  914. switch (peek()) {
  915. case "/":
  916. next();
  917. return skip_line_comment("comment1");
  918. case "*":
  919. next();
  920. return skip_multiline_comment();
  921. }
  922. return S.regex_allowed ? read_regexp("") : read_operator("/");
  923. }
  924. function handle_eq_sign() {
  925. next();
  926. if (peek() === ">") {
  927. next();
  928. return token("arrow", "=>");
  929. } else {
  930. return read_operator("=");
  931. }
  932. }
  933. function handle_dot() {
  934. next();
  935. if (is_digit(peek().charCodeAt(0))) {
  936. return read_num(".");
  937. }
  938. if (peek() === ".") {
  939. next(); // Consume second dot
  940. next(); // Consume third dot
  941. return token("expand", "...");
  942. }
  943. return token("punc", ".");
  944. }
  945. function read_word() {
  946. var word = read_name();
  947. if (prev_was_dot) return token("name", word);
  948. return KEYWORDS_ATOM(word) ? token("atom", word)
  949. : !KEYWORDS(word) ? token("name", word)
  950. : OPERATORS(word) ? token("operator", word)
  951. : token("keyword", word);
  952. }
  953. function with_eof_error(eof_error, cont) {
  954. return function(x) {
  955. try {
  956. return cont(x);
  957. } catch(ex) {
  958. if (ex === EX_EOF) parse_error(eof_error);
  959. else throw ex;
  960. }
  961. };
  962. }
  963. function next_token(force_regexp) {
  964. if (force_regexp != null)
  965. return read_regexp(force_regexp);
  966. if (shebang && S.pos == 0 && looking_at("#!")) {
  967. start_token();
  968. forward(2);
  969. skip_line_comment("comment5");
  970. }
  971. for (;;) {
  972. skip_whitespace();
  973. start_token();
  974. if (html5_comments) {
  975. if (looking_at("<!--")) {
  976. forward(4);
  977. skip_line_comment("comment3");
  978. continue;
  979. }
  980. if (looking_at("-->") && S.newline_before) {
  981. forward(3);
  982. skip_line_comment("comment4");
  983. continue;
  984. }
  985. }
  986. var ch = peek();
  987. if (!ch) return token("eof");
  988. var code = ch.charCodeAt(0);
  989. switch (code) {
  990. case 34: case 39: return read_string(ch);
  991. case 46: return handle_dot();
  992. case 47: {
  993. var tok = handle_slash();
  994. if (tok === next_token) continue;
  995. return tok;
  996. }
  997. case 61: return handle_eq_sign();
  998. case 96: return read_template_characters(true);
  999. case 123:
  1000. S.brace_counter++;
  1001. break;
  1002. case 125:
  1003. S.brace_counter--;
  1004. if (S.template_braces.length > 0
  1005. && S.template_braces[S.template_braces.length - 1] === S.brace_counter)
  1006. return read_template_characters(false);
  1007. break;
  1008. }
  1009. if (is_digit(code)) return read_num();
  1010. if (PUNC_CHARS(ch)) return token("punc", next());
  1011. if (OPERATOR_CHARS(ch)) return read_operator();
  1012. if (code == 92 || is_identifier_start(ch)) return read_word();
  1013. break;
  1014. }
  1015. parse_error("Unexpected character '" + ch + "'");
  1016. }
  1017. next_token.next = next;
  1018. next_token.peek = peek;
  1019. next_token.context = function(nc) {
  1020. if (nc) S = nc;
  1021. return S;
  1022. };
  1023. next_token.add_directive = function(directive) {
  1024. S.directive_stack[S.directive_stack.length - 1].push(directive);
  1025. if (S.directives[directive] === undefined) {
  1026. S.directives[directive] = 1;
  1027. } else {
  1028. S.directives[directive]++;
  1029. }
  1030. };
  1031. next_token.push_directives_stack = function() {
  1032. S.directive_stack.push([]);
  1033. };
  1034. next_token.pop_directives_stack = function() {
  1035. var directives = S.directive_stack[S.directive_stack.length - 1];
  1036. for (var i = 0; i < directives.length; i++) {
  1037. S.directives[directives[i]]--;
  1038. }
  1039. S.directive_stack.pop();
  1040. };
  1041. next_token.has_directive = function(directive) {
  1042. return S.directives[directive] > 0;
  1043. };
  1044. return next_token;
  1045. }
  1046. /* -----[ Parser (constants) ]----- */
  1047. var UNARY_PREFIX = makePredicate([
  1048. "typeof",
  1049. "void",
  1050. "delete",
  1051. "--",
  1052. "++",
  1053. "!",
  1054. "~",
  1055. "-",
  1056. "+"
  1057. ]);
  1058. var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
  1059. var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "**=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
  1060. var PRECEDENCE = (function(a, ret) {
  1061. for (var i = 0; i < a.length; ++i) {
  1062. var b = a[i];
  1063. for (var j = 0; j < b.length; ++j) {
  1064. ret[b[j]] = i + 1;
  1065. }
  1066. }
  1067. return ret;
  1068. })(
  1069. [
  1070. ["||"],
  1071. ["&&"],
  1072. ["|"],
  1073. ["^"],
  1074. ["&"],
  1075. ["==", "===", "!=", "!=="],
  1076. ["<", ">", "<=", ">=", "in", "instanceof"],
  1077. [">>", "<<", ">>>"],
  1078. ["+", "-"],
  1079. ["*", "/", "%"],
  1080. ["**"]
  1081. ],
  1082. {}
  1083. );
  1084. var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "string", "regexp", "name" ]);
  1085. /* -----[ Parser ]----- */
  1086. function parse($TEXT, options) {
  1087. options = defaults(options, {
  1088. bare_returns : false,
  1089. ecma : 8,
  1090. expression : false,
  1091. filename : null,
  1092. html5_comments : true,
  1093. module : false,
  1094. shebang : true,
  1095. strict : false,
  1096. toplevel : null,
  1097. }, true);
  1098. var S = {
  1099. input : (typeof $TEXT == "string"
  1100. ? tokenizer($TEXT, options.filename,
  1101. options.html5_comments, options.shebang)
  1102. : $TEXT),
  1103. token : null,
  1104. prev : null,
  1105. peeked : null,
  1106. in_function : 0,
  1107. in_async : -1,
  1108. in_generator : -1,
  1109. in_directives : true,
  1110. in_loop : 0,
  1111. labels : []
  1112. };
  1113. S.token = next();
  1114. function is(type, value) {
  1115. return is_token(S.token, type, value);
  1116. }
  1117. function peek() { return S.peeked || (S.peeked = S.input()); }
  1118. function next() {
  1119. S.prev = S.token;
  1120. if (!S.peeked) peek();
  1121. S.token = S.peeked;
  1122. S.peeked = null;
  1123. S.in_directives = S.in_directives && (
  1124. S.token.type == "string" || is("punc", ";")
  1125. );
  1126. return S.token;
  1127. }
  1128. function prev() {
  1129. return S.prev;
  1130. }
  1131. function croak(msg, line, col, pos) {
  1132. var ctx = S.input.context();
  1133. js_error(msg,
  1134. ctx.filename,
  1135. line != null ? line : ctx.tokline,
  1136. col != null ? col : ctx.tokcol,
  1137. pos != null ? pos : ctx.tokpos);
  1138. }
  1139. function token_error(token, msg) {
  1140. croak(msg, token.line, token.col);
  1141. }
  1142. function unexpected(token) {
  1143. if (token == null)
  1144. token = S.token;
  1145. token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
  1146. }
  1147. function expect_token(type, val) {
  1148. if (is(type, val)) {
  1149. return next();
  1150. }
  1151. token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
  1152. }
  1153. function expect(punc) { return expect_token("punc", punc); }
  1154. function has_newline_before(token) {
  1155. return token.nlb || !all(token.comments_before, function(comment) {
  1156. return !comment.nlb;
  1157. });
  1158. }
  1159. function can_insert_semicolon() {
  1160. return !options.strict
  1161. && (is("eof") || is("punc", "}") || has_newline_before(S.token));
  1162. }
  1163. function is_in_generator() {
  1164. return S.in_generator === S.in_function;
  1165. }
  1166. function is_in_async() {
  1167. return S.in_async === S.in_function;
  1168. }
  1169. function semicolon(optional) {
  1170. if (is("punc", ";")) next();
  1171. else if (!optional && !can_insert_semicolon()) unexpected();
  1172. }
  1173. function parenthesised() {
  1174. expect("(");
  1175. var exp = expression(true);
  1176. expect(")");
  1177. return exp;
  1178. }
  1179. function embed_tokens(parser) {
  1180. return function() {
  1181. var start = S.token;
  1182. var expr = parser.apply(null, arguments);
  1183. var end = prev();
  1184. expr.start = start;
  1185. expr.end = end;
  1186. return expr;
  1187. };
  1188. }
  1189. function handle_regexp() {
  1190. if (is("operator", "/") || is("operator", "/=")) {
  1191. S.peeked = null;
  1192. S.token = S.input(S.token.value.substr(1)); // force regexp
  1193. }
  1194. }
  1195. var statement = embed_tokens(function(is_export_default, is_for_body, is_if_body) {
  1196. handle_regexp();
  1197. switch (S.token.type) {
  1198. case "string":
  1199. if (S.in_directives) {
  1200. var token = peek();
  1201. if (!S.token.raw.includes("\\")
  1202. && (is_token(token, "punc", ";")
  1203. || is_token(token, "punc", "}")
  1204. || has_newline_before(token)
  1205. || is_token(token, "eof"))) {
  1206. S.input.add_directive(S.token.value);
  1207. } else {
  1208. S.in_directives = false;
  1209. }
  1210. }
  1211. var dir = S.in_directives, stat = simple_statement();
  1212. return dir && stat.body instanceof AST_String ? new AST_Directive(stat.body) : stat;
  1213. case "template_head":
  1214. case "num":
  1215. case "regexp":
  1216. case "operator":
  1217. case "atom":
  1218. return simple_statement();
  1219. case "name":
  1220. if (S.token.value == "async" && is_token(peek(), "keyword", "function")) {
  1221. next();
  1222. next();
  1223. if (is_for_body) {
  1224. croak("functions are not allowed as the body of a loop");
  1225. }
  1226. return function_(AST_Defun, false, true, is_export_default);
  1227. }
  1228. if (S.token.value == "import" && !is_token(peek(), "punc", "(")) {
  1229. next();
  1230. var node = import_();
  1231. semicolon();
  1232. return node;
  1233. }
  1234. return is_token(peek(), "punc", ":")
  1235. ? labeled_statement()
  1236. : simple_statement();
  1237. case "punc":
  1238. switch (S.token.value) {
  1239. case "{":
  1240. return new AST_BlockStatement({
  1241. start : S.token,
  1242. body : block_(),
  1243. end : prev()
  1244. });
  1245. case "[":
  1246. case "(":
  1247. return simple_statement();
  1248. case ";":
  1249. S.in_directives = false;
  1250. next();
  1251. return new AST_EmptyStatement();
  1252. default:
  1253. unexpected();
  1254. }
  1255. case "keyword":
  1256. switch (S.token.value) {
  1257. case "break":
  1258. next();
  1259. return break_cont(AST_Break);
  1260. case "continue":
  1261. next();
  1262. return break_cont(AST_Continue);
  1263. case "debugger":
  1264. next();
  1265. semicolon();
  1266. return new AST_Debugger();
  1267. case "do":
  1268. next();
  1269. var body = in_loop(statement);
  1270. expect_token("keyword", "while");
  1271. var condition = parenthesised();
  1272. semicolon(true);
  1273. return new AST_Do({
  1274. body : body,
  1275. condition : condition
  1276. });
  1277. case "while":
  1278. next();
  1279. return new AST_While({
  1280. condition : parenthesised(),
  1281. body : in_loop(function() { return statement(false, true); })
  1282. });
  1283. case "for":
  1284. next();
  1285. return for_();
  1286. case "class":
  1287. next();
  1288. if (is_for_body) {
  1289. croak("classes are not allowed as the body of a loop");
  1290. }
  1291. if (is_if_body) {
  1292. croak("classes are not allowed as the body of an if");
  1293. }
  1294. return class_(AST_DefClass);
  1295. case "function":
  1296. next();
  1297. if (is_for_body) {
  1298. croak("functions are not allowed as the body of a loop");
  1299. }
  1300. return function_(AST_Defun, false, false, is_export_default);
  1301. case "if":
  1302. next();
  1303. return if_();
  1304. case "return":
  1305. if (S.in_function == 0 && !options.bare_returns)
  1306. croak("'return' outside of function");
  1307. next();
  1308. var value = null;
  1309. if (is("punc", ";")) {
  1310. next();
  1311. } else if (!can_insert_semicolon()) {
  1312. value = expression(true);
  1313. semicolon();
  1314. }
  1315. return new AST_Return({
  1316. value: value
  1317. });
  1318. case "switch":
  1319. next();
  1320. return new AST_Switch({
  1321. expression : parenthesised(),
  1322. body : in_loop(switch_body_)
  1323. });
  1324. case "throw":
  1325. next();
  1326. if (has_newline_before(S.token))
  1327. croak("Illegal newline after 'throw'");
  1328. var value = expression(true);
  1329. semicolon();
  1330. return new AST_Throw({
  1331. value: value
  1332. });
  1333. case "try":
  1334. next();
  1335. return try_();
  1336. case "var":
  1337. next();
  1338. var node = var_();
  1339. semicolon();
  1340. return node;
  1341. case "let":
  1342. next();
  1343. var node = let_();
  1344. semicolon();
  1345. return node;
  1346. case "const":
  1347. next();
  1348. var node = const_();
  1349. semicolon();
  1350. return node;
  1351. case "with":
  1352. if (S.input.has_directive("use strict")) {
  1353. croak("Strict mode may not include a with statement");
  1354. }
  1355. next();
  1356. return new AST_With({
  1357. expression : parenthesised(),
  1358. body : statement()
  1359. });
  1360. case "export":
  1361. if (!is_token(peek(), "punc", "(")) {
  1362. next();
  1363. var node = export_();
  1364. if (is("punc", ";")) semicolon();
  1365. return node;
  1366. }
  1367. }
  1368. }
  1369. unexpected();
  1370. });
  1371. function labeled_statement() {
  1372. var label = as_symbol(AST_Label);
  1373. if (label.name === "await" && is_in_async()) {
  1374. token_error(S.prev, "await cannot be used as label inside async function");
  1375. }
  1376. if (find_if(function(l) { return l.name == label.name; }, S.labels)) {
  1377. // ECMA-262, 12.12: An ECMAScript program is considered
  1378. // syntactically incorrect if it contains a
  1379. // LabelledStatement that is enclosed by a
  1380. // LabelledStatement with the same Identifier as label.
  1381. croak("Label " + label.name + " defined twice");
  1382. }
  1383. expect(":");
  1384. S.labels.push(label);
  1385. var stat = statement();
  1386. S.labels.pop();
  1387. if (!(stat instanceof AST_IterationStatement)) {
  1388. // check for `continue` that refers to this label.
  1389. // those should be reported as syntax errors.
  1390. // https://github.com/mishoo/UglifyJS2/issues/287
  1391. label.references.forEach(function(ref) {
  1392. if (ref instanceof AST_Continue) {
  1393. ref = ref.label.start;
  1394. croak("Continue label `" + label.name + "` refers to non-IterationStatement.",
  1395. ref.line, ref.col, ref.pos);
  1396. }
  1397. });
  1398. }
  1399. return new AST_LabeledStatement({ body: stat, label: label });
  1400. }
  1401. function simple_statement(tmp) {
  1402. return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) });
  1403. }
  1404. function break_cont(type) {
  1405. var label = null, ldef;
  1406. if (!can_insert_semicolon()) {
  1407. label = as_symbol(AST_LabelRef, true);
  1408. }
  1409. if (label != null) {
  1410. ldef = find_if(function(l) { return l.name == label.name; }, S.labels);
  1411. if (!ldef)
  1412. croak("Undefined label " + label.name);
  1413. label.thedef = ldef;
  1414. } else if (S.in_loop == 0)
  1415. croak(type.TYPE + " not inside a loop or switch");
  1416. semicolon();
  1417. var stat = new type({ label: label });
  1418. if (ldef) ldef.references.push(stat);
  1419. return stat;
  1420. }
  1421. function for_() {
  1422. var for_await_error = "`for await` invalid in this context";
  1423. var await_tok = S.token;
  1424. if (await_tok.type == "name" && await_tok.value == "await") {
  1425. if (!is_in_async()) {
  1426. token_error(await_tok, for_await_error);
  1427. }
  1428. next();
  1429. } else {
  1430. await_tok = false;
  1431. }
  1432. expect("(");
  1433. var init = null;
  1434. if (!is("punc", ";")) {
  1435. init =
  1436. is("keyword", "var") ? (next(), var_(true)) :
  1437. is("keyword", "let") ? (next(), let_(true)) :
  1438. is("keyword", "const") ? (next(), const_(true)) :
  1439. expression(true, true);
  1440. var is_in = is("operator", "in");
  1441. var is_of = is("name", "of");
  1442. if (await_tok && !is_of) {
  1443. token_error(await_tok, for_await_error);
  1444. }
  1445. if (is_in || is_of) {
  1446. if (init instanceof AST_Definitions) {
  1447. if (init.definitions.length > 1)
  1448. token_error(init.start, "Only one variable declaration allowed in for..in loop");
  1449. } else if (!(is_assignable(init) || (init = to_destructuring(init)) instanceof AST_Destructuring)) {
  1450. token_error(init.start, "Invalid left-hand side in for..in loop");
  1451. }
  1452. next();
  1453. if (is_in) {
  1454. return for_in(init);
  1455. } else {
  1456. return for_of(init, !!await_tok);
  1457. }
  1458. }
  1459. } else if (await_tok) {
  1460. token_error(await_tok, for_await_error);
  1461. }
  1462. return regular_for(init);
  1463. }
  1464. function regular_for(init) {
  1465. expect(";");
  1466. var test = is("punc", ";") ? null : expression(true);
  1467. expect(";");
  1468. var step = is("punc", ")") ? null : expression(true);
  1469. expect(")");
  1470. return new AST_For({
  1471. init : init,
  1472. condition : test,
  1473. step : step,
  1474. body : in_loop(function() { return statement(false, true); })
  1475. });
  1476. }
  1477. function for_of(init, is_await) {
  1478. var lhs = init instanceof AST_Definitions ? init.definitions[0].name : null;
  1479. var obj = expression(true);
  1480. expect(")");
  1481. return new AST_ForOf({
  1482. await : is_await,
  1483. init : init,
  1484. name : lhs,
  1485. object : obj,
  1486. body : in_loop(function() { return statement(false, true); })
  1487. });
  1488. }
  1489. function for_in(init) {
  1490. var obj = expression(true);
  1491. expect(")");
  1492. return new AST_ForIn({
  1493. init : init,
  1494. object : obj,
  1495. body : in_loop(function() { return statement(false, true); })
  1496. });
  1497. }
  1498. var arrow_function = function(start, argnames, is_async) {
  1499. if (has_newline_before(S.token)) {
  1500. croak("Unexpected newline before arrow (=>)");
  1501. }
  1502. expect_token("arrow", "=>");
  1503. var body = _function_body(is("punc", "{"), false, is_async);
  1504. var end =
  1505. body instanceof Array && body.length ? body[body.length - 1].end :
  1506. body instanceof Array ? start :
  1507. body.end;
  1508. return new AST_Arrow({
  1509. start : start,
  1510. end : end,
  1511. async : is_async,
  1512. argnames : argnames,
  1513. body : body
  1514. });
  1515. };
  1516. var function_ = function(ctor, is_generator_property, is_async, is_export_default) {
  1517. var in_statement = ctor === AST_Defun;
  1518. var is_generator = is("operator", "*");
  1519. if (is_generator) {
  1520. next();
  1521. }
  1522. var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
  1523. if (in_statement && !name) {
  1524. if (is_export_default) {
  1525. ctor = AST_Function;
  1526. } else {
  1527. unexpected();
  1528. }
  1529. }
  1530. if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
  1531. unexpected(prev());
  1532. var args = [];
  1533. var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);
  1534. return new ctor({
  1535. start : args.start,
  1536. end : body.end,
  1537. is_generator: is_generator,
  1538. async : is_async,
  1539. name : name,
  1540. argnames: args,
  1541. body : body
  1542. });
  1543. };
  1544. function track_used_binding_identifiers(is_parameter, strict) {
  1545. var parameters = {};
  1546. var duplicate = false;
  1547. var default_assignment = false;
  1548. var spread = false;
  1549. var strict_mode = !!strict;
  1550. var tracker = {
  1551. add_parameter: function(token) {
  1552. if (parameters["$" + token.value] !== undefined) {
  1553. if (duplicate === false) {
  1554. duplicate = token;
  1555. }
  1556. tracker.check_strict();
  1557. } else {
  1558. parameters["$" + token.value] = true;
  1559. if (is_parameter) {
  1560. switch (token.value) {
  1561. case "arguments":
  1562. case "eval":
  1563. case "yield":
  1564. if (strict_mode) {
  1565. token_error(token, "Unexpected " + token.value + " identifier as parameter inside strict mode");
  1566. }
  1567. break;
  1568. default:
  1569. if (RESERVED_WORDS(token.value)) {
  1570. unexpected();
  1571. }
  1572. }
  1573. }
  1574. }
  1575. },
  1576. mark_default_assignment: function(token) {
  1577. if (default_assignment === false) {
  1578. default_assignment = token;
  1579. }
  1580. },
  1581. mark_spread: function(token) {
  1582. if (spread === false) {
  1583. spread = token;
  1584. }
  1585. },
  1586. mark_strict_mode: function() {
  1587. strict_mode = true;
  1588. },
  1589. is_strict: function() {
  1590. return default_assignment !== false || spread !== false || strict_mode;
  1591. },
  1592. check_strict: function() {
  1593. if (tracker.is_strict() && duplicate !== false) {
  1594. token_error(duplicate, "Parameter " + duplicate.value + " was used already");
  1595. }
  1596. }
  1597. };
  1598. return tracker;
  1599. }
  1600. function parameters(params) {
  1601. var used_parameters = track_used_binding_identifiers(true, S.input.has_directive("use strict"));
  1602. expect("(");
  1603. while (!is("punc", ")")) {
  1604. var param = parameter(used_parameters);
  1605. params.push(param);
  1606. if (!is("punc", ")")) {
  1607. expect(",");
  1608. if (is("punc", ")") && options.ecma < 8) unexpected();
  1609. }
  1610. if (param instanceof AST_Expansion) {
  1611. break;
  1612. }
  1613. }
  1614. next();
  1615. }
  1616. function parameter(used_parameters, symbol_type) {
  1617. var param;
  1618. var expand = false;
  1619. if (used_parameters === undefined) {
  1620. used_parameters = track_used_binding_identifiers(true, S.input.has_directive("use strict"));
  1621. }
  1622. if (is("expand", "...")) {
  1623. expand = S.token;
  1624. used_parameters.mark_spread(S.token);
  1625. next();
  1626. }
  1627. param = binding_element(used_parameters, symbol_type);
  1628. if (is("operator", "=") && expand === false) {
  1629. used_parameters.mark_default_assignment(S.token);
  1630. next();
  1631. param = new AST_DefaultAssign({
  1632. start: param.start,
  1633. left: param,
  1634. operator: "=",
  1635. right: expression(false),
  1636. end: S.token
  1637. });
  1638. }
  1639. if (expand !== false) {
  1640. if (!is("punc", ")")) {
  1641. unexpected();
  1642. }
  1643. param = new AST_Expansion({
  1644. start: expand,
  1645. expression: param,
  1646. end: expand
  1647. });
  1648. }
  1649. used_parameters.check_strict();
  1650. return param;
  1651. }
  1652. function binding_element(used_parameters, symbol_type) {
  1653. var elements = [];
  1654. var first = true;
  1655. var is_expand = false;
  1656. var expand_token;
  1657. var first_token = S.token;
  1658. if (used_parameters === undefined) {
  1659. used_parameters = track_used_binding_identifiers(false, S.input.has_directive("use strict"));
  1660. }
  1661. symbol_type = symbol_type === undefined ? AST_SymbolFunarg : symbol_type;
  1662. if (is("punc", "[")) {
  1663. next();
  1664. while (!is("punc", "]")) {
  1665. if (first) {
  1666. first = false;
  1667. } else {
  1668. expect(",");
  1669. }
  1670. if (is("expand", "...")) {
  1671. is_expand = true;
  1672. expand_token = S.token;
  1673. used_parameters.mark_spread(S.token);
  1674. next();
  1675. }
  1676. if (is("punc")) {
  1677. switch (S.token.value) {
  1678. case ",":
  1679. elements.push(new AST_Hole({
  1680. start: S.token,
  1681. end: S.token
  1682. }));
  1683. continue;
  1684. case "]": // Trailing comma after last element
  1685. break;
  1686. case "[":
  1687. case "{":
  1688. elements.push(binding_element(used_parameters, symbol_type));
  1689. break;
  1690. default:
  1691. unexpected();
  1692. }
  1693. } else if (is("name")) {
  1694. used_parameters.add_parameter(S.token);
  1695. elements.push(as_symbol(symbol_type));
  1696. } else {
  1697. croak("Invalid function parameter");
  1698. }
  1699. if (is("operator", "=") && is_expand === false) {
  1700. used_parameters.mark_default_assignment(S.token);
  1701. next();
  1702. elements[elements.length - 1] = new AST_DefaultAssign({
  1703. start: elements[elements.length - 1].start,
  1704. left: elements[elements.length - 1],
  1705. operator: "=",
  1706. right: expression(false),
  1707. end: S.token
  1708. });
  1709. }
  1710. if (is_expand) {
  1711. if (!is("punc", "]")) {
  1712. croak("Rest element must be last element");
  1713. }
  1714. elements[elements.length - 1] = new AST_Expansion({
  1715. start: expand_token,
  1716. expression: elements[elements.length - 1],
  1717. end: expand_token
  1718. });
  1719. }
  1720. }
  1721. expect("]");
  1722. used_parameters.check_strict();
  1723. return new AST_Destructuring({
  1724. start: first_token,
  1725. names: elements,
  1726. is_array: true,
  1727. end: prev()
  1728. });
  1729. } else if (is("punc", "{")) {
  1730. next();
  1731. while (!is("punc", "}")) {
  1732. if (first) {
  1733. first = false;
  1734. } else {
  1735. expect(",");
  1736. }
  1737. if (is("expand", "...")) {
  1738. is_expand = true;
  1739. expand_token = S.token;
  1740. used_parameters.mark_spread(S.token);
  1741. next();
  1742. }
  1743. if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].includes(peek().value)) {
  1744. used_parameters.add_parameter(S.token);
  1745. var start = prev();
  1746. var value = as_symbol(symbol_type);
  1747. if (is_expand) {
  1748. elements.push(new AST_Expansion({
  1749. start: expand_token,
  1750. expression: value,
  1751. end: value.end,
  1752. }));
  1753. } else {
  1754. elements.push(new AST_ObjectKeyVal({
  1755. start: start,
  1756. key: value.name,
  1757. value: value,
  1758. end: value.end,
  1759. }));
  1760. }
  1761. } else if (is("punc", "}")) {
  1762. continue; // Allow trailing hole
  1763. } else {
  1764. var property_token = S.token;
  1765. var property = as_property_name();
  1766. if (property === null) {
  1767. unexpected(prev());
  1768. } else if (prev().type === "name" && !is("punc", ":")) {
  1769. elements.push(new AST_ObjectKeyVal({
  1770. start: prev(),
  1771. key: property,
  1772. value: new symbol_type({
  1773. start: prev(),
  1774. name: property,
  1775. end: prev()
  1776. }),
  1777. end: prev()
  1778. }));
  1779. } else {
  1780. expect(":");
  1781. elements.push(new AST_ObjectKeyVal({
  1782. start: property_token,
  1783. quote: property_token.quote,
  1784. key: property,
  1785. value: binding_element(used_parameters, symbol_type),
  1786. end: prev()
  1787. }));
  1788. }
  1789. }
  1790. if (is_expand) {
  1791. if (!is("punc", "}")) {
  1792. croak("Rest element must be last element");
  1793. }
  1794. } else if (is("operator", "=")) {
  1795. used_parameters.mark_default_assignment(S.token);
  1796. next();
  1797. elements[elements.length - 1].value = new AST_DefaultAssign({
  1798. start: elements[elements.length - 1].value.start,
  1799. left: elements[elements.length - 1].value,
  1800. operator: "=",
  1801. right: expression(false),
  1802. end: S.token
  1803. });
  1804. }
  1805. }
  1806. expect("}");
  1807. used_parameters.check_strict();
  1808. return new AST_Destructuring({
  1809. start: first_token,
  1810. names: elements,
  1811. is_array: false,
  1812. end: prev()
  1813. });
  1814. } else if (is("name")) {
  1815. used_parameters.add_parameter(S.token);
  1816. return as_symbol(symbol_type);
  1817. } else {
  1818. croak("Invalid function parameter");
  1819. }
  1820. }
  1821. function params_or_seq_(allow_arrows, maybe_sequence) {
  1822. var spread_token;
  1823. var invalid_sequence;
  1824. var trailing_comma;
  1825. var a = [];
  1826. expect("(");
  1827. while (!is("punc", ")")) {
  1828. if (spread_token) unexpected(spread_token);
  1829. if (is("expand", "...")) {
  1830. spread_token = S.token;
  1831. if (maybe_sequence) invalid_sequence = S.token;
  1832. next();
  1833. a.push(new AST_Expansion({
  1834. start: prev(),
  1835. expression: expression(),
  1836. end: S.token,
  1837. }));
  1838. } else {
  1839. a.push(expression());
  1840. }
  1841. if (!is("punc", ")")) {
  1842. expect(",");
  1843. if (is("punc", ")")) {
  1844. if (options.ecma < 8) unexpected();
  1845. trailing_comma = prev();
  1846. if (maybe_sequence) invalid_sequence = trailing_comma;
  1847. }
  1848. }
  1849. }
  1850. expect(")");
  1851. if (allow_arrows && is("arrow", "=>")) {
  1852. if (spread_token && trailing_comma) unexpected(trailing_comma);
  1853. } else if (invalid_sequence) {
  1854. unexpected(invalid_sequence);
  1855. }
  1856. return a;
  1857. }
  1858. function _function_body(block, generator, is_async, name, args) {
  1859. var loop = S.in_loop;
  1860. var labels = S.labels;
  1861. var current_generator = S.in_generator;
  1862. var current_async = S.in_async;
  1863. ++S.in_function;
  1864. if (generator)
  1865. S.in_generator = S.in_function;
  1866. if (is_async)
  1867. S.in_async = S.in_function;
  1868. if (args) parameters(args);
  1869. if (block)
  1870. S.in_directives = true;
  1871. S.in_loop = 0;
  1872. S.labels = [];
  1873. if (block) {
  1874. S.input.push_directives_stack();
  1875. var a = block_();
  1876. if (name) _verify_symbol(name);
  1877. if (args) args.forEach(_verify_symbol);
  1878. S.input.pop_directives_stack();
  1879. } else {
  1880. var a = expression(false);
  1881. }
  1882. --S.in_function;
  1883. S.in_loop = loop;
  1884. S.labels = labels;
  1885. S.in_generator = current_generator;
  1886. S.in_async = current_async;
  1887. return a;
  1888. }
  1889. function _await_expression() {
  1890. // Previous token must be "await" and not be interpreted as an identifier
  1891. if (!is_in_async()) {
  1892. croak("Unexpected await expression outside async function",
  1893. S.prev.line, S.prev.col, S.prev.pos);
  1894. }
  1895. // the await expression is parsed as a unary expression in Babel
  1896. return new AST_Await({
  1897. start: prev(),
  1898. end: S.token,
  1899. expression : maybe_unary(true),
  1900. });
  1901. }
  1902. function _yield_expression() {
  1903. // Previous token must be keyword yield and not be interpret as an identifier
  1904. if (!is_in_generator()) {
  1905. croak("Unexpected yield expression outside generator function",
  1906. S.prev.line, S.prev.col, S.prev.pos);
  1907. }
  1908. var start = S.token;
  1909. var star = false;
  1910. var has_expression = true;
  1911. // Attempt to get expression or star (and then the mandatory expression)
  1912. // behind yield on the same line.
  1913. //
  1914. // If nothing follows on the same line of the yieldExpression,
  1915. // it should default to the value `undefined` for yield to return.
  1916. // In that case, the `undefined` stored as `null` in ast.
  1917. //
  1918. // Note 1: It isn't allowed for yield* to close without an expression
  1919. // Note 2: If there is a nlb between yield and star, it is interpret as
  1920. // yield <explicit undefined> <inserted automatic semicolon> *
  1921. if (can_insert_semicolon() ||
  1922. (is("punc") && PUNC_AFTER_EXPRESSION(S.token.value))) {
  1923. has_expression = false;
  1924. } else if (is("operator", "*")) {
  1925. star = true;
  1926. next();
  1927. }
  1928. return new AST_Yield({
  1929. start : start,
  1930. is_star : star,
  1931. expression : has_expression ? expression() : null,
  1932. end : prev()
  1933. });
  1934. }
  1935. function if_() {
  1936. var cond = parenthesised(), body = statement(false, false, true), belse = null;
  1937. if (is("keyword", "else")) {
  1938. next();
  1939. belse = statement(false, false, true);
  1940. }
  1941. return new AST_If({
  1942. condition : cond,
  1943. body : body,
  1944. alternative : belse
  1945. });
  1946. }
  1947. function block_() {
  1948. expect("{");
  1949. var a = [];
  1950. while (!is("punc", "}")) {
  1951. if (is("eof")) unexpected();
  1952. a.push(statement());
  1953. }
  1954. next();
  1955. return a;
  1956. }
  1957. function switch_body_() {
  1958. expect("{");
  1959. var a = [], cur = null, branch = null, tmp;
  1960. while (!is("punc", "}")) {
  1961. if (is("eof")) unexpected();
  1962. if (is("keyword", "case")) {
  1963. if (branch) branch.end = prev();
  1964. cur = [];
  1965. branch = new AST_Case({
  1966. start : (tmp = S.token, next(), tmp),
  1967. expression : expression(true),
  1968. body : cur
  1969. });
  1970. a.push(branch);
  1971. expect(":");
  1972. } else if (is("keyword", "default")) {
  1973. if (branch) branch.end = prev();
  1974. cur = [];
  1975. branch = new AST_Default({
  1976. start : (tmp = S.token, next(), expect(":"), tmp),
  1977. body : cur
  1978. });
  1979. a.push(branch);
  1980. } else {
  1981. if (!cur) unexpected();
  1982. cur.push(statement());
  1983. }
  1984. }
  1985. if (branch) branch.end = prev();
  1986. next();
  1987. return a;
  1988. }
  1989. function try_() {
  1990. var body = block_(), bcatch = null, bfinally = null;
  1991. if (is("keyword", "catch")) {
  1992. var start = S.token;
  1993. next();
  1994. if (is("punc", "{")) {
  1995. var name = null;
  1996. } else {
  1997. expect("(");
  1998. var name = parameter(undefined, AST_SymbolCatch);
  1999. expect(")");
  2000. }
  2001. bcatch = new AST_Catch({
  2002. start : start,
  2003. argname : name,
  2004. body : block_(),
  2005. end : prev()
  2006. });
  2007. }
  2008. if (is("keyword", "finally")) {
  2009. var start = S.token;
  2010. next();
  2011. bfinally = new AST_Finally({
  2012. start : start,
  2013. body : block_(),
  2014. end : prev()
  2015. });
  2016. }
  2017. if (!bcatch && !bfinally)
  2018. croak("Missing catch/finally blocks");
  2019. return new AST_Try({
  2020. body : body,
  2021. bcatch : bcatch,
  2022. bfinally : bfinally
  2023. });
  2024. }
  2025. function vardefs(no_in, kind) {
  2026. var a = [];
  2027. var def;
  2028. for (;;) {
  2029. var sym_type =
  2030. kind === "var" ? AST_SymbolVar :
  2031. kind === "const" ? AST_SymbolConst :
  2032. kind === "let" ? AST_SymbolLet : null;
  2033. if (is("punc", "{") || is("punc", "[")) {
  2034. def = new AST_VarDef({
  2035. start: S.token,
  2036. name: binding_element(undefined ,sym_type),
  2037. value: is("operator", "=") ? (expect_token("operator", "="), expression(false, no_in)) : null,
  2038. end: prev()
  2039. });
  2040. } else {
  2041. def = new AST_VarDef({
  2042. start : S.token,
  2043. name : as_symbol(sym_type),
  2044. value : is("operator", "=")
  2045. ? (next(), expression(false, no_in))
  2046. : !no_in && kind === "const"
  2047. ? croak("Missing initializer in const declaration") : null,
  2048. end : prev()
  2049. });
  2050. if (def.name.name == "import") croak("Unexpected token: import");
  2051. }
  2052. a.push(def);
  2053. if (!is("punc", ","))
  2054. break;
  2055. next();
  2056. }
  2057. return a;
  2058. }
  2059. var var_ = function(no_in) {
  2060. return new AST_Var({
  2061. start : prev(),
  2062. definitions : vardefs(no_in, "var"),
  2063. end : prev()
  2064. });
  2065. };
  2066. var let_ = function(no_in) {
  2067. return new AST_Let({
  2068. start : prev(),
  2069. definitions : vardefs(no_in, "let"),
  2070. end : prev()
  2071. });
  2072. };
  2073. var const_ = function(no_in) {
  2074. return new AST_Const({
  2075. start : prev(),
  2076. definitions : vardefs(no_in, "const"),
  2077. end : prev()
  2078. });
  2079. };
  2080. var new_ = function(allow_calls) {
  2081. var start = S.token;
  2082. expect_token("operator", "new");
  2083. if (is("punc", ".")) {
  2084. next();
  2085. expect_token("name", "target");
  2086. return subscripts(new AST_NewTarget({
  2087. start : start,
  2088. end : prev()
  2089. }), allow_calls);
  2090. }
  2091. var newexp = expr_atom(false), args;
  2092. if (is("punc", "(")) {
  2093. next();
  2094. args = expr_list(")", options.ecma >= 8);
  2095. } else {
  2096. args = [];
  2097. }
  2098. var call = new AST_New({
  2099. start : start,
  2100. expression : newexp,
  2101. args : args,
  2102. end : prev()
  2103. });
  2104. mark_pure(call);
  2105. return subscripts(call, allow_calls);
  2106. };
  2107. function as_atom_node() {
  2108. var tok = S.token, ret;
  2109. switch (tok.type) {
  2110. case "name":
  2111. ret = _make_symbol(AST_SymbolRef);
  2112. break;
  2113. case "num":
  2114. ret = new AST_Number({ start: tok, end: tok, value: tok.value });
  2115. break;
  2116. case "string":
  2117. ret = new AST_String({
  2118. start : tok,
  2119. end : tok,
  2120. value : tok.value,
  2121. quote : tok.quote
  2122. });
  2123. break;
  2124. case "regexp":
  2125. ret = new AST_RegExp({ start: tok, end: tok, value: tok.value });
  2126. break;
  2127. case "atom":
  2128. switch (tok.value) {
  2129. case "false":
  2130. ret = new AST_False({ start: tok, end: tok });
  2131. break;
  2132. case "true":
  2133. ret = new AST_True({ start: tok, end: tok });
  2134. break;
  2135. case "null":
  2136. ret = new AST_Null({ start: tok, end: tok });
  2137. break;
  2138. }
  2139. break;
  2140. }
  2141. next();
  2142. return ret;
  2143. }
  2144. function to_fun_args(ex, _, __, default_seen_above) {
  2145. var insert_default = function(ex, default_value) {
  2146. if (default_value) {
  2147. return new AST_DefaultAssign({
  2148. start: ex.start,
  2149. left: ex,
  2150. operator: "=",
  2151. right: default_value,
  2152. end: default_value.end
  2153. });
  2154. }
  2155. return ex;
  2156. };
  2157. if (ex instanceof AST_Object) {
  2158. return insert_default(new AST_Destructuring({
  2159. start: ex.start,
  2160. end: ex.end,
  2161. is_array: false,
  2162. names: ex.properties.map(to_fun_args)
  2163. }), default_seen_above);
  2164. } else if (ex instanceof AST_ObjectKeyVal) {
  2165. ex.value = to_fun_args(ex.value, 0, [ex.key]);
  2166. return insert_default(ex, default_seen_above);
  2167. } else if (ex instanceof AST_Hole) {
  2168. return ex;
  2169. } else if (ex instanceof AST_Destructuring) {
  2170. ex.names = ex.names.map(to_fun_args);
  2171. return insert_default(ex, default_seen_above);
  2172. } else if (ex instanceof AST_SymbolRef) {
  2173. return insert_default(new AST_SymbolFunarg({
  2174. name: ex.name,
  2175. start: ex.start,
  2176. end: ex.end
  2177. }), default_seen_above);
  2178. } else if (ex instanceof AST_Expansion) {
  2179. ex.expression = to_fun_args(ex.expression);
  2180. return insert_default(ex, default_seen_above);
  2181. } else if (ex instanceof AST_Array) {
  2182. return insert_default(new AST_Destructuring({
  2183. start: ex.start,
  2184. end: ex.end,
  2185. is_array: true,
  2186. names: ex.elements.map(to_fun_args)
  2187. }), default_seen_above);
  2188. } else if (ex instanceof AST_Assign) {
  2189. return insert_default(to_fun_args(ex.left, undefined, undefined, ex.right), default_seen_above);
  2190. } else if (ex instanceof AST_DefaultAssign) {
  2191. ex.left = to_fun_args(ex.left, 0, [ex.left]);
  2192. return ex;
  2193. } else {
  2194. croak("Invalid function parameter", ex.start.line, ex.start.col);
  2195. }
  2196. }
  2197. var expr_atom = function(allow_calls, allow_arrows) {
  2198. if (is("operator", "new")) {
  2199. return new_(allow_calls);
  2200. }
  2201. var start = S.token;
  2202. var peeked;
  2203. var async = is("name", "async")
  2204. && (peeked = peek()).value != "["
  2205. && peeked.type != "arrow"
  2206. && as_atom_node();
  2207. if (is("punc")) {
  2208. switch (S.token.value) {
  2209. case "(":
  2210. if (async && !allow_calls) break;
  2211. var exprs = params_or_seq_(allow_arrows, !async);
  2212. if (allow_arrows && is("arrow", "=>")) {
  2213. return arrow_function(start, exprs.map(to_fun_args), !!async);
  2214. }
  2215. var ex = async ? new AST_Call({
  2216. expression: async,
  2217. args: exprs
  2218. }) : exprs.length == 1 ? exprs[0] : new AST_Sequence({
  2219. expressions: exprs
  2220. });
  2221. if (ex.start) {
  2222. var len = start.comments_before.length;
  2223. [].unshift.apply(ex.start.comments_before, start.comments_before);
  2224. start.comments_before = ex.start.comments_before;
  2225. start.comments_before_length = len;
  2226. if (len == 0 && start.comments_before.length > 0) {
  2227. var comment = start.comments_before[0];
  2228. if (!comment.nlb) {
  2229. comment.nlb = start.nlb;
  2230. start.nlb = false;
  2231. }
  2232. }
  2233. start.comments_after = ex.start.comments_after;
  2234. }
  2235. ex.start = start;
  2236. var end = prev();
  2237. if (ex.end) {
  2238. end.comments_before = ex.end.comments_before;
  2239. [].push.apply(ex.end.comments_after, end.comments_after);
  2240. end.comments_after = ex.end.comments_after;
  2241. }
  2242. ex.end = end;
  2243. if (ex instanceof AST_Call) mark_pure(ex);
  2244. return subscripts(ex, allow_calls);
  2245. case "[":
  2246. return subscripts(array_(), allow_calls);
  2247. case "{":
  2248. return subscripts(object_or_destructuring_(), allow_calls);
  2249. }
  2250. if (!async) unexpected();
  2251. }
  2252. if (allow_arrows && is("name") && is_token(peek(), "arrow")) {
  2253. var param = new AST_SymbolFunarg({
  2254. name: S.token.value,
  2255. start: start,
  2256. end: start,
  2257. });
  2258. next();
  2259. return arrow_function(start, [param], !!async);
  2260. }
  2261. if (is("keyword", "function")) {
  2262. next();
  2263. var func = function_(AST_Function, false, !!async);
  2264. func.start = start;
  2265. func.end = prev();
  2266. return subscripts(func, allow_calls);
  2267. }
  2268. if (async) return subscripts(async, allow_calls);
  2269. if (is("keyword", "class")) {
  2270. next();
  2271. var cls = class_(AST_ClassExpression);
  2272. cls.start = start;
  2273. cls.end = prev();
  2274. return subscripts(cls, allow_calls);
  2275. }
  2276. if (is("template_head")) {
  2277. return subscripts(template_string(false), allow_calls);
  2278. }
  2279. if (ATOMIC_START_TOKEN(S.token.type)) {
  2280. return subscripts(as_atom_node(), allow_calls);
  2281. }
  2282. unexpected();
  2283. };
  2284. function template_string(tagged) {
  2285. var segments = [], start = S.token;
  2286. segments.push(new AST_TemplateSegment({
  2287. start: S.token,
  2288. raw: S.token.raw,
  2289. value: S.token.value,
  2290. end: S.token
  2291. }));
  2292. while (S.token.end === false) {
  2293. next();
  2294. handle_regexp();
  2295. segments.push(expression(true));
  2296. if (!is_token("template_substitution")) {
  2297. unexpected();
  2298. }
  2299. segments.push(new AST_TemplateSegment({
  2300. start: S.token,
  2301. raw: S.token.raw,
  2302. value: S.token.value,
  2303. end: S.token
  2304. }));
  2305. }
  2306. next();
  2307. return new AST_TemplateString({
  2308. start: start,
  2309. segments: segments,
  2310. end: S.token
  2311. });
  2312. }
  2313. function expr_list(closing, allow_trailing_comma, allow_empty) {
  2314. var first = true, a = [];
  2315. while (!is("punc", closing)) {
  2316. if (first) first = false; else expect(",");
  2317. if (allow_trailing_comma && is("punc", closing)) break;
  2318. if (is("punc", ",") && allow_empty) {
  2319. a.push(new AST_Hole({ start: S.token, end: S.token }));
  2320. } else if (is("expand", "...")) {
  2321. next();
  2322. a.push(new AST_Expansion({start: prev(), expression: expression(),end: S.token}));
  2323. } else {
  2324. a.push(expression(false));
  2325. }
  2326. }
  2327. next();
  2328. return a;
  2329. }
  2330. var array_ = embed_tokens(function() {
  2331. expect("[");
  2332. return new AST_Array({
  2333. elements: expr_list("]", !options.strict, true)
  2334. });
  2335. });
  2336. var create_accessor = embed_tokens(function(is_generator, is_async) {
  2337. return function_(AST_Accessor, is_generator, is_async);
  2338. });
  2339. var object_or_destructuring_ = embed_tokens(function object_or_destructuring_() {
  2340. var start = S.token, first = true, a = [];
  2341. expect("{");
  2342. while (!is("punc", "}")) {
  2343. if (first) first = false; else expect(",");
  2344. if (!options.strict && is("punc", "}"))
  2345. // allow trailing comma
  2346. break;
  2347. start = S.token;
  2348. if (start.type == "expand") {
  2349. next();
  2350. a.push(new AST_Expansion({
  2351. start: start,
  2352. expression: expression(false),
  2353. end: prev(),
  2354. }));
  2355. continue;
  2356. }
  2357. var name = as_property_name();
  2358. var value;
  2359. // Check property and fetch value
  2360. if (!is("punc", ":")) {
  2361. var concise = concise_method_or_getset(name, start);
  2362. if (concise) {
  2363. a.push(concise);
  2364. continue;
  2365. }
  2366. value = new AST_SymbolRef({
  2367. start: prev(),
  2368. name: name,
  2369. end: prev()
  2370. });
  2371. } else if (name === null) {
  2372. unexpected(prev());
  2373. } else {
  2374. next(); // `:` - see first condition
  2375. value = expression(false);
  2376. }
  2377. // Check for default value and alter value accordingly if necessary
  2378. if (is("operator", "=")) {
  2379. next();
  2380. value = new AST_Assign({
  2381. start: start,
  2382. left: value,
  2383. operator: "=",
  2384. right: expression(false),
  2385. end: prev()
  2386. });
  2387. }
  2388. // Create property
  2389. a.push(new AST_ObjectKeyVal({
  2390. start: start,
  2391. quote: start.quote,
  2392. key: name instanceof AST_Node ? name : "" + name,
  2393. value: value,
  2394. end: prev()
  2395. }));
  2396. }
  2397. next();
  2398. return new AST_Object({ properties: a });
  2399. });
  2400. function class_(KindOfClass) {
  2401. var start, method, class_name, extends_, a = [];
  2402. S.input.push_directives_stack(); // Push directive stack, but not scope stack
  2403. S.input.add_directive("use strict");
  2404. if (S.token.type == "name" && S.token.value != "extends") {
  2405. class_name = as_symbol(KindOfClass === AST_DefClass ? AST_SymbolDefClass : AST_SymbolClass);
  2406. }
  2407. if (KindOfClass === AST_DefClass && !class_name) {
  2408. unexpected();
  2409. }
  2410. if (S.token.value == "extends") {
  2411. next();
  2412. extends_ = expression(true);
  2413. }
  2414. expect("{");
  2415. if (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
  2416. while (!is("punc", "}")) {
  2417. start = S.token;
  2418. method = concise_method_or_getset(as_property_name(), start, true);
  2419. if (!method) { unexpected(); }
  2420. a.push(method);
  2421. if (is("punc", ";")) { next(); }
  2422. }
  2423. S.input.pop_directives_stack();
  2424. next();
  2425. return new KindOfClass({
  2426. start: start,
  2427. name: class_name,
  2428. extends: extends_,
  2429. properties: a,
  2430. end: prev(),
  2431. });
  2432. }
  2433. function concise_method_or_getset(name, start, is_class) {
  2434. var get_ast = function(name, token) {
  2435. if (typeof name === "string" || typeof name === "number") {
  2436. return new AST_SymbolMethod({
  2437. start: token,
  2438. name: "" + name,
  2439. end: prev()
  2440. });
  2441. } else if (name === null) {
  2442. unexpected();
  2443. }
  2444. return name;
  2445. };
  2446. var is_async = false;
  2447. var is_static = false;
  2448. var is_generator = false;
  2449. var property_token = start;
  2450. if (is_class && name === "static" && !is("punc", "(")) {
  2451. is_static = true;
  2452. property_token = S.token;
  2453. name = as_property_name();
  2454. }
  2455. if (name === "async" && !is("punc", "(") && !is("punc", ",") && !is("punc", "}")) {
  2456. is_async = true;
  2457. property_token = S.token;
  2458. name = as_property_name();
  2459. }
  2460. if (name === null) {
  2461. is_generator = true;
  2462. property_token = S.token;
  2463. name = as_property_name();
  2464. if (name === null) {
  2465. unexpected();
  2466. }
  2467. }
  2468. if (is("punc", "(")) {
  2469. name = get_ast(name, start);
  2470. var node = new AST_ConciseMethod({
  2471. start : start,
  2472. static : is_static,
  2473. is_generator: is_generator,
  2474. async : is_async,
  2475. key : name,
  2476. quote : name instanceof AST_SymbolMethod ?
  2477. property_token.quote : undefined,
  2478. value : create_accessor(is_generator, is_async),
  2479. end : prev()
  2480. });
  2481. return node;
  2482. }
  2483. property_token = S.token;
  2484. if (name == "get") {
  2485. if (!is("punc") || is("punc", "[")) {
  2486. name = get_ast(as_property_name(), start);
  2487. return new AST_ObjectGetter({
  2488. start : start,
  2489. static: is_static,
  2490. key : name,
  2491. quote : name instanceof AST_SymbolMethod ?
  2492. property_token.quote : undefined,
  2493. value : create_accessor(),
  2494. end : prev()
  2495. });
  2496. }
  2497. } else if (name == "set") {
  2498. if (!is("punc") || is("punc", "[")) {
  2499. name = get_ast(as_property_name(), start);
  2500. return new AST_ObjectSetter({
  2501. start : start,
  2502. static: is_static,
  2503. key : name,
  2504. quote : name instanceof AST_SymbolMethod ?
  2505. property_token.quote : undefined,
  2506. value : create_accessor(),
  2507. end : prev()
  2508. });
  2509. }
  2510. }
  2511. }
  2512. function import_() {
  2513. var start = prev();
  2514. var imported_name;
  2515. var imported_names;
  2516. if (is("name")) {
  2517. imported_name = as_symbol(AST_SymbolImport);
  2518. }
  2519. if (is("punc", ",")) {
  2520. next();
  2521. }
  2522. imported_names = map_names(true);
  2523. if (imported_names || imported_name) {
  2524. expect_token("name", "from");
  2525. }
  2526. var mod_str = S.token;
  2527. if (mod_str.type !== "string") {
  2528. unexpected();
  2529. }
  2530. next();
  2531. return new AST_Import({
  2532. start: start,
  2533. imported_name: imported_name,
  2534. imported_names: imported_names,
  2535. module_name: new AST_String({
  2536. start: mod_str,
  2537. value: mod_str.value,
  2538. quote: mod_str.quote,
  2539. end: mod_str,
  2540. }),
  2541. end: S.token,
  2542. });
  2543. }
  2544. function map_name(is_import) {
  2545. function make_symbol(type) {
  2546. return new type({
  2547. name: as_property_name(),
  2548. start: prev(),
  2549. end: prev()
  2550. });
  2551. }
  2552. var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;
  2553. var type = is_import ? AST_SymbolImport : AST_SymbolExport;
  2554. var start = S.token;
  2555. var foreign_name;
  2556. var name;
  2557. if (is_import) {
  2558. foreign_name = make_symbol(foreign_type);
  2559. } else {
  2560. name = make_symbol(type);
  2561. }
  2562. if (is("name", "as")) {
  2563. next(); // The "as" word
  2564. if (is_import) {
  2565. name = make_symbol(type);
  2566. } else {
  2567. foreign_name = make_symbol(foreign_type);
  2568. }
  2569. } else if (is_import) {
  2570. name = new type(foreign_name);
  2571. } else {
  2572. foreign_name = new foreign_type(name);
  2573. }
  2574. return new AST_NameMapping({
  2575. start: start,
  2576. foreign_name: foreign_name,
  2577. name: name,
  2578. end: prev(),
  2579. });
  2580. }
  2581. function map_nameAsterisk(is_import, name) {
  2582. var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;
  2583. var type = is_import ? AST_SymbolImport : AST_SymbolExport;
  2584. var start = S.token;
  2585. var foreign_name;
  2586. var end = prev();
  2587. name = name || new type({
  2588. name: "*",
  2589. start: start,
  2590. end: end,
  2591. });
  2592. foreign_name = new foreign_type({
  2593. name: "*",
  2594. start: start,
  2595. end: end,
  2596. });
  2597. return new AST_NameMapping({
  2598. start: start,
  2599. foreign_name: foreign_name,
  2600. name: name,
  2601. end: end,
  2602. });
  2603. }
  2604. function map_names(is_import) {
  2605. var names;
  2606. if (is("punc", "{")) {
  2607. next();
  2608. names = [];
  2609. while (!is("punc", "}")) {
  2610. names.push(map_name(is_import));
  2611. if (is("punc", ",")) {
  2612. next();
  2613. }
  2614. }
  2615. next();
  2616. } else if (is("operator", "*")) {
  2617. var name;
  2618. next();
  2619. if (is_import && is("name", "as")) {
  2620. next(); // The "as" word
  2621. name = as_symbol(is_import ? AST_SymbolImport : AST_SymbolExportForeign);
  2622. }
  2623. names = [map_nameAsterisk(is_import, name)];
  2624. }
  2625. return names;
  2626. }
  2627. function export_() {
  2628. var start = S.token;
  2629. var is_default;
  2630. var exported_names;
  2631. if (is("keyword", "default")) {
  2632. is_default = true;
  2633. next();
  2634. } else if (exported_names = map_names(false)) {
  2635. if (is("name", "from")) {
  2636. next();
  2637. var mod_str = S.token;
  2638. if (mod_str.type !== "string") {
  2639. unexpected();
  2640. }
  2641. next();
  2642. return new AST_Export({
  2643. start: start,
  2644. is_default: is_default,
  2645. exported_names: exported_names,
  2646. module_name: new AST_String({
  2647. start: mod_str,
  2648. value: mod_str.value,
  2649. quote: mod_str.quote,
  2650. end: mod_str,
  2651. }),
  2652. end: prev(),
  2653. });
  2654. } else {
  2655. return new AST_Export({
  2656. start: start,
  2657. is_default: is_default,
  2658. exported_names: exported_names,
  2659. end: prev(),
  2660. });
  2661. }
  2662. }
  2663. var node;
  2664. var exported_value;
  2665. var exported_definition;
  2666. if (is("punc", "{")
  2667. || is_default
  2668. && (is("keyword", "class") || is("keyword", "function"))
  2669. && is_token(peek(), "punc")) {
  2670. exported_value = expression(false);
  2671. semicolon();
  2672. } else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
  2673. unexpected(node.start);
  2674. } else if (node instanceof AST_Definitions || node instanceof AST_Lambda || node instanceof AST_DefClass) {
  2675. exported_definition = node;
  2676. } else if (node instanceof AST_SimpleStatement) {
  2677. exported_value = node.body;
  2678. } else {
  2679. unexpected(node.start);
  2680. }
  2681. return new AST_Export({
  2682. start: start,
  2683. is_default: is_default,
  2684. exported_value: exported_value,
  2685. exported_definition: exported_definition,
  2686. end: prev(),
  2687. });
  2688. }
  2689. function as_property_name() {
  2690. var tmp = S.token;
  2691. switch (tmp.type) {
  2692. case "punc":
  2693. if (tmp.value === "[") {
  2694. next();
  2695. var ex = expression(false);
  2696. expect("]");
  2697. return ex;
  2698. } else unexpected(tmp);
  2699. case "operator":
  2700. if (tmp.value === "*") {
  2701. next();
  2702. return null;
  2703. }
  2704. if (!["delete", "in", "instanceof", "new", "typeof", "void"].includes(tmp.value)) {
  2705. unexpected(tmp);
  2706. }
  2707. case "name":
  2708. if (tmp.value == "yield") {
  2709. if (is_in_generator()) {
  2710. token_error(tmp, "Yield cannot be used as identifier inside generators");
  2711. } else if (!is_token(peek(), "punc", ":")
  2712. && !is_token(peek(), "punc", "(")
  2713. && S.input.has_directive("use strict")) {
  2714. token_error(tmp, "Unexpected yield identifier inside strict mode");
  2715. }
  2716. }
  2717. case "string":
  2718. case "num":
  2719. case "keyword":
  2720. case "atom":
  2721. next();
  2722. return tmp.value;
  2723. default:
  2724. unexpected(tmp);
  2725. }
  2726. }
  2727. function as_name() {
  2728. var tmp = S.token;
  2729. if (tmp.type != "name") unexpected();
  2730. next();
  2731. return tmp.value;
  2732. }
  2733. function _make_symbol(type) {
  2734. var name = S.token.value;
  2735. return new (name == "this" ? AST_This :
  2736. name == "super" ? AST_Super :
  2737. type)({
  2738. name : String(name),
  2739. start : S.token,
  2740. end : S.token
  2741. });
  2742. }
  2743. function _verify_symbol(sym) {
  2744. var name = sym.name;
  2745. if (is_in_generator() && name == "yield") {
  2746. token_error(sym.start, "Yield cannot be used as identifier inside generators");
  2747. }
  2748. if (S.input.has_directive("use strict")) {
  2749. if (name == "yield") {
  2750. token_error(sym.start, "Unexpected yield identifier inside strict mode");
  2751. }
  2752. if (sym instanceof AST_SymbolDeclaration && (name == "arguments" || name == "eval")) {
  2753. token_error(sym.start, "Unexpected " + name + " in strict mode");
  2754. }
  2755. }
  2756. }
  2757. function as_symbol(type, noerror) {
  2758. if (!is("name")) {
  2759. if (!noerror) croak("Name expected");
  2760. return null;
  2761. }
  2762. var sym = _make_symbol(type);
  2763. _verify_symbol(sym);
  2764. next();
  2765. return sym;
  2766. }
  2767. function mark_pure(call) {
  2768. var start = call.start;
  2769. var comments = start.comments_before;
  2770. var i = HOP(start, "comments_before_length") ? start.comments_before_length : comments.length;
  2771. while (--i >= 0) {
  2772. var comment = comments[i];
  2773. if (/[@#]__PURE__/.test(comment.value)) {
  2774. call.pure = comment;
  2775. break;
  2776. }
  2777. }
  2778. }
  2779. var subscripts = function(expr, allow_calls) {
  2780. var start = expr.start;
  2781. if (is("punc", ".")) {
  2782. next();
  2783. return subscripts(new AST_Dot({
  2784. start : start,
  2785. expression : expr,
  2786. property : as_name(),
  2787. end : prev()
  2788. }), allow_calls);
  2789. }
  2790. if (is("punc", "[")) {
  2791. next();
  2792. var prop = expression(true);
  2793. expect("]");
  2794. return subscripts(new AST_Sub({
  2795. start : start,
  2796. expression : expr,
  2797. property : prop,
  2798. end : prev()
  2799. }), allow_calls);
  2800. }
  2801. if (allow_calls && is("punc", "(")) {
  2802. next();
  2803. var call = new AST_Call({
  2804. start : start,
  2805. expression : expr,
  2806. args : call_args(),
  2807. end : prev()
  2808. });
  2809. mark_pure(call);
  2810. return subscripts(call, true);
  2811. }
  2812. if (is("template_head")) {
  2813. return subscripts(new AST_PrefixedTemplateString({
  2814. start: start,
  2815. prefix: expr,
  2816. template_string: template_string(true),
  2817. end: prev()
  2818. }), allow_calls);
  2819. }
  2820. return expr;
  2821. };
  2822. var call_args = embed_tokens(function _call_args() {
  2823. var args = [];
  2824. while (!is("punc", ")")) {
  2825. if (is("expand", "...")) {
  2826. next();
  2827. args.push(new AST_Expansion({
  2828. start: prev(),
  2829. expression: expression(false),
  2830. end: prev()
  2831. }));
  2832. } else {
  2833. args.push(expression(false));
  2834. }
  2835. if (!is("punc", ")")) {
  2836. expect(",");
  2837. if (is("punc", ")") && options.ecma < 8) unexpected();
  2838. }
  2839. }
  2840. next();
  2841. return args;
  2842. });
  2843. var maybe_unary = function(allow_calls, allow_arrows) {
  2844. var start = S.token;
  2845. if (start.type == "name" && start.value == "await") {
  2846. if (is_in_async()) {
  2847. next();
  2848. return _await_expression();
  2849. } else if (S.input.has_directive("use strict")) {
  2850. token_error(S.token, "Unexpected await identifier inside strict mode");
  2851. }
  2852. }
  2853. if (is("operator") && UNARY_PREFIX(start.value)) {
  2854. next();
  2855. handle_regexp();
  2856. var ex = make_unary(AST_UnaryPrefix, start, maybe_unary(allow_calls));
  2857. ex.start = start;
  2858. ex.end = prev();
  2859. return ex;
  2860. }
  2861. var val = expr_atom(allow_calls, allow_arrows);
  2862. while (is("operator") && UNARY_POSTFIX(S.token.value) && !has_newline_before(S.token)) {
  2863. if (val instanceof AST_Arrow) unexpected();
  2864. val = make_unary(AST_UnaryPostfix, S.token, val);
  2865. val.start = start;
  2866. val.end = S.token;
  2867. next();
  2868. }
  2869. return val;
  2870. };
  2871. function make_unary(ctor, token, expr) {
  2872. var op = token.value;
  2873. switch (op) {
  2874. case "++":
  2875. case "--":
  2876. if (!is_assignable(expr))
  2877. croak("Invalid use of " + op + " operator", token.line, token.col, token.pos);
  2878. break;
  2879. case "delete":
  2880. if (expr instanceof AST_SymbolRef && S.input.has_directive("use strict"))
  2881. croak("Calling delete on expression not allowed in strict mode", expr.start.line, expr.start.col, expr.start.pos);
  2882. break;
  2883. }
  2884. return new ctor({ operator: op, expression: expr });
  2885. }
  2886. var expr_op = function(left, min_prec, no_in) {
  2887. var op = is("operator") ? S.token.value : null;
  2888. if (op == "in" && no_in) op = null;
  2889. if (op == "**" && left instanceof AST_UnaryPrefix
  2890. /* unary token in front not allowed - parenthesis required */
  2891. && !is_token(left.start, "punc", "(")
  2892. && left.operator !== "--" && left.operator !== "++")
  2893. unexpected(left.start);
  2894. var prec = op != null ? PRECEDENCE[op] : null;
  2895. if (prec != null && (prec > min_prec || (op === "**" && min_prec === prec))) {
  2896. next();
  2897. var right = expr_op(maybe_unary(true), prec, no_in);
  2898. return expr_op(new AST_Binary({
  2899. start : left.start,
  2900. left : left,
  2901. operator : op,
  2902. right : right,
  2903. end : right.end
  2904. }), min_prec, no_in);
  2905. }
  2906. return left;
  2907. };
  2908. function expr_ops(no_in) {
  2909. return expr_op(maybe_unary(true, true), 0, no_in);
  2910. }
  2911. var maybe_conditional = function(no_in) {
  2912. var start = S.token;
  2913. var expr = expr_ops(no_in);
  2914. if (is("operator", "?")) {
  2915. next();
  2916. var yes = expression(false);
  2917. expect(":");
  2918. return new AST_Conditional({
  2919. start : start,
  2920. condition : expr,
  2921. consequent : yes,
  2922. alternative : expression(false, no_in),
  2923. end : prev()
  2924. });
  2925. }
  2926. return expr;
  2927. };
  2928. function is_assignable(expr) {
  2929. return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef;
  2930. }
  2931. function to_destructuring(node) {
  2932. if (node instanceof AST_Object) {
  2933. node = new AST_Destructuring({
  2934. start: node.start,
  2935. names: node.properties.map(to_destructuring),
  2936. is_array: false,
  2937. end: node.end
  2938. });
  2939. } else if (node instanceof AST_Array) {
  2940. var names = [];
  2941. for (var i = 0; i < node.elements.length; i++) {
  2942. // Only allow expansion as last element
  2943. if (node.elements[i] instanceof AST_Expansion) {
  2944. if (i + 1 !== node.elements.length) {
  2945. token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
  2946. }
  2947. node.elements[i].expression = to_destructuring(node.elements[i].expression);
  2948. }
  2949. names.push(to_destructuring(node.elements[i]));
  2950. }
  2951. node = new AST_Destructuring({
  2952. start: node.start,
  2953. names: names,
  2954. is_array: true,
  2955. end: node.end
  2956. });
  2957. } else if (node instanceof AST_ObjectProperty) {
  2958. node.value = to_destructuring(node.value);
  2959. } else if (node instanceof AST_Assign) {
  2960. node = new AST_DefaultAssign({
  2961. start: node.start,
  2962. left: node.left,
  2963. operator: "=",
  2964. right: node.right,
  2965. end: node.end
  2966. });
  2967. }
  2968. return node;
  2969. }
  2970. // In ES6, AssignmentExpression can also be an ArrowFunction
  2971. var maybe_assign = function(no_in) {
  2972. handle_regexp();
  2973. var start = S.token;
  2974. if (start.type == "name" && start.value == "yield") {
  2975. if (is_in_generator()) {
  2976. next();
  2977. return _yield_expression();
  2978. } else if (S.input.has_directive("use strict")) {
  2979. token_error(S.token, "Unexpected yield identifier inside strict mode");
  2980. }
  2981. }
  2982. var left = maybe_conditional(no_in);
  2983. var val = S.token.value;
  2984. if (is("operator") && ASSIGNMENT(val)) {
  2985. if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {
  2986. next();
  2987. return new AST_Assign({
  2988. start : start,
  2989. left : left,
  2990. operator : val,
  2991. right : maybe_assign(no_in),
  2992. end : prev()
  2993. });
  2994. }
  2995. croak("Invalid assignment");
  2996. }
  2997. return left;
  2998. };
  2999. var expression = function(commas, no_in) {
  3000. var start = S.token;
  3001. var exprs = [];
  3002. while (true) {
  3003. exprs.push(maybe_assign(no_in));
  3004. if (!commas || !is("punc", ",")) break;
  3005. next();
  3006. commas = true;
  3007. }
  3008. return exprs.length == 1 ? exprs[0] : new AST_Sequence({
  3009. start : start,
  3010. expressions : exprs,
  3011. end : peek()
  3012. });
  3013. };
  3014. function in_loop(cont) {
  3015. ++S.in_loop;
  3016. var ret = cont();
  3017. --S.in_loop;
  3018. return ret;
  3019. }
  3020. if (options.expression) {
  3021. return expression(true);
  3022. }
  3023. return (function() {
  3024. var start = S.token;
  3025. var body = [];
  3026. S.input.push_directives_stack();
  3027. if (options.module) S.input.add_directive("use strict");
  3028. while (!is("eof"))
  3029. body.push(statement());
  3030. S.input.pop_directives_stack();
  3031. var end = prev();
  3032. var toplevel = options.toplevel;
  3033. if (toplevel) {
  3034. toplevel.body = toplevel.body.concat(body);
  3035. toplevel.end = end;
  3036. } else {
  3037. toplevel = new AST_Toplevel({ start: start, body: body, end: end });
  3038. }
  3039. return toplevel;
  3040. })();
  3041. }
  3042. /***********************************************************************
  3043. A JavaScript tokenizer / parser / beautifier / compressor.
  3044. https://github.com/mishoo/UglifyJS2
  3045. -------------------------------- (C) ---------------------------------
  3046. Author: Mihai Bazon
  3047. <mihai.bazon@gmail.com>
  3048. http://mihai.bazon.net/blog
  3049. Distributed under the BSD license:
  3050. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  3051. Redistribution and use in source and binary forms, with or without
  3052. modification, are permitted provided that the following conditions
  3053. are met:
  3054. * Redistributions of source code must retain the above
  3055. copyright notice, this list of conditions and the following
  3056. disclaimer.
  3057. * Redistributions in binary form must reproduce the above
  3058. copyright notice, this list of conditions and the following
  3059. disclaimer in the documentation and/or other materials
  3060. provided with the distribution.
  3061. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  3062. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3063. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  3064. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  3065. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  3066. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  3067. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  3068. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  3069. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  3070. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  3071. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  3072. SUCH DAMAGE.
  3073. ***********************************************************************/
  3074. function DEFNODE(type, props, methods, base) {
  3075. if (arguments.length < 4) base = AST_Node;
  3076. if (!props) props = [];
  3077. else props = props.split(/\s+/);
  3078. var self_props = props;
  3079. if (base && base.PROPS)
  3080. props = props.concat(base.PROPS);
  3081. var code = "return function AST_" + type + "(props){ if (props) { ";
  3082. for (var i = props.length; --i >= 0;) {
  3083. code += "this." + props[i] + " = props." + props[i] + ";";
  3084. }
  3085. var proto = base && new base;
  3086. if (proto && proto.initialize || (methods && methods.initialize))
  3087. code += "this.initialize();";
  3088. code += "}}";
  3089. var ctor = new Function(code)();
  3090. if (proto) {
  3091. ctor.prototype = proto;
  3092. ctor.BASE = base;
  3093. }
  3094. if (base) base.SUBCLASSES.push(ctor);
  3095. ctor.prototype.CTOR = ctor;
  3096. ctor.PROPS = props || null;
  3097. ctor.SELF_PROPS = self_props;
  3098. ctor.SUBCLASSES = [];
  3099. if (type) {
  3100. ctor.prototype.TYPE = ctor.TYPE = type;
  3101. }
  3102. if (methods) for (i in methods) if (HOP(methods, i)) {
  3103. if (/^\$/.test(i)) {
  3104. ctor[i.substr(1)] = methods[i];
  3105. } else {
  3106. ctor.prototype[i] = methods[i];
  3107. }
  3108. }
  3109. ctor.DEFMETHOD = function(name, method) {
  3110. this.prototype[name] = method;
  3111. };
  3112. return ctor;
  3113. }
  3114. var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before comments_after file raw", {
  3115. }, null);
  3116. var AST_Node = DEFNODE("Node", "start end", {
  3117. _clone: function(deep) {
  3118. if (deep) {
  3119. var self = this.clone();
  3120. return self.transform(new TreeTransformer(function(node) {
  3121. if (node !== self) {
  3122. return node.clone(true);
  3123. }
  3124. }));
  3125. }
  3126. return new this.CTOR(this);
  3127. },
  3128. clone: function(deep) {
  3129. return this._clone(deep);
  3130. },
  3131. $documentation: "Base class of all AST nodes",
  3132. $propdoc: {
  3133. start: "[AST_Token] The first token of this node",
  3134. end: "[AST_Token] The last token of this node"
  3135. },
  3136. _walk: function(visitor) {
  3137. return visitor._visit(this);
  3138. },
  3139. walk: function(visitor) {
  3140. return this._walk(visitor); // not sure the indirection will be any help
  3141. }
  3142. }, null);
  3143. AST_Node.warn_function = null;
  3144. AST_Node.warn = function(txt, props) {
  3145. if (AST_Node.warn_function)
  3146. AST_Node.warn_function(string_template(txt, props));
  3147. };
  3148. /* -----[ statements ]----- */
  3149. var AST_Statement = DEFNODE("Statement", null, {
  3150. $documentation: "Base class of all statements",
  3151. });
  3152. var AST_Debugger = DEFNODE("Debugger", null, {
  3153. $documentation: "Represents a debugger statement",
  3154. }, AST_Statement);
  3155. var AST_Directive = DEFNODE("Directive", "value quote", {
  3156. $documentation: "Represents a directive, like \"use strict\";",
  3157. $propdoc: {
  3158. value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
  3159. quote: "[string] the original quote character"
  3160. },
  3161. }, AST_Statement);
  3162. var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
  3163. $documentation: "A statement consisting of an expression, i.e. a = 1 + 2",
  3164. $propdoc: {
  3165. body: "[AST_Node] an expression node (should not be instanceof AST_Statement)"
  3166. },
  3167. _walk: function(visitor) {
  3168. return visitor._visit(this, function() {
  3169. this.body._walk(visitor);
  3170. });
  3171. }
  3172. }, AST_Statement);
  3173. function walk_body(node, visitor) {
  3174. var body = node.body;
  3175. if (body instanceof AST_Node) {
  3176. body._walk(visitor);
  3177. } else for (var i = 0, len = body.length; i < len; i++) {
  3178. body[i]._walk(visitor);
  3179. }
  3180. }
  3181. function clone_block_scope(deep) {
  3182. var clone = this._clone(deep);
  3183. if (this.block_scope) {
  3184. // TODO this is sometimes undefined during compression.
  3185. // But it should always have a value!
  3186. clone.block_scope = this.block_scope.clone();
  3187. }
  3188. return clone;
  3189. }
  3190. var AST_Block = DEFNODE("Block", "body block_scope", {
  3191. $documentation: "A body of statements (usually braced)",
  3192. $propdoc: {
  3193. body: "[AST_Statement*] an array of statements",
  3194. block_scope: "[AST_Scope] the block scope"
  3195. },
  3196. _walk: function(visitor) {
  3197. return visitor._visit(this, function() {
  3198. walk_body(this, visitor);
  3199. });
  3200. },
  3201. clone: clone_block_scope
  3202. }, AST_Statement);
  3203. var AST_BlockStatement = DEFNODE("BlockStatement", null, {
  3204. $documentation: "A block statement",
  3205. }, AST_Block);
  3206. var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
  3207. $documentation: "The empty statement (empty block or simply a semicolon)"
  3208. }, AST_Statement);
  3209. var AST_StatementWithBody = DEFNODE("StatementWithBody", "body", {
  3210. $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`",
  3211. $propdoc: {
  3212. body: "[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement"
  3213. }
  3214. }, AST_Statement);
  3215. var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
  3216. $documentation: "Statement with a label",
  3217. $propdoc: {
  3218. label: "[AST_Label] a label definition"
  3219. },
  3220. _walk: function(visitor) {
  3221. return visitor._visit(this, function() {
  3222. this.label._walk(visitor);
  3223. this.body._walk(visitor);
  3224. });
  3225. },
  3226. clone: function(deep) {
  3227. var node = this._clone(deep);
  3228. if (deep) {
  3229. var label = node.label;
  3230. var def = this.label;
  3231. node.walk(new TreeWalker(function(node) {
  3232. if (node instanceof AST_LoopControl
  3233. && node.label && node.label.thedef === def) {
  3234. node.label.thedef = label;
  3235. label.references.push(node);
  3236. }
  3237. }));
  3238. }
  3239. return node;
  3240. }
  3241. }, AST_StatementWithBody);
  3242. var AST_IterationStatement = DEFNODE("IterationStatement", "block_scope", {
  3243. $documentation: "Internal class. All loops inherit from it.",
  3244. $propdoc: {
  3245. block_scope: "[AST_Scope] the block scope for this iteration statement."
  3246. },
  3247. clone: clone_block_scope
  3248. }, AST_StatementWithBody);
  3249. var AST_DWLoop = DEFNODE("DWLoop", "condition", {
  3250. $documentation: "Base class for do/while statements",
  3251. $propdoc: {
  3252. condition: "[AST_Node] the loop condition. Should not be instanceof AST_Statement"
  3253. }
  3254. }, AST_IterationStatement);
  3255. var AST_Do = DEFNODE("Do", null, {
  3256. $documentation: "A `do` statement",
  3257. _walk: function(visitor) {
  3258. return visitor._visit(this, function() {
  3259. this.body._walk(visitor);
  3260. this.condition._walk(visitor);
  3261. });
  3262. }
  3263. }, AST_DWLoop);
  3264. var AST_While = DEFNODE("While", null, {
  3265. $documentation: "A `while` statement",
  3266. _walk: function(visitor) {
  3267. return visitor._visit(this, function() {
  3268. this.condition._walk(visitor);
  3269. this.body._walk(visitor);
  3270. });
  3271. }
  3272. }, AST_DWLoop);
  3273. var AST_For = DEFNODE("For", "init condition step", {
  3274. $documentation: "A `for` statement",
  3275. $propdoc: {
  3276. init: "[AST_Node?] the `for` initialization code, or null if empty",
  3277. condition: "[AST_Node?] the `for` termination clause, or null if empty",
  3278. step: "[AST_Node?] the `for` update clause, or null if empty"
  3279. },
  3280. _walk: function(visitor) {
  3281. return visitor._visit(this, function() {
  3282. if (this.init) this.init._walk(visitor);
  3283. if (this.condition) this.condition._walk(visitor);
  3284. if (this.step) this.step._walk(visitor);
  3285. this.body._walk(visitor);
  3286. });
  3287. }
  3288. }, AST_IterationStatement);
  3289. var AST_ForIn = DEFNODE("ForIn", "init object", {
  3290. $documentation: "A `for ... in` statement",
  3291. $propdoc: {
  3292. init: "[AST_Node] the `for/in` initialization code",
  3293. object: "[AST_Node] the object that we're looping through"
  3294. },
  3295. _walk: function(visitor) {
  3296. return visitor._visit(this, function() {
  3297. this.init._walk(visitor);
  3298. this.object._walk(visitor);
  3299. this.body._walk(visitor);
  3300. });
  3301. }
  3302. }, AST_IterationStatement);
  3303. var AST_ForOf = DEFNODE("ForOf", "await", {
  3304. $documentation: "A `for ... of` statement",
  3305. }, AST_ForIn);
  3306. var AST_With = DEFNODE("With", "expression", {
  3307. $documentation: "A `with` statement",
  3308. $propdoc: {
  3309. expression: "[AST_Node] the `with` expression"
  3310. },
  3311. _walk: function(visitor) {
  3312. return visitor._visit(this, function() {
  3313. this.expression._walk(visitor);
  3314. this.body._walk(visitor);
  3315. });
  3316. }
  3317. }, AST_StatementWithBody);
  3318. /* -----[ scope and functions ]----- */
  3319. var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent_scope enclosed cname", {
  3320. $documentation: "Base class for all statements introducing a lexical scope",
  3321. $propdoc: {
  3322. variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope",
  3323. functions: "[Object/S] like `variables`, but only lists function declarations",
  3324. uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
  3325. uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`",
  3326. parent_scope: "[AST_Scope?/S] link to the parent scope",
  3327. enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
  3328. cname: "[integer/S] current index for mangling variables (used internally by the mangler)",
  3329. },
  3330. get_defun_scope: function() {
  3331. var self = this;
  3332. while (self.is_block_scope()) {
  3333. self = self.parent_scope;
  3334. }
  3335. return self;
  3336. },
  3337. clone: function(deep) {
  3338. var node = this._clone(deep);
  3339. if (this.variables) node.variables = this.variables.clone();
  3340. if (this.functions) node.functions = this.functions.clone();
  3341. if (this.enclosed) node.enclosed = this.enclosed.slice();
  3342. return node;
  3343. },
  3344. pinned: function() {
  3345. return this.uses_eval || this.uses_with;
  3346. }
  3347. }, AST_Block);
  3348. var AST_Toplevel = DEFNODE("Toplevel", "globals", {
  3349. $documentation: "The toplevel scope",
  3350. $propdoc: {
  3351. globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
  3352. },
  3353. wrap_commonjs: function(name) {
  3354. var body = this.body;
  3355. var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
  3356. wrapped_tl = parse(wrapped_tl);
  3357. wrapped_tl = wrapped_tl.transform(new TreeTransformer(function(node) {
  3358. if (node instanceof AST_Directive && node.value == "$ORIG") {
  3359. return MAP.splice(body);
  3360. }
  3361. }));
  3362. return wrapped_tl;
  3363. },
  3364. wrap_enclose: function(args_values) {
  3365. if (typeof args_values != "string") args_values = "";
  3366. var index = args_values.indexOf(":");
  3367. if (index < 0) index = args_values.length;
  3368. var body = this.body;
  3369. return parse([
  3370. "(function(",
  3371. args_values.slice(0, index),
  3372. '){"$ORIG"})(',
  3373. args_values.slice(index + 1),
  3374. ")"
  3375. ].join("")).transform(new TreeTransformer(function(node) {
  3376. if (node instanceof AST_Directive && node.value == "$ORIG") {
  3377. return MAP.splice(body);
  3378. }
  3379. }));
  3380. }
  3381. }, AST_Scope);
  3382. var AST_Expansion = DEFNODE("Expansion", "expression", {
  3383. $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",
  3384. $propdoc: {
  3385. expression: "[AST_Node] the thing to be expanded"
  3386. },
  3387. _walk: function(visitor) {
  3388. var self = this;
  3389. return visitor._visit(this, function() {
  3390. self.expression.walk(visitor);
  3391. });
  3392. }
  3393. });
  3394. var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator async", {
  3395. $documentation: "Base class for functions",
  3396. $propdoc: {
  3397. name: "[AST_SymbolDeclaration?] the name of this function",
  3398. argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding arguments",
  3399. uses_arguments: "[boolean/S] tells whether this function accesses the arguments array",
  3400. is_generator: "[boolean] is this a generator method",
  3401. async: "[boolean] is this method async",
  3402. },
  3403. args_as_names: function () {
  3404. var out = [];
  3405. for (var i = 0; i < this.argnames.length; i++) {
  3406. if (this.argnames[i] instanceof AST_Destructuring) {
  3407. out = out.concat(this.argnames[i].all_symbols());
  3408. } else {
  3409. out.push(this.argnames[i]);
  3410. }
  3411. }
  3412. return out;
  3413. },
  3414. _walk: function(visitor) {
  3415. return visitor._visit(this, function() {
  3416. if (this.name) this.name._walk(visitor);
  3417. var argnames = this.argnames;
  3418. for (var i = 0, len = argnames.length; i < len; i++) {
  3419. argnames[i]._walk(visitor);
  3420. }
  3421. walk_body(this, visitor);
  3422. });
  3423. }
  3424. }, AST_Scope);
  3425. var AST_Accessor = DEFNODE("Accessor", null, {
  3426. $documentation: "A setter/getter function. The `name` property is always null."
  3427. }, AST_Lambda);
  3428. var AST_Function = DEFNODE("Function", "inlined", {
  3429. $documentation: "A function expression"
  3430. }, AST_Lambda);
  3431. var AST_Arrow = DEFNODE("Arrow", "inlined", {
  3432. $documentation: "An ES6 Arrow function ((a) => b)"
  3433. }, AST_Lambda);
  3434. var AST_Defun = DEFNODE("Defun", "inlined", {
  3435. $documentation: "A function definition"
  3436. }, AST_Lambda);
  3437. /* -----[ DESTRUCTURING ]----- */
  3438. var AST_Destructuring = DEFNODE("Destructuring", "names is_array", {
  3439. $documentation: "A destructuring of several names. Used in destructuring assignment and with destructuring function argument names",
  3440. $propdoc: {
  3441. "names": "[AST_Node*] Array of properties or elements",
  3442. "is_array": "[Boolean] Whether the destructuring represents an object or array"
  3443. },
  3444. _walk: function(visitor) {
  3445. return visitor._visit(this, function() {
  3446. this.names.forEach(function(name) {
  3447. name._walk(visitor);
  3448. });
  3449. });
  3450. },
  3451. all_symbols: function() {
  3452. var out = [];
  3453. this.walk(new TreeWalker(function (node) {
  3454. if (node instanceof AST_Symbol) {
  3455. out.push(node);
  3456. }
  3457. if (node instanceof AST_Expansion) {
  3458. out.push(node.expression);
  3459. }
  3460. }));
  3461. return out;
  3462. }
  3463. });
  3464. var AST_PrefixedTemplateString = DEFNODE("PrefixedTemplateString", "template_string prefix", {
  3465. $documentation: "A templatestring with a prefix, such as String.raw`foobarbaz`",
  3466. $propdoc: {
  3467. template_string: "[AST_TemplateString] The template string",
  3468. prefix: "[AST_SymbolRef|AST_PropAccess] The prefix, which can be a symbol such as `foo` or a dotted expression such as `String.raw`."
  3469. },
  3470. _walk: function(visitor) {
  3471. this.prefix._walk(visitor);
  3472. this.template_string._walk(visitor);
  3473. }
  3474. });
  3475. var AST_TemplateString = DEFNODE("TemplateString", "segments", {
  3476. $documentation: "A template string literal",
  3477. $propdoc: {
  3478. segments: "[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."
  3479. },
  3480. _walk: function(visitor) {
  3481. return visitor._visit(this, function() {
  3482. this.segments.forEach(function(seg) {
  3483. seg._walk(visitor);
  3484. });
  3485. });
  3486. }
  3487. });
  3488. var AST_TemplateSegment = DEFNODE("TemplateSegment", "value raw", {
  3489. $documentation: "A segment of a template string literal",
  3490. $propdoc: {
  3491. value: "Content of the segment",
  3492. raw: "Raw content of the segment"
  3493. }
  3494. });
  3495. /* -----[ JUMPS ]----- */
  3496. var AST_Jump = DEFNODE("Jump", null, {
  3497. $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"
  3498. }, AST_Statement);
  3499. var AST_Exit = DEFNODE("Exit", "value", {
  3500. $documentation: "Base class for “exits” (`return` and `throw`)",
  3501. $propdoc: {
  3502. value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"
  3503. },
  3504. _walk: function(visitor) {
  3505. return visitor._visit(this, this.value && function() {
  3506. this.value._walk(visitor);
  3507. });
  3508. }
  3509. }, AST_Jump);
  3510. var AST_Return = DEFNODE("Return", null, {
  3511. $documentation: "A `return` statement"
  3512. }, AST_Exit);
  3513. var AST_Throw = DEFNODE("Throw", null, {
  3514. $documentation: "A `throw` statement"
  3515. }, AST_Exit);
  3516. var AST_LoopControl = DEFNODE("LoopControl", "label", {
  3517. $documentation: "Base class for loop control statements (`break` and `continue`)",
  3518. $propdoc: {
  3519. label: "[AST_LabelRef?] the label, or null if none",
  3520. },
  3521. _walk: function(visitor) {
  3522. return visitor._visit(this, this.label && function() {
  3523. this.label._walk(visitor);
  3524. });
  3525. }
  3526. }, AST_Jump);
  3527. var AST_Break = DEFNODE("Break", null, {
  3528. $documentation: "A `break` statement"
  3529. }, AST_LoopControl);
  3530. var AST_Continue = DEFNODE("Continue", null, {
  3531. $documentation: "A `continue` statement"
  3532. }, AST_LoopControl);
  3533. /* -----[ IF ]----- */
  3534. var AST_If = DEFNODE("If", "condition alternative", {
  3535. $documentation: "A `if` statement",
  3536. $propdoc: {
  3537. condition: "[AST_Node] the `if` condition",
  3538. alternative: "[AST_Statement?] the `else` part, or null if not present"
  3539. },
  3540. _walk: function(visitor) {
  3541. return visitor._visit(this, function() {
  3542. this.condition._walk(visitor);
  3543. this.body._walk(visitor);
  3544. if (this.alternative) this.alternative._walk(visitor);
  3545. });
  3546. }
  3547. }, AST_StatementWithBody);
  3548. /* -----[ SWITCH ]----- */
  3549. var AST_Switch = DEFNODE("Switch", "expression", {
  3550. $documentation: "A `switch` statement",
  3551. $propdoc: {
  3552. expression: "[AST_Node] the `switch` “discriminant”"
  3553. },
  3554. _walk: function(visitor) {
  3555. return visitor._visit(this, function() {
  3556. this.expression._walk(visitor);
  3557. walk_body(this, visitor);
  3558. });
  3559. }
  3560. }, AST_Block);
  3561. var AST_SwitchBranch = DEFNODE("SwitchBranch", null, {
  3562. $documentation: "Base class for `switch` branches",
  3563. }, AST_Block);
  3564. var AST_Default = DEFNODE("Default", null, {
  3565. $documentation: "A `default` switch branch",
  3566. }, AST_SwitchBranch);
  3567. var AST_Case = DEFNODE("Case", "expression", {
  3568. $documentation: "A `case` switch branch",
  3569. $propdoc: {
  3570. expression: "[AST_Node] the `case` expression"
  3571. },
  3572. _walk: function(visitor) {
  3573. return visitor._visit(this, function() {
  3574. this.expression._walk(visitor);
  3575. walk_body(this, visitor);
  3576. });
  3577. }
  3578. }, AST_SwitchBranch);
  3579. /* -----[ EXCEPTIONS ]----- */
  3580. var AST_Try = DEFNODE("Try", "bcatch bfinally", {
  3581. $documentation: "A `try` statement",
  3582. $propdoc: {
  3583. bcatch: "[AST_Catch?] the catch block, or null if not present",
  3584. bfinally: "[AST_Finally?] the finally block, or null if not present"
  3585. },
  3586. _walk: function(visitor) {
  3587. return visitor._visit(this, function() {
  3588. walk_body(this, visitor);
  3589. if (this.bcatch) this.bcatch._walk(visitor);
  3590. if (this.bfinally) this.bfinally._walk(visitor);
  3591. });
  3592. }
  3593. }, AST_Block);
  3594. var AST_Catch = DEFNODE("Catch", "argname", {
  3595. $documentation: "A `catch` node; only makes sense as part of a `try` statement",
  3596. $propdoc: {
  3597. argname: "[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception"
  3598. },
  3599. _walk: function(visitor) {
  3600. return visitor._visit(this, function() {
  3601. if (this.argname) this.argname._walk(visitor);
  3602. walk_body(this, visitor);
  3603. });
  3604. }
  3605. }, AST_Block);
  3606. var AST_Finally = DEFNODE("Finally", null, {
  3607. $documentation: "A `finally` node; only makes sense as part of a `try` statement"
  3608. }, AST_Block);
  3609. /* -----[ VAR/CONST ]----- */
  3610. var AST_Definitions = DEFNODE("Definitions", "definitions", {
  3611. $documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)",
  3612. $propdoc: {
  3613. definitions: "[AST_VarDef*] array of variable definitions"
  3614. },
  3615. _walk: function(visitor) {
  3616. return visitor._visit(this, function() {
  3617. var definitions = this.definitions;
  3618. for (var i = 0, len = definitions.length; i < len; i++) {
  3619. definitions[i]._walk(visitor);
  3620. }
  3621. });
  3622. }
  3623. }, AST_Statement);
  3624. var AST_Var = DEFNODE("Var", null, {
  3625. $documentation: "A `var` statement"
  3626. }, AST_Definitions);
  3627. var AST_Let = DEFNODE("Let", null, {
  3628. $documentation: "A `let` statement"
  3629. }, AST_Definitions);
  3630. var AST_Const = DEFNODE("Const", null, {
  3631. $documentation: "A `const` statement"
  3632. }, AST_Definitions);
  3633. var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", {
  3634. $documentation: "The part of the export/import statement that declare names from a module.",
  3635. $propdoc: {
  3636. foreign_name: "[AST_SymbolExportForeign|AST_SymbolImportForeign] The name being exported/imported (as specified in the module)",
  3637. name: "[AST_SymbolExport|AST_SymbolImport] The name as it is visible to this module."
  3638. },
  3639. _walk: function (visitor) {
  3640. return visitor._visit(this, function() {
  3641. this.foreign_name._walk(visitor);
  3642. this.name._walk(visitor);
  3643. });
  3644. }
  3645. });
  3646. var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {
  3647. $documentation: "An `import` statement",
  3648. $propdoc: {
  3649. imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
  3650. imported_names: "[AST_NameMapping*] The names of non-default imported variables",
  3651. module_name: "[AST_String] String literal describing where this module came from",
  3652. },
  3653. _walk: function(visitor) {
  3654. return visitor._visit(this, function() {
  3655. if (this.imported_name) {
  3656. this.imported_name._walk(visitor);
  3657. }
  3658. if (this.imported_names) {
  3659. this.imported_names.forEach(function(name_import) {
  3660. name_import._walk(visitor);
  3661. });
  3662. }
  3663. this.module_name._walk(visitor);
  3664. });
  3665. }
  3666. });
  3667. var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name", {
  3668. $documentation: "An `export` statement",
  3669. $propdoc: {
  3670. exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition",
  3671. exported_value: "[AST_Node?] An exported value",
  3672. exported_names: "[AST_NameMapping*?] List of exported names",
  3673. module_name: "[AST_String?] Name of the file to load exports from",
  3674. is_default: "[Boolean] Whether this is the default exported value of this module"
  3675. },
  3676. _walk: function (visitor) {
  3677. visitor._visit(this, function () {
  3678. if (this.exported_definition) {
  3679. this.exported_definition._walk(visitor);
  3680. }
  3681. if (this.exported_value) {
  3682. this.exported_value._walk(visitor);
  3683. }
  3684. if (this.exported_names) {
  3685. this.exported_names.forEach(function(name_export) {
  3686. name_export._walk(visitor);
  3687. });
  3688. }
  3689. if (this.module_name) {
  3690. this.module_name._walk(visitor);
  3691. }
  3692. });
  3693. }
  3694. }, AST_Statement);
  3695. var AST_VarDef = DEFNODE("VarDef", "name value", {
  3696. $documentation: "A variable declaration; only appears in a AST_Definitions node",
  3697. $propdoc: {
  3698. name: "[AST_Destructuring|AST_SymbolConst|AST_SymbolLet|AST_SymbolVar] name of the variable",
  3699. value: "[AST_Node?] initializer, or null of there's no initializer"
  3700. },
  3701. _walk: function(visitor) {
  3702. return visitor._visit(this, function() {
  3703. this.name._walk(visitor);
  3704. if (this.value) this.value._walk(visitor);
  3705. });
  3706. }
  3707. });
  3708. /* -----[ OTHER ]----- */
  3709. var AST_Call = DEFNODE("Call", "expression args", {
  3710. $documentation: "A function call expression",
  3711. $propdoc: {
  3712. expression: "[AST_Node] expression to invoke as function",
  3713. args: "[AST_Node*] array of arguments"
  3714. },
  3715. _walk: function(visitor) {
  3716. return visitor._visit(this, function() {
  3717. var args = this.args;
  3718. for (var i = 0, len = args.length; i < len; i++) {
  3719. args[i]._walk(visitor);
  3720. }
  3721. this.expression._walk(visitor);
  3722. });
  3723. }
  3724. });
  3725. var AST_New = DEFNODE("New", null, {
  3726. $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties"
  3727. }, AST_Call);
  3728. var AST_Sequence = DEFNODE("Sequence", "expressions", {
  3729. $documentation: "A sequence expression (comma-separated expressions)",
  3730. $propdoc: {
  3731. expressions: "[AST_Node*] array of expressions (at least two)"
  3732. },
  3733. _walk: function(visitor) {
  3734. return visitor._visit(this, function() {
  3735. this.expressions.forEach(function(node) {
  3736. node._walk(visitor);
  3737. });
  3738. });
  3739. }
  3740. });
  3741. var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
  3742. $documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`",
  3743. $propdoc: {
  3744. expression: "[AST_Node] the “container” expression",
  3745. property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node"
  3746. }
  3747. });
  3748. var AST_Dot = DEFNODE("Dot", null, {
  3749. $documentation: "A dotted property access expression",
  3750. _walk: function(visitor) {
  3751. return visitor._visit(this, function() {
  3752. this.expression._walk(visitor);
  3753. });
  3754. }
  3755. }, AST_PropAccess);
  3756. var AST_Sub = DEFNODE("Sub", null, {
  3757. $documentation: "Index-style property access, i.e. `a[\"foo\"]`",
  3758. _walk: function(visitor) {
  3759. return visitor._visit(this, function() {
  3760. this.expression._walk(visitor);
  3761. this.property._walk(visitor);
  3762. });
  3763. }
  3764. }, AST_PropAccess);
  3765. var AST_Unary = DEFNODE("Unary", "operator expression", {
  3766. $documentation: "Base class for unary expressions",
  3767. $propdoc: {
  3768. operator: "[string] the operator",
  3769. expression: "[AST_Node] expression that this unary operator applies to"
  3770. },
  3771. _walk: function(visitor) {
  3772. return visitor._visit(this, function() {
  3773. this.expression._walk(visitor);
  3774. });
  3775. }
  3776. });
  3777. var AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, {
  3778. $documentation: "Unary prefix expression, i.e. `typeof i` or `++i`"
  3779. }, AST_Unary);
  3780. var AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, {
  3781. $documentation: "Unary postfix expression, i.e. `i++`"
  3782. }, AST_Unary);
  3783. var AST_Binary = DEFNODE("Binary", "operator left right", {
  3784. $documentation: "Binary expression, i.e. `a + b`",
  3785. $propdoc: {
  3786. left: "[AST_Node] left-hand side expression",
  3787. operator: "[string] the operator",
  3788. right: "[AST_Node] right-hand side expression"
  3789. },
  3790. _walk: function(visitor) {
  3791. return visitor._visit(this, function() {
  3792. this.left._walk(visitor);
  3793. this.right._walk(visitor);
  3794. });
  3795. }
  3796. });
  3797. var AST_Conditional = DEFNODE("Conditional", "condition consequent alternative", {
  3798. $documentation: "Conditional expression using the ternary operator, i.e. `a ? b : c`",
  3799. $propdoc: {
  3800. condition: "[AST_Node]",
  3801. consequent: "[AST_Node]",
  3802. alternative: "[AST_Node]"
  3803. },
  3804. _walk: function(visitor) {
  3805. return visitor._visit(this, function() {
  3806. this.condition._walk(visitor);
  3807. this.consequent._walk(visitor);
  3808. this.alternative._walk(visitor);
  3809. });
  3810. }
  3811. });
  3812. var AST_Assign = DEFNODE("Assign", null, {
  3813. $documentation: "An assignment expression — `a = b + 5`",
  3814. }, AST_Binary);
  3815. var AST_DefaultAssign = DEFNODE("DefaultAssign", null, {
  3816. $documentation: "A default assignment expression like in `(a = 3) => a`"
  3817. }, AST_Binary);
  3818. /* -----[ LITERALS ]----- */
  3819. var AST_Array = DEFNODE("Array", "elements", {
  3820. $documentation: "An array literal",
  3821. $propdoc: {
  3822. elements: "[AST_Node*] array of elements"
  3823. },
  3824. _walk: function(visitor) {
  3825. return visitor._visit(this, function() {
  3826. var elements = this.elements;
  3827. for (var i = 0, len = elements.length; i < len; i++) {
  3828. elements[i]._walk(visitor);
  3829. }
  3830. });
  3831. }
  3832. });
  3833. var AST_Object = DEFNODE("Object", "properties", {
  3834. $documentation: "An object literal",
  3835. $propdoc: {
  3836. properties: "[AST_ObjectProperty*] array of properties"
  3837. },
  3838. _walk: function(visitor) {
  3839. return visitor._visit(this, function() {
  3840. var properties = this.properties;
  3841. for (var i = 0, len = properties.length; i < len; i++) {
  3842. properties[i]._walk(visitor);
  3843. }
  3844. });
  3845. }
  3846. });
  3847. var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
  3848. $documentation: "Base class for literal object properties",
  3849. $propdoc: {
  3850. key: "[string|AST_Node] property name. For ObjectKeyVal this is a string. For getters, setters and computed property this is an AST_Node.",
  3851. value: "[AST_Node] property value. For getters and setters this is an AST_Accessor."
  3852. },
  3853. _walk: function(visitor) {
  3854. return visitor._visit(this, function() {
  3855. if (this.key instanceof AST_Node)
  3856. this.key._walk(visitor);
  3857. this.value._walk(visitor);
  3858. });
  3859. }
  3860. });
  3861. var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
  3862. $documentation: "A key: value object property",
  3863. $propdoc: {
  3864. quote: "[string] the original quote character"
  3865. }
  3866. }, AST_ObjectProperty);
  3867. var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", {
  3868. $propdoc: {
  3869. quote: "[string|undefined] the original quote character, if any",
  3870. static: "[boolean] whether this is a static setter (classes only)"
  3871. },
  3872. $documentation: "An object setter property",
  3873. }, AST_ObjectProperty);
  3874. var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", {
  3875. $propdoc: {
  3876. quote: "[string|undefined] the original quote character, if any",
  3877. static: "[boolean] whether this is a static getter (classes only)"
  3878. },
  3879. $documentation: "An object getter property",
  3880. }, AST_ObjectProperty);
  3881. var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator async", {
  3882. $propdoc: {
  3883. quote: "[string|undefined] the original quote character, if any",
  3884. static: "[boolean] is this method static (classes only)",
  3885. is_generator: "[boolean] is this a generator method",
  3886. async: "[boolean] is this method async",
  3887. },
  3888. $documentation: "An ES6 concise method inside an object or class"
  3889. }, AST_ObjectProperty);
  3890. var AST_Class = DEFNODE("Class", "name extends properties inlined", {
  3891. $propdoc: {
  3892. name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
  3893. extends: "[AST_Node]? optional parent class",
  3894. properties: "[AST_ObjectProperty*] array of properties"
  3895. },
  3896. $documentation: "An ES6 class",
  3897. _walk: function(visitor) {
  3898. return visitor._visit(this, function() {
  3899. if (this.name) {
  3900. this.name._walk(visitor);
  3901. }
  3902. if (this.extends) {
  3903. this.extends._walk(visitor);
  3904. }
  3905. this.properties.forEach(function(prop) {
  3906. prop._walk(visitor);
  3907. });
  3908. });
  3909. },
  3910. }, AST_Scope);
  3911. var AST_DefClass = DEFNODE("DefClass", null, {
  3912. $documentation: "A class definition",
  3913. }, AST_Class);
  3914. var AST_ClassExpression = DEFNODE("ClassExpression", null, {
  3915. $documentation: "A class expression."
  3916. }, AST_Class);
  3917. var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
  3918. $propdoc: {
  3919. name: "[string] name of this symbol",
  3920. scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
  3921. thedef: "[SymbolDef/S] the definition of this symbol"
  3922. },
  3923. $documentation: "Base class for all symbols"
  3924. });
  3925. var AST_NewTarget = DEFNODE("NewTarget", null, {
  3926. $documentation: "A reference to new.target"
  3927. });
  3928. var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
  3929. $documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
  3930. }, AST_Symbol);
  3931. var AST_SymbolVar = DEFNODE("SymbolVar", null, {
  3932. $documentation: "Symbol defining a variable",
  3933. }, AST_SymbolDeclaration);
  3934. var AST_SymbolBlockDeclaration = DEFNODE("SymbolBlockDeclaration", null, {
  3935. $documentation: "Base class for block-scoped declaration symbols"
  3936. }, AST_SymbolDeclaration);
  3937. var AST_SymbolConst = DEFNODE("SymbolConst", null, {
  3938. $documentation: "A constant declaration"
  3939. }, AST_SymbolBlockDeclaration);
  3940. var AST_SymbolLet = DEFNODE("SymbolLet", null, {
  3941. $documentation: "A block-scoped `let` declaration"
  3942. }, AST_SymbolBlockDeclaration);
  3943. var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {
  3944. $documentation: "Symbol naming a function argument",
  3945. }, AST_SymbolVar);
  3946. var AST_SymbolDefun = DEFNODE("SymbolDefun", null, {
  3947. $documentation: "Symbol defining a function",
  3948. }, AST_SymbolDeclaration);
  3949. var AST_SymbolMethod = DEFNODE("SymbolMethod", null, {
  3950. $documentation: "Symbol in an object defining a method",
  3951. }, AST_Symbol);
  3952. var AST_SymbolLambda = DEFNODE("SymbolLambda", null, {
  3953. $documentation: "Symbol naming a function expression",
  3954. }, AST_SymbolDeclaration);
  3955. var AST_SymbolDefClass = DEFNODE("SymbolDefClass", null, {
  3956. $documentation: "Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class."
  3957. }, AST_SymbolBlockDeclaration);
  3958. var AST_SymbolClass = DEFNODE("SymbolClass", null, {
  3959. $documentation: "Symbol naming a class's name. Lexically scoped to the class."
  3960. }, AST_SymbolDeclaration);
  3961. var AST_SymbolCatch = DEFNODE("SymbolCatch", null, {
  3962. $documentation: "Symbol naming the exception in catch",
  3963. }, AST_SymbolBlockDeclaration);
  3964. var AST_SymbolImport = DEFNODE("SymbolImport", null, {
  3965. $documentation: "Symbol referring to an imported name",
  3966. }, AST_SymbolBlockDeclaration);
  3967. var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, {
  3968. $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",
  3969. }, AST_Symbol);
  3970. var AST_Label = DEFNODE("Label", "references", {
  3971. $documentation: "Symbol naming a label (declaration)",
  3972. $propdoc: {
  3973. references: "[AST_LoopControl*] a list of nodes referring to this label"
  3974. },
  3975. initialize: function() {
  3976. this.references = [];
  3977. this.thedef = this;
  3978. }
  3979. }, AST_Symbol);
  3980. var AST_SymbolRef = DEFNODE("SymbolRef", null, {
  3981. $documentation: "Reference to some symbol (not definition/declaration)",
  3982. }, AST_Symbol);
  3983. var AST_SymbolExport = DEFNODE("SymbolExport", null, {
  3984. $documentation: "Symbol referring to a name to export",
  3985. }, AST_SymbolRef);
  3986. var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, {
  3987. $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",
  3988. }, AST_Symbol);
  3989. var AST_LabelRef = DEFNODE("LabelRef", null, {
  3990. $documentation: "Reference to a label symbol",
  3991. }, AST_Symbol);
  3992. var AST_This = DEFNODE("This", null, {
  3993. $documentation: "The `this` symbol",
  3994. }, AST_Symbol);
  3995. var AST_Super = DEFNODE("Super", null, {
  3996. $documentation: "The `super` symbol",
  3997. }, AST_This);
  3998. var AST_Constant = DEFNODE("Constant", null, {
  3999. $documentation: "Base class for all constants",
  4000. getValue: function() {
  4001. return this.value;
  4002. }
  4003. });
  4004. var AST_String = DEFNODE("String", "value quote", {
  4005. $documentation: "A string literal",
  4006. $propdoc: {
  4007. value: "[string] the contents of this string",
  4008. quote: "[string] the original quote character"
  4009. }
  4010. }, AST_Constant);
  4011. var AST_Number = DEFNODE("Number", "value literal", {
  4012. $documentation: "A number literal",
  4013. $propdoc: {
  4014. value: "[number] the numeric value",
  4015. literal: "[string] numeric value as string (optional)"
  4016. }
  4017. }, AST_Constant);
  4018. var AST_RegExp = DEFNODE("RegExp", "value", {
  4019. $documentation: "A regexp literal",
  4020. $propdoc: {
  4021. value: "[RegExp] the actual regexp",
  4022. }
  4023. }, AST_Constant);
  4024. var AST_Atom = DEFNODE("Atom", null, {
  4025. $documentation: "Base class for atoms",
  4026. }, AST_Constant);
  4027. var AST_Null = DEFNODE("Null", null, {
  4028. $documentation: "The `null` atom",
  4029. value: null
  4030. }, AST_Atom);
  4031. var AST_NaN = DEFNODE("NaN", null, {
  4032. $documentation: "The impossible value",
  4033. value: 0/0
  4034. }, AST_Atom);
  4035. var AST_Undefined = DEFNODE("Undefined", null, {
  4036. $documentation: "The `undefined` value",
  4037. value: (function() {}())
  4038. }, AST_Atom);
  4039. var AST_Hole = DEFNODE("Hole", null, {
  4040. $documentation: "A hole in an array",
  4041. value: (function() {}())
  4042. }, AST_Atom);
  4043. var AST_Infinity = DEFNODE("Infinity", null, {
  4044. $documentation: "The `Infinity` value",
  4045. value: 1/0
  4046. }, AST_Atom);
  4047. var AST_Boolean = DEFNODE("Boolean", null, {
  4048. $documentation: "Base class for booleans",
  4049. }, AST_Atom);
  4050. var AST_False = DEFNODE("False", null, {
  4051. $documentation: "The `false` atom",
  4052. value: false
  4053. }, AST_Boolean);
  4054. var AST_True = DEFNODE("True", null, {
  4055. $documentation: "The `true` atom",
  4056. value: true
  4057. }, AST_Boolean);
  4058. var AST_Await = DEFNODE("Await", "expression", {
  4059. $documentation: "An `await` statement",
  4060. $propdoc: {
  4061. expression: "[AST_Node] the mandatory expression being awaited",
  4062. },
  4063. _walk: function(visitor) {
  4064. return visitor._visit(this, function() {
  4065. this.expression._walk(visitor);
  4066. });
  4067. }
  4068. });
  4069. var AST_Yield = DEFNODE("Yield", "expression is_star", {
  4070. $documentation: "A `yield` statement",
  4071. $propdoc: {
  4072. expression: "[AST_Node?] the value returned or thrown by this statement; could be null (representing undefined) but only when is_star is set to false",
  4073. is_star: "[Boolean] Whether this is a yield or yield* statement"
  4074. },
  4075. _walk: function(visitor) {
  4076. return visitor._visit(this, this.expression && function() {
  4077. this.expression._walk(visitor);
  4078. });
  4079. }
  4080. });
  4081. /* -----[ TreeWalker ]----- */
  4082. function TreeWalker(callback) {
  4083. this.visit = callback;
  4084. this.stack = [];
  4085. this.directives = Object.create(null);
  4086. }
  4087. TreeWalker.prototype = {
  4088. _visit: function(node, descend) {
  4089. this.push(node);
  4090. var ret = this.visit(node, descend ? function() {
  4091. descend.call(node);
  4092. } : noop);
  4093. if (!ret && descend) {
  4094. descend.call(node);
  4095. }
  4096. this.pop();
  4097. return ret;
  4098. },
  4099. parent: function(n) {
  4100. return this.stack[this.stack.length - 2 - (n || 0)];
  4101. },
  4102. push: function(node) {
  4103. if (node instanceof AST_Lambda) {
  4104. this.directives = Object.create(this.directives);
  4105. } else if (node instanceof AST_Directive && !this.directives[node.value]) {
  4106. this.directives[node.value] = node;
  4107. } else if (node instanceof AST_Class) {
  4108. this.directives = Object.create(this.directives);
  4109. if (!this.directives["use strict"]) {
  4110. this.directives["use strict"] = node;
  4111. }
  4112. }
  4113. this.stack.push(node);
  4114. },
  4115. pop: function() {
  4116. var node = this.stack.pop();
  4117. if (node instanceof AST_Lambda || node instanceof AST_Class) {
  4118. this.directives = Object.getPrototypeOf(this.directives);
  4119. }
  4120. },
  4121. self: function() {
  4122. return this.stack[this.stack.length - 1];
  4123. },
  4124. find_parent: function(type) {
  4125. var stack = this.stack;
  4126. for (var i = stack.length; --i >= 0;) {
  4127. var x = stack[i];
  4128. if (x instanceof type) return x;
  4129. }
  4130. },
  4131. has_directive: function(type) {
  4132. var dir = this.directives[type];
  4133. if (dir) return dir;
  4134. var node = this.stack[this.stack.length - 1];
  4135. if (node instanceof AST_Scope && node.body) {
  4136. for (var i = 0; i < node.body.length; ++i) {
  4137. var st = node.body[i];
  4138. if (!(st instanceof AST_Directive)) break;
  4139. if (st.value == type) return st;
  4140. }
  4141. }
  4142. },
  4143. loopcontrol_target: function(node) {
  4144. var stack = this.stack;
  4145. if (node.label) for (var i = stack.length; --i >= 0;) {
  4146. var x = stack[i];
  4147. if (x instanceof AST_LabeledStatement && x.label.name == node.label.name)
  4148. return x.body;
  4149. } else for (var i = stack.length; --i >= 0;) {
  4150. var x = stack[i];
  4151. if (x instanceof AST_IterationStatement
  4152. || node instanceof AST_Break && x instanceof AST_Switch)
  4153. return x;
  4154. }
  4155. }
  4156. };
  4157. // Tree transformer helpers.
  4158. function TreeTransformer(before, after) {
  4159. TreeWalker.call(this);
  4160. this.before = before;
  4161. this.after = after;
  4162. }
  4163. TreeTransformer.prototype = new TreeWalker;
  4164. var ast = /*#__PURE__*/Object.freeze({
  4165. AST_Accessor: AST_Accessor,
  4166. AST_Array: AST_Array,
  4167. AST_Arrow: AST_Arrow,
  4168. AST_Assign: AST_Assign,
  4169. AST_Atom: AST_Atom,
  4170. AST_Await: AST_Await,
  4171. AST_Binary: AST_Binary,
  4172. AST_Block: AST_Block,
  4173. AST_BlockStatement: AST_BlockStatement,
  4174. AST_Boolean: AST_Boolean,
  4175. AST_Break: AST_Break,
  4176. AST_Call: AST_Call,
  4177. AST_Case: AST_Case,
  4178. AST_Catch: AST_Catch,
  4179. AST_Class: AST_Class,
  4180. AST_ClassExpression: AST_ClassExpression,
  4181. AST_ConciseMethod: AST_ConciseMethod,
  4182. AST_Conditional: AST_Conditional,
  4183. AST_Const: AST_Const,
  4184. AST_Constant: AST_Constant,
  4185. AST_Continue: AST_Continue,
  4186. AST_Debugger: AST_Debugger,
  4187. AST_Default: AST_Default,
  4188. AST_DefaultAssign: AST_DefaultAssign,
  4189. AST_DefClass: AST_DefClass,
  4190. AST_Definitions: AST_Definitions,
  4191. AST_Defun: AST_Defun,
  4192. AST_Destructuring: AST_Destructuring,
  4193. AST_Directive: AST_Directive,
  4194. AST_Do: AST_Do,
  4195. AST_Dot: AST_Dot,
  4196. AST_DWLoop: AST_DWLoop,
  4197. AST_EmptyStatement: AST_EmptyStatement,
  4198. AST_Exit: AST_Exit,
  4199. AST_Expansion: AST_Expansion,
  4200. AST_Export: AST_Export,
  4201. AST_False: AST_False,
  4202. AST_Finally: AST_Finally,
  4203. AST_For: AST_For,
  4204. AST_ForIn: AST_ForIn,
  4205. AST_ForOf: AST_ForOf,
  4206. AST_Function: AST_Function,
  4207. AST_Hole: AST_Hole,
  4208. AST_If: AST_If,
  4209. AST_Import: AST_Import,
  4210. AST_Infinity: AST_Infinity,
  4211. AST_IterationStatement: AST_IterationStatement,
  4212. AST_Jump: AST_Jump,
  4213. AST_Label: AST_Label,
  4214. AST_LabeledStatement: AST_LabeledStatement,
  4215. AST_LabelRef: AST_LabelRef,
  4216. AST_Lambda: AST_Lambda,
  4217. AST_Let: AST_Let,
  4218. AST_LoopControl: AST_LoopControl,
  4219. AST_NameMapping: AST_NameMapping,
  4220. AST_NaN: AST_NaN,
  4221. AST_New: AST_New,
  4222. AST_NewTarget: AST_NewTarget,
  4223. AST_Node: AST_Node,
  4224. AST_Null: AST_Null,
  4225. AST_Number: AST_Number,
  4226. AST_Object: AST_Object,
  4227. AST_ObjectGetter: AST_ObjectGetter,
  4228. AST_ObjectKeyVal: AST_ObjectKeyVal,
  4229. AST_ObjectProperty: AST_ObjectProperty,
  4230. AST_ObjectSetter: AST_ObjectSetter,
  4231. AST_PrefixedTemplateString: AST_PrefixedTemplateString,
  4232. AST_PropAccess: AST_PropAccess,
  4233. AST_RegExp: AST_RegExp,
  4234. AST_Return: AST_Return,
  4235. AST_Scope: AST_Scope,
  4236. AST_Sequence: AST_Sequence,
  4237. AST_SimpleStatement: AST_SimpleStatement,
  4238. AST_Statement: AST_Statement,
  4239. AST_StatementWithBody: AST_StatementWithBody,
  4240. AST_String: AST_String,
  4241. AST_Sub: AST_Sub,
  4242. AST_Super: AST_Super,
  4243. AST_Switch: AST_Switch,
  4244. AST_SwitchBranch: AST_SwitchBranch,
  4245. AST_Symbol: AST_Symbol,
  4246. AST_SymbolBlockDeclaration: AST_SymbolBlockDeclaration,
  4247. AST_SymbolCatch: AST_SymbolCatch,
  4248. AST_SymbolClass: AST_SymbolClass,
  4249. AST_SymbolConst: AST_SymbolConst,
  4250. AST_SymbolDeclaration: AST_SymbolDeclaration,
  4251. AST_SymbolDefClass: AST_SymbolDefClass,
  4252. AST_SymbolDefun: AST_SymbolDefun,
  4253. AST_SymbolExport: AST_SymbolExport,
  4254. AST_SymbolExportForeign: AST_SymbolExportForeign,
  4255. AST_SymbolFunarg: AST_SymbolFunarg,
  4256. AST_SymbolImport: AST_SymbolImport,
  4257. AST_SymbolImportForeign: AST_SymbolImportForeign,
  4258. AST_SymbolLambda: AST_SymbolLambda,
  4259. AST_SymbolLet: AST_SymbolLet,
  4260. AST_SymbolMethod: AST_SymbolMethod,
  4261. AST_SymbolRef: AST_SymbolRef,
  4262. AST_SymbolVar: AST_SymbolVar,
  4263. AST_TemplateSegment: AST_TemplateSegment,
  4264. AST_TemplateString: AST_TemplateString,
  4265. AST_This: AST_This,
  4266. AST_Throw: AST_Throw,
  4267. AST_Token: AST_Token,
  4268. AST_Toplevel: AST_Toplevel,
  4269. AST_True: AST_True,
  4270. AST_Try: AST_Try,
  4271. AST_Unary: AST_Unary,
  4272. AST_UnaryPostfix: AST_UnaryPostfix,
  4273. AST_UnaryPrefix: AST_UnaryPrefix,
  4274. AST_Undefined: AST_Undefined,
  4275. AST_Var: AST_Var,
  4276. AST_VarDef: AST_VarDef,
  4277. AST_While: AST_While,
  4278. AST_With: AST_With,
  4279. AST_Yield: AST_Yield,
  4280. TreeTransformer: TreeTransformer,
  4281. TreeWalker: TreeWalker,
  4282. walk_body: walk_body
  4283. });
  4284. /***********************************************************************
  4285. A JavaScript tokenizer / parser / beautifier / compressor.
  4286. https://github.com/mishoo/UglifyJS2
  4287. -------------------------------- (C) ---------------------------------
  4288. Author: Mihai Bazon
  4289. <mihai.bazon@gmail.com>
  4290. http://mihai.bazon.net/blog
  4291. Distributed under the BSD license:
  4292. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  4293. Redistribution and use in source and binary forms, with or without
  4294. modification, are permitted provided that the following conditions
  4295. are met:
  4296. * Redistributions of source code must retain the above
  4297. copyright notice, this list of conditions and the following
  4298. disclaimer.
  4299. * Redistributions in binary form must reproduce the above
  4300. copyright notice, this list of conditions and the following
  4301. disclaimer in the documentation and/or other materials
  4302. provided with the distribution.
  4303. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  4304. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  4305. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  4306. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  4307. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  4308. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  4309. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  4310. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  4311. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  4312. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  4313. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  4314. SUCH DAMAGE.
  4315. ***********************************************************************/
  4316. (function(undefined) {
  4317. function _(node, descend) {
  4318. node.DEFMETHOD("transform", function(tw, in_list) {
  4319. var x, y;
  4320. tw.push(this);
  4321. if (tw.before) x = tw.before(this, descend, in_list);
  4322. if (x === undefined) {
  4323. x = this;
  4324. descend(x, tw);
  4325. if (tw.after) {
  4326. y = tw.after(x, in_list);
  4327. if (y !== undefined) x = y;
  4328. }
  4329. }
  4330. tw.pop();
  4331. return x;
  4332. });
  4333. }
  4334. function do_list(list, tw) {
  4335. return MAP(list, function(node) {
  4336. return node.transform(tw, true);
  4337. });
  4338. }
  4339. _(AST_Node, noop);
  4340. _(AST_LabeledStatement, function(self, tw) {
  4341. self.label = self.label.transform(tw);
  4342. self.body = self.body.transform(tw);
  4343. });
  4344. _(AST_SimpleStatement, function(self, tw) {
  4345. self.body = self.body.transform(tw);
  4346. });
  4347. _(AST_Block, function(self, tw) {
  4348. self.body = do_list(self.body, tw);
  4349. });
  4350. _(AST_Do, function(self, tw) {
  4351. self.body = self.body.transform(tw);
  4352. self.condition = self.condition.transform(tw);
  4353. });
  4354. _(AST_While, function(self, tw) {
  4355. self.condition = self.condition.transform(tw);
  4356. self.body = self.body.transform(tw);
  4357. });
  4358. _(AST_For, function(self, tw) {
  4359. if (self.init) self.init = self.init.transform(tw);
  4360. if (self.condition) self.condition = self.condition.transform(tw);
  4361. if (self.step) self.step = self.step.transform(tw);
  4362. self.body = self.body.transform(tw);
  4363. });
  4364. _(AST_ForIn, function(self, tw) {
  4365. self.init = self.init.transform(tw);
  4366. self.object = self.object.transform(tw);
  4367. self.body = self.body.transform(tw);
  4368. });
  4369. _(AST_With, function(self, tw) {
  4370. self.expression = self.expression.transform(tw);
  4371. self.body = self.body.transform(tw);
  4372. });
  4373. _(AST_Exit, function(self, tw) {
  4374. if (self.value) self.value = self.value.transform(tw);
  4375. });
  4376. _(AST_LoopControl, function(self, tw) {
  4377. if (self.label) self.label = self.label.transform(tw);
  4378. });
  4379. _(AST_If, function(self, tw) {
  4380. self.condition = self.condition.transform(tw);
  4381. self.body = self.body.transform(tw);
  4382. if (self.alternative) self.alternative = self.alternative.transform(tw);
  4383. });
  4384. _(AST_Switch, function(self, tw) {
  4385. self.expression = self.expression.transform(tw);
  4386. self.body = do_list(self.body, tw);
  4387. });
  4388. _(AST_Case, function(self, tw) {
  4389. self.expression = self.expression.transform(tw);
  4390. self.body = do_list(self.body, tw);
  4391. });
  4392. _(AST_Try, function(self, tw) {
  4393. self.body = do_list(self.body, tw);
  4394. if (self.bcatch) self.bcatch = self.bcatch.transform(tw);
  4395. if (self.bfinally) self.bfinally = self.bfinally.transform(tw);
  4396. });
  4397. _(AST_Catch, function(self, tw) {
  4398. if (self.argname) self.argname = self.argname.transform(tw);
  4399. self.body = do_list(self.body, tw);
  4400. });
  4401. _(AST_Definitions, function(self, tw) {
  4402. self.definitions = do_list(self.definitions, tw);
  4403. });
  4404. _(AST_VarDef, function(self, tw) {
  4405. self.name = self.name.transform(tw);
  4406. if (self.value) self.value = self.value.transform(tw);
  4407. });
  4408. _(AST_Destructuring, function(self, tw) {
  4409. self.names = do_list(self.names, tw);
  4410. });
  4411. _(AST_Lambda, function(self, tw) {
  4412. if (self.name) self.name = self.name.transform(tw);
  4413. self.argnames = do_list(self.argnames, tw);
  4414. if (self.body instanceof AST_Node) {
  4415. self.body = self.body.transform(tw);
  4416. } else {
  4417. self.body = do_list(self.body, tw);
  4418. }
  4419. });
  4420. _(AST_Call, function(self, tw) {
  4421. self.expression = self.expression.transform(tw);
  4422. self.args = do_list(self.args, tw);
  4423. });
  4424. _(AST_Sequence, function(self, tw) {
  4425. self.expressions = do_list(self.expressions, tw);
  4426. });
  4427. _(AST_Dot, function(self, tw) {
  4428. self.expression = self.expression.transform(tw);
  4429. });
  4430. _(AST_Sub, function(self, tw) {
  4431. self.expression = self.expression.transform(tw);
  4432. self.property = self.property.transform(tw);
  4433. });
  4434. _(AST_Yield, function(self, tw) {
  4435. if (self.expression) self.expression = self.expression.transform(tw);
  4436. });
  4437. _(AST_Await, function(self, tw) {
  4438. self.expression = self.expression.transform(tw);
  4439. });
  4440. _(AST_Unary, function(self, tw) {
  4441. self.expression = self.expression.transform(tw);
  4442. });
  4443. _(AST_Binary, function(self, tw) {
  4444. self.left = self.left.transform(tw);
  4445. self.right = self.right.transform(tw);
  4446. });
  4447. _(AST_Conditional, function(self, tw) {
  4448. self.condition = self.condition.transform(tw);
  4449. self.consequent = self.consequent.transform(tw);
  4450. self.alternative = self.alternative.transform(tw);
  4451. });
  4452. _(AST_Array, function(self, tw) {
  4453. self.elements = do_list(self.elements, tw);
  4454. });
  4455. _(AST_Object, function(self, tw) {
  4456. self.properties = do_list(self.properties, tw);
  4457. });
  4458. _(AST_ObjectProperty, function(self, tw) {
  4459. if (self.key instanceof AST_Node) {
  4460. self.key = self.key.transform(tw);
  4461. }
  4462. self.value = self.value.transform(tw);
  4463. });
  4464. _(AST_Class, function(self, tw) {
  4465. if (self.name) self.name = self.name.transform(tw);
  4466. if (self.extends) self.extends = self.extends.transform(tw);
  4467. self.properties = do_list(self.properties, tw);
  4468. });
  4469. _(AST_Expansion, function(self, tw) {
  4470. self.expression = self.expression.transform(tw);
  4471. });
  4472. _(AST_NameMapping, function(self, tw) {
  4473. self.foreign_name = self.foreign_name.transform(tw);
  4474. self.name = self.name.transform(tw);
  4475. });
  4476. _(AST_Import, function(self, tw) {
  4477. if (self.imported_name) self.imported_name = self.imported_name.transform(tw);
  4478. if (self.imported_names) do_list(self.imported_names, tw);
  4479. self.module_name = self.module_name.transform(tw);
  4480. });
  4481. _(AST_Export, function(self, tw) {
  4482. if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw);
  4483. if (self.exported_value) self.exported_value = self.exported_value.transform(tw);
  4484. if (self.exported_names) do_list(self.exported_names, tw);
  4485. if (self.module_name) self.module_name = self.module_name.transform(tw);
  4486. });
  4487. _(AST_TemplateString, function(self, tw) {
  4488. self.segments = do_list(self.segments, tw);
  4489. });
  4490. _(AST_PrefixedTemplateString, function(self, tw) {
  4491. self.prefix = self.prefix.transform(tw);
  4492. self.template_string = self.template_string.transform(tw);
  4493. });
  4494. })();
  4495. /***********************************************************************
  4496. A JavaScript tokenizer / parser / beautifier / compressor.
  4497. https://github.com/mishoo/UglifyJS2
  4498. -------------------------------- (C) ---------------------------------
  4499. Author: Mihai Bazon
  4500. <mihai.bazon@gmail.com>
  4501. http://mihai.bazon.net/blog
  4502. Distributed under the BSD license:
  4503. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  4504. Redistribution and use in source and binary forms, with or without
  4505. modification, are permitted provided that the following conditions
  4506. are met:
  4507. * Redistributions of source code must retain the above
  4508. copyright notice, this list of conditions and the following
  4509. disclaimer.
  4510. * Redistributions in binary form must reproduce the above
  4511. copyright notice, this list of conditions and the following
  4512. disclaimer in the documentation and/or other materials
  4513. provided with the distribution.
  4514. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  4515. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  4516. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  4517. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  4518. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  4519. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  4520. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  4521. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  4522. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  4523. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  4524. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  4525. SUCH DAMAGE.
  4526. ***********************************************************************/
  4527. var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
  4528. function is_some_comments(comment) {
  4529. // multiline comment
  4530. return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value);
  4531. }
  4532. function OutputStream(options) {
  4533. var readonly = !options;
  4534. options = defaults(options, {
  4535. ascii_only : false,
  4536. beautify : false,
  4537. braces : false,
  4538. comments : false,
  4539. ecma : 5,
  4540. ie8 : false,
  4541. indent_level : 4,
  4542. indent_start : 0,
  4543. inline_script : true,
  4544. keep_quoted_props: false,
  4545. max_line_len : false,
  4546. preamble : null,
  4547. quote_keys : false,
  4548. quote_style : 0,
  4549. safari10 : false,
  4550. semicolons : true,
  4551. shebang : true,
  4552. shorthand : undefined,
  4553. source_map : null,
  4554. webkit : false,
  4555. width : 80,
  4556. wrap_iife : false,
  4557. }, true);
  4558. if (options.shorthand === undefined)
  4559. options.shorthand = options.ecma > 5;
  4560. // Convert comment option to RegExp if neccessary and set up comments filter
  4561. var comment_filter = return_false; // Default case, throw all comments away
  4562. if (options.comments) {
  4563. var comments = options.comments;
  4564. if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
  4565. var regex_pos = options.comments.lastIndexOf("/");
  4566. comments = new RegExp(
  4567. options.comments.substr(1, regex_pos - 1),
  4568. options.comments.substr(regex_pos + 1)
  4569. );
  4570. }
  4571. if (comments instanceof RegExp) {
  4572. comment_filter = function(comment) {
  4573. return comment.type != "comment5" && comments.test(comment.value);
  4574. };
  4575. } else if (typeof comments === "function") {
  4576. comment_filter = function(comment) {
  4577. return comment.type != "comment5" && comments(this, comment);
  4578. };
  4579. } else if (comments === "some") {
  4580. comment_filter = is_some_comments;
  4581. } else { // NOTE includes "all" option
  4582. comment_filter = return_true;
  4583. }
  4584. }
  4585. var indentation = 0;
  4586. var current_col = 0;
  4587. var current_line = 1;
  4588. var current_pos = 0;
  4589. var OUTPUT = "";
  4590. var to_utf8 = options.ascii_only ? function(str, identifier) {
  4591. if (options.ecma >= 6) {
  4592. str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {
  4593. var code = get_full_char_code(ch, 0).toString(16);
  4594. return "\\u{" + code + "}";
  4595. });
  4596. }
  4597. return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
  4598. var code = ch.charCodeAt(0).toString(16);
  4599. if (code.length <= 2 && !identifier) {
  4600. while (code.length < 2) code = "0" + code;
  4601. return "\\x" + code;
  4602. } else {
  4603. while (code.length < 4) code = "0" + code;
  4604. return "\\u" + code;
  4605. }
  4606. });
  4607. } : function(str) {
  4608. var s = "";
  4609. for (var i = 0, len = str.length; i < len; i++) {
  4610. if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
  4611. || is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
  4612. s += "\\u" + str.charCodeAt(i).toString(16);
  4613. } else {
  4614. s += str[i];
  4615. }
  4616. }
  4617. return s;
  4618. };
  4619. function make_string(str, quote) {
  4620. var dq = 0, sq = 0;
  4621. str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,
  4622. function(s, i) {
  4623. switch (s) {
  4624. case '"': ++dq; return '"';
  4625. case "'": ++sq; return "'";
  4626. case "\\": return "\\\\";
  4627. case "\n": return "\\n";
  4628. case "\r": return "\\r";
  4629. case "\t": return "\\t";
  4630. case "\b": return "\\b";
  4631. case "\f": return "\\f";
  4632. case "\x0B": return options.ie8 ? "\\x0B" : "\\v";
  4633. case "\u2028": return "\\u2028";
  4634. case "\u2029": return "\\u2029";
  4635. case "\ufeff": return "\\ufeff";
  4636. case "\0":
  4637. return /[0-9]/.test(get_full_char(str, i+1)) ? "\\x00" : "\\0";
  4638. }
  4639. return s;
  4640. });
  4641. function quote_single() {
  4642. return "'" + str.replace(/\x27/g, "\\'") + "'";
  4643. }
  4644. function quote_double() {
  4645. return '"' + str.replace(/\x22/g, '\\"') + '"';
  4646. }
  4647. function quote_template() {
  4648. return "`" + str.replace(/`/g, "\\`") + "`";
  4649. }
  4650. str = to_utf8(str);
  4651. if (quote === "`") return quote_template();
  4652. switch (options.quote_style) {
  4653. case 1:
  4654. return quote_single();
  4655. case 2:
  4656. return quote_double();
  4657. case 3:
  4658. return quote == "'" ? quote_single() : quote_double();
  4659. default:
  4660. return dq > sq ? quote_single() : quote_double();
  4661. }
  4662. }
  4663. function encode_string(str, quote) {
  4664. var ret = make_string(str, quote);
  4665. if (options.inline_script) {
  4666. ret = ret.replace(/<\x2f(script)([>\/\t\n\f\r ])/gi, "<\\/$1$2");
  4667. ret = ret.replace(/\x3c!--/g, "\\x3c!--");
  4668. ret = ret.replace(/--\x3e/g, "--\\x3e");
  4669. }
  4670. return ret;
  4671. }
  4672. function make_name(name) {
  4673. name = name.toString();
  4674. name = to_utf8(name, true);
  4675. return name;
  4676. }
  4677. function make_indent(back) {
  4678. return repeat_string(" ", options.indent_start + indentation - back * options.indent_level);
  4679. }
  4680. /* -----[ beautification/minification ]----- */
  4681. var has_parens = false;
  4682. var might_need_space = false;
  4683. var might_need_semicolon = false;
  4684. var might_add_newline = 0;
  4685. var need_newline_indented = false;
  4686. var need_space = false;
  4687. var newline_insert = -1;
  4688. var last = "";
  4689. var mapping_token, mapping_name, mappings = options.source_map && [];
  4690. var do_add_mapping = mappings ? function() {
  4691. mappings.forEach(function(mapping) {
  4692. try {
  4693. options.source_map.add(
  4694. mapping.token.file,
  4695. mapping.line, mapping.col,
  4696. mapping.token.line, mapping.token.col,
  4697. !mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
  4698. );
  4699. } catch(ex) {
  4700. mapping.token.file != null && AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
  4701. file: mapping.token.file,
  4702. line: mapping.token.line,
  4703. col: mapping.token.col,
  4704. cline: mapping.line,
  4705. ccol: mapping.col,
  4706. name: mapping.name || ""
  4707. });
  4708. }
  4709. });
  4710. mappings = [];
  4711. } : noop;
  4712. var ensure_line_len = options.max_line_len ? function() {
  4713. if (current_col > options.max_line_len) {
  4714. if (might_add_newline) {
  4715. var left = OUTPUT.slice(0, might_add_newline);
  4716. var right = OUTPUT.slice(might_add_newline);
  4717. if (mappings) {
  4718. var delta = right.length - current_col;
  4719. mappings.forEach(function(mapping) {
  4720. mapping.line++;
  4721. mapping.col += delta;
  4722. });
  4723. }
  4724. OUTPUT = left + "\n" + right;
  4725. current_line++;
  4726. current_pos++;
  4727. current_col = right.length;
  4728. }
  4729. if (current_col > options.max_line_len) {
  4730. AST_Node.warn("Output exceeds {max_line_len} characters", options);
  4731. }
  4732. }
  4733. if (might_add_newline) {
  4734. might_add_newline = 0;
  4735. do_add_mapping();
  4736. }
  4737. } : noop;
  4738. var requireSemicolonChars = makePredicate("( [ + * / - , . `");
  4739. function print(str) {
  4740. str = String(str);
  4741. var ch = get_full_char(str, 0);
  4742. if (need_newline_indented && ch) {
  4743. need_newline_indented = false;
  4744. if (ch !== "\n") {
  4745. print("\n");
  4746. indent();
  4747. }
  4748. }
  4749. if (need_space && ch) {
  4750. need_space = false;
  4751. if (!/[\s;})]/.test(ch)) {
  4752. space();
  4753. }
  4754. }
  4755. newline_insert = -1;
  4756. var prev = last.charAt(last.length - 1);
  4757. if (might_need_semicolon) {
  4758. might_need_semicolon = false;
  4759. if (prev === ":" && ch === "}" || (!ch || !";}".includes(ch)) && prev !== ";") {
  4760. if (options.semicolons || requireSemicolonChars(ch)) {
  4761. OUTPUT += ";";
  4762. current_col++;
  4763. current_pos++;
  4764. } else {
  4765. ensure_line_len();
  4766. OUTPUT += "\n";
  4767. current_pos++;
  4768. current_line++;
  4769. current_col = 0;
  4770. if (/^\s+$/.test(str)) {
  4771. // reset the semicolon flag, since we didn't print one
  4772. // now and might still have to later
  4773. might_need_semicolon = true;
  4774. }
  4775. }
  4776. if (!options.beautify)
  4777. might_need_space = false;
  4778. }
  4779. }
  4780. if (might_need_space) {
  4781. if ((is_identifier_char(prev)
  4782. && (is_identifier_char(ch) || ch == "\\"))
  4783. || (ch == "/" && ch == prev)
  4784. || ((ch == "+" || ch == "-") && ch == last)
  4785. ) {
  4786. OUTPUT += " ";
  4787. current_col++;
  4788. current_pos++;
  4789. }
  4790. might_need_space = false;
  4791. }
  4792. if (mapping_token) {
  4793. mappings.push({
  4794. token: mapping_token,
  4795. name: mapping_name,
  4796. line: current_line,
  4797. col: current_col
  4798. });
  4799. mapping_token = false;
  4800. if (!might_add_newline) do_add_mapping();
  4801. }
  4802. OUTPUT += str;
  4803. has_parens = str[str.length - 1] == "(";
  4804. current_pos += str.length;
  4805. var a = str.split(/\r?\n/), n = a.length - 1;
  4806. current_line += n;
  4807. current_col += a[0].length;
  4808. if (n > 0) {
  4809. ensure_line_len();
  4810. current_col = a[n].length;
  4811. }
  4812. last = str;
  4813. }
  4814. var star = function() {
  4815. print("*");
  4816. };
  4817. var space = options.beautify ? function() {
  4818. print(" ");
  4819. } : function() {
  4820. might_need_space = true;
  4821. };
  4822. var indent = options.beautify ? function(half) {
  4823. if (options.beautify) {
  4824. print(make_indent(half ? 0.5 : 0));
  4825. }
  4826. } : noop;
  4827. var with_indent = options.beautify ? function(col, cont) {
  4828. if (col === true) col = next_indent();
  4829. var save_indentation = indentation;
  4830. indentation = col;
  4831. var ret = cont();
  4832. indentation = save_indentation;
  4833. return ret;
  4834. } : function(col, cont) { return cont(); };
  4835. var newline = options.beautify ? function() {
  4836. if (newline_insert < 0) return print("\n");
  4837. if (OUTPUT[newline_insert] != "\n") {
  4838. OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert);
  4839. current_pos++;
  4840. current_line++;
  4841. }
  4842. newline_insert++;
  4843. } : options.max_line_len ? function() {
  4844. ensure_line_len();
  4845. might_add_newline = OUTPUT.length;
  4846. } : noop;
  4847. var semicolon = options.beautify ? function() {
  4848. print(";");
  4849. } : function() {
  4850. might_need_semicolon = true;
  4851. };
  4852. function force_semicolon() {
  4853. might_need_semicolon = false;
  4854. print(";");
  4855. }
  4856. function next_indent() {
  4857. return indentation + options.indent_level;
  4858. }
  4859. function with_block(cont) {
  4860. var ret;
  4861. print("{");
  4862. newline();
  4863. with_indent(next_indent(), function() {
  4864. ret = cont();
  4865. });
  4866. indent();
  4867. print("}");
  4868. return ret;
  4869. }
  4870. function with_parens(cont) {
  4871. print("(");
  4872. //XXX: still nice to have that for argument lists
  4873. //var ret = with_indent(current_col, cont);
  4874. var ret = cont();
  4875. print(")");
  4876. return ret;
  4877. }
  4878. function with_square(cont) {
  4879. print("[");
  4880. //var ret = with_indent(current_col, cont);
  4881. var ret = cont();
  4882. print("]");
  4883. return ret;
  4884. }
  4885. function comma() {
  4886. print(",");
  4887. space();
  4888. }
  4889. function colon() {
  4890. print(":");
  4891. space();
  4892. }
  4893. var add_mapping = mappings ? function(token, name) {
  4894. mapping_token = token;
  4895. mapping_name = name;
  4896. } : noop;
  4897. function get() {
  4898. if (might_add_newline) {
  4899. ensure_line_len();
  4900. }
  4901. return OUTPUT;
  4902. }
  4903. function has_nlb() {
  4904. var index = OUTPUT.lastIndexOf("\n");
  4905. return /^ *$/.test(OUTPUT.slice(index + 1));
  4906. }
  4907. function prepend_comments(node) {
  4908. var self = this;
  4909. var start = node.start;
  4910. if (!start) return;
  4911. if (start.comments_before && start.comments_before._dumped === self) return;
  4912. var comments = start.comments_before;
  4913. if (!comments) {
  4914. comments = start.comments_before = [];
  4915. }
  4916. comments._dumped = self;
  4917. if (node instanceof AST_Exit && node.value) {
  4918. var tw = new TreeWalker(function(node) {
  4919. var parent = tw.parent();
  4920. if (parent instanceof AST_Exit
  4921. || parent instanceof AST_Binary && parent.left === node
  4922. || parent.TYPE == "Call" && parent.expression === node
  4923. || parent instanceof AST_Conditional && parent.condition === node
  4924. || parent instanceof AST_Dot && parent.expression === node
  4925. || parent instanceof AST_Sequence && parent.expressions[0] === node
  4926. || parent instanceof AST_Sub && parent.expression === node
  4927. || parent instanceof AST_UnaryPostfix) {
  4928. if (!node.start) return;
  4929. var text = node.start.comments_before;
  4930. if (text && text._dumped !== self) {
  4931. text._dumped = self;
  4932. comments = comments.concat(text);
  4933. }
  4934. } else {
  4935. return true;
  4936. }
  4937. });
  4938. tw.push(node);
  4939. node.value.walk(tw);
  4940. }
  4941. if (current_pos == 0) {
  4942. if (comments.length > 0 && options.shebang && comments[0].type == "comment5") {
  4943. print("#!" + comments.shift().value + "\n");
  4944. indent();
  4945. }
  4946. var preamble = options.preamble;
  4947. if (preamble) {
  4948. print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
  4949. }
  4950. }
  4951. comments = comments.filter(comment_filter, node);
  4952. if (comments.length == 0) return;
  4953. var last_nlb = has_nlb();
  4954. comments.forEach(function(c, i) {
  4955. if (!last_nlb) {
  4956. if (c.nlb) {
  4957. print("\n");
  4958. indent();
  4959. last_nlb = true;
  4960. } else if (i > 0) {
  4961. space();
  4962. }
  4963. }
  4964. if (/comment[134]/.test(c.type)) {
  4965. print("//" + c.value.replace(/[@#]__PURE__/g, " ") + "\n");
  4966. indent();
  4967. last_nlb = true;
  4968. } else if (c.type == "comment2") {
  4969. print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/");
  4970. last_nlb = false;
  4971. }
  4972. });
  4973. if (!last_nlb) {
  4974. if (start.nlb) {
  4975. print("\n");
  4976. indent();
  4977. } else {
  4978. space();
  4979. }
  4980. }
  4981. }
  4982. function append_comments(node, tail) {
  4983. var self = this;
  4984. var token = node.end;
  4985. if (!token) return;
  4986. var comments = token[tail ? "comments_before" : "comments_after"];
  4987. if (!comments || comments._dumped === self) return;
  4988. if (!(node instanceof AST_Statement || all(comments, function(c) {
  4989. return !/comment[134]/.test(c.type);
  4990. }))) return;
  4991. comments._dumped = self;
  4992. var insert = OUTPUT.length;
  4993. comments.filter(comment_filter, node).forEach(function(c, i) {
  4994. need_space = false;
  4995. if (need_newline_indented) {
  4996. print("\n");
  4997. indent();
  4998. need_newline_indented = false;
  4999. } else if (c.nlb && (i > 0 || !has_nlb())) {
  5000. print("\n");
  5001. indent();
  5002. } else if (i > 0 || !tail) {
  5003. space();
  5004. }
  5005. if (/comment[134]/.test(c.type)) {
  5006. print("//" + c.value.replace(/[@#]__PURE__/g, " "));
  5007. need_newline_indented = true;
  5008. } else if (c.type == "comment2") {
  5009. print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/");
  5010. need_space = true;
  5011. }
  5012. });
  5013. if (OUTPUT.length > insert) newline_insert = insert;
  5014. }
  5015. var stack = [];
  5016. return {
  5017. get : get,
  5018. toString : get,
  5019. indent : indent,
  5020. indentation : function() { return indentation; },
  5021. current_width : function() { return current_col - indentation; },
  5022. should_break : function() { return options.width && this.current_width() >= options.width; },
  5023. has_parens : function() { return has_parens; },
  5024. newline : newline,
  5025. print : print,
  5026. star : star,
  5027. space : space,
  5028. comma : comma,
  5029. colon : colon,
  5030. last : function() { return last; },
  5031. semicolon : semicolon,
  5032. force_semicolon : force_semicolon,
  5033. to_utf8 : to_utf8,
  5034. print_name : function(name) { print(make_name(name)); },
  5035. print_string : function(str, quote, escape_directive) {
  5036. var encoded = encode_string(str, quote);
  5037. if (escape_directive === true && !encoded.includes("\\")) {
  5038. // Insert semicolons to break directive prologue
  5039. if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
  5040. force_semicolon();
  5041. }
  5042. force_semicolon();
  5043. }
  5044. print(encoded);
  5045. },
  5046. print_template_string_chars: function(str) {
  5047. var encoded = encode_string(str, "`").replace(/\${/g, "\\${");
  5048. return print(encoded.substr(1, encoded.length - 2));
  5049. },
  5050. encode_string : encode_string,
  5051. next_indent : next_indent,
  5052. with_indent : with_indent,
  5053. with_block : with_block,
  5054. with_parens : with_parens,
  5055. with_square : with_square,
  5056. add_mapping : add_mapping,
  5057. option : function(opt) { return options[opt]; },
  5058. prepend_comments: readonly ? noop : prepend_comments,
  5059. append_comments : readonly || comment_filter === return_false ? noop : append_comments,
  5060. line : function() { return current_line; },
  5061. col : function() { return current_col; },
  5062. pos : function() { return current_pos; },
  5063. push_node : function(node) { stack.push(node); },
  5064. pop_node : function() { return stack.pop(); },
  5065. parent : function(n) {
  5066. return stack[stack.length - 2 - (n || 0)];
  5067. }
  5068. };
  5069. }
  5070. /* -----[ code generators ]----- */
  5071. (function() {
  5072. /* -----[ utils ]----- */
  5073. function DEFPRINT(nodetype, generator) {
  5074. nodetype.DEFMETHOD("_codegen", generator);
  5075. }
  5076. var in_directive = false;
  5077. var active_scope = null;
  5078. var use_asm = null;
  5079. AST_Node.DEFMETHOD("print", function(stream, force_parens) {
  5080. var self = this, generator = self._codegen;
  5081. if (self instanceof AST_Scope) {
  5082. active_scope = self;
  5083. } else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
  5084. use_asm = active_scope;
  5085. }
  5086. function doit() {
  5087. stream.prepend_comments(self);
  5088. self.add_source_map(stream);
  5089. generator(self, stream);
  5090. stream.append_comments(self);
  5091. }
  5092. stream.push_node(self);
  5093. if (force_parens || self.needs_parens(stream)) {
  5094. stream.with_parens(doit);
  5095. } else {
  5096. doit();
  5097. }
  5098. stream.pop_node();
  5099. if (self === use_asm) {
  5100. use_asm = null;
  5101. }
  5102. });
  5103. AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
  5104. AST_Node.DEFMETHOD("print_to_string", function(options) {
  5105. var s = OutputStream(options);
  5106. this.print(s);
  5107. return s.get();
  5108. });
  5109. /* -----[ PARENTHESES ]----- */
  5110. function PARENS(nodetype, func) {
  5111. if (Array.isArray(nodetype)) {
  5112. nodetype.forEach(function(nodetype) {
  5113. PARENS(nodetype, func);
  5114. });
  5115. } else {
  5116. nodetype.DEFMETHOD("needs_parens", func);
  5117. }
  5118. }
  5119. PARENS(AST_Node, return_false);
  5120. // a function expression needs parens around it when it's provably
  5121. // the first token to appear in a statement.
  5122. PARENS(AST_Function, function(output) {
  5123. if (!output.has_parens() && first_in_statement(output)) {
  5124. return true;
  5125. }
  5126. if (output.option("webkit")) {
  5127. var p = output.parent();
  5128. if (p instanceof AST_PropAccess && p.expression === this) {
  5129. return true;
  5130. }
  5131. }
  5132. if (output.option("wrap_iife")) {
  5133. var p = output.parent();
  5134. return p instanceof AST_Call && p.expression === this;
  5135. }
  5136. return false;
  5137. });
  5138. PARENS(AST_Arrow, function(output) {
  5139. var p = output.parent();
  5140. return p instanceof AST_PropAccess && p.expression === this;
  5141. });
  5142. // same goes for an object literal, because otherwise it would be
  5143. // interpreted as a block of code.
  5144. PARENS(AST_Object, function(output) {
  5145. return !output.has_parens() && first_in_statement(output);
  5146. });
  5147. PARENS(AST_ClassExpression, first_in_statement);
  5148. PARENS(AST_Unary, function(output) {
  5149. var p = output.parent();
  5150. return p instanceof AST_PropAccess && p.expression === this
  5151. || p instanceof AST_Call && p.expression === this
  5152. || p instanceof AST_Binary
  5153. && p.operator === "**"
  5154. && this instanceof AST_UnaryPrefix
  5155. && p.left === this
  5156. && this.operator !== "++"
  5157. && this.operator !== "--";
  5158. });
  5159. PARENS(AST_Await, function(output) {
  5160. var p = output.parent();
  5161. return p instanceof AST_PropAccess && p.expression === this
  5162. || p instanceof AST_Call && p.expression === this
  5163. || output.option("safari10") && p instanceof AST_UnaryPrefix;
  5164. });
  5165. PARENS(AST_Sequence, function(output) {
  5166. var p = output.parent();
  5167. return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
  5168. || p instanceof AST_Unary // !(foo, bar, baz)
  5169. || p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
  5170. || p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
  5171. || p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
  5172. || p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
  5173. || p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
  5174. || p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
  5175. * ==> 20 (side effect, set a := 10 and b := 20) */
  5176. || p instanceof AST_Arrow // x => (x, x)
  5177. || p instanceof AST_DefaultAssign // x => (x = (0, function(){}))
  5178. || p instanceof AST_Expansion // [...(a, b)]
  5179. || p instanceof AST_ForOf && this === p.object // for (e of (foo, bar)) {}
  5180. || p instanceof AST_Yield // yield (foo, bar)
  5181. || p instanceof AST_Export // export default (foo, bar)
  5182. ;
  5183. });
  5184. PARENS(AST_Binary, function(output) {
  5185. var p = output.parent();
  5186. // (foo && bar)()
  5187. if (p instanceof AST_Call && p.expression === this)
  5188. return true;
  5189. // typeof (foo && bar)
  5190. if (p instanceof AST_Unary)
  5191. return true;
  5192. // (foo && bar)["prop"], (foo && bar).prop
  5193. if (p instanceof AST_PropAccess && p.expression === this)
  5194. return true;
  5195. // this deals with precedence: 3 * (2 + 1)
  5196. if (p instanceof AST_Binary) {
  5197. var po = p.operator, pp = PRECEDENCE[po];
  5198. var so = this.operator, sp = PRECEDENCE[so];
  5199. if (pp > sp
  5200. || (pp == sp
  5201. && (this === p.right || po == "**"))) {
  5202. return true;
  5203. }
  5204. }
  5205. });
  5206. PARENS(AST_Yield, function(output) {
  5207. var p = output.parent();
  5208. // (yield 1) + (yield 2)
  5209. // a = yield 3
  5210. if (p instanceof AST_Binary && p.operator !== "=")
  5211. return true;
  5212. // (yield 1)()
  5213. // new (yield 1)()
  5214. if (p instanceof AST_Call && p.expression === this)
  5215. return true;
  5216. // (yield 1) ? yield 2 : yield 3
  5217. if (p instanceof AST_Conditional && p.condition === this)
  5218. return true;
  5219. // -(yield 4)
  5220. if (p instanceof AST_Unary)
  5221. return true;
  5222. // (yield x).foo
  5223. // (yield x)['foo']
  5224. if (p instanceof AST_PropAccess && p.expression === this)
  5225. return true;
  5226. });
  5227. PARENS(AST_PropAccess, function(output) {
  5228. var p = output.parent();
  5229. if (p instanceof AST_New && p.expression === this) {
  5230. // i.e. new (foo.bar().baz)
  5231. //
  5232. // if there's one call into this subtree, then we need
  5233. // parens around it too, otherwise the call will be
  5234. // interpreted as passing the arguments to the upper New
  5235. // expression.
  5236. var parens = false;
  5237. this.walk(new TreeWalker(function(node) {
  5238. if (parens || node instanceof AST_Scope) return true;
  5239. if (node instanceof AST_Call) {
  5240. parens = true;
  5241. return true;
  5242. }
  5243. }));
  5244. return parens;
  5245. }
  5246. });
  5247. PARENS(AST_Call, function(output) {
  5248. var p = output.parent(), p1;
  5249. if (p instanceof AST_New && p.expression === this
  5250. || p instanceof AST_Export && p.is_default && this.expression instanceof AST_Function)
  5251. return true;
  5252. // workaround for Safari bug.
  5253. // https://bugs.webkit.org/show_bug.cgi?id=123506
  5254. return this.expression instanceof AST_Function
  5255. && p instanceof AST_PropAccess
  5256. && p.expression === this
  5257. && (p1 = output.parent(1)) instanceof AST_Assign
  5258. && p1.left === p;
  5259. });
  5260. PARENS(AST_New, function(output) {
  5261. var p = output.parent();
  5262. if (!need_constructor_parens(this, output)
  5263. && (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]()
  5264. || p instanceof AST_Call && p.expression === this)) // (new foo)(bar)
  5265. return true;
  5266. });
  5267. PARENS(AST_Number, function(output) {
  5268. var p = output.parent();
  5269. if (p instanceof AST_PropAccess && p.expression === this) {
  5270. var value = this.getValue();
  5271. if (value < 0 || /^0/.test(make_num(value))) {
  5272. return true;
  5273. }
  5274. }
  5275. });
  5276. PARENS([ AST_Assign, AST_Conditional ], function(output) {
  5277. var p = output.parent();
  5278. // !(a = false) → true
  5279. if (p instanceof AST_Unary)
  5280. return true;
  5281. // 1 + (a = 2) + 3 → 6, side effect setting a = 2
  5282. if (p instanceof AST_Binary && !(p instanceof AST_Assign))
  5283. return true;
  5284. // (a = func)() —or— new (a = Object)()
  5285. if (p instanceof AST_Call && p.expression === this)
  5286. return true;
  5287. // (a = foo) ? bar : baz
  5288. if (p instanceof AST_Conditional && p.condition === this)
  5289. return true;
  5290. // (a = foo)["prop"] —or— (a = foo).prop
  5291. if (p instanceof AST_PropAccess && p.expression === this)
  5292. return true;
  5293. // ({a, b} = {a: 1, b: 2}), a destructuring assignment
  5294. if (this instanceof AST_Assign && this.left instanceof AST_Destructuring && this.left.is_array === false)
  5295. return true;
  5296. });
  5297. /* -----[ PRINTERS ]----- */
  5298. DEFPRINT(AST_Directive, function(self, output) {
  5299. output.print_string(self.value, self.quote);
  5300. output.semicolon();
  5301. });
  5302. DEFPRINT(AST_Expansion, function (self, output) {
  5303. output.print("...");
  5304. self.expression.print(output);
  5305. });
  5306. DEFPRINT(AST_Destructuring, function (self, output) {
  5307. output.print(self.is_array ? "[" : "{");
  5308. var len = self.names.length;
  5309. self.names.forEach(function (name, i) {
  5310. if (i > 0) output.comma();
  5311. name.print(output);
  5312. // If the final element is a hole, we need to make sure it
  5313. // doesn't look like a trailing comma, by inserting an actual
  5314. // trailing comma.
  5315. if (i == len - 1 && name instanceof AST_Hole) output.comma();
  5316. });
  5317. output.print(self.is_array ? "]" : "}");
  5318. });
  5319. DEFPRINT(AST_Debugger, function(self, output) {
  5320. output.print("debugger");
  5321. output.semicolon();
  5322. });
  5323. /* -----[ statements ]----- */
  5324. function display_body(body, is_toplevel, output, allow_directives) {
  5325. var last = body.length - 1;
  5326. in_directive = allow_directives;
  5327. body.forEach(function(stmt, i) {
  5328. if (in_directive === true && !(stmt instanceof AST_Directive ||
  5329. stmt instanceof AST_EmptyStatement ||
  5330. (stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String)
  5331. )) {
  5332. in_directive = false;
  5333. }
  5334. if (!(stmt instanceof AST_EmptyStatement)) {
  5335. output.indent();
  5336. stmt.print(output);
  5337. if (!(i == last && is_toplevel)) {
  5338. output.newline();
  5339. if (is_toplevel) output.newline();
  5340. }
  5341. }
  5342. if (in_directive === true &&
  5343. stmt instanceof AST_SimpleStatement &&
  5344. stmt.body instanceof AST_String
  5345. ) {
  5346. in_directive = false;
  5347. }
  5348. });
  5349. in_directive = false;
  5350. }
  5351. AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
  5352. force_statement(this.body, output);
  5353. });
  5354. DEFPRINT(AST_Statement, function(self, output) {
  5355. self.body.print(output);
  5356. output.semicolon();
  5357. });
  5358. DEFPRINT(AST_Toplevel, function(self, output) {
  5359. display_body(self.body, true, output, true);
  5360. output.print("");
  5361. });
  5362. DEFPRINT(AST_LabeledStatement, function(self, output) {
  5363. self.label.print(output);
  5364. output.colon();
  5365. self.body.print(output);
  5366. });
  5367. DEFPRINT(AST_SimpleStatement, function(self, output) {
  5368. self.body.print(output);
  5369. output.semicolon();
  5370. });
  5371. function print_braced_empty(self, output) {
  5372. output.print("{");
  5373. output.with_indent(output.next_indent(), function() {
  5374. output.append_comments(self, true);
  5375. });
  5376. output.print("}");
  5377. }
  5378. function print_braced(self, output, allow_directives) {
  5379. if (self.body.length > 0) {
  5380. output.with_block(function() {
  5381. display_body(self.body, false, output, allow_directives);
  5382. });
  5383. } else print_braced_empty(self, output);
  5384. }
  5385. DEFPRINT(AST_BlockStatement, function(self, output) {
  5386. print_braced(self, output);
  5387. });
  5388. DEFPRINT(AST_EmptyStatement, function(self, output) {
  5389. output.semicolon();
  5390. });
  5391. DEFPRINT(AST_Do, function(self, output) {
  5392. output.print("do");
  5393. output.space();
  5394. make_block(self.body, output);
  5395. output.space();
  5396. output.print("while");
  5397. output.space();
  5398. output.with_parens(function() {
  5399. self.condition.print(output);
  5400. });
  5401. output.semicolon();
  5402. });
  5403. DEFPRINT(AST_While, function(self, output) {
  5404. output.print("while");
  5405. output.space();
  5406. output.with_parens(function() {
  5407. self.condition.print(output);
  5408. });
  5409. output.space();
  5410. self._do_print_body(output);
  5411. });
  5412. DEFPRINT(AST_For, function(self, output) {
  5413. output.print("for");
  5414. output.space();
  5415. output.with_parens(function() {
  5416. if (self.init) {
  5417. if (self.init instanceof AST_Definitions) {
  5418. self.init.print(output);
  5419. } else {
  5420. parenthesize_for_noin(self.init, output, true);
  5421. }
  5422. output.print(";");
  5423. output.space();
  5424. } else {
  5425. output.print(";");
  5426. }
  5427. if (self.condition) {
  5428. self.condition.print(output);
  5429. output.print(";");
  5430. output.space();
  5431. } else {
  5432. output.print(";");
  5433. }
  5434. if (self.step) {
  5435. self.step.print(output);
  5436. }
  5437. });
  5438. output.space();
  5439. self._do_print_body(output);
  5440. });
  5441. DEFPRINT(AST_ForIn, function(self, output) {
  5442. output.print("for");
  5443. if (self.await) {
  5444. output.space();
  5445. output.print("await");
  5446. }
  5447. output.space();
  5448. output.with_parens(function() {
  5449. self.init.print(output);
  5450. output.space();
  5451. output.print(self instanceof AST_ForOf ? "of" : "in");
  5452. output.space();
  5453. self.object.print(output);
  5454. });
  5455. output.space();
  5456. self._do_print_body(output);
  5457. });
  5458. DEFPRINT(AST_With, function(self, output) {
  5459. output.print("with");
  5460. output.space();
  5461. output.with_parens(function() {
  5462. self.expression.print(output);
  5463. });
  5464. output.space();
  5465. self._do_print_body(output);
  5466. });
  5467. /* -----[ functions ]----- */
  5468. AST_Lambda.DEFMETHOD("_do_print", function(output, nokeyword) {
  5469. var self = this;
  5470. if (!nokeyword) {
  5471. if (self.async) {
  5472. output.print("async");
  5473. output.space();
  5474. }
  5475. output.print("function");
  5476. if (self.is_generator) {
  5477. output.star();
  5478. }
  5479. if (self.name) {
  5480. output.space();
  5481. }
  5482. }
  5483. if (self.name instanceof AST_Symbol) {
  5484. self.name.print(output);
  5485. } else if (nokeyword && self.name instanceof AST_Node) {
  5486. output.with_square(function() {
  5487. self.name.print(output); // Computed method name
  5488. });
  5489. }
  5490. output.with_parens(function() {
  5491. self.argnames.forEach(function(arg, i) {
  5492. if (i) output.comma();
  5493. arg.print(output);
  5494. });
  5495. });
  5496. output.space();
  5497. print_braced(self, output, true);
  5498. });
  5499. DEFPRINT(AST_Lambda, function(self, output) {
  5500. self._do_print(output);
  5501. });
  5502. DEFPRINT(AST_PrefixedTemplateString, function(self, output) {
  5503. var tag = self.prefix;
  5504. var parenthesize_tag = tag instanceof AST_Arrow
  5505. || tag instanceof AST_Binary
  5506. || tag instanceof AST_Conditional
  5507. || tag instanceof AST_Sequence
  5508. || tag instanceof AST_Unary;
  5509. if (parenthesize_tag) output.print("(");
  5510. self.prefix.print(output);
  5511. if (parenthesize_tag) output.print(")");
  5512. self.template_string.print(output);
  5513. });
  5514. DEFPRINT(AST_TemplateString, function(self, output) {
  5515. var is_tagged = output.parent() instanceof AST_PrefixedTemplateString;
  5516. output.print("`");
  5517. for (var i = 0; i < self.segments.length; i++) {
  5518. if (!(self.segments[i] instanceof AST_TemplateSegment)) {
  5519. output.print("${");
  5520. self.segments[i].print(output);
  5521. output.print("}");
  5522. } else if (is_tagged) {
  5523. output.print(self.segments[i].raw);
  5524. } else {
  5525. output.print_template_string_chars(self.segments[i].value);
  5526. }
  5527. }
  5528. output.print("`");
  5529. });
  5530. AST_Arrow.DEFMETHOD("_do_print", function(output) {
  5531. var self = this;
  5532. var parent = output.parent();
  5533. var needs_parens = parent instanceof AST_Binary ||
  5534. parent instanceof AST_Unary ||
  5535. (parent instanceof AST_Call && self === parent.expression);
  5536. if (needs_parens) { output.print("("); }
  5537. if (self.async) {
  5538. output.print("async");
  5539. output.space();
  5540. }
  5541. if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol) {
  5542. self.argnames[0].print(output);
  5543. } else {
  5544. output.with_parens(function() {
  5545. self.argnames.forEach(function(arg, i) {
  5546. if (i) output.comma();
  5547. arg.print(output);
  5548. });
  5549. });
  5550. }
  5551. output.space();
  5552. output.print("=>");
  5553. output.space();
  5554. if (self.body instanceof AST_Node) {
  5555. self.body.print(output);
  5556. } else {
  5557. print_braced(self, output);
  5558. }
  5559. if (needs_parens) { output.print(")"); }
  5560. });
  5561. /* -----[ exits ]----- */
  5562. AST_Exit.DEFMETHOD("_do_print", function(output, kind) {
  5563. output.print(kind);
  5564. if (this.value) {
  5565. output.space();
  5566. this.value.print(output);
  5567. }
  5568. output.semicolon();
  5569. });
  5570. DEFPRINT(AST_Return, function(self, output) {
  5571. self._do_print(output, "return");
  5572. });
  5573. DEFPRINT(AST_Throw, function(self, output) {
  5574. self._do_print(output, "throw");
  5575. });
  5576. /* -----[ yield ]----- */
  5577. DEFPRINT(AST_Yield, function(self, output) {
  5578. var star = self.is_star ? "*" : "";
  5579. output.print("yield" + star);
  5580. if (self.expression) {
  5581. output.space();
  5582. self.expression.print(output);
  5583. }
  5584. });
  5585. DEFPRINT(AST_Await, function(self, output) {
  5586. output.print("await");
  5587. output.space();
  5588. var e = self.expression;
  5589. var parens = !(
  5590. e instanceof AST_Call
  5591. || e instanceof AST_SymbolRef
  5592. || e instanceof AST_PropAccess
  5593. || e instanceof AST_Unary
  5594. || e instanceof AST_Constant
  5595. );
  5596. if (parens) output.print("(");
  5597. self.expression.print(output);
  5598. if (parens) output.print(")");
  5599. });
  5600. /* -----[ loop control ]----- */
  5601. AST_LoopControl.DEFMETHOD("_do_print", function(output, kind) {
  5602. output.print(kind);
  5603. if (this.label) {
  5604. output.space();
  5605. this.label.print(output);
  5606. }
  5607. output.semicolon();
  5608. });
  5609. DEFPRINT(AST_Break, function(self, output) {
  5610. self._do_print(output, "break");
  5611. });
  5612. DEFPRINT(AST_Continue, function(self, output) {
  5613. self._do_print(output, "continue");
  5614. });
  5615. /* -----[ if ]----- */
  5616. function make_then(self, output) {
  5617. var b = self.body;
  5618. if (output.option("braces")
  5619. || output.option("ie8") && b instanceof AST_Do)
  5620. return make_block(b, output);
  5621. // The squeezer replaces "block"-s that contain only a single
  5622. // statement with the statement itself; technically, the AST
  5623. // is correct, but this can create problems when we output an
  5624. // IF having an ELSE clause where the THEN clause ends in an
  5625. // IF *without* an ELSE block (then the outer ELSE would refer
  5626. // to the inner IF). This function checks for this case and
  5627. // adds the block braces if needed.
  5628. if (!b) return output.force_semicolon();
  5629. while (true) {
  5630. if (b instanceof AST_If) {
  5631. if (!b.alternative) {
  5632. make_block(self.body, output);
  5633. return;
  5634. }
  5635. b = b.alternative;
  5636. } else if (b instanceof AST_StatementWithBody) {
  5637. b = b.body;
  5638. } else break;
  5639. }
  5640. force_statement(self.body, output);
  5641. }
  5642. DEFPRINT(AST_If, function(self, output) {
  5643. output.print("if");
  5644. output.space();
  5645. output.with_parens(function() {
  5646. self.condition.print(output);
  5647. });
  5648. output.space();
  5649. if (self.alternative) {
  5650. make_then(self, output);
  5651. output.space();
  5652. output.print("else");
  5653. output.space();
  5654. if (self.alternative instanceof AST_If)
  5655. self.alternative.print(output);
  5656. else
  5657. force_statement(self.alternative, output);
  5658. } else {
  5659. self._do_print_body(output);
  5660. }
  5661. });
  5662. /* -----[ switch ]----- */
  5663. DEFPRINT(AST_Switch, function(self, output) {
  5664. output.print("switch");
  5665. output.space();
  5666. output.with_parens(function() {
  5667. self.expression.print(output);
  5668. });
  5669. output.space();
  5670. var last = self.body.length - 1;
  5671. if (last < 0) print_braced_empty(self, output);
  5672. else output.with_block(function() {
  5673. self.body.forEach(function(branch, i) {
  5674. output.indent(true);
  5675. branch.print(output);
  5676. if (i < last && branch.body.length > 0)
  5677. output.newline();
  5678. });
  5679. });
  5680. });
  5681. AST_SwitchBranch.DEFMETHOD("_do_print_body", function(output) {
  5682. output.newline();
  5683. this.body.forEach(function(stmt) {
  5684. output.indent();
  5685. stmt.print(output);
  5686. output.newline();
  5687. });
  5688. });
  5689. DEFPRINT(AST_Default, function(self, output) {
  5690. output.print("default:");
  5691. self._do_print_body(output);
  5692. });
  5693. DEFPRINT(AST_Case, function(self, output) {
  5694. output.print("case");
  5695. output.space();
  5696. self.expression.print(output);
  5697. output.print(":");
  5698. self._do_print_body(output);
  5699. });
  5700. /* -----[ exceptions ]----- */
  5701. DEFPRINT(AST_Try, function(self, output) {
  5702. output.print("try");
  5703. output.space();
  5704. print_braced(self, output);
  5705. if (self.bcatch) {
  5706. output.space();
  5707. self.bcatch.print(output);
  5708. }
  5709. if (self.bfinally) {
  5710. output.space();
  5711. self.bfinally.print(output);
  5712. }
  5713. });
  5714. DEFPRINT(AST_Catch, function(self, output) {
  5715. output.print("catch");
  5716. if (self.argname) {
  5717. output.space();
  5718. output.with_parens(function() {
  5719. self.argname.print(output);
  5720. });
  5721. }
  5722. output.space();
  5723. print_braced(self, output);
  5724. });
  5725. DEFPRINT(AST_Finally, function(self, output) {
  5726. output.print("finally");
  5727. output.space();
  5728. print_braced(self, output);
  5729. });
  5730. /* -----[ var/const ]----- */
  5731. AST_Definitions.DEFMETHOD("_do_print", function(output, kind) {
  5732. output.print(kind);
  5733. output.space();
  5734. this.definitions.forEach(function(def, i) {
  5735. if (i) output.comma();
  5736. def.print(output);
  5737. });
  5738. var p = output.parent();
  5739. var in_for = p instanceof AST_For || p instanceof AST_ForIn;
  5740. var output_semicolon = !in_for || p && p.init !== this;
  5741. if (output_semicolon)
  5742. output.semicolon();
  5743. });
  5744. DEFPRINT(AST_Let, function(self, output) {
  5745. self._do_print(output, "let");
  5746. });
  5747. DEFPRINT(AST_Var, function(self, output) {
  5748. self._do_print(output, "var");
  5749. });
  5750. DEFPRINT(AST_Const, function(self, output) {
  5751. self._do_print(output, "const");
  5752. });
  5753. DEFPRINT(AST_Import, function(self, output) {
  5754. output.print("import");
  5755. output.space();
  5756. if (self.imported_name) {
  5757. self.imported_name.print(output);
  5758. }
  5759. if (self.imported_name && self.imported_names) {
  5760. output.print(",");
  5761. output.space();
  5762. }
  5763. if (self.imported_names) {
  5764. if (self.imported_names.length === 1 && self.imported_names[0].foreign_name.name === "*") {
  5765. self.imported_names[0].print(output);
  5766. } else {
  5767. output.print("{");
  5768. self.imported_names.forEach(function (name_import, i) {
  5769. output.space();
  5770. name_import.print(output);
  5771. if (i < self.imported_names.length - 1) {
  5772. output.print(",");
  5773. }
  5774. });
  5775. output.space();
  5776. output.print("}");
  5777. }
  5778. }
  5779. if (self.imported_name || self.imported_names) {
  5780. output.space();
  5781. output.print("from");
  5782. output.space();
  5783. }
  5784. self.module_name.print(output);
  5785. output.semicolon();
  5786. });
  5787. DEFPRINT(AST_NameMapping, function(self, output) {
  5788. var is_import = output.parent() instanceof AST_Import;
  5789. var definition = self.name.definition();
  5790. var names_are_different =
  5791. (definition && definition.mangled_name || self.name.name) !==
  5792. self.foreign_name.name;
  5793. if (names_are_different) {
  5794. if (is_import) {
  5795. output.print(self.foreign_name.name);
  5796. } else {
  5797. self.name.print(output);
  5798. }
  5799. output.space();
  5800. output.print("as");
  5801. output.space();
  5802. if (is_import) {
  5803. self.name.print(output);
  5804. } else {
  5805. output.print(self.foreign_name.name);
  5806. }
  5807. } else {
  5808. self.name.print(output);
  5809. }
  5810. });
  5811. DEFPRINT(AST_Export, function(self, output) {
  5812. output.print("export");
  5813. output.space();
  5814. if (self.is_default) {
  5815. output.print("default");
  5816. output.space();
  5817. }
  5818. if (self.exported_names) {
  5819. if (self.exported_names.length === 1 && self.exported_names[0].name.name === "*") {
  5820. self.exported_names[0].print(output);
  5821. } else {
  5822. output.print("{");
  5823. self.exported_names.forEach(function(name_export, i) {
  5824. output.space();
  5825. name_export.print(output);
  5826. if (i < self.exported_names.length - 1) {
  5827. output.print(",");
  5828. }
  5829. });
  5830. output.space();
  5831. output.print("}");
  5832. }
  5833. } else if (self.exported_value) {
  5834. self.exported_value.print(output);
  5835. } else if (self.exported_definition) {
  5836. self.exported_definition.print(output);
  5837. if (self.exported_definition instanceof AST_Definitions) return;
  5838. }
  5839. if (self.module_name) {
  5840. output.space();
  5841. output.print("from");
  5842. output.space();
  5843. self.module_name.print(output);
  5844. }
  5845. if (self.exported_value
  5846. && !(self.exported_value instanceof AST_Defun ||
  5847. self.exported_value instanceof AST_Function ||
  5848. self.exported_value instanceof AST_Class)
  5849. || self.module_name
  5850. || self.exported_names
  5851. ) {
  5852. output.semicolon();
  5853. }
  5854. });
  5855. function parenthesize_for_noin(node, output, noin) {
  5856. var parens = false;
  5857. // need to take some precautions here:
  5858. // https://github.com/mishoo/UglifyJS2/issues/60
  5859. if (noin) node.walk(new TreeWalker(function(node) {
  5860. if (parens || node instanceof AST_Scope) return true;
  5861. if (node instanceof AST_Binary && node.operator == "in") {
  5862. parens = true;
  5863. return true;
  5864. }
  5865. }));
  5866. node.print(output, parens);
  5867. }
  5868. DEFPRINT(AST_VarDef, function(self, output) {
  5869. self.name.print(output);
  5870. if (self.value) {
  5871. output.space();
  5872. output.print("=");
  5873. output.space();
  5874. var p = output.parent(1);
  5875. var noin = p instanceof AST_For || p instanceof AST_ForIn;
  5876. parenthesize_for_noin(self.value, output, noin);
  5877. }
  5878. });
  5879. /* -----[ other expressions ]----- */
  5880. DEFPRINT(AST_Call, function(self, output) {
  5881. self.expression.print(output);
  5882. if (self instanceof AST_New && !need_constructor_parens(self, output))
  5883. return;
  5884. if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {
  5885. output.add_mapping(self.start);
  5886. }
  5887. output.with_parens(function() {
  5888. self.args.forEach(function(expr, i) {
  5889. if (i) output.comma();
  5890. expr.print(output);
  5891. });
  5892. });
  5893. });
  5894. DEFPRINT(AST_New, function(self, output) {
  5895. output.print("new");
  5896. output.space();
  5897. AST_Call.prototype._codegen(self, output);
  5898. });
  5899. AST_Sequence.DEFMETHOD("_do_print", function(output) {
  5900. this.expressions.forEach(function(node, index) {
  5901. if (index > 0) {
  5902. output.comma();
  5903. if (output.should_break()) {
  5904. output.newline();
  5905. output.indent();
  5906. }
  5907. }
  5908. node.print(output);
  5909. });
  5910. });
  5911. DEFPRINT(AST_Sequence, function(self, output) {
  5912. self._do_print(output);
  5913. // var p = output.parent();
  5914. // if (p instanceof AST_Statement) {
  5915. // output.with_indent(output.next_indent(), function(){
  5916. // self._do_print(output);
  5917. // });
  5918. // } else {
  5919. // self._do_print(output);
  5920. // }
  5921. });
  5922. DEFPRINT(AST_Dot, function(self, output) {
  5923. var expr = self.expression;
  5924. expr.print(output);
  5925. var prop = self.property;
  5926. if (output.option("ie8") && RESERVED_WORDS(prop)) {
  5927. output.print("[");
  5928. output.add_mapping(self.end);
  5929. output.print_string(prop);
  5930. output.print("]");
  5931. } else {
  5932. if (expr instanceof AST_Number && expr.getValue() >= 0) {
  5933. if (!/[xa-f.)]/i.test(output.last())) {
  5934. output.print(".");
  5935. }
  5936. }
  5937. output.print(".");
  5938. // the name after dot would be mapped about here.
  5939. output.add_mapping(self.end);
  5940. output.print_name(prop);
  5941. }
  5942. });
  5943. DEFPRINT(AST_Sub, function(self, output) {
  5944. self.expression.print(output);
  5945. output.print("[");
  5946. self.property.print(output);
  5947. output.print("]");
  5948. });
  5949. DEFPRINT(AST_UnaryPrefix, function(self, output) {
  5950. var op = self.operator;
  5951. output.print(op);
  5952. if (/^[a-z]/i.test(op)
  5953. || (/[+-]$/.test(op)
  5954. && self.expression instanceof AST_UnaryPrefix
  5955. && /^[+-]/.test(self.expression.operator))) {
  5956. output.space();
  5957. }
  5958. self.expression.print(output);
  5959. });
  5960. DEFPRINT(AST_UnaryPostfix, function(self, output) {
  5961. self.expression.print(output);
  5962. output.print(self.operator);
  5963. });
  5964. DEFPRINT(AST_Binary, function(self, output) {
  5965. var op = self.operator;
  5966. self.left.print(output);
  5967. if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
  5968. && self.left instanceof AST_UnaryPostfix
  5969. && self.left.operator == "--") {
  5970. // space is mandatory to avoid outputting -->
  5971. output.print(" ");
  5972. } else {
  5973. // the space is optional depending on "beautify"
  5974. output.space();
  5975. }
  5976. output.print(op);
  5977. if ((op == "<" || op == "<<")
  5978. && self.right instanceof AST_UnaryPrefix
  5979. && self.right.operator == "!"
  5980. && self.right.expression instanceof AST_UnaryPrefix
  5981. && self.right.expression.operator == "--") {
  5982. // space is mandatory to avoid outputting <!--
  5983. output.print(" ");
  5984. } else {
  5985. // the space is optional depending on "beautify"
  5986. output.space();
  5987. }
  5988. self.right.print(output);
  5989. });
  5990. DEFPRINT(AST_Conditional, function(self, output) {
  5991. self.condition.print(output);
  5992. output.space();
  5993. output.print("?");
  5994. output.space();
  5995. self.consequent.print(output);
  5996. output.space();
  5997. output.colon();
  5998. self.alternative.print(output);
  5999. });
  6000. /* -----[ literals ]----- */
  6001. DEFPRINT(AST_Array, function(self, output) {
  6002. output.with_square(function() {
  6003. var a = self.elements, len = a.length;
  6004. if (len > 0) output.space();
  6005. a.forEach(function(exp, i) {
  6006. if (i) output.comma();
  6007. exp.print(output);
  6008. // If the final element is a hole, we need to make sure it
  6009. // doesn't look like a trailing comma, by inserting an actual
  6010. // trailing comma.
  6011. if (i === len - 1 && exp instanceof AST_Hole)
  6012. output.comma();
  6013. });
  6014. if (len > 0) output.space();
  6015. });
  6016. });
  6017. DEFPRINT(AST_Object, function(self, output) {
  6018. if (self.properties.length > 0) output.with_block(function() {
  6019. self.properties.forEach(function(prop, i) {
  6020. if (i) {
  6021. output.print(",");
  6022. output.newline();
  6023. }
  6024. output.indent();
  6025. prop.print(output);
  6026. });
  6027. output.newline();
  6028. });
  6029. else print_braced_empty(self, output);
  6030. });
  6031. DEFPRINT(AST_Class, function(self, output) {
  6032. output.print("class");
  6033. output.space();
  6034. if (self.name) {
  6035. self.name.print(output);
  6036. output.space();
  6037. }
  6038. if (self.extends) {
  6039. var parens = (
  6040. !(self.extends instanceof AST_SymbolRef)
  6041. && !(self.extends instanceof AST_PropAccess)
  6042. && !(self.extends instanceof AST_ClassExpression)
  6043. && !(self.extends instanceof AST_Function)
  6044. );
  6045. output.print("extends");
  6046. if (parens) {
  6047. output.print("(");
  6048. } else {
  6049. output.space();
  6050. }
  6051. self.extends.print(output);
  6052. if (parens) {
  6053. output.print(")");
  6054. } else {
  6055. output.space();
  6056. }
  6057. }
  6058. if (self.properties.length > 0) output.with_block(function() {
  6059. self.properties.forEach(function(prop, i) {
  6060. if (i) {
  6061. output.newline();
  6062. }
  6063. output.indent();
  6064. prop.print(output);
  6065. });
  6066. output.newline();
  6067. });
  6068. else output.print("{}");
  6069. });
  6070. DEFPRINT(AST_NewTarget, function(self, output) {
  6071. output.print("new.target");
  6072. });
  6073. function print_property_name(key, quote, output) {
  6074. if (output.option("quote_keys")) {
  6075. output.print_string(key);
  6076. } else if ("" + +key == key && key >= 0) {
  6077. output.print(make_num(key));
  6078. } else if (RESERVED_WORDS(key) ? !output.option("ie8") : is_identifier_string(key)) {
  6079. if (quote && output.option("keep_quoted_props")) {
  6080. output.print_string(key, quote);
  6081. } else {
  6082. output.print_name(key);
  6083. }
  6084. } else {
  6085. output.print_string(key, quote);
  6086. }
  6087. }
  6088. DEFPRINT(AST_ObjectKeyVal, function(self, output) {
  6089. function get_name(self) {
  6090. var def = self.definition();
  6091. return def ? def.mangled_name || def.name : self.name;
  6092. }
  6093. var allowShortHand = output.option("shorthand");
  6094. if (allowShortHand &&
  6095. self.value instanceof AST_Symbol &&
  6096. is_identifier_string(self.key) &&
  6097. get_name(self.value) === self.key &&
  6098. is_identifier(self.key)
  6099. ) {
  6100. print_property_name(self.key, self.quote, output);
  6101. } else if (allowShortHand &&
  6102. self.value instanceof AST_DefaultAssign &&
  6103. self.value.left instanceof AST_Symbol &&
  6104. is_identifier_string(self.key) &&
  6105. get_name(self.value.left) === self.key
  6106. ) {
  6107. print_property_name(self.key, self.quote, output);
  6108. output.space();
  6109. output.print("=");
  6110. output.space();
  6111. self.value.right.print(output);
  6112. } else {
  6113. if (!(self.key instanceof AST_Node)) {
  6114. print_property_name(self.key, self.quote, output);
  6115. } else {
  6116. output.with_square(function() {
  6117. self.key.print(output);
  6118. });
  6119. }
  6120. output.colon();
  6121. self.value.print(output);
  6122. }
  6123. });
  6124. AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, output) {
  6125. var self = this;
  6126. if (self.static) {
  6127. output.print("static");
  6128. output.space();
  6129. }
  6130. if (type) {
  6131. output.print(type);
  6132. output.space();
  6133. }
  6134. if (self.key instanceof AST_SymbolMethod) {
  6135. print_property_name(self.key.name, self.quote, output);
  6136. } else {
  6137. output.with_square(function() {
  6138. self.key.print(output);
  6139. });
  6140. }
  6141. self.value._do_print(output, true);
  6142. });
  6143. DEFPRINT(AST_ObjectSetter, function(self, output) {
  6144. self._print_getter_setter("set", output);
  6145. });
  6146. DEFPRINT(AST_ObjectGetter, function(self, output) {
  6147. self._print_getter_setter("get", output);
  6148. });
  6149. DEFPRINT(AST_ConciseMethod, function(self, output) {
  6150. var type;
  6151. if (self.is_generator && self.async) {
  6152. type = "async*";
  6153. } else if (self.is_generator) {
  6154. type = "*";
  6155. } else if (self.async) {
  6156. type = "async";
  6157. }
  6158. self._print_getter_setter(type, output);
  6159. });
  6160. AST_Symbol.DEFMETHOD("_do_print", function(output) {
  6161. var def = this.definition();
  6162. output.print_name(def ? def.mangled_name || def.name : this.name);
  6163. });
  6164. DEFPRINT(AST_Symbol, function (self, output) {
  6165. self._do_print(output);
  6166. });
  6167. DEFPRINT(AST_Hole, noop);
  6168. DEFPRINT(AST_This, function(self, output) {
  6169. output.print("this");
  6170. });
  6171. DEFPRINT(AST_Super, function(self, output) {
  6172. output.print("super");
  6173. });
  6174. DEFPRINT(AST_Constant, function(self, output) {
  6175. output.print(self.getValue());
  6176. });
  6177. DEFPRINT(AST_String, function(self, output) {
  6178. output.print_string(self.getValue(), self.quote, in_directive);
  6179. });
  6180. DEFPRINT(AST_Number, function(self, output) {
  6181. if (use_asm && self.start && self.start.raw != null) {
  6182. output.print(self.start.raw);
  6183. } else {
  6184. output.print(make_num(self.getValue()));
  6185. }
  6186. });
  6187. DEFPRINT(AST_RegExp, function(self, output) {
  6188. var regexp = self.getValue();
  6189. var str = regexp.toString();
  6190. str = output.to_utf8(str);
  6191. output.print(str);
  6192. var p = output.parent();
  6193. if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
  6194. output.print(" ");
  6195. });
  6196. function force_statement(stat, output) {
  6197. if (output.option("braces")) {
  6198. make_block(stat, output);
  6199. } else {
  6200. if (!stat || stat instanceof AST_EmptyStatement)
  6201. output.force_semicolon();
  6202. else
  6203. stat.print(output);
  6204. }
  6205. }
  6206. // self should be AST_New. decide if we want to show parens or not.
  6207. function need_constructor_parens(self, output) {
  6208. // Always print parentheses with arguments
  6209. if (self.args.length > 0) return true;
  6210. return output.option("beautify");
  6211. }
  6212. function best_of(a) {
  6213. var best = a[0], len = best.length;
  6214. for (var i = 1; i < a.length; ++i) {
  6215. if (a[i].length < len) {
  6216. best = a[i];
  6217. len = best.length;
  6218. }
  6219. }
  6220. return best;
  6221. }
  6222. function make_num(num) {
  6223. var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace("e+", "e") ], m;
  6224. if (Math.floor(num) === num) {
  6225. a.push(
  6226. (num >= 0 ? "0x" : "-0x") + num.toString(16).toLowerCase() // probably pointless
  6227. );
  6228. if ((m = /^(.*?)(0{3,})$/.exec(num))) {
  6229. a.push(m[1] + "e" + m[2].length);
  6230. }
  6231. } else if ((m = /^0?\.(0+)(.*)$/.exec(num))) {
  6232. a.push(m[2] + "e-" + (m[1].length + m[2].length));
  6233. }
  6234. return best_of(a);
  6235. }
  6236. function make_block(stmt, output) {
  6237. if (!stmt || stmt instanceof AST_EmptyStatement)
  6238. output.print("{}");
  6239. else if (stmt instanceof AST_BlockStatement)
  6240. stmt.print(output);
  6241. else output.with_block(function() {
  6242. output.indent();
  6243. stmt.print(output);
  6244. output.newline();
  6245. });
  6246. }
  6247. /* -----[ source map generators ]----- */
  6248. function DEFMAP(nodetype, generator) {
  6249. nodetype.forEach(function(nodetype) {
  6250. nodetype.DEFMETHOD("add_source_map", generator);
  6251. });
  6252. }
  6253. DEFMAP([
  6254. // We could easily add info for ALL nodes, but it seems to me that
  6255. // would be quite wasteful, hence this noop in the base class.
  6256. AST_Node,
  6257. // since the label symbol will mark it
  6258. AST_LabeledStatement,
  6259. AST_Toplevel,
  6260. ], noop);
  6261. // XXX: I'm not exactly sure if we need it for all of these nodes,
  6262. // or if we should add even more.
  6263. DEFMAP([
  6264. AST_Array,
  6265. AST_BlockStatement,
  6266. AST_Catch,
  6267. AST_Class,
  6268. AST_Constant,
  6269. AST_Debugger,
  6270. AST_Definitions,
  6271. AST_Directive,
  6272. AST_Finally,
  6273. AST_Jump,
  6274. AST_Lambda,
  6275. AST_New,
  6276. AST_Object,
  6277. AST_StatementWithBody,
  6278. AST_Symbol,
  6279. AST_Switch,
  6280. AST_SwitchBranch,
  6281. AST_Try,
  6282. ], function(output) {
  6283. output.add_mapping(this.start);
  6284. });
  6285. DEFMAP([
  6286. AST_ObjectGetter,
  6287. AST_ObjectSetter,
  6288. ], function(output) {
  6289. output.add_mapping(this.start, this.key.name);
  6290. });
  6291. DEFMAP([ AST_ObjectProperty ], function(output) {
  6292. output.add_mapping(this.start, this.key);
  6293. });
  6294. })();
  6295. /***********************************************************************
  6296. A JavaScript tokenizer / parser / beautifier / compressor.
  6297. https://github.com/mishoo/UglifyJS2
  6298. -------------------------------- (C) ---------------------------------
  6299. Author: Mihai Bazon
  6300. <mihai.bazon@gmail.com>
  6301. http://mihai.bazon.net/blog
  6302. Distributed under the BSD license:
  6303. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  6304. Redistribution and use in source and binary forms, with or without
  6305. modification, are permitted provided that the following conditions
  6306. are met:
  6307. * Redistributions of source code must retain the above
  6308. copyright notice, this list of conditions and the following
  6309. disclaimer.
  6310. * Redistributions in binary form must reproduce the above
  6311. copyright notice, this list of conditions and the following
  6312. disclaimer in the documentation and/or other materials
  6313. provided with the distribution.
  6314. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  6315. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  6316. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  6317. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  6318. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  6319. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  6320. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  6321. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  6322. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  6323. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  6324. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  6325. SUCH DAMAGE.
  6326. ***********************************************************************/
  6327. function SymbolDef(scope, orig, init) {
  6328. this.name = orig.name;
  6329. this.orig = [ orig ];
  6330. this.init = init;
  6331. this.eliminated = 0;
  6332. this.scope = scope;
  6333. this.references = [];
  6334. this.replaced = 0;
  6335. this.global = false;
  6336. this.export = false;
  6337. this.mangled_name = null;
  6338. this.undeclared = false;
  6339. this.id = SymbolDef.next_id++;
  6340. }
  6341. SymbolDef.next_id = 1;
  6342. var MASK_EXPORT_DONT_MANGLE = 1 << 0;
  6343. var MASK_EXPORT_WANT_MANGLE = 1 << 1;
  6344. SymbolDef.prototype = {
  6345. unmangleable: function(options) {
  6346. if (!options) options = {};
  6347. return this.global && !options.toplevel
  6348. || (this.export & MASK_EXPORT_DONT_MANGLE)
  6349. || this.undeclared
  6350. || !options.eval && this.scope.pinned()
  6351. || (this.orig[0] instanceof AST_SymbolLambda
  6352. || this.orig[0] instanceof AST_SymbolDefun) && keep_name(options.keep_fnames, this.orig[0].name)
  6353. || this.orig[0] instanceof AST_SymbolMethod
  6354. || (this.orig[0] instanceof AST_SymbolClass
  6355. || this.orig[0] instanceof AST_SymbolDefClass) && keep_name(options.keep_classnames, this.orig[0].name);
  6356. },
  6357. mangle: function(options) {
  6358. var cache = options.cache && options.cache.props;
  6359. if (this.global && cache && cache.has(this.name)) {
  6360. this.mangled_name = cache.get(this.name);
  6361. } else if (!this.mangled_name && !this.unmangleable(options)) {
  6362. var s = this.scope;
  6363. var sym = this.orig[0];
  6364. if (options.ie8 && sym instanceof AST_SymbolLambda)
  6365. s = s.parent_scope;
  6366. var def;
  6367. if (def = this.redefined()) {
  6368. this.mangled_name = def.mangled_name || def.name;
  6369. } else
  6370. this.mangled_name = s.next_mangled(options, this);
  6371. if (this.global && cache) {
  6372. cache.set(this.name, this.mangled_name);
  6373. }
  6374. }
  6375. },
  6376. redefined: function() {
  6377. return this.defun && this.defun.variables.get(this.name);
  6378. }
  6379. };
  6380. AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
  6381. options = defaults(options, {
  6382. cache: null,
  6383. ie8: false,
  6384. safari10: false,
  6385. });
  6386. // pass 1: setup scope chaining and handle definitions
  6387. var self = this;
  6388. var scope = self.parent_scope = null;
  6389. var labels = new Dictionary();
  6390. var defun = null;
  6391. var in_destructuring = null;
  6392. var for_scopes = [];
  6393. var tw = new TreeWalker(function(node, descend) {
  6394. if (node.is_block_scope()) {
  6395. var save_scope = scope;
  6396. node.block_scope = scope = new AST_Scope(node);
  6397. scope.init_scope_vars(save_scope);
  6398. if (!(node instanceof AST_Scope)) {
  6399. scope.uses_with = save_scope.uses_with;
  6400. scope.uses_eval = save_scope.uses_eval;
  6401. scope.directives = save_scope.directives;
  6402. }
  6403. if (options.safari10) {
  6404. if (node instanceof AST_For || node instanceof AST_ForIn) {
  6405. for_scopes.push(scope);
  6406. }
  6407. }
  6408. descend();
  6409. scope = save_scope;
  6410. return true;
  6411. }
  6412. if (node instanceof AST_Destructuring) {
  6413. in_destructuring = node; // These don't nest
  6414. descend();
  6415. in_destructuring = null;
  6416. return true;
  6417. }
  6418. if (node instanceof AST_Scope) {
  6419. node.init_scope_vars(scope);
  6420. var save_scope = scope;
  6421. var save_defun = defun;
  6422. var save_labels = labels;
  6423. defun = scope = node;
  6424. labels = new Dictionary();
  6425. descend();
  6426. scope = save_scope;
  6427. defun = save_defun;
  6428. labels = save_labels;
  6429. return true; // don't descend again in TreeWalker
  6430. }
  6431. if (node instanceof AST_LabeledStatement) {
  6432. var l = node.label;
  6433. if (labels.has(l.name)) {
  6434. throw new Error(string_template("Label {name} defined twice", l));
  6435. }
  6436. labels.set(l.name, l);
  6437. descend();
  6438. labels.del(l.name);
  6439. return true; // no descend again
  6440. }
  6441. if (node instanceof AST_With) {
  6442. for (var s = scope; s; s = s.parent_scope)
  6443. s.uses_with = true;
  6444. return;
  6445. }
  6446. if (node instanceof AST_Symbol) {
  6447. node.scope = scope;
  6448. }
  6449. if (node instanceof AST_Label) {
  6450. node.thedef = node;
  6451. node.references = [];
  6452. }
  6453. if (node instanceof AST_SymbolLambda) {
  6454. defun.def_function(node, node.name == "arguments" ? undefined : defun);
  6455. } else if (node instanceof AST_SymbolDefun) {
  6456. // Careful here, the scope where this should be defined is
  6457. // the parent scope. The reason is that we enter a new
  6458. // scope when we encounter the AST_Defun node (which is
  6459. // instanceof AST_Scope) but we get to the symbol a bit
  6460. // later.
  6461. mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node, defun), 1);
  6462. } else if (node instanceof AST_SymbolClass) {
  6463. mark_export(defun.def_variable(node, defun), 1);
  6464. } else if (node instanceof AST_SymbolImport) {
  6465. scope.def_variable(node);
  6466. } else if (node instanceof AST_SymbolDefClass) {
  6467. // This deals with the name of the class being available
  6468. // inside the class.
  6469. mark_export((node.scope = defun.parent_scope).def_function(node, defun), 1);
  6470. } else if (node instanceof AST_SymbolVar
  6471. || node instanceof AST_SymbolLet
  6472. || node instanceof AST_SymbolConst) {
  6473. var def;
  6474. if (node instanceof AST_SymbolBlockDeclaration) {
  6475. def = scope.def_variable(node, null);
  6476. } else {
  6477. def = defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
  6478. }
  6479. if (!all(def.orig, function(sym) {
  6480. if (sym === node) return true;
  6481. if (node instanceof AST_SymbolBlockDeclaration) {
  6482. return sym instanceof AST_SymbolLambda;
  6483. }
  6484. return !(sym instanceof AST_SymbolLet || sym instanceof AST_SymbolConst);
  6485. })) {
  6486. js_error(
  6487. node.name + " redeclared",
  6488. node.start.file,
  6489. node.start.line,
  6490. node.start.col,
  6491. node.start.pos
  6492. );
  6493. }
  6494. if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2);
  6495. def.destructuring = in_destructuring;
  6496. if (defun !== scope) {
  6497. node.mark_enclosed(options);
  6498. var def = scope.find_variable(node);
  6499. if (node.thedef !== def) {
  6500. node.thedef = def;
  6501. node.reference(options);
  6502. }
  6503. }
  6504. } else if (node instanceof AST_SymbolCatch) {
  6505. scope.def_variable(node).defun = defun;
  6506. } else if (node instanceof AST_LabelRef) {
  6507. var sym = labels.get(node.name);
  6508. if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", {
  6509. name: node.name,
  6510. line: node.start.line,
  6511. col: node.start.col
  6512. }));
  6513. node.thedef = sym;
  6514. }
  6515. if (!(scope instanceof AST_Toplevel) && (node instanceof AST_Export || node instanceof AST_Import)) {
  6516. js_error(
  6517. node.TYPE + " statement may only appear at top level",
  6518. node.start.file,
  6519. node.start.line,
  6520. node.start.col,
  6521. node.start.pos
  6522. );
  6523. }
  6524. function mark_export(def, level) {
  6525. if (in_destructuring) {
  6526. var i = 0;
  6527. do {
  6528. level++;
  6529. } while (tw.parent(i++) !== in_destructuring);
  6530. }
  6531. var node = tw.parent(level);
  6532. if (def.export = node instanceof AST_Export && MASK_EXPORT_DONT_MANGLE) {
  6533. var exported = node.exported_definition;
  6534. if ((exported instanceof AST_Defun || exported instanceof AST_DefClass) && node.is_default) {
  6535. def.export = MASK_EXPORT_WANT_MANGLE;
  6536. }
  6537. }
  6538. }
  6539. });
  6540. self.walk(tw);
  6541. // pass 2: find back references and eval
  6542. self.globals = new Dictionary();
  6543. var tw = new TreeWalker(function(node, descend) {
  6544. if (node instanceof AST_LoopControl && node.label) {
  6545. node.label.thedef.references.push(node);
  6546. return true;
  6547. }
  6548. if (node instanceof AST_SymbolRef) {
  6549. var name = node.name;
  6550. if (name == "eval" && tw.parent() instanceof AST_Call) {
  6551. for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
  6552. s.uses_eval = true;
  6553. }
  6554. }
  6555. var sym;
  6556. if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name
  6557. || !(sym = node.scope.find_variable(name))) {
  6558. sym = self.def_global(node);
  6559. if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;
  6560. } else if (sym.scope instanceof AST_Lambda && name == "arguments") {
  6561. sym.scope.uses_arguments = true;
  6562. }
  6563. node.thedef = sym;
  6564. node.reference(options);
  6565. if (node.scope.is_block_scope()
  6566. && !(sym.orig[0] instanceof AST_SymbolBlockDeclaration)) {
  6567. node.scope = node.scope.get_defun_scope();
  6568. }
  6569. return true;
  6570. }
  6571. // ensure mangling works if catch reuses a scope variable
  6572. var def;
  6573. if (node instanceof AST_SymbolCatch && (def = node.definition().redefined())) {
  6574. var s = node.scope;
  6575. while (s) {
  6576. push_uniq(s.enclosed, def);
  6577. if (s === def.scope) break;
  6578. s = s.parent_scope;
  6579. }
  6580. }
  6581. });
  6582. self.walk(tw);
  6583. // pass 3: work around IE8 and Safari catch scope bugs
  6584. if (options.ie8 || options.safari10) {
  6585. self.walk(new TreeWalker(function(node, descend) {
  6586. if (node instanceof AST_SymbolCatch) {
  6587. var name = node.name;
  6588. var refs = node.thedef.references;
  6589. var scope = node.thedef.defun;
  6590. var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
  6591. refs.forEach(function(ref) {
  6592. ref.thedef = def;
  6593. ref.reference(options);
  6594. });
  6595. node.thedef = def;
  6596. node.reference(options);
  6597. return true;
  6598. }
  6599. }));
  6600. }
  6601. // pass 4: add symbol definitions to loop scopes
  6602. // Safari/Webkit bug workaround - loop init let variable shadowing argument.
  6603. // https://github.com/mishoo/UglifyJS2/issues/1753
  6604. // https://bugs.webkit.org/show_bug.cgi?id=171041
  6605. if (options.safari10) {
  6606. for (var i = 0; i < for_scopes.length; i++) {
  6607. var scope = for_scopes[i];
  6608. scope.parent_scope.variables.each(function(def) {
  6609. push_uniq(scope.enclosed, def);
  6610. });
  6611. }
  6612. }
  6613. });
  6614. AST_Toplevel.DEFMETHOD("def_global", function(node) {
  6615. var globals = this.globals, name = node.name;
  6616. if (globals.has(name)) {
  6617. return globals.get(name);
  6618. } else {
  6619. var g = new SymbolDef(this, node);
  6620. g.undeclared = true;
  6621. g.global = true;
  6622. globals.set(name, g);
  6623. return g;
  6624. }
  6625. });
  6626. AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {
  6627. this.variables = new Dictionary(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
  6628. this.functions = new Dictionary(); // map name to AST_SymbolDefun (functions defined in this scope)
  6629. this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
  6630. this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
  6631. this.parent_scope = parent_scope; // the parent scope
  6632. this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes
  6633. this.cname = -1; // the current index for mangling functions/variables
  6634. });
  6635. AST_Node.DEFMETHOD("is_block_scope", return_false);
  6636. AST_Class.DEFMETHOD("is_block_scope", return_false);
  6637. AST_Lambda.DEFMETHOD("is_block_scope", return_false);
  6638. AST_Toplevel.DEFMETHOD("is_block_scope", return_false);
  6639. AST_SwitchBranch.DEFMETHOD("is_block_scope", return_false);
  6640. AST_Block.DEFMETHOD("is_block_scope", return_true);
  6641. AST_IterationStatement.DEFMETHOD("is_block_scope", return_true);
  6642. AST_Lambda.DEFMETHOD("init_scope_vars", function() {
  6643. AST_Scope.prototype.init_scope_vars.apply(this, arguments);
  6644. this.uses_arguments = false;
  6645. this.def_variable(new AST_SymbolFunarg({
  6646. name: "arguments",
  6647. start: this.start,
  6648. end: this.end
  6649. }));
  6650. });
  6651. AST_Arrow.DEFMETHOD("init_scope_vars", function() {
  6652. AST_Scope.prototype.init_scope_vars.apply(this, arguments);
  6653. this.uses_arguments = false;
  6654. });
  6655. AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
  6656. var def = this.definition();
  6657. var s = this.scope;
  6658. while (s) {
  6659. push_uniq(s.enclosed, def);
  6660. if (options.keep_fnames) {
  6661. s.functions.each(function(d) {
  6662. if (keep_name(options.keep_fnames, d.name)) {
  6663. push_uniq(def.scope.enclosed, d);
  6664. }
  6665. });
  6666. }
  6667. if (s === def.scope) break;
  6668. s = s.parent_scope;
  6669. }
  6670. });
  6671. AST_Symbol.DEFMETHOD("reference", function(options) {
  6672. this.definition().references.push(this);
  6673. this.mark_enclosed(options);
  6674. });
  6675. AST_Scope.DEFMETHOD("find_variable", function(name) {
  6676. if (name instanceof AST_Symbol) name = name.name;
  6677. return this.variables.get(name)
  6678. || (this.parent_scope && this.parent_scope.find_variable(name));
  6679. });
  6680. AST_Scope.DEFMETHOD("def_function", function(symbol, init) {
  6681. var def = this.def_variable(symbol, init);
  6682. if (!def.init || def.init instanceof AST_Defun) def.init = init;
  6683. this.functions.set(symbol.name, def);
  6684. return def;
  6685. });
  6686. AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
  6687. var def = this.variables.get(symbol.name);
  6688. if (def) {
  6689. def.orig.push(symbol);
  6690. if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {
  6691. def.init = init;
  6692. }
  6693. } else {
  6694. def = new SymbolDef(this, symbol, init);
  6695. this.variables.set(symbol.name, def);
  6696. def.global = !this.parent_scope;
  6697. }
  6698. return symbol.thedef = def;
  6699. });
  6700. function next_mangled(scope, options) {
  6701. var ext = scope.enclosed;
  6702. out: while (true) {
  6703. var m = base54(++scope.cname);
  6704. if (!is_identifier(m)) continue; // skip over "do"
  6705. // https://github.com/mishoo/UglifyJS2/issues/242 -- do not
  6706. // shadow a name reserved from mangling.
  6707. if (member(m, options.reserved)) continue;
  6708. // we must ensure that the mangled name does not shadow a name
  6709. // from some parent scope that is referenced in this or in
  6710. // inner scopes.
  6711. for (var i = ext.length; --i >= 0;) {
  6712. var sym = ext[i];
  6713. var name = sym.mangled_name || (sym.unmangleable(options) && sym.name);
  6714. if (m == name) continue out;
  6715. }
  6716. return m;
  6717. }
  6718. }
  6719. AST_Scope.DEFMETHOD("next_mangled", function(options) {
  6720. return next_mangled(this, options);
  6721. });
  6722. AST_Toplevel.DEFMETHOD("next_mangled", function(options) {
  6723. var name;
  6724. do {
  6725. name = next_mangled(this, options);
  6726. } while (this.mangled_names.has(name));
  6727. return name;
  6728. });
  6729. AST_Function.DEFMETHOD("next_mangled", function(options, def) {
  6730. // #179, #326
  6731. // in Safari strict mode, something like (function x(x){...}) is a syntax error;
  6732. // a function expression's argument cannot shadow the function expression's name
  6733. var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
  6734. // the function's mangled_name is null when keep_fnames is true
  6735. var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
  6736. while (true) {
  6737. var name = next_mangled(this, options);
  6738. if (!tricky_name || tricky_name != name)
  6739. return name;
  6740. }
  6741. });
  6742. AST_Symbol.DEFMETHOD("unmangleable", function(options) {
  6743. var def = this.definition();
  6744. return !def || def.unmangleable(options);
  6745. });
  6746. // labels are always mangleable
  6747. AST_Label.DEFMETHOD("unmangleable", return_false);
  6748. AST_Symbol.DEFMETHOD("unreferenced", function() {
  6749. return !this.definition().references.length && !this.scope.pinned();
  6750. });
  6751. AST_Symbol.DEFMETHOD("definition", function() {
  6752. return this.thedef;
  6753. });
  6754. AST_Symbol.DEFMETHOD("global", function() {
  6755. return this.definition().global;
  6756. });
  6757. AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
  6758. options = defaults(options, {
  6759. eval : false,
  6760. ie8 : false,
  6761. keep_classnames: false,
  6762. keep_fnames : false,
  6763. module : false,
  6764. reserved : [],
  6765. toplevel : false,
  6766. });
  6767. if (options["module"]) {
  6768. options.toplevel = true;
  6769. }
  6770. if (!Array.isArray(options.reserved)) options.reserved = [];
  6771. // Never mangle arguments
  6772. push_uniq(options.reserved, "arguments");
  6773. return options;
  6774. });
  6775. AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
  6776. options = this._default_mangler_options(options);
  6777. // We only need to mangle declaration nodes. Special logic wired
  6778. // into the code generator will display the mangled name if it's
  6779. // present (and for AST_SymbolRef-s it'll use the mangled name of
  6780. // the AST_SymbolDeclaration that it points to).
  6781. var lname = -1;
  6782. var to_mangle = [];
  6783. var mangled_names = this.mangled_names = new Set();
  6784. if (options.cache) {
  6785. this.globals.each(collect);
  6786. if (options.cache.props) {
  6787. options.cache.props.each(function(mangled_name) {
  6788. mangled_names.add(mangled_name);
  6789. });
  6790. }
  6791. }
  6792. var tw = new TreeWalker(function(node, descend) {
  6793. if (node instanceof AST_LabeledStatement) {
  6794. // lname is incremented when we get to the AST_Label
  6795. var save_nesting = lname;
  6796. descend();
  6797. lname = save_nesting;
  6798. return true; // don't descend again in TreeWalker
  6799. }
  6800. if (node instanceof AST_Scope) {
  6801. node.variables.each(collect);
  6802. return;
  6803. }
  6804. if (node.is_block_scope()) {
  6805. node.block_scope.variables.each(collect);
  6806. return;
  6807. }
  6808. if (node instanceof AST_Label) {
  6809. var name;
  6810. do name = base54(++lname); while (!is_identifier(name));
  6811. node.mangled_name = name;
  6812. return true;
  6813. }
  6814. if (!(options.ie8 || options.safari10) && node instanceof AST_SymbolCatch) {
  6815. to_mangle.push(node.definition());
  6816. return;
  6817. }
  6818. });
  6819. this.walk(tw);
  6820. to_mangle.forEach(function(def) { def.mangle(options); });
  6821. function collect(symbol) {
  6822. if (!member(symbol.name, options.reserved)) {
  6823. if (!(symbol.export & MASK_EXPORT_DONT_MANGLE)) {
  6824. to_mangle.push(symbol);
  6825. }
  6826. }
  6827. }
  6828. });
  6829. AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
  6830. var cache = options.cache && options.cache.props;
  6831. var avoid = Object.create(null);
  6832. options.reserved.forEach(to_avoid);
  6833. this.globals.each(add_def);
  6834. this.walk(new TreeWalker(function(node) {
  6835. if (node instanceof AST_Scope) node.variables.each(add_def);
  6836. if (node instanceof AST_SymbolCatch) add_def(node.definition());
  6837. }));
  6838. return avoid;
  6839. function to_avoid(name) {
  6840. avoid[name] = true;
  6841. }
  6842. function add_def(def) {
  6843. var name = def.name;
  6844. if (def.global && cache && cache.has(name)) name = cache.get(name);
  6845. else if (!def.unmangleable(options)) return;
  6846. to_avoid(name);
  6847. }
  6848. });
  6849. AST_Toplevel.DEFMETHOD("expand_names", function(options) {
  6850. base54.reset();
  6851. base54.sort();
  6852. options = this._default_mangler_options(options);
  6853. var avoid = this.find_colliding_names(options);
  6854. var cname = 0;
  6855. this.globals.each(rename);
  6856. this.walk(new TreeWalker(function(node) {
  6857. if (node instanceof AST_Scope) node.variables.each(rename);
  6858. if (node instanceof AST_SymbolCatch) rename(node.definition());
  6859. }));
  6860. function next_name() {
  6861. var name;
  6862. do {
  6863. name = base54(cname++);
  6864. } while (avoid[name] || !is_identifier(name));
  6865. return name;
  6866. }
  6867. function rename(def) {
  6868. if (def.global && options.cache) return;
  6869. if (def.unmangleable(options)) return;
  6870. if (member(def.name, options.reserved)) return;
  6871. var d = def.redefined();
  6872. def.name = d ? d.name : next_name();
  6873. def.orig.forEach(function(sym) {
  6874. sym.name = def.name;
  6875. });
  6876. def.references.forEach(function(sym) {
  6877. sym.name = def.name;
  6878. });
  6879. }
  6880. });
  6881. AST_Node.DEFMETHOD("tail_node", return_this);
  6882. AST_Sequence.DEFMETHOD("tail_node", function() {
  6883. return this.expressions[this.expressions.length - 1];
  6884. });
  6885. AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
  6886. options = this._default_mangler_options(options);
  6887. try {
  6888. AST_Node.prototype.print = function(stream, force_parens) {
  6889. this._print(stream, force_parens);
  6890. if (this instanceof AST_Symbol && !this.unmangleable(options)) {
  6891. base54.consider(this.name, -1);
  6892. } else if (options.properties) {
  6893. if (this instanceof AST_Dot) {
  6894. base54.consider(this.property, -1);
  6895. } else if (this instanceof AST_Sub) {
  6896. skip_string(this.property);
  6897. }
  6898. }
  6899. };
  6900. base54.consider(this.print_to_string(), 1);
  6901. } finally {
  6902. AST_Node.prototype.print = AST_Node.prototype._print;
  6903. }
  6904. base54.sort();
  6905. function skip_string(node) {
  6906. if (node instanceof AST_String) {
  6907. base54.consider(node.value, -1);
  6908. } else if (node instanceof AST_Conditional) {
  6909. skip_string(node.consequent);
  6910. skip_string(node.alternative);
  6911. } else if (node instanceof AST_Sequence) {
  6912. skip_string(node.tail_node());
  6913. }
  6914. }
  6915. });
  6916. var base54 = (function() {
  6917. var leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split("");
  6918. var digits = "0123456789".split("");
  6919. var chars, frequency;
  6920. function reset() {
  6921. frequency = Object.create(null);
  6922. leading.forEach(function(ch) {
  6923. frequency[ch] = 0;
  6924. });
  6925. digits.forEach(function(ch) {
  6926. frequency[ch] = 0;
  6927. });
  6928. }
  6929. base54.consider = function(str, delta) {
  6930. for (var i = str.length; --i >= 0;) {
  6931. frequency[str[i]] += delta;
  6932. }
  6933. };
  6934. function compare(a, b) {
  6935. return frequency[b] - frequency[a];
  6936. }
  6937. base54.sort = function() {
  6938. chars = mergeSort(leading, compare).concat(mergeSort(digits, compare));
  6939. };
  6940. base54.reset = reset;
  6941. reset();
  6942. function base54(num) {
  6943. var ret = "", base = 54;
  6944. num++;
  6945. do {
  6946. num--;
  6947. ret += chars[num % base];
  6948. num = Math.floor(num / base);
  6949. base = 64;
  6950. } while (num > 0);
  6951. return ret;
  6952. }
  6953. return base54;
  6954. })();
  6955. /***********************************************************************
  6956. A JavaScript tokenizer / parser / beautifier / compressor.
  6957. https://github.com/mishoo/UglifyJS2
  6958. -------------------------------- (C) ---------------------------------
  6959. Author: Mihai Bazon
  6960. <mihai.bazon@gmail.com>
  6961. http://mihai.bazon.net/blog
  6962. Distributed under the BSD license:
  6963. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  6964. Redistribution and use in source and binary forms, with or without
  6965. modification, are permitted provided that the following conditions
  6966. are met:
  6967. * Redistributions of source code must retain the above
  6968. copyright notice, this list of conditions and the following
  6969. disclaimer.
  6970. * Redistributions in binary form must reproduce the above
  6971. copyright notice, this list of conditions and the following
  6972. disclaimer in the documentation and/or other materials
  6973. provided with the distribution.
  6974. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  6975. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  6976. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  6977. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  6978. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  6979. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  6980. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  6981. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  6982. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  6983. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  6984. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  6985. SUCH DAMAGE.
  6986. ***********************************************************************/
  6987. function Compressor(options, false_by_default) {
  6988. if (!(this instanceof Compressor))
  6989. return new Compressor(options, false_by_default);
  6990. TreeTransformer.call(this, this.before, this.after);
  6991. if (options.defaults !== undefined && !options.defaults) false_by_default = true;
  6992. this.options = defaults(options, {
  6993. arguments : false,
  6994. arrows : !false_by_default,
  6995. booleans : !false_by_default,
  6996. booleans_as_integers : false,
  6997. collapse_vars : !false_by_default,
  6998. comparisons : !false_by_default,
  6999. computed_props: !false_by_default,
  7000. conditionals : !false_by_default,
  7001. dead_code : !false_by_default,
  7002. defaults : true,
  7003. directives : !false_by_default,
  7004. drop_console : false,
  7005. drop_debugger : !false_by_default,
  7006. ecma : 5,
  7007. evaluate : !false_by_default,
  7008. expression : false,
  7009. global_defs : false,
  7010. hoist_funs : false,
  7011. hoist_props : !false_by_default,
  7012. hoist_vars : false,
  7013. ie8 : false,
  7014. if_return : !false_by_default,
  7015. inline : !false_by_default,
  7016. join_vars : !false_by_default,
  7017. keep_classnames: false,
  7018. keep_fargs : true,
  7019. keep_fnames : false,
  7020. keep_infinity : false,
  7021. loops : !false_by_default,
  7022. module : false,
  7023. negate_iife : !false_by_default,
  7024. passes : 1,
  7025. properties : !false_by_default,
  7026. pure_getters : !false_by_default && "strict",
  7027. pure_funcs : null,
  7028. reduce_funcs : !false_by_default,
  7029. reduce_vars : !false_by_default,
  7030. sequences : !false_by_default,
  7031. side_effects : !false_by_default,
  7032. switches : !false_by_default,
  7033. top_retain : null,
  7034. toplevel : !!(options && options["top_retain"]),
  7035. typeofs : !false_by_default,
  7036. unsafe : false,
  7037. unsafe_arrows : false,
  7038. unsafe_comps : false,
  7039. unsafe_Function: false,
  7040. unsafe_math : false,
  7041. unsafe_methods: false,
  7042. unsafe_proto : false,
  7043. unsafe_regexp : false,
  7044. unsafe_undefined: false,
  7045. unused : !false_by_default,
  7046. warnings : false,
  7047. }, true);
  7048. var global_defs = this.options["global_defs"];
  7049. if (typeof global_defs == "object") for (var key in global_defs) {
  7050. if (/^@/.test(key) && HOP(global_defs, key)) {
  7051. global_defs[key.slice(1)] = parse(global_defs[key], {
  7052. expression: true
  7053. });
  7054. }
  7055. }
  7056. if (this.options["inline"] === true) this.options["inline"] = 3;
  7057. var pure_funcs = this.options["pure_funcs"];
  7058. if (typeof pure_funcs == "function") {
  7059. this.pure_funcs = pure_funcs;
  7060. } else {
  7061. this.pure_funcs = pure_funcs ? function(node) {
  7062. return !pure_funcs.includes(node.expression.print_to_string());
  7063. } : return_true;
  7064. }
  7065. var top_retain = this.options["top_retain"];
  7066. if (top_retain instanceof RegExp) {
  7067. this.top_retain = function(def) {
  7068. return top_retain.test(def.name);
  7069. };
  7070. } else if (typeof top_retain == "function") {
  7071. this.top_retain = top_retain;
  7072. } else if (top_retain) {
  7073. if (typeof top_retain == "string") {
  7074. top_retain = top_retain.split(/,/);
  7075. }
  7076. this.top_retain = function(def) {
  7077. return top_retain.includes(def.name);
  7078. };
  7079. }
  7080. if (this.options["module"]) {
  7081. this.directives["use strict"] = true;
  7082. this.options["toplevel"] = true;
  7083. }
  7084. var toplevel = this.options["toplevel"];
  7085. this.toplevel = typeof toplevel == "string" ? {
  7086. funcs: /funcs/.test(toplevel),
  7087. vars: /vars/.test(toplevel)
  7088. } : {
  7089. funcs: toplevel,
  7090. vars: toplevel
  7091. };
  7092. var sequences = this.options["sequences"];
  7093. this.sequences_limit = sequences == 1 ? 800 : sequences | 0;
  7094. this.warnings_produced = {};
  7095. }
  7096. Compressor.prototype = new TreeTransformer;
  7097. merge(Compressor.prototype, {
  7098. option: function(key) { return this.options[key]; },
  7099. exposed: function(def) {
  7100. if (def.export) return true;
  7101. if (def.global) for (var i = 0, len = def.orig.length; i < len; i++)
  7102. if (!this.toplevel[def.orig[i] instanceof AST_SymbolDefun ? "funcs" : "vars"])
  7103. return true;
  7104. return false;
  7105. },
  7106. in_boolean_context: function() {
  7107. if (!this.option("booleans")) return false;
  7108. var self = this.self();
  7109. for (var i = 0, p; p = this.parent(i); i++) {
  7110. if (p instanceof AST_SimpleStatement
  7111. || p instanceof AST_Conditional && p.condition === self
  7112. || p instanceof AST_DWLoop && p.condition === self
  7113. || p instanceof AST_For && p.condition === self
  7114. || p instanceof AST_If && p.condition === self
  7115. || p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) {
  7116. return true;
  7117. }
  7118. if (p instanceof AST_Binary && (p.operator == "&&" || p.operator == "||")
  7119. || p instanceof AST_Conditional
  7120. || p.tail_node() === self) {
  7121. self = p;
  7122. } else {
  7123. return false;
  7124. }
  7125. }
  7126. },
  7127. compress: function(node) {
  7128. node = node.resolve_defines(this);
  7129. if (this.option("expression")) {
  7130. node.process_expression(true);
  7131. }
  7132. var passes = +this.options.passes || 1;
  7133. var min_count = 1 / 0;
  7134. var stopping = false;
  7135. var mangle = { ie8: this.option("ie8") };
  7136. for (var pass = 0; pass < passes; pass++) {
  7137. node.figure_out_scope(mangle);
  7138. if (pass === 0 && this.option("drop_console")) {
  7139. // must be run before reduce_vars and compress pass
  7140. node = node.drop_console();
  7141. }
  7142. if (pass > 0 || this.option("reduce_vars"))
  7143. node.reset_opt_flags(this);
  7144. node = node.transform(this);
  7145. if (passes > 1) {
  7146. var count = 0;
  7147. node.walk(new TreeWalker(function() {
  7148. count++;
  7149. }));
  7150. this.info("pass " + pass + ": last_count: " + min_count + ", count: " + count);
  7151. if (count < min_count) {
  7152. min_count = count;
  7153. stopping = false;
  7154. } else if (stopping) {
  7155. break;
  7156. } else {
  7157. stopping = true;
  7158. }
  7159. }
  7160. }
  7161. if (this.option("expression")) {
  7162. node.process_expression(false);
  7163. }
  7164. return node;
  7165. },
  7166. info: function() {
  7167. if (this.options.warnings == "verbose") {
  7168. AST_Node.warn.apply(AST_Node, arguments);
  7169. }
  7170. },
  7171. warn: function(text, props) {
  7172. if (this.options.warnings) {
  7173. // only emit unique warnings
  7174. var message = string_template(text, props);
  7175. if (!(message in this.warnings_produced)) {
  7176. this.warnings_produced[message] = true;
  7177. AST_Node.warn.apply(AST_Node, arguments);
  7178. }
  7179. }
  7180. },
  7181. clear_warnings: function() {
  7182. this.warnings_produced = {};
  7183. },
  7184. before: function(node, descend, in_list) {
  7185. if (node._squeezed) return node;
  7186. var was_scope = false;
  7187. if (node instanceof AST_Scope) {
  7188. node = node.hoist_properties(this);
  7189. node = node.hoist_declarations(this);
  7190. was_scope = true;
  7191. }
  7192. // Before https://github.com/mishoo/UglifyJS2/pull/1602 AST_Node.optimize()
  7193. // would call AST_Node.transform() if a different instance of AST_Node is
  7194. // produced after def_optimize().
  7195. // This corrupts TreeWalker.stack, which cause AST look-ups to malfunction.
  7196. // Migrate and defer all children's AST_Node.transform() to below, which
  7197. // will now happen after this parent AST_Node has been properly substituted
  7198. // thus gives a consistent AST snapshot.
  7199. descend(node, this);
  7200. // Existing code relies on how AST_Node.optimize() worked, and omitting the
  7201. // following replacement call would result in degraded efficiency of both
  7202. // output and performance.
  7203. descend(node, this);
  7204. var opt = node.optimize(this);
  7205. if (was_scope && opt instanceof AST_Scope) {
  7206. opt.drop_unused(this);
  7207. descend(opt, this);
  7208. }
  7209. if (opt === node) opt._squeezed = true;
  7210. return opt;
  7211. }
  7212. });
  7213. (function() {
  7214. function def_optimize(node, optimizer) {
  7215. node.DEFMETHOD("optimize", function(compressor) {
  7216. var self = this;
  7217. if (self._optimized) return self;
  7218. if (compressor.has_directive("use asm")) return self;
  7219. var opt = optimizer(self, compressor);
  7220. opt._optimized = true;
  7221. return opt;
  7222. });
  7223. }
  7224. def_optimize(AST_Node, function(self, compressor) {
  7225. return self;
  7226. });
  7227. AST_Toplevel.DEFMETHOD("drop_console", function() {
  7228. return this.transform(new TreeTransformer(function(self) {
  7229. if (self.TYPE == "Call") {
  7230. var exp = self.expression;
  7231. if (exp instanceof AST_PropAccess) {
  7232. var name = exp.expression;
  7233. while (name.expression) {
  7234. name = name.expression;
  7235. }
  7236. if (is_undeclared_ref(name) && name.name == "console") {
  7237. return make_node(AST_Undefined, self);
  7238. }
  7239. }
  7240. }
  7241. }));
  7242. });
  7243. AST_Node.DEFMETHOD("equivalent_to", function(node) {
  7244. return this.TYPE == node.TYPE && this.print_to_string() == node.print_to_string();
  7245. });
  7246. AST_Scope.DEFMETHOD("process_expression", function(insert, compressor) {
  7247. var self = this;
  7248. var tt = new TreeTransformer(function(node) {
  7249. if (insert && node instanceof AST_SimpleStatement) {
  7250. return make_node(AST_Return, node, {
  7251. value: node.body
  7252. });
  7253. }
  7254. if (!insert && node instanceof AST_Return) {
  7255. if (compressor) {
  7256. var value = node.value && node.value.drop_side_effect_free(compressor, true);
  7257. return value ? make_node(AST_SimpleStatement, node, {
  7258. body: value
  7259. }) : make_node(AST_EmptyStatement, node);
  7260. }
  7261. return make_node(AST_SimpleStatement, node, {
  7262. body: node.value || make_node(AST_UnaryPrefix, node, {
  7263. operator: "void",
  7264. expression: make_node(AST_Number, node, {
  7265. value: 0
  7266. })
  7267. })
  7268. });
  7269. }
  7270. if (node instanceof AST_Class || node instanceof AST_Lambda && node !== self) {
  7271. return node;
  7272. }
  7273. if (node instanceof AST_Block) {
  7274. var index = node.body.length - 1;
  7275. if (index >= 0) {
  7276. node.body[index] = node.body[index].transform(tt);
  7277. }
  7278. } else if (node instanceof AST_If) {
  7279. node.body = node.body.transform(tt);
  7280. if (node.alternative) {
  7281. node.alternative = node.alternative.transform(tt);
  7282. }
  7283. } else if (node instanceof AST_With) {
  7284. node.body = node.body.transform(tt);
  7285. }
  7286. return node;
  7287. });
  7288. self.transform(tt);
  7289. });
  7290. function read_property(obj, key) {
  7291. key = get_value(key);
  7292. if (key instanceof AST_Node) return;
  7293. var value;
  7294. if (obj instanceof AST_Array) {
  7295. var elements = obj.elements;
  7296. if (key == "length") return make_node_from_constant(elements.length, obj);
  7297. if (typeof key == "number" && key in elements) value = elements[key];
  7298. } else if (obj instanceof AST_Object) {
  7299. key = "" + key;
  7300. var props = obj.properties;
  7301. for (var i = props.length; --i >= 0;) {
  7302. var prop = props[i];
  7303. if (!(prop instanceof AST_ObjectKeyVal)) return;
  7304. if (!value && props[i].key === key) value = props[i].value;
  7305. }
  7306. }
  7307. return value instanceof AST_SymbolRef && value.fixed_value() || value;
  7308. }
  7309. function is_modified(compressor, tw, node, value, level, immutable) {
  7310. var parent = tw.parent(level);
  7311. var lhs = is_lhs(node, parent);
  7312. if (lhs) return lhs;
  7313. if (!immutable
  7314. && parent instanceof AST_Call
  7315. && parent.expression === node
  7316. && !(value instanceof AST_Arrow)
  7317. && !(value instanceof AST_Class)
  7318. && !parent.is_expr_pure(compressor)
  7319. && (!(value instanceof AST_Function)
  7320. || !(parent instanceof AST_New) && value.contains_this())) {
  7321. return true;
  7322. }
  7323. if (parent instanceof AST_Array) {
  7324. return is_modified(compressor, tw, parent, parent, level + 1);
  7325. }
  7326. if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
  7327. var obj = tw.parent(level + 1);
  7328. return is_modified(compressor, tw, obj, obj, level + 2);
  7329. }
  7330. if (parent instanceof AST_PropAccess && parent.expression === node) {
  7331. var prop = read_property(value, parent.property);
  7332. return !immutable && is_modified(compressor, tw, parent, prop, level + 1);
  7333. }
  7334. }
  7335. (function(def_reduce_vars) {
  7336. def_reduce_vars(AST_Node, noop);
  7337. function reset_def(compressor, def) {
  7338. def.assignments = 0;
  7339. def.chained = false;
  7340. def.direct_access = false;
  7341. def.escaped = false;
  7342. if (def.scope.pinned()) {
  7343. def.fixed = false;
  7344. } else if (def.orig[0] instanceof AST_SymbolConst || !compressor.exposed(def)) {
  7345. def.fixed = def.init;
  7346. } else {
  7347. def.fixed = false;
  7348. }
  7349. def.recursive_refs = 0;
  7350. def.references = [];
  7351. def.should_replace = undefined;
  7352. def.single_use = undefined;
  7353. }
  7354. function reset_variables(tw, compressor, node) {
  7355. node.variables.each(function(def) {
  7356. reset_def(compressor, def);
  7357. if (def.fixed === null) {
  7358. def.safe_ids = tw.safe_ids;
  7359. mark(tw, def, true);
  7360. } else if (def.fixed) {
  7361. tw.loop_ids[def.id] = tw.in_loop;
  7362. mark(tw, def, true);
  7363. }
  7364. });
  7365. }
  7366. function reset_block_variables(compressor, node) {
  7367. if (node.block_scope) node.block_scope.variables.each(function(def) {
  7368. reset_def(compressor, def);
  7369. });
  7370. }
  7371. function push(tw) {
  7372. tw.safe_ids = Object.create(tw.safe_ids);
  7373. }
  7374. function pop(tw) {
  7375. tw.safe_ids = Object.getPrototypeOf(tw.safe_ids);
  7376. }
  7377. function mark(tw, def, safe) {
  7378. tw.safe_ids[def.id] = safe;
  7379. }
  7380. function safe_to_read(tw, def) {
  7381. if (def.single_use == "m") return false;
  7382. if (tw.safe_ids[def.id]) {
  7383. if (def.fixed == null) {
  7384. var orig = def.orig[0];
  7385. if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false;
  7386. def.fixed = make_node(AST_Undefined, orig);
  7387. }
  7388. return true;
  7389. }
  7390. return def.fixed instanceof AST_Defun;
  7391. }
  7392. function safe_to_assign(tw, def, value) {
  7393. if (def.fixed === undefined) return true;
  7394. if (def.fixed === null && def.safe_ids) {
  7395. def.safe_ids[def.id] = false;
  7396. delete def.safe_ids;
  7397. return true;
  7398. }
  7399. if (!HOP(tw.safe_ids, def.id)) return false;
  7400. if (!safe_to_read(tw, def)) return false;
  7401. if (def.fixed === false) return false;
  7402. if (def.fixed != null && (!value || def.references.length > def.assignments)) return false;
  7403. return all(def.orig, function(sym) {
  7404. return !(sym instanceof AST_SymbolConst
  7405. || sym instanceof AST_SymbolDefun
  7406. || sym instanceof AST_SymbolLambda);
  7407. });
  7408. }
  7409. function ref_once(tw, compressor, def) {
  7410. return compressor.option("unused")
  7411. && !def.scope.pinned()
  7412. && def.references.length - def.recursive_refs == 1
  7413. && tw.loop_ids[def.id] === tw.in_loop;
  7414. }
  7415. function is_immutable(value) {
  7416. if (!value) return false;
  7417. return value.is_constant()
  7418. || value instanceof AST_Lambda
  7419. || value instanceof AST_This;
  7420. }
  7421. function mark_escaped(tw, d, scope, node, value, level, depth) {
  7422. var parent = tw.parent(level);
  7423. if (value) {
  7424. if (value.is_constant()) return;
  7425. if (value instanceof AST_ClassExpression) return;
  7426. }
  7427. if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
  7428. || parent instanceof AST_Call && (node !== parent.expression || parent instanceof AST_New)
  7429. || parent instanceof AST_Exit && node === parent.value && node.scope !== d.scope
  7430. || parent instanceof AST_VarDef && node === parent.value
  7431. || parent instanceof AST_Yield && node === parent.value && node.scope !== d.scope) {
  7432. if (depth > 1 && !(value && value.is_constant_expression(scope))) depth = 1;
  7433. if (!d.escaped || d.escaped > depth) d.escaped = depth;
  7434. return;
  7435. } else if (parent instanceof AST_Array
  7436. || parent instanceof AST_Await
  7437. || parent instanceof AST_Binary && lazy_op(parent.operator)
  7438. || parent instanceof AST_Conditional && node !== parent.condition
  7439. || parent instanceof AST_Expansion
  7440. || parent instanceof AST_Sequence && node === parent.tail_node()) {
  7441. mark_escaped(tw, d, scope, parent, parent, level + 1, depth);
  7442. } else if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
  7443. var obj = tw.parent(level + 1);
  7444. mark_escaped(tw, d, scope, obj, obj, level + 2, depth);
  7445. } else if (parent instanceof AST_PropAccess && node === parent.expression) {
  7446. value = read_property(value, parent.property);
  7447. mark_escaped(tw, d, scope, parent, value, level + 1, depth + 1);
  7448. if (value) return;
  7449. }
  7450. if (level > 0) return;
  7451. if (parent instanceof AST_Sequence && node !== parent.tail_node()) return;
  7452. if (parent instanceof AST_SimpleStatement) return;
  7453. d.direct_access = true;
  7454. }
  7455. var suppressor = new TreeWalker(function(node) {
  7456. if (!(node instanceof AST_Symbol)) return;
  7457. var d = node.definition();
  7458. if (!d) return;
  7459. if (node instanceof AST_SymbolRef) d.references.push(node);
  7460. d.fixed = false;
  7461. });
  7462. def_reduce_vars(AST_Accessor, function(tw, descend, compressor) {
  7463. push(tw);
  7464. reset_variables(tw, compressor, this);
  7465. descend();
  7466. pop(tw);
  7467. return true;
  7468. });
  7469. def_reduce_vars(AST_Arrow, mark_func_expr);
  7470. def_reduce_vars(AST_Assign, function(tw, descend, compressor) {
  7471. var node = this;
  7472. if (node.left instanceof AST_Destructuring) {
  7473. node.left.walk(suppressor);
  7474. return;
  7475. }
  7476. var sym = node.left;
  7477. if (!(sym instanceof AST_SymbolRef)) return;
  7478. var d = sym.definition();
  7479. var safe = safe_to_assign(tw, d, sym.scope, node.right);
  7480. d.assignments++;
  7481. if (!safe) return;
  7482. var fixed = d.fixed;
  7483. if (!fixed && node.operator != "=") return;
  7484. var eq = node.operator == "=";
  7485. var value = eq ? node.right : node;
  7486. if (is_modified(compressor, tw, node, value, 0)) return;
  7487. d.references.push(sym);
  7488. if (!eq) d.chained = true;
  7489. d.fixed = eq ? function() {
  7490. return node.right;
  7491. } : function() {
  7492. return make_node(AST_Binary, node, {
  7493. operator: node.operator.slice(0, -1),
  7494. left: fixed instanceof AST_Node ? fixed : fixed(),
  7495. right: node.right
  7496. });
  7497. };
  7498. mark(tw, d, false);
  7499. node.right.walk(tw);
  7500. mark(tw, d, true);
  7501. mark_escaped(tw, d, sym.scope, node, value, 0, 1);
  7502. return true;
  7503. });
  7504. def_reduce_vars(AST_Binary, function(tw) {
  7505. if (!lazy_op(this.operator)) return;
  7506. this.left.walk(tw);
  7507. push(tw);
  7508. this.right.walk(tw);
  7509. pop(tw);
  7510. return true;
  7511. });
  7512. def_reduce_vars(AST_Block, function(tw, descend, compressor) {
  7513. reset_block_variables(compressor, this);
  7514. });
  7515. def_reduce_vars(AST_Case, function(tw) {
  7516. push(tw);
  7517. this.expression.walk(tw);
  7518. pop(tw);
  7519. push(tw);
  7520. walk_body(this, tw);
  7521. pop(tw);
  7522. return true;
  7523. });
  7524. def_reduce_vars(AST_ClassExpression, function(tw, descend) {
  7525. this.inlined = false;
  7526. push(tw);
  7527. descend();
  7528. pop(tw);
  7529. return true;
  7530. });
  7531. def_reduce_vars(AST_Conditional, function(tw) {
  7532. this.condition.walk(tw);
  7533. push(tw);
  7534. this.consequent.walk(tw);
  7535. pop(tw);
  7536. push(tw);
  7537. this.alternative.walk(tw);
  7538. pop(tw);
  7539. return true;
  7540. });
  7541. def_reduce_vars(AST_Default, function(tw, descend) {
  7542. push(tw);
  7543. descend();
  7544. pop(tw);
  7545. return true;
  7546. });
  7547. function mark_def_node(tw, descend, compressor) {
  7548. this.inlined = false;
  7549. var save_ids = tw.safe_ids;
  7550. tw.safe_ids = Object.create(null);
  7551. reset_variables(tw, compressor, this);
  7552. descend();
  7553. tw.safe_ids = save_ids;
  7554. return true;
  7555. }
  7556. def_reduce_vars(AST_DefClass, mark_def_node);
  7557. def_reduce_vars(AST_Defun, mark_def_node);
  7558. def_reduce_vars(AST_Do, function(tw, descend, compressor) {
  7559. reset_block_variables(compressor, this);
  7560. var saved_loop = tw.in_loop;
  7561. tw.in_loop = this;
  7562. push(tw);
  7563. this.body.walk(tw);
  7564. if (has_break_or_continue(this)) {
  7565. pop(tw);
  7566. push(tw);
  7567. }
  7568. this.condition.walk(tw);
  7569. pop(tw);
  7570. tw.in_loop = saved_loop;
  7571. return true;
  7572. });
  7573. def_reduce_vars(AST_For, function(tw, descend, compressor) {
  7574. reset_block_variables(compressor, this);
  7575. if (this.init) this.init.walk(tw);
  7576. var saved_loop = tw.in_loop;
  7577. tw.in_loop = this;
  7578. push(tw);
  7579. if (this.condition) this.condition.walk(tw);
  7580. this.body.walk(tw);
  7581. if (this.step) {
  7582. if (has_break_or_continue(this)) {
  7583. pop(tw);
  7584. push(tw);
  7585. }
  7586. this.step.walk(tw);
  7587. }
  7588. pop(tw);
  7589. tw.in_loop = saved_loop;
  7590. return true;
  7591. });
  7592. def_reduce_vars(AST_ForIn, function(tw, descend, compressor) {
  7593. reset_block_variables(compressor, this);
  7594. this.init.walk(suppressor);
  7595. this.object.walk(tw);
  7596. var saved_loop = tw.in_loop;
  7597. tw.in_loop = this;
  7598. push(tw);
  7599. this.body.walk(tw);
  7600. pop(tw);
  7601. tw.in_loop = saved_loop;
  7602. return true;
  7603. });
  7604. function mark_func_expr(tw, descend, compressor) {
  7605. var node = this;
  7606. node.inlined = false;
  7607. push(tw);
  7608. reset_variables(tw, compressor, node);
  7609. var iife;
  7610. if (!node.name
  7611. && (iife = tw.parent()) instanceof AST_Call
  7612. && iife.expression === node) {
  7613. // Virtually turn IIFE parameters into variable definitions:
  7614. // (function(a,b) {...})(c,d) => (function() {var a=c,b=d; ...})()
  7615. // So existing transformation rules can work on them.
  7616. node.argnames.forEach(function(arg, i) {
  7617. if (!arg.definition) return;
  7618. var d = arg.definition();
  7619. if (d.fixed === undefined && (!node.uses_arguments || tw.has_directive("use strict"))) {
  7620. d.fixed = function() {
  7621. return iife.args[i] || make_node(AST_Undefined, iife);
  7622. };
  7623. tw.loop_ids[d.id] = tw.in_loop;
  7624. mark(tw, d, true);
  7625. } else {
  7626. d.fixed = false;
  7627. }
  7628. });
  7629. }
  7630. descend();
  7631. pop(tw);
  7632. return true;
  7633. }
  7634. def_reduce_vars(AST_Function, mark_func_expr);
  7635. def_reduce_vars(AST_If, function(tw) {
  7636. this.condition.walk(tw);
  7637. push(tw);
  7638. this.body.walk(tw);
  7639. pop(tw);
  7640. if (this.alternative) {
  7641. push(tw);
  7642. this.alternative.walk(tw);
  7643. pop(tw);
  7644. }
  7645. return true;
  7646. });
  7647. def_reduce_vars(AST_LabeledStatement, function(tw) {
  7648. push(tw);
  7649. this.body.walk(tw);
  7650. pop(tw);
  7651. return true;
  7652. });
  7653. def_reduce_vars(AST_SymbolCatch, function() {
  7654. this.definition().fixed = false;
  7655. });
  7656. def_reduce_vars(AST_SymbolRef, function(tw, descend, compressor) {
  7657. var d = this.definition();
  7658. d.references.push(this);
  7659. if (d.references.length == 1
  7660. && !d.fixed
  7661. && d.orig[0] instanceof AST_SymbolDefun) {
  7662. tw.loop_ids[d.id] = tw.in_loop;
  7663. }
  7664. var value;
  7665. if (d.fixed === undefined || !safe_to_read(tw, d)) {
  7666. d.fixed = false;
  7667. } else if (d.fixed) {
  7668. value = this.fixed_value();
  7669. if (value instanceof AST_Lambda && recursive_ref(tw, d)) {
  7670. d.recursive_refs++;
  7671. } else if (value && !compressor.exposed(d) && ref_once(tw, compressor, d)) {
  7672. d.single_use = value instanceof AST_Lambda && !value.pinned()
  7673. || value instanceof AST_Class
  7674. || d.scope === this.scope && value.is_constant_expression();
  7675. } else {
  7676. d.single_use = false;
  7677. }
  7678. if (is_modified(compressor, tw, this, value, 0, is_immutable(value))) {
  7679. if (d.single_use) {
  7680. d.single_use = "m";
  7681. } else {
  7682. d.fixed = false;
  7683. }
  7684. }
  7685. }
  7686. mark_escaped(tw, d, this.scope, this, value, 0, 1);
  7687. });
  7688. def_reduce_vars(AST_Toplevel, function(tw, descend, compressor) {
  7689. this.globals.each(function(def) {
  7690. reset_def(compressor, def);
  7691. });
  7692. reset_variables(tw, compressor, this);
  7693. });
  7694. def_reduce_vars(AST_Try, function(tw, descend, compressor) {
  7695. reset_block_variables(compressor, this);
  7696. push(tw);
  7697. walk_body(this, tw);
  7698. pop(tw);
  7699. if (this.bcatch) {
  7700. push(tw);
  7701. this.bcatch.walk(tw);
  7702. pop(tw);
  7703. }
  7704. if (this.bfinally) this.bfinally.walk(tw);
  7705. return true;
  7706. });
  7707. def_reduce_vars(AST_Unary, function(tw, descend) {
  7708. var node = this;
  7709. if (node.operator != "++" && node.operator != "--") return;
  7710. var exp = node.expression;
  7711. if (!(exp instanceof AST_SymbolRef)) return;
  7712. var d = exp.definition();
  7713. var safe = safe_to_assign(tw, d, true);
  7714. d.assignments++;
  7715. if (!safe) return;
  7716. var fixed = d.fixed;
  7717. if (!fixed) return;
  7718. d.references.push(exp);
  7719. d.chained = true;
  7720. d.fixed = function() {
  7721. return make_node(AST_Binary, node, {
  7722. operator: node.operator.slice(0, -1),
  7723. left: make_node(AST_UnaryPrefix, node, {
  7724. operator: "+",
  7725. expression: fixed instanceof AST_Node ? fixed : fixed()
  7726. }),
  7727. right: make_node(AST_Number, node, {
  7728. value: 1
  7729. })
  7730. });
  7731. };
  7732. mark(tw, d, true);
  7733. return true;
  7734. });
  7735. def_reduce_vars(AST_VarDef, function(tw, descend) {
  7736. var node = this;
  7737. if (node.name instanceof AST_Destructuring) {
  7738. node.name.walk(suppressor);
  7739. return;
  7740. }
  7741. var d = node.name.definition();
  7742. if (node.value) {
  7743. if (safe_to_assign(tw, d, node.value)) {
  7744. d.fixed = function() {
  7745. return node.value;
  7746. };
  7747. tw.loop_ids[d.id] = tw.in_loop;
  7748. mark(tw, d, false);
  7749. descend();
  7750. mark(tw, d, true);
  7751. return true;
  7752. } else {
  7753. d.fixed = false;
  7754. }
  7755. }
  7756. });
  7757. def_reduce_vars(AST_While, function(tw, descend, compressor) {
  7758. reset_block_variables(compressor, this);
  7759. var saved_loop = tw.in_loop;
  7760. tw.in_loop = this;
  7761. push(tw);
  7762. descend();
  7763. pop(tw);
  7764. tw.in_loop = saved_loop;
  7765. return true;
  7766. });
  7767. })(function(node, func) {
  7768. node.DEFMETHOD("reduce_vars", func);
  7769. });
  7770. AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) {
  7771. var self = this;
  7772. var reduce_vars = compressor.option("reduce_vars");
  7773. var tw = new TreeWalker(function(node, descend) {
  7774. node._squeezed = false;
  7775. node._optimized = false;
  7776. if (reduce_vars) {
  7777. if (compressor.top_retain) {
  7778. if (tw.parent() === self)
  7779. node._top = true;
  7780. else
  7781. delete node._top;
  7782. }
  7783. return node.reduce_vars(tw, descend, compressor);
  7784. }
  7785. });
  7786. // Stack of look-up tables to keep track of whether a `SymbolDef` has been
  7787. // properly assigned before use:
  7788. // - `push()` & `pop()` when visiting conditional branches
  7789. // - backup & restore via `save_ids` when visiting out-of-order sections
  7790. tw.safe_ids = Object.create(null);
  7791. tw.in_loop = null;
  7792. tw.loop_ids = Object.create(null);
  7793. self.walk(tw);
  7794. });
  7795. AST_Symbol.DEFMETHOD("fixed_value", function() {
  7796. var fixed = this.definition().fixed;
  7797. if (!fixed || fixed instanceof AST_Node) return fixed;
  7798. return fixed();
  7799. });
  7800. AST_SymbolRef.DEFMETHOD("is_immutable", function() {
  7801. var orig = this.definition().orig;
  7802. return orig.length == 1 && orig[0] instanceof AST_SymbolLambda;
  7803. });
  7804. function is_func_expr(node) {
  7805. return node instanceof AST_Arrow || node instanceof AST_Function;
  7806. }
  7807. function is_lhs_read_only(lhs) {
  7808. if (lhs instanceof AST_This) return true;
  7809. if (lhs instanceof AST_SymbolRef) return lhs.definition().orig[0] instanceof AST_SymbolLambda;
  7810. if (lhs instanceof AST_PropAccess) {
  7811. lhs = lhs.expression;
  7812. if (lhs instanceof AST_SymbolRef) {
  7813. if (lhs.is_immutable()) return false;
  7814. lhs = lhs.fixed_value();
  7815. }
  7816. if (!lhs) return true;
  7817. if (lhs instanceof AST_RegExp) return false;
  7818. if (lhs instanceof AST_Constant) return true;
  7819. return is_lhs_read_only(lhs);
  7820. }
  7821. return false;
  7822. }
  7823. function is_ref_of(ref, type) {
  7824. if (!(ref instanceof AST_SymbolRef)) return false;
  7825. var orig = ref.definition().orig;
  7826. for (var i = orig.length; --i >= 0;) {
  7827. if (orig[i] instanceof type) return true;
  7828. }
  7829. }
  7830. function find_variable(compressor, name) {
  7831. var scope, i = 0;
  7832. while (scope = compressor.parent(i++)) {
  7833. if (scope instanceof AST_Scope) break;
  7834. if (scope instanceof AST_Catch && scope.argname) {
  7835. scope = scope.argname.definition().scope;
  7836. break;
  7837. }
  7838. }
  7839. return scope.find_variable(name);
  7840. }
  7841. function make_node(ctor, orig, props) {
  7842. if (!props) props = {};
  7843. if (orig) {
  7844. if (!props.start) props.start = orig.start;
  7845. if (!props.end) props.end = orig.end;
  7846. }
  7847. return new ctor(props);
  7848. }
  7849. function make_sequence(orig, expressions) {
  7850. if (expressions.length == 1) return expressions[0];
  7851. return make_node(AST_Sequence, orig, {
  7852. expressions: expressions.reduce(merge_sequence, [])
  7853. });
  7854. }
  7855. function make_node_from_constant(val, orig) {
  7856. switch (typeof val) {
  7857. case "string":
  7858. return make_node(AST_String, orig, {
  7859. value: val
  7860. });
  7861. case "number":
  7862. if (isNaN(val)) return make_node(AST_NaN, orig);
  7863. if (isFinite(val)) {
  7864. return 1 / val < 0 ? make_node(AST_UnaryPrefix, orig, {
  7865. operator: "-",
  7866. expression: make_node(AST_Number, orig, { value: -val })
  7867. }) : make_node(AST_Number, orig, { value: val });
  7868. }
  7869. return val < 0 ? make_node(AST_UnaryPrefix, orig, {
  7870. operator: "-",
  7871. expression: make_node(AST_Infinity, orig)
  7872. }) : make_node(AST_Infinity, orig);
  7873. case "boolean":
  7874. return make_node(val ? AST_True : AST_False, orig);
  7875. case "undefined":
  7876. return make_node(AST_Undefined, orig);
  7877. default:
  7878. if (val === null) {
  7879. return make_node(AST_Null, orig, { value: null });
  7880. }
  7881. if (val instanceof RegExp) {
  7882. return make_node(AST_RegExp, orig, { value: val });
  7883. }
  7884. throw new Error(string_template("Can't handle constant of type: {type}", {
  7885. type: typeof val
  7886. }));
  7887. }
  7888. }
  7889. // we shouldn't compress (1,func)(something) to
  7890. // func(something) because that changes the meaning of
  7891. // the func (becomes lexical instead of global).
  7892. function maintain_this_binding(parent, orig, val) {
  7893. if (parent instanceof AST_UnaryPrefix && parent.operator == "delete"
  7894. || parent instanceof AST_Call && parent.expression === orig
  7895. && (val instanceof AST_PropAccess || val instanceof AST_SymbolRef && val.name == "eval")) {
  7896. return make_sequence(orig, [ make_node(AST_Number, orig, { value: 0 }), val ]);
  7897. }
  7898. return val;
  7899. }
  7900. function merge_sequence(array, node) {
  7901. if (node instanceof AST_Sequence) {
  7902. array.push.apply(array, node.expressions);
  7903. } else {
  7904. array.push(node);
  7905. }
  7906. return array;
  7907. }
  7908. function as_statement_array(thing) {
  7909. if (thing === null) return [];
  7910. if (thing instanceof AST_BlockStatement) return thing.body;
  7911. if (thing instanceof AST_EmptyStatement) return [];
  7912. if (thing instanceof AST_Statement) return [ thing ];
  7913. throw new Error("Can't convert thing to statement array");
  7914. }
  7915. function is_empty(thing) {
  7916. if (thing === null) return true;
  7917. if (thing instanceof AST_EmptyStatement) return true;
  7918. if (thing instanceof AST_BlockStatement) return thing.body.length == 0;
  7919. return false;
  7920. }
  7921. function can_be_evicted_from_block(node) {
  7922. return !(
  7923. node instanceof AST_DefClass ||
  7924. node instanceof AST_Defun ||
  7925. node instanceof AST_Let ||
  7926. node instanceof AST_Const ||
  7927. node instanceof AST_Export ||
  7928. node instanceof AST_Import
  7929. );
  7930. }
  7931. function loop_body(x) {
  7932. if (x instanceof AST_IterationStatement) {
  7933. return x.body instanceof AST_BlockStatement ? x.body : x;
  7934. }
  7935. return x;
  7936. }
  7937. function is_iife_call(node) {
  7938. if (node.TYPE != "Call") return false;
  7939. return node.expression instanceof AST_Function || is_iife_call(node.expression);
  7940. }
  7941. function is_undeclared_ref(node) {
  7942. return node instanceof AST_SymbolRef && node.definition().undeclared;
  7943. }
  7944. var global_names = makePredicate("Array Boolean clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError");
  7945. AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) {
  7946. return !this.definition().undeclared
  7947. || compressor.option("unsafe") && global_names(this.name);
  7948. });
  7949. var identifier_atom = makePredicate("Infinity NaN undefined");
  7950. function is_identifier_atom(node) {
  7951. return node instanceof AST_Infinity
  7952. || node instanceof AST_NaN
  7953. || node instanceof AST_Undefined;
  7954. }
  7955. function tighten_body(statements, compressor) {
  7956. var in_loop, in_try;
  7957. var scope = compressor.find_parent(AST_Scope).get_defun_scope();
  7958. find_loop_scope_try();
  7959. var CHANGED, max_iter = 10;
  7960. do {
  7961. CHANGED = false;
  7962. eliminate_spurious_blocks(statements);
  7963. if (compressor.option("dead_code")) {
  7964. eliminate_dead_code(statements, compressor);
  7965. }
  7966. if (compressor.option("if_return")) {
  7967. handle_if_return(statements, compressor);
  7968. }
  7969. if (compressor.sequences_limit > 0) {
  7970. sequencesize(statements, compressor);
  7971. sequencesize_2(statements, compressor);
  7972. }
  7973. if (compressor.option("join_vars")) {
  7974. join_consecutive_vars(statements);
  7975. }
  7976. if (compressor.option("collapse_vars")) {
  7977. collapse(statements, compressor);
  7978. }
  7979. } while (CHANGED && max_iter-- > 0);
  7980. function find_loop_scope_try() {
  7981. var node = compressor.self(), level = 0;
  7982. do {
  7983. if (node instanceof AST_Catch || node instanceof AST_Finally) {
  7984. level++;
  7985. } else if (node instanceof AST_IterationStatement) {
  7986. in_loop = true;
  7987. } else if (node instanceof AST_Scope) {
  7988. scope = node;
  7989. break;
  7990. } else if (node instanceof AST_Try) {
  7991. in_try = true;
  7992. }
  7993. } while (node = compressor.parent(level++));
  7994. }
  7995. // Search from right to left for assignment-like expressions:
  7996. // - `var a = x;`
  7997. // - `a = x;`
  7998. // - `++a`
  7999. // For each candidate, scan from left to right for first usage, then try
  8000. // to fold assignment into the site for compression.
  8001. // Will not attempt to collapse assignments into or past code blocks
  8002. // which are not sequentially executed, e.g. loops and conditionals.
  8003. function collapse(statements, compressor) {
  8004. if (scope.pinned()) return statements;
  8005. var args;
  8006. var candidates = [];
  8007. var stat_index = statements.length;
  8008. var scanner = new TreeTransformer(function(node, descend) {
  8009. if (abort) return node;
  8010. // Skip nodes before `candidate` as quickly as possible
  8011. if (!hit) {
  8012. if (node !== hit_stack[hit_index]) return node;
  8013. hit_index++;
  8014. if (hit_index < hit_stack.length) return handle_custom_scan_order(node);
  8015. hit = true;
  8016. stop_after = find_stop(node, 0);
  8017. if (stop_after === node) abort = true;
  8018. return node;
  8019. }
  8020. // Stop immediately if these node types are encountered
  8021. var parent = scanner.parent();
  8022. if (node instanceof AST_Assign && node.operator != "=" && lhs.equivalent_to(node.left)
  8023. || node instanceof AST_Await
  8024. || node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression)
  8025. || node instanceof AST_Debugger
  8026. || node instanceof AST_Destructuring
  8027. || node instanceof AST_Expansion
  8028. && node.expression instanceof AST_Symbol
  8029. && node.expression.definition().references.length > 1
  8030. || node instanceof AST_IterationStatement && !(node instanceof AST_For)
  8031. || node instanceof AST_LoopControl
  8032. || node instanceof AST_Try
  8033. || node instanceof AST_With
  8034. || node instanceof AST_Yield
  8035. || parent instanceof AST_For && node !== parent.init
  8036. || !replace_all
  8037. && (node instanceof AST_SymbolRef && !node.is_declared(compressor))) {
  8038. abort = true;
  8039. return node;
  8040. }
  8041. // Stop only if candidate is found within conditional branches
  8042. if (!stop_if_hit && (!lhs_local || !replace_all)
  8043. && (parent instanceof AST_Binary && lazy_op(parent.operator) && parent.left !== node
  8044. || parent instanceof AST_Conditional && parent.condition !== node
  8045. || parent instanceof AST_If && parent.condition !== node)) {
  8046. stop_if_hit = parent;
  8047. }
  8048. // Replace variable with assignment when found
  8049. if (can_replace
  8050. && !(node instanceof AST_SymbolDeclaration)
  8051. && lhs.equivalent_to(node)) {
  8052. if (stop_if_hit) {
  8053. abort = true;
  8054. return node;
  8055. }
  8056. if (is_lhs(node, parent)) {
  8057. if (value_def) replaced++;
  8058. return node;
  8059. }
  8060. CHANGED = abort = true;
  8061. replaced++;
  8062. compressor.info("Collapsing {name} [{file}:{line},{col}]", {
  8063. name: node.print_to_string(),
  8064. file: node.start.file,
  8065. line: node.start.line,
  8066. col: node.start.col
  8067. });
  8068. if (candidate instanceof AST_UnaryPostfix) {
  8069. return make_node(AST_UnaryPrefix, candidate, candidate);
  8070. }
  8071. if (candidate instanceof AST_VarDef) {
  8072. if (value_def) {
  8073. abort = false;
  8074. return node;
  8075. }
  8076. var def = candidate.name.definition();
  8077. var value = candidate.value;
  8078. if (def.references.length - def.replaced == 1 && !compressor.exposed(def)) {
  8079. def.replaced++;
  8080. if (funarg && is_identifier_atom(value)) {
  8081. return value.transform(compressor);
  8082. } else {
  8083. return maintain_this_binding(parent, node, value);
  8084. }
  8085. }
  8086. return make_node(AST_Assign, candidate, {
  8087. operator: "=",
  8088. left: make_node(AST_SymbolRef, candidate.name, candidate.name),
  8089. right: value
  8090. });
  8091. }
  8092. candidate.write_only = false;
  8093. return candidate;
  8094. }
  8095. // These node types have child nodes that execute sequentially,
  8096. // but are otherwise not safe to scan into or beyond them.
  8097. var sym;
  8098. if (node instanceof AST_Call
  8099. || node instanceof AST_Exit
  8100. && (side_effects || lhs instanceof AST_PropAccess || may_modify(lhs))
  8101. || node instanceof AST_PropAccess
  8102. && (side_effects || node.expression.may_throw_on_access(compressor))
  8103. || node instanceof AST_SymbolRef
  8104. && (lvalues[node.name] || side_effects && may_modify(node))
  8105. || node instanceof AST_VarDef && node.value
  8106. && (node.name.name in lvalues || side_effects && may_modify(node.name))
  8107. || (sym = is_lhs(node.left, node))
  8108. && (sym instanceof AST_PropAccess || sym.name in lvalues)
  8109. || may_throw
  8110. && (in_try ? node.has_side_effects(compressor) : side_effects_external(node))) {
  8111. stop_after = node;
  8112. if (node instanceof AST_Scope) abort = true;
  8113. }
  8114. return handle_custom_scan_order(node);
  8115. }, function(node) {
  8116. if (abort) return;
  8117. if (stop_after === node) abort = true;
  8118. if (stop_if_hit === node) stop_if_hit = null;
  8119. });
  8120. var multi_replacer = new TreeTransformer(function(node) {
  8121. if (abort) return node;
  8122. // Skip nodes before `candidate` as quickly as possible
  8123. if (!hit) {
  8124. if (node !== hit_stack[hit_index]) return node;
  8125. hit_index++;
  8126. if (hit_index < hit_stack.length) return;
  8127. hit = true;
  8128. return node;
  8129. }
  8130. // Replace variable when found
  8131. if (node instanceof AST_SymbolRef
  8132. && node.name == def.name) {
  8133. if (!--replaced) abort = true;
  8134. if (is_lhs(node, multi_replacer.parent())) return node;
  8135. def.replaced++;
  8136. value_def.replaced--;
  8137. return candidate.value;
  8138. }
  8139. // Skip (non-executed) functions and (leading) default case in switch statements
  8140. if (node instanceof AST_Default || node instanceof AST_Scope) return node;
  8141. });
  8142. while (--stat_index >= 0) {
  8143. // Treat parameters as collapsible in IIFE, i.e.
  8144. // function(a, b){ ... }(x());
  8145. // would be translated into equivalent assignments:
  8146. // var a = x(), b = undefined;
  8147. if (stat_index == 0 && compressor.option("unused")) extract_args();
  8148. // Find collapsible assignments
  8149. var hit_stack = [];
  8150. extract_candidates(statements[stat_index]);
  8151. while (candidates.length > 0) {
  8152. hit_stack = candidates.pop();
  8153. var hit_index = 0;
  8154. var candidate = hit_stack[hit_stack.length - 1];
  8155. var value_def = null;
  8156. var stop_after = null;
  8157. var stop_if_hit = null;
  8158. var lhs = get_lhs(candidate);
  8159. if (!lhs || is_lhs_read_only(lhs) || lhs.has_side_effects(compressor)) continue;
  8160. // Locate symbols which may execute code outside of scanning range
  8161. var lvalues = get_lvalues(candidate);
  8162. var lhs_local = is_lhs_local(lhs);
  8163. if (lhs instanceof AST_SymbolRef) lvalues[lhs.name] = false;
  8164. var side_effects = value_has_side_effects(candidate);
  8165. var replace_all = replace_all_symbols();
  8166. var may_throw = candidate.may_throw(compressor);
  8167. var funarg = candidate.name instanceof AST_SymbolFunarg;
  8168. var hit = funarg;
  8169. var abort = false, replaced = 0, can_replace = !args || !hit;
  8170. if (!can_replace) {
  8171. for (var j = compressor.self().argnames.lastIndexOf(candidate.name) + 1; !abort && j < args.length; j++) {
  8172. args[j].transform(scanner);
  8173. }
  8174. can_replace = true;
  8175. }
  8176. for (var i = stat_index; !abort && i < statements.length; i++) {
  8177. statements[i].transform(scanner);
  8178. }
  8179. if (value_def) {
  8180. var def = candidate.name.definition();
  8181. if (abort && def.references.length - def.replaced > replaced) replaced = false;
  8182. else {
  8183. abort = false;
  8184. hit_index = 0;
  8185. hit = funarg;
  8186. for (var i = stat_index; !abort && i < statements.length; i++) {
  8187. statements[i].transform(multi_replacer);
  8188. }
  8189. value_def.single_use = false;
  8190. }
  8191. }
  8192. if (replaced && !remove_candidate(candidate)) statements.splice(stat_index, 1);
  8193. }
  8194. }
  8195. function handle_custom_scan_order(node) {
  8196. // Skip (non-executed) functions
  8197. if (node instanceof AST_Scope) return node;
  8198. // Scan case expressions first in a switch statement
  8199. if (node instanceof AST_Switch) {
  8200. node.expression = node.expression.transform(scanner);
  8201. for (var i = 0, len = node.body.length; !abort && i < len; i++) {
  8202. var branch = node.body[i];
  8203. if (branch instanceof AST_Case) {
  8204. if (!hit) {
  8205. if (branch !== hit_stack[hit_index]) continue;
  8206. hit_index++;
  8207. }
  8208. branch.expression = branch.expression.transform(scanner);
  8209. if (!replace_all) break;
  8210. }
  8211. }
  8212. abort = true;
  8213. return node;
  8214. }
  8215. }
  8216. function has_overlapping_symbol(fn, arg, fn_strict) {
  8217. var found = false, scan_this = !(fn instanceof AST_Arrow);
  8218. arg.walk(new TreeWalker(function(node, descend) {
  8219. if (found) return true;
  8220. if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) {
  8221. var s = node.definition().scope;
  8222. if (s !== scope) while (s = s.parent_scope) {
  8223. if (s === scope) return true;
  8224. }
  8225. return found = true;
  8226. }
  8227. if ((fn_strict || scan_this) && node instanceof AST_This) {
  8228. return found = true;
  8229. }
  8230. if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) {
  8231. var prev = scan_this;
  8232. scan_this = false;
  8233. descend();
  8234. scan_this = prev;
  8235. return true;
  8236. }
  8237. }));
  8238. return found;
  8239. }
  8240. function extract_args() {
  8241. var iife, fn = compressor.self();
  8242. if (is_func_expr(fn)
  8243. && !fn.name
  8244. && !fn.uses_arguments
  8245. && !fn.pinned()
  8246. && (iife = compressor.parent()) instanceof AST_Call
  8247. && iife.expression === fn
  8248. && all(iife.args, function(arg) {
  8249. return !(arg instanceof AST_Expansion);
  8250. })) {
  8251. var fn_strict = compressor.has_directive("use strict");
  8252. if (fn_strict && !member(fn_strict, fn.body)) fn_strict = false;
  8253. var len = fn.argnames.length;
  8254. args = iife.args.slice(len);
  8255. var names = Object.create(null);
  8256. for (var i = len; --i >= 0;) {
  8257. var sym = fn.argnames[i];
  8258. var arg = iife.args[i];
  8259. args.unshift(make_node(AST_VarDef, sym, {
  8260. name: sym,
  8261. value: arg
  8262. }));
  8263. if (sym.name in names) continue;
  8264. names[sym.name] = true;
  8265. if (sym instanceof AST_Expansion) {
  8266. var elements = iife.args.slice(i);
  8267. if (all(elements, function(arg) {
  8268. return !has_overlapping_symbol(fn, arg, fn_strict);
  8269. })) {
  8270. candidates.unshift([ make_node(AST_VarDef, sym, {
  8271. name: sym.expression,
  8272. value: make_node(AST_Array, iife, {
  8273. elements: elements
  8274. })
  8275. }) ]);
  8276. }
  8277. } else {
  8278. if (!arg) {
  8279. arg = make_node(AST_Undefined, sym).transform(compressor);
  8280. } else if (arg instanceof AST_Lambda && arg.pinned()
  8281. || has_overlapping_symbol(fn, arg, fn_strict)) {
  8282. arg = null;
  8283. }
  8284. if (arg) candidates.unshift([ make_node(AST_VarDef, sym, {
  8285. name: sym,
  8286. value: arg
  8287. }) ]);
  8288. }
  8289. }
  8290. }
  8291. }
  8292. function extract_candidates(expr) {
  8293. hit_stack.push(expr);
  8294. if (expr instanceof AST_Assign) {
  8295. if (!expr.left.has_side_effects(compressor)) {
  8296. candidates.push(hit_stack.slice());
  8297. }
  8298. extract_candidates(expr.right);
  8299. } else if (expr instanceof AST_Binary) {
  8300. extract_candidates(expr.left);
  8301. extract_candidates(expr.right);
  8302. } else if (expr instanceof AST_Call) {
  8303. extract_candidates(expr.expression);
  8304. expr.args.forEach(extract_candidates);
  8305. } else if (expr instanceof AST_Case) {
  8306. extract_candidates(expr.expression);
  8307. } else if (expr instanceof AST_Conditional) {
  8308. extract_candidates(expr.condition);
  8309. extract_candidates(expr.consequent);
  8310. extract_candidates(expr.alternative);
  8311. } else if (expr instanceof AST_Definitions
  8312. && (compressor.option("unused") || !(expr instanceof AST_Const))) {
  8313. var len = expr.definitions.length;
  8314. // limit number of trailing variable definitions for consideration
  8315. var i = len - 200;
  8316. if (i < 0) i = 0;
  8317. for (; i < len; i++) {
  8318. extract_candidates(expr.definitions[i]);
  8319. }
  8320. } else if (expr instanceof AST_DWLoop) {
  8321. extract_candidates(expr.condition);
  8322. if (!(expr.body instanceof AST_Block)) {
  8323. extract_candidates(expr.body);
  8324. }
  8325. } else if (expr instanceof AST_Exit) {
  8326. if (expr.value) extract_candidates(expr.value);
  8327. } else if (expr instanceof AST_For) {
  8328. if (expr.init) extract_candidates(expr.init);
  8329. if (expr.condition) extract_candidates(expr.condition);
  8330. if (expr.step) extract_candidates(expr.step);
  8331. if (!(expr.body instanceof AST_Block)) {
  8332. extract_candidates(expr.body);
  8333. }
  8334. } else if (expr instanceof AST_ForIn) {
  8335. extract_candidates(expr.object);
  8336. if (!(expr.body instanceof AST_Block)) {
  8337. extract_candidates(expr.body);
  8338. }
  8339. } else if (expr instanceof AST_If) {
  8340. extract_candidates(expr.condition);
  8341. if (!(expr.body instanceof AST_Block)) {
  8342. extract_candidates(expr.body);
  8343. }
  8344. if (expr.alternative && !(expr.alternative instanceof AST_Block)) {
  8345. extract_candidates(expr.alternative);
  8346. }
  8347. } else if (expr instanceof AST_Sequence) {
  8348. expr.expressions.forEach(extract_candidates);
  8349. } else if (expr instanceof AST_SimpleStatement) {
  8350. extract_candidates(expr.body);
  8351. } else if (expr instanceof AST_Switch) {
  8352. extract_candidates(expr.expression);
  8353. expr.body.forEach(extract_candidates);
  8354. } else if (expr instanceof AST_Unary) {
  8355. if (expr.operator == "++" || expr.operator == "--") {
  8356. candidates.push(hit_stack.slice());
  8357. }
  8358. } else if (expr instanceof AST_VarDef) {
  8359. if (expr.value) {
  8360. candidates.push(hit_stack.slice());
  8361. extract_candidates(expr.value);
  8362. }
  8363. }
  8364. hit_stack.pop();
  8365. }
  8366. function find_stop(node, level, write_only) {
  8367. var parent = scanner.parent(level);
  8368. if (parent instanceof AST_Assign) {
  8369. if (write_only
  8370. && !(parent.left instanceof AST_PropAccess
  8371. || parent.left.name in lvalues)) {
  8372. return find_stop(parent, level + 1, write_only);
  8373. }
  8374. return node;
  8375. }
  8376. if (parent instanceof AST_Binary) {
  8377. if (write_only && (!lazy_op(parent.operator) || parent.left === node)) {
  8378. return find_stop(parent, level + 1, write_only);
  8379. }
  8380. return node;
  8381. }
  8382. if (parent instanceof AST_Call) return node;
  8383. if (parent instanceof AST_Case) return node;
  8384. if (parent instanceof AST_Conditional) {
  8385. if (write_only && parent.condition === node) {
  8386. return find_stop(parent, level + 1, write_only);
  8387. }
  8388. return node;
  8389. }
  8390. if (parent instanceof AST_Definitions) {
  8391. return find_stop(parent, level + 1, true);
  8392. }
  8393. if (parent instanceof AST_Exit) {
  8394. return write_only ? find_stop(parent, level + 1, write_only) : node;
  8395. }
  8396. if (parent instanceof AST_If) {
  8397. if (write_only && parent.condition === node) {
  8398. return find_stop(parent, level + 1, write_only);
  8399. }
  8400. return node;
  8401. }
  8402. if (parent instanceof AST_IterationStatement) return node;
  8403. if (parent instanceof AST_Sequence) {
  8404. return find_stop(parent, level + 1, parent.tail_node() !== node);
  8405. }
  8406. if (parent instanceof AST_SimpleStatement) {
  8407. return find_stop(parent, level + 1, true);
  8408. }
  8409. if (parent instanceof AST_Switch) return node;
  8410. if (parent instanceof AST_VarDef) return node;
  8411. return null;
  8412. }
  8413. function mangleable_var(var_def) {
  8414. var value = var_def.value;
  8415. if (!(value instanceof AST_SymbolRef)) return;
  8416. if (value.name == "arguments") return;
  8417. var def = value.definition();
  8418. if (def.undeclared) return;
  8419. return value_def = def;
  8420. }
  8421. function get_lhs(expr) {
  8422. if (expr instanceof AST_VarDef && expr.name instanceof AST_SymbolDeclaration) {
  8423. var def = expr.name.definition();
  8424. if (!member(expr.name, def.orig)) return;
  8425. var referenced = def.references.length - def.replaced;
  8426. if (!referenced) return;
  8427. var declared = def.orig.length - def.eliminated;
  8428. if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg)
  8429. || (referenced > 1 ? mangleable_var(expr) : !compressor.exposed(def))) {
  8430. return make_node(AST_SymbolRef, expr.name, expr.name);
  8431. }
  8432. } else {
  8433. var lhs = expr[expr instanceof AST_Assign ? "left" : "expression"];
  8434. return !is_ref_of(lhs, AST_SymbolConst) && lhs;
  8435. }
  8436. }
  8437. function get_rvalue(expr) {
  8438. return expr[expr instanceof AST_Assign ? "right" : "value"];
  8439. }
  8440. function get_lvalues(expr) {
  8441. var lvalues = Object.create(null);
  8442. if (expr instanceof AST_Unary) return lvalues;
  8443. var tw = new TreeWalker(function(node, descend) {
  8444. var sym = node;
  8445. while (sym instanceof AST_PropAccess) sym = sym.expression;
  8446. if (sym instanceof AST_SymbolRef || sym instanceof AST_This) {
  8447. lvalues[sym.name] = lvalues[sym.name] || is_modified(compressor, tw, node, node, 0);
  8448. }
  8449. });
  8450. get_rvalue(expr).walk(tw);
  8451. return lvalues;
  8452. }
  8453. function remove_candidate(expr) {
  8454. if (expr.name instanceof AST_SymbolFunarg) {
  8455. var iife = compressor.parent(), argnames = compressor.self().argnames;
  8456. var index = argnames.indexOf(expr.name);
  8457. if (index < 0) {
  8458. iife.args.length = Math.min(iife.args.length, argnames.length - 1);
  8459. } else {
  8460. var args = iife.args;
  8461. if (args[index]) args[index] = make_node(AST_Number, args[index], {
  8462. value: 0
  8463. });
  8464. }
  8465. return true;
  8466. }
  8467. var found = false;
  8468. return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {
  8469. if (found) return node;
  8470. if (node === expr || node.body === expr) {
  8471. found = true;
  8472. if (node instanceof AST_VarDef) {
  8473. node.value = null;
  8474. return node;
  8475. }
  8476. return in_list ? MAP.skip : null;
  8477. }
  8478. }, function(node) {
  8479. if (node instanceof AST_Sequence) switch (node.expressions.length) {
  8480. case 0: return null;
  8481. case 1: return node.expressions[0];
  8482. }
  8483. }));
  8484. }
  8485. function is_lhs_local(lhs) {
  8486. while (lhs instanceof AST_PropAccess) lhs = lhs.expression;
  8487. return lhs instanceof AST_SymbolRef
  8488. && lhs.definition().scope === scope
  8489. && !(in_loop
  8490. && (lhs.name in lvalues
  8491. || candidate instanceof AST_Unary
  8492. || candidate instanceof AST_Assign && candidate.operator != "="));
  8493. }
  8494. function value_has_side_effects(expr) {
  8495. if (expr instanceof AST_Unary) return false;
  8496. return get_rvalue(expr).has_side_effects(compressor);
  8497. }
  8498. function replace_all_symbols() {
  8499. if (side_effects) return false;
  8500. if (value_def) return true;
  8501. if (lhs instanceof AST_SymbolRef) {
  8502. var def = lhs.definition();
  8503. if (def.references.length - def.replaced == (candidate instanceof AST_VarDef ? 1 : 2)) {
  8504. return true;
  8505. }
  8506. }
  8507. return false;
  8508. }
  8509. function may_modify(sym) {
  8510. if (!sym.definition) return true; // AST_Destructuring
  8511. var def = sym.definition();
  8512. if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
  8513. if (def.scope.get_defun_scope() !== scope) return true;
  8514. return !all(def.references, function(ref) {
  8515. var s = ref.scope.get_defun_scope();
  8516. // "block" scope within AST_Catch
  8517. if (s.TYPE == "Scope") s = s.parent_scope;
  8518. return s === scope;
  8519. });
  8520. }
  8521. function side_effects_external(node, lhs) {
  8522. if (node instanceof AST_Assign) return side_effects_external(node.left, true);
  8523. if (node instanceof AST_Unary) return side_effects_external(node.expression, true);
  8524. if (node instanceof AST_VarDef) return node.value && side_effects_external(node.value);
  8525. if (lhs) {
  8526. if (node instanceof AST_Dot) return side_effects_external(node.expression, true);
  8527. if (node instanceof AST_Sub) return side_effects_external(node.expression, true);
  8528. if (node instanceof AST_SymbolRef) return node.definition().scope !== scope;
  8529. }
  8530. return false;
  8531. }
  8532. }
  8533. function eliminate_spurious_blocks(statements) {
  8534. var seen_dirs = [];
  8535. for (var i = 0; i < statements.length;) {
  8536. var stat = statements[i];
  8537. if (stat instanceof AST_BlockStatement && all(stat.body, can_be_evicted_from_block)) {
  8538. CHANGED = true;
  8539. eliminate_spurious_blocks(stat.body);
  8540. [].splice.apply(statements, [i, 1].concat(stat.body));
  8541. i += stat.body.length;
  8542. } else if (stat instanceof AST_EmptyStatement) {
  8543. CHANGED = true;
  8544. statements.splice(i, 1);
  8545. } else if (stat instanceof AST_Directive) {
  8546. if (seen_dirs.indexOf(stat.value) < 0) {
  8547. i++;
  8548. seen_dirs.push(stat.value);
  8549. } else {
  8550. CHANGED = true;
  8551. statements.splice(i, 1);
  8552. }
  8553. } else i++;
  8554. }
  8555. }
  8556. function handle_if_return(statements, compressor) {
  8557. var self = compressor.self();
  8558. var multiple_if_returns = has_multiple_if_returns(statements);
  8559. var in_lambda = self instanceof AST_Lambda;
  8560. for (var i = statements.length; --i >= 0;) {
  8561. var stat = statements[i];
  8562. var j = next_index(i);
  8563. var next = statements[j];
  8564. if (in_lambda && !next && stat instanceof AST_Return) {
  8565. if (!stat.value) {
  8566. CHANGED = true;
  8567. statements.splice(i, 1);
  8568. continue;
  8569. }
  8570. if (stat.value instanceof AST_UnaryPrefix && stat.value.operator == "void") {
  8571. CHANGED = true;
  8572. statements[i] = make_node(AST_SimpleStatement, stat, {
  8573. body: stat.value.expression
  8574. });
  8575. continue;
  8576. }
  8577. }
  8578. if (stat instanceof AST_If) {
  8579. var ab = aborts(stat.body);
  8580. if (can_merge_flow(ab)) {
  8581. if (ab.label) {
  8582. remove(ab.label.thedef.references, ab);
  8583. }
  8584. CHANGED = true;
  8585. stat = stat.clone();
  8586. stat.condition = stat.condition.negate(compressor);
  8587. var body = as_statement_array_with_return(stat.body, ab);
  8588. stat.body = make_node(AST_BlockStatement, stat, {
  8589. body: as_statement_array(stat.alternative).concat(extract_functions())
  8590. });
  8591. stat.alternative = make_node(AST_BlockStatement, stat, {
  8592. body: body
  8593. });
  8594. statements[i] = stat.transform(compressor);
  8595. continue;
  8596. }
  8597. var ab = aborts(stat.alternative);
  8598. if (can_merge_flow(ab)) {
  8599. if (ab.label) {
  8600. remove(ab.label.thedef.references, ab);
  8601. }
  8602. CHANGED = true;
  8603. stat = stat.clone();
  8604. stat.body = make_node(AST_BlockStatement, stat.body, {
  8605. body: as_statement_array(stat.body).concat(extract_functions())
  8606. });
  8607. var body = as_statement_array_with_return(stat.alternative, ab);
  8608. stat.alternative = make_node(AST_BlockStatement, stat.alternative, {
  8609. body: body
  8610. });
  8611. statements[i] = stat.transform(compressor);
  8612. continue;
  8613. }
  8614. }
  8615. if (stat instanceof AST_If && stat.body instanceof AST_Return) {
  8616. var value = stat.body.value;
  8617. //---
  8618. // pretty silly case, but:
  8619. // if (foo()) return; return; ==> foo(); return;
  8620. if (!value && !stat.alternative
  8621. && (in_lambda && !next || next instanceof AST_Return && !next.value)) {
  8622. CHANGED = true;
  8623. statements[i] = make_node(AST_SimpleStatement, stat.condition, {
  8624. body: stat.condition
  8625. });
  8626. continue;
  8627. }
  8628. //---
  8629. // if (foo()) return x; return y; ==> return foo() ? x : y;
  8630. if (value && !stat.alternative && next instanceof AST_Return && next.value) {
  8631. CHANGED = true;
  8632. stat = stat.clone();
  8633. stat.alternative = next;
  8634. statements.splice(i, 1, stat.transform(compressor));
  8635. statements.splice(j, 1);
  8636. continue;
  8637. }
  8638. //---
  8639. // if (foo()) return x; [ return ; ] ==> return foo() ? x : undefined;
  8640. if (value && !stat.alternative
  8641. && (!next && in_lambda && multiple_if_returns
  8642. || next instanceof AST_Return)) {
  8643. CHANGED = true;
  8644. stat = stat.clone();
  8645. stat.alternative = next || make_node(AST_Return, stat, {
  8646. value: null
  8647. });
  8648. statements.splice(i, 1, stat.transform(compressor));
  8649. if (next) statements.splice(j, 1);
  8650. continue;
  8651. }
  8652. //---
  8653. // if (a) return b; if (c) return d; e; ==> return a ? b : c ? d : void e;
  8654. //
  8655. // if sequences is not enabled, this can lead to an endless loop (issue #866).
  8656. // however, with sequences on this helps producing slightly better output for
  8657. // the example code.
  8658. var prev = statements[prev_index(i)];
  8659. if (compressor.option("sequences") && in_lambda && !stat.alternative
  8660. && prev instanceof AST_If && prev.body instanceof AST_Return
  8661. && next_index(j) == statements.length && next instanceof AST_SimpleStatement) {
  8662. CHANGED = true;
  8663. stat = stat.clone();
  8664. stat.alternative = make_node(AST_BlockStatement, next, {
  8665. body: [
  8666. next,
  8667. make_node(AST_Return, next, {
  8668. value: null
  8669. })
  8670. ]
  8671. });
  8672. statements.splice(i, 1, stat.transform(compressor));
  8673. statements.splice(j, 1);
  8674. continue;
  8675. }
  8676. }
  8677. }
  8678. function has_multiple_if_returns(statements) {
  8679. var n = 0;
  8680. for (var i = statements.length; --i >= 0;) {
  8681. var stat = statements[i];
  8682. if (stat instanceof AST_If && stat.body instanceof AST_Return) {
  8683. if (++n > 1) return true;
  8684. }
  8685. }
  8686. return false;
  8687. }
  8688. function is_return_void(value) {
  8689. return !value || value instanceof AST_UnaryPrefix && value.operator == "void";
  8690. }
  8691. function can_merge_flow(ab) {
  8692. if (!ab) return false;
  8693. for (var j = i + 1, len = statements.length; j < len; j++) {
  8694. var stat = statements[j];
  8695. if (stat instanceof AST_Const || stat instanceof AST_Let) return false;
  8696. }
  8697. var lct = ab instanceof AST_LoopControl ? compressor.loopcontrol_target(ab) : null;
  8698. return ab instanceof AST_Return && in_lambda && is_return_void(ab.value)
  8699. || ab instanceof AST_Continue && self === loop_body(lct)
  8700. || ab instanceof AST_Break && lct instanceof AST_BlockStatement && self === lct;
  8701. }
  8702. function extract_functions() {
  8703. var tail = statements.slice(i + 1);
  8704. statements.length = i + 1;
  8705. return tail.filter(function(stat) {
  8706. if (stat instanceof AST_Defun) {
  8707. statements.push(stat);
  8708. return false;
  8709. }
  8710. return true;
  8711. });
  8712. }
  8713. function as_statement_array_with_return(node, ab) {
  8714. var body = as_statement_array(node).slice(0, -1);
  8715. if (ab.value) {
  8716. body.push(make_node(AST_SimpleStatement, ab.value, {
  8717. body: ab.value.expression
  8718. }));
  8719. }
  8720. return body;
  8721. }
  8722. function next_index(i) {
  8723. for (var j = i + 1, len = statements.length; j < len; j++) {
  8724. var stat = statements[j];
  8725. if (!(stat instanceof AST_Var && declarations_only(stat))) {
  8726. break;
  8727. }
  8728. }
  8729. return j;
  8730. }
  8731. function prev_index(i) {
  8732. for (var j = i; --j >= 0;) {
  8733. var stat = statements[j];
  8734. if (!(stat instanceof AST_Var && declarations_only(stat))) {
  8735. break;
  8736. }
  8737. }
  8738. return j;
  8739. }
  8740. }
  8741. function eliminate_dead_code(statements, compressor) {
  8742. var has_quit;
  8743. var self = compressor.self();
  8744. for (var i = 0, n = 0, len = statements.length; i < len; i++) {
  8745. var stat = statements[i];
  8746. if (stat instanceof AST_LoopControl) {
  8747. var lct = compressor.loopcontrol_target(stat);
  8748. if (stat instanceof AST_Break
  8749. && !(lct instanceof AST_IterationStatement)
  8750. && loop_body(lct) === self
  8751. || stat instanceof AST_Continue
  8752. && loop_body(lct) === self) {
  8753. if (stat.label) {
  8754. remove(stat.label.thedef.references, stat);
  8755. }
  8756. } else {
  8757. statements[n++] = stat;
  8758. }
  8759. } else {
  8760. statements[n++] = stat;
  8761. }
  8762. if (aborts(stat)) {
  8763. has_quit = statements.slice(i + 1);
  8764. break;
  8765. }
  8766. }
  8767. statements.length = n;
  8768. CHANGED = n != len;
  8769. if (has_quit) has_quit.forEach(function(stat) {
  8770. extract_declarations_from_unreachable_code(compressor, stat, statements);
  8771. });
  8772. }
  8773. function declarations_only(node) {
  8774. return all(node.definitions, function(var_def) {
  8775. return !var_def.value;
  8776. });
  8777. }
  8778. function sequencesize(statements, compressor) {
  8779. if (statements.length < 2) return;
  8780. var seq = [], n = 0;
  8781. function push_seq() {
  8782. if (!seq.length) return;
  8783. var body = make_sequence(seq[0], seq);
  8784. statements[n++] = make_node(AST_SimpleStatement, body, { body: body });
  8785. seq = [];
  8786. }
  8787. for (var i = 0, len = statements.length; i < len; i++) {
  8788. var stat = statements[i];
  8789. if (stat instanceof AST_SimpleStatement) {
  8790. if (seq.length >= compressor.sequences_limit) push_seq();
  8791. var body = stat.body;
  8792. if (seq.length > 0) body = body.drop_side_effect_free(compressor);
  8793. if (body) merge_sequence(seq, body);
  8794. } else if (stat instanceof AST_Definitions && declarations_only(stat)
  8795. || stat instanceof AST_Defun) {
  8796. statements[n++] = stat;
  8797. } else {
  8798. push_seq();
  8799. statements[n++] = stat;
  8800. }
  8801. }
  8802. push_seq();
  8803. statements.length = n;
  8804. if (n != len) CHANGED = true;
  8805. }
  8806. function to_simple_statement(block, decls) {
  8807. if (!(block instanceof AST_BlockStatement)) return block;
  8808. var stat = null;
  8809. for (var i = 0, len = block.body.length; i < len; i++) {
  8810. var line = block.body[i];
  8811. if (line instanceof AST_Var && declarations_only(line)) {
  8812. decls.push(line);
  8813. } else if (stat) {
  8814. return false;
  8815. } else {
  8816. stat = line;
  8817. }
  8818. }
  8819. return stat;
  8820. }
  8821. function sequencesize_2(statements, compressor) {
  8822. function cons_seq(right) {
  8823. n--;
  8824. CHANGED = true;
  8825. var left = prev.body;
  8826. return make_sequence(left, [ left, right ]).transform(compressor);
  8827. }
  8828. var n = 0, prev;
  8829. for (var i = 0; i < statements.length; i++) {
  8830. var stat = statements[i];
  8831. if (prev) {
  8832. if (stat instanceof AST_Exit) {
  8833. stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat).transform(compressor));
  8834. } else if (stat instanceof AST_For) {
  8835. if (!(stat.init instanceof AST_Definitions)) {
  8836. var abort = false;
  8837. prev.body.walk(new TreeWalker(function(node) {
  8838. if (abort || node instanceof AST_Scope) return true;
  8839. if (node instanceof AST_Binary && node.operator == "in") {
  8840. abort = true;
  8841. return true;
  8842. }
  8843. }));
  8844. if (!abort) {
  8845. if (stat.init) stat.init = cons_seq(stat.init);
  8846. else {
  8847. stat.init = prev.body;
  8848. n--;
  8849. CHANGED = true;
  8850. }
  8851. }
  8852. }
  8853. } else if (stat instanceof AST_ForIn) {
  8854. if (!(stat.init instanceof AST_Const) && !(stat.init instanceof AST_Let)) {
  8855. stat.object = cons_seq(stat.object);
  8856. }
  8857. } else if (stat instanceof AST_If) {
  8858. stat.condition = cons_seq(stat.condition);
  8859. } else if (stat instanceof AST_Switch) {
  8860. stat.expression = cons_seq(stat.expression);
  8861. } else if (stat instanceof AST_With) {
  8862. stat.expression = cons_seq(stat.expression);
  8863. }
  8864. }
  8865. if (compressor.option("conditionals") && stat instanceof AST_If) {
  8866. var decls = [];
  8867. var body = to_simple_statement(stat.body, decls);
  8868. var alt = to_simple_statement(stat.alternative, decls);
  8869. if (body !== false && alt !== false && decls.length > 0) {
  8870. var len = decls.length;
  8871. decls.push(make_node(AST_If, stat, {
  8872. condition: stat.condition,
  8873. body: body || make_node(AST_EmptyStatement, stat.body),
  8874. alternative: alt
  8875. }));
  8876. decls.unshift(n, 1);
  8877. [].splice.apply(statements, decls);
  8878. i += len;
  8879. n += len + 1;
  8880. prev = null;
  8881. CHANGED = true;
  8882. continue;
  8883. }
  8884. }
  8885. statements[n++] = stat;
  8886. prev = stat instanceof AST_SimpleStatement ? stat : null;
  8887. }
  8888. statements.length = n;
  8889. }
  8890. function join_object_assignments(defn, body) {
  8891. if (!(defn instanceof AST_Definitions)) return;
  8892. var def = defn.definitions[defn.definitions.length - 1];
  8893. if (!(def.value instanceof AST_Object)) return;
  8894. var exprs;
  8895. if (body instanceof AST_Assign) {
  8896. exprs = [ body ];
  8897. } else if (body instanceof AST_Sequence) {
  8898. exprs = body.expressions.slice();
  8899. }
  8900. if (!exprs) return;
  8901. var trimmed = false;
  8902. do {
  8903. var node = exprs[0];
  8904. if (!(node instanceof AST_Assign)) break;
  8905. if (node.operator != "=") break;
  8906. if (!(node.left instanceof AST_PropAccess)) break;
  8907. var sym = node.left.expression;
  8908. if (!(sym instanceof AST_SymbolRef)) break;
  8909. if (def.name.name != sym.name) break;
  8910. if (!node.right.is_constant_expression(scope)) break;
  8911. var prop = node.left.property;
  8912. if (prop instanceof AST_Node) {
  8913. prop = prop.evaluate(compressor);
  8914. }
  8915. if (prop instanceof AST_Node) break;
  8916. prop = "" + prop;
  8917. var diff = compressor.option("ecma") < 6
  8918. && compressor.has_directive("use strict") ? function(node) {
  8919. return node.key != prop && (node.key && node.key.name != prop);
  8920. } : function(node) {
  8921. return node.key && node.key.name != prop;
  8922. };
  8923. if (!all(def.value.properties, diff)) break;
  8924. var p = def.value.properties.filter(function (p) { return p.key === prop; })[0];
  8925. if (!p) {
  8926. def.value.properties.push(make_node(AST_ObjectKeyVal, node, {
  8927. key: prop,
  8928. value: node.right
  8929. }));
  8930. } else {
  8931. p.value = new AST_Sequence({
  8932. start: p.start,
  8933. expressions: [p.value.clone(), node.right.clone()],
  8934. end: p.end
  8935. });
  8936. }
  8937. exprs.shift();
  8938. trimmed = true;
  8939. } while (exprs.length);
  8940. return trimmed && exprs;
  8941. }
  8942. function join_consecutive_vars(statements) {
  8943. var defs;
  8944. for (var i = 0, j = -1, len = statements.length; i < len; i++) {
  8945. var stat = statements[i];
  8946. var prev = statements[j];
  8947. if (stat instanceof AST_Definitions) {
  8948. if (prev && prev.TYPE == stat.TYPE) {
  8949. prev.definitions = prev.definitions.concat(stat.definitions);
  8950. CHANGED = true;
  8951. } else if (defs && defs.TYPE == stat.TYPE && declarations_only(stat)) {
  8952. defs.definitions = defs.definitions.concat(stat.definitions);
  8953. CHANGED = true;
  8954. } else {
  8955. statements[++j] = stat;
  8956. defs = stat;
  8957. }
  8958. } else if (stat instanceof AST_Exit) {
  8959. stat.value = extract_object_assignments(stat.value);
  8960. } else if (stat instanceof AST_For) {
  8961. var exprs = join_object_assignments(prev, stat.init);
  8962. if (exprs) {
  8963. CHANGED = true;
  8964. stat.init = exprs.length ? make_sequence(stat.init, exprs) : null;
  8965. statements[++j] = stat;
  8966. } else if (prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) {
  8967. if (stat.init) {
  8968. prev.definitions = prev.definitions.concat(stat.init.definitions);
  8969. }
  8970. stat.init = prev;
  8971. statements[j] = stat;
  8972. CHANGED = true;
  8973. } else if (defs && stat.init && defs.TYPE == stat.init.TYPE && declarations_only(stat.init)) {
  8974. defs.definitions = defs.definitions.concat(stat.init.definitions);
  8975. stat.init = null;
  8976. statements[++j] = stat;
  8977. CHANGED = true;
  8978. } else {
  8979. statements[++j] = stat;
  8980. }
  8981. } else if (stat instanceof AST_ForIn) {
  8982. stat.object = extract_object_assignments(stat.object);
  8983. } else if (stat instanceof AST_If) {
  8984. stat.condition = extract_object_assignments(stat.condition);
  8985. } else if (stat instanceof AST_SimpleStatement) {
  8986. var exprs = join_object_assignments(prev, stat.body);
  8987. if (exprs) {
  8988. CHANGED = true;
  8989. if (!exprs.length) continue;
  8990. stat.body = make_sequence(stat.body, exprs);
  8991. }
  8992. statements[++j] = stat;
  8993. } else if (stat instanceof AST_Switch) {
  8994. stat.expression = extract_object_assignments(stat.expression);
  8995. } else if (stat instanceof AST_With) {
  8996. stat.expression = extract_object_assignments(stat.expression);
  8997. } else {
  8998. statements[++j] = stat;
  8999. }
  9000. }
  9001. statements.length = j + 1;
  9002. function extract_object_assignments(value) {
  9003. statements[++j] = stat;
  9004. var exprs = join_object_assignments(prev, value);
  9005. if (exprs) {
  9006. CHANGED = true;
  9007. if (exprs.length) {
  9008. return make_sequence(value, exprs);
  9009. } else if (value instanceof AST_Sequence) {
  9010. return value.tail_node().left;
  9011. } else {
  9012. return value.left;
  9013. }
  9014. }
  9015. return value;
  9016. }
  9017. }
  9018. }
  9019. function extract_declarations_from_unreachable_code(compressor, stat, target) {
  9020. if (!(stat instanceof AST_Defun)) {
  9021. compressor.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start);
  9022. }
  9023. stat.walk(new TreeWalker(function(node) {
  9024. if (node instanceof AST_Var) {
  9025. compressor.warn("Declarations in unreachable code! [{file}:{line},{col}]", node.start);
  9026. node.remove_initializers();
  9027. target.push(node);
  9028. return true;
  9029. }
  9030. if (node instanceof AST_Defun && (node === stat || !compressor.has_directive("use strict"))) {
  9031. target.push(node === stat ? node : make_node(AST_Var, node, {
  9032. definitions: [
  9033. make_node(AST_VarDef, node, {
  9034. name: make_node(AST_SymbolVar, node.name, node.name),
  9035. value: null
  9036. })
  9037. ]
  9038. }));
  9039. return true;
  9040. }
  9041. if (node instanceof AST_Scope) {
  9042. return true;
  9043. }
  9044. }));
  9045. }
  9046. function get_value(key) {
  9047. if (key instanceof AST_Constant) {
  9048. return key.getValue();
  9049. }
  9050. if (key instanceof AST_UnaryPrefix
  9051. && key.operator == "void"
  9052. && key.expression instanceof AST_Constant) {
  9053. return;
  9054. }
  9055. return key;
  9056. }
  9057. function is_undefined(node, compressor) {
  9058. return node.is_undefined
  9059. || node instanceof AST_Undefined
  9060. || node instanceof AST_UnaryPrefix
  9061. && node.operator == "void"
  9062. && !node.expression.has_side_effects(compressor);
  9063. }
  9064. // may_throw_on_access()
  9065. // returns true if this node may be null, undefined or contain `AST_Accessor`
  9066. (function(def_dot_throw) {
  9067. AST_Node.DEFMETHOD("may_throw_on_access", function(compressor) {
  9068. return !compressor.option("pure_getters")
  9069. || this._dot_throw(compressor);
  9070. });
  9071. function is_strict(compressor) {
  9072. return /strict/.test(compressor.option("pure_getters"));
  9073. }
  9074. def_dot_throw(AST_Node, is_strict);
  9075. def_dot_throw(AST_Null, return_true);
  9076. def_dot_throw(AST_Undefined, return_true);
  9077. def_dot_throw(AST_Constant, return_false);
  9078. def_dot_throw(AST_Array, return_false);
  9079. def_dot_throw(AST_Object, function(compressor) {
  9080. if (!is_strict(compressor)) return false;
  9081. for (var i = this.properties.length; --i >=0;)
  9082. if (this.properties[i]._dot_throw(compressor)) return true;
  9083. return false;
  9084. });
  9085. def_dot_throw(AST_ObjectProperty, return_false);
  9086. def_dot_throw(AST_ObjectGetter, return_true);
  9087. def_dot_throw(AST_Expansion, function(compressor) {
  9088. return this.expression._dot_throw(compressor);
  9089. });
  9090. def_dot_throw(AST_Function, return_false);
  9091. def_dot_throw(AST_Arrow, return_false);
  9092. def_dot_throw(AST_UnaryPostfix, return_false);
  9093. def_dot_throw(AST_UnaryPrefix, function() {
  9094. return this.operator == "void";
  9095. });
  9096. def_dot_throw(AST_Binary, function(compressor) {
  9097. return (this.operator == "&&" || this.operator == "||")
  9098. && (this.left._dot_throw(compressor) || this.right._dot_throw(compressor));
  9099. });
  9100. def_dot_throw(AST_Assign, function(compressor) {
  9101. return this.operator == "="
  9102. && this.right._dot_throw(compressor);
  9103. });
  9104. def_dot_throw(AST_Conditional, function(compressor) {
  9105. return this.consequent._dot_throw(compressor)
  9106. || this.alternative._dot_throw(compressor);
  9107. });
  9108. def_dot_throw(AST_Dot, function(compressor) {
  9109. if (!is_strict(compressor)) return false;
  9110. if (this.expression instanceof AST_Function && this.property == "prototype") return false;
  9111. return true;
  9112. });
  9113. def_dot_throw(AST_Sequence, function(compressor) {
  9114. return this.tail_node()._dot_throw(compressor);
  9115. });
  9116. def_dot_throw(AST_SymbolRef, function(compressor) {
  9117. if (this.is_undefined) return true;
  9118. if (!is_strict(compressor)) return false;
  9119. if (is_undeclared_ref(this) && this.is_declared(compressor)) return false;
  9120. if (this.is_immutable()) return false;
  9121. var fixed = this.fixed_value();
  9122. return !fixed || fixed._dot_throw(compressor);
  9123. });
  9124. })(function(node, func) {
  9125. node.DEFMETHOD("_dot_throw", func);
  9126. });
  9127. /* -----[ boolean/negation helpers ]----- */
  9128. // methods to determine whether an expression has a boolean result type
  9129. (function(def_is_boolean) {
  9130. var unary_bool = [ "!", "delete" ];
  9131. var binary_bool = [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ];
  9132. def_is_boolean(AST_Node, return_false);
  9133. def_is_boolean(AST_UnaryPrefix, function() {
  9134. return member(this.operator, unary_bool);
  9135. });
  9136. def_is_boolean(AST_Binary, function() {
  9137. return member(this.operator, binary_bool)
  9138. || lazy_op(this.operator)
  9139. && this.left.is_boolean()
  9140. && this.right.is_boolean();
  9141. });
  9142. def_is_boolean(AST_Conditional, function() {
  9143. return this.consequent.is_boolean() && this.alternative.is_boolean();
  9144. });
  9145. def_is_boolean(AST_Assign, function() {
  9146. return this.operator == "=" && this.right.is_boolean();
  9147. });
  9148. def_is_boolean(AST_Sequence, function() {
  9149. return this.tail_node().is_boolean();
  9150. });
  9151. def_is_boolean(AST_True, return_true);
  9152. def_is_boolean(AST_False, return_true);
  9153. })(function(node, func) {
  9154. node.DEFMETHOD("is_boolean", func);
  9155. });
  9156. // methods to determine if an expression has a numeric result type
  9157. (function(def_is_number) {
  9158. def_is_number(AST_Node, return_false);
  9159. def_is_number(AST_Number, return_true);
  9160. var unary = makePredicate("+ - ~ ++ --");
  9161. def_is_number(AST_Unary, function() {
  9162. return unary(this.operator);
  9163. });
  9164. var binary = makePredicate("- * / % & | ^ << >> >>>");
  9165. def_is_number(AST_Binary, function(compressor) {
  9166. return binary(this.operator) || this.operator == "+"
  9167. && this.left.is_number(compressor)
  9168. && this.right.is_number(compressor);
  9169. });
  9170. def_is_number(AST_Assign, function(compressor) {
  9171. return binary(this.operator.slice(0, -1))
  9172. || this.operator == "=" && this.right.is_number(compressor);
  9173. });
  9174. def_is_number(AST_Sequence, function(compressor) {
  9175. return this.tail_node().is_number(compressor);
  9176. });
  9177. def_is_number(AST_Conditional, function(compressor) {
  9178. return this.consequent.is_number(compressor) && this.alternative.is_number(compressor);
  9179. });
  9180. })(function(node, func) {
  9181. node.DEFMETHOD("is_number", func);
  9182. });
  9183. // methods to determine if an expression has a string result type
  9184. (function(def_is_string) {
  9185. def_is_string(AST_Node, return_false);
  9186. def_is_string(AST_String, return_true);
  9187. def_is_string(AST_TemplateString, function() {
  9188. return this.segments.length === 1;
  9189. });
  9190. def_is_string(AST_UnaryPrefix, function() {
  9191. return this.operator == "typeof";
  9192. });
  9193. def_is_string(AST_Binary, function(compressor) {
  9194. return this.operator == "+" &&
  9195. (this.left.is_string(compressor) || this.right.is_string(compressor));
  9196. });
  9197. def_is_string(AST_Assign, function(compressor) {
  9198. return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor);
  9199. });
  9200. def_is_string(AST_Sequence, function(compressor) {
  9201. return this.tail_node().is_string(compressor);
  9202. });
  9203. def_is_string(AST_Conditional, function(compressor) {
  9204. return this.consequent.is_string(compressor) && this.alternative.is_string(compressor);
  9205. });
  9206. })(function(node, func) {
  9207. node.DEFMETHOD("is_string", func);
  9208. });
  9209. var lazy_op = makePredicate("&& ||");
  9210. var unary_side_effects = makePredicate("delete ++ --");
  9211. function is_lhs(node, parent) {
  9212. if (parent instanceof AST_Unary && unary_side_effects(parent.operator)) return parent.expression;
  9213. if (parent instanceof AST_Assign && parent.left === node) return node;
  9214. }
  9215. (function(def_find_defs) {
  9216. function to_node(value, orig) {
  9217. if (value instanceof AST_Node) return make_node(value.CTOR, orig, value);
  9218. if (Array.isArray(value)) return make_node(AST_Array, orig, {
  9219. elements: value.map(function(value) {
  9220. return to_node(value, orig);
  9221. })
  9222. });
  9223. if (value && typeof value == "object") {
  9224. var props = [];
  9225. for (var key in value) if (HOP(value, key)) {
  9226. props.push(make_node(AST_ObjectKeyVal, orig, {
  9227. key: key,
  9228. value: to_node(value[key], orig)
  9229. }));
  9230. }
  9231. return make_node(AST_Object, orig, {
  9232. properties: props
  9233. });
  9234. }
  9235. return make_node_from_constant(value, orig);
  9236. }
  9237. function warn(compressor, node) {
  9238. compressor.warn("global_defs " + node.print_to_string() + " redefined [{file}:{line},{col}]", node.start);
  9239. }
  9240. AST_Toplevel.DEFMETHOD("resolve_defines", function(compressor) {
  9241. if (!compressor.option("global_defs")) return this;
  9242. this.figure_out_scope({ ie8: compressor.option("ie8") });
  9243. return this.transform(new TreeTransformer(function(node) {
  9244. var def = node._find_defs(compressor, "");
  9245. if (!def) return;
  9246. var level = 0, child = node, parent;
  9247. while (parent = this.parent(level++)) {
  9248. if (!(parent instanceof AST_PropAccess)) break;
  9249. if (parent.expression !== child) break;
  9250. child = parent;
  9251. }
  9252. if (is_lhs(child, parent)) {
  9253. warn(compressor, node);
  9254. return;
  9255. }
  9256. return def;
  9257. }));
  9258. });
  9259. def_find_defs(AST_Node, noop);
  9260. def_find_defs(AST_Dot, function(compressor, suffix) {
  9261. return this.expression._find_defs(compressor, "." + this.property + suffix);
  9262. });
  9263. def_find_defs(AST_SymbolDeclaration, function(compressor) {
  9264. if (!this.global()) return;
  9265. if (HOP(compressor.option("global_defs"), this.name)) warn(compressor, this);
  9266. });
  9267. def_find_defs(AST_SymbolRef, function(compressor, suffix) {
  9268. if (!this.global()) return;
  9269. var defines = compressor.option("global_defs");
  9270. var name = this.name + suffix;
  9271. if (HOP(defines, name)) return to_node(defines[name], this);
  9272. });
  9273. })(function(node, func) {
  9274. node.DEFMETHOD("_find_defs", func);
  9275. });
  9276. function best_of_expression(ast1, ast2) {
  9277. return ast1.print_to_string().length >
  9278. ast2.print_to_string().length
  9279. ? ast2 : ast1;
  9280. }
  9281. function best_of_statement(ast1, ast2) {
  9282. return best_of_expression(make_node(AST_SimpleStatement, ast1, {
  9283. body: ast1
  9284. }), make_node(AST_SimpleStatement, ast2, {
  9285. body: ast2
  9286. })).body;
  9287. }
  9288. function best_of(compressor, ast1, ast2) {
  9289. return (first_in_statement(compressor) ? best_of_statement : best_of_expression)(ast1, ast2);
  9290. }
  9291. function convert_to_predicate(obj) {
  9292. for (var key in obj) {
  9293. obj[key] = makePredicate(obj[key]);
  9294. }
  9295. }
  9296. var object_fns = [
  9297. "constructor",
  9298. "toString",
  9299. "valueOf",
  9300. ];
  9301. var native_fns = {
  9302. Array: [
  9303. "indexOf",
  9304. "join",
  9305. "lastIndexOf",
  9306. "slice",
  9307. ].concat(object_fns),
  9308. Boolean: object_fns,
  9309. Function: object_fns,
  9310. Number: [
  9311. "toExponential",
  9312. "toFixed",
  9313. "toPrecision",
  9314. ].concat(object_fns),
  9315. Object: object_fns,
  9316. RegExp: [
  9317. "test",
  9318. ].concat(object_fns),
  9319. String: [
  9320. "charAt",
  9321. "charCodeAt",
  9322. "concat",
  9323. "indexOf",
  9324. "italics",
  9325. "lastIndexOf",
  9326. "match",
  9327. "replace",
  9328. "search",
  9329. "slice",
  9330. "split",
  9331. "substr",
  9332. "substring",
  9333. "toLowerCase",
  9334. "toUpperCase",
  9335. "trim",
  9336. ].concat(object_fns),
  9337. };
  9338. convert_to_predicate(native_fns);
  9339. var static_fns = {
  9340. Array: [
  9341. "isArray",
  9342. ],
  9343. Math: [
  9344. "abs",
  9345. "acos",
  9346. "asin",
  9347. "atan",
  9348. "ceil",
  9349. "cos",
  9350. "exp",
  9351. "floor",
  9352. "log",
  9353. "round",
  9354. "sin",
  9355. "sqrt",
  9356. "tan",
  9357. "atan2",
  9358. "pow",
  9359. "max",
  9360. "min",
  9361. ],
  9362. Number: [
  9363. "isFinite",
  9364. "isNaN",
  9365. ],
  9366. Object: [
  9367. "create",
  9368. "getOwnPropertyDescriptor",
  9369. "getOwnPropertyNames",
  9370. "getPrototypeOf",
  9371. "isExtensible",
  9372. "isFrozen",
  9373. "isSealed",
  9374. "keys",
  9375. ],
  9376. String: [
  9377. "fromCharCode",
  9378. ],
  9379. };
  9380. convert_to_predicate(static_fns);
  9381. // methods to evaluate a constant expression
  9382. (function(def_eval) {
  9383. // If the node has been successfully reduced to a constant,
  9384. // then its value is returned; otherwise the element itself
  9385. // is returned.
  9386. // They can be distinguished as constant value is never a
  9387. // descendant of AST_Node.
  9388. AST_Node.DEFMETHOD("evaluate", function(compressor) {
  9389. if (!compressor.option("evaluate")) return this;
  9390. var val = this._eval(compressor, 1);
  9391. if (!val || val instanceof RegExp) return val;
  9392. if (typeof val == "function" || typeof val == "object") return this;
  9393. return val;
  9394. });
  9395. var unaryPrefix = makePredicate("! ~ - + void");
  9396. AST_Node.DEFMETHOD("is_constant", function() {
  9397. // Accomodate when compress option evaluate=false
  9398. // as well as the common constant expressions !0 and -1
  9399. if (this instanceof AST_Constant) {
  9400. return !(this instanceof AST_RegExp);
  9401. } else {
  9402. return this instanceof AST_UnaryPrefix
  9403. && this.expression instanceof AST_Constant
  9404. && unaryPrefix(this.operator);
  9405. }
  9406. });
  9407. def_eval(AST_Statement, function() {
  9408. throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
  9409. });
  9410. def_eval(AST_Lambda, return_this);
  9411. def_eval(AST_Class, return_this);
  9412. def_eval(AST_Node, return_this);
  9413. def_eval(AST_Constant, function() {
  9414. return this.getValue();
  9415. });
  9416. def_eval(AST_TemplateString, function() {
  9417. if (this.segments.length !== 1) return this;
  9418. return this.segments[0].value;
  9419. });
  9420. def_eval(AST_Function, function(compressor) {
  9421. if (compressor.option("unsafe")) {
  9422. var fn = function() {};
  9423. fn.node = this;
  9424. fn.toString = function() {
  9425. return this.node.print_to_string();
  9426. };
  9427. return fn;
  9428. }
  9429. return this;
  9430. });
  9431. def_eval(AST_Array, function(compressor, depth) {
  9432. if (compressor.option("unsafe")) {
  9433. var elements = [];
  9434. for (var i = 0, len = this.elements.length; i < len; i++) {
  9435. var element = this.elements[i];
  9436. var value = element._eval(compressor, depth);
  9437. if (element === value) return this;
  9438. elements.push(value);
  9439. }
  9440. return elements;
  9441. }
  9442. return this;
  9443. });
  9444. def_eval(AST_Object, function(compressor, depth) {
  9445. if (compressor.option("unsafe")) {
  9446. var val = {};
  9447. for (var i = 0, len = this.properties.length; i < len; i++) {
  9448. var prop = this.properties[i];
  9449. if (prop instanceof AST_Expansion) return this;
  9450. var key = prop.key;
  9451. if (key instanceof AST_Symbol) {
  9452. key = key.name;
  9453. } else if (key instanceof AST_Node) {
  9454. key = key._eval(compressor, depth);
  9455. if (key === prop.key) return this;
  9456. }
  9457. if (typeof Object.prototype[key] === "function") {
  9458. return this;
  9459. }
  9460. if (prop.value instanceof AST_Function) continue;
  9461. val[key] = prop.value._eval(compressor, depth);
  9462. if (val[key] === prop.value) return this;
  9463. }
  9464. return val;
  9465. }
  9466. return this;
  9467. });
  9468. var non_converting_unary = makePredicate("! typeof void");
  9469. def_eval(AST_UnaryPrefix, function(compressor, depth) {
  9470. var e = this.expression;
  9471. // Function would be evaluated to an array and so typeof would
  9472. // incorrectly return 'object'. Hence making is a special case.
  9473. if (compressor.option("typeofs")
  9474. && this.operator == "typeof"
  9475. && (e instanceof AST_Lambda
  9476. || e instanceof AST_SymbolRef
  9477. && e.fixed_value() instanceof AST_Lambda)) {
  9478. return typeof function() {};
  9479. }
  9480. if (!non_converting_unary(this.operator)) depth++;
  9481. e = e._eval(compressor, depth);
  9482. if (e === this.expression) return this;
  9483. switch (this.operator) {
  9484. case "!": return !e;
  9485. case "typeof":
  9486. // typeof <RegExp> returns "object" or "function" on different platforms
  9487. // so cannot evaluate reliably
  9488. if (e instanceof RegExp) return this;
  9489. return typeof e;
  9490. case "void": return void e;
  9491. case "~": return ~e;
  9492. case "-": return -e;
  9493. case "+": return +e;
  9494. }
  9495. return this;
  9496. });
  9497. var non_converting_binary = makePredicate("&& || === !==");
  9498. def_eval(AST_Binary, function(compressor, depth) {
  9499. if (!non_converting_binary(this.operator)) depth++;
  9500. var left = this.left._eval(compressor, depth);
  9501. if (left === this.left) return this;
  9502. var right = this.right._eval(compressor, depth);
  9503. if (right === this.right) return this;
  9504. var result;
  9505. switch (this.operator) {
  9506. case "&&" : result = left && right; break;
  9507. case "||" : result = left || right; break;
  9508. case "|" : result = left | right; break;
  9509. case "&" : result = left & right; break;
  9510. case "^" : result = left ^ right; break;
  9511. case "+" : result = left + right; break;
  9512. case "*" : result = left * right; break;
  9513. case "**" : result = Math.pow(left, right); break;
  9514. case "/" : result = left / right; break;
  9515. case "%" : result = left % right; break;
  9516. case "-" : result = left - right; break;
  9517. case "<<" : result = left << right; break;
  9518. case ">>" : result = left >> right; break;
  9519. case ">>>" : result = left >>> right; break;
  9520. case "==" : result = left == right; break;
  9521. case "===" : result = left === right; break;
  9522. case "!=" : result = left != right; break;
  9523. case "!==" : result = left !== right; break;
  9524. case "<" : result = left < right; break;
  9525. case "<=" : result = left <= right; break;
  9526. case ">" : result = left > right; break;
  9527. case ">=" : result = left >= right; break;
  9528. default:
  9529. return this;
  9530. }
  9531. if (isNaN(result) && compressor.find_parent(AST_With)) {
  9532. // leave original expression as is
  9533. return this;
  9534. }
  9535. return result;
  9536. });
  9537. def_eval(AST_Conditional, function(compressor, depth) {
  9538. var condition = this.condition._eval(compressor, depth);
  9539. if (condition === this.condition) return this;
  9540. var node = condition ? this.consequent : this.alternative;
  9541. var value = node._eval(compressor, depth);
  9542. return value === node ? this : value;
  9543. });
  9544. def_eval(AST_SymbolRef, function(compressor, depth) {
  9545. var fixed = this.fixed_value();
  9546. if (!fixed) return this;
  9547. var value;
  9548. if (HOP(fixed, "_eval")) {
  9549. value = fixed._eval();
  9550. } else {
  9551. this._eval = return_this;
  9552. value = fixed._eval(compressor, depth);
  9553. delete this._eval;
  9554. if (value === fixed) return this;
  9555. fixed._eval = function() {
  9556. return value;
  9557. };
  9558. }
  9559. if (value && typeof value == "object") {
  9560. var escaped = this.definition().escaped;
  9561. if (escaped && depth > escaped) return this;
  9562. }
  9563. return value;
  9564. });
  9565. var global_objs = {
  9566. Array: Array,
  9567. Math: Math,
  9568. Number: Number,
  9569. Object: Object,
  9570. String: String,
  9571. };
  9572. var static_values = {
  9573. Math: [
  9574. "E",
  9575. "LN10",
  9576. "LN2",
  9577. "LOG2E",
  9578. "LOG10E",
  9579. "PI",
  9580. "SQRT1_2",
  9581. "SQRT2",
  9582. ],
  9583. Number: [
  9584. "MAX_VALUE",
  9585. "MIN_VALUE",
  9586. "NaN",
  9587. "NEGATIVE_INFINITY",
  9588. "POSITIVE_INFINITY",
  9589. ],
  9590. };
  9591. convert_to_predicate(static_values);
  9592. def_eval(AST_PropAccess, function(compressor, depth) {
  9593. if (compressor.option("unsafe")) {
  9594. var key = this.property;
  9595. if (key instanceof AST_Node) {
  9596. key = key._eval(compressor, depth);
  9597. if (key === this.property) return this;
  9598. }
  9599. var exp = this.expression;
  9600. var val;
  9601. if (is_undeclared_ref(exp)) {
  9602. var aa;
  9603. var first_arg = exp.name === "hasOwnProperty"
  9604. && key === "call"
  9605. && (aa = compressor.parent() && compressor.parent().args)
  9606. && (aa && aa[0]
  9607. && aa[0].evaluate(compressor));
  9608. first_arg = first_arg instanceof AST_Dot ? first_arg.expression : first_arg;
  9609. if (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) {
  9610. return this.clone();
  9611. }
  9612. if (!(static_values[exp.name] || return_false)(key)) return this;
  9613. val = global_objs[exp.name];
  9614. } else {
  9615. val = exp._eval(compressor, depth + 1);
  9616. if (!val || val === exp || !HOP(val, key)) return this;
  9617. if (typeof val == "function") switch (key) {
  9618. case "name":
  9619. return val.node.name ? val.node.name.name : "";
  9620. case "length":
  9621. return val.node.argnames.length;
  9622. default:
  9623. return this;
  9624. }
  9625. }
  9626. return val[key];
  9627. }
  9628. return this;
  9629. });
  9630. def_eval(AST_Call, function(compressor, depth) {
  9631. var exp = this.expression;
  9632. if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
  9633. var key = exp.property;
  9634. if (key instanceof AST_Node) {
  9635. key = key._eval(compressor, depth);
  9636. if (key === exp.property) return this;
  9637. }
  9638. var val;
  9639. var e = exp.expression;
  9640. if (is_undeclared_ref(e)) {
  9641. var first_arg =
  9642. e.name === "hasOwnProperty" &&
  9643. key === "call" &&
  9644. (this.args[0] && this.args[0].evaluate(compressor));
  9645. first_arg = first_arg instanceof AST_Dot ? first_arg.expression : first_arg;
  9646. if ((first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)) {
  9647. return this.clone();
  9648. }
  9649. if (!(static_fns[e.name] || return_false)(key)) return this;
  9650. val = global_objs[e.name];
  9651. } else {
  9652. val = e._eval(compressor, depth + 1);
  9653. if (val === e || !(val && native_fns[val.constructor.name] || return_false)(key)) return this;
  9654. }
  9655. var args = [];
  9656. for (var i = 0, len = this.args.length; i < len; i++) {
  9657. var arg = this.args[i];
  9658. var value = arg._eval(compressor, depth);
  9659. if (arg === value) return this;
  9660. args.push(value);
  9661. }
  9662. try {
  9663. return val[key].apply(val, args);
  9664. } catch (ex) {
  9665. compressor.warn("Error evaluating {code} [{file}:{line},{col}]", {
  9666. code: this.print_to_string(),
  9667. file: this.start.file,
  9668. line: this.start.line,
  9669. col: this.start.col
  9670. });
  9671. }
  9672. }
  9673. return this;
  9674. });
  9675. def_eval(AST_New, return_this);
  9676. })(function(node, func) {
  9677. node.DEFMETHOD("_eval", func);
  9678. });
  9679. // method to negate an expression
  9680. (function(def_negate) {
  9681. function basic_negation(exp) {
  9682. return make_node(AST_UnaryPrefix, exp, {
  9683. operator: "!",
  9684. expression: exp
  9685. });
  9686. }
  9687. function best(orig, alt, first_in_statement$$1) {
  9688. var negated = basic_negation(orig);
  9689. if (first_in_statement$$1) {
  9690. var stat = make_node(AST_SimpleStatement, alt, {
  9691. body: alt
  9692. });
  9693. return best_of_expression(negated, stat) === stat ? alt : negated;
  9694. }
  9695. return best_of_expression(negated, alt);
  9696. }
  9697. def_negate(AST_Node, function() {
  9698. return basic_negation(this);
  9699. });
  9700. def_negate(AST_Statement, function() {
  9701. throw new Error("Cannot negate a statement");
  9702. });
  9703. def_negate(AST_Function, function() {
  9704. return basic_negation(this);
  9705. });
  9706. def_negate(AST_Arrow, function() {
  9707. return basic_negation(this);
  9708. });
  9709. def_negate(AST_UnaryPrefix, function() {
  9710. if (this.operator == "!")
  9711. return this.expression;
  9712. return basic_negation(this);
  9713. });
  9714. def_negate(AST_Sequence, function(compressor) {
  9715. var expressions = this.expressions.slice();
  9716. expressions.push(expressions.pop().negate(compressor));
  9717. return make_sequence(this, expressions);
  9718. });
  9719. def_negate(AST_Conditional, function(compressor, first_in_statement$$1) {
  9720. var self = this.clone();
  9721. self.consequent = self.consequent.negate(compressor);
  9722. self.alternative = self.alternative.negate(compressor);
  9723. return best(this, self, first_in_statement$$1);
  9724. });
  9725. def_negate(AST_Binary, function(compressor, first_in_statement$$1) {
  9726. var self = this.clone(), op = this.operator;
  9727. if (compressor.option("unsafe_comps")) {
  9728. switch (op) {
  9729. case "<=" : self.operator = ">" ; return self;
  9730. case "<" : self.operator = ">=" ; return self;
  9731. case ">=" : self.operator = "<" ; return self;
  9732. case ">" : self.operator = "<=" ; return self;
  9733. }
  9734. }
  9735. switch (op) {
  9736. case "==" : self.operator = "!="; return self;
  9737. case "!=" : self.operator = "=="; return self;
  9738. case "===": self.operator = "!=="; return self;
  9739. case "!==": self.operator = "==="; return self;
  9740. case "&&":
  9741. self.operator = "||";
  9742. self.left = self.left.negate(compressor, first_in_statement$$1);
  9743. self.right = self.right.negate(compressor);
  9744. return best(this, self, first_in_statement$$1);
  9745. case "||":
  9746. self.operator = "&&";
  9747. self.left = self.left.negate(compressor, first_in_statement$$1);
  9748. self.right = self.right.negate(compressor);
  9749. return best(this, self, first_in_statement$$1);
  9750. }
  9751. return basic_negation(this);
  9752. });
  9753. })(function(node, func) {
  9754. node.DEFMETHOD("negate", function(compressor, first_in_statement$$1) {
  9755. return func.call(this, compressor, first_in_statement$$1);
  9756. });
  9757. });
  9758. var global_pure_fns = makePredicate("Boolean decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError");
  9759. AST_Call.DEFMETHOD("is_expr_pure", function(compressor) {
  9760. if (compressor.option("unsafe")) {
  9761. var expr = this.expression;
  9762. var first_arg = (this.args && this.args[0] && this.args[0].evaluate(compressor));
  9763. if (
  9764. expr.expression && expr.expression.name === "hasOwnProperty" &&
  9765. (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)
  9766. ) {
  9767. return false;
  9768. }
  9769. if (is_undeclared_ref(expr) && global_pure_fns(expr.name)) return true;
  9770. if (expr instanceof AST_Dot
  9771. && is_undeclared_ref(expr.expression)
  9772. && (static_fns.hasOwnProperty(expr.expression.name) && static_fns[expr.expression.name] || return_false)(expr.property)) {
  9773. return true;
  9774. }
  9775. }
  9776. return this.pure || !compressor.pure_funcs(this);
  9777. });
  9778. AST_Node.DEFMETHOD("is_call_pure", return_false);
  9779. AST_Dot.DEFMETHOD("is_call_pure", function(compressor) {
  9780. if (!compressor.option("unsafe")) return;
  9781. var expr = this.expression;
  9782. var fns = return_false;
  9783. if (expr instanceof AST_Array) {
  9784. fns = native_fns.Array;
  9785. } else if (expr.is_boolean()) {
  9786. fns = native_fns.Boolean;
  9787. } else if (expr.is_number(compressor)) {
  9788. fns = native_fns.Number;
  9789. } else if (expr instanceof AST_RegExp) {
  9790. fns = native_fns.RegExp;
  9791. } else if (expr.is_string(compressor)) {
  9792. fns = native_fns.String;
  9793. } else if (!this.may_throw_on_access(compressor)) {
  9794. fns = native_fns.Object;
  9795. }
  9796. return fns(this.property);
  9797. });
  9798. // determine if expression has side effects
  9799. (function(def_has_side_effects) {
  9800. def_has_side_effects(AST_Node, return_true);
  9801. def_has_side_effects(AST_EmptyStatement, return_false);
  9802. def_has_side_effects(AST_Constant, return_false);
  9803. def_has_side_effects(AST_This, return_false);
  9804. function any(list, compressor) {
  9805. for (var i = list.length; --i >= 0;)
  9806. if (list[i].has_side_effects(compressor))
  9807. return true;
  9808. return false;
  9809. }
  9810. def_has_side_effects(AST_Block, function(compressor) {
  9811. return any(this.body, compressor);
  9812. });
  9813. def_has_side_effects(AST_Call, function(compressor) {
  9814. if (!this.is_expr_pure(compressor)
  9815. && (!this.expression.is_call_pure(compressor)
  9816. || this.expression.has_side_effects(compressor))) {
  9817. return true;
  9818. }
  9819. return any(this.args, compressor);
  9820. });
  9821. def_has_side_effects(AST_Switch, function(compressor) {
  9822. return this.expression.has_side_effects(compressor)
  9823. || any(this.body, compressor);
  9824. });
  9825. def_has_side_effects(AST_Case, function(compressor) {
  9826. return this.expression.has_side_effects(compressor)
  9827. || any(this.body, compressor);
  9828. });
  9829. def_has_side_effects(AST_Try, function(compressor) {
  9830. return any(this.body, compressor)
  9831. || this.bcatch && this.bcatch.has_side_effects(compressor)
  9832. || this.bfinally && this.bfinally.has_side_effects(compressor);
  9833. });
  9834. def_has_side_effects(AST_If, function(compressor) {
  9835. return this.condition.has_side_effects(compressor)
  9836. || this.body && this.body.has_side_effects(compressor)
  9837. || this.alternative && this.alternative.has_side_effects(compressor);
  9838. });
  9839. def_has_side_effects(AST_LabeledStatement, function(compressor) {
  9840. return this.body.has_side_effects(compressor);
  9841. });
  9842. def_has_side_effects(AST_SimpleStatement, function(compressor) {
  9843. return this.body.has_side_effects(compressor);
  9844. });
  9845. def_has_side_effects(AST_Lambda, return_false);
  9846. def_has_side_effects(AST_Class, return_false);
  9847. def_has_side_effects(AST_DefClass, return_true);
  9848. def_has_side_effects(AST_Binary, function(compressor) {
  9849. return this.left.has_side_effects(compressor)
  9850. || this.right.has_side_effects(compressor);
  9851. });
  9852. def_has_side_effects(AST_Assign, return_true);
  9853. def_has_side_effects(AST_Conditional, function(compressor) {
  9854. return this.condition.has_side_effects(compressor)
  9855. || this.consequent.has_side_effects(compressor)
  9856. || this.alternative.has_side_effects(compressor);
  9857. });
  9858. def_has_side_effects(AST_Unary, function(compressor) {
  9859. return unary_side_effects(this.operator)
  9860. || this.expression.has_side_effects(compressor);
  9861. });
  9862. def_has_side_effects(AST_SymbolRef, function(compressor) {
  9863. return !this.is_declared(compressor);
  9864. });
  9865. def_has_side_effects(AST_SymbolDeclaration, return_false);
  9866. def_has_side_effects(AST_Object, function(compressor) {
  9867. return any(this.properties, compressor);
  9868. });
  9869. def_has_side_effects(AST_ObjectProperty, function(compressor) {
  9870. if (this.key instanceof AST_ObjectKeyVal &&
  9871. this.key.has_side_effects(compressor))
  9872. return true;
  9873. return this.value.has_side_effects(compressor);
  9874. });
  9875. def_has_side_effects(AST_Array, function(compressor) {
  9876. return any(this.elements, compressor);
  9877. });
  9878. def_has_side_effects(AST_Dot, function(compressor) {
  9879. return this.expression.may_throw_on_access(compressor)
  9880. || this.expression.has_side_effects(compressor);
  9881. });
  9882. def_has_side_effects(AST_Sub, function(compressor) {
  9883. return this.expression.may_throw_on_access(compressor)
  9884. || this.expression.has_side_effects(compressor)
  9885. || this.property.has_side_effects(compressor);
  9886. });
  9887. def_has_side_effects(AST_Sequence, function(compressor) {
  9888. return any(this.expressions, compressor);
  9889. });
  9890. def_has_side_effects(AST_Definitions, function(compressor) {
  9891. return any(this.definitions, compressor);
  9892. });
  9893. def_has_side_effects(AST_VarDef, function(compressor) {
  9894. return this.value;
  9895. });
  9896. def_has_side_effects(AST_TemplateSegment, return_false);
  9897. def_has_side_effects(AST_TemplateString, function(compressor) {
  9898. return any(this.segments, compressor);
  9899. });
  9900. })(function(node, func) {
  9901. node.DEFMETHOD("has_side_effects", func);
  9902. });
  9903. // determine if expression may throw
  9904. (function(def_may_throw) {
  9905. def_may_throw(AST_Node, return_true);
  9906. def_may_throw(AST_Class, return_false);
  9907. def_may_throw(AST_Constant, return_false);
  9908. def_may_throw(AST_EmptyStatement, return_false);
  9909. def_may_throw(AST_Lambda, return_false);
  9910. def_may_throw(AST_SymbolDeclaration, return_false);
  9911. def_may_throw(AST_This, return_false);
  9912. function any(list, compressor) {
  9913. for (var i = list.length; --i >= 0;)
  9914. if (list[i].may_throw(compressor))
  9915. return true;
  9916. return false;
  9917. }
  9918. def_may_throw(AST_Array, function(compressor) {
  9919. return any(this.elements, compressor);
  9920. });
  9921. def_may_throw(AST_Assign, function(compressor) {
  9922. if (this.right.may_throw(compressor)) return true;
  9923. if (!compressor.has_directive("use strict")
  9924. && this.operator == "="
  9925. && this.left instanceof AST_SymbolRef) {
  9926. return false;
  9927. }
  9928. return this.left.may_throw(compressor);
  9929. });
  9930. def_may_throw(AST_Binary, function(compressor) {
  9931. return this.left.may_throw(compressor)
  9932. || this.right.may_throw(compressor);
  9933. });
  9934. def_may_throw(AST_Block, function(compressor) {
  9935. return any(this.body, compressor);
  9936. });
  9937. def_may_throw(AST_Call, function(compressor) {
  9938. if (any(this.args, compressor)) return true;
  9939. if (this.is_expr_pure(compressor)) return false;
  9940. if (this.expression.may_throw(compressor)) return true;
  9941. return !(this.expression instanceof AST_Lambda)
  9942. || any(this.expression.body, compressor);
  9943. });
  9944. def_may_throw(AST_Case, function(compressor) {
  9945. return this.expression.may_throw(compressor)
  9946. || any(this.body, compressor);
  9947. });
  9948. def_may_throw(AST_Conditional, function(compressor) {
  9949. return this.condition.may_throw(compressor)
  9950. || this.consequent.may_throw(compressor)
  9951. || this.alternative.may_throw(compressor);
  9952. });
  9953. def_may_throw(AST_Definitions, function(compressor) {
  9954. return any(this.definitions, compressor);
  9955. });
  9956. def_may_throw(AST_Dot, function(compressor) {
  9957. return this.expression.may_throw_on_access(compressor)
  9958. || this.expression.may_throw(compressor);
  9959. });
  9960. def_may_throw(AST_If, function(compressor) {
  9961. return this.condition.may_throw(compressor)
  9962. || this.body && this.body.may_throw(compressor)
  9963. || this.alternative && this.alternative.may_throw(compressor);
  9964. });
  9965. def_may_throw(AST_LabeledStatement, function(compressor) {
  9966. return this.body.may_throw(compressor);
  9967. });
  9968. def_may_throw(AST_Object, function(compressor) {
  9969. return any(this.properties, compressor);
  9970. });
  9971. def_may_throw(AST_ObjectProperty, function(compressor) {
  9972. return this.value.may_throw(compressor);
  9973. });
  9974. def_may_throw(AST_Return, function(compressor) {
  9975. return this.value && this.value.may_throw(compressor);
  9976. });
  9977. def_may_throw(AST_Sequence, function(compressor) {
  9978. return any(this.expressions, compressor);
  9979. });
  9980. def_may_throw(AST_SimpleStatement, function(compressor) {
  9981. return this.body.may_throw(compressor);
  9982. });
  9983. def_may_throw(AST_Sub, function(compressor) {
  9984. return this.expression.may_throw_on_access(compressor)
  9985. || this.expression.may_throw(compressor)
  9986. || this.property.may_throw(compressor);
  9987. });
  9988. def_may_throw(AST_Switch, function(compressor) {
  9989. return this.expression.may_throw(compressor)
  9990. || any(this.body, compressor);
  9991. });
  9992. def_may_throw(AST_SymbolRef, function(compressor) {
  9993. return !this.is_declared(compressor);
  9994. });
  9995. def_may_throw(AST_Try, function(compressor) {
  9996. return this.bcatch ? this.bcatch.may_throw(compressor) : any(this.body, compressor)
  9997. || this.bfinally && this.bfinally.may_throw(compressor);
  9998. });
  9999. def_may_throw(AST_Unary, function(compressor) {
  10000. if (this.operator == "typeof" && this.expression instanceof AST_SymbolRef)
  10001. return false;
  10002. return this.expression.may_throw(compressor);
  10003. });
  10004. def_may_throw(AST_VarDef, function(compressor) {
  10005. if (!this.value) return false;
  10006. return this.value.may_throw(compressor);
  10007. });
  10008. })(function(node, func) {
  10009. node.DEFMETHOD("may_throw", func);
  10010. });
  10011. // determine if expression is constant
  10012. (function(def_is_constant_expression) {
  10013. function all$$1(list) {
  10014. for (var i = list.length; --i >= 0;)
  10015. if (!list[i].is_constant_expression())
  10016. return false;
  10017. return true;
  10018. }
  10019. function all_refs_local(scope) {
  10020. var self = this;
  10021. var result = true;
  10022. self.walk(new TreeWalker(function(node) {
  10023. if (!result) return true;
  10024. if (node instanceof AST_SymbolRef) {
  10025. if (self.inlined) {
  10026. result = false;
  10027. return true;
  10028. }
  10029. var def = node.definition();
  10030. if (member(def, self.enclosed)
  10031. && !self.variables.has(def.name)) {
  10032. if (scope) {
  10033. var scope_def = scope.find_variable(node);
  10034. if (def.undeclared ? !scope_def : scope_def === def) {
  10035. result = "f";
  10036. return true;
  10037. }
  10038. }
  10039. result = false;
  10040. }
  10041. return true;
  10042. }
  10043. if (node instanceof AST_This && self instanceof AST_Arrow) {
  10044. result = false;
  10045. return true;
  10046. }
  10047. }));
  10048. return result;
  10049. }
  10050. def_is_constant_expression(AST_Node, return_false);
  10051. def_is_constant_expression(AST_Constant, return_true);
  10052. def_is_constant_expression(AST_Class, function(scope) {
  10053. var self = this;
  10054. if (self.extends && !self.extends.is_constant_expression(scope)) {
  10055. return false;
  10056. }
  10057. return all_refs_local.call(self, scope);
  10058. });
  10059. def_is_constant_expression(AST_Lambda, all_refs_local);
  10060. def_is_constant_expression(AST_Unary, function() {
  10061. return this.expression.is_constant_expression();
  10062. });
  10063. def_is_constant_expression(AST_Binary, function() {
  10064. return this.left.is_constant_expression() && this.right.is_constant_expression();
  10065. });
  10066. def_is_constant_expression(AST_Array, function() {
  10067. return all$$1(this.elements);
  10068. });
  10069. def_is_constant_expression(AST_Object, function() {
  10070. return all$$1(this.properties);
  10071. });
  10072. def_is_constant_expression(AST_ObjectProperty, function() {
  10073. return !(this.key instanceof AST_Node) && this.value.is_constant_expression();
  10074. });
  10075. })(function(node, func) {
  10076. node.DEFMETHOD("is_constant_expression", func);
  10077. });
  10078. // tell me if a statement aborts
  10079. function aborts(thing) {
  10080. return thing && thing.aborts();
  10081. }
  10082. (function(def) {
  10083. def(AST_Statement, return_null);
  10084. def(AST_Jump, return_this);
  10085. function block_aborts() {
  10086. for (var i = 0; i < this.body.length; i++) {
  10087. if (aborts(this.body[i])) {
  10088. return this.body[i];
  10089. }
  10090. }
  10091. return null;
  10092. }
  10093. def(AST_Import, function() { return null; });
  10094. def(AST_BlockStatement, block_aborts);
  10095. def(AST_SwitchBranch, block_aborts);
  10096. def(AST_If, function() {
  10097. return this.alternative && aborts(this.body) && aborts(this.alternative) && this;
  10098. });
  10099. })(function(node, func) {
  10100. node.DEFMETHOD("aborts", func);
  10101. });
  10102. /* -----[ optimizers ]----- */
  10103. var directives = ["use asm", "use strict"];
  10104. def_optimize(AST_Directive, function(self, compressor) {
  10105. if (compressor.option("directives")
  10106. && (!member(self.value, directives) || compressor.has_directive(self.value) !== self)) {
  10107. return make_node(AST_EmptyStatement, self);
  10108. }
  10109. return self;
  10110. });
  10111. def_optimize(AST_Debugger, function(self, compressor) {
  10112. if (compressor.option("drop_debugger"))
  10113. return make_node(AST_EmptyStatement, self);
  10114. return self;
  10115. });
  10116. def_optimize(AST_LabeledStatement, function(self, compressor) {
  10117. if (self.body instanceof AST_Break
  10118. && compressor.loopcontrol_target(self.body) === self.body) {
  10119. return make_node(AST_EmptyStatement, self);
  10120. }
  10121. return self.label.references.length == 0 ? self.body : self;
  10122. });
  10123. def_optimize(AST_Block, function(self, compressor) {
  10124. tighten_body(self.body, compressor);
  10125. return self;
  10126. });
  10127. function can_be_extracted_from_if_block(node) {
  10128. return !(
  10129. node instanceof AST_Const ||
  10130. node instanceof AST_Let ||
  10131. node instanceof AST_Class
  10132. );
  10133. }
  10134. def_optimize(AST_BlockStatement, function(self, compressor) {
  10135. tighten_body(self.body, compressor);
  10136. switch (self.body.length) {
  10137. case 1:
  10138. if (!compressor.has_directive("use strict")
  10139. && compressor.parent() instanceof AST_If
  10140. && can_be_extracted_from_if_block(self.body[0])
  10141. || can_be_evicted_from_block(self.body[0])) {
  10142. return self.body[0];
  10143. }
  10144. break;
  10145. case 0: return make_node(AST_EmptyStatement, self);
  10146. }
  10147. return self;
  10148. });
  10149. function opt_AST_Lambda(self, compressor) {
  10150. tighten_body(self.body, compressor);
  10151. if (compressor.option("side_effects")
  10152. && self.body.length == 1
  10153. && self.body[0] === compressor.has_directive("use strict")) {
  10154. self.body.length = 0;
  10155. }
  10156. return self;
  10157. }
  10158. def_optimize(AST_Lambda, opt_AST_Lambda);
  10159. AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
  10160. if (!compressor.option("unused")) return;
  10161. if (compressor.has_directive("use asm")) return;
  10162. var self = this;
  10163. if (self.pinned()) return;
  10164. var drop_funcs = !(self instanceof AST_Toplevel) || compressor.toplevel.funcs;
  10165. var drop_vars = !(self instanceof AST_Toplevel) || compressor.toplevel.vars;
  10166. var assign_as_unused = /keep_assign/.test(compressor.option("unused")) ? return_false : function(node) {
  10167. if (node instanceof AST_Assign && (node.write_only || node.operator == "=")) {
  10168. return node.left;
  10169. }
  10170. if (node instanceof AST_Unary && node.write_only) return node.expression;
  10171. };
  10172. var in_use = [];
  10173. var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use
  10174. var fixed_ids = Object.create(null);
  10175. if (self instanceof AST_Toplevel && compressor.top_retain) {
  10176. self.variables.each(function(def) {
  10177. if (compressor.top_retain(def) && !(def.id in in_use_ids)) {
  10178. in_use_ids[def.id] = true;
  10179. in_use.push(def);
  10180. }
  10181. });
  10182. }
  10183. var var_defs_by_id = new Dictionary();
  10184. var initializations = new Dictionary();
  10185. var destructuring_value = null;
  10186. // pass 1: find out which symbols are directly used in
  10187. // this scope (not in nested scopes).
  10188. var scope = this;
  10189. var tw = new TreeWalker(function(node, descend) {
  10190. if (node instanceof AST_Lambda && node.uses_arguments && !tw.has_directive("use strict")) {
  10191. node.argnames.forEach(function(argname) {
  10192. if (!(argname instanceof AST_SymbolDeclaration)) return;
  10193. var def = argname.definition();
  10194. if (!(def.id in in_use_ids)) {
  10195. in_use_ids[def.id] = true;
  10196. in_use.push(def);
  10197. }
  10198. });
  10199. }
  10200. if (node === self) return;
  10201. if (node instanceof AST_Defun || node instanceof AST_DefClass) {
  10202. var node_def = node.name.definition();
  10203. var in_export = tw.parent() instanceof AST_Export;
  10204. if (in_export || !drop_funcs && scope === self) {
  10205. if (node_def.global && !(node_def.id in in_use_ids)) {
  10206. in_use_ids[node_def.id] = true;
  10207. in_use.push(node_def);
  10208. }
  10209. }
  10210. initializations.add(node_def.id, node);
  10211. return true; // don't go in nested scopes
  10212. }
  10213. if (node instanceof AST_SymbolFunarg && scope === self) {
  10214. var_defs_by_id.add(node.definition().id, node);
  10215. }
  10216. if (node instanceof AST_Definitions && scope === self) {
  10217. var in_export = tw.parent() instanceof AST_Export;
  10218. node.definitions.forEach(function(def) {
  10219. if (def.name instanceof AST_SymbolVar) {
  10220. var_defs_by_id.add(def.name.definition().id, def);
  10221. }
  10222. if (in_export || !drop_vars) {
  10223. def.name.walk(new TreeWalker(function(node) {
  10224. if (node instanceof AST_SymbolDeclaration) {
  10225. var def = node.definition();
  10226. if ((in_export || def.global) && !(def.id in in_use_ids)) {
  10227. in_use_ids[def.id] = true;
  10228. in_use.push(def);
  10229. }
  10230. }
  10231. }));
  10232. }
  10233. if (def.value) {
  10234. if (def.name instanceof AST_Destructuring) {
  10235. var destructuring_cache = destructuring_value;
  10236. destructuring_value = def.value;
  10237. def.walk(tw);
  10238. destructuring_value = destructuring_cache;
  10239. } else {
  10240. var node_def = def.name.definition();
  10241. initializations.add(node_def.id, def.value);
  10242. if (!node_def.chained && def.name.fixed_value() === def.value) {
  10243. fixed_ids[node_def.id] = def;
  10244. }
  10245. }
  10246. if (def.value.has_side_effects(compressor)) {
  10247. def.value.walk(tw);
  10248. }
  10249. }
  10250. });
  10251. return true;
  10252. }
  10253. if (node.destructuring && destructuring_value) {
  10254. initializations.add(node.name, destructuring_value);
  10255. }
  10256. return scan_ref_scoped(node, descend);
  10257. });
  10258. self.walk(tw);
  10259. // pass 2: for every used symbol we need to walk its
  10260. // initialization code to figure out if it uses other
  10261. // symbols (that may not be in_use).
  10262. tw = new TreeWalker(scan_ref_scoped);
  10263. for (var i = 0; i < in_use.length; i++) {
  10264. var init = initializations.get(in_use[i].id);
  10265. if (init) init.forEach(function(init) {
  10266. init.walk(tw);
  10267. });
  10268. }
  10269. // pass 3: we should drop declarations not in_use
  10270. var tt = new TreeTransformer(
  10271. function before(node, descend, in_list) {
  10272. var parent = tt.parent();
  10273. if (drop_vars) {
  10274. var sym = assign_as_unused(node);
  10275. if (sym instanceof AST_SymbolRef) {
  10276. var def = sym.definition();
  10277. var in_use = def.id in in_use_ids;
  10278. if (node instanceof AST_Assign) {
  10279. if (!in_use || def.id in fixed_ids && fixed_ids[def.id] !== node) {
  10280. return maintain_this_binding(parent, node, node.right.transform(tt));
  10281. }
  10282. } else if (!in_use) return make_node(AST_Number, node, {
  10283. value: 0
  10284. });
  10285. }
  10286. }
  10287. if (scope !== self) return;
  10288. var def;
  10289. if (node.name
  10290. && (node instanceof AST_ClassExpression
  10291. && !keep_name(compressor.option("keep_classnames"), (def = node.name.definition()).name)
  10292. || node instanceof AST_Function
  10293. && !keep_name(compressor.option("keep_fnames"), (def = node.name.definition()).name))) {
  10294. // any declarations with same name will overshadow
  10295. // name of this anonymous function and can therefore
  10296. // never be used anywhere
  10297. if (!(def.id in in_use_ids) || def.orig.length > 1) node.name = null;
  10298. }
  10299. if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
  10300. var trim = !compressor.option("keep_fargs");
  10301. for (var a = node.argnames, i = a.length; --i >= 0;) {
  10302. var sym = a[i];
  10303. if (sym instanceof AST_Expansion) {
  10304. sym = sym.expression;
  10305. }
  10306. if (sym instanceof AST_DefaultAssign) {
  10307. sym = sym.left;
  10308. }
  10309. // Do not drop destructuring arguments.
  10310. // They constitute a type assertion, so dropping
  10311. // them would stop that TypeError which would happen
  10312. // if someone called it with an incorrectly formatted
  10313. // parameter.
  10314. if (!(sym instanceof AST_Destructuring) && !(sym.definition().id in in_use_ids)) {
  10315. sym.__unused = true;
  10316. if (trim) {
  10317. a.pop();
  10318. compressor[sym.unreferenced() ? "warn" : "info"]("Dropping unused function argument {name} [{file}:{line},{col}]", template(sym));
  10319. }
  10320. } else {
  10321. trim = false;
  10322. }
  10323. }
  10324. }
  10325. if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
  10326. var def = node.name.definition();
  10327. var keep = (def.id in in_use_ids) || !drop_funcs && def.global;
  10328. if (!keep) {
  10329. compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
  10330. def.eliminated++;
  10331. return make_node(AST_EmptyStatement, node);
  10332. }
  10333. }
  10334. if (node instanceof AST_Definitions && !(parent instanceof AST_ForIn && parent.init === node)) {
  10335. var drop_block = !(parent instanceof AST_Toplevel) && !(node instanceof AST_Var);
  10336. // place uninitialized names at the start
  10337. var body = [], head = [], tail = [];
  10338. // for unused names whose initialization has
  10339. // side effects, we can cascade the init. code
  10340. // into the next one, or next statement.
  10341. var side_effects = [];
  10342. node.definitions.forEach(function(def) {
  10343. if (def.value) def.value = def.value.transform(tt);
  10344. var is_destructure = def.name instanceof AST_Destructuring;
  10345. var sym = is_destructure
  10346. ? new SymbolDef(null, { name: "<destructure>" }) /* fake SymbolDef */
  10347. : def.name.definition();
  10348. if (drop_block && sym.global) return tail.push(def);
  10349. if (!(drop_vars || drop_block)
  10350. || is_destructure
  10351. && (def.name.names.length
  10352. || def.name.is_array
  10353. || compressor.option("pure_getters") != true)
  10354. || sym.id in in_use_ids) {
  10355. if (def.value && sym.id in fixed_ids && fixed_ids[sym.id] !== def) {
  10356. def.value = def.value.drop_side_effect_free(compressor);
  10357. }
  10358. if (def.name instanceof AST_SymbolVar) {
  10359. var var_defs = var_defs_by_id.get(sym.id);
  10360. if (var_defs.length > 1 && (!def.value || sym.orig.indexOf(def.name) > sym.eliminated)) {
  10361. compressor.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
  10362. if (def.value) {
  10363. var ref = make_node(AST_SymbolRef, def.name, def.name);
  10364. sym.references.push(ref);
  10365. var assign = make_node(AST_Assign, def, {
  10366. operator: "=",
  10367. left: ref,
  10368. right: def.value
  10369. });
  10370. if (fixed_ids[sym.id] === def) {
  10371. fixed_ids[sym.id] = assign;
  10372. }
  10373. side_effects.push(assign.transform(tt));
  10374. }
  10375. remove(var_defs, def);
  10376. sym.eliminated++;
  10377. return;
  10378. }
  10379. }
  10380. if (def.value) {
  10381. if (side_effects.length > 0) {
  10382. if (tail.length > 0) {
  10383. side_effects.push(def.value);
  10384. def.value = make_sequence(def.value, side_effects);
  10385. } else {
  10386. body.push(make_node(AST_SimpleStatement, node, {
  10387. body: make_sequence(node, side_effects)
  10388. }));
  10389. }
  10390. side_effects = [];
  10391. }
  10392. tail.push(def);
  10393. } else {
  10394. head.push(def);
  10395. }
  10396. } else if (sym.orig[0] instanceof AST_SymbolCatch) {
  10397. var value = def.value && def.value.drop_side_effect_free(compressor);
  10398. if (value) side_effects.push(value);
  10399. def.value = null;
  10400. head.push(def);
  10401. } else {
  10402. var value = def.value && def.value.drop_side_effect_free(compressor);
  10403. if (value) {
  10404. if (!is_destructure) compressor.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name));
  10405. side_effects.push(value);
  10406. } else {
  10407. if (!is_destructure) compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
  10408. }
  10409. sym.eliminated++;
  10410. }
  10411. });
  10412. if (head.length > 0 || tail.length > 0) {
  10413. node.definitions = head.concat(tail);
  10414. body.push(node);
  10415. }
  10416. if (side_effects.length > 0) {
  10417. body.push(make_node(AST_SimpleStatement, node, {
  10418. body: make_sequence(node, side_effects)
  10419. }));
  10420. }
  10421. switch (body.length) {
  10422. case 0:
  10423. return in_list ? MAP.skip : make_node(AST_EmptyStatement, node);
  10424. case 1:
  10425. return body[0];
  10426. default:
  10427. return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
  10428. body: body
  10429. });
  10430. }
  10431. }
  10432. // certain combination of unused name + side effect leads to:
  10433. // https://github.com/mishoo/UglifyJS2/issues/44
  10434. // https://github.com/mishoo/UglifyJS2/issues/1830
  10435. // https://github.com/mishoo/UglifyJS2/issues/1838
  10436. // that's an invalid AST.
  10437. // We fix it at this stage by moving the `var` outside the `for`.
  10438. if (node instanceof AST_For) {
  10439. descend(node, this);
  10440. var block;
  10441. if (node.init instanceof AST_BlockStatement) {
  10442. block = node.init;
  10443. node.init = block.body.pop();
  10444. block.body.push(node);
  10445. }
  10446. if (node.init instanceof AST_SimpleStatement) {
  10447. node.init = node.init.body;
  10448. } else if (is_empty(node.init)) {
  10449. node.init = null;
  10450. }
  10451. return !block ? node : in_list ? MAP.splice(block.body) : block;
  10452. }
  10453. if (node instanceof AST_LabeledStatement && node.body instanceof AST_For) {
  10454. descend(node, this);
  10455. if (node.body instanceof AST_BlockStatement) {
  10456. var block = node.body;
  10457. node.body = block.body.pop();
  10458. block.body.push(node);
  10459. return in_list ? MAP.splice(block.body) : block;
  10460. }
  10461. return node;
  10462. }
  10463. if (node instanceof AST_BlockStatement) {
  10464. descend(node, this);
  10465. if (in_list && all(node.body, can_be_evicted_from_block)) {
  10466. return MAP.splice(node.body);
  10467. }
  10468. return node;
  10469. }
  10470. if (node instanceof AST_Scope) {
  10471. var save_scope = scope;
  10472. scope = node;
  10473. descend(node, this);
  10474. scope = save_scope;
  10475. return node;
  10476. }
  10477. function template(sym) {
  10478. return {
  10479. name : sym.name,
  10480. file : sym.start.file,
  10481. line : sym.start.line,
  10482. col : sym.start.col
  10483. };
  10484. }
  10485. }
  10486. );
  10487. self.transform(tt);
  10488. function scan_ref_scoped(node, descend) {
  10489. var node_def, sym = assign_as_unused(node);
  10490. if (sym instanceof AST_SymbolRef
  10491. && !is_ref_of(node.left, AST_SymbolBlockDeclaration)
  10492. && self.variables.get(sym.name) === (node_def = sym.definition())) {
  10493. if (node instanceof AST_Assign) {
  10494. node.right.walk(tw);
  10495. if (!node_def.chained && node.left.fixed_value() === node.right) {
  10496. fixed_ids[node_def.id] = node;
  10497. }
  10498. }
  10499. return true;
  10500. }
  10501. if (node instanceof AST_SymbolRef) {
  10502. node_def = node.definition();
  10503. if (!(node_def.id in in_use_ids)) {
  10504. in_use_ids[node_def.id] = true;
  10505. in_use.push(node_def);
  10506. if (node_def = node_def.redefined()) {
  10507. in_use_ids[node_def.id] = true;
  10508. in_use.push(node_def);
  10509. }
  10510. }
  10511. return true;
  10512. }
  10513. if (node instanceof AST_Scope) {
  10514. var save_scope = scope;
  10515. scope = node;
  10516. descend();
  10517. scope = save_scope;
  10518. return true;
  10519. }
  10520. }
  10521. });
  10522. AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) {
  10523. var self = this;
  10524. if (compressor.has_directive("use asm")) return self;
  10525. // Hoisting makes no sense in an arrow func
  10526. if (!Array.isArray(self.body)) return self;
  10527. var hoist_funs = compressor.option("hoist_funs");
  10528. var hoist_vars = compressor.option("hoist_vars");
  10529. if (hoist_funs || hoist_vars) {
  10530. var dirs = [];
  10531. var hoisted = [];
  10532. var vars = new Dictionary(), vars_found = 0, var_decl = 0;
  10533. // let's count var_decl first, we seem to waste a lot of
  10534. // space if we hoist `var` when there's only one.
  10535. self.walk(new TreeWalker(function(node) {
  10536. if (node instanceof AST_Scope && node !== self)
  10537. return true;
  10538. if (node instanceof AST_Var) {
  10539. ++var_decl;
  10540. return true;
  10541. }
  10542. }));
  10543. hoist_vars = hoist_vars && var_decl > 1;
  10544. var tt = new TreeTransformer(
  10545. function before(node) {
  10546. if (node !== self) {
  10547. if (node instanceof AST_Directive) {
  10548. dirs.push(node);
  10549. return make_node(AST_EmptyStatement, node);
  10550. }
  10551. if (hoist_funs && node instanceof AST_Defun
  10552. && !(tt.parent() instanceof AST_Export)
  10553. && tt.parent() === self) {
  10554. hoisted.push(node);
  10555. return make_node(AST_EmptyStatement, node);
  10556. }
  10557. if (hoist_vars && node instanceof AST_Var) {
  10558. node.definitions.forEach(function(def) {
  10559. if (def.name instanceof AST_Destructuring) return;
  10560. vars.set(def.name.name, def);
  10561. ++vars_found;
  10562. });
  10563. var seq = node.to_assignments(compressor);
  10564. var p = tt.parent();
  10565. if (p instanceof AST_ForIn && p.init === node) {
  10566. if (seq == null) {
  10567. var def = node.definitions[0].name;
  10568. return make_node(AST_SymbolRef, def, def);
  10569. }
  10570. return seq;
  10571. }
  10572. if (p instanceof AST_For && p.init === node) {
  10573. return seq;
  10574. }
  10575. if (!seq) return make_node(AST_EmptyStatement, node);
  10576. return make_node(AST_SimpleStatement, node, {
  10577. body: seq
  10578. });
  10579. }
  10580. if (node instanceof AST_Scope)
  10581. return node; // to avoid descending in nested scopes
  10582. }
  10583. }
  10584. );
  10585. self = self.transform(tt);
  10586. if (vars_found > 0) {
  10587. // collect only vars which don't show up in self's arguments list
  10588. var defs = [];
  10589. vars.each(function(def, name) {
  10590. if (self instanceof AST_Lambda
  10591. && find_if(function(x) { return x.name == def.name.name; },
  10592. self.args_as_names())) {
  10593. vars.del(name);
  10594. } else {
  10595. def = def.clone();
  10596. def.value = null;
  10597. defs.push(def);
  10598. vars.set(name, def);
  10599. }
  10600. });
  10601. if (defs.length > 0) {
  10602. // try to merge in assignments
  10603. for (var i = 0; i < self.body.length;) {
  10604. if (self.body[i] instanceof AST_SimpleStatement) {
  10605. var expr = self.body[i].body, sym, assign;
  10606. if (expr instanceof AST_Assign
  10607. && expr.operator == "="
  10608. && (sym = expr.left) instanceof AST_Symbol
  10609. && vars.has(sym.name)
  10610. ) {
  10611. var def = vars.get(sym.name);
  10612. if (def.value) break;
  10613. def.value = expr.right;
  10614. remove(defs, def);
  10615. defs.push(def);
  10616. self.body.splice(i, 1);
  10617. continue;
  10618. }
  10619. if (expr instanceof AST_Sequence
  10620. && (assign = expr.expressions[0]) instanceof AST_Assign
  10621. && assign.operator == "="
  10622. && (sym = assign.left) instanceof AST_Symbol
  10623. && vars.has(sym.name)
  10624. ) {
  10625. var def = vars.get(sym.name);
  10626. if (def.value) break;
  10627. def.value = assign.right;
  10628. remove(defs, def);
  10629. defs.push(def);
  10630. self.body[i].body = make_sequence(expr, expr.expressions.slice(1));
  10631. continue;
  10632. }
  10633. }
  10634. if (self.body[i] instanceof AST_EmptyStatement) {
  10635. self.body.splice(i, 1);
  10636. continue;
  10637. }
  10638. if (self.body[i] instanceof AST_BlockStatement) {
  10639. var tmp = [ i, 1 ].concat(self.body[i].body);
  10640. self.body.splice.apply(self.body, tmp);
  10641. continue;
  10642. }
  10643. break;
  10644. }
  10645. defs = make_node(AST_Var, self, {
  10646. definitions: defs
  10647. });
  10648. hoisted.push(defs);
  10649. }
  10650. }
  10651. self.body = dirs.concat(hoisted, self.body);
  10652. }
  10653. return self;
  10654. });
  10655. AST_Scope.DEFMETHOD("var_names", function varNames() {
  10656. var var_names = this._var_names;
  10657. if (!var_names) {
  10658. const isParentScopeAvailable = this.parent_scope && !this.parent_scope instanceof AST_Toplevel;
  10659. this._var_names = var_names = isParentScopeAvailable ? varNames.call(this.parent_scope) : Object.create(null);
  10660. this.enclosed.forEach(function(def) {
  10661. var_names[def.name] = true;
  10662. });
  10663. this.variables.each(function(def, name) {
  10664. var_names[name] = true;
  10665. });
  10666. }
  10667. return var_names;
  10668. });
  10669. AST_Scope.DEFMETHOD("make_var_name", function(prefix) {
  10670. var var_names = this.var_names();
  10671. prefix = prefix.replace(/(?:^[^a-z_$]|[^a-z0-9_$])/ig, "_");
  10672. var name = prefix;
  10673. for (var i = 0; var_names[name]; i++) name = prefix + "$" + i;
  10674. var_names[name] = true;
  10675. return name;
  10676. });
  10677. AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
  10678. var self = this;
  10679. if (!compressor.option("hoist_props") || compressor.has_directive("use asm")) return self;
  10680. var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false;
  10681. var defs_by_id = Object.create(null);
  10682. var tt = new TreeTransformer(function(node, descend) {
  10683. if (node instanceof AST_Definitions && tt.parent() instanceof AST_Export) return node;
  10684. if (node instanceof AST_VarDef) {
  10685. var sym = node.name, def, value;
  10686. if (sym.scope === self
  10687. && (def = sym.definition()).escaped != 1
  10688. && !def.assignments
  10689. && !def.direct_access
  10690. && !def.single_use
  10691. && !compressor.exposed(def)
  10692. && !top_retain(def)
  10693. && (value = sym.fixed_value()) === node.value
  10694. && value instanceof AST_Object) {
  10695. descend(node, this);
  10696. var defs = new Dictionary();
  10697. var assignments = [];
  10698. value.properties.forEach(function(prop) {
  10699. assignments.push(make_node(AST_VarDef, node, {
  10700. name: make_sym(prop.key),
  10701. value: prop.value
  10702. }));
  10703. });
  10704. defs_by_id[def.id] = defs;
  10705. return MAP.splice(assignments);
  10706. }
  10707. }
  10708. if (node instanceof AST_PropAccess && node.expression instanceof AST_SymbolRef) {
  10709. var defs = defs_by_id[node.expression.definition().id];
  10710. if (defs) {
  10711. var def = defs.get(get_value(node.property));
  10712. var sym = make_node(AST_SymbolRef, node, {
  10713. name: def.name,
  10714. scope: node.expression.scope,
  10715. thedef: def
  10716. });
  10717. sym.reference({});
  10718. return sym;
  10719. }
  10720. }
  10721. function make_sym(key) {
  10722. var new_var = make_node(sym.CTOR, sym, {
  10723. name: self.make_var_name(sym.name + "_" + key),
  10724. scope: self
  10725. });
  10726. var def = self.def_variable(new_var);
  10727. defs.set(key, def);
  10728. self.enclosed.push(def);
  10729. return new_var;
  10730. }
  10731. });
  10732. return self.transform(tt);
  10733. });
  10734. // drop_side_effect_free()
  10735. // remove side-effect-free parts which only affects return value
  10736. (function(def_drop_side_effect_free) {
  10737. // Drop side-effect-free elements from an array of expressions.
  10738. // Returns an array of expressions with side-effects or null
  10739. // if all elements were dropped. Note: original array may be
  10740. // returned if nothing changed.
  10741. function trim(nodes, compressor, first_in_statement$$1) {
  10742. var len = nodes.length;
  10743. if (!len) return null;
  10744. var ret = [], changed = false;
  10745. for (var i = 0; i < len; i++) {
  10746. var node = nodes[i].drop_side_effect_free(compressor, first_in_statement$$1);
  10747. changed |= node !== nodes[i];
  10748. if (node) {
  10749. ret.push(node);
  10750. first_in_statement$$1 = false;
  10751. }
  10752. }
  10753. return changed ? ret.length ? ret : null : nodes;
  10754. }
  10755. def_drop_side_effect_free(AST_Node, return_this);
  10756. def_drop_side_effect_free(AST_Constant, return_null);
  10757. def_drop_side_effect_free(AST_This, return_null);
  10758. def_drop_side_effect_free(AST_Call, function(compressor, first_in_statement$$1) {
  10759. if (!this.is_expr_pure(compressor)) {
  10760. if (this.expression.is_call_pure(compressor)) {
  10761. var exprs = this.args.slice();
  10762. exprs.unshift(this.expression.expression);
  10763. exprs = trim(exprs, compressor, first_in_statement$$1);
  10764. return exprs && make_sequence(this, exprs);
  10765. }
  10766. if (is_func_expr(this.expression)
  10767. && (!this.expression.name || !this.expression.name.definition().references.length)) {
  10768. var node = this.clone();
  10769. node.expression.process_expression(false, compressor);
  10770. return node;
  10771. }
  10772. return this;
  10773. }
  10774. if (this.pure) {
  10775. compressor.warn("Dropping __PURE__ call [{file}:{line},{col}]", this.start);
  10776. }
  10777. var args = trim(this.args, compressor, first_in_statement$$1);
  10778. return args && make_sequence(this, args);
  10779. });
  10780. def_drop_side_effect_free(AST_Accessor, return_null);
  10781. def_drop_side_effect_free(AST_Function, return_null);
  10782. def_drop_side_effect_free(AST_Arrow, return_null);
  10783. def_drop_side_effect_free(AST_ClassExpression, return_null);
  10784. def_drop_side_effect_free(AST_Binary, function(compressor, first_in_statement$$1) {
  10785. var right = this.right.drop_side_effect_free(compressor);
  10786. if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement$$1);
  10787. if (lazy_op(this.operator)) {
  10788. if (right === this.right) return this;
  10789. var node = this.clone();
  10790. node.right = right;
  10791. return node;
  10792. } else {
  10793. var left = this.left.drop_side_effect_free(compressor, first_in_statement$$1);
  10794. if (!left) return this.right.drop_side_effect_free(compressor, first_in_statement$$1);
  10795. return make_sequence(this, [ left, right ]);
  10796. }
  10797. });
  10798. def_drop_side_effect_free(AST_Assign, function(compressor) {
  10799. var left = this.left;
  10800. if (left.has_side_effects(compressor)
  10801. || compressor.has_directive("use strict")
  10802. && left instanceof AST_PropAccess
  10803. && left.expression.is_constant()) {
  10804. return this;
  10805. }
  10806. this.write_only = true;
  10807. while (left instanceof AST_PropAccess) {
  10808. left = left.expression;
  10809. }
  10810. if (left.is_constant_expression(compressor.find_parent(AST_Scope))) {
  10811. return this.right.drop_side_effect_free(compressor);
  10812. }
  10813. return this;
  10814. });
  10815. def_drop_side_effect_free(AST_Conditional, function(compressor) {
  10816. var consequent = this.consequent.drop_side_effect_free(compressor);
  10817. var alternative = this.alternative.drop_side_effect_free(compressor);
  10818. if (consequent === this.consequent && alternative === this.alternative) return this;
  10819. if (!consequent) return alternative ? make_node(AST_Binary, this, {
  10820. operator: "||",
  10821. left: this.condition,
  10822. right: alternative
  10823. }) : this.condition.drop_side_effect_free(compressor);
  10824. if (!alternative) return make_node(AST_Binary, this, {
  10825. operator: "&&",
  10826. left: this.condition,
  10827. right: consequent
  10828. });
  10829. var node = this.clone();
  10830. node.consequent = consequent;
  10831. node.alternative = alternative;
  10832. return node;
  10833. });
  10834. def_drop_side_effect_free(AST_Unary, function(compressor, first_in_statement$$1) {
  10835. if (unary_side_effects(this.operator)) {
  10836. this.write_only = !this.expression.has_side_effects(compressor);
  10837. return this;
  10838. }
  10839. if (this.operator == "typeof" && this.expression instanceof AST_SymbolRef) return null;
  10840. var expression = this.expression.drop_side_effect_free(compressor, first_in_statement$$1);
  10841. if (first_in_statement$$1 && expression && is_iife_call(expression)) {
  10842. if (expression === this.expression && this.operator == "!") return this;
  10843. return expression.negate(compressor, first_in_statement$$1);
  10844. }
  10845. return expression;
  10846. });
  10847. def_drop_side_effect_free(AST_SymbolRef, function(compressor) {
  10848. return this.is_declared(compressor) ? null : this;
  10849. });
  10850. def_drop_side_effect_free(AST_Object, function(compressor, first_in_statement$$1) {
  10851. var values = trim(this.properties, compressor, first_in_statement$$1);
  10852. return values && make_sequence(this, values);
  10853. });
  10854. def_drop_side_effect_free(AST_ObjectProperty, function(compressor, first_in_statement$$1) {
  10855. return this.value.drop_side_effect_free(compressor, first_in_statement$$1);
  10856. });
  10857. def_drop_side_effect_free(AST_Array, function(compressor, first_in_statement$$1) {
  10858. var values = trim(this.elements, compressor, first_in_statement$$1);
  10859. return values && make_sequence(this, values);
  10860. });
  10861. def_drop_side_effect_free(AST_Dot, function(compressor, first_in_statement$$1) {
  10862. if (this.expression.may_throw_on_access(compressor)) return this;
  10863. return this.expression.drop_side_effect_free(compressor, first_in_statement$$1);
  10864. });
  10865. def_drop_side_effect_free(AST_Sub, function(compressor, first_in_statement$$1) {
  10866. if (this.expression.may_throw_on_access(compressor)) return this;
  10867. var expression = this.expression.drop_side_effect_free(compressor, first_in_statement$$1);
  10868. if (!expression) return this.property.drop_side_effect_free(compressor, first_in_statement$$1);
  10869. var property = this.property.drop_side_effect_free(compressor);
  10870. if (!property) return expression;
  10871. return make_sequence(this, [ expression, property ]);
  10872. });
  10873. def_drop_side_effect_free(AST_Sequence, function(compressor) {
  10874. var last = this.tail_node();
  10875. var expr = last.drop_side_effect_free(compressor);
  10876. if (expr === last) return this;
  10877. var expressions = this.expressions.slice(0, -1);
  10878. if (expr) expressions.push(expr);
  10879. return make_sequence(this, expressions);
  10880. });
  10881. def_drop_side_effect_free(AST_Expansion, function(compressor, first_in_statement$$1) {
  10882. return this.expression.drop_side_effect_free(compressor, first_in_statement$$1);
  10883. });
  10884. def_drop_side_effect_free(AST_TemplateSegment, return_null);
  10885. def_drop_side_effect_free(AST_TemplateString, function(compressor) {
  10886. var values = trim(this.segments, compressor, first_in_statement);
  10887. return values && make_sequence(this, values);
  10888. });
  10889. })(function(node, func) {
  10890. node.DEFMETHOD("drop_side_effect_free", func);
  10891. });
  10892. var pure_prop_access_globals = [
  10893. "Number",
  10894. "String",
  10895. "Array",
  10896. "Object",
  10897. "Function",
  10898. "Promise",
  10899. "global",
  10900. "window",
  10901. "document",
  10902. "location"
  10903. ];
  10904. def_optimize(AST_SimpleStatement, function(self, compressor) {
  10905. if (self.body instanceof AST_SymbolRef && pure_prop_access_globals.indexOf(self.body.name) !== -1) {
  10906. return make_node(AST_EmptyStatement, self);
  10907. }
  10908. if (compressor.option("side_effects")) {
  10909. var body = self.body;
  10910. var node = body.drop_side_effect_free(compressor, true);
  10911. if (!node) {
  10912. compressor.warn("Dropping side-effect-free statement [{file}:{line},{col}]", self.start);
  10913. return make_node(AST_EmptyStatement, self);
  10914. }
  10915. if (node !== body) {
  10916. return make_node(AST_SimpleStatement, self, { body: node });
  10917. }
  10918. }
  10919. return self;
  10920. });
  10921. def_optimize(AST_While, function(self, compressor) {
  10922. return compressor.option("loops") ? make_node(AST_For, self, self).optimize(compressor) : self;
  10923. });
  10924. function has_break_or_continue(loop, parent) {
  10925. var found = false;
  10926. var tw = new TreeWalker(function(node) {
  10927. if (found || node instanceof AST_Scope) return true;
  10928. if (node instanceof AST_LoopControl && tw.loopcontrol_target(node) === loop) {
  10929. return found = true;
  10930. }
  10931. });
  10932. if (parent instanceof AST_LabeledStatement) tw.push(parent);
  10933. tw.push(loop);
  10934. loop.body.walk(tw);
  10935. return found;
  10936. }
  10937. def_optimize(AST_Do, function(self, compressor) {
  10938. if (!compressor.option("loops")) return self;
  10939. var cond = self.condition.tail_node().evaluate(compressor);
  10940. if (!(cond instanceof AST_Node)) {
  10941. if (cond) return make_node(AST_For, self, {
  10942. body: make_node(AST_BlockStatement, self.body, {
  10943. body: [
  10944. self.body,
  10945. make_node(AST_SimpleStatement, self.condition, {
  10946. body: self.condition
  10947. })
  10948. ]
  10949. })
  10950. }).optimize(compressor);
  10951. if (!has_break_or_continue(self, compressor.parent())) {
  10952. return make_node(AST_BlockStatement, self.body, {
  10953. body: [
  10954. self.body,
  10955. make_node(AST_SimpleStatement, self.condition, {
  10956. body: self.condition
  10957. })
  10958. ]
  10959. }).optimize(compressor);
  10960. }
  10961. }
  10962. return self;
  10963. });
  10964. function if_break_in_loop(self, compressor) {
  10965. var first = self.body instanceof AST_BlockStatement ? self.body.body[0] : self.body;
  10966. if (compressor.option("dead_code") && is_break(first)) {
  10967. var body = [];
  10968. if (self.init instanceof AST_Statement) {
  10969. body.push(self.init);
  10970. } else if (self.init) {
  10971. body.push(make_node(AST_SimpleStatement, self.init, {
  10972. body: self.init
  10973. }));
  10974. }
  10975. if (self.condition) {
  10976. body.push(make_node(AST_SimpleStatement, self.condition, {
  10977. body: self.condition
  10978. }));
  10979. }
  10980. extract_declarations_from_unreachable_code(compressor, self.body, body);
  10981. return make_node(AST_BlockStatement, self, {
  10982. body: body
  10983. });
  10984. }
  10985. if (first instanceof AST_If) {
  10986. if (is_break(first.body)) {
  10987. if (self.condition) {
  10988. self.condition = make_node(AST_Binary, self.condition, {
  10989. left: self.condition,
  10990. operator: "&&",
  10991. right: first.condition.negate(compressor),
  10992. });
  10993. } else {
  10994. self.condition = first.condition.negate(compressor);
  10995. }
  10996. drop_it(first.alternative);
  10997. } else if (is_break(first.alternative)) {
  10998. if (self.condition) {
  10999. self.condition = make_node(AST_Binary, self.condition, {
  11000. left: self.condition,
  11001. operator: "&&",
  11002. right: first.condition,
  11003. });
  11004. } else {
  11005. self.condition = first.condition;
  11006. }
  11007. drop_it(first.body);
  11008. }
  11009. }
  11010. return self;
  11011. function is_break(node) {
  11012. return node instanceof AST_Break
  11013. && compressor.loopcontrol_target(node) === compressor.self();
  11014. }
  11015. function drop_it(rest) {
  11016. rest = as_statement_array(rest);
  11017. if (self.body instanceof AST_BlockStatement) {
  11018. self.body = self.body.clone();
  11019. self.body.body = rest.concat(self.body.body.slice(1));
  11020. self.body = self.body.transform(compressor);
  11021. } else {
  11022. self.body = make_node(AST_BlockStatement, self.body, {
  11023. body: rest
  11024. }).transform(compressor);
  11025. }
  11026. self = if_break_in_loop(self, compressor);
  11027. }
  11028. }
  11029. def_optimize(AST_For, function(self, compressor) {
  11030. if (!compressor.option("loops")) return self;
  11031. if (compressor.option("side_effects") && self.init) {
  11032. self.init = self.init.drop_side_effect_free(compressor);
  11033. }
  11034. if (self.condition) {
  11035. var cond = self.condition.evaluate(compressor);
  11036. if (!(cond instanceof AST_Node)) {
  11037. if (cond) self.condition = null;
  11038. else if (!compressor.option("dead_code")) {
  11039. var orig = self.condition;
  11040. self.condition = make_node_from_constant(cond, self.condition);
  11041. self.condition = best_of_expression(self.condition.transform(compressor), orig);
  11042. }
  11043. }
  11044. if (compressor.option("dead_code")) {
  11045. if (cond instanceof AST_Node) cond = self.condition.tail_node().evaluate(compressor);
  11046. if (!cond) {
  11047. var body = [];
  11048. extract_declarations_from_unreachable_code(compressor, self.body, body);
  11049. if (self.init instanceof AST_Statement) {
  11050. body.push(self.init);
  11051. } else if (self.init) {
  11052. body.push(make_node(AST_SimpleStatement, self.init, {
  11053. body: self.init
  11054. }));
  11055. }
  11056. body.push(make_node(AST_SimpleStatement, self.condition, {
  11057. body: self.condition
  11058. }));
  11059. return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor);
  11060. }
  11061. }
  11062. }
  11063. return if_break_in_loop(self, compressor);
  11064. });
  11065. def_optimize(AST_If, function(self, compressor) {
  11066. if (is_empty(self.alternative)) self.alternative = null;
  11067. if (!compressor.option("conditionals")) return self;
  11068. // if condition can be statically determined, warn and drop
  11069. // one of the blocks. note, statically determined implies
  11070. // “has no side effects”; also it doesn't work for cases like
  11071. // `x && true`, though it probably should.
  11072. var cond = self.condition.evaluate(compressor);
  11073. if (!compressor.option("dead_code") && !(cond instanceof AST_Node)) {
  11074. var orig = self.condition;
  11075. self.condition = make_node_from_constant(cond, orig);
  11076. self.condition = best_of_expression(self.condition.transform(compressor), orig);
  11077. }
  11078. if (compressor.option("dead_code")) {
  11079. if (cond instanceof AST_Node) cond = self.condition.tail_node().evaluate(compressor);
  11080. if (!cond) {
  11081. compressor.warn("Condition always false [{file}:{line},{col}]", self.condition.start);
  11082. var body = [];
  11083. extract_declarations_from_unreachable_code(compressor, self.body, body);
  11084. body.push(make_node(AST_SimpleStatement, self.condition, {
  11085. body: self.condition
  11086. }));
  11087. if (self.alternative) body.push(self.alternative);
  11088. return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor);
  11089. } else if (!(cond instanceof AST_Node)) {
  11090. compressor.warn("Condition always true [{file}:{line},{col}]", self.condition.start);
  11091. var body = [];
  11092. if (self.alternative) {
  11093. extract_declarations_from_unreachable_code(compressor, self.alternative, body);
  11094. }
  11095. body.push(make_node(AST_SimpleStatement, self.condition, {
  11096. body: self.condition
  11097. }));
  11098. body.push(self.body);
  11099. return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor);
  11100. }
  11101. }
  11102. var negated = self.condition.negate(compressor);
  11103. var self_condition_length = self.condition.print_to_string().length;
  11104. var negated_length = negated.print_to_string().length;
  11105. var negated_is_best = negated_length < self_condition_length;
  11106. if (self.alternative && negated_is_best) {
  11107. negated_is_best = false; // because we already do the switch here.
  11108. // no need to swap values of self_condition_length and negated_length
  11109. // here because they are only used in an equality comparison later on.
  11110. self.condition = negated;
  11111. var tmp = self.body;
  11112. self.body = self.alternative || make_node(AST_EmptyStatement, self);
  11113. self.alternative = tmp;
  11114. }
  11115. if (is_empty(self.body) && is_empty(self.alternative)) {
  11116. return make_node(AST_SimpleStatement, self.condition, {
  11117. body: self.condition.clone()
  11118. }).optimize(compressor);
  11119. }
  11120. if (self.body instanceof AST_SimpleStatement
  11121. && self.alternative instanceof AST_SimpleStatement) {
  11122. return make_node(AST_SimpleStatement, self, {
  11123. body: make_node(AST_Conditional, self, {
  11124. condition : self.condition,
  11125. consequent : self.body.body,
  11126. alternative : self.alternative.body
  11127. })
  11128. }).optimize(compressor);
  11129. }
  11130. if (is_empty(self.alternative) && self.body instanceof AST_SimpleStatement) {
  11131. if (self_condition_length === negated_length && !negated_is_best
  11132. && self.condition instanceof AST_Binary && self.condition.operator == "||") {
  11133. // although the code length of self.condition and negated are the same,
  11134. // negated does not require additional surrounding parentheses.
  11135. // see https://github.com/mishoo/UglifyJS2/issues/979
  11136. negated_is_best = true;
  11137. }
  11138. if (negated_is_best) return make_node(AST_SimpleStatement, self, {
  11139. body: make_node(AST_Binary, self, {
  11140. operator : "||",
  11141. left : negated,
  11142. right : self.body.body
  11143. })
  11144. }).optimize(compressor);
  11145. return make_node(AST_SimpleStatement, self, {
  11146. body: make_node(AST_Binary, self, {
  11147. operator : "&&",
  11148. left : self.condition,
  11149. right : self.body.body
  11150. })
  11151. }).optimize(compressor);
  11152. }
  11153. if (self.body instanceof AST_EmptyStatement
  11154. && self.alternative instanceof AST_SimpleStatement) {
  11155. return make_node(AST_SimpleStatement, self, {
  11156. body: make_node(AST_Binary, self, {
  11157. operator : "||",
  11158. left : self.condition,
  11159. right : self.alternative.body
  11160. })
  11161. }).optimize(compressor);
  11162. }
  11163. if (self.body instanceof AST_Exit
  11164. && self.alternative instanceof AST_Exit
  11165. && self.body.TYPE == self.alternative.TYPE) {
  11166. return make_node(self.body.CTOR, self, {
  11167. value: make_node(AST_Conditional, self, {
  11168. condition : self.condition,
  11169. consequent : self.body.value || make_node(AST_Undefined, self.body),
  11170. alternative : self.alternative.value || make_node(AST_Undefined, self.alternative)
  11171. }).transform(compressor)
  11172. }).optimize(compressor);
  11173. }
  11174. if (self.body instanceof AST_If
  11175. && !self.body.alternative
  11176. && !self.alternative) {
  11177. self = make_node(AST_If, self, {
  11178. condition: make_node(AST_Binary, self.condition, {
  11179. operator: "&&",
  11180. left: self.condition,
  11181. right: self.body.condition
  11182. }),
  11183. body: self.body.body,
  11184. alternative: null
  11185. });
  11186. }
  11187. if (aborts(self.body)) {
  11188. if (self.alternative) {
  11189. var alt = self.alternative;
  11190. self.alternative = null;
  11191. return make_node(AST_BlockStatement, self, {
  11192. body: [ self, alt ]
  11193. }).optimize(compressor);
  11194. }
  11195. }
  11196. if (aborts(self.alternative)) {
  11197. var body = self.body;
  11198. self.body = self.alternative;
  11199. self.condition = negated_is_best ? negated : self.condition.negate(compressor);
  11200. self.alternative = null;
  11201. return make_node(AST_BlockStatement, self, {
  11202. body: [ self, body ]
  11203. }).optimize(compressor);
  11204. }
  11205. return self;
  11206. });
  11207. def_optimize(AST_Switch, function(self, compressor) {
  11208. if (!compressor.option("switches")) return self;
  11209. var branch;
  11210. var value = self.expression.evaluate(compressor);
  11211. if (!(value instanceof AST_Node)) {
  11212. var orig = self.expression;
  11213. self.expression = make_node_from_constant(value, orig);
  11214. self.expression = best_of_expression(self.expression.transform(compressor), orig);
  11215. }
  11216. if (!compressor.option("dead_code")) return self;
  11217. if (value instanceof AST_Node) {
  11218. value = self.expression.tail_node().evaluate(compressor);
  11219. }
  11220. var decl = [];
  11221. var body = [];
  11222. var default_branch;
  11223. var exact_match;
  11224. for (var i = 0, len = self.body.length; i < len && !exact_match; i++) {
  11225. branch = self.body[i];
  11226. if (branch instanceof AST_Default) {
  11227. if (!default_branch) {
  11228. default_branch = branch;
  11229. } else {
  11230. eliminate_branch(branch, body[body.length - 1]);
  11231. }
  11232. } else if (!(value instanceof AST_Node)) {
  11233. var exp = branch.expression.evaluate(compressor);
  11234. if (!(exp instanceof AST_Node) && exp !== value) {
  11235. eliminate_branch(branch, body[body.length - 1]);
  11236. continue;
  11237. }
  11238. if (exp instanceof AST_Node) exp = branch.expression.tail_node().evaluate(compressor);
  11239. if (exp === value) {
  11240. exact_match = branch;
  11241. if (default_branch) {
  11242. var default_index = body.indexOf(default_branch);
  11243. body.splice(default_index, 1);
  11244. eliminate_branch(default_branch, body[default_index - 1]);
  11245. default_branch = null;
  11246. }
  11247. }
  11248. }
  11249. if (aborts(branch)) {
  11250. var prev = body[body.length - 1];
  11251. if (aborts(prev) && prev.body.length == branch.body.length
  11252. && make_node(AST_BlockStatement, prev, prev).equivalent_to(make_node(AST_BlockStatement, branch, branch))) {
  11253. prev.body = [];
  11254. }
  11255. }
  11256. body.push(branch);
  11257. }
  11258. while (i < len) eliminate_branch(self.body[i++], body[body.length - 1]);
  11259. if (body.length > 0) {
  11260. body[0].body = decl.concat(body[0].body);
  11261. }
  11262. self.body = body;
  11263. while (branch = body[body.length - 1]) {
  11264. var stat = branch.body[branch.body.length - 1];
  11265. if (stat instanceof AST_Break && compressor.loopcontrol_target(stat) === self)
  11266. branch.body.pop();
  11267. if (branch.body.length || branch instanceof AST_Case
  11268. && (default_branch || branch.expression.has_side_effects(compressor))) break;
  11269. if (body.pop() === default_branch) default_branch = null;
  11270. }
  11271. if (body.length == 0) {
  11272. return make_node(AST_BlockStatement, self, {
  11273. body: decl.concat(make_node(AST_SimpleStatement, self.expression, {
  11274. body: self.expression
  11275. }))
  11276. }).optimize(compressor);
  11277. }
  11278. if (body.length == 1 && (body[0] === exact_match || body[0] === default_branch)) {
  11279. var has_break = false;
  11280. var tw = new TreeWalker(function(node) {
  11281. if (has_break
  11282. || node instanceof AST_Lambda
  11283. || node instanceof AST_SimpleStatement) return true;
  11284. if (node instanceof AST_Break && tw.loopcontrol_target(node) === self)
  11285. has_break = true;
  11286. });
  11287. self.walk(tw);
  11288. if (!has_break) {
  11289. var statements = body[0].body.slice();
  11290. var exp = body[0].expression;
  11291. if (exp) statements.unshift(make_node(AST_SimpleStatement, exp, {
  11292. body: exp
  11293. }));
  11294. statements.unshift(make_node(AST_SimpleStatement, self.expression, {
  11295. body:self.expression
  11296. }));
  11297. return make_node(AST_BlockStatement, self, {
  11298. body: statements
  11299. }).optimize(compressor);
  11300. }
  11301. }
  11302. return self;
  11303. function eliminate_branch(branch, prev) {
  11304. if (prev && !aborts(prev)) {
  11305. prev.body = prev.body.concat(branch.body);
  11306. } else {
  11307. extract_declarations_from_unreachable_code(compressor, branch, decl);
  11308. }
  11309. }
  11310. });
  11311. def_optimize(AST_Try, function(self, compressor) {
  11312. tighten_body(self.body, compressor);
  11313. if (self.bcatch && self.bfinally && all(self.bfinally.body, is_empty)) self.bfinally = null;
  11314. if (compressor.option("dead_code") && all(self.body, is_empty)) {
  11315. var body = [];
  11316. if (self.bcatch) {
  11317. extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
  11318. body.forEach(function(stat) {
  11319. if (!(stat instanceof AST_Definitions)) return;
  11320. stat.definitions.forEach(function(var_def) {
  11321. var def = var_def.name.definition().redefined();
  11322. if (!def) return;
  11323. var_def.name = var_def.name.clone();
  11324. var_def.name.thedef = def;
  11325. });
  11326. });
  11327. }
  11328. if (self.bfinally) body = body.concat(self.bfinally.body);
  11329. return make_node(AST_BlockStatement, self, {
  11330. body: body
  11331. }).optimize(compressor);
  11332. }
  11333. return self;
  11334. });
  11335. AST_Definitions.DEFMETHOD("remove_initializers", function() {
  11336. var decls = [];
  11337. this.definitions.forEach(function(def) {
  11338. if (def.name instanceof AST_SymbolDeclaration) {
  11339. def.value = null;
  11340. decls.push(def);
  11341. } else def.name.walk(new TreeWalker(function(node) {
  11342. if (node instanceof AST_SymbolDeclaration) {
  11343. decls.push(make_node(AST_VarDef, def, {
  11344. name: node,
  11345. value: null
  11346. }));
  11347. }
  11348. }));
  11349. });
  11350. this.definitions = decls;
  11351. });
  11352. AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
  11353. var reduce_vars = compressor.option("reduce_vars");
  11354. var assignments = this.definitions.reduce(function(a, def) {
  11355. if (def.value && !(def.name instanceof AST_Destructuring)) {
  11356. var name = make_node(AST_SymbolRef, def.name, def.name);
  11357. a.push(make_node(AST_Assign, def, {
  11358. operator : "=",
  11359. left : name,
  11360. right : def.value
  11361. }));
  11362. if (reduce_vars) name.definition().fixed = false;
  11363. } else if (def.value) {
  11364. // Because it's a destructuring, do not turn into an assignment.
  11365. var varDef = make_node(AST_VarDef, def, {
  11366. name: def.name,
  11367. value: def.value
  11368. });
  11369. var var_ = make_node(AST_Var, def, {
  11370. definitions: [ varDef ]
  11371. });
  11372. a.push(var_);
  11373. }
  11374. def = def.name.definition();
  11375. def.eliminated++;
  11376. def.replaced--;
  11377. return a;
  11378. }, []);
  11379. if (assignments.length == 0) return null;
  11380. return make_sequence(this, assignments);
  11381. });
  11382. def_optimize(AST_Definitions, function(self, compressor) {
  11383. if (self.definitions.length == 0)
  11384. return make_node(AST_EmptyStatement, self);
  11385. return self;
  11386. });
  11387. def_optimize(AST_Import, function(self, compressor) {
  11388. return self;
  11389. });
  11390. function retain_top_func(fn, compressor) {
  11391. return compressor.top_retain
  11392. && fn instanceof AST_Defun
  11393. && fn._top
  11394. && fn.name
  11395. && compressor.top_retain(fn.name);
  11396. }
  11397. def_optimize(AST_Call, function(self, compressor) {
  11398. var exp = self.expression;
  11399. var fn = exp;
  11400. inline_array_like_spread(self, compressor, self.args);
  11401. var simple_args = all(self.args, function(arg) {
  11402. return !(arg instanceof AST_Expansion);
  11403. });
  11404. if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef) {
  11405. fn = fn.fixed_value();
  11406. if (retain_top_func(fn, compressor)) fn = exp;
  11407. }
  11408. var is_func = fn instanceof AST_Lambda;
  11409. if (compressor.option("unused")
  11410. && simple_args
  11411. && is_func
  11412. && !fn.uses_arguments
  11413. && !fn.pinned()) {
  11414. var pos = 0, last = 0;
  11415. for (var i = 0, len = self.args.length; i < len; i++) {
  11416. if (fn.argnames[i] instanceof AST_Expansion) {
  11417. if (fn.argnames[i].expression.__unused) while (i < len) {
  11418. var node = self.args[i++].drop_side_effect_free(compressor);
  11419. if (node) {
  11420. self.args[pos++] = node;
  11421. }
  11422. } else while (i < len) {
  11423. self.args[pos++] = self.args[i++];
  11424. }
  11425. last = pos;
  11426. break;
  11427. }
  11428. var trim = i >= fn.argnames.length;
  11429. if (trim || fn.argnames[i].__unused) {
  11430. var node = self.args[i].drop_side_effect_free(compressor);
  11431. if (node) {
  11432. self.args[pos++] = node;
  11433. } else if (!trim) {
  11434. self.args[pos++] = make_node(AST_Number, self.args[i], {
  11435. value: 0
  11436. });
  11437. continue;
  11438. }
  11439. } else {
  11440. self.args[pos++] = self.args[i];
  11441. }
  11442. last = pos;
  11443. }
  11444. self.args.length = last;
  11445. }
  11446. if (compressor.option("unsafe")) {
  11447. if (is_undeclared_ref(exp)) switch (exp.name) {
  11448. case "Array":
  11449. if (self.args.length != 1) {
  11450. return make_node(AST_Array, self, {
  11451. elements: self.args
  11452. }).optimize(compressor);
  11453. }
  11454. break;
  11455. case "Object":
  11456. if (self.args.length == 0) {
  11457. return make_node(AST_Object, self, {
  11458. properties: []
  11459. });
  11460. }
  11461. break;
  11462. case "String":
  11463. if (self.args.length == 0) return make_node(AST_String, self, {
  11464. value: ""
  11465. });
  11466. if (self.args.length <= 1) return make_node(AST_Binary, self, {
  11467. left: self.args[0],
  11468. operator: "+",
  11469. right: make_node(AST_String, self, { value: "" })
  11470. }).optimize(compressor);
  11471. break;
  11472. case "Number":
  11473. if (self.args.length == 0) return make_node(AST_Number, self, {
  11474. value: 0
  11475. });
  11476. if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
  11477. expression: self.args[0],
  11478. operator: "+"
  11479. }).optimize(compressor);
  11480. case "Boolean":
  11481. if (self.args.length == 0) return make_node(AST_False, self);
  11482. if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
  11483. expression: make_node(AST_UnaryPrefix, self, {
  11484. expression: self.args[0],
  11485. operator: "!"
  11486. }),
  11487. operator: "!"
  11488. }).optimize(compressor);
  11489. break;
  11490. case "RegExp":
  11491. var params = [];
  11492. if (all(self.args, function(arg) {
  11493. var value = arg.evaluate(compressor);
  11494. params.unshift(value);
  11495. return arg !== value;
  11496. })) {
  11497. try {
  11498. return best_of(compressor, self, make_node(AST_RegExp, self, {
  11499. value: RegExp.apply(RegExp, params),
  11500. }));
  11501. } catch (ex) {
  11502. compressor.warn("Error converting {expr} [{file}:{line},{col}]", {
  11503. expr: self.print_to_string(),
  11504. file: self.start.file,
  11505. line: self.start.line,
  11506. col: self.start.col
  11507. });
  11508. }
  11509. }
  11510. break;
  11511. } else if (exp instanceof AST_Dot) switch(exp.property) {
  11512. case "toString":
  11513. if (self.args.length == 0 && !exp.expression.may_throw_on_access(compressor)) {
  11514. return make_node(AST_Binary, self, {
  11515. left: make_node(AST_String, self, { value: "" }),
  11516. operator: "+",
  11517. right: exp.expression
  11518. }).optimize(compressor);
  11519. }
  11520. break;
  11521. case "join":
  11522. if (exp.expression instanceof AST_Array) EXIT: {
  11523. var separator;
  11524. if (self.args.length > 0) {
  11525. separator = self.args[0].evaluate(compressor);
  11526. if (separator === self.args[0]) break EXIT; // not a constant
  11527. }
  11528. var elements = [];
  11529. var consts = [];
  11530. for (var i = 0, len = exp.expression.elements.length; i < len; i++) {
  11531. var el = exp.expression.elements[i];
  11532. if (el instanceof AST_Expansion) break EXIT;
  11533. var value = el.evaluate(compressor);
  11534. if (value !== el) {
  11535. consts.push(value);
  11536. } else {
  11537. if (consts.length > 0) {
  11538. elements.push(make_node(AST_String, self, {
  11539. value: consts.join(separator)
  11540. }));
  11541. consts.length = 0;
  11542. }
  11543. elements.push(el);
  11544. }
  11545. }
  11546. if (consts.length > 0) {
  11547. elements.push(make_node(AST_String, self, {
  11548. value: consts.join(separator)
  11549. }));
  11550. }
  11551. if (elements.length == 0) return make_node(AST_String, self, { value: "" });
  11552. if (elements.length == 1) {
  11553. if (elements[0].is_string(compressor)) {
  11554. return elements[0];
  11555. }
  11556. return make_node(AST_Binary, elements[0], {
  11557. operator : "+",
  11558. left : make_node(AST_String, self, { value: "" }),
  11559. right : elements[0]
  11560. });
  11561. }
  11562. if (separator == "") {
  11563. var first;
  11564. if (elements[0].is_string(compressor)
  11565. || elements[1].is_string(compressor)) {
  11566. first = elements.shift();
  11567. } else {
  11568. first = make_node(AST_String, self, { value: "" });
  11569. }
  11570. return elements.reduce(function(prev, el) {
  11571. return make_node(AST_Binary, el, {
  11572. operator : "+",
  11573. left : prev,
  11574. right : el
  11575. });
  11576. }, first).optimize(compressor);
  11577. }
  11578. // need this awkward cloning to not affect original element
  11579. // best_of will decide which one to get through.
  11580. var node = self.clone();
  11581. node.expression = node.expression.clone();
  11582. node.expression.expression = node.expression.expression.clone();
  11583. node.expression.expression.elements = elements;
  11584. return best_of(compressor, self, node);
  11585. }
  11586. break;
  11587. case "charAt":
  11588. if (exp.expression.is_string(compressor)) {
  11589. var arg = self.args[0];
  11590. var index = arg ? arg.evaluate(compressor) : 0;
  11591. if (index !== arg) {
  11592. return make_node(AST_Sub, exp, {
  11593. expression: exp.expression,
  11594. property: make_node_from_constant(index | 0, arg || exp)
  11595. }).optimize(compressor);
  11596. }
  11597. }
  11598. break;
  11599. case "apply":
  11600. if (self.args.length == 2 && self.args[1] instanceof AST_Array) {
  11601. var args = self.args[1].elements.slice();
  11602. args.unshift(self.args[0]);
  11603. return make_node(AST_Call, self, {
  11604. expression: make_node(AST_Dot, exp, {
  11605. expression: exp.expression,
  11606. property: "call"
  11607. }),
  11608. args: args
  11609. }).optimize(compressor);
  11610. }
  11611. break;
  11612. case "call":
  11613. var func = exp.expression;
  11614. if (func instanceof AST_SymbolRef) {
  11615. func = func.fixed_value();
  11616. }
  11617. if (func instanceof AST_Lambda && !func.contains_this()) {
  11618. return (self.args.length ? make_sequence(this, [
  11619. self.args[0],
  11620. make_node(AST_Call, self, {
  11621. expression: exp.expression,
  11622. args: self.args.slice(1)
  11623. })
  11624. ]) : make_node(AST_Call, self, {
  11625. expression: exp.expression,
  11626. args: []
  11627. })).optimize(compressor);
  11628. }
  11629. break;
  11630. }
  11631. }
  11632. if (compressor.option("unsafe_Function")
  11633. && is_undeclared_ref(exp)
  11634. && exp.name == "Function") {
  11635. // new Function() => function(){}
  11636. if (self.args.length == 0) return make_node(AST_Function, self, {
  11637. argnames: [],
  11638. body: []
  11639. }).optimize(compressor);
  11640. if (all(self.args, function(x) {
  11641. return x instanceof AST_String;
  11642. })) {
  11643. // quite a corner-case, but we can handle it:
  11644. // https://github.com/mishoo/UglifyJS2/issues/203
  11645. // if the code argument is a constant, then we can minify it.
  11646. try {
  11647. var code = "n(function(" + self.args.slice(0, -1).map(function(arg) {
  11648. return arg.value;
  11649. }).join(",") + "){" + self.args[self.args.length - 1].value + "})";
  11650. var ast = parse(code);
  11651. var mangle = { ie8: compressor.option("ie8") };
  11652. ast.figure_out_scope(mangle);
  11653. var comp = new Compressor(compressor.options);
  11654. ast = ast.transform(comp);
  11655. ast.figure_out_scope(mangle);
  11656. base54.reset();
  11657. ast.compute_char_frequency(mangle);
  11658. ast.mangle_names(mangle);
  11659. var fun;
  11660. ast.walk(new TreeWalker(function(node) {
  11661. if (fun) return true;
  11662. if (is_func_expr(node)) {
  11663. fun = node;
  11664. return true;
  11665. }
  11666. }));
  11667. if (fun.body instanceof AST_Node) {
  11668. fun.body = [
  11669. make_node(AST_Return, fun.body, {
  11670. value: fun.body
  11671. })
  11672. ];
  11673. }
  11674. var code = OutputStream();
  11675. AST_BlockStatement.prototype._codegen.call(fun, fun, code);
  11676. self.args = [
  11677. make_node(AST_String, self, {
  11678. value: fun.argnames.map(function(arg) {
  11679. return arg.print_to_string();
  11680. }).join(",")
  11681. }),
  11682. make_node(AST_String, self.args[self.args.length - 1], {
  11683. value: code.get().replace(/^{|}$/g, "")
  11684. })
  11685. ];
  11686. return self;
  11687. } catch (ex) {
  11688. if (ex instanceof JS_Parse_Error) {
  11689. compressor.warn("Error parsing code passed to new Function [{file}:{line},{col}]", self.args[self.args.length - 1].start);
  11690. compressor.warn(ex.toString());
  11691. } else {
  11692. throw ex;
  11693. }
  11694. }
  11695. }
  11696. }
  11697. var stat = is_func && fn.body;
  11698. if (stat instanceof AST_Node) {
  11699. stat = make_node(AST_Return, stat, {
  11700. value: stat
  11701. });
  11702. } else if (stat) {
  11703. stat = stat[0];
  11704. }
  11705. var is_regular_func = is_func && !fn.is_generator && !fn.async;
  11706. var can_inline = compressor.option("inline") && !self.is_expr_pure(compressor);
  11707. if (can_inline && stat instanceof AST_Return && is_regular_func) {
  11708. var value = stat.value;
  11709. if (!value || value.is_constant_expression()) {
  11710. if (value) {
  11711. value = value.clone(true);
  11712. } else {
  11713. value = make_node(AST_Undefined, self);
  11714. }
  11715. var args = self.args.concat(value);
  11716. return make_sequence(self, args).optimize(compressor);
  11717. }
  11718. }
  11719. if (is_regular_func) {
  11720. var def, value, scope, in_loop, level = -1;
  11721. if (can_inline
  11722. && simple_args
  11723. && !fn.uses_arguments
  11724. && !fn.pinned()
  11725. && !(compressor.parent() instanceof AST_Class)
  11726. && !(fn.name && fn instanceof AST_Function)
  11727. && (!(compressor.find_parent(AST_Lambda) instanceof AST_Arrow)
  11728. || fn.argnames.length == 0
  11729. && (fn.body instanceof AST_Node || fn.body.length == 1))
  11730. && (value = can_flatten_body(stat))
  11731. && (exp === fn
  11732. || compressor.option("unused")
  11733. && (def = exp.definition()).references.length == 1
  11734. && !recursive_ref(compressor, def)
  11735. && fn.is_constant_expression(exp.scope))
  11736. && !self.pure
  11737. && !fn.contains_this()
  11738. && can_inject_symbols()
  11739. && !(scope instanceof AST_Class)) {
  11740. fn._squeezed = true;
  11741. return make_sequence(self, flatten_fn()).optimize(compressor);
  11742. }
  11743. if (compressor.option("side_effects") && !(fn.body instanceof AST_Node) && all(fn.body, is_empty)) {
  11744. var args = self.args.concat(make_node(AST_Undefined, self));
  11745. return make_sequence(self, args).optimize(compressor);
  11746. }
  11747. }
  11748. if (compressor.option("negate_iife")
  11749. && compressor.parent() instanceof AST_SimpleStatement
  11750. && is_iife_call(self)) {
  11751. return self.negate(compressor, true);
  11752. }
  11753. var ev = self.evaluate(compressor);
  11754. if (ev !== self) {
  11755. ev = make_node_from_constant(ev, self).optimize(compressor);
  11756. return best_of(compressor, ev, self);
  11757. }
  11758. return self;
  11759. function return_value(stat) {
  11760. if (!stat) return make_node(AST_Undefined, self);
  11761. if (stat instanceof AST_Return) {
  11762. if (!stat.value) return make_node(AST_Undefined, self);
  11763. return stat.value.clone(true);
  11764. }
  11765. if (stat instanceof AST_SimpleStatement) {
  11766. return make_node(AST_UnaryPrefix, stat, {
  11767. operator: "void",
  11768. expression: stat.body.clone(true)
  11769. });
  11770. }
  11771. }
  11772. function can_flatten_body(stat) {
  11773. var body = fn.body instanceof AST_Node ? [ fn.body ] : fn.body;
  11774. var len = body.length;
  11775. if (compressor.option("inline") < 3) {
  11776. return len == 1 && return_value(stat);
  11777. }
  11778. stat = null;
  11779. for (var i = 0; i < len; i++) {
  11780. var line = body[i];
  11781. if (line instanceof AST_Var) {
  11782. if (stat && !all(line.definitions, function(var_def) {
  11783. return !var_def.value;
  11784. })) {
  11785. return false;
  11786. }
  11787. } else if (stat) {
  11788. return false;
  11789. } else {
  11790. stat = line;
  11791. }
  11792. }
  11793. return return_value(stat);
  11794. }
  11795. function can_inject_args(block_scoped, safe_to_inject) {
  11796. for (var i = 0, len = fn.argnames.length; i < len; i++) {
  11797. var arg = fn.argnames[i];
  11798. if (arg instanceof AST_DefaultAssign) {
  11799. if (arg.left.__unused) continue;
  11800. return false;
  11801. }
  11802. if (arg instanceof AST_Destructuring) return false;
  11803. if (arg instanceof AST_Expansion) {
  11804. if (arg.expression.__unused) continue;
  11805. return false;
  11806. }
  11807. if (arg.__unused) continue;
  11808. if (!safe_to_inject
  11809. || block_scoped[arg.name]
  11810. || identifier_atom(arg.name)
  11811. || scope.var_names()[arg.name]) {
  11812. return false;
  11813. }
  11814. if (in_loop) in_loop.push(arg.definition());
  11815. }
  11816. return true;
  11817. }
  11818. function can_inject_vars(block_scoped, safe_to_inject) {
  11819. var len = fn.body.length;
  11820. for (var i = 0; i < len; i++) {
  11821. var stat = fn.body[i];
  11822. if (!(stat instanceof AST_Var)) continue;
  11823. if (!safe_to_inject) return false;
  11824. for (var j = stat.definitions.length; --j >= 0;) {
  11825. var name = stat.definitions[j].name;
  11826. if (name instanceof AST_Destructuring
  11827. || block_scoped[name.name]
  11828. || identifier_atom(name.name)
  11829. || scope.var_names()[name.name]) {
  11830. return false;
  11831. }
  11832. if (in_loop) in_loop.push(name.definition());
  11833. }
  11834. }
  11835. return true;
  11836. }
  11837. function can_inject_symbols() {
  11838. var block_scoped = Object.create(null);
  11839. do {
  11840. scope = compressor.parent(++level);
  11841. if (scope.is_block_scope() && !(compressor.parent(level - 1) instanceof AST_Scope)) {
  11842. if (scope.block_scope) {
  11843. // TODO this is sometimes undefined during compression.
  11844. // But it should always have a value!
  11845. scope.block_scope.variables.each(function (variable) {
  11846. block_scoped[variable.name] = true;
  11847. });
  11848. }
  11849. }
  11850. if (scope instanceof AST_Catch) {
  11851. if (scope.argname) {
  11852. block_scoped[scope.argname.name] = true;
  11853. }
  11854. } else if (scope instanceof AST_IterationStatement) {
  11855. in_loop = [];
  11856. } else if (scope instanceof AST_SymbolRef) {
  11857. if (scope.fixed_value() instanceof AST_Scope) return false;
  11858. }
  11859. } while (!(scope instanceof AST_Scope) || scope instanceof AST_Arrow);
  11860. var safe_to_inject = !(scope instanceof AST_Toplevel) || compressor.toplevel.vars;
  11861. var inline = compressor.option("inline");
  11862. if (!can_inject_vars(block_scoped, inline >= 3 && safe_to_inject)) return false;
  11863. if (!can_inject_args(block_scoped, inline >= 2 && safe_to_inject)) return false;
  11864. return !in_loop || in_loop.length == 0 || !is_reachable(fn, in_loop);
  11865. }
  11866. function append_var(decls, expressions, name, value) {
  11867. var def = name.definition();
  11868. scope.variables.set(name.name, def);
  11869. scope.enclosed.push(def);
  11870. if (!scope.var_names()[name.name]) {
  11871. scope.var_names()[name.name] = true;
  11872. decls.push(make_node(AST_VarDef, name, {
  11873. name: name,
  11874. value: null
  11875. }));
  11876. }
  11877. var sym = make_node(AST_SymbolRef, name, name);
  11878. def.references.push(sym);
  11879. if (value) expressions.push(make_node(AST_Assign, self, {
  11880. operator: "=",
  11881. left: sym,
  11882. right: value.clone()
  11883. }));
  11884. }
  11885. function flatten_args(decls, expressions) {
  11886. var len = fn.argnames.length;
  11887. for (var i = self.args.length; --i >= len;) {
  11888. expressions.push(self.args[i]);
  11889. }
  11890. for (i = len; --i >= 0;) {
  11891. var name = fn.argnames[i];
  11892. var value = self.args[i];
  11893. if (name.__unused || !name.name || scope.var_names()[name.name]) {
  11894. if (value) expressions.push(value);
  11895. } else {
  11896. var symbol = make_node(AST_SymbolVar, name, name);
  11897. name.definition().orig.push(symbol);
  11898. if (!value && in_loop) value = make_node(AST_Undefined, self);
  11899. append_var(decls, expressions, symbol, value);
  11900. }
  11901. }
  11902. decls.reverse();
  11903. expressions.reverse();
  11904. }
  11905. function flatten_vars(decls, expressions) {
  11906. var pos = expressions.length;
  11907. for (var i = 0, lines = fn.body.length; i < lines; i++) {
  11908. var stat = fn.body[i];
  11909. if (!(stat instanceof AST_Var)) continue;
  11910. for (var j = 0, defs = stat.definitions.length; j < defs; j++) {
  11911. var var_def = stat.definitions[j];
  11912. var name = var_def.name;
  11913. append_var(decls, expressions, name, var_def.value);
  11914. if (in_loop && all(fn.argnames, function(argname) {
  11915. return argname.name != name.name;
  11916. })) {
  11917. var def = fn.variables.get(name.name);
  11918. var sym = make_node(AST_SymbolRef, name, name);
  11919. def.references.push(sym);
  11920. expressions.splice(pos++, 0, make_node(AST_Assign, var_def, {
  11921. operator: "=",
  11922. left: sym,
  11923. right: make_node(AST_Undefined, name)
  11924. }));
  11925. }
  11926. }
  11927. }
  11928. }
  11929. function flatten_fn() {
  11930. var decls = [];
  11931. var expressions = [];
  11932. flatten_args(decls, expressions);
  11933. flatten_vars(decls, expressions);
  11934. expressions.push(value);
  11935. if (decls.length) {
  11936. i = scope.body.indexOf(compressor.parent(level - 1)) + 1;
  11937. scope.body.splice(i, 0, make_node(AST_Var, fn, {
  11938. definitions: decls
  11939. }));
  11940. }
  11941. return expressions;
  11942. }
  11943. });
  11944. def_optimize(AST_New, function(self, compressor) {
  11945. const {args, expression: exp} = self;
  11946. if (compressor.option("unsafe") && is_undeclared_ref(exp)) {
  11947. if (["Object", "RegExp", "Function", "Error"].includes(exp.name))
  11948. return make_node(AST_Call, self, self).transform(compressor);
  11949. if (exp.name === "Array" && args.length < 2) {
  11950. if (args.length === 0 || args[0].value === 0) return new AST_Array;
  11951. if (args[0].value > 11) {
  11952. return make_node(AST_Call, self, self).transform(compressor);
  11953. }
  11954. const elements = [];
  11955. for (let i = 0; i < self.args[0].value; i++) elements.push(new AST_Hole);
  11956. return new AST_Array({elements});
  11957. }
  11958. }
  11959. return self;
  11960. });
  11961. def_optimize(AST_Sequence, function(self, compressor) {
  11962. if (!compressor.option("side_effects")) return self;
  11963. var expressions = [];
  11964. filter_for_side_effects();
  11965. var end = expressions.length - 1;
  11966. trim_right_for_undefined();
  11967. if (end == 0) {
  11968. self = maintain_this_binding(compressor.parent(), compressor.self(), expressions[0]);
  11969. if (!(self instanceof AST_Sequence)) self = self.optimize(compressor);
  11970. return self;
  11971. }
  11972. self.expressions = expressions;
  11973. return self;
  11974. function filter_for_side_effects() {
  11975. var first = first_in_statement(compressor);
  11976. var last = self.expressions.length - 1;
  11977. self.expressions.forEach(function(expr, index) {
  11978. if (index < last) expr = expr.drop_side_effect_free(compressor, first);
  11979. if (expr) {
  11980. merge_sequence(expressions, expr);
  11981. first = false;
  11982. }
  11983. });
  11984. }
  11985. function trim_right_for_undefined() {
  11986. while (end > 0 && is_undefined(expressions[end], compressor)) end--;
  11987. if (end < expressions.length - 1) {
  11988. expressions[end] = make_node(AST_UnaryPrefix, self, {
  11989. operator : "void",
  11990. expression : expressions[end]
  11991. });
  11992. expressions.length = end + 1;
  11993. }
  11994. }
  11995. });
  11996. AST_Unary.DEFMETHOD("lift_sequences", function(compressor) {
  11997. if (compressor.option("sequences")) {
  11998. if (this.expression instanceof AST_Sequence) {
  11999. var x = this.expression.expressions.slice();
  12000. var e = this.clone();
  12001. e.expression = x.pop();
  12002. x.push(e);
  12003. return make_sequence(this, x).optimize(compressor);
  12004. }
  12005. }
  12006. return this;
  12007. });
  12008. def_optimize(AST_UnaryPostfix, function(self, compressor) {
  12009. return self.lift_sequences(compressor);
  12010. });
  12011. def_optimize(AST_UnaryPrefix, function(self, compressor) {
  12012. var e = self.expression;
  12013. if (self.operator == "delete"
  12014. && !(e instanceof AST_SymbolRef
  12015. || e instanceof AST_PropAccess
  12016. || is_identifier_atom(e))) {
  12017. if (e instanceof AST_Sequence) {
  12018. e = e.expressions.slice();
  12019. e.push(make_node(AST_True, self));
  12020. return make_sequence(self, e).optimize(compressor);
  12021. }
  12022. return make_sequence(self, [ e, make_node(AST_True, self) ]).optimize(compressor);
  12023. }
  12024. var seq = self.lift_sequences(compressor);
  12025. if (seq !== self) {
  12026. return seq;
  12027. }
  12028. if (compressor.option("side_effects") && self.operator == "void") {
  12029. e = e.drop_side_effect_free(compressor);
  12030. if (e) {
  12031. self.expression = e;
  12032. return self;
  12033. } else {
  12034. return make_node(AST_Undefined, self).optimize(compressor);
  12035. }
  12036. }
  12037. if (compressor.in_boolean_context()) {
  12038. switch (self.operator) {
  12039. case "!":
  12040. if (e instanceof AST_UnaryPrefix && e.operator == "!") {
  12041. // !!foo ==> foo, if we're in boolean context
  12042. return e.expression;
  12043. }
  12044. if (e instanceof AST_Binary) {
  12045. self = best_of(compressor, self, e.negate(compressor, first_in_statement(compressor)));
  12046. }
  12047. break;
  12048. case "typeof":
  12049. // typeof always returns a non-empty string, thus it's
  12050. // always true in booleans
  12051. compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
  12052. return (e instanceof AST_SymbolRef ? make_node(AST_True, self) : make_sequence(self, [
  12053. e,
  12054. make_node(AST_True, self)
  12055. ])).optimize(compressor);
  12056. }
  12057. }
  12058. if (self.operator == "-" && e instanceof AST_Infinity) {
  12059. e = e.transform(compressor);
  12060. }
  12061. if (e instanceof AST_Binary
  12062. && (self.operator == "+" || self.operator == "-")
  12063. && (e.operator == "*" || e.operator == "/" || e.operator == "%")) {
  12064. return make_node(AST_Binary, self, {
  12065. operator: e.operator,
  12066. left: make_node(AST_UnaryPrefix, e.left, {
  12067. operator: self.operator,
  12068. expression: e.left
  12069. }),
  12070. right: e.right
  12071. });
  12072. }
  12073. // avoids infinite recursion of numerals
  12074. if (self.operator != "-"
  12075. || !(e instanceof AST_Number || e instanceof AST_Infinity)) {
  12076. var ev = self.evaluate(compressor);
  12077. if (ev !== self) {
  12078. ev = make_node_from_constant(ev, self).optimize(compressor);
  12079. return best_of(compressor, ev, self);
  12080. }
  12081. }
  12082. return self;
  12083. });
  12084. AST_Binary.DEFMETHOD("lift_sequences", function(compressor) {
  12085. if (compressor.option("sequences")) {
  12086. if (this.left instanceof AST_Sequence) {
  12087. var x = this.left.expressions.slice();
  12088. var e = this.clone();
  12089. e.left = x.pop();
  12090. x.push(e);
  12091. return make_sequence(this, x).optimize(compressor);
  12092. }
  12093. if (this.right instanceof AST_Sequence && !this.left.has_side_effects(compressor)) {
  12094. var assign = this.operator == "=" && this.left instanceof AST_SymbolRef;
  12095. var x = this.right.expressions;
  12096. var last = x.length - 1;
  12097. for (var i = 0; i < last; i++) {
  12098. if (!assign && x[i].has_side_effects(compressor)) break;
  12099. }
  12100. if (i == last) {
  12101. x = x.slice();
  12102. var e = this.clone();
  12103. e.right = x.pop();
  12104. x.push(e);
  12105. return make_sequence(this, x).optimize(compressor);
  12106. } else if (i > 0) {
  12107. var e = this.clone();
  12108. e.right = make_sequence(this.right, x.slice(i));
  12109. x = x.slice(0, i);
  12110. x.push(e);
  12111. return make_sequence(this, x).optimize(compressor);
  12112. }
  12113. }
  12114. }
  12115. return this;
  12116. });
  12117. var commutativeOperators = makePredicate("== === != !== * & | ^");
  12118. function is_object(node) {
  12119. return node instanceof AST_Array
  12120. || node instanceof AST_Lambda
  12121. || node instanceof AST_Object
  12122. || node instanceof AST_Class;
  12123. }
  12124. def_optimize(AST_Binary, function(self, compressor) {
  12125. function reversible() {
  12126. return self.left.is_constant()
  12127. || self.right.is_constant()
  12128. || !self.left.has_side_effects(compressor)
  12129. && !self.right.has_side_effects(compressor);
  12130. }
  12131. function reverse(op) {
  12132. if (reversible()) {
  12133. if (op) self.operator = op;
  12134. var tmp = self.left;
  12135. self.left = self.right;
  12136. self.right = tmp;
  12137. }
  12138. }
  12139. if (commutativeOperators(self.operator)) {
  12140. if (self.right.is_constant()
  12141. && !self.left.is_constant()) {
  12142. // if right is a constant, whatever side effects the
  12143. // left side might have could not influence the
  12144. // result. hence, force switch.
  12145. if (!(self.left instanceof AST_Binary
  12146. && PRECEDENCE[self.left.operator] >= PRECEDENCE[self.operator])) {
  12147. reverse();
  12148. }
  12149. }
  12150. }
  12151. self = self.lift_sequences(compressor);
  12152. if (compressor.option("comparisons")) switch (self.operator) {
  12153. case "===":
  12154. case "!==":
  12155. var is_strict_comparison = true;
  12156. if ((self.left.is_string(compressor) && self.right.is_string(compressor)) ||
  12157. (self.left.is_number(compressor) && self.right.is_number(compressor)) ||
  12158. (self.left.is_boolean() && self.right.is_boolean()) ||
  12159. self.left.equivalent_to(self.right)) {
  12160. self.operator = self.operator.substr(0, 2);
  12161. }
  12162. // XXX: intentionally falling down to the next case
  12163. case "==":
  12164. case "!=":
  12165. // void 0 == x => null == x
  12166. if (!is_strict_comparison && is_undefined(self.left, compressor)) {
  12167. self.left = make_node(AST_Null, self.left);
  12168. } else if (compressor.option("typeofs")
  12169. // "undefined" == typeof x => undefined === x
  12170. && self.left instanceof AST_String
  12171. && self.left.value == "undefined"
  12172. && self.right instanceof AST_UnaryPrefix
  12173. && self.right.operator == "typeof") {
  12174. var expr = self.right.expression;
  12175. if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor)
  12176. : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) {
  12177. self.right = expr;
  12178. self.left = make_node(AST_Undefined, self.left).optimize(compressor);
  12179. if (self.operator.length == 2) self.operator += "=";
  12180. }
  12181. } else if (self.left instanceof AST_SymbolRef
  12182. // obj !== obj => false
  12183. && self.right instanceof AST_SymbolRef
  12184. && self.left.definition() === self.right.definition()
  12185. && is_object(self.left.fixed_value())) {
  12186. return make_node(self.operator[0] == "=" ? AST_True : AST_False, self);
  12187. }
  12188. break;
  12189. case "&&":
  12190. case "||":
  12191. var lhs = self.left;
  12192. if (lhs.operator == self.operator) {
  12193. lhs = lhs.right;
  12194. }
  12195. if (lhs instanceof AST_Binary
  12196. && lhs.operator == (self.operator == "&&" ? "!==" : "===")
  12197. && self.right instanceof AST_Binary
  12198. && lhs.operator == self.right.operator
  12199. && (is_undefined(lhs.left, compressor) && self.right.left instanceof AST_Null
  12200. || lhs.left instanceof AST_Null && is_undefined(self.right.left, compressor))
  12201. && !lhs.right.has_side_effects(compressor)
  12202. && lhs.right.equivalent_to(self.right.right)) {
  12203. var combined = make_node(AST_Binary, self, {
  12204. operator: lhs.operator.slice(0, -1),
  12205. left: make_node(AST_Null, self),
  12206. right: lhs.right
  12207. });
  12208. if (lhs !== self.left) {
  12209. combined = make_node(AST_Binary, self, {
  12210. operator: self.operator,
  12211. left: self.left.left,
  12212. right: combined
  12213. });
  12214. }
  12215. return combined;
  12216. }
  12217. break;
  12218. }
  12219. if (self.operator == "+" && compressor.in_boolean_context()) {
  12220. var ll = self.left.evaluate(compressor);
  12221. var rr = self.right.evaluate(compressor);
  12222. if (ll && typeof ll == "string") {
  12223. compressor.warn("+ in boolean context always true [{file}:{line},{col}]", self.start);
  12224. return make_sequence(self, [
  12225. self.right,
  12226. make_node(AST_True, self)
  12227. ]).optimize(compressor);
  12228. }
  12229. if (rr && typeof rr == "string") {
  12230. compressor.warn("+ in boolean context always true [{file}:{line},{col}]", self.start);
  12231. return make_sequence(self, [
  12232. self.left,
  12233. make_node(AST_True, self)
  12234. ]).optimize(compressor);
  12235. }
  12236. }
  12237. if (compressor.option("comparisons") && self.is_boolean()) {
  12238. if (!(compressor.parent() instanceof AST_Binary)
  12239. || compressor.parent() instanceof AST_Assign) {
  12240. var negated = make_node(AST_UnaryPrefix, self, {
  12241. operator: "!",
  12242. expression: self.negate(compressor, first_in_statement(compressor))
  12243. });
  12244. self = best_of(compressor, self, negated);
  12245. }
  12246. if (compressor.option("unsafe_comps")) {
  12247. switch (self.operator) {
  12248. case "<": reverse(">"); break;
  12249. case "<=": reverse(">="); break;
  12250. }
  12251. }
  12252. }
  12253. if (self.operator == "+") {
  12254. if (self.right instanceof AST_String
  12255. && self.right.getValue() == ""
  12256. && self.left.is_string(compressor)) {
  12257. return self.left;
  12258. }
  12259. if (self.left instanceof AST_String
  12260. && self.left.getValue() == ""
  12261. && self.right.is_string(compressor)) {
  12262. return self.right;
  12263. }
  12264. if (self.left instanceof AST_Binary
  12265. && self.left.operator == "+"
  12266. && self.left.left instanceof AST_String
  12267. && self.left.left.getValue() == ""
  12268. && self.right.is_string(compressor)) {
  12269. self.left = self.left.right;
  12270. return self.transform(compressor);
  12271. }
  12272. }
  12273. if (compressor.option("evaluate")) {
  12274. switch (self.operator) {
  12275. case "&&":
  12276. var ll = self.left.truthy ? true : self.left.falsy ? false : self.left.evaluate(compressor);
  12277. if (!ll) {
  12278. compressor.warn("Condition left of && always false [{file}:{line},{col}]", self.start);
  12279. return maintain_this_binding(compressor.parent(), compressor.self(), self.left).optimize(compressor);
  12280. } else if (!(ll instanceof AST_Node)) {
  12281. compressor.warn("Condition left of && always true [{file}:{line},{col}]", self.start);
  12282. return make_sequence(self, [ self.left, self.right ]).optimize(compressor);
  12283. }
  12284. var rr = self.right.evaluate(compressor);
  12285. if (!rr) {
  12286. if (compressor.in_boolean_context()) {
  12287. compressor.warn("Boolean && always false [{file}:{line},{col}]", self.start);
  12288. return make_sequence(self, [
  12289. self.left,
  12290. make_node(AST_False, self)
  12291. ]).optimize(compressor);
  12292. } else self.falsy = true;
  12293. } else if (!(rr instanceof AST_Node)) {
  12294. var parent = compressor.parent();
  12295. if (parent.operator == "&&" && parent.left === compressor.self() || compressor.in_boolean_context()) {
  12296. compressor.warn("Dropping side-effect-free && [{file}:{line},{col}]", self.start);
  12297. return self.left.optimize(compressor);
  12298. }
  12299. }
  12300. // x || false && y ---> x ? y : false
  12301. if (self.left.operator == "||") {
  12302. var lr = self.left.right.evaluate(compressor);
  12303. if (!lr) return make_node(AST_Conditional, self, {
  12304. condition: self.left.left,
  12305. consequent: self.right,
  12306. alternative: self.left.right
  12307. }).optimize(compressor);
  12308. }
  12309. break;
  12310. case "||":
  12311. var ll = self.left.truthy ? true : self.left.falsy ? false : self.left.evaluate(compressor);
  12312. if (!ll) {
  12313. compressor.warn("Condition left of || always false [{file}:{line},{col}]", self.start);
  12314. return make_sequence(self, [ self.left, self.right ]).optimize(compressor);
  12315. } else if (!(ll instanceof AST_Node)) {
  12316. compressor.warn("Condition left of || always true [{file}:{line},{col}]", self.start);
  12317. return maintain_this_binding(compressor.parent(), compressor.self(), self.left).optimize(compressor);
  12318. }
  12319. var rr = self.right.evaluate(compressor);
  12320. if (!rr) {
  12321. var parent = compressor.parent();
  12322. if (parent.operator == "||" && parent.left === compressor.self() || compressor.in_boolean_context()) {
  12323. compressor.warn("Dropping side-effect-free || [{file}:{line},{col}]", self.start);
  12324. return self.left.optimize(compressor);
  12325. }
  12326. } else if (!(rr instanceof AST_Node)) {
  12327. if (compressor.in_boolean_context()) {
  12328. compressor.warn("Boolean || always true [{file}:{line},{col}]", self.start);
  12329. return make_sequence(self, [
  12330. self.left,
  12331. make_node(AST_True, self)
  12332. ]).optimize(compressor);
  12333. } else self.truthy = true;
  12334. }
  12335. if (self.left.operator == "&&") {
  12336. var lr = self.left.right.evaluate(compressor);
  12337. if (lr && !(lr instanceof AST_Node)) return make_node(AST_Conditional, self, {
  12338. condition: self.left.left,
  12339. consequent: self.left.right,
  12340. alternative: self.right
  12341. }).optimize(compressor);
  12342. }
  12343. break;
  12344. }
  12345. var associative = true;
  12346. switch (self.operator) {
  12347. case "+":
  12348. // "foo" + ("bar" + x) => "foobar" + x
  12349. if (self.left instanceof AST_Constant
  12350. && self.right instanceof AST_Binary
  12351. && self.right.operator == "+"
  12352. && self.right.left instanceof AST_Constant
  12353. && self.right.is_string(compressor)) {
  12354. self = make_node(AST_Binary, self, {
  12355. operator: "+",
  12356. left: make_node(AST_String, self.left, {
  12357. value: "" + self.left.getValue() + self.right.left.getValue(),
  12358. start: self.left.start,
  12359. end: self.right.left.end
  12360. }),
  12361. right: self.right.right
  12362. });
  12363. }
  12364. // (x + "foo") + "bar" => x + "foobar"
  12365. if (self.right instanceof AST_Constant
  12366. && self.left instanceof AST_Binary
  12367. && self.left.operator == "+"
  12368. && self.left.right instanceof AST_Constant
  12369. && self.left.is_string(compressor)) {
  12370. self = make_node(AST_Binary, self, {
  12371. operator: "+",
  12372. left: self.left.left,
  12373. right: make_node(AST_String, self.right, {
  12374. value: "" + self.left.right.getValue() + self.right.getValue(),
  12375. start: self.left.right.start,
  12376. end: self.right.end
  12377. })
  12378. });
  12379. }
  12380. // (x + "foo") + ("bar" + y) => (x + "foobar") + y
  12381. if (self.left instanceof AST_Binary
  12382. && self.left.operator == "+"
  12383. && self.left.is_string(compressor)
  12384. && self.left.right instanceof AST_Constant
  12385. && self.right instanceof AST_Binary
  12386. && self.right.operator == "+"
  12387. && self.right.left instanceof AST_Constant
  12388. && self.right.is_string(compressor)) {
  12389. self = make_node(AST_Binary, self, {
  12390. operator: "+",
  12391. left: make_node(AST_Binary, self.left, {
  12392. operator: "+",
  12393. left: self.left.left,
  12394. right: make_node(AST_String, self.left.right, {
  12395. value: "" + self.left.right.getValue() + self.right.left.getValue(),
  12396. start: self.left.right.start,
  12397. end: self.right.left.end
  12398. })
  12399. }),
  12400. right: self.right.right
  12401. });
  12402. }
  12403. // a + -b => a - b
  12404. if (self.right instanceof AST_UnaryPrefix
  12405. && self.right.operator == "-"
  12406. && self.left.is_number(compressor)) {
  12407. self = make_node(AST_Binary, self, {
  12408. operator: "-",
  12409. left: self.left,
  12410. right: self.right.expression
  12411. });
  12412. break;
  12413. }
  12414. // -a + b => b - a
  12415. if (self.left instanceof AST_UnaryPrefix
  12416. && self.left.operator == "-"
  12417. && reversible()
  12418. && self.right.is_number(compressor)) {
  12419. self = make_node(AST_Binary, self, {
  12420. operator: "-",
  12421. left: self.right,
  12422. right: self.left.expression
  12423. });
  12424. break;
  12425. }
  12426. case "*":
  12427. associative = compressor.option("unsafe_math");
  12428. case "&":
  12429. case "|":
  12430. case "^":
  12431. // a + +b => +b + a
  12432. if (self.left.is_number(compressor)
  12433. && self.right.is_number(compressor)
  12434. && reversible()
  12435. && !(self.left instanceof AST_Binary
  12436. && self.left.operator != self.operator
  12437. && PRECEDENCE[self.left.operator] >= PRECEDENCE[self.operator])) {
  12438. var reversed = make_node(AST_Binary, self, {
  12439. operator: self.operator,
  12440. left: self.right,
  12441. right: self.left
  12442. });
  12443. if (self.right instanceof AST_Constant
  12444. && !(self.left instanceof AST_Constant)) {
  12445. self = best_of(compressor, reversed, self);
  12446. } else {
  12447. self = best_of(compressor, self, reversed);
  12448. }
  12449. }
  12450. if (associative && self.is_number(compressor)) {
  12451. // a + (b + c) => (a + b) + c
  12452. if (self.right instanceof AST_Binary
  12453. && self.right.operator == self.operator) {
  12454. self = make_node(AST_Binary, self, {
  12455. operator: self.operator,
  12456. left: make_node(AST_Binary, self.left, {
  12457. operator: self.operator,
  12458. left: self.left,
  12459. right: self.right.left,
  12460. start: self.left.start,
  12461. end: self.right.left.end
  12462. }),
  12463. right: self.right.right
  12464. });
  12465. }
  12466. // (n + 2) + 3 => 5 + n
  12467. // (2 * n) * 3 => 6 + n
  12468. if (self.right instanceof AST_Constant
  12469. && self.left instanceof AST_Binary
  12470. && self.left.operator == self.operator) {
  12471. if (self.left.left instanceof AST_Constant) {
  12472. self = make_node(AST_Binary, self, {
  12473. operator: self.operator,
  12474. left: make_node(AST_Binary, self.left, {
  12475. operator: self.operator,
  12476. left: self.left.left,
  12477. right: self.right,
  12478. start: self.left.left.start,
  12479. end: self.right.end
  12480. }),
  12481. right: self.left.right
  12482. });
  12483. } else if (self.left.right instanceof AST_Constant) {
  12484. self = make_node(AST_Binary, self, {
  12485. operator: self.operator,
  12486. left: make_node(AST_Binary, self.left, {
  12487. operator: self.operator,
  12488. left: self.left.right,
  12489. right: self.right,
  12490. start: self.left.right.start,
  12491. end: self.right.end
  12492. }),
  12493. right: self.left.left
  12494. });
  12495. }
  12496. }
  12497. // (a | 1) | (2 | d) => (3 | a) | b
  12498. if (self.left instanceof AST_Binary
  12499. && self.left.operator == self.operator
  12500. && self.left.right instanceof AST_Constant
  12501. && self.right instanceof AST_Binary
  12502. && self.right.operator == self.operator
  12503. && self.right.left instanceof AST_Constant) {
  12504. self = make_node(AST_Binary, self, {
  12505. operator: self.operator,
  12506. left: make_node(AST_Binary, self.left, {
  12507. operator: self.operator,
  12508. left: make_node(AST_Binary, self.left.left, {
  12509. operator: self.operator,
  12510. left: self.left.right,
  12511. right: self.right.left,
  12512. start: self.left.right.start,
  12513. end: self.right.left.end
  12514. }),
  12515. right: self.left.left
  12516. }),
  12517. right: self.right.right
  12518. });
  12519. }
  12520. }
  12521. }
  12522. }
  12523. // x && (y && z) ==> x && y && z
  12524. // x || (y || z) ==> x || y || z
  12525. // x + ("y" + z) ==> x + "y" + z
  12526. // "x" + (y + "z")==> "x" + y + "z"
  12527. if (self.right instanceof AST_Binary
  12528. && self.right.operator == self.operator
  12529. && (lazy_op(self.operator)
  12530. || (self.operator == "+"
  12531. && (self.right.left.is_string(compressor)
  12532. || (self.left.is_string(compressor)
  12533. && self.right.right.is_string(compressor)))))
  12534. ) {
  12535. self.left = make_node(AST_Binary, self.left, {
  12536. operator : self.operator,
  12537. left : self.left,
  12538. right : self.right.left
  12539. });
  12540. self.right = self.right.right;
  12541. return self.transform(compressor);
  12542. }
  12543. var ev = self.evaluate(compressor);
  12544. if (ev !== self) {
  12545. ev = make_node_from_constant(ev, self).optimize(compressor);
  12546. return best_of(compressor, ev, self);
  12547. }
  12548. return self;
  12549. });
  12550. def_optimize(AST_SymbolExport, function(self, compressor) {
  12551. return self;
  12552. });
  12553. function recursive_ref(compressor, def) {
  12554. var node;
  12555. for (var i = 0; node = compressor.parent(i); i++) {
  12556. if (node instanceof AST_Lambda) {
  12557. var name = node.name;
  12558. if (name && name.definition() === def) break;
  12559. }
  12560. }
  12561. return node;
  12562. }
  12563. function within_array_or_object_literal(compressor) {
  12564. var node, level = 0;
  12565. while (node = compressor.parent(level++)) {
  12566. if (node instanceof AST_Statement) return false;
  12567. if (node instanceof AST_Array
  12568. || node instanceof AST_ObjectKeyVal
  12569. || node instanceof AST_Object) {
  12570. return true;
  12571. }
  12572. }
  12573. return false;
  12574. }
  12575. def_optimize(AST_SymbolRef, function(self, compressor) {
  12576. if (!compressor.option("ie8")
  12577. && is_undeclared_ref(self)
  12578. && (!self.scope.uses_with || !compressor.find_parent(AST_With))) {
  12579. switch (self.name) {
  12580. case "undefined":
  12581. return make_node(AST_Undefined, self).optimize(compressor);
  12582. case "NaN":
  12583. return make_node(AST_NaN, self).optimize(compressor);
  12584. case "Infinity":
  12585. return make_node(AST_Infinity, self).optimize(compressor);
  12586. }
  12587. }
  12588. var parent = compressor.parent();
  12589. if (compressor.option("reduce_vars") && is_lhs(self, parent) !== self) {
  12590. var d = self.definition();
  12591. if (compressor.top_retain && d.global && compressor.top_retain(d)) {
  12592. d.fixed = false;
  12593. d.should_replace = false;
  12594. d.single_use = false;
  12595. return self;
  12596. }
  12597. var fixed = self.fixed_value();
  12598. var single_use = d.single_use
  12599. && !(parent instanceof AST_Call && parent.is_expr_pure(compressor));
  12600. if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
  12601. if (retain_top_func(fixed, compressor)) {
  12602. single_use = false;
  12603. } else if (d.scope !== self.scope
  12604. && (!compressor.option("reduce_funcs") && fixed instanceof AST_Lambda
  12605. || d.escaped == 1
  12606. || fixed.inlined
  12607. || within_array_or_object_literal(compressor))) {
  12608. single_use = false;
  12609. } else if (recursive_ref(compressor, d)) {
  12610. single_use = false;
  12611. } else if (d.scope !== self.scope || d.orig[0] instanceof AST_SymbolFunarg) {
  12612. single_use = fixed.is_constant_expression(self.scope);
  12613. if (single_use == "f") {
  12614. var scope = self.scope;
  12615. do {
  12616. if (scope instanceof AST_Defun || is_func_expr(scope)) {
  12617. scope.inlined = true;
  12618. }
  12619. } while (scope = scope.parent_scope);
  12620. }
  12621. }
  12622. }
  12623. if (single_use && fixed) {
  12624. if (fixed instanceof AST_DefClass) {
  12625. fixed = make_node(AST_ClassExpression, fixed, fixed);
  12626. }
  12627. if (fixed instanceof AST_Defun) {
  12628. fixed._squeezed = true;
  12629. fixed = make_node(AST_Function, fixed, fixed);
  12630. }
  12631. var value;
  12632. if (d.recursive_refs > 0 && fixed.name instanceof AST_SymbolDefun) {
  12633. value = fixed.clone(true);
  12634. var defun_def = value.name.definition();
  12635. var lambda_def = value.variables.get(value.name.name);
  12636. var name = lambda_def && lambda_def.orig[0];
  12637. if (!(name instanceof AST_SymbolLambda)) {
  12638. name = make_node(AST_SymbolLambda, value.name, value.name);
  12639. name.scope = value;
  12640. value.name = name;
  12641. lambda_def = value.def_function(name);
  12642. }
  12643. value.walk(new TreeWalker(function(node) {
  12644. if (node instanceof AST_SymbolRef && node.definition() === defun_def) {
  12645. node.thedef = lambda_def;
  12646. lambda_def.references.push(node);
  12647. }
  12648. }));
  12649. } else {
  12650. value = fixed.optimize(compressor);
  12651. if (value === fixed) value = fixed.clone(true);
  12652. }
  12653. return value;
  12654. }
  12655. if (fixed && d.should_replace === undefined) {
  12656. var init;
  12657. if (fixed instanceof AST_This) {
  12658. if (!(d.orig[0] instanceof AST_SymbolFunarg)
  12659. && all(d.references, function(ref) {
  12660. return d.scope === ref.scope;
  12661. })) {
  12662. init = fixed;
  12663. }
  12664. } else {
  12665. var ev = fixed.evaluate(compressor);
  12666. if (ev !== fixed && (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))) {
  12667. init = make_node_from_constant(ev, fixed);
  12668. }
  12669. }
  12670. if (init) {
  12671. var value_length = init.optimize(compressor).print_to_string().length;
  12672. var fn;
  12673. if (has_symbol_ref(fixed)) {
  12674. fn = function() {
  12675. var result = init.optimize(compressor);
  12676. return result === init ? result.clone(true) : result;
  12677. };
  12678. } else {
  12679. value_length = Math.min(value_length, fixed.print_to_string().length);
  12680. fn = function() {
  12681. var result = best_of_expression(init.optimize(compressor), fixed);
  12682. return result === init || result === fixed ? result.clone(true) : result;
  12683. };
  12684. }
  12685. var name_length = d.name.length;
  12686. var overhead = 0;
  12687. if (compressor.option("unused") && !compressor.exposed(d)) {
  12688. overhead = (name_length + 2 + value_length) / (d.references.length - d.assignments);
  12689. }
  12690. d.should_replace = value_length <= name_length + overhead ? fn : false;
  12691. } else {
  12692. d.should_replace = false;
  12693. }
  12694. }
  12695. if (d.should_replace) {
  12696. return d.should_replace();
  12697. }
  12698. }
  12699. return self;
  12700. function has_symbol_ref(value) {
  12701. var found;
  12702. value.walk(new TreeWalker(function(node) {
  12703. if (node instanceof AST_SymbolRef) found = true;
  12704. if (found) return true;
  12705. }));
  12706. return found;
  12707. }
  12708. });
  12709. function is_atomic(lhs, self) {
  12710. return lhs instanceof AST_SymbolRef || lhs.TYPE === self.TYPE;
  12711. }
  12712. def_optimize(AST_Undefined, function(self, compressor) {
  12713. if (compressor.option("unsafe_undefined")) {
  12714. var undef = find_variable(compressor, "undefined");
  12715. if (undef) {
  12716. var ref = make_node(AST_SymbolRef, self, {
  12717. name : "undefined",
  12718. scope : undef.scope,
  12719. thedef : undef
  12720. });
  12721. ref.is_undefined = true;
  12722. return ref;
  12723. }
  12724. }
  12725. var lhs = is_lhs(compressor.self(), compressor.parent());
  12726. if (lhs && is_atomic(lhs, self)) return self;
  12727. return make_node(AST_UnaryPrefix, self, {
  12728. operator: "void",
  12729. expression: make_node(AST_Number, self, {
  12730. value: 0
  12731. })
  12732. });
  12733. });
  12734. def_optimize(AST_Infinity, function(self, compressor) {
  12735. var lhs = is_lhs(compressor.self(), compressor.parent());
  12736. if (lhs && is_atomic(lhs, self)) return self;
  12737. if (compressor.option("keep_infinity")
  12738. && !(lhs && !is_atomic(lhs, self))
  12739. && !find_variable(compressor, "Infinity"))
  12740. return self;
  12741. return make_node(AST_Binary, self, {
  12742. operator: "/",
  12743. left: make_node(AST_Number, self, {
  12744. value: 1
  12745. }),
  12746. right: make_node(AST_Number, self, {
  12747. value: 0
  12748. })
  12749. });
  12750. });
  12751. def_optimize(AST_NaN, function(self, compressor) {
  12752. var lhs = is_lhs(compressor.self(), compressor.parent());
  12753. if (lhs && !is_atomic(lhs, self)
  12754. || find_variable(compressor, "NaN")) {
  12755. return make_node(AST_Binary, self, {
  12756. operator: "/",
  12757. left: make_node(AST_Number, self, {
  12758. value: 0
  12759. }),
  12760. right: make_node(AST_Number, self, {
  12761. value: 0
  12762. })
  12763. });
  12764. }
  12765. return self;
  12766. });
  12767. function is_reachable(self, defs) {
  12768. var reachable = false;
  12769. var find_ref = new TreeWalker(function(node) {
  12770. if (reachable) return true;
  12771. if (node instanceof AST_SymbolRef && member(node.definition(), defs)) {
  12772. return reachable = true;
  12773. }
  12774. });
  12775. var scan_scope = new TreeWalker(function(node) {
  12776. if (reachable) return true;
  12777. if (node instanceof AST_Scope && node !== self) {
  12778. var parent = scan_scope.parent();
  12779. if (parent instanceof AST_Call && parent.expression === node) return;
  12780. node.walk(find_ref);
  12781. return true;
  12782. }
  12783. });
  12784. self.walk(scan_scope);
  12785. return reachable;
  12786. }
  12787. var ASSIGN_OPS = [ "+", "-", "/", "*", "%", ">>", "<<", ">>>", "|", "^", "&" ];
  12788. var ASSIGN_OPS_COMMUTATIVE = [ "*", "|", "^", "&" ];
  12789. def_optimize(AST_Assign, function(self, compressor) {
  12790. var def;
  12791. if (compressor.option("dead_code")
  12792. && self.left instanceof AST_SymbolRef
  12793. && (def = self.left.definition()).scope === compressor.find_parent(AST_Lambda)) {
  12794. var level = 0, node, parent = self;
  12795. do {
  12796. node = parent;
  12797. parent = compressor.parent(level++);
  12798. if (parent instanceof AST_Exit) {
  12799. if (in_try(level, parent)) break;
  12800. if (is_reachable(def.scope, [ def ])) break;
  12801. if (self.operator == "=") return self.right;
  12802. def.fixed = false;
  12803. return make_node(AST_Binary, self, {
  12804. operator: self.operator.slice(0, -1),
  12805. left: self.left,
  12806. right: self.right
  12807. }).optimize(compressor);
  12808. }
  12809. } while (parent instanceof AST_Binary && parent.right === node
  12810. || parent instanceof AST_Sequence && parent.tail_node() === node);
  12811. }
  12812. self = self.lift_sequences(compressor);
  12813. if (self.operator == "=" && self.left instanceof AST_SymbolRef && self.right instanceof AST_Binary) {
  12814. // x = expr1 OP expr2
  12815. if (self.right.left instanceof AST_SymbolRef
  12816. && self.right.left.name == self.left.name
  12817. && member(self.right.operator, ASSIGN_OPS)) {
  12818. // x = x - 2 ---> x -= 2
  12819. self.operator = self.right.operator + "=";
  12820. self.right = self.right.right;
  12821. } else if (self.right.right instanceof AST_SymbolRef
  12822. && self.right.right.name == self.left.name
  12823. && member(self.right.operator, ASSIGN_OPS_COMMUTATIVE)
  12824. && !self.right.left.has_side_effects(compressor)) {
  12825. // x = 2 & x ---> x &= 2
  12826. self.operator = self.right.operator + "=";
  12827. self.right = self.right.left;
  12828. }
  12829. }
  12830. return self;
  12831. function in_try(level, node) {
  12832. var right = self.right;
  12833. self.right = make_node(AST_Null, right);
  12834. var may_throw = node.may_throw(compressor);
  12835. self.right = right;
  12836. var scope = self.left.definition().scope;
  12837. var parent;
  12838. while ((parent = compressor.parent(level++)) !== scope) {
  12839. if (parent instanceof AST_Try) {
  12840. if (parent.bfinally) return true;
  12841. if (may_throw && parent.bcatch) return true;
  12842. }
  12843. }
  12844. }
  12845. });
  12846. def_optimize(AST_DefaultAssign, function(self, compressor) {
  12847. if (!compressor.option("evaluate")) {
  12848. return self;
  12849. }
  12850. var evaluateRight = self.right.evaluate(compressor);
  12851. // `[x = undefined] = foo` ---> `[x] = foo`
  12852. if (evaluateRight === undefined) {
  12853. self = self.left;
  12854. } else if (evaluateRight !== self.right) {
  12855. evaluateRight = make_node_from_constant(evaluateRight, self.right);
  12856. self.right = best_of_expression(evaluateRight, self.right);
  12857. }
  12858. return self;
  12859. });
  12860. def_optimize(AST_Conditional, function(self, compressor) {
  12861. if (!compressor.option("conditionals")) return self;
  12862. // This looks like lift_sequences(), should probably be under "sequences"
  12863. if (self.condition instanceof AST_Sequence) {
  12864. var expressions = self.condition.expressions.slice();
  12865. self.condition = expressions.pop();
  12866. expressions.push(self);
  12867. return make_sequence(self, expressions);
  12868. }
  12869. var cond = self.condition.evaluate(compressor);
  12870. if (cond !== self.condition) {
  12871. if (cond) {
  12872. compressor.warn("Condition always true [{file}:{line},{col}]", self.start);
  12873. return maintain_this_binding(compressor.parent(), compressor.self(), self.consequent);
  12874. } else {
  12875. compressor.warn("Condition always false [{file}:{line},{col}]", self.start);
  12876. return maintain_this_binding(compressor.parent(), compressor.self(), self.alternative);
  12877. }
  12878. }
  12879. var negated = cond.negate(compressor, first_in_statement(compressor));
  12880. if (best_of(compressor, cond, negated) === negated) {
  12881. self = make_node(AST_Conditional, self, {
  12882. condition: negated,
  12883. consequent: self.alternative,
  12884. alternative: self.consequent
  12885. });
  12886. }
  12887. var condition = self.condition;
  12888. var consequent = self.consequent;
  12889. var alternative = self.alternative;
  12890. // x?x:y --> x||y
  12891. if (condition instanceof AST_SymbolRef
  12892. && consequent instanceof AST_SymbolRef
  12893. && condition.definition() === consequent.definition()) {
  12894. return make_node(AST_Binary, self, {
  12895. operator: "||",
  12896. left: condition,
  12897. right: alternative
  12898. });
  12899. }
  12900. // if (foo) exp = something; else exp = something_else;
  12901. // |
  12902. // v
  12903. // exp = foo ? something : something_else;
  12904. if (consequent instanceof AST_Assign
  12905. && alternative instanceof AST_Assign
  12906. && consequent.operator == alternative.operator
  12907. && consequent.left.equivalent_to(alternative.left)
  12908. && (!self.condition.has_side_effects(compressor)
  12909. || consequent.operator == "="
  12910. && !consequent.left.has_side_effects(compressor))) {
  12911. return make_node(AST_Assign, self, {
  12912. operator: consequent.operator,
  12913. left: consequent.left,
  12914. right: make_node(AST_Conditional, self, {
  12915. condition: self.condition,
  12916. consequent: consequent.right,
  12917. alternative: alternative.right
  12918. })
  12919. });
  12920. }
  12921. // x ? y(a) : y(b) --> y(x ? a : b)
  12922. var arg_index;
  12923. if (consequent instanceof AST_Call
  12924. && alternative.TYPE === consequent.TYPE
  12925. && consequent.args.length > 0
  12926. && consequent.args.length == alternative.args.length
  12927. && consequent.expression.equivalent_to(alternative.expression)
  12928. && !self.condition.has_side_effects(compressor)
  12929. && !consequent.expression.has_side_effects(compressor)
  12930. && typeof (arg_index = single_arg_diff()) == "number") {
  12931. var node = consequent.clone();
  12932. node.args[arg_index] = make_node(AST_Conditional, self, {
  12933. condition: self.condition,
  12934. consequent: consequent.args[arg_index],
  12935. alternative: alternative.args[arg_index]
  12936. });
  12937. return node;
  12938. }
  12939. // x?y?z:a:a --> x&&y?z:a
  12940. if (consequent instanceof AST_Conditional
  12941. && consequent.alternative.equivalent_to(alternative)) {
  12942. return make_node(AST_Conditional, self, {
  12943. condition: make_node(AST_Binary, self, {
  12944. left: self.condition,
  12945. operator: "&&",
  12946. right: consequent.condition
  12947. }),
  12948. consequent: consequent.consequent,
  12949. alternative: alternative
  12950. });
  12951. }
  12952. // x ? y : y --> x, y
  12953. if (consequent.equivalent_to(alternative)) {
  12954. return make_sequence(self, [
  12955. self.condition,
  12956. consequent
  12957. ]).optimize(compressor);
  12958. }
  12959. // x ? y || z : z --> x && y || z
  12960. if (consequent instanceof AST_Binary
  12961. && consequent.operator == "||"
  12962. && consequent.right.equivalent_to(alternative)) {
  12963. return make_node(AST_Binary, self, {
  12964. operator: "||",
  12965. left: make_node(AST_Binary, self, {
  12966. operator: "&&",
  12967. left: self.condition,
  12968. right: consequent.left
  12969. }),
  12970. right: alternative
  12971. }).optimize(compressor);
  12972. }
  12973. var in_bool = compressor.in_boolean_context();
  12974. if (is_true(self.consequent)) {
  12975. if (is_false(self.alternative)) {
  12976. // c ? true : false ---> !!c
  12977. return booleanize(self.condition);
  12978. }
  12979. // c ? true : x ---> !!c || x
  12980. return make_node(AST_Binary, self, {
  12981. operator: "||",
  12982. left: booleanize(self.condition),
  12983. right: self.alternative
  12984. });
  12985. }
  12986. if (is_false(self.consequent)) {
  12987. if (is_true(self.alternative)) {
  12988. // c ? false : true ---> !c
  12989. return booleanize(self.condition.negate(compressor));
  12990. }
  12991. // c ? false : x ---> !c && x
  12992. return make_node(AST_Binary, self, {
  12993. operator: "&&",
  12994. left: booleanize(self.condition.negate(compressor)),
  12995. right: self.alternative
  12996. });
  12997. }
  12998. if (is_true(self.alternative)) {
  12999. // c ? x : true ---> !c || x
  13000. return make_node(AST_Binary, self, {
  13001. operator: "||",
  13002. left: booleanize(self.condition.negate(compressor)),
  13003. right: self.consequent
  13004. });
  13005. }
  13006. if (is_false(self.alternative)) {
  13007. // c ? x : false ---> !!c && x
  13008. return make_node(AST_Binary, self, {
  13009. operator: "&&",
  13010. left: booleanize(self.condition),
  13011. right: self.consequent
  13012. });
  13013. }
  13014. return self;
  13015. function booleanize(node) {
  13016. if (node.is_boolean()) return node;
  13017. // !!expression
  13018. return make_node(AST_UnaryPrefix, node, {
  13019. operator: "!",
  13020. expression: node.negate(compressor)
  13021. });
  13022. }
  13023. // AST_True or !0
  13024. function is_true(node) {
  13025. return node instanceof AST_True
  13026. || in_bool
  13027. && node instanceof AST_Constant
  13028. && node.getValue()
  13029. || (node instanceof AST_UnaryPrefix
  13030. && node.operator == "!"
  13031. && node.expression instanceof AST_Constant
  13032. && !node.expression.getValue());
  13033. }
  13034. // AST_False or !1
  13035. function is_false(node) {
  13036. return node instanceof AST_False
  13037. || in_bool
  13038. && node instanceof AST_Constant
  13039. && !node.getValue()
  13040. || (node instanceof AST_UnaryPrefix
  13041. && node.operator == "!"
  13042. && node.expression instanceof AST_Constant
  13043. && node.expression.getValue());
  13044. }
  13045. function single_arg_diff() {
  13046. var a = consequent.args;
  13047. var b = alternative.args;
  13048. for (var i = 0, len = a.length; i < len; i++) {
  13049. if (a[i] instanceof AST_Expansion) return;
  13050. if (!a[i].equivalent_to(b[i])) {
  13051. if (b[i] instanceof AST_Expansion) return;
  13052. for (var j = i + 1; j < len; j++) {
  13053. if (a[j] instanceof AST_Expansion) return;
  13054. if (!a[j].equivalent_to(b[j])) return;
  13055. }
  13056. return i;
  13057. }
  13058. }
  13059. }
  13060. });
  13061. def_optimize(AST_Boolean, function(self, compressor) {
  13062. if (compressor.in_boolean_context()) return make_node(AST_Number, self, {
  13063. value: +self.value
  13064. });
  13065. var p = compressor.parent();
  13066. if (compressor.option("booleans_as_integers")) {
  13067. if (p instanceof AST_Binary && (p.operator == "===" || p.operator == "!==")) {
  13068. p.operator = p.operator.replace(/=$/, "");
  13069. }
  13070. return make_node(AST_Number, self, {
  13071. value: +self.value
  13072. });
  13073. }
  13074. if (compressor.option("booleans")) {
  13075. if (p instanceof AST_Binary && (p.operator == "=="
  13076. || p.operator == "!=")) {
  13077. compressor.warn("Non-strict equality against boolean: {operator} {value} [{file}:{line},{col}]", {
  13078. operator : p.operator,
  13079. value : self.value,
  13080. file : p.start.file,
  13081. line : p.start.line,
  13082. col : p.start.col,
  13083. });
  13084. return make_node(AST_Number, self, {
  13085. value: +self.value
  13086. });
  13087. }
  13088. return make_node(AST_UnaryPrefix, self, {
  13089. operator: "!",
  13090. expression: make_node(AST_Number, self, {
  13091. value: 1 - self.value
  13092. })
  13093. });
  13094. }
  13095. return self;
  13096. });
  13097. function safe_to_flatten(value, compressor) {
  13098. if (value instanceof AST_SymbolRef) {
  13099. value = value.fixed_value();
  13100. }
  13101. if (!value) return false;
  13102. return !(value instanceof AST_Lambda || value instanceof AST_Class)
  13103. || compressor.parent() instanceof AST_New
  13104. || !value.contains_this();
  13105. }
  13106. def_optimize(AST_Sub, function(self, compressor) {
  13107. var expr = self.expression;
  13108. var prop = self.property;
  13109. if (compressor.option("properties")) {
  13110. var key = prop.evaluate(compressor);
  13111. if (key !== prop) {
  13112. if (typeof key == "string") {
  13113. if (key == "undefined") {
  13114. key = undefined;
  13115. } else {
  13116. var value = parseFloat(key);
  13117. if (value.toString() == key) {
  13118. key = value;
  13119. }
  13120. }
  13121. }
  13122. prop = self.property = best_of_expression(prop, make_node_from_constant(key, prop).transform(compressor));
  13123. var property = "" + key;
  13124. if (is_identifier_string(property)
  13125. && property.length <= prop.print_to_string().length + 1) {
  13126. return make_node(AST_Dot, self, {
  13127. expression: expr,
  13128. property: property
  13129. }).optimize(compressor);
  13130. }
  13131. }
  13132. }
  13133. var fn;
  13134. OPT_ARGUMENTS: if (compressor.option("arguments")
  13135. && expr instanceof AST_SymbolRef
  13136. && expr.name == "arguments"
  13137. && expr.definition().orig.length == 1
  13138. && (fn = expr.scope) instanceof AST_Lambda
  13139. && fn.uses_arguments
  13140. && !(fn instanceof AST_Arrow)
  13141. && prop instanceof AST_Number) {
  13142. var index = prop.getValue();
  13143. var params = Object.create(null);
  13144. var argnames = fn.argnames;
  13145. for (var n = 0; n < argnames.length; n++) {
  13146. if (!(argnames[n] instanceof AST_SymbolFunarg)) {
  13147. break OPT_ARGUMENTS; // destructuring parameter - bail
  13148. }
  13149. var param = argnames[n].name;
  13150. if (param in params) {
  13151. break OPT_ARGUMENTS; // duplicate parameter - bail
  13152. }
  13153. params[param] = true;
  13154. }
  13155. var argname = fn.argnames[index];
  13156. if (argname && compressor.has_directive("use strict")) {
  13157. var def = argname.definition();
  13158. if (!compressor.option("reduce_vars") || def.assignments || def.orig.length > 1) {
  13159. argname = null;
  13160. }
  13161. } else if (!argname && !compressor.option("keep_fargs") && index < fn.argnames.length + 5) {
  13162. while (index >= fn.argnames.length) {
  13163. argname = make_node(AST_SymbolFunarg, fn, {
  13164. name: fn.make_var_name("argument_" + fn.argnames.length),
  13165. scope: fn
  13166. });
  13167. fn.argnames.push(argname);
  13168. fn.enclosed.push(fn.def_variable(argname));
  13169. }
  13170. }
  13171. if (argname) {
  13172. var sym = make_node(AST_SymbolRef, self, argname);
  13173. sym.reference({});
  13174. delete argname.__unused;
  13175. return sym;
  13176. }
  13177. }
  13178. if (is_lhs(self, compressor.parent())) return self;
  13179. if (key !== prop) {
  13180. var sub = self.flatten_object(property, compressor);
  13181. if (sub) {
  13182. expr = self.expression = sub.expression;
  13183. prop = self.property = sub.property;
  13184. }
  13185. }
  13186. if (compressor.option("properties") && compressor.option("side_effects")
  13187. && prop instanceof AST_Number && expr instanceof AST_Array) {
  13188. var index = prop.getValue();
  13189. var elements = expr.elements;
  13190. var retValue = elements[index];
  13191. FLATTEN: if (safe_to_flatten(retValue, compressor)) {
  13192. var flatten = true;
  13193. var values = [];
  13194. for (var i = elements.length; --i > index;) {
  13195. var value = elements[i].drop_side_effect_free(compressor);
  13196. if (value) {
  13197. values.unshift(value);
  13198. if (flatten && value.has_side_effects(compressor)) flatten = false;
  13199. }
  13200. }
  13201. if (retValue instanceof AST_Expansion) break FLATTEN;
  13202. retValue = retValue instanceof AST_Hole ? make_node(AST_Undefined, retValue) : retValue;
  13203. if (!flatten) values.unshift(retValue);
  13204. while (--i >= 0) {
  13205. var value = elements[i];
  13206. if (value instanceof AST_Expansion) break FLATTEN;
  13207. value = value.drop_side_effect_free(compressor);
  13208. if (value) values.unshift(value);
  13209. else index--;
  13210. }
  13211. if (flatten) {
  13212. values.push(retValue);
  13213. return make_sequence(self, values).optimize(compressor);
  13214. } else return make_node(AST_Sub, self, {
  13215. expression: make_node(AST_Array, expr, {
  13216. elements: values
  13217. }),
  13218. property: make_node(AST_Number, prop, {
  13219. value: index
  13220. })
  13221. });
  13222. }
  13223. }
  13224. var ev = self.evaluate(compressor);
  13225. if (ev !== self) {
  13226. ev = make_node_from_constant(ev, self).optimize(compressor);
  13227. return best_of(compressor, ev, self);
  13228. }
  13229. return self;
  13230. });
  13231. AST_Lambda.DEFMETHOD("contains_this", function() {
  13232. var result;
  13233. var self = this;
  13234. self.walk(new TreeWalker(function(node) {
  13235. if (result) return true;
  13236. if (node instanceof AST_This) return result = true;
  13237. if (node !== self && node instanceof AST_Scope && !(node instanceof AST_Arrow)) return true;
  13238. }));
  13239. return result;
  13240. });
  13241. AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
  13242. if (!compressor.option("properties")) return;
  13243. var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 6;
  13244. var expr = this.expression;
  13245. if (expr instanceof AST_Object) {
  13246. var props = expr.properties;
  13247. for (var i = props.length; --i >= 0;) {
  13248. var prop = props[i];
  13249. if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) {
  13250. if (!all(props, function(prop) {
  13251. return prop instanceof AST_ObjectKeyVal
  13252. || arrows && prop instanceof AST_ConciseMethod && !prop.is_generator;
  13253. })) break;
  13254. if (!safe_to_flatten(prop.value, compressor)) break;
  13255. return make_node(AST_Sub, this, {
  13256. expression: make_node(AST_Array, expr, {
  13257. elements: props.map(function(prop) {
  13258. var v = prop.value;
  13259. if (v instanceof AST_Accessor) v = make_node(AST_Function, v, v);
  13260. var k = prop.key;
  13261. if (k instanceof AST_Node && !(k instanceof AST_SymbolMethod)) {
  13262. return make_sequence(prop, [ k, v ]);
  13263. }
  13264. return v;
  13265. })
  13266. }),
  13267. property: make_node(AST_Number, this, {
  13268. value: i
  13269. })
  13270. });
  13271. }
  13272. }
  13273. }
  13274. });
  13275. def_optimize(AST_Dot, function(self, compressor) {
  13276. if (self.property == "arguments" || self.property == "caller") {
  13277. compressor.warn("Function.prototype.{prop} not supported [{file}:{line},{col}]", {
  13278. prop: self.property,
  13279. file: self.start.file,
  13280. line: self.start.line,
  13281. col: self.start.col
  13282. });
  13283. }
  13284. if (is_lhs(self, compressor.parent())) return self;
  13285. if (compressor.option("unsafe_proto")
  13286. && self.expression instanceof AST_Dot
  13287. && self.expression.property == "prototype") {
  13288. var exp = self.expression.expression;
  13289. if (is_undeclared_ref(exp)) switch (exp.name) {
  13290. case "Array":
  13291. self.expression = make_node(AST_Array, self.expression, {
  13292. elements: []
  13293. });
  13294. break;
  13295. case "Function":
  13296. self.expression = make_node(AST_Function, self.expression, {
  13297. argnames: [],
  13298. body: []
  13299. });
  13300. break;
  13301. case "Number":
  13302. self.expression = make_node(AST_Number, self.expression, {
  13303. value: 0
  13304. });
  13305. break;
  13306. case "Object":
  13307. self.expression = make_node(AST_Object, self.expression, {
  13308. properties: []
  13309. });
  13310. break;
  13311. case "RegExp":
  13312. self.expression = make_node(AST_RegExp, self.expression, {
  13313. value: /t/
  13314. });
  13315. break;
  13316. case "String":
  13317. self.expression = make_node(AST_String, self.expression, {
  13318. value: ""
  13319. });
  13320. break;
  13321. }
  13322. }
  13323. var sub = self.flatten_object(self.property, compressor);
  13324. if (sub) return sub.optimize(compressor);
  13325. var ev = self.evaluate(compressor);
  13326. if (ev !== self) {
  13327. ev = make_node_from_constant(ev, self).optimize(compressor);
  13328. return best_of(compressor, ev, self);
  13329. }
  13330. return self;
  13331. });
  13332. function literals_in_boolean_context(self, compressor) {
  13333. if (compressor.in_boolean_context()) {
  13334. return best_of(compressor, self, make_sequence(self, [
  13335. self,
  13336. make_node(AST_True, self)
  13337. ]).optimize(compressor));
  13338. }
  13339. return self;
  13340. }
  13341. function inline_array_like_spread(self, compressor, elements) {
  13342. for (var i = 0; i < elements.length; i++) {
  13343. var el = elements[i];
  13344. if (el instanceof AST_Expansion) {
  13345. var expr = el.expression;
  13346. if ( expr instanceof AST_Array) {
  13347. elements.splice.apply(elements, [i, 1].concat(expr.elements));
  13348. // Step back one, as the element at i is now new.
  13349. i--;
  13350. }
  13351. // In array-like spread, spreading a non-iterable value is TypeError.
  13352. // We therefore can’t optimize anything else, unlike with object spread.
  13353. }
  13354. }
  13355. return self;
  13356. }
  13357. def_optimize(AST_Array, function(self, compressor) {
  13358. var optimized = literals_in_boolean_context(self, compressor);
  13359. if (optimized !== self) {
  13360. return optimized;
  13361. }
  13362. return inline_array_like_spread(self, compressor, self.elements);
  13363. });
  13364. def_optimize(AST_Object, function(self, compressor) {
  13365. var optimized = literals_in_boolean_context(self, compressor);
  13366. if (optimized !== self) {
  13367. return optimized;
  13368. }
  13369. var props = self.properties;
  13370. for (var i = 0; i < props.length; i++) {
  13371. var prop = props[i];
  13372. if (prop instanceof AST_Expansion) {
  13373. var expr = prop.expression;
  13374. if (expr instanceof AST_Object) {
  13375. props.splice.apply(props, [i, 1].concat(prop.expression.properties));
  13376. // Step back one, as the property at i is now new.
  13377. i--;
  13378. } else if (expr instanceof AST_Constant
  13379. && !(expr instanceof AST_String)) {
  13380. // Unlike array-like spread, in object spread, spreading a
  13381. // non-iterable value silently does nothing; it is thus safe
  13382. // to remove. AST_String is the only iterable AST_Constant.
  13383. props.splice(i, 1);
  13384. }
  13385. }
  13386. }
  13387. return self;
  13388. });
  13389. def_optimize(AST_RegExp, literals_in_boolean_context);
  13390. def_optimize(AST_Return, function(self, compressor) {
  13391. if (self.value && is_undefined(self.value, compressor)) {
  13392. self.value = null;
  13393. }
  13394. return self;
  13395. });
  13396. def_optimize(AST_Arrow, function(self, compressor) {
  13397. if (!(self.body instanceof AST_Node)) {
  13398. self = opt_AST_Lambda(self, compressor);
  13399. }
  13400. if (compressor.option("arrows")
  13401. && self.body.length == 1
  13402. && self.body[0] instanceof AST_Return) {
  13403. var value = self.body[0].value;
  13404. self.body = value ? value : [];
  13405. }
  13406. return self;
  13407. });
  13408. def_optimize(AST_Function, function(self, compressor) {
  13409. self = opt_AST_Lambda(self, compressor);
  13410. if (compressor.option("unsafe_arrows")
  13411. && compressor.option("ecma") >= 6
  13412. && !self.name
  13413. && !self.is_generator
  13414. && !self.uses_arguments
  13415. && !self.pinned()) {
  13416. var has_special_symbol = false;
  13417. self.walk(new TreeWalker(function(node) {
  13418. if (has_special_symbol) return true;
  13419. if (node instanceof AST_This) {
  13420. has_special_symbol = true;
  13421. return true;
  13422. }
  13423. }));
  13424. if (!has_special_symbol) return make_node(AST_Arrow, self, self).optimize(compressor);
  13425. }
  13426. return self;
  13427. });
  13428. def_optimize(AST_Class, function(self, compressor) {
  13429. // HACK to avoid compress failure.
  13430. // AST_Class is not really an AST_Scope/AST_Block as it lacks a body.
  13431. return self;
  13432. });
  13433. def_optimize(AST_Yield, function(self, compressor) {
  13434. if (self.expression && !self.is_star && is_undefined(self.expression, compressor)) {
  13435. self.expression = null;
  13436. }
  13437. return self;
  13438. });
  13439. def_optimize(AST_TemplateString, function(self, compressor) {
  13440. if (!compressor.option("evaluate")
  13441. || compressor.parent() instanceof AST_PrefixedTemplateString)
  13442. return self;
  13443. var segments = [];
  13444. for (var i = 0; i < self.segments.length; i++) {
  13445. var segment = self.segments[i];
  13446. if (segment instanceof AST_Node) {
  13447. var result = segment.evaluate(compressor);
  13448. // Evaluate to constant value
  13449. // Constant value shorter than ${segment}
  13450. if (result !== segment && (result + "").length <= segment.print_to_string().length + "${}".length) {
  13451. // There should always be a previous and next segment if segment is a node
  13452. segments[segments.length - 1].value = segments[segments.length - 1].value + result + self.segments[++i].value;
  13453. continue;
  13454. }
  13455. }
  13456. segments.push(segment);
  13457. }
  13458. self.segments = segments;
  13459. return segments.length == 1 ? make_node(AST_String, self, segments[0]) : self;
  13460. });
  13461. def_optimize(AST_PrefixedTemplateString, function(self, compressor) {
  13462. return self;
  13463. });
  13464. // ["p"]:1 ---> p:1
  13465. // [42]:1 ---> 42:1
  13466. function lift_key(self, compressor) {
  13467. if (!compressor.option("computed_props")) return self;
  13468. // save a comparison in the typical case
  13469. if (!(self.key instanceof AST_Constant)) return self;
  13470. // whitelist acceptable props as not all AST_Constants are true constants
  13471. if (self.key instanceof AST_String || self.key instanceof AST_Number) {
  13472. if (self.key.value === "__proto__") return self;
  13473. if (self.key.value == "constructor"
  13474. && compressor.parent() instanceof AST_Class) return self;
  13475. if (self instanceof AST_ObjectKeyVal) {
  13476. self.key = self.key.value;
  13477. } else {
  13478. self.key = make_node(AST_SymbolMethod, self.key, {
  13479. name: self.key.value
  13480. });
  13481. }
  13482. }
  13483. return self;
  13484. }
  13485. def_optimize(AST_ObjectProperty, lift_key);
  13486. def_optimize(AST_ConciseMethod, function(self, compressor) {
  13487. lift_key(self, compressor);
  13488. // p(){return x;} ---> p:()=>x
  13489. if (compressor.option("arrows")
  13490. && compressor.parent() instanceof AST_Object
  13491. && !self.is_generator
  13492. && !self.value.uses_arguments
  13493. && !self.value.pinned()
  13494. && self.value.body.length == 1
  13495. && self.value.body[0] instanceof AST_Return
  13496. && self.value.body[0].value
  13497. && !self.value.contains_this()) {
  13498. var arrow = make_node(AST_Arrow, self.value, self.value);
  13499. arrow.async = self.async;
  13500. arrow.is_generator = self.is_generator;
  13501. return make_node(AST_ObjectKeyVal, self, {
  13502. key: self.key instanceof AST_SymbolMethod ? self.key.name : self.key,
  13503. value: arrow,
  13504. quote: self.quote,
  13505. });
  13506. }
  13507. return self;
  13508. });
  13509. def_optimize(AST_ObjectKeyVal, function(self, compressor) {
  13510. lift_key(self, compressor);
  13511. // p:function(){} ---> p(){}
  13512. // p:function*(){} ---> *p(){}
  13513. // p:async function(){} ---> async p(){}
  13514. // p:()=>{} ---> p(){}
  13515. // p:async()=>{} ---> async p(){}
  13516. var unsafe_methods = compressor.option("unsafe_methods");
  13517. if (unsafe_methods
  13518. && compressor.option("ecma") >= 6
  13519. && (!(unsafe_methods instanceof RegExp) || unsafe_methods.test(self.key + ""))) {
  13520. var key = self.key;
  13521. var value = self.value;
  13522. var is_arrow_with_block = value instanceof AST_Arrow
  13523. && Array.isArray(value.body)
  13524. && !value.contains_this();
  13525. if ((is_arrow_with_block || value instanceof AST_Function) && !value.name) {
  13526. return make_node(AST_ConciseMethod, self, {
  13527. async: value.async,
  13528. is_generator: value.is_generator,
  13529. key: key instanceof AST_Node ? key : make_node(AST_SymbolMethod, self, {
  13530. name: key,
  13531. }),
  13532. value: make_node(AST_Accessor, value, value),
  13533. quote: self.quote,
  13534. });
  13535. }
  13536. }
  13537. return self;
  13538. });
  13539. def_optimize(AST_Destructuring, function(self, compressor) {
  13540. if (compressor.option("pure_getters") == true
  13541. && compressor.option("unused")
  13542. && !self.is_array
  13543. && Array.isArray(self.names)
  13544. && !is_destructuring_export_decl(compressor)) {
  13545. var keep = [];
  13546. for (var i = 0; i < self.names.length; i++) {
  13547. var elem = self.names[i];
  13548. if (!(elem instanceof AST_ObjectKeyVal
  13549. && typeof elem.key == "string"
  13550. && elem.value instanceof AST_SymbolDeclaration
  13551. && !should_retain(compressor, elem.value.definition()))) {
  13552. keep.push(elem);
  13553. }
  13554. }
  13555. if (keep.length != self.names.length) {
  13556. self.names = keep;
  13557. }
  13558. }
  13559. return self;
  13560. function is_destructuring_export_decl(compressor) {
  13561. var ancestors = [/^VarDef$/, /^(Const|Let|Var)$/, /^Export$/];
  13562. for (var a = 0, p = 0, len = ancestors.length; a < len; p++) {
  13563. var parent = compressor.parent(p);
  13564. if (!parent) return false;
  13565. if (a === 0 && parent.TYPE == "Destructuring") continue;
  13566. if (!ancestors[a].test(parent.TYPE)) {
  13567. return false;
  13568. }
  13569. a++;
  13570. }
  13571. return true;
  13572. }
  13573. function should_retain(compressor, def) {
  13574. if (def.references.length) return true;
  13575. if (!def.global) return false;
  13576. if (compressor.toplevel.vars) {
  13577. if (compressor.top_retain) {
  13578. return compressor.top_retain(def);
  13579. }
  13580. return false;
  13581. }
  13582. return true;
  13583. }
  13584. });
  13585. })();
  13586. /***********************************************************************
  13587. A JavaScript tokenizer / parser / beautifier / compressor.
  13588. https://github.com/mishoo/UglifyJS2
  13589. -------------------------------- (C) ---------------------------------
  13590. Author: Mihai Bazon
  13591. <mihai.bazon@gmail.com>
  13592. http://mihai.bazon.net/blog
  13593. Distributed under the BSD license:
  13594. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  13595. Redistribution and use in source and binary forms, with or without
  13596. modification, are permitted provided that the following conditions
  13597. are met:
  13598. * Redistributions of source code must retain the above
  13599. copyright notice, this list of conditions and the following
  13600. disclaimer.
  13601. * Redistributions in binary form must reproduce the above
  13602. copyright notice, this list of conditions and the following
  13603. disclaimer in the documentation and/or other materials
  13604. provided with the distribution.
  13605. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  13606. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  13607. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  13608. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  13609. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  13610. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  13611. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  13612. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13613. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  13614. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  13615. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  13616. SUCH DAMAGE.
  13617. ***********************************************************************/
  13618. // a small wrapper around fitzgen's source-map library
  13619. function SourceMap(options) {
  13620. options = defaults(options, {
  13621. file : null,
  13622. root : null,
  13623. orig : null,
  13624. orig_line_diff : 0,
  13625. dest_line_diff : 0,
  13626. });
  13627. var generator = new MOZ_SourceMap.SourceMapGenerator({
  13628. file : options.file,
  13629. sourceRoot : options.root
  13630. });
  13631. var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
  13632. if (orig_map) {
  13633. orig_map.sources.forEach(function(source) {
  13634. var sourceContent = orig_map.sourceContentFor(source, true);
  13635. if (sourceContent) {
  13636. generator.setSourceContent(source, sourceContent);
  13637. }
  13638. });
  13639. }
  13640. function add(source, gen_line, gen_col, orig_line, orig_col, name) {
  13641. if (orig_map) {
  13642. var info = orig_map.originalPositionFor({
  13643. line: orig_line,
  13644. column: orig_col
  13645. });
  13646. if (info.source === null) {
  13647. return;
  13648. }
  13649. source = info.source;
  13650. orig_line = info.line;
  13651. orig_col = info.column;
  13652. name = info.name || name;
  13653. }
  13654. generator.addMapping({
  13655. generated : { line: gen_line + options.dest_line_diff, column: gen_col },
  13656. original : { line: orig_line + options.orig_line_diff, column: orig_col },
  13657. source : source,
  13658. name : name
  13659. });
  13660. }
  13661. return {
  13662. add : add,
  13663. get : function() { return generator; },
  13664. toString : function() { return JSON.stringify(generator.toJSON()); }
  13665. };
  13666. }
  13667. var domprops = [
  13668. "$&",
  13669. "$'",
  13670. "$*",
  13671. "$+",
  13672. "$1",
  13673. "$2",
  13674. "$3",
  13675. "$4",
  13676. "$5",
  13677. "$6",
  13678. "$7",
  13679. "$8",
  13680. "$9",
  13681. "$_",
  13682. "$`",
  13683. "$input",
  13684. "@@iterator",
  13685. "ABORT_ERR",
  13686. "ACTIVE",
  13687. "ACTIVE_ATTRIBUTES",
  13688. "ACTIVE_TEXTURE",
  13689. "ACTIVE_UNIFORMS",
  13690. "ADDITION",
  13691. "ALIASED_LINE_WIDTH_RANGE",
  13692. "ALIASED_POINT_SIZE_RANGE",
  13693. "ALLOW_KEYBOARD_INPUT",
  13694. "ALLPASS",
  13695. "ALPHA",
  13696. "ALPHA_BITS",
  13697. "ALT_MASK",
  13698. "ALWAYS",
  13699. "ANY_TYPE",
  13700. "ANY_UNORDERED_NODE_TYPE",
  13701. "ARRAY_BUFFER",
  13702. "ARRAY_BUFFER_BINDING",
  13703. "ATTACHED_SHADERS",
  13704. "ATTRIBUTE_NODE",
  13705. "AT_TARGET",
  13706. "AddSearchProvider",
  13707. "AnalyserNode",
  13708. "AnimationEvent",
  13709. "AnonXMLHttpRequest",
  13710. "ApplicationCache",
  13711. "ApplicationCacheErrorEvent",
  13712. "Array",
  13713. "ArrayBuffer",
  13714. "Attr",
  13715. "Audio",
  13716. "AudioBuffer",
  13717. "AudioBufferSourceNode",
  13718. "AudioContext",
  13719. "AudioDestinationNode",
  13720. "AudioListener",
  13721. "AudioNode",
  13722. "AudioParam",
  13723. "AudioProcessingEvent",
  13724. "AudioStreamTrack",
  13725. "AutocompleteErrorEvent",
  13726. "BACK",
  13727. "BAD_BOUNDARYPOINTS_ERR",
  13728. "BANDPASS",
  13729. "BLEND",
  13730. "BLEND_COLOR",
  13731. "BLEND_DST_ALPHA",
  13732. "BLEND_DST_RGB",
  13733. "BLEND_EQUATION",
  13734. "BLEND_EQUATION_ALPHA",
  13735. "BLEND_EQUATION_RGB",
  13736. "BLEND_SRC_ALPHA",
  13737. "BLEND_SRC_RGB",
  13738. "BLUE_BITS",
  13739. "BLUR",
  13740. "BOOL",
  13741. "BOOLEAN_TYPE",
  13742. "BOOL_VEC2",
  13743. "BOOL_VEC3",
  13744. "BOOL_VEC4",
  13745. "BOTH",
  13746. "BROWSER_DEFAULT_WEBGL",
  13747. "BUBBLING_PHASE",
  13748. "BUFFER_SIZE",
  13749. "BUFFER_USAGE",
  13750. "BYTE",
  13751. "BYTES_PER_ELEMENT",
  13752. "BarProp",
  13753. "BaseHref",
  13754. "BatteryManager",
  13755. "BeforeLoadEvent",
  13756. "BeforeUnloadEvent",
  13757. "BiquadFilterNode",
  13758. "Blob",
  13759. "BlobEvent",
  13760. "Boolean",
  13761. "CAPTURING_PHASE",
  13762. "CCW",
  13763. "CDATASection",
  13764. "CDATA_SECTION_NODE",
  13765. "CHANGE",
  13766. "CHARSET_RULE",
  13767. "CHECKING",
  13768. "CLAMP_TO_EDGE",
  13769. "CLICK",
  13770. "CLOSED",
  13771. "CLOSING",
  13772. "COLOR_ATTACHMENT0",
  13773. "COLOR_BUFFER_BIT",
  13774. "COLOR_CLEAR_VALUE",
  13775. "COLOR_WRITEMASK",
  13776. "COMMENT_NODE",
  13777. "COMPILE_STATUS",
  13778. "COMPRESSED_RGBA_S3TC_DXT1_EXT",
  13779. "COMPRESSED_RGBA_S3TC_DXT3_EXT",
  13780. "COMPRESSED_RGBA_S3TC_DXT5_EXT",
  13781. "COMPRESSED_RGB_S3TC_DXT1_EXT",
  13782. "COMPRESSED_TEXTURE_FORMATS",
  13783. "CONNECTING",
  13784. "CONSTANT_ALPHA",
  13785. "CONSTANT_COLOR",
  13786. "CONSTRAINT_ERR",
  13787. "CONTEXT_LOST_WEBGL",
  13788. "CONTROL_MASK",
  13789. "COUNTER_STYLE_RULE",
  13790. "CSS",
  13791. "CSS2Properties",
  13792. "CSSCharsetRule",
  13793. "CSSConditionRule",
  13794. "CSSCounterStyleRule",
  13795. "CSSFontFaceRule",
  13796. "CSSFontFeatureValuesRule",
  13797. "CSSGroupingRule",
  13798. "CSSImportRule",
  13799. "CSSKeyframeRule",
  13800. "CSSKeyframesRule",
  13801. "CSSMediaRule",
  13802. "CSSMozDocumentRule",
  13803. "CSSNameSpaceRule",
  13804. "CSSPageRule",
  13805. "CSSPrimitiveValue",
  13806. "CSSRule",
  13807. "CSSRuleList",
  13808. "CSSStyleDeclaration",
  13809. "CSSStyleRule",
  13810. "CSSStyleSheet",
  13811. "CSSSupportsRule",
  13812. "CSSUnknownRule",
  13813. "CSSValue",
  13814. "CSSValueList",
  13815. "CSSVariablesDeclaration",
  13816. "CSSVariablesRule",
  13817. "CSSViewportRule",
  13818. "CSS_ATTR",
  13819. "CSS_CM",
  13820. "CSS_COUNTER",
  13821. "CSS_CUSTOM",
  13822. "CSS_DEG",
  13823. "CSS_DIMENSION",
  13824. "CSS_EMS",
  13825. "CSS_EXS",
  13826. "CSS_FILTER_BLUR",
  13827. "CSS_FILTER_BRIGHTNESS",
  13828. "CSS_FILTER_CONTRAST",
  13829. "CSS_FILTER_CUSTOM",
  13830. "CSS_FILTER_DROP_SHADOW",
  13831. "CSS_FILTER_GRAYSCALE",
  13832. "CSS_FILTER_HUE_ROTATE",
  13833. "CSS_FILTER_INVERT",
  13834. "CSS_FILTER_OPACITY",
  13835. "CSS_FILTER_REFERENCE",
  13836. "CSS_FILTER_SATURATE",
  13837. "CSS_FILTER_SEPIA",
  13838. "CSS_GRAD",
  13839. "CSS_HZ",
  13840. "CSS_IDENT",
  13841. "CSS_IN",
  13842. "CSS_INHERIT",
  13843. "CSS_KHZ",
  13844. "CSS_MATRIX",
  13845. "CSS_MATRIX3D",
  13846. "CSS_MM",
  13847. "CSS_MS",
  13848. "CSS_NUMBER",
  13849. "CSS_PC",
  13850. "CSS_PERCENTAGE",
  13851. "CSS_PERSPECTIVE",
  13852. "CSS_PRIMITIVE_VALUE",
  13853. "CSS_PT",
  13854. "CSS_PX",
  13855. "CSS_RAD",
  13856. "CSS_RECT",
  13857. "CSS_RGBCOLOR",
  13858. "CSS_ROTATE",
  13859. "CSS_ROTATE3D",
  13860. "CSS_ROTATEX",
  13861. "CSS_ROTATEY",
  13862. "CSS_ROTATEZ",
  13863. "CSS_S",
  13864. "CSS_SCALE",
  13865. "CSS_SCALE3D",
  13866. "CSS_SCALEX",
  13867. "CSS_SCALEY",
  13868. "CSS_SCALEZ",
  13869. "CSS_SKEW",
  13870. "CSS_SKEWX",
  13871. "CSS_SKEWY",
  13872. "CSS_STRING",
  13873. "CSS_TRANSLATE",
  13874. "CSS_TRANSLATE3D",
  13875. "CSS_TRANSLATEX",
  13876. "CSS_TRANSLATEY",
  13877. "CSS_TRANSLATEZ",
  13878. "CSS_UNKNOWN",
  13879. "CSS_URI",
  13880. "CSS_VALUE_LIST",
  13881. "CSS_VH",
  13882. "CSS_VMAX",
  13883. "CSS_VMIN",
  13884. "CSS_VW",
  13885. "CULL_FACE",
  13886. "CULL_FACE_MODE",
  13887. "CURRENT_PROGRAM",
  13888. "CURRENT_VERTEX_ATTRIB",
  13889. "CUSTOM",
  13890. "CW",
  13891. "CanvasGradient",
  13892. "CanvasPattern",
  13893. "CanvasRenderingContext2D",
  13894. "CaretPosition",
  13895. "ChannelMergerNode",
  13896. "ChannelSplitterNode",
  13897. "CharacterData",
  13898. "ClientRect",
  13899. "ClientRectList",
  13900. "Clipboard",
  13901. "ClipboardEvent",
  13902. "CloseEvent",
  13903. "Collator",
  13904. "CommandEvent",
  13905. "Comment",
  13906. "CompositionEvent",
  13907. "Console",
  13908. "Controllers",
  13909. "ConvolverNode",
  13910. "Counter",
  13911. "Crypto",
  13912. "CryptoKey",
  13913. "CustomEvent",
  13914. "DATABASE_ERR",
  13915. "DATA_CLONE_ERR",
  13916. "DATA_ERR",
  13917. "DBLCLICK",
  13918. "DECR",
  13919. "DECR_WRAP",
  13920. "DELETE_STATUS",
  13921. "DEPTH_ATTACHMENT",
  13922. "DEPTH_BITS",
  13923. "DEPTH_BUFFER_BIT",
  13924. "DEPTH_CLEAR_VALUE",
  13925. "DEPTH_COMPONENT",
  13926. "DEPTH_COMPONENT16",
  13927. "DEPTH_FUNC",
  13928. "DEPTH_RANGE",
  13929. "DEPTH_STENCIL",
  13930. "DEPTH_STENCIL_ATTACHMENT",
  13931. "DEPTH_TEST",
  13932. "DEPTH_WRITEMASK",
  13933. "DIRECTION_DOWN",
  13934. "DIRECTION_LEFT",
  13935. "DIRECTION_RIGHT",
  13936. "DIRECTION_UP",
  13937. "DISABLED",
  13938. "DISPATCH_REQUEST_ERR",
  13939. "DITHER",
  13940. "DOCUMENT_FRAGMENT_NODE",
  13941. "DOCUMENT_NODE",
  13942. "DOCUMENT_POSITION_CONTAINED_BY",
  13943. "DOCUMENT_POSITION_CONTAINS",
  13944. "DOCUMENT_POSITION_DISCONNECTED",
  13945. "DOCUMENT_POSITION_FOLLOWING",
  13946. "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC",
  13947. "DOCUMENT_POSITION_PRECEDING",
  13948. "DOCUMENT_TYPE_NODE",
  13949. "DOMCursor",
  13950. "DOMError",
  13951. "DOMException",
  13952. "DOMImplementation",
  13953. "DOMImplementationLS",
  13954. "DOMMatrix",
  13955. "DOMMatrixReadOnly",
  13956. "DOMParser",
  13957. "DOMPoint",
  13958. "DOMPointReadOnly",
  13959. "DOMQuad",
  13960. "DOMRect",
  13961. "DOMRectList",
  13962. "DOMRectReadOnly",
  13963. "DOMRequest",
  13964. "DOMSTRING_SIZE_ERR",
  13965. "DOMSettableTokenList",
  13966. "DOMStringList",
  13967. "DOMStringMap",
  13968. "DOMTokenList",
  13969. "DOMTransactionEvent",
  13970. "DOM_DELTA_LINE",
  13971. "DOM_DELTA_PAGE",
  13972. "DOM_DELTA_PIXEL",
  13973. "DOM_INPUT_METHOD_DROP",
  13974. "DOM_INPUT_METHOD_HANDWRITING",
  13975. "DOM_INPUT_METHOD_IME",
  13976. "DOM_INPUT_METHOD_KEYBOARD",
  13977. "DOM_INPUT_METHOD_MULTIMODAL",
  13978. "DOM_INPUT_METHOD_OPTION",
  13979. "DOM_INPUT_METHOD_PASTE",
  13980. "DOM_INPUT_METHOD_SCRIPT",
  13981. "DOM_INPUT_METHOD_UNKNOWN",
  13982. "DOM_INPUT_METHOD_VOICE",
  13983. "DOM_KEY_LOCATION_JOYSTICK",
  13984. "DOM_KEY_LOCATION_LEFT",
  13985. "DOM_KEY_LOCATION_MOBILE",
  13986. "DOM_KEY_LOCATION_NUMPAD",
  13987. "DOM_KEY_LOCATION_RIGHT",
  13988. "DOM_KEY_LOCATION_STANDARD",
  13989. "DOM_VK_0",
  13990. "DOM_VK_1",
  13991. "DOM_VK_2",
  13992. "DOM_VK_3",
  13993. "DOM_VK_4",
  13994. "DOM_VK_5",
  13995. "DOM_VK_6",
  13996. "DOM_VK_7",
  13997. "DOM_VK_8",
  13998. "DOM_VK_9",
  13999. "DOM_VK_A",
  14000. "DOM_VK_ACCEPT",
  14001. "DOM_VK_ADD",
  14002. "DOM_VK_ALT",
  14003. "DOM_VK_ALTGR",
  14004. "DOM_VK_AMPERSAND",
  14005. "DOM_VK_ASTERISK",
  14006. "DOM_VK_AT",
  14007. "DOM_VK_ATTN",
  14008. "DOM_VK_B",
  14009. "DOM_VK_BACKSPACE",
  14010. "DOM_VK_BACK_QUOTE",
  14011. "DOM_VK_BACK_SLASH",
  14012. "DOM_VK_BACK_SPACE",
  14013. "DOM_VK_C",
  14014. "DOM_VK_CANCEL",
  14015. "DOM_VK_CAPS_LOCK",
  14016. "DOM_VK_CIRCUMFLEX",
  14017. "DOM_VK_CLEAR",
  14018. "DOM_VK_CLOSE_BRACKET",
  14019. "DOM_VK_CLOSE_CURLY_BRACKET",
  14020. "DOM_VK_CLOSE_PAREN",
  14021. "DOM_VK_COLON",
  14022. "DOM_VK_COMMA",
  14023. "DOM_VK_CONTEXT_MENU",
  14024. "DOM_VK_CONTROL",
  14025. "DOM_VK_CONVERT",
  14026. "DOM_VK_CRSEL",
  14027. "DOM_VK_CTRL",
  14028. "DOM_VK_D",
  14029. "DOM_VK_DECIMAL",
  14030. "DOM_VK_DELETE",
  14031. "DOM_VK_DIVIDE",
  14032. "DOM_VK_DOLLAR",
  14033. "DOM_VK_DOUBLE_QUOTE",
  14034. "DOM_VK_DOWN",
  14035. "DOM_VK_E",
  14036. "DOM_VK_EISU",
  14037. "DOM_VK_END",
  14038. "DOM_VK_ENTER",
  14039. "DOM_VK_EQUALS",
  14040. "DOM_VK_EREOF",
  14041. "DOM_VK_ESCAPE",
  14042. "DOM_VK_EXCLAMATION",
  14043. "DOM_VK_EXECUTE",
  14044. "DOM_VK_EXSEL",
  14045. "DOM_VK_F",
  14046. "DOM_VK_F1",
  14047. "DOM_VK_F10",
  14048. "DOM_VK_F11",
  14049. "DOM_VK_F12",
  14050. "DOM_VK_F13",
  14051. "DOM_VK_F14",
  14052. "DOM_VK_F15",
  14053. "DOM_VK_F16",
  14054. "DOM_VK_F17",
  14055. "DOM_VK_F18",
  14056. "DOM_VK_F19",
  14057. "DOM_VK_F2",
  14058. "DOM_VK_F20",
  14059. "DOM_VK_F21",
  14060. "DOM_VK_F22",
  14061. "DOM_VK_F23",
  14062. "DOM_VK_F24",
  14063. "DOM_VK_F25",
  14064. "DOM_VK_F26",
  14065. "DOM_VK_F27",
  14066. "DOM_VK_F28",
  14067. "DOM_VK_F29",
  14068. "DOM_VK_F3",
  14069. "DOM_VK_F30",
  14070. "DOM_VK_F31",
  14071. "DOM_VK_F32",
  14072. "DOM_VK_F33",
  14073. "DOM_VK_F34",
  14074. "DOM_VK_F35",
  14075. "DOM_VK_F36",
  14076. "DOM_VK_F4",
  14077. "DOM_VK_F5",
  14078. "DOM_VK_F6",
  14079. "DOM_VK_F7",
  14080. "DOM_VK_F8",
  14081. "DOM_VK_F9",
  14082. "DOM_VK_FINAL",
  14083. "DOM_VK_FRONT",
  14084. "DOM_VK_G",
  14085. "DOM_VK_GREATER_THAN",
  14086. "DOM_VK_H",
  14087. "DOM_VK_HANGUL",
  14088. "DOM_VK_HANJA",
  14089. "DOM_VK_HASH",
  14090. "DOM_VK_HELP",
  14091. "DOM_VK_HK_TOGGLE",
  14092. "DOM_VK_HOME",
  14093. "DOM_VK_HYPHEN_MINUS",
  14094. "DOM_VK_I",
  14095. "DOM_VK_INSERT",
  14096. "DOM_VK_J",
  14097. "DOM_VK_JUNJA",
  14098. "DOM_VK_K",
  14099. "DOM_VK_KANA",
  14100. "DOM_VK_KANJI",
  14101. "DOM_VK_L",
  14102. "DOM_VK_LEFT",
  14103. "DOM_VK_LEFT_TAB",
  14104. "DOM_VK_LESS_THAN",
  14105. "DOM_VK_M",
  14106. "DOM_VK_META",
  14107. "DOM_VK_MODECHANGE",
  14108. "DOM_VK_MULTIPLY",
  14109. "DOM_VK_N",
  14110. "DOM_VK_NONCONVERT",
  14111. "DOM_VK_NUMPAD0",
  14112. "DOM_VK_NUMPAD1",
  14113. "DOM_VK_NUMPAD2",
  14114. "DOM_VK_NUMPAD3",
  14115. "DOM_VK_NUMPAD4",
  14116. "DOM_VK_NUMPAD5",
  14117. "DOM_VK_NUMPAD6",
  14118. "DOM_VK_NUMPAD7",
  14119. "DOM_VK_NUMPAD8",
  14120. "DOM_VK_NUMPAD9",
  14121. "DOM_VK_NUM_LOCK",
  14122. "DOM_VK_O",
  14123. "DOM_VK_OEM_1",
  14124. "DOM_VK_OEM_102",
  14125. "DOM_VK_OEM_2",
  14126. "DOM_VK_OEM_3",
  14127. "DOM_VK_OEM_4",
  14128. "DOM_VK_OEM_5",
  14129. "DOM_VK_OEM_6",
  14130. "DOM_VK_OEM_7",
  14131. "DOM_VK_OEM_8",
  14132. "DOM_VK_OEM_COMMA",
  14133. "DOM_VK_OEM_MINUS",
  14134. "DOM_VK_OEM_PERIOD",
  14135. "DOM_VK_OEM_PLUS",
  14136. "DOM_VK_OPEN_BRACKET",
  14137. "DOM_VK_OPEN_CURLY_BRACKET",
  14138. "DOM_VK_OPEN_PAREN",
  14139. "DOM_VK_P",
  14140. "DOM_VK_PA1",
  14141. "DOM_VK_PAGEDOWN",
  14142. "DOM_VK_PAGEUP",
  14143. "DOM_VK_PAGE_DOWN",
  14144. "DOM_VK_PAGE_UP",
  14145. "DOM_VK_PAUSE",
  14146. "DOM_VK_PERCENT",
  14147. "DOM_VK_PERIOD",
  14148. "DOM_VK_PIPE",
  14149. "DOM_VK_PLAY",
  14150. "DOM_VK_PLUS",
  14151. "DOM_VK_PRINT",
  14152. "DOM_VK_PRINTSCREEN",
  14153. "DOM_VK_PROCESSKEY",
  14154. "DOM_VK_PROPERITES",
  14155. "DOM_VK_Q",
  14156. "DOM_VK_QUESTION_MARK",
  14157. "DOM_VK_QUOTE",
  14158. "DOM_VK_R",
  14159. "DOM_VK_REDO",
  14160. "DOM_VK_RETURN",
  14161. "DOM_VK_RIGHT",
  14162. "DOM_VK_S",
  14163. "DOM_VK_SCROLL_LOCK",
  14164. "DOM_VK_SELECT",
  14165. "DOM_VK_SEMICOLON",
  14166. "DOM_VK_SEPARATOR",
  14167. "DOM_VK_SHIFT",
  14168. "DOM_VK_SLASH",
  14169. "DOM_VK_SLEEP",
  14170. "DOM_VK_SPACE",
  14171. "DOM_VK_SUBTRACT",
  14172. "DOM_VK_T",
  14173. "DOM_VK_TAB",
  14174. "DOM_VK_TILDE",
  14175. "DOM_VK_U",
  14176. "DOM_VK_UNDERSCORE",
  14177. "DOM_VK_UNDO",
  14178. "DOM_VK_UNICODE",
  14179. "DOM_VK_UP",
  14180. "DOM_VK_V",
  14181. "DOM_VK_VOLUME_DOWN",
  14182. "DOM_VK_VOLUME_MUTE",
  14183. "DOM_VK_VOLUME_UP",
  14184. "DOM_VK_W",
  14185. "DOM_VK_WIN",
  14186. "DOM_VK_WINDOW",
  14187. "DOM_VK_WIN_ICO_00",
  14188. "DOM_VK_WIN_ICO_CLEAR",
  14189. "DOM_VK_WIN_ICO_HELP",
  14190. "DOM_VK_WIN_OEM_ATTN",
  14191. "DOM_VK_WIN_OEM_AUTO",
  14192. "DOM_VK_WIN_OEM_BACKTAB",
  14193. "DOM_VK_WIN_OEM_CLEAR",
  14194. "DOM_VK_WIN_OEM_COPY",
  14195. "DOM_VK_WIN_OEM_CUSEL",
  14196. "DOM_VK_WIN_OEM_ENLW",
  14197. "DOM_VK_WIN_OEM_FINISH",
  14198. "DOM_VK_WIN_OEM_FJ_JISHO",
  14199. "DOM_VK_WIN_OEM_FJ_LOYA",
  14200. "DOM_VK_WIN_OEM_FJ_MASSHOU",
  14201. "DOM_VK_WIN_OEM_FJ_ROYA",
  14202. "DOM_VK_WIN_OEM_FJ_TOUROKU",
  14203. "DOM_VK_WIN_OEM_JUMP",
  14204. "DOM_VK_WIN_OEM_PA1",
  14205. "DOM_VK_WIN_OEM_PA2",
  14206. "DOM_VK_WIN_OEM_PA3",
  14207. "DOM_VK_WIN_OEM_RESET",
  14208. "DOM_VK_WIN_OEM_WSCTRL",
  14209. "DOM_VK_X",
  14210. "DOM_VK_XF86XK_ADD_FAVORITE",
  14211. "DOM_VK_XF86XK_APPLICATION_LEFT",
  14212. "DOM_VK_XF86XK_APPLICATION_RIGHT",
  14213. "DOM_VK_XF86XK_AUDIO_CYCLE_TRACK",
  14214. "DOM_VK_XF86XK_AUDIO_FORWARD",
  14215. "DOM_VK_XF86XK_AUDIO_LOWER_VOLUME",
  14216. "DOM_VK_XF86XK_AUDIO_MEDIA",
  14217. "DOM_VK_XF86XK_AUDIO_MUTE",
  14218. "DOM_VK_XF86XK_AUDIO_NEXT",
  14219. "DOM_VK_XF86XK_AUDIO_PAUSE",
  14220. "DOM_VK_XF86XK_AUDIO_PLAY",
  14221. "DOM_VK_XF86XK_AUDIO_PREV",
  14222. "DOM_VK_XF86XK_AUDIO_RAISE_VOLUME",
  14223. "DOM_VK_XF86XK_AUDIO_RANDOM_PLAY",
  14224. "DOM_VK_XF86XK_AUDIO_RECORD",
  14225. "DOM_VK_XF86XK_AUDIO_REPEAT",
  14226. "DOM_VK_XF86XK_AUDIO_REWIND",
  14227. "DOM_VK_XF86XK_AUDIO_STOP",
  14228. "DOM_VK_XF86XK_AWAY",
  14229. "DOM_VK_XF86XK_BACK",
  14230. "DOM_VK_XF86XK_BACK_FORWARD",
  14231. "DOM_VK_XF86XK_BATTERY",
  14232. "DOM_VK_XF86XK_BLUE",
  14233. "DOM_VK_XF86XK_BLUETOOTH",
  14234. "DOM_VK_XF86XK_BOOK",
  14235. "DOM_VK_XF86XK_BRIGHTNESS_ADJUST",
  14236. "DOM_VK_XF86XK_CALCULATOR",
  14237. "DOM_VK_XF86XK_CALENDAR",
  14238. "DOM_VK_XF86XK_CD",
  14239. "DOM_VK_XF86XK_CLOSE",
  14240. "DOM_VK_XF86XK_COMMUNITY",
  14241. "DOM_VK_XF86XK_CONTRAST_ADJUST",
  14242. "DOM_VK_XF86XK_COPY",
  14243. "DOM_VK_XF86XK_CUT",
  14244. "DOM_VK_XF86XK_CYCLE_ANGLE",
  14245. "DOM_VK_XF86XK_DISPLAY",
  14246. "DOM_VK_XF86XK_DOCUMENTS",
  14247. "DOM_VK_XF86XK_DOS",
  14248. "DOM_VK_XF86XK_EJECT",
  14249. "DOM_VK_XF86XK_EXCEL",
  14250. "DOM_VK_XF86XK_EXPLORER",
  14251. "DOM_VK_XF86XK_FAVORITES",
  14252. "DOM_VK_XF86XK_FINANCE",
  14253. "DOM_VK_XF86XK_FORWARD",
  14254. "DOM_VK_XF86XK_FRAME_BACK",
  14255. "DOM_VK_XF86XK_FRAME_FORWARD",
  14256. "DOM_VK_XF86XK_GAME",
  14257. "DOM_VK_XF86XK_GO",
  14258. "DOM_VK_XF86XK_GREEN",
  14259. "DOM_VK_XF86XK_HIBERNATE",
  14260. "DOM_VK_XF86XK_HISTORY",
  14261. "DOM_VK_XF86XK_HOME_PAGE",
  14262. "DOM_VK_XF86XK_HOT_LINKS",
  14263. "DOM_VK_XF86XK_I_TOUCH",
  14264. "DOM_VK_XF86XK_KBD_BRIGHTNESS_DOWN",
  14265. "DOM_VK_XF86XK_KBD_BRIGHTNESS_UP",
  14266. "DOM_VK_XF86XK_KBD_LIGHT_ON_OFF",
  14267. "DOM_VK_XF86XK_LAUNCH0",
  14268. "DOM_VK_XF86XK_LAUNCH1",
  14269. "DOM_VK_XF86XK_LAUNCH2",
  14270. "DOM_VK_XF86XK_LAUNCH3",
  14271. "DOM_VK_XF86XK_LAUNCH4",
  14272. "DOM_VK_XF86XK_LAUNCH5",
  14273. "DOM_VK_XF86XK_LAUNCH6",
  14274. "DOM_VK_XF86XK_LAUNCH7",
  14275. "DOM_VK_XF86XK_LAUNCH8",
  14276. "DOM_VK_XF86XK_LAUNCH9",
  14277. "DOM_VK_XF86XK_LAUNCH_A",
  14278. "DOM_VK_XF86XK_LAUNCH_B",
  14279. "DOM_VK_XF86XK_LAUNCH_C",
  14280. "DOM_VK_XF86XK_LAUNCH_D",
  14281. "DOM_VK_XF86XK_LAUNCH_E",
  14282. "DOM_VK_XF86XK_LAUNCH_F",
  14283. "DOM_VK_XF86XK_LIGHT_BULB",
  14284. "DOM_VK_XF86XK_LOG_OFF",
  14285. "DOM_VK_XF86XK_MAIL",
  14286. "DOM_VK_XF86XK_MAIL_FORWARD",
  14287. "DOM_VK_XF86XK_MARKET",
  14288. "DOM_VK_XF86XK_MEETING",
  14289. "DOM_VK_XF86XK_MEMO",
  14290. "DOM_VK_XF86XK_MENU_KB",
  14291. "DOM_VK_XF86XK_MENU_PB",
  14292. "DOM_VK_XF86XK_MESSENGER",
  14293. "DOM_VK_XF86XK_MON_BRIGHTNESS_DOWN",
  14294. "DOM_VK_XF86XK_MON_BRIGHTNESS_UP",
  14295. "DOM_VK_XF86XK_MUSIC",
  14296. "DOM_VK_XF86XK_MY_COMPUTER",
  14297. "DOM_VK_XF86XK_MY_SITES",
  14298. "DOM_VK_XF86XK_NEW",
  14299. "DOM_VK_XF86XK_NEWS",
  14300. "DOM_VK_XF86XK_OFFICE_HOME",
  14301. "DOM_VK_XF86XK_OPEN",
  14302. "DOM_VK_XF86XK_OPEN_URL",
  14303. "DOM_VK_XF86XK_OPTION",
  14304. "DOM_VK_XF86XK_PASTE",
  14305. "DOM_VK_XF86XK_PHONE",
  14306. "DOM_VK_XF86XK_PICTURES",
  14307. "DOM_VK_XF86XK_POWER_DOWN",
  14308. "DOM_VK_XF86XK_POWER_OFF",
  14309. "DOM_VK_XF86XK_RED",
  14310. "DOM_VK_XF86XK_REFRESH",
  14311. "DOM_VK_XF86XK_RELOAD",
  14312. "DOM_VK_XF86XK_REPLY",
  14313. "DOM_VK_XF86XK_ROCKER_DOWN",
  14314. "DOM_VK_XF86XK_ROCKER_ENTER",
  14315. "DOM_VK_XF86XK_ROCKER_UP",
  14316. "DOM_VK_XF86XK_ROTATE_WINDOWS",
  14317. "DOM_VK_XF86XK_ROTATION_KB",
  14318. "DOM_VK_XF86XK_ROTATION_PB",
  14319. "DOM_VK_XF86XK_SAVE",
  14320. "DOM_VK_XF86XK_SCREEN_SAVER",
  14321. "DOM_VK_XF86XK_SCROLL_CLICK",
  14322. "DOM_VK_XF86XK_SCROLL_DOWN",
  14323. "DOM_VK_XF86XK_SCROLL_UP",
  14324. "DOM_VK_XF86XK_SEARCH",
  14325. "DOM_VK_XF86XK_SEND",
  14326. "DOM_VK_XF86XK_SHOP",
  14327. "DOM_VK_XF86XK_SPELL",
  14328. "DOM_VK_XF86XK_SPLIT_SCREEN",
  14329. "DOM_VK_XF86XK_STANDBY",
  14330. "DOM_VK_XF86XK_START",
  14331. "DOM_VK_XF86XK_STOP",
  14332. "DOM_VK_XF86XK_SUBTITLE",
  14333. "DOM_VK_XF86XK_SUPPORT",
  14334. "DOM_VK_XF86XK_SUSPEND",
  14335. "DOM_VK_XF86XK_TASK_PANE",
  14336. "DOM_VK_XF86XK_TERMINAL",
  14337. "DOM_VK_XF86XK_TIME",
  14338. "DOM_VK_XF86XK_TOOLS",
  14339. "DOM_VK_XF86XK_TOP_MENU",
  14340. "DOM_VK_XF86XK_TO_DO_LIST",
  14341. "DOM_VK_XF86XK_TRAVEL",
  14342. "DOM_VK_XF86XK_USER1KB",
  14343. "DOM_VK_XF86XK_USER2KB",
  14344. "DOM_VK_XF86XK_USER_PB",
  14345. "DOM_VK_XF86XK_UWB",
  14346. "DOM_VK_XF86XK_VENDOR_HOME",
  14347. "DOM_VK_XF86XK_VIDEO",
  14348. "DOM_VK_XF86XK_VIEW",
  14349. "DOM_VK_XF86XK_WAKE_UP",
  14350. "DOM_VK_XF86XK_WEB_CAM",
  14351. "DOM_VK_XF86XK_WHEEL_BUTTON",
  14352. "DOM_VK_XF86XK_WLAN",
  14353. "DOM_VK_XF86XK_WORD",
  14354. "DOM_VK_XF86XK_WWW",
  14355. "DOM_VK_XF86XK_XFER",
  14356. "DOM_VK_XF86XK_YELLOW",
  14357. "DOM_VK_XF86XK_ZOOM_IN",
  14358. "DOM_VK_XF86XK_ZOOM_OUT",
  14359. "DOM_VK_Y",
  14360. "DOM_VK_Z",
  14361. "DOM_VK_ZOOM",
  14362. "DONE",
  14363. "DONT_CARE",
  14364. "DOWNLOADING",
  14365. "DRAGDROP",
  14366. "DST_ALPHA",
  14367. "DST_COLOR",
  14368. "DYNAMIC_DRAW",
  14369. "DataChannel",
  14370. "DataTransfer",
  14371. "DataTransferItem",
  14372. "DataTransferItemList",
  14373. "DataView",
  14374. "Date",
  14375. "DateTimeFormat",
  14376. "DelayNode",
  14377. "DesktopNotification",
  14378. "DesktopNotificationCenter",
  14379. "DeviceLightEvent",
  14380. "DeviceMotionEvent",
  14381. "DeviceOrientationEvent",
  14382. "DeviceProximityEvent",
  14383. "DeviceStorage",
  14384. "DeviceStorageChangeEvent",
  14385. "Document",
  14386. "DocumentFragment",
  14387. "DocumentType",
  14388. "DragEvent",
  14389. "DynamicsCompressorNode",
  14390. "E",
  14391. "ELEMENT_ARRAY_BUFFER",
  14392. "ELEMENT_ARRAY_BUFFER_BINDING",
  14393. "ELEMENT_NODE",
  14394. "EMPTY",
  14395. "ENCODING_ERR",
  14396. "ENDED",
  14397. "END_TO_END",
  14398. "END_TO_START",
  14399. "ENTITY_NODE",
  14400. "ENTITY_REFERENCE_NODE",
  14401. "EPSILON",
  14402. "EQUAL",
  14403. "EQUALPOWER",
  14404. "ERROR",
  14405. "EXPONENTIAL_DISTANCE",
  14406. "Element",
  14407. "ElementQuery",
  14408. "Entity",
  14409. "EntityReference",
  14410. "Error",
  14411. "ErrorEvent",
  14412. "EvalError",
  14413. "Event",
  14414. "EventException",
  14415. "EventSource",
  14416. "EventTarget",
  14417. "External",
  14418. "FASTEST",
  14419. "FIDOSDK",
  14420. "FILTER_ACCEPT",
  14421. "FILTER_INTERRUPT",
  14422. "FILTER_REJECT",
  14423. "FILTER_SKIP",
  14424. "FINISHED_STATE",
  14425. "FIRST_ORDERED_NODE_TYPE",
  14426. "FLOAT",
  14427. "FLOAT_MAT2",
  14428. "FLOAT_MAT3",
  14429. "FLOAT_MAT4",
  14430. "FLOAT_VEC2",
  14431. "FLOAT_VEC3",
  14432. "FLOAT_VEC4",
  14433. "FOCUS",
  14434. "FONT_FACE_RULE",
  14435. "FONT_FEATURE_VALUES_RULE",
  14436. "FRAGMENT_SHADER",
  14437. "FRAGMENT_SHADER_DERIVATIVE_HINT_OES",
  14438. "FRAMEBUFFER",
  14439. "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME",
  14440. "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE",
  14441. "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE",
  14442. "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL",
  14443. "FRAMEBUFFER_BINDING",
  14444. "FRAMEBUFFER_COMPLETE",
  14445. "FRAMEBUFFER_INCOMPLETE_ATTACHMENT",
  14446. "FRAMEBUFFER_INCOMPLETE_DIMENSIONS",
  14447. "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT",
  14448. "FRAMEBUFFER_UNSUPPORTED",
  14449. "FRONT",
  14450. "FRONT_AND_BACK",
  14451. "FRONT_FACE",
  14452. "FUNC_ADD",
  14453. "FUNC_REVERSE_SUBTRACT",
  14454. "FUNC_SUBTRACT",
  14455. "Feed",
  14456. "FeedEntry",
  14457. "File",
  14458. "FileError",
  14459. "FileList",
  14460. "FileReader",
  14461. "FindInPage",
  14462. "Float32Array",
  14463. "Float64Array",
  14464. "FocusEvent",
  14465. "FontFace",
  14466. "FormData",
  14467. "Function",
  14468. "GENERATE_MIPMAP_HINT",
  14469. "GEQUAL",
  14470. "GREATER",
  14471. "GREEN_BITS",
  14472. "GainNode",
  14473. "Gamepad",
  14474. "GamepadButton",
  14475. "GamepadEvent",
  14476. "GestureEvent",
  14477. "HAVE_CURRENT_DATA",
  14478. "HAVE_ENOUGH_DATA",
  14479. "HAVE_FUTURE_DATA",
  14480. "HAVE_METADATA",
  14481. "HAVE_NOTHING",
  14482. "HEADERS_RECEIVED",
  14483. "HIDDEN",
  14484. "HIERARCHY_REQUEST_ERR",
  14485. "HIGHPASS",
  14486. "HIGHSHELF",
  14487. "HIGH_FLOAT",
  14488. "HIGH_INT",
  14489. "HORIZONTAL",
  14490. "HORIZONTAL_AXIS",
  14491. "HRTF",
  14492. "HTMLAllCollection",
  14493. "HTMLAnchorElement",
  14494. "HTMLAppletElement",
  14495. "HTMLAreaElement",
  14496. "HTMLAudioElement",
  14497. "HTMLBRElement",
  14498. "HTMLBaseElement",
  14499. "HTMLBaseFontElement",
  14500. "HTMLBlockquoteElement",
  14501. "HTMLBodyElement",
  14502. "HTMLButtonElement",
  14503. "HTMLCanvasElement",
  14504. "HTMLCollection",
  14505. "HTMLCommandElement",
  14506. "HTMLContentElement",
  14507. "HTMLDListElement",
  14508. "HTMLDataElement",
  14509. "HTMLDataListElement",
  14510. "HTMLDetailsElement",
  14511. "HTMLDialogElement",
  14512. "HTMLDirectoryElement",
  14513. "HTMLDivElement",
  14514. "HTMLDocument",
  14515. "HTMLElement",
  14516. "HTMLEmbedElement",
  14517. "HTMLFieldSetElement",
  14518. "HTMLFontElement",
  14519. "HTMLFormControlsCollection",
  14520. "HTMLFormElement",
  14521. "HTMLFrameElement",
  14522. "HTMLFrameSetElement",
  14523. "HTMLHRElement",
  14524. "HTMLHeadElement",
  14525. "HTMLHeadingElement",
  14526. "HTMLHtmlElement",
  14527. "HTMLIFrameElement",
  14528. "HTMLImageElement",
  14529. "HTMLInputElement",
  14530. "HTMLIsIndexElement",
  14531. "HTMLKeygenElement",
  14532. "HTMLLIElement",
  14533. "HTMLLabelElement",
  14534. "HTMLLegendElement",
  14535. "HTMLLinkElement",
  14536. "HTMLMapElement",
  14537. "HTMLMarqueeElement",
  14538. "HTMLMediaElement",
  14539. "HTMLMenuElement",
  14540. "HTMLMenuItemElement",
  14541. "HTMLMetaElement",
  14542. "HTMLMeterElement",
  14543. "HTMLModElement",
  14544. "HTMLOListElement",
  14545. "HTMLObjectElement",
  14546. "HTMLOptGroupElement",
  14547. "HTMLOptionElement",
  14548. "HTMLOptionsCollection",
  14549. "HTMLOutputElement",
  14550. "HTMLParagraphElement",
  14551. "HTMLParamElement",
  14552. "HTMLPictureElement",
  14553. "HTMLPreElement",
  14554. "HTMLProgressElement",
  14555. "HTMLPropertiesCollection",
  14556. "HTMLQuoteElement",
  14557. "HTMLScriptElement",
  14558. "HTMLSelectElement",
  14559. "HTMLShadowElement",
  14560. "HTMLSourceElement",
  14561. "HTMLSpanElement",
  14562. "HTMLStyleElement",
  14563. "HTMLTableCaptionElement",
  14564. "HTMLTableCellElement",
  14565. "HTMLTableColElement",
  14566. "HTMLTableElement",
  14567. "HTMLTableRowElement",
  14568. "HTMLTableSectionElement",
  14569. "HTMLTemplateElement",
  14570. "HTMLTextAreaElement",
  14571. "HTMLTimeElement",
  14572. "HTMLTitleElement",
  14573. "HTMLTrackElement",
  14574. "HTMLUListElement",
  14575. "HTMLUnknownElement",
  14576. "HTMLVideoElement",
  14577. "HashChangeEvent",
  14578. "Headers",
  14579. "History",
  14580. "ICE_CHECKING",
  14581. "ICE_CLOSED",
  14582. "ICE_COMPLETED",
  14583. "ICE_CONNECTED",
  14584. "ICE_FAILED",
  14585. "ICE_GATHERING",
  14586. "ICE_WAITING",
  14587. "IDBCursor",
  14588. "IDBCursorWithValue",
  14589. "IDBDatabase",
  14590. "IDBDatabaseException",
  14591. "IDBFactory",
  14592. "IDBFileHandle",
  14593. "IDBFileRequest",
  14594. "IDBIndex",
  14595. "IDBKeyRange",
  14596. "IDBMutableFile",
  14597. "IDBObjectStore",
  14598. "IDBOpenDBRequest",
  14599. "IDBRequest",
  14600. "IDBTransaction",
  14601. "IDBVersionChangeEvent",
  14602. "IDLE",
  14603. "IMPLEMENTATION_COLOR_READ_FORMAT",
  14604. "IMPLEMENTATION_COLOR_READ_TYPE",
  14605. "IMPORT_RULE",
  14606. "INCR",
  14607. "INCR_WRAP",
  14608. "INDEX_SIZE_ERR",
  14609. "INT",
  14610. "INT_VEC2",
  14611. "INT_VEC3",
  14612. "INT_VEC4",
  14613. "INUSE_ATTRIBUTE_ERR",
  14614. "INVALID_ACCESS_ERR",
  14615. "INVALID_CHARACTER_ERR",
  14616. "INVALID_ENUM",
  14617. "INVALID_EXPRESSION_ERR",
  14618. "INVALID_FRAMEBUFFER_OPERATION",
  14619. "INVALID_MODIFICATION_ERR",
  14620. "INVALID_NODE_TYPE_ERR",
  14621. "INVALID_OPERATION",
  14622. "INVALID_STATE_ERR",
  14623. "INVALID_VALUE",
  14624. "INVERSE_DISTANCE",
  14625. "INVERT",
  14626. "IceCandidate",
  14627. "Image",
  14628. "ImageBitmap",
  14629. "ImageData",
  14630. "Infinity",
  14631. "InputEvent",
  14632. "InputMethodContext",
  14633. "InstallTrigger",
  14634. "Int16Array",
  14635. "Int32Array",
  14636. "Int8Array",
  14637. "Intent",
  14638. "InternalError",
  14639. "Intl",
  14640. "IsSearchProviderInstalled",
  14641. "Iterator",
  14642. "JSON",
  14643. "KEEP",
  14644. "KEYDOWN",
  14645. "KEYFRAMES_RULE",
  14646. "KEYFRAME_RULE",
  14647. "KEYPRESS",
  14648. "KEYUP",
  14649. "KeyEvent",
  14650. "KeyboardEvent",
  14651. "LENGTHADJUST_SPACING",
  14652. "LENGTHADJUST_SPACINGANDGLYPHS",
  14653. "LENGTHADJUST_UNKNOWN",
  14654. "LEQUAL",
  14655. "LESS",
  14656. "LINEAR",
  14657. "LINEAR_DISTANCE",
  14658. "LINEAR_MIPMAP_LINEAR",
  14659. "LINEAR_MIPMAP_NEAREST",
  14660. "LINES",
  14661. "LINE_LOOP",
  14662. "LINE_STRIP",
  14663. "LINE_WIDTH",
  14664. "LINK_STATUS",
  14665. "LIVE",
  14666. "LN10",
  14667. "LN2",
  14668. "LOADED",
  14669. "LOADING",
  14670. "LOG10E",
  14671. "LOG2E",
  14672. "LOWPASS",
  14673. "LOWSHELF",
  14674. "LOW_FLOAT",
  14675. "LOW_INT",
  14676. "LSException",
  14677. "LSParserFilter",
  14678. "LUMINANCE",
  14679. "LUMINANCE_ALPHA",
  14680. "LocalMediaStream",
  14681. "Location",
  14682. "MAX_COMBINED_TEXTURE_IMAGE_UNITS",
  14683. "MAX_CUBE_MAP_TEXTURE_SIZE",
  14684. "MAX_FRAGMENT_UNIFORM_VECTORS",
  14685. "MAX_RENDERBUFFER_SIZE",
  14686. "MAX_SAFE_INTEGER",
  14687. "MAX_TEXTURE_IMAGE_UNITS",
  14688. "MAX_TEXTURE_MAX_ANISOTROPY_EXT",
  14689. "MAX_TEXTURE_SIZE",
  14690. "MAX_VALUE",
  14691. "MAX_VARYING_VECTORS",
  14692. "MAX_VERTEX_ATTRIBS",
  14693. "MAX_VERTEX_TEXTURE_IMAGE_UNITS",
  14694. "MAX_VERTEX_UNIFORM_VECTORS",
  14695. "MAX_VIEWPORT_DIMS",
  14696. "MEDIA_ERR_ABORTED",
  14697. "MEDIA_ERR_DECODE",
  14698. "MEDIA_ERR_ENCRYPTED",
  14699. "MEDIA_ERR_NETWORK",
  14700. "MEDIA_ERR_SRC_NOT_SUPPORTED",
  14701. "MEDIA_KEYERR_CLIENT",
  14702. "MEDIA_KEYERR_DOMAIN",
  14703. "MEDIA_KEYERR_HARDWARECHANGE",
  14704. "MEDIA_KEYERR_OUTPUT",
  14705. "MEDIA_KEYERR_SERVICE",
  14706. "MEDIA_KEYERR_UNKNOWN",
  14707. "MEDIA_RULE",
  14708. "MEDIUM_FLOAT",
  14709. "MEDIUM_INT",
  14710. "META_MASK",
  14711. "MIN_SAFE_INTEGER",
  14712. "MIN_VALUE",
  14713. "MIRRORED_REPEAT",
  14714. "MODE_ASYNCHRONOUS",
  14715. "MODE_SYNCHRONOUS",
  14716. "MODIFICATION",
  14717. "MOUSEDOWN",
  14718. "MOUSEDRAG",
  14719. "MOUSEMOVE",
  14720. "MOUSEOUT",
  14721. "MOUSEOVER",
  14722. "MOUSEUP",
  14723. "MOZ_KEYFRAMES_RULE",
  14724. "MOZ_KEYFRAME_RULE",
  14725. "MOZ_SOURCE_CURSOR",
  14726. "MOZ_SOURCE_ERASER",
  14727. "MOZ_SOURCE_KEYBOARD",
  14728. "MOZ_SOURCE_MOUSE",
  14729. "MOZ_SOURCE_PEN",
  14730. "MOZ_SOURCE_TOUCH",
  14731. "MOZ_SOURCE_UNKNOWN",
  14732. "MSGESTURE_FLAG_BEGIN",
  14733. "MSGESTURE_FLAG_CANCEL",
  14734. "MSGESTURE_FLAG_END",
  14735. "MSGESTURE_FLAG_INERTIA",
  14736. "MSGESTURE_FLAG_NONE",
  14737. "MSPOINTER_TYPE_MOUSE",
  14738. "MSPOINTER_TYPE_PEN",
  14739. "MSPOINTER_TYPE_TOUCH",
  14740. "MS_ASYNC_CALLBACK_STATUS_ASSIGN_DELEGATE",
  14741. "MS_ASYNC_CALLBACK_STATUS_CANCEL",
  14742. "MS_ASYNC_CALLBACK_STATUS_CHOOSEANY",
  14743. "MS_ASYNC_CALLBACK_STATUS_ERROR",
  14744. "MS_ASYNC_CALLBACK_STATUS_JOIN",
  14745. "MS_ASYNC_OP_STATUS_CANCELED",
  14746. "MS_ASYNC_OP_STATUS_ERROR",
  14747. "MS_ASYNC_OP_STATUS_SUCCESS",
  14748. "MS_MANIPULATION_STATE_ACTIVE",
  14749. "MS_MANIPULATION_STATE_CANCELLED",
  14750. "MS_MANIPULATION_STATE_COMMITTED",
  14751. "MS_MANIPULATION_STATE_DRAGGING",
  14752. "MS_MANIPULATION_STATE_INERTIA",
  14753. "MS_MANIPULATION_STATE_PRESELECT",
  14754. "MS_MANIPULATION_STATE_SELECTING",
  14755. "MS_MANIPULATION_STATE_STOPPED",
  14756. "MS_MEDIA_ERR_ENCRYPTED",
  14757. "MS_MEDIA_KEYERR_CLIENT",
  14758. "MS_MEDIA_KEYERR_DOMAIN",
  14759. "MS_MEDIA_KEYERR_HARDWARECHANGE",
  14760. "MS_MEDIA_KEYERR_OUTPUT",
  14761. "MS_MEDIA_KEYERR_SERVICE",
  14762. "MS_MEDIA_KEYERR_UNKNOWN",
  14763. "Map",
  14764. "Math",
  14765. "MediaController",
  14766. "MediaDevices",
  14767. "MediaElementAudioSourceNode",
  14768. "MediaEncryptedEvent",
  14769. "MediaError",
  14770. "MediaKeyError",
  14771. "MediaKeyEvent",
  14772. "MediaKeyMessageEvent",
  14773. "MediaKeyNeededEvent",
  14774. "MediaKeySession",
  14775. "MediaKeyStatusMap",
  14776. "MediaKeySystemAccess",
  14777. "MediaKeys",
  14778. "MediaList",
  14779. "MediaQueryList",
  14780. "MediaQueryListEvent",
  14781. "MediaRecorder",
  14782. "MediaSource",
  14783. "MediaStream",
  14784. "MediaStreamAudioDestinationNode",
  14785. "MediaStreamAudioSourceNode",
  14786. "MediaStreamEvent",
  14787. "MediaStreamTrack",
  14788. "MediaStreamTrackEvent",
  14789. "MessageChannel",
  14790. "MessageEvent",
  14791. "MessagePort",
  14792. "Methods",
  14793. "MimeType",
  14794. "MimeTypeArray",
  14795. "MouseEvent",
  14796. "MouseScrollEvent",
  14797. "MozAnimation",
  14798. "MozAnimationDelay",
  14799. "MozAnimationDirection",
  14800. "MozAnimationDuration",
  14801. "MozAnimationFillMode",
  14802. "MozAnimationIterationCount",
  14803. "MozAnimationName",
  14804. "MozAnimationPlayState",
  14805. "MozAnimationTimingFunction",
  14806. "MozAppearance",
  14807. "MozBackfaceVisibility",
  14808. "MozBinding",
  14809. "MozBorderBottomColors",
  14810. "MozBorderEnd",
  14811. "MozBorderEndColor",
  14812. "MozBorderEndStyle",
  14813. "MozBorderEndWidth",
  14814. "MozBorderImage",
  14815. "MozBorderLeftColors",
  14816. "MozBorderRightColors",
  14817. "MozBorderStart",
  14818. "MozBorderStartColor",
  14819. "MozBorderStartStyle",
  14820. "MozBorderStartWidth",
  14821. "MozBorderTopColors",
  14822. "MozBoxAlign",
  14823. "MozBoxDirection",
  14824. "MozBoxFlex",
  14825. "MozBoxOrdinalGroup",
  14826. "MozBoxOrient",
  14827. "MozBoxPack",
  14828. "MozBoxSizing",
  14829. "MozCSSKeyframeRule",
  14830. "MozCSSKeyframesRule",
  14831. "MozColumnCount",
  14832. "MozColumnFill",
  14833. "MozColumnGap",
  14834. "MozColumnRule",
  14835. "MozColumnRuleColor",
  14836. "MozColumnRuleStyle",
  14837. "MozColumnRuleWidth",
  14838. "MozColumnWidth",
  14839. "MozColumns",
  14840. "MozContactChangeEvent",
  14841. "MozFloatEdge",
  14842. "MozFontFeatureSettings",
  14843. "MozFontLanguageOverride",
  14844. "MozForceBrokenImageIcon",
  14845. "MozHyphens",
  14846. "MozImageRegion",
  14847. "MozMarginEnd",
  14848. "MozMarginStart",
  14849. "MozMmsEvent",
  14850. "MozMmsMessage",
  14851. "MozMobileMessageThread",
  14852. "MozOSXFontSmoothing",
  14853. "MozOrient",
  14854. "MozOutlineRadius",
  14855. "MozOutlineRadiusBottomleft",
  14856. "MozOutlineRadiusBottomright",
  14857. "MozOutlineRadiusTopleft",
  14858. "MozOutlineRadiusTopright",
  14859. "MozPaddingEnd",
  14860. "MozPaddingStart",
  14861. "MozPerspective",
  14862. "MozPerspectiveOrigin",
  14863. "MozPowerManager",
  14864. "MozSettingsEvent",
  14865. "MozSmsEvent",
  14866. "MozSmsMessage",
  14867. "MozStackSizing",
  14868. "MozTabSize",
  14869. "MozTextAlignLast",
  14870. "MozTextDecorationColor",
  14871. "MozTextDecorationLine",
  14872. "MozTextDecorationStyle",
  14873. "MozTextSizeAdjust",
  14874. "MozTransform",
  14875. "MozTransformOrigin",
  14876. "MozTransformStyle",
  14877. "MozTransition",
  14878. "MozTransitionDelay",
  14879. "MozTransitionDuration",
  14880. "MozTransitionProperty",
  14881. "MozTransitionTimingFunction",
  14882. "MozUserFocus",
  14883. "MozUserInput",
  14884. "MozUserModify",
  14885. "MozUserSelect",
  14886. "MozWindowDragging",
  14887. "MozWindowShadow",
  14888. "MutationEvent",
  14889. "MutationObserver",
  14890. "MutationRecord",
  14891. "NAMESPACE_ERR",
  14892. "NAMESPACE_RULE",
  14893. "NEAREST",
  14894. "NEAREST_MIPMAP_LINEAR",
  14895. "NEAREST_MIPMAP_NEAREST",
  14896. "NEGATIVE_INFINITY",
  14897. "NETWORK_EMPTY",
  14898. "NETWORK_ERR",
  14899. "NETWORK_IDLE",
  14900. "NETWORK_LOADED",
  14901. "NETWORK_LOADING",
  14902. "NETWORK_NO_SOURCE",
  14903. "NEVER",
  14904. "NEW",
  14905. "NEXT",
  14906. "NEXT_NO_DUPLICATE",
  14907. "NICEST",
  14908. "NODE_AFTER",
  14909. "NODE_BEFORE",
  14910. "NODE_BEFORE_AND_AFTER",
  14911. "NODE_INSIDE",
  14912. "NONE",
  14913. "NON_TRANSIENT_ERR",
  14914. "NOTATION_NODE",
  14915. "NOTCH",
  14916. "NOTEQUAL",
  14917. "NOT_ALLOWED_ERR",
  14918. "NOT_FOUND_ERR",
  14919. "NOT_READABLE_ERR",
  14920. "NOT_SUPPORTED_ERR",
  14921. "NO_DATA_ALLOWED_ERR",
  14922. "NO_ERR",
  14923. "NO_ERROR",
  14924. "NO_MODIFICATION_ALLOWED_ERR",
  14925. "NUMBER_TYPE",
  14926. "NUM_COMPRESSED_TEXTURE_FORMATS",
  14927. "NaN",
  14928. "NamedNodeMap",
  14929. "Navigator",
  14930. "NearbyLinks",
  14931. "NetworkInformation",
  14932. "Node",
  14933. "NodeFilter",
  14934. "NodeIterator",
  14935. "NodeList",
  14936. "Notation",
  14937. "Notification",
  14938. "NotifyPaintEvent",
  14939. "Number",
  14940. "NumberFormat",
  14941. "OBSOLETE",
  14942. "ONE",
  14943. "ONE_MINUS_CONSTANT_ALPHA",
  14944. "ONE_MINUS_CONSTANT_COLOR",
  14945. "ONE_MINUS_DST_ALPHA",
  14946. "ONE_MINUS_DST_COLOR",
  14947. "ONE_MINUS_SRC_ALPHA",
  14948. "ONE_MINUS_SRC_COLOR",
  14949. "OPEN",
  14950. "OPENED",
  14951. "OPENING",
  14952. "ORDERED_NODE_ITERATOR_TYPE",
  14953. "ORDERED_NODE_SNAPSHOT_TYPE",
  14954. "OUT_OF_MEMORY",
  14955. "Object",
  14956. "OfflineAudioCompletionEvent",
  14957. "OfflineAudioContext",
  14958. "OfflineResourceList",
  14959. "Option",
  14960. "OscillatorNode",
  14961. "OverflowEvent",
  14962. "PACK_ALIGNMENT",
  14963. "PAGE_RULE",
  14964. "PARSE_ERR",
  14965. "PATHSEG_ARC_ABS",
  14966. "PATHSEG_ARC_REL",
  14967. "PATHSEG_CLOSEPATH",
  14968. "PATHSEG_CURVETO_CUBIC_ABS",
  14969. "PATHSEG_CURVETO_CUBIC_REL",
  14970. "PATHSEG_CURVETO_CUBIC_SMOOTH_ABS",
  14971. "PATHSEG_CURVETO_CUBIC_SMOOTH_REL",
  14972. "PATHSEG_CURVETO_QUADRATIC_ABS",
  14973. "PATHSEG_CURVETO_QUADRATIC_REL",
  14974. "PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS",
  14975. "PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL",
  14976. "PATHSEG_LINETO_ABS",
  14977. "PATHSEG_LINETO_HORIZONTAL_ABS",
  14978. "PATHSEG_LINETO_HORIZONTAL_REL",
  14979. "PATHSEG_LINETO_REL",
  14980. "PATHSEG_LINETO_VERTICAL_ABS",
  14981. "PATHSEG_LINETO_VERTICAL_REL",
  14982. "PATHSEG_MOVETO_ABS",
  14983. "PATHSEG_MOVETO_REL",
  14984. "PATHSEG_UNKNOWN",
  14985. "PATH_EXISTS_ERR",
  14986. "PEAKING",
  14987. "PERMISSION_DENIED",
  14988. "PERSISTENT",
  14989. "PI",
  14990. "PLAYING_STATE",
  14991. "POINTS",
  14992. "POLYGON_OFFSET_FACTOR",
  14993. "POLYGON_OFFSET_FILL",
  14994. "POLYGON_OFFSET_UNITS",
  14995. "POSITION_UNAVAILABLE",
  14996. "POSITIVE_INFINITY",
  14997. "PREV",
  14998. "PREV_NO_DUPLICATE",
  14999. "PROCESSING_INSTRUCTION_NODE",
  15000. "PageChangeEvent",
  15001. "PageTransitionEvent",
  15002. "PaintRequest",
  15003. "PaintRequestList",
  15004. "PannerNode",
  15005. "Path2D",
  15006. "Performance",
  15007. "PerformanceEntry",
  15008. "PerformanceMark",
  15009. "PerformanceMeasure",
  15010. "PerformanceNavigation",
  15011. "PerformanceResourceTiming",
  15012. "PerformanceTiming",
  15013. "PeriodicWave",
  15014. "Plugin",
  15015. "PluginArray",
  15016. "PopStateEvent",
  15017. "PopupBlockedEvent",
  15018. "ProcessingInstruction",
  15019. "ProgressEvent",
  15020. "Promise",
  15021. "PropertyNodeList",
  15022. "Proxy",
  15023. "PushManager",
  15024. "PushSubscription",
  15025. "Q",
  15026. "QUOTA_ERR",
  15027. "QUOTA_EXCEEDED_ERR",
  15028. "QueryInterface",
  15029. "READ_ONLY",
  15030. "READ_ONLY_ERR",
  15031. "READ_WRITE",
  15032. "RED_BITS",
  15033. "REMOVAL",
  15034. "RENDERBUFFER",
  15035. "RENDERBUFFER_ALPHA_SIZE",
  15036. "RENDERBUFFER_BINDING",
  15037. "RENDERBUFFER_BLUE_SIZE",
  15038. "RENDERBUFFER_DEPTH_SIZE",
  15039. "RENDERBUFFER_GREEN_SIZE",
  15040. "RENDERBUFFER_HEIGHT",
  15041. "RENDERBUFFER_INTERNAL_FORMAT",
  15042. "RENDERBUFFER_RED_SIZE",
  15043. "RENDERBUFFER_STENCIL_SIZE",
  15044. "RENDERBUFFER_WIDTH",
  15045. "RENDERER",
  15046. "RENDERING_INTENT_ABSOLUTE_COLORIMETRIC",
  15047. "RENDERING_INTENT_AUTO",
  15048. "RENDERING_INTENT_PERCEPTUAL",
  15049. "RENDERING_INTENT_RELATIVE_COLORIMETRIC",
  15050. "RENDERING_INTENT_SATURATION",
  15051. "RENDERING_INTENT_UNKNOWN",
  15052. "REPEAT",
  15053. "REPLACE",
  15054. "RGB",
  15055. "RGB565",
  15056. "RGB5_A1",
  15057. "RGBA",
  15058. "RGBA4",
  15059. "RGBColor",
  15060. "ROTATION_CLOCKWISE",
  15061. "ROTATION_COUNTERCLOCKWISE",
  15062. "RTCDataChannelEvent",
  15063. "RTCIceCandidate",
  15064. "RTCPeerConnectionIceEvent",
  15065. "RTCRtpReceiver",
  15066. "RTCRtpSender",
  15067. "RTCSessionDescription",
  15068. "RTCStatsReport",
  15069. "RadioNodeList",
  15070. "Range",
  15071. "RangeError",
  15072. "RangeException",
  15073. "RecordErrorEvent",
  15074. "Rect",
  15075. "ReferenceError",
  15076. "RegExp",
  15077. "Request",
  15078. "Response",
  15079. "SAMPLER_2D",
  15080. "SAMPLER_CUBE",
  15081. "SAMPLES",
  15082. "SAMPLE_ALPHA_TO_COVERAGE",
  15083. "SAMPLE_BUFFERS",
  15084. "SAMPLE_COVERAGE",
  15085. "SAMPLE_COVERAGE_INVERT",
  15086. "SAMPLE_COVERAGE_VALUE",
  15087. "SAWTOOTH",
  15088. "SCHEDULED_STATE",
  15089. "SCISSOR_BOX",
  15090. "SCISSOR_TEST",
  15091. "SCROLL_PAGE_DOWN",
  15092. "SCROLL_PAGE_UP",
  15093. "SDP_ANSWER",
  15094. "SDP_OFFER",
  15095. "SDP_PRANSWER",
  15096. "SECURITY_ERR",
  15097. "SELECT",
  15098. "SERIALIZE_ERR",
  15099. "SEVERITY_ERROR",
  15100. "SEVERITY_FATAL_ERROR",
  15101. "SEVERITY_WARNING",
  15102. "SHADER_COMPILER",
  15103. "SHADER_TYPE",
  15104. "SHADING_LANGUAGE_VERSION",
  15105. "SHIFT_MASK",
  15106. "SHORT",
  15107. "SHOWING",
  15108. "SHOW_ALL",
  15109. "SHOW_ATTRIBUTE",
  15110. "SHOW_CDATA_SECTION",
  15111. "SHOW_COMMENT",
  15112. "SHOW_DOCUMENT",
  15113. "SHOW_DOCUMENT_FRAGMENT",
  15114. "SHOW_DOCUMENT_TYPE",
  15115. "SHOW_ELEMENT",
  15116. "SHOW_ENTITY",
  15117. "SHOW_ENTITY_REFERENCE",
  15118. "SHOW_NOTATION",
  15119. "SHOW_PROCESSING_INSTRUCTION",
  15120. "SHOW_TEXT",
  15121. "SINE",
  15122. "SOUNDFIELD",
  15123. "SQLException",
  15124. "SQRT1_2",
  15125. "SQRT2",
  15126. "SQUARE",
  15127. "SRC_ALPHA",
  15128. "SRC_ALPHA_SATURATE",
  15129. "SRC_COLOR",
  15130. "START_TO_END",
  15131. "START_TO_START",
  15132. "STATIC_DRAW",
  15133. "STENCIL_ATTACHMENT",
  15134. "STENCIL_BACK_FAIL",
  15135. "STENCIL_BACK_FUNC",
  15136. "STENCIL_BACK_PASS_DEPTH_FAIL",
  15137. "STENCIL_BACK_PASS_DEPTH_PASS",
  15138. "STENCIL_BACK_REF",
  15139. "STENCIL_BACK_VALUE_MASK",
  15140. "STENCIL_BACK_WRITEMASK",
  15141. "STENCIL_BITS",
  15142. "STENCIL_BUFFER_BIT",
  15143. "STENCIL_CLEAR_VALUE",
  15144. "STENCIL_FAIL",
  15145. "STENCIL_FUNC",
  15146. "STENCIL_INDEX",
  15147. "STENCIL_INDEX8",
  15148. "STENCIL_PASS_DEPTH_FAIL",
  15149. "STENCIL_PASS_DEPTH_PASS",
  15150. "STENCIL_REF",
  15151. "STENCIL_TEST",
  15152. "STENCIL_VALUE_MASK",
  15153. "STENCIL_WRITEMASK",
  15154. "STREAM_DRAW",
  15155. "STRING_TYPE",
  15156. "STYLE_RULE",
  15157. "SUBPIXEL_BITS",
  15158. "SUPPORTS_RULE",
  15159. "SVGAElement",
  15160. "SVGAltGlyphDefElement",
  15161. "SVGAltGlyphElement",
  15162. "SVGAltGlyphItemElement",
  15163. "SVGAngle",
  15164. "SVGAnimateColorElement",
  15165. "SVGAnimateElement",
  15166. "SVGAnimateMotionElement",
  15167. "SVGAnimateTransformElement",
  15168. "SVGAnimatedAngle",
  15169. "SVGAnimatedBoolean",
  15170. "SVGAnimatedEnumeration",
  15171. "SVGAnimatedInteger",
  15172. "SVGAnimatedLength",
  15173. "SVGAnimatedLengthList",
  15174. "SVGAnimatedNumber",
  15175. "SVGAnimatedNumberList",
  15176. "SVGAnimatedPreserveAspectRatio",
  15177. "SVGAnimatedRect",
  15178. "SVGAnimatedString",
  15179. "SVGAnimatedTransformList",
  15180. "SVGAnimationElement",
  15181. "SVGCircleElement",
  15182. "SVGClipPathElement",
  15183. "SVGColor",
  15184. "SVGComponentTransferFunctionElement",
  15185. "SVGCursorElement",
  15186. "SVGDefsElement",
  15187. "SVGDescElement",
  15188. "SVGDiscardElement",
  15189. "SVGDocument",
  15190. "SVGElement",
  15191. "SVGElementInstance",
  15192. "SVGElementInstanceList",
  15193. "SVGEllipseElement",
  15194. "SVGException",
  15195. "SVGFEBlendElement",
  15196. "SVGFEColorMatrixElement",
  15197. "SVGFEComponentTransferElement",
  15198. "SVGFECompositeElement",
  15199. "SVGFEConvolveMatrixElement",
  15200. "SVGFEDiffuseLightingElement",
  15201. "SVGFEDisplacementMapElement",
  15202. "SVGFEDistantLightElement",
  15203. "SVGFEDropShadowElement",
  15204. "SVGFEFloodElement",
  15205. "SVGFEFuncAElement",
  15206. "SVGFEFuncBElement",
  15207. "SVGFEFuncGElement",
  15208. "SVGFEFuncRElement",
  15209. "SVGFEGaussianBlurElement",
  15210. "SVGFEImageElement",
  15211. "SVGFEMergeElement",
  15212. "SVGFEMergeNodeElement",
  15213. "SVGFEMorphologyElement",
  15214. "SVGFEOffsetElement",
  15215. "SVGFEPointLightElement",
  15216. "SVGFESpecularLightingElement",
  15217. "SVGFESpotLightElement",
  15218. "SVGFETileElement",
  15219. "SVGFETurbulenceElement",
  15220. "SVGFilterElement",
  15221. "SVGFontElement",
  15222. "SVGFontFaceElement",
  15223. "SVGFontFaceFormatElement",
  15224. "SVGFontFaceNameElement",
  15225. "SVGFontFaceSrcElement",
  15226. "SVGFontFaceUriElement",
  15227. "SVGForeignObjectElement",
  15228. "SVGGElement",
  15229. "SVGGeometryElement",
  15230. "SVGGlyphElement",
  15231. "SVGGlyphRefElement",
  15232. "SVGGradientElement",
  15233. "SVGGraphicsElement",
  15234. "SVGHKernElement",
  15235. "SVGImageElement",
  15236. "SVGLength",
  15237. "SVGLengthList",
  15238. "SVGLineElement",
  15239. "SVGLinearGradientElement",
  15240. "SVGMPathElement",
  15241. "SVGMarkerElement",
  15242. "SVGMaskElement",
  15243. "SVGMatrix",
  15244. "SVGMetadataElement",
  15245. "SVGMissingGlyphElement",
  15246. "SVGNumber",
  15247. "SVGNumberList",
  15248. "SVGPaint",
  15249. "SVGPathElement",
  15250. "SVGPathSeg",
  15251. "SVGPathSegArcAbs",
  15252. "SVGPathSegArcRel",
  15253. "SVGPathSegClosePath",
  15254. "SVGPathSegCurvetoCubicAbs",
  15255. "SVGPathSegCurvetoCubicRel",
  15256. "SVGPathSegCurvetoCubicSmoothAbs",
  15257. "SVGPathSegCurvetoCubicSmoothRel",
  15258. "SVGPathSegCurvetoQuadraticAbs",
  15259. "SVGPathSegCurvetoQuadraticRel",
  15260. "SVGPathSegCurvetoQuadraticSmoothAbs",
  15261. "SVGPathSegCurvetoQuadraticSmoothRel",
  15262. "SVGPathSegLinetoAbs",
  15263. "SVGPathSegLinetoHorizontalAbs",
  15264. "SVGPathSegLinetoHorizontalRel",
  15265. "SVGPathSegLinetoRel",
  15266. "SVGPathSegLinetoVerticalAbs",
  15267. "SVGPathSegLinetoVerticalRel",
  15268. "SVGPathSegList",
  15269. "SVGPathSegMovetoAbs",
  15270. "SVGPathSegMovetoRel",
  15271. "SVGPatternElement",
  15272. "SVGPoint",
  15273. "SVGPointList",
  15274. "SVGPolygonElement",
  15275. "SVGPolylineElement",
  15276. "SVGPreserveAspectRatio",
  15277. "SVGRadialGradientElement",
  15278. "SVGRect",
  15279. "SVGRectElement",
  15280. "SVGRenderingIntent",
  15281. "SVGSVGElement",
  15282. "SVGScriptElement",
  15283. "SVGSetElement",
  15284. "SVGStopElement",
  15285. "SVGStringList",
  15286. "SVGStyleElement",
  15287. "SVGSwitchElement",
  15288. "SVGSymbolElement",
  15289. "SVGTRefElement",
  15290. "SVGTSpanElement",
  15291. "SVGTextContentElement",
  15292. "SVGTextElement",
  15293. "SVGTextPathElement",
  15294. "SVGTextPositioningElement",
  15295. "SVGTitleElement",
  15296. "SVGTransform",
  15297. "SVGTransformList",
  15298. "SVGUnitTypes",
  15299. "SVGUseElement",
  15300. "SVGVKernElement",
  15301. "SVGViewElement",
  15302. "SVGViewSpec",
  15303. "SVGZoomAndPan",
  15304. "SVGZoomEvent",
  15305. "SVG_ANGLETYPE_DEG",
  15306. "SVG_ANGLETYPE_GRAD",
  15307. "SVG_ANGLETYPE_RAD",
  15308. "SVG_ANGLETYPE_UNKNOWN",
  15309. "SVG_ANGLETYPE_UNSPECIFIED",
  15310. "SVG_CHANNEL_A",
  15311. "SVG_CHANNEL_B",
  15312. "SVG_CHANNEL_G",
  15313. "SVG_CHANNEL_R",
  15314. "SVG_CHANNEL_UNKNOWN",
  15315. "SVG_COLORTYPE_CURRENTCOLOR",
  15316. "SVG_COLORTYPE_RGBCOLOR",
  15317. "SVG_COLORTYPE_RGBCOLOR_ICCCOLOR",
  15318. "SVG_COLORTYPE_UNKNOWN",
  15319. "SVG_EDGEMODE_DUPLICATE",
  15320. "SVG_EDGEMODE_NONE",
  15321. "SVG_EDGEMODE_UNKNOWN",
  15322. "SVG_EDGEMODE_WRAP",
  15323. "SVG_FEBLEND_MODE_COLOR",
  15324. "SVG_FEBLEND_MODE_COLOR_BURN",
  15325. "SVG_FEBLEND_MODE_COLOR_DODGE",
  15326. "SVG_FEBLEND_MODE_DARKEN",
  15327. "SVG_FEBLEND_MODE_DIFFERENCE",
  15328. "SVG_FEBLEND_MODE_EXCLUSION",
  15329. "SVG_FEBLEND_MODE_HARD_LIGHT",
  15330. "SVG_FEBLEND_MODE_HUE",
  15331. "SVG_FEBLEND_MODE_LIGHTEN",
  15332. "SVG_FEBLEND_MODE_LUMINOSITY",
  15333. "SVG_FEBLEND_MODE_MULTIPLY",
  15334. "SVG_FEBLEND_MODE_NORMAL",
  15335. "SVG_FEBLEND_MODE_OVERLAY",
  15336. "SVG_FEBLEND_MODE_SATURATION",
  15337. "SVG_FEBLEND_MODE_SCREEN",
  15338. "SVG_FEBLEND_MODE_SOFT_LIGHT",
  15339. "SVG_FEBLEND_MODE_UNKNOWN",
  15340. "SVG_FECOLORMATRIX_TYPE_HUEROTATE",
  15341. "SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA",
  15342. "SVG_FECOLORMATRIX_TYPE_MATRIX",
  15343. "SVG_FECOLORMATRIX_TYPE_SATURATE",
  15344. "SVG_FECOLORMATRIX_TYPE_UNKNOWN",
  15345. "SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE",
  15346. "SVG_FECOMPONENTTRANSFER_TYPE_GAMMA",
  15347. "SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY",
  15348. "SVG_FECOMPONENTTRANSFER_TYPE_LINEAR",
  15349. "SVG_FECOMPONENTTRANSFER_TYPE_TABLE",
  15350. "SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN",
  15351. "SVG_FECOMPOSITE_OPERATOR_ARITHMETIC",
  15352. "SVG_FECOMPOSITE_OPERATOR_ATOP",
  15353. "SVG_FECOMPOSITE_OPERATOR_IN",
  15354. "SVG_FECOMPOSITE_OPERATOR_OUT",
  15355. "SVG_FECOMPOSITE_OPERATOR_OVER",
  15356. "SVG_FECOMPOSITE_OPERATOR_UNKNOWN",
  15357. "SVG_FECOMPOSITE_OPERATOR_XOR",
  15358. "SVG_INVALID_VALUE_ERR",
  15359. "SVG_LENGTHTYPE_CM",
  15360. "SVG_LENGTHTYPE_EMS",
  15361. "SVG_LENGTHTYPE_EXS",
  15362. "SVG_LENGTHTYPE_IN",
  15363. "SVG_LENGTHTYPE_MM",
  15364. "SVG_LENGTHTYPE_NUMBER",
  15365. "SVG_LENGTHTYPE_PC",
  15366. "SVG_LENGTHTYPE_PERCENTAGE",
  15367. "SVG_LENGTHTYPE_PT",
  15368. "SVG_LENGTHTYPE_PX",
  15369. "SVG_LENGTHTYPE_UNKNOWN",
  15370. "SVG_MARKERUNITS_STROKEWIDTH",
  15371. "SVG_MARKERUNITS_UNKNOWN",
  15372. "SVG_MARKERUNITS_USERSPACEONUSE",
  15373. "SVG_MARKER_ORIENT_ANGLE",
  15374. "SVG_MARKER_ORIENT_AUTO",
  15375. "SVG_MARKER_ORIENT_UNKNOWN",
  15376. "SVG_MASKTYPE_ALPHA",
  15377. "SVG_MASKTYPE_LUMINANCE",
  15378. "SVG_MATRIX_NOT_INVERTABLE",
  15379. "SVG_MEETORSLICE_MEET",
  15380. "SVG_MEETORSLICE_SLICE",
  15381. "SVG_MEETORSLICE_UNKNOWN",
  15382. "SVG_MORPHOLOGY_OPERATOR_DILATE",
  15383. "SVG_MORPHOLOGY_OPERATOR_ERODE",
  15384. "SVG_MORPHOLOGY_OPERATOR_UNKNOWN",
  15385. "SVG_PAINTTYPE_CURRENTCOLOR",
  15386. "SVG_PAINTTYPE_NONE",
  15387. "SVG_PAINTTYPE_RGBCOLOR",
  15388. "SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR",
  15389. "SVG_PAINTTYPE_UNKNOWN",
  15390. "SVG_PAINTTYPE_URI",
  15391. "SVG_PAINTTYPE_URI_CURRENTCOLOR",
  15392. "SVG_PAINTTYPE_URI_NONE",
  15393. "SVG_PAINTTYPE_URI_RGBCOLOR",
  15394. "SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR",
  15395. "SVG_PRESERVEASPECTRATIO_NONE",
  15396. "SVG_PRESERVEASPECTRATIO_UNKNOWN",
  15397. "SVG_PRESERVEASPECTRATIO_XMAXYMAX",
  15398. "SVG_PRESERVEASPECTRATIO_XMAXYMID",
  15399. "SVG_PRESERVEASPECTRATIO_XMAXYMIN",
  15400. "SVG_PRESERVEASPECTRATIO_XMIDYMAX",
  15401. "SVG_PRESERVEASPECTRATIO_XMIDYMID",
  15402. "SVG_PRESERVEASPECTRATIO_XMIDYMIN",
  15403. "SVG_PRESERVEASPECTRATIO_XMINYMAX",
  15404. "SVG_PRESERVEASPECTRATIO_XMINYMID",
  15405. "SVG_PRESERVEASPECTRATIO_XMINYMIN",
  15406. "SVG_SPREADMETHOD_PAD",
  15407. "SVG_SPREADMETHOD_REFLECT",
  15408. "SVG_SPREADMETHOD_REPEAT",
  15409. "SVG_SPREADMETHOD_UNKNOWN",
  15410. "SVG_STITCHTYPE_NOSTITCH",
  15411. "SVG_STITCHTYPE_STITCH",
  15412. "SVG_STITCHTYPE_UNKNOWN",
  15413. "SVG_TRANSFORM_MATRIX",
  15414. "SVG_TRANSFORM_ROTATE",
  15415. "SVG_TRANSFORM_SCALE",
  15416. "SVG_TRANSFORM_SKEWX",
  15417. "SVG_TRANSFORM_SKEWY",
  15418. "SVG_TRANSFORM_TRANSLATE",
  15419. "SVG_TRANSFORM_UNKNOWN",
  15420. "SVG_TURBULENCE_TYPE_FRACTALNOISE",
  15421. "SVG_TURBULENCE_TYPE_TURBULENCE",
  15422. "SVG_TURBULENCE_TYPE_UNKNOWN",
  15423. "SVG_UNIT_TYPE_OBJECTBOUNDINGBOX",
  15424. "SVG_UNIT_TYPE_UNKNOWN",
  15425. "SVG_UNIT_TYPE_USERSPACEONUSE",
  15426. "SVG_WRONG_TYPE_ERR",
  15427. "SVG_ZOOMANDPAN_DISABLE",
  15428. "SVG_ZOOMANDPAN_MAGNIFY",
  15429. "SVG_ZOOMANDPAN_UNKNOWN",
  15430. "SYNTAX_ERR",
  15431. "SavedPages",
  15432. "Screen",
  15433. "ScreenOrientation",
  15434. "Script",
  15435. "ScriptProcessorNode",
  15436. "ScrollAreaEvent",
  15437. "SecurityPolicyViolationEvent",
  15438. "Selection",
  15439. "ServiceWorker",
  15440. "ServiceWorkerContainer",
  15441. "ServiceWorkerRegistration",
  15442. "SessionDescription",
  15443. "Set",
  15444. "ShadowRoot",
  15445. "SharedWorker",
  15446. "SimpleGestureEvent",
  15447. "SpeechSynthesisEvent",
  15448. "SpeechSynthesisUtterance",
  15449. "StopIteration",
  15450. "Storage",
  15451. "StorageEvent",
  15452. "String",
  15453. "StyleSheet",
  15454. "StyleSheetList",
  15455. "SubtleCrypto",
  15456. "Symbol",
  15457. "SyntaxError",
  15458. "TEMPORARY",
  15459. "TEXTPATH_METHODTYPE_ALIGN",
  15460. "TEXTPATH_METHODTYPE_STRETCH",
  15461. "TEXTPATH_METHODTYPE_UNKNOWN",
  15462. "TEXTPATH_SPACINGTYPE_AUTO",
  15463. "TEXTPATH_SPACINGTYPE_EXACT",
  15464. "TEXTPATH_SPACINGTYPE_UNKNOWN",
  15465. "TEXTURE",
  15466. "TEXTURE0",
  15467. "TEXTURE1",
  15468. "TEXTURE10",
  15469. "TEXTURE11",
  15470. "TEXTURE12",
  15471. "TEXTURE13",
  15472. "TEXTURE14",
  15473. "TEXTURE15",
  15474. "TEXTURE16",
  15475. "TEXTURE17",
  15476. "TEXTURE18",
  15477. "TEXTURE19",
  15478. "TEXTURE2",
  15479. "TEXTURE20",
  15480. "TEXTURE21",
  15481. "TEXTURE22",
  15482. "TEXTURE23",
  15483. "TEXTURE24",
  15484. "TEXTURE25",
  15485. "TEXTURE26",
  15486. "TEXTURE27",
  15487. "TEXTURE28",
  15488. "TEXTURE29",
  15489. "TEXTURE3",
  15490. "TEXTURE30",
  15491. "TEXTURE31",
  15492. "TEXTURE4",
  15493. "TEXTURE5",
  15494. "TEXTURE6",
  15495. "TEXTURE7",
  15496. "TEXTURE8",
  15497. "TEXTURE9",
  15498. "TEXTURE_2D",
  15499. "TEXTURE_BINDING_2D",
  15500. "TEXTURE_BINDING_CUBE_MAP",
  15501. "TEXTURE_CUBE_MAP",
  15502. "TEXTURE_CUBE_MAP_NEGATIVE_X",
  15503. "TEXTURE_CUBE_MAP_NEGATIVE_Y",
  15504. "TEXTURE_CUBE_MAP_NEGATIVE_Z",
  15505. "TEXTURE_CUBE_MAP_POSITIVE_X",
  15506. "TEXTURE_CUBE_MAP_POSITIVE_Y",
  15507. "TEXTURE_CUBE_MAP_POSITIVE_Z",
  15508. "TEXTURE_MAG_FILTER",
  15509. "TEXTURE_MAX_ANISOTROPY_EXT",
  15510. "TEXTURE_MIN_FILTER",
  15511. "TEXTURE_WRAP_S",
  15512. "TEXTURE_WRAP_T",
  15513. "TEXT_NODE",
  15514. "TIMEOUT",
  15515. "TIMEOUT_ERR",
  15516. "TOO_LARGE_ERR",
  15517. "TRANSACTION_INACTIVE_ERR",
  15518. "TRIANGLE",
  15519. "TRIANGLES",
  15520. "TRIANGLE_FAN",
  15521. "TRIANGLE_STRIP",
  15522. "TYPE_BACK_FORWARD",
  15523. "TYPE_ERR",
  15524. "TYPE_MISMATCH_ERR",
  15525. "TYPE_NAVIGATE",
  15526. "TYPE_RELOAD",
  15527. "TYPE_RESERVED",
  15528. "Text",
  15529. "TextDecoder",
  15530. "TextEncoder",
  15531. "TextEvent",
  15532. "TextMetrics",
  15533. "TextTrack",
  15534. "TextTrackCue",
  15535. "TextTrackCueList",
  15536. "TextTrackList",
  15537. "TimeEvent",
  15538. "TimeRanges",
  15539. "Touch",
  15540. "TouchEvent",
  15541. "TouchList",
  15542. "TrackEvent",
  15543. "TransitionEvent",
  15544. "TreeWalker",
  15545. "TypeError",
  15546. "UIEvent",
  15547. "UNCACHED",
  15548. "UNKNOWN_ERR",
  15549. "UNKNOWN_RULE",
  15550. "UNMASKED_RENDERER_WEBGL",
  15551. "UNMASKED_VENDOR_WEBGL",
  15552. "UNORDERED_NODE_ITERATOR_TYPE",
  15553. "UNORDERED_NODE_SNAPSHOT_TYPE",
  15554. "UNPACK_ALIGNMENT",
  15555. "UNPACK_COLORSPACE_CONVERSION_WEBGL",
  15556. "UNPACK_FLIP_Y_WEBGL",
  15557. "UNPACK_PREMULTIPLY_ALPHA_WEBGL",
  15558. "UNSCHEDULED_STATE",
  15559. "UNSENT",
  15560. "UNSIGNED_BYTE",
  15561. "UNSIGNED_INT",
  15562. "UNSIGNED_SHORT",
  15563. "UNSIGNED_SHORT_4_4_4_4",
  15564. "UNSIGNED_SHORT_5_5_5_1",
  15565. "UNSIGNED_SHORT_5_6_5",
  15566. "UNSPECIFIED_EVENT_TYPE_ERR",
  15567. "UPDATEREADY",
  15568. "URIError",
  15569. "URL",
  15570. "URLSearchParams",
  15571. "URLUnencoded",
  15572. "URL_MISMATCH_ERR",
  15573. "UTC",
  15574. "Uint16Array",
  15575. "Uint32Array",
  15576. "Uint8Array",
  15577. "Uint8ClampedArray",
  15578. "UserMessageHandler",
  15579. "UserMessageHandlersNamespace",
  15580. "UserProximityEvent",
  15581. "VALIDATE_STATUS",
  15582. "VALIDATION_ERR",
  15583. "VARIABLES_RULE",
  15584. "VENDOR",
  15585. "VERSION",
  15586. "VERSION_CHANGE",
  15587. "VERSION_ERR",
  15588. "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING",
  15589. "VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE",
  15590. "VERTEX_ATTRIB_ARRAY_ENABLED",
  15591. "VERTEX_ATTRIB_ARRAY_NORMALIZED",
  15592. "VERTEX_ATTRIB_ARRAY_POINTER",
  15593. "VERTEX_ATTRIB_ARRAY_SIZE",
  15594. "VERTEX_ATTRIB_ARRAY_STRIDE",
  15595. "VERTEX_ATTRIB_ARRAY_TYPE",
  15596. "VERTEX_SHADER",
  15597. "VERTICAL",
  15598. "VERTICAL_AXIS",
  15599. "VER_ERR",
  15600. "VIEWPORT",
  15601. "VIEWPORT_RULE",
  15602. "VTTCue",
  15603. "VTTRegion",
  15604. "ValidityState",
  15605. "VideoStreamTrack",
  15606. "WEBKIT_FILTER_RULE",
  15607. "WEBKIT_KEYFRAMES_RULE",
  15608. "WEBKIT_KEYFRAME_RULE",
  15609. "WEBKIT_REGION_RULE",
  15610. "WRONG_DOCUMENT_ERR",
  15611. "WaveShaperNode",
  15612. "WeakMap",
  15613. "WeakSet",
  15614. "WebGLActiveInfo",
  15615. "WebGLBuffer",
  15616. "WebGLContextEvent",
  15617. "WebGLFramebuffer",
  15618. "WebGLProgram",
  15619. "WebGLRenderbuffer",
  15620. "WebGLRenderingContext",
  15621. "WebGLShader",
  15622. "WebGLShaderPrecisionFormat",
  15623. "WebGLTexture",
  15624. "WebGLUniformLocation",
  15625. "WebGLVertexArray",
  15626. "WebKitAnimationEvent",
  15627. "WebKitBlobBuilder",
  15628. "WebKitCSSFilterRule",
  15629. "WebKitCSSFilterValue",
  15630. "WebKitCSSKeyframeRule",
  15631. "WebKitCSSKeyframesRule",
  15632. "WebKitCSSMatrix",
  15633. "WebKitCSSRegionRule",
  15634. "WebKitCSSTransformValue",
  15635. "WebKitDataCue",
  15636. "WebKitGamepad",
  15637. "WebKitMediaKeyError",
  15638. "WebKitMediaKeyMessageEvent",
  15639. "WebKitMediaKeySession",
  15640. "WebKitMediaKeys",
  15641. "WebKitMediaSource",
  15642. "WebKitMutationObserver",
  15643. "WebKitNamespace",
  15644. "WebKitPlaybackTargetAvailabilityEvent",
  15645. "WebKitPoint",
  15646. "WebKitShadowRoot",
  15647. "WebKitSourceBuffer",
  15648. "WebKitSourceBufferList",
  15649. "WebKitTransitionEvent",
  15650. "WebSocket",
  15651. "WheelEvent",
  15652. "Window",
  15653. "Worker",
  15654. "XMLDocument",
  15655. "XMLHttpRequest",
  15656. "XMLHttpRequestEventTarget",
  15657. "XMLHttpRequestException",
  15658. "XMLHttpRequestProgressEvent",
  15659. "XMLHttpRequestUpload",
  15660. "XMLSerializer",
  15661. "XMLStylesheetProcessingInstruction",
  15662. "XPathEvaluator",
  15663. "XPathException",
  15664. "XPathExpression",
  15665. "XPathNSResolver",
  15666. "XPathResult",
  15667. "XSLTProcessor",
  15668. "ZERO",
  15669. "_XD0M_",
  15670. "_YD0M_",
  15671. "__defineGetter__",
  15672. "__defineSetter__",
  15673. "__lookupGetter__",
  15674. "__lookupSetter__",
  15675. "__opera",
  15676. "__proto__",
  15677. "_browserjsran",
  15678. "a",
  15679. "aLink",
  15680. "abbr",
  15681. "abort",
  15682. "abs",
  15683. "absolute",
  15684. "acceleration",
  15685. "accelerationIncludingGravity",
  15686. "accelerator",
  15687. "accept",
  15688. "acceptCharset",
  15689. "acceptNode",
  15690. "accessKey",
  15691. "accessKeyLabel",
  15692. "accuracy",
  15693. "acos",
  15694. "acosh",
  15695. "action",
  15696. "actionURL",
  15697. "active",
  15698. "activeCues",
  15699. "activeElement",
  15700. "activeSourceBuffers",
  15701. "activeSourceCount",
  15702. "activeTexture",
  15703. "add",
  15704. "addBehavior",
  15705. "addCandidate",
  15706. "addColorStop",
  15707. "addCue",
  15708. "addElement",
  15709. "addEventListener",
  15710. "addFilter",
  15711. "addFromString",
  15712. "addFromUri",
  15713. "addIceCandidate",
  15714. "addImport",
  15715. "addListener",
  15716. "addNamed",
  15717. "addPageRule",
  15718. "addPath",
  15719. "addPointer",
  15720. "addRange",
  15721. "addRegion",
  15722. "addRule",
  15723. "addSearchEngine",
  15724. "addSourceBuffer",
  15725. "addStream",
  15726. "addTextTrack",
  15727. "addTrack",
  15728. "addWakeLockListener",
  15729. "addedNodes",
  15730. "additionalName",
  15731. "additiveSymbols",
  15732. "addons",
  15733. "adoptNode",
  15734. "adr",
  15735. "advance",
  15736. "alert",
  15737. "algorithm",
  15738. "align",
  15739. "align-content",
  15740. "align-items",
  15741. "align-self",
  15742. "alignContent",
  15743. "alignItems",
  15744. "alignSelf",
  15745. "alignmentBaseline",
  15746. "alinkColor",
  15747. "all",
  15748. "allowFullscreen",
  15749. "allowedDirections",
  15750. "alpha",
  15751. "alt",
  15752. "altGraphKey",
  15753. "altHtml",
  15754. "altKey",
  15755. "altLeft",
  15756. "altitude",
  15757. "altitudeAccuracy",
  15758. "amplitude",
  15759. "ancestorOrigins",
  15760. "anchor",
  15761. "anchorNode",
  15762. "anchorOffset",
  15763. "anchors",
  15764. "angle",
  15765. "animVal",
  15766. "animate",
  15767. "animatedInstanceRoot",
  15768. "animatedNormalizedPathSegList",
  15769. "animatedPathSegList",
  15770. "animatedPoints",
  15771. "animation",
  15772. "animation-delay",
  15773. "animation-direction",
  15774. "animation-duration",
  15775. "animation-fill-mode",
  15776. "animation-iteration-count",
  15777. "animation-name",
  15778. "animation-play-state",
  15779. "animation-timing-function",
  15780. "animationDelay",
  15781. "animationDirection",
  15782. "animationDuration",
  15783. "animationFillMode",
  15784. "animationIterationCount",
  15785. "animationName",
  15786. "animationPlayState",
  15787. "animationStartTime",
  15788. "animationTimingFunction",
  15789. "animationsPaused",
  15790. "anniversary",
  15791. "app",
  15792. "appCodeName",
  15793. "appMinorVersion",
  15794. "appName",
  15795. "appNotifications",
  15796. "appVersion",
  15797. "append",
  15798. "appendBuffer",
  15799. "appendChild",
  15800. "appendData",
  15801. "appendItem",
  15802. "appendMedium",
  15803. "appendNamed",
  15804. "appendRule",
  15805. "appendStream",
  15806. "appendWindowEnd",
  15807. "appendWindowStart",
  15808. "applets",
  15809. "applicationCache",
  15810. "apply",
  15811. "applyElement",
  15812. "arc",
  15813. "arcTo",
  15814. "archive",
  15815. "areas",
  15816. "arguments",
  15817. "arrayBuffer",
  15818. "asin",
  15819. "asinh",
  15820. "assert",
  15821. "assign",
  15822. "async",
  15823. "atEnd",
  15824. "atan",
  15825. "atan2",
  15826. "atanh",
  15827. "atob",
  15828. "attachEvent",
  15829. "attachShader",
  15830. "attachments",
  15831. "attack",
  15832. "attrChange",
  15833. "attrName",
  15834. "attributeName",
  15835. "attributeNamespace",
  15836. "attributes",
  15837. "audioTracks",
  15838. "autoIncrement",
  15839. "autobuffer",
  15840. "autocapitalize",
  15841. "autocomplete",
  15842. "autocorrect",
  15843. "autofocus",
  15844. "autoplay",
  15845. "availHeight",
  15846. "availLeft",
  15847. "availTop",
  15848. "availWidth",
  15849. "availability",
  15850. "available",
  15851. "aversion",
  15852. "axes",
  15853. "axis",
  15854. "azimuth",
  15855. "b",
  15856. "back",
  15857. "backface-visibility",
  15858. "backfaceVisibility",
  15859. "background",
  15860. "background-attachment",
  15861. "background-blend-mode",
  15862. "background-clip",
  15863. "background-color",
  15864. "background-image",
  15865. "background-origin",
  15866. "background-position",
  15867. "background-repeat",
  15868. "background-size",
  15869. "backgroundAttachment",
  15870. "backgroundBlendMode",
  15871. "backgroundClip",
  15872. "backgroundColor",
  15873. "backgroundImage",
  15874. "backgroundOrigin",
  15875. "backgroundPosition",
  15876. "backgroundPositionX",
  15877. "backgroundPositionY",
  15878. "backgroundRepeat",
  15879. "backgroundSize",
  15880. "badInput",
  15881. "balance",
  15882. "baseFrequencyX",
  15883. "baseFrequencyY",
  15884. "baseNode",
  15885. "baseOffset",
  15886. "baseURI",
  15887. "baseVal",
  15888. "baselineShift",
  15889. "battery",
  15890. "bday",
  15891. "beginElement",
  15892. "beginElementAt",
  15893. "beginPath",
  15894. "behavior",
  15895. "behaviorCookie",
  15896. "behaviorPart",
  15897. "behaviorUrns",
  15898. "beta",
  15899. "bezierCurveTo",
  15900. "bgColor",
  15901. "bgProperties",
  15902. "bias",
  15903. "big",
  15904. "binaryType",
  15905. "bind",
  15906. "bindAttribLocation",
  15907. "bindBuffer",
  15908. "bindFramebuffer",
  15909. "bindRenderbuffer",
  15910. "bindTexture",
  15911. "blendColor",
  15912. "blendEquation",
  15913. "blendEquationSeparate",
  15914. "blendFunc",
  15915. "blendFuncSeparate",
  15916. "blink",
  15917. "blob",
  15918. "blockDirection",
  15919. "blue",
  15920. "blur",
  15921. "body",
  15922. "bodyUsed",
  15923. "bold",
  15924. "bookmarks",
  15925. "booleanValue",
  15926. "border",
  15927. "border-bottom",
  15928. "border-bottom-color",
  15929. "border-bottom-left-radius",
  15930. "border-bottom-right-radius",
  15931. "border-bottom-style",
  15932. "border-bottom-width",
  15933. "border-collapse",
  15934. "border-color",
  15935. "border-image",
  15936. "border-image-outset",
  15937. "border-image-repeat",
  15938. "border-image-slice",
  15939. "border-image-source",
  15940. "border-image-width",
  15941. "border-left",
  15942. "border-left-color",
  15943. "border-left-style",
  15944. "border-left-width",
  15945. "border-radius",
  15946. "border-right",
  15947. "border-right-color",
  15948. "border-right-style",
  15949. "border-right-width",
  15950. "border-spacing",
  15951. "border-style",
  15952. "border-top",
  15953. "border-top-color",
  15954. "border-top-left-radius",
  15955. "border-top-right-radius",
  15956. "border-top-style",
  15957. "border-top-width",
  15958. "border-width",
  15959. "borderBottom",
  15960. "borderBottomColor",
  15961. "borderBottomLeftRadius",
  15962. "borderBottomRightRadius",
  15963. "borderBottomStyle",
  15964. "borderBottomWidth",
  15965. "borderCollapse",
  15966. "borderColor",
  15967. "borderColorDark",
  15968. "borderColorLight",
  15969. "borderImage",
  15970. "borderImageOutset",
  15971. "borderImageRepeat",
  15972. "borderImageSlice",
  15973. "borderImageSource",
  15974. "borderImageWidth",
  15975. "borderLeft",
  15976. "borderLeftColor",
  15977. "borderLeftStyle",
  15978. "borderLeftWidth",
  15979. "borderRadius",
  15980. "borderRight",
  15981. "borderRightColor",
  15982. "borderRightStyle",
  15983. "borderRightWidth",
  15984. "borderSpacing",
  15985. "borderStyle",
  15986. "borderTop",
  15987. "borderTopColor",
  15988. "borderTopLeftRadius",
  15989. "borderTopRightRadius",
  15990. "borderTopStyle",
  15991. "borderTopWidth",
  15992. "borderWidth",
  15993. "bottom",
  15994. "bottomMargin",
  15995. "bound",
  15996. "boundElements",
  15997. "boundingClientRect",
  15998. "boundingHeight",
  15999. "boundingLeft",
  16000. "boundingTop",
  16001. "boundingWidth",
  16002. "bounds",
  16003. "box-decoration-break",
  16004. "box-shadow",
  16005. "box-sizing",
  16006. "boxDecorationBreak",
  16007. "boxShadow",
  16008. "boxSizing",
  16009. "breakAfter",
  16010. "breakBefore",
  16011. "breakInside",
  16012. "browserLanguage",
  16013. "btoa",
  16014. "bubbles",
  16015. "buffer",
  16016. "bufferData",
  16017. "bufferDepth",
  16018. "bufferSize",
  16019. "bufferSubData",
  16020. "buffered",
  16021. "bufferedAmount",
  16022. "buildID",
  16023. "buildNumber",
  16024. "button",
  16025. "buttonID",
  16026. "buttons",
  16027. "byteLength",
  16028. "byteOffset",
  16029. "c",
  16030. "call",
  16031. "caller",
  16032. "canBeFormatted",
  16033. "canBeMounted",
  16034. "canBeShared",
  16035. "canHaveChildren",
  16036. "canHaveHTML",
  16037. "canPlayType",
  16038. "cancel",
  16039. "cancelAnimationFrame",
  16040. "cancelBubble",
  16041. "cancelScheduledValues",
  16042. "cancelable",
  16043. "candidate",
  16044. "canvas",
  16045. "caption",
  16046. "caption-side",
  16047. "captionSide",
  16048. "captureEvents",
  16049. "captureStackTrace",
  16050. "caretPositionFromPoint",
  16051. "caretRangeFromPoint",
  16052. "cast",
  16053. "catch",
  16054. "category",
  16055. "cbrt",
  16056. "cd",
  16057. "ceil",
  16058. "cellIndex",
  16059. "cellPadding",
  16060. "cellSpacing",
  16061. "cells",
  16062. "ch",
  16063. "chOff",
  16064. "chain",
  16065. "challenge",
  16066. "changedTouches",
  16067. "channel",
  16068. "channelCount",
  16069. "channelCountMode",
  16070. "channelInterpretation",
  16071. "char",
  16072. "charAt",
  16073. "charCode",
  16074. "charCodeAt",
  16075. "charIndex",
  16076. "characterSet",
  16077. "charging",
  16078. "chargingTime",
  16079. "charset",
  16080. "checkEnclosure",
  16081. "checkFramebufferStatus",
  16082. "checkIntersection",
  16083. "checkValidity",
  16084. "checked",
  16085. "childElementCount",
  16086. "childNodes",
  16087. "children",
  16088. "chrome",
  16089. "ciphertext",
  16090. "cite",
  16091. "classList",
  16092. "className",
  16093. "classid",
  16094. "clear",
  16095. "clearAttributes",
  16096. "clearColor",
  16097. "clearData",
  16098. "clearDepth",
  16099. "clearImmediate",
  16100. "clearInterval",
  16101. "clearMarks",
  16102. "clearMeasures",
  16103. "clearParameters",
  16104. "clearRect",
  16105. "clearResourceTimings",
  16106. "clearShadow",
  16107. "clearStencil",
  16108. "clearTimeout",
  16109. "clearWatch",
  16110. "click",
  16111. "clickCount",
  16112. "clientHeight",
  16113. "clientInformation",
  16114. "clientLeft",
  16115. "clientRect",
  16116. "clientRects",
  16117. "clientTop",
  16118. "clientWidth",
  16119. "clientX",
  16120. "clientY",
  16121. "clip",
  16122. "clip-path",
  16123. "clip-rule",
  16124. "clipBottom",
  16125. "clipLeft",
  16126. "clipPath",
  16127. "clipPathUnits",
  16128. "clipRight",
  16129. "clipRule",
  16130. "clipTop",
  16131. "clipboardData",
  16132. "clone",
  16133. "cloneContents",
  16134. "cloneNode",
  16135. "cloneRange",
  16136. "close",
  16137. "closePath",
  16138. "closed",
  16139. "closest",
  16140. "clz",
  16141. "clz32",
  16142. "cmp",
  16143. "code",
  16144. "codeBase",
  16145. "codePointAt",
  16146. "codeType",
  16147. "colSpan",
  16148. "collapse",
  16149. "collapseToEnd",
  16150. "collapseToStart",
  16151. "collapsed",
  16152. "collect",
  16153. "colno",
  16154. "color",
  16155. "color-interpolation",
  16156. "color-interpolation-filters",
  16157. "colorDepth",
  16158. "colorInterpolation",
  16159. "colorInterpolationFilters",
  16160. "colorMask",
  16161. "colorType",
  16162. "cols",
  16163. "columnCount",
  16164. "columnFill",
  16165. "columnGap",
  16166. "columnNumber",
  16167. "columnRule",
  16168. "columnRuleColor",
  16169. "columnRuleStyle",
  16170. "columnRuleWidth",
  16171. "columnSpan",
  16172. "columnWidth",
  16173. "columns",
  16174. "command",
  16175. "commitPreferences",
  16176. "commonAncestorContainer",
  16177. "compact",
  16178. "compareBoundaryPoints",
  16179. "compareDocumentPosition",
  16180. "compareEndPoints",
  16181. "compareNode",
  16182. "comparePoint",
  16183. "compatMode",
  16184. "compatible",
  16185. "compile",
  16186. "compileShader",
  16187. "complete",
  16188. "componentFromPoint",
  16189. "compositionEndOffset",
  16190. "compositionStartOffset",
  16191. "compressedTexImage2D",
  16192. "compressedTexSubImage2D",
  16193. "concat",
  16194. "conditionText",
  16195. "coneInnerAngle",
  16196. "coneOuterAngle",
  16197. "coneOuterGain",
  16198. "confirm",
  16199. "confirmComposition",
  16200. "confirmSiteSpecificTrackingException",
  16201. "confirmWebWideTrackingException",
  16202. "connect",
  16203. "connectEnd",
  16204. "connectStart",
  16205. "connected",
  16206. "connection",
  16207. "connectionSpeed",
  16208. "console",
  16209. "consolidate",
  16210. "constrictionActive",
  16211. "constructor",
  16212. "contactID",
  16213. "contains",
  16214. "containsNode",
  16215. "content",
  16216. "contentDocument",
  16217. "contentEditable",
  16218. "contentOverflow",
  16219. "contentScriptType",
  16220. "contentStyleType",
  16221. "contentType",
  16222. "contentWindow",
  16223. "context",
  16224. "contextMenu",
  16225. "contextmenu",
  16226. "continue",
  16227. "continuous",
  16228. "control",
  16229. "controller",
  16230. "controls",
  16231. "convertToSpecifiedUnits",
  16232. "cookie",
  16233. "cookieEnabled",
  16234. "coords",
  16235. "copyFromChannel",
  16236. "copyTexImage2D",
  16237. "copyTexSubImage2D",
  16238. "copyToChannel",
  16239. "copyWithin",
  16240. "correspondingElement",
  16241. "correspondingUseElement",
  16242. "cos",
  16243. "cosh",
  16244. "count",
  16245. "counter-increment",
  16246. "counter-reset",
  16247. "counterIncrement",
  16248. "counterReset",
  16249. "cpuClass",
  16250. "cpuSleepAllowed",
  16251. "create",
  16252. "createAnalyser",
  16253. "createAnswer",
  16254. "createAttribute",
  16255. "createAttributeNS",
  16256. "createBiquadFilter",
  16257. "createBuffer",
  16258. "createBufferSource",
  16259. "createCDATASection",
  16260. "createCSSStyleSheet",
  16261. "createCaption",
  16262. "createChannelMerger",
  16263. "createChannelSplitter",
  16264. "createComment",
  16265. "createContextualFragment",
  16266. "createControlRange",
  16267. "createConvolver",
  16268. "createDTMFSender",
  16269. "createDataChannel",
  16270. "createDelay",
  16271. "createDelayNode",
  16272. "createDocument",
  16273. "createDocumentFragment",
  16274. "createDocumentType",
  16275. "createDynamicsCompressor",
  16276. "createElement",
  16277. "createElementNS",
  16278. "createEntityReference",
  16279. "createEvent",
  16280. "createEventObject",
  16281. "createExpression",
  16282. "createFramebuffer",
  16283. "createFunction",
  16284. "createGain",
  16285. "createGainNode",
  16286. "createHTMLDocument",
  16287. "createImageBitmap",
  16288. "createImageData",
  16289. "createIndex",
  16290. "createJavaScriptNode",
  16291. "createLinearGradient",
  16292. "createMediaElementSource",
  16293. "createMediaKeys",
  16294. "createMediaStreamDestination",
  16295. "createMediaStreamSource",
  16296. "createMutableFile",
  16297. "createNSResolver",
  16298. "createNodeIterator",
  16299. "createNotification",
  16300. "createObjectStore",
  16301. "createObjectURL",
  16302. "createOffer",
  16303. "createOscillator",
  16304. "createPanner",
  16305. "createPattern",
  16306. "createPeriodicWave",
  16307. "createPopup",
  16308. "createProcessingInstruction",
  16309. "createProgram",
  16310. "createRadialGradient",
  16311. "createRange",
  16312. "createRangeCollection",
  16313. "createRenderbuffer",
  16314. "createSVGAngle",
  16315. "createSVGLength",
  16316. "createSVGMatrix",
  16317. "createSVGNumber",
  16318. "createSVGPathSegArcAbs",
  16319. "createSVGPathSegArcRel",
  16320. "createSVGPathSegClosePath",
  16321. "createSVGPathSegCurvetoCubicAbs",
  16322. "createSVGPathSegCurvetoCubicRel",
  16323. "createSVGPathSegCurvetoCubicSmoothAbs",
  16324. "createSVGPathSegCurvetoCubicSmoothRel",
  16325. "createSVGPathSegCurvetoQuadraticAbs",
  16326. "createSVGPathSegCurvetoQuadraticRel",
  16327. "createSVGPathSegCurvetoQuadraticSmoothAbs",
  16328. "createSVGPathSegCurvetoQuadraticSmoothRel",
  16329. "createSVGPathSegLinetoAbs",
  16330. "createSVGPathSegLinetoHorizontalAbs",
  16331. "createSVGPathSegLinetoHorizontalRel",
  16332. "createSVGPathSegLinetoRel",
  16333. "createSVGPathSegLinetoVerticalAbs",
  16334. "createSVGPathSegLinetoVerticalRel",
  16335. "createSVGPathSegMovetoAbs",
  16336. "createSVGPathSegMovetoRel",
  16337. "createSVGPoint",
  16338. "createSVGRect",
  16339. "createSVGTransform",
  16340. "createSVGTransformFromMatrix",
  16341. "createScriptProcessor",
  16342. "createSession",
  16343. "createShader",
  16344. "createShadowRoot",
  16345. "createStereoPanner",
  16346. "createStyleSheet",
  16347. "createTBody",
  16348. "createTFoot",
  16349. "createTHead",
  16350. "createTextNode",
  16351. "createTextRange",
  16352. "createTexture",
  16353. "createTouch",
  16354. "createTouchList",
  16355. "createTreeWalker",
  16356. "createWaveShaper",
  16357. "creationTime",
  16358. "crossOrigin",
  16359. "crypto",
  16360. "csi",
  16361. "cssFloat",
  16362. "cssRules",
  16363. "cssText",
  16364. "cssValueType",
  16365. "ctrlKey",
  16366. "ctrlLeft",
  16367. "cues",
  16368. "cullFace",
  16369. "currentNode",
  16370. "currentPage",
  16371. "currentScale",
  16372. "currentScript",
  16373. "currentSrc",
  16374. "currentState",
  16375. "currentStyle",
  16376. "currentTarget",
  16377. "currentTime",
  16378. "currentTranslate",
  16379. "currentView",
  16380. "cursor",
  16381. "curve",
  16382. "customError",
  16383. "cx",
  16384. "cy",
  16385. "d",
  16386. "data",
  16387. "dataFld",
  16388. "dataFormatAs",
  16389. "dataPageSize",
  16390. "dataSrc",
  16391. "dataTransfer",
  16392. "database",
  16393. "dataset",
  16394. "dateTime",
  16395. "db",
  16396. "debug",
  16397. "debuggerEnabled",
  16398. "declare",
  16399. "decode",
  16400. "decodeAudioData",
  16401. "decodingInfo",
  16402. "decodeURI",
  16403. "decodeURIComponent",
  16404. "decrypt",
  16405. "default",
  16406. "defaultCharset",
  16407. "defaultChecked",
  16408. "defaultMuted",
  16409. "defaultPlaybackRate",
  16410. "defaultPrevented",
  16411. "defaultSelected",
  16412. "defaultStatus",
  16413. "defaultURL",
  16414. "defaultValue",
  16415. "defaultView",
  16416. "defaultstatus",
  16417. "defer",
  16418. "defineMagicFunction",
  16419. "defineMagicVariable",
  16420. "defineProperties",
  16421. "defineProperty",
  16422. "delayTime",
  16423. "delete",
  16424. "deleteBuffer",
  16425. "deleteCaption",
  16426. "deleteCell",
  16427. "deleteContents",
  16428. "deleteData",
  16429. "deleteDatabase",
  16430. "deleteFramebuffer",
  16431. "deleteFromDocument",
  16432. "deleteIndex",
  16433. "deleteMedium",
  16434. "deleteObjectStore",
  16435. "deleteProgram",
  16436. "deleteRenderbuffer",
  16437. "deleteRow",
  16438. "deleteRule",
  16439. "deleteShader",
  16440. "deleteTFoot",
  16441. "deleteTHead",
  16442. "deleteTexture",
  16443. "deliverChangeRecords",
  16444. "delivery",
  16445. "deliveryInfo",
  16446. "deliveryStatus",
  16447. "deliveryTimestamp",
  16448. "delta",
  16449. "deltaMode",
  16450. "deltaX",
  16451. "deltaY",
  16452. "deltaZ",
  16453. "depthFunc",
  16454. "depthMask",
  16455. "depthRange",
  16456. "deriveBits",
  16457. "deriveKey",
  16458. "description",
  16459. "deselectAll",
  16460. "designMode",
  16461. "destination",
  16462. "destinationURL",
  16463. "detach",
  16464. "detachEvent",
  16465. "detachShader",
  16466. "detail",
  16467. "detune",
  16468. "devicePixelRatio",
  16469. "deviceXDPI",
  16470. "deviceYDPI",
  16471. "diffuseConstant",
  16472. "digest",
  16473. "dimensions",
  16474. "dir",
  16475. "dirName",
  16476. "direction",
  16477. "dirxml",
  16478. "disable",
  16479. "disableVertexAttribArray",
  16480. "disabled",
  16481. "dischargingTime",
  16482. "disconnect",
  16483. "dispatchEvent",
  16484. "display",
  16485. "distanceModel",
  16486. "divisor",
  16487. "djsapi",
  16488. "djsproxy",
  16489. "doImport",
  16490. "doNotTrack",
  16491. "doScroll",
  16492. "doctype",
  16493. "document",
  16494. "documentElement",
  16495. "documentMode",
  16496. "documentURI",
  16497. "dolphin",
  16498. "dolphinGameCenter",
  16499. "dolphininfo",
  16500. "dolphinmeta",
  16501. "domComplete",
  16502. "domContentLoadedEventEnd",
  16503. "domContentLoadedEventStart",
  16504. "domInteractive",
  16505. "domLoading",
  16506. "domain",
  16507. "domainLookupEnd",
  16508. "domainLookupStart",
  16509. "dominant-baseline",
  16510. "dominantBaseline",
  16511. "done",
  16512. "dopplerFactor",
  16513. "download",
  16514. "dragDrop",
  16515. "draggable",
  16516. "drawArrays",
  16517. "drawArraysInstancedANGLE",
  16518. "drawCustomFocusRing",
  16519. "drawElements",
  16520. "drawElementsInstancedANGLE",
  16521. "drawFocusIfNeeded",
  16522. "drawImage",
  16523. "drawImageFromRect",
  16524. "drawSystemFocusRing",
  16525. "drawingBufferHeight",
  16526. "drawingBufferWidth",
  16527. "dropEffect",
  16528. "droppedVideoFrames",
  16529. "dropzone",
  16530. "dump",
  16531. "duplicate",
  16532. "duration",
  16533. "dvname",
  16534. "dvnum",
  16535. "dx",
  16536. "dy",
  16537. "dynsrc",
  16538. "e",
  16539. "edgeMode",
  16540. "effectAllowed",
  16541. "elapsedTime",
  16542. "elementFromPoint",
  16543. "elements",
  16544. "elevation",
  16545. "ellipse",
  16546. "email",
  16547. "embeds",
  16548. "empty",
  16549. "empty-cells",
  16550. "emptyCells",
  16551. "enable",
  16552. "enableBackground",
  16553. "enableStyleSheetsForSet",
  16554. "enableVertexAttribArray",
  16555. "enabled",
  16556. "enabledPlugin",
  16557. "encode",
  16558. "encodeURI",
  16559. "encodeURIComponent",
  16560. "encoding",
  16561. "encrypt",
  16562. "enctype",
  16563. "end",
  16564. "endContainer",
  16565. "endElement",
  16566. "endElementAt",
  16567. "endOfStream",
  16568. "endOffset",
  16569. "endTime",
  16570. "ended",
  16571. "endsWith",
  16572. "entities",
  16573. "entries",
  16574. "entryType",
  16575. "enumerate",
  16576. "enumerateEditable",
  16577. "error",
  16578. "errorCode",
  16579. "escape",
  16580. "eval",
  16581. "evaluate",
  16582. "event",
  16583. "eventPhase",
  16584. "every",
  16585. "exception",
  16586. "exec",
  16587. "execCommand",
  16588. "execCommandShowHelp",
  16589. "execScript",
  16590. "exitFullscreen",
  16591. "exitPointerLock",
  16592. "exp",
  16593. "expand",
  16594. "expandEntityReferences",
  16595. "expando",
  16596. "expansion",
  16597. "expiryDate",
  16598. "explicitOriginalTarget",
  16599. "expm1",
  16600. "exponent",
  16601. "exponentialRampToValueAtTime",
  16602. "exportKey",
  16603. "extend",
  16604. "extensions",
  16605. "extentNode",
  16606. "extentOffset",
  16607. "external",
  16608. "externalResourcesRequired",
  16609. "extractContents",
  16610. "extractable",
  16611. "f",
  16612. "face",
  16613. "factoryReset",
  16614. "fallback",
  16615. "familyName",
  16616. "farthestViewportElement",
  16617. "fastSeek",
  16618. "fatal",
  16619. "fetch",
  16620. "fetchStart",
  16621. "fftSize",
  16622. "fgColor",
  16623. "fileCreatedDate",
  16624. "fileHandle",
  16625. "fileModifiedDate",
  16626. "fileName",
  16627. "fileSize",
  16628. "fileUpdatedDate",
  16629. "filename",
  16630. "files",
  16631. "fill",
  16632. "fill-opacity",
  16633. "fill-rule",
  16634. "fillOpacity",
  16635. "fillRect",
  16636. "fillRule",
  16637. "fillStyle",
  16638. "fillText",
  16639. "filter",
  16640. "filterResX",
  16641. "filterResY",
  16642. "filterUnits",
  16643. "filters",
  16644. "finally",
  16645. "find",
  16646. "findIndex",
  16647. "findRule",
  16648. "findText",
  16649. "finish",
  16650. "fireEvent",
  16651. "firstChild",
  16652. "firstElementChild",
  16653. "firstPage",
  16654. "fixed",
  16655. "flex",
  16656. "flex-basis",
  16657. "flex-direction",
  16658. "flex-flow",
  16659. "flex-grow",
  16660. "flex-shrink",
  16661. "flex-wrap",
  16662. "flexBasis",
  16663. "flexDirection",
  16664. "flexFlow",
  16665. "flexGrow",
  16666. "flexShrink",
  16667. "flexWrap",
  16668. "flipX",
  16669. "flipY",
  16670. "float",
  16671. "flood-color",
  16672. "flood-opacity",
  16673. "floodColor",
  16674. "floodOpacity",
  16675. "floor",
  16676. "flush",
  16677. "focus",
  16678. "focusNode",
  16679. "focusOffset",
  16680. "font",
  16681. "font-family",
  16682. "font-feature-settings",
  16683. "font-kerning",
  16684. "font-language-override",
  16685. "font-size",
  16686. "font-size-adjust",
  16687. "font-stretch",
  16688. "font-style",
  16689. "font-synthesis",
  16690. "font-variant",
  16691. "font-variant-alternates",
  16692. "font-variant-caps",
  16693. "font-variant-east-asian",
  16694. "font-variant-ligatures",
  16695. "font-variant-numeric",
  16696. "font-variant-position",
  16697. "font-weight",
  16698. "fontFamily",
  16699. "fontFeatureSettings",
  16700. "fontKerning",
  16701. "fontLanguageOverride",
  16702. "fontSize",
  16703. "fontSizeAdjust",
  16704. "fontSmoothingEnabled",
  16705. "fontStretch",
  16706. "fontStyle",
  16707. "fontSynthesis",
  16708. "fontVariant",
  16709. "fontVariantAlternates",
  16710. "fontVariantCaps",
  16711. "fontVariantEastAsian",
  16712. "fontVariantLigatures",
  16713. "fontVariantNumeric",
  16714. "fontVariantPosition",
  16715. "fontWeight",
  16716. "fontcolor",
  16717. "fonts",
  16718. "fontsize",
  16719. "for",
  16720. "forEach",
  16721. "forceRedraw",
  16722. "form",
  16723. "formAction",
  16724. "formEnctype",
  16725. "formMethod",
  16726. "formNoValidate",
  16727. "formTarget",
  16728. "format",
  16729. "forms",
  16730. "forward",
  16731. "fr",
  16732. "frame",
  16733. "frameBorder",
  16734. "frameElement",
  16735. "frameSpacing",
  16736. "framebufferRenderbuffer",
  16737. "framebufferTexture2D",
  16738. "frames",
  16739. "freeSpace",
  16740. "freeze",
  16741. "frequency",
  16742. "frequencyBinCount",
  16743. "from",
  16744. "fromCharCode",
  16745. "fromCodePoint",
  16746. "fromElement",
  16747. "frontFace",
  16748. "fround",
  16749. "fullScreen",
  16750. "fullscreenElement",
  16751. "fullscreenEnabled",
  16752. "fx",
  16753. "fy",
  16754. "gain",
  16755. "gamepad",
  16756. "gamma",
  16757. "genderIdentity",
  16758. "generateKey",
  16759. "generateMipmap",
  16760. "generateRequest",
  16761. "geolocation",
  16762. "gestureObject",
  16763. "get",
  16764. "getActiveAttrib",
  16765. "getActiveUniform",
  16766. "getAdjacentText",
  16767. "getAll",
  16768. "getAllResponseHeaders",
  16769. "getAsFile",
  16770. "getAsString",
  16771. "getAttachedShaders",
  16772. "getAttribLocation",
  16773. "getAttribute",
  16774. "getAttributeNS",
  16775. "getAttributeNode",
  16776. "getAttributeNodeNS",
  16777. "getAudioTracks",
  16778. "getBBox",
  16779. "getBattery",
  16780. "getBlob",
  16781. "getBookmark",
  16782. "getBoundingClientRect",
  16783. "getBufferParameter",
  16784. "getByteFrequencyData",
  16785. "getByteTimeDomainData",
  16786. "getCSSCanvasContext",
  16787. "getCTM",
  16788. "getCandidateWindowClientRect",
  16789. "getChannelData",
  16790. "getCharNumAtPosition",
  16791. "getClientRect",
  16792. "getClientRects",
  16793. "getCompositionAlternatives",
  16794. "getComputedStyle",
  16795. "getComputedTextLength",
  16796. "getConfiguration",
  16797. "getContext",
  16798. "getContextAttributes",
  16799. "getCounterValue",
  16800. "getCueAsHTML",
  16801. "getCueById",
  16802. "getCurrentPosition",
  16803. "getCurrentTime",
  16804. "getData",
  16805. "getDatabaseNames",
  16806. "getDate",
  16807. "getDay",
  16808. "getDefaultComputedStyle",
  16809. "getDestinationInsertionPoints",
  16810. "getDistributedNodes",
  16811. "getEditable",
  16812. "getElementById",
  16813. "getElementsByClassName",
  16814. "getElementsByName",
  16815. "getElementsByTagName",
  16816. "getElementsByTagNameNS",
  16817. "getEnclosureList",
  16818. "getEndPositionOfChar",
  16819. "getEntries",
  16820. "getEntriesByName",
  16821. "getEntriesByType",
  16822. "getError",
  16823. "getExtension",
  16824. "getExtentOfChar",
  16825. "getFeature",
  16826. "getFile",
  16827. "getFloat32",
  16828. "getFloat64",
  16829. "getFloatFrequencyData",
  16830. "getFloatTimeDomainData",
  16831. "getFloatValue",
  16832. "getFramebufferAttachmentParameter",
  16833. "getFrequencyResponse",
  16834. "getFullYear",
  16835. "getGamepads",
  16836. "getHours",
  16837. "getImageData",
  16838. "getInt16",
  16839. "getInt32",
  16840. "getInt8",
  16841. "getIntersectionList",
  16842. "getItem",
  16843. "getItems",
  16844. "getKey",
  16845. "getLineDash",
  16846. "getLocalStreams",
  16847. "getMarks",
  16848. "getMatchedCSSRules",
  16849. "getMeasures",
  16850. "getMetadata",
  16851. "getMilliseconds",
  16852. "getMinutes",
  16853. "getModifierState",
  16854. "getMonth",
  16855. "getNamedItem",
  16856. "getNamedItemNS",
  16857. "getNotifier",
  16858. "getNumberOfChars",
  16859. "getOverrideHistoryNavigationMode",
  16860. "getOverrideStyle",
  16861. "getOwnPropertyDescriptor",
  16862. "getOwnPropertyNames",
  16863. "getOwnPropertySymbols",
  16864. "getParameter",
  16865. "getPathSegAtLength",
  16866. "getPointAtLength",
  16867. "getPreference",
  16868. "getPreferenceDefault",
  16869. "getPresentationAttribute",
  16870. "getPreventDefault",
  16871. "getProgramInfoLog",
  16872. "getProgramParameter",
  16873. "getPropertyCSSValue",
  16874. "getPropertyPriority",
  16875. "getPropertyShorthand",
  16876. "getPropertyValue",
  16877. "getPrototypeOf",
  16878. "getRGBColorValue",
  16879. "getRandomValues",
  16880. "getRangeAt",
  16881. "getReceivers",
  16882. "getRectValue",
  16883. "getRegistration",
  16884. "getRemoteStreams",
  16885. "getRenderbufferParameter",
  16886. "getResponseHeader",
  16887. "getRoot",
  16888. "getRotationOfChar",
  16889. "getSVGDocument",
  16890. "getScreenCTM",
  16891. "getSeconds",
  16892. "getSelection",
  16893. "getSenders",
  16894. "getShaderInfoLog",
  16895. "getShaderParameter",
  16896. "getShaderPrecisionFormat",
  16897. "getShaderSource",
  16898. "getSimpleDuration",
  16899. "getSiteIcons",
  16900. "getSources",
  16901. "getSpeculativeParserUrls",
  16902. "getStartPositionOfChar",
  16903. "getStartTime",
  16904. "getStats",
  16905. "getStorageUpdates",
  16906. "getStreamById",
  16907. "getStringValue",
  16908. "getSubStringLength",
  16909. "getSubscription",
  16910. "getSupportedExtensions",
  16911. "getTexParameter",
  16912. "getTime",
  16913. "getTimezoneOffset",
  16914. "getTotalLength",
  16915. "getTrackById",
  16916. "getTracks",
  16917. "getTransformToElement",
  16918. "getUTCDate",
  16919. "getUTCDay",
  16920. "getUTCFullYear",
  16921. "getUTCHours",
  16922. "getUTCMilliseconds",
  16923. "getUTCMinutes",
  16924. "getUTCMonth",
  16925. "getUTCSeconds",
  16926. "getUint16",
  16927. "getUint32",
  16928. "getUint8",
  16929. "getUniform",
  16930. "getUniformLocation",
  16931. "getUserMedia",
  16932. "getValues",
  16933. "getVarDate",
  16934. "getVariableValue",
  16935. "getVertexAttrib",
  16936. "getVertexAttribOffset",
  16937. "getVideoPlaybackQuality",
  16938. "getVideoTracks",
  16939. "getWakeLockState",
  16940. "getYear",
  16941. "givenName",
  16942. "global",
  16943. "globalAlpha",
  16944. "globalCompositeOperation",
  16945. "glyphOrientationHorizontal",
  16946. "glyphOrientationVertical",
  16947. "glyphRef",
  16948. "go",
  16949. "gradientTransform",
  16950. "gradientUnits",
  16951. "grammars",
  16952. "green",
  16953. "group",
  16954. "groupCollapsed",
  16955. "groupEnd",
  16956. "hardwareConcurrency",
  16957. "has",
  16958. "hasAttribute",
  16959. "hasAttributeNS",
  16960. "hasAttributes",
  16961. "hasChildNodes",
  16962. "hasComposition",
  16963. "hasExtension",
  16964. "hasFeature",
  16965. "hasFocus",
  16966. "hasLayout",
  16967. "hasOwnProperty",
  16968. "hash",
  16969. "head",
  16970. "headers",
  16971. "heading",
  16972. "height",
  16973. "hidden",
  16974. "hide",
  16975. "hideFocus",
  16976. "high",
  16977. "hint",
  16978. "history",
  16979. "honorificPrefix",
  16980. "honorificSuffix",
  16981. "horizontalOverflow",
  16982. "host",
  16983. "hostname",
  16984. "href",
  16985. "hreflang",
  16986. "hspace",
  16987. "html5TagCheckInerface",
  16988. "htmlFor",
  16989. "htmlText",
  16990. "httpEquiv",
  16991. "hwTimestamp",
  16992. "hypot",
  16993. "iccId",
  16994. "iceConnectionState",
  16995. "iceGatheringState",
  16996. "icon",
  16997. "id",
  16998. "identifier",
  16999. "identity",
  17000. "ignoreBOM",
  17001. "ignoreCase",
  17002. "image-orientation",
  17003. "image-rendering",
  17004. "imageOrientation",
  17005. "imageRendering",
  17006. "images",
  17007. "ime-mode",
  17008. "imeMode",
  17009. "implementation",
  17010. "importKey",
  17011. "importNode",
  17012. "importStylesheet",
  17013. "imports",
  17014. "impp",
  17015. "imul",
  17016. "in1",
  17017. "in2",
  17018. "inBandMetadataTrackDispatchType",
  17019. "inRange",
  17020. "includes",
  17021. "incremental",
  17022. "indeterminate",
  17023. "index",
  17024. "indexNames",
  17025. "indexOf",
  17026. "indexedDB",
  17027. "inertiaDestinationX",
  17028. "inertiaDestinationY",
  17029. "info",
  17030. "init",
  17031. "initAnimationEvent",
  17032. "initBeforeLoadEvent",
  17033. "initClipboardEvent",
  17034. "initCloseEvent",
  17035. "initCommandEvent",
  17036. "initCompositionEvent",
  17037. "initCustomEvent",
  17038. "initData",
  17039. "initDeviceMotionEvent",
  17040. "initDeviceOrientationEvent",
  17041. "initDragEvent",
  17042. "initErrorEvent",
  17043. "initEvent",
  17044. "initFocusEvent",
  17045. "initGestureEvent",
  17046. "initHashChangeEvent",
  17047. "initKeyEvent",
  17048. "initKeyboardEvent",
  17049. "initMSManipulationEvent",
  17050. "initMessageEvent",
  17051. "initMouseEvent",
  17052. "initMouseScrollEvent",
  17053. "initMouseWheelEvent",
  17054. "initMutationEvent",
  17055. "initNSMouseEvent",
  17056. "initOverflowEvent",
  17057. "initPageEvent",
  17058. "initPageTransitionEvent",
  17059. "initPointerEvent",
  17060. "initPopStateEvent",
  17061. "initProgressEvent",
  17062. "initScrollAreaEvent",
  17063. "initSimpleGestureEvent",
  17064. "initStorageEvent",
  17065. "initTextEvent",
  17066. "initTimeEvent",
  17067. "initTouchEvent",
  17068. "initTransitionEvent",
  17069. "initUIEvent",
  17070. "initWebKitAnimationEvent",
  17071. "initWebKitTransitionEvent",
  17072. "initWebKitWheelEvent",
  17073. "initWheelEvent",
  17074. "initialTime",
  17075. "initialize",
  17076. "initiatorType",
  17077. "inner",
  17078. "innerHTML",
  17079. "innerHeight",
  17080. "innerText",
  17081. "innerWidth",
  17082. "input",
  17083. "inputBuffer",
  17084. "inputEncoding",
  17085. "inputMethod",
  17086. "insertAdjacentElement",
  17087. "insertAdjacentHTML",
  17088. "insertAdjacentText",
  17089. "insertBefore",
  17090. "insertCell",
  17091. "insertData",
  17092. "insertItemBefore",
  17093. "insertNode",
  17094. "insertRow",
  17095. "insertRule",
  17096. "instanceRoot",
  17097. "intercept",
  17098. "interimResults",
  17099. "internalSubset",
  17100. "intersectsNode",
  17101. "interval",
  17102. "invalidIteratorState",
  17103. "inverse",
  17104. "invertSelf",
  17105. "is",
  17106. "is2D",
  17107. "isAlternate",
  17108. "isArray",
  17109. "isBingCurrentSearchDefault",
  17110. "isBuffer",
  17111. "isCandidateWindowVisible",
  17112. "isChar",
  17113. "isCollapsed",
  17114. "isComposing",
  17115. "isContentEditable",
  17116. "isContentHandlerRegistered",
  17117. "isContextLost",
  17118. "isDefaultNamespace",
  17119. "isDisabled",
  17120. "isEnabled",
  17121. "isEqual",
  17122. "isEqualNode",
  17123. "isExtensible",
  17124. "isFinite",
  17125. "isFramebuffer",
  17126. "isFrozen",
  17127. "isGenerator",
  17128. "isId",
  17129. "isInjected",
  17130. "isInteger",
  17131. "isMap",
  17132. "isMultiLine",
  17133. "isNaN",
  17134. "isOpen",
  17135. "isPointInFill",
  17136. "isPointInPath",
  17137. "isPointInRange",
  17138. "isPointInStroke",
  17139. "isPrefAlternate",
  17140. "isPrimary",
  17141. "isProgram",
  17142. "isPropertyImplicit",
  17143. "isProtocolHandlerRegistered",
  17144. "isPrototypeOf",
  17145. "isRenderbuffer",
  17146. "isSafeInteger",
  17147. "isSameNode",
  17148. "isSealed",
  17149. "isShader",
  17150. "isSupported",
  17151. "isTextEdit",
  17152. "isTexture",
  17153. "isTrusted",
  17154. "isTypeSupported",
  17155. "isView",
  17156. "isolation",
  17157. "italics",
  17158. "item",
  17159. "itemId",
  17160. "itemProp",
  17161. "itemRef",
  17162. "itemScope",
  17163. "itemType",
  17164. "itemValue",
  17165. "iterateNext",
  17166. "iterator",
  17167. "javaEnabled",
  17168. "jobTitle",
  17169. "join",
  17170. "json",
  17171. "justify-content",
  17172. "justifyContent",
  17173. "k1",
  17174. "k2",
  17175. "k3",
  17176. "k4",
  17177. "kernelMatrix",
  17178. "kernelUnitLengthX",
  17179. "kernelUnitLengthY",
  17180. "kerning",
  17181. "key",
  17182. "keyCode",
  17183. "keyFor",
  17184. "keyIdentifier",
  17185. "keyLightEnabled",
  17186. "keyLocation",
  17187. "keyPath",
  17188. "keySystem",
  17189. "keyText",
  17190. "keyUsage",
  17191. "keys",
  17192. "keytype",
  17193. "kind",
  17194. "knee",
  17195. "label",
  17196. "labels",
  17197. "lang",
  17198. "language",
  17199. "languages",
  17200. "largeArcFlag",
  17201. "lastChild",
  17202. "lastElementChild",
  17203. "lastEventId",
  17204. "lastIndex",
  17205. "lastIndexOf",
  17206. "lastMatch",
  17207. "lastMessageSubject",
  17208. "lastMessageType",
  17209. "lastModified",
  17210. "lastModifiedDate",
  17211. "lastPage",
  17212. "lastParen",
  17213. "lastState",
  17214. "lastStyleSheetSet",
  17215. "latitude",
  17216. "layerX",
  17217. "layerY",
  17218. "layoutFlow",
  17219. "layoutGrid",
  17220. "layoutGridChar",
  17221. "layoutGridLine",
  17222. "layoutGridMode",
  17223. "layoutGridType",
  17224. "lbound",
  17225. "left",
  17226. "leftContext",
  17227. "leftMargin",
  17228. "length",
  17229. "lengthAdjust",
  17230. "lengthComputable",
  17231. "letter-spacing",
  17232. "letterSpacing",
  17233. "level",
  17234. "lighting-color",
  17235. "lightingColor",
  17236. "limitingConeAngle",
  17237. "line",
  17238. "line-height",
  17239. "lineAlign",
  17240. "lineBreak",
  17241. "lineCap",
  17242. "lineDashOffset",
  17243. "lineHeight",
  17244. "lineJoin",
  17245. "lineNumber",
  17246. "lineTo",
  17247. "lineWidth",
  17248. "linearRampToValueAtTime",
  17249. "lineno",
  17250. "link",
  17251. "linkColor",
  17252. "linkProgram",
  17253. "links",
  17254. "list",
  17255. "list-style",
  17256. "list-style-image",
  17257. "list-style-position",
  17258. "list-style-type",
  17259. "listStyle",
  17260. "listStyleImage",
  17261. "listStylePosition",
  17262. "listStyleType",
  17263. "listener",
  17264. "load",
  17265. "loadEventEnd",
  17266. "loadEventStart",
  17267. "loadTimes",
  17268. "loaded",
  17269. "localDescription",
  17270. "localName",
  17271. "localStorage",
  17272. "locale",
  17273. "localeCompare",
  17274. "location",
  17275. "locationbar",
  17276. "lock",
  17277. "lockedFile",
  17278. "log",
  17279. "log10",
  17280. "log1p",
  17281. "log2",
  17282. "logicalXDPI",
  17283. "logicalYDPI",
  17284. "longDesc",
  17285. "longitude",
  17286. "lookupNamespaceURI",
  17287. "lookupPrefix",
  17288. "loop",
  17289. "loopEnd",
  17290. "loopStart",
  17291. "looping",
  17292. "low",
  17293. "lower",
  17294. "lowerBound",
  17295. "lowerOpen",
  17296. "lowsrc",
  17297. "m11",
  17298. "m12",
  17299. "m13",
  17300. "m14",
  17301. "m21",
  17302. "m22",
  17303. "m23",
  17304. "m24",
  17305. "m31",
  17306. "m32",
  17307. "m33",
  17308. "m34",
  17309. "m41",
  17310. "m42",
  17311. "m43",
  17312. "m44",
  17313. "manifest",
  17314. "map",
  17315. "mapping",
  17316. "margin",
  17317. "margin-bottom",
  17318. "margin-left",
  17319. "margin-right",
  17320. "margin-top",
  17321. "marginBottom",
  17322. "marginHeight",
  17323. "marginLeft",
  17324. "marginRight",
  17325. "marginTop",
  17326. "marginWidth",
  17327. "mark",
  17328. "marker",
  17329. "marker-end",
  17330. "marker-mid",
  17331. "marker-offset",
  17332. "marker-start",
  17333. "markerEnd",
  17334. "markerHeight",
  17335. "markerMid",
  17336. "markerOffset",
  17337. "markerStart",
  17338. "markerUnits",
  17339. "markerWidth",
  17340. "marks",
  17341. "mask",
  17342. "mask-type",
  17343. "maskContentUnits",
  17344. "maskType",
  17345. "maskUnits",
  17346. "match",
  17347. "matchMedia",
  17348. "matchMedium",
  17349. "matches",
  17350. "matrix",
  17351. "matrixTransform",
  17352. "max",
  17353. "max-height",
  17354. "max-width",
  17355. "maxAlternatives",
  17356. "maxChannelCount",
  17357. "maxConnectionsPerServer",
  17358. "maxDecibels",
  17359. "maxDistance",
  17360. "maxHeight",
  17361. "maxLength",
  17362. "maxTouchPoints",
  17363. "maxValue",
  17364. "maxWidth",
  17365. "measure",
  17366. "measureText",
  17367. "media",
  17368. "mediaCapabilities",
  17369. "mediaDevices",
  17370. "mediaElement",
  17371. "mediaGroup",
  17372. "mediaKeys",
  17373. "mediaText",
  17374. "meetOrSlice",
  17375. "memory",
  17376. "menubar",
  17377. "mergeAttributes",
  17378. "message",
  17379. "messageClass",
  17380. "messageHandlers",
  17381. "metaKey",
  17382. "method",
  17383. "mimeType",
  17384. "mimeTypes",
  17385. "min",
  17386. "min-height",
  17387. "min-width",
  17388. "minDecibels",
  17389. "minHeight",
  17390. "minValue",
  17391. "minWidth",
  17392. "miterLimit",
  17393. "mix-blend-mode",
  17394. "mixBlendMode",
  17395. "mode",
  17396. "modify",
  17397. "mount",
  17398. "move",
  17399. "moveBy",
  17400. "moveEnd",
  17401. "moveFirst",
  17402. "moveFocusDown",
  17403. "moveFocusLeft",
  17404. "moveFocusRight",
  17405. "moveFocusUp",
  17406. "moveNext",
  17407. "moveRow",
  17408. "moveStart",
  17409. "moveTo",
  17410. "moveToBookmark",
  17411. "moveToElementText",
  17412. "moveToPoint",
  17413. "mozAdd",
  17414. "mozAnimationStartTime",
  17415. "mozAnon",
  17416. "mozApps",
  17417. "mozAudioCaptured",
  17418. "mozAudioChannelType",
  17419. "mozAutoplayEnabled",
  17420. "mozCancelAnimationFrame",
  17421. "mozCancelFullScreen",
  17422. "mozCancelRequestAnimationFrame",
  17423. "mozCaptureStream",
  17424. "mozCaptureStreamUntilEnded",
  17425. "mozClearDataAt",
  17426. "mozContact",
  17427. "mozContacts",
  17428. "mozCreateFileHandle",
  17429. "mozCurrentTransform",
  17430. "mozCurrentTransformInverse",
  17431. "mozCursor",
  17432. "mozDash",
  17433. "mozDashOffset",
  17434. "mozDecodedFrames",
  17435. "mozExitPointerLock",
  17436. "mozFillRule",
  17437. "mozFragmentEnd",
  17438. "mozFrameDelay",
  17439. "mozFullScreen",
  17440. "mozFullScreenElement",
  17441. "mozFullScreenEnabled",
  17442. "mozGetAll",
  17443. "mozGetAllKeys",
  17444. "mozGetAsFile",
  17445. "mozGetDataAt",
  17446. "mozGetMetadata",
  17447. "mozGetUserMedia",
  17448. "mozHasAudio",
  17449. "mozHasItem",
  17450. "mozHidden",
  17451. "mozImageSmoothingEnabled",
  17452. "mozIndexedDB",
  17453. "mozInnerScreenX",
  17454. "mozInnerScreenY",
  17455. "mozInputSource",
  17456. "mozIsTextField",
  17457. "mozItem",
  17458. "mozItemCount",
  17459. "mozItems",
  17460. "mozLength",
  17461. "mozLockOrientation",
  17462. "mozMatchesSelector",
  17463. "mozMovementX",
  17464. "mozMovementY",
  17465. "mozOpaque",
  17466. "mozOrientation",
  17467. "mozPaintCount",
  17468. "mozPaintedFrames",
  17469. "mozParsedFrames",
  17470. "mozPay",
  17471. "mozPointerLockElement",
  17472. "mozPresentedFrames",
  17473. "mozPreservesPitch",
  17474. "mozPressure",
  17475. "mozPrintCallback",
  17476. "mozRTCIceCandidate",
  17477. "mozRTCPeerConnection",
  17478. "mozRTCSessionDescription",
  17479. "mozRemove",
  17480. "mozRequestAnimationFrame",
  17481. "mozRequestFullScreen",
  17482. "mozRequestPointerLock",
  17483. "mozSetDataAt",
  17484. "mozSetImageElement",
  17485. "mozSourceNode",
  17486. "mozSrcObject",
  17487. "mozSystem",
  17488. "mozTCPSocket",
  17489. "mozTextStyle",
  17490. "mozTypesAt",
  17491. "mozUnlockOrientation",
  17492. "mozUserCancelled",
  17493. "mozVisibilityState",
  17494. "msAnimation",
  17495. "msAnimationDelay",
  17496. "msAnimationDirection",
  17497. "msAnimationDuration",
  17498. "msAnimationFillMode",
  17499. "msAnimationIterationCount",
  17500. "msAnimationName",
  17501. "msAnimationPlayState",
  17502. "msAnimationStartTime",
  17503. "msAnimationTimingFunction",
  17504. "msBackfaceVisibility",
  17505. "msBlockProgression",
  17506. "msCSSOMElementFloatMetrics",
  17507. "msCaching",
  17508. "msCachingEnabled",
  17509. "msCancelRequestAnimationFrame",
  17510. "msCapsLockWarningOff",
  17511. "msClearImmediate",
  17512. "msClose",
  17513. "msContentZoomChaining",
  17514. "msContentZoomFactor",
  17515. "msContentZoomLimit",
  17516. "msContentZoomLimitMax",
  17517. "msContentZoomLimitMin",
  17518. "msContentZoomSnap",
  17519. "msContentZoomSnapPoints",
  17520. "msContentZoomSnapType",
  17521. "msContentZooming",
  17522. "msConvertURL",
  17523. "msCrypto",
  17524. "msDoNotTrack",
  17525. "msElementsFromPoint",
  17526. "msElementsFromRect",
  17527. "msExitFullscreen",
  17528. "msExtendedCode",
  17529. "msFillRule",
  17530. "msFirstPaint",
  17531. "msFlex",
  17532. "msFlexAlign",
  17533. "msFlexDirection",
  17534. "msFlexFlow",
  17535. "msFlexItemAlign",
  17536. "msFlexLinePack",
  17537. "msFlexNegative",
  17538. "msFlexOrder",
  17539. "msFlexPack",
  17540. "msFlexPositive",
  17541. "msFlexPreferredSize",
  17542. "msFlexWrap",
  17543. "msFlowFrom",
  17544. "msFlowInto",
  17545. "msFontFeatureSettings",
  17546. "msFullscreenElement",
  17547. "msFullscreenEnabled",
  17548. "msGetInputContext",
  17549. "msGetRegionContent",
  17550. "msGetUntransformedBounds",
  17551. "msGraphicsTrustStatus",
  17552. "msGridColumn",
  17553. "msGridColumnAlign",
  17554. "msGridColumnSpan",
  17555. "msGridColumns",
  17556. "msGridRow",
  17557. "msGridRowAlign",
  17558. "msGridRowSpan",
  17559. "msGridRows",
  17560. "msHidden",
  17561. "msHighContrastAdjust",
  17562. "msHyphenateLimitChars",
  17563. "msHyphenateLimitLines",
  17564. "msHyphenateLimitZone",
  17565. "msHyphens",
  17566. "msImageSmoothingEnabled",
  17567. "msImeAlign",
  17568. "msIndexedDB",
  17569. "msInterpolationMode",
  17570. "msIsStaticHTML",
  17571. "msKeySystem",
  17572. "msKeys",
  17573. "msLaunchUri",
  17574. "msLockOrientation",
  17575. "msManipulationViewsEnabled",
  17576. "msMatchMedia",
  17577. "msMatchesSelector",
  17578. "msMaxTouchPoints",
  17579. "msOrientation",
  17580. "msOverflowStyle",
  17581. "msPerspective",
  17582. "msPerspectiveOrigin",
  17583. "msPlayToDisabled",
  17584. "msPlayToPreferredSourceUri",
  17585. "msPlayToPrimary",
  17586. "msPointerEnabled",
  17587. "msRegionOverflow",
  17588. "msReleasePointerCapture",
  17589. "msRequestAnimationFrame",
  17590. "msRequestFullscreen",
  17591. "msSaveBlob",
  17592. "msSaveOrOpenBlob",
  17593. "msScrollChaining",
  17594. "msScrollLimit",
  17595. "msScrollLimitXMax",
  17596. "msScrollLimitXMin",
  17597. "msScrollLimitYMax",
  17598. "msScrollLimitYMin",
  17599. "msScrollRails",
  17600. "msScrollSnapPointsX",
  17601. "msScrollSnapPointsY",
  17602. "msScrollSnapType",
  17603. "msScrollSnapX",
  17604. "msScrollSnapY",
  17605. "msScrollTranslation",
  17606. "msSetImmediate",
  17607. "msSetMediaKeys",
  17608. "msSetPointerCapture",
  17609. "msTextCombineHorizontal",
  17610. "msTextSizeAdjust",
  17611. "msToBlob",
  17612. "msTouchAction",
  17613. "msTouchSelect",
  17614. "msTraceAsyncCallbackCompleted",
  17615. "msTraceAsyncCallbackStarting",
  17616. "msTraceAsyncOperationCompleted",
  17617. "msTraceAsyncOperationStarting",
  17618. "msTransform",
  17619. "msTransformOrigin",
  17620. "msTransformStyle",
  17621. "msTransition",
  17622. "msTransitionDelay",
  17623. "msTransitionDuration",
  17624. "msTransitionProperty",
  17625. "msTransitionTimingFunction",
  17626. "msUnlockOrientation",
  17627. "msUpdateAsyncCallbackRelation",
  17628. "msUserSelect",
  17629. "msVisibilityState",
  17630. "msWrapFlow",
  17631. "msWrapMargin",
  17632. "msWrapThrough",
  17633. "msWriteProfilerMark",
  17634. "msZoom",
  17635. "msZoomTo",
  17636. "mt",
  17637. "multiEntry",
  17638. "multiSelectionObj",
  17639. "multiline",
  17640. "multiple",
  17641. "multiply",
  17642. "multiplySelf",
  17643. "mutableFile",
  17644. "muted",
  17645. "n",
  17646. "name",
  17647. "nameProp",
  17648. "namedItem",
  17649. "namedRecordset",
  17650. "names",
  17651. "namespaceURI",
  17652. "namespaces",
  17653. "naturalHeight",
  17654. "naturalWidth",
  17655. "navigate",
  17656. "navigation",
  17657. "navigationMode",
  17658. "navigationStart",
  17659. "navigator",
  17660. "near",
  17661. "nearestViewportElement",
  17662. "negative",
  17663. "netscape",
  17664. "networkState",
  17665. "newScale",
  17666. "newTranslate",
  17667. "newURL",
  17668. "newValue",
  17669. "newValueSpecifiedUnits",
  17670. "newVersion",
  17671. "newhome",
  17672. "next",
  17673. "nextElementSibling",
  17674. "nextNode",
  17675. "nextPage",
  17676. "nextSibling",
  17677. "nickname",
  17678. "noHref",
  17679. "noResize",
  17680. "noShade",
  17681. "noValidate",
  17682. "noWrap",
  17683. "nodeName",
  17684. "nodeType",
  17685. "nodeValue",
  17686. "normalize",
  17687. "normalizedPathSegList",
  17688. "notationName",
  17689. "notations",
  17690. "note",
  17691. "noteGrainOn",
  17692. "noteOff",
  17693. "noteOn",
  17694. "now",
  17695. "numOctaves",
  17696. "number",
  17697. "numberOfChannels",
  17698. "numberOfInputs",
  17699. "numberOfItems",
  17700. "numberOfOutputs",
  17701. "numberValue",
  17702. "oMatchesSelector",
  17703. "object",
  17704. "object-fit",
  17705. "object-position",
  17706. "objectFit",
  17707. "objectPosition",
  17708. "objectStore",
  17709. "objectStoreNames",
  17710. "observe",
  17711. "of",
  17712. "offscreenBuffering",
  17713. "offset",
  17714. "offsetHeight",
  17715. "offsetLeft",
  17716. "offsetNode",
  17717. "offsetParent",
  17718. "offsetTop",
  17719. "offsetWidth",
  17720. "offsetX",
  17721. "offsetY",
  17722. "ok",
  17723. "oldURL",
  17724. "oldValue",
  17725. "oldVersion",
  17726. "olderShadowRoot",
  17727. "onLine",
  17728. "onabort",
  17729. "onactivate",
  17730. "onactive",
  17731. "onaddstream",
  17732. "onaddtrack",
  17733. "onafterprint",
  17734. "onafterscriptexecute",
  17735. "onafterupdate",
  17736. "onaudioend",
  17737. "onaudioprocess",
  17738. "onaudiostart",
  17739. "onautocomplete",
  17740. "onautocompleteerror",
  17741. "onbeforeactivate",
  17742. "onbeforecopy",
  17743. "onbeforecut",
  17744. "onbeforedeactivate",
  17745. "onbeforeeditfocus",
  17746. "onbeforepaste",
  17747. "onbeforeprint",
  17748. "onbeforescriptexecute",
  17749. "onbeforeunload",
  17750. "onbeforeupdate",
  17751. "onblocked",
  17752. "onblur",
  17753. "onbounce",
  17754. "onboundary",
  17755. "oncached",
  17756. "oncancel",
  17757. "oncandidatewindowhide",
  17758. "oncandidatewindowshow",
  17759. "oncandidatewindowupdate",
  17760. "oncanplay",
  17761. "oncanplaythrough",
  17762. "oncellchange",
  17763. "onchange",
  17764. "onchargingchange",
  17765. "onchargingtimechange",
  17766. "onchecking",
  17767. "onclick",
  17768. "onclose",
  17769. "oncompassneedscalibration",
  17770. "oncomplete",
  17771. "oncontextmenu",
  17772. "oncontrolselect",
  17773. "oncopy",
  17774. "oncuechange",
  17775. "oncut",
  17776. "ondataavailable",
  17777. "ondatachannel",
  17778. "ondatasetchanged",
  17779. "ondatasetcomplete",
  17780. "ondblclick",
  17781. "ondeactivate",
  17782. "ondevicelight",
  17783. "ondevicemotion",
  17784. "ondeviceorientation",
  17785. "ondeviceproximity",
  17786. "ondischargingtimechange",
  17787. "ondisplay",
  17788. "ondownloading",
  17789. "ondrag",
  17790. "ondragend",
  17791. "ondragenter",
  17792. "ondragleave",
  17793. "ondragover",
  17794. "ondragstart",
  17795. "ondrop",
  17796. "ondurationchange",
  17797. "onemptied",
  17798. "onencrypted",
  17799. "onend",
  17800. "onended",
  17801. "onenter",
  17802. "onerror",
  17803. "onerrorupdate",
  17804. "onexit",
  17805. "onfilterchange",
  17806. "onfinish",
  17807. "onfocus",
  17808. "onfocusin",
  17809. "onfocusout",
  17810. "onfullscreenchange",
  17811. "onfullscreenerror",
  17812. "ongesturechange",
  17813. "ongestureend",
  17814. "ongesturestart",
  17815. "ongotpointercapture",
  17816. "onhashchange",
  17817. "onhelp",
  17818. "onicecandidate",
  17819. "oniceconnectionstatechange",
  17820. "oninactive",
  17821. "oninput",
  17822. "oninvalid",
  17823. "onkeydown",
  17824. "onkeypress",
  17825. "onkeyup",
  17826. "onlanguagechange",
  17827. "onlayoutcomplete",
  17828. "onlevelchange",
  17829. "onload",
  17830. "onloadeddata",
  17831. "onloadedmetadata",
  17832. "onloadend",
  17833. "onloadstart",
  17834. "onlosecapture",
  17835. "onlostpointercapture",
  17836. "only",
  17837. "onmark",
  17838. "onmessage",
  17839. "onmousedown",
  17840. "onmouseenter",
  17841. "onmouseleave",
  17842. "onmousemove",
  17843. "onmouseout",
  17844. "onmouseover",
  17845. "onmouseup",
  17846. "onmousewheel",
  17847. "onmove",
  17848. "onmoveend",
  17849. "onmovestart",
  17850. "onmozfullscreenchange",
  17851. "onmozfullscreenerror",
  17852. "onmozorientationchange",
  17853. "onmozpointerlockchange",
  17854. "onmozpointerlockerror",
  17855. "onmscontentzoom",
  17856. "onmsfullscreenchange",
  17857. "onmsfullscreenerror",
  17858. "onmsgesturechange",
  17859. "onmsgesturedoubletap",
  17860. "onmsgestureend",
  17861. "onmsgesturehold",
  17862. "onmsgesturestart",
  17863. "onmsgesturetap",
  17864. "onmsgotpointercapture",
  17865. "onmsinertiastart",
  17866. "onmslostpointercapture",
  17867. "onmsmanipulationstatechanged",
  17868. "onmsneedkey",
  17869. "onmsorientationchange",
  17870. "onmspointercancel",
  17871. "onmspointerdown",
  17872. "onmspointerenter",
  17873. "onmspointerhover",
  17874. "onmspointerleave",
  17875. "onmspointermove",
  17876. "onmspointerout",
  17877. "onmspointerover",
  17878. "onmspointerup",
  17879. "onmssitemodejumplistitemremoved",
  17880. "onmsthumbnailclick",
  17881. "onnegotiationneeded",
  17882. "onnomatch",
  17883. "onnoupdate",
  17884. "onobsolete",
  17885. "onoffline",
  17886. "ononline",
  17887. "onopen",
  17888. "onorientationchange",
  17889. "onpagechange",
  17890. "onpagehide",
  17891. "onpageshow",
  17892. "onpaste",
  17893. "onpause",
  17894. "onplay",
  17895. "onplaying",
  17896. "onpluginstreamstart",
  17897. "onpointercancel",
  17898. "onpointerdown",
  17899. "onpointerenter",
  17900. "onpointerleave",
  17901. "onpointerlockchange",
  17902. "onpointerlockerror",
  17903. "onpointermove",
  17904. "onpointerout",
  17905. "onpointerover",
  17906. "onpointerup",
  17907. "onpopstate",
  17908. "onprogress",
  17909. "onpropertychange",
  17910. "onratechange",
  17911. "onreadystatechange",
  17912. "onremovestream",
  17913. "onremovetrack",
  17914. "onreset",
  17915. "onresize",
  17916. "onresizeend",
  17917. "onresizestart",
  17918. "onresourcetimingbufferfull",
  17919. "onresult",
  17920. "onresume",
  17921. "onrowenter",
  17922. "onrowexit",
  17923. "onrowsdelete",
  17924. "onrowsinserted",
  17925. "onscroll",
  17926. "onsearch",
  17927. "onseeked",
  17928. "onseeking",
  17929. "onselect",
  17930. "onselectionchange",
  17931. "onselectstart",
  17932. "onshow",
  17933. "onsignalingstatechange",
  17934. "onsoundend",
  17935. "onsoundstart",
  17936. "onspeechend",
  17937. "onspeechstart",
  17938. "onstalled",
  17939. "onstart",
  17940. "onstatechange",
  17941. "onstop",
  17942. "onstorage",
  17943. "onstoragecommit",
  17944. "onsubmit",
  17945. "onsuccess",
  17946. "onsuspend",
  17947. "ontextinput",
  17948. "ontimeout",
  17949. "ontimeupdate",
  17950. "ontoggle",
  17951. "ontouchcancel",
  17952. "ontouchend",
  17953. "ontouchmove",
  17954. "ontouchstart",
  17955. "ontransitionend",
  17956. "onunload",
  17957. "onupdateready",
  17958. "onupgradeneeded",
  17959. "onuserproximity",
  17960. "onversionchange",
  17961. "onvoiceschanged",
  17962. "onvolumechange",
  17963. "onwaiting",
  17964. "onwarning",
  17965. "onwebkitanimationend",
  17966. "onwebkitanimationiteration",
  17967. "onwebkitanimationstart",
  17968. "onwebkitcurrentplaybacktargetiswirelesschanged",
  17969. "onwebkitfullscreenchange",
  17970. "onwebkitfullscreenerror",
  17971. "onwebkitkeyadded",
  17972. "onwebkitkeyerror",
  17973. "onwebkitkeymessage",
  17974. "onwebkitneedkey",
  17975. "onwebkitorientationchange",
  17976. "onwebkitplaybacktargetavailabilitychanged",
  17977. "onwebkitpointerlockchange",
  17978. "onwebkitpointerlockerror",
  17979. "onwebkitresourcetimingbufferfull",
  17980. "onwebkittransitionend",
  17981. "onwheel",
  17982. "onzoom",
  17983. "opacity",
  17984. "open",
  17985. "openCursor",
  17986. "openDatabase",
  17987. "openKeyCursor",
  17988. "opener",
  17989. "opera",
  17990. "operationType",
  17991. "operator",
  17992. "opr",
  17993. "optimum",
  17994. "options",
  17995. "order",
  17996. "orderX",
  17997. "orderY",
  17998. "ordered",
  17999. "org",
  18000. "orient",
  18001. "orientAngle",
  18002. "orientType",
  18003. "orientation",
  18004. "origin",
  18005. "originalTarget",
  18006. "orphans",
  18007. "oscpu",
  18008. "outerHTML",
  18009. "outerHeight",
  18010. "outerText",
  18011. "outerWidth",
  18012. "outline",
  18013. "outline-color",
  18014. "outline-offset",
  18015. "outline-style",
  18016. "outline-width",
  18017. "outlineColor",
  18018. "outlineOffset",
  18019. "outlineStyle",
  18020. "outlineWidth",
  18021. "outputBuffer",
  18022. "overflow",
  18023. "overflow-x",
  18024. "overflow-y",
  18025. "overflowX",
  18026. "overflowY",
  18027. "overrideMimeType",
  18028. "oversample",
  18029. "ownerDocument",
  18030. "ownerElement",
  18031. "ownerNode",
  18032. "ownerRule",
  18033. "ownerSVGElement",
  18034. "owningElement",
  18035. "p1",
  18036. "p2",
  18037. "p3",
  18038. "p4",
  18039. "pad",
  18040. "padding",
  18041. "padding-bottom",
  18042. "padding-left",
  18043. "padding-right",
  18044. "padding-top",
  18045. "paddingBottom",
  18046. "paddingLeft",
  18047. "paddingRight",
  18048. "paddingTop",
  18049. "page",
  18050. "page-break-after",
  18051. "page-break-before",
  18052. "page-break-inside",
  18053. "pageBreakAfter",
  18054. "pageBreakBefore",
  18055. "pageBreakInside",
  18056. "pageCount",
  18057. "pageX",
  18058. "pageXOffset",
  18059. "pageY",
  18060. "pageYOffset",
  18061. "pages",
  18062. "paint-order",
  18063. "paintOrder",
  18064. "paintRequests",
  18065. "paintType",
  18066. "palette",
  18067. "panningModel",
  18068. "parent",
  18069. "parentElement",
  18070. "parentNode",
  18071. "parentRule",
  18072. "parentStyleSheet",
  18073. "parentTextEdit",
  18074. "parentWindow",
  18075. "parse",
  18076. "parseFloat",
  18077. "parseFromString",
  18078. "parseInt",
  18079. "participants",
  18080. "password",
  18081. "pasteHTML",
  18082. "path",
  18083. "pathLength",
  18084. "pathSegList",
  18085. "pathSegType",
  18086. "pathSegTypeAsLetter",
  18087. "pathname",
  18088. "pattern",
  18089. "patternContentUnits",
  18090. "patternMismatch",
  18091. "patternTransform",
  18092. "patternUnits",
  18093. "pause",
  18094. "pauseAnimations",
  18095. "pauseOnExit",
  18096. "paused",
  18097. "pending",
  18098. "performance",
  18099. "permission",
  18100. "persisted",
  18101. "personalbar",
  18102. "perspective",
  18103. "perspective-origin",
  18104. "perspectiveOrigin",
  18105. "phoneticFamilyName",
  18106. "phoneticGivenName",
  18107. "photo",
  18108. "ping",
  18109. "pitch",
  18110. "pixelBottom",
  18111. "pixelDepth",
  18112. "pixelHeight",
  18113. "pixelLeft",
  18114. "pixelRight",
  18115. "pixelStorei",
  18116. "pixelTop",
  18117. "pixelUnitToMillimeterX",
  18118. "pixelUnitToMillimeterY",
  18119. "pixelWidth",
  18120. "placeholder",
  18121. "platform",
  18122. "play",
  18123. "playbackRate",
  18124. "playbackState",
  18125. "playbackTime",
  18126. "played",
  18127. "plugins",
  18128. "pluginspage",
  18129. "pname",
  18130. "pointer-events",
  18131. "pointerBeforeReferenceNode",
  18132. "pointerEnabled",
  18133. "pointerEvents",
  18134. "pointerId",
  18135. "pointerLockElement",
  18136. "pointerType",
  18137. "points",
  18138. "pointsAtX",
  18139. "pointsAtY",
  18140. "pointsAtZ",
  18141. "polygonOffset",
  18142. "pop",
  18143. "popupWindowFeatures",
  18144. "popupWindowName",
  18145. "popupWindowURI",
  18146. "port",
  18147. "port1",
  18148. "port2",
  18149. "ports",
  18150. "posBottom",
  18151. "posHeight",
  18152. "posLeft",
  18153. "posRight",
  18154. "posTop",
  18155. "posWidth",
  18156. "position",
  18157. "positionAlign",
  18158. "postError",
  18159. "postMessage",
  18160. "poster",
  18161. "pow",
  18162. "powerOff",
  18163. "preMultiplySelf",
  18164. "precision",
  18165. "preferredStyleSheetSet",
  18166. "preferredStylesheetSet",
  18167. "prefix",
  18168. "preload",
  18169. "preserveAlpha",
  18170. "preserveAspectRatio",
  18171. "preserveAspectRatioString",
  18172. "pressed",
  18173. "pressure",
  18174. "prevValue",
  18175. "preventDefault",
  18176. "preventExtensions",
  18177. "previousElementSibling",
  18178. "previousNode",
  18179. "previousPage",
  18180. "previousScale",
  18181. "previousSibling",
  18182. "previousTranslate",
  18183. "primaryKey",
  18184. "primitiveType",
  18185. "primitiveUnits",
  18186. "principals",
  18187. "print",
  18188. "privateKey",
  18189. "probablySupportsContext",
  18190. "process",
  18191. "processIceMessage",
  18192. "product",
  18193. "productSub",
  18194. "profile",
  18195. "profileEnd",
  18196. "profiles",
  18197. "prompt",
  18198. "properties",
  18199. "propertyIsEnumerable",
  18200. "propertyName",
  18201. "protocol",
  18202. "protocolLong",
  18203. "prototype",
  18204. "pseudoClass",
  18205. "pseudoElement",
  18206. "publicId",
  18207. "publicKey",
  18208. "published",
  18209. "push",
  18210. "pushNotification",
  18211. "pushState",
  18212. "put",
  18213. "putImageData",
  18214. "quadraticCurveTo",
  18215. "qualifier",
  18216. "queryCommandEnabled",
  18217. "queryCommandIndeterm",
  18218. "queryCommandState",
  18219. "queryCommandSupported",
  18220. "queryCommandText",
  18221. "queryCommandValue",
  18222. "querySelector",
  18223. "querySelectorAll",
  18224. "quote",
  18225. "quotes",
  18226. "r",
  18227. "r1",
  18228. "r2",
  18229. "race",
  18230. "radiogroup",
  18231. "radiusX",
  18232. "radiusY",
  18233. "random",
  18234. "range",
  18235. "rangeCount",
  18236. "rangeMax",
  18237. "rangeMin",
  18238. "rangeOffset",
  18239. "rangeOverflow",
  18240. "rangeParent",
  18241. "rangeUnderflow",
  18242. "rate",
  18243. "ratio",
  18244. "raw",
  18245. "read",
  18246. "readAsArrayBuffer",
  18247. "readAsBinaryString",
  18248. "readAsBlob",
  18249. "readAsDataURL",
  18250. "readAsText",
  18251. "readOnly",
  18252. "readPixels",
  18253. "readReportRequested",
  18254. "readyState",
  18255. "reason",
  18256. "reboot",
  18257. "receiver",
  18258. "receivers",
  18259. "recordNumber",
  18260. "recordset",
  18261. "rect",
  18262. "red",
  18263. "redirectCount",
  18264. "redirectEnd",
  18265. "redirectStart",
  18266. "reduce",
  18267. "reduceRight",
  18268. "reduction",
  18269. "refDistance",
  18270. "refX",
  18271. "refY",
  18272. "referenceNode",
  18273. "referrer",
  18274. "refresh",
  18275. "region",
  18276. "regionAnchorX",
  18277. "regionAnchorY",
  18278. "regionId",
  18279. "regions",
  18280. "register",
  18281. "registerContentHandler",
  18282. "registerElement",
  18283. "registerProtocolHandler",
  18284. "reject",
  18285. "rel",
  18286. "relList",
  18287. "relatedNode",
  18288. "relatedTarget",
  18289. "release",
  18290. "releaseCapture",
  18291. "releaseEvents",
  18292. "releasePointerCapture",
  18293. "releaseShaderCompiler",
  18294. "reliable",
  18295. "reload",
  18296. "remainingSpace",
  18297. "remoteDescription",
  18298. "remove",
  18299. "removeAllRanges",
  18300. "removeAttribute",
  18301. "removeAttributeNS",
  18302. "removeAttributeNode",
  18303. "removeBehavior",
  18304. "removeChild",
  18305. "removeCue",
  18306. "removeEventListener",
  18307. "removeFilter",
  18308. "removeImport",
  18309. "removeItem",
  18310. "removeListener",
  18311. "removeNamedItem",
  18312. "removeNamedItemNS",
  18313. "removeNode",
  18314. "removeParameter",
  18315. "removeProperty",
  18316. "removeRange",
  18317. "removeRegion",
  18318. "removeRule",
  18319. "removeSiteSpecificTrackingException",
  18320. "removeSourceBuffer",
  18321. "removeStream",
  18322. "removeTrack",
  18323. "removeVariable",
  18324. "removeWakeLockListener",
  18325. "removeWebWideTrackingException",
  18326. "removedNodes",
  18327. "renderbufferStorage",
  18328. "renderedBuffer",
  18329. "renderingMode",
  18330. "repeat",
  18331. "replace",
  18332. "replaceAdjacentText",
  18333. "replaceChild",
  18334. "replaceData",
  18335. "replaceId",
  18336. "replaceItem",
  18337. "replaceNode",
  18338. "replaceState",
  18339. "replaceTrack",
  18340. "replaceWholeText",
  18341. "reportValidity",
  18342. "requestAnimationFrame",
  18343. "requestAutocomplete",
  18344. "requestData",
  18345. "requestFullscreen",
  18346. "requestMediaKeySystemAccess",
  18347. "requestPermission",
  18348. "requestPointerLock",
  18349. "requestStart",
  18350. "requestingWindow",
  18351. "required",
  18352. "requiredExtensions",
  18353. "requiredFeatures",
  18354. "reset",
  18355. "resetTransform",
  18356. "resize",
  18357. "resizeBy",
  18358. "resizeTo",
  18359. "resolve",
  18360. "response",
  18361. "responseBody",
  18362. "responseEnd",
  18363. "responseStart",
  18364. "responseText",
  18365. "responseType",
  18366. "responseURL",
  18367. "responseXML",
  18368. "restore",
  18369. "result",
  18370. "resultType",
  18371. "resume",
  18372. "returnValue",
  18373. "rev",
  18374. "reverse",
  18375. "reversed",
  18376. "revocable",
  18377. "revokeObjectURL",
  18378. "rgbColor",
  18379. "right",
  18380. "rightContext",
  18381. "rightMargin",
  18382. "rolloffFactor",
  18383. "root",
  18384. "rootElement",
  18385. "rotate",
  18386. "rotateAxisAngle",
  18387. "rotateAxisAngleSelf",
  18388. "rotateFromVector",
  18389. "rotateFromVectorSelf",
  18390. "rotateSelf",
  18391. "rotation",
  18392. "rotationRate",
  18393. "round",
  18394. "rowIndex",
  18395. "rowSpan",
  18396. "rows",
  18397. "rubyAlign",
  18398. "rubyOverhang",
  18399. "rubyPosition",
  18400. "rules",
  18401. "runtime",
  18402. "runtimeStyle",
  18403. "rx",
  18404. "ry",
  18405. "safari",
  18406. "sampleCoverage",
  18407. "sampleRate",
  18408. "sandbox",
  18409. "save",
  18410. "scale",
  18411. "scale3d",
  18412. "scale3dSelf",
  18413. "scaleNonUniform",
  18414. "scaleNonUniformSelf",
  18415. "scaleSelf",
  18416. "scheme",
  18417. "scissor",
  18418. "scope",
  18419. "scopeName",
  18420. "scoped",
  18421. "screen",
  18422. "screenBrightness",
  18423. "screenEnabled",
  18424. "screenLeft",
  18425. "screenPixelToMillimeterX",
  18426. "screenPixelToMillimeterY",
  18427. "screenTop",
  18428. "screenX",
  18429. "screenY",
  18430. "scripts",
  18431. "scroll",
  18432. "scroll-behavior",
  18433. "scrollAmount",
  18434. "scrollBehavior",
  18435. "scrollBy",
  18436. "scrollByLines",
  18437. "scrollByPages",
  18438. "scrollDelay",
  18439. "scrollHeight",
  18440. "scrollIntoView",
  18441. "scrollIntoViewIfNeeded",
  18442. "scrollLeft",
  18443. "scrollLeftMax",
  18444. "scrollMaxX",
  18445. "scrollMaxY",
  18446. "scrollTo",
  18447. "scrollTop",
  18448. "scrollTopMax",
  18449. "scrollWidth",
  18450. "scrollX",
  18451. "scrollY",
  18452. "scrollbar3dLightColor",
  18453. "scrollbarArrowColor",
  18454. "scrollbarBaseColor",
  18455. "scrollbarDarkShadowColor",
  18456. "scrollbarFaceColor",
  18457. "scrollbarHighlightColor",
  18458. "scrollbarShadowColor",
  18459. "scrollbarTrackColor",
  18460. "scrollbars",
  18461. "scrolling",
  18462. "sdp",
  18463. "sdpMLineIndex",
  18464. "sdpMid",
  18465. "seal",
  18466. "search",
  18467. "searchBox",
  18468. "searchBoxJavaBridge_",
  18469. "searchParams",
  18470. "sectionRowIndex",
  18471. "secureConnectionStart",
  18472. "security",
  18473. "seed",
  18474. "seekable",
  18475. "seeking",
  18476. "select",
  18477. "selectAllChildren",
  18478. "selectNode",
  18479. "selectNodeContents",
  18480. "selectNodes",
  18481. "selectSingleNode",
  18482. "selectSubString",
  18483. "selected",
  18484. "selectedIndex",
  18485. "selectedOptions",
  18486. "selectedStyleSheetSet",
  18487. "selectedStylesheetSet",
  18488. "selection",
  18489. "selectionDirection",
  18490. "selectionEnd",
  18491. "selectionStart",
  18492. "selector",
  18493. "selectorText",
  18494. "self",
  18495. "send",
  18496. "sendAsBinary",
  18497. "sendBeacon",
  18498. "sender",
  18499. "sentTimestamp",
  18500. "separator",
  18501. "serializeToString",
  18502. "serviceWorker",
  18503. "sessionId",
  18504. "sessionStorage",
  18505. "set",
  18506. "setActive",
  18507. "setAlpha",
  18508. "setAttribute",
  18509. "setAttributeNS",
  18510. "setAttributeNode",
  18511. "setAttributeNodeNS",
  18512. "setBaseAndExtent",
  18513. "setBingCurrentSearchDefault",
  18514. "setCapture",
  18515. "setColor",
  18516. "setCompositeOperation",
  18517. "setCurrentTime",
  18518. "setCustomValidity",
  18519. "setData",
  18520. "setDate",
  18521. "setDragImage",
  18522. "setEnd",
  18523. "setEndAfter",
  18524. "setEndBefore",
  18525. "setEndPoint",
  18526. "setFillColor",
  18527. "setFilterRes",
  18528. "setFloat32",
  18529. "setFloat64",
  18530. "setFloatValue",
  18531. "setFullYear",
  18532. "setHours",
  18533. "setImmediate",
  18534. "setInt16",
  18535. "setInt32",
  18536. "setInt8",
  18537. "setInterval",
  18538. "setItem",
  18539. "setLineCap",
  18540. "setLineDash",
  18541. "setLineJoin",
  18542. "setLineWidth",
  18543. "setLocalDescription",
  18544. "setMatrix",
  18545. "setMatrixValue",
  18546. "setMediaKeys",
  18547. "setMilliseconds",
  18548. "setMinutes",
  18549. "setMiterLimit",
  18550. "setMonth",
  18551. "setNamedItem",
  18552. "setNamedItemNS",
  18553. "setNonUserCodeExceptions",
  18554. "setOrientToAngle",
  18555. "setOrientToAuto",
  18556. "setOrientation",
  18557. "setOverrideHistoryNavigationMode",
  18558. "setPaint",
  18559. "setParameter",
  18560. "setPeriodicWave",
  18561. "setPointerCapture",
  18562. "setPosition",
  18563. "setPreference",
  18564. "setProperty",
  18565. "setPrototypeOf",
  18566. "setRGBColor",
  18567. "setRGBColorICCColor",
  18568. "setRadius",
  18569. "setRangeText",
  18570. "setRemoteDescription",
  18571. "setRequestHeader",
  18572. "setResizable",
  18573. "setResourceTimingBufferSize",
  18574. "setRotate",
  18575. "setScale",
  18576. "setSeconds",
  18577. "setSelectionRange",
  18578. "setServerCertificate",
  18579. "setShadow",
  18580. "setSkewX",
  18581. "setSkewY",
  18582. "setStart",
  18583. "setStartAfter",
  18584. "setStartBefore",
  18585. "setStdDeviation",
  18586. "setStringValue",
  18587. "setStrokeColor",
  18588. "setSuggestResult",
  18589. "setTargetAtTime",
  18590. "setTargetValueAtTime",
  18591. "setTime",
  18592. "setTimeout",
  18593. "setTransform",
  18594. "setTranslate",
  18595. "setUTCDate",
  18596. "setUTCFullYear",
  18597. "setUTCHours",
  18598. "setUTCMilliseconds",
  18599. "setUTCMinutes",
  18600. "setUTCMonth",
  18601. "setUTCSeconds",
  18602. "setUint16",
  18603. "setUint32",
  18604. "setUint8",
  18605. "setUri",
  18606. "setValueAtTime",
  18607. "setValueCurveAtTime",
  18608. "setVariable",
  18609. "setVelocity",
  18610. "setVersion",
  18611. "setYear",
  18612. "settingName",
  18613. "settingValue",
  18614. "sex",
  18615. "shaderSource",
  18616. "shadowBlur",
  18617. "shadowColor",
  18618. "shadowOffsetX",
  18619. "shadowOffsetY",
  18620. "shadowRoot",
  18621. "shape",
  18622. "shape-rendering",
  18623. "shapeRendering",
  18624. "sheet",
  18625. "shift",
  18626. "shiftKey",
  18627. "shiftLeft",
  18628. "show",
  18629. "showHelp",
  18630. "showModal",
  18631. "showModalDialog",
  18632. "showModelessDialog",
  18633. "showNotification",
  18634. "sidebar",
  18635. "sign",
  18636. "signalingState",
  18637. "sin",
  18638. "singleNodeValue",
  18639. "sinh",
  18640. "size",
  18641. "sizeToContent",
  18642. "sizes",
  18643. "skewX",
  18644. "skewXSelf",
  18645. "skewY",
  18646. "skewYSelf",
  18647. "slice",
  18648. "slope",
  18649. "small",
  18650. "smooth",
  18651. "smil",
  18652. "smoothingTimeConstant",
  18653. "snapToLines",
  18654. "snapshotItem",
  18655. "snapshotLength",
  18656. "some",
  18657. "sort",
  18658. "source",
  18659. "sourceBuffer",
  18660. "sourceBuffers",
  18661. "sourceIndex",
  18662. "spacing",
  18663. "span",
  18664. "speakAs",
  18665. "speaking",
  18666. "specified",
  18667. "specularConstant",
  18668. "specularExponent",
  18669. "speechSynthesis",
  18670. "speed",
  18671. "speedOfSound",
  18672. "spellcheck",
  18673. "splice",
  18674. "split",
  18675. "splitText",
  18676. "spreadMethod",
  18677. "sqrt",
  18678. "src",
  18679. "srcElement",
  18680. "srcFilter",
  18681. "srcUrn",
  18682. "srcdoc",
  18683. "srclang",
  18684. "srcset",
  18685. "stack",
  18686. "stackTraceLimit",
  18687. "stacktrace",
  18688. "standalone",
  18689. "standby",
  18690. "start",
  18691. "startContainer",
  18692. "startIce",
  18693. "startOffset",
  18694. "startRendering",
  18695. "startTime",
  18696. "startsWith",
  18697. "state",
  18698. "status",
  18699. "statusMessage",
  18700. "statusText",
  18701. "statusbar",
  18702. "stdDeviationX",
  18703. "stdDeviationY",
  18704. "stencilFunc",
  18705. "stencilFuncSeparate",
  18706. "stencilMask",
  18707. "stencilMaskSeparate",
  18708. "stencilOp",
  18709. "stencilOpSeparate",
  18710. "step",
  18711. "stepDown",
  18712. "stepMismatch",
  18713. "stepUp",
  18714. "sticky",
  18715. "stitchTiles",
  18716. "stop",
  18717. "stop-color",
  18718. "stop-opacity",
  18719. "stopColor",
  18720. "stopImmediatePropagation",
  18721. "stopOpacity",
  18722. "stopPropagation",
  18723. "storageArea",
  18724. "storageName",
  18725. "storageStatus",
  18726. "storeSiteSpecificTrackingException",
  18727. "storeWebWideTrackingException",
  18728. "stpVersion",
  18729. "stream",
  18730. "strike",
  18731. "stringValue",
  18732. "stringify",
  18733. "stroke",
  18734. "stroke-dasharray",
  18735. "stroke-dashoffset",
  18736. "stroke-linecap",
  18737. "stroke-linejoin",
  18738. "stroke-miterlimit",
  18739. "stroke-opacity",
  18740. "stroke-width",
  18741. "strokeDasharray",
  18742. "strokeDashoffset",
  18743. "strokeLinecap",
  18744. "strokeLinejoin",
  18745. "strokeMiterlimit",
  18746. "strokeOpacity",
  18747. "strokeRect",
  18748. "strokeStyle",
  18749. "strokeText",
  18750. "strokeWidth",
  18751. "style",
  18752. "styleFloat",
  18753. "styleMedia",
  18754. "styleSheet",
  18755. "styleSheetSets",
  18756. "styleSheets",
  18757. "sub",
  18758. "subarray",
  18759. "subject",
  18760. "submit",
  18761. "subscribe",
  18762. "substr",
  18763. "substring",
  18764. "substringData",
  18765. "subtle",
  18766. "suffix",
  18767. "suffixes",
  18768. "summary",
  18769. "sup",
  18770. "supports",
  18771. "surfaceScale",
  18772. "surroundContents",
  18773. "suspend",
  18774. "suspendRedraw",
  18775. "swapCache",
  18776. "swapNode",
  18777. "sweepFlag",
  18778. "symbols",
  18779. "system",
  18780. "systemCode",
  18781. "systemId",
  18782. "systemLanguage",
  18783. "systemXDPI",
  18784. "systemYDPI",
  18785. "tBodies",
  18786. "tFoot",
  18787. "tHead",
  18788. "tabIndex",
  18789. "table",
  18790. "table-layout",
  18791. "tableLayout",
  18792. "tableValues",
  18793. "tag",
  18794. "tagName",
  18795. "tagUrn",
  18796. "tags",
  18797. "taintEnabled",
  18798. "takeRecords",
  18799. "tan",
  18800. "tanh",
  18801. "target",
  18802. "targetElement",
  18803. "targetTouches",
  18804. "targetX",
  18805. "targetY",
  18806. "tel",
  18807. "terminate",
  18808. "test",
  18809. "texImage2D",
  18810. "texParameterf",
  18811. "texParameteri",
  18812. "texSubImage2D",
  18813. "text",
  18814. "text-align",
  18815. "text-anchor",
  18816. "text-decoration",
  18817. "text-decoration-color",
  18818. "text-decoration-line",
  18819. "text-decoration-style",
  18820. "text-indent",
  18821. "text-overflow",
  18822. "text-rendering",
  18823. "text-shadow",
  18824. "text-transform",
  18825. "textAlign",
  18826. "textAlignLast",
  18827. "textAnchor",
  18828. "textAutospace",
  18829. "textBaseline",
  18830. "textContent",
  18831. "textDecoration",
  18832. "textDecorationBlink",
  18833. "textDecorationColor",
  18834. "textDecorationLine",
  18835. "textDecorationLineThrough",
  18836. "textDecorationNone",
  18837. "textDecorationOverline",
  18838. "textDecorationStyle",
  18839. "textDecorationUnderline",
  18840. "textIndent",
  18841. "textJustify",
  18842. "textJustifyTrim",
  18843. "textKashida",
  18844. "textKashidaSpace",
  18845. "textLength",
  18846. "textOverflow",
  18847. "textRendering",
  18848. "textShadow",
  18849. "textTracks",
  18850. "textTransform",
  18851. "textUnderlinePosition",
  18852. "then",
  18853. "threadId",
  18854. "threshold",
  18855. "tiltX",
  18856. "tiltY",
  18857. "time",
  18858. "timeEnd",
  18859. "timeStamp",
  18860. "timeout",
  18861. "timestamp",
  18862. "timestampOffset",
  18863. "timing",
  18864. "title",
  18865. "toArray",
  18866. "toBlob",
  18867. "toDataURL",
  18868. "toDateString",
  18869. "toElement",
  18870. "toExponential",
  18871. "toFixed",
  18872. "toFloat32Array",
  18873. "toFloat64Array",
  18874. "toGMTString",
  18875. "toISOString",
  18876. "toJSON",
  18877. "toLocaleDateString",
  18878. "toLocaleFormat",
  18879. "toLocaleLowerCase",
  18880. "toLocaleString",
  18881. "toLocaleTimeString",
  18882. "toLocaleUpperCase",
  18883. "toLowerCase",
  18884. "toMethod",
  18885. "toPrecision",
  18886. "toSdp",
  18887. "toSource",
  18888. "toStaticHTML",
  18889. "toString",
  18890. "toStringTag",
  18891. "toTimeString",
  18892. "toUTCString",
  18893. "toUpperCase",
  18894. "toggle",
  18895. "toggleLongPressEnabled",
  18896. "tooLong",
  18897. "toolbar",
  18898. "top",
  18899. "topMargin",
  18900. "total",
  18901. "totalFrameDelay",
  18902. "totalVideoFrames",
  18903. "touchAction",
  18904. "touches",
  18905. "trace",
  18906. "track",
  18907. "transaction",
  18908. "transactions",
  18909. "transform",
  18910. "transform-origin",
  18911. "transform-style",
  18912. "transformOrigin",
  18913. "transformPoint",
  18914. "transformString",
  18915. "transformStyle",
  18916. "transformToDocument",
  18917. "transformToFragment",
  18918. "transition",
  18919. "transition-delay",
  18920. "transition-duration",
  18921. "transition-property",
  18922. "transition-timing-function",
  18923. "transitionDelay",
  18924. "transitionDuration",
  18925. "transitionProperty",
  18926. "transitionTimingFunction",
  18927. "translate",
  18928. "translateSelf",
  18929. "translationX",
  18930. "translationY",
  18931. "trim",
  18932. "trimLeft",
  18933. "trimRight",
  18934. "trueSpeed",
  18935. "trunc",
  18936. "truncate",
  18937. "type",
  18938. "typeDetail",
  18939. "typeMismatch",
  18940. "typeMustMatch",
  18941. "types",
  18942. "ubound",
  18943. "undefined",
  18944. "unescape",
  18945. "uneval",
  18946. "unicode-bidi",
  18947. "unicodeBidi",
  18948. "uniform1f",
  18949. "uniform1fv",
  18950. "uniform1i",
  18951. "uniform1iv",
  18952. "uniform2f",
  18953. "uniform2fv",
  18954. "uniform2i",
  18955. "uniform2iv",
  18956. "uniform3f",
  18957. "uniform3fv",
  18958. "uniform3i",
  18959. "uniform3iv",
  18960. "uniform4f",
  18961. "uniform4fv",
  18962. "uniform4i",
  18963. "uniform4iv",
  18964. "uniformMatrix2fv",
  18965. "uniformMatrix3fv",
  18966. "uniformMatrix4fv",
  18967. "unique",
  18968. "uniqueID",
  18969. "uniqueNumber",
  18970. "unitType",
  18971. "units",
  18972. "unloadEventEnd",
  18973. "unloadEventStart",
  18974. "unlock",
  18975. "unmount",
  18976. "unobserve",
  18977. "unpause",
  18978. "unpauseAnimations",
  18979. "unreadCount",
  18980. "unregister",
  18981. "unregisterContentHandler",
  18982. "unregisterProtocolHandler",
  18983. "unscopables",
  18984. "unselectable",
  18985. "unshift",
  18986. "unsubscribe",
  18987. "unsuspendRedraw",
  18988. "unsuspendRedrawAll",
  18989. "unwatch",
  18990. "unwrapKey",
  18991. "update",
  18992. "updateCommands",
  18993. "updateIce",
  18994. "updateInterval",
  18995. "updateSettings",
  18996. "updated",
  18997. "updating",
  18998. "upload",
  18999. "upper",
  19000. "upperBound",
  19001. "upperOpen",
  19002. "uri",
  19003. "url",
  19004. "urn",
  19005. "urns",
  19006. "usages",
  19007. "useCurrentView",
  19008. "useMap",
  19009. "useProgram",
  19010. "usedSpace",
  19011. "userAgent",
  19012. "userLanguage",
  19013. "username",
  19014. "v8BreakIterator",
  19015. "vAlign",
  19016. "vLink",
  19017. "valid",
  19018. "validateProgram",
  19019. "validationMessage",
  19020. "validity",
  19021. "value",
  19022. "valueAsDate",
  19023. "valueAsNumber",
  19024. "valueAsString",
  19025. "valueInSpecifiedUnits",
  19026. "valueMissing",
  19027. "valueOf",
  19028. "valueText",
  19029. "valueType",
  19030. "values",
  19031. "vector-effect",
  19032. "vectorEffect",
  19033. "velocityAngular",
  19034. "velocityExpansion",
  19035. "velocityX",
  19036. "velocityY",
  19037. "vendor",
  19038. "vendorSub",
  19039. "verify",
  19040. "version",
  19041. "vertexAttrib1f",
  19042. "vertexAttrib1fv",
  19043. "vertexAttrib2f",
  19044. "vertexAttrib2fv",
  19045. "vertexAttrib3f",
  19046. "vertexAttrib3fv",
  19047. "vertexAttrib4f",
  19048. "vertexAttrib4fv",
  19049. "vertexAttribDivisorANGLE",
  19050. "vertexAttribPointer",
  19051. "vertical",
  19052. "vertical-align",
  19053. "verticalAlign",
  19054. "verticalOverflow",
  19055. "vibrate",
  19056. "videoHeight",
  19057. "videoTracks",
  19058. "videoWidth",
  19059. "view",
  19060. "viewBox",
  19061. "viewBoxString",
  19062. "viewTarget",
  19063. "viewTargetString",
  19064. "viewport",
  19065. "viewportAnchorX",
  19066. "viewportAnchorY",
  19067. "viewportElement",
  19068. "visibility",
  19069. "visibilityState",
  19070. "visible",
  19071. "vlinkColor",
  19072. "voice",
  19073. "volume",
  19074. "vrml",
  19075. "vspace",
  19076. "w",
  19077. "wand",
  19078. "warn",
  19079. "wasClean",
  19080. "watch",
  19081. "watchPosition",
  19082. "webdriver",
  19083. "webkitAddKey",
  19084. "webkitAnimation",
  19085. "webkitAnimationDelay",
  19086. "webkitAnimationDirection",
  19087. "webkitAnimationDuration",
  19088. "webkitAnimationFillMode",
  19089. "webkitAnimationIterationCount",
  19090. "webkitAnimationName",
  19091. "webkitAnimationPlayState",
  19092. "webkitAnimationTimingFunction",
  19093. "webkitAppearance",
  19094. "webkitAudioContext",
  19095. "webkitAudioDecodedByteCount",
  19096. "webkitAudioPannerNode",
  19097. "webkitBackfaceVisibility",
  19098. "webkitBackground",
  19099. "webkitBackgroundAttachment",
  19100. "webkitBackgroundClip",
  19101. "webkitBackgroundColor",
  19102. "webkitBackgroundImage",
  19103. "webkitBackgroundOrigin",
  19104. "webkitBackgroundPosition",
  19105. "webkitBackgroundPositionX",
  19106. "webkitBackgroundPositionY",
  19107. "webkitBackgroundRepeat",
  19108. "webkitBackgroundSize",
  19109. "webkitBackingStorePixelRatio",
  19110. "webkitBorderImage",
  19111. "webkitBorderImageOutset",
  19112. "webkitBorderImageRepeat",
  19113. "webkitBorderImageSlice",
  19114. "webkitBorderImageSource",
  19115. "webkitBorderImageWidth",
  19116. "webkitBoxAlign",
  19117. "webkitBoxDirection",
  19118. "webkitBoxFlex",
  19119. "webkitBoxOrdinalGroup",
  19120. "webkitBoxOrient",
  19121. "webkitBoxPack",
  19122. "webkitBoxSizing",
  19123. "webkitCancelAnimationFrame",
  19124. "webkitCancelFullScreen",
  19125. "webkitCancelKeyRequest",
  19126. "webkitCancelRequestAnimationFrame",
  19127. "webkitClearResourceTimings",
  19128. "webkitClosedCaptionsVisible",
  19129. "webkitConvertPointFromNodeToPage",
  19130. "webkitConvertPointFromPageToNode",
  19131. "webkitCreateShadowRoot",
  19132. "webkitCurrentFullScreenElement",
  19133. "webkitCurrentPlaybackTargetIsWireless",
  19134. "webkitDirectionInvertedFromDevice",
  19135. "webkitDisplayingFullscreen",
  19136. "webkitEnterFullScreen",
  19137. "webkitEnterFullscreen",
  19138. "webkitExitFullScreen",
  19139. "webkitExitFullscreen",
  19140. "webkitExitPointerLock",
  19141. "webkitFullScreenKeyboardInputAllowed",
  19142. "webkitFullscreenElement",
  19143. "webkitFullscreenEnabled",
  19144. "webkitGenerateKeyRequest",
  19145. "webkitGetAsEntry",
  19146. "webkitGetDatabaseNames",
  19147. "webkitGetEntries",
  19148. "webkitGetEntriesByName",
  19149. "webkitGetEntriesByType",
  19150. "webkitGetFlowByName",
  19151. "webkitGetGamepads",
  19152. "webkitGetImageDataHD",
  19153. "webkitGetNamedFlows",
  19154. "webkitGetRegionFlowRanges",
  19155. "webkitGetUserMedia",
  19156. "webkitHasClosedCaptions",
  19157. "webkitHidden",
  19158. "webkitIDBCursor",
  19159. "webkitIDBDatabase",
  19160. "webkitIDBDatabaseError",
  19161. "webkitIDBDatabaseException",
  19162. "webkitIDBFactory",
  19163. "webkitIDBIndex",
  19164. "webkitIDBKeyRange",
  19165. "webkitIDBObjectStore",
  19166. "webkitIDBRequest",
  19167. "webkitIDBTransaction",
  19168. "webkitImageSmoothingEnabled",
  19169. "webkitIndexedDB",
  19170. "webkitInitMessageEvent",
  19171. "webkitIsFullScreen",
  19172. "webkitKeys",
  19173. "webkitLineDashOffset",
  19174. "webkitLockOrientation",
  19175. "webkitMatchesSelector",
  19176. "webkitMediaStream",
  19177. "webkitNotifications",
  19178. "webkitOfflineAudioContext",
  19179. "webkitOrientation",
  19180. "webkitPeerConnection00",
  19181. "webkitPersistentStorage",
  19182. "webkitPointerLockElement",
  19183. "webkitPostMessage",
  19184. "webkitPreservesPitch",
  19185. "webkitPutImageDataHD",
  19186. "webkitRTCPeerConnection",
  19187. "webkitRegionOverset",
  19188. "webkitRequestAnimationFrame",
  19189. "webkitRequestFileSystem",
  19190. "webkitRequestFullScreen",
  19191. "webkitRequestFullscreen",
  19192. "webkitRequestPointerLock",
  19193. "webkitResolveLocalFileSystemURL",
  19194. "webkitSetMediaKeys",
  19195. "webkitSetResourceTimingBufferSize",
  19196. "webkitShadowRoot",
  19197. "webkitShowPlaybackTargetPicker",
  19198. "webkitSlice",
  19199. "webkitSpeechGrammar",
  19200. "webkitSpeechGrammarList",
  19201. "webkitSpeechRecognition",
  19202. "webkitSpeechRecognitionError",
  19203. "webkitSpeechRecognitionEvent",
  19204. "webkitStorageInfo",
  19205. "webkitSupportsFullscreen",
  19206. "webkitTemporaryStorage",
  19207. "webkitTextSizeAdjust",
  19208. "webkitTransform",
  19209. "webkitTransformOrigin",
  19210. "webkitTransition",
  19211. "webkitTransitionDelay",
  19212. "webkitTransitionDuration",
  19213. "webkitTransitionProperty",
  19214. "webkitTransitionTimingFunction",
  19215. "webkitURL",
  19216. "webkitUnlockOrientation",
  19217. "webkitUserSelect",
  19218. "webkitVideoDecodedByteCount",
  19219. "webkitVisibilityState",
  19220. "webkitWirelessVideoPlaybackDisabled",
  19221. "webkitdropzone",
  19222. "webstore",
  19223. "weight",
  19224. "whatToShow",
  19225. "wheelDelta",
  19226. "wheelDeltaX",
  19227. "wheelDeltaY",
  19228. "which",
  19229. "white-space",
  19230. "whiteSpace",
  19231. "wholeText",
  19232. "widows",
  19233. "width",
  19234. "will-change",
  19235. "willChange",
  19236. "willValidate",
  19237. "window",
  19238. "withCredentials",
  19239. "word-break",
  19240. "word-spacing",
  19241. "word-wrap",
  19242. "wordBreak",
  19243. "wordSpacing",
  19244. "wordWrap",
  19245. "wrap",
  19246. "wrapKey",
  19247. "write",
  19248. "writeln",
  19249. "writingMode",
  19250. "x",
  19251. "x1",
  19252. "x2",
  19253. "xChannelSelector",
  19254. "xmlEncoding",
  19255. "xmlStandalone",
  19256. "xmlVersion",
  19257. "xmlbase",
  19258. "xmllang",
  19259. "xmlspace",
  19260. "y",
  19261. "y1",
  19262. "y2",
  19263. "yChannelSelector",
  19264. "yandex",
  19265. "z",
  19266. "z-index",
  19267. "zIndex",
  19268. "zoom",
  19269. "zoomAndPan",
  19270. "zoomRectScreen"
  19271. ];
  19272. /***********************************************************************
  19273. A JavaScript tokenizer / parser / beautifier / compressor.
  19274. https://github.com/mishoo/UglifyJS2
  19275. -------------------------------- (C) ---------------------------------
  19276. Author: Mihai Bazon
  19277. <mihai.bazon@gmail.com>
  19278. http://mihai.bazon.net/blog
  19279. Distributed under the BSD license:
  19280. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  19281. Redistribution and use in source and binary forms, with or without
  19282. modification, are permitted provided that the following conditions
  19283. are met:
  19284. * Redistributions of source code must retain the above
  19285. copyright notice, this list of conditions and the following
  19286. disclaimer.
  19287. * Redistributions in binary form must reproduce the above
  19288. copyright notice, this list of conditions and the following
  19289. disclaimer in the documentation and/or other materials
  19290. provided with the distribution.
  19291. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  19292. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19293. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19294. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  19295. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  19296. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19297. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19298. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19299. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  19300. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  19301. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  19302. SUCH DAMAGE.
  19303. ***********************************************************************/
  19304. function find_builtins(reserved) {
  19305. domprops.forEach(add);
  19306. // Compatibility fix for some standard defined globals not defined on every js environment
  19307. var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
  19308. var objects = {};
  19309. var global_ref = typeof global === "object" ? global : self;
  19310. new_globals.forEach(function (new_global) {
  19311. objects[new_global] = global_ref[new_global] || new Function();
  19312. });
  19313. // NaN will be included due to Number.NaN
  19314. [
  19315. "null",
  19316. "true",
  19317. "false",
  19318. "Infinity",
  19319. "-Infinity",
  19320. "undefined",
  19321. ].forEach(add);
  19322. [ Object, Array, Function, Number,
  19323. String, Boolean, Error, Math,
  19324. Date, RegExp, objects.Symbol, ArrayBuffer,
  19325. DataView, decodeURI, decodeURIComponent,
  19326. encodeURI, encodeURIComponent, eval, EvalError,
  19327. Float32Array, Float64Array, Int8Array, Int16Array,
  19328. Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat,
  19329. parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError,
  19330. objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array,
  19331. Uint8ClampedArray, Uint16Array, Uint32Array, URIError,
  19332. objects.WeakMap, objects.WeakSet
  19333. ].forEach(function(ctor) {
  19334. Object.getOwnPropertyNames(ctor).map(add);
  19335. if (ctor.prototype) {
  19336. Object.getOwnPropertyNames(ctor.prototype).map(add);
  19337. }
  19338. });
  19339. function add(name) {
  19340. reserved.add(name);
  19341. }
  19342. }
  19343. function reserve_quoted_keys(ast, reserved) {
  19344. function add(name) {
  19345. push_uniq(reserved, name);
  19346. }
  19347. ast.walk(new TreeWalker(function(node) {
  19348. if (node instanceof AST_ObjectKeyVal && node.quote) {
  19349. add(node.key);
  19350. } else if (node instanceof AST_ObjectProperty && node.quote) {
  19351. add(node.key.name);
  19352. } else if (node instanceof AST_Sub) {
  19353. addStrings(node.property, add);
  19354. }
  19355. }));
  19356. }
  19357. function addStrings(node, add) {
  19358. node.walk(new TreeWalker(function(node) {
  19359. if (node instanceof AST_Sequence) {
  19360. addStrings(node.tail_node(), add);
  19361. } else if (node instanceof AST_String) {
  19362. add(node.value);
  19363. } else if (node instanceof AST_Conditional) {
  19364. addStrings(node.consequent, add);
  19365. addStrings(node.alternative, add);
  19366. }
  19367. return true;
  19368. }));
  19369. }
  19370. function mangle_properties(ast, options) {
  19371. options = defaults(options, {
  19372. builtins: false,
  19373. cache: null,
  19374. debug: false,
  19375. keep_quoted: false,
  19376. only_cache: false,
  19377. regex: null,
  19378. reserved: null,
  19379. }, true);
  19380. var reserved_option = options.reserved;
  19381. if (!Array.isArray(reserved_option)) reserved_option = [reserved_option];
  19382. var reserved = new Set(reserved_option);
  19383. if (!options.builtins) find_builtins(reserved);
  19384. var cname = -1;
  19385. var cache;
  19386. if (options.cache) {
  19387. cache = options.cache.props;
  19388. cache.each(function(mangled_name) {
  19389. reserved.add(mangled_name);
  19390. });
  19391. } else {
  19392. cache = new Dictionary();
  19393. }
  19394. var regex = options.regex;
  19395. // note debug is either false (disabled), or a string of the debug suffix to use (enabled).
  19396. // note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
  19397. // the same as passing an empty string.
  19398. var debug = options.debug !== false;
  19399. var debug_name_suffix;
  19400. if (debug) {
  19401. debug_name_suffix = (options.debug === true ? "" : options.debug);
  19402. }
  19403. var names_to_mangle = new Set();
  19404. var unmangleable = new Set();
  19405. // step 1: find candidates to mangle
  19406. ast.walk(new TreeWalker(function(node) {
  19407. if (node instanceof AST_ObjectKeyVal) {
  19408. if (typeof node.key == "string") {
  19409. add(node.key);
  19410. }
  19411. } else if (node instanceof AST_ObjectProperty) {
  19412. // setter or getter, since KeyVal is handled above
  19413. add(node.key.name);
  19414. } else if (node instanceof AST_Dot) {
  19415. var root = node;
  19416. while (root.expression) {
  19417. root = root.expression;
  19418. }
  19419. if (!(root.thedef && root.thedef.undeclared)) add(node.property);
  19420. } else if (node instanceof AST_Sub) {
  19421. addStrings(node.property, add);
  19422. } else if (node instanceof AST_Call
  19423. && node.expression.print_to_string() == "Object.defineProperty") {
  19424. addStrings(node.args[1], add);
  19425. }
  19426. }));
  19427. // step 2: transform the tree, renaming properties
  19428. return ast.transform(new TreeTransformer(function(node) {
  19429. if (node instanceof AST_ObjectKeyVal) {
  19430. if (typeof node.key == "string") {
  19431. node.key = mangle(node.key);
  19432. }
  19433. } else if (node instanceof AST_ObjectProperty) {
  19434. // setter or getter
  19435. node.key.name = mangle(node.key.name);
  19436. } else if (node instanceof AST_Dot) {
  19437. node.property = mangle(node.property);
  19438. } else if (!options.keep_quoted && node instanceof AST_Sub) {
  19439. node.property = mangleStrings(node.property);
  19440. } else if (node instanceof AST_Call
  19441. && node.expression.print_to_string() == "Object.defineProperty") {
  19442. node.args[1] = mangleStrings(node.args[1]);
  19443. }
  19444. }));
  19445. // only function declarations after this line
  19446. function can_mangle(name) {
  19447. if (unmangleable.has(name)) return false;
  19448. if (reserved.has(name)) return false;
  19449. if (options.only_cache) {
  19450. return cache.has(name);
  19451. }
  19452. if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
  19453. return true;
  19454. }
  19455. function should_mangle(name) {
  19456. if (regex && !regex.test(name)) return false;
  19457. if (reserved.has(name)) return false;
  19458. return cache.has(name)
  19459. || names_to_mangle.has(name);
  19460. }
  19461. function add(name) {
  19462. if (can_mangle(name))
  19463. names_to_mangle.add(name);
  19464. if (!should_mangle(name)) {
  19465. unmangleable.add(name);
  19466. }
  19467. }
  19468. function mangle(name) {
  19469. if (!should_mangle(name)) {
  19470. return name;
  19471. }
  19472. var mangled = cache.get(name);
  19473. if (!mangled) {
  19474. if (debug) {
  19475. // debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
  19476. var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
  19477. if (can_mangle(debug_mangled)) {
  19478. mangled = debug_mangled;
  19479. }
  19480. }
  19481. // either debug mode is off, or it is on and we could not use the mangled name
  19482. if (!mangled) {
  19483. do {
  19484. mangled = base54(++cname);
  19485. } while (!can_mangle(mangled));
  19486. }
  19487. cache.set(name, mangled);
  19488. }
  19489. return mangled;
  19490. }
  19491. function mangleStrings(node) {
  19492. return node.transform(new TreeTransformer(function(node) {
  19493. if (node instanceof AST_Sequence) {
  19494. var last = node.expressions.length - 1;
  19495. node.expressions[last] = mangleStrings(node.expressions[last]);
  19496. } else if (node instanceof AST_String) {
  19497. node.value = mangle(node.value);
  19498. } else if (node instanceof AST_Conditional) {
  19499. node.consequent = mangleStrings(node.consequent);
  19500. node.alternative = mangleStrings(node.alternative);
  19501. }
  19502. return node;
  19503. }));
  19504. }
  19505. }
  19506. var to_ascii = typeof atob == "undefined" ? function(b64) {
  19507. return Buffer.from(b64, "base64").toString();
  19508. } : atob;
  19509. var to_base64 = typeof btoa == "undefined" ? function(str) {
  19510. return Buffer.from(str).toString("base64");
  19511. } : btoa;
  19512. function read_source_map(code) {
  19513. var match = /(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(code);
  19514. if (!match) {
  19515. AST_Node.warn("inline source map not found");
  19516. return null;
  19517. }
  19518. return to_ascii(match[2]);
  19519. }
  19520. function set_shorthand(name, options, keys) {
  19521. if (options[name]) {
  19522. keys.forEach(function(key) {
  19523. if (options[key]) {
  19524. if (typeof options[key] != "object") options[key] = {};
  19525. if (!(name in options[key])) options[key][name] = options[name];
  19526. }
  19527. });
  19528. }
  19529. }
  19530. function init_cache(cache) {
  19531. if (!cache) return;
  19532. if (!("props" in cache)) {
  19533. cache.props = new Dictionary();
  19534. } else if (!(cache.props instanceof Dictionary)) {
  19535. cache.props = Dictionary.fromObject(cache.props);
  19536. }
  19537. }
  19538. function to_json(cache) {
  19539. return {
  19540. props: cache.props.toObject()
  19541. };
  19542. }
  19543. function minify(files, options) {
  19544. var warn_function = AST_Node.warn_function;
  19545. try {
  19546. options = defaults(options, {
  19547. compress: {},
  19548. ecma: undefined,
  19549. enclose: false,
  19550. ie8: false,
  19551. keep_classnames: undefined,
  19552. keep_fnames: false,
  19553. mangle: {},
  19554. module: false,
  19555. nameCache: null,
  19556. output: {},
  19557. parse: {},
  19558. rename: undefined,
  19559. safari10: false,
  19560. sourceMap: false,
  19561. timings: false,
  19562. toplevel: false,
  19563. warnings: false,
  19564. wrap: false,
  19565. }, true);
  19566. var timings = options.timings && {
  19567. start: Date.now()
  19568. };
  19569. if (options.keep_classnames === undefined) {
  19570. options.keep_classnames = options.keep_fnames;
  19571. }
  19572. if (options.rename === undefined) {
  19573. options.rename = options.compress && options.mangle;
  19574. }
  19575. set_shorthand("ecma", options, [ "parse", "compress", "output" ]);
  19576. set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
  19577. set_shorthand("keep_classnames", options, [ "compress", "mangle" ]);
  19578. set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
  19579. set_shorthand("module", options, [ "parse", "compress", "mangle" ]);
  19580. set_shorthand("safari10", options, [ "mangle", "output" ]);
  19581. set_shorthand("toplevel", options, [ "compress", "mangle" ]);
  19582. set_shorthand("warnings", options, [ "compress" ]);
  19583. var quoted_props;
  19584. if (options.mangle) {
  19585. options.mangle = defaults(options.mangle, {
  19586. cache: options.nameCache && (options.nameCache.vars || {}),
  19587. eval: false,
  19588. ie8: false,
  19589. keep_classnames: false,
  19590. keep_fnames: false,
  19591. module: false,
  19592. properties: false,
  19593. reserved: [],
  19594. safari10: false,
  19595. toplevel: false,
  19596. }, true);
  19597. if (options.mangle.properties) {
  19598. if (typeof options.mangle.properties != "object") {
  19599. options.mangle.properties = {};
  19600. }
  19601. if (options.mangle.properties.keep_quoted) {
  19602. quoted_props = options.mangle.properties.reserved;
  19603. if (!Array.isArray(quoted_props)) quoted_props = [];
  19604. options.mangle.properties.reserved = quoted_props;
  19605. }
  19606. if (options.nameCache && !("cache" in options.mangle.properties)) {
  19607. options.mangle.properties.cache = options.nameCache.props || {};
  19608. }
  19609. }
  19610. init_cache(options.mangle.cache);
  19611. init_cache(options.mangle.properties.cache);
  19612. }
  19613. if (options.sourceMap) {
  19614. options.sourceMap = defaults(options.sourceMap, {
  19615. content: null,
  19616. filename: null,
  19617. includeSources: false,
  19618. root: null,
  19619. url: null,
  19620. }, true);
  19621. }
  19622. var warnings = [];
  19623. if (options.warnings && !AST_Node.warn_function) {
  19624. AST_Node.warn_function = function(warning) {
  19625. warnings.push(warning);
  19626. };
  19627. }
  19628. if (timings) timings.parse = Date.now();
  19629. var toplevel;
  19630. if (files instanceof AST_Toplevel) {
  19631. toplevel = files;
  19632. } else {
  19633. if (typeof files == "string") {
  19634. files = [ files ];
  19635. }
  19636. options.parse = options.parse || {};
  19637. options.parse.toplevel = null;
  19638. for (var name in files) if (HOP(files, name)) {
  19639. options.parse.filename = name;
  19640. options.parse.toplevel = parse(files[name], options.parse);
  19641. if (options.sourceMap && options.sourceMap.content == "inline") {
  19642. if (Object.keys(files).length > 1)
  19643. throw new Error("inline source map only works with singular input");
  19644. options.sourceMap.content = read_source_map(files[name]);
  19645. }
  19646. }
  19647. toplevel = options.parse.toplevel;
  19648. }
  19649. if (quoted_props) {
  19650. reserve_quoted_keys(toplevel, quoted_props);
  19651. }
  19652. if (options.wrap) {
  19653. toplevel = toplevel.wrap_commonjs(options.wrap);
  19654. }
  19655. if (options.enclose) {
  19656. toplevel = toplevel.wrap_enclose(options.enclose);
  19657. }
  19658. if (timings) timings.rename = Date.now();
  19659. if (timings) timings.compress = Date.now();
  19660. if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
  19661. if (timings) timings.scope = Date.now();
  19662. if (options.mangle) toplevel.figure_out_scope(options.mangle);
  19663. if (timings) timings.mangle = Date.now();
  19664. if (options.mangle) {
  19665. base54.reset();
  19666. toplevel.compute_char_frequency(options.mangle);
  19667. toplevel.mangle_names(options.mangle);
  19668. }
  19669. if (timings) timings.properties = Date.now();
  19670. if (options.mangle && options.mangle.properties) {
  19671. toplevel = mangle_properties(toplevel, options.mangle.properties);
  19672. }
  19673. if (timings) timings.output = Date.now();
  19674. var result = {};
  19675. if (options.output.ast) {
  19676. result.ast = toplevel;
  19677. }
  19678. if (!HOP(options.output, "code") || options.output.code) {
  19679. if (options.sourceMap) {
  19680. if (typeof options.sourceMap.content == "string") {
  19681. options.sourceMap.content = JSON.parse(options.sourceMap.content);
  19682. }
  19683. options.output.source_map = SourceMap({
  19684. file: options.sourceMap.filename,
  19685. orig: options.sourceMap.content,
  19686. root: options.sourceMap.root
  19687. });
  19688. if (options.sourceMap.includeSources) {
  19689. if (files instanceof AST_Toplevel) {
  19690. throw new Error("original source content unavailable");
  19691. } else for (var name in files) if (HOP(files, name)) {
  19692. options.output.source_map.get().setSourceContent(name, files[name]);
  19693. }
  19694. }
  19695. }
  19696. delete options.output.ast;
  19697. delete options.output.code;
  19698. var stream = OutputStream(options.output);
  19699. toplevel.print(stream);
  19700. result.code = stream.get();
  19701. if (options.sourceMap) {
  19702. result.map = options.output.source_map.toString();
  19703. if (options.sourceMap.url == "inline") {
  19704. result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
  19705. } else if (options.sourceMap.url) {
  19706. result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
  19707. }
  19708. }
  19709. }
  19710. if (options.nameCache && options.mangle) {
  19711. if (options.mangle.cache) options.nameCache.vars = to_json(options.mangle.cache);
  19712. if (options.mangle.properties && options.mangle.properties.cache) {
  19713. options.nameCache.props = to_json(options.mangle.properties.cache);
  19714. }
  19715. }
  19716. if (timings) {
  19717. timings.end = Date.now();
  19718. result.timings = {
  19719. parse: 1e-3 * (timings.rename - timings.parse),
  19720. rename: 1e-3 * (timings.compress - timings.rename),
  19721. compress: 1e-3 * (timings.scope - timings.compress),
  19722. scope: 1e-3 * (timings.mangle - timings.scope),
  19723. mangle: 1e-3 * (timings.properties - timings.mangle),
  19724. properties: 1e-3 * (timings.output - timings.properties),
  19725. output: 1e-3 * (timings.end - timings.output),
  19726. total: 1e-3 * (timings.end - timings.start)
  19727. };
  19728. }
  19729. if (warnings.length) {
  19730. result.warnings = warnings;
  19731. }
  19732. return result;
  19733. } catch (ex) {
  19734. return { error: ex };
  19735. } finally {
  19736. AST_Node.warn_function = warn_function;
  19737. }
  19738. }
  19739. /***********************************************************************
  19740. A JavaScript tokenizer / parser / beautifier / compressor.
  19741. https://github.com/mishoo/UglifyJS2
  19742. -------------------------------- (C) ---------------------------------
  19743. Author: Mihai Bazon
  19744. <mihai.bazon@gmail.com>
  19745. http://mihai.bazon.net/blog
  19746. Distributed under the BSD license:
  19747. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  19748. Redistribution and use in source and binary forms, with or without
  19749. modification, are permitted provided that the following conditions
  19750. are met:
  19751. * Redistributions of source code must retain the above
  19752. copyright notice, this list of conditions and the following
  19753. disclaimer.
  19754. * Redistributions in binary form must reproduce the above
  19755. copyright notice, this list of conditions and the following
  19756. disclaimer in the documentation and/or other materials
  19757. provided with the distribution.
  19758. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
  19759. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19760. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19761. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  19762. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  19763. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19764. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19765. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19766. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  19767. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  19768. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  19769. SUCH DAMAGE.
  19770. ***********************************************************************/
  19771. (function() {
  19772. var normalize_directives = function(body) {
  19773. var in_directive = true;
  19774. for (var i = 0; i < body.length; i++) {
  19775. if (in_directive && body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {
  19776. body[i] = new AST_Directive({
  19777. start: body[i].start,
  19778. end: body[i].end,
  19779. value: body[i].body.value
  19780. });
  19781. } else if (in_directive && !(body[i] instanceof AST_Statement && body[i].body instanceof AST_String)) {
  19782. in_directive = false;
  19783. }
  19784. }
  19785. return body;
  19786. };
  19787. var MOZ_TO_ME = {
  19788. Program: function(M) {
  19789. return new AST_Toplevel({
  19790. start: my_start_token(M),
  19791. end: my_end_token(M),
  19792. body: normalize_directives(M.body.map(from_moz))
  19793. });
  19794. },
  19795. ArrayPattern: function(M) {
  19796. return new AST_Destructuring({
  19797. start: my_start_token(M),
  19798. end: my_end_token(M),
  19799. names: M.elements.map(function(elm) {
  19800. if (elm === null) {
  19801. return new AST_Hole();
  19802. }
  19803. return from_moz(elm);
  19804. }),
  19805. is_array: true
  19806. });
  19807. },
  19808. ObjectPattern: function(M) {
  19809. return new AST_Destructuring({
  19810. start: my_start_token(M),
  19811. end: my_end_token(M),
  19812. names: M.properties.map(from_moz),
  19813. is_array: false
  19814. });
  19815. },
  19816. AssignmentPattern: function(M) {
  19817. return new AST_Binary({
  19818. start: my_start_token(M),
  19819. end: my_end_token(M),
  19820. left: from_moz(M.left),
  19821. operator: "=",
  19822. right: from_moz(M.right)
  19823. });
  19824. },
  19825. SpreadElement: function(M) {
  19826. return new AST_Expansion({
  19827. start: my_start_token(M),
  19828. end: my_end_token(M),
  19829. expression: from_moz(M.argument)
  19830. });
  19831. },
  19832. RestElement: function(M) {
  19833. return new AST_Expansion({
  19834. start: my_start_token(M),
  19835. end: my_end_token(M),
  19836. expression: from_moz(M.argument)
  19837. });
  19838. },
  19839. TemplateElement: function(M) {
  19840. return new AST_TemplateSegment({
  19841. start: my_start_token(M),
  19842. end: my_end_token(M),
  19843. value: M.value.cooked,
  19844. raw: M.value.raw
  19845. });
  19846. },
  19847. TemplateLiteral: function(M) {
  19848. var segments = [];
  19849. for (var i = 0; i < M.quasis.length; i++) {
  19850. segments.push(from_moz(M.quasis[i]));
  19851. if (M.expressions[i]) {
  19852. segments.push(from_moz(M.expressions[i]));
  19853. }
  19854. }
  19855. return new AST_TemplateString({
  19856. start: my_start_token(M),
  19857. end: my_end_token(M),
  19858. segments: segments
  19859. });
  19860. },
  19861. TaggedTemplateExpression: function(M) {
  19862. return new AST_PrefixedTemplateString({
  19863. start: my_start_token(M),
  19864. end: my_end_token(M),
  19865. template_string: from_moz(M.quasi),
  19866. prefix: from_moz(M.tag)
  19867. });
  19868. },
  19869. FunctionDeclaration: function(M) {
  19870. return new AST_Defun({
  19871. start: my_start_token(M),
  19872. end: my_end_token(M),
  19873. name: from_moz(M.id),
  19874. argnames: M.params.map(from_moz),
  19875. is_generator: M.generator,
  19876. async: M.async,
  19877. body: normalize_directives(from_moz(M.body).body)
  19878. });
  19879. },
  19880. FunctionExpression: function(M) {
  19881. return new AST_Function({
  19882. start: my_start_token(M),
  19883. end: my_end_token(M),
  19884. name: from_moz(M.id),
  19885. argnames: M.params.map(from_moz),
  19886. is_generator: M.generator,
  19887. async: M.async,
  19888. body: normalize_directives(from_moz(M.body).body)
  19889. });
  19890. },
  19891. ArrowFunctionExpression: function(M) {
  19892. return new AST_Arrow({
  19893. start: my_start_token(M),
  19894. end: my_end_token(M),
  19895. argnames: M.params.map(from_moz),
  19896. body: from_moz(M.body),
  19897. async: M.async,
  19898. });
  19899. },
  19900. ExpressionStatement: function(M) {
  19901. return new AST_SimpleStatement({
  19902. start: my_start_token(M),
  19903. end: my_end_token(M),
  19904. body: from_moz(M.expression)
  19905. });
  19906. },
  19907. TryStatement: function(M) {
  19908. var handlers = M.handlers || [M.handler];
  19909. if (handlers.length > 1 || M.guardedHandlers && M.guardedHandlers.length) {
  19910. throw new Error("Multiple catch clauses are not supported.");
  19911. }
  19912. return new AST_Try({
  19913. start : my_start_token(M),
  19914. end : my_end_token(M),
  19915. body : from_moz(M.block).body,
  19916. bcatch : from_moz(handlers[0]),
  19917. bfinally : M.finalizer ? new AST_Finally(from_moz(M.finalizer)) : null
  19918. });
  19919. },
  19920. Property: function(M) {
  19921. var key = M.key;
  19922. var args = {
  19923. start : my_start_token(key || M.value),
  19924. end : my_end_token(M.value),
  19925. key : key.type == "Identifier" ? key.name : key.value,
  19926. value : from_moz(M.value)
  19927. };
  19928. if (M.computed) {
  19929. args.key = from_moz(M.key);
  19930. }
  19931. if (M.method) {
  19932. args.is_generator = M.value.generator;
  19933. args.async = M.value.async;
  19934. if (!M.computed) {
  19935. args.key = new AST_SymbolMethod({ name: args.key });
  19936. } else {
  19937. args.key = from_moz(M.key);
  19938. }
  19939. return new AST_ConciseMethod(args);
  19940. }
  19941. if (M.kind == "init") {
  19942. if (key.type != "Identifier" && key.type != "Literal") {
  19943. args.key = from_moz(key);
  19944. }
  19945. return new AST_ObjectKeyVal(args);
  19946. }
  19947. if (typeof args.key === "string" || typeof args.key === "number") {
  19948. args.key = new AST_SymbolMethod({
  19949. name: args.key
  19950. });
  19951. }
  19952. args.value = new AST_Accessor(args.value);
  19953. if (M.kind == "get") return new AST_ObjectGetter(args);
  19954. if (M.kind == "set") return new AST_ObjectSetter(args);
  19955. if (M.kind == "method") {
  19956. args.async = M.value.async;
  19957. args.is_generator = M.value.generator;
  19958. args.quote = M.computed ? "\"" : null;
  19959. return new AST_ConciseMethod(args);
  19960. }
  19961. },
  19962. MethodDefinition: function(M) {
  19963. var args = {
  19964. start : my_start_token(M),
  19965. end : my_end_token(M),
  19966. key : M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value }),
  19967. value : from_moz(M.value),
  19968. static : M.static,
  19969. };
  19970. if (M.kind == "get") {
  19971. return new AST_ObjectGetter(args);
  19972. }
  19973. if (M.kind == "set") {
  19974. return new AST_ObjectSetter(args);
  19975. }
  19976. args.is_generator = M.value.generator;
  19977. args.async = M.value.async;
  19978. return new AST_ConciseMethod(args);
  19979. },
  19980. ArrayExpression: function(M) {
  19981. return new AST_Array({
  19982. start : my_start_token(M),
  19983. end : my_end_token(M),
  19984. elements : M.elements.map(function(elem) {
  19985. return elem === null ? new AST_Hole() : from_moz(elem);
  19986. })
  19987. });
  19988. },
  19989. ObjectExpression: function(M) {
  19990. return new AST_Object({
  19991. start : my_start_token(M),
  19992. end : my_end_token(M),
  19993. properties : M.properties.map(function(prop) {
  19994. if (prop.type === "SpreadElement") {
  19995. return from_moz(prop);
  19996. }
  19997. prop.type = "Property";
  19998. return from_moz(prop);
  19999. })
  20000. });
  20001. },
  20002. SequenceExpression: function(M) {
  20003. return new AST_Sequence({
  20004. start : my_start_token(M),
  20005. end : my_end_token(M),
  20006. expressions: M.expressions.map(from_moz)
  20007. });
  20008. },
  20009. MemberExpression: function(M) {
  20010. return new (M.computed ? AST_Sub : AST_Dot)({
  20011. start : my_start_token(M),
  20012. end : my_end_token(M),
  20013. property : M.computed ? from_moz(M.property) : M.property.name,
  20014. expression : from_moz(M.object)
  20015. });
  20016. },
  20017. SwitchCase: function(M) {
  20018. return new (M.test ? AST_Case : AST_Default)({
  20019. start : my_start_token(M),
  20020. end : my_end_token(M),
  20021. expression : from_moz(M.test),
  20022. body : M.consequent.map(from_moz)
  20023. });
  20024. },
  20025. VariableDeclaration: function(M) {
  20026. return new (M.kind === "const" ? AST_Const :
  20027. M.kind === "let" ? AST_Let : AST_Var)({
  20028. start : my_start_token(M),
  20029. end : my_end_token(M),
  20030. definitions : M.declarations.map(from_moz)
  20031. });
  20032. },
  20033. ImportDeclaration: function(M) {
  20034. var imported_name = null;
  20035. var imported_names = null;
  20036. M.specifiers.forEach(function (specifier) {
  20037. if (specifier.type === "ImportSpecifier") {
  20038. if (!imported_names) { imported_names = []; }
  20039. imported_names.push(new AST_NameMapping({
  20040. start: my_start_token(specifier),
  20041. end: my_end_token(specifier),
  20042. foreign_name: from_moz(specifier.imported),
  20043. name: from_moz(specifier.local)
  20044. }));
  20045. } else if (specifier.type === "ImportDefaultSpecifier") {
  20046. imported_name = from_moz(specifier.local);
  20047. } else if (specifier.type === "ImportNamespaceSpecifier") {
  20048. if (!imported_names) { imported_names = []; }
  20049. imported_names.push(new AST_NameMapping({
  20050. start: my_start_token(specifier),
  20051. end: my_end_token(specifier),
  20052. foreign_name: new AST_SymbolImportForeign({ name: "*" }),
  20053. name: from_moz(specifier.local)
  20054. }));
  20055. }
  20056. });
  20057. return new AST_Import({
  20058. start : my_start_token(M),
  20059. end : my_end_token(M),
  20060. imported_name: imported_name,
  20061. imported_names : imported_names,
  20062. module_name : from_moz(M.source)
  20063. });
  20064. },
  20065. ExportAllDeclaration: function(M) {
  20066. return new AST_Export({
  20067. start: my_start_token(M),
  20068. end: my_end_token(M),
  20069. exported_names: [
  20070. new AST_NameMapping({
  20071. name: new AST_SymbolExportForeign({ name: "*" }),
  20072. foreign_name: new AST_SymbolExportForeign({ name: "*" })
  20073. })
  20074. ],
  20075. module_name: from_moz(M.source)
  20076. });
  20077. },
  20078. ExportNamedDeclaration: function(M) {
  20079. return new AST_Export({
  20080. start: my_start_token(M),
  20081. end: my_end_token(M),
  20082. exported_definition: from_moz(M.declaration),
  20083. exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(function (specifier) {
  20084. return new AST_NameMapping({
  20085. foreign_name: from_moz(specifier.exported),
  20086. name: from_moz(specifier.local)
  20087. });
  20088. }) : null,
  20089. module_name: from_moz(M.source)
  20090. });
  20091. },
  20092. ExportDefaultDeclaration: function(M) {
  20093. return new AST_Export({
  20094. start: my_start_token(M),
  20095. end: my_end_token(M),
  20096. exported_value: from_moz(M.declaration),
  20097. is_default: true
  20098. });
  20099. },
  20100. Literal: function(M) {
  20101. var val = M.value, args = {
  20102. start : my_start_token(M),
  20103. end : my_end_token(M)
  20104. };
  20105. if (val === null) return new AST_Null(args);
  20106. var rx = M.regex;
  20107. if (rx && rx.pattern) {
  20108. // RegExpLiteral as per ESTree AST spec
  20109. args.value = new RegExp(rx.pattern, rx.flags);
  20110. var raw = args.value.toString();
  20111. args.value.raw_source = rx.flags
  20112. ? raw.substring(0, raw.length - rx.flags.length) + rx.flags
  20113. : raw;
  20114. return new AST_RegExp(args);
  20115. } else if (rx) {
  20116. // support legacy RegExp
  20117. args.value = M.regex && M.raw ? M.raw : val;
  20118. return new AST_RegExp(args);
  20119. }
  20120. switch (typeof val) {
  20121. case "string":
  20122. args.value = val;
  20123. return new AST_String(args);
  20124. case "number":
  20125. args.value = val;
  20126. return new AST_Number(args);
  20127. case "boolean":
  20128. return new (val ? AST_True : AST_False)(args);
  20129. }
  20130. },
  20131. MetaProperty: function(M) {
  20132. if (M.meta.name === "new" && M.property.name === "target") {
  20133. return new AST_NewTarget({
  20134. start: my_start_token(M),
  20135. end: my_end_token(M)
  20136. });
  20137. }
  20138. },
  20139. Identifier: function(M) {
  20140. var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
  20141. return new ( p.type == "LabeledStatement" ? AST_Label
  20142. : p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : p.kind == "let" ? AST_SymbolLet : AST_SymbolVar)
  20143. : /Import.*Specifier/.test(p.type) ? (p.local === M ? AST_SymbolImport : AST_SymbolImportForeign)
  20144. : p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)
  20145. : p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
  20146. : p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
  20147. : p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef
  20148. : p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
  20149. : p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
  20150. : p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
  20151. : p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
  20152. : p.type == "CatchClause" ? AST_SymbolCatch
  20153. : p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef
  20154. : AST_SymbolRef)({
  20155. start : my_start_token(M),
  20156. end : my_end_token(M),
  20157. name : M.name
  20158. });
  20159. }
  20160. };
  20161. MOZ_TO_ME.UpdateExpression =
  20162. MOZ_TO_ME.UnaryExpression = function To_Moz_Unary(M) {
  20163. var prefix = "prefix" in M ? M.prefix
  20164. : M.type == "UnaryExpression" ? true : false;
  20165. return new (prefix ? AST_UnaryPrefix : AST_UnaryPostfix)({
  20166. start : my_start_token(M),
  20167. end : my_end_token(M),
  20168. operator : M.operator,
  20169. expression : from_moz(M.argument)
  20170. });
  20171. };
  20172. MOZ_TO_ME.ClassDeclaration =
  20173. MOZ_TO_ME.ClassExpression = function From_Moz_Class(M) {
  20174. return new (M.type === "ClassDeclaration" ? AST_DefClass : AST_ClassExpression)({
  20175. start : my_start_token(M),
  20176. end : my_end_token(M),
  20177. name : from_moz(M.id),
  20178. extends : from_moz(M.superClass),
  20179. properties: M.body.body.map(from_moz)
  20180. });
  20181. };
  20182. map("EmptyStatement", AST_EmptyStatement);
  20183. map("BlockStatement", AST_BlockStatement, "body@body");
  20184. map("IfStatement", AST_If, "test>condition, consequent>body, alternate>alternative");
  20185. map("LabeledStatement", AST_LabeledStatement, "label>label, body>body");
  20186. map("BreakStatement", AST_Break, "label>label");
  20187. map("ContinueStatement", AST_Continue, "label>label");
  20188. map("WithStatement", AST_With, "object>expression, body>body");
  20189. map("SwitchStatement", AST_Switch, "discriminant>expression, cases@body");
  20190. map("ReturnStatement", AST_Return, "argument>value");
  20191. map("ThrowStatement", AST_Throw, "argument>value");
  20192. map("WhileStatement", AST_While, "test>condition, body>body");
  20193. map("DoWhileStatement", AST_Do, "test>condition, body>body");
  20194. map("ForStatement", AST_For, "init>init, test>condition, update>step, body>body");
  20195. map("ForInStatement", AST_ForIn, "left>init, right>object, body>body");
  20196. map("ForOfStatement", AST_ForOf, "left>init, right>object, body>body, await=await");
  20197. map("AwaitExpression", AST_Await, "argument>expression");
  20198. map("YieldExpression", AST_Yield, "argument>expression, delegate=is_star");
  20199. map("DebuggerStatement", AST_Debugger);
  20200. map("VariableDeclarator", AST_VarDef, "id>name, init>value");
  20201. map("CatchClause", AST_Catch, "param>argname, body%body");
  20202. map("ThisExpression", AST_This);
  20203. map("Super", AST_Super);
  20204. map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
  20205. map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
  20206. map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
  20207. map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative");
  20208. map("NewExpression", AST_New, "callee>expression, arguments@args");
  20209. map("CallExpression", AST_Call, "callee>expression, arguments@args");
  20210. def_to_moz(AST_Toplevel, function To_Moz_Program(M) {
  20211. return to_moz_scope("Program", M);
  20212. });
  20213. def_to_moz(AST_Expansion, function To_Moz_Spread(M, parent) {
  20214. return {
  20215. type: to_moz_in_destructuring() ? "RestElement" : "SpreadElement",
  20216. argument: to_moz(M.expression)
  20217. };
  20218. });
  20219. def_to_moz(AST_PrefixedTemplateString, function To_Moz_TaggedTemplateExpression(M) {
  20220. return {
  20221. type: "TaggedTemplateExpression",
  20222. tag: to_moz(M.prefix),
  20223. quasi: to_moz(M.template_string)
  20224. };
  20225. });
  20226. def_to_moz(AST_TemplateString, function To_Moz_TemplateLiteral(M) {
  20227. var quasis = [];
  20228. var expressions = [];
  20229. for (var i = 0; i < M.segments.length; i++) {
  20230. if (i % 2 !== 0) {
  20231. expressions.push(to_moz(M.segments[i]));
  20232. } else {
  20233. quasis.push({
  20234. type: "TemplateElement",
  20235. value: {
  20236. raw: M.segments[i].raw,
  20237. cooked: M.segments[i].value
  20238. },
  20239. tail: i === M.segments.length - 1
  20240. });
  20241. }
  20242. }
  20243. return {
  20244. type: "TemplateLiteral",
  20245. quasis: quasis,
  20246. expressions: expressions
  20247. };
  20248. });
  20249. def_to_moz(AST_Defun, function To_Moz_FunctionDeclaration(M) {
  20250. return {
  20251. type: "FunctionDeclaration",
  20252. id: to_moz(M.name),
  20253. params: M.argnames.map(to_moz),
  20254. generator: M.is_generator,
  20255. async: M.async,
  20256. body: to_moz_scope("BlockStatement", M)
  20257. };
  20258. });
  20259. def_to_moz(AST_Function, function To_Moz_FunctionExpression(M, parent) {
  20260. var is_generator = parent.is_generator !== undefined ?
  20261. parent.is_generator : M.is_generator;
  20262. return {
  20263. type: "FunctionExpression",
  20264. id: to_moz(M.name),
  20265. params: M.argnames.map(to_moz),
  20266. generator: is_generator,
  20267. async: M.async,
  20268. body: to_moz_scope("BlockStatement", M)
  20269. };
  20270. });
  20271. def_to_moz(AST_Arrow, function To_Moz_ArrowFunctionExpression(M) {
  20272. var body = M.body instanceof Array ? {
  20273. type: "BlockStatement",
  20274. body: M.body.map(to_moz)
  20275. } : to_moz(M.body);
  20276. return {
  20277. type: "ArrowFunctionExpression",
  20278. params: M.argnames.map(to_moz),
  20279. async: M.async,
  20280. body: body
  20281. };
  20282. });
  20283. def_to_moz(AST_Destructuring, function To_Moz_ObjectPattern(M) {
  20284. if (M.is_array) {
  20285. return {
  20286. type: "ArrayPattern",
  20287. elements: M.names.map(to_moz)
  20288. };
  20289. }
  20290. return {
  20291. type: "ObjectPattern",
  20292. properties: M.names.map(to_moz)
  20293. };
  20294. });
  20295. def_to_moz(AST_Directive, function To_Moz_Directive(M) {
  20296. return {
  20297. type: "ExpressionStatement",
  20298. expression: {
  20299. type: "Literal",
  20300. value: M.value
  20301. }
  20302. };
  20303. });
  20304. def_to_moz(AST_SimpleStatement, function To_Moz_ExpressionStatement(M) {
  20305. return {
  20306. type: "ExpressionStatement",
  20307. expression: to_moz(M.body)
  20308. };
  20309. });
  20310. def_to_moz(AST_SwitchBranch, function To_Moz_SwitchCase(M) {
  20311. return {
  20312. type: "SwitchCase",
  20313. test: to_moz(M.expression),
  20314. consequent: M.body.map(to_moz)
  20315. };
  20316. });
  20317. def_to_moz(AST_Try, function To_Moz_TryStatement(M) {
  20318. return {
  20319. type: "TryStatement",
  20320. block: to_moz_block(M),
  20321. handler: to_moz(M.bcatch),
  20322. guardedHandlers: [],
  20323. finalizer: to_moz(M.bfinally)
  20324. };
  20325. });
  20326. def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
  20327. return {
  20328. type: "CatchClause",
  20329. param: to_moz(M.argname),
  20330. guard: null,
  20331. body: to_moz_block(M)
  20332. };
  20333. });
  20334. def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
  20335. return {
  20336. type: "VariableDeclaration",
  20337. kind:
  20338. M instanceof AST_Const ? "const" :
  20339. M instanceof AST_Let ? "let" : "var",
  20340. declarations: M.definitions.map(to_moz)
  20341. };
  20342. });
  20343. def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
  20344. if (M.exported_names) {
  20345. if (M.exported_names[0].name.name === "*") {
  20346. return {
  20347. type: "ExportAllDeclaration",
  20348. source: to_moz(M.module_name)
  20349. };
  20350. }
  20351. return {
  20352. type: "ExportNamedDeclaration",
  20353. specifiers: M.exported_names.map(function (name_mapping) {
  20354. return {
  20355. type: "ExportSpecifier",
  20356. exported: to_moz(name_mapping.foreign_name),
  20357. local: to_moz(name_mapping.name)
  20358. };
  20359. }),
  20360. declaration: to_moz(M.exported_definition),
  20361. source: to_moz(M.module_name)
  20362. };
  20363. }
  20364. return {
  20365. type: M.is_default ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",
  20366. declaration: to_moz(M.exported_value || M.exported_definition)
  20367. };
  20368. });
  20369. def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) {
  20370. var specifiers = [];
  20371. if (M.imported_name) {
  20372. specifiers.push({
  20373. type: "ImportDefaultSpecifier",
  20374. local: to_moz(M.imported_name)
  20375. });
  20376. }
  20377. if (M.imported_names && M.imported_names[0].foreign_name.name === "*") {
  20378. specifiers.push({
  20379. type: "ImportNamespaceSpecifier",
  20380. local: to_moz(M.imported_names[0].name)
  20381. });
  20382. } else if (M.imported_names) {
  20383. M.imported_names.forEach(function(name_mapping) {
  20384. specifiers.push({
  20385. type: "ImportSpecifier",
  20386. local: to_moz(name_mapping.name),
  20387. imported: to_moz(name_mapping.foreign_name)
  20388. });
  20389. });
  20390. }
  20391. return {
  20392. type: "ImportDeclaration",
  20393. specifiers: specifiers,
  20394. source: to_moz(M.module_name)
  20395. };
  20396. });
  20397. def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) {
  20398. return {
  20399. type: "SequenceExpression",
  20400. expressions: M.expressions.map(to_moz)
  20401. };
  20402. });
  20403. def_to_moz(AST_PropAccess, function To_Moz_MemberExpression(M) {
  20404. var isComputed = M instanceof AST_Sub;
  20405. return {
  20406. type: "MemberExpression",
  20407. object: to_moz(M.expression),
  20408. computed: isComputed,
  20409. property: isComputed ? to_moz(M.property) : {type: "Identifier", name: M.property}
  20410. };
  20411. });
  20412. def_to_moz(AST_Unary, function To_Moz_Unary(M) {
  20413. return {
  20414. type: M.operator == "++" || M.operator == "--" ? "UpdateExpression" : "UnaryExpression",
  20415. operator: M.operator,
  20416. prefix: M instanceof AST_UnaryPrefix,
  20417. argument: to_moz(M.expression)
  20418. };
  20419. });
  20420. def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
  20421. if (M.operator == "=" && to_moz_in_destructuring()) {
  20422. return {
  20423. type: "AssignmentPattern",
  20424. left: to_moz(M.left),
  20425. right: to_moz(M.right)
  20426. };
  20427. }
  20428. return {
  20429. type: M.operator == "&&" || M.operator == "||" ? "LogicalExpression" : "BinaryExpression",
  20430. left: to_moz(M.left),
  20431. operator: M.operator,
  20432. right: to_moz(M.right)
  20433. };
  20434. });
  20435. def_to_moz(AST_Array, function To_Moz_ArrayExpression(M) {
  20436. return {
  20437. type: "ArrayExpression",
  20438. elements: M.elements.map(to_moz)
  20439. };
  20440. });
  20441. def_to_moz(AST_Object, function To_Moz_ObjectExpression(M) {
  20442. return {
  20443. type: "ObjectExpression",
  20444. properties: M.properties.map(to_moz)
  20445. };
  20446. });
  20447. def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {
  20448. var key = M.key instanceof AST_Node ? to_moz(M.key) : {
  20449. type: "Identifier",
  20450. value: M.key
  20451. };
  20452. if (typeof M.key === "number") {
  20453. key = {
  20454. type: "Literal",
  20455. value: Number(M.key)
  20456. };
  20457. }
  20458. if (typeof M.key === "string") {
  20459. key = {
  20460. type: "Identifier",
  20461. name: M.key
  20462. };
  20463. }
  20464. var kind;
  20465. var string_or_num = typeof M.key === "string" || typeof M.key === "number";
  20466. var computed = string_or_num ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;
  20467. if (M instanceof AST_ObjectKeyVal) {
  20468. kind = "init";
  20469. computed = !string_or_num;
  20470. } else
  20471. if (M instanceof AST_ObjectGetter) {
  20472. kind = "get";
  20473. } else
  20474. if (M instanceof AST_ObjectSetter) {
  20475. kind = "set";
  20476. }
  20477. if (parent instanceof AST_Class) {
  20478. return {
  20479. type: "MethodDefinition",
  20480. computed: computed,
  20481. kind: kind,
  20482. static: M.static,
  20483. key: to_moz(M.key),
  20484. value: to_moz(M.value)
  20485. };
  20486. }
  20487. return {
  20488. type: "Property",
  20489. computed: computed,
  20490. kind: kind,
  20491. key: key,
  20492. value: to_moz(M.value)
  20493. };
  20494. });
  20495. def_to_moz(AST_ConciseMethod, function To_Moz_MethodDefinition(M, parent) {
  20496. if (parent instanceof AST_Object) {
  20497. return {
  20498. type: "Property",
  20499. computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
  20500. kind: "init",
  20501. method: true,
  20502. shorthand: false,
  20503. key: to_moz(M.key),
  20504. value: to_moz(M.value)
  20505. };
  20506. }
  20507. return {
  20508. type: "MethodDefinition",
  20509. computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
  20510. kind: M.key === "constructor" ? "constructor" : "method",
  20511. static: M.static,
  20512. key: to_moz(M.key),
  20513. value: to_moz(M.value)
  20514. };
  20515. });
  20516. def_to_moz(AST_Class, function To_Moz_Class(M) {
  20517. var type = M instanceof AST_ClassExpression ? "ClassExpression" : "ClassDeclaration";
  20518. return {
  20519. type: type,
  20520. superClass: to_moz(M.extends),
  20521. id: M.name ? to_moz(M.name) : null,
  20522. body: {
  20523. type: "ClassBody",
  20524. body: M.properties.map(to_moz)
  20525. }
  20526. };
  20527. });
  20528. def_to_moz(AST_NewTarget, function To_Moz_MetaProperty(M) {
  20529. return {
  20530. type: "MetaProperty",
  20531. meta: {
  20532. type: "Identifier",
  20533. name: "new"
  20534. },
  20535. property: {
  20536. type: "Identifier",
  20537. name: "target"
  20538. }
  20539. };
  20540. });
  20541. def_to_moz(AST_Symbol, function To_Moz_Identifier(M, parent) {
  20542. if (M instanceof AST_SymbolMethod && parent.quote) {
  20543. return {
  20544. type: "Literal",
  20545. value: M.name
  20546. };
  20547. }
  20548. var def = M.definition();
  20549. return {
  20550. type: "Identifier",
  20551. name: def ? def.mangled_name || def.name : M.name
  20552. };
  20553. });
  20554. def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
  20555. var pattern = M.value.source;
  20556. var flags = M.value.toString().match(/[gimuys]*$/)[0];
  20557. return {
  20558. type: "Literal",
  20559. value: new RegExp(pattern, flags),
  20560. raw: M.value.raw_source,
  20561. regex: {
  20562. pattern: pattern,
  20563. flags: flags,
  20564. }
  20565. };
  20566. });
  20567. def_to_moz(AST_Constant, function To_Moz_Literal(M) {
  20568. var value = M.value;
  20569. if (typeof value === "number" && (value < 0 || (value === 0 && 1 / value < 0))) {
  20570. return {
  20571. type: "UnaryExpression",
  20572. operator: "-",
  20573. prefix: true,
  20574. argument: {
  20575. type: "Literal",
  20576. value: -value,
  20577. raw: M.start.raw
  20578. }
  20579. };
  20580. }
  20581. return {
  20582. type: "Literal",
  20583. value: value,
  20584. raw: M.start.raw
  20585. };
  20586. });
  20587. def_to_moz(AST_Atom, function To_Moz_Atom(M) {
  20588. return {
  20589. type: "Identifier",
  20590. name: String(M.value)
  20591. };
  20592. });
  20593. AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
  20594. AST_Null.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
  20595. AST_Hole.DEFMETHOD("to_mozilla_ast", function To_Moz_ArrayHole() { return null; });
  20596. AST_Block.DEFMETHOD("to_mozilla_ast", AST_BlockStatement.prototype.to_mozilla_ast);
  20597. AST_Lambda.DEFMETHOD("to_mozilla_ast", AST_Function.prototype.to_mozilla_ast);
  20598. /* -----[ tools ]----- */
  20599. function raw_token(moznode) {
  20600. if (moznode.type == "Literal") {
  20601. return moznode.raw != null ? moznode.raw : moznode.value + "";
  20602. }
  20603. }
  20604. function my_start_token(moznode) {
  20605. var loc = moznode.loc, start = loc && loc.start;
  20606. var range = moznode.range;
  20607. return new AST_Token({
  20608. file : loc && loc.source,
  20609. line : start && start.line,
  20610. col : start && start.column,
  20611. pos : range ? range[0] : moznode.start,
  20612. endline : start && start.line,
  20613. endcol : start && start.column,
  20614. endpos : range ? range[0] : moznode.start,
  20615. raw : raw_token(moznode),
  20616. });
  20617. }
  20618. function my_end_token(moznode) {
  20619. var loc = moznode.loc, end = loc && loc.end;
  20620. var range = moznode.range;
  20621. return new AST_Token({
  20622. file : loc && loc.source,
  20623. line : end && end.line,
  20624. col : end && end.column,
  20625. pos : range ? range[1] : moznode.end,
  20626. endline : end && end.line,
  20627. endcol : end && end.column,
  20628. endpos : range ? range[1] : moznode.end,
  20629. raw : raw_token(moznode),
  20630. });
  20631. }
  20632. function map(moztype, mytype, propmap) {
  20633. var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
  20634. moz_to_me += "return new U2." + mytype.name + "({\n" +
  20635. "start: my_start_token(M),\n" +
  20636. "end: my_end_token(M)";
  20637. var me_to_moz = "function To_Moz_" + moztype + "(M){\n";
  20638. me_to_moz += "return {\n" +
  20639. "type: " + JSON.stringify(moztype);
  20640. if (propmap) propmap.split(/\s*,\s*/).forEach(function(prop) {
  20641. var m = /([a-z0-9$_]+)([=@>%])([a-z0-9$_]+)/i.exec(prop);
  20642. if (!m) throw new Error("Can't understand property map: " + prop);
  20643. var moz = m[1], how = m[2], my = m[3];
  20644. moz_to_me += ",\n" + my + ": ";
  20645. me_to_moz += ",\n" + moz + ": ";
  20646. switch (how) {
  20647. case "@":
  20648. moz_to_me += "M." + moz + ".map(from_moz)";
  20649. me_to_moz += "M." + my + ".map(to_moz)";
  20650. break;
  20651. case ">":
  20652. moz_to_me += "from_moz(M." + moz + ")";
  20653. me_to_moz += "to_moz(M." + my + ")";
  20654. break;
  20655. case "=":
  20656. moz_to_me += "M." + moz;
  20657. me_to_moz += "M." + my;
  20658. break;
  20659. case "%":
  20660. moz_to_me += "from_moz(M." + moz + ").body";
  20661. me_to_moz += "to_moz_block(M)";
  20662. break;
  20663. default:
  20664. throw new Error("Can't understand operator in propmap: " + prop);
  20665. }
  20666. });
  20667. moz_to_me += "\n})\n}";
  20668. me_to_moz += "\n}\n}";
  20669. //moz_to_me = parse(moz_to_me).print_to_string({ beautify: true });
  20670. //me_to_moz = parse(me_to_moz).print_to_string({ beautify: true });
  20671. //console.log(moz_to_me);
  20672. moz_to_me = new Function("U2", "my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
  20673. ast, my_start_token, my_end_token, from_moz
  20674. );
  20675. me_to_moz = new Function("to_moz", "to_moz_block", "to_moz_scope", "return(" + me_to_moz + ")")(
  20676. to_moz, to_moz_block, to_moz_scope
  20677. );
  20678. MOZ_TO_ME[moztype] = moz_to_me;
  20679. def_to_moz(mytype, me_to_moz);
  20680. }
  20681. var FROM_MOZ_STACK = null;
  20682. function from_moz(node) {
  20683. FROM_MOZ_STACK.push(node);
  20684. var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
  20685. FROM_MOZ_STACK.pop();
  20686. return ret;
  20687. }
  20688. AST_Node.from_mozilla_ast = function(node) {
  20689. var save_stack = FROM_MOZ_STACK;
  20690. FROM_MOZ_STACK = [];
  20691. var ast = from_moz(node);
  20692. FROM_MOZ_STACK = save_stack;
  20693. return ast;
  20694. };
  20695. function set_moz_loc(mynode, moznode, myparent) {
  20696. var start = mynode.start;
  20697. var end = mynode.end;
  20698. if (start.pos != null && end.endpos != null) {
  20699. moznode.range = [start.pos, end.endpos];
  20700. }
  20701. if (start.line) {
  20702. moznode.loc = {
  20703. start: {line: start.line, column: start.col},
  20704. end: end.endline ? {line: end.endline, column: end.endcol} : null
  20705. };
  20706. if (start.file) {
  20707. moznode.loc.source = start.file;
  20708. }
  20709. }
  20710. return moznode;
  20711. }
  20712. function def_to_moz(mytype, handler) {
  20713. mytype.DEFMETHOD("to_mozilla_ast", function(parent) {
  20714. return set_moz_loc(this, handler(this, parent));
  20715. });
  20716. }
  20717. var TO_MOZ_STACK = null;
  20718. function to_moz(node) {
  20719. if (TO_MOZ_STACK === null) { TO_MOZ_STACK = []; }
  20720. TO_MOZ_STACK.push(node);
  20721. var ast = node != null ? node.to_mozilla_ast(TO_MOZ_STACK[TO_MOZ_STACK.length - 2]) : null;
  20722. TO_MOZ_STACK.pop();
  20723. if (TO_MOZ_STACK.length === 0) { TO_MOZ_STACK = null; }
  20724. return ast;
  20725. }
  20726. function to_moz_in_destructuring() {
  20727. var i = TO_MOZ_STACK.length;
  20728. while (i--) {
  20729. if (TO_MOZ_STACK[i] instanceof AST_Destructuring) {
  20730. return true;
  20731. }
  20732. }
  20733. return false;
  20734. }
  20735. function to_moz_block(node) {
  20736. return {
  20737. type: "BlockStatement",
  20738. body: node.body.map(to_moz)
  20739. };
  20740. }
  20741. function to_moz_scope(type, node) {
  20742. var body = node.body.map(to_moz);
  20743. if (node.body[0] instanceof AST_SimpleStatement && node.body[0].body instanceof AST_String) {
  20744. body.unshift(to_moz(new AST_EmptyStatement(node.body[0])));
  20745. }
  20746. return {
  20747. type: type,
  20748. body: body
  20749. };
  20750. }
  20751. })();
  20752. // API
  20753. exports.minify = minify;
  20754. exports.AST_Array = AST_Array;
  20755. exports.AST_Assign = AST_Assign;
  20756. exports.AST_Constant = AST_Constant;
  20757. exports.AST_Node = AST_Node;
  20758. exports.AST_PropAccess = AST_PropAccess;
  20759. exports.AST_Sequence = AST_Sequence;
  20760. exports.AST_Symbol = AST_Symbol;
  20761. exports.AST_Token = AST_Token;
  20762. exports.TreeTransformer = TreeTransformer;
  20763. exports.TreeWalker = TreeWalker;
  20764. exports.defaults = defaults;
  20765. exports.Dictionary = Dictionary;
  20766. exports.push_uniq = push_uniq;
  20767. exports.string_template = string_template;
  20768. exports.base54 = base54;
  20769. exports.Compressor = Compressor;
  20770. exports.OutputStream = OutputStream;
  20771. exports.parse = parse;
  20772. exports.mangle_properties = mangle_properties;
  20773. exports.reserve_quoted_keys = reserve_quoted_keys;
  20774. exports.JS_Parse_Error = JS_Parse_Error;
  20775. exports.tokenizer = tokenizer;
  20776. exports.to_ascii = to_ascii;
  20777. exports.AST_Accessor = AST_Accessor;
  20778. exports.AST_Arrow = AST_Arrow;
  20779. exports.AST_Atom = AST_Atom;
  20780. exports.AST_Await = AST_Await;
  20781. exports.AST_Binary = AST_Binary;
  20782. exports.AST_Block = AST_Block;
  20783. exports.AST_BlockStatement = AST_BlockStatement;
  20784. exports.AST_Boolean = AST_Boolean;
  20785. exports.AST_Break = AST_Break;
  20786. exports.AST_Call = AST_Call;
  20787. exports.AST_Case = AST_Case;
  20788. exports.AST_Catch = AST_Catch;
  20789. exports.AST_Class = AST_Class;
  20790. exports.AST_ClassExpression = AST_ClassExpression;
  20791. exports.AST_ConciseMethod = AST_ConciseMethod;
  20792. exports.AST_Conditional = AST_Conditional;
  20793. exports.AST_Const = AST_Const;
  20794. exports.AST_Continue = AST_Continue;
  20795. exports.AST_Debugger = AST_Debugger;
  20796. exports.AST_Default = AST_Default;
  20797. exports.AST_DefaultAssign = AST_DefaultAssign;
  20798. exports.AST_DefClass = AST_DefClass;
  20799. exports.AST_Definitions = AST_Definitions;
  20800. exports.AST_Defun = AST_Defun;
  20801. exports.AST_Destructuring = AST_Destructuring;
  20802. exports.AST_Directive = AST_Directive;
  20803. exports.AST_Do = AST_Do;
  20804. exports.AST_Dot = AST_Dot;
  20805. exports.AST_DWLoop = AST_DWLoop;
  20806. exports.AST_EmptyStatement = AST_EmptyStatement;
  20807. exports.AST_Exit = AST_Exit;
  20808. exports.AST_Expansion = AST_Expansion;
  20809. exports.AST_Export = AST_Export;
  20810. exports.AST_False = AST_False;
  20811. exports.AST_Finally = AST_Finally;
  20812. exports.AST_For = AST_For;
  20813. exports.AST_ForIn = AST_ForIn;
  20814. exports.AST_ForOf = AST_ForOf;
  20815. exports.AST_Function = AST_Function;
  20816. exports.AST_Hole = AST_Hole;
  20817. exports.AST_If = AST_If;
  20818. exports.AST_Import = AST_Import;
  20819. exports.AST_Infinity = AST_Infinity;
  20820. exports.AST_IterationStatement = AST_IterationStatement;
  20821. exports.AST_Jump = AST_Jump;
  20822. exports.AST_Label = AST_Label;
  20823. exports.AST_LabeledStatement = AST_LabeledStatement;
  20824. exports.AST_LabelRef = AST_LabelRef;
  20825. exports.AST_Lambda = AST_Lambda;
  20826. exports.AST_Let = AST_Let;
  20827. exports.AST_LoopControl = AST_LoopControl;
  20828. exports.AST_NameMapping = AST_NameMapping;
  20829. exports.AST_NaN = AST_NaN;
  20830. exports.AST_New = AST_New;
  20831. exports.AST_NewTarget = AST_NewTarget;
  20832. exports.AST_Null = AST_Null;
  20833. exports.AST_Number = AST_Number;
  20834. exports.AST_Object = AST_Object;
  20835. exports.AST_ObjectGetter = AST_ObjectGetter;
  20836. exports.AST_ObjectKeyVal = AST_ObjectKeyVal;
  20837. exports.AST_ObjectProperty = AST_ObjectProperty;
  20838. exports.AST_ObjectSetter = AST_ObjectSetter;
  20839. exports.AST_PrefixedTemplateString = AST_PrefixedTemplateString;
  20840. exports.AST_RegExp = AST_RegExp;
  20841. exports.AST_Return = AST_Return;
  20842. exports.AST_Scope = AST_Scope;
  20843. exports.AST_SimpleStatement = AST_SimpleStatement;
  20844. exports.AST_Statement = AST_Statement;
  20845. exports.AST_StatementWithBody = AST_StatementWithBody;
  20846. exports.AST_String = AST_String;
  20847. exports.AST_Sub = AST_Sub;
  20848. exports.AST_Super = AST_Super;
  20849. exports.AST_Switch = AST_Switch;
  20850. exports.AST_SwitchBranch = AST_SwitchBranch;
  20851. exports.AST_SymbolBlockDeclaration = AST_SymbolBlockDeclaration;
  20852. exports.AST_SymbolCatch = AST_SymbolCatch;
  20853. exports.AST_SymbolClass = AST_SymbolClass;
  20854. exports.AST_SymbolConst = AST_SymbolConst;
  20855. exports.AST_SymbolDeclaration = AST_SymbolDeclaration;
  20856. exports.AST_SymbolDefClass = AST_SymbolDefClass;
  20857. exports.AST_SymbolDefun = AST_SymbolDefun;
  20858. exports.AST_SymbolExport = AST_SymbolExport;
  20859. exports.AST_SymbolExportForeign = AST_SymbolExportForeign;
  20860. exports.AST_SymbolFunarg = AST_SymbolFunarg;
  20861. exports.AST_SymbolImport = AST_SymbolImport;
  20862. exports.AST_SymbolImportForeign = AST_SymbolImportForeign;
  20863. exports.AST_SymbolLambda = AST_SymbolLambda;
  20864. exports.AST_SymbolLet = AST_SymbolLet;
  20865. exports.AST_SymbolMethod = AST_SymbolMethod;
  20866. exports.AST_SymbolRef = AST_SymbolRef;
  20867. exports.AST_SymbolVar = AST_SymbolVar;
  20868. exports.AST_TemplateSegment = AST_TemplateSegment;
  20869. exports.AST_TemplateString = AST_TemplateString;
  20870. exports.AST_This = AST_This;
  20871. exports.AST_Throw = AST_Throw;
  20872. exports.AST_Toplevel = AST_Toplevel;
  20873. exports.AST_True = AST_True;
  20874. exports.AST_Try = AST_Try;
  20875. exports.AST_Unary = AST_Unary;
  20876. exports.AST_UnaryPostfix = AST_UnaryPostfix;
  20877. exports.AST_UnaryPrefix = AST_UnaryPrefix;
  20878. exports.AST_Undefined = AST_Undefined;
  20879. exports.AST_Var = AST_Var;
  20880. exports.AST_VarDef = AST_VarDef;
  20881. exports.AST_While = AST_While;
  20882. exports.AST_With = AST_With;
  20883. exports.AST_Yield = AST_Yield;
  20884. exports.walk_body = walk_body;
  20885. }));
  20886. //# sourceMappingURL=bundle.js.map