diff --git a/documentation/js/classes.js b/documentation/js/classes.js index 18d14f5d..922207f6 100644 --- a/documentation/js/classes.js +++ b/documentation/js/classes.js @@ -7,24 +7,30 @@ var __extends = function(child, parent) { if (typeof parent.extended === "function") parent.extended(child); child.__super__ = parent.prototype; }; -Animal = function(_arg) { - this.name = _arg; - return this; -}; +Animal = (function() { + return function Animal(_arg) { + this.name = _arg; + return this; + }; +})(); Animal.prototype.move = function(meters) { return alert(this.name + " moved " + meters + "m."); }; -Snake = function() { - return Animal.apply(this, arguments); -}; +Snake = (function() { + return function Snake() { + return Animal.apply(this, arguments); + }; +})(); __extends(Snake, Animal); Snake.prototype.move = function() { alert("Slithering..."); return Snake.__super__.move.call(this, 5); }; -Horse = function() { - return Animal.apply(this, arguments); -}; +Horse = (function() { + return function Horse() { + return Animal.apply(this, arguments); + }; +})(); __extends(Horse, Animal); Horse.prototype.move = function() { alert("Galloping..."); diff --git a/documentation/js/existence.js b/documentation/js/existence.js index f48fdc59..6fc021b5 100644 --- a/documentation/js/existence.js +++ b/documentation/js/existence.js @@ -2,4 +2,4 @@ var solipsism, speed; if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) { solipsism = true; } -speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140; \ No newline at end of file +(typeof speed !== "undefined" && speed !== null) ? speed : (speed = 140); \ No newline at end of file diff --git a/documentation/js/interpolation_expression.js b/documentation/js/interpolation_expression.js index d4ae828f..8ef308c5 100644 --- a/documentation/js/interpolation_expression.js +++ b/documentation/js/interpolation_expression.js @@ -1,4 +1,4 @@ var dates, sentence, sep; sentence = ("" + (22 / 7) + " is a decent approximation of π"); sep = "[.\\/\\- ]"; -dates = (new RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g")); \ No newline at end of file +dates = (RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g")); \ No newline at end of file diff --git a/documentation/js/multiple_return_values.js b/documentation/js/multiple_return_values.js index 9a9f8d80..e4bf1e6f 100644 --- a/documentation/js/multiple_return_values.js +++ b/documentation/js/multiple_return_values.js @@ -2,7 +2,4 @@ var _ref, city, forecast, temp, weatherReport; weatherReport = function(location) { return [location, 72, "Mostly Sunny"]; }; -_ref = weatherReport("Berkeley, CA"); -city = _ref[0]; -temp = _ref[1]; -forecast = _ref[2]; \ No newline at end of file +_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2]; \ No newline at end of file diff --git a/documentation/js/object_comprehensions.js b/documentation/js/object_comprehensions.js index bc05d294..8d719ed6 100644 --- a/documentation/js/object_comprehensions.js +++ b/documentation/js/object_comprehensions.js @@ -1,4 +1,4 @@ -var _ref, _result, age, ages, child, yearsOld; +var _result, age, ages, child, yearsOld; var __hasProp = Object.prototype.hasOwnProperty; yearsOld = { max: 10, @@ -6,10 +6,10 @@ yearsOld = { tim: 11 }; ages = (function() { - _result = []; _ref = yearsOld; - for (child in _ref) { - if (!__hasProp.call(_ref, child)) continue; - age = _ref[child]; + _result = []; + for (child in yearsOld) { + if (!__hasProp.call(yearsOld, child)) continue; + age = yearsOld[child]; _result.push(child + " is " + age); } return _result; diff --git a/documentation/js/object_extraction.js b/documentation/js/object_extraction.js index f50374ce..90eff3da 100644 --- a/documentation/js/object_extraction.js +++ b/documentation/js/object_extraction.js @@ -1,4 +1,4 @@ -var _ref, _ref2, _ref3, city, futurists, name, street; +var _ref, _ref2, city, futurists, name, street; futurists = { sculptor: "Umberto Boccioni", painter: "Vladimir Burliuk", @@ -7,9 +7,4 @@ futurists = { address: ["Via Roma 42R", "Bellagio, Italy 22021"] } }; -_ref = futurists; -_ref2 = _ref.poet; -name = _ref2.name; -_ref3 = _ref2.address; -street = _ref3[0]; -city = _ref3[1]; \ No newline at end of file +_ref = futurists.poet, name = _ref.name, _ref2 = _ref.address, street = _ref2[0], city = _ref2[1]; \ No newline at end of file diff --git a/documentation/js/overview.js b/documentation/js/overview.js index 4ae3d185..5bdbffa9 100644 --- a/documentation/js/overview.js +++ b/documentation/js/overview.js @@ -1,4 +1,4 @@ -var _i, _len, _ref, _result, cubes, list, math, num, number, opposite, race, square; +var _i, _len, _result, cubes, list, math, num, number, opposite, race, square; var __slice = Array.prototype.slice; number = 42; opposite = true; @@ -25,9 +25,9 @@ if (typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); } cubes = (function() { - _result = []; _ref = list; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - num = _ref[_i]; + _result = []; + for (_i = 0, _len = list.length; _i < _len; _i++) { + num = list[_i]; _result.push(math.cube(num)); } return _result; diff --git a/documentation/js/parallel_assignment.js b/documentation/js/parallel_assignment.js index e6ddcce0..a24e7f6a 100644 --- a/documentation/js/parallel_assignment.js +++ b/documentation/js/parallel_assignment.js @@ -1,6 +1,4 @@ var _ref, theBait, theSwitch; theBait = 1000; theSwitch = 0; -_ref = [theSwitch, theBait]; -theBait = _ref[0]; -theSwitch = _ref[1]; \ No newline at end of file +_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1]; \ No newline at end of file diff --git a/documentation/js/patterns_and_splats.js b/documentation/js/patterns_and_splats.js index 562040b9..46b2260b 100644 --- a/documentation/js/patterns_and_splats.js +++ b/documentation/js/patterns_and_splats.js @@ -1,7 +1,4 @@ var _ref, close, contents, open, tag; var __slice = Array.prototype.slice; tag = ""; -_ref = tag.split(""); -open = _ref[0]; -contents = __slice.call(_ref, 1, _ref.length - 1); -close = _ref[_ref.length - 1]; \ No newline at end of file +_ref = tag.split(""), open = _ref[0], contents = __slice.call(_ref, 1, _ref.length - 1), close = _ref[_ref.length - 1]; \ No newline at end of file diff --git a/documentation/js/soaks.js b/documentation/js/soaks.js index fa814b50..5cf887e2 100644 --- a/documentation/js/soaks.js +++ b/documentation/js/soaks.js @@ -1,2 +1,2 @@ var _ref, _ref2; -(typeof (_ref2 = ((_ref = lottery.drawWinner()))) === "undefined" || _ref2 === null) ? undefined : _ref2.address == null ? undefined : _ref2.address.zipcode; \ No newline at end of file +(((_ref = lottery.drawWinner()) != null) ? (((_ref2 = _ref.address) != null) ? _ref2.zipcode : undefined) : undefined); \ No newline at end of file diff --git a/documentation/js/splats.js b/documentation/js/splats.js index aa04e1c4..3f16b83d 100644 --- a/documentation/js/splats.js +++ b/documentation/js/splats.js @@ -9,7 +9,7 @@ awardMedals = function(first, second) { return (rest = others); }; contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"]; -awardMedals.apply(this, contenders); +awardMedals.apply(awardMedals, contenders); alert("Gold: " + gold); alert("Silver: " + silver); alert("The Field: " + rest); \ No newline at end of file diff --git a/documentation/js/splices.js b/documentation/js/splices.js index cd60fe70..944f1e39 100644 --- a/documentation/js/splices.js +++ b/documentation/js/splices.js @@ -1,3 +1,3 @@ -var numbers; +var _ref, numbers; numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; -numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6])); \ No newline at end of file +([].splice.apply(numbers, [3, 6 - 3 + 1].concat(_ref = [-3, -4, -5, -6])), _ref); \ No newline at end of file diff --git a/index.html b/index.html index 0b05db07..7fa52fbb 100644 --- a/index.html +++ b/index.html @@ -149,7 +149,7 @@ alert "I knew it!# Array comprehensions: cubes = math.cube num for num in list -
var _i, _len, _ref, _result, cubes, list, math, num, number, opposite, race, square;
+
var _i, _len, _result, cubes, list, math, num, number, opposite, race, square;
 var __slice = Array.prototype.slice;
 number = 42;
 opposite = true;
@@ -176,14 +176,14 @@ math = {
   alert("I knew it!");
 }
 cubes = (function() {
-  _result = []; _ref = list;
-  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-    num = _ref[_i];
+  _result = [];
+  for (_i = 0, _len = list.length; _i < _len; _i++) {
+    num = list[_i];
     _result.push(math.cube(num));
   }
   return _result;
 })();
-

@@ -913,7 +913,7 @@ deliverEggs = function() { ages = for child, age of yearsOld child + " is " + age -
var _ref, _result, age, ages, child, yearsOld;
+
var _result, age, ages, child, yearsOld;
 var __hasProp = Object.prototype.hasOwnProperty;
 yearsOld = {
   max: 10,
@@ -921,15 +921,15 @@ yearsOld = {
   tim: 11
 };
 ages = (function() {
-  _result = []; _ref = yearsOld;
-  for (child in _ref) {
-    if (!__hasProp.call(_ref, child)) continue;
-    age = _ref[child];
+  _result = [];
+  for (child in yearsOld) {
+    if (!__hasProp.call(yearsOld, child)) continue;
+    age = yearsOld[child];
     _result.push(child + " is " + age);
   }
   return _result;
 })();
-

3
..6] = [-3, -4, -5, -6] -
var numbers;
+
var _ref, numbers;
 numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
-numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));
-

+([].splice.apply(numbers, [3, 6 - 3 + 1].concat(_ref = [-3, -4, -5, -6])), _ref);;alert(numbers);'>run: numbers

@@ -1121,12 +1121,12 @@ speed ?= if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) { solipsism = true; } -speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140; +(typeof speed !== "undefined" && speed !== null) ? speed : (speed = 140);
+(typeof speed !== "undefined" && speed !== null) ? speed : (speed = 140);;alert(speed);'>run: speed

The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead @@ -1137,7 +1137,7 @@ speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;;alert(sp

lottery.drawWinner()?.address?.zipcode
 
var _ref, _ref2;
-(typeof (_ref2 = ((_ref = lottery.drawWinner()))) === "undefined" || _ref2 === null) ? undefined : _ref2.address == null ? undefined : _ref2.address.zipcode;
+(((_ref = lottery.drawWinner()) != null) ? (((_ref2 = _ref.address) != null) ? _ref2.zipcode : undefined) : undefined);
 

Soaking up nulls is similar to Ruby's @@ -1201,24 +1201,30 @@ tom.move() if (typeof parent.extended === "function") parent.extended(child); child.__super__ = parent.prototype; }; -Animal = function(_arg) { - this.name = _arg; - return this; -}; +Animal = (function() { + return function Animal(_arg) { + this.name = _arg; + return this; + }; +})(); Animal.prototype.move = function(meters) { return alert(this.name + " moved " + meters + "m."); }; -Snake = function() { - return Animal.apply(this, arguments); -}; +Snake = (function() { + return function Snake() { + return Animal.apply(this, arguments); + }; +})(); __extends(Snake, Animal); Snake.prototype.move = function() { alert("Slithering..."); return Snake.__super__.move.call(this, 5); }; -Horse = function() { - return Animal.apply(this, arguments); -}; +Horse = (function() { + return function Horse() { + return Animal.apply(this, arguments); + }; +})(); __extends(Horse, Animal); Horse.prototype.move = function() { alert("Galloping..."); @@ -1237,24 +1243,30 @@ var __extends = function(child, parent) { if (typeof parent.extended === "function") parent.extended(child); child.__super__ = parent.prototype; }; -Animal = function(_arg) { - this.name = _arg; - return this; -}; +Animal = (function() { + return function Animal(_arg) { + this.name = _arg; + return this; + }; +})(); Animal.prototype.move = function(meters) { return alert(this.name + " moved " + meters + "m."); }; -Snake = function() { - return Animal.apply(this, arguments); -}; +Snake = (function() { + return function Snake() { + return Animal.apply(this, arguments); + }; +})(); __extends(Snake, Animal); Snake.prototype.move = function() { alert("Slithering..."); return Snake.__super__.move.call(this, 5); }; -Horse = function() { - return Animal.apply(this, arguments); -}; +Horse = (function() { + return function Horse() { + return Animal.apply(this, arguments); + }; +})(); __extends(Horse, Animal); Horse.prototype.move = function() { alert("Galloping..."); @@ -1281,7 +1293,7 @@ tom.move();;'>run
};;alert("one_two".dasherize());'>run: "one_two".dasherize()

Finally, you may assign Class-level (static) properties within a class - definition by using
@property = value + definition by using
@property: value

@@ -1302,15 +1314,11 @@ theSwitch = 0

var _ref, theBait, theSwitch;
 theBait = 1000;
 theSwitch = 0;
-_ref = [theSwitch, theBait];
-theBait = _ref[0];
-theSwitch = _ref[1];
+_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
 

+_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];;alert(theBait);'>run: theBait

But it's also helpful for dealing with functions that return multiple values. @@ -1324,18 +1332,12 @@ theSwitch = _ref[1];;alert(theBait);'>run: theBait
< weatherReport = function(location) { return [location, 72, "Mostly Sunny"]; }; -_ref = weatherReport("Berkeley, CA"); -city = _ref[0]; -temp = _ref[1]; -forecast = _ref[2]; +_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];
+_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];;alert(forecast);'>run: forecast

Pattern matching can be used with any depth of array and object nesting, to help pull out deeply nested properties. @@ -1351,7 +1353,7 @@ forecast = _ref[2];;alert(forecast);'>run: forecast
] {poet: {name, address: [street, city]}} = futurists -

var _ref, _ref2, _ref3, city, futurists, name, street;
+
var _ref, _ref2, city, futurists, name, street;
 futurists = {
   sculptor: "Umberto Boccioni",
   painter: "Vladimir Burliuk",
@@ -1360,13 +1362,8 @@ futurists = {
     address: ["Via Roma 42R", "Bellagio, Italy 22021"]
   }
 };
-_ref = futurists;
-_ref2 = _ref.poet;
-name = _ref2.name;
-_ref3 = _ref2.address;
-street = _ref3[0];
-city = _ref3[1];
-

+_ref = futurists.poet, name = _ref.name, _ref2 = _ref.address, street = _ref2[0], city = _ref2[1];;alert(name + " — " + street);'>run: name + " — " + street

Pattern matching can even be combined with splats.

@@ -1394,17 +1386,11 @@ city = _ref3[1];;alert(name + " — " + street);'>run: name + " — " + street
var _ref, close, contents, open, tag;
 var __slice = Array.prototype.slice;
 tag = "<impossible>";
-_ref = tag.split("");
-open = _ref[0];
-contents = __slice.call(_ref, 1, _ref.length - 1);
-close = _ref[_ref.length - 1];
+_ref = tag.split(""), open = _ref[0], contents = __slice.call(_ref, 1, _ref.length - 1), close = _ref[_ref.length - 1];
 

+_ref = tag.split(""), open = _ref[0], contents = __slice.call(_ref, 1, _ref.length - 1), close = _ref[_ref.length - 1];;alert(contents.join(""));'>run: contents.join("")

@@ -1589,11 +1575,11 @@ dates = /\d+#{sep}\d+#{sep}\d+

var dates, sentence, sep;
 sentence = ("" + (22 / 7) + " is a decent approximation of π");
 sep = "[.\\/\\- ]";
-dates = (new RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g"));
+dates = (RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g"));
 

+dates = (RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g"));;alert(sentence);'>run: sentence

diff --git a/lib/lexer.js b/lib/lexer.js index e5813690..edc545b0 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -4,7 +4,9 @@ Rewriter = require('./rewriter').Rewriter; _ref = require('./helpers'), include = _ref.include, count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last; exports.Lexer = (function() { - Lexer = function() {}; + Lexer = (function() { + return function Lexer() {}; + })(); Lexer.prototype.tokenize = function(code, options) { var o; code = code.replace(/\r/g, '').replace(/\s+$/, ''); diff --git a/lib/nodes.js b/lib/nodes.js index f723b414..5cd8b303 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -20,10 +20,12 @@ return this; }; exports.BaseNode = (function() { - BaseNode = function() { - this.tags = {}; - return this; - }; + BaseNode = (function() { + return function BaseNode() { + this.tags = {}; + return this; + }; + })(); BaseNode.prototype.compile = function(o) { var closure, code, top; this.options = o ? merge(o) : {}; @@ -159,11 +161,13 @@ return BaseNode; })(); exports.Expressions = (function() { - Expressions = function(nodes) { - Expressions.__super__.constructor.call(this); - this.expressions = compact(flatten(nodes || [])); - return this; - }; + Expressions = (function() { + return function Expressions(nodes) { + Expressions.__super__.constructor.call(this); + this.expressions = compact(flatten(nodes || [])); + return this; + }; + })(); __extends(Expressions, BaseNode); Expressions.prototype["class"] = 'Expressions'; Expressions.prototype.children = ['expressions']; @@ -244,11 +248,13 @@ return new Expressions(nodes); }; exports.LiteralNode = (function() { - LiteralNode = function(_arg) { - this.value = _arg; - LiteralNode.__super__.constructor.call(this); - return this; - }; + LiteralNode = (function() { + return function LiteralNode(_arg) { + this.value = _arg; + LiteralNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(LiteralNode, BaseNode); LiteralNode.prototype["class"] = 'LiteralNode'; LiteralNode.prototype.makeReturn = function() { @@ -272,11 +278,13 @@ return LiteralNode; })(); exports.ReturnNode = (function() { - ReturnNode = function(_arg) { - this.expression = _arg; - ReturnNode.__super__.constructor.call(this); - return this; - }; + ReturnNode = (function() { + return function ReturnNode(_arg) { + this.expression = _arg; + ReturnNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(ReturnNode, BaseNode); ReturnNode.prototype["class"] = 'ReturnNode'; ReturnNode.prototype.isStatement = YES; @@ -300,16 +308,18 @@ return ReturnNode; })(); exports.ValueNode = (function() { - ValueNode = function(_arg, _arg2, tag) { - this.properties = _arg2; - this.base = _arg; - ValueNode.__super__.constructor.call(this); - this.properties || (this.properties = []); - if (tag) { - this.tags[tag] = true; - } - return this; - }; + ValueNode = (function() { + return function ValueNode(_arg, _arg2, tag) { + this.properties = _arg2; + this.base = _arg; + ValueNode.__super__.constructor.call(this); + this.properties || (this.properties = []); + if (tag) { + this.tags[tag] = true; + } + return this; + }; + })(); __extends(ValueNode, BaseNode); ValueNode.prototype["class"] = 'ValueNode'; ValueNode.prototype.children = ['base', 'properties']; @@ -432,11 +442,13 @@ return ValueNode; }).call(this); exports.CommentNode = (function() { - CommentNode = function(_arg) { - this.comment = _arg; - CommentNode.__super__.constructor.call(this); - return this; - }; + CommentNode = (function() { + return function CommentNode(_arg) { + this.comment = _arg; + CommentNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(CommentNode, BaseNode); CommentNode.prototype["class"] = 'CommentNode'; CommentNode.prototype.isStatement = YES; @@ -447,16 +459,18 @@ return CommentNode; })(); exports.CallNode = (function() { - CallNode = function(variable, _arg, _arg2) { - this.exist = _arg2; - this.args = _arg; - CallNode.__super__.constructor.call(this); - this.isNew = false; - this.isSuper = variable === 'super'; - this.variable = this.isSuper ? null : variable; - this.args || (this.args = []); - return this; - }; + CallNode = (function() { + return function CallNode(variable, _arg, _arg2) { + this.exist = _arg2; + this.args = _arg; + CallNode.__super__.constructor.call(this); + this.isNew = false; + this.isSuper = variable === 'super'; + this.variable = this.isSuper ? null : variable; + this.args || (this.args = []); + return this; + }; + })(); __extends(CallNode, BaseNode); CallNode.prototype["class"] = 'CallNode'; CallNode.prototype.children = ['variable', 'args']; @@ -596,12 +610,14 @@ return CallNode; })(); exports.ExtendsNode = (function() { - ExtendsNode = function(_arg, _arg2) { - this.parent = _arg2; - this.child = _arg; - ExtendsNode.__super__.constructor.call(this); - return this; - }; + ExtendsNode = (function() { + return function ExtendsNode(_arg, _arg2) { + this.parent = _arg2; + this.child = _arg; + ExtendsNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(ExtendsNode, BaseNode); ExtendsNode.prototype["class"] = 'ExtendsNode'; ExtendsNode.prototype.children = ['child', 'parent']; @@ -613,13 +629,15 @@ return ExtendsNode; })(); exports.AccessorNode = (function() { - AccessorNode = function(_arg, tag) { - this.name = _arg; - AccessorNode.__super__.constructor.call(this); - this.prototype = tag === 'prototype' ? '.prototype' : ''; - this.soakNode = tag === 'soak'; - return this; - }; + AccessorNode = (function() { + return function AccessorNode(_arg, tag) { + this.name = _arg; + AccessorNode.__super__.constructor.call(this); + this.prototype = tag === 'prototype' ? '.prototype' : ''; + this.soakNode = tag === 'soak'; + return this; + }; + })(); __extends(AccessorNode, BaseNode); AccessorNode.prototype["class"] = 'AccessorNode'; AccessorNode.prototype.children = ['name']; @@ -633,11 +651,13 @@ return AccessorNode; })(); exports.IndexNode = (function() { - IndexNode = function(_arg) { - this.index = _arg; - IndexNode.__super__.constructor.call(this); - return this; - }; + IndexNode = (function() { + return function IndexNode(_arg) { + this.index = _arg; + IndexNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(IndexNode, BaseNode); IndexNode.prototype["class"] = 'IndexNode'; IndexNode.prototype.children = ['index']; @@ -653,14 +673,16 @@ return IndexNode; })(); exports.RangeNode = (function() { - RangeNode = function(_arg, _arg2, tag) { - this.to = _arg2; - this.from = _arg; - RangeNode.__super__.constructor.call(this); - this.exclusive = tag === 'exclusive'; - this.equals = this.exclusive ? '' : '='; - return this; - }; + RangeNode = (function() { + return function RangeNode(_arg, _arg2, tag) { + this.to = _arg2; + this.from = _arg; + RangeNode.__super__.constructor.call(this); + this.exclusive = tag === 'exclusive'; + this.equals = this.exclusive ? '' : '='; + return this; + }; + })(); __extends(RangeNode, BaseNode); RangeNode.prototype["class"] = 'RangeNode'; RangeNode.prototype.children = ['from', 'to']; @@ -743,11 +765,13 @@ return RangeNode; })(); exports.SliceNode = (function() { - SliceNode = function(_arg) { - this.range = _arg; - SliceNode.__super__.constructor.call(this); - return this; - }; + SliceNode = (function() { + return function SliceNode(_arg) { + this.range = _arg; + SliceNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(SliceNode, BaseNode); SliceNode.prototype["class"] = 'SliceNode'; SliceNode.prototype.children = ['range']; @@ -764,11 +788,13 @@ return SliceNode; })(); exports.ObjectNode = (function() { - ObjectNode = function(props) { - ObjectNode.__super__.constructor.call(this); - this.objects = (this.properties = props || []); - return this; - }; + ObjectNode = (function() { + return function ObjectNode(props) { + ObjectNode.__super__.constructor.call(this); + this.objects = (this.properties = props || []); + return this; + }; + })(); __extends(ObjectNode, BaseNode); ObjectNode.prototype["class"] = 'ObjectNode'; ObjectNode.prototype.children = ['properties']; @@ -818,12 +844,14 @@ return ObjectNode; })(); exports.ArrayNode = (function() { - ArrayNode = function(_arg) { - this.objects = _arg; - ArrayNode.__super__.constructor.call(this); - this.objects || (this.objects = []); - return this; - }; + ArrayNode = (function() { + return function ArrayNode(_arg) { + this.objects = _arg; + ArrayNode.__super__.constructor.call(this); + this.objects || (this.objects = []); + return this; + }; + })(); __extends(ArrayNode, BaseNode); ArrayNode.prototype["class"] = 'ArrayNode'; ArrayNode.prototype.children = ['objects']; @@ -854,15 +882,17 @@ return ArrayNode; })(); exports.ClassNode = (function() { - ClassNode = function(_arg, _arg2, _arg3) { - this.properties = _arg3; - this.parent = _arg2; - this.variable = _arg; - ClassNode.__super__.constructor.call(this); - this.properties || (this.properties = []); - this.returns = false; - return this; - }; + ClassNode = (function() { + return function ClassNode(_arg, _arg2, _arg3) { + this.properties = _arg3; + this.parent = _arg2; + this.variable = _arg; + ClassNode.__super__.constructor.call(this); + this.properties || (this.properties = []); + this.returns = false; + return this; + }; + })(); __extends(ClassNode, BaseNode); ClassNode.prototype["class"] = 'ClassNode'; ClassNode.prototype.children = ['variable', 'parent', 'properties']; @@ -924,6 +954,7 @@ } props.push(prop); } + constructor.className = className.match(/[\w\d\$_]+$/); if (me) { constructor.body.unshift(literal("" + (me) + " = this")); } @@ -938,13 +969,15 @@ return ClassNode; })(); exports.AssignNode = (function() { - AssignNode = function(_arg, _arg2, _arg3) { - this.context = _arg3; - this.value = _arg2; - this.variable = _arg; - AssignNode.__super__.constructor.call(this); - return this; - }; + AssignNode = (function() { + return function AssignNode(_arg, _arg2, _arg3) { + this.context = _arg3; + this.value = _arg2; + this.variable = _arg; + AssignNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(AssignNode, BaseNode); AssignNode.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.)?([$A-Za-z_][$\w]*)$/; AssignNode.prototype["class"] = 'AssignNode'; @@ -1065,23 +1098,25 @@ return AssignNode; })(); exports.CodeNode = (function() { - CodeNode = function(_arg, _arg2, tag) { - this.body = _arg2; - this.params = _arg; - CodeNode.__super__.constructor.call(this); - this.params || (this.params = []); - this.body || (this.body = new Expressions); - this.bound = tag === 'boundfunc'; - if (this.bound) { - this.context = 'this'; - } - return this; - }; + CodeNode = (function() { + return function CodeNode(_arg, _arg2, tag) { + this.body = _arg2; + this.params = _arg; + CodeNode.__super__.constructor.call(this); + this.params || (this.params = []); + this.body || (this.body = new Expressions); + this.bound = tag === 'boundfunc'; + if (this.bound) { + this.context = 'this'; + } + return this; + }; + })(); __extends(CodeNode, BaseNode); CodeNode.prototype["class"] = 'CodeNode'; CodeNode.prototype.children = ['params', 'body']; CodeNode.prototype.compileNode = function(o) { - var _i, _len, _ref2, _ref3, _result, code, empty, func, i, param, params, sharedScope, splat, top, value; + var _i, _len, _ref2, _ref3, _result, close, code, empty, func, i, open, param, params, sharedScope, splat, top, value; sharedScope = del(o, 'sharedScope'); top = del(o, 'top'); o.scope = sharedScope || new Scope(o.scope, this.body, this); @@ -1133,10 +1168,15 @@ param = params[_i]; (o.scope.parameter(param)); } + if (this.className) { + o.indent = this.idt(2); + } code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : ''; - func = ("function(" + (params.join(', ')) + ") {" + (code) + (code && this.tab) + "}"); + open = this.className ? ("(function() {\n" + (this.idt(1)) + "return function " + (this.className) + "(") : "function("; + close = this.className ? ("" + (code && this.idt(1)) + "};\n" + (this.tab) + "})()") : ("" + (code && this.tab) + "}"); + func = ("" + (open) + (params.join(', ')) + ") {" + (code) + (close)); if (this.bound) { - return ("(" + (utility('bind')) + "(" + (func) + ", " + (this.context) + "))"); + return ("" + (utility('bind')) + "(" + (func) + ", " + (this.context) + ")"); } return top ? ("(" + (func) + ")") : func; }; @@ -1147,14 +1187,16 @@ return CodeNode; })(); exports.ParamNode = (function() { - ParamNode = function(_arg, _arg2, _arg3) { - this.splat = _arg3; - this.attach = _arg2; - this.name = _arg; - ParamNode.__super__.constructor.call(this); - this.value = literal(this.name); - return this; - }; + ParamNode = (function() { + return function ParamNode(_arg, _arg2, _arg3) { + this.splat = _arg3; + this.attach = _arg2; + this.name = _arg; + ParamNode.__super__.constructor.call(this); + this.value = literal(this.name); + return this; + }; + })(); __extends(ParamNode, BaseNode); ParamNode.prototype["class"] = 'ParamNode'; ParamNode.prototype.children = ['name']; @@ -1175,14 +1217,16 @@ return ParamNode; })(); exports.SplatNode = (function() { - SplatNode = function(name) { - SplatNode.__super__.constructor.call(this); - if (!(name.compile)) { - name = literal(name); - } - this.name = name; - return this; - }; + SplatNode = (function() { + return function SplatNode(name) { + SplatNode.__super__.constructor.call(this); + if (!(name.compile)) { + name = literal(name); + } + this.name = name; + return this; + }; + })(); __extends(SplatNode, BaseNode); SplatNode.prototype["class"] = 'SplatNode'; SplatNode.prototype.children = ['name']; @@ -1245,18 +1289,20 @@ return SplatNode; }).call(this); exports.WhileNode = (function() { - WhileNode = function(condition, opts) { - WhileNode.__super__.constructor.call(this); - if (((opts != null) ? opts.invert : undefined)) { - if (condition instanceof OpNode) { - condition = new ParentheticalNode(condition); + WhileNode = (function() { + return function WhileNode(condition, opts) { + WhileNode.__super__.constructor.call(this); + if (((opts != null) ? opts.invert : undefined)) { + if (condition instanceof OpNode) { + condition = new ParentheticalNode(condition); + } + condition = new OpNode('!', condition); } - condition = new OpNode('!', condition); - } - this.condition = condition; - this.guard = ((opts != null) ? opts.guard : undefined); - return this; - }; + this.condition = condition; + this.guard = ((opts != null) ? opts.guard : undefined); + return this; + }; + })(); __extends(WhileNode, BaseNode); WhileNode.prototype["class"] = 'WhileNode'; WhileNode.prototype.children = ['condition', 'guard', 'body']; @@ -1301,24 +1347,26 @@ return WhileNode; })(); exports.OpNode = (function() { - OpNode = function(_arg, _arg2, _arg3, flip) { - this.second = _arg3; - this.first = _arg2; - this.operator = _arg; - OpNode.__super__.constructor.call(this); - this.operator = this.CONVERSIONS[this.operator] || this.operator; - this.flip = !!flip; - if (this.first instanceof ValueNode && this.first.base instanceof ObjectNode) { - this.first = new ParentheticalNode(this.first); - } else if (this.operator === 'new' && this.first instanceof CallNode) { - return this.first.newInstance(); - } - this.first.tags.operation = true; - if (this.second) { - this.second.tags.operation = true; - } - return this; - }; + OpNode = (function() { + return function OpNode(_arg, _arg2, _arg3, flip) { + this.second = _arg3; + this.first = _arg2; + this.operator = _arg; + OpNode.__super__.constructor.call(this); + this.operator = this.CONVERSIONS[this.operator] || this.operator; + this.flip = !!flip; + if (this.first instanceof ValueNode && this.first.base instanceof ObjectNode) { + this.first = new ParentheticalNode(this.first); + } else if (this.operator === 'new' && this.first instanceof CallNode) { + return this.first.newInstance(); + } + this.first.tags.operation = true; + if (this.second) { + this.second.tags.operation = true; + } + return this; + }; + })(); __extends(OpNode, BaseNode); OpNode.prototype.CONVERSIONS = { '==': '===', @@ -1417,12 +1465,14 @@ return OpNode; })(); exports.InNode = (function() { - InNode = function(_arg, _arg2) { - this.array = _arg2; - this.object = _arg; - InNode.__super__.constructor.call(this); - return this; - }; + InNode = (function() { + return function InNode(_arg, _arg2) { + this.array = _arg2; + this.object = _arg; + InNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(InNode, BaseNode); InNode.prototype["class"] = 'InNode'; InNode.prototype.children = ['object', 'array']; @@ -1460,14 +1510,16 @@ return InNode; })(); exports.TryNode = (function() { - TryNode = function(_arg, _arg2, _arg3, _arg4) { - this.ensure = _arg4; - this.recovery = _arg3; - this.error = _arg2; - this.attempt = _arg; - TryNode.__super__.constructor.call(this); - return this; - }; + TryNode = (function() { + return function TryNode(_arg, _arg2, _arg3, _arg4) { + this.ensure = _arg4; + this.recovery = _arg3; + this.error = _arg2; + this.attempt = _arg; + TryNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(TryNode, BaseNode); TryNode.prototype["class"] = 'TryNode'; TryNode.prototype.children = ['attempt', 'recovery', 'ensure']; @@ -1494,11 +1546,13 @@ return TryNode; })(); exports.ThrowNode = (function() { - ThrowNode = function(_arg) { - this.expression = _arg; - ThrowNode.__super__.constructor.call(this); - return this; - }; + ThrowNode = (function() { + return function ThrowNode(_arg) { + this.expression = _arg; + ThrowNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(ThrowNode, BaseNode); ThrowNode.prototype["class"] = 'ThrowNode'; ThrowNode.prototype.children = ['expression']; @@ -1510,11 +1564,13 @@ return ThrowNode; })(); exports.ExistenceNode = (function() { - ExistenceNode = function(_arg) { - this.expression = _arg; - ExistenceNode.__super__.constructor.call(this); - return this; - }; + ExistenceNode = (function() { + return function ExistenceNode(_arg) { + this.expression = _arg; + ExistenceNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(ExistenceNode, BaseNode); ExistenceNode.prototype["class"] = 'ExistenceNode'; ExistenceNode.prototype.children = ['expression']; @@ -1527,11 +1583,13 @@ return ExistenceNode; })(); exports.ParentheticalNode = (function() { - ParentheticalNode = function(_arg) { - this.expression = _arg; - ParentheticalNode.__super__.constructor.call(this); - return this; - }; + ParentheticalNode = (function() { + return function ParentheticalNode(_arg) { + this.expression = _arg; + ParentheticalNode.__super__.constructor.call(this); + return this; + }; + })(); __extends(ParentheticalNode, BaseNode); ParentheticalNode.prototype["class"] = 'ParentheticalNode'; ParentheticalNode.prototype.children = ['expression']; @@ -1561,28 +1619,30 @@ return ParentheticalNode; })(); exports.ForNode = (function() { - ForNode = function(_arg, source, _arg2, _arg3) { - var _ref2; - this.index = _arg3; - this.name = _arg2; - this.body = _arg; - ForNode.__super__.constructor.call(this); - this.index || (this.index = null); - this.source = source.source; - this.guard = source.guard; - this.step = source.step; - this.raw = !!source.raw; - this.object = !!source.object; - if (this.object) { - _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1]; - } - this.pattern = this.name instanceof ValueNode; - if (this.index instanceof ValueNode) { - throw new Error('index cannot be a pattern matching expression'); - } - this.returns = false; - return this; - }; + ForNode = (function() { + return function ForNode(_arg, source, _arg2, _arg3) { + var _ref2; + this.index = _arg3; + this.name = _arg2; + this.body = _arg; + ForNode.__super__.constructor.call(this); + this.index || (this.index = null); + this.source = source.source; + this.guard = source.guard; + this.step = source.step; + this.raw = !!source.raw; + this.object = !!source.object; + if (this.object) { + _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1]; + } + this.pattern = this.name instanceof ValueNode; + if (this.index instanceof ValueNode) { + throw new Error('index cannot be a pattern matching expression'); + } + this.returns = false; + return this; + }; + })(); __extends(ForNode, BaseNode); ForNode.prototype["class"] = 'ForNode'; ForNode.prototype.children = ['body', 'source', 'guard']; @@ -1700,15 +1760,17 @@ return ForNode; })(); exports.SwitchNode = (function() { - SwitchNode = function(_arg, _arg2, _arg3) { - this.otherwise = _arg3; - this.cases = _arg2; - this.subject = _arg; - SwitchNode.__super__.constructor.call(this); - this.tags.subjectless = !this.subject; - this.subject || (this.subject = literal('true')); - return this; - }; + SwitchNode = (function() { + return function SwitchNode(_arg, _arg2, _arg3) { + this.otherwise = _arg3; + this.cases = _arg2; + this.subject = _arg; + SwitchNode.__super__.constructor.call(this); + this.tags.subjectless = !this.subject; + this.subject || (this.subject = literal('true')); + return this; + }; + })(); __extends(SwitchNode, BaseNode); SwitchNode.prototype["class"] = 'SwitchNode'; SwitchNode.prototype.children = ['subject', 'cases', 'otherwise']; @@ -1757,22 +1819,24 @@ return SwitchNode; })(); exports.IfNode = (function() { - IfNode = function(_arg, _arg2, _arg3) { - this.tags = _arg3; - this.body = _arg2; - this.condition = _arg; - this.tags || (this.tags = {}); - if (this.tags.invert) { - if (this.condition instanceof OpNode && this.condition.isInvertible()) { - this.condition.invert(); - } else { - this.condition = new OpNode('!', new ParentheticalNode(this.condition)); + IfNode = (function() { + return function IfNode(_arg, _arg2, _arg3) { + this.tags = _arg3; + this.body = _arg2; + this.condition = _arg; + this.tags || (this.tags = {}); + if (this.tags.invert) { + if (this.condition instanceof OpNode && this.condition.isInvertible()) { + this.condition.invert(); + } else { + this.condition = new OpNode('!', new ParentheticalNode(this.condition)); + } } - } - this.elseBody = null; - this.isChain = false; - return this; - }; + this.elseBody = null; + this.isChain = false; + return this; + }; + })(); __extends(IfNode, BaseNode); IfNode.prototype["class"] = 'IfNode'; IfNode.prototype.children = ['condition', 'body', 'elseBody', 'assigner']; diff --git a/lib/optparse.js b/lib/optparse.js index 2839c242..ca24b813 100755 --- a/lib/optparse.js +++ b/lib/optparse.js @@ -1,11 +1,13 @@ (function() { var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments; exports.OptionParser = (function() { - OptionParser = function(rules, banner) { - this.banner = banner; - this.rules = buildRules(rules); - return this; - }; + OptionParser = (function() { + return function OptionParser(rules, banner) { + this.banner = banner; + this.rules = buildRules(rules); + return this; + }; + })(); OptionParser.prototype.parse = function(args) { var _i, _len, _len2, _ref, arg, i, isOption, matchedRule, options, rule, value; options = { diff --git a/lib/rewriter.js b/lib/rewriter.js index c079c439..1f453ab8 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -1,7 +1,9 @@ (function() { var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, include, left, rite; include = require('./helpers').include; - exports.Rewriter = function() {}; + exports.Rewriter = (function() { + return function Rewriter() {}; + })(); exports.Rewriter.prototype.rewrite = function(_arg) { this.tokens = _arg; this.adjustComments(); diff --git a/lib/scope.js b/lib/scope.js index 82b1eb1c..c38a8955 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -3,21 +3,23 @@ var __hasProp = Object.prototype.hasOwnProperty; _ref = require('./helpers'), extend = _ref.extend, last = _ref.last; exports.Scope = (function() { - Scope = function(_arg, _arg2, _arg3) { - this.method = _arg3; - this.expressions = _arg2; - this.parent = _arg; - this.variables = { - 'arguments': 'arguments' + Scope = (function() { + return function Scope(_arg, _arg2, _arg3) { + this.method = _arg3; + this.expressions = _arg2; + this.parent = _arg; + this.variables = { + 'arguments': 'arguments' + }; + if (this.parent) { + this.garbage = this.parent.garbage; + } else { + this.garbage = []; + Scope.root = this; + } + return this; }; - if (this.parent) { - this.garbage = this.parent.garbage; - } else { - this.garbage = []; - Scope.root = this; - } - return this; - }; + })(); Scope.root = null; Scope.prototype.startLevel = function() { return this.garbage.push([]); diff --git a/src/nodes.coffee b/src/nodes.coffee index bf9b0e0d..a6b7c2a3 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -823,6 +823,7 @@ exports.ClassNode = class ClassNode extends BaseNode prop = new AssignNode(val, func) props.push prop + constructor.className = className.match /[\w\d\$_]+$/ constructor.body.unshift literal "#{me} = this" if me construct = @idt() + (new AssignNode(@variable, constructor)).compile(merge o, {sharedScope: constScope}) + ';' props = if !props.empty() then '\n' + props.compile(o) else '' @@ -991,9 +992,12 @@ exports.CodeNode = class CodeNode extends BaseNode params = (param.compile(o) for param in params) @body.makeReturn() unless empty (o.scope.parameter(param)) for param in params - code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else '' - func = "function(#{ params.join(', ') }) {#{code}#{ code and @tab }}" - return "(#{utility 'bind'}(#{func}, #{@context}))" if @bound + o.indent = @idt 2 if @className + code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else '' + open = if @className then "(function() {\n#{@idt(1)}return function #{@className}(" else "function(" + close = if @className then "#{code and @idt(1)}};\n#{@tab}})()" else "#{code and @tab}}" + func = "#{open}#{ params.join(', ') }) {#{code}#{close}" + return "#{utility 'bind'}(#{func}, #{@context})" if @bound if top then "(#{func})" else func topSensitive: YES