From b743e3219a219b60b420ebc2c4d7f6d1a614d329 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 24 Dec 2009 00:12:07 -0800 Subject: [PATCH] added some execution test --- README | 2 +- TODO | 13 ------------ documentation/index.html.erb | 21 +++++++++++++++---- index.html | 21 +++++++++++++++---- lib/coffee_script/nodes.rb | 2 +- .../fixtures/execution/array_comprehension.cs | 4 ++++ .../fixtures/execution/array_comprehension.js | 21 +++++++++++++++++++ .../fixtures/execution/assign_to_try_catch.cs | 6 ++++++ .../fixtures/execution/assign_to_try_catch.js | 9 ++++++++ test/fixtures/execution/fancy_if_statement.cs | 11 ++++++++++ test/fixtures/execution/fancy_if_statement.js | 6 ++++++ test/unit/test_execution.rb | 17 +++++++++++++++ 12 files changed, 110 insertions(+), 23 deletions(-) delete mode 100644 TODO create mode 100644 test/fixtures/execution/array_comprehension.cs create mode 100644 test/fixtures/execution/array_comprehension.js create mode 100644 test/fixtures/execution/assign_to_try_catch.cs create mode 100644 test/fixtures/execution/assign_to_try_catch.js create mode 100644 test/fixtures/execution/fancy_if_statement.cs create mode 100644 test/fixtures/execution/fancy_if_statement.js create mode 100644 test/unit/test_execution.rb diff --git a/README b/README index fa170417..244d6f82 100644 --- a/README +++ b/README @@ -35,4 +35,4 @@ http://github.com/jashkenas/coffee-script/issues/ The source repository: - git://github.com/jashkenas/coffee-script.git \ No newline at end of file + git://github.com/jashkenas/coffee-script.git diff --git a/TODO b/TODO deleted file mode 100644 index 14a7bfa8..00000000 --- a/TODO +++ /dev/null @@ -1,13 +0,0 @@ -TODO: - -* Finish the doc page. - -* Write a test suite that checks the JS evaluation. - -* Is it possible to close blocks (functions, ifs, trys) without an explicit - block delimiter or significant whitespace? - -* Is it possible to pass comments through cleanly and have them show up on - the other end? This includes comments in the middle of array and object - literals, and argument lists. - \ No newline at end of file diff --git a/documentation/index.html.erb b/documentation/index.html.erb index 3f039253..fabb13a0 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -32,7 +32,7 @@

CoffeeScript is a little language that compiles into JavaScript. Think of it as JavaScript's less ostentatious kid brother — the same genes, - the same accent, but a different sense of style. Apart from a handful of + roughly the same height, but a different sense of style. Apart from a handful of bonus goodies, statements in CoffeeScript correspond one-to-one with their equivalent in JavaScript, it's just another way of saying it.

@@ -72,6 +72,7 @@ Switch/Case/Else
Try/Catch/Finally
Multiline Strings
+ Change Log

Mini Overview

@@ -81,9 +82,14 @@ <%= code_for('overview', 'cubed_list') %>

Installation and Usage

+ +

+ The CoffeeScript compiler is written in pure Ruby, and is available + as a Ruby Gem. +

-sudo gem install coffee-script
+gem install coffee-script

Installing the gem provides the coffee-script command, which can @@ -339,7 +345,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js

Switch/Case/Else Switch statements in JavaScript are rather broken. You can only - do string comparisons, and need to remember to break at the end of + do comparisons based on string equality, and need to remember to break at the end of every case statement to avoid accidentally falling through to the default case. CoffeeScript compiles switch statements into JavaScript if-else chains, allowing you to @@ -352,7 +358,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js

Try/Catch/Finally Try/catch statements are just about the same as JavaScript (although - they work as expressions). No braces required. + they work as expressions).

<%= code_for('try') %> @@ -361,6 +367,13 @@ coffee-script --print app/scripts/*.cs > concatenation.js Multiline strings are allowed in CoffeeScript.

<%= code_for('strings', 'moby_dick') %> + +

Change Log

+ +

+ 0.1.0 + Initial CoffeeScript release. +

diff --git a/index.html b/index.html index a34ac81d..ff9087fe 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@

CoffeeScript is a little language that compiles into JavaScript. Think of it as JavaScript's less ostentatious kid brother — the same genes, - the same accent, but a different sense of style. Apart from a handful of + roughly the same height, but a different sense of style. Apart from a handful of bonus goodies, statements in CoffeeScript correspond one-to-one with their equivalent in JavaScript, it's just another way of saying it.

@@ -58,6 +58,7 @@ Switch/Case/Else
Try/Catch/Finally
Multiline Strings
+ Change Log

Mini Overview

@@ -151,9 +152,14 @@ cubed_list = d; ;alert(cubed_list);'>run: cubed_list

Installation and Usage

+ +

+ The CoffeeScript compiler is written in pure Ruby, and is available + as a Ruby Gem. +

-sudo gem install coffee-script
+gem install coffee-script

Installing the gem provides the coffee-script command, which can @@ -654,7 +660,7 @@ return [document.title, "Hello JavaScript"].join(": ");

Switch/Case/Else Switch statements in JavaScript are rather broken. You can only - do string comparisons, and need to remember to break at the end of + do comparisons based on string equality, and need to remember to break at the end of every case statement to avoid accidentally falling through to the default case. CoffeeScript compiles switch statements into JavaScript if-else chains, allowing you to @@ -690,7 +696,7 @@ return [document.title, "Hello JavaScript"].join(": ");

Try/Catch/Finally Try/catch statements are just about the same as JavaScript (although - they work as expressions). No braces required. + they work as expressions).

try
   all_hell_breaks_loose()
@@ -733,6 +739,13 @@ to interest me on shore, I thought I would sail \
 about a little and see the watery part of the \
 world...";
 ;alert(moby_dick);'>run: moby_dick
+ +

Change Log

+ +

+ 0.1.0 + Initial CoffeeScript release. +

diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 38fac8bc..07603d38 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -507,7 +507,7 @@ module CoffeeScript return_result = "\n#{o[:indent]}#{return_result}" if @filter body = CallNode.new(ValueNode.new(LiteralNode.new(rvar), [AccessorNode.new('push')]), [@body]) - body = IfNode.new(@filter, body, nil, :statement) + body = IfNode.new(@filter, body, nil, :statement => true) save_result = '' suffix = '' end diff --git a/test/fixtures/execution/array_comprehension.cs b/test/fixtures/execution/array_comprehension.cs new file mode 100644 index 00000000..378d8f7e --- /dev/null +++ b/test/fixtures/execution/array_comprehension.cs @@ -0,0 +1,4 @@ +nums: n * n for n in [1, 2, 3] if n % 2 aint 0. +result: n * 2 for n in nums. + +print(result.join(',') is '2,18') \ No newline at end of file diff --git a/test/fixtures/execution/array_comprehension.js b/test/fixtures/execution/array_comprehension.js new file mode 100644 index 00000000..5bdaeee9 --- /dev/null +++ b/test/fixtures/execution/array_comprehension.js @@ -0,0 +1,21 @@ +(function(){ + var nums; + var a = [1, 2, 3]; + var d = []; + for (var b=0, c=a.length; b