batman-rails-flo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +29 -0
  3. data/Rakefile +2 -0
  4. data/lib/batman-rails-flo.rb +5 -0
  5. data/lib/batman_rails_flo/railtie.rb +9 -0
  6. data/lib/batman_rails_flo/tasks.rake +14 -0
  7. data/lib/batman_rails_flo/version.rb +3 -0
  8. data/vendor/assets/javascripts/batman_rails_flo/flo_server.js +67 -0
  9. data/vendor/assets/javascripts/batman_rails_flo/live_reload.js.coffee +129 -0
  10. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CNAME +1 -0
  11. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CONTRIBUTING.md +9 -0
  12. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/LICENSE +22 -0
  13. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/README +50 -0
  14. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/cake +7 -0
  15. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/coffee +7 -0
  16. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/browser.js +134 -0
  17. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/cake.js +112 -0
  18. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/coffee-script.js +335 -0
  19. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/command.js +569 -0
  20. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/grammar.js +631 -0
  21. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/helpers.js +252 -0
  22. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
  23. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/lexer.js +926 -0
  24. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/nodes.js +3158 -0
  25. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/optparse.js +139 -0
  26. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/parser.js +724 -0
  27. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/register.js +66 -0
  28. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/repl.js +163 -0
  29. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/rewriter.js +475 -0
  30. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
  31. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/sourcemap.js +161 -0
  32. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/LICENSE +21 -0
  33. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/examples/pow.js +6 -0
  34. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/index.js +82 -0
  35. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/package.json +34 -0
  36. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/readme.markdown +63 -0
  37. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/chmod.js +38 -0
  38. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/clobber.js +37 -0
  39. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/mkdirp.js +28 -0
  40. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm.js +32 -0
  41. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm_sync.js +39 -0
  42. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/race.js +41 -0
  43. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/rel.js +32 -0
  44. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return.js +25 -0
  45. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return_sync.js +24 -0
  46. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/root.js +18 -0
  47. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/sync.js +32 -0
  48. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask.js +28 -0
  49. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask_sync.js +32 -0
  50. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/package.json +50 -0
  51. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/register.js +1 -0
  52. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/LICENSE +30 -0
  53. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/PATENTS +23 -0
  54. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/README.md +124 -0
  55. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/bin/flo +26 -0
  56. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.html +57 -0
  57. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.js +205 -0
  58. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/style.css +334 -0
  59. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/connection.js +235 -0
  60. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/devtools.html +12 -0
  61. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/index.js +323 -0
  62. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logger.js +42 -0
  63. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logo.png +0 -0
  64. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/manifest.json +13 -0
  65. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/session.js +305 -0
  66. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/index.js +10 -0
  67. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/flo.js +226 -0
  68. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/server.js +94 -0
  69. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/README.md +66 -0
  70. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/index.js +437 -0
  71. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/LICENSE +23 -0
  72. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/README.md +218 -0
  73. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/minimatch.js +1055 -0
  74. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/CONTRIBUTORS +14 -0
  75. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
  76. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
  77. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +252 -0
  78. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/package.json +33 -0
  79. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/basic.js +369 -0
  80. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
  81. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
  82. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
  83. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
  84. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
  85. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/package.json +42 -0
  86. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
  87. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
  88. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/package.json +40 -0
  89. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/basic.js +399 -0
  90. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/brace-expand.js +33 -0
  91. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/caching.js +14 -0
  92. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/defaults.js +274 -0
  93. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
  94. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/lib/walker.js +111 -0
  95. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/license +13 -0
  96. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/lib/makeerror.js +87 -0
  97. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/lib/tmpl.js +17 -0
  98. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/package.json +31 -0
  99. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/readme.md +10 -0
  100. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/package.json +34 -0
  101. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/readme.md +77 -0
  102. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/package.json +36 -0
  103. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/readme.md +52 -0
  104. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/LICENSE +55 -0
  105. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/main.js +128 -0
  106. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/package.json +34 -0
  107. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/readme.mkd +72 -0
  108. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/d/t +0 -0
  109. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/t +0 -0
  110. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitor.js +31 -0
  111. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitorRootDirectory.js +28 -0
  112. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_watchTree.js +20 -0
  113. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/package.json +45 -0
  114. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/test/test.js +243 -0
  115. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/CHANGELOG.md +81 -0
  116. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/LICENSE +177 -0
  117. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/Makefile +11 -0
  118. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/README.md +245 -0
  119. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/binding.gyp +14 -0
  120. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Makefile +355 -0
  121. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/linker.lock +0 -0
  122. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/validation/src/validation.o +0 -0
  123. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/xor/src/xor.o +0 -0
  124. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/validation.node +0 -0
  125. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/xor.node +0 -0
  126. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/binding.Makefile +6 -0
  127. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/config.gypi +115 -0
  128. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/gyp-mac-tool +512 -0
  129. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/validation.target.mk +154 -0
  130. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/xor.target.mk +154 -0
  131. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/index.js +1 -0
  132. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/install.js +31 -0
  133. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Constants.js +23 -0
  134. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Deprecation.js +38 -0
  135. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.fallback.js +12 -0
  136. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.js +18 -0
  137. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketClient.js +359 -0
  138. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketConnection.js +717 -0
  139. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketFrame.js +282 -0
  140. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRequest.js +478 -0
  141. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouter.js +154 -0
  142. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouterRequest.js +59 -0
  143. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketServer.js +216 -0
  144. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/utils.js +7 -0
  145. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/websocket.js +11 -0
  146. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.fallback.js +13 -0
  147. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.js +18 -0
  148. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/package.json +43 -0
  149. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/validation.cc +144 -0
  150. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/xor.cpp +86 -0
  151. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/FastBufferList.js +192 -0
  152. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/LICENSE +18 -0
  153. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/ctio-faster.js +1126 -0
  154. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/package.json +25 -0
  155. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/browser_websocket.js +63 -0
  156. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/connection_test.js +57 -0
  157. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/logger_mock.js +15 -0
  158. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/session_test.js +194 -0
  159. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/server/flo_test.js +211 -0
  160. data/vendor/assets/javascripts/batman_rails_flo/package.json +15 -0
  161. data/vendor/assets/javascripts/batman_rails_flo/reload_event_handler.js.coffee +56 -0
  162. metadata +232 -0
@@ -0,0 +1,3158 @@
1
+ // Generated by CoffeeScript 1.7.1
2
+ (function() {
3
+ var Access, Arr, Assign, Base, Block, Call, Class, Code, CodeFragment, Comment, Existence, Expansion, Extends, For, HEXNUM, IDENTIFIER, IDENTIFIER_STR, IS_REGEX, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, NUMBER, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, isLiteralArguments, isLiteralThis, last, locationDataToString, merge, multident, parseNum, some, starts, throwSyntaxError, unfoldSoak, utility, _ref, _ref1,
4
+ __hasProp = {}.hasOwnProperty,
5
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
6
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
7
+ __slice = [].slice;
8
+
9
+ Error.stackTraceLimit = Infinity;
10
+
11
+ Scope = require('./scope').Scope;
12
+
13
+ _ref = require('./lexer'), RESERVED = _ref.RESERVED, STRICT_PROSCRIBED = _ref.STRICT_PROSCRIBED;
14
+
15
+ _ref1 = require('./helpers'), compact = _ref1.compact, flatten = _ref1.flatten, extend = _ref1.extend, merge = _ref1.merge, del = _ref1.del, starts = _ref1.starts, ends = _ref1.ends, last = _ref1.last, some = _ref1.some, addLocationDataFn = _ref1.addLocationDataFn, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
16
+
17
+ exports.extend = extend;
18
+
19
+ exports.addLocationDataFn = addLocationDataFn;
20
+
21
+ YES = function() {
22
+ return true;
23
+ };
24
+
25
+ NO = function() {
26
+ return false;
27
+ };
28
+
29
+ THIS = function() {
30
+ return this;
31
+ };
32
+
33
+ NEGATE = function() {
34
+ this.negated = !this.negated;
35
+ return this;
36
+ };
37
+
38
+ exports.CodeFragment = CodeFragment = (function() {
39
+ function CodeFragment(parent, code) {
40
+ var _ref2;
41
+ this.code = "" + code;
42
+ this.locationData = parent != null ? parent.locationData : void 0;
43
+ this.type = (parent != null ? (_ref2 = parent.constructor) != null ? _ref2.name : void 0 : void 0) || 'unknown';
44
+ }
45
+
46
+ CodeFragment.prototype.toString = function() {
47
+ return "" + this.code + (this.locationData ? ": " + locationDataToString(this.locationData) : '');
48
+ };
49
+
50
+ return CodeFragment;
51
+
52
+ })();
53
+
54
+ fragmentsToText = function(fragments) {
55
+ var fragment;
56
+ return ((function() {
57
+ var _i, _len, _results;
58
+ _results = [];
59
+ for (_i = 0, _len = fragments.length; _i < _len; _i++) {
60
+ fragment = fragments[_i];
61
+ _results.push(fragment.code);
62
+ }
63
+ return _results;
64
+ })()).join('');
65
+ };
66
+
67
+ exports.Base = Base = (function() {
68
+ function Base() {}
69
+
70
+ Base.prototype.compile = function(o, lvl) {
71
+ return fragmentsToText(this.compileToFragments(o, lvl));
72
+ };
73
+
74
+ Base.prototype.compileToFragments = function(o, lvl) {
75
+ var node;
76
+ o = extend({}, o);
77
+ if (lvl) {
78
+ o.level = lvl;
79
+ }
80
+ node = this.unfoldSoak(o) || this;
81
+ node.tab = o.indent;
82
+ if (o.level === LEVEL_TOP || !node.isStatement(o)) {
83
+ return node.compileNode(o);
84
+ } else {
85
+ return node.compileClosure(o);
86
+ }
87
+ };
88
+
89
+ Base.prototype.compileClosure = function(o) {
90
+ var args, argumentsNode, func, jumpNode, meth;
91
+ if (jumpNode = this.jumps()) {
92
+ jumpNode.error('cannot use a pure statement in an expression');
93
+ }
94
+ o.sharedScope = true;
95
+ func = new Code([], Block.wrap([this]));
96
+ args = [];
97
+ if ((argumentsNode = this.contains(isLiteralArguments)) || this.contains(isLiteralThis)) {
98
+ args = [new Literal('this')];
99
+ if (argumentsNode) {
100
+ meth = 'apply';
101
+ args.push(new Literal('arguments'));
102
+ } else {
103
+ meth = 'call';
104
+ }
105
+ func = new Value(func, [new Access(new Literal(meth))]);
106
+ }
107
+ return (new Call(func, args)).compileNode(o);
108
+ };
109
+
110
+ Base.prototype.cache = function(o, level, reused) {
111
+ var ref, sub;
112
+ if (!this.isComplex()) {
113
+ ref = level ? this.compileToFragments(o, level) : this;
114
+ return [ref, ref];
115
+ } else {
116
+ ref = new Literal(reused || o.scope.freeVariable('ref'));
117
+ sub = new Assign(ref, this);
118
+ if (level) {
119
+ return [sub.compileToFragments(o, level), [this.makeCode(ref.value)]];
120
+ } else {
121
+ return [sub, ref];
122
+ }
123
+ }
124
+ };
125
+
126
+ Base.prototype.cacheToCodeFragments = function(cacheValues) {
127
+ return [fragmentsToText(cacheValues[0]), fragmentsToText(cacheValues[1])];
128
+ };
129
+
130
+ Base.prototype.makeReturn = function(res) {
131
+ var me;
132
+ me = this.unwrapAll();
133
+ if (res) {
134
+ return new Call(new Literal("" + res + ".push"), [me]);
135
+ } else {
136
+ return new Return(me);
137
+ }
138
+ };
139
+
140
+ Base.prototype.contains = function(pred) {
141
+ var node;
142
+ node = void 0;
143
+ this.traverseChildren(false, function(n) {
144
+ if (pred(n)) {
145
+ node = n;
146
+ return false;
147
+ }
148
+ });
149
+ return node;
150
+ };
151
+
152
+ Base.prototype.lastNonComment = function(list) {
153
+ var i;
154
+ i = list.length;
155
+ while (i--) {
156
+ if (!(list[i] instanceof Comment)) {
157
+ return list[i];
158
+ }
159
+ }
160
+ return null;
161
+ };
162
+
163
+ Base.prototype.toString = function(idt, name) {
164
+ var tree;
165
+ if (idt == null) {
166
+ idt = '';
167
+ }
168
+ if (name == null) {
169
+ name = this.constructor.name;
170
+ }
171
+ tree = '\n' + idt + name;
172
+ if (this.soak) {
173
+ tree += '?';
174
+ }
175
+ this.eachChild(function(node) {
176
+ return tree += node.toString(idt + TAB);
177
+ });
178
+ return tree;
179
+ };
180
+
181
+ Base.prototype.eachChild = function(func) {
182
+ var attr, child, _i, _j, _len, _len1, _ref2, _ref3;
183
+ if (!this.children) {
184
+ return this;
185
+ }
186
+ _ref2 = this.children;
187
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
188
+ attr = _ref2[_i];
189
+ if (this[attr]) {
190
+ _ref3 = flatten([this[attr]]);
191
+ for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
192
+ child = _ref3[_j];
193
+ if (func(child) === false) {
194
+ return this;
195
+ }
196
+ }
197
+ }
198
+ }
199
+ return this;
200
+ };
201
+
202
+ Base.prototype.traverseChildren = function(crossScope, func) {
203
+ return this.eachChild(function(child) {
204
+ var recur;
205
+ recur = func(child);
206
+ if (recur !== false) {
207
+ return child.traverseChildren(crossScope, func);
208
+ }
209
+ });
210
+ };
211
+
212
+ Base.prototype.invert = function() {
213
+ return new Op('!', this);
214
+ };
215
+
216
+ Base.prototype.unwrapAll = function() {
217
+ var node;
218
+ node = this;
219
+ while (node !== (node = node.unwrap())) {
220
+ continue;
221
+ }
222
+ return node;
223
+ };
224
+
225
+ Base.prototype.children = [];
226
+
227
+ Base.prototype.isStatement = NO;
228
+
229
+ Base.prototype.jumps = NO;
230
+
231
+ Base.prototype.isComplex = YES;
232
+
233
+ Base.prototype.isChainable = NO;
234
+
235
+ Base.prototype.isAssignable = NO;
236
+
237
+ Base.prototype.unwrap = THIS;
238
+
239
+ Base.prototype.unfoldSoak = NO;
240
+
241
+ Base.prototype.assigns = NO;
242
+
243
+ Base.prototype.updateLocationDataIfMissing = function(locationData) {
244
+ if (this.locationData) {
245
+ return this;
246
+ }
247
+ this.locationData = locationData;
248
+ return this.eachChild(function(child) {
249
+ return child.updateLocationDataIfMissing(locationData);
250
+ });
251
+ };
252
+
253
+ Base.prototype.error = function(message) {
254
+ return throwSyntaxError(message, this.locationData);
255
+ };
256
+
257
+ Base.prototype.makeCode = function(code) {
258
+ return new CodeFragment(this, code);
259
+ };
260
+
261
+ Base.prototype.wrapInBraces = function(fragments) {
262
+ return [].concat(this.makeCode('('), fragments, this.makeCode(')'));
263
+ };
264
+
265
+ Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) {
266
+ var answer, fragments, i, _i, _len;
267
+ answer = [];
268
+ for (i = _i = 0, _len = fragmentsList.length; _i < _len; i = ++_i) {
269
+ fragments = fragmentsList[i];
270
+ if (i) {
271
+ answer.push(this.makeCode(joinStr));
272
+ }
273
+ answer = answer.concat(fragments);
274
+ }
275
+ return answer;
276
+ };
277
+
278
+ return Base;
279
+
280
+ })();
281
+
282
+ exports.Block = Block = (function(_super) {
283
+ __extends(Block, _super);
284
+
285
+ function Block(nodes) {
286
+ this.expressions = compact(flatten(nodes || []));
287
+ }
288
+
289
+ Block.prototype.children = ['expressions'];
290
+
291
+ Block.prototype.push = function(node) {
292
+ this.expressions.push(node);
293
+ return this;
294
+ };
295
+
296
+ Block.prototype.pop = function() {
297
+ return this.expressions.pop();
298
+ };
299
+
300
+ Block.prototype.unshift = function(node) {
301
+ this.expressions.unshift(node);
302
+ return this;
303
+ };
304
+
305
+ Block.prototype.unwrap = function() {
306
+ if (this.expressions.length === 1) {
307
+ return this.expressions[0];
308
+ } else {
309
+ return this;
310
+ }
311
+ };
312
+
313
+ Block.prototype.isEmpty = function() {
314
+ return !this.expressions.length;
315
+ };
316
+
317
+ Block.prototype.isStatement = function(o) {
318
+ var exp, _i, _len, _ref2;
319
+ _ref2 = this.expressions;
320
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
321
+ exp = _ref2[_i];
322
+ if (exp.isStatement(o)) {
323
+ return true;
324
+ }
325
+ }
326
+ return false;
327
+ };
328
+
329
+ Block.prototype.jumps = function(o) {
330
+ var exp, jumpNode, _i, _len, _ref2;
331
+ _ref2 = this.expressions;
332
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
333
+ exp = _ref2[_i];
334
+ if (jumpNode = exp.jumps(o)) {
335
+ return jumpNode;
336
+ }
337
+ }
338
+ };
339
+
340
+ Block.prototype.makeReturn = function(res) {
341
+ var expr, len;
342
+ len = this.expressions.length;
343
+ while (len--) {
344
+ expr = this.expressions[len];
345
+ if (!(expr instanceof Comment)) {
346
+ this.expressions[len] = expr.makeReturn(res);
347
+ if (expr instanceof Return && !expr.expression) {
348
+ this.expressions.splice(len, 1);
349
+ }
350
+ break;
351
+ }
352
+ }
353
+ return this;
354
+ };
355
+
356
+ Block.prototype.compileToFragments = function(o, level) {
357
+ if (o == null) {
358
+ o = {};
359
+ }
360
+ if (o.scope) {
361
+ return Block.__super__.compileToFragments.call(this, o, level);
362
+ } else {
363
+ return this.compileRoot(o);
364
+ }
365
+ };
366
+
367
+ Block.prototype.compileNode = function(o) {
368
+ var answer, compiledNodes, fragments, index, node, top, _i, _len, _ref2;
369
+ this.tab = o.indent;
370
+ top = o.level === LEVEL_TOP;
371
+ compiledNodes = [];
372
+ _ref2 = this.expressions;
373
+ for (index = _i = 0, _len = _ref2.length; _i < _len; index = ++_i) {
374
+ node = _ref2[index];
375
+ node = node.unwrapAll();
376
+ node = node.unfoldSoak(o) || node;
377
+ if (node instanceof Block) {
378
+ compiledNodes.push(node.compileNode(o));
379
+ } else if (top) {
380
+ node.front = true;
381
+ fragments = node.compileToFragments(o);
382
+ if (!node.isStatement(o)) {
383
+ fragments.unshift(this.makeCode("" + this.tab));
384
+ fragments.push(this.makeCode(";"));
385
+ }
386
+ compiledNodes.push(fragments);
387
+ } else {
388
+ compiledNodes.push(node.compileToFragments(o, LEVEL_LIST));
389
+ }
390
+ }
391
+ if (top) {
392
+ if (this.spaced) {
393
+ return [].concat(this.joinFragmentArrays(compiledNodes, '\n\n'), this.makeCode("\n"));
394
+ } else {
395
+ return this.joinFragmentArrays(compiledNodes, '\n');
396
+ }
397
+ }
398
+ if (compiledNodes.length) {
399
+ answer = this.joinFragmentArrays(compiledNodes, ', ');
400
+ } else {
401
+ answer = [this.makeCode("void 0")];
402
+ }
403
+ if (compiledNodes.length > 1 && o.level >= LEVEL_LIST) {
404
+ return this.wrapInBraces(answer);
405
+ } else {
406
+ return answer;
407
+ }
408
+ };
409
+
410
+ Block.prototype.compileRoot = function(o) {
411
+ var exp, fragments, i, name, prelude, preludeExps, rest, _i, _len, _ref2;
412
+ o.indent = o.bare ? '' : TAB;
413
+ o.level = LEVEL_TOP;
414
+ this.spaced = true;
415
+ o.scope = new Scope(null, this, null);
416
+ _ref2 = o.locals || [];
417
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
418
+ name = _ref2[_i];
419
+ o.scope.parameter(name);
420
+ }
421
+ prelude = [];
422
+ if (!o.bare) {
423
+ preludeExps = (function() {
424
+ var _j, _len1, _ref3, _results;
425
+ _ref3 = this.expressions;
426
+ _results = [];
427
+ for (i = _j = 0, _len1 = _ref3.length; _j < _len1; i = ++_j) {
428
+ exp = _ref3[i];
429
+ if (!(exp.unwrap() instanceof Comment)) {
430
+ break;
431
+ }
432
+ _results.push(exp);
433
+ }
434
+ return _results;
435
+ }).call(this);
436
+ rest = this.expressions.slice(preludeExps.length);
437
+ this.expressions = preludeExps;
438
+ if (preludeExps.length) {
439
+ prelude = this.compileNode(merge(o, {
440
+ indent: ''
441
+ }));
442
+ prelude.push(this.makeCode("\n"));
443
+ }
444
+ this.expressions = rest;
445
+ }
446
+ fragments = this.compileWithDeclarations(o);
447
+ if (o.bare) {
448
+ return fragments;
449
+ }
450
+ return [].concat(prelude, this.makeCode("(function() {\n"), fragments, this.makeCode("\n}).call(this);\n"));
451
+ };
452
+
453
+ Block.prototype.compileWithDeclarations = function(o) {
454
+ var assigns, declars, exp, fragments, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
455
+ fragments = [];
456
+ post = [];
457
+ _ref2 = this.expressions;
458
+ for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
459
+ exp = _ref2[i];
460
+ exp = exp.unwrap();
461
+ if (!(exp instanceof Comment || exp instanceof Literal)) {
462
+ break;
463
+ }
464
+ }
465
+ o = merge(o, {
466
+ level: LEVEL_TOP
467
+ });
468
+ if (i) {
469
+ rest = this.expressions.splice(i, 9e9);
470
+ _ref3 = [this.spaced, false], spaced = _ref3[0], this.spaced = _ref3[1];
471
+ _ref4 = [this.compileNode(o), spaced], fragments = _ref4[0], this.spaced = _ref4[1];
472
+ this.expressions = rest;
473
+ }
474
+ post = this.compileNode(o);
475
+ scope = o.scope;
476
+ if (scope.expressions === this) {
477
+ declars = o.scope.hasDeclarations();
478
+ assigns = scope.hasAssignments;
479
+ if (declars || assigns) {
480
+ if (i) {
481
+ fragments.push(this.makeCode('\n'));
482
+ }
483
+ fragments.push(this.makeCode("" + this.tab + "var "));
484
+ if (declars) {
485
+ fragments.push(this.makeCode(scope.declaredVariables().join(', ')));
486
+ }
487
+ if (assigns) {
488
+ if (declars) {
489
+ fragments.push(this.makeCode(",\n" + (this.tab + TAB)));
490
+ }
491
+ fragments.push(this.makeCode(scope.assignedVariables().join(",\n" + (this.tab + TAB))));
492
+ }
493
+ fragments.push(this.makeCode(";\n" + (this.spaced ? '\n' : '')));
494
+ } else if (fragments.length && post.length) {
495
+ fragments.push(this.makeCode("\n"));
496
+ }
497
+ }
498
+ return fragments.concat(post);
499
+ };
500
+
501
+ Block.wrap = function(nodes) {
502
+ if (nodes.length === 1 && nodes[0] instanceof Block) {
503
+ return nodes[0];
504
+ }
505
+ return new Block(nodes);
506
+ };
507
+
508
+ return Block;
509
+
510
+ })(Base);
511
+
512
+ exports.Literal = Literal = (function(_super) {
513
+ __extends(Literal, _super);
514
+
515
+ function Literal(value) {
516
+ this.value = value;
517
+ }
518
+
519
+ Literal.prototype.makeReturn = function() {
520
+ if (this.isStatement()) {
521
+ return this;
522
+ } else {
523
+ return Literal.__super__.makeReturn.apply(this, arguments);
524
+ }
525
+ };
526
+
527
+ Literal.prototype.isAssignable = function() {
528
+ return IDENTIFIER.test(this.value);
529
+ };
530
+
531
+ Literal.prototype.isStatement = function() {
532
+ var _ref2;
533
+ return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
534
+ };
535
+
536
+ Literal.prototype.isComplex = NO;
537
+
538
+ Literal.prototype.assigns = function(name) {
539
+ return name === this.value;
540
+ };
541
+
542
+ Literal.prototype.jumps = function(o) {
543
+ if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) {
544
+ return this;
545
+ }
546
+ if (this.value === 'continue' && !(o != null ? o.loop : void 0)) {
547
+ return this;
548
+ }
549
+ };
550
+
551
+ Literal.prototype.compileNode = function(o) {
552
+ var answer, code, _ref2;
553
+ code = this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value;
554
+ answer = this.isStatement() ? "" + this.tab + code + ";" : code;
555
+ return [this.makeCode(answer)];
556
+ };
557
+
558
+ Literal.prototype.toString = function() {
559
+ return ' "' + this.value + '"';
560
+ };
561
+
562
+ return Literal;
563
+
564
+ })(Base);
565
+
566
+ exports.Undefined = (function(_super) {
567
+ __extends(Undefined, _super);
568
+
569
+ function Undefined() {
570
+ return Undefined.__super__.constructor.apply(this, arguments);
571
+ }
572
+
573
+ Undefined.prototype.isAssignable = NO;
574
+
575
+ Undefined.prototype.isComplex = NO;
576
+
577
+ Undefined.prototype.compileNode = function(o) {
578
+ return [this.makeCode(o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0')];
579
+ };
580
+
581
+ return Undefined;
582
+
583
+ })(Base);
584
+
585
+ exports.Null = (function(_super) {
586
+ __extends(Null, _super);
587
+
588
+ function Null() {
589
+ return Null.__super__.constructor.apply(this, arguments);
590
+ }
591
+
592
+ Null.prototype.isAssignable = NO;
593
+
594
+ Null.prototype.isComplex = NO;
595
+
596
+ Null.prototype.compileNode = function() {
597
+ return [this.makeCode("null")];
598
+ };
599
+
600
+ return Null;
601
+
602
+ })(Base);
603
+
604
+ exports.Bool = (function(_super) {
605
+ __extends(Bool, _super);
606
+
607
+ Bool.prototype.isAssignable = NO;
608
+
609
+ Bool.prototype.isComplex = NO;
610
+
611
+ Bool.prototype.compileNode = function() {
612
+ return [this.makeCode(this.val)];
613
+ };
614
+
615
+ function Bool(val) {
616
+ this.val = val;
617
+ }
618
+
619
+ return Bool;
620
+
621
+ })(Base);
622
+
623
+ exports.Return = Return = (function(_super) {
624
+ __extends(Return, _super);
625
+
626
+ function Return(expr) {
627
+ if (expr && !expr.unwrap().isUndefined) {
628
+ this.expression = expr;
629
+ }
630
+ }
631
+
632
+ Return.prototype.children = ['expression'];
633
+
634
+ Return.prototype.isStatement = YES;
635
+
636
+ Return.prototype.makeReturn = THIS;
637
+
638
+ Return.prototype.jumps = THIS;
639
+
640
+ Return.prototype.compileToFragments = function(o, level) {
641
+ var expr, _ref2;
642
+ expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0;
643
+ if (expr && !(expr instanceof Return)) {
644
+ return expr.compileToFragments(o, level);
645
+ } else {
646
+ return Return.__super__.compileToFragments.call(this, o, level);
647
+ }
648
+ };
649
+
650
+ Return.prototype.compileNode = function(o) {
651
+ var answer;
652
+ answer = [];
653
+ answer.push(this.makeCode(this.tab + ("return" + (this.expression ? " " : ""))));
654
+ if (this.expression) {
655
+ answer = answer.concat(this.expression.compileToFragments(o, LEVEL_PAREN));
656
+ }
657
+ answer.push(this.makeCode(";"));
658
+ return answer;
659
+ };
660
+
661
+ return Return;
662
+
663
+ })(Base);
664
+
665
+ exports.Value = Value = (function(_super) {
666
+ __extends(Value, _super);
667
+
668
+ function Value(base, props, tag) {
669
+ if (!props && base instanceof Value) {
670
+ return base;
671
+ }
672
+ this.base = base;
673
+ this.properties = props || [];
674
+ if (tag) {
675
+ this[tag] = true;
676
+ }
677
+ return this;
678
+ }
679
+
680
+ Value.prototype.children = ['base', 'properties'];
681
+
682
+ Value.prototype.add = function(props) {
683
+ this.properties = this.properties.concat(props);
684
+ return this;
685
+ };
686
+
687
+ Value.prototype.hasProperties = function() {
688
+ return !!this.properties.length;
689
+ };
690
+
691
+ Value.prototype.bareLiteral = function(type) {
692
+ return !this.properties.length && this.base instanceof type;
693
+ };
694
+
695
+ Value.prototype.isArray = function() {
696
+ return this.bareLiteral(Arr);
697
+ };
698
+
699
+ Value.prototype.isRange = function() {
700
+ return this.bareLiteral(Range);
701
+ };
702
+
703
+ Value.prototype.isComplex = function() {
704
+ return this.hasProperties() || this.base.isComplex();
705
+ };
706
+
707
+ Value.prototype.isAssignable = function() {
708
+ return this.hasProperties() || this.base.isAssignable();
709
+ };
710
+
711
+ Value.prototype.isSimpleNumber = function() {
712
+ return this.bareLiteral(Literal) && SIMPLENUM.test(this.base.value);
713
+ };
714
+
715
+ Value.prototype.isString = function() {
716
+ return this.bareLiteral(Literal) && IS_STRING.test(this.base.value);
717
+ };
718
+
719
+ Value.prototype.isRegex = function() {
720
+ return this.bareLiteral(Literal) && IS_REGEX.test(this.base.value);
721
+ };
722
+
723
+ Value.prototype.isAtomic = function() {
724
+ var node, _i, _len, _ref2;
725
+ _ref2 = this.properties.concat(this.base);
726
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
727
+ node = _ref2[_i];
728
+ if (node.soak || node instanceof Call) {
729
+ return false;
730
+ }
731
+ }
732
+ return true;
733
+ };
734
+
735
+ Value.prototype.isNotCallable = function() {
736
+ return this.isSimpleNumber() || this.isString() || this.isRegex() || this.isArray() || this.isRange() || this.isSplice() || this.isObject();
737
+ };
738
+
739
+ Value.prototype.isStatement = function(o) {
740
+ return !this.properties.length && this.base.isStatement(o);
741
+ };
742
+
743
+ Value.prototype.assigns = function(name) {
744
+ return !this.properties.length && this.base.assigns(name);
745
+ };
746
+
747
+ Value.prototype.jumps = function(o) {
748
+ return !this.properties.length && this.base.jumps(o);
749
+ };
750
+
751
+ Value.prototype.isObject = function(onlyGenerated) {
752
+ if (this.properties.length) {
753
+ return false;
754
+ }
755
+ return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);
756
+ };
757
+
758
+ Value.prototype.isSplice = function() {
759
+ return last(this.properties) instanceof Slice;
760
+ };
761
+
762
+ Value.prototype.looksStatic = function(className) {
763
+ var _ref2;
764
+ return this.base.value === className && this.properties.length && ((_ref2 = this.properties[0].name) != null ? _ref2.value : void 0) !== 'prototype';
765
+ };
766
+
767
+ Value.prototype.unwrap = function() {
768
+ if (this.properties.length) {
769
+ return this;
770
+ } else {
771
+ return this.base;
772
+ }
773
+ };
774
+
775
+ Value.prototype.cacheReference = function(o) {
776
+ var base, bref, name, nref;
777
+ name = last(this.properties);
778
+ if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
779
+ return [this, this];
780
+ }
781
+ base = new Value(this.base, this.properties.slice(0, -1));
782
+ if (base.isComplex()) {
783
+ bref = new Literal(o.scope.freeVariable('base'));
784
+ base = new Value(new Parens(new Assign(bref, base)));
785
+ }
786
+ if (!name) {
787
+ return [base, bref];
788
+ }
789
+ if (name.isComplex()) {
790
+ nref = new Literal(o.scope.freeVariable('name'));
791
+ name = new Index(new Assign(nref, name.index));
792
+ nref = new Index(nref);
793
+ }
794
+ return [base.add(name), new Value(bref || base.base, [nref || name])];
795
+ };
796
+
797
+ Value.prototype.compileNode = function(o) {
798
+ var fragments, prop, props, _i, _len;
799
+ this.base.front = this.front;
800
+ props = this.properties;
801
+ fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null));
802
+ if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(fragmentsToText(fragments))) {
803
+ fragments.push(this.makeCode('.'));
804
+ }
805
+ for (_i = 0, _len = props.length; _i < _len; _i++) {
806
+ prop = props[_i];
807
+ fragments.push.apply(fragments, prop.compileToFragments(o));
808
+ }
809
+ return fragments;
810
+ };
811
+
812
+ Value.prototype.unfoldSoak = function(o) {
813
+ return this.unfoldedSoak != null ? this.unfoldedSoak : this.unfoldedSoak = (function(_this) {
814
+ return function() {
815
+ var fst, i, ifn, prop, ref, snd, _i, _len, _ref2, _ref3;
816
+ if (ifn = _this.base.unfoldSoak(o)) {
817
+ (_ref2 = ifn.body.properties).push.apply(_ref2, _this.properties);
818
+ return ifn;
819
+ }
820
+ _ref3 = _this.properties;
821
+ for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
822
+ prop = _ref3[i];
823
+ if (!prop.soak) {
824
+ continue;
825
+ }
826
+ prop.soak = false;
827
+ fst = new Value(_this.base, _this.properties.slice(0, i));
828
+ snd = new Value(_this.base, _this.properties.slice(i));
829
+ if (fst.isComplex()) {
830
+ ref = new Literal(o.scope.freeVariable('ref'));
831
+ fst = new Parens(new Assign(ref, fst));
832
+ snd.base = ref;
833
+ }
834
+ return new If(new Existence(fst), snd, {
835
+ soak: true
836
+ });
837
+ }
838
+ return false;
839
+ };
840
+ })(this)();
841
+ };
842
+
843
+ return Value;
844
+
845
+ })(Base);
846
+
847
+ exports.Comment = Comment = (function(_super) {
848
+ __extends(Comment, _super);
849
+
850
+ function Comment(comment) {
851
+ this.comment = comment;
852
+ }
853
+
854
+ Comment.prototype.isStatement = YES;
855
+
856
+ Comment.prototype.makeReturn = THIS;
857
+
858
+ Comment.prototype.compileNode = function(o, level) {
859
+ var code, comment;
860
+ comment = this.comment.replace(/^(\s*)#/gm, "$1 *");
861
+ code = "/*" + (multident(comment, this.tab)) + (__indexOf.call(comment, '\n') >= 0 ? "\n" + this.tab : '') + " */";
862
+ if ((level || o.level) === LEVEL_TOP) {
863
+ code = o.indent + code;
864
+ }
865
+ return [this.makeCode("\n"), this.makeCode(code)];
866
+ };
867
+
868
+ return Comment;
869
+
870
+ })(Base);
871
+
872
+ exports.Call = Call = (function(_super) {
873
+ __extends(Call, _super);
874
+
875
+ function Call(variable, args, soak) {
876
+ this.args = args != null ? args : [];
877
+ this.soak = soak;
878
+ this.isNew = false;
879
+ this.isSuper = variable === 'super';
880
+ this.variable = this.isSuper ? null : variable;
881
+ if (variable instanceof Value && variable.isNotCallable()) {
882
+ variable.error("literal is not a function");
883
+ }
884
+ }
885
+
886
+ Call.prototype.children = ['variable', 'args'];
887
+
888
+ Call.prototype.newInstance = function() {
889
+ var base, _ref2;
890
+ base = ((_ref2 = this.variable) != null ? _ref2.base : void 0) || this.variable;
891
+ if (base instanceof Call && !base.isNew) {
892
+ base.newInstance();
893
+ } else {
894
+ this.isNew = true;
895
+ }
896
+ return this;
897
+ };
898
+
899
+ Call.prototype.superReference = function(o) {
900
+ var accesses, method;
901
+ method = o.scope.namedMethod();
902
+ if (method != null ? method.klass : void 0) {
903
+ accesses = [new Access(new Literal('__super__'))];
904
+ if (method["static"]) {
905
+ accesses.push(new Access(new Literal('constructor')));
906
+ }
907
+ accesses.push(new Access(new Literal(method.name)));
908
+ return (new Value(new Literal(method.klass), accesses)).compile(o);
909
+ } else if (method != null ? method.ctor : void 0) {
910
+ return "" + method.name + ".__super__.constructor";
911
+ } else {
912
+ return this.error('cannot call super outside of an instance method.');
913
+ }
914
+ };
915
+
916
+ Call.prototype.superThis = function(o) {
917
+ var method;
918
+ method = o.scope.method;
919
+ return (method && !method.klass && method.context) || "this";
920
+ };
921
+
922
+ Call.prototype.unfoldSoak = function(o) {
923
+ var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
924
+ if (this.soak) {
925
+ if (this.variable) {
926
+ if (ifn = unfoldSoak(o, this, 'variable')) {
927
+ return ifn;
928
+ }
929
+ _ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1];
930
+ } else {
931
+ left = new Literal(this.superReference(o));
932
+ rite = new Value(left);
933
+ }
934
+ rite = new Call(rite, this.args);
935
+ rite.isNew = this.isNew;
936
+ left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");
937
+ return new If(left, new Value(rite), {
938
+ soak: true
939
+ });
940
+ }
941
+ call = this;
942
+ list = [];
943
+ while (true) {
944
+ if (call.variable instanceof Call) {
945
+ list.push(call);
946
+ call = call.variable;
947
+ continue;
948
+ }
949
+ if (!(call.variable instanceof Value)) {
950
+ break;
951
+ }
952
+ list.push(call);
953
+ if (!((call = call.variable.base) instanceof Call)) {
954
+ break;
955
+ }
956
+ }
957
+ _ref3 = list.reverse();
958
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
959
+ call = _ref3[_i];
960
+ if (ifn) {
961
+ if (call.variable instanceof Call) {
962
+ call.variable = ifn;
963
+ } else {
964
+ call.variable.base = ifn;
965
+ }
966
+ }
967
+ ifn = unfoldSoak(o, call, 'variable');
968
+ }
969
+ return ifn;
970
+ };
971
+
972
+ Call.prototype.compileNode = function(o) {
973
+ var arg, argIndex, compiledArgs, compiledArray, fragments, preface, _i, _len, _ref2, _ref3;
974
+ if ((_ref2 = this.variable) != null) {
975
+ _ref2.front = this.front;
976
+ }
977
+ compiledArray = Splat.compileSplattedArray(o, this.args, true);
978
+ if (compiledArray.length) {
979
+ return this.compileSplat(o, compiledArray);
980
+ }
981
+ compiledArgs = [];
982
+ _ref3 = this.args;
983
+ for (argIndex = _i = 0, _len = _ref3.length; _i < _len; argIndex = ++_i) {
984
+ arg = _ref3[argIndex];
985
+ if (argIndex) {
986
+ compiledArgs.push(this.makeCode(", "));
987
+ }
988
+ compiledArgs.push.apply(compiledArgs, arg.compileToFragments(o, LEVEL_LIST));
989
+ }
990
+ fragments = [];
991
+ if (this.isSuper) {
992
+ preface = this.superReference(o) + (".call(" + (this.superThis(o)));
993
+ if (compiledArgs.length) {
994
+ preface += ", ";
995
+ }
996
+ fragments.push(this.makeCode(preface));
997
+ } else {
998
+ if (this.isNew) {
999
+ fragments.push(this.makeCode('new '));
1000
+ }
1001
+ fragments.push.apply(fragments, this.variable.compileToFragments(o, LEVEL_ACCESS));
1002
+ fragments.push(this.makeCode("("));
1003
+ }
1004
+ fragments.push.apply(fragments, compiledArgs);
1005
+ fragments.push(this.makeCode(")"));
1006
+ return fragments;
1007
+ };
1008
+
1009
+ Call.prototype.compileSplat = function(o, splatArgs) {
1010
+ var answer, base, fun, idt, name, ref;
1011
+ if (this.isSuper) {
1012
+ return [].concat(this.makeCode("" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")"));
1013
+ }
1014
+ if (this.isNew) {
1015
+ idt = this.tab + TAB;
1016
+ return [].concat(this.makeCode("(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return Object(result) === result ? result : child;\n" + this.tab + "})("), this.variable.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), splatArgs, this.makeCode(", function(){})"));
1017
+ }
1018
+ answer = [];
1019
+ base = new Value(this.variable);
1020
+ if ((name = base.properties.pop()) && base.isComplex()) {
1021
+ ref = o.scope.freeVariable('ref');
1022
+ answer = answer.concat(this.makeCode("(" + ref + " = "), base.compileToFragments(o, LEVEL_LIST), this.makeCode(")"), name.compileToFragments(o));
1023
+ } else {
1024
+ fun = base.compileToFragments(o, LEVEL_ACCESS);
1025
+ if (SIMPLENUM.test(fragmentsToText(fun))) {
1026
+ fun = this.wrapInBraces(fun);
1027
+ }
1028
+ if (name) {
1029
+ ref = fragmentsToText(fun);
1030
+ fun.push.apply(fun, name.compileToFragments(o));
1031
+ } else {
1032
+ ref = 'null';
1033
+ }
1034
+ answer = answer.concat(fun);
1035
+ }
1036
+ return answer = answer.concat(this.makeCode(".apply(" + ref + ", "), splatArgs, this.makeCode(")"));
1037
+ };
1038
+
1039
+ return Call;
1040
+
1041
+ })(Base);
1042
+
1043
+ exports.Extends = Extends = (function(_super) {
1044
+ __extends(Extends, _super);
1045
+
1046
+ function Extends(child, parent) {
1047
+ this.child = child;
1048
+ this.parent = parent;
1049
+ }
1050
+
1051
+ Extends.prototype.children = ['child', 'parent'];
1052
+
1053
+ Extends.prototype.compileToFragments = function(o) {
1054
+ return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compileToFragments(o);
1055
+ };
1056
+
1057
+ return Extends;
1058
+
1059
+ })(Base);
1060
+
1061
+ exports.Access = Access = (function(_super) {
1062
+ __extends(Access, _super);
1063
+
1064
+ function Access(name, tag) {
1065
+ this.name = name;
1066
+ this.name.asKey = true;
1067
+ this.soak = tag === 'soak';
1068
+ }
1069
+
1070
+ Access.prototype.children = ['name'];
1071
+
1072
+ Access.prototype.compileToFragments = function(o) {
1073
+ var name;
1074
+ name = this.name.compileToFragments(o);
1075
+ if (IDENTIFIER.test(fragmentsToText(name))) {
1076
+ name.unshift(this.makeCode("."));
1077
+ } else {
1078
+ name.unshift(this.makeCode("["));
1079
+ name.push(this.makeCode("]"));
1080
+ }
1081
+ return name;
1082
+ };
1083
+
1084
+ Access.prototype.isComplex = NO;
1085
+
1086
+ return Access;
1087
+
1088
+ })(Base);
1089
+
1090
+ exports.Index = Index = (function(_super) {
1091
+ __extends(Index, _super);
1092
+
1093
+ function Index(index) {
1094
+ this.index = index;
1095
+ }
1096
+
1097
+ Index.prototype.children = ['index'];
1098
+
1099
+ Index.prototype.compileToFragments = function(o) {
1100
+ return [].concat(this.makeCode("["), this.index.compileToFragments(o, LEVEL_PAREN), this.makeCode("]"));
1101
+ };
1102
+
1103
+ Index.prototype.isComplex = function() {
1104
+ return this.index.isComplex();
1105
+ };
1106
+
1107
+ return Index;
1108
+
1109
+ })(Base);
1110
+
1111
+ exports.Range = Range = (function(_super) {
1112
+ __extends(Range, _super);
1113
+
1114
+ Range.prototype.children = ['from', 'to'];
1115
+
1116
+ function Range(from, to, tag) {
1117
+ this.from = from;
1118
+ this.to = to;
1119
+ this.exclusive = tag === 'exclusive';
1120
+ this.equals = this.exclusive ? '' : '=';
1121
+ }
1122
+
1123
+ Range.prototype.compileVariables = function(o) {
1124
+ var step, _ref2, _ref3, _ref4, _ref5;
1125
+ o = merge(o, {
1126
+ top: true
1127
+ });
1128
+ _ref2 = this.cacheToCodeFragments(this.from.cache(o, LEVEL_LIST)), this.fromC = _ref2[0], this.fromVar = _ref2[1];
1129
+ _ref3 = this.cacheToCodeFragments(this.to.cache(o, LEVEL_LIST)), this.toC = _ref3[0], this.toVar = _ref3[1];
1130
+ if (step = del(o, 'step')) {
1131
+ _ref4 = this.cacheToCodeFragments(step.cache(o, LEVEL_LIST)), this.step = _ref4[0], this.stepVar = _ref4[1];
1132
+ }
1133
+ _ref5 = [this.fromVar.match(NUMBER), this.toVar.match(NUMBER)], this.fromNum = _ref5[0], this.toNum = _ref5[1];
1134
+ if (this.stepVar) {
1135
+ return this.stepNum = this.stepVar.match(NUMBER);
1136
+ }
1137
+ };
1138
+
1139
+ Range.prototype.compileNode = function(o) {
1140
+ var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref2, _ref3;
1141
+ if (!this.fromVar) {
1142
+ this.compileVariables(o);
1143
+ }
1144
+ if (!o.index) {
1145
+ return this.compileArray(o);
1146
+ }
1147
+ known = this.fromNum && this.toNum;
1148
+ idx = del(o, 'index');
1149
+ idxName = del(o, 'name');
1150
+ namedIndex = idxName && idxName !== idx;
1151
+ varPart = "" + idx + " = " + this.fromC;
1152
+ if (this.toC !== this.toVar) {
1153
+ varPart += ", " + this.toC;
1154
+ }
1155
+ if (this.step !== this.stepVar) {
1156
+ varPart += ", " + this.step;
1157
+ }
1158
+ _ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1];
1159
+ condPart = this.stepNum ? parseNum(this.stepNum[0]) > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [parseNum(this.fromNum[0]), parseNum(this.toNum[0])], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = this.stepVar ? "" + this.stepVar + " > 0" : "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
1160
+ stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";
1161
+ if (namedIndex) {
1162
+ varPart = "" + idxName + " = " + varPart;
1163
+ }
1164
+ if (namedIndex) {
1165
+ stepPart = "" + idxName + " = " + stepPart;
1166
+ }
1167
+ return [this.makeCode("" + varPart + "; " + condPart + "; " + stepPart)];
1168
+ };
1169
+
1170
+ Range.prototype.compileArray = function(o) {
1171
+ var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results;
1172
+ if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
1173
+ range = (function() {
1174
+ _results = [];
1175
+ for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); }
1176
+ return _results;
1177
+ }).apply(this);
1178
+ if (this.exclusive) {
1179
+ range.pop();
1180
+ }
1181
+ return [this.makeCode("[" + (range.join(', ')) + "]")];
1182
+ }
1183
+ idt = this.tab + TAB;
1184
+ i = o.scope.freeVariable('i');
1185
+ result = o.scope.freeVariable('results');
1186
+ pre = "\n" + idt + result + " = [];";
1187
+ if (this.fromNum && this.toNum) {
1188
+ o.index = i;
1189
+ body = fragmentsToText(this.compileNode(o));
1190
+ } else {
1191
+ vars = ("" + i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : '');
1192
+ cond = "" + this.fromVar + " <= " + this.toVar;
1193
+ body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";
1194
+ }
1195
+ post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
1196
+ hasArgs = function(node) {
1197
+ return node != null ? node.contains(isLiteralArguments) : void 0;
1198
+ };
1199
+ if (hasArgs(this.from) || hasArgs(this.to)) {
1200
+ args = ', arguments';
1201
+ }
1202
+ return [this.makeCode("(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")")];
1203
+ };
1204
+
1205
+ return Range;
1206
+
1207
+ })(Base);
1208
+
1209
+ exports.Slice = Slice = (function(_super) {
1210
+ __extends(Slice, _super);
1211
+
1212
+ Slice.prototype.children = ['range'];
1213
+
1214
+ function Slice(range) {
1215
+ this.range = range;
1216
+ Slice.__super__.constructor.call(this);
1217
+ }
1218
+
1219
+ Slice.prototype.compileNode = function(o) {
1220
+ var compiled, compiledText, from, fromCompiled, to, toStr, _ref2;
1221
+ _ref2 = this.range, to = _ref2.to, from = _ref2.from;
1222
+ fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')];
1223
+ if (to) {
1224
+ compiled = to.compileToFragments(o, LEVEL_PAREN);
1225
+ compiledText = fragmentsToText(compiled);
1226
+ if (!(!this.range.exclusive && +compiledText === -1)) {
1227
+ toStr = ', ' + (this.range.exclusive ? compiledText : SIMPLENUM.test(compiledText) ? "" + (+compiledText + 1) : (compiled = to.compileToFragments(o, LEVEL_ACCESS), "+" + (fragmentsToText(compiled)) + " + 1 || 9e9"));
1228
+ }
1229
+ }
1230
+ return [this.makeCode(".slice(" + (fragmentsToText(fromCompiled)) + (toStr || '') + ")")];
1231
+ };
1232
+
1233
+ return Slice;
1234
+
1235
+ })(Base);
1236
+
1237
+ exports.Obj = Obj = (function(_super) {
1238
+ __extends(Obj, _super);
1239
+
1240
+ function Obj(props, generated) {
1241
+ this.generated = generated != null ? generated : false;
1242
+ this.objects = this.properties = props || [];
1243
+ }
1244
+
1245
+ Obj.prototype.children = ['properties'];
1246
+
1247
+ Obj.prototype.compileNode = function(o) {
1248
+ var answer, i, idt, indent, join, lastNoncom, node, prop, props, _i, _j, _len, _len1;
1249
+ props = this.properties;
1250
+ if (!props.length) {
1251
+ return [this.makeCode(this.front ? '({})' : '{}')];
1252
+ }
1253
+ if (this.generated) {
1254
+ for (_i = 0, _len = props.length; _i < _len; _i++) {
1255
+ node = props[_i];
1256
+ if (node instanceof Value) {
1257
+ node.error('cannot have an implicit value in an implicit object');
1258
+ }
1259
+ }
1260
+ }
1261
+ idt = o.indent += TAB;
1262
+ lastNoncom = this.lastNonComment(this.properties);
1263
+ answer = [];
1264
+ for (i = _j = 0, _len1 = props.length; _j < _len1; i = ++_j) {
1265
+ prop = props[i];
1266
+ join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
1267
+ indent = prop instanceof Comment ? '' : idt;
1268
+ if (prop instanceof Assign && prop.variable instanceof Value && prop.variable.hasProperties()) {
1269
+ prop.variable.error('Invalid object key');
1270
+ }
1271
+ if (prop instanceof Value && prop["this"]) {
1272
+ prop = new Assign(prop.properties[0].name, prop, 'object');
1273
+ }
1274
+ if (!(prop instanceof Comment)) {
1275
+ if (!(prop instanceof Assign)) {
1276
+ prop = new Assign(prop, prop, 'object');
1277
+ }
1278
+ (prop.variable.base || prop.variable).asKey = true;
1279
+ }
1280
+ if (indent) {
1281
+ answer.push(this.makeCode(indent));
1282
+ }
1283
+ answer.push.apply(answer, prop.compileToFragments(o, LEVEL_TOP));
1284
+ if (join) {
1285
+ answer.push(this.makeCode(join));
1286
+ }
1287
+ }
1288
+ answer.unshift(this.makeCode("{" + (props.length && '\n')));
1289
+ answer.push(this.makeCode("" + (props.length && '\n' + this.tab) + "}"));
1290
+ if (this.front) {
1291
+ return this.wrapInBraces(answer);
1292
+ } else {
1293
+ return answer;
1294
+ }
1295
+ };
1296
+
1297
+ Obj.prototype.assigns = function(name) {
1298
+ var prop, _i, _len, _ref2;
1299
+ _ref2 = this.properties;
1300
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1301
+ prop = _ref2[_i];
1302
+ if (prop.assigns(name)) {
1303
+ return true;
1304
+ }
1305
+ }
1306
+ return false;
1307
+ };
1308
+
1309
+ return Obj;
1310
+
1311
+ })(Base);
1312
+
1313
+ exports.Arr = Arr = (function(_super) {
1314
+ __extends(Arr, _super);
1315
+
1316
+ function Arr(objs) {
1317
+ this.objects = objs || [];
1318
+ }
1319
+
1320
+ Arr.prototype.children = ['objects'];
1321
+
1322
+ Arr.prototype.compileNode = function(o) {
1323
+ var answer, compiledObjs, fragments, index, obj, _i, _len;
1324
+ if (!this.objects.length) {
1325
+ return [this.makeCode('[]')];
1326
+ }
1327
+ o.indent += TAB;
1328
+ answer = Splat.compileSplattedArray(o, this.objects);
1329
+ if (answer.length) {
1330
+ return answer;
1331
+ }
1332
+ answer = [];
1333
+ compiledObjs = (function() {
1334
+ var _i, _len, _ref2, _results;
1335
+ _ref2 = this.objects;
1336
+ _results = [];
1337
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1338
+ obj = _ref2[_i];
1339
+ _results.push(obj.compileToFragments(o, LEVEL_LIST));
1340
+ }
1341
+ return _results;
1342
+ }).call(this);
1343
+ for (index = _i = 0, _len = compiledObjs.length; _i < _len; index = ++_i) {
1344
+ fragments = compiledObjs[index];
1345
+ if (index) {
1346
+ answer.push(this.makeCode(", "));
1347
+ }
1348
+ answer.push.apply(answer, fragments);
1349
+ }
1350
+ if (fragmentsToText(answer).indexOf('\n') >= 0) {
1351
+ answer.unshift(this.makeCode("[\n" + o.indent));
1352
+ answer.push(this.makeCode("\n" + this.tab + "]"));
1353
+ } else {
1354
+ answer.unshift(this.makeCode("["));
1355
+ answer.push(this.makeCode("]"));
1356
+ }
1357
+ return answer;
1358
+ };
1359
+
1360
+ Arr.prototype.assigns = function(name) {
1361
+ var obj, _i, _len, _ref2;
1362
+ _ref2 = this.objects;
1363
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1364
+ obj = _ref2[_i];
1365
+ if (obj.assigns(name)) {
1366
+ return true;
1367
+ }
1368
+ }
1369
+ return false;
1370
+ };
1371
+
1372
+ return Arr;
1373
+
1374
+ })(Base);
1375
+
1376
+ exports.Class = Class = (function(_super) {
1377
+ __extends(Class, _super);
1378
+
1379
+ function Class(variable, parent, body) {
1380
+ this.variable = variable;
1381
+ this.parent = parent;
1382
+ this.body = body != null ? body : new Block;
1383
+ this.boundFuncs = [];
1384
+ this.body.classBody = true;
1385
+ }
1386
+
1387
+ Class.prototype.children = ['variable', 'parent', 'body'];
1388
+
1389
+ Class.prototype.determineName = function() {
1390
+ var decl, tail;
1391
+ if (!this.variable) {
1392
+ return null;
1393
+ }
1394
+ decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
1395
+ if (__indexOf.call(STRICT_PROSCRIBED, decl) >= 0) {
1396
+ this.variable.error("class variable name may not be " + decl);
1397
+ }
1398
+ return decl && (decl = IDENTIFIER.test(decl) && decl);
1399
+ };
1400
+
1401
+ Class.prototype.setContext = function(name) {
1402
+ return this.body.traverseChildren(false, function(node) {
1403
+ if (node.classBody) {
1404
+ return false;
1405
+ }
1406
+ if (node instanceof Literal && node.value === 'this') {
1407
+ return node.value = name;
1408
+ } else if (node instanceof Code) {
1409
+ node.klass = name;
1410
+ if (node.bound) {
1411
+ return node.context = name;
1412
+ }
1413
+ }
1414
+ });
1415
+ };
1416
+
1417
+ Class.prototype.addBoundFunctions = function(o) {
1418
+ var bvar, lhs, _i, _len, _ref2;
1419
+ _ref2 = this.boundFuncs;
1420
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1421
+ bvar = _ref2[_i];
1422
+ lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);
1423
+ this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)"));
1424
+ }
1425
+ };
1426
+
1427
+ Class.prototype.addProperties = function(node, name, o) {
1428
+ var assign, base, exprs, func, props;
1429
+ props = node.base.properties.slice(0);
1430
+ exprs = (function() {
1431
+ var _results;
1432
+ _results = [];
1433
+ while (assign = props.shift()) {
1434
+ if (assign instanceof Assign) {
1435
+ base = assign.variable.base;
1436
+ delete assign.context;
1437
+ func = assign.value;
1438
+ if (base.value === 'constructor') {
1439
+ if (this.ctor) {
1440
+ assign.error('cannot define more than one constructor in a class');
1441
+ }
1442
+ if (func.bound) {
1443
+ assign.error('cannot define a constructor as a bound function');
1444
+ }
1445
+ if (func instanceof Code) {
1446
+ assign = this.ctor = func;
1447
+ } else {
1448
+ this.externalCtor = o.classScope.freeVariable('class');
1449
+ assign = new Assign(new Literal(this.externalCtor), func);
1450
+ }
1451
+ } else {
1452
+ if (assign.variable["this"]) {
1453
+ func["static"] = true;
1454
+ } else {
1455
+ assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]);
1456
+ if (func instanceof Code && func.bound) {
1457
+ this.boundFuncs.push(base);
1458
+ func.bound = false;
1459
+ }
1460
+ }
1461
+ }
1462
+ }
1463
+ _results.push(assign);
1464
+ }
1465
+ return _results;
1466
+ }).call(this);
1467
+ return compact(exprs);
1468
+ };
1469
+
1470
+ Class.prototype.walkBody = function(name, o) {
1471
+ return this.traverseChildren(false, (function(_this) {
1472
+ return function(child) {
1473
+ var cont, exps, i, node, _i, _len, _ref2;
1474
+ cont = true;
1475
+ if (child instanceof Class) {
1476
+ return false;
1477
+ }
1478
+ if (child instanceof Block) {
1479
+ _ref2 = exps = child.expressions;
1480
+ for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
1481
+ node = _ref2[i];
1482
+ if (node instanceof Assign && node.variable.looksStatic(name)) {
1483
+ node.value["static"] = true;
1484
+ } else if (node instanceof Value && node.isObject(true)) {
1485
+ cont = false;
1486
+ exps[i] = _this.addProperties(node, name, o);
1487
+ }
1488
+ }
1489
+ child.expressions = exps = flatten(exps);
1490
+ }
1491
+ return cont && !(child instanceof Class);
1492
+ };
1493
+ })(this));
1494
+ };
1495
+
1496
+ Class.prototype.hoistDirectivePrologue = function() {
1497
+ var expressions, index, node;
1498
+ index = 0;
1499
+ expressions = this.body.expressions;
1500
+ while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
1501
+ ++index;
1502
+ }
1503
+ return this.directives = expressions.splice(0, index);
1504
+ };
1505
+
1506
+ Class.prototype.ensureConstructor = function(name) {
1507
+ if (!this.ctor) {
1508
+ this.ctor = new Code;
1509
+ if (this.externalCtor) {
1510
+ this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
1511
+ } else if (this.parent) {
1512
+ this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)"));
1513
+ }
1514
+ this.ctor.body.makeReturn();
1515
+ this.body.expressions.unshift(this.ctor);
1516
+ }
1517
+ this.ctor.ctor = this.ctor.name = name;
1518
+ this.ctor.klass = null;
1519
+ return this.ctor.noReturn = true;
1520
+ };
1521
+
1522
+ Class.prototype.compileNode = function(o) {
1523
+ var args, argumentsNode, func, jumpNode, klass, lname, name, superClass, _ref2;
1524
+ if (jumpNode = this.body.jumps()) {
1525
+ jumpNode.error('Class bodies cannot contain pure statements');
1526
+ }
1527
+ if (argumentsNode = this.body.contains(isLiteralArguments)) {
1528
+ argumentsNode.error("Class bodies shouldn't reference arguments");
1529
+ }
1530
+ name = this.determineName() || '_Class';
1531
+ if (name.reserved) {
1532
+ name = "_" + name;
1533
+ }
1534
+ lname = new Literal(name);
1535
+ func = new Code([], Block.wrap([this.body]));
1536
+ args = [];
1537
+ o.classScope = func.makeScope(o.scope);
1538
+ this.hoistDirectivePrologue();
1539
+ this.setContext(name);
1540
+ this.walkBody(name, o);
1541
+ this.ensureConstructor(name);
1542
+ this.addBoundFunctions(o);
1543
+ this.body.spaced = true;
1544
+ this.body.expressions.push(lname);
1545
+ if (this.parent) {
1546
+ superClass = new Literal(o.classScope.freeVariable('super', false));
1547
+ this.body.expressions.unshift(new Extends(lname, superClass));
1548
+ func.params.push(new Param(superClass));
1549
+ args.push(this.parent);
1550
+ }
1551
+ (_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
1552
+ klass = new Parens(new Call(func, args));
1553
+ if (this.variable) {
1554
+ klass = new Assign(this.variable, klass);
1555
+ }
1556
+ return klass.compileToFragments(o);
1557
+ };
1558
+
1559
+ return Class;
1560
+
1561
+ })(Base);
1562
+
1563
+ exports.Assign = Assign = (function(_super) {
1564
+ __extends(Assign, _super);
1565
+
1566
+ function Assign(variable, value, context, options) {
1567
+ var forbidden, name, _ref2;
1568
+ this.variable = variable;
1569
+ this.value = value;
1570
+ this.context = context;
1571
+ this.param = options && options.param;
1572
+ this.subpattern = options && options.subpattern;
1573
+ forbidden = (_ref2 = (name = this.variable.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0);
1574
+ if (forbidden && this.context !== 'object') {
1575
+ this.variable.error("variable name may not be \"" + name + "\"");
1576
+ }
1577
+ }
1578
+
1579
+ Assign.prototype.children = ['variable', 'value'];
1580
+
1581
+ Assign.prototype.isStatement = function(o) {
1582
+ return (o != null ? o.level : void 0) === LEVEL_TOP && (this.context != null) && __indexOf.call(this.context, "?") >= 0;
1583
+ };
1584
+
1585
+ Assign.prototype.assigns = function(name) {
1586
+ return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
1587
+ };
1588
+
1589
+ Assign.prototype.unfoldSoak = function(o) {
1590
+ return unfoldSoak(o, this, 'variable');
1591
+ };
1592
+
1593
+ Assign.prototype.compileNode = function(o) {
1594
+ var answer, compiledName, isValue, match, name, val, varBase, _ref2, _ref3, _ref4, _ref5;
1595
+ if (isValue = this.variable instanceof Value) {
1596
+ if (this.variable.isArray() || this.variable.isObject()) {
1597
+ return this.compilePatternMatch(o);
1598
+ }
1599
+ if (this.variable.isSplice()) {
1600
+ return this.compileSplice(o);
1601
+ }
1602
+ if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') {
1603
+ return this.compileConditional(o);
1604
+ }
1605
+ if ((_ref3 = this.context) === '**=' || _ref3 === '//=' || _ref3 === '%%=') {
1606
+ return this.compileSpecialMath(o);
1607
+ }
1608
+ }
1609
+ compiledName = this.variable.compileToFragments(o, LEVEL_LIST);
1610
+ name = fragmentsToText(compiledName);
1611
+ if (!this.context) {
1612
+ varBase = this.variable.unwrapAll();
1613
+ if (!varBase.isAssignable()) {
1614
+ this.variable.error("\"" + (this.variable.compile(o)) + "\" cannot be assigned");
1615
+ }
1616
+ if (!(typeof varBase.hasProperties === "function" ? varBase.hasProperties() : void 0)) {
1617
+ if (this.param) {
1618
+ o.scope.add(name, 'var');
1619
+ } else {
1620
+ o.scope.find(name);
1621
+ }
1622
+ }
1623
+ }
1624
+ if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {
1625
+ if (match[2]) {
1626
+ this.value.klass = match[1];
1627
+ }
1628
+ this.value.name = (_ref4 = (_ref5 = match[3]) != null ? _ref5 : match[4]) != null ? _ref4 : match[5];
1629
+ }
1630
+ val = this.value.compileToFragments(o, LEVEL_LIST);
1631
+ if (this.context === 'object') {
1632
+ return compiledName.concat(this.makeCode(": "), val);
1633
+ }
1634
+ answer = compiledName.concat(this.makeCode(" " + (this.context || '=') + " "), val);
1635
+ if (o.level <= LEVEL_LIST) {
1636
+ return answer;
1637
+ } else {
1638
+ return this.wrapInBraces(answer);
1639
+ }
1640
+ };
1641
+
1642
+ Assign.prototype.compilePatternMatch = function(o) {
1643
+ var acc, assigns, code, expandedIdx, fragments, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, top, val, value, vvar, vvarText, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
1644
+ top = o.level === LEVEL_TOP;
1645
+ value = this.value;
1646
+ objects = this.variable.base.objects;
1647
+ if (!(olen = objects.length)) {
1648
+ code = value.compileToFragments(o);
1649
+ if (o.level >= LEVEL_OP) {
1650
+ return this.wrapInBraces(code);
1651
+ } else {
1652
+ return code;
1653
+ }
1654
+ }
1655
+ isObject = this.variable.isObject();
1656
+ if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
1657
+ if (obj instanceof Assign) {
1658
+ _ref2 = obj, (_ref3 = _ref2.variable, idx = _ref3.base), obj = _ref2.value;
1659
+ } else {
1660
+ idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
1661
+ }
1662
+ acc = IDENTIFIER.test(idx.unwrap().value || 0);
1663
+ value = new Value(value);
1664
+ value.properties.push(new (acc ? Access : Index)(idx));
1665
+ if (_ref4 = obj.unwrap().value, __indexOf.call(RESERVED, _ref4) >= 0) {
1666
+ obj.error("assignment to a reserved word: " + (obj.compile(o)));
1667
+ }
1668
+ return new Assign(obj, value, null, {
1669
+ param: this.param
1670
+ }).compileToFragments(o, LEVEL_TOP);
1671
+ }
1672
+ vvar = value.compileToFragments(o, LEVEL_LIST);
1673
+ vvarText = fragmentsToText(vvar);
1674
+ assigns = [];
1675
+ expandedIdx = false;
1676
+ if (!IDENTIFIER.test(vvarText) || this.variable.assigns(vvarText)) {
1677
+ assigns.push([this.makeCode("" + (ref = o.scope.freeVariable('ref')) + " = ")].concat(__slice.call(vvar)));
1678
+ vvar = [this.makeCode(ref)];
1679
+ vvarText = ref;
1680
+ }
1681
+ for (i = _i = 0, _len = objects.length; _i < _len; i = ++_i) {
1682
+ obj = objects[i];
1683
+ idx = i;
1684
+ if (isObject) {
1685
+ if (obj instanceof Assign) {
1686
+ _ref5 = obj, (_ref6 = _ref5.variable, idx = _ref6.base), obj = _ref5.value;
1687
+ } else {
1688
+ if (obj.base instanceof Parens) {
1689
+ _ref7 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref7[0], idx = _ref7[1];
1690
+ } else {
1691
+ idx = obj["this"] ? obj.properties[0].name : obj;
1692
+ }
1693
+ }
1694
+ }
1695
+ if (!expandedIdx && obj instanceof Splat) {
1696
+ name = obj.name.unwrap().value;
1697
+ obj = obj.unwrap();
1698
+ val = "" + olen + " <= " + vvarText + ".length ? " + (utility('slice')) + ".call(" + vvarText + ", " + i;
1699
+ if (rest = olen - i - 1) {
1700
+ ivar = o.scope.freeVariable('i');
1701
+ val += ", " + ivar + " = " + vvarText + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";
1702
+ } else {
1703
+ val += ") : []";
1704
+ }
1705
+ val = new Literal(val);
1706
+ expandedIdx = "" + ivar + "++";
1707
+ } else if (!expandedIdx && obj instanceof Expansion) {
1708
+ if (rest = olen - i - 1) {
1709
+ if (rest === 1) {
1710
+ expandedIdx = "" + vvarText + ".length - 1";
1711
+ } else {
1712
+ ivar = o.scope.freeVariable('i');
1713
+ val = new Literal("" + ivar + " = " + vvarText + ".length - " + rest);
1714
+ expandedIdx = "" + ivar + "++";
1715
+ assigns.push(val.compileToFragments(o, LEVEL_LIST));
1716
+ }
1717
+ }
1718
+ continue;
1719
+ } else {
1720
+ name = obj.unwrap().value;
1721
+ if (obj instanceof Splat || obj instanceof Expansion) {
1722
+ obj.error("multiple splats/expansions are disallowed in an assignment");
1723
+ }
1724
+ if (typeof idx === 'number') {
1725
+ idx = new Literal(expandedIdx || idx);
1726
+ acc = false;
1727
+ } else {
1728
+ acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
1729
+ }
1730
+ val = new Value(new Literal(vvarText), [new (acc ? Access : Index)(idx)]);
1731
+ }
1732
+ if ((name != null) && __indexOf.call(RESERVED, name) >= 0) {
1733
+ obj.error("assignment to a reserved word: " + (obj.compile(o)));
1734
+ }
1735
+ assigns.push(new Assign(obj, val, null, {
1736
+ param: this.param,
1737
+ subpattern: true
1738
+ }).compileToFragments(o, LEVEL_LIST));
1739
+ }
1740
+ if (!(top || this.subpattern)) {
1741
+ assigns.push(vvar);
1742
+ }
1743
+ fragments = this.joinFragmentArrays(assigns, ', ');
1744
+ if (o.level < LEVEL_LIST) {
1745
+ return fragments;
1746
+ } else {
1747
+ return this.wrapInBraces(fragments);
1748
+ }
1749
+ };
1750
+
1751
+ Assign.prototype.compileConditional = function(o) {
1752
+ var fragments, left, right, _ref2;
1753
+ _ref2 = this.variable.cacheReference(o), left = _ref2[0], right = _ref2[1];
1754
+ if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {
1755
+ this.variable.error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been declared before");
1756
+ }
1757
+ if (__indexOf.call(this.context, "?") >= 0) {
1758
+ o.isExistentialEquals = true;
1759
+ return new If(new Existence(left), right, {
1760
+ type: 'if'
1761
+ }).addElse(new Assign(right, this.value, '=')).compileToFragments(o);
1762
+ } else {
1763
+ fragments = new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compileToFragments(o);
1764
+ if (o.level <= LEVEL_LIST) {
1765
+ return fragments;
1766
+ } else {
1767
+ return this.wrapInBraces(fragments);
1768
+ }
1769
+ }
1770
+ };
1771
+
1772
+ Assign.prototype.compileSpecialMath = function(o) {
1773
+ var left, right, _ref2;
1774
+ _ref2 = this.variable.cacheReference(o), left = _ref2[0], right = _ref2[1];
1775
+ return new Assign(left, new Op(this.context.slice(0, -1), right, this.value)).compileToFragments(o);
1776
+ };
1777
+
1778
+ Assign.prototype.compileSplice = function(o) {
1779
+ var answer, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
1780
+ _ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive;
1781
+ name = this.variable.compile(o);
1782
+ if (from) {
1783
+ _ref3 = this.cacheToCodeFragments(from.cache(o, LEVEL_OP)), fromDecl = _ref3[0], fromRef = _ref3[1];
1784
+ } else {
1785
+ fromDecl = fromRef = '0';
1786
+ }
1787
+ if (to) {
1788
+ if (from instanceof Value && from.isSimpleNumber() && to instanceof Value && to.isSimpleNumber()) {
1789
+ to = to.compile(o) - fromRef;
1790
+ if (!exclusive) {
1791
+ to += 1;
1792
+ }
1793
+ } else {
1794
+ to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;
1795
+ if (!exclusive) {
1796
+ to += ' + 1';
1797
+ }
1798
+ }
1799
+ } else {
1800
+ to = "9e9";
1801
+ }
1802
+ _ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1];
1803
+ answer = [].concat(this.makeCode("[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat("), valDef, this.makeCode(")), "), valRef);
1804
+ if (o.level > LEVEL_TOP) {
1805
+ return this.wrapInBraces(answer);
1806
+ } else {
1807
+ return answer;
1808
+ }
1809
+ };
1810
+
1811
+ return Assign;
1812
+
1813
+ })(Base);
1814
+
1815
+ exports.Code = Code = (function(_super) {
1816
+ __extends(Code, _super);
1817
+
1818
+ function Code(params, body, tag) {
1819
+ this.params = params || [];
1820
+ this.body = body || new Block;
1821
+ this.bound = tag === 'boundfunc';
1822
+ }
1823
+
1824
+ Code.prototype.children = ['params', 'body'];
1825
+
1826
+ Code.prototype.isStatement = function() {
1827
+ return !!this.ctor;
1828
+ };
1829
+
1830
+ Code.prototype.jumps = NO;
1831
+
1832
+ Code.prototype.makeScope = function(parentScope) {
1833
+ return new Scope(parentScope, this.body, this);
1834
+ };
1835
+
1836
+ Code.prototype.compileNode = function(o) {
1837
+ var answer, boundfunc, code, exprs, i, lit, p, param, params, ref, splats, uniqs, val, wasEmpty, wrapper, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
1838
+ if (this.bound && ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0)) {
1839
+ this.context = o.scope.method.context;
1840
+ }
1841
+ if (this.bound && !this.context) {
1842
+ this.context = '_this';
1843
+ wrapper = new Code([new Param(new Literal(this.context))], new Block([this]));
1844
+ boundfunc = new Call(wrapper, [new Literal('this')]);
1845
+ boundfunc.updateLocationDataIfMissing(this.locationData);
1846
+ return boundfunc.compileNode(o);
1847
+ }
1848
+ o.scope = del(o, 'classScope') || this.makeScope(o.scope);
1849
+ o.scope.shared = del(o, 'sharedScope');
1850
+ o.indent += TAB;
1851
+ delete o.bare;
1852
+ delete o.isExistentialEquals;
1853
+ params = [];
1854
+ exprs = [];
1855
+ _ref3 = this.params;
1856
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
1857
+ param = _ref3[_i];
1858
+ if (!(param instanceof Expansion)) {
1859
+ o.scope.parameter(param.asReference(o));
1860
+ }
1861
+ }
1862
+ _ref4 = this.params;
1863
+ for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
1864
+ param = _ref4[_j];
1865
+ if (!(param.splat || param instanceof Expansion)) {
1866
+ continue;
1867
+ }
1868
+ _ref5 = this.params;
1869
+ for (_k = 0, _len2 = _ref5.length; _k < _len2; _k++) {
1870
+ p = _ref5[_k].name;
1871
+ if (!(!(param instanceof Expansion))) {
1872
+ continue;
1873
+ }
1874
+ if (p["this"]) {
1875
+ p = p.properties[0].name;
1876
+ }
1877
+ if (p.value) {
1878
+ o.scope.add(p.value, 'var', true);
1879
+ }
1880
+ }
1881
+ splats = new Assign(new Value(new Arr((function() {
1882
+ var _l, _len3, _ref6, _results;
1883
+ _ref6 = this.params;
1884
+ _results = [];
1885
+ for (_l = 0, _len3 = _ref6.length; _l < _len3; _l++) {
1886
+ p = _ref6[_l];
1887
+ _results.push(p.asReference(o));
1888
+ }
1889
+ return _results;
1890
+ }).call(this))), new Value(new Literal('arguments')));
1891
+ break;
1892
+ }
1893
+ _ref6 = this.params;
1894
+ for (_l = 0, _len3 = _ref6.length; _l < _len3; _l++) {
1895
+ param = _ref6[_l];
1896
+ if (param.isComplex()) {
1897
+ val = ref = param.asReference(o);
1898
+ if (param.value) {
1899
+ val = new Op('?', ref, param.value);
1900
+ }
1901
+ exprs.push(new Assign(new Value(param.name), val, '=', {
1902
+ param: true
1903
+ }));
1904
+ } else {
1905
+ ref = param;
1906
+ if (param.value) {
1907
+ lit = new Literal(ref.name.value + ' == null');
1908
+ val = new Assign(new Value(param.name), param.value, '=');
1909
+ exprs.push(new If(lit, val));
1910
+ }
1911
+ }
1912
+ if (!splats) {
1913
+ params.push(ref);
1914
+ }
1915
+ }
1916
+ wasEmpty = this.body.isEmpty();
1917
+ if (splats) {
1918
+ exprs.unshift(splats);
1919
+ }
1920
+ if (exprs.length) {
1921
+ (_ref7 = this.body.expressions).unshift.apply(_ref7, exprs);
1922
+ }
1923
+ for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {
1924
+ p = params[i];
1925
+ params[i] = p.compileToFragments(o);
1926
+ o.scope.parameter(fragmentsToText(params[i]));
1927
+ }
1928
+ uniqs = [];
1929
+ this.eachParamName(function(name, node) {
1930
+ if (__indexOf.call(uniqs, name) >= 0) {
1931
+ node.error("multiple parameters named '" + name + "'");
1932
+ }
1933
+ return uniqs.push(name);
1934
+ });
1935
+ if (!(wasEmpty || this.noReturn)) {
1936
+ this.body.makeReturn();
1937
+ }
1938
+ code = 'function';
1939
+ if (this.ctor) {
1940
+ code += ' ' + this.name;
1941
+ }
1942
+ code += '(';
1943
+ answer = [this.makeCode(code)];
1944
+ for (i = _n = 0, _len5 = params.length; _n < _len5; i = ++_n) {
1945
+ p = params[i];
1946
+ if (i) {
1947
+ answer.push(this.makeCode(", "));
1948
+ }
1949
+ answer.push.apply(answer, p);
1950
+ }
1951
+ answer.push(this.makeCode(') {'));
1952
+ if (!this.body.isEmpty()) {
1953
+ answer = answer.concat(this.makeCode("\n"), this.body.compileWithDeclarations(o), this.makeCode("\n" + this.tab));
1954
+ }
1955
+ answer.push(this.makeCode('}'));
1956
+ if (this.ctor) {
1957
+ return [this.makeCode(this.tab)].concat(__slice.call(answer));
1958
+ }
1959
+ if (this.front || (o.level >= LEVEL_ACCESS)) {
1960
+ return this.wrapInBraces(answer);
1961
+ } else {
1962
+ return answer;
1963
+ }
1964
+ };
1965
+
1966
+ Code.prototype.eachParamName = function(iterator) {
1967
+ var param, _i, _len, _ref2, _results;
1968
+ _ref2 = this.params;
1969
+ _results = [];
1970
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1971
+ param = _ref2[_i];
1972
+ _results.push(param.eachName(iterator));
1973
+ }
1974
+ return _results;
1975
+ };
1976
+
1977
+ Code.prototype.traverseChildren = function(crossScope, func) {
1978
+ if (crossScope) {
1979
+ return Code.__super__.traverseChildren.call(this, crossScope, func);
1980
+ }
1981
+ };
1982
+
1983
+ return Code;
1984
+
1985
+ })(Base);
1986
+
1987
+ exports.Param = Param = (function(_super) {
1988
+ __extends(Param, _super);
1989
+
1990
+ function Param(name, value, splat) {
1991
+ var _ref2;
1992
+ this.name = name;
1993
+ this.value = value;
1994
+ this.splat = splat;
1995
+ if (_ref2 = (name = this.name.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
1996
+ this.name.error("parameter name \"" + name + "\" is not allowed");
1997
+ }
1998
+ }
1999
+
2000
+ Param.prototype.children = ['name', 'value'];
2001
+
2002
+ Param.prototype.compileToFragments = function(o) {
2003
+ return this.name.compileToFragments(o, LEVEL_LIST);
2004
+ };
2005
+
2006
+ Param.prototype.asReference = function(o) {
2007
+ var node;
2008
+ if (this.reference) {
2009
+ return this.reference;
2010
+ }
2011
+ node = this.name;
2012
+ if (node["this"]) {
2013
+ node = node.properties[0].name;
2014
+ if (node.value.reserved) {
2015
+ node = new Literal(o.scope.freeVariable(node.value));
2016
+ }
2017
+ } else if (node.isComplex()) {
2018
+ node = new Literal(o.scope.freeVariable('arg'));
2019
+ }
2020
+ node = new Value(node);
2021
+ if (this.splat) {
2022
+ node = new Splat(node);
2023
+ }
2024
+ node.updateLocationDataIfMissing(this.locationData);
2025
+ return this.reference = node;
2026
+ };
2027
+
2028
+ Param.prototype.isComplex = function() {
2029
+ return this.name.isComplex();
2030
+ };
2031
+
2032
+ Param.prototype.eachName = function(iterator, name) {
2033
+ var atParam, node, obj, _i, _len, _ref2;
2034
+ if (name == null) {
2035
+ name = this.name;
2036
+ }
2037
+ atParam = function(obj) {
2038
+ var node;
2039
+ node = obj.properties[0].name;
2040
+ if (!node.value.reserved) {
2041
+ return iterator(node.value, node);
2042
+ }
2043
+ };
2044
+ if (name instanceof Literal) {
2045
+ return iterator(name.value, name);
2046
+ }
2047
+ if (name instanceof Value) {
2048
+ return atParam(name);
2049
+ }
2050
+ _ref2 = name.objects;
2051
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2052
+ obj = _ref2[_i];
2053
+ if (obj instanceof Assign) {
2054
+ this.eachName(iterator, obj.value.unwrap());
2055
+ } else if (obj instanceof Splat) {
2056
+ node = obj.name.unwrap();
2057
+ iterator(node.value, node);
2058
+ } else if (obj instanceof Value) {
2059
+ if (obj.isArray() || obj.isObject()) {
2060
+ this.eachName(iterator, obj.base);
2061
+ } else if (obj["this"]) {
2062
+ atParam(obj);
2063
+ } else {
2064
+ iterator(obj.base.value, obj.base);
2065
+ }
2066
+ } else if (!(obj instanceof Expansion)) {
2067
+ obj.error("illegal parameter " + (obj.compile()));
2068
+ }
2069
+ }
2070
+ };
2071
+
2072
+ return Param;
2073
+
2074
+ })(Base);
2075
+
2076
+ exports.Splat = Splat = (function(_super) {
2077
+ __extends(Splat, _super);
2078
+
2079
+ Splat.prototype.children = ['name'];
2080
+
2081
+ Splat.prototype.isAssignable = YES;
2082
+
2083
+ function Splat(name) {
2084
+ this.name = name.compile ? name : new Literal(name);
2085
+ }
2086
+
2087
+ Splat.prototype.assigns = function(name) {
2088
+ return this.name.assigns(name);
2089
+ };
2090
+
2091
+ Splat.prototype.compileToFragments = function(o) {
2092
+ return this.name.compileToFragments(o);
2093
+ };
2094
+
2095
+ Splat.prototype.unwrap = function() {
2096
+ return this.name;
2097
+ };
2098
+
2099
+ Splat.compileSplattedArray = function(o, list, apply) {
2100
+ var args, base, compiledNode, concatPart, fragments, i, index, node, _i, _len;
2101
+ index = -1;
2102
+ while ((node = list[++index]) && !(node instanceof Splat)) {
2103
+ continue;
2104
+ }
2105
+ if (index >= list.length) {
2106
+ return [];
2107
+ }
2108
+ if (list.length === 1) {
2109
+ node = list[0];
2110
+ fragments = node.compileToFragments(o, LEVEL_LIST);
2111
+ if (apply) {
2112
+ return fragments;
2113
+ }
2114
+ return [].concat(node.makeCode("" + (utility('slice')) + ".call("), fragments, node.makeCode(")"));
2115
+ }
2116
+ args = list.slice(index);
2117
+ for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
2118
+ node = args[i];
2119
+ compiledNode = node.compileToFragments(o, LEVEL_LIST);
2120
+ args[i] = node instanceof Splat ? [].concat(node.makeCode("" + (utility('slice')) + ".call("), compiledNode, node.makeCode(")")) : [].concat(node.makeCode("["), compiledNode, node.makeCode("]"));
2121
+ }
2122
+ if (index === 0) {
2123
+ node = list[0];
2124
+ concatPart = node.joinFragmentArrays(args.slice(1), ', ');
2125
+ return args[0].concat(node.makeCode(".concat("), concatPart, node.makeCode(")"));
2126
+ }
2127
+ base = (function() {
2128
+ var _j, _len1, _ref2, _results;
2129
+ _ref2 = list.slice(0, index);
2130
+ _results = [];
2131
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
2132
+ node = _ref2[_j];
2133
+ _results.push(node.compileToFragments(o, LEVEL_LIST));
2134
+ }
2135
+ return _results;
2136
+ })();
2137
+ base = list[0].joinFragmentArrays(base, ', ');
2138
+ concatPart = list[index].joinFragmentArrays(args, ', ');
2139
+ return [].concat(list[0].makeCode("["), base, list[index].makeCode("].concat("), concatPart, (last(list)).makeCode(")"));
2140
+ };
2141
+
2142
+ return Splat;
2143
+
2144
+ })(Base);
2145
+
2146
+ exports.Expansion = Expansion = (function(_super) {
2147
+ __extends(Expansion, _super);
2148
+
2149
+ function Expansion() {
2150
+ return Expansion.__super__.constructor.apply(this, arguments);
2151
+ }
2152
+
2153
+ Expansion.prototype.isComplex = NO;
2154
+
2155
+ Expansion.prototype.compileNode = function(o) {
2156
+ return this.error('Expansion must be used inside a destructuring assignment or parameter list');
2157
+ };
2158
+
2159
+ Expansion.prototype.asReference = function(o) {
2160
+ return this;
2161
+ };
2162
+
2163
+ Expansion.prototype.eachName = function(iterator) {};
2164
+
2165
+ return Expansion;
2166
+
2167
+ })(Base);
2168
+
2169
+ exports.While = While = (function(_super) {
2170
+ __extends(While, _super);
2171
+
2172
+ function While(condition, options) {
2173
+ this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
2174
+ this.guard = options != null ? options.guard : void 0;
2175
+ }
2176
+
2177
+ While.prototype.children = ['condition', 'guard', 'body'];
2178
+
2179
+ While.prototype.isStatement = YES;
2180
+
2181
+ While.prototype.makeReturn = function(res) {
2182
+ if (res) {
2183
+ return While.__super__.makeReturn.apply(this, arguments);
2184
+ } else {
2185
+ this.returns = !this.jumps({
2186
+ loop: true
2187
+ });
2188
+ return this;
2189
+ }
2190
+ };
2191
+
2192
+ While.prototype.addBody = function(body) {
2193
+ this.body = body;
2194
+ return this;
2195
+ };
2196
+
2197
+ While.prototype.jumps = function() {
2198
+ var expressions, jumpNode, node, _i, _len;
2199
+ expressions = this.body.expressions;
2200
+ if (!expressions.length) {
2201
+ return false;
2202
+ }
2203
+ for (_i = 0, _len = expressions.length; _i < _len; _i++) {
2204
+ node = expressions[_i];
2205
+ if (jumpNode = node.jumps({
2206
+ loop: true
2207
+ })) {
2208
+ return jumpNode;
2209
+ }
2210
+ }
2211
+ return false;
2212
+ };
2213
+
2214
+ While.prototype.compileNode = function(o) {
2215
+ var answer, body, rvar, set;
2216
+ o.indent += TAB;
2217
+ set = '';
2218
+ body = this.body;
2219
+ if (body.isEmpty()) {
2220
+ body = this.makeCode('');
2221
+ } else {
2222
+ if (this.returns) {
2223
+ body.makeReturn(rvar = o.scope.freeVariable('results'));
2224
+ set = "" + this.tab + rvar + " = [];\n";
2225
+ }
2226
+ if (this.guard) {
2227
+ if (body.expressions.length > 1) {
2228
+ body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
2229
+ } else {
2230
+ if (this.guard) {
2231
+ body = Block.wrap([new If(this.guard, body)]);
2232
+ }
2233
+ }
2234
+ }
2235
+ body = [].concat(this.makeCode("\n"), body.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab));
2236
+ }
2237
+ answer = [].concat(this.makeCode(set + this.tab + "while ("), this.condition.compileToFragments(o, LEVEL_PAREN), this.makeCode(") {"), body, this.makeCode("}"));
2238
+ if (this.returns) {
2239
+ answer.push(this.makeCode("\n" + this.tab + "return " + rvar + ";"));
2240
+ }
2241
+ return answer;
2242
+ };
2243
+
2244
+ return While;
2245
+
2246
+ })(Base);
2247
+
2248
+ exports.Op = Op = (function(_super) {
2249
+ var CONVERSIONS, INVERSIONS;
2250
+
2251
+ __extends(Op, _super);
2252
+
2253
+ function Op(op, first, second, flip) {
2254
+ if (op === 'in') {
2255
+ return new In(first, second);
2256
+ }
2257
+ if (op === 'do') {
2258
+ return this.generateDo(first);
2259
+ }
2260
+ if (op === 'new') {
2261
+ if (first instanceof Call && !first["do"] && !first.isNew) {
2262
+ return first.newInstance();
2263
+ }
2264
+ if (first instanceof Code && first.bound || first["do"]) {
2265
+ first = new Parens(first);
2266
+ }
2267
+ }
2268
+ this.operator = CONVERSIONS[op] || op;
2269
+ this.first = first;
2270
+ this.second = second;
2271
+ this.flip = !!flip;
2272
+ return this;
2273
+ }
2274
+
2275
+ CONVERSIONS = {
2276
+ '==': '===',
2277
+ '!=': '!==',
2278
+ 'of': 'in'
2279
+ };
2280
+
2281
+ INVERSIONS = {
2282
+ '!==': '===',
2283
+ '===': '!=='
2284
+ };
2285
+
2286
+ Op.prototype.children = ['first', 'second'];
2287
+
2288
+ Op.prototype.isSimpleNumber = NO;
2289
+
2290
+ Op.prototype.isUnary = function() {
2291
+ return !this.second;
2292
+ };
2293
+
2294
+ Op.prototype.isComplex = function() {
2295
+ var _ref2;
2296
+ return !(this.isUnary() && ((_ref2 = this.operator) === '+' || _ref2 === '-')) || this.first.isComplex();
2297
+ };
2298
+
2299
+ Op.prototype.isChainable = function() {
2300
+ var _ref2;
2301
+ return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!==';
2302
+ };
2303
+
2304
+ Op.prototype.invert = function() {
2305
+ var allInvertable, curr, fst, op, _ref2;
2306
+ if (this.isChainable() && this.first.isChainable()) {
2307
+ allInvertable = true;
2308
+ curr = this;
2309
+ while (curr && curr.operator) {
2310
+ allInvertable && (allInvertable = curr.operator in INVERSIONS);
2311
+ curr = curr.first;
2312
+ }
2313
+ if (!allInvertable) {
2314
+ return new Parens(this).invert();
2315
+ }
2316
+ curr = this;
2317
+ while (curr && curr.operator) {
2318
+ curr.invert = !curr.invert;
2319
+ curr.operator = INVERSIONS[curr.operator];
2320
+ curr = curr.first;
2321
+ }
2322
+ return this;
2323
+ } else if (op = INVERSIONS[this.operator]) {
2324
+ this.operator = op;
2325
+ if (this.first.unwrap() instanceof Op) {
2326
+ this.first.invert();
2327
+ }
2328
+ return this;
2329
+ } else if (this.second) {
2330
+ return new Parens(this).invert();
2331
+ } else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) {
2332
+ return fst;
2333
+ } else {
2334
+ return new Op('!', this);
2335
+ }
2336
+ };
2337
+
2338
+ Op.prototype.unfoldSoak = function(o) {
2339
+ var _ref2;
2340
+ return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
2341
+ };
2342
+
2343
+ Op.prototype.generateDo = function(exp) {
2344
+ var call, func, param, passedParams, ref, _i, _len, _ref2;
2345
+ passedParams = [];
2346
+ func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
2347
+ _ref2 = func.params || [];
2348
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2349
+ param = _ref2[_i];
2350
+ if (param.value) {
2351
+ passedParams.push(param.value);
2352
+ delete param.value;
2353
+ } else {
2354
+ passedParams.push(param);
2355
+ }
2356
+ }
2357
+ call = new Call(exp, passedParams);
2358
+ call["do"] = true;
2359
+ return call;
2360
+ };
2361
+
2362
+ Op.prototype.compileNode = function(o) {
2363
+ var answer, isChain, lhs, rhs, _ref2, _ref3;
2364
+ isChain = this.isChainable() && this.first.isChainable();
2365
+ if (!isChain) {
2366
+ this.first.front = this.front;
2367
+ }
2368
+ if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {
2369
+ this.error('delete operand may not be argument or var');
2370
+ }
2371
+ if (((_ref2 = this.operator) === '--' || _ref2 === '++') && (_ref3 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) {
2372
+ this.error("cannot increment/decrement \"" + (this.first.unwrapAll().value) + "\"");
2373
+ }
2374
+ if (this.isUnary()) {
2375
+ return this.compileUnary(o);
2376
+ }
2377
+ if (isChain) {
2378
+ return this.compileChain(o);
2379
+ }
2380
+ switch (this.operator) {
2381
+ case '?':
2382
+ return this.compileExistence(o);
2383
+ case '**':
2384
+ return this.compilePower(o);
2385
+ case '//':
2386
+ return this.compileFloorDivision(o);
2387
+ case '%%':
2388
+ return this.compileModulo(o);
2389
+ default:
2390
+ lhs = this.first.compileToFragments(o, LEVEL_OP);
2391
+ rhs = this.second.compileToFragments(o, LEVEL_OP);
2392
+ answer = [].concat(lhs, this.makeCode(" " + this.operator + " "), rhs);
2393
+ if (o.level <= LEVEL_OP) {
2394
+ return answer;
2395
+ } else {
2396
+ return this.wrapInBraces(answer);
2397
+ }
2398
+ }
2399
+ };
2400
+
2401
+ Op.prototype.compileChain = function(o) {
2402
+ var fragments, fst, shared, _ref2;
2403
+ _ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
2404
+ fst = this.first.compileToFragments(o, LEVEL_OP);
2405
+ fragments = fst.concat(this.makeCode(" " + (this.invert ? '&&' : '||') + " "), shared.compileToFragments(o), this.makeCode(" " + this.operator + " "), this.second.compileToFragments(o, LEVEL_OP));
2406
+ return this.wrapInBraces(fragments);
2407
+ };
2408
+
2409
+ Op.prototype.compileExistence = function(o) {
2410
+ var fst, ref;
2411
+ if (this.first.isComplex()) {
2412
+ ref = new Literal(o.scope.freeVariable('ref'));
2413
+ fst = new Parens(new Assign(ref, this.first));
2414
+ } else {
2415
+ fst = this.first;
2416
+ ref = fst;
2417
+ }
2418
+ return new If(new Existence(fst), ref, {
2419
+ type: 'if'
2420
+ }).addElse(this.second).compileToFragments(o);
2421
+ };
2422
+
2423
+ Op.prototype.compileUnary = function(o) {
2424
+ var op, parts, plusMinus;
2425
+ parts = [];
2426
+ op = this.operator;
2427
+ parts.push([this.makeCode(op)]);
2428
+ if (op === '!' && this.first instanceof Existence) {
2429
+ this.first.negated = !this.first.negated;
2430
+ return this.first.compileToFragments(o);
2431
+ }
2432
+ if (o.level >= LEVEL_ACCESS) {
2433
+ return (new Parens(this)).compileToFragments(o);
2434
+ }
2435
+ plusMinus = op === '+' || op === '-';
2436
+ if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
2437
+ parts.push([this.makeCode(' ')]);
2438
+ }
2439
+ if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {
2440
+ this.first = new Parens(this.first);
2441
+ }
2442
+ parts.push(this.first.compileToFragments(o, LEVEL_OP));
2443
+ if (this.flip) {
2444
+ parts.reverse();
2445
+ }
2446
+ return this.joinFragmentArrays(parts, '');
2447
+ };
2448
+
2449
+ Op.prototype.compilePower = function(o) {
2450
+ var pow;
2451
+ pow = new Value(new Literal('Math'), [new Access(new Literal('pow'))]);
2452
+ return new Call(pow, [this.first, this.second]).compileToFragments(o);
2453
+ };
2454
+
2455
+ Op.prototype.compileFloorDivision = function(o) {
2456
+ var div, floor;
2457
+ floor = new Value(new Literal('Math'), [new Access(new Literal('floor'))]);
2458
+ div = new Op('/', this.first, this.second);
2459
+ return new Call(floor, [div]).compileToFragments(o);
2460
+ };
2461
+
2462
+ Op.prototype.compileModulo = function(o) {
2463
+ var mod;
2464
+ mod = new Value(new Literal(utility('modulo')));
2465
+ return new Call(mod, [this.first, this.second]).compileToFragments(o);
2466
+ };
2467
+
2468
+ Op.prototype.toString = function(idt) {
2469
+ return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
2470
+ };
2471
+
2472
+ return Op;
2473
+
2474
+ })(Base);
2475
+
2476
+ exports.In = In = (function(_super) {
2477
+ __extends(In, _super);
2478
+
2479
+ function In(object, array) {
2480
+ this.object = object;
2481
+ this.array = array;
2482
+ }
2483
+
2484
+ In.prototype.children = ['object', 'array'];
2485
+
2486
+ In.prototype.invert = NEGATE;
2487
+
2488
+ In.prototype.compileNode = function(o) {
2489
+ var hasSplat, obj, _i, _len, _ref2;
2490
+ if (this.array instanceof Value && this.array.isArray() && this.array.base.objects.length) {
2491
+ _ref2 = this.array.base.objects;
2492
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2493
+ obj = _ref2[_i];
2494
+ if (!(obj instanceof Splat)) {
2495
+ continue;
2496
+ }
2497
+ hasSplat = true;
2498
+ break;
2499
+ }
2500
+ if (!hasSplat) {
2501
+ return this.compileOrTest(o);
2502
+ }
2503
+ }
2504
+ return this.compileLoopTest(o);
2505
+ };
2506
+
2507
+ In.prototype.compileOrTest = function(o) {
2508
+ var cmp, cnj, i, item, ref, sub, tests, _i, _len, _ref2, _ref3, _ref4;
2509
+ _ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
2510
+ _ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
2511
+ tests = [];
2512
+ _ref4 = this.array.base.objects;
2513
+ for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
2514
+ item = _ref4[i];
2515
+ if (i) {
2516
+ tests.push(this.makeCode(cnj));
2517
+ }
2518
+ tests = tests.concat((i ? ref : sub), this.makeCode(cmp), item.compileToFragments(o, LEVEL_ACCESS));
2519
+ }
2520
+ if (o.level < LEVEL_OP) {
2521
+ return tests;
2522
+ } else {
2523
+ return this.wrapInBraces(tests);
2524
+ }
2525
+ };
2526
+
2527
+ In.prototype.compileLoopTest = function(o) {
2528
+ var fragments, ref, sub, _ref2;
2529
+ _ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
2530
+ fragments = [].concat(this.makeCode(utility('indexOf') + ".call("), this.array.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), ref, this.makeCode(") " + (this.negated ? '< 0' : '>= 0')));
2531
+ if (fragmentsToText(sub) === fragmentsToText(ref)) {
2532
+ return fragments;
2533
+ }
2534
+ fragments = sub.concat(this.makeCode(', '), fragments);
2535
+ if (o.level < LEVEL_LIST) {
2536
+ return fragments;
2537
+ } else {
2538
+ return this.wrapInBraces(fragments);
2539
+ }
2540
+ };
2541
+
2542
+ In.prototype.toString = function(idt) {
2543
+ return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
2544
+ };
2545
+
2546
+ return In;
2547
+
2548
+ })(Base);
2549
+
2550
+ exports.Try = Try = (function(_super) {
2551
+ __extends(Try, _super);
2552
+
2553
+ function Try(attempt, errorVariable, recovery, ensure) {
2554
+ this.attempt = attempt;
2555
+ this.errorVariable = errorVariable;
2556
+ this.recovery = recovery;
2557
+ this.ensure = ensure;
2558
+ }
2559
+
2560
+ Try.prototype.children = ['attempt', 'recovery', 'ensure'];
2561
+
2562
+ Try.prototype.isStatement = YES;
2563
+
2564
+ Try.prototype.jumps = function(o) {
2565
+ var _ref2;
2566
+ return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0);
2567
+ };
2568
+
2569
+ Try.prototype.makeReturn = function(res) {
2570
+ if (this.attempt) {
2571
+ this.attempt = this.attempt.makeReturn(res);
2572
+ }
2573
+ if (this.recovery) {
2574
+ this.recovery = this.recovery.makeReturn(res);
2575
+ }
2576
+ return this;
2577
+ };
2578
+
2579
+ Try.prototype.compileNode = function(o) {
2580
+ var catchPart, ensurePart, placeholder, tryPart;
2581
+ o.indent += TAB;
2582
+ tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);
2583
+ catchPart = this.recovery ? (placeholder = new Literal('_error'), this.errorVariable ? this.recovery.unshift(new Assign(this.errorVariable, placeholder)) : void 0, [].concat(this.makeCode(" catch ("), placeholder.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(' catch (_error) {}')] : [];
2584
+ ensurePart = this.ensure ? [].concat(this.makeCode(" finally {\n"), this.ensure.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}")) : [];
2585
+ return [].concat(this.makeCode("" + this.tab + "try {\n"), tryPart, this.makeCode("\n" + this.tab + "}"), catchPart, ensurePart);
2586
+ };
2587
+
2588
+ return Try;
2589
+
2590
+ })(Base);
2591
+
2592
+ exports.Throw = Throw = (function(_super) {
2593
+ __extends(Throw, _super);
2594
+
2595
+ function Throw(expression) {
2596
+ this.expression = expression;
2597
+ }
2598
+
2599
+ Throw.prototype.children = ['expression'];
2600
+
2601
+ Throw.prototype.isStatement = YES;
2602
+
2603
+ Throw.prototype.jumps = NO;
2604
+
2605
+ Throw.prototype.makeReturn = THIS;
2606
+
2607
+ Throw.prototype.compileNode = function(o) {
2608
+ return [].concat(this.makeCode(this.tab + "throw "), this.expression.compileToFragments(o), this.makeCode(";"));
2609
+ };
2610
+
2611
+ return Throw;
2612
+
2613
+ })(Base);
2614
+
2615
+ exports.Existence = Existence = (function(_super) {
2616
+ __extends(Existence, _super);
2617
+
2618
+ function Existence(expression) {
2619
+ this.expression = expression;
2620
+ }
2621
+
2622
+ Existence.prototype.children = ['expression'];
2623
+
2624
+ Existence.prototype.invert = NEGATE;
2625
+
2626
+ Existence.prototype.compileNode = function(o) {
2627
+ var cmp, cnj, code, _ref2;
2628
+ this.expression.front = this.front;
2629
+ code = this.expression.compile(o, LEVEL_OP);
2630
+ if (IDENTIFIER.test(code) && !o.scope.check(code)) {
2631
+ _ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1];
2632
+ code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null";
2633
+ } else {
2634
+ code = "" + code + " " + (this.negated ? '==' : '!=') + " null";
2635
+ }
2636
+ return [this.makeCode(o.level <= LEVEL_COND ? code : "(" + code + ")")];
2637
+ };
2638
+
2639
+ return Existence;
2640
+
2641
+ })(Base);
2642
+
2643
+ exports.Parens = Parens = (function(_super) {
2644
+ __extends(Parens, _super);
2645
+
2646
+ function Parens(body) {
2647
+ this.body = body;
2648
+ }
2649
+
2650
+ Parens.prototype.children = ['body'];
2651
+
2652
+ Parens.prototype.unwrap = function() {
2653
+ return this.body;
2654
+ };
2655
+
2656
+ Parens.prototype.isComplex = function() {
2657
+ return this.body.isComplex();
2658
+ };
2659
+
2660
+ Parens.prototype.compileNode = function(o) {
2661
+ var bare, expr, fragments;
2662
+ expr = this.body.unwrap();
2663
+ if (expr instanceof Value && expr.isAtomic()) {
2664
+ expr.front = this.front;
2665
+ return expr.compileToFragments(o);
2666
+ }
2667
+ fragments = expr.compileToFragments(o, LEVEL_PAREN);
2668
+ bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));
2669
+ if (bare) {
2670
+ return fragments;
2671
+ } else {
2672
+ return this.wrapInBraces(fragments);
2673
+ }
2674
+ };
2675
+
2676
+ return Parens;
2677
+
2678
+ })(Base);
2679
+
2680
+ exports.For = For = (function(_super) {
2681
+ __extends(For, _super);
2682
+
2683
+ function For(body, source) {
2684
+ var _ref2;
2685
+ this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
2686
+ this.body = Block.wrap([body]);
2687
+ this.own = !!source.own;
2688
+ this.object = !!source.object;
2689
+ if (this.object) {
2690
+ _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
2691
+ }
2692
+ if (this.index instanceof Value) {
2693
+ this.index.error('index cannot be a pattern matching expression');
2694
+ }
2695
+ this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
2696
+ this.pattern = this.name instanceof Value;
2697
+ if (this.range && this.index) {
2698
+ this.index.error('indexes do not apply to range loops');
2699
+ }
2700
+ if (this.range && this.pattern) {
2701
+ this.name.error('cannot pattern match over range loops');
2702
+ }
2703
+ if (this.own && !this.object) {
2704
+ this.name.error('cannot use own with for-in');
2705
+ }
2706
+ this.returns = false;
2707
+ }
2708
+
2709
+ For.prototype.children = ['body', 'source', 'guard', 'step'];
2710
+
2711
+ For.prototype.compileNode = function(o) {
2712
+ var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, defPartFragments, down, forPartFragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart, _ref2, _ref3;
2713
+ body = Block.wrap([this.body]);
2714
+ lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
2715
+ if (lastJumps && lastJumps instanceof Return) {
2716
+ this.returns = false;
2717
+ }
2718
+ source = this.range ? this.source.base : this.source;
2719
+ scope = o.scope;
2720
+ if (!this.pattern) {
2721
+ name = this.name && (this.name.compile(o, LEVEL_LIST));
2722
+ }
2723
+ index = this.index && (this.index.compile(o, LEVEL_LIST));
2724
+ if (name && !this.pattern) {
2725
+ scope.find(name);
2726
+ }
2727
+ if (index) {
2728
+ scope.find(index);
2729
+ }
2730
+ if (this.returns) {
2731
+ rvar = scope.freeVariable('results');
2732
+ }
2733
+ ivar = (this.object && index) || scope.freeVariable('i');
2734
+ kvar = (this.range && name) || index || ivar;
2735
+ kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";
2736
+ if (this.step && !this.range) {
2737
+ _ref3 = this.cacheToCodeFragments(this.step.cache(o, LEVEL_LIST)), step = _ref3[0], stepVar = _ref3[1];
2738
+ stepNum = stepVar.match(NUMBER);
2739
+ }
2740
+ if (this.pattern) {
2741
+ name = ivar;
2742
+ }
2743
+ varPart = '';
2744
+ guardPart = '';
2745
+ defPart = '';
2746
+ idt1 = this.tab + TAB;
2747
+ if (this.range) {
2748
+ forPartFragments = source.compileToFragments(merge(o, {
2749
+ index: ivar,
2750
+ name: name,
2751
+ step: this.step
2752
+ }));
2753
+ } else {
2754
+ svar = this.source.compile(o, LEVEL_LIST);
2755
+ if ((name || this.own) && !IDENTIFIER.test(svar)) {
2756
+ defPart += "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
2757
+ svar = ref;
2758
+ }
2759
+ if (name && !this.pattern) {
2760
+ namePart = "" + name + " = " + svar + "[" + kvar + "]";
2761
+ }
2762
+ if (!this.object) {
2763
+ if (step !== stepVar) {
2764
+ defPart += "" + this.tab + step + ";\n";
2765
+ }
2766
+ if (!(this.step && stepNum && (down = parseNum(stepNum[0]) < 0))) {
2767
+ lvar = scope.freeVariable('len');
2768
+ }
2769
+ declare = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";
2770
+ declareDown = "" + kvarAssign + ivar + " = " + svar + ".length - 1";
2771
+ compare = "" + ivar + " < " + lvar;
2772
+ compareDown = "" + ivar + " >= 0";
2773
+ if (this.step) {
2774
+ if (stepNum) {
2775
+ if (down) {
2776
+ compare = compareDown;
2777
+ declare = declareDown;
2778
+ }
2779
+ } else {
2780
+ compare = "" + stepVar + " > 0 ? " + compare + " : " + compareDown;
2781
+ declare = "(" + stepVar + " > 0 ? (" + declare + ") : " + declareDown + ")";
2782
+ }
2783
+ increment = "" + ivar + " += " + stepVar;
2784
+ } else {
2785
+ increment = "" + (kvar !== ivar ? "++" + ivar : "" + ivar + "++");
2786
+ }
2787
+ forPartFragments = [this.makeCode("" + declare + "; " + compare + "; " + kvarAssign + increment)];
2788
+ }
2789
+ }
2790
+ if (this.returns) {
2791
+ resultPart = "" + this.tab + rvar + " = [];\n";
2792
+ returnResult = "\n" + this.tab + "return " + rvar + ";";
2793
+ body.makeReturn(rvar);
2794
+ }
2795
+ if (this.guard) {
2796
+ if (body.expressions.length > 1) {
2797
+ body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
2798
+ } else {
2799
+ if (this.guard) {
2800
+ body = Block.wrap([new If(this.guard, body)]);
2801
+ }
2802
+ }
2803
+ }
2804
+ if (this.pattern) {
2805
+ body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + kvar + "]")));
2806
+ }
2807
+ defPartFragments = [].concat(this.makeCode(defPart), this.pluckDirectCall(o, body));
2808
+ if (namePart) {
2809
+ varPart = "\n" + idt1 + namePart + ";";
2810
+ }
2811
+ if (this.object) {
2812
+ forPartFragments = [this.makeCode("" + kvar + " in " + svar)];
2813
+ if (this.own) {
2814
+ guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + kvar + ")) continue;";
2815
+ }
2816
+ }
2817
+ bodyFragments = body.compileToFragments(merge(o, {
2818
+ indent: idt1
2819
+ }), LEVEL_TOP);
2820
+ if (bodyFragments && (bodyFragments.length > 0)) {
2821
+ bodyFragments = [].concat(this.makeCode("\n"), bodyFragments, this.makeCode("\n"));
2822
+ }
2823
+ return [].concat(defPartFragments, this.makeCode("" + (resultPart || '') + this.tab + "for ("), forPartFragments, this.makeCode(") {" + guardPart + varPart), bodyFragments, this.makeCode("" + this.tab + "}" + (returnResult || '')));
2824
+ };
2825
+
2826
+ For.prototype.pluckDirectCall = function(o, body) {
2827
+ var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
2828
+ defs = [];
2829
+ _ref2 = body.expressions;
2830
+ for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) {
2831
+ expr = _ref2[idx];
2832
+ expr = expr.unwrapAll();
2833
+ if (!(expr instanceof Call)) {
2834
+ continue;
2835
+ }
2836
+ val = (_ref3 = expr.variable) != null ? _ref3.unwrapAll() : void 0;
2837
+ if (!((val instanceof Code) || (val instanceof Value && ((_ref4 = val.base) != null ? _ref4.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref5 = (_ref6 = val.properties[0].name) != null ? _ref6.value : void 0) === 'call' || _ref5 === 'apply')))) {
2838
+ continue;
2839
+ }
2840
+ fn = ((_ref7 = val.base) != null ? _ref7.unwrapAll() : void 0) || val;
2841
+ ref = new Literal(o.scope.freeVariable('fn'));
2842
+ base = new Value(ref);
2843
+ if (val.base) {
2844
+ _ref8 = [base, val], val.base = _ref8[0], base = _ref8[1];
2845
+ }
2846
+ body.expressions[idx] = new Call(base, expr.args);
2847
+ defs = defs.concat(this.makeCode(this.tab), new Assign(ref, fn).compileToFragments(o, LEVEL_TOP), this.makeCode(';\n'));
2848
+ }
2849
+ return defs;
2850
+ };
2851
+
2852
+ return For;
2853
+
2854
+ })(While);
2855
+
2856
+ exports.Switch = Switch = (function(_super) {
2857
+ __extends(Switch, _super);
2858
+
2859
+ function Switch(subject, cases, otherwise) {
2860
+ this.subject = subject;
2861
+ this.cases = cases;
2862
+ this.otherwise = otherwise;
2863
+ }
2864
+
2865
+ Switch.prototype.children = ['subject', 'cases', 'otherwise'];
2866
+
2867
+ Switch.prototype.isStatement = YES;
2868
+
2869
+ Switch.prototype.jumps = function(o) {
2870
+ var block, conds, jumpNode, _i, _len, _ref2, _ref3, _ref4;
2871
+ if (o == null) {
2872
+ o = {
2873
+ block: true
2874
+ };
2875
+ }
2876
+ _ref2 = this.cases;
2877
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2878
+ _ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
2879
+ if (jumpNode = block.jumps(o)) {
2880
+ return jumpNode;
2881
+ }
2882
+ }
2883
+ return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0;
2884
+ };
2885
+
2886
+ Switch.prototype.makeReturn = function(res) {
2887
+ var pair, _i, _len, _ref2, _ref3;
2888
+ _ref2 = this.cases;
2889
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2890
+ pair = _ref2[_i];
2891
+ pair[1].makeReturn(res);
2892
+ }
2893
+ if (res) {
2894
+ this.otherwise || (this.otherwise = new Block([new Literal('void 0')]));
2895
+ }
2896
+ if ((_ref3 = this.otherwise) != null) {
2897
+ _ref3.makeReturn(res);
2898
+ }
2899
+ return this;
2900
+ };
2901
+
2902
+ Switch.prototype.compileNode = function(o) {
2903
+ var block, body, cond, conditions, expr, fragments, i, idt1, idt2, _i, _j, _len, _len1, _ref2, _ref3, _ref4;
2904
+ idt1 = o.indent + TAB;
2905
+ idt2 = o.indent = idt1 + TAB;
2906
+ fragments = [].concat(this.makeCode(this.tab + "switch ("), (this.subject ? this.subject.compileToFragments(o, LEVEL_PAREN) : this.makeCode("false")), this.makeCode(") {\n"));
2907
+ _ref2 = this.cases;
2908
+ for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
2909
+ _ref3 = _ref2[i], conditions = _ref3[0], block = _ref3[1];
2910
+ _ref4 = flatten([conditions]);
2911
+ for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
2912
+ cond = _ref4[_j];
2913
+ if (!this.subject) {
2914
+ cond = cond.invert();
2915
+ }
2916
+ fragments = fragments.concat(this.makeCode(idt1 + "case "), cond.compileToFragments(o, LEVEL_PAREN), this.makeCode(":\n"));
2917
+ }
2918
+ if ((body = block.compileToFragments(o, LEVEL_TOP)).length > 0) {
2919
+ fragments = fragments.concat(body, this.makeCode('\n'));
2920
+ }
2921
+ if (i === this.cases.length - 1 && !this.otherwise) {
2922
+ break;
2923
+ }
2924
+ expr = this.lastNonComment(block.expressions);
2925
+ if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {
2926
+ continue;
2927
+ }
2928
+ fragments.push(cond.makeCode(idt2 + 'break;\n'));
2929
+ }
2930
+ if (this.otherwise && this.otherwise.expressions.length) {
2931
+ fragments.push.apply(fragments, [this.makeCode(idt1 + "default:\n")].concat(__slice.call(this.otherwise.compileToFragments(o, LEVEL_TOP)), [this.makeCode("\n")]));
2932
+ }
2933
+ fragments.push(this.makeCode(this.tab + '}'));
2934
+ return fragments;
2935
+ };
2936
+
2937
+ return Switch;
2938
+
2939
+ })(Base);
2940
+
2941
+ exports.If = If = (function(_super) {
2942
+ __extends(If, _super);
2943
+
2944
+ function If(condition, body, options) {
2945
+ this.body = body;
2946
+ if (options == null) {
2947
+ options = {};
2948
+ }
2949
+ this.condition = options.type === 'unless' ? condition.invert() : condition;
2950
+ this.elseBody = null;
2951
+ this.isChain = false;
2952
+ this.soak = options.soak;
2953
+ }
2954
+
2955
+ If.prototype.children = ['condition', 'body', 'elseBody'];
2956
+
2957
+ If.prototype.bodyNode = function() {
2958
+ var _ref2;
2959
+ return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0;
2960
+ };
2961
+
2962
+ If.prototype.elseBodyNode = function() {
2963
+ var _ref2;
2964
+ return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0;
2965
+ };
2966
+
2967
+ If.prototype.addElse = function(elseBody) {
2968
+ if (this.isChain) {
2969
+ this.elseBodyNode().addElse(elseBody);
2970
+ } else {
2971
+ this.isChain = elseBody instanceof If;
2972
+ this.elseBody = this.ensureBlock(elseBody);
2973
+ this.elseBody.updateLocationDataIfMissing(elseBody.locationData);
2974
+ }
2975
+ return this;
2976
+ };
2977
+
2978
+ If.prototype.isStatement = function(o) {
2979
+ var _ref2;
2980
+ return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0);
2981
+ };
2982
+
2983
+ If.prototype.jumps = function(o) {
2984
+ var _ref2;
2985
+ return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0);
2986
+ };
2987
+
2988
+ If.prototype.compileNode = function(o) {
2989
+ if (this.isStatement(o)) {
2990
+ return this.compileStatement(o);
2991
+ } else {
2992
+ return this.compileExpression(o);
2993
+ }
2994
+ };
2995
+
2996
+ If.prototype.makeReturn = function(res) {
2997
+ if (res) {
2998
+ this.elseBody || (this.elseBody = new Block([new Literal('void 0')]));
2999
+ }
3000
+ this.body && (this.body = new Block([this.body.makeReturn(res)]));
3001
+ this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn(res)]));
3002
+ return this;
3003
+ };
3004
+
3005
+ If.prototype.ensureBlock = function(node) {
3006
+ if (node instanceof Block) {
3007
+ return node;
3008
+ } else {
3009
+ return new Block([node]);
3010
+ }
3011
+ };
3012
+
3013
+ If.prototype.compileStatement = function(o) {
3014
+ var answer, body, child, cond, exeq, ifPart, indent;
3015
+ child = del(o, 'chainChild');
3016
+ exeq = del(o, 'isExistentialEquals');
3017
+ if (exeq) {
3018
+ return new If(this.condition.invert(), this.elseBodyNode(), {
3019
+ type: 'if'
3020
+ }).compileToFragments(o);
3021
+ }
3022
+ indent = o.indent + TAB;
3023
+ cond = this.condition.compileToFragments(o, LEVEL_PAREN);
3024
+ body = this.ensureBlock(this.body).compileToFragments(merge(o, {
3025
+ indent: indent
3026
+ }));
3027
+ ifPart = [].concat(this.makeCode("if ("), cond, this.makeCode(") {\n"), body, this.makeCode("\n" + this.tab + "}"));
3028
+ if (!child) {
3029
+ ifPart.unshift(this.makeCode(this.tab));
3030
+ }
3031
+ if (!this.elseBody) {
3032
+ return ifPart;
3033
+ }
3034
+ answer = ifPart.concat(this.makeCode(' else '));
3035
+ if (this.isChain) {
3036
+ o.chainChild = true;
3037
+ answer = answer.concat(this.elseBody.unwrap().compileToFragments(o, LEVEL_TOP));
3038
+ } else {
3039
+ answer = answer.concat(this.makeCode("{\n"), this.elseBody.compileToFragments(merge(o, {
3040
+ indent: indent
3041
+ }), LEVEL_TOP), this.makeCode("\n" + this.tab + "}"));
3042
+ }
3043
+ return answer;
3044
+ };
3045
+
3046
+ If.prototype.compileExpression = function(o) {
3047
+ var alt, body, cond, fragments;
3048
+ cond = this.condition.compileToFragments(o, LEVEL_COND);
3049
+ body = this.bodyNode().compileToFragments(o, LEVEL_LIST);
3050
+ alt = this.elseBodyNode() ? this.elseBodyNode().compileToFragments(o, LEVEL_LIST) : [this.makeCode('void 0')];
3051
+ fragments = cond.concat(this.makeCode(" ? "), body, this.makeCode(" : "), alt);
3052
+ if (o.level >= LEVEL_COND) {
3053
+ return this.wrapInBraces(fragments);
3054
+ } else {
3055
+ return fragments;
3056
+ }
3057
+ };
3058
+
3059
+ If.prototype.unfoldSoak = function() {
3060
+ return this.soak && this;
3061
+ };
3062
+
3063
+ return If;
3064
+
3065
+ })(Base);
3066
+
3067
+ UTILITIES = {
3068
+ "extends": function() {
3069
+ return "function(child, parent) { for (var key in parent) { if (" + (utility('hasProp')) + ".call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }";
3070
+ },
3071
+ bind: function() {
3072
+ return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
3073
+ },
3074
+ indexOf: function() {
3075
+ return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
3076
+ },
3077
+ modulo: function() {
3078
+ return "function(a, b) { return (a % b + +b) % b; }";
3079
+ },
3080
+ hasProp: function() {
3081
+ return '{}.hasOwnProperty';
3082
+ },
3083
+ slice: function() {
3084
+ return '[].slice';
3085
+ }
3086
+ };
3087
+
3088
+ LEVEL_TOP = 1;
3089
+
3090
+ LEVEL_PAREN = 2;
3091
+
3092
+ LEVEL_LIST = 3;
3093
+
3094
+ LEVEL_COND = 4;
3095
+
3096
+ LEVEL_OP = 5;
3097
+
3098
+ LEVEL_ACCESS = 6;
3099
+
3100
+ TAB = ' ';
3101
+
3102
+ IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
3103
+
3104
+ IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$");
3105
+
3106
+ SIMPLENUM = /^[+-]?\d+$/;
3107
+
3108
+ HEXNUM = /^[+-]?0x[\da-f]+/i;
3109
+
3110
+ NUMBER = /^[+-]?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)$/i;
3111
+
3112
+ METHOD_DEF = RegExp("^(" + IDENTIFIER_STR + ")(\\.prototype)?(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\])$");
3113
+
3114
+ IS_STRING = /^['"]/;
3115
+
3116
+ IS_REGEX = /^\//;
3117
+
3118
+ utility = function(name) {
3119
+ var ref;
3120
+ ref = "__" + name;
3121
+ Scope.root.assign(ref, UTILITIES[name]());
3122
+ return ref;
3123
+ };
3124
+
3125
+ multident = function(code, tab) {
3126
+ code = code.replace(/\n/g, '$&' + tab);
3127
+ return code.replace(/\s+$/, '');
3128
+ };
3129
+
3130
+ parseNum = function(x) {
3131
+ if (x == null) {
3132
+ return 0;
3133
+ } else if (x.match(HEXNUM)) {
3134
+ return parseInt(x, 16);
3135
+ } else {
3136
+ return parseFloat(x);
3137
+ }
3138
+ };
3139
+
3140
+ isLiteralArguments = function(node) {
3141
+ return node instanceof Literal && node.value === 'arguments' && !node.asKey;
3142
+ };
3143
+
3144
+ isLiteralThis = function(node) {
3145
+ return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound) || (node instanceof Call && node.isSuper);
3146
+ };
3147
+
3148
+ unfoldSoak = function(o, parent, name) {
3149
+ var ifn;
3150
+ if (!(ifn = parent[name].unfoldSoak(o))) {
3151
+ return;
3152
+ }
3153
+ parent[name] = ifn.body;
3154
+ ifn.body = new Value(parent);
3155
+ return ifn;
3156
+ };
3157
+
3158
+ }).call(this);