Permalink
...
Comparing changes
Open a pull request
- 17 commits
- 60 files changed
- 0 commit comments
- 1 contributor
Commits on Dec 26, 2009
Commits on Dec 27, 2009
|
|
jashkenas |
903331f
|
|||
|
|
jashkenas |
78589f5
|
|||
|
|
jashkenas |
ff0062b
|
Unified
Split
Showing
with
1,415 additions
and 1,156 deletions.
- +1 −1 README
- +2 −2 Rakefile
- 0 bin/{coffee-script → coffee}
- +3 −3 coffee-script.gemspec
- +1 −1 documentation/coffee/array_comprehensions.coffee
- +1 −0 documentation/coffee/embedded.coffee
- +1 −0 documentation/coffee/expressions_assignment.coffee
- +6 −2 documentation/coffee/slices.coffee
- +1 −0 documentation/coffee/strings.coffee
- +2 −0 documentation/css/docs.css
- +56 −21 documentation/index.html.erb
- +1 −1 documentation/js/aliases.js
- +10 −11 documentation/js/array_comprehensions.js
- +3 −2 documentation/js/assignment.js
- +2 −2 documentation/js/conditionals.js
- +2 −1 documentation/js/embedded.js
- +3 −2 documentation/js/expressions.js
- +4 −0 documentation/js/expressions_assignment.js
- +3 −2 documentation/js/functions.js
- +3 −2 documentation/js/objects_and_arrays.js
- +10 −11 documentation/js/overview.js
- +6 −4 documentation/js/scope.js
- +4 −2 documentation/js/slices.js
- +2 −1 documentation/js/strings.js
- +6 −5 documentation/js/super.js
- +1 −1 examples/code.coffee
- +1 −1 examples/poignant.coffee
- +169 −104 index.html
- +1 −1 lib/coffee-script.rb
- +1 −1 lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
- +11 −9 lib/coffee_script/command_line.rb
- +16 −14 lib/coffee_script/grammar.y
- +5 −3 lib/coffee_script/lexer.rb
- +4 −4 lib/coffee_script/narwhal/coffee-script.coffee
- +18 −14 lib/coffee_script/narwhal/js/coffee-script.js
- +4 −4 lib/coffee_script/narwhal/js/loader.js
- +86 −40 lib/coffee_script/nodes.rb
- +2 −2 lib/coffee_script/parse_error.rb
- +859 −838 lib/coffee_script/parser.rb
- +18 −3 lib/coffee_script/scope.rb
- +1 −1 package.json
- 0 test/fixtures/execution/{array_comprehension.coffee → test_array_comprehension.coffee}
- 0 test/fixtures/execution/{assign_to_try_catch.coffee → test_assign_to_try_catch.coffee}
- 0 test/fixtures/execution/{calling_super.coffee → test_calling_super.coffee}
- 0 test/fixtures/execution/{chained_calls.coffee → test_chained_calls.coffee}
- +1 −1 test/fixtures/execution/test_everything.coffee
- 0 test/fixtures/execution/{fancy_if_statement.coffee → test_fancy_if_statement.coffee}
- +3 −0 test/fixtures/execution/test_lexical_scope.coffee
- +6 −0 test/fixtures/execution/test_newline_escaping.coffee
- +8 −0 test/fixtures/execution/test_range_comprehension.coffee
- +8 −0 test/fixtures/execution/test_ranges_and_slices.coffee
- 0 test/fixtures/{ → generation}/each.coffee
- +11 −10 test/fixtures/{ → generation}/each.js
- 0 test/fixtures/{ → generation}/each.tokens
- +11 −10 test/fixtures/{ → generation}/each_no_wrap.js
- 0 test/fixtures/{ → generation}/inner_comments.coffee
- +3 −2 test/fixtures/{ → generation}/inner_comments.js
- +9 −4 test/unit/test_execution.rb
- +10 −4 test/unit/test_lexer.rb
- +15 −9 test/unit/test_parser.rb
View
2
README
| @@ -26,7 +26,7 @@ | ||
| gem install coffee-script | ||
| Compile a script: | ||
| - coffee-script /path/to/script.coffee | ||
| + coffee /path/to/script.coffee | ||
| For documentation, usage, and examples, see: | ||
| http://jashkenas.github.com/coffee-script/ | ||
View
4
Rakefile
| @@ -19,15 +19,15 @@ namespace :build do | ||
| desc "Compile the Narwhal interface for --interactive and --run" | ||
| task :narwhal do | ||
| - sh "bin/coffee-script lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/js" | ||
| + sh "bin/coffee lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/js" | ||
| end | ||
| end | ||
| desc "Build the documentation page" | ||
| task :doc do | ||
| source = 'documentation/index.html.erb' | ||
| - child = fork { exec "bin/coffee-script documentation/coffee/*.coffee -o documentation/js -w" } | ||
| + child = fork { exec "bin/coffee documentation/coffee/*.coffee -o documentation/js -w" } | ||
| at_exit { Process.kill("INT", child) } | ||
| Signal.trap("INT") { exit } | ||
| loop do | ||
View
0
bin/coffee-script → bin/coffee
File renamed without changes.
View
6
coffee-script.gemspec
| @@ -1,7 +1,7 @@ | ||
| Gem::Specification.new do |s| | ||
| s.name = 'coffee-script' | ||
| - s.version = '0.1.4' # Keep version in sync with coffee-script.rb | ||
| - s.date = '2009-12-25' | ||
| + s.version = '0.1.5' # Keep version in sync with coffee-script.rb | ||
| + s.date = '2009-12-26' | ||
| s.homepage = "http://jashkenas.github.com/coffee-script/" | ||
| s.summary = "The CoffeeScript Compiler" | ||
| @@ -20,7 +20,7 @@ Gem::Specification.new do |s| | ||
| s.has_rdoc = false | ||
| s.require_paths = ['lib'] | ||
| - s.executables = ['coffee-script'] | ||
| + s.executables = ['coffee'] | ||
| s.files = Dir['bin/*', 'examples/*', 'lib/**/*', 'coffee-script.gemspec', 'LICENSE', 'README'] | ||
| end | ||
View
2
documentation/coffee/array_comprehensions.coffee
| @@ -2,4 +2,4 @@ | ||
| lunch: food.eat() for food in ['toast', 'cheese', 'wine']. | ||
| # Zebra-stripe a table. | ||
| -highlight(row) for row, i in table if i % 2 is 0. | ||
| +highlight(row) for row, i in table if i % 2 is 0. | ||
View
1
documentation/coffee/embedded.coffee
| @@ -2,3 +2,4 @@ hi: `function() { | ||
| return [document.title, "Hello JavaScript"].join(": "); | ||
| }` | ||
| + | ||
View
1
documentation/coffee/expressions_assignment.coffee
| @@ -0,0 +1 @@ | ||
| +six: (one: 1) + (two: 2) + (three: 3) |
View
8
documentation/coffee/slices.coffee
| @@ -1,2 +1,6 @@ | ||
| -nums: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
| -three_to_six: nums[3, 6] | ||
| +numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
| + | ||
| +three_to_six: numbers[3..6] | ||
| + | ||
| +numbers_copy: numbers[0...numbers.length] | ||
| + |
View
1
documentation/coffee/strings.coffee
| @@ -5,3 +5,4 @@ to interest me on shore, I thought I would sail | ||
| about a little and see the watery part of the | ||
| world..." | ||
| + | ||
View
2
documentation/css/docs.css
| @@ -48,6 +48,8 @@ code, pre, tt { | ||
| font-size: 12px; | ||
| line-height: 18px; | ||
| color: #191955; | ||
| + white-space: pre-wrap; | ||
| + word-wrap: break-word; | ||
| } | ||
| tt { | ||
| background: #f8f8ff; | ||
View
77
documentation/index.html.erb
| @@ -64,16 +64,17 @@ | ||
| <a href="#aliases">Aliases</a><br /> | ||
| <a href="#while">While Loops</a><br /> | ||
| <a href="#array_comprehensions">Array Comprehensions</a><br /> | ||
| - <a href="#slice">Array Slice Literals</a><br /> | ||
| + <a href="#slice">Slicing Arrays with Ranges</a><br /> | ||
| <a href="#inheritance">Inheritance, and Calling Super from a Subclass</a><br /> | ||
| <a href="#embedded">Embedded JavaScript</a><br /> | ||
| <a href="#switch">Switch/When/Else</a><br /> | ||
| <a href="#try">Try/Catch/Finally</a><br /> | ||
| <a href="#strings">Multiline Strings</a><br /> | ||
| + <a href="#resources">Resources</a><br /> | ||
| <a href="#contributing">Contributing</a><br /> | ||
| <a href="#change_log">Change Log</a><br /> | ||
| </p> | ||
| - | ||
| + | ||
| <h2 id="overview">Mini Overview</h2> | ||
| <p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p> | ||
| @@ -91,12 +92,12 @@ | ||
| gem install coffee-script</pre> | ||
| <p> | ||
| - Installing the gem provides the <tt>coffee-script</tt> command, which can | ||
| + Installing the gem provides the <tt>coffee</tt> command, which can | ||
| be used to compile CoffeeScript <tt>.coffee</tt> files into JavaScript, as | ||
| well as debug them. In conjunction with | ||
| - <a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee-script</tt> | ||
| + <a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee</tt> | ||
| command also provides direct evaluation and an interactive REPL. | ||
| - When compiling to JavaScript, <tt>coffee-script</tt> writes the output | ||
| + When compiling to JavaScript, <tt>coffee</tt> writes the output | ||
| as <tt>.js</tt> files in the same directory by default, but output | ||
| can be customized with the following options: | ||
| </p> | ||
| @@ -148,7 +149,7 @@ gem install coffee-script</pre> | ||
| <td><code>-e, --eval</code></td> | ||
| <td> | ||
| Compile and print a little snippet of CoffeeScript directly from the | ||
| - command line (or from <b>stdin</b>). For example:<br /><tt>coffee-script -e "square: x => x * x."</tt> | ||
| + command line (or from <b>stdin</b>). For example:<br /><tt>coffee -e "square: x => x * x."</tt> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| @@ -187,10 +188,10 @@ gem install coffee-script</pre> | ||
| </p> | ||
| <pre> | ||
| -coffee-script path/to/script.coffee | ||
| -coffee-script --interactive | ||
| -coffee-script --watch --lint experimental.coffee | ||
| -coffee-script --print app/scripts/*.coffee > concatenation.js</pre> | ||
| +coffee path/to/script.coffee | ||
| +coffee --interactive | ||
| +coffee --watch --lint experimental.coffee | ||
| +coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <h2>Language Reference</h2> | ||
| @@ -230,6 +231,10 @@ coffee-script --print app/scripts/*.coffee > concatenation.js</pre> | ||
| mathy things. | ||
| </p> | ||
| <%= code_for('assignment', 'greeting') %> | ||
| + <p> | ||
| + Declarations of new variables are pushed up to the top of the current scope, | ||
| + so that assignments may always be used within expressions. | ||
| + </p> | ||
| <p id="objects_and_arrays"> | ||
| <b class="header">Objects and Arrays</b> | ||
| @@ -293,7 +298,12 @@ coffee-script --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <p> | ||
| The same mechanism is used to push down assignment through <b>switch</b> | ||
| statements, and <b>if-elses</b> (although the ternary operator is preferred). | ||
| + Another part of manipulating assignment statements is | ||
| + CoffeeScript's declaration of new variables at the top of the | ||
| + current scope. This allows assignment to be used as a piece of an | ||
| + expression. | ||
| </p> | ||
| + <%= code_for('expressions_assignment', 'six') %> | ||
| <p id="aliases"> | ||
| <b class="header">Aliases</b> | ||
| @@ -347,14 +357,22 @@ coffee-script --print app/scripts/*.coffee > concatenation.js</pre> | ||
| would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>. | ||
| </p> | ||
| <%= code_for('array_comprehensions') %> | ||
| + <p> | ||
| + If you're not iterating over an actual array, you can use a range to | ||
| + specify the start and end of an array comprehension: | ||
| + <tt>coundown(i) for i in [10..1].</tt> | ||
| + </p> | ||
| <p id="slice"> | ||
| - <b class="header">Array Slice Literals</b> | ||
| - CoffeeScript includes syntax for extracting slices of arrays. | ||
| - The first argument is the index of the first element in the slice, and | ||
| - the second is the index of the last one. | ||
| + <b class="header">Slicing Arrays with Ranges</b> | ||
| + CoffeeScript borrows Ruby's | ||
| + <a href="http://ruby-doc.org/core/classes/Range.html">range syntax</a> | ||
| + for extracting slices of arrays. With two dots (<tt>3..5</tt>), the range | ||
| + is inclusive: the first argument is the index of the first element in | ||
| + the slice, and the second is the index of the last one. Three dots signify | ||
| + a range that excludes the end. | ||
| </p> | ||
| - <%= code_for('slices', 'three_to_six') %> | ||
| + <%= code_for('slices', 'numbers_copy') %> | ||
| <p id="inheritance"> | ||
| <b class="header">Inheritance, and Calling Super from a Subclass</b> | ||
| @@ -406,6 +424,13 @@ coffee-script --print app/scripts/*.coffee > concatenation.js</pre> | ||
| Multiline strings are allowed in CoffeeScript. | ||
| </p> | ||
| <%= code_for('strings', 'moby_dick') %> | ||
| + | ||
| + <h2 id="resources">Resources</h2> | ||
| + | ||
| + <p> | ||
| + <a href="http://github.com/jashkenas/coffee-script/">Source Code</a><br /> | ||
| + <a href="http://github.com/jashkenas/coffee-script/issues">Bugs and Feature Requests</a><br /> | ||
| + </p> | ||
| <h2 id="contributing">Contributing</h2> | ||
| @@ -421,7 +446,8 @@ coffee-script --print app/scripts/*.coffee > concatenation.js</pre> | ||
| </li> | ||
| <li> | ||
| Ideas for alternate syntax to end blocks of expressions — the periods | ||
| - can look a little weird with deeply nested structure. | ||
| + can look a little weird with deeply nested structure. (There's now a | ||
| + 'whitespace' branch — help add significant whitespace over there.) | ||
| </li> | ||
| <li> | ||
| Test cases for any syntax errors you encounter that you think CoffeeScript | ||
| @@ -445,20 +471,29 @@ coffee-script --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <h2 id="change_log">Change Log</h2> | ||
| <p> | ||
| + <b class="header" style="margin-top: 20px;">0.1.5</b> | ||
| + Array slice literals and array comprehensions can now both take Ruby-style | ||
| + ranges to specify the start and end. JavaScript variable declaration is | ||
| + now pushed up to the top of the scope, making all assignment statements into | ||
| + expressions. You can use <tt>\</tt> to escape newlines. | ||
| + The <tt>coffee-script</tt> command is now called <tt>coffee</tt>. | ||
| + </p> | ||
| + | ||
| + <p> | ||
| <b class="header" style="margin-top: 20px;">0.1.4</b> | ||
| The official CoffeeScript extension is now <tt>.coffee</tt> instead of | ||
| - <tt>.cs</tt>, which properly belongs to | ||
| + <tt>.cs</tt>, which properly belongs to | ||
| <a href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)">C#</a>. | ||
| Due to popular demand, you can now also use <tt>=</tt> to assign. Unlike | ||
| JavaScript, <tt>=</tt> can also be used within object literals, interchangeably | ||
| - with <tt>:</tt>. Made a grammatical fix for chained function calls | ||
| - like <tt>func(1)(2)(3)(4)</tt>. Inheritance and super no longer use | ||
| - <tt>__proto__</tt>, so they should be IE-compatible now. | ||
| + with <tt>:</tt>. Made a grammatical fix for chained function calls | ||
| + like <tt>func(1)(2)(3)(4)</tt>. Inheritance and super no longer use | ||
| + <tt>__proto__</tt>, so they should be IE-compatible now. | ||
| </p> | ||
| <p> | ||
| <b class="header" style="margin-top: 20px;">0.1.3</b> | ||
| - The <tt>coffee-script</tt> command now includes <tt>--interactive</tt>, | ||
| + The <tt>coffee</tt> command now includes <tt>--interactive</tt>, | ||
| which launches an interactive CoffeeScript session, and <tt>--run</tt>, | ||
| which directly compiles and executes a script. Both options depend on a | ||
| working installation of Narwhal. | ||
View
2
documentation/js/aliases.js
| @@ -1,8 +1,8 @@ | ||
| (function(){ | ||
| + var volume; | ||
| if (ignition === true) { | ||
| launch(); | ||
| } | ||
| - var volume; | ||
| if (band !== spinal_tap) { | ||
| volume = 10; | ||
| } | ||
View
21
documentation/js/array_comprehensions.js
| @@ -1,20 +1,19 @@ | ||
| (function(){ | ||
| - | ||
| + var __a, __b, __c, __d, __e, __f, __g, __h, food, i, lunch, row; | ||
| // Eat lunch. | ||
| - var lunch; | ||
| - var __a = ['toast', 'cheese', 'wine']; | ||
| - var __d = []; | ||
| - for (var __b=0, __c=__a.length; __b<__c; __b++) { | ||
| - var food = __a[__b]; | ||
| + __a = ['toast', 'cheese', 'wine']; | ||
| + __d = []; | ||
| + for (__b=0, __c=__a.length; __b<__c; __b++) { | ||
| + food = __a[__b]; | ||
| __d[__b] = food.eat(); | ||
| } | ||
| lunch = __d; | ||
| // Zebra-stripe a table. | ||
| - var __e = table; | ||
| - var __h = []; | ||
| - for (var __f=0, __g=__e.length; __f<__g; __f++) { | ||
| - var row = __e[__f]; | ||
| - var i = __f; | ||
| + __e = table; | ||
| + __h = []; | ||
| + for (__f=0, __g=__e.length; __f<__g; __f++) { | ||
| + row = __e[__f]; | ||
| + i = __f; | ||
| __h[__f] = i % 2 === 0 ? highlight(row) : null; | ||
| } | ||
| __h; | ||
View
5
documentation/js/assignment.js
| @@ -1,4 +1,5 @@ | ||
| (function(){ | ||
| - var greeting = "Hello CoffeeScript"; | ||
| - var difficulty = 0.5; | ||
| + var difficulty, greeting; | ||
| + greeting = "Hello CoffeeScript"; | ||
| + difficulty = 0.5; | ||
| })(); |
View
4
documentation/js/conditionals.js
| @@ -1,12 +1,12 @@ | ||
| (function(){ | ||
| - var mood; | ||
| + var date, mood; | ||
| if (singing) { | ||
| mood = greatly_improved; | ||
| } | ||
| if (happy && knows_it) { | ||
| claps_hands(); | ||
| cha_cha_cha(); | ||
| } | ||
| - var date = friday ? sue : jill; | ||
| + date = friday ? sue : jill; | ||
| expensive = expensive || do_the_math(); | ||
| })(); |
View
3
documentation/js/embedded.js
| @@ -1,5 +1,6 @@ | ||
| (function(){ | ||
| - var hi = function() { | ||
| + var hi; | ||
| + hi = function() { | ||
| return [document.title, "Hello JavaScript"].join(": "); | ||
| }; | ||
| })(); |
View
5
documentation/js/expressions.js
| @@ -1,5 +1,6 @@ | ||
| (function(){ | ||
| - var grade = function(student) { | ||
| + var eldest, grade; | ||
| + grade = function(student) { | ||
| if (student.excellent_work) { | ||
| return "A+"; | ||
| } else if (student.okay_stuff) { | ||
| @@ -8,5 +9,5 @@ | ||
| return "C"; | ||
| } | ||
| }; | ||
| - var eldest = 24 > 21 ? "Liz" : "Ike"; | ||
| + eldest = 24 > 21 ? "Liz" : "Ike"; | ||
| })(); | ||
View
4
documentation/js/expressions_assignment.js
| @@ -0,0 +1,4 @@ | ||
| +(function(){ | ||
| + var one, six, three, two; | ||
| + six = (one = 1) + (two = 2) + (three = 3); | ||
| +})(); |
View
5
documentation/js/functions.js
| @@ -1,8 +1,9 @@ | ||
| (function(){ | ||
| - var square = function(x) { | ||
| + var cube, square; | ||
| + square = function(x) { | ||
| return x * x; | ||
| }; | ||
| - var cube = function(x) { | ||
| + cube = function(x) { | ||
| return square(x) * x; | ||
| }; | ||
| })(); |
View
5
documentation/js/objects_and_arrays.js
| @@ -1,6 +1,7 @@ | ||
| (function(){ | ||
| - var song = ["do", "re", "mi", "fa", "so"]; | ||
| - var ages = { | ||
| + var ages, song; | ||
| + song = ["do", "re", "mi", "fa", "so"]; | ||
| + ages = { | ||
| max: 10, | ||
| ida: 9, | ||
| tim: 11 | ||
Oops, something went wrong.