diff --git a/documentation/js/classes.js b/documentation/js/classes.js index 0caea30f..c9f1fc0a 100644 --- a/documentation/js/classes.js +++ b/documentation/js/classes.js @@ -7,7 +7,7 @@ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, par child.__super__ = parent.prototype; return child; }; -Animal = function() { +Animal = (function() { function Animal(name) { this.name = name; } @@ -15,8 +15,8 @@ Animal = function() { return alert(this.name + " moved " + meters + "m."); }; return Animal; -}(); -Snake = function() { +})(); +Snake = (function() { function Snake() { Snake.__super__.constructor.apply(this, arguments); } @@ -26,8 +26,8 @@ Snake = function() { return Snake.__super__.move.call(this, 5); }; return Snake; -}(); -Horse = function() { +})(); +Horse = (function() { function Horse() { Horse.__super__.constructor.apply(this, arguments); } @@ -37,7 +37,7 @@ Horse = function() { return Horse.__super__.move.call(this, 45); }; return Horse; -}(); +})(); sam = new Snake("Sammy the Python"); tom = new Horse("Tommy the Palomino"); sam.move(); diff --git a/documentation/js/expressions_comprehension.js b/documentation/js/expressions_comprehension.js index da13ec1f..eb4e316e 100644 --- a/documentation/js/expressions_comprehension.js +++ b/documentation/js/expressions_comprehension.js @@ -1,9 +1,9 @@ var globals, name; -globals = (function() { +globals = ((function() { var _results; _results = []; for (name in window) { _results.push(name); } return _results; -}()).slice(0, 10); \ No newline at end of file +})()).slice(0, 10); \ No newline at end of file diff --git a/documentation/js/expressions_try.js b/documentation/js/expressions_try.js index 65991212..b6122563 100644 --- a/documentation/js/expressions_try.js +++ b/documentation/js/expressions_try.js @@ -1,7 +1,7 @@ -alert(function() { +alert((function() { try { return nonexistent / void 0; } catch (error) { return "And the error is ... " + error; } -}()); \ No newline at end of file +})()); \ No newline at end of file diff --git a/documentation/js/object_comprehensions.js b/documentation/js/object_comprehensions.js index c7edeeef..25c97bf2 100644 --- a/documentation/js/object_comprehensions.js +++ b/documentation/js/object_comprehensions.js @@ -4,7 +4,7 @@ yearsOld = { ida: 9, tim: 11 }; -ages = function() { +ages = (function() { var _results; _results = []; for (child in yearsOld) { @@ -12,4 +12,4 @@ ages = function() { _results.push(child + " is " + age); } return _results; -}(); \ No newline at end of file +})(); \ No newline at end of file diff --git a/documentation/js/overview.js b/documentation/js/overview.js index cfb333c7..9d51f2ff 100644 --- a/documentation/js/overview.js +++ b/documentation/js/overview.js @@ -32,4 +32,4 @@ cubes = (function() { _results.push(math.cube(num)); } return _results; -}()); \ No newline at end of file +})(); \ No newline at end of file diff --git a/documentation/js/range_comprehensions.js b/documentation/js/range_comprehensions.js index 9f4e03e4..bac2a530 100644 --- a/documentation/js/range_comprehensions.js +++ b/documentation/js/range_comprehensions.js @@ -6,4 +6,4 @@ countdown = (function() { _results.push(num); } return _results; -}()); \ No newline at end of file +})(); \ No newline at end of file diff --git a/documentation/js/while.js b/documentation/js/while.js index 190cc726..bd02bf60 100644 --- a/documentation/js/while.js +++ b/documentation/js/while.js @@ -8,11 +8,11 @@ if (this.studyingEconomics) { } } num = 6; -lyrics = function() { +lyrics = (function() { var _results; _results = []; while (num -= 1) { _results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head."); } return _results; -}(); \ No newline at end of file +})(); \ No newline at end of file diff --git a/index.html b/index.html index a8de8d15..7b5bc706 100644 --- a/index.html +++ b/index.html @@ -181,7 +181,7 @@ cubes = (function() { _results.push(math.cube(num)); } return _results; -}()); +})();
run: cubes

+})();;alert(cubes);'>run: cubes

@@ -754,14 +754,14 @@ lyrics = while num = 6; -lyrics = function() { +lyrics = (function() { var _results; _results = []; while (num -= 1) { _results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head."); } return _results; -}(); +})();
Load
run: lyrics.join("\n")

+})();;alert(lyrics.join("\n"));'>run: lyrics.join("\n")

For readability, the until keyword is equivalent to while not, and the loop keyword is equivalent to while true. @@ -819,7 +819,7 @@ countdown = (function( _results.push(num); } return _results; -}()); +})();

Load
run: countdown

+})();;alert(countdown);'>run: countdown

Note how because we are assigning the value of the comprehensions to a variable in the example above, CoffeeScript is collecting the result of @@ -858,7 +858,7 @@ yearsOld = { ida: 9, tim: 11 }; -ages = function() { +ages = (function() { var _results; _results = []; for (child in yearsOld) { @@ -866,14 +866,14 @@ yearsOld = { _results.push(child + " is " + age); } return _results; -}(); +})();

Load
run: ages.join(", ")

+})();;alert(ages.join(", "));'>run: ages.join(", ")

If you would like to iterate over just the keys that are defined on the object itself, by adding a hasOwnProperty @@ -1035,23 +1035,23 @@ six = (one = 1) + (two = 2) + (three = 3);;alert(six);'>run: six
= (name for name of window)[0...10]

var globals, name;
-globals = (function() {
+globals = ((function() {
   var _results;
   _results = [];
   for (name in window) {
     _results.push(name);
   }
   return _results;
-}()).slice(0, 10);
+})()).slice(0, 10);
 
Load
run: globals

+})()).slice(0, 10);;alert(globals);'>run: globals

As well as silly things, like passing a try/catch statement directly into a function call: @@ -1063,20 +1063,20 @@ globals = (function() { "And the error is ... " + error ) -

alert(function() {
+
alert((function() {
   try {
     return nonexistent / void 0;
   } catch (error) {
     return "And the error is ... " + error;
   }
-}());
-
Load
Load
run

+})());;'>run

There are a handful of statements in JavaScript that can't be meaningfully converted into expressions, namely break, continue, @@ -1281,7 +1281,7 @@ tom.move() child.__super__ = parent.prototype; return child; }; -Animal = function() { +Animal = (function() { function Animal(name) { this.name = name; } @@ -1289,8 +1289,8 @@ tom.move() return alert(this.name + " moved " + meters + "m."); }; return Animal; -}(); -Snake = function() { +})(); +Snake = (function() { function Snake() { Snake.__super__.constructor.apply(this, arguments); } @@ -1300,8 +1300,8 @@ tom.move() return Snake.__super__.move.call(this, 5); }; return Snake; -}(); -Horse = function() { +})(); +Horse = (function() { function Horse() { Horse.__super__.constructor.apply(this, arguments); } @@ -1311,7 +1311,7 @@ tom.move() return Horse.__super__.move.call(this, 45); }; return Horse; -}(); +})(); sam = new Snake("Sammy the Python"); tom = new Horse("Tommy the Palomino"); sam.move(); @@ -1325,7 +1325,7 @@ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, par child.__super__ = parent.prototype; return child; }; -Animal = function() { +Animal = (function() { function Animal(name) { this.name = name; } @@ -1333,8 +1333,8 @@ Animal = function() { return alert(this.name + " moved " + meters + "m."); }; return Animal; -}(); -Snake = function() { +})(); +Snake = (function() { function Snake() { Snake.__super__.constructor.apply(this, arguments); } @@ -1344,8 +1344,8 @@ Snake = function() { return Snake.__super__.move.call(this, 5); }; return Snake; -}(); -Horse = function() { +})(); +Horse = (function() { function Horse() { Horse.__super__.constructor.apply(this, arguments); } @@ -1355,7 +1355,7 @@ Horse = function() { return Horse.__super__.move.call(this, 45); }; return Horse; -}(); +})(); sam = new Snake("Sammy the Python"); tom = new Horse("Tommy the Palomino"); sam.move(); diff --git a/lib/nodes.js b/lib/nodes.js index 41e114ec..33fc7f60 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1418,7 +1418,7 @@ if (index === 0) { return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")"); } - base = ((function() { + base = (function() { var _i, _len, _ref, _results; _ref = list.slice(0, index); _results = []; @@ -1427,7 +1427,7 @@ _results.push(node.compile(o, LEVEL_LIST)); } return _results; - })()); + })(); return "[" + (base.join(', ')) + "].concat(" + (args.join(', ')) + ")"; }; return Splat; @@ -1764,8 +1764,8 @@ expr.front = this.front; return expr.compile(o); } - bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call); code = expr.compile(o, LEVEL_PAREN); + bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns)); if (bare) { return code; } else { diff --git a/src/nodes.coffee b/src/nodes.coffee index 72a91cb6..f5e46fa6 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1405,8 +1405,9 @@ exports.Parens = class Parens extends Base if expr instanceof Value and expr.isAtomic() expr.front = @front return expr.compile o - bare = o.level < LEVEL_OP and (expr instanceof Op or expr instanceof Call) code = expr.compile o, LEVEL_PAREN + bare = o.level < LEVEL_OP and (expr instanceof Op or expr instanceof Call or + (expr instanceof For and expr.returns)) if bare then code else "(#{code})" #### For