mobile_template 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +28 -0
  5. data/Rakefile +3 -0
  6. data/bin/mobile_template +71 -0
  7. data/lib/mobile_template/version.rb +4 -0
  8. data/lib/mobile_template.rb +5 -0
  9. data/mobile_template.gemspec +21 -0
  10. data/templates/assets/Gemfile +4 -0
  11. data/templates/assets/config.rb +96 -0
  12. data/templates/assets/config.ru +4 -0
  13. data/templates/assets/source/images/vendor/ajax-loader.gif +0 -0
  14. data/templates/assets/source/images/vendor/ajax-loader.png +0 -0
  15. data/templates/assets/source/images/vendor/icons-18-black.png +0 -0
  16. data/templates/assets/source/images/vendor/icons-18-white.png +0 -0
  17. data/templates/assets/source/images/vendor/icons-36-black.png +0 -0
  18. data/templates/assets/source/images/vendor/icons-36-white.png +0 -0
  19. data/templates/assets/source/index.html.erb +2 -0
  20. data/templates/assets/source/javascripts/app/index.js.coffee +2 -0
  21. data/templates/assets/source/javascripts/application.js.coffee +5 -0
  22. data/templates/assets/source/javascripts/vendor/cordova.js +4841 -0
  23. data/templates/assets/source/javascripts/vendor/jquery.js +9267 -0
  24. data/templates/assets/source/javascripts/vendor/jquery.mobile.js +7410 -0
  25. data/templates/assets/source/layout.erb +24 -0
  26. data/templates/assets/source/stylesheets/application.css.scss +2 -0
  27. data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +1872 -0
  28. data/templates/cordova_android/.gitignore +18 -0
  29. data/templates/cordova_android/LICENSE +202 -0
  30. data/templates/cordova_android/NOTICE +5 -0
  31. data/templates/cordova_android/README.md +95 -0
  32. data/templates/cordova_android/VERSION +1 -0
  33. data/templates/cordova_android/bin/BOOM +4 -0
  34. data/templates/cordova_android/bin/autotest +2 -0
  35. data/templates/cordova_android/bin/bench +29 -0
  36. data/templates/cordova_android/bin/create +46 -0
  37. data/templates/cordova_android/bin/create.bat +1 -0
  38. data/templates/cordova_android/bin/create.js +88 -0
  39. data/templates/cordova_android/bin/create.xml +79 -0
  40. data/templates/cordova_android/bin/node_modules/.bin/cake +7 -0
  41. data/templates/cordova_android/bin/node_modules/.bin/coffee +7 -0
  42. data/templates/cordova_android/bin/node_modules/.bin/nodeunit +120 -0
  43. data/templates/cordova_android/bin/node_modules/coffee-script/.npmignore +11 -0
  44. data/templates/cordova_android/bin/node_modules/coffee-script/LICENSE +22 -0
  45. data/templates/cordova_android/bin/node_modules/coffee-script/README +48 -0
  46. data/templates/cordova_android/bin/node_modules/coffee-script/Rakefile +78 -0
  47. data/templates/cordova_android/bin/node_modules/coffee-script/bin/cake +7 -0
  48. data/templates/cordova_android/bin/node_modules/coffee-script/bin/coffee +7 -0
  49. data/templates/cordova_android/bin/node_modules/coffee-script/extras/jsl.conf +44 -0
  50. data/templates/cordova_android/bin/node_modules/coffee-script/lib/browser.js +75 -0
  51. data/templates/cordova_android/bin/node_modules/coffee-script/lib/cake.js +76 -0
  52. data/templates/cordova_android/bin/node_modules/coffee-script/lib/coffee-script.js +135 -0
  53. data/templates/cordova_android/bin/node_modules/coffee-script/lib/command.js +301 -0
  54. data/templates/cordova_android/bin/node_modules/coffee-script/lib/grammar.js +591 -0
  55. data/templates/cordova_android/bin/node_modules/coffee-script/lib/helpers.js +66 -0
  56. data/templates/cordova_android/bin/node_modules/coffee-script/lib/index.js +8 -0
  57. data/templates/cordova_android/bin/node_modules/coffee-script/lib/lexer.js +656 -0
  58. data/templates/cordova_android/bin/node_modules/coffee-script/lib/nodes.js +2289 -0
  59. data/templates/cordova_android/bin/node_modules/coffee-script/lib/optparse.js +111 -0
  60. data/templates/cordova_android/bin/node_modules/coffee-script/lib/parser.js +676 -0
  61. data/templates/cordova_android/bin/node_modules/coffee-script/lib/repl.js +123 -0
  62. data/templates/cordova_android/bin/node_modules/coffee-script/lib/rewriter.js +363 -0
  63. data/templates/cordova_android/bin/node_modules/coffee-script/lib/scope.js +120 -0
  64. data/templates/cordova_android/bin/node_modules/coffee-script/package.json +27 -0
  65. data/templates/cordova_android/bin/node_modules/nodeunit/.gitignore +5 -0
  66. data/templates/cordova_android/bin/node_modules/nodeunit/.npmignore +3 -0
  67. data/templates/cordova_android/bin/node_modules/nodeunit/CONTRIBUTORS.md +60 -0
  68. data/templates/cordova_android/bin/node_modules/nodeunit/LICENSE +19 -0
  69. data/templates/cordova_android/bin/node_modules/nodeunit/Makefile +126 -0
  70. data/templates/cordova_android/bin/node_modules/nodeunit/README.md +432 -0
  71. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit +120 -0
  72. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit.json +10 -0
  73. data/templates/cordova_android/bin/node_modules/nodeunit/deps/async.js +623 -0
  74. data/templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js +55 -0
  75. data/templates/cordova_android/bin/node_modules/nodeunit/deps/ejs.js +125 -0
  76. data/templates/cordova_android/bin/node_modules/nodeunit/deps/json2.js +483 -0
  77. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/nodeunit.js +1757 -0
  78. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite1.js +12 -0
  79. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite2.js +13 -0
  80. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/test.html +16 -0
  81. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_fail.png +0 -0
  82. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_pass.png +0 -0
  83. data/templates/cordova_android/bin/node_modules/nodeunit/index.js +3 -0
  84. data/templates/cordova_android/bin/node_modules/nodeunit/lib/assert.js +316 -0
  85. data/templates/cordova_android/bin/node_modules/nodeunit/lib/core.js +260 -0
  86. data/templates/cordova_android/bin/node_modules/nodeunit/lib/nodeunit.js +82 -0
  87. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/browser.js +119 -0
  88. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/default.js +123 -0
  89. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/html.js +107 -0
  90. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/index.js +9 -0
  91. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/junit.js +183 -0
  92. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/minimal.js +112 -0
  93. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/skip_passed.js +105 -0
  94. data/templates/cordova_android/bin/node_modules/nodeunit/lib/track.js +48 -0
  95. data/templates/cordova_android/bin/node_modules/nodeunit/lib/types.js +187 -0
  96. data/templates/cordova_android/bin/node_modules/nodeunit/lib/utils.js +209 -0
  97. data/templates/cordova_android/bin/node_modules/nodeunit/man1/nodeunit.1 +95 -0
  98. data/templates/cordova_android/bin/node_modules/nodeunit/nodelint.cfg +4 -0
  99. data/templates/cordova_android/bin/node_modules/nodeunit/package.json +56 -0
  100. data/templates/cordova_android/bin/node_modules/nodeunit/share/junit.xml.ejs +19 -0
  101. data/templates/cordova_android/bin/node_modules/nodeunit/share/license.js +11 -0
  102. data/templates/cordova_android/bin/node_modules/nodeunit/share/nodeunit.css +70 -0
  103. data/templates/cordova_android/bin/templates/project/.cordova/android/readme.md +1 -0
  104. data/templates/cordova_android/bin/templates/project/.cordova/readme.md +3 -0
  105. data/templates/cordova_android/bin/templates/project/cordova/create +36 -0
  106. data/templates/cordova_android/bin/templates/project/cordova/debug +9 -0
  107. data/templates/cordova_android/bin/templates/project/cordova/emulate +12 -0
  108. data/templates/cordova_android/bin/templates/project/cordova/log +3 -0
  109. data/templates/cordova_android/bin/templates/project/cordova/templates/Activity.java +16 -0
  110. data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +50 -0
  111. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +42 -0
  112. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/main.js +146 -0
  113. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/master.css +96 -0
  114. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/drawable/icon.png +0 -0
  115. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/cordova.xml +5 -0
  116. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/plugins.xml +19 -0
  117. data/templates/cordova_android/bin/test +26 -0
  118. data/templates/cordova_android/bin/tests/autotest.coffee +4 -0
  119. data/templates/cordova_android/bin/tests/create.coffee +21 -0
  120. data/templates/cordova_android/bin/tests/debug.coffee +0 -0
  121. data/templates/cordova_android/bin/tests/test.coffee +0 -0
  122. data/templates/cordova_android/framework/.classpath +8 -0
  123. data/templates/cordova_android/framework/.project +33 -0
  124. data/templates/cordova_android/framework/AndroidManifest.xml +68 -0
  125. data/templates/cordova_android/framework/ant.properties +34 -0
  126. data/templates/cordova_android/framework/assets/js/accelerometer.js +137 -0
  127. data/templates/cordova_android/framework/assets/js/app.js +89 -0
  128. data/templates/cordova_android/framework/assets/js/battery.js +134 -0
  129. data/templates/cordova_android/framework/assets/js/camera.js +168 -0
  130. data/templates/cordova_android/framework/assets/js/capture.js +203 -0
  131. data/templates/cordova_android/framework/assets/js/compass.js +168 -0
  132. data/templates/cordova_android/framework/assets/js/contact.js +310 -0
  133. data/templates/cordova_android/framework/assets/js/cordova.android.js +4841 -0
  134. data/templates/cordova_android/framework/assets/js/cordova.js.base +924 -0
  135. data/templates/cordova_android/framework/assets/js/crypto.js +54 -0
  136. data/templates/cordova_android/framework/assets/js/device.js +83 -0
  137. data/templates/cordova_android/framework/assets/js/file.js +1082 -0
  138. data/templates/cordova_android/framework/assets/js/filetransfer.js +125 -0
  139. data/templates/cordova_android/framework/assets/js/geolocation.js +209 -0
  140. data/templates/cordova_android/framework/assets/js/header.txt +19 -0
  141. data/templates/cordova_android/framework/assets/js/media.js +233 -0
  142. data/templates/cordova_android/framework/assets/js/network.js +100 -0
  143. data/templates/cordova_android/framework/assets/js/notification.js +133 -0
  144. data/templates/cordova_android/framework/assets/js/position.js +100 -0
  145. data/templates/cordova_android/framework/assets/js/storage.js +439 -0
  146. data/templates/cordova_android/framework/assets/www/index.html +27 -0
  147. data/templates/cordova_android/framework/build.xml +216 -0
  148. data/templates/cordova_android/framework/libs/commons-codec-1.3.jar +0 -0
  149. data/templates/cordova_android/framework/proguard-project.txt +20 -0
  150. data/templates/cordova_android/framework/project.properties +14 -0
  151. data/templates/cordova_android/framework/res/drawable/icon.png +0 -0
  152. data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
  153. data/templates/cordova_android/framework/res/layout/main.xml +29 -0
  154. data/templates/cordova_android/framework/res/values/strings.xml +23 -0
  155. data/templates/cordova_android/framework/res/xml/cordova.xml +37 -0
  156. data/templates/cordova_android/framework/res/xml/plugins.xml +37 -0
  157. data/templates/cordova_android/framework/src/com/phonegap/api/IPlugin.java +27 -0
  158. data/templates/cordova_android/framework/src/com/phonegap/api/LOG.java +28 -0
  159. data/templates/cordova_android/framework/src/com/phonegap/api/PhonegapActivity.java +28 -0
  160. data/templates/cordova_android/framework/src/com/phonegap/api/Plugin.java +27 -0
  161. data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +35 -0
  162. data/templates/cordova_android/framework/src/com/phonegap/api/PluginResult.java +53 -0
  163. data/templates/cordova_android/framework/src/org/apache/cordova/AccelListener.java +311 -0
  164. data/templates/cordova_android/framework/src/org/apache/cordova/App.java +198 -0
  165. data/templates/cordova_android/framework/src/org/apache/cordova/AudioHandler.java +364 -0
  166. data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +450 -0
  167. data/templates/cordova_android/framework/src/org/apache/cordova/AuthenticationToken.java +69 -0
  168. data/templates/cordova_android/framework/src/org/apache/cordova/BatteryListener.java +156 -0
  169. data/templates/cordova_android/framework/src/org/apache/cordova/CallbackServer.java +431 -0
  170. data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +500 -0
  171. data/templates/cordova_android/framework/src/org/apache/cordova/Capture.java +400 -0
  172. data/templates/cordova_android/framework/src/org/apache/cordova/CompassListener.java +308 -0
  173. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +198 -0
  174. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +1934 -0
  175. data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +113 -0
  176. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +314 -0
  177. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +306 -0
  178. data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +219 -0
  179. data/templates/cordova_android/framework/src/org/apache/cordova/DirectoryManager.java +161 -0
  180. data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +1417 -0
  181. data/templates/cordova_android/framework/src/org/apache/cordova/ExifHelper.java +165 -0
  182. data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +458 -0
  183. data/templates/cordova_android/framework/src/org/apache/cordova/FileUploadResult.java +63 -0
  184. data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +1048 -0
  185. data/templates/cordova_android/framework/src/org/apache/cordova/GeoBroker.java +165 -0
  186. data/templates/cordova_android/framework/src/org/apache/cordova/GeoListener.java +133 -0
  187. data/templates/cordova_android/framework/src/org/apache/cordova/GpsListener.java +163 -0
  188. data/templates/cordova_android/framework/src/org/apache/cordova/HttpHandler.java +80 -0
  189. data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +104 -0
  190. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkListener.java +153 -0
  191. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +248 -0
  192. data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +366 -0
  193. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceNode.java +34 -0
  194. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceSet.java +62 -0
  195. data/templates/cordova_android/framework/src/org/apache/cordova/StandAlone.java +35 -0
  196. data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +239 -0
  197. data/templates/cordova_android/framework/src/org/apache/cordova/TempListener.java +112 -0
  198. data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +145 -0
  199. data/templates/cordova_android/framework/src/org/apache/cordova/api/IPlugin.java +116 -0
  200. data/templates/cordova_android/framework/src/org/apache/cordova/api/LOG.java +234 -0
  201. data/templates/cordova_android/framework/src/org/apache/cordova/api/Plugin.java +210 -0
  202. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +359 -0
  203. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +119 -0
  204. data/templates/cordova_android/framework/src/org/apache/cordova/file/EncodingException.java +28 -0
  205. data/templates/cordova_android/framework/src/org/apache/cordova/file/FileExistsException.java +28 -0
  206. data/templates/cordova_android/framework/src/org/apache/cordova/file/InvalidModificationException.java +29 -0
  207. data/templates/cordova_android/framework/src/org/apache/cordova/file/NoModificationAllowedException.java +28 -0
  208. data/templates/cordova_android/framework/src/org/apache/cordova/file/TypeMismatchException.java +29 -0
  209. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceNodeTest.java +53 -0
  210. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceSetTest.java +73 -0
  211. metadata +279 -0
@@ -0,0 +1,2289 @@
1
+ (function() {
2
+ var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
3
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
4
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
5
+ function ctor() { this.constructor = child; }
6
+ ctor.prototype = parent.prototype;
7
+ child.prototype = new ctor;
8
+ child.__super__ = parent.prototype;
9
+ return child;
10
+ }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __indexOf = Array.prototype.indexOf || function(item) {
11
+ for (var i = 0, l = this.length; i < l; i++) {
12
+ if (this[i] === item) return i;
13
+ }
14
+ return -1;
15
+ };
16
+ Scope = require('./scope').Scope;
17
+ _ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, extend = _ref.extend, merge = _ref.merge, del = _ref.del, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
18
+ exports.extend = extend;
19
+ YES = function() {
20
+ return true;
21
+ };
22
+ NO = function() {
23
+ return false;
24
+ };
25
+ THIS = function() {
26
+ return this;
27
+ };
28
+ NEGATE = function() {
29
+ this.negated = !this.negated;
30
+ return this;
31
+ };
32
+ exports.Base = Base = (function() {
33
+ function Base() {}
34
+ Base.prototype.compile = function(o, lvl) {
35
+ var node;
36
+ o = extend({}, o);
37
+ if (lvl) {
38
+ o.level = lvl;
39
+ }
40
+ node = this.unfoldSoak(o) || this;
41
+ node.tab = o.indent;
42
+ if (o.level === LEVEL_TOP || !node.isStatement(o)) {
43
+ return node.compileNode(o);
44
+ } else {
45
+ return node.compileClosure(o);
46
+ }
47
+ };
48
+ Base.prototype.compileClosure = function(o) {
49
+ if (this.jumps() || this instanceof Throw) {
50
+ throw SyntaxError('cannot use a pure statement in an expression.');
51
+ }
52
+ o.sharedScope = true;
53
+ return Closure.wrap(this).compileNode(o);
54
+ };
55
+ Base.prototype.cache = function(o, level, reused) {
56
+ var ref, sub;
57
+ if (!this.isComplex()) {
58
+ ref = level ? this.compile(o, level) : this;
59
+ return [ref, ref];
60
+ } else {
61
+ ref = new Literal(reused || o.scope.freeVariable('ref'));
62
+ sub = new Assign(ref, this);
63
+ if (level) {
64
+ return [sub.compile(o, level), ref.value];
65
+ } else {
66
+ return [sub, ref];
67
+ }
68
+ }
69
+ };
70
+ Base.prototype.compileLoopReference = function(o, name) {
71
+ var src, tmp;
72
+ src = tmp = this.compile(o, LEVEL_LIST);
73
+ if (!((-Infinity < +src && +src < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) {
74
+ src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
75
+ }
76
+ return [src, tmp];
77
+ };
78
+ Base.prototype.makeReturn = function() {
79
+ return new Return(this);
80
+ };
81
+ Base.prototype.contains = function(pred) {
82
+ var contains;
83
+ contains = false;
84
+ this.traverseChildren(false, function(node) {
85
+ if (pred(node)) {
86
+ contains = true;
87
+ return false;
88
+ }
89
+ });
90
+ return contains;
91
+ };
92
+ Base.prototype.containsType = function(type) {
93
+ return this instanceof type || this.contains(function(node) {
94
+ return node instanceof type;
95
+ });
96
+ };
97
+ Base.prototype.lastNonComment = function(list) {
98
+ var i;
99
+ i = list.length;
100
+ while (i--) {
101
+ if (!(list[i] instanceof Comment)) {
102
+ return list[i];
103
+ }
104
+ }
105
+ return null;
106
+ };
107
+ Base.prototype.toString = function(idt, name) {
108
+ var tree;
109
+ if (idt == null) {
110
+ idt = '';
111
+ }
112
+ if (name == null) {
113
+ name = this.constructor.name;
114
+ }
115
+ tree = '\n' + idt + name;
116
+ if (this.soak) {
117
+ tree += '?';
118
+ }
119
+ this.eachChild(function(node) {
120
+ return tree += node.toString(idt + TAB);
121
+ });
122
+ return tree;
123
+ };
124
+ Base.prototype.eachChild = function(func) {
125
+ var attr, child, _i, _j, _len, _len2, _ref2, _ref3;
126
+ if (!this.children) {
127
+ return this;
128
+ }
129
+ _ref2 = this.children;
130
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
131
+ attr = _ref2[_i];
132
+ if (this[attr]) {
133
+ _ref3 = flatten([this[attr]]);
134
+ for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
135
+ child = _ref3[_j];
136
+ if (func(child) === false) {
137
+ return this;
138
+ }
139
+ }
140
+ }
141
+ }
142
+ return this;
143
+ };
144
+ Base.prototype.traverseChildren = function(crossScope, func) {
145
+ return this.eachChild(function(child) {
146
+ if (func(child) === false) {
147
+ return false;
148
+ }
149
+ return child.traverseChildren(crossScope, func);
150
+ });
151
+ };
152
+ Base.prototype.invert = function() {
153
+ return new Op('!', this);
154
+ };
155
+ Base.prototype.unwrapAll = function() {
156
+ var node;
157
+ node = this;
158
+ while (node !== (node = node.unwrap())) {
159
+ continue;
160
+ }
161
+ return node;
162
+ };
163
+ Base.prototype.children = [];
164
+ Base.prototype.isStatement = NO;
165
+ Base.prototype.jumps = NO;
166
+ Base.prototype.isComplex = YES;
167
+ Base.prototype.isChainable = NO;
168
+ Base.prototype.isAssignable = NO;
169
+ Base.prototype.unwrap = THIS;
170
+ Base.prototype.unfoldSoak = NO;
171
+ Base.prototype.assigns = NO;
172
+ return Base;
173
+ })();
174
+ exports.Block = Block = (function() {
175
+ __extends(Block, Base);
176
+ function Block(nodes) {
177
+ this.expressions = compact(flatten(nodes || []));
178
+ }
179
+ Block.prototype.children = ['expressions'];
180
+ Block.prototype.push = function(node) {
181
+ this.expressions.push(node);
182
+ return this;
183
+ };
184
+ Block.prototype.pop = function() {
185
+ return this.expressions.pop();
186
+ };
187
+ Block.prototype.unshift = function(node) {
188
+ this.expressions.unshift(node);
189
+ return this;
190
+ };
191
+ Block.prototype.unwrap = function() {
192
+ if (this.expressions.length === 1) {
193
+ return this.expressions[0];
194
+ } else {
195
+ return this;
196
+ }
197
+ };
198
+ Block.prototype.isEmpty = function() {
199
+ return !this.expressions.length;
200
+ };
201
+ Block.prototype.isStatement = function(o) {
202
+ var exp, _i, _len, _ref2;
203
+ _ref2 = this.expressions;
204
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
205
+ exp = _ref2[_i];
206
+ if (exp.isStatement(o)) {
207
+ return true;
208
+ }
209
+ }
210
+ return false;
211
+ };
212
+ Block.prototype.jumps = function(o) {
213
+ var exp, _i, _len, _ref2;
214
+ _ref2 = this.expressions;
215
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
216
+ exp = _ref2[_i];
217
+ if (exp.jumps(o)) {
218
+ return exp;
219
+ }
220
+ }
221
+ };
222
+ Block.prototype.makeReturn = function() {
223
+ var expr, len;
224
+ len = this.expressions.length;
225
+ while (len--) {
226
+ expr = this.expressions[len];
227
+ if (!(expr instanceof Comment)) {
228
+ this.expressions[len] = expr.makeReturn();
229
+ if (expr instanceof Return && !expr.expression) {
230
+ this.expressions.splice(len, 1);
231
+ }
232
+ break;
233
+ }
234
+ }
235
+ return this;
236
+ };
237
+ Block.prototype.compile = function(o, level) {
238
+ if (o == null) {
239
+ o = {};
240
+ }
241
+ if (o.scope) {
242
+ return Block.__super__.compile.call(this, o, level);
243
+ } else {
244
+ return this.compileRoot(o);
245
+ }
246
+ };
247
+ Block.prototype.compileNode = function(o) {
248
+ var code, codes, node, top, _i, _len, _ref2;
249
+ this.tab = o.indent;
250
+ top = o.level === LEVEL_TOP;
251
+ codes = [];
252
+ _ref2 = this.expressions;
253
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
254
+ node = _ref2[_i];
255
+ node = node.unwrapAll();
256
+ node = node.unfoldSoak(o) || node;
257
+ if (node instanceof Block) {
258
+ codes.push(node.compileNode(o));
259
+ } else if (top) {
260
+ node.front = true;
261
+ code = node.compile(o);
262
+ codes.push(node.isStatement(o) ? code : this.tab + code + ';');
263
+ } else {
264
+ codes.push(node.compile(o, LEVEL_LIST));
265
+ }
266
+ }
267
+ if (top) {
268
+ return codes.join('\n');
269
+ }
270
+ code = codes.join(', ') || 'void 0';
271
+ if (codes.length > 1 && o.level >= LEVEL_LIST) {
272
+ return "(" + code + ")";
273
+ } else {
274
+ return code;
275
+ }
276
+ };
277
+ Block.prototype.compileRoot = function(o) {
278
+ var code;
279
+ o.indent = this.tab = o.bare ? '' : TAB;
280
+ o.scope = new Scope(null, this, null);
281
+ o.level = LEVEL_TOP;
282
+ code = this.compileWithDeclarations(o);
283
+ if (o.bare) {
284
+ return code;
285
+ } else {
286
+ return "(function() {\n" + code + "\n}).call(this);\n";
287
+ }
288
+ };
289
+ Block.prototype.compileWithDeclarations = function(o) {
290
+ var assigns, code, declars, exp, i, post, rest, scope, _len, _ref2;
291
+ code = post = '';
292
+ _ref2 = this.expressions;
293
+ for (i = 0, _len = _ref2.length; i < _len; i++) {
294
+ exp = _ref2[i];
295
+ exp = exp.unwrap();
296
+ if (!(exp instanceof Comment || exp instanceof Literal)) {
297
+ break;
298
+ }
299
+ }
300
+ o = merge(o, {
301
+ level: LEVEL_TOP
302
+ });
303
+ if (i) {
304
+ rest = this.expressions.splice(i, this.expressions.length);
305
+ code = this.compileNode(o);
306
+ this.expressions = rest;
307
+ }
308
+ post = this.compileNode(o);
309
+ scope = o.scope;
310
+ if (scope.expressions === this) {
311
+ declars = o.scope.hasDeclarations();
312
+ assigns = scope.hasAssignments;
313
+ if ((declars || assigns) && i) {
314
+ code += '\n';
315
+ }
316
+ if (declars) {
317
+ code += "" + this.tab + "var " + (scope.declaredVariables().join(', ')) + ";\n";
318
+ }
319
+ if (assigns) {
320
+ code += "" + this.tab + "var " + (multident(scope.assignedVariables().join(', '), this.tab)) + ";\n";
321
+ }
322
+ }
323
+ return code + post;
324
+ };
325
+ Block.wrap = function(nodes) {
326
+ if (nodes.length === 1 && nodes[0] instanceof Block) {
327
+ return nodes[0];
328
+ }
329
+ return new Block(nodes);
330
+ };
331
+ return Block;
332
+ })();
333
+ exports.Literal = Literal = (function() {
334
+ __extends(Literal, Base);
335
+ function Literal(value) {
336
+ this.value = value;
337
+ }
338
+ Literal.prototype.makeReturn = function() {
339
+ if (this.isStatement()) {
340
+ return this;
341
+ } else {
342
+ return new Return(this);
343
+ }
344
+ };
345
+ Literal.prototype.isAssignable = function() {
346
+ return IDENTIFIER.test(this.value);
347
+ };
348
+ Literal.prototype.isStatement = function() {
349
+ var _ref2;
350
+ return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
351
+ };
352
+ Literal.prototype.isComplex = NO;
353
+ Literal.prototype.assigns = function(name) {
354
+ return name === this.value;
355
+ };
356
+ Literal.prototype.jumps = function(o) {
357
+ if (!this.isStatement()) {
358
+ return false;
359
+ }
360
+ if (!(o && (o.loop || o.block && (this.value !== 'continue')))) {
361
+ return this;
362
+ } else {
363
+ return false;
364
+ }
365
+ };
366
+ Literal.prototype.compileNode = function(o) {
367
+ var code;
368
+ code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value.reserved ? "\"" + this.value + "\"" : this.value;
369
+ if (this.isStatement()) {
370
+ return "" + this.tab + code + ";";
371
+ } else {
372
+ return code;
373
+ }
374
+ };
375
+ Literal.prototype.toString = function() {
376
+ return ' "' + this.value + '"';
377
+ };
378
+ return Literal;
379
+ })();
380
+ exports.Return = Return = (function() {
381
+ __extends(Return, Base);
382
+ function Return(expr) {
383
+ if (expr && !expr.unwrap().isUndefined) {
384
+ this.expression = expr;
385
+ }
386
+ }
387
+ Return.prototype.children = ['expression'];
388
+ Return.prototype.isStatement = YES;
389
+ Return.prototype.makeReturn = THIS;
390
+ Return.prototype.jumps = THIS;
391
+ Return.prototype.compile = function(o, level) {
392
+ var expr, _ref2;
393
+ expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0;
394
+ if (expr && !(expr instanceof Return)) {
395
+ return expr.compile(o, level);
396
+ } else {
397
+ return Return.__super__.compile.call(this, o, level);
398
+ }
399
+ };
400
+ Return.prototype.compileNode = function(o) {
401
+ return this.tab + ("return" + (this.expression ? ' ' + this.expression.compile(o, LEVEL_PAREN) : '') + ";");
402
+ };
403
+ return Return;
404
+ })();
405
+ exports.Value = Value = (function() {
406
+ __extends(Value, Base);
407
+ function Value(base, props, tag) {
408
+ if (!props && base instanceof Value) {
409
+ return base;
410
+ }
411
+ this.base = base;
412
+ this.properties = props || [];
413
+ if (tag) {
414
+ this[tag] = true;
415
+ }
416
+ return this;
417
+ }
418
+ Value.prototype.children = ['base', 'properties'];
419
+ Value.prototype.push = function(prop) {
420
+ this.properties.push(prop);
421
+ return this;
422
+ };
423
+ Value.prototype.hasProperties = function() {
424
+ return !!this.properties.length;
425
+ };
426
+ Value.prototype.isArray = function() {
427
+ return !this.properties.length && this.base instanceof Arr;
428
+ };
429
+ Value.prototype.isComplex = function() {
430
+ return this.hasProperties() || this.base.isComplex();
431
+ };
432
+ Value.prototype.isAssignable = function() {
433
+ return this.hasProperties() || this.base.isAssignable();
434
+ };
435
+ Value.prototype.isSimpleNumber = function() {
436
+ return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
437
+ };
438
+ Value.prototype.isAtomic = function() {
439
+ var node, _i, _len, _ref2;
440
+ _ref2 = this.properties.concat(this.base);
441
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
442
+ node = _ref2[_i];
443
+ if (node.soak || node instanceof Call) {
444
+ return false;
445
+ }
446
+ }
447
+ return true;
448
+ };
449
+ Value.prototype.isStatement = function(o) {
450
+ return !this.properties.length && this.base.isStatement(o);
451
+ };
452
+ Value.prototype.assigns = function(name) {
453
+ return !this.properties.length && this.base.assigns(name);
454
+ };
455
+ Value.prototype.jumps = function(o) {
456
+ return !this.properties.length && this.base.jumps(o);
457
+ };
458
+ Value.prototype.isObject = function(onlyGenerated) {
459
+ if (this.properties.length) {
460
+ return false;
461
+ }
462
+ return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);
463
+ };
464
+ Value.prototype.isSplice = function() {
465
+ return last(this.properties) instanceof Slice;
466
+ };
467
+ Value.prototype.makeReturn = function() {
468
+ if (this.properties.length) {
469
+ return Value.__super__.makeReturn.call(this);
470
+ } else {
471
+ return this.base.makeReturn();
472
+ }
473
+ };
474
+ Value.prototype.unwrap = function() {
475
+ if (this.properties.length) {
476
+ return this;
477
+ } else {
478
+ return this.base;
479
+ }
480
+ };
481
+ Value.prototype.cacheReference = function(o) {
482
+ var base, bref, name, nref;
483
+ name = last(this.properties);
484
+ if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
485
+ return [this, this];
486
+ }
487
+ base = new Value(this.base, this.properties.slice(0, -1));
488
+ if (base.isComplex()) {
489
+ bref = new Literal(o.scope.freeVariable('base'));
490
+ base = new Value(new Parens(new Assign(bref, base)));
491
+ }
492
+ if (!name) {
493
+ return [base, bref];
494
+ }
495
+ if (name.isComplex()) {
496
+ nref = new Literal(o.scope.freeVariable('name'));
497
+ name = new Index(new Assign(nref, name.index));
498
+ nref = new Index(nref);
499
+ }
500
+ return [base.push(name), new Value(bref || base.base, [nref || name])];
501
+ };
502
+ Value.prototype.compileNode = function(o) {
503
+ var code, prop, props, _i, _len;
504
+ this.base.front = this.front;
505
+ props = this.properties;
506
+ code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
507
+ if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(code)) {
508
+ code = "" + code + ".";
509
+ }
510
+ for (_i = 0, _len = props.length; _i < _len; _i++) {
511
+ prop = props[_i];
512
+ code += prop.compile(o);
513
+ }
514
+ return code;
515
+ };
516
+ Value.prototype.unfoldSoak = function(o) {
517
+ var result;
518
+ if (this.unfoldedSoak != null) {
519
+ return this.unfoldedSoak;
520
+ }
521
+ result = __bind(function() {
522
+ var fst, i, ifn, prop, ref, snd, _len, _ref2;
523
+ if (ifn = this.base.unfoldSoak(o)) {
524
+ Array.prototype.push.apply(ifn.body.properties, this.properties);
525
+ return ifn;
526
+ }
527
+ _ref2 = this.properties;
528
+ for (i = 0, _len = _ref2.length; i < _len; i++) {
529
+ prop = _ref2[i];
530
+ if (prop.soak) {
531
+ prop.soak = false;
532
+ fst = new Value(this.base, this.properties.slice(0, i));
533
+ snd = new Value(this.base, this.properties.slice(i));
534
+ if (fst.isComplex()) {
535
+ ref = new Literal(o.scope.freeVariable('ref'));
536
+ fst = new Parens(new Assign(ref, fst));
537
+ snd.base = ref;
538
+ }
539
+ return new If(new Existence(fst), snd, {
540
+ soak: true
541
+ });
542
+ }
543
+ }
544
+ return null;
545
+ }, this)();
546
+ return this.unfoldedSoak = result || false;
547
+ };
548
+ return Value;
549
+ })();
550
+ exports.Comment = Comment = (function() {
551
+ __extends(Comment, Base);
552
+ function Comment(comment) {
553
+ this.comment = comment;
554
+ }
555
+ Comment.prototype.isStatement = YES;
556
+ Comment.prototype.makeReturn = THIS;
557
+ Comment.prototype.compileNode = function(o, level) {
558
+ var code;
559
+ code = '/*' + multident(this.comment, this.tab) + '*/';
560
+ if ((level || o.level) === LEVEL_TOP) {
561
+ code = o.indent + code;
562
+ }
563
+ return code;
564
+ };
565
+ return Comment;
566
+ })();
567
+ exports.Call = Call = (function() {
568
+ __extends(Call, Base);
569
+ function Call(variable, args, soak) {
570
+ this.args = args != null ? args : [];
571
+ this.soak = soak;
572
+ this.isNew = false;
573
+ this.isSuper = variable === 'super';
574
+ this.variable = this.isSuper ? null : variable;
575
+ }
576
+ Call.prototype.children = ['variable', 'args'];
577
+ Call.prototype.newInstance = function() {
578
+ var base;
579
+ base = this.variable.base || this.variable;
580
+ if (base instanceof Call && !base.isNew) {
581
+ base.newInstance();
582
+ } else {
583
+ this.isNew = true;
584
+ }
585
+ return this;
586
+ };
587
+ Call.prototype.superReference = function(o) {
588
+ var method, name;
589
+ method = o.scope.method;
590
+ if (!method) {
591
+ throw SyntaxError('cannot call super outside of a function.');
592
+ }
593
+ name = method.name;
594
+ if (name == null) {
595
+ throw SyntaxError('cannot call super on an anonymous function.');
596
+ }
597
+ if (method.klass) {
598
+ return (new Value(new Literal(method.klass), [new Access(new Literal("__super__")), new Access(new Literal(name))])).compile(o);
599
+ } else {
600
+ return "" + name + ".__super__.constructor";
601
+ }
602
+ };
603
+ Call.prototype.unfoldSoak = function(o) {
604
+ var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
605
+ if (this.soak) {
606
+ if (this.variable) {
607
+ if (ifn = unfoldSoak(o, this, 'variable')) {
608
+ return ifn;
609
+ }
610
+ _ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1];
611
+ } else {
612
+ left = new Literal(this.superReference(o));
613
+ rite = new Value(left);
614
+ }
615
+ rite = new Call(rite, this.args);
616
+ rite.isNew = this.isNew;
617
+ left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");
618
+ return new If(left, new Value(rite), {
619
+ soak: true
620
+ });
621
+ }
622
+ call = this;
623
+ list = [];
624
+ while (true) {
625
+ if (call.variable instanceof Call) {
626
+ list.push(call);
627
+ call = call.variable;
628
+ continue;
629
+ }
630
+ if (!(call.variable instanceof Value)) {
631
+ break;
632
+ }
633
+ list.push(call);
634
+ if (!((call = call.variable.base) instanceof Call)) {
635
+ break;
636
+ }
637
+ }
638
+ _ref3 = list.reverse();
639
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
640
+ call = _ref3[_i];
641
+ if (ifn) {
642
+ if (call.variable instanceof Call) {
643
+ call.variable = ifn;
644
+ } else {
645
+ call.variable.base = ifn;
646
+ }
647
+ }
648
+ ifn = unfoldSoak(o, call, 'variable');
649
+ }
650
+ return ifn;
651
+ };
652
+ Call.prototype.filterImplicitObjects = function(list) {
653
+ var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref2;
654
+ nodes = [];
655
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
656
+ node = list[_i];
657
+ if (!((typeof node.isObject === "function" ? node.isObject() : void 0) && node.base.generated)) {
658
+ nodes.push(node);
659
+ continue;
660
+ }
661
+ obj = null;
662
+ _ref2 = node.base.properties;
663
+ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
664
+ prop = _ref2[_j];
665
+ if (prop instanceof Assign || prop instanceof Comment) {
666
+ if (!obj) {
667
+ nodes.push(obj = new Obj(properties = [], true));
668
+ }
669
+ properties.push(prop);
670
+ } else {
671
+ nodes.push(prop);
672
+ obj = null;
673
+ }
674
+ }
675
+ }
676
+ return nodes;
677
+ };
678
+ Call.prototype.compileNode = function(o) {
679
+ var arg, args, code, _ref2;
680
+ if ((_ref2 = this.variable) != null) {
681
+ _ref2.front = this.front;
682
+ }
683
+ if (code = Splat.compileSplattedArray(o, this.args, true)) {
684
+ return this.compileSplat(o, code);
685
+ }
686
+ args = this.filterImplicitObjects(this.args);
687
+ args = ((function() {
688
+ var _i, _len, _results;
689
+ _results = [];
690
+ for (_i = 0, _len = args.length; _i < _len; _i++) {
691
+ arg = args[_i];
692
+ _results.push(arg.compile(o, LEVEL_LIST));
693
+ }
694
+ return _results;
695
+ })()).join(', ');
696
+ if (this.isSuper) {
697
+ return this.superReference(o) + (".call(this" + (args && ', ' + args) + ")");
698
+ } else {
699
+ return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")");
700
+ }
701
+ };
702
+ Call.prototype.compileSuper = function(args, o) {
703
+ return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
704
+ };
705
+ Call.prototype.compileSplat = function(o, splatArgs) {
706
+ var base, fun, idt, name, ref;
707
+ if (this.isSuper) {
708
+ return "" + (this.superReference(o)) + ".apply(this, " + splatArgs + ")";
709
+ }
710
+ if (this.isNew) {
711
+ idt = this.tab + TAB;
712
+ return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})";
713
+ }
714
+ base = new Value(this.variable);
715
+ if ((name = base.properties.pop()) && base.isComplex()) {
716
+ ref = o.scope.freeVariable('ref');
717
+ fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o));
718
+ } else {
719
+ fun = base.compile(o, LEVEL_ACCESS);
720
+ if (SIMPLENUM.test(fun)) {
721
+ fun = "(" + fun + ")";
722
+ }
723
+ if (name) {
724
+ ref = fun;
725
+ fun += name.compile(o);
726
+ } else {
727
+ ref = 'null';
728
+ }
729
+ }
730
+ return "" + fun + ".apply(" + ref + ", " + splatArgs + ")";
731
+ };
732
+ return Call;
733
+ })();
734
+ exports.Extends = Extends = (function() {
735
+ __extends(Extends, Base);
736
+ function Extends(child, parent) {
737
+ this.child = child;
738
+ this.parent = parent;
739
+ }
740
+ Extends.prototype.children = ['child', 'parent'];
741
+ Extends.prototype.compile = function(o) {
742
+ utility('hasProp');
743
+ return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compile(o);
744
+ };
745
+ return Extends;
746
+ })();
747
+ exports.Access = Access = (function() {
748
+ __extends(Access, Base);
749
+ function Access(name, tag) {
750
+ this.name = name;
751
+ this.name.asKey = true;
752
+ this.proto = tag === 'proto' ? '.prototype' : '';
753
+ this.soak = tag === 'soak';
754
+ }
755
+ Access.prototype.children = ['name'];
756
+ Access.prototype.compile = function(o) {
757
+ var name;
758
+ name = this.name.compile(o);
759
+ return this.proto + (IDENTIFIER.test(name) ? "." + name : "[" + name + "]");
760
+ };
761
+ Access.prototype.isComplex = NO;
762
+ return Access;
763
+ })();
764
+ exports.Index = Index = (function() {
765
+ __extends(Index, Base);
766
+ function Index(index) {
767
+ this.index = index;
768
+ }
769
+ Index.prototype.children = ['index'];
770
+ Index.prototype.compile = function(o) {
771
+ return (this.proto ? '.prototype' : '') + ("[" + (this.index.compile(o, LEVEL_PAREN)) + "]");
772
+ };
773
+ Index.prototype.isComplex = function() {
774
+ return this.index.isComplex();
775
+ };
776
+ return Index;
777
+ })();
778
+ exports.Range = Range = (function() {
779
+ __extends(Range, Base);
780
+ Range.prototype.children = ['from', 'to'];
781
+ function Range(from, to, tag) {
782
+ this.from = from;
783
+ this.to = to;
784
+ this.exclusive = tag === 'exclusive';
785
+ this.equals = this.exclusive ? '' : '=';
786
+ }
787
+ Range.prototype.compileVariables = function(o) {
788
+ var step, _ref2, _ref3, _ref4, _ref5;
789
+ o = merge(o, {
790
+ top: true
791
+ });
792
+ _ref2 = this.from.cache(o, LEVEL_LIST), this.fromC = _ref2[0], this.fromVar = _ref2[1];
793
+ _ref3 = this.to.cache(o, LEVEL_LIST), this.toC = _ref3[0], this.toVar = _ref3[1];
794
+ if (step = del(o, 'step')) {
795
+ _ref4 = step.cache(o, LEVEL_LIST), this.step = _ref4[0], this.stepVar = _ref4[1];
796
+ }
797
+ _ref5 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref5[0], this.toNum = _ref5[1];
798
+ if (this.stepVar) {
799
+ return this.stepNum = this.stepVar.match(SIMPLENUM);
800
+ }
801
+ };
802
+ Range.prototype.compileNode = function(o) {
803
+ var cond, condPart, from, gt, idx, known, lt, stepPart, to, varPart, _ref2, _ref3;
804
+ if (!this.fromVar) {
805
+ this.compileVariables(o);
806
+ }
807
+ if (!o.index) {
808
+ return this.compileArray(o);
809
+ }
810
+ known = this.fromNum && this.toNum;
811
+ idx = del(o, 'index');
812
+ varPart = "" + idx + " = " + this.fromC;
813
+ if (this.toC !== this.toVar) {
814
+ varPart += ", " + this.toC;
815
+ }
816
+ if (this.step !== this.stepVar) {
817
+ varPart += ", " + this.step;
818
+ }
819
+ _ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1];
820
+ condPart = this.stepNum ? condPart = +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [+this.fromNum, +this.toNum], from = _ref3[0], to = _ref3[1], _ref3), condPart = from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, condPart = "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
821
+ stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? from <= to ? "" + idx + "++" : "" + idx + "--" : "" + cond + " ? " + idx + "++ : " + idx + "--";
822
+ return "" + varPart + "; " + condPart + "; " + stepPart;
823
+ };
824
+ Range.prototype.compileArray = function(o) {
825
+ var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results;
826
+ if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
827
+ range = (function() {
828
+ _results = [];
829
+ for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); }
830
+ return _results;
831
+ }).apply(this);
832
+ if (this.exclusive) {
833
+ range.pop();
834
+ }
835
+ return "[" + (range.join(', ')) + "]";
836
+ }
837
+ idt = this.tab + TAB;
838
+ i = o.scope.freeVariable('i');
839
+ result = o.scope.freeVariable('results');
840
+ pre = "\n" + idt + result + " = [];";
841
+ if (this.fromNum && this.toNum) {
842
+ o.index = i;
843
+ body = this.compileNode(o);
844
+ } else {
845
+ vars = ("" + i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : '');
846
+ cond = "" + this.fromVar + " <= " + this.toVar;
847
+ body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";
848
+ }
849
+ post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
850
+ hasArgs = function(node) {
851
+ return node != null ? node.contains(function(n) {
852
+ return n instanceof Literal && n.value === 'arguments' && !n.asKey;
853
+ }) : void 0;
854
+ };
855
+ if (hasArgs(this.from) || hasArgs(this.to)) {
856
+ args = ', arguments';
857
+ }
858
+ return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")";
859
+ };
860
+ return Range;
861
+ })();
862
+ exports.Slice = Slice = (function() {
863
+ __extends(Slice, Base);
864
+ Slice.prototype.children = ['range'];
865
+ function Slice(range) {
866
+ this.range = range;
867
+ Slice.__super__.constructor.call(this);
868
+ }
869
+ Slice.prototype.compileNode = function(o) {
870
+ var compiled, from, fromStr, to, toStr, _ref2;
871
+ _ref2 = this.range, to = _ref2.to, from = _ref2.from;
872
+ fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
873
+ compiled = to && to.compile(o, LEVEL_PAREN);
874
+ if (to && !(!this.range.exclusive && +compiled === -1)) {
875
+ toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : "(" + compiled + " + 1) || 9e9");
876
+ }
877
+ return ".slice(" + fromStr + (toStr || '') + ")";
878
+ };
879
+ return Slice;
880
+ })();
881
+ exports.Obj = Obj = (function() {
882
+ __extends(Obj, Base);
883
+ function Obj(props, generated) {
884
+ this.generated = generated != null ? generated : false;
885
+ this.objects = this.properties = props || [];
886
+ }
887
+ Obj.prototype.children = ['properties'];
888
+ Obj.prototype.compileNode = function(o) {
889
+ var i, idt, indent, join, lastNoncom, node, obj, prop, props, _i, _len;
890
+ props = this.properties;
891
+ if (!props.length) {
892
+ if (this.front) {
893
+ return '({})';
894
+ } else {
895
+ return '{}';
896
+ }
897
+ }
898
+ if (this.generated) {
899
+ for (_i = 0, _len = props.length; _i < _len; _i++) {
900
+ node = props[_i];
901
+ if (node instanceof Value) {
902
+ throw new Error('cannot have an implicit value in an implicit object');
903
+ }
904
+ }
905
+ }
906
+ idt = o.indent += TAB;
907
+ lastNoncom = this.lastNonComment(this.properties);
908
+ props = (function() {
909
+ var _len2, _results;
910
+ _results = [];
911
+ for (i = 0, _len2 = props.length; i < _len2; i++) {
912
+ prop = props[i];
913
+ join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
914
+ indent = prop instanceof Comment ? '' : idt;
915
+ if (prop instanceof Value && prop["this"]) {
916
+ prop = new Assign(prop.properties[0].name, prop, 'object');
917
+ }
918
+ if (!(prop instanceof Comment)) {
919
+ if (!(prop instanceof Assign)) {
920
+ prop = new Assign(prop, prop, 'object');
921
+ }
922
+ (prop.variable.base || prop.variable).asKey = true;
923
+ }
924
+ _results.push(indent + prop.compile(o, LEVEL_TOP) + join);
925
+ }
926
+ return _results;
927
+ })();
928
+ props = props.join('');
929
+ obj = "{" + (props && '\n' + props + '\n' + this.tab) + "}";
930
+ if (this.front) {
931
+ return "(" + obj + ")";
932
+ } else {
933
+ return obj;
934
+ }
935
+ };
936
+ Obj.prototype.assigns = function(name) {
937
+ var prop, _i, _len, _ref2;
938
+ _ref2 = this.properties;
939
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
940
+ prop = _ref2[_i];
941
+ if (prop.assigns(name)) {
942
+ return true;
943
+ }
944
+ }
945
+ return false;
946
+ };
947
+ return Obj;
948
+ })();
949
+ exports.Arr = Arr = (function() {
950
+ __extends(Arr, Base);
951
+ function Arr(objs) {
952
+ this.objects = objs || [];
953
+ }
954
+ Arr.prototype.children = ['objects'];
955
+ Arr.prototype.filterImplicitObjects = Call.prototype.filterImplicitObjects;
956
+ Arr.prototype.compileNode = function(o) {
957
+ var code, obj, objs;
958
+ if (!this.objects.length) {
959
+ return '[]';
960
+ }
961
+ o.indent += TAB;
962
+ objs = this.filterImplicitObjects(this.objects);
963
+ if (code = Splat.compileSplattedArray(o, objs)) {
964
+ return code;
965
+ }
966
+ code = ((function() {
967
+ var _i, _len, _results;
968
+ _results = [];
969
+ for (_i = 0, _len = objs.length; _i < _len; _i++) {
970
+ obj = objs[_i];
971
+ _results.push(obj.compile(o, LEVEL_LIST));
972
+ }
973
+ return _results;
974
+ })()).join(', ');
975
+ if (code.indexOf('\n') >= 0) {
976
+ return "[\n" + o.indent + code + "\n" + this.tab + "]";
977
+ } else {
978
+ return "[" + code + "]";
979
+ }
980
+ };
981
+ Arr.prototype.assigns = function(name) {
982
+ var obj, _i, _len, _ref2;
983
+ _ref2 = this.objects;
984
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
985
+ obj = _ref2[_i];
986
+ if (obj.assigns(name)) {
987
+ return true;
988
+ }
989
+ }
990
+ return false;
991
+ };
992
+ return Arr;
993
+ })();
994
+ exports.Class = Class = (function() {
995
+ __extends(Class, Base);
996
+ function Class(variable, parent, body) {
997
+ this.variable = variable;
998
+ this.parent = parent;
999
+ this.body = body != null ? body : new Block;
1000
+ this.boundFuncs = [];
1001
+ this.body.classBody = true;
1002
+ }
1003
+ Class.prototype.children = ['variable', 'parent', 'body'];
1004
+ Class.prototype.determineName = function() {
1005
+ var decl, tail;
1006
+ if (!this.variable) {
1007
+ return null;
1008
+ }
1009
+ decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
1010
+ return decl && (decl = IDENTIFIER.test(decl) && decl);
1011
+ };
1012
+ Class.prototype.setContext = function(name) {
1013
+ return this.body.traverseChildren(false, function(node) {
1014
+ if (node.classBody) {
1015
+ return false;
1016
+ }
1017
+ if (node instanceof Literal && node.value === 'this') {
1018
+ return node.value = name;
1019
+ } else if (node instanceof Code) {
1020
+ node.klass = name;
1021
+ if (node.bound) {
1022
+ return node.context = name;
1023
+ }
1024
+ }
1025
+ });
1026
+ };
1027
+ Class.prototype.addBoundFunctions = function(o) {
1028
+ var bvar, lhs, _i, _len, _ref2, _results;
1029
+ if (this.boundFuncs.length) {
1030
+ _ref2 = this.boundFuncs;
1031
+ _results = [];
1032
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1033
+ bvar = _ref2[_i];
1034
+ lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);
1035
+ _results.push(this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)")));
1036
+ }
1037
+ return _results;
1038
+ }
1039
+ };
1040
+ Class.prototype.addProperties = function(node, name, o) {
1041
+ var assign, base, exprs, func, props;
1042
+ props = node.base.properties.slice(0);
1043
+ exprs = (function() {
1044
+ var _results;
1045
+ _results = [];
1046
+ while (assign = props.shift()) {
1047
+ if (assign instanceof Assign) {
1048
+ base = assign.variable.base;
1049
+ delete assign.context;
1050
+ func = assign.value;
1051
+ if (base.value === 'constructor') {
1052
+ if (this.ctor) {
1053
+ throw new Error('cannot define more than one constructor in a class');
1054
+ }
1055
+ if (func.bound) {
1056
+ throw new Error('cannot define a constructor as a bound function');
1057
+ }
1058
+ if (func instanceof Code) {
1059
+ assign = this.ctor = func;
1060
+ } else {
1061
+ this.externalCtor = o.scope.freeVariable('class');
1062
+ assign = new Assign(new Literal(this.externalCtor), func);
1063
+ }
1064
+ } else {
1065
+ if (!assign.variable["this"]) {
1066
+ assign.variable = new Value(new Literal(name), [new Access(base, 'proto')]);
1067
+ }
1068
+ if (func instanceof Code && func.bound) {
1069
+ this.boundFuncs.push(base);
1070
+ func.bound = false;
1071
+ }
1072
+ }
1073
+ }
1074
+ _results.push(assign);
1075
+ }
1076
+ return _results;
1077
+ }).call(this);
1078
+ return compact(exprs);
1079
+ };
1080
+ Class.prototype.walkBody = function(name, o) {
1081
+ return this.traverseChildren(false, __bind(function(child) {
1082
+ var exps, i, node, _len, _ref2;
1083
+ if (child instanceof Class) {
1084
+ return false;
1085
+ }
1086
+ if (child instanceof Block) {
1087
+ _ref2 = exps = child.expressions;
1088
+ for (i = 0, _len = _ref2.length; i < _len; i++) {
1089
+ node = _ref2[i];
1090
+ if (node instanceof Value && node.isObject(true)) {
1091
+ exps[i] = this.addProperties(node, name, o);
1092
+ }
1093
+ }
1094
+ return child.expressions = exps = flatten(exps);
1095
+ }
1096
+ }, this));
1097
+ };
1098
+ Class.prototype.ensureConstructor = function(name) {
1099
+ if (!this.ctor) {
1100
+ this.ctor = new Code;
1101
+ if (this.parent) {
1102
+ this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)"));
1103
+ }
1104
+ if (this.externalCtor) {
1105
+ this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
1106
+ }
1107
+ this.body.expressions.unshift(this.ctor);
1108
+ }
1109
+ this.ctor.ctor = this.ctor.name = name;
1110
+ this.ctor.klass = null;
1111
+ return this.ctor.noReturn = true;
1112
+ };
1113
+ Class.prototype.compileNode = function(o) {
1114
+ var decl, klass, lname, name;
1115
+ decl = this.determineName();
1116
+ name = decl || this.name || '_Class';
1117
+ lname = new Literal(name);
1118
+ this.setContext(name);
1119
+ this.walkBody(name, o);
1120
+ this.ensureConstructor(name);
1121
+ if (this.parent) {
1122
+ this.body.expressions.unshift(new Extends(lname, this.parent));
1123
+ }
1124
+ if (!(this.ctor instanceof Code)) {
1125
+ this.body.expressions.unshift(this.ctor);
1126
+ }
1127
+ this.body.expressions.push(lname);
1128
+ this.addBoundFunctions(o);
1129
+ klass = new Parens(Closure.wrap(this.body), true);
1130
+ if (this.variable) {
1131
+ klass = new Assign(this.variable, klass);
1132
+ }
1133
+ return klass.compile(o);
1134
+ };
1135
+ return Class;
1136
+ })();
1137
+ exports.Assign = Assign = (function() {
1138
+ __extends(Assign, Base);
1139
+ function Assign(variable, value, context, options) {
1140
+ this.variable = variable;
1141
+ this.value = value;
1142
+ this.context = context;
1143
+ this.param = options && options.param;
1144
+ }
1145
+ Assign.prototype.children = ['variable', 'value'];
1146
+ Assign.prototype.isStatement = function(o) {
1147
+ return (o != null ? o.level : void 0) === LEVEL_TOP && (this.context != null) && __indexOf.call(this.context, "?") >= 0;
1148
+ };
1149
+ Assign.prototype.assigns = function(name) {
1150
+ return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
1151
+ };
1152
+ Assign.prototype.unfoldSoak = function(o) {
1153
+ return unfoldSoak(o, this, 'variable');
1154
+ };
1155
+ Assign.prototype.compileNode = function(o) {
1156
+ var isValue, match, name, val, _ref2, _ref3, _ref4, _ref5;
1157
+ if (isValue = this.variable instanceof Value) {
1158
+ if (this.variable.isArray() || this.variable.isObject()) {
1159
+ return this.compilePatternMatch(o);
1160
+ }
1161
+ if (this.variable.isSplice()) {
1162
+ return this.compileSplice(o);
1163
+ }
1164
+ if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') {
1165
+ return this.compileConditional(o);
1166
+ }
1167
+ }
1168
+ name = this.variable.compile(o, LEVEL_LIST);
1169
+ if (!(this.context || this.variable.isAssignable())) {
1170
+ throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
1171
+ }
1172
+ if (!(this.context || isValue && (this.variable.namespaced || this.variable.hasProperties()))) {
1173
+ if (this.param) {
1174
+ o.scope.add(name, 'var');
1175
+ } else {
1176
+ o.scope.find(name);
1177
+ }
1178
+ }
1179
+ if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {
1180
+ if (match[1]) {
1181
+ this.value.klass = match[1];
1182
+ }
1183
+ this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5];
1184
+ }
1185
+ val = this.value.compile(o, LEVEL_LIST);
1186
+ if (this.context === 'object') {
1187
+ return "" + name + ": " + val;
1188
+ }
1189
+ val = name + (" " + (this.context || '=') + " ") + val;
1190
+ if (o.level <= LEVEL_LIST) {
1191
+ return val;
1192
+ } else {
1193
+ return "(" + val + ")";
1194
+ }
1195
+ };
1196
+ Assign.prototype.compilePatternMatch = function(o) {
1197
+ var acc, assigns, code, i, idx, isObject, ivar, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref2, _ref3, _ref4, _ref5;
1198
+ top = o.level === LEVEL_TOP;
1199
+ value = this.value;
1200
+ objects = this.variable.base.objects;
1201
+ if (!(olen = objects.length)) {
1202
+ code = value.compile(o);
1203
+ if (o.level >= LEVEL_OP) {
1204
+ return "(" + code + ")";
1205
+ } else {
1206
+ return code;
1207
+ }
1208
+ }
1209
+ isObject = this.variable.isObject();
1210
+ if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
1211
+ if (obj instanceof Assign) {
1212
+ _ref2 = obj, idx = _ref2.variable.base, obj = _ref2.value;
1213
+ } else {
1214
+ if (obj.base instanceof Parens) {
1215
+ _ref3 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref3[0], idx = _ref3[1];
1216
+ } else {
1217
+ idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
1218
+ }
1219
+ }
1220
+ acc = IDENTIFIER.test(idx.unwrap().value || 0);
1221
+ value = new Value(value);
1222
+ value.properties.push(new (acc ? Access : Index)(idx));
1223
+ return new Assign(obj, value, null, {
1224
+ param: this.param
1225
+ }).compile(o, LEVEL_TOP);
1226
+ }
1227
+ vvar = value.compile(o, LEVEL_LIST);
1228
+ assigns = [];
1229
+ splat = false;
1230
+ if (!IDENTIFIER.test(vvar) || this.variable.assigns(vvar)) {
1231
+ assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar);
1232
+ vvar = ref;
1233
+ }
1234
+ for (i = 0, _len = objects.length; i < _len; i++) {
1235
+ obj = objects[i];
1236
+ idx = i;
1237
+ if (isObject) {
1238
+ if (obj instanceof Assign) {
1239
+ _ref4 = obj, idx = _ref4.variable.base, obj = _ref4.value;
1240
+ } else {
1241
+ if (obj.base instanceof Parens) {
1242
+ _ref5 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref5[0], idx = _ref5[1];
1243
+ } else {
1244
+ idx = obj["this"] ? obj.properties[0].name : obj;
1245
+ }
1246
+ }
1247
+ }
1248
+ if (!splat && obj instanceof Splat) {
1249
+ val = "" + olen + " <= " + vvar + ".length ? " + (utility('slice')) + ".call(" + vvar + ", " + i;
1250
+ if (rest = olen - i - 1) {
1251
+ ivar = o.scope.freeVariable('i');
1252
+ val += ", " + ivar + " = " + vvar + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";
1253
+ } else {
1254
+ val += ") : []";
1255
+ }
1256
+ val = new Literal(val);
1257
+ splat = "" + ivar + "++";
1258
+ } else {
1259
+ if (obj instanceof Splat) {
1260
+ obj = obj.name.compile(o);
1261
+ throw SyntaxError("multiple splats are disallowed in an assignment: " + obj + " ...");
1262
+ }
1263
+ if (typeof idx === 'number') {
1264
+ idx = new Literal(splat || idx);
1265
+ acc = false;
1266
+ } else {
1267
+ acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
1268
+ }
1269
+ val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
1270
+ }
1271
+ assigns.push(new Assign(obj, val, null, {
1272
+ param: this.param
1273
+ }).compile(o, LEVEL_TOP));
1274
+ }
1275
+ if (!top) {
1276
+ assigns.push(vvar);
1277
+ }
1278
+ code = assigns.join(', ');
1279
+ if (o.level < LEVEL_LIST) {
1280
+ return code;
1281
+ } else {
1282
+ return "(" + code + ")";
1283
+ }
1284
+ };
1285
+ Assign.prototype.compileConditional = function(o) {
1286
+ var left, rite, _ref2;
1287
+ _ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1];
1288
+ if (__indexOf.call(this.context, "?") >= 0) {
1289
+ o.isExistentialEquals = true;
1290
+ }
1291
+ return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o);
1292
+ };
1293
+ Assign.prototype.compileSplice = function(o) {
1294
+ var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
1295
+ _ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive;
1296
+ name = this.variable.compile(o);
1297
+ _ref3 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref3[0], fromRef = _ref3[1];
1298
+ if (to) {
1299
+ if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
1300
+ to = +to.compile(o) - +fromRef;
1301
+ if (!exclusive) {
1302
+ to += 1;
1303
+ }
1304
+ } else {
1305
+ to = to.compile(o) + ' - ' + fromRef;
1306
+ if (!exclusive) {
1307
+ to += ' + 1';
1308
+ }
1309
+ }
1310
+ } else {
1311
+ to = "9e9";
1312
+ }
1313
+ _ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1];
1314
+ code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef;
1315
+ if (o.level > LEVEL_TOP) {
1316
+ return "(" + code + ")";
1317
+ } else {
1318
+ return code;
1319
+ }
1320
+ };
1321
+ return Assign;
1322
+ })();
1323
+ exports.Code = Code = (function() {
1324
+ __extends(Code, Base);
1325
+ function Code(params, body, tag) {
1326
+ this.params = params || [];
1327
+ this.body = body || new Block;
1328
+ this.bound = tag === 'boundfunc';
1329
+ if (this.bound) {
1330
+ this.context = 'this';
1331
+ }
1332
+ }
1333
+ Code.prototype.children = ['params', 'body'];
1334
+ Code.prototype.isStatement = function() {
1335
+ return !!this.ctor;
1336
+ };
1337
+ Code.prototype.jumps = NO;
1338
+ Code.prototype.compileNode = function(o) {
1339
+ var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _k, _len, _len2, _len3, _len4, _ref2, _ref3, _ref4, _ref5;
1340
+ o.scope = new Scope(o.scope, this.body, this);
1341
+ o.scope.shared = del(o, 'sharedScope');
1342
+ o.indent += TAB;
1343
+ delete o.bare;
1344
+ vars = [];
1345
+ exprs = [];
1346
+ _ref2 = this.params;
1347
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1348
+ param = _ref2[_i];
1349
+ if (param.splat) {
1350
+ _ref3 = this.params;
1351
+ for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
1352
+ p = _ref3[_j];
1353
+ if (p.name.value) {
1354
+ o.scope.add(p.name.value, 'var', true);
1355
+ }
1356
+ }
1357
+ splats = new Assign(new Value(new Arr((function() {
1358
+ var _k, _len3, _ref4, _results;
1359
+ _ref4 = this.params;
1360
+ _results = [];
1361
+ for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
1362
+ p = _ref4[_k];
1363
+ _results.push(p.asReference(o));
1364
+ }
1365
+ return _results;
1366
+ }).call(this))), new Value(new Literal('arguments')));
1367
+ break;
1368
+ }
1369
+ }
1370
+ _ref4 = this.params;
1371
+ for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
1372
+ param = _ref4[_k];
1373
+ if (param.isComplex()) {
1374
+ val = ref = param.asReference(o);
1375
+ if (param.value) {
1376
+ val = new Op('?', ref, param.value);
1377
+ }
1378
+ exprs.push(new Assign(new Value(param.name), val, '=', {
1379
+ param: true
1380
+ }));
1381
+ } else {
1382
+ ref = param;
1383
+ if (param.value) {
1384
+ lit = new Literal(ref.name.value + ' == null');
1385
+ val = new Assign(new Value(param.name), param.value, '=');
1386
+ exprs.push(new If(lit, val));
1387
+ }
1388
+ }
1389
+ if (!splats) {
1390
+ vars.push(ref);
1391
+ }
1392
+ }
1393
+ wasEmpty = this.body.isEmpty();
1394
+ if (splats) {
1395
+ exprs.unshift(splats);
1396
+ }
1397
+ if (exprs.length) {
1398
+ (_ref5 = this.body.expressions).unshift.apply(_ref5, exprs);
1399
+ }
1400
+ if (!splats) {
1401
+ for (i = 0, _len4 = vars.length; i < _len4; i++) {
1402
+ v = vars[i];
1403
+ o.scope.parameter(vars[i] = v.compile(o));
1404
+ }
1405
+ }
1406
+ if (!(wasEmpty || this.noReturn)) {
1407
+ this.body.makeReturn();
1408
+ }
1409
+ idt = o.indent;
1410
+ code = 'function';
1411
+ if (this.ctor) {
1412
+ code += ' ' + this.name;
1413
+ }
1414
+ code += '(' + vars.join(', ') + ') {';
1415
+ if (!this.body.isEmpty()) {
1416
+ code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab;
1417
+ }
1418
+ code += '}';
1419
+ if (this.ctor) {
1420
+ return this.tab + code;
1421
+ }
1422
+ if (this.bound) {
1423
+ return utility('bind') + ("(" + code + ", " + this.context + ")");
1424
+ }
1425
+ if (this.front || (o.level >= LEVEL_ACCESS)) {
1426
+ return "(" + code + ")";
1427
+ } else {
1428
+ return code;
1429
+ }
1430
+ };
1431
+ Code.prototype.traverseChildren = function(crossScope, func) {
1432
+ if (crossScope) {
1433
+ return Code.__super__.traverseChildren.call(this, crossScope, func);
1434
+ }
1435
+ };
1436
+ return Code;
1437
+ })();
1438
+ exports.Param = Param = (function() {
1439
+ __extends(Param, Base);
1440
+ function Param(name, value, splat) {
1441
+ this.name = name;
1442
+ this.value = value;
1443
+ this.splat = splat;
1444
+ }
1445
+ Param.prototype.children = ['name', 'value'];
1446
+ Param.prototype.compile = function(o) {
1447
+ return this.name.compile(o, LEVEL_LIST);
1448
+ };
1449
+ Param.prototype.asReference = function(o) {
1450
+ var node;
1451
+ if (this.reference) {
1452
+ return this.reference;
1453
+ }
1454
+ node = this.name;
1455
+ if (node["this"]) {
1456
+ node = node.properties[0].name;
1457
+ if (node.value.reserved) {
1458
+ node = new Literal('_' + node.value);
1459
+ }
1460
+ } else if (node.isComplex()) {
1461
+ node = new Literal(o.scope.freeVariable('arg'));
1462
+ }
1463
+ node = new Value(node);
1464
+ if (this.splat) {
1465
+ node = new Splat(node);
1466
+ }
1467
+ return this.reference = node;
1468
+ };
1469
+ Param.prototype.isComplex = function() {
1470
+ return this.name.isComplex();
1471
+ };
1472
+ return Param;
1473
+ })();
1474
+ exports.Splat = Splat = (function() {
1475
+ __extends(Splat, Base);
1476
+ Splat.prototype.children = ['name'];
1477
+ Splat.prototype.isAssignable = YES;
1478
+ function Splat(name) {
1479
+ this.name = name.compile ? name : new Literal(name);
1480
+ }
1481
+ Splat.prototype.assigns = function(name) {
1482
+ return this.name.assigns(name);
1483
+ };
1484
+ Splat.prototype.compile = function(o) {
1485
+ if (this.index != null) {
1486
+ return this.compileParam(o);
1487
+ } else {
1488
+ return this.name.compile(o);
1489
+ }
1490
+ };
1491
+ Splat.compileSplattedArray = function(o, list, apply) {
1492
+ var args, base, code, i, index, node, _len;
1493
+ index = -1;
1494
+ while ((node = list[++index]) && !(node instanceof Splat)) {
1495
+ continue;
1496
+ }
1497
+ if (index >= list.length) {
1498
+ return '';
1499
+ }
1500
+ if (list.length === 1) {
1501
+ code = list[0].compile(o, LEVEL_LIST);
1502
+ if (apply) {
1503
+ return code;
1504
+ }
1505
+ return "" + (utility('slice')) + ".call(" + code + ")";
1506
+ }
1507
+ args = list.slice(index);
1508
+ for (i = 0, _len = args.length; i < _len; i++) {
1509
+ node = args[i];
1510
+ code = node.compile(o, LEVEL_LIST);
1511
+ args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]";
1512
+ }
1513
+ if (index === 0) {
1514
+ return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
1515
+ }
1516
+ base = (function() {
1517
+ var _i, _len2, _ref2, _results;
1518
+ _ref2 = list.slice(0, index);
1519
+ _results = [];
1520
+ for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) {
1521
+ node = _ref2[_i];
1522
+ _results.push(node.compile(o, LEVEL_LIST));
1523
+ }
1524
+ return _results;
1525
+ })();
1526
+ return "[" + (base.join(', ')) + "].concat(" + (args.join(', ')) + ")";
1527
+ };
1528
+ return Splat;
1529
+ })();
1530
+ exports.While = While = (function() {
1531
+ __extends(While, Base);
1532
+ function While(condition, options) {
1533
+ this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
1534
+ this.guard = options != null ? options.guard : void 0;
1535
+ }
1536
+ While.prototype.children = ['condition', 'guard', 'body'];
1537
+ While.prototype.isStatement = YES;
1538
+ While.prototype.makeReturn = function() {
1539
+ this.returns = true;
1540
+ return this;
1541
+ };
1542
+ While.prototype.addBody = function(body) {
1543
+ this.body = body;
1544
+ return this;
1545
+ };
1546
+ While.prototype.jumps = function() {
1547
+ var expressions, node, _i, _len;
1548
+ expressions = this.body.expressions;
1549
+ if (!expressions.length) {
1550
+ return false;
1551
+ }
1552
+ for (_i = 0, _len = expressions.length; _i < _len; _i++) {
1553
+ node = expressions[_i];
1554
+ if (node.jumps({
1555
+ loop: true
1556
+ })) {
1557
+ return node;
1558
+ }
1559
+ }
1560
+ return false;
1561
+ };
1562
+ While.prototype.compileNode = function(o) {
1563
+ var body, code, rvar, set;
1564
+ o.indent += TAB;
1565
+ set = '';
1566
+ body = this.body;
1567
+ if (body.isEmpty()) {
1568
+ body = '';
1569
+ } else {
1570
+ if (o.level > LEVEL_TOP || this.returns) {
1571
+ rvar = o.scope.freeVariable('results');
1572
+ set = "" + this.tab + rvar + " = [];\n";
1573
+ if (body) {
1574
+ body = Push.wrap(rvar, body);
1575
+ }
1576
+ }
1577
+ if (this.guard) {
1578
+ body = Block.wrap([new If(this.guard, body)]);
1579
+ }
1580
+ body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab;
1581
+ }
1582
+ code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}");
1583
+ if (this.returns) {
1584
+ code += "\n" + this.tab + "return " + rvar + ";";
1585
+ }
1586
+ return code;
1587
+ };
1588
+ return While;
1589
+ })();
1590
+ exports.Op = Op = (function() {
1591
+ var CONVERSIONS, INVERSIONS;
1592
+ __extends(Op, Base);
1593
+ function Op(op, first, second, flip) {
1594
+ var call;
1595
+ if (op === 'in') {
1596
+ return new In(first, second);
1597
+ }
1598
+ if (op === 'do') {
1599
+ call = new Call(first, first.params || []);
1600
+ call["do"] = true;
1601
+ return call;
1602
+ }
1603
+ if (op === 'new') {
1604
+ if (first instanceof Call && !first["do"] && !first.isNew) {
1605
+ return first.newInstance();
1606
+ }
1607
+ if (first instanceof Code && first.bound || first["do"]) {
1608
+ first = new Parens(first);
1609
+ }
1610
+ }
1611
+ this.operator = CONVERSIONS[op] || op;
1612
+ this.first = first;
1613
+ this.second = second;
1614
+ this.flip = !!flip;
1615
+ return this;
1616
+ }
1617
+ CONVERSIONS = {
1618
+ '==': '===',
1619
+ '!=': '!==',
1620
+ 'of': 'in'
1621
+ };
1622
+ INVERSIONS = {
1623
+ '!==': '===',
1624
+ '===': '!=='
1625
+ };
1626
+ Op.prototype.children = ['first', 'second'];
1627
+ Op.prototype.isSimpleNumber = NO;
1628
+ Op.prototype.isUnary = function() {
1629
+ return !this.second;
1630
+ };
1631
+ Op.prototype.isComplex = function() {
1632
+ var _ref2;
1633
+ return !(this.isUnary() && ((_ref2 = this.operator) === '+' || _ref2 === '-')) || this.first.isComplex();
1634
+ };
1635
+ Op.prototype.isChainable = function() {
1636
+ var _ref2;
1637
+ return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!==';
1638
+ };
1639
+ Op.prototype.invert = function() {
1640
+ var allInvertable, curr, fst, op, _ref2;
1641
+ if (this.isChainable() && this.first.isChainable()) {
1642
+ allInvertable = true;
1643
+ curr = this;
1644
+ while (curr && curr.operator) {
1645
+ allInvertable && (allInvertable = curr.operator in INVERSIONS);
1646
+ curr = curr.first;
1647
+ }
1648
+ if (!allInvertable) {
1649
+ return new Parens(this).invert();
1650
+ }
1651
+ curr = this;
1652
+ while (curr && curr.operator) {
1653
+ curr.invert = !curr.invert;
1654
+ curr.operator = INVERSIONS[curr.operator];
1655
+ curr = curr.first;
1656
+ }
1657
+ return this;
1658
+ } else if (op = INVERSIONS[this.operator]) {
1659
+ this.operator = op;
1660
+ if (this.first.unwrap() instanceof Op) {
1661
+ this.first.invert();
1662
+ }
1663
+ return this;
1664
+ } else if (this.second) {
1665
+ return new Parens(this).invert();
1666
+ } else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) {
1667
+ return fst;
1668
+ } else {
1669
+ return new Op('!', this);
1670
+ }
1671
+ };
1672
+ Op.prototype.unfoldSoak = function(o) {
1673
+ var _ref2;
1674
+ return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
1675
+ };
1676
+ Op.prototype.compileNode = function(o) {
1677
+ var code;
1678
+ if (this.isUnary()) {
1679
+ return this.compileUnary(o);
1680
+ }
1681
+ if (this.isChainable() && this.first.isChainable()) {
1682
+ return this.compileChain(o);
1683
+ }
1684
+ if (this.operator === '?') {
1685
+ return this.compileExistence(o);
1686
+ }
1687
+ this.first.front = this.front;
1688
+ code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP);
1689
+ if (o.level <= LEVEL_OP) {
1690
+ return code;
1691
+ } else {
1692
+ return "(" + code + ")";
1693
+ }
1694
+ };
1695
+ Op.prototype.compileChain = function(o) {
1696
+ var code, fst, shared, _ref2;
1697
+ _ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
1698
+ fst = this.first.compile(o, LEVEL_OP);
1699
+ code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
1700
+ return "(" + code + ")";
1701
+ };
1702
+ Op.prototype.compileExistence = function(o) {
1703
+ var fst, ref;
1704
+ if (this.first.isComplex()) {
1705
+ ref = new Literal(o.scope.freeVariable('ref'));
1706
+ fst = new Parens(new Assign(ref, this.first));
1707
+ } else {
1708
+ fst = this.first;
1709
+ ref = fst;
1710
+ }
1711
+ return new If(new Existence(fst), ref, {
1712
+ type: 'if'
1713
+ }).addElse(this.second).compile(o);
1714
+ };
1715
+ Op.prototype.compileUnary = function(o) {
1716
+ var op, parts;
1717
+ parts = [op = this.operator];
1718
+ if ((op === 'new' || op === 'typeof' || op === 'delete') || (op === '+' || op === '-') && this.first instanceof Op && this.first.operator === op) {
1719
+ parts.push(' ');
1720
+ }
1721
+ if (op === 'new' && this.first.isStatement(o)) {
1722
+ this.first = new Parens(this.first);
1723
+ }
1724
+ parts.push(this.first.compile(o, LEVEL_OP));
1725
+ if (this.flip) {
1726
+ parts.reverse();
1727
+ }
1728
+ return parts.join('');
1729
+ };
1730
+ Op.prototype.toString = function(idt) {
1731
+ return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
1732
+ };
1733
+ return Op;
1734
+ })();
1735
+ exports.In = In = (function() {
1736
+ __extends(In, Base);
1737
+ function In(object, array) {
1738
+ this.object = object;
1739
+ this.array = array;
1740
+ }
1741
+ In.prototype.children = ['object', 'array'];
1742
+ In.prototype.invert = NEGATE;
1743
+ In.prototype.compileNode = function(o) {
1744
+ var hasSplat, obj, _i, _len, _ref2;
1745
+ if (this.array instanceof Value && this.array.isArray()) {
1746
+ _ref2 = this.array.base.objects;
1747
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1748
+ obj = _ref2[_i];
1749
+ if (obj instanceof Splat) {
1750
+ hasSplat = true;
1751
+ break;
1752
+ }
1753
+ }
1754
+ if (!hasSplat) {
1755
+ return this.compileOrTest(o);
1756
+ }
1757
+ }
1758
+ return this.compileLoopTest(o);
1759
+ };
1760
+ In.prototype.compileOrTest = function(o) {
1761
+ var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;
1762
+ _ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
1763
+ _ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
1764
+ tests = (function() {
1765
+ var _len, _ref4, _results;
1766
+ _ref4 = this.array.base.objects;
1767
+ _results = [];
1768
+ for (i = 0, _len = _ref4.length; i < _len; i++) {
1769
+ item = _ref4[i];
1770
+ _results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_OP));
1771
+ }
1772
+ return _results;
1773
+ }).call(this);
1774
+ if (tests.length === 0) {
1775
+ return 'false';
1776
+ }
1777
+ tests = tests.join(cnj);
1778
+ if (o.level < LEVEL_OP) {
1779
+ return tests;
1780
+ } else {
1781
+ return "(" + tests + ")";
1782
+ }
1783
+ };
1784
+ In.prototype.compileLoopTest = function(o) {
1785
+ var code, ref, sub, _ref2;
1786
+ _ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
1787
+ code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
1788
+ if (sub === ref) {
1789
+ return code;
1790
+ }
1791
+ code = sub + ', ' + code;
1792
+ if (o.level < LEVEL_LIST) {
1793
+ return code;
1794
+ } else {
1795
+ return "(" + code + ")";
1796
+ }
1797
+ };
1798
+ In.prototype.toString = function(idt) {
1799
+ return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
1800
+ };
1801
+ return In;
1802
+ })();
1803
+ exports.Try = Try = (function() {
1804
+ __extends(Try, Base);
1805
+ function Try(attempt, error, recovery, ensure) {
1806
+ this.attempt = attempt;
1807
+ this.error = error;
1808
+ this.recovery = recovery;
1809
+ this.ensure = ensure;
1810
+ }
1811
+ Try.prototype.children = ['attempt', 'recovery', 'ensure'];
1812
+ Try.prototype.isStatement = YES;
1813
+ Try.prototype.jumps = function(o) {
1814
+ var _ref2;
1815
+ return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0);
1816
+ };
1817
+ Try.prototype.makeReturn = function() {
1818
+ if (this.attempt) {
1819
+ this.attempt = this.attempt.makeReturn();
1820
+ }
1821
+ if (this.recovery) {
1822
+ this.recovery = this.recovery.makeReturn();
1823
+ }
1824
+ return this;
1825
+ };
1826
+ Try.prototype.compileNode = function(o) {
1827
+ var catchPart, errorPart;
1828
+ o.indent += TAB;
1829
+ errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
1830
+ catchPart = this.recovery ? (o.scope.add(this.error.value, 'param'), " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}") : !(this.ensure || this.recovery) ? ' catch (_e) {}' : void 0;
1831
+ return ("" + this.tab + "try {\n" + (this.attempt.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" + (catchPart || '')) + (this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '');
1832
+ };
1833
+ return Try;
1834
+ })();
1835
+ exports.Throw = Throw = (function() {
1836
+ __extends(Throw, Base);
1837
+ function Throw(expression) {
1838
+ this.expression = expression;
1839
+ }
1840
+ Throw.prototype.children = ['expression'];
1841
+ Throw.prototype.isStatement = YES;
1842
+ Throw.prototype.jumps = NO;
1843
+ Throw.prototype.makeReturn = THIS;
1844
+ Throw.prototype.compileNode = function(o) {
1845
+ return this.tab + ("throw " + (this.expression.compile(o)) + ";");
1846
+ };
1847
+ return Throw;
1848
+ })();
1849
+ exports.Existence = Existence = (function() {
1850
+ __extends(Existence, Base);
1851
+ function Existence(expression) {
1852
+ this.expression = expression;
1853
+ }
1854
+ Existence.prototype.children = ['expression'];
1855
+ Existence.prototype.invert = NEGATE;
1856
+ Existence.prototype.compileNode = function(o) {
1857
+ var cmp, cnj, code, _ref2;
1858
+ code = this.expression.compile(o, LEVEL_OP);
1859
+ code = IDENTIFIER.test(code) && !o.scope.check(code) ? ((_ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1], _ref2), "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null") : "" + code + " " + (this.negated ? '==' : '!=') + " null";
1860
+ if (o.level <= LEVEL_COND) {
1861
+ return code;
1862
+ } else {
1863
+ return "(" + code + ")";
1864
+ }
1865
+ };
1866
+ return Existence;
1867
+ })();
1868
+ exports.Parens = Parens = (function() {
1869
+ __extends(Parens, Base);
1870
+ function Parens(body) {
1871
+ this.body = body;
1872
+ }
1873
+ Parens.prototype.children = ['body'];
1874
+ Parens.prototype.unwrap = function() {
1875
+ return this.body;
1876
+ };
1877
+ Parens.prototype.isComplex = function() {
1878
+ return this.body.isComplex();
1879
+ };
1880
+ Parens.prototype.makeReturn = function() {
1881
+ return this.body.makeReturn();
1882
+ };
1883
+ Parens.prototype.compileNode = function(o) {
1884
+ var bare, code, expr;
1885
+ expr = this.body.unwrap();
1886
+ if (expr instanceof Value && expr.isAtomic()) {
1887
+ expr.front = this.front;
1888
+ return expr.compile(o);
1889
+ }
1890
+ code = expr.compile(o, LEVEL_PAREN);
1891
+ bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));
1892
+ if (bare) {
1893
+ return code;
1894
+ } else {
1895
+ return "(" + code + ")";
1896
+ }
1897
+ };
1898
+ return Parens;
1899
+ })();
1900
+ exports.For = For = (function() {
1901
+ __extends(For, Base);
1902
+ function For(body, source) {
1903
+ var _ref2;
1904
+ this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
1905
+ this.body = Block.wrap([body]);
1906
+ this.own = !!source.own;
1907
+ this.object = !!source.object;
1908
+ if (this.object) {
1909
+ _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
1910
+ }
1911
+ if (this.index instanceof Value) {
1912
+ throw SyntaxError('index cannot be a pattern matching expression');
1913
+ }
1914
+ this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
1915
+ this.pattern = this.name instanceof Value;
1916
+ if (this.range && this.index) {
1917
+ throw SyntaxError('indexes do not apply to range loops');
1918
+ }
1919
+ if (this.range && this.pattern) {
1920
+ throw SyntaxError('cannot pattern match over range loops');
1921
+ }
1922
+ this.returns = false;
1923
+ }
1924
+ For.prototype.children = ['body', 'source', 'guard', 'step'];
1925
+ For.prototype.isStatement = YES;
1926
+ For.prototype.jumps = While.prototype.jumps;
1927
+ For.prototype.makeReturn = function() {
1928
+ this.returns = true;
1929
+ return this;
1930
+ };
1931
+ For.prototype.compileNode = function(o) {
1932
+ var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
1933
+ body = Block.wrap([this.body]);
1934
+ lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
1935
+ if (lastJumps && lastJumps instanceof Return) {
1936
+ this.returns = false;
1937
+ }
1938
+ source = this.range ? this.source.base : this.source;
1939
+ scope = o.scope;
1940
+ name = this.name && this.name.compile(o, LEVEL_LIST);
1941
+ index = this.index && this.index.compile(o, LEVEL_LIST);
1942
+ if (name && !this.pattern) {
1943
+ scope.find(name, {
1944
+ immediate: true
1945
+ });
1946
+ }
1947
+ if (index) {
1948
+ scope.find(index, {
1949
+ immediate: true
1950
+ });
1951
+ }
1952
+ if (this.returns) {
1953
+ rvar = scope.freeVariable('results');
1954
+ }
1955
+ ivar = (this.range ? name : index) || scope.freeVariable('i');
1956
+ if (this.step && !this.range) {
1957
+ stepvar = scope.freeVariable("step");
1958
+ }
1959
+ if (this.pattern) {
1960
+ name = ivar;
1961
+ }
1962
+ varPart = '';
1963
+ guardPart = '';
1964
+ defPart = '';
1965
+ idt1 = this.tab + TAB;
1966
+ if (this.range) {
1967
+ forPart = source.compile(merge(o, {
1968
+ index: ivar,
1969
+ step: this.step
1970
+ }));
1971
+ } else {
1972
+ svar = this.source.compile(o, LEVEL_LIST);
1973
+ if ((name || this.own) && !IDENTIFIER.test(svar)) {
1974
+ defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
1975
+ svar = ref;
1976
+ }
1977
+ if (name && !this.pattern) {
1978
+ namePart = "" + name + " = " + svar + "[" + ivar + "]";
1979
+ }
1980
+ if (!this.object) {
1981
+ lvar = scope.freeVariable('len');
1982
+ forVarPart = ("" + ivar + " = 0, " + lvar + " = " + svar + ".length") + (this.step ? ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP)) : '');
1983
+ stepPart = this.step ? "" + ivar + " += " + stepvar : "" + ivar + "++";
1984
+ forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart;
1985
+ }
1986
+ }
1987
+ if (this.returns) {
1988
+ resultPart = "" + this.tab + rvar + " = [];\n";
1989
+ returnResult = "\n" + this.tab + "return " + rvar + ";";
1990
+ body = Push.wrap(rvar, body);
1991
+ }
1992
+ if (this.guard) {
1993
+ body = Block.wrap([new If(this.guard, body)]);
1994
+ }
1995
+ if (this.pattern) {
1996
+ body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")));
1997
+ }
1998
+ defPart += this.pluckDirectCall(o, body);
1999
+ if (namePart) {
2000
+ varPart = "\n" + idt1 + namePart + ";";
2001
+ }
2002
+ if (this.object) {
2003
+ forPart = "" + ivar + " in " + svar;
2004
+ if (this.own) {
2005
+ guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;";
2006
+ }
2007
+ }
2008
+ body = body.compile(merge(o, {
2009
+ indent: idt1
2010
+ }), LEVEL_TOP);
2011
+ if (body) {
2012
+ body = '\n' + body + '\n';
2013
+ }
2014
+ return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || '');
2015
+ };
2016
+ For.prototype.pluckDirectCall = function(o, body) {
2017
+ var base, defs, expr, fn, idx, ref, val, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
2018
+ defs = '';
2019
+ _ref2 = body.expressions;
2020
+ for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
2021
+ expr = _ref2[idx];
2022
+ expr = expr.unwrapAll();
2023
+ if (!(expr instanceof Call)) {
2024
+ continue;
2025
+ }
2026
+ val = expr.variable.unwrapAll();
2027
+ if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) {
2028
+ continue;
2029
+ }
2030
+ fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val;
2031
+ ref = new Literal(o.scope.freeVariable('fn'));
2032
+ base = new Value(ref);
2033
+ if (val.base) {
2034
+ _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
2035
+ }
2036
+ body.expressions[idx] = new Call(base, expr.args);
2037
+ defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n';
2038
+ }
2039
+ return defs;
2040
+ };
2041
+ return For;
2042
+ })();
2043
+ exports.Switch = Switch = (function() {
2044
+ __extends(Switch, Base);
2045
+ function Switch(subject, cases, otherwise) {
2046
+ this.subject = subject;
2047
+ this.cases = cases;
2048
+ this.otherwise = otherwise;
2049
+ }
2050
+ Switch.prototype.children = ['subject', 'cases', 'otherwise'];
2051
+ Switch.prototype.isStatement = YES;
2052
+ Switch.prototype.jumps = function(o) {
2053
+ var block, conds, _i, _len, _ref2, _ref3, _ref4;
2054
+ if (o == null) {
2055
+ o = {
2056
+ block: true
2057
+ };
2058
+ }
2059
+ _ref2 = this.cases;
2060
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2061
+ _ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
2062
+ if (block.jumps(o)) {
2063
+ return block;
2064
+ }
2065
+ }
2066
+ return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0;
2067
+ };
2068
+ Switch.prototype.makeReturn = function() {
2069
+ var pair, _i, _len, _ref2, _ref3;
2070
+ _ref2 = this.cases;
2071
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2072
+ pair = _ref2[_i];
2073
+ pair[1].makeReturn();
2074
+ }
2075
+ if ((_ref3 = this.otherwise) != null) {
2076
+ _ref3.makeReturn();
2077
+ }
2078
+ return this;
2079
+ };
2080
+ Switch.prototype.compileNode = function(o) {
2081
+ var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _len, _len2, _ref2, _ref3, _ref4, _ref5;
2082
+ idt1 = o.indent + TAB;
2083
+ idt2 = o.indent = idt1 + TAB;
2084
+ code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
2085
+ _ref3 = this.cases;
2086
+ for (i = 0, _len = _ref3.length; i < _len; i++) {
2087
+ _ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1];
2088
+ _ref5 = flatten([conditions]);
2089
+ for (_i = 0, _len2 = _ref5.length; _i < _len2; _i++) {
2090
+ cond = _ref5[_i];
2091
+ if (!this.subject) {
2092
+ cond = cond.invert();
2093
+ }
2094
+ code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
2095
+ }
2096
+ if (body = block.compile(o, LEVEL_TOP)) {
2097
+ code += body + '\n';
2098
+ }
2099
+ if (i === this.cases.length - 1 && !this.otherwise) {
2100
+ break;
2101
+ }
2102
+ expr = this.lastNonComment(block.expressions);
2103
+ if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {
2104
+ continue;
2105
+ }
2106
+ code += idt2 + 'break;\n';
2107
+ }
2108
+ if (this.otherwise && this.otherwise.expressions.length) {
2109
+ code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n");
2110
+ }
2111
+ return code + this.tab + '}';
2112
+ };
2113
+ return Switch;
2114
+ })();
2115
+ exports.If = If = (function() {
2116
+ __extends(If, Base);
2117
+ function If(condition, body, options) {
2118
+ this.body = body;
2119
+ if (options == null) {
2120
+ options = {};
2121
+ }
2122
+ this.condition = options.type === 'unless' ? condition.invert() : condition;
2123
+ this.elseBody = null;
2124
+ this.isChain = false;
2125
+ this.soak = options.soak;
2126
+ }
2127
+ If.prototype.children = ['condition', 'body', 'elseBody'];
2128
+ If.prototype.bodyNode = function() {
2129
+ var _ref2;
2130
+ return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0;
2131
+ };
2132
+ If.prototype.elseBodyNode = function() {
2133
+ var _ref2;
2134
+ return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0;
2135
+ };
2136
+ If.prototype.addElse = function(elseBody) {
2137
+ if (this.isChain) {
2138
+ this.elseBodyNode().addElse(elseBody);
2139
+ } else {
2140
+ this.isChain = elseBody instanceof If;
2141
+ this.elseBody = this.ensureBlock(elseBody);
2142
+ }
2143
+ return this;
2144
+ };
2145
+ If.prototype.isStatement = function(o) {
2146
+ var _ref2;
2147
+ return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0);
2148
+ };
2149
+ If.prototype.jumps = function(o) {
2150
+ var _ref2;
2151
+ return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0);
2152
+ };
2153
+ If.prototype.compileNode = function(o) {
2154
+ if (this.isStatement(o)) {
2155
+ return this.compileStatement(o);
2156
+ } else {
2157
+ return this.compileExpression(o);
2158
+ }
2159
+ };
2160
+ If.prototype.makeReturn = function() {
2161
+ this.body && (this.body = new Block([this.body.makeReturn()]));
2162
+ this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn()]));
2163
+ return this;
2164
+ };
2165
+ If.prototype.ensureBlock = function(node) {
2166
+ if (node instanceof Block) {
2167
+ return node;
2168
+ } else {
2169
+ return new Block([node]);
2170
+ }
2171
+ };
2172
+ If.prototype.compileStatement = function(o) {
2173
+ var body, child, cond, exeq, ifPart;
2174
+ child = del(o, 'chainChild');
2175
+ exeq = del(o, 'isExistentialEquals');
2176
+ if (exeq) {
2177
+ return new If(this.condition.invert(), this.elseBodyNode(), {
2178
+ type: 'if'
2179
+ }).compile(o);
2180
+ }
2181
+ cond = this.condition.compile(o, LEVEL_PAREN);
2182
+ o.indent += TAB;
2183
+ body = this.ensureBlock(this.body).compile(o);
2184
+ if (body) {
2185
+ body = "\n" + body + "\n" + this.tab;
2186
+ }
2187
+ ifPart = "if (" + cond + ") {" + body + "}";
2188
+ if (!child) {
2189
+ ifPart = this.tab + ifPart;
2190
+ }
2191
+ if (!this.elseBody) {
2192
+ return ifPart;
2193
+ }
2194
+ return ifPart + ' else ' + (this.isChain ? (o.indent = this.tab, o.chainChild = true, this.elseBody.unwrap().compile(o, LEVEL_TOP)) : "{\n" + (this.elseBody.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}");
2195
+ };
2196
+ If.prototype.compileExpression = function(o) {
2197
+ var alt, body, code, cond;
2198
+ cond = this.condition.compile(o, LEVEL_COND);
2199
+ body = this.bodyNode().compile(o, LEVEL_LIST);
2200
+ alt = this.elseBodyNode() ? this.elseBodyNode().compile(o, LEVEL_LIST) : 'void 0';
2201
+ code = "" + cond + " ? " + body + " : " + alt;
2202
+ if (o.level >= LEVEL_COND) {
2203
+ return "(" + code + ")";
2204
+ } else {
2205
+ return code;
2206
+ }
2207
+ };
2208
+ If.prototype.unfoldSoak = function() {
2209
+ return this.soak && this;
2210
+ };
2211
+ return If;
2212
+ })();
2213
+ Push = {
2214
+ wrap: function(name, exps) {
2215
+ if (exps.isEmpty() || last(exps.expressions).jumps()) {
2216
+ return exps;
2217
+ }
2218
+ return exps.push(new Call(new Value(new Literal(name), [new Access(new Literal('push'))]), [exps.pop()]));
2219
+ }
2220
+ };
2221
+ Closure = {
2222
+ wrap: function(expressions, statement, noReturn) {
2223
+ var args, call, func, mentionsArgs, meth;
2224
+ if (expressions.jumps()) {
2225
+ return expressions;
2226
+ }
2227
+ func = new Code([], Block.wrap([expressions]));
2228
+ args = [];
2229
+ if ((mentionsArgs = expressions.contains(this.literalArgs)) || expressions.contains(this.literalThis)) {
2230
+ meth = new Literal(mentionsArgs ? 'apply' : 'call');
2231
+ args = [new Literal('this')];
2232
+ if (mentionsArgs) {
2233
+ args.push(new Literal('arguments'));
2234
+ }
2235
+ func = new Value(func, [new Access(meth)]);
2236
+ }
2237
+ func.noReturn = noReturn;
2238
+ call = new Call(func, args);
2239
+ if (statement) {
2240
+ return Block.wrap([call]);
2241
+ } else {
2242
+ return call;
2243
+ }
2244
+ },
2245
+ literalArgs: function(node) {
2246
+ return node instanceof Literal && node.value === 'arguments' && !node.asKey;
2247
+ },
2248
+ literalThis: function(node) {
2249
+ return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound);
2250
+ }
2251
+ };
2252
+ unfoldSoak = function(o, parent, name) {
2253
+ var ifn;
2254
+ if (!(ifn = parent[name].unfoldSoak(o))) {
2255
+ return;
2256
+ }
2257
+ parent[name] = ifn.body;
2258
+ ifn.body = new Value(parent);
2259
+ return ifn;
2260
+ };
2261
+ UTILITIES = {
2262
+ "extends": 'function(child, parent) {\n for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n child.__super__ = parent.prototype;\n return child;\n}',
2263
+ bind: 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }',
2264
+ indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (this[i] === item) return i;\n }\n return -1;\n}',
2265
+ hasProp: 'Object.prototype.hasOwnProperty',
2266
+ slice: 'Array.prototype.slice'
2267
+ };
2268
+ LEVEL_TOP = 1;
2269
+ LEVEL_PAREN = 2;
2270
+ LEVEL_LIST = 3;
2271
+ LEVEL_COND = 4;
2272
+ LEVEL_OP = 5;
2273
+ LEVEL_ACCESS = 6;
2274
+ TAB = ' ';
2275
+ IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
2276
+ IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$");
2277
+ SIMPLENUM = /^[+-]?\d+$/;
2278
+ METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\]))|(" + IDENTIFIER_STR + ")$");
2279
+ IS_STRING = /^['"]/;
2280
+ utility = function(name) {
2281
+ var ref;
2282
+ ref = "__" + name;
2283
+ Scope.root.assign(ref, UTILITIES[name]);
2284
+ return ref;
2285
+ };
2286
+ multident = function(code, tab) {
2287
+ return code.replace(/\n/g, '$&' + tab);
2288
+ };
2289
+ }).call(this);