mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merge branch 'master' of http://github.com/jashkenas/coffee-script into refactorTests
This commit is contained in:
commit
912d6f442a
13 changed files with 6295 additions and 36 deletions
|
@ -161,7 +161,7 @@
|
|||
</p>
|
||||
|
||||
<p>
|
||||
To install, first make sure you have a working copy of the latest tagged version of
|
||||
To install, first make sure you have a working copy of the latest stable version of
|
||||
<a href="http://nodejs.org/">Node.js</a>, and <a href="http://npmjs.org">NPM</a>
|
||||
(the Node Package Manager). You can then install CoffeeScript with NPM:
|
||||
</p>
|
||||
|
@ -1539,7 +1539,7 @@ coffee --bare --print --stdio</pre>
|
|||
|
||||
</script>
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
|
||||
<script src="documentation/vendor/jquery-1.4.2.js"></script>
|
||||
<script src="extras/coffee-script.js"></script>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var globals, name, _results;
|
||||
var globals, name;
|
||||
globals = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (name in window) {
|
||||
_results.push(name);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
var age, ages, child, yearsOld, _results;
|
||||
var age, ages, child, yearsOld;
|
||||
yearsOld = {
|
||||
max: 10,
|
||||
ida: 9,
|
||||
tim: 11
|
||||
};
|
||||
ages = function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var cubes, list, math, num, number, opposite, race, square, _i, _len, _results;
|
||||
var cubes, list, math, num, number, opposite, race, square;
|
||||
var __slice = Array.prototype.slice;
|
||||
number = 42;
|
||||
opposite = true;
|
||||
|
@ -25,6 +25,7 @@ if (typeof elvis != "undefined" && elvis !== null) {
|
|||
alert("I knew it!");
|
||||
}
|
||||
cubes = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
num = list[_i];
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var countdown, num, _results;
|
||||
var countdown, num;
|
||||
countdown = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (num = 10; num >= 1; num--) {
|
||||
_results.push(num);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var lyrics, num, _results;
|
||||
var lyrics, num;
|
||||
if (this.studyingEconomics) {
|
||||
while (supply > demand) {
|
||||
buy();
|
||||
|
@ -9,6 +9,7 @@ if (this.studyingEconomics) {
|
|||
}
|
||||
num = 6;
|
||||
lyrics = function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
while (num -= 1) {
|
||||
_results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
|
|
6240
documentation/vendor/jquery-1.4.2.js
vendored
Normal file
6240
documentation/vendor/jquery-1.4.2.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
32
index.html
32
index.html
|
@ -153,7 +153,7 @@ alert <span class="String"><span class="String">"</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> cubes, list, math, num, number, opposite, race, square, _i, _len, _results;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> 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>;
|
||||
|
@ -180,6 +180,7 @@ math <span class="Keyword">=</span> {
|
|||
<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">"</span>I knew it!<span class="String">"</span></span>);
|
||||
}
|
||||
cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _i, _len, _results;
|
||||
_results <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"><</span> _len; _i<span class="Keyword">++</span>) {
|
||||
num <span class="Keyword">=</span> list[_i];
|
||||
|
@ -187,7 +188,7 @@ cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
|||
}
|
||||
<span class="Keyword">return</span> _results;
|
||||
}());
|
||||
</pre><script>window.example1 = "# Assignment:\nnumber = 42\nopposite = true\n\n# Conditions:\nnumber = -42 if opposite\n\n# Functions:\nsquare = (x) -> x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example1);'>Load</div><div class='minibutton ok' onclick='javascript: var cubes, list, math, num, number, opposite, race, square, _i, _len, _results;
|
||||
</pre><script>window.example1 = "# Assignment:\nnumber = 42\nopposite = true\n\n# Conditions:\nnumber = -42 if opposite\n\n# Functions:\nsquare = (x) -> x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example1);'>Load</div><div class='minibutton ok' onclick='javascript: var cubes, list, math, num, number, opposite, race, square;
|
||||
var __slice = Array.prototype.slice;
|
||||
number = 42;
|
||||
opposite = true;
|
||||
|
@ -214,6 +215,7 @@ if (typeof elvis != "undefined" && elvis !== null) {
|
|||
alert("I knew it!");
|
||||
}
|
||||
cubes = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
num = list[_i];
|
||||
|
@ -813,7 +815,7 @@ num <span class="Keyword">=</span> <span class="Number">6</span>
|
|||
lyrics <span class="Keyword">=</span> <span class="Keyword">while</span> num <span class="Keyword">-</span><span class="Keyword">=</span> <span class="Number">1</span>
|
||||
num <span class="Keyword">+</span> <span class="String"><span class="String">"</span> little monkeys, jumping on the bed.</span>
|
||||
<span class="String"> One fell out and bumped his head.<span class="String">"</span></span>
|
||||
</pre><pre class="idle"><span class="Storage">var</span> lyrics, num, _results;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> lyrics, num;
|
||||
<span class="Keyword">if</span> (<span class="Variable">this</span>.studyingEconomics) {
|
||||
<span class="Keyword">while</span> (supply <span class="Keyword">></span> demand) {
|
||||
buy();
|
||||
|
@ -824,13 +826,14 @@ lyrics <span class="Keyword">=</span> <span class="Keyword">while</span> num <sp
|
|||
}
|
||||
num <span class="Keyword">=</span> <span class="Number">6</span>;
|
||||
<span class="FunctionName">lyrics</span> = <span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _results;
|
||||
_results <span class="Keyword">=</span> [];
|
||||
<span class="Keyword">while</span> (num <span class="Keyword">-</span><span class="Keyword">=</span> <span class="Number">1</span>) {
|
||||
_results.<span class="LibraryFunction">push</span>(num <span class="Keyword">+</span> <span class="String"><span class="String">"</span> little monkeys, jumping on the bed. One fell out and bumped his head.<span class="String">"</span></span>);
|
||||
}
|
||||
<span class="Keyword">return</span> _results;
|
||||
}();
|
||||
</pre><script>window.example10 = "# Econ 101\nif this.studyingEconomics\n buy() while supply > demand\n sell() until supply > demand\n\n# Nursery Rhyme\nnum = 6\nlyrics = while num -= 1\n num + \" little monkeys, jumping on the bed.\n One fell out and bumped his head.\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example10);'>Load</div><div class='minibutton ok' onclick='javascript: var lyrics, num, _results;
|
||||
</pre><script>window.example10 = "# Econ 101\nif this.studyingEconomics\n buy() while supply > demand\n sell() until supply > demand\n\n# Nursery Rhyme\nnum = 6\nlyrics = while num -= 1\n num + \" little monkeys, jumping on the bed.\n One fell out and bumped his head.\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example10);'>Load</div><div class='minibutton ok' onclick='javascript: var lyrics, num;
|
||||
if (this.studyingEconomics) {
|
||||
while (supply > demand) {
|
||||
buy();
|
||||
|
@ -841,6 +844,7 @@ if (this.studyingEconomics) {
|
|||
}
|
||||
num = 6;
|
||||
lyrics = function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
while (num -= 1) {
|
||||
_results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
|
@ -882,16 +886,18 @@ _ref <span class="Keyword">=</span> [<span class="String"><span class="String">'
|
|||
</p>
|
||||
<div class='code'><pre class="idle">countdown <span class="Keyword">=</span> (num <span class="Keyword">for</span> num <span class="Keyword">in</span> [<span class="Number">10</span>..<span class="Number">1</span>])
|
||||
|
||||
</pre><pre class="idle"><span class="Storage">var</span> countdown, num, _results;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> countdown, num;
|
||||
countdown <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _results;
|
||||
_results <span class="Keyword">=</span> [];
|
||||
<span class="Keyword">for</span> (num <span class="Keyword">=</span> <span class="Number">10</span>; num <span class="Keyword">>=</span> <span class="Number">1</span>; num<span class="Keyword">--</span>) {
|
||||
_results.<span class="LibraryFunction">push</span>(num);
|
||||
}
|
||||
<span class="Keyword">return</span> _results;
|
||||
}());
|
||||
</pre><script>window.example12 = "countdown = (num for num in [10..1])\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example12);'>Load</div><div class='minibutton ok' onclick='javascript: var countdown, num, _results;
|
||||
</pre><script>window.example12 = "countdown = (num for num in [10..1])\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example12);'>Load</div><div class='minibutton ok' onclick='javascript: var countdown, num;
|
||||
countdown = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (num = 10; num >= 1; num--) {
|
||||
_results.push(num);
|
||||
|
@ -916,13 +922,14 @@ countdown = (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">"</span> is <span class="String">"</span></span> <span class="Keyword">+</span> age
|
||||
</pre><pre class="idle"><span class="Storage">var</span> age, ages, child, yearsOld, _results;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> age, ages, child, yearsOld;
|
||||
yearsOld <span class="Keyword">=</span> {
|
||||
max: <span class="Number">10</span>,
|
||||
ida: <span class="Number">9</span>,
|
||||
tim: <span class="Number">11</span>
|
||||
};
|
||||
<span class="FunctionName">ages</span> = <span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _results;
|
||||
_results <span class="Keyword">=</span> [];
|
||||
<span class="Keyword">for</span> (child <span class="Keyword">in</span> yearsOld) {
|
||||
age <span class="Keyword">=</span> yearsOld[child];
|
||||
|
@ -930,13 +937,14 @@ yearsOld <span class="Keyword">=</span> {
|
|||
}
|
||||
<span class="Keyword">return</span> _results;
|
||||
}();
|
||||
</pre><script>window.example13 = "yearsOld = max: 10, ida: 9, tim: 11\n\nages = for child, age of yearsOld\n child + \" is \" + age"</script><div class='minibutton load' onclick='javascript: loadConsole(example13);'>Load</div><div class='minibutton ok' onclick='javascript: var age, ages, child, yearsOld, _results;
|
||||
</pre><script>window.example13 = "yearsOld = max: 10, ida: 9, tim: 11\n\nages = for child, age of yearsOld\n child + \" is \" + age"</script><div class='minibutton load' onclick='javascript: loadConsole(example13);'>Load</div><div class='minibutton ok' onclick='javascript: var age, ages, child, yearsOld;
|
||||
yearsOld = {
|
||||
max: 10,
|
||||
ida: 9,
|
||||
tim: 11
|
||||
};
|
||||
ages = function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
|
@ -1065,16 +1073,18 @@ six = (one = 1) + (two = 2) + (three = 3);;alert(six);'>run: six</div><br class=
|
|||
<div class='code'><pre class="idle"><span class="Comment"><span class="Comment">#</span> The first ten global properties.</span>
|
||||
|
||||
globals <span class="Keyword">=</span> (name <span class="Keyword">for</span> name <span class="Keyword">of</span> window)[<span class="Number">0</span>...<span class="Number">10</span>]
|
||||
</pre><pre class="idle"><span class="Storage">var</span> globals, name, _results;
|
||||
</pre><pre class="idle"><span class="Storage">var</span> globals, name;
|
||||
globals <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _results;
|
||||
_results <span class="Keyword">=</span> [];
|
||||
<span class="Keyword">for</span> (name <span class="Keyword">in</span> <span class="LibraryClassType">window</span>) {
|
||||
_results.<span class="LibraryFunction">push</span>(name);
|
||||
}
|
||||
<span class="Keyword">return</span> _results;
|
||||
}()).<span class="LibraryFunction">slice</span>(<span class="Number">0</span>, <span class="Number">10</span>);
|
||||
</pre><script>window.example18 = "# The first ten global properties.\n\nglobals = (name for name of window)[0...10]"</script><div class='minibutton load' onclick='javascript: loadConsole(example18);'>Load</div><div class='minibutton ok' onclick='javascript: var globals, name, _results;
|
||||
</pre><script>window.example18 = "# The first ten global properties.\n\nglobals = (name for name of window)[0...10]"</script><div class='minibutton load' onclick='javascript: loadConsole(example18);'>Load</div><div class='minibutton ok' onclick='javascript: var globals, name;
|
||||
globals = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (name in window) {
|
||||
_results.push(name);
|
||||
|
@ -2425,7 +2435,7 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
|
|||
|
||||
</script>
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
|
||||
<script src="documentation/vendor/jquery-1.4.2.js"></script>
|
||||
<script src="extras/coffee-script.js"></script>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -458,7 +458,6 @@
|
|||
case '\\':
|
||||
i++;
|
||||
continue;
|
||||
break;
|
||||
case stack[stack.length - 1][1]:
|
||||
stack.pop();
|
||||
if (!stack.length) {
|
||||
|
@ -604,7 +603,7 @@
|
|||
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;
|
||||
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
|
||||
WHITESPACE = /^[^\n\S]+/;
|
||||
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
|
||||
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
|
||||
CODE = /^[-=]>/;
|
||||
MULTI_DENT = /^(?:\n[^\n\S]*)+/;
|
||||
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
|
||||
|
|
16
lib/nodes.js
16
lib/nodes.js
|
@ -91,7 +91,7 @@
|
|||
};
|
||||
Base.prototype.containsPureStatement = function() {
|
||||
return this.isPureStatement() || this.contains(function(node) {
|
||||
return node.isPureStatement();
|
||||
return node.isPureStatement() && !(node instanceof Comment);
|
||||
});
|
||||
};
|
||||
Base.prototype.toString = function(idt, name) {
|
||||
|
@ -1915,7 +1915,7 @@
|
|||
return this;
|
||||
};
|
||||
Switch.prototype.compileNode = function(o) {
|
||||
var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4, _ref5;
|
||||
var block, body, code, cond, conditions, exprs, i, idt1, idt2, _i, _len, _len2, _ref, _ref2, _ref3, _ref4;
|
||||
idt1 = o.indent + TAB;
|
||||
idt2 = o.indent = idt1 + TAB;
|
||||
code = this.tab + ("switch (" + (((_ref = this.subject) != null ? _ref.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
|
||||
|
@ -1936,15 +1936,9 @@
|
|||
if (i === this.cases.length - 1 && !this.otherwise) {
|
||||
break;
|
||||
}
|
||||
_ref5 = block.expressions;
|
||||
for (_j = 0, _len3 = _ref5.length; _j < _len3; _j += -1) {
|
||||
expr = _ref5[_j];
|
||||
if (!(expr instanceof Comment)) {
|
||||
if (!(expr instanceof Return)) {
|
||||
code += idt2 + 'break;\n';
|
||||
}
|
||||
break;
|
||||
}
|
||||
exprs = block.expressions;
|
||||
if (!exprs.length || !last(exprs).isPureStatement()) {
|
||||
code += idt2 + 'break;\n';
|
||||
}
|
||||
}
|
||||
if (this.otherwise) {
|
||||
|
|
|
@ -550,7 +550,7 @@ OPERATOR = /// ^ (
|
|||
|
||||
WHITESPACE = /^[^\n\S]+/
|
||||
|
||||
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/
|
||||
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/
|
||||
|
||||
CODE = /^[-=]>/
|
||||
|
||||
|
|
|
@ -97,7 +97,8 @@ exports.Base = class Base
|
|||
# Convenience for the most common use of contains. Does the node contain
|
||||
# a pure statement?
|
||||
containsPureStatement: ->
|
||||
@isPureStatement() or @contains (node) -> node.isPureStatement()
|
||||
@isPureStatement() or @contains (node) ->
|
||||
node.isPureStatement() and node not instanceof Comment
|
||||
|
||||
# `toString` representation of the node, for inspecting the parse tree.
|
||||
# This is what `coffee --nodes` prints out.
|
||||
|
@ -1523,9 +1524,9 @@ exports.Switch = class Switch extends Base
|
|||
code += idt1 + "case #{ cond.compile o, LEVEL_PAREN }:\n"
|
||||
code += body + '\n' if body = block.compile o, LEVEL_TOP
|
||||
break if i is @cases.length - 1 and not @otherwise
|
||||
for expr in block.expressions by -1 when expr not instanceof Comment
|
||||
code += idt2 + 'break;\n' unless expr instanceof Return
|
||||
break
|
||||
exprs = block.expressions
|
||||
if not exprs.length or not last(exprs).isPureStatement()
|
||||
code += idt2 + 'break;\n'
|
||||
code += idt1 + "default:\n#{ @otherwise.compile o, LEVEL_TOP }\n" if @otherwise
|
||||
code + @tab + '}'
|
||||
|
||||
|
|
|
@ -199,3 +199,13 @@ test "block comments inside class bodies", ->
|
|||
b: ->
|
||||
|
||||
ok B.prototype.a instanceof Function
|
||||
|
||||
test "#934, block comments inside conditional bodies", ->
|
||||
|
||||
eq undefined, (if true
|
||||
###
|
||||
block comment
|
||||
###
|
||||
else
|
||||
# comment
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue