a zip code crypto-currency system good for red ONLY

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. /***********************************************************************
  2. A JavaScript tokenizer / parser / beautifier / compressor.
  3. https://github.com/mishoo/UglifyJS2
  4. -------------------------------- (C) ---------------------------------
  5. Author: Mihai Bazon
  6. <mihai.bazon@gmail.com>
  7. http://mihai.bazon.net/blog
  8. Distributed under the BSD license:
  9. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions
  12. are met:
  13. * Redistributions of source code must retain the above
  14. copyright notice, this list of conditions and the following
  15. disclaimer.
  16. * Redistributions in binary form must reproduce the above
  17. copyright notice, this list of conditions and the following
  18. disclaimer in the documentation and/or other materials
  19. provided with the distribution.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
  21. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  25. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  29. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. SUCH DAMAGE.
  32. ***********************************************************************/
  33. "use strict";
  34. function DEFNODE(type, props, methods, base) {
  35. if (arguments.length < 4) base = AST_Node;
  36. if (!props) props = [];
  37. else props = props.split(/\s+/);
  38. var self_props = props;
  39. if (base && base.PROPS)
  40. props = props.concat(base.PROPS);
  41. var code = "return function AST_" + type + "(props){ if (props) { ";
  42. for (var i = props.length; --i >= 0;) {
  43. code += "this." + props[i] + " = props." + props[i] + ";";
  44. }
  45. var proto = base && new base;
  46. if (proto && proto.initialize || (methods && methods.initialize))
  47. code += "this.initialize();";
  48. code += "}}";
  49. var ctor = new Function(code)();
  50. if (proto) {
  51. ctor.prototype = proto;
  52. ctor.BASE = base;
  53. }
  54. if (base) base.SUBCLASSES.push(ctor);
  55. ctor.prototype.CTOR = ctor;
  56. ctor.PROPS = props || null;
  57. ctor.SELF_PROPS = self_props;
  58. ctor.SUBCLASSES = [];
  59. if (type) {
  60. ctor.prototype.TYPE = ctor.TYPE = type;
  61. }
  62. if (methods) for (i in methods) if (HOP(methods, i)) {
  63. if (/^\$/.test(i)) {
  64. ctor[i.substr(1)] = methods[i];
  65. } else {
  66. ctor.prototype[i] = methods[i];
  67. }
  68. }
  69. ctor.DEFMETHOD = function(name, method) {
  70. this.prototype[name] = method;
  71. };
  72. if (typeof exports !== "undefined") {
  73. exports["AST_" + type] = ctor;
  74. }
  75. return ctor;
  76. };
  77. var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before file raw", {
  78. }, null);
  79. var AST_Node = DEFNODE("Node", "start end", {
  80. _clone: function(deep) {
  81. if (deep) {
  82. var self = this.clone();
  83. return self.transform(new TreeTransformer(function(node) {
  84. if (node !== self) {
  85. return node.clone(true);
  86. }
  87. }));
  88. }
  89. return new this.CTOR(this);
  90. },
  91. clone: function(deep) {
  92. return this._clone(deep);
  93. },
  94. $documentation: "Base class of all AST nodes",
  95. $propdoc: {
  96. start: "[AST_Token] The first token of this node",
  97. end: "[AST_Token] The last token of this node"
  98. },
  99. _walk: function(visitor) {
  100. return visitor._visit(this);
  101. },
  102. walk: function(visitor) {
  103. return this._walk(visitor); // not sure the indirection will be any help
  104. }
  105. }, null);
  106. AST_Node.warn_function = null;
  107. AST_Node.warn = function(txt, props) {
  108. if (AST_Node.warn_function)
  109. AST_Node.warn_function(string_template(txt, props));
  110. };
  111. /* -----[ statements ]----- */
  112. var AST_Statement = DEFNODE("Statement", null, {
  113. $documentation: "Base class of all statements",
  114. });
  115. var AST_Debugger = DEFNODE("Debugger", null, {
  116. $documentation: "Represents a debugger statement",
  117. }, AST_Statement);
  118. var AST_Directive = DEFNODE("Directive", "value quote", {
  119. $documentation: "Represents a directive, like \"use strict\";",
  120. $propdoc: {
  121. value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
  122. quote: "[string] the original quote character"
  123. },
  124. }, AST_Statement);
  125. var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
  126. $documentation: "A statement consisting of an expression, i.e. a = 1 + 2",
  127. $propdoc: {
  128. body: "[AST_Node] an expression node (should not be instanceof AST_Statement)"
  129. },
  130. _walk: function(visitor) {
  131. return visitor._visit(this, function(){
  132. this.body._walk(visitor);
  133. });
  134. }
  135. }, AST_Statement);
  136. function walk_body(node, visitor) {
  137. var body = node.body;
  138. if (body instanceof AST_Node) {
  139. body._walk(visitor);
  140. }
  141. else for (var i = 0, len = body.length; i < len; i++) {
  142. body[i]._walk(visitor);
  143. }
  144. };
  145. var AST_Block = DEFNODE("Block", "body", {
  146. $documentation: "A body of statements (usually bracketed)",
  147. $propdoc: {
  148. body: "[AST_Statement*] an array of statements"
  149. },
  150. _walk: function(visitor) {
  151. return visitor._visit(this, function(){
  152. walk_body(this, visitor);
  153. });
  154. }
  155. }, AST_Statement);
  156. var AST_BlockStatement = DEFNODE("BlockStatement", null, {
  157. $documentation: "A block statement",
  158. }, AST_Block);
  159. var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
  160. $documentation: "The empty statement (empty block or simply a semicolon)"
  161. }, AST_Statement);
  162. var AST_StatementWithBody = DEFNODE("StatementWithBody", "body", {
  163. $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`",
  164. $propdoc: {
  165. body: "[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement"
  166. }
  167. }, AST_Statement);
  168. var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
  169. $documentation: "Statement with a label",
  170. $propdoc: {
  171. label: "[AST_Label] a label definition"
  172. },
  173. _walk: function(visitor) {
  174. return visitor._visit(this, function(){
  175. this.label._walk(visitor);
  176. this.body._walk(visitor);
  177. });
  178. },
  179. clone: function(deep) {
  180. var node = this._clone(deep);
  181. if (deep) {
  182. var label = node.label;
  183. var def = this.label;
  184. node.walk(new TreeWalker(function(node) {
  185. if (node instanceof AST_LoopControl
  186. && node.label && node.label.thedef === def) {
  187. node.label.thedef = label;
  188. label.references.push(node);
  189. }
  190. }));
  191. }
  192. return node;
  193. }
  194. }, AST_StatementWithBody);
  195. var AST_IterationStatement = DEFNODE("IterationStatement", null, {
  196. $documentation: "Internal class. All loops inherit from it."
  197. }, AST_StatementWithBody);
  198. var AST_DWLoop = DEFNODE("DWLoop", "condition", {
  199. $documentation: "Base class for do/while statements",
  200. $propdoc: {
  201. condition: "[AST_Node] the loop condition. Should not be instanceof AST_Statement"
  202. }
  203. }, AST_IterationStatement);
  204. var AST_Do = DEFNODE("Do", null, {
  205. $documentation: "A `do` statement",
  206. _walk: function(visitor) {
  207. return visitor._visit(this, function(){
  208. this.body._walk(visitor);
  209. this.condition._walk(visitor);
  210. });
  211. }
  212. }, AST_DWLoop);
  213. var AST_While = DEFNODE("While", null, {
  214. $documentation: "A `while` statement",
  215. _walk: function(visitor) {
  216. return visitor._visit(this, function(){
  217. this.condition._walk(visitor);
  218. this.body._walk(visitor);
  219. });
  220. }
  221. }, AST_DWLoop);
  222. var AST_For = DEFNODE("For", "init condition step", {
  223. $documentation: "A `for` statement",
  224. $propdoc: {
  225. init: "[AST_Node?] the `for` initialization code, or null if empty",
  226. condition: "[AST_Node?] the `for` termination clause, or null if empty",
  227. step: "[AST_Node?] the `for` update clause, or null if empty"
  228. },
  229. _walk: function(visitor) {
  230. return visitor._visit(this, function(){
  231. if (this.init) this.init._walk(visitor);
  232. if (this.condition) this.condition._walk(visitor);
  233. if (this.step) this.step._walk(visitor);
  234. this.body._walk(visitor);
  235. });
  236. }
  237. }, AST_IterationStatement);
  238. var AST_ForIn = DEFNODE("ForIn", "init name object", {
  239. $documentation: "A `for ... in` statement",
  240. $propdoc: {
  241. init: "[AST_Node] the `for/in` initialization code",
  242. name: "[AST_SymbolRef?] the loop variable, only if `init` is AST_Var",
  243. object: "[AST_Node] the object that we're looping through"
  244. },
  245. _walk: function(visitor) {
  246. return visitor._visit(this, function(){
  247. this.init._walk(visitor);
  248. this.object._walk(visitor);
  249. this.body._walk(visitor);
  250. });
  251. }
  252. }, AST_IterationStatement);
  253. var AST_ForOf = DEFNODE("ForOf", null, {
  254. $documentation: "A `for ... of` statement",
  255. }, AST_ForIn);
  256. var AST_With = DEFNODE("With", "expression", {
  257. $documentation: "A `with` statement",
  258. $propdoc: {
  259. expression: "[AST_Node] the `with` expression"
  260. },
  261. _walk: function(visitor) {
  262. return visitor._visit(this, function(){
  263. this.expression._walk(visitor);
  264. this.body._walk(visitor);
  265. });
  266. }
  267. }, AST_StatementWithBody);
  268. /* -----[ scope and functions ]----- */
  269. var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent_scope enclosed cname", {
  270. $documentation: "Base class for all statements introducing a lexical scope",
  271. $propdoc: {
  272. variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope",
  273. functions: "[Object/S] like `variables`, but only lists function declarations",
  274. uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
  275. uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`",
  276. parent_scope: "[AST_Scope?/S] link to the parent scope",
  277. enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
  278. cname: "[integer/S] current index for mangling variables (used internally by the mangler)",
  279. },
  280. get_defun_scope: function() {
  281. var self = this;
  282. while (self.is_block_scope()) {
  283. self = self.parent_scope;
  284. }
  285. return self;
  286. }
  287. }, AST_Block);
  288. var AST_Toplevel = DEFNODE("Toplevel", "globals", {
  289. $documentation: "The toplevel scope",
  290. $propdoc: {
  291. globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
  292. },
  293. wrap_commonjs: function(name) {
  294. var body = this.body;
  295. var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
  296. wrapped_tl = parse(wrapped_tl);
  297. wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node){
  298. if (node instanceof AST_Directive && node.value == "$ORIG") {
  299. return MAP.splice(body);
  300. }
  301. }));
  302. return wrapped_tl;
  303. }
  304. }, AST_Scope);
  305. var AST_Expansion = DEFNODE("Expansion", "expression", {
  306. $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",
  307. $propdoc: {
  308. expression: "[AST_Node] the thing to be expanded"
  309. },
  310. _walk: function(visitor) {
  311. var self = this;
  312. return visitor._visit(this, function(){
  313. self.expression.walk(visitor);
  314. });
  315. }
  316. });
  317. var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator async", {
  318. $documentation: "Base class for functions",
  319. $propdoc: {
  320. name: "[AST_SymbolDeclaration?] the name of this function",
  321. argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding arguments",
  322. uses_arguments: "[boolean/S] tells whether this function accesses the arguments array",
  323. is_generator: "[boolean] is this a generator method",
  324. async: "[boolean] is this method async",
  325. },
  326. args_as_names: function () {
  327. var out = [];
  328. for (var i = 0; i < this.argnames.length; i++) {
  329. if (this.argnames[i] instanceof AST_Destructuring) {
  330. out = out.concat(this.argnames[i].all_symbols());
  331. } else {
  332. out.push(this.argnames[i]);
  333. }
  334. }
  335. return out;
  336. },
  337. _walk: function(visitor) {
  338. return visitor._visit(this, function(){
  339. if (this.name) this.name._walk(visitor);
  340. var argnames = this.argnames;
  341. for (var i = 0, len = argnames.length; i < len; i++) {
  342. argnames[i]._walk(visitor);
  343. }
  344. walk_body(this, visitor);
  345. });
  346. }
  347. }, AST_Scope);
  348. var AST_Accessor = DEFNODE("Accessor", null, {
  349. $documentation: "A setter/getter function. The `name` property is always null."
  350. }, AST_Lambda);
  351. var AST_Function = DEFNODE("Function", "inlined", {
  352. $documentation: "A function expression"
  353. }, AST_Lambda);
  354. var AST_Arrow = DEFNODE("Arrow", "inlined", {
  355. $documentation: "An ES6 Arrow function ((a) => b)"
  356. }, AST_Lambda);
  357. var AST_Defun = DEFNODE("Defun", "inlined", {
  358. $documentation: "A function definition"
  359. }, AST_Lambda);
  360. /* -----[ DESTRUCTURING ]----- */
  361. var AST_Destructuring = DEFNODE("Destructuring", "names is_array", {
  362. $documentation: "A destructuring of several names. Used in destructuring assignment and with destructuring function argument names",
  363. $propdoc: {
  364. "names": "[AST_Node*] Array of properties or elements",
  365. "is_array": "[Boolean] Whether the destructuring represents an object or array"
  366. },
  367. _walk: function(visitor) {
  368. return visitor._visit(this, function(){
  369. this.names.forEach(function(name){
  370. name._walk(visitor);
  371. });
  372. });
  373. },
  374. all_symbols: function() {
  375. var out = [];
  376. this.walk(new TreeWalker(function (node) {
  377. if (node instanceof AST_Symbol) {
  378. out.push(node);
  379. }
  380. if (node instanceof AST_Expansion) {
  381. out.push(node.expression);
  382. }
  383. }));
  384. return out;
  385. }
  386. });
  387. var AST_PrefixedTemplateString = DEFNODE("PrefixedTemplateString", "template_string prefix", {
  388. $documentation: "A templatestring with a prefix, such as String.raw`foobarbaz`",
  389. $propdoc: {
  390. template_string: "[AST_TemplateString] The template string",
  391. prefix: "[AST_SymbolRef|AST_PropAccess] The prefix, which can be a symbol such as `foo` or a dotted expression such as `String.raw`."
  392. },
  393. _walk: function(visitor) {
  394. this.prefix._walk(visitor);
  395. this.template_string._walk(visitor);
  396. }
  397. })
  398. var AST_TemplateString = DEFNODE("TemplateString", "segments", {
  399. $documentation: "A template string literal",
  400. $propdoc: {
  401. 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."
  402. },
  403. _walk: function(visitor) {
  404. return visitor._visit(this, function(){
  405. this.segments.forEach(function(seg){
  406. seg._walk(visitor);
  407. });
  408. });
  409. }
  410. });
  411. var AST_TemplateSegment = DEFNODE("TemplateSegment", "value raw", {
  412. $documentation: "A segment of a template string literal",
  413. $propdoc: {
  414. value: "Content of the segment",
  415. raw: "Raw content of the segment"
  416. }
  417. });
  418. /* -----[ JUMPS ]----- */
  419. var AST_Jump = DEFNODE("Jump", null, {
  420. $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"
  421. }, AST_Statement);
  422. var AST_Exit = DEFNODE("Exit", "value", {
  423. $documentation: "Base class for “exits” (`return` and `throw`)",
  424. $propdoc: {
  425. value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"
  426. },
  427. _walk: function(visitor) {
  428. return visitor._visit(this, this.value && function(){
  429. this.value._walk(visitor);
  430. });
  431. }
  432. }, AST_Jump);
  433. var AST_Return = DEFNODE("Return", null, {
  434. $documentation: "A `return` statement"
  435. }, AST_Exit);
  436. var AST_Throw = DEFNODE("Throw", null, {
  437. $documentation: "A `throw` statement"
  438. }, AST_Exit);
  439. var AST_LoopControl = DEFNODE("LoopControl", "label", {
  440. $documentation: "Base class for loop control statements (`break` and `continue`)",
  441. $propdoc: {
  442. label: "[AST_LabelRef?] the label, or null if none",
  443. },
  444. _walk: function(visitor) {
  445. return visitor._visit(this, this.label && function(){
  446. this.label._walk(visitor);
  447. });
  448. }
  449. }, AST_Jump);
  450. var AST_Break = DEFNODE("Break", null, {
  451. $documentation: "A `break` statement"
  452. }, AST_LoopControl);
  453. var AST_Continue = DEFNODE("Continue", null, {
  454. $documentation: "A `continue` statement"
  455. }, AST_LoopControl);
  456. /* -----[ IF ]----- */
  457. var AST_If = DEFNODE("If", "condition alternative", {
  458. $documentation: "A `if` statement",
  459. $propdoc: {
  460. condition: "[AST_Node] the `if` condition",
  461. alternative: "[AST_Statement?] the `else` part, or null if not present"
  462. },
  463. _walk: function(visitor) {
  464. return visitor._visit(this, function(){
  465. this.condition._walk(visitor);
  466. this.body._walk(visitor);
  467. if (this.alternative) this.alternative._walk(visitor);
  468. });
  469. }
  470. }, AST_StatementWithBody);
  471. /* -----[ SWITCH ]----- */
  472. var AST_Switch = DEFNODE("Switch", "expression", {
  473. $documentation: "A `switch` statement",
  474. $propdoc: {
  475. expression: "[AST_Node] the `switch` “discriminant”"
  476. },
  477. _walk: function(visitor) {
  478. return visitor._visit(this, function(){
  479. this.expression._walk(visitor);
  480. walk_body(this, visitor);
  481. });
  482. }
  483. }, AST_Block);
  484. var AST_SwitchBranch = DEFNODE("SwitchBranch", null, {
  485. $documentation: "Base class for `switch` branches",
  486. }, AST_Block);
  487. var AST_Default = DEFNODE("Default", null, {
  488. $documentation: "A `default` switch branch",
  489. }, AST_SwitchBranch);
  490. var AST_Case = DEFNODE("Case", "expression", {
  491. $documentation: "A `case` switch branch",
  492. $propdoc: {
  493. expression: "[AST_Node] the `case` expression"
  494. },
  495. _walk: function(visitor) {
  496. return visitor._visit(this, function(){
  497. this.expression._walk(visitor);
  498. walk_body(this, visitor);
  499. });
  500. }
  501. }, AST_SwitchBranch);
  502. /* -----[ EXCEPTIONS ]----- */
  503. var AST_Try = DEFNODE("Try", "bcatch bfinally", {
  504. $documentation: "A `try` statement",
  505. $propdoc: {
  506. bcatch: "[AST_Catch?] the catch block, or null if not present",
  507. bfinally: "[AST_Finally?] the finally block, or null if not present"
  508. },
  509. _walk: function(visitor) {
  510. return visitor._visit(this, function(){
  511. walk_body(this, visitor);
  512. if (this.bcatch) this.bcatch._walk(visitor);
  513. if (this.bfinally) this.bfinally._walk(visitor);
  514. });
  515. }
  516. }, AST_Block);
  517. var AST_Catch = DEFNODE("Catch", "argname", {
  518. $documentation: "A `catch` node; only makes sense as part of a `try` statement",
  519. $propdoc: {
  520. argname: "[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception"
  521. },
  522. _walk: function(visitor) {
  523. return visitor._visit(this, function(){
  524. this.argname._walk(visitor);
  525. walk_body(this, visitor);
  526. });
  527. }
  528. }, AST_Block);
  529. var AST_Finally = DEFNODE("Finally", null, {
  530. $documentation: "A `finally` node; only makes sense as part of a `try` statement"
  531. }, AST_Block);
  532. /* -----[ VAR/CONST ]----- */
  533. var AST_Definitions = DEFNODE("Definitions", "definitions", {
  534. $documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)",
  535. $propdoc: {
  536. definitions: "[AST_VarDef*] array of variable definitions"
  537. },
  538. _walk: function(visitor) {
  539. return visitor._visit(this, function(){
  540. var definitions = this.definitions;
  541. for (var i = 0, len = definitions.length; i < len; i++) {
  542. definitions[i]._walk(visitor);
  543. }
  544. });
  545. }
  546. }, AST_Statement);
  547. var AST_Var = DEFNODE("Var", null, {
  548. $documentation: "A `var` statement"
  549. }, AST_Definitions);
  550. var AST_Let = DEFNODE("Let", null, {
  551. $documentation: "A `let` statement"
  552. }, AST_Definitions);
  553. var AST_Const = DEFNODE("Const", null, {
  554. $documentation: "A `const` statement"
  555. }, AST_Definitions);
  556. var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", {
  557. $documentation: "The part of the export/import statement that declare names from a module.",
  558. $propdoc: {
  559. foreign_name: "[AST_SymbolExportForeign|AST_SymbolImportForeign] The name being exported/imported (as specified in the module)",
  560. name: "[AST_SymbolExport|AST_SymbolImport] The name as it is visible to this module."
  561. },
  562. _walk: function (visitor) {
  563. return visitor._visit(this, function() {
  564. this.foreign_name._walk(visitor);
  565. this.name._walk(visitor);
  566. });
  567. }
  568. })
  569. var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {
  570. $documentation: "An `import` statement",
  571. $propdoc: {
  572. imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
  573. imported_names: "[AST_NameMapping*] The names of non-default imported variables",
  574. module_name: "[AST_String] String literal describing where this module came from",
  575. },
  576. _walk: function(visitor) {
  577. return visitor._visit(this, function() {
  578. if (this.imported_name) {
  579. this.imported_name._walk(visitor);
  580. }
  581. if (this.imported_names) {
  582. this.imported_names.forEach(function(name_import) {
  583. name_import._walk(visitor);
  584. });
  585. }
  586. this.module_name._walk(visitor);
  587. });
  588. }
  589. });
  590. var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name", {
  591. $documentation: "An `export` statement",
  592. $propdoc: {
  593. exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition",
  594. exported_value: "[AST_Node?] An exported value",
  595. exported_names: "[AST_NameMapping*?] List of exported names",
  596. module_name: "[AST_String?] Name of the file to load exports from",
  597. is_default: "[Boolean] Whether this is the default exported value of this module"
  598. },
  599. _walk: function (visitor) {
  600. visitor._visit(this, function () {
  601. if (this.exported_definition) {
  602. this.exported_definition._walk(visitor);
  603. }
  604. if (this.exported_value) {
  605. this.exported_value._walk(visitor);
  606. }
  607. if (this.exported_names) {
  608. this.exported_names.forEach(function(name_export) {
  609. name_export._walk(visitor);
  610. });
  611. }
  612. if (this.module_name) {
  613. this.module_name._walk(visitor);
  614. }
  615. });
  616. }
  617. }, AST_Statement);
  618. var AST_VarDef = DEFNODE("VarDef", "name value", {
  619. $documentation: "A variable declaration; only appears in a AST_Definitions node",
  620. $propdoc: {
  621. name: "[AST_Destructuring|AST_SymbolConst|AST_SymbolLet|AST_SymbolVar] name of the variable",
  622. value: "[AST_Node?] initializer, or null of there's no initializer"
  623. },
  624. _walk: function(visitor) {
  625. return visitor._visit(this, function(){
  626. this.name._walk(visitor);
  627. if (this.value) this.value._walk(visitor);
  628. });
  629. }
  630. });
  631. /* -----[ OTHER ]----- */
  632. var AST_Call = DEFNODE("Call", "expression args", {
  633. $documentation: "A function call expression",
  634. $propdoc: {
  635. expression: "[AST_Node] expression to invoke as function",
  636. args: "[AST_Node*] array of arguments"
  637. },
  638. _walk: function(visitor) {
  639. return visitor._visit(this, function(){
  640. var args = this.args;
  641. for (var i = 0, len = args.length; i < len; i++) {
  642. args[i]._walk(visitor);
  643. }
  644. this.expression._walk(visitor);
  645. });
  646. }
  647. });
  648. var AST_New = DEFNODE("New", null, {
  649. $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties"
  650. }, AST_Call);
  651. var AST_Sequence = DEFNODE("Sequence", "expressions", {
  652. $documentation: "A sequence expression (comma-separated expressions)",
  653. $propdoc: {
  654. expressions: "[AST_Node*] array of expressions (at least two)"
  655. },
  656. _walk: function(visitor) {
  657. return visitor._visit(this, function(){
  658. this.expressions.forEach(function(node) {
  659. node._walk(visitor);
  660. });
  661. });
  662. }
  663. });
  664. var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
  665. $documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`",
  666. $propdoc: {
  667. expression: "[AST_Node] the “container” expression",
  668. 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"
  669. }
  670. });
  671. var AST_Dot = DEFNODE("Dot", null, {
  672. $documentation: "A dotted property access expression",
  673. _walk: function(visitor) {
  674. return visitor._visit(this, function(){
  675. this.expression._walk(visitor);
  676. });
  677. }
  678. }, AST_PropAccess);
  679. var AST_Sub = DEFNODE("Sub", null, {
  680. $documentation: "Index-style property access, i.e. `a[\"foo\"]`",
  681. _walk: function(visitor) {
  682. return visitor._visit(this, function(){
  683. this.expression._walk(visitor);
  684. this.property._walk(visitor);
  685. });
  686. }
  687. }, AST_PropAccess);
  688. var AST_Unary = DEFNODE("Unary", "operator expression", {
  689. $documentation: "Base class for unary expressions",
  690. $propdoc: {
  691. operator: "[string] the operator",
  692. expression: "[AST_Node] expression that this unary operator applies to"
  693. },
  694. _walk: function(visitor) {
  695. return visitor._visit(this, function(){
  696. this.expression._walk(visitor);
  697. });
  698. }
  699. });
  700. var AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, {
  701. $documentation: "Unary prefix expression, i.e. `typeof i` or `++i`"
  702. }, AST_Unary);
  703. var AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, {
  704. $documentation: "Unary postfix expression, i.e. `i++`"
  705. }, AST_Unary);
  706. var AST_Binary = DEFNODE("Binary", "operator left right", {
  707. $documentation: "Binary expression, i.e. `a + b`",
  708. $propdoc: {
  709. left: "[AST_Node] left-hand side expression",
  710. operator: "[string] the operator",
  711. right: "[AST_Node] right-hand side expression"
  712. },
  713. _walk: function(visitor) {
  714. return visitor._visit(this, function(){
  715. this.left._walk(visitor);
  716. this.right._walk(visitor);
  717. });
  718. }
  719. });
  720. var AST_Conditional = DEFNODE("Conditional", "condition consequent alternative", {
  721. $documentation: "Conditional expression using the ternary operator, i.e. `a ? b : c`",
  722. $propdoc: {
  723. condition: "[AST_Node]",
  724. consequent: "[AST_Node]",
  725. alternative: "[AST_Node]"
  726. },
  727. _walk: function(visitor) {
  728. return visitor._visit(this, function(){
  729. this.condition._walk(visitor);
  730. this.consequent._walk(visitor);
  731. this.alternative._walk(visitor);
  732. });
  733. }
  734. });
  735. var AST_Assign = DEFNODE("Assign", null, {
  736. $documentation: "An assignment expression — `a = b + 5`",
  737. }, AST_Binary);
  738. var AST_DefaultAssign = DEFNODE("DefaultAssign", null, {
  739. $documentation: "A default assignment expression like in `(a = 3) => a`"
  740. }, AST_Binary);
  741. /* -----[ LITERALS ]----- */
  742. var AST_Array = DEFNODE("Array", "elements", {
  743. $documentation: "An array literal",
  744. $propdoc: {
  745. elements: "[AST_Node*] array of elements"
  746. },
  747. _walk: function(visitor) {
  748. return visitor._visit(this, function(){
  749. var elements = this.elements;
  750. for (var i = 0, len = elements.length; i < len; i++) {
  751. elements[i]._walk(visitor);
  752. }
  753. });
  754. }
  755. });
  756. var AST_Object = DEFNODE("Object", "properties", {
  757. $documentation: "An object literal",
  758. $propdoc: {
  759. properties: "[AST_ObjectProperty*] array of properties"
  760. },
  761. _walk: function(visitor) {
  762. return visitor._visit(this, function(){
  763. var properties = this.properties;
  764. for (var i = 0, len = properties.length; i < len; i++) {
  765. properties[i]._walk(visitor);
  766. }
  767. });
  768. }
  769. });
  770. var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
  771. $documentation: "Base class for literal object properties",
  772. $propdoc: {
  773. key: "[string|AST_Node] the property name converted to a string for ObjectKeyVal. For setters, getters and computed property this is an arbitrary AST_Node",
  774. value: "[AST_Node] property value. For setters and getters this is an AST_Accessor."
  775. },
  776. _walk: function(visitor) {
  777. return visitor._visit(this, function(){
  778. if (this.key instanceof AST_Node)
  779. this.key._walk(visitor);
  780. this.value._walk(visitor);
  781. });
  782. }
  783. });
  784. var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
  785. $documentation: "A key: value object property",
  786. $propdoc: {
  787. quote: "[string] the original quote character"
  788. }
  789. }, AST_ObjectProperty);
  790. var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", {
  791. $propdoc: {
  792. quote: "[string|undefined] the original quote character, if any",
  793. static: "[boolean] whether this is a static setter (classes only)"
  794. },
  795. $documentation: "An object setter property",
  796. }, AST_ObjectProperty);
  797. var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", {
  798. $propdoc: {
  799. quote: "[string|undefined] the original quote character, if any",
  800. static: "[boolean] whether this is a static getter (classes only)"
  801. },
  802. $documentation: "An object getter property",
  803. }, AST_ObjectProperty);
  804. var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator async", {
  805. $propdoc: {
  806. quote: "[string|undefined] the original quote character, if any",
  807. static: "[boolean] is this method static (classes only)",
  808. is_generator: "[boolean] is this a generator method",
  809. async: "[boolean] is this method async",
  810. },
  811. $documentation: "An ES6 concise method inside an object or class"
  812. }, AST_ObjectProperty);
  813. var AST_Class = DEFNODE("Class", "name extends properties inlined", {
  814. $propdoc: {
  815. name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
  816. extends: "[AST_Node]? optional parent class",
  817. properties: "[AST_ObjectProperty*] array of properties"
  818. },
  819. $documentation: "An ES6 class",
  820. _walk: function(visitor) {
  821. return visitor._visit(this, function(){
  822. if (this.name) {
  823. this.name._walk(visitor);
  824. }
  825. if (this.extends) {
  826. this.extends._walk(visitor);
  827. }
  828. this.properties.forEach(function(prop){
  829. prop._walk(visitor);
  830. });
  831. });
  832. },
  833. }, AST_Scope);
  834. var AST_DefClass = DEFNODE("DefClass", null, {
  835. $documentation: "A class definition",
  836. }, AST_Class);
  837. var AST_ClassExpression = DEFNODE("ClassExpression", null, {
  838. $documentation: "A class expression."
  839. }, AST_Class);
  840. var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
  841. $propdoc: {
  842. name: "[string] name of this symbol",
  843. scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
  844. thedef: "[SymbolDef/S] the definition of this symbol"
  845. },
  846. $documentation: "Base class for all symbols"
  847. });
  848. var AST_NewTarget = DEFNODE("NewTarget", null, {
  849. $documentation: "A reference to new.target"
  850. });
  851. var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
  852. $documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
  853. }, AST_Symbol);
  854. var AST_SymbolVar = DEFNODE("SymbolVar", null, {
  855. $documentation: "Symbol defining a variable",
  856. }, AST_SymbolDeclaration);
  857. var AST_SymbolBlockDeclaration = DEFNODE("SymbolBlockDeclaration", null, {
  858. $documentation: "Base class for block-scoped declaration symbols"
  859. }, AST_SymbolDeclaration);
  860. var AST_SymbolConst = DEFNODE("SymbolConst", null, {
  861. $documentation: "A constant declaration"
  862. }, AST_SymbolBlockDeclaration);
  863. var AST_SymbolLet = DEFNODE("SymbolLet", null, {
  864. $documentation: "A block-scoped `let` declaration"
  865. }, AST_SymbolBlockDeclaration);
  866. var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {
  867. $documentation: "Symbol naming a function argument",
  868. }, AST_SymbolVar);
  869. var AST_SymbolDefun = DEFNODE("SymbolDefun", null, {
  870. $documentation: "Symbol defining a function",
  871. }, AST_SymbolDeclaration);
  872. var AST_SymbolMethod = DEFNODE("SymbolMethod", null, {
  873. $documentation: "Symbol in an object defining a method",
  874. }, AST_Symbol);
  875. var AST_SymbolLambda = DEFNODE("SymbolLambda", null, {
  876. $documentation: "Symbol naming a function expression",
  877. }, AST_SymbolDeclaration);
  878. var AST_SymbolDefClass = DEFNODE("SymbolDefClass", null, {
  879. $documentation: "Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class."
  880. }, AST_SymbolBlockDeclaration);
  881. var AST_SymbolClass = DEFNODE("SymbolClass", null, {
  882. $documentation: "Symbol naming a class's name. Lexically scoped to the class."
  883. }, AST_SymbolDeclaration);
  884. var AST_SymbolCatch = DEFNODE("SymbolCatch", null, {
  885. $documentation: "Symbol naming the exception in catch",
  886. }, AST_SymbolBlockDeclaration);
  887. var AST_SymbolImport = DEFNODE("SymbolImport", null, {
  888. $documentation: "Symbol referring to an imported name",
  889. }, AST_SymbolBlockDeclaration);
  890. var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, {
  891. $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",
  892. }, AST_Symbol);
  893. var AST_Label = DEFNODE("Label", "references", {
  894. $documentation: "Symbol naming a label (declaration)",
  895. $propdoc: {
  896. references: "[AST_LoopControl*] a list of nodes referring to this label"
  897. },
  898. initialize: function() {
  899. this.references = [];
  900. this.thedef = this;
  901. }
  902. }, AST_Symbol);
  903. var AST_SymbolRef = DEFNODE("SymbolRef", null, {
  904. $documentation: "Reference to some symbol (not definition/declaration)",
  905. }, AST_Symbol);
  906. var AST_SymbolExport = DEFNODE("SymbolExport", null, {
  907. $documentation: "Symbol referring to a name to export",
  908. }, AST_SymbolRef);
  909. var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, {
  910. $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",
  911. }, AST_Symbol);
  912. var AST_LabelRef = DEFNODE("LabelRef", null, {
  913. $documentation: "Reference to a label symbol",
  914. }, AST_Symbol);
  915. var AST_This = DEFNODE("This", null, {
  916. $documentation: "The `this` symbol",
  917. }, AST_Symbol);
  918. var AST_Super = DEFNODE("Super", null, {
  919. $documentation: "The `super` symbol",
  920. }, AST_This);
  921. var AST_Constant = DEFNODE("Constant", null, {
  922. $documentation: "Base class for all constants",
  923. getValue: function() {
  924. return this.value;
  925. }
  926. });
  927. var AST_String = DEFNODE("String", "value quote", {
  928. $documentation: "A string literal",
  929. $propdoc: {
  930. value: "[string] the contents of this string",
  931. quote: "[string] the original quote character"
  932. }
  933. }, AST_Constant);
  934. var AST_Number = DEFNODE("Number", "value literal", {
  935. $documentation: "A number literal",
  936. $propdoc: {
  937. value: "[number] the numeric value",
  938. literal: "[string] numeric value as string (optional)"
  939. }
  940. }, AST_Constant);
  941. var AST_RegExp = DEFNODE("RegExp", "value", {
  942. $documentation: "A regexp literal",
  943. $propdoc: {
  944. value: "[RegExp] the actual regexp"
  945. }
  946. }, AST_Constant);
  947. var AST_Atom = DEFNODE("Atom", null, {
  948. $documentation: "Base class for atoms",
  949. }, AST_Constant);
  950. var AST_Null = DEFNODE("Null", null, {
  951. $documentation: "The `null` atom",
  952. value: null
  953. }, AST_Atom);
  954. var AST_NaN = DEFNODE("NaN", null, {
  955. $documentation: "The impossible value",
  956. value: 0/0
  957. }, AST_Atom);
  958. var AST_Undefined = DEFNODE("Undefined", null, {
  959. $documentation: "The `undefined` value",
  960. value: (function(){}())
  961. }, AST_Atom);
  962. var AST_Hole = DEFNODE("Hole", null, {
  963. $documentation: "A hole in an array",
  964. value: (function(){}())
  965. }, AST_Atom);
  966. var AST_Infinity = DEFNODE("Infinity", null, {
  967. $documentation: "The `Infinity` value",
  968. value: 1/0
  969. }, AST_Atom);
  970. var AST_Boolean = DEFNODE("Boolean", null, {
  971. $documentation: "Base class for booleans",
  972. }, AST_Atom);
  973. var AST_False = DEFNODE("False", null, {
  974. $documentation: "The `false` atom",
  975. value: false
  976. }, AST_Boolean);
  977. var AST_True = DEFNODE("True", null, {
  978. $documentation: "The `true` atom",
  979. value: true
  980. }, AST_Boolean);
  981. var AST_Await = DEFNODE("Await", "expression", {
  982. $documentation: "An `await` statement",
  983. $propdoc: {
  984. expression: "[AST_Node] the mandatory expression being awaited",
  985. },
  986. _walk: function(visitor) {
  987. return visitor._visit(this, function(){
  988. this.expression._walk(visitor);
  989. });
  990. }
  991. });
  992. var AST_Yield = DEFNODE("Yield", "expression is_star", {
  993. $documentation: "A `yield` statement",
  994. $propdoc: {
  995. 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",
  996. is_star: "[Boolean] Whether this is a yield or yield* statement"
  997. },
  998. _walk: function(visitor) {
  999. return visitor._visit(this, this.expression && function(){
  1000. this.expression._walk(visitor);
  1001. });
  1002. }
  1003. });
  1004. /* -----[ TreeWalker ]----- */
  1005. function TreeWalker(callback) {
  1006. this.visit = callback;
  1007. this.stack = [];
  1008. this.directives = Object.create(null);
  1009. };
  1010. TreeWalker.prototype = {
  1011. _visit: function(node, descend) {
  1012. this.push(node);
  1013. var ret = this.visit(node, descend ? function(){
  1014. descend.call(node);
  1015. } : noop);
  1016. if (!ret && descend) {
  1017. descend.call(node);
  1018. }
  1019. this.pop();
  1020. return ret;
  1021. },
  1022. parent: function(n) {
  1023. return this.stack[this.stack.length - 2 - (n || 0)];
  1024. },
  1025. push: function(node) {
  1026. if (node instanceof AST_Lambda) {
  1027. this.directives = Object.create(this.directives);
  1028. } else if (node instanceof AST_Directive && !this.directives[node.value]) {
  1029. this.directives[node.value] = node;
  1030. } else if (node instanceof AST_Class) {
  1031. this.directives = Object.create(this.directives);
  1032. if (!this.directives["use strict"]) {
  1033. this.directives["use strict"] = node;
  1034. }
  1035. }
  1036. this.stack.push(node);
  1037. },
  1038. pop: function() {
  1039. var node = this.stack.pop();
  1040. if (node instanceof AST_Lambda || node instanceof AST_Class) {
  1041. this.directives = Object.getPrototypeOf(this.directives);
  1042. }
  1043. },
  1044. self: function() {
  1045. return this.stack[this.stack.length - 1];
  1046. },
  1047. find_parent: function(type) {
  1048. var stack = this.stack;
  1049. for (var i = stack.length; --i >= 0;) {
  1050. var x = stack[i];
  1051. if (x instanceof type) return x;
  1052. }
  1053. },
  1054. has_directive: function(type) {
  1055. var dir = this.directives[type];
  1056. if (dir) return dir;
  1057. var node = this.stack[this.stack.length - 1];
  1058. if (node instanceof AST_Scope && node.body) {
  1059. for (var i = 0; i < node.body.length; ++i) {
  1060. var st = node.body[i];
  1061. if (!(st instanceof AST_Directive)) break;
  1062. if (st.value == type) return st;
  1063. }
  1064. }
  1065. },
  1066. loopcontrol_target: function(node) {
  1067. var stack = this.stack;
  1068. if (node.label) for (var i = stack.length; --i >= 0;) {
  1069. var x = stack[i];
  1070. if (x instanceof AST_LabeledStatement && x.label.name == node.label.name)
  1071. return x.body;
  1072. } else for (var i = stack.length; --i >= 0;) {
  1073. var x = stack[i];
  1074. if (x instanceof AST_IterationStatement
  1075. || node instanceof AST_Break && x instanceof AST_Switch)
  1076. return x;
  1077. }
  1078. }
  1079. };