coffeescript-router 0.0.1

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