First draft of named classes.

This commit is contained in:
Jeremy Ashkenas 2010-10-04 23:21:16 -04:00
commit 2b66d5d6c0
19 changed files with 445 additions and 390 deletions

View File

@ -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...");

View File

@ -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;
(typeof speed !== "undefined" && speed !== null) ? speed : (speed = 140);

View File

@ -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"));
dates = (RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g"));

View File

@ -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];
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];

View File

@ -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;

View File

@ -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];
_ref = futurists.poet, name = _ref.name, _ref2 = _ref.address, street = _ref2[0], city = _ref2[1];

View File

@ -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;

View File

@ -1,6 +1,4 @@
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];

View File

@ -1,7 +1,4 @@
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];

View File

@ -1,2 +1,2 @@
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);

View File

@ -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);

View File

@ -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]));
([].splice.apply(numbers, [3, 6 - 3 + 1].concat(_ref = [-3, -4, -5, -6])), _ref);

View File

@ -149,7 +149,7 @@ alert <span class="String"><span class="String">&quot;</span>I knew it!<span cla
<span class="Comment"><span class="Comment">#</span> Array comprehensions:</span>
cubes <span class="Keyword">=</span> math.cube num <span class="Keyword">for</span> num <span class="Keyword">in</span> list
</pre><pre class="idle"><span class="Storage">var</span> _i, _len, _ref, _result, cubes, list, math, num, number, opposite, race, square;
</pre><pre class="idle"><span class="Storage">var</span> _i, _len, _result, cubes, list, math, num, number, opposite, race, square;
<span class="Storage">var</span> __slice <span class="Keyword">=</span> <span class="LibraryClassType">Array</span>.<span class="LibraryConstant">prototype</span>.slice;
number <span class="Keyword">=</span> <span class="Number">42</span>;
opposite <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
@ -176,14 +176,14 @@ math <span class="Keyword">=</span> {
<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">&quot;</span>I knew it!<span class="String">&quot;</span></span>);
}
cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() {
_result <span class="Keyword">=</span> []; _ref <span class="Keyword">=</span> list;
<span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> _ref.<span class="LibraryConstant">length</span>; _i <span class="Keyword">&lt;</span> _len; _i<span class="Keyword">++</span>) {
num <span class="Keyword">=</span> _ref[_i];
_result <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> list.<span class="LibraryConstant">length</span>; _i <span class="Keyword">&lt;</span> _len; _i<span class="Keyword">++</span>) {
num <span class="Keyword">=</span> list[_i];
_result.<span class="LibraryFunction">push</span>(math.cube(num));
}
<span class="Keyword">return</span> _result;
})();
</pre><button onclick='javascript: var _i, _len, _ref, _result, cubes, list, math, num, number, opposite, race, square;
</pre><button onclick='javascript: var _i, _len, _result, cubes, list, math, num, number, opposite, race, square;
var __slice = Array.prototype.slice;
number = 42;
opposite = true;
@ -210,9 +210,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;
@ -734,7 +734,7 @@ gold <span class="Keyword">=</span> (silver <span class="Keyword">=</span> (rest
<span class="Keyword">return</span> (rest <span class="Keyword">=</span> others);
};
contenders <span class="Keyword">=</span> [<span class="String"><span class="String">&quot;</span>Michael Phelps<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Liu Xiang<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Yao Ming<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Allyson Felix<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Shawn Johnson<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Roman Sebrle<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Guo Jingjing<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Tyson Gay<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Asafa Powell<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Usain Bolt<span class="String">&quot;</span></span>];
awardMedals.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, contenders);
awardMedals.<span class="LibraryFunction">apply</span>(awardMedals, contenders);
<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">&quot;</span>Gold: <span class="String">&quot;</span></span> <span class="Keyword">+</span> gold);
<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">&quot;</span>Silver: <span class="String">&quot;</span></span> <span class="Keyword">+</span> silver);
<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">&quot;</span>The Field: <span class="String">&quot;</span></span> <span class="Keyword">+</span> rest);
@ -749,7 +749,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);;'>run</button><br class='clear' /></div>
@ -913,7 +913,7 @@ deliverEggs = function() {
ages <span class="Keyword">=</span> <span class="Keyword">for</span> child, age <span class="Keyword">of</span> yearsOld
child <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> is <span class="String">&quot;</span></span> <span class="Keyword">+</span> age
</pre><pre class="idle"><span class="Storage">var</span> _ref, _result, age, ages, child, yearsOld;
</pre><pre class="idle"><span class="Storage">var</span> _result, age, ages, child, yearsOld;
<span class="Storage">var</span> __hasProp <span class="Keyword">=</span> <span class="LibraryClassType">Object</span>.<span class="LibraryConstant">prototype</span>.hasOwnProperty;
yearsOld <span class="Keyword">=</span> {
max: <span class="Number">10</span>,
@ -921,15 +921,15 @@ yearsOld <span class="Keyword">=</span> {
tim: <span class="Number">11</span>
};
ages <span class="Keyword">=</span> (<span class="Storage">function</span>() {
_result <span class="Keyword">=</span> []; _ref <span class="Keyword">=</span> yearsOld;
<span class="Keyword">for</span> (child <span class="Keyword">in</span> _ref) {
<span class="Keyword">if</span> (<span class="Keyword">!</span>__hasProp.<span class="LibraryFunction">call</span>(_ref, child)) <span class="Keyword">continue</span>;
age <span class="Keyword">=</span> _ref[child];
_result <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (child <span class="Keyword">in</span> yearsOld) {
<span class="Keyword">if</span> (<span class="Keyword">!</span>__hasProp.<span class="LibraryFunction">call</span>(yearsOld, child)) <span class="Keyword">continue</span>;
age <span class="Keyword">=</span> yearsOld[child];
_result.<span class="LibraryFunction">push</span>(child <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> is <span class="String">&quot;</span></span> <span class="Keyword">+</span> age);
}
<span class="Keyword">return</span> _result;
})();
</pre><button onclick='javascript: var _ref, _result, age, ages, child, yearsOld;
</pre><button onclick='javascript: var _result, age, ages, child, yearsOld;
var __hasProp = Object.prototype.hasOwnProperty;
yearsOld = {
max: 10,
@ -937,10 +937,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;
@ -986,12 +986,12 @@ copy = numbers.slice(0, numbers.length);;alert(copy);'>run: copy</button><br cla
numbers[<span class="Number">3</span>..<span class="Number">6</span>] <span class="Keyword">=</span> [<span class="Keyword">-</span><span class="Number">3</span>, <span class="Keyword">-</span><span class="Number">4</span>, <span class="Keyword">-</span><span class="Number">5</span>, <span class="Keyword">-</span><span class="Number">6</span>]
</pre><pre class="idle"><span class="Storage">var</span> numbers;
</pre><pre class="idle"><span class="Storage">var</span> _ref, numbers;
numbers <span class="Keyword">=</span> [<span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>, <span class="Number">6</span>, <span class="Number">7</span>, <span class="Number">8</span>, <span class="Number">9</span>];
numbers.splice.<span class="LibraryFunction">apply</span>(numbers, [<span class="Number">3</span>, <span class="Number">6</span> <span class="Keyword">-</span> <span class="Number">3</span> <span class="Keyword">+</span> <span class="Number">1</span>].<span class="LibraryFunction">concat</span>([<span class="Keyword">-</span><span class="Number">3</span>, <span class="Keyword">-</span><span class="Number">4</span>, <span class="Keyword">-</span><span class="Number">5</span>, <span class="Keyword">-</span><span class="Number">6</span>]));
</pre><button onclick='javascript: var numbers;
([].splice.<span class="LibraryFunction">apply</span>(numbers, [<span class="Number">3</span>, <span class="Number">6</span> <span class="Keyword">-</span> <span class="Number">3</span> <span class="Keyword">+</span> <span class="Number">1</span>].<span class="LibraryFunction">concat</span>(_ref <span class="Keyword">=</span> [<span class="Keyword">-</span><span class="Number">3</span>, <span class="Keyword">-</span><span class="Number">4</span>, <span class="Keyword">-</span><span class="Number">5</span>, <span class="Keyword">-</span><span class="Number">6</span>])), _ref);
</pre><button onclick='javascript: 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]));;alert(numbers);'>run: numbers</button><br class='clear' /></div>
([].splice.apply(numbers, [3, 6 - 3 + 1].concat(_ref = [-3, -4, -5, -6])), _ref);;alert(numbers);'>run: numbers</button><br class='clear' /></div>
<p>
<span id="expressions" class="bookmark"></span>
@ -1121,12 +1121,12 @@ speed <span class="Keyword">?</span><span class="Keyword">=</span> <span class="
<span class="Keyword">if</span> ((<span class="Keyword">typeof</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">&quot;</span>undefined<span class="String">&quot;</span></span> <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> <span class="Keyword">!</span>(<span class="Keyword">typeof</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">&quot;</span>undefined<span class="String">&quot;</span></span> <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>)) {
solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
}
speed <span class="Keyword">=</span> (<span class="Keyword">typeof</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">&quot;</span>undefined<span class="String">&quot;</span></span> <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) ? speed : <span class="Number">140</span>;
(<span class="Keyword">typeof</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">&quot;</span>undefined<span class="String">&quot;</span></span> <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) ? speed : (speed <span class="Keyword">=</span> <span class="Number">140</span>);
</pre><button onclick='javascript: var solipsism, speed;
if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
solipsism = true;
}
speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;;alert(speed);'>run: speed</button><br class='clear' /></div>
(typeof speed !== "undefined" && speed !== null) ? speed : (speed = 140);;alert(speed);'>run: speed</button><br class='clear' /></div>
<p>
The accessor variant of the existential operator <tt>?.</tt> 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
</p>
<div class='code'><pre class="idle">lottery.drawWinner()<span class="Keyword">?</span>.address<span class="Keyword">?</span>.zipcode
</pre><pre class="idle"><span class="Storage">var</span> _ref, _ref2;
(<span class="Keyword">typeof</span> (_ref2 <span class="Keyword">=</span> ((_ref <span class="Keyword">=</span> lottery.drawWinner()))) <span class="Keyword">===</span> <span class="String"><span class="String">&quot;</span>undefined<span class="String">&quot;</span></span> <span class="Keyword">||</span> _ref2 <span class="Keyword">===</span> <span class="BuiltInConstant">null</span>) ? undefined : _ref2.address <span class="Keyword">==</span> <span class="BuiltInConstant">null</span> ? undefined : _ref2.address.zipcode;
(((_ref <span class="Keyword">=</span> lottery.drawWinner()) <span class="Keyword">!</span><span class="Keyword">=</span> <span class="BuiltInConstant">null</span>) ? (((_ref2 <span class="Keyword">=</span> _ref.address) <span class="Keyword">!</span><span class="Keyword">=</span> <span class="BuiltInConstant">null</span>) ? _ref2.zipcode : undefined) : undefined);
</pre><br class='clear' /></div>
<p>
Soaking up nulls is similar to Ruby's
@ -1201,24 +1201,30 @@ tom.move()
<span class="Keyword">if</span> (<span class="Keyword">typeof</span> parent.extended <span class="Keyword">===</span> <span class="String"><span class="String">&quot;</span>function<span class="String">&quot;</span></span>) parent.extended(child);
child.__super__ <span class="Keyword">=</span> parent.<span class="LibraryConstant">prototype</span>;
};
<span class="FunctionName">Animal</span> = <span class="Storage">function</span>(<span class="FunctionArgument">_arg</span>) {
<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> _arg;
<span class="Keyword">return</span> <span class="Variable">this</span>;
};
Animal <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Keyword">return</span> <span class="Storage">function</span> <span class="FunctionName">Animal</span>(<span class="FunctionArgument">_arg</span>) {
<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> _arg;
<span class="Keyword">return</span> <span class="Variable">this</span>;
};
})();
<span class="LibraryClassType">Animal</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>(<span class="FunctionArgument">meters</span>) {
<span class="Keyword">return</span> <span class="LibraryFunction">alert</span>(<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> moved <span class="String">&quot;</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span>m.<span class="String">&quot;</span></span>);
};
<span class="FunctionName">Snake</span> = <span class="Storage">function</span>() {
<span class="Keyword">return</span> Animal.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
};
Snake <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Keyword">return</span> <span class="Storage">function</span> <span class="FunctionName">Snake</span>() {
<span class="Keyword">return</span> Animal.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
};
})();
__extends(Snake, Animal);
<span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() {
<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">&quot;</span>Slithering...<span class="String">&quot;</span></span>);
<span class="Keyword">return</span> Snake.__super__.move.<span class="LibraryFunction">call</span>(<span class="Variable">this</span>, <span class="Number">5</span>);
};
<span class="FunctionName">Horse</span> = <span class="Storage">function</span>() {
<span class="Keyword">return</span> Animal.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
};
Horse <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Keyword">return</span> <span class="Storage">function</span> <span class="FunctionName">Horse</span>() {
<span class="Keyword">return</span> Animal.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
};
})();
__extends(Horse, Animal);
<span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() {
<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">&quot;</span>Galloping...<span class="String">&quot;</span></span>);
@ -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</button><br class='clear' /></div>
};;alert("one_two".dasherize());'>run: "one_two".dasherize()</button><br class='clear' /></div>
<p>
Finally, you may assign Class-level (static) properties within a class
definition by using<br /><tt>@property = value</tt>
definition by using<br /><tt>@property: value</tt>
</p>
<p>
@ -1302,15 +1314,11 @@ theSwitch <span class="Keyword">=</span> <span class="Number">0</span>
</pre><pre class="idle"><span class="Storage">var</span> _ref, theBait, theSwitch;
theBait <span class="Keyword">=</span> <span class="Number">1000</span>;
theSwitch <span class="Keyword">=</span> <span class="Number">0</span>;
_ref <span class="Keyword">=</span> [theSwitch, theBait];
theBait <span class="Keyword">=</span> _ref[<span class="Number">0</span>];
theSwitch <span class="Keyword">=</span> _ref[<span class="Number">1</span>];
_ref <span class="Keyword">=</span> [theSwitch, theBait], theBait <span class="Keyword">=</span> _ref[<span class="Number">0</span>], theSwitch <span class="Keyword">=</span> _ref[<span class="Number">1</span>];
</pre><button onclick='javascript: var _ref, theBait, theSwitch;
theBait = 1000;
theSwitch = 0;
_ref = [theSwitch, theBait];
theBait = _ref[0];
theSwitch = _ref[1];;alert(theBait);'>run: theBait</button><br class='clear' /></div>
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];;alert(theBait);'>run: theBait</button><br class='clear' /></div>
<p>
But it's also helpful for dealing with functions that return multiple
values.
@ -1324,18 +1332,12 @@ theSwitch = _ref[1];;alert(theBait);'>run: theBait</button><br class='clear' /><
<span class="FunctionName">weatherReport</span> = <span class="Storage">function</span>(<span class="FunctionArgument">location</span>) {
<span class="Keyword">return</span> [location, <span class="Number">72</span>, <span class="String"><span class="String">&quot;</span>Mostly Sunny<span class="String">&quot;</span></span>];
};
_ref <span class="Keyword">=</span> weatherReport(<span class="String"><span class="String">&quot;</span>Berkeley, CA<span class="String">&quot;</span></span>);
city <span class="Keyword">=</span> _ref[<span class="Number">0</span>];
temp <span class="Keyword">=</span> _ref[<span class="Number">1</span>];
forecast <span class="Keyword">=</span> _ref[<span class="Number">2</span>];
_ref <span class="Keyword">=</span> weatherReport(<span class="String"><span class="String">&quot;</span>Berkeley, CA<span class="String">&quot;</span></span>), city <span class="Keyword">=</span> _ref[<span class="Number">0</span>], temp <span class="Keyword">=</span> _ref[<span class="Number">1</span>], forecast <span class="Keyword">=</span> _ref[<span class="Number">2</span>];
</pre><button onclick='javascript: 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];;alert(forecast);'>run: forecast</button><br class='clear' /></div>
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];;alert(forecast);'>run: forecast</button><br class='clear' /></div>
<p>
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</button><br class='clear' />
]
{poet: {name, address: [street, city]}} <span class="Keyword">=</span> futurists
</pre><pre class="idle"><span class="Storage">var</span> _ref, _ref2, _ref3, city, futurists, name, street;
</pre><pre class="idle"><span class="Storage">var</span> _ref, _ref2, city, futurists, name, street;
futurists <span class="Keyword">=</span> {
sculptor: <span class="String"><span class="String">&quot;</span>Umberto Boccioni<span class="String">&quot;</span></span>,
painter: <span class="String"><span class="String">&quot;</span>Vladimir Burliuk<span class="String">&quot;</span></span>,
@ -1360,13 +1362,8 @@ futurists <span class="Keyword">=</span> {
address: [<span class="String"><span class="String">&quot;</span>Via Roma 42R<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>Bellagio, Italy 22021<span class="String">&quot;</span></span>]
}
};
_ref <span class="Keyword">=</span> futurists;
_ref2 <span class="Keyword">=</span> _ref.poet;
name <span class="Keyword">=</span> _ref2.<span class="LibraryConstant">name</span>;
_ref3 <span class="Keyword">=</span> _ref2.address;
street <span class="Keyword">=</span> _ref3[<span class="Number">0</span>];
city <span class="Keyword">=</span> _ref3[<span class="Number">1</span>];
</pre><button onclick='javascript: var _ref, _ref2, _ref3, city, futurists, name, street;
_ref <span class="Keyword">=</span> futurists.poet, name <span class="Keyword">=</span> _ref.<span class="LibraryConstant">name</span>, _ref2 <span class="Keyword">=</span> _ref.address, street <span class="Keyword">=</span> _ref2[<span class="Number">0</span>], city <span class="Keyword">=</span> _ref2[<span class="Number">1</span>];
</pre><button onclick='javascript: var _ref, _ref2, city, futurists, name, street;
futurists = {
sculptor: "Umberto Boccioni",
painter: "Vladimir Burliuk",
@ -1375,12 +1372,7 @@ 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];;alert(name + " — " + street);'>run: name + " — " + street</button><br class='clear' /></div>
_ref = futurists.poet, name = _ref.name, _ref2 = _ref.address, street = _ref2[0], city = _ref2[1];;alert(name + " — " + street);'>run: name + " — " + street</button><br class='clear' /></div>
<p>
Pattern matching can even be combined with splats.
</p>
@ -1394,17 +1386,11 @@ city = _ref3[1];;alert(name + " — " + street);'>run: name + " — " + street</
</pre><pre class="idle"><span class="Storage">var</span> _ref, close, contents, open, tag;
<span class="Storage">var</span> __slice <span class="Keyword">=</span> <span class="LibraryClassType">Array</span>.<span class="LibraryConstant">prototype</span>.slice;
tag <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>&lt;impossible&gt;<span class="String">&quot;</span></span>;
_ref <span class="Keyword">=</span> tag.<span class="LibraryFunction">split</span>(<span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span>);
open <span class="Keyword">=</span> _ref[<span class="Number">0</span>];
contents <span class="Keyword">=</span> __slice.<span class="LibraryFunction">call</span>(_ref, <span class="Number">1</span>, _ref.<span class="LibraryConstant">length</span> <span class="Keyword">-</span> <span class="Number">1</span>);
close <span class="Keyword">=</span> _ref[_ref.<span class="LibraryConstant">length</span> <span class="Keyword">-</span> <span class="Number">1</span>];
_ref <span class="Keyword">=</span> tag.<span class="LibraryFunction">split</span>(<span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span>), open <span class="Keyword">=</span> _ref[<span class="Number">0</span>], contents <span class="Keyword">=</span> __slice.<span class="LibraryFunction">call</span>(_ref, <span class="Number">1</span>, _ref.<span class="LibraryConstant">length</span> <span class="Keyword">-</span> <span class="Number">1</span>), close <span class="Keyword">=</span> _ref[_ref.<span class="LibraryConstant">length</span> <span class="Keyword">-</span> <span class="Number">1</span>];
</pre><button onclick='javascript: 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];;alert(contents.join(""));'>run: contents.join("")</button><br class='clear' /></div>
_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("")</button><br class='clear' /></div>
<p>
<span id="fat_arrow" class="bookmark"></span>
@ -1589,11 +1575,11 @@ dates <span class="Keyword">=</span><span class="String"> /\d+#{sep}\d+#{sep}\d+
</pre><pre class="idle"><span class="Storage">var</span> dates, sentence, sep;
sentence <span class="Keyword">=</span> (<span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">+</span> (<span class="Number">22</span> / <span class="Number">7</span>) <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> is a decent approximation of π<span class="String">&quot;</span></span>);
sep <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>[.<span class="UserDefinedConstant">\\</span>/<span class="UserDefinedConstant">\\</span>- ]<span class="String">&quot;</span></span>;
dates <span class="Keyword">=</span> (<span class="Keyword">new</span> <span class="TypeName">RegExp</span>(<span class="String"><span class="String">&quot;</span><span class="UserDefinedConstant">\\</span>d+<span class="String">&quot;</span></span> <span class="Keyword">+</span> (sep) <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span><span class="UserDefinedConstant">\\</span>d+<span class="String">&quot;</span></span> <span class="Keyword">+</span> (sep) <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span><span class="UserDefinedConstant">\\</span>d+<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>g<span class="String">&quot;</span></span>));
dates <span class="Keyword">=</span> (<span class="LibraryClassType">RegExp</span>(<span class="String"><span class="String">&quot;</span><span class="UserDefinedConstant">\\</span>d+<span class="String">&quot;</span></span> <span class="Keyword">+</span> (sep) <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span><span class="UserDefinedConstant">\\</span>d+<span class="String">&quot;</span></span> <span class="Keyword">+</span> (sep) <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span><span class="UserDefinedConstant">\\</span>d+<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>g<span class="String">&quot;</span></span>));
</pre><button onclick='javascript: var dates, sentence, sep;
sentence = ("" + (22 / 7) + " is a decent approximation of π");
sep = "[.\\/\\- ]";
dates = (new RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g"));;alert(sentence);'>run: sentence</button><br class='clear' /></div>
dates = (RegExp("\\d+" + (sep) + "\\d+" + (sep) + "\\d+", "g"));;alert(sentence);'>run: sentence</button><br class='clear' /></div>
<p>
<span id="heredocs" class="bookmark"></span>

View File

@ -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+$/, '');

View File

@ -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'];

View File

@ -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 = {

View File

@ -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();

View File

@ -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([]);

View File

@ -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