Permalink
...
Comparing changes
Open a pull request
- 3 commits
- 12 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
1,244 additions
and 1,163 deletions.
- +1 −1 coffee-script.gemspec
- +4 −0 documentation/coffee/arguments.coffee
- +22 −7 documentation/index.html.erb
- +7 −0 documentation/js/arguments.js
- +36 −7 index.html
- +1 −1 lib/coffee-script.rb
- +2 −0 lib/coffee_script/grammar.y
- +1 −0 lib/coffee_script/lexer.rb
- +6 −1 lib/coffee_script/nodes.rb
- +1,156 −1,145 lib/coffee_script/parser.rb
- +1 −1 package.json
- +7 −0 test/fixtures/execution/test_arguments.coffee
View
2
coffee-script.gemspec
| @@ -1,6 +1,6 @@ | ||
| Gem::Specification.new do |s| | ||
| s.name = 'coffee-script' | ||
| - s.version = '0.2.0' # Keep version in sync with coffee-script.rb | ||
| + s.version = '0.2.1' # Keep version in sync with coffee-script.rb | ||
| s.date = '2010-1-5' | ||
| s.homepage = "http://jashkenas.github.com/coffee-script/" | ||
View
4
documentation/coffee/arguments.coffee
| @@ -0,0 +1,4 @@ | ||
| +backwards: => | ||
| + alert(arguments.reverse()) | ||
| + | ||
| +backwards("stairway", "to", "heaven") |
View
29
documentation/index.html.erb
| @@ -66,7 +66,7 @@ | ||
| <p> | ||
| <b>Latest Version:</b> | ||
| - <a href="http://gemcutter.org/gems/coffee-script">0.2.0</a> | ||
| + <a href="http://gemcutter.org/gems/coffee-script">0.2.1</a> | ||
| </p> | ||
| <h2>Table of Contents</h2> | ||
| @@ -83,6 +83,7 @@ | ||
| <a href="#existence">The Existence Operator</a><br /> | ||
| <a href="#aliases">Aliases</a><br /> | ||
| <a href="#splats">Splats</a><br /> | ||
| + <a href="#arguments">Arguments are Arrays</a><br /> | ||
| <a href="#while">While Loops</a><br /> | ||
| <a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a><br /> | ||
| <a href="#slice_splice">Array Slicing and Splicing with Ranges</a><br /> | ||
| @@ -109,7 +110,7 @@ | ||
| <a href="documentation/underscore.html">Underscore.coffee</a>, a port | ||
| of <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> | ||
| to CoffeeScript, which, when compiled, can pass the complete Underscore test suite. | ||
| - Or, clone the source and take a look in the | ||
| + Or, clone the source and take a look in the | ||
| <a href="http://github.com/jashkenas/coffee-script/tree/master/examples/">examples</a> folder. | ||
| </p> | ||
| @@ -372,6 +373,15 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| </p> | ||
| <%= code_for('splats', true) %> | ||
| + <p id="arguments"> | ||
| + <b class="header">Arguments are Arrays</b> | ||
| + If you reference the <b>arguments object</b> directly, it will be converted | ||
| + into a real Array, making all of the | ||
| + <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array">Array methods</a> | ||
| + available. | ||
| + </p> | ||
| + <%= code_for('arguments', true) %> | ||
| + | ||
| <p id="while"> | ||
| <b class="header">While Loops</b> | ||
| The only low-level loop that CoffeeScript provides is the while loop. | ||
| @@ -472,8 +482,8 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <p id="blocks"> | ||
| <b class="header">Blocks</b> | ||
| Many common looping functions (in Prototype, jQuery, and Underscore, | ||
| - for example) take a single function as their final argument. To make | ||
| - final functions easier to pass, CoffeeScript includes block syntax, | ||
| + for example) take a single function as their final argument. To make | ||
| + final functions easier to pass, CoffeeScript includes block syntax, | ||
| so you don't have to close the parentheses on the other side. | ||
| </p> | ||
| <%= code_for('blocks') %> | ||
| @@ -524,7 +534,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| </li> | ||
| <li> | ||
| <a href="http://github.com/jnicklas/bistro_car">BistroCar</a><br /> | ||
| - A Rails plugin by | ||
| + A Rails plugin by | ||
| <a href="http://github.com/jnicklas">Jonas Nicklas</a> | ||
| that includes CoffeeScript helpers, | ||
| bundling and minification. | ||
| @@ -541,7 +551,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <ul> | ||
| <li> | ||
| A clean, safe syntax for manipulating the prototype chain, and performing | ||
| - inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but | ||
| + inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but | ||
| aren't a complete answer. | ||
| </li> | ||
| <li> | ||
| @@ -570,11 +580,16 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <h2 id="change_log">Change Log</h2> | ||
| <p> | ||
| + <b class="header" style="margin-top: 20px;">0.2.1</b> | ||
| + Arguments objects are now converted into real arrays when referenced. | ||
| + </p> | ||
| + | ||
| + <p> | ||
| <b class="header" style="margin-top: 20px;">0.2.0</b> | ||
| Major release. Significant whitespace. Better statement-to-expression | ||
| conversion. Splats. Splice literals. Object comprehensions. Blocks. | ||
| The existence operator. Many thanks to all the folks who posted issues, | ||
| - with special thanks to | ||
| + with special thanks to | ||
| <a href="http://github.com/kamatsu">Liam O'Connor-Davis</a> for whitespace | ||
| and expression help. | ||
| </p> | ||
View
7
documentation/js/arguments.js
| @@ -0,0 +1,7 @@ | ||
| +(function(){ | ||
| + var backwards; | ||
| + backwards = function backwards() { | ||
| + return alert(Array.prototype.slice.call(arguments, 0).reverse()); | ||
| + }; | ||
| + backwards("stairway", "to", "heaven"); | ||
| +})(); |
View
43
index.html
| @@ -39,7 +39,7 @@ | ||
| <p> | ||
| <b>Latest Version:</b> | ||
| - <a href="http://gemcutter.org/gems/coffee-script">0.2.0</a> | ||
| + <a href="http://gemcutter.org/gems/coffee-script">0.2.1</a> | ||
| </p> | ||
| <h2>Table of Contents</h2> | ||
| @@ -56,6 +56,7 @@ | ||
| <a href="#existence">The Existence Operator</a><br /> | ||
| <a href="#aliases">Aliases</a><br /> | ||
| <a href="#splats">Splats</a><br /> | ||
| + <a href="#arguments">Arguments are Arrays</a><br /> | ||
| <a href="#while">While Loops</a><br /> | ||
| <a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a><br /> | ||
| <a href="#slice_splice">Array Slicing and Splicing with Ranges</a><br /> | ||
| @@ -201,7 +202,7 @@ <h2 id="overview">Mini Overview</h2> | ||
| <a href="documentation/underscore.html">Underscore.coffee</a>, a port | ||
| of <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> | ||
| to CoffeeScript, which, when compiled, can pass the complete Underscore test suite. | ||
| - Or, clone the source and take a look in the | ||
| + Or, clone the source and take a look in the | ||
| <a href="http://github.com/jashkenas/coffee-script/tree/master/examples/">examples</a> folder. | ||
| </p> | ||
| @@ -633,6 +634,29 @@ <h2 id="installation">Installation and Usage</h2> | ||
| alert("The Field: " + the_field); | ||
| ;'>run</button><br class='clear' /></div> | ||
| + <p id="arguments"> | ||
| + <b class="header">Arguments are Arrays</b> | ||
| + If you reference the <b>arguments object</b> directly, it will be converted | ||
| + into a real Array, making all of the | ||
| + <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array">Array methods</a> | ||
| + available. | ||
| + </p> | ||
| + <div class='code'><pre class="idle"><span class="FunctionName">backwards</span><span class="Keyword">:</span> <span class="Storage">=></span> | ||
| + alert(arguments.reverse()) | ||
| + | ||
| +backwards(<span class="String"><span class="String">"</span>stairway<span class="String">"</span></span>, <span class="String"><span class="String">"</span>to<span class="String">"</span></span>, <span class="String"><span class="String">"</span>heaven<span class="String">"</span></span>) | ||
| +</pre><pre class="idle"><span class="Storage">var</span> backwards; | ||
| +backwards <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">backwards</span>() { | ||
| + <span class="Keyword">return</span> <span class="LibraryFunction">alert</span>(<span class="LibraryClassType">Array</span>.<span class="LibraryConstant">prototype</span>.slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">0</span>).<span class="LibraryFunction">reverse</span>()); | ||
| +}; | ||
| +backwards(<span class="String"><span class="String">"</span>stairway<span class="String">"</span></span>, <span class="String"><span class="String">"</span>to<span class="String">"</span></span>, <span class="String"><span class="String">"</span>heaven<span class="String">"</span></span>); | ||
| +</pre><button onclick='javascript: var backwards; | ||
| +backwards = function backwards() { | ||
| + return alert(Array.prototype.slice.call(arguments, 0).reverse()); | ||
| +}; | ||
| +backwards("stairway", "to", "heaven"); | ||
| +;'>run</button><br class='clear' /></div> | ||
| + | ||
| <p id="while"> | ||
| <b class="header">While Loops</b> | ||
| The only low-level loop that CoffeeScript provides is the while loop. | ||
| @@ -1030,8 +1054,8 @@ <h2 id="installation">Installation and Usage</h2> | ||
| <p id="blocks"> | ||
| <b class="header">Blocks</b> | ||
| Many common looping functions (in Prototype, jQuery, and Underscore, | ||
| - for example) take a single function as their final argument. To make | ||
| - final functions easier to pass, CoffeeScript includes block syntax, | ||
| + for example) take a single function as their final argument. To make | ||
| + final functions easier to pass, CoffeeScript includes block syntax, | ||
| so you don't have to close the parentheses on the other side. | ||
| </p> | ||
| <div class='code'><pre class="idle"><span class="Keyword">$</span>(<span class="String"><span class="String">'</span>table.list<span class="String">'</span></span>).each()<span class="FunctionArgument"> table </span><span class="Storage">=></span> | ||
| @@ -1165,7 +1189,7 @@ <h2 id="resources">Resources</h2> | ||
| </li> | ||
| <li> | ||
| <a href="http://github.com/jnicklas/bistro_car">BistroCar</a><br /> | ||
| - A Rails plugin by | ||
| + A Rails plugin by | ||
| <a href="http://github.com/jnicklas">Jonas Nicklas</a> | ||
| that includes CoffeeScript helpers, | ||
| bundling and minification. | ||
| @@ -1182,7 +1206,7 @@ <h2 id="contributing">Contributing</h2> | ||
| <ul> | ||
| <li> | ||
| A clean, safe syntax for manipulating the prototype chain, and performing | ||
| - inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but | ||
| + inheritance. <a href="#inheritance"><b>extends</b> and <b>super</b></a> are the start of this, but | ||
| aren't a complete answer. | ||
| </li> | ||
| <li> | ||
| @@ -1211,11 +1235,16 @@ <h2 id="contributing">Contributing</h2> | ||
| <h2 id="change_log">Change Log</h2> | ||
| <p> | ||
| + <b class="header" style="margin-top: 20px;">0.2.1</b> | ||
| + Arguments objects are now converted into real arrays when referenced. | ||
| + </p> | ||
| + | ||
| + <p> | ||
| <b class="header" style="margin-top: 20px;">0.2.0</b> | ||
| Major release. Significant whitespace. Better statement-to-expression | ||
| conversion. Splats. Splice literals. Object comprehensions. Blocks. | ||
| The existence operator. Many thanks to all the folks who posted issues, | ||
| - with special thanks to | ||
| + with special thanks to | ||
| <a href="http://github.com/kamatsu">Liam O'Connor-Davis</a> for whitespace | ||
| and expression help. | ||
| </p> | ||
View
2
lib/coffee-script.rb
| @@ -10,7 +10,7 @@ | ||
| # Namespace for all CoffeeScript internal classes. | ||
| module CoffeeScript | ||
| - VERSION = '0.2.0' # Keep in sync with the gemspec. | ||
| + VERSION = '0.2.1' # Keep in sync with the gemspec. | ||
| # Compile a script (String or IO) to JavaScript. | ||
| def self.compile(script, options={}) | ||
View
2
lib/coffee_script/grammar.y
| @@ -12,6 +12,7 @@ token FOR IN BY WHEN WHILE | ||
| token SWITCH LEADING_WHEN | ||
| token DELETE INSTANCEOF TYPEOF | ||
| token SUPER EXTENDS | ||
| +token ARGUMENTS | ||
| token NEWLINE | ||
| token COMMENT | ||
| token JS | ||
| @@ -97,6 +98,7 @@ rule | ||
| | REGEX { result = LiteralNode.new(val[0]) } | ||
| | BREAK { result = LiteralNode.new(val[0]) } | ||
| | CONTINUE { result = LiteralNode.new(val[0]) } | ||
| + | ARGUMENTS { result = LiteralNode.new(val[0]) } | ||
| | TRUE { result = LiteralNode.new(true) } | ||
| | FALSE { result = LiteralNode.new(false) } | ||
| | YES { result = LiteralNode.new(true) } | ||
View
1
lib/coffee_script/lexer.rb
| @@ -15,6 +15,7 @@ class Lexer | ||
| "for", "in", "by", "where", "while", | ||
| "switch", "when", | ||
| "super", "extends", | ||
| + "arguments", | ||
| "delete", "instanceof", "typeof"] | ||
| # Token matching regexes. | ||
View
7
lib/coffee_script/nodes.rb
| @@ -134,6 +134,10 @@ def compile_with_declarations(o={}) | ||
| class LiteralNode < Node | ||
| STATEMENTS = ['break', 'continue'] | ||
| + CONVERSIONS = { | ||
| + 'arguments' => 'Array.prototype.slice.call(arguments, 0)' | ||
| + } | ||
| + | ||
| attr_reader :value | ||
| def initialize(value) | ||
| @@ -146,9 +150,10 @@ def statement? | ||
| alias_method :statement_only?, :statement? | ||
| def compile_node(o) | ||
| + val = CONVERSIONS[@value.to_s] || @value.to_s | ||
| indent = statement? ? o[:indent] : '' | ||
| ending = statement? ? ';' : '' | ||
| - write(indent + @value.to_s + ending) | ||
| + write("#{indent}#{val}#{ending}") | ||
| end | ||
| end | ||
Oops, something went wrong.