mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 01:07:55 -05:00
moved the coffeescript extension over from .cs to .coffee -- let's leave C# in peace. Changed array comprehensions to always return their mapped result, even when unassigned
This commit is contained in:
2
README
2
README
@@ -26,7 +26,7 @@
|
||||
gem install coffee-script
|
||||
|
||||
Compile a script:
|
||||
coffee-script /path/to/script.cs
|
||||
coffee-script /path/to/script.coffee
|
||||
|
||||
For documentation, usage, and examples, see:
|
||||
http://jashkenas.github.com/coffee-script/
|
||||
|
||||
4
Rakefile
4
Rakefile
@@ -19,7 +19,7 @@ namespace :build do
|
||||
|
||||
desc "Compile the Narwhal interface for --interactive and --run"
|
||||
task :narwhal do
|
||||
sh "bin/coffee-script lib/coffee_script/narwhal/*.cs -o lib/coffee_script/narwhal/js"
|
||||
sh "bin/coffee-script lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/js"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -27,7 +27,7 @@ end
|
||||
desc "Build the documentation page"
|
||||
task :doc do
|
||||
source = 'documentation/index.html.erb'
|
||||
child = fork { exec "bin/coffee-script documentation/cs/*.cs -o documentation/js -w" }
|
||||
child = fork { exec "bin/coffee-script documentation/coffee/*.coffee -o documentation/js -w" }
|
||||
at_exit { Process.kill("INT", child) }
|
||||
Signal.trap("INT") { exit }
|
||||
loop do
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# CoffeeScript on the left, JS on the right.
|
||||
|
||||
square: x => x * x.
|
||||
@@ -1,11 +0,0 @@
|
||||
# Comments start with hash marks.
|
||||
|
||||
# Periods mark the end of a block.
|
||||
left_hand: if raining then umbrella else parasol.
|
||||
|
||||
# To signal the beginning of the next expression,
|
||||
# use "then", or a newline.
|
||||
left_hand: if raining
|
||||
umbrella
|
||||
else
|
||||
parasol.
|
||||
@@ -3,7 +3,7 @@
|
||||
def code_for(file, executable=false)
|
||||
@stripper ||= /(\A\(function\(\)\{\n|\}\)\(\);\Z|^ )/
|
||||
return '' unless File.exists?("documentation/js/#{file}.js")
|
||||
cs = File.read("documentation/cs/#{file}.cs")
|
||||
cs = File.read("documentation/coffee/#{file}.coffee")
|
||||
js = File.read("documentation/js/#{file}.js").gsub(@stripper, '')
|
||||
cshtml = Uv.parse(cs, 'xhtml', 'coffeescript', false, 'idle', false)
|
||||
jshtml = Uv.parse(js, 'xhtml', 'javascript', false, 'idle', false)
|
||||
@@ -92,11 +92,11 @@ gem install coffee-script</pre>
|
||||
|
||||
<p>
|
||||
Installing the gem provides the <tt>coffee-script</tt> command, which can
|
||||
be used to compile CoffeeScript <tt>.cs</tt> files into JavaScript, as
|
||||
well as debug them. In conjunction with
|
||||
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>
|
||||
command also provides direct evaluation and an interactive REPL.
|
||||
When compiling to JavaScript, <tt>coffee-script</tt> writes the output
|
||||
command also provides direct evaluation and an interactive REPL.
|
||||
When compiling to JavaScript, <tt>coffee-script</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>
|
||||
@@ -105,7 +105,7 @@ gem install coffee-script</pre>
|
||||
<tr>
|
||||
<td width="25%"><code>-i, --interactive</code></td>
|
||||
<td>
|
||||
Launch an interactive CoffeeScript session.
|
||||
Launch an interactive CoffeeScript session.
|
||||
Requires <a href="http://narwhaljs.org/">Narwhal</a>.
|
||||
</td>
|
||||
</tr>
|
||||
@@ -187,9 +187,9 @@ gem install coffee-script</pre>
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
coffee-script path/to/script.cs
|
||||
coffee-script --watch --lint experimental.cs
|
||||
coffee-script --print app/scripts/*.cs > concatenation.js</pre>
|
||||
coffee-script path/to/script.coffee
|
||||
coffee-script --watch --lint experimental.coffee
|
||||
coffee-script --print app/scripts/*.coffee > concatenation.js</pre>
|
||||
|
||||
<h2>Language Reference</h2>
|
||||
|
||||
@@ -442,18 +442,18 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
|
||||
</ul>
|
||||
|
||||
<h2 id="change_log">Change Log</h2>
|
||||
|
||||
|
||||
<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-script</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.
|
||||
The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
|
||||
The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
|
||||
together a little smoother with <tt>is</tt>.
|
||||
Quoted strings are now allowed as identifiers within object literals: eg.
|
||||
<tt>{"5+5": 10}</tt>.
|
||||
All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
|
||||
All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
|
||||
<tt>*:</tt>, etc.
|
||||
</p>
|
||||
|
||||
|
||||
24
index.html
24
index.html
@@ -162,11 +162,11 @@ gem install coffee-script</pre>
|
||||
|
||||
<p>
|
||||
Installing the gem provides the <tt>coffee-script</tt> command, which can
|
||||
be used to compile CoffeeScript <tt>.cs</tt> files into JavaScript, as
|
||||
well as debug them. In conjunction with
|
||||
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>
|
||||
command also provides direct evaluation and an interactive REPL.
|
||||
When compiling to JavaScript, <tt>coffee-script</tt> writes the output
|
||||
command also provides direct evaluation and an interactive REPL.
|
||||
When compiling to JavaScript, <tt>coffee-script</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>
|
||||
@@ -175,7 +175,7 @@ gem install coffee-script</pre>
|
||||
<tr>
|
||||
<td width="25%"><code>-i, --interactive</code></td>
|
||||
<td>
|
||||
Launch an interactive CoffeeScript session.
|
||||
Launch an interactive CoffeeScript session.
|
||||
Requires <a href="http://narwhaljs.org/">Narwhal</a>.
|
||||
</td>
|
||||
</tr>
|
||||
@@ -257,9 +257,9 @@ gem install coffee-script</pre>
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
coffee-script path/to/script.cs
|
||||
coffee-script --watch --lint experimental.cs
|
||||
coffee-script --print app/scripts/*.cs > concatenation.js</pre>
|
||||
coffee-script path/to/script.coffee
|
||||
coffee-script --watch --lint experimental.coffee
|
||||
coffee-script --print app/scripts/*.coffee > concatenation.js</pre>
|
||||
|
||||
<h2>Language Reference</h2>
|
||||
|
||||
@@ -829,18 +829,18 @@ world...";
|
||||
</ul>
|
||||
|
||||
<h2 id="change_log">Change Log</h2>
|
||||
|
||||
|
||||
<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-script</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.
|
||||
The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
|
||||
The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
|
||||
together a little smoother with <tt>is</tt>.
|
||||
Quoted strings are now allowed as identifiers within object literals: eg.
|
||||
<tt>{"5+5": 10}</tt>.
|
||||
All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
|
||||
All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
|
||||
<tt>*:</tt>, etc.
|
||||
</p>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<key>name</key>
|
||||
<string>comments</string>
|
||||
<key>scope</key>
|
||||
<string>source.cs</string>
|
||||
<string>source.coffee</string>
|
||||
<key>settings</key>
|
||||
<dict>
|
||||
<key>shellVariables</key>
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
<string>CoffeeScript Syntax: version 1</string>
|
||||
<key>fileTypes</key>
|
||||
<array>
|
||||
<string>cs</string>
|
||||
<string>coffeescript</string>
|
||||
<string>coffee</string>
|
||||
</array>
|
||||
<key>name</key>
|
||||
<string>CoffeeScript</string>
|
||||
@@ -19,22 +18,22 @@
|
||||
<key>1</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>entity.name.function.cs</string>
|
||||
<string>entity.name.function.coffee</string>
|
||||
</dict>
|
||||
<key>2</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>keyword.operator.cs</string>
|
||||
<string>keyword.operator.coffee</string>
|
||||
</dict>
|
||||
<key>3</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>variable.parameter.function.cs</string>
|
||||
<string>variable.parameter.function.coffee</string>
|
||||
</dict>
|
||||
<key>4</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>storage.type.function.cs</string>
|
||||
<string>storage.type.function.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>comment</key>
|
||||
@@ -42,7 +41,7 @@
|
||||
<key>match</key>
|
||||
<string>([a-zA-Z_?.$]*)\s*(=|:)\s*([\w,\s]*?)\s*(=>)</string>
|
||||
<key>name</key>
|
||||
<string>meta.function.cs</string>
|
||||
<string>meta.function.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>captures</key>
|
||||
@@ -50,12 +49,12 @@
|
||||
<key>1</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>variable.parameter.function.cs</string>
|
||||
<string>variable.parameter.function.coffee</string>
|
||||
</dict>
|
||||
<key>2</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>storage.type.function.cs</string>
|
||||
<string>storage.type.function.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>comment</key>
|
||||
@@ -63,7 +62,7 @@
|
||||
<key>match</key>
|
||||
<string>([a-zA-Z_?., $]*)\s*(=>)</string>
|
||||
<key>name</key>
|
||||
<string>meta.inline.function.cs</string>
|
||||
<string>meta.inline.function.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>captures</key>
|
||||
@@ -71,12 +70,12 @@
|
||||
<key>1</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>keyword.operator.new.cs</string>
|
||||
<string>keyword.operator.new.coffee</string>
|
||||
</dict>
|
||||
<key>2</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>entity.name.type.instance.cs</string>
|
||||
<string>entity.name.type.instance.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>match</key>
|
||||
@@ -88,7 +87,7 @@
|
||||
<key>match</key>
|
||||
<string>\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[+\-]?[0-9]+)?))\b</string>
|
||||
<key>name</key>
|
||||
<string>constant.numeric.cs</string>
|
||||
<string>constant.numeric.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>begin</key>
|
||||
@@ -98,7 +97,7 @@
|
||||
<key>0</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.begin.cs</string>
|
||||
<string>punctuation.definition.string.begin.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>end</key>
|
||||
@@ -108,18 +107,18 @@
|
||||
<key>0</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.end.cs</string>
|
||||
<string>punctuation.definition.string.end.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>name</key>
|
||||
<string>string.quoted.single.cs</string>
|
||||
<string>string.quoted.single.coffee</string>
|
||||
<key>patterns</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)</string>
|
||||
<key>name</key>
|
||||
<string>constant.character.escape.cs</string>
|
||||
<string>constant.character.escape.coffee</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
@@ -131,7 +130,7 @@
|
||||
<key>0</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.begin.cs</string>
|
||||
<string>punctuation.definition.string.begin.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>end</key>
|
||||
@@ -141,18 +140,18 @@
|
||||
<key>0</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.end.cs</string>
|
||||
<string>punctuation.definition.string.end.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>name</key>
|
||||
<string>string.quoted.double.cs</string>
|
||||
<string>string.quoted.double.coffee</string>
|
||||
<key>patterns</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)</string>
|
||||
<key>name</key>
|
||||
<string>constant.character.escape.cs</string>
|
||||
<string>constant.character.escape.coffee</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
@@ -164,7 +163,7 @@
|
||||
<key>0</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.begin.cs</string>
|
||||
<string>punctuation.definition.string.begin.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>end</key>
|
||||
@@ -174,18 +173,18 @@
|
||||
<key>0</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.end.cs</string>
|
||||
<string>punctuation.definition.string.end.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>name</key>
|
||||
<string>string.quoted.script.cs</string>
|
||||
<string>string.quoted.script.coffee</string>
|
||||
<key>patterns</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)</string>
|
||||
<key>name</key>
|
||||
<string>constant.character.escape.cs</string>
|
||||
<string>constant.character.escape.coffee</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
@@ -195,61 +194,61 @@
|
||||
<key>1</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.comment.cs</string>
|
||||
<string>punctuation.definition.comment.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>match</key>
|
||||
<string>(#).*$\n?</string>
|
||||
<key>name</key>
|
||||
<string>comment.line.cs</string>
|
||||
<string>comment.line.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\b(break|when|catch|continue|else|finally|for|if|return|switch|then|throw|try|unless|while)\b</string>
|
||||
<key>name</key>
|
||||
<string>keyword.control.cs</string>
|
||||
<string>keyword.control.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\b(true|on|yes)\b</string>
|
||||
<key>name</key>
|
||||
<string>constant.language.boolean.true.cs</string>
|
||||
<string>constant.language.boolean.true.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\b(false|off|no)\b</string>
|
||||
<key>name</key>
|
||||
<string>constant.language.boolean.false.cs</string>
|
||||
<string>constant.language.boolean.false.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\bnull\b</string>
|
||||
<key>name</key>
|
||||
<string>constant.language.null.cs</string>
|
||||
<string>constant.language.null.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\b(super|this|extends)\b</string>
|
||||
<key>name</key>
|
||||
<string>variable.language.cs</string>
|
||||
<string>variable.language.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\b(debugger)\b</string>
|
||||
<key>name</key>
|
||||
<string>keyword.other.cs</string>
|
||||
<string>keyword.other.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b</string>
|
||||
<key>name</key>
|
||||
<string>keyword.operator.cs</string>
|
||||
<string>keyword.operator.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\b(Infinity|NaN|undefined)\b</string>
|
||||
<key>name</key>
|
||||
<string>constant.language.cs</string>
|
||||
<string>constant.language.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>begin</key>
|
||||
@@ -259,7 +258,7 @@
|
||||
<key>1</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.begin.cs</string>
|
||||
<string>punctuation.definition.string.begin.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>end</key>
|
||||
@@ -269,18 +268,18 @@
|
||||
<key>1</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>punctuation.definition.string.end.cs</string>
|
||||
<string>punctuation.definition.string.end.coffee</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>name</key>
|
||||
<string>string.regexp.cs</string>
|
||||
<string>string.regexp.coffee</string>
|
||||
<key>patterns</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\\.</string>
|
||||
<key>name</key>
|
||||
<string>constant.character.escape.cs</string>
|
||||
<string>constant.character.escape.coffee</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
@@ -288,41 +287,41 @@
|
||||
<key>match</key>
|
||||
<string>\;</string>
|
||||
<key>name</key>
|
||||
<string>punctuation.terminator.statement.cs</string>
|
||||
<string>punctuation.terminator.statement.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>,[ |\t]*</string>
|
||||
<key>name</key>
|
||||
<string>meta.delimiter.object.comma.cs</string>
|
||||
<string>meta.delimiter.object.comma.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\.</string>
|
||||
<key>name</key>
|
||||
<string>meta.delimiter.method.period.cs</string>
|
||||
<string>meta.delimiter.method.period.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\{|\}</string>
|
||||
<key>name</key>
|
||||
<string>meta.brace.curly.cs</string>
|
||||
<string>meta.brace.curly.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\(|\)</string>
|
||||
<key>name</key>
|
||||
<string>meta.brace.round.cs</string>
|
||||
<string>meta.brace.round.coffee</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\[|\]</string>
|
||||
<key>name</key>
|
||||
<string>meta.brace.square.cs</string>
|
||||
<string>meta.brace.square.coffee</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>scopeName</key>
|
||||
<string>source.cs</string>
|
||||
<string>source.coffee</string>
|
||||
<key>uuid</key>
|
||||
<string>5B520980-A7D5-4E10-8582-1A4C889A8DE5</string>
|
||||
</dict>
|
||||
|
||||
@@ -13,7 +13,7 @@ module CoffeeScript
|
||||
coffee-script compiles CoffeeScript source files into JavaScript.
|
||||
|
||||
Usage:
|
||||
coffee-script path/to/script.cs
|
||||
coffee-script path/to/script.coffee
|
||||
EOS
|
||||
|
||||
# Seconds to pause between checks for changed source files.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.cs
|
||||
# This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee
|
||||
|
||||
# Executes the `coffee-script` Ruby program to convert from CoffeeScript
|
||||
# to Javascript. Eventually this will hopefully happen entirely within JS.
|
||||
@@ -1,6 +1,6 @@
|
||||
(function(){
|
||||
|
||||
// This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.cs Executes the `coffee-script` Ruby program to convert from CoffeeScript
|
||||
// This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee Executes the `coffee-script` Ruby program to convert from CoffeeScript
|
||||
// to Javascript. Eventually this will hopefully happen entirely within JS. Require external dependencies.
|
||||
var OS = require('os');
|
||||
var File = require('file');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(function(){
|
||||
|
||||
// This (javascript) file is generated from lib/coffee_script/narwhal/loader.cs
|
||||
// This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
|
||||
var coffeescript = null;
|
||||
var factories = {
|
||||
};
|
||||
@@ -16,5 +16,5 @@
|
||||
return factories[topId] = factories[topId] || this.reload(topId, path);
|
||||
}
|
||||
};
|
||||
require.loader.loaders.unshift([".cs", loader]);
|
||||
require.loader.loaders.unshift([".coffee", loader]);
|
||||
})();
|
||||
@@ -1,4 +1,4 @@
|
||||
# This (javascript) file is generated from lib/coffee_script/narwhal/loader.cs
|
||||
# This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
|
||||
|
||||
coffeescript: null
|
||||
factories: {}
|
||||
@@ -16,4 +16,4 @@ loader: {
|
||||
|
||||
}
|
||||
|
||||
require.loader.loaders.unshift([".cs", loader])
|
||||
require.loader.loaders.unshift([".coffee", loader])
|
||||
@@ -506,32 +506,28 @@ module CoffeeScript
|
||||
|
||||
def compile(o={})
|
||||
o = super(o)
|
||||
scope = o[:scope]
|
||||
name_found = scope.find(@name)
|
||||
index_found = @index && scope.find(@index)
|
||||
svar = scope.free_variable
|
||||
ivar = scope.free_variable
|
||||
lvar = scope.free_variable
|
||||
name_part = name_found ? @name : "var #{@name}"
|
||||
index_name = @index ? (index_found ? @index : "var #{@index}") : nil
|
||||
source_part = "var #{svar} = #{@source.compile(o)};"
|
||||
for_part = "var #{ivar}=0, #{lvar}=#{svar}.length; #{ivar}<#{lvar}; #{ivar}++"
|
||||
var_part = "\n#{o[:indent] + TAB}#{name_part} = #{svar}[#{ivar}];\n"
|
||||
index_part = @index ? "#{o[:indent] + TAB}#{index_name} = #{ivar};\n" : ''
|
||||
scope = o[:scope]
|
||||
name_found = scope.find(@name)
|
||||
index_found = @index && scope.find(@index)
|
||||
svar = scope.free_variable
|
||||
ivar = scope.free_variable
|
||||
lvar = scope.free_variable
|
||||
rvar = scope.free_variable
|
||||
name_part = name_found ? @name : "var #{@name}"
|
||||
index_name = @index ? (index_found ? @index : "var #{@index}") : nil
|
||||
source_part = "var #{svar} = #{@source.compile(o)};"
|
||||
for_part = "var #{ivar}=0, #{lvar}=#{svar}.length; #{ivar}<#{lvar}; #{ivar}++"
|
||||
var_part = "\n#{o[:indent] + TAB}#{name_part} = #{svar}[#{ivar}];\n"
|
||||
index_part = @index ? "#{o[:indent] + TAB}#{index_name} = #{ivar};\n" : ''
|
||||
body = @body
|
||||
suffix = ';'
|
||||
set_result = "var #{rvar} = [];\n#{o[:indent]}"
|
||||
save_result = "#{rvar}[#{ivar}] = "
|
||||
return_result = rvar
|
||||
|
||||
set_result = ''
|
||||
save_result = ''
|
||||
return_result = ''
|
||||
body = @body
|
||||
suffix = ';'
|
||||
if o[:return] || o[:assign]
|
||||
rvar = scope.free_variable
|
||||
set_result = "var #{rvar} = [];\n#{o[:indent]}"
|
||||
save_result += "#{rvar}[#{ivar}] = "
|
||||
return_result = rvar
|
||||
return_result = "#{o[:assign]} = #{return_result};" if o[:assign]
|
||||
return_result = "return #{return_result};" if o[:return]
|
||||
return_result = "\n#{o[:indent]}#{return_result}"
|
||||
return_result = "#{o[:assign]} = #{return_result}" if o[:assign]
|
||||
return_result = "return #{return_result}" if o[:return]
|
||||
if @filter
|
||||
body = CallNode.new(ValueNode.new(LiteralNode.new(rvar), [AccessorNode.new('push')]), [@body])
|
||||
body = IfNode.new(@filter, body, nil, :statement => true)
|
||||
@@ -542,6 +538,7 @@ module CoffeeScript
|
||||
body = IfNode.new(@filter, @body)
|
||||
end
|
||||
|
||||
return_result = "\n#{o[:indent]}#{return_result};"
|
||||
indent = o[:indent] + TAB
|
||||
body = body.compile(o.merge(:indent => indent))
|
||||
write("#{source_part}\n#{o[:indent]}#{set_result}for (#{for_part}) {#{var_part}#{index_part}#{indent}#{save_result}#{body}#{suffix}\n#{o[:indent]}}#{return_result}")
|
||||
|
||||
14
test/fixtures/each.js
vendored
14
test/fixtures/each.js
vendored
@@ -9,17 +9,21 @@
|
||||
obj.forEach(iterator, context);
|
||||
} else if (_.isArray(obj) || _.isArguments(obj)) {
|
||||
var __a = obj;
|
||||
var __d = [];
|
||||
for (var __b=0, __c=__a.length; __b<__c; __b++) {
|
||||
var item = __a[__b];
|
||||
var i = __b;
|
||||
iterator.call(context, item, i, obj);
|
||||
__d[__b] = iterator.call(context, item, i, obj);
|
||||
}
|
||||
__d;
|
||||
} else {
|
||||
var __d = _.keys(obj);
|
||||
for (var __e=0, __f=__d.length; __e<__f; __e++) {
|
||||
var key = __d[__e];
|
||||
iterator.call(context, obj[key], key, obj);
|
||||
var __e = _.keys(obj);
|
||||
var __h = [];
|
||||
for (var __f=0, __g=__e.length; __f<__g; __f++) {
|
||||
var key = __e[__f];
|
||||
__h[__f] = iterator.call(context, obj[key], key, obj);
|
||||
}
|
||||
__h;
|
||||
}
|
||||
} catch (e) {
|
||||
if (e !== breaker) {
|
||||
|
||||
14
test/fixtures/each_no_wrap.js
vendored
14
test/fixtures/each_no_wrap.js
vendored
@@ -8,17 +8,21 @@ _.each = function(obj, iterator, context) {
|
||||
obj.forEach(iterator, context);
|
||||
} else if (_.isArray(obj) || _.isArguments(obj)) {
|
||||
var __a = obj;
|
||||
var __d = [];
|
||||
for (var __b=0, __c=__a.length; __b<__c; __b++) {
|
||||
var item = __a[__b];
|
||||
var i = __b;
|
||||
iterator.call(context, item, i, obj);
|
||||
__d[__b] = iterator.call(context, item, i, obj);
|
||||
}
|
||||
__d;
|
||||
} else {
|
||||
var __d = _.keys(obj);
|
||||
for (var __e=0, __f=__d.length; __e<__f; __e++) {
|
||||
var key = __d[__e];
|
||||
iterator.call(context, obj[key], key, obj);
|
||||
var __e = _.keys(obj);
|
||||
var __h = [];
|
||||
for (var __f=0, __g=__e.length; __f<__g; __f++) {
|
||||
var key = __e[__f];
|
||||
__h[__f] = iterator.call(context, obj[key], key, obj);
|
||||
}
|
||||
__h;
|
||||
}
|
||||
} catch (e) {
|
||||
if (e !== breaker) {
|
||||
|
||||
10
test/fixtures/execution/keyword_operators.cs
vendored
10
test/fixtures/execution/keyword_operators.cs
vendored
@@ -1,10 +0,0 @@
|
||||
a: 5
|
||||
atype: typeof a
|
||||
|
||||
b: "hello"
|
||||
btype: typeof b
|
||||
|
||||
Klass: => .
|
||||
k: new Klass()
|
||||
|
||||
print(atype is 'number' and btype is 'string' and k instanceof Klass)
|
||||
@@ -6,17 +6,17 @@ class ExecutionTest < Test::Unit::TestCase
|
||||
ALLS_WELL = /\A\n?(true\n)+\Z/
|
||||
|
||||
def test_execution_of_coffeescript
|
||||
sources = ['test/fixtures/execution/*.cs'].join(' ')
|
||||
sources = ['test/fixtures/execution/*.coffee'].join(' ')
|
||||
assert `bin/coffee-script -r #{sources}`.match(ALLS_WELL)
|
||||
end
|
||||
|
||||
def test_lintless_coffeescript
|
||||
lint_results = `bin/coffee-script -l test/fixtures/execution/*.cs`
|
||||
lint_results = `bin/coffee-script -l test/fixtures/execution/*.coffee`
|
||||
assert lint_results.match(NO_WARNINGS)
|
||||
end
|
||||
|
||||
def test_lintless_examples
|
||||
lint_results = `bin/coffee-script -l examples/*.cs`
|
||||
lint_results = `bin/coffee-script -l examples/*.coffee`
|
||||
assert lint_results.match(NO_WARNINGS)
|
||||
end
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class LexerTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_lexing
|
||||
tokens = @lex.tokenize(File.read('test/fixtures/each.cs'))
|
||||
tokens = @lex.tokenize(File.read('test/fixtures/each.coffee'))
|
||||
assert tokens.inspect == File.read('test/fixtures/each.tokens')
|
||||
end
|
||||
|
||||
|
||||
@@ -58,12 +58,12 @@ class ParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_parsing_inner_comments
|
||||
nodes = @par.parse(File.read('test/fixtures/inner_comments.cs'))
|
||||
nodes = @par.parse(File.read('test/fixtures/inner_comments.coffee'))
|
||||
assert nodes.compile == File.read('test/fixtures/inner_comments.js')
|
||||
end
|
||||
|
||||
def test_parsing
|
||||
nodes = @par.parse(File.read('test/fixtures/each.cs'))
|
||||
nodes = @par.parse(File.read('test/fixtures/each.coffee'))
|
||||
assign = nodes.expressions[1]
|
||||
assert assign.is_a? AssignNode
|
||||
assert assign.variable.literal == '_'
|
||||
@@ -73,7 +73,7 @@ class ParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_no_wrap
|
||||
nodes = @par.parse(File.read('test/fixtures/each.cs'))
|
||||
nodes = @par.parse(File.read('test/fixtures/each.coffee'))
|
||||
assert nodes.compile(:no_wrap => true) == File.read('test/fixtures/each_no_wrap.js')
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user