Skip to content
This repository
Browse code

got indentation for if else's working pretty well

  • Loading branch information...
commit f3c82b315475c70960fc41dcde6164123e12a62c 1 parent e1e2137
Maxwell Krohn authored November 19, 2011
277  lib/coffee-script/nodes.js
... ...
@@ -1,18 +1,13 @@
1 1
 (function() {
2  
-<<<<<<< HEAD
3  
-  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, RESERVED, 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,
4  
-    __hasProp = Object.prototype.hasOwnProperty,
5  
-    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
6  
-    __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
7  
-=======
8  
-  var Access, Arr, Assign, Await, Base, Block, CALL_CONTINUATION, Call, Class, Closure, Code, Comment, CpsCascade, 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, RESERVED, 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;
  2
+  var Access, Arr, Assign, Await, Base, Block, CALL_CONTINUATION, Call, Class, Closure, Code, Comment, CpsCascade, 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, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, tame, unfoldSoak, utility, _ref;
9 3
   var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (__hasProp.call(this, i) && this[i] === item) return i; } return -1; };
10  
->>>>>>> src/nodes.coffee
11 4
 
12 5
   Scope = require('./scope').Scope;
13 6
 
14 7
   RESERVED = require('./lexer').RESERVED;
15 8
 
  9
+  tame = require('./tame');
  10
+
16 11
   _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;
17 12
 
18 13
   exports.extend = extend;
@@ -35,13 +30,11 @@
35 30
   };
36 31
 
37 32
   CALL_CONTINUATION = function() {
38  
-    return new Call(new Literal("_k", []));
  33
+    return new Call(new Literal(tame["const"].k, []));
39 34
   };
40 35
 
41 36
   exports.Base = Base = (function() {
42 37
 
43  
-    Base.name = 'Base';
44  
-
45 38
     function Base() {}
46 39
 
47 40
     Base.prototype.compile = function(o, lvl) {
@@ -68,8 +61,13 @@
68 61
     };
69 62
 
70 63
     Base.prototype.compileCps = function(o) {
  64
+      var node, ret;
71 65
       this.gotCpsSplit = true;
72  
-      return this.tab + CpsCascade.wrap(this, this.tameContinuationBlock).compileNode(o);
  66
+      node = CpsCascade.wrap(this, this.tameContinuationBlock);
  67
+      console.log("yo INDENT" + o.indent + "TNEDNI");
  68
+      ret = node.compile(o);
  69
+      console.log("yo TAB" + node.tab + "BAT");
  70
+      return ret;
73 71
     };
74 72
 
75 73
     Base.prototype.cache = function(o, level, reused) {
@@ -282,8 +280,6 @@
282 280
 
283 281
     __extends(Block, Base);
284 282
 
285  
-    Block.name = 'Block';
286  
-
287 283
     function Block(nodes) {
288 284
       this.expressions = compact(flatten(nodes || []));
289 285
     }
@@ -375,11 +371,7 @@
375 371
         } else if (top) {
376 372
           node.front = true;
377 373
           code = node.compile(o);
378  
-          if (!node.isStatement(o)) {
379  
-            code = "" + this.tab + code + ";";
380  
-            if (node instanceof Literal) code = "" + code + "\n";
381  
-          }
382  
-          codes.push(code);
  374
+          codes.push(node.isStatement(o) ? code : "" + this.tab + code + ";");
383 375
         } else {
384 376
           codes.push(node.compile(o, LEVEL_LIST));
385 377
         }
@@ -400,42 +392,6 @@
400 392
     };
401 393
 
402 394
     Block.prototype.compileRoot = function(o) {
403  
-<<<<<<< HEAD
404  
-      var code, exp, i, prelude, preludeExps, rest;
405  
-      o.indent = o.bare ? '' : TAB;
406  
-      o.scope = new Scope(null, this, null);
407  
-      o.level = LEVEL_TOP;
408  
-      this.spaced = true;
409  
-      prelude = "";
410  
-      if (!o.bare) {
411  
-        preludeExps = (function() {
412  
-          var _i, _len, _ref2, _results;
413  
-          _ref2 = this.expressions;
414  
-          _results = [];
415  
-          for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
416  
-            exp = _ref2[i];
417  
-            if (!(exp.unwrap() instanceof Comment)) break;
418  
-            _results.push(exp);
419  
-          }
420  
-          return _results;
421  
-        }).call(this);
422  
-        rest = this.expressions.slice(preludeExps.length);
423  
-        this.expressions = preludeExps;
424  
-        if (preludeExps.length) {
425  
-          prelude = "" + (this.compileNode(merge(o, {
426  
-            indent: ''
427  
-          }))) + "\n";
428  
-        }
429  
-        this.expressions = rest;
430  
-      }
431  
-      code = this.compileWithDeclarations(o);
432  
-      if (o.bare) return code;
433  
-      return "" + prelude + "(function() {\n" + code + "\n}).call(this);\n";
434  
-    };
435  
-
436  
-    Block.prototype.compileWithDeclarations = function(o) {
437  
-      var assigns, code, declars, exp, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
438  
-=======
439 395
       var code;
440 396
       o.indent = this.tab = o.bare ? '' : TAB;
441 397
       o.scope = new Scope(null, this, null);
@@ -448,10 +404,9 @@
448 404
 
449 405
     Block.prototype.compileWithDeclarations = function(o) {
450 406
       var assigns, code, declars, exp, i, post, rest, scope, _len, _ref2;
451  
->>>>>>> src/nodes.coffee
452 407
       code = post = '';
453 408
       _ref2 = this.expressions;
454  
-      for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
  409
+      for (i = 0, _len = _ref2.length; i < _len; i++) {
455 410
         exp = _ref2[i];
456 411
         exp = exp.unwrap();
457 412
         if (!(exp instanceof Comment || exp instanceof Literal)) break;
@@ -510,7 +465,7 @@
510 465
     };
511 466
 
512 467
     Block.prototype.addCpsChain = function() {
513  
-      return this.expressions.push(new Call(new Literal("_k", [])));
  468
+      return this.expressions.push(new Call(new Literal(tame["const"].k, [])));
514 469
     };
515 470
 
516 471
     Block.wrap = function(nodes) {
@@ -531,8 +486,6 @@
531 486
 
532 487
     __extends(Literal, Base);
533 488
 
534  
-    Literal.name = 'Literal';
535  
-
536 489
     function Literal(value) {
537 490
       this.value = value;
538 491
     }
@@ -591,8 +544,6 @@
591 544
 
592 545
     __extends(Return, Base);
593 546
 
594  
-    Return.name = 'Return';
595  
-
596 547
     function Return(expr) {
597 548
       if (expr && !expr.unwrap().isUndefined) this.expression = expr;
598 549
     }
@@ -627,8 +578,6 @@
627 578
 
628 579
     __extends(Value, Base);
629 580
 
630  
-    Value.name = 'Value';
631  
-
632 581
     function Value(base, props, tag) {
633 582
       if (!props && base instanceof Value) return base;
634 583
       this.base = base;
@@ -743,13 +692,13 @@
743 692
       var _this = this;
744 693
       if (this.unfoldedSoak != null) return this.unfoldedSoak;
745 694
       result = (function() {
746  
-        var fst, i, ifn, prop, ref, snd, _i, _len, _ref2;
  695
+        var fst, i, ifn, prop, ref, snd, _len, _ref2;
747 696
         if (ifn = _this.base.unfoldSoak(o)) {
748 697
           Array.prototype.push.apply(ifn.body.properties, _this.properties);
749 698
           return ifn;
750 699
         }
751 700
         _ref2 = _this.properties;
752  
-        for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
  701
+        for (i = 0, _len = _ref2.length; i < _len; i++) {
753 702
           prop = _ref2[i];
754 703
           if (!prop.soak) continue;
755 704
           prop.soak = false;
@@ -777,8 +726,6 @@
777 726
 
778 727
     __extends(Comment, Base);
779 728
 
780  
-    Comment.name = 'Comment';
781  
-
782 729
     function Comment(comment) {
783 730
       this.comment = comment;
784 731
     }
@@ -802,8 +749,6 @@
802 749
 
803 750
     __extends(Call, Base);
804 751
 
805  
-    Call.name = 'Call';
806  
-
807 752
     function Call(variable, args, soak) {
808 753
       this.args = args != null ? args : [];
809 754
       this.soak = soak;
@@ -973,8 +918,6 @@
973 918
 
974 919
     __extends(Extends, Base);
975 920
 
976  
-    Extends.name = 'Extends';
977  
-
978 921
     function Extends(child, parent) {
979 922
       this.child = child;
980 923
       this.parent = parent;
@@ -994,8 +937,6 @@
994 937
 
995 938
     __extends(Access, Base);
996 939
 
997  
-    Access.name = 'Access';
998  
-
999 940
     function Access(name, tag) {
1000 941
       this.name = name;
1001 942
       this.name.asKey = true;
@@ -1024,8 +965,6 @@
1024 965
 
1025 966
     __extends(Index, Base);
1026 967
 
1027  
-    Index.name = 'Index';
1028  
-
1029 968
     function Index(index) {
1030 969
       this.index = index;
1031 970
     }
@@ -1048,8 +987,6 @@
1048 987
 
1049 988
     __extends(Range, Base);
1050 989
 
1051  
-    Range.name = 'Range';
1052  
-
1053 990
     Range.prototype.children = ['from', 'to'];
1054 991
 
1055 992
     function Range(from, to, tag) {
@@ -1074,21 +1011,17 @@
1074 1011
     };
1075 1012
 
1076 1013
     Range.prototype.compileNode = function(o) {
1077  
-      var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref2, _ref3;
  1014
+      var cond, condPart, from, gt, idx, known, lt, stepPart, to, varPart, _ref2, _ref3;
1078 1015
       if (!this.fromVar) this.compileVariables(o);
1079 1016
       if (!o.index) return this.compileArray(o);
1080 1017
       known = this.fromNum && this.toNum;
1081 1018
       idx = del(o, 'index');
1082  
-      idxName = del(o, 'name');
1083  
-      namedIndex = idxName && idxName !== idx;
1084 1019
       varPart = "" + idx + " = " + this.fromC;
1085 1020
       if (this.toC !== this.toVar) varPart += ", " + this.toC;
1086 1021
       if (this.step !== this.stepVar) varPart += ", " + this.step;
1087 1022
       _ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1];
1088 1023
       condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [+this.fromNum, +this.toNum], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
1089  
-      stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";
1090  
-      if (namedIndex) varPart = "" + idxName + " = " + varPart;
1091  
-      if (namedIndex) stepPart = "" + idxName + " = " + stepPart;
  1024
+      stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? from <= to ? "" + idx + "++" : "" + idx + "--" : "" + cond + " ? " + idx + "++ : " + idx + "--";
1092 1025
       return "" + varPart + "; " + condPart + "; " + stepPart;
1093 1026
     };
1094 1027
 
@@ -1133,8 +1066,6 @@
1133 1066
 
1134 1067
     __extends(Slice, Base);
1135 1068
 
1136  
-    Slice.name = 'Slice';
1137  
-
1138 1069
     Slice.prototype.children = ['range'];
1139 1070
 
1140 1071
     function Slice(range) {
@@ -1161,8 +1092,6 @@
1161 1092
 
1162 1093
     __extends(Obj, Base);
1163 1094
 
1164  
-    Obj.name = 'Obj';
1165  
-
1166 1095
     function Obj(props, generated) {
1167 1096
       this.generated = generated != null ? generated : false;
1168 1097
       this.objects = this.properties = props || [];
@@ -1185,9 +1114,9 @@
1185 1114
       idt = o.indent += TAB;
1186 1115
       lastNoncom = this.lastNonComment(this.properties);
1187 1116
       props = (function() {
1188  
-        var _j, _len2, _results;
  1117
+        var _len2, _results;
1189 1118
         _results = [];
1190  
-        for (i = _j = 0, _len2 = props.length; _j < _len2; i = ++_j) {
  1119
+        for (i = 0, _len2 = props.length; i < _len2; i++) {
1191 1120
           prop = props[i];
1192 1121
           join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
1193 1122
           indent = prop instanceof Comment ? '' : idt;
@@ -1229,8 +1158,6 @@
1229 1158
 
1230 1159
     __extends(Arr, Base);
1231 1160
 
1232  
-    Arr.name = 'Arr';
1233  
-
1234 1161
     function Arr(objs) {
1235 1162
       this.objects = objs || [];
1236 1163
     }
@@ -1279,8 +1206,6 @@
1279 1206
 
1280 1207
     __extends(Class, Base);
1281 1208
 
1282  
-    Class.name = 'Class';
1283  
-
1284 1209
     function Class(variable, parent, body) {
1285 1210
       this.variable = variable;
1286 1211
       this.parent = parent;
@@ -1370,11 +1295,11 @@
1370 1295
     Class.prototype.walkBody = function(name, o) {
1371 1296
       var _this = this;
1372 1297
       return this.traverseChildren(false, function(child) {
1373  
-        var exps, i, node, _i, _len, _ref2;
  1298
+        var exps, i, node, _len, _ref2;
1374 1299
         if (child instanceof Class) return false;
1375 1300
         if (child instanceof Block) {
1376 1301
           _ref2 = exps = child.expressions;
1377  
-          for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
  1302
+          for (i = 0, _len = _ref2.length; i < _len; i++) {
1378 1303
             node = _ref2[i];
1379 1304
             if (node instanceof Value && node.isObject(true)) {
1380 1305
               exps[i] = _this.addProperties(node, name, o);
@@ -1394,7 +1319,6 @@
1394 1319
         if (this.externalCtor) {
1395 1320
           this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
1396 1321
         }
1397  
-        this.ctor.body.makeReturn();
1398 1322
         this.body.expressions.unshift(this.ctor);
1399 1323
       }
1400 1324
       this.ctor.ctor = this.ctor.name = name;
@@ -1403,13 +1327,9 @@
1403 1327
     };
1404 1328
 
1405 1329
     Class.prototype.compileNode = function(o) {
1406  
-<<<<<<< HEAD
1407  
-      var call, decl, klass, lname, name, params;
1408  
-=======
1409 1330
       var decl, klass, lname, name;
1410  
->>>>>>> src/nodes.coffee
1411 1331
       decl = this.determineName();
1412  
-      name = decl || '_Class';
  1332
+      name = decl || this.name || '_Class';
1413 1333
       if (name.reserved) name = "_" + name;
1414 1334
       lname = new Literal(name);
1415 1335
       this.setContext(name);
@@ -1420,24 +1340,9 @@
1420 1340
         this.body.expressions.unshift(new Extends(lname, this.parent));
1421 1341
       }
1422 1342
       if (!(this.ctor instanceof Code)) this.body.expressions.unshift(this.ctor);
1423  
-      if (decl) {
1424  
-        this.body.expressions.unshift(new Assign(new Value(new Literal(name), [new Access(new Literal('name'))]), new Literal("'" + name + "'")));
1425  
-      }
1426 1343
       this.body.expressions.push(lname);
1427 1344
       this.addBoundFunctions(o);
1428  
-<<<<<<< HEAD
1429  
-      call = Closure.wrap(this.body);
1430  
-      if (this.parent) {
1431  
-        this.superClass = new Literal(o.scope.freeVariable('super', false));
1432  
-        this.body.expressions.unshift(new Extends(lname, this.superClass));
1433  
-        call.args.push(this.parent);
1434  
-        params = call.variable.params || call.variable.base.params;
1435  
-        params.push(new Param(this.superClass));
1436  
-      }
1437  
-      klass = new Parens(call, true);
1438  
-=======
1439 1345
       klass = new Parens(Closure.wrap(this.body), true);
1440  
->>>>>>> src/nodes.coffee
1441 1346
       if (this.variable) klass = new Assign(this.variable, klass);
1442 1347
       return klass.compile(o);
1443 1348
     };
@@ -1450,8 +1355,6 @@
1450 1355
 
1451 1356
     __extends(Assign, Base);
1452 1357
 
1453  
-    Assign.name = 'Assign';
1454  
-
1455 1358
     function Assign(variable, value, context, options) {
1456 1359
       this.variable = variable;
1457 1360
       this.value = value;
@@ -1513,7 +1416,7 @@
1513 1416
     };
1514 1417
 
1515 1418
     Assign.prototype.compilePatternMatch = function(o) {
1516  
-      var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
  1419
+      var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
1517 1420
       top = o.level === LEVEL_TOP;
1518 1421
       value = this.value;
1519 1422
       objects = this.variable.base.objects;
@@ -1553,7 +1456,7 @@
1553 1456
         assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar);
1554 1457
         vvar = ref;
1555 1458
       }
1556  
-      for (i = _i = 0, _len = objects.length; _i < _len; i = ++_i) {
  1459
+      for (i = 0, _len = objects.length; i < _len; i++) {
1557 1460
         obj = objects[i];
1558 1461
         idx = i;
1559 1462
         if (isObject) {
@@ -1650,8 +1553,6 @@
1650 1553
 
1651 1554
     __extends(Code, Base);
1652 1555
 
1653  
-    Code.name = 'Code';
1654  
-
1655 1556
     function Code(params, body, tag) {
1656 1557
       this.params = params || [];
1657 1558
       this.body = body || new Block;
@@ -1668,7 +1569,7 @@
1668 1569
     Code.prototype.jumps = NO;
1669 1570
 
1670 1571
     Code.prototype.compileNode = function(o) {
1671  
-      var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref2, _ref3, _ref4, _ref5, _ref6;
  1572
+      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, _ref6;
1672 1573
       o.scope = new Scope(o.scope, this.body, this);
1673 1574
       o.scope.shared = del(o, 'sharedScope');
1674 1575
       o.indent += TAB;
@@ -1721,7 +1622,7 @@
1721 1622
         (_ref5 = this.body.expressions).unshift.apply(_ref5, exprs);
1722 1623
       }
1723 1624
       if (!splats) {
1724  
-        for (i = _l = 0, _len4 = vars.length; _l < _len4; i = ++_l) {
  1625
+        for (i = 0, _len4 = vars.length; i < _len4; i++) {
1725 1626
           v = vars[i];
1726 1627
           o.scope.parameter(vars[i] = v.compile(o));
1727 1628
         }
@@ -1770,8 +1671,6 @@
1770 1671
 
1771 1672
     __extends(Param, Base);
1772 1673
 
1773  
-    Param.name = 'Param';
1774  
-
1775 1674
     function Param(name, value, splat) {
1776 1675
       this.name = name;
1777 1676
       this.value = value;
@@ -1811,8 +1710,6 @@
1811 1710
 
1812 1711
     __extends(Splat, Base);
1813 1712
 
1814  
-    Splat.name = 'Splat';
1815  
-
1816 1713
     Splat.prototype.children = ['name'];
1817 1714
 
1818 1715
     Splat.prototype.isAssignable = YES;
@@ -1838,7 +1735,7 @@
1838 1735
     };
1839 1736
 
1840 1737
     Splat.compileSplattedArray = function(o, list, apply) {
1841  
-      var args, base, code, i, index, node, _i, _len;
  1738
+      var args, base, code, i, index, node, _len;
1842 1739
       index = -1;
1843 1740
       while ((node = list[++index]) && !(node instanceof Splat)) {
1844 1741
         continue;
@@ -1850,7 +1747,7 @@
1850 1747
         return "" + (utility('slice')) + ".call(" + code + ")";
1851 1748
       }
1852 1749
       args = list.slice(index);
1853  
-      for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
  1750
+      for (i = 0, _len = args.length; i < _len; i++) {
1854 1751
         node = args[i];
1855 1752
         code = node.compile(o, LEVEL_LIST);
1856 1753
         args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]";
@@ -1859,11 +1756,11 @@
1859 1756
         return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
1860 1757
       }
1861 1758
       base = (function() {
1862  
-        var _j, _len2, _ref2, _results;
  1759
+        var _i, _len2, _ref2, _results;
1863 1760
         _ref2 = list.slice(0, index);
1864 1761
         _results = [];
1865  
-        for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
1866  
-          node = _ref2[_j];
  1762
+        for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) {
  1763
+          node = _ref2[_i];
1867 1764
           _results.push(node.compile(o, LEVEL_LIST));
1868 1765
         }
1869 1766
         return _results;
@@ -1879,8 +1776,6 @@
1879 1776
 
1880 1777
     __extends(While, Base);
1881 1778
 
1882  
-    While.name = 'While';
1883  
-
1884 1779
     function While(condition, options) {
1885 1780
       this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
1886 1781
       this.guard = options != null ? options.guard : void 0;
@@ -1954,11 +1849,14 @@
1954 1849
 
1955 1850
     __extends(Op, Base);
1956 1851
 
1957  
-    Op.name = 'Op';
1958  
-
1959 1852
     function Op(op, first, second, flip) {
  1853
+      var call;
1960 1854
       if (op === 'in') return new In(first, second);
1961  
-      if (op === 'do') return this.generateDo(first);
  1855
+      if (op === 'do') {
  1856
+        call = new Call(first, first.params || []);
  1857
+        call["do"] = true;
  1858
+        return call;
  1859
+      }
1962 1860
       if (op === 'new') {
1963 1861
         if (first instanceof Call && !first["do"] && !first.isNew) {
1964 1862
           return first.newInstance();
@@ -2038,25 +1936,6 @@
2038 1936
       return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
2039 1937
     };
2040 1938
 
2041  
-    Op.prototype.generateDo = function(exp) {
2042  
-      var call, func, param, passedParams, ref, _i, _len, _ref2;
2043  
-      passedParams = [];
2044  
-      func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
2045  
-      _ref2 = func.params || [];
2046  
-      for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2047  
-        param = _ref2[_i];
2048  
-        if (param.value) {
2049  
-          passedParams.push(param.value);
2050  
-          delete param.value;
2051  
-        } else {
2052  
-          passedParams.push(param);
2053  
-        }
2054  
-      }
2055  
-      call = new Call(exp, passedParams);
2056  
-      call["do"] = true;
2057  
-      return call;
2058  
-    };
2059  
-
2060 1939
     Op.prototype.compileNode = function(o) {
2061 1940
       var code, isChain;
2062 1941
       isChain = this.isChainable() && this.first.isChainable();
@@ -2121,8 +2000,6 @@
2121 2000
 
2122 2001
     __extends(In, Base);
2123 2002
 
2124  
-    In.name = 'In';
2125  
-
2126 2003
     function In(object, array) {
2127 2004
       this.object = object;
2128 2005
       this.array = array;
@@ -2153,10 +2030,10 @@
2153 2030
       _ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
2154 2031
       _ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
2155 2032
       tests = (function() {
2156  
-        var _i, _len, _ref4, _results;
  2033
+        var _len, _ref4, _results;
2157 2034
         _ref4 = this.array.base.objects;
2158 2035
         _results = [];
2159  
-        for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
  2036
+        for (i = 0, _len = _ref4.length; i < _len; i++) {
2160 2037
           item = _ref4[i];
2161 2038
           _results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_ACCESS));
2162 2039
         }
@@ -2196,14 +2073,18 @@
2196 2073
     __extends(Await, Base);
2197 2074
 
2198 2075
     function Await(body) {
2199  
-      var assign, call, cls, lhs, rhs;
2200  
-      lhs = new Value(new Literal("__tame_deferrals"));
2201  
-      cls = new Value(new Literal("tame"));
2202  
-      cls.add(new Access(new Value(new Literal("Deferrals"))));
2203  
-      call = new Call(cls, [new Value(new Literal("_k"))]);
  2076
+      var assign, call, cls, lhs, meth, rhs;
  2077
+      lhs = new Value(new Literal(tame["const"].deferrals));
  2078
+      cls = new Value(new Literal(tame["const"].ns));
  2079
+      cls.add(new Access(new Value(new Literal(tame["const"].Deferrals))));
  2080
+      call = new Call(cls, [new Value(new Literal(tame["const"].k))]);
2204 2081
       rhs = new Op("new", call);
2205 2082
       assign = new Assign(lhs, rhs);
2206  
-      this.body = [assign] + body;
  2083
+      body.unshift(assign);
  2084
+      meth = lhs.add(new Access(new Value(new Literal(tame["const"].fulfill))));
  2085
+      call = new Call(meth, []);
  2086
+      body.push(call);
  2087
+      this.body = body;
2207 2088
     }
2208 2089
 
2209 2090
     Await.prototype.children = ['body'];
@@ -2214,9 +2095,7 @@
2214 2095
 
2215 2096
     Await.prototype.compileNode = function(o) {
2216 2097
       o.indent += TAB;
2217  
-      body += "" + (this.body.compile(o)) + "\n" + this.tab;
2218  
-      body += "__tame_deferrals._fulfill();";
2219  
-      return body;
  2098
+      return this.body.compile(o);
2220 2099
     };
2221 2100
 
2222 2101
     Await.prototype.walkTaming = function() {
@@ -2232,8 +2111,6 @@
2232 2111
 
2233 2112
     __extends(Try, Base);
2234 2113
 
2235  
-    Try.name = 'Try';
2236  
-
2237 2114
     function Try(attempt, error, recovery, ensure) {
2238 2115
       this.attempt = attempt;
2239 2116
       this.error = error;
@@ -2274,8 +2151,6 @@
2274 2151
 
2275 2152
     __extends(Throw, Base);
2276 2153
 
2277  
-    Throw.name = 'Throw';
2278  
-
2279 2154
     function Throw(expression) {
2280 2155
       this.expression = expression;
2281 2156
     }
@@ -2300,8 +2175,6 @@
2300 2175
 
2301 2176
     __extends(Existence, Base);
2302 2177
 
2303  
-    Existence.name = 'Existence';
2304  
-
2305 2178
     function Existence(expression) {
2306 2179
       this.expression = expression;
2307 2180
     }
@@ -2335,8 +2208,6 @@
2335 2208
 
2336 2209
     __extends(Parens, Base);
2337 2210
 
2338  
-    Parens.name = 'Parens';
2339  
-
2340 2211
     function Parens(body) {
2341 2212
       this.body = body;
2342 2213
     }
@@ -2375,8 +2246,6 @@
2375 2246
 
2376 2247
     __extends(For, While);
2377 2248
 
2378  
-    For.name = 'For';
2379  
-
2380 2249
     function For(body, source) {
2381 2250
       var _ref2;
2382 2251
       this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
@@ -2403,7 +2272,7 @@
2403 2272
     For.prototype.children = ['body', 'source', 'guard', 'step'];
2404 2273
 
2405 2274
     For.prototype.compileNode = function(o) {
2406  
-      var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
  2275
+      var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
2407 2276
       body = Block.wrap([this.body]);
2408 2277
       lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
2409 2278
       if (lastJumps && lastJumps instanceof Return) this.returns = false;
@@ -2422,9 +2291,7 @@
2422 2291
         });
2423 2292
       }
2424 2293
       if (this.returns) rvar = scope.freeVariable('results');
2425  
-      ivar = (this.object && index) || scope.freeVariable('i');
2426  
-      kvar = (this.range && name) || index || ivar;
2427  
-      kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";
  2294
+      ivar = (this.range ? name : index) || scope.freeVariable('i');
2428 2295
       if (this.step && !this.range) stepvar = scope.freeVariable("step");
2429 2296
       if (this.pattern) name = ivar;
2430 2297
       varPart = '';
@@ -2434,7 +2301,6 @@
2434 2301
       if (this.range) {
2435 2302
         forPart = source.compile(merge(o, {
2436 2303
           index: ivar,
2437  
-          name: name,
2438 2304
           step: this.step
2439 2305
         }));
2440 2306
       } else {
@@ -2444,15 +2310,12 @@
2444 2310
           svar = ref;
2445 2311
         }
2446 2312
         if (name && !this.pattern) {
2447  
-          namePart = "" + name + " = " + svar + "[" + kvar + "]";
  2313
+          namePart = "" + name + " = " + svar + "[" + ivar + "]";
2448 2314
         }
2449 2315
         if (!this.object) {
2450 2316
           lvar = scope.freeVariable('len');
2451  
-          forVarPart = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";
2452  
-          if (this.step) {
2453  
-            forVarPart += ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP));
2454  
-          }
2455  
-          stepPart = "" + kvarAssign + (this.step ? "" + ivar + " += " + stepvar : (kvar !== ivar ? "++" + ivar : "" + ivar + "++"));
  2317
+          forVarPart = ("" + ivar + " = 0, " + lvar + " = " + svar + ".length") + (this.step ? ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP)) : '');
  2318
+          stepPart = this.step ? "" + ivar + " += " + stepvar : "" + ivar + "++";
2456 2319
           forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart;
2457 2320
         }
2458 2321
       }
@@ -2469,14 +2332,14 @@
2469 2332
         }
2470 2333
       }
2471 2334
       if (this.pattern) {
2472  
-        body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + kvar + "]")));
  2335
+        body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")));
2473 2336
       }
2474 2337
       defPart += this.pluckDirectCall(o, body);
2475 2338
       if (namePart) varPart = "\n" + idt1 + namePart + ";";
2476 2339
       if (this.object) {
2477  
-        forPart = "" + kvar + " in " + svar;
  2340
+        forPart = "" + ivar + " in " + svar;
2478 2341
         if (this.own) {
2479  
-          guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + kvar + ")) continue;";
  2342
+          guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;";
2480 2343
         }
2481 2344
       }
2482 2345
       body = body.compile(merge(o, {
@@ -2487,10 +2350,10 @@
2487 2350
     };
2488 2351
 
2489 2352
     For.prototype.pluckDirectCall = function(o, body) {
2490  
-      var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
  2353
+      var base, defs, expr, fn, idx, ref, val, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
2491 2354
       defs = '';
2492 2355
       _ref2 = body.expressions;
2493  
-      for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) {
  2356
+      for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
2494 2357
         expr = _ref2[idx];
2495 2358
         expr = expr.unwrapAll();
2496 2359
         if (!(expr instanceof Call)) continue;
@@ -2516,8 +2379,6 @@
2516 2379
 
2517 2380
     __extends(Switch, Base);
2518 2381
 
2519  
-    Switch.name = 'Switch';
2520  
-
2521 2382
     function Switch(subject, cases, otherwise) {
2522 2383
       this.subject = subject;
2523 2384
       this.cases = cases;
@@ -2558,16 +2419,16 @@
2558 2419
     };
2559 2420
 
2560 2421
     Switch.prototype.compileNode = function(o) {
2561  
-      var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len2, _ref2, _ref3, _ref4, _ref5;
  2422
+      var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _len, _len2, _ref2, _ref3, _ref4, _ref5;
2562 2423
       idt1 = o.indent + TAB;
2563 2424
       idt2 = o.indent = idt1 + TAB;
2564 2425
       code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
2565 2426
       _ref3 = this.cases;
2566  
-      for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
  2427
+      for (i = 0, _len = _ref3.length; i < _len; i++) {
2567 2428
         _ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1];
2568 2429
         _ref5 = flatten([conditions]);
2569  
-        for (_j = 0, _len2 = _ref5.length; _j < _len2; _j++) {
2570  
-          cond = _ref5[_j];
  2430
+        for (_i = 0, _len2 = _ref5.length; _i < _len2; _i++) {
  2431
+          cond = _ref5[_i];
2571 2432
           if (!this.subject) cond = cond.invert();
2572 2433
           code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
2573 2434
         }
@@ -2593,8 +2454,6 @@
2593 2454
 
2594 2455
     __extends(If, Base);
2595 2456
 
2596  
-    If.name = 'If';
2597  
-
2598 2457
     function If(condition, body, options) {
2599 2458
       this.body = body;
2600 2459
       if (options == null) options = {};
@@ -2631,6 +2490,7 @@
2631 2490
       code = CALL_CONTINUATION();
2632 2491
       if (this.elseBody) {
2633 2492
         this.elseBody.push(code);
  2493
+        this.isChain = false;
2634 2494
       } else {
2635 2495
         this.addElse(code);
2636 2496
       }
@@ -2747,9 +2607,10 @@
2747 2607
   CpsCascade = {
2748 2608
     wrap: function(statement, rest) {
2749 2609
       var call, cont, func;
2750  
-      func = new Code([new Param(new Literal("_k"))], Block.wrap([statement]));
  2610
+      func = new Code([new Param(new Literal(tame["const"].k))], Block.wrap([statement]));
2751 2611
       cont = new Code([], Block.wrap([rest]));
2752  
-      return call = new Call(func, [cont]);
  2612
+      call = new Call(func, [cont]);
  2613
+      return new Block([call]);
2753 2614
     }
2754 2615
   };
2755 2616
 
@@ -2769,7 +2630,7 @@
2769 2630
       return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
2770 2631
     },
2771 2632
     indexOf: function() {
2772  
-      return "Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
  2633
+      return "Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (" + (utility('hasProp')) + ".call(this, i) && this[i] === item) return i; } return -1; }";
2773 2634
     },
2774 2635
     hasProp: function() {
2775 2636
       return 'Object.prototype.hasOwnProperty';
1  lib/coffee-script/parser.js
... ...
@@ -1,6 +1,5 @@
1 1
 /* Jison generated parser */
2 2
 var parser = (function(){
3  
-undefined
4 3
 var parser = {trace: function trace() { },
5 4
 yy: {},
6 5
 <<<<<<< HEAD
7  src/nodes.coffee
@@ -65,9 +65,7 @@ exports.Base = class Base
65 65
   compileCps : (o) ->
66 66
     @gotCpsSplit = true
67 67
     node = CpsCascade.wrap(this, @tameContinuationBlock)
68  
-    console.log("yo INDENT#{o.indent}TNEDNI")
69 68
     ret = node.compile o
70  
-    console.log("yo TAB#{node.tab}BAT")
71 69
     ret
72 70
 
73 71
   # If the code generation wishes to use the result of a complex expression
@@ -1991,10 +1989,14 @@ exports.If = class If extends Base
1991 1989
       @elseBody = @ensureBlock elseBody
1992 1990
     this
1993 1991
 
  1992
+  # propogate the closing continuation call down both branches of the if.
  1993
+  # note this prevents if ...else if... inline chaining, and makes it 
  1994
+  # fully nested if { .. } else { if { } ..} ..'s
1994 1995
   callContinuation : ->
1995 1996
     code = CALL_CONTINUATION()
1996 1997
     if @elseBody
1997 1998
       @elseBody.push code
  1999
+      @isChain = false
1998 2000
     else
1999 2001
       @addElse code
2000 2002
     @body.push code
@@ -2103,6 +2105,7 @@ CpsCascade =
2103 2105
     func = new Code [ new Param new Literal tame.const.k ], Block.wrap [ statement ]
2104 2106
     cont = new Code [], Block.wrap [ rest ]
2105 2107
     call = new Call func, [ cont ]
  2108
+    new Block [ call ]
2106 2109
 
2107 2110
 # Unfold a node's child if soak, then tuck the node under created `If`
2108 2111
 unfoldSoak = (o, parent, name) ->

0 notes on commit f3c82b3

Please sign in to comment.
Something went wrong with that request. Please try again.