Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	lib/coffee-script/coffee-script.js
	lib/coffee-script/parser.js
	package.json
	src/coffee-script.coffee
	src/grammar.coffee
  • Loading branch information
jiangmiao committed Jun 24, 2013
2 parents 81fe884 + ef5f58e commit 4511493
Show file tree
Hide file tree
Showing 101 changed files with 2,857 additions and 1,657 deletions.
14 changes: 5 additions & 9 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
code = ''
for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'sourcemap', 'coffee-script', 'browser']
code += """
require['./#{name}'] = new function() {
var exports = this;
require['./#{name}'] = (function() {
var exports = {}, module = {exports: exports};
#{fs.readFileSync "lib/coffee-script/#{name}.js"}
};
return module.exports;
})();
"""
code = """
(function(root) {
Expand Down Expand Up @@ -211,20 +212,15 @@ runTests = (CoffeeScript) ->
log "failed #{failures.length} and #{message}", red
for fail in failures
{error, filename, description, source} = fail
jsFilename = filename.replace(/\.coffee$/,'.js')
match = error.stack?.match(new RegExp(fail.file+":(\\d+):(\\d+)"))
match = error.stack?.match(/on line (\d+):/) unless match
[match, line, col] = match if match
console.log ''
log " #{description}", red if description
log " #{error.stack}", red
log " #{jsFilename}: line #{line ? 'unknown'}, column #{col ? 'unknown'}", red
console.log " #{source}" if source
return

# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
for file in files when file.match /\.(lit)?coffee$/i
for file in files when helpers.isCoffee file
literate = helpers.isLiterate file
currentFile = filename = path.join 'test', file
code = fs.readFileSync filename
Expand Down
22 changes: 12 additions & 10 deletions documentation/docs/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ <h1>browser.coffee</h1>
to make things work smoothly when compiling code directly in the browser.
We add support for loading remote Coffee scripts via <strong>XHR</strong>, and
<code>text/coffeescript</code> script tags, source maps via data-URLs, and so on.

</p>

</div>

<div class="content"><div class='highlight'><pre>CoffeeScript = require <span class="string">'./coffee-script'</span>
<div class="content"><div class='highlight'><pre>
CoffeeScript = require <span class="string">'./coffee-script'</span>
CoffeeScript.require = require
compile = CoffeeScript.compile</pre></div></div>

Expand Down Expand Up @@ -155,6 +155,7 @@ <h1>browser.coffee</h1>

<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">run</span></span> = (code, options = {}) -&gt;
options.bare = <span class="literal">on</span>
options.shiftLine = <span class="literal">on</span>
Function(compile code, options)()</pre></div></div>

</li>
Expand Down Expand Up @@ -182,18 +183,19 @@ <h1>browser.coffee</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Include source maps where possible. If we&#39;ve got a base64 encoder, and a
JSON serializer, we&#39;re good to go.
<p>Include source maps where possible. If we&#39;ve got a base64 encoder, a
JSON serializer, and tools for escaping unicode characters, we&#39;re good to go.
Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">https://developer.mozilla.org/en-US/docs/DOM/window.btoa</a>
</p>

</div>

<div class="content"><div class='highlight'><pre><span class="keyword">if</span> btoa? <span class="keyword">and</span> JSON?
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> btoa? <span class="keyword">and</span> JSON? <span class="keyword">and</span> unescape? <span class="keyword">and</span> encodeURIComponent?
<span class="function"><span class="title">compile</span></span> = (code, options = {}) -&gt;
options.sourceMap = <span class="literal">true</span>
options.inline = <span class="literal">true</span>
{js, v3SourceMap} = CoffeeScript.compile code, options
<span class="string">"<span class="subst">#{js}</span>\n//@ sourceMappingURL=data:application/json;base64,<span class="subst">#{btoa v3SourceMap}</span>\n//@ sourceURL=coffeescript"</span></pre></div></div>
<span class="string">"<span class="subst">#{js}</span>\n//@ sourceMappingURL=data:application/json;base64,<span class="subst">#{btoa unescape encodeURIComponent v3SourceMap}</span>\n//@ sourceURL=coffeescript"</span></pre></div></div>

</li>

Expand All @@ -214,7 +216,7 @@ <h1>browser.coffee</h1>
xhr = <span class="keyword">if</span> window.ActiveXObject
<span class="keyword">new</span> window.ActiveXObject(<span class="string">'Microsoft.XMLHTTP'</span>)
<span class="keyword">else</span>
<span class="keyword">new</span> XMLHttpRequest()
<span class="keyword">new</span> window.XMLHttpRequest()
xhr.open <span class="string">'GET'</span>, url, <span class="literal">true</span>
xhr.overrideMimeType <span class="string">'text/plain'</span> <span class="keyword">if</span> <span class="string">'overrideMimeType'</span> <span class="keyword">of</span> xhr
xhr.<span class="function"><span class="title">onreadystatechange</span></span> = -&gt;
Expand Down Expand Up @@ -243,7 +245,7 @@ <h1>browser.coffee</h1>
</div>

<div class="content"><div class='highlight'><pre><span class="function"><span class="title">runScripts</span></span> = -&gt;
scripts = document.getElementsByTagName <span class="string">'script'</span>
scripts = window.document.getElementsByTagName <span class="string">'script'</span>
coffeetypes = [<span class="string">'text/coffeescript'</span>, <span class="string">'text/literate-coffeescript'</span>]
coffees = (s <span class="keyword">for</span> s <span class="keyword">in</span> scripts <span class="keyword">when</span> s.type <span class="keyword">in</span> coffeetypes)
index = <span class="number">0</span>
Expand Down Expand Up @@ -276,9 +278,9 @@ <h1>browser.coffee</h1>
</div>

<div class="content"><div class='highlight'><pre><span class="keyword">if</span> window.addEventListener
addEventListener <span class="string">'DOMContentLoaded'</span>, runScripts, <span class="literal">no</span>
window.addEventListener <span class="string">'DOMContentLoaded'</span>, runScripts, <span class="literal">no</span>
<span class="keyword">else</span>
attachEvent <span class="string">'onload'</span>, runScripts</pre></div></div>
window.attachEvent <span class="string">'onload'</span>, runScripts</pre></div></div>

</li>

Expand Down
51 changes: 31 additions & 20 deletions documentation/docs/cake.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,20 @@ <h1>cake.coffee</h1>
</p>
<p>Running <code>cake</code> with no arguments will print out a list of all the tasks in the
current directory&#39;s Cakefile.

</p>
<p>External dependencies.

</div>

</li>


<li id="section-2">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>External dependencies.
</p>

</div>
Expand All @@ -134,11 +145,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-2">
<li id="section-3">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>Keep track of the list of defined tasks, the accepted options, and so on.
</p>
Expand All @@ -153,11 +164,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-3">
<li id="section-4">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>Mixin the top-level Cake functions for Cakefiles to use directly.
</p>
Expand All @@ -169,11 +180,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-4">
<li id="section-5">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Define a Cake task with a short name, an optional sentence description,
and the function to run as the action itself.
Expand All @@ -188,11 +199,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-5">
<li id="section-6">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p>Define an option that the Cakefile accepts. The parsed options hash,
containing all of the command-line options passed, will be made available
Expand All @@ -207,11 +218,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-6">
<li id="section-7">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p>Invoke another task in the current Cakefile.
</p>
Expand All @@ -225,11 +236,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-7">
<li id="section-8">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
<a class="pilcrow" href="#section-8">&#182;</a>
</div>
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node&#39;s
asynchrony may cause tasks to execute in a different order than you&#39;d expect.
Expand All @@ -255,11 +266,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-8">
<li id="section-9">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a>
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code>
</p>
Expand All @@ -280,11 +291,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-9">
<li id="section-10">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
<a class="pilcrow" href="#section-10">&#182;</a>
</div>
<p>Print an error and exit when attempting to use an invalid task/option.
</p>
Expand All @@ -301,11 +312,11 @@ <h1>cake.coffee</h1>
</li>


<li id="section-10">
<li id="section-11">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a>
<a class="pilcrow" href="#section-11">&#182;</a>
</div>
<p>When <code>cake</code> is invoked, search in the current and all parent directories
to find the relevant Cakefile.
Expand Down
Loading

0 comments on commit 4511493

Please sign in to comment.