Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'origin/gh-pages'

  • Loading branch information...
commit eda4f0c55bba462358719c57789a746a463d17c5 2 parents ed92892 + 5f28319
@michaelficarra michaelficarra authored
Showing with 5,446 additions and 6,084 deletions.
  1. +74 −67 documentation/docs/browser.html
  2. +75 −97 documentation/docs/cake.html
  3. +252 −365 documentation/docs/coffee-script.html
  4. +335 −301 documentation/docs/command.html
  5. +2 −11 documentation/docs/docco.css
  6. +493 −615 documentation/docs/grammar.html
  7. +190 −172 documentation/docs/helpers.html
  8. +7 −3 documentation/docs/index.html
  9. +791 −846 documentation/docs/lexer.html
  10. +2,020 −2,423 documentation/docs/nodes.html
  11. +85 −105 documentation/docs/optparse.html
  12. +251 −0 documentation/docs/register.html
  13. +139 −132 documentation/docs/repl.html
  14. +434 −509 documentation/docs/rewriter.html
  15. +85 −123 documentation/docs/scope.html
  16. +141 −266 documentation/docs/sourcemap.html
  17. +12 −1 documentation/index.html.js
  18. +1 −1  documentation/js/aliases.js
  19. +1 −1  documentation/js/array_comprehensions.js
  20. +1 −1  documentation/js/block_comment.js
  21. +1 −1  documentation/js/cake_tasks.js
  22. +1 −1  documentation/js/chaining.js
  23. +1 −1  documentation/js/classes.js
  24. +1 −1  documentation/js/comparisons.js
  25. +1 −1  documentation/js/conditionals.js
  26. +1 −1  documentation/js/constructor_destructuring.js
  27. +1 −1  documentation/js/default_args.js
  28. +1 −1  documentation/js/do.js
  29. +1 −1  documentation/js/embedded.js
  30. +1 −1  documentation/js/existence.js
  31. +1 −1  documentation/js/expansion.js
  32. +1 −1  documentation/js/expressions.js
  33. +1 −1  documentation/js/expressions_assignment.js
  34. +1 −1  documentation/js/expressions_comprehension.js
  35. +1 −1  documentation/js/expressions_try.js
  36. +1 −1  documentation/js/fat_arrow.js
  37. +1 −1  documentation/js/functions.js
  38. +1 −1  documentation/js/heredocs.js
  39. +1 −1  documentation/js/heregexes.js
  40. +1 −1  documentation/js/interpolation.js
  41. +1 −1  documentation/js/multiple_return_values.js
  42. +1 −1  documentation/js/object_comprehensions.js
  43. +1 −1  documentation/js/object_extraction.js
  44. +1 −1  documentation/js/objects_and_arrays.js
  45. +1 −1  documentation/js/objects_reserved.js
  46. +1 −1  documentation/js/overview.js
  47. +1 −1  documentation/js/parallel_assignment.js
  48. +1 −1  documentation/js/patterns_and_splats.js
  49. +1 −1  documentation/js/prototypes.js
  50. +1 −1  documentation/js/range_comprehensions.js
  51. +1 −1  documentation/js/scope.js
  52. +1 −1  documentation/js/slices.js
  53. +1 −1  documentation/js/soaks.js
  54. +1 −1  documentation/js/splats.js
  55. +1 −1  documentation/js/splices.js
  56. +1 −1  documentation/js/strings.js
  57. +1 −1  documentation/js/switch.js
  58. +1 −1  documentation/js/switch_with_no_expression.js
  59. +1 −1  documentation/js/try.js
  60. +1 −1  documentation/js/while.js
  61. +15 −4 index.html
  62. +2 −1  package.json
View
141 documentation/docs/browser.html
@@ -69,6 +69,11 @@
</a>
+ <a class="source" href="register.html">
+ register.coffee
+ </a>
+
+
<a class="source" href="repl.html">
repl.coffee
</a>
@@ -111,14 +116,12 @@
<p>This <strong>Browser</strong> compatibility layer extends core CoffeeScript functions
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>
+<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>
-CoffeeScript.require = require
+ <div class="content"><div class='highlight'><pre>CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span>
+CoffeeScript.<span class="hljs-built_in">require</span> = <span class="hljs-built_in">require</span>
compile = CoffeeScript.compile</pre></div></div>
</li>
@@ -130,13 +133,12 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
- <p>Use standard JavaScript <code>eval</code> to eval code.
-</p>
+ <p>Use standard JavaScript <code>eval</code> to eval code.</p>
</div>
- <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">eval</span></span> = (code, options = {}) -&gt;
- options.bare ?= <span class="literal">on</span>
+ <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">eval</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
+ options.bare ?= <span class="hljs-literal">on</span>
eval compile code, options</pre></div></div>
</li>
@@ -148,14 +150,13 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
- <p>Running code does not provide access to this scope.
-</p>
+ <p>Running code does not provide access to this scope.</p>
</div>
- <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>
+ <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">run</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
+ options.bare = <span class="hljs-literal">on</span>
+ options.shiftLine = <span class="hljs-literal">on</span>
Function(compile code, options)()</pre></div></div>
</li>
@@ -167,12 +168,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
- <p>If we&#39;re not in a browser environment, we&#39;re finished with the public API.
-</p>
+ <p>If we&#39;re not in a browser environment, we&#39;re finished with the public API.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="keyword">return</span> <span class="keyword">unless</span> window?</pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> <span class="hljs-built_in">window</span>?</pre></div></div>
</li>
@@ -185,17 +185,16 @@
</div>
<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>
+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? <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>
+ <div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> btoa? <span class="hljs-keyword">and</span> JSON? <span class="hljs-keyword">and</span> unescape? <span class="hljs-keyword">and</span> encodeURIComponent?
+ <span class="hljs-function"><span class="hljs-title">compile</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
+ options.sourceMap = <span class="hljs-literal">true</span>
+ options.inline = <span class="hljs-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 unescape encodeURIComponent v3SourceMap}</span>\n//@ sourceURL=coffeescript"</span></pre></div></div>
+ <span class="hljs-string">"<span class="hljs-subst">#{js}</span>\n//# sourceMappingURL=data:application/json;base64,<span class="hljs-subst">#{btoa unescape encodeURIComponent v3SourceMap}</span>\n//# sourceURL=coffeescript"</span></pre></div></div>
</li>
@@ -206,27 +205,27 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
- <p>Load a remote script from the current domain via XHR.
-</p>
+ <p>Load a remote script from the current domain via XHR.</p>
</div>
- <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">load</span></span> = (url, callback, options = {}) -&gt;
+ <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">load</span> = <span class="hljs-params">(url, callback, options = {}, hold = <span class="hljs-literal">false</span>)</span> -&gt;</span>
options.sourceFiles = [url]
- 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> 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;
- <span class="keyword">if</span> xhr.readyState <span class="keyword">is</span> <span class="number">4</span>
- <span class="keyword">if</span> xhr.status <span class="keyword">in</span> [<span class="number">0</span>, <span class="number">200</span>]
- CoffeeScript.run xhr.responseText, options
- <span class="keyword">else</span>
- <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Could not load <span class="subst">#{url}</span>"</span>
- callback() <span class="keyword">if</span> callback
- xhr.send <span class="literal">null</span></pre></div></div>
+ xhr = <span class="hljs-keyword">if</span> <span class="hljs-built_in">window</span>.ActiveXObject
+ <span class="hljs-keyword">new</span> <span class="hljs-built_in">window</span>.ActiveXObject(<span class="hljs-string">'Microsoft.XMLHTTP'</span>)
+ <span class="hljs-keyword">else</span>
+ <span class="hljs-keyword">new</span> <span class="hljs-built_in">window</span>.XMLHttpRequest()
+ xhr.open <span class="hljs-string">'GET'</span>, url, <span class="hljs-literal">true</span>
+ xhr.overrideMimeType <span class="hljs-string">'text/plain'</span> <span class="hljs-keyword">if</span> <span class="hljs-string">'overrideMimeType'</span> <span class="hljs-keyword">of</span> xhr
+ xhr.<span class="hljs-function"><span class="hljs-title">onreadystatechange</span> = -&gt;</span>
+ <span class="hljs-keyword">if</span> xhr.readyState <span class="hljs-keyword">is</span> <span class="hljs-number">4</span>
+ <span class="hljs-keyword">if</span> xhr.status <span class="hljs-keyword">in</span> [<span class="hljs-number">0</span>, <span class="hljs-number">200</span>]
+ param = [xhr.responseText, options]
+ CoffeeScript.run param... <span class="hljs-keyword">unless</span> hold
+ <span class="hljs-keyword">else</span>
+ <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"Could not load <span class="hljs-subst">#{url}</span>"</span>
+ callback param <span class="hljs-keyword">if</span> callback
+ xhr.send <span class="hljs-literal">null</span></pre></div></div>
</li>
@@ -239,29 +238,38 @@
</div>
<p>Activate CoffeeScript in the browser by having it compile and evaluate
all script tags with a content-type of <code>text/coffeescript</code>.
-This happens on page load.
-</p>
+This happens on page load.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="function"><span class="title">runScripts</span></span> = -&gt;
- 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>
- length = coffees.length
- <span class="keyword">do</span> <span class="function"><span class="title">execute</span></span> = -&gt;
- script = coffees[index++]
- mediatype = script?.type
- <span class="keyword">if</span> mediatype <span class="keyword">in</span> coffeetypes
- options = {literate: mediatype <span class="keyword">is</span> <span class="string">'text/literate-coffeescript'</span>}
- <span class="keyword">if</span> script.src
- CoffeeScript.load script.src, execute, options
- <span class="keyword">else</span>
- options.sourceFiles = [<span class="string">'embedded'</span>]
- CoffeeScript.run script.innerHTML, options
- execute()
- <span class="literal">null</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">runScripts</span> = -&gt;</span>
+ scripts = <span class="hljs-built_in">window</span>.<span class="hljs-built_in">document</span>.getElementsByTagName <span class="hljs-string">'script'</span>
+ coffeetypes = [<span class="hljs-string">'text/coffeescript'</span>, <span class="hljs-string">'text/literate-coffeescript'</span>]
+ coffees = (s <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> scripts <span class="hljs-keyword">when</span> s.type <span class="hljs-keyword">in</span> coffeetypes)
+ index = <span class="hljs-number">0</span>
+
+ <span class="hljs-function"><span class="hljs-title">execute</span> = -&gt;</span>
+ param = coffees[index]
+ <span class="hljs-keyword">if</span> param <span class="hljs-keyword">instanceof</span> Array
+ CoffeeScript.run param...
+ index++
+ execute()
+
+ <span class="hljs-keyword">for</span> script, i <span class="hljs-keyword">in</span> coffees
+ <span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-params">(script, i)</span> -&gt;</span>
+ options = <span class="hljs-attribute">literate</span>: script.type <span class="hljs-keyword">is</span> coffeetypes[<span class="hljs-number">1</span>]
+ <span class="hljs-keyword">if</span> script.src
+ CoffeeScript.load script.src,
+ <span class="hljs-function"><span class="hljs-params">(param)</span> -&gt;</span>
+ coffees[i] = param
+ execute()
+ options
+ <span class="hljs-literal">true</span>
+ <span class="hljs-keyword">else</span>
+ options.sourceFiles = [<span class="hljs-string">'embedded'</span>]
+ coffees[i] = [script.innerHTML, options]
+
+ execute()</pre></div></div>
</li>
@@ -272,15 +280,14 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a>
</div>
- <p>Listen for window load, both in decent browsers and in IE.
-</p>
+ <p>Listen for window load, both in decent browsers and in IE.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="keyword">if</span> window.addEventListener
- window.addEventListener <span class="string">'DOMContentLoaded'</span>, runScripts, <span class="literal">no</span>
-<span class="keyword">else</span>
- window.attachEvent <span class="string">'onload'</span>, runScripts</pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> <span class="hljs-built_in">window</span>.addEventListener
+ <span class="hljs-built_in">window</span>.addEventListener <span class="hljs-string">'DOMContentLoaded'</span>, runScripts, <span class="hljs-literal">no</span>
+<span class="hljs-keyword">else</span>
+ <span class="hljs-built_in">window</span>.attachEvent <span class="hljs-string">'onload'</span>, runScripts</pre></div></div>
</li>
View
172 documentation/docs/cake.html
@@ -69,6 +69,11 @@
</a>
+ <a class="source" href="register.html">
+ register.coffee
+ </a>
+
+
<a class="source" href="repl.html">
repl.coffee
</a>
@@ -111,15 +116,19 @@
<p><code>cake</code> is a simplified version of <a href="http://www.gnu.org/software/make/">Make</a>
(<a href="http://rake.rubyforge.org/">Rake</a>, <a href="http://github.com/280north/jake">Jake</a>)
for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
-and can call them from the command line, or invoke them from other tasks.
-
-</p>
+and can call them from the command line, or invoke them from other tasks.</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>
+current directory&#39;s Cakefile.</p>
+<p>External dependencies.</p>
</div>
+ <div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
+path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
+helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
+optparse = <span class="hljs-built_in">require</span> <span class="hljs-string">'./optparse'</span>
+CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span></pre></div></div>
+
</li>
@@ -129,18 +138,14 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
- <p>External dependencies.
-</p>
+ <p>Keep track of the list of defined tasks, the accepted options, and so on.</p>
</div>
- <div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
-path = require <span class="string">'path'</span>
-helpers = require <span class="string">'./helpers'</span>
-optparse = require <span class="string">'./optparse'</span>
-CoffeeScript = require <span class="string">'./coffee-script'</span>
-
-existsSync = fs.existsSync <span class="keyword">or</span> path.existsSync</pre></div></div>
+ <div class="content"><div class='highlight'><pre>tasks = {}
+options = {}
+switches = []
+oparse = <span class="hljs-literal">null</span></pre></div></div>
</li>
@@ -151,15 +156,11 @@
<div class="pilwrap ">
<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>
+ <p>Mixin the top-level Cake functions for Cakefiles to use directly.</p>
</div>
- <div class="content"><div class='highlight'><pre>tasks = {}
-options = {}
-switches = []
-oparse = <span class="literal">null</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre>helpers.extend <span class="hljs-built_in">global</span>,</pre></div></div>
</li>
@@ -170,165 +171,142 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
- <p>Mixin the top-level Cake functions for Cakefiles to use directly.
-</p>
-
- </div>
-
- <div class="content"><div class='highlight'><pre>helpers.extend global,</pre></div></div>
-
- </li>
-
-
- <li id="section-5">
- <div class="annotation">
-
- <div class="pilwrap ">
- <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.
-</p>
+and the function to run as the action itself.</p>
</div>
- <div class="content"><div class='highlight'><pre> task: (name, description, action) -&gt;
- [action, description] = [description, action] <span class="keyword">unless</span> action
+ <div class="content"><div class='highlight'><pre> <span class="hljs-attribute">task</span>: <span class="hljs-function"><span class="hljs-params">(name, description, action)</span> -&gt;</span>
+ [action, description] = [description, action] <span class="hljs-keyword">unless</span> action
tasks[name] = {name, description, action}</pre></div></div>
</li>
- <li id="section-6">
+ <li id="section-5">
<div class="annotation">
<div class="pilwrap ">
- <a class="pilcrow" href="#section-6">&#182;</a>
+ <a class="pilcrow" href="#section-5">&#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
-as the first argument to the action.
-</p>
+as the first argument to the action.</p>
</div>
- <div class="content"><div class='highlight'><pre> option: (letter, flag, description) -&gt;
+ <div class="content"><div class='highlight'><pre> <span class="hljs-attribute">option</span>: <span class="hljs-function"><span class="hljs-params">(letter, flag, description)</span> -&gt;</span>
switches.push [letter, flag, description]</pre></div></div>
</li>
- <li id="section-7">
+ <li id="section-6">
<div class="annotation">
<div class="pilwrap ">
- <a class="pilcrow" href="#section-7">&#182;</a>
+ <a class="pilcrow" href="#section-6">&#182;</a>
</div>
- <p>Invoke another task in the current Cakefile.
-</p>
+ <p>Invoke another task in the current Cakefile.</p>
</div>
- <div class="content"><div class='highlight'><pre> invoke: (name) -&gt;
- missingTask name <span class="keyword">unless</span> tasks[name]
+ <div class="content"><div class='highlight'><pre> <span class="hljs-attribute">invoke</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -&gt;</span>
+ missingTask name <span class="hljs-keyword">unless</span> tasks[name]
tasks[name].action options</pre></div></div>
</li>
- <li id="section-8">
+ <li id="section-7">
<div class="annotation">
<div class="pilwrap ">
- <a class="pilcrow" href="#section-8">&#182;</a>
+ <a class="pilcrow" href="#section-7">&#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.
If no tasks are passed, print the help screen. Keep a reference to the
-original directory name, when running Cake tasks from subdirectories.
-</p>
+original directory name, when running Cake tasks from subdirectories.</p>
</div>
- <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = -&gt;
- global.__originalDirname = fs.realpathSync <span class="string">'.'</span>
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">run</span> = -&gt;</span>
+ <span class="hljs-built_in">global</span>.__originalDirname = fs.realpathSync <span class="hljs-string">'.'</span>
process.chdir cakefileDirectory __originalDirname
- args = process.argv[<span class="number">2.</span>.]
- CoffeeScript.run fs.readFileSync(<span class="string">'Cakefile'</span>).toString(), filename: <span class="string">'Cakefile'</span>
- oparse = <span class="keyword">new</span> optparse.OptionParser switches
- <span class="keyword">return</span> printTasks() <span class="keyword">unless</span> args.length
- <span class="keyword">try</span>
+ args = process.argv[<span class="hljs-number">2.</span>.]
+ CoffeeScript.run fs.readFileSync(<span class="hljs-string">'Cakefile'</span>).toString(), <span class="hljs-attribute">filename</span>: <span class="hljs-string">'Cakefile'</span>
+ oparse = <span class="hljs-keyword">new</span> optparse.OptionParser switches
+ <span class="hljs-keyword">return</span> printTasks() <span class="hljs-keyword">unless</span> args.length
+ <span class="hljs-keyword">try</span>
options = oparse.parse(args)
- <span class="keyword">catch</span> e
- <span class="keyword">return</span> fatalError <span class="string">"<span class="subst">#{e}</span>"</span>
- invoke arg <span class="keyword">for</span> arg <span class="keyword">in</span> options.arguments</pre></div></div>
+ <span class="hljs-keyword">catch</span> e
+ <span class="hljs-keyword">return</span> fatalError <span class="hljs-string">"<span class="hljs-subst">#{e}</span>"</span>
+ invoke arg <span class="hljs-keyword">for</span> arg <span class="hljs-keyword">in</span> options.arguments</pre></div></div>
</li>
- <li id="section-9">
+ <li id="section-8">
<div class="annotation">
<div class="pilwrap ">
- <a class="pilcrow" href="#section-9">&#182;</a>
+ <a class="pilcrow" href="#section-8">&#182;</a>
</div>
- <p>Display the list of Cake tasks in a format similar to <code>rake -T</code>
-</p>
+ <p>Display the list of Cake tasks in a format similar to <code>rake -T</code></p>
</div>
- <div class="content"><div class='highlight'><pre><span class="function"><span class="title">printTasks</span></span> = -&gt;
- relative = path.relative <span class="keyword">or</span> path.resolve
- cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="string">'Cakefile'</span>
- console.log <span class="string">"<span class="subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
- <span class="keyword">for</span> name, task <span class="keyword">of</span> tasks
- spaces = <span class="number">20</span> - name.length
- spaces = <span class="keyword">if</span> spaces &gt; <span class="number">0</span> <span class="keyword">then</span> Array(spaces + <span class="number">1</span>).join(<span class="string">' '</span>) <span class="keyword">else</span> <span class="string">''</span>
- desc = <span class="keyword">if</span> task.description <span class="keyword">then</span> <span class="string">"# <span class="subst">#{task.description}</span>"</span> <span class="keyword">else</span> <span class="string">''</span>
- console.log <span class="string">"cake <span class="subst">#{name}</span><span class="subst">#{spaces}</span> <span class="subst">#{desc}</span>"</span>
- console.log oparse.help() <span class="keyword">if</span> switches.length</pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">printTasks</span> = -&gt;</span>
+ relative = path.relative <span class="hljs-keyword">or</span> path.resolve
+ cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="hljs-string">'Cakefile'</span>
+ <span class="hljs-built_in">console</span>.log <span class="hljs-string">"<span class="hljs-subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
+ <span class="hljs-keyword">for</span> name, task <span class="hljs-keyword">of</span> tasks
+ spaces = <span class="hljs-number">20</span> - name.length
+ spaces = <span class="hljs-keyword">if</span> spaces &gt; <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> Array(spaces + <span class="hljs-number">1</span>).join(<span class="hljs-string">' '</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
+ desc = <span class="hljs-keyword">if</span> task.description <span class="hljs-keyword">then</span> <span class="hljs-string">"# <span class="hljs-subst">#{task.description}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
+ <span class="hljs-built_in">console</span>.log <span class="hljs-string">"cake <span class="hljs-subst">#{name}</span><span class="hljs-subst">#{spaces}</span> <span class="hljs-subst">#{desc}</span>"</span>
+ <span class="hljs-built_in">console</span>.log oparse.help() <span class="hljs-keyword">if</span> switches.length</pre></div></div>
</li>
- <li id="section-10">
+ <li id="section-9">
<div class="annotation">
<div class="pilwrap ">
- <a class="pilcrow" href="#section-10">&#182;</a>
+ <a class="pilcrow" href="#section-9">&#182;</a>
</div>
- <p>Print an error and exit when attempting to use an invalid task/option.
-</p>
+ <p>Print an error and exit when attempting to use an invalid task/option.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="function"><span class="title">fatalError</span></span> = (message) -&gt;
- console.error message + <span class="string">'\n'</span>
- console.log <span class="string">'To see a list of all tasks/options, run "cake"'</span>
- process.exit <span class="number">1</span>
+ <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">fatalError</span> = <span class="hljs-params">(message)</span> -&gt;</span>
+ <span class="hljs-built_in">console</span>.error message + <span class="hljs-string">'\n'</span>
+ <span class="hljs-built_in">console</span>.log <span class="hljs-string">'To see a list of all tasks/options, run "cake"'</span>
+ process.exit <span class="hljs-number">1</span>
-<span class="function"><span class="title">missingTask</span></span> = (task) -&gt; fatalError <span class="string">"No such task: <span class="subst">#{task}</span>"</span></pre></div></div>
+<span class="hljs-function"><span class="hljs-title">missingTask</span> = <span class="hljs-params">(task)</span> -&gt;</span> fatalError <span class="hljs-string">"No such task: <span class="hljs-subst">#{task}</span>"</span></pre></div></div>
</li>
- <li id="section-11">
+ <li id="section-10">
<div class="annotation">
<div class="pilwrap ">
- <a class="pilcrow" href="#section-11">&#182;</a>
+ <a class="pilcrow" href="#section-10">&#182;</a>
</div>
<p>When <code>cake</code> is invoked, search in the current and all parent directories
-to find the relevant Cakefile.
-</p>
+to find the relevant Cakefile.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="function"><span class="title">cakefileDirectory</span></span> = (dir) -&gt;
- <span class="keyword">return</span> dir <span class="keyword">if</span> existsSync path.join dir, <span class="string">'Cakefile'</span>
- parent = path.normalize path.join dir, <span class="string">'..'</span>
- <span class="keyword">return</span> cakefileDirectory parent <span class="keyword">unless</span> parent <span class="keyword">is</span> dir
- <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cakefile not found in <span class="subst">#{process.cwd()}</span>"</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">cakefileDirectory</span> = <span class="hljs-params">(dir)</span> -&gt;</span>
+ <span class="hljs-keyword">return</span> dir <span class="hljs-keyword">if</span> fs.existsSync path.join dir, <span class="hljs-string">'Cakefile'</span>
+ parent = path.normalize path.join dir, <span class="hljs-string">'..'</span>
+ <span class="hljs-keyword">return</span> cakefileDirectory parent <span class="hljs-keyword">unless</span> parent <span class="hljs-keyword">is</span> dir
+ <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"Cakefile not found in <span class="hljs-subst">#{process.cwd()}</span>"</span></pre></div></div>
</li>
View
617 documentation/docs/coffee-script.html
@@ -69,6 +69,11 @@
</a>
+ <a class="source" href="register.html">
+ register.coffee
+ </a>
+
+
<a class="source" href="repl.html">
repl.coffee
</a>
@@ -111,20 +116,17 @@
<p>CoffeeScript can be used both on the server, as a command-line compiler based
on Node.js/V8, or to run CoffeeScript directly in the browser. This module
contains the main entry functions for tokenizing, parsing, and compiling
-source CoffeeScript into JavaScript.
-</p>
+source CoffeeScript into JavaScript.</p>
</div>
- <div class="content"><div class='highlight'><pre>
-fs = require <span class="string">'fs'</span>
-vm = require <span class="string">'vm'</span>
-path = require <span class="string">'path'</span>
-child_process = require <span class="string">'child_process'</span>
-{Lexer} = require <span class="string">'./lexer'</span>
-{parser} = require <span class="string">'./parser'</span>
-helpers = require <span class="string">'./helpers'</span>
-SourceMap = require <span class="string">'./sourcemap'</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
+vm = <span class="hljs-built_in">require</span> <span class="hljs-string">'vm'</span>
+path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
+{Lexer} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./lexer'</span>
+{parser} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./parser'</span>
+helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
+SourceMap = <span class="hljs-built_in">require</span> <span class="hljs-string">'./sourcemap'</span></pre></div></div>
</li>
@@ -135,12 +137,13 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
- <p>The current CoffeeScript version number.
-</p>
+ <p>The current CoffeeScript version number.</p>
</div>
- <div class="content"><div class='highlight'><pre>exports.VERSION = <span class="string">'1.6.3'</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.VERSION = <span class="hljs-string">'1.7.1'</span>
+
+<span class="hljs-built_in">exports</span>.FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'</span>, <span class="hljs-string">'.litcoffee'</span>, <span class="hljs-string">'.coffee.md'</span>]</pre></div></div>
</li>
@@ -151,12 +154,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
- <p>Expose helpers for testing.
-</p>
+ <p>Expose helpers for testing.</p>
</div>
- <div class="content"><div class='highlight'><pre>exports.helpers = helpers</pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.helpers = helpers</pre></div></div>
</li>
@@ -167,162 +169,159 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
- <p>Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
+ <p>Function wrapper to add source file information to SyntaxErrors thrown by the
+lexer/parser/compiler.</p>
-</p>
+ </div>
+
+ <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">withPrettyErrors</span> = <span class="hljs-params">(fn)</span> -&gt;</span>
+ <span class="hljs-function"><span class="hljs-params">(code, options = {})</span> -&gt;</span>
+ <span class="hljs-keyword">try</span>
+ fn.call @, code, options
+ <span class="hljs-keyword">catch</span> err
+ <span class="hljs-keyword">throw</span> helpers.updateSyntaxError err, code, options.filename</pre></div></div>
+
+ </li>
+
+
+ <li id="section-5">
+ <div class="annotation">
+
+ <div class="pilwrap ">
+ <a class="pilcrow" href="#section-5">&#182;</a>
+ </div>
+ <p>Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.</p>
<p>If <code>options.sourceMap</code> is specified, then <code>options.filename</code> must also be specified. All
-options that can be passed to <code>SourceMap#generate</code> may also be passed here.
-
-</p>
+options that can be passed to <code>SourceMap#generate</code> may also be passed here.</p>
<p>This returns a javascript string, unless <code>options.sourceMap</code> is passed,
in which case this returns a <code>{js, v3SourceMap, sourceMap}</code>
object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for doing programatic
-lookups.
-</p>
+lookups.</p>
</div>
- <div class="content"><div class='highlight'><pre>exports.compile = <span class="function"><span class="title">compile</span></span> = (code, options = {}) -&gt;
- {merge} = helpers
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.compile = compile = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -&gt;</span>
+ {merge, extend} = helpers
+ options = extend {}, options
- <span class="keyword">if</span> options.sourceMap
- map = <span class="keyword">new</span> SourceMap
+ <span class="hljs-keyword">if</span> options.sourceMap
+ map = <span class="hljs-keyword">new</span> SourceMap
fragments = parser.parse(lexer.tokenize code, options).compileToFragments options
- currentLine = <span class="number">0</span>
- currentLine += <span class="number">1</span> <span class="keyword">if</span> options.header
- currentLine += <span class="number">1</span> <span class="keyword">if</span> options.shiftLine
- currentColumn = <span class="number">0</span>
- js = <span class="string">""</span>
- <span class="keyword">for</span> fragment <span class="keyword">in</span> fragments</pre></div></div>
+ currentLine = <span class="hljs-number">0</span>
+ currentLine += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> options.header
+ currentLine += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> options.shiftLine
+ currentColumn = <span class="hljs-number">0</span>
+ js = <span class="hljs-string">""</span>
+ <span class="hljs-keyword">for</span> fragment <span class="hljs-keyword">in</span> fragments</pre></div></div>
</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>Update the sourcemap with data from each fragment
-</p>
+ <p>Update the sourcemap with data from each fragment</p>
</div>
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> options.sourceMap
- <span class="keyword">if</span> fragment.locationData
+ <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> options.sourceMap
+ <span class="hljs-keyword">if</span> fragment.locationData
map.add(
[fragment.locationData.first_line, fragment.locationData.first_column]
[currentLine, currentColumn]
- {noReplace: <span class="literal">true</span>})
- newLines = helpers.count fragment.code, <span class="string">"\n"</span>
+ {<span class="hljs-attribute">noReplace</span>: <span class="hljs-literal">true</span>})
+ newLines = helpers.count fragment.code, <span class="hljs-string">"\n"</span>
currentLine += newLines
- currentColumn = fragment.code.length - (<span class="keyword">if</span> newLines <span class="keyword">then</span> fragment.code.lastIndexOf <span class="string">"\n"</span> <span class="keyword">else</span> <span class="number">0</span>)</pre></div></div>
+ <span class="hljs-keyword">if</span> newLines
+ currentColumn = fragment.code.length - (fragment.code.lastIndexOf(<span class="hljs-string">"\n"</span>) + <span class="hljs-number">1</span>)
+ <span class="hljs-keyword">else</span>
+ currentColumn += fragment.code.length</pre></div></div>
</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>Copy the code from each fragment into the final JavaScript.
-</p>
+ <p>Copy the code from each fragment into the final JavaScript.</p>
</div>
<div class="content"><div class='highlight'><pre> js += fragment.code
- <span class="keyword">if</span> options.header
- header = <span class="string">"Generated by CoffeeScript <span class="subst">#{@VERSION}</span>"</span>
- js = <span class="string">"// <span class="subst">#{header}</span>\n<span class="subst">#{js}</span>"</span>
+ <span class="hljs-keyword">if</span> options.header
+ header = <span class="hljs-string">"Generated by CoffeeScript <span class="hljs-subst">#{<span class="hljs-property">@VERSION</span>}</span>"</span>
+ js = <span class="hljs-string">"// <span class="hljs-subst">#{header}</span>\n<span class="hljs-subst">#{js}</span>"</span>
- <span class="keyword">if</span> options.sourceMap
+ <span class="hljs-keyword">if</span> options.sourceMap
answer = {js}
answer.sourceMap = map
answer.v3SourceMap = map.generate(options, code)
answer
- <span class="keyword">else</span>
+ <span class="hljs-keyword">else</span>
js</pre></div></div>
</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>Tokenize a string of CoffeeScript code, and return the array of tokens.
-</p>
+ <p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p>
</div>
- <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">tokens</span></span> = (code, options) -&gt;
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.tokens = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -&gt;</span>
lexer.tokenize code, options</pre></div></div>
</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>Parse a string of CoffeeScript code or an array of lexed tokens, and
return the AST. You can then compile it by calling <code>.compile()</code> on the root,
-or traverse it by using <code>.traverseChildren()</code> with a callback.
-</p>
+or traverse it by using <code>.traverseChildren()</code> with a callback.</p>
</div>
- <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">nodes</span></span> = (source, options) -&gt;
- <span class="keyword">if</span> <span class="keyword">typeof</span> source <span class="keyword">is</span> <span class="string">'string'</span>
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.nodes = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(source, options)</span> -&gt;</span>
+ <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> source <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
parser.parse lexer.tokenize source, options
- <span class="keyword">else</span>
+ <span class="hljs-keyword">else</span>
parser.parse source</pre></div></div>
</li>
- <li id="section-9">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-9">&#182;</a>
- </div>
- <p>Compile and execute a string of CoffeeScript (on the server), correctly
-setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.
-</p>
-
- </div>
-
- <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = (code, options = {}) -&gt;
- mainModule = require.main
- options.sourceMap ?= <span class="literal">true</span></pre></div></div>
-
- </li>
-
-
<li id="section-10">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a>
</div>
- <p>Set the filename.
-</p>
+ <p>Compile and execute a string of CoffeeScript (on the server), correctly
+setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.</p>
</div>
- <div class="content"><div class='highlight'><pre> mainModule.filename = process.argv[<span class="number">1</span>] =
- <span class="keyword">if</span> options.filename <span class="keyword">then</span> fs.realpathSync(options.filename) <span class="keyword">else</span> <span class="string">'.'</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">run</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
+ mainModule = <span class="hljs-built_in">require</span>.main</pre></div></div>
</li>
@@ -333,12 +332,12 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a>
</div>
- <p>Clear the module cache.
-</p>
+ <p>Set the filename.</p>
</div>
- <div class="content"><div class='highlight'><pre> mainModule.moduleCache <span class="keyword">and</span>= {}</pre></div></div>
+ <div class="content"><div class='highlight'><pre> mainModule.filename = process.argv[<span class="hljs-number">1</span>] =
+ <span class="hljs-keyword">if</span> options.filename <span class="hljs-keyword">then</span> fs.realpathSync(options.filename) <span class="hljs-keyword">else</span> <span class="hljs-string">'.'</span></pre></div></div>
</li>
@@ -349,12 +348,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a>
</div>
- <p>Assign paths for node_modules loading
-</p>
+ <p>Clear the module cache.</p>
</div>
- <div class="content"><div class='highlight'><pre> mainModule.paths = require(<span class="string">'module'</span>)._nodeModulePaths path.dirname fs.realpathSync options.filename <span class="keyword">or</span> <span class="string">'.'</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre> mainModule.moduleCache <span class="hljs-keyword">and</span>= {}</pre></div></div>
</li>
@@ -365,13 +363,15 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a>
</div>
- <p>Compile.
-</p>
+ <p>Assign paths for node_modules loading</p>
</div>
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="keyword">not</span> helpers.isCoffee(mainModule.filename) <span class="keyword">or</span> require.extensions
- answer = compile(code, options)</pre></div></div>
+ <div class="content"><div class='highlight'><pre> dir = <span class="hljs-keyword">if</span> options.filename
+ path.dirname fs.realpathSync options.filename
+ <span class="hljs-keyword">else</span>
+ fs.realpathSync <span class="hljs-string">'.'</span>
+ mainModule.paths = <span class="hljs-built_in">require</span>(<span class="hljs-string">'module'</span>)._nodeModulePaths dir</pre></div></div>
</li>
@@ -382,17 +382,15 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a>
</div>
- <p>Attach sourceMap object to sourceMaps[options.filename] so that
-it is accessible by Error.prepareStackTrace.
-</p>
+ <p>Compile.</p>
</div>
- <div class="content"><div class='highlight'><pre> <span class="keyword">do</span> patchStackTrace
- sourceMaps[mainModule.filename] = answer.sourceMap
- mainModule._compile answer.js, mainModule.filename
- <span class="keyword">else</span>
- mainModule._compile code, mainModule.filename</pre></div></div>
+ <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> helpers.isCoffee(mainModule.filename) <span class="hljs-keyword">or</span> <span class="hljs-built_in">require</span>.extensions
+ answer = compile code, options
+ code = answer.js ? answer
+
+ mainModule._compile code, mainModule.filename</pre></div></div>
</li>
@@ -404,25 +402,24 @@
<a class="pilcrow" href="#section-15">&#182;</a>
</div>
<p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
-The CoffeeScript REPL uses this to run the input.
-</p>
+The CoffeeScript REPL uses this to run the input.</p>
</div>
- <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">eval</span></span> = (code, options = {}) -&gt;
- <span class="keyword">return</span> <span class="keyword">unless</span> code = code.trim()
+ <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">eval</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
+ <span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> code = code.trim()
Script = vm.Script
- <span class="keyword">if</span> Script
- <span class="keyword">if</span> options.sandbox?
- <span class="keyword">if</span> options.sandbox <span class="keyword">instanceof</span> Script.createContext().constructor
+ <span class="hljs-keyword">if</span> Script
+ <span class="hljs-keyword">if</span> options.sandbox?
+ <span class="hljs-keyword">if</span> options.sandbox <span class="hljs-keyword">instanceof</span> Script.createContext().constructor
sandbox = options.sandbox
- <span class="keyword">else</span>
+ <span class="hljs-keyword">else</span>
sandbox = Script.createContext()
- sandbox[k] = v <span class="keyword">for</span> own k, v <span class="keyword">of</span> options.sandbox
- sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
- <span class="keyword">else</span>
- sandbox = global
- sandbox.__filename = options.filename || <span class="string">'eval'</span>
+ sandbox[k] = v <span class="hljs-keyword">for</span> own k, v <span class="hljs-keyword">of</span> options.sandbox
+ sandbox.<span class="hljs-built_in">global</span> = sandbox.root = sandbox.GLOBAL = sandbox
+ <span class="hljs-keyword">else</span>
+ sandbox = <span class="hljs-built_in">global</span>
+ sandbox.__filename = options.filename || <span class="hljs-string">'eval'</span>
sandbox.__dirname = path.dirname sandbox.__filename</pre></div></div>
</li>
@@ -434,17 +431,16 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</a>
</div>
- <p>define module/require only if they chose not to specify their own
-</p>
+ <p>define module/require only if they chose not to specify their own</p>
</div>
- <div class="content"><div class='highlight'><pre> <span class="keyword">unless</span> sandbox <span class="keyword">isnt</span> global <span class="keyword">or</span> sandbox.module <span class="keyword">or</span> sandbox.require
- Module = require <span class="string">'module'</span>
- sandbox.module = _module = <span class="keyword">new</span> Module(options.modulename || <span class="string">'eval'</span>)
- sandbox.require = <span class="function"><span class="title">_require</span></span> = (path) -&gt; Module._load path, _module, <span class="literal">true</span>
+ <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> sandbox <span class="hljs-keyword">isnt</span> <span class="hljs-built_in">global</span> <span class="hljs-keyword">or</span> sandbox.<span class="hljs-built_in">module</span> <span class="hljs-keyword">or</span> sandbox.<span class="hljs-built_in">require</span>
+ Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
+ sandbox.<span class="hljs-built_in">module</span> = _module = <span class="hljs-keyword">new</span> Module(options.modulename || <span class="hljs-string">'eval'</span>)
+ sandbox.<span class="hljs-built_in">require</span> = <span class="hljs-function"><span class="hljs-title">_require</span> = <span class="hljs-params">(path)</span> -&gt;</span> Module._load path, _module, <span class="hljs-literal">true</span>
_module.filename = sandbox.__filename
- _require[r] = require[r] <span class="keyword">for</span> r <span class="keyword">in</span> Object.getOwnPropertyNames require <span class="keyword">when</span> r <span class="keyword">isnt</span> <span class="string">'paths'</span></pre></div></div>
+ _require[r] = <span class="hljs-built_in">require</span>[r] <span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> Object.getOwnPropertyNames <span class="hljs-built_in">require</span> <span class="hljs-keyword">when</span> r <span class="hljs-keyword">isnt</span> <span class="hljs-string">'paths'</span></pre></div></div>
</li>
@@ -455,21 +451,30 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a>
</div>
- <p>use the same hack node currently uses for their own REPL
-</p>
+ <p>use the same hack node currently uses for their own REPL</p>
</div>
<div class="content"><div class='highlight'><pre> _require.paths = _module.paths = Module._nodeModulePaths process.cwd()
- _require.<span class="function"><span class="title">resolve</span></span> = (request) -&gt; Module._resolveFilename request, _module
+ _require.<span class="hljs-function"><span class="hljs-title">resolve</span> = <span class="hljs-params">(request)</span> -&gt;</span> Module._resolveFilename request, _module
o = {}
- o[k] = v <span class="keyword">for</span> own k, v <span class="keyword">of</span> options
- o.bare = <span class="literal">on</span> <span class="comment"># ensure return value</span>
+ o[k] = v <span class="hljs-keyword">for</span> own k, v <span class="hljs-keyword">of</span> options
+ o.bare = <span class="hljs-literal">on</span> <span class="hljs-comment"># ensure return value</span>
js = compile code, o
- <span class="keyword">if</span> sandbox <span class="keyword">is</span> global
+ <span class="hljs-keyword">if</span> sandbox <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
vm.runInThisContext js
- <span class="keyword">else</span>
- vm.runInContext js, sandbox</pre></div></div>
+ <span class="hljs-keyword">else</span>
+ vm.runInContext js, sandbox
+
+<span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">register</span> = -&gt;</span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./register'</span>
+
+<span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">_compileFile</span> = <span class="hljs-params">(filename, sourceMap = <span class="hljs-literal">no</span>)</span> -&gt;</span>
+ raw = fs.readFileSync filename, <span class="hljs-string">'utf8'</span>
+ stripped = <span class="hljs-keyword">if</span> raw.charCodeAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-number">0xFEFF</span> <span class="hljs-keyword">then</span> raw.substring <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> raw
+
+ <span class="hljs-keyword">try</span>
+ answer = compile(stripped, {filename, sourceMap, <span class="hljs-attribute">literate</span>: helpers.isLiterate filename})
+ <span class="hljs-keyword">catch</span> err</pre></div></div>
</li>
@@ -480,17 +485,15 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a>
</div>
- <p>Load and run a CoffeeScript file for Node, stripping any <code>BOM</code>s.
-</p>
+ <p>As the filename and code of a dynamically loaded file will be different
+from the original file compiled with CoffeeScript.run, add that
+information to error so it can be pretty-printed later.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="function"><span class="title">loadFile</span></span> = (module, filename) -&gt;
- raw = fs.readFileSync filename, <span class="string">'utf8'</span>
- stripped = <span class="keyword">if</span> raw.charCodeAt(<span class="number">0</span>) <span class="keyword">is</span> <span class="number">0xFEFF</span> <span class="keyword">then</span> raw.substring <span class="number">1</span> <span class="keyword">else</span> raw
- answer = compile(stripped, {filename, sourceMap: <span class="literal">true</span>, literate: helpers.isLiterate filename})
- sourceMaps[filename] = answer.sourceMap
- module._compile answer.js, filename</pre></div></div>
+ <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">throw</span> helpers.updateSyntaxError err, stripped, filename
+
+ answer</pre></div></div>
</li>
@@ -501,15 +504,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">&#182;</a>
</div>
- <p>If the installed version of Node supports <code>require.extensions</code>, register
-CoffeeScript as an extension.
-</p>
+ <p>Instantiate a Lexer for our use here.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="keyword">if</span> require.extensions
- <span class="keyword">for</span> ext <span class="keyword">in</span> [<span class="string">'.coffee'</span>, <span class="string">'.litcoffee'</span>, <span class="string">'.coffee.md'</span>]
- require.extensions[ext] = loadFile</pre></div></div>
+ <div class="content"><div class='highlight'><pre>lexer = <span class="hljs-keyword">new</span> Lexer</pre></div></div>
</li>
@@ -520,18 +519,27 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">&#182;</a>
</div>
- <p>Patch Node&#39;s module loader to be able to handle mult-dot extensions.
-This is a horrible thing that should not be required. Perhaps, one day,
-when a truly benevolent dictator comes to rule over the Republik of Node,
-it won&#39;t be.
-</p>
+ <p>The real Lexer produces a generic stream of tokens. This object provides a
+thin wrapper around it, compatible with the Jison API. We can then pass it
+directly as a &quot;Jison lexer&quot;.</p>
</div>
- <div class="content"><div class='highlight'><pre> Module = require <span class="string">'module'</span>
+ <div class="content"><div class='highlight'><pre>parser.lexer =
+ <span class="hljs-attribute">lex</span>:<span class="hljs-function"> -&gt;</span>
+ token = <span class="hljs-property">@tokens</span>[<span class="hljs-property">@pos</span>++]
+ <span class="hljs-keyword">if</span> token
+ [tag, <span class="hljs-property">@yytext</span>, <span class="hljs-property">@yylloc</span>] = token
+ <span class="hljs-property">@errorToken</span> = token.origin <span class="hljs-keyword">or</span> token
+ <span class="hljs-property">@yylineno</span> = <span class="hljs-property">@yylloc</span>.first_line
+ <span class="hljs-keyword">else</span>
+ tag = <span class="hljs-string">''</span>
- <span class="function"><span class="title">findExtension</span></span> = (filename) -&gt;
- extensions = path.basename(filename).split <span class="string">'.'</span></pre></div></div>
+ tag
+ <span class="hljs-attribute">setInput</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@tokens</span>)</span> -&gt;</span>
+ <span class="hljs-property">@pos</span> = <span class="hljs-number">0</span>
+ <span class="hljs-attribute">upcomingInput</span>:<span class="hljs-function"> -&gt;</span>
+ <span class="hljs-string">""</span></pre></div></div>
</li>
@@ -542,12 +550,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a>
</div>
- <p>Remove the initial dot from dotfiles.
-</p>
+ <p>Make all the AST nodes visible to the parser.</p>
</div>
- <div class="content"><div class='highlight'><pre> extensions.shift() <span class="keyword">if</span> extensions[<span class="number">0</span>] <span class="keyword">is</span> <span class="string">''</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre>parser.yy = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span></pre></div></div>
</li>
@@ -558,22 +565,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a>
</div>
- <p>Start with the longest possible extension and work our way shortwards.
-</p>
+ <p>Override Jison&#39;s default error handling function.</p>
</div>
- <div class="content"><div class='highlight'><pre> <span class="keyword">while</span> extensions.shift()
- curExtension = <span class="string">'.'</span> + extensions.join <span class="string">'.'</span>
- <span class="keyword">return</span> curExtension <span class="keyword">if</span> Module._extensions[curExtension]
- <span class="string">'.js'</span>
-
- Module::<span class="function"><span class="title">load</span></span> = (filename) -&gt;
- <span class="property">@filename</span> = filename
- <span class="property">@paths</span> = Module._nodeModulePaths path.dirname filename
- extension = findExtension filename
- Module._extensions[extension](<span class="keyword">this</span>, filename)
- <span class="property">@loaded</span> = <span class="literal">true</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre>parser.yy.<span class="hljs-function"><span class="hljs-title">parseError</span> = <span class="hljs-params">(message, {token})</span> -&gt;</span></pre></div></div>
</li>
@@ -584,21 +580,21 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a>
</div>
- <p>If we&#39;re on Node, patch <code>child_process.fork</code> so that Coffee scripts are able
-to fork both CoffeeScript files, and JavaScript files, directly.
-</p>
+ <p>Disregard Jison&#39;s message, it contains redundant line numer information.
+Disregard the token, we take its value directly from the lexer in case
+the error is caused by a generated token which might refer to its origin.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="keyword">if</span> child_process
- {fork} = child_process
- child_process.<span class="function"><span class="title">fork</span></span> = (path, args = [], options = {}) -&gt;
- execPath = <span class="keyword">if</span> helpers.isCoffee(path) <span class="keyword">then</span> <span class="string">'coffee'</span> <span class="keyword">else</span> <span class="literal">null</span>
- <span class="keyword">if</span> <span class="keyword">not</span> Array.isArray args
- args = []
- options = args <span class="keyword">or</span> {}
- options.execPath <span class="keyword">or</span>= execPath
- fork path, args, options</pre></div></div>
+ <div class="content"><div class='highlight'><pre> {errorToken, tokens} = parser.lexer
+ [errorTag, errorText, errorLoc] = errorToken
+
+ errorText = <span class="hljs-keyword">if</span> errorToken <span class="hljs-keyword">is</span> tokens[tokens.length - <span class="hljs-number">1</span>]
+ <span class="hljs-string">'end of input'</span>
+ <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'INDENT'</span>, <span class="hljs-string">'OUTDENT'</span>]
+ <span class="hljs-string">'indentation'</span>
+ <span class="hljs-keyword">else</span>
+ helpers.nameWhitespaceCharacter errorText</pre></div></div>
</li>
@@ -609,12 +605,14 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</a>
</div>
- <p>Instantiate a Lexer for our use here.
-</p>
+ <p>The second argument has a <code>loc</code> property, which should have the location
+data for this token. Unfortunately, Jison seems to send an outdated <code>loc</code>
+(from the previous token), so we take the location information directly
+from the lexer.</p>
</div>
- <div class="content"><div class='highlight'><pre>lexer = <span class="keyword">new</span> Lexer</pre></div></div>
+ <div class="content"><div class='highlight'><pre> helpers.throwSyntaxError <span class="hljs-string">"unexpected <span class="hljs-subst">#{errorText}</span>"</span>, errorLoc</pre></div></div>
</li>
@@ -625,27 +623,28 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">&#182;</a>
</div>
- <p>The real Lexer produces a generic stream of tokens. This object provides a
-thin wrapper around it, compatible with the Jison API. We can then pass it
-directly as a &quot;Jison lexer&quot;.
-</p>
+ <p>Based on <a href="http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js">http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js</a>
+Modified to handle sourceMap</p>
</div>
- <div class="content"><div class='highlight'><pre>parser.lexer =
- lex: -&gt;
- token = <span class="property">@tokens</span>[<span class="property">@pos</span>++]
- <span class="keyword">if</span> token
- [tag, <span class="property">@yytext</span>, <span class="property">@yylloc</span>] = token
- <span class="property">@yylineno</span> = <span class="property">@yylloc</span>.first_line
- <span class="keyword">else</span>
- tag = <span class="string">''</span>
+ <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">formatSourcePosition</span> = <span class="hljs-params">(frame, getSourceMapping)</span> -&gt;</span>
+ fileName = <span class="hljs-literal">undefined</span>
+ fileLocation = <span class="hljs-string">''</span>
- tag
- setInput: (<span class="property">@tokens</span>) -&gt;
- <span class="property">@pos</span> = <span class="number">0</span>
- upcomingInput: -&gt;
- <span class="string">""</span></pre></div></div>
+ <span class="hljs-keyword">if</span> frame.isNative()
+ fileLocation = <span class="hljs-string">"native"</span>
+ <span class="hljs-keyword">else</span>
+ <span class="hljs-keyword">if</span> frame.isEval()
+ fileName = frame.getScriptNameOrSourceURL()
+ fileLocation = <span class="hljs-string">"<span class="hljs-subst">#{frame.getEvalOrigin()}</span>, "</span> <span class="hljs-keyword">unless</span> fileName
+ <span class="hljs-keyword">else</span>
+ fileName = frame.getFileName()
+
+ fileName <span class="hljs-keyword">or</span>= <span class="hljs-string">"&lt;anonymous&gt;"</span>
+
+ line = frame.getLineNumber()
+ column = frame.getColumnNumber()</pre></div></div>
</li>
@@ -656,12 +655,41 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-26">&#182;</a>
</div>
- <p>Make all the AST nodes visible to the parser.
-</p>
+ <p>Check for a sourceMap position</p>
</div>
- <div class="content"><div class='highlight'><pre>parser.yy = require <span class="string">'./nodes'</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre> source = getSourceMapping fileName, line, column
+ fileLocation =
+ <span class="hljs-keyword">if</span> source
+ <span class="hljs-string">"<span class="hljs-subst">#{fileName}</span>:<span class="hljs-subst">#{source[<span class="hljs-number">0</span>]}</span>:<span class="hljs-subst">#{source[<span class="hljs-number">1</span>]}</span>"</span>
+ <span class="hljs-keyword">else</span>
+ <span class="hljs-string">"<span class="hljs-subst">#{fileName}</span>:<span class="hljs-subst">#{line}</span>:<span class="hljs-subst">#{column}</span>"</span>
+
+ functionName = frame.getFunctionName()
+ isConstructor = frame.isConstructor()
+ isMethodCall = <span class="hljs-keyword">not</span> (frame.isToplevel() <span class="hljs-keyword">or</span> isConstructor)
+
+ <span class="hljs-keyword">if</span> isMethodCall
+ methodName = frame.getMethodName()
+ typeName = frame.getTypeName()
+
+ <span class="hljs-keyword">if</span> functionName
+ tp = as = <span class="hljs-string">''</span>
+ <span class="hljs-keyword">if</span> typeName <span class="hljs-keyword">and</span> functionName.indexOf typeName
+ tp = <span class="hljs-string">"<span class="hljs-subst">#{typeName}</span>."</span>
+ <span class="hljs-keyword">if</span> methodName <span class="hljs-keyword">and</span> functionName.indexOf(<span class="hljs-string">".<span class="hljs-subst">#{methodName}</span>"</span>) <span class="hljs-keyword">isnt</span> functionName.length - methodName.length - <span class="hljs-number">1</span>
+ as = <span class="hljs-string">" [as <span class="hljs-subst">#{methodName}</span>]"</span>
+
+ <span class="hljs-string">"<span class="hljs-subst">#{tp}</span><span class="hljs-subst">#{functionName}</span><span class="hljs-subst">#{as}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
+ <span class="hljs-keyword">else</span>
+ <span class="hljs-string">"<span class="hljs-subst">#{typeName}</span>.<span class="hljs-subst">#{methodName <span class="hljs-keyword">or</span> <span class="hljs-string">'&lt;anonymous&gt;'</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
+ <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> isConstructor
+ <span class="hljs-string">"new <span class="hljs-subst">#{functionName <span class="hljs-keyword">or</span> <span class="hljs-string">'&lt;anonymous&gt;'</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
+ <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> functionName
+ <span class="hljs-string">"<span class="hljs-subst">#{functionName}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
+ <span class="hljs-keyword">else</span>
+ fileLocation</pre></div></div>
</li>
@@ -672,12 +700,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-27">&#182;</a>
</div>
- <p>Override Jison&#39;s default error handling function.
-</p>
+ <p>Map of filenames -&gt; sourceMap object.</p>
</div>
- <div class="content"><div class='highlight'><pre>parser.yy.<span class="function"><span class="title">parseError</span></span> = (message, {token}) -&gt;</pre></div></div>
+ <div class="content"><div class='highlight'><pre>sourceMaps = {}</pre></div></div>
</li>
@@ -688,12 +715,15 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-28">&#182;</a>
</div>
- <p>Disregard Jison&#39;s message, it contains redundant line numer information.
-</p>
+ <p>Generates the source map for a coffee file and stores it in the local cache variable.</p>
</div>
- <div class="content"><div class='highlight'><pre> message = <span class="string">"unexpected <span class="subst">#{<span class="keyword">if</span> token <span class="keyword">is</span> <span class="number">1</span> <span class="keyword">then</span> 'end <span class="keyword">of</span> input' <span class="keyword">else</span> token}</span>"</span></pre></div></div>
+ <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">getSourceMap</span> = <span class="hljs-params">(filename)</span> -&gt;</span>
+ <span class="hljs-keyword">return</span> sourceMaps[filename] <span class="hljs-keyword">if</span> sourceMaps[filename]
+ <span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> path?.extname(filename) <span class="hljs-keyword">in</span> <span class="hljs-built_in">exports</span>.FILE_EXTENSIONS
+ answer = <span class="hljs-built_in">exports</span>._compileFile filename, <span class="hljs-literal">true</span>
+ sourceMaps[filename] = answer.sourceMap</pre></div></div>
</li>
@@ -704,167 +734,24 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-29">&#182;</a>
</div>
- <p>The second argument has a <code>loc</code> property, which should have the location
-data for this token. Unfortunately, Jison seems to send an outdated <code>loc</code>
-(from the previous token), so we take the location information directly
-from the lexer.
-</p>
-
- </div>
-
- <div class="content"><div class='highlight'><pre> helpers.throwSyntaxError message, parser.lexer.yylloc</pre></div></div>
-
- </li>
-
-
- <li id="section-30">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-30">&#182;</a>
- </div>
<p>Based on <a href="http://goo.gl/ZTx1p">michaelficarra/CoffeeScriptRedux</a>
NodeJS / V8 have no support for transforming positions in stack traces using
sourceMap, so we must monkey-patch Error to display CoffeeScript source
-positions.
-</p>
-
- </div>
-
- <div class="content"><div class='highlight'><pre>
-patched = <span class="literal">false</span></pre></div></div>
-
- </li>
-
-
- <li id="section-31">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-31">&#182;</a>
- </div>
- <p>Map of filenames -&gt; sourceMap object.
-</p>
-
- </div>
-
- <div class="content"><div class='highlight'><pre>sourceMaps = {}
-
-<span class="function"><span class="title">patchStackTrace</span></span> = -&gt;
- <span class="keyword">return</span> <span class="keyword">if</span> patched
- patched = <span class="literal">true</span>
- mainModule = require.main</pre></div></div>
-
- </li>
-
-
- <li id="section-32">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-32">&#182;</a>
- </div>
- <p>(Assigning to a property of the Module object in the normal module cache is
-unsuitable, because node deletes those objects from the cache if an
-exception is thrown in the module body.)
-</p>
-
- </div>
-
- <div class="content"><div class='highlight'><pre>
- Error.<span class="function"><span class="title">prepareStackTrace</span></span> = (err, stack) -&gt;
- sourceFiles = {}
-
- <span class="function"><span class="title">getSourceMapping</span></span> = (filename, line, column) -&gt;
- sourceMap = sourceMaps[filename]
- answer = sourceMap.sourceLocation [line - <span class="number">1</span>, column - <span class="number">1</span>] <span class="keyword">if</span> sourceMap
- <span class="keyword">if</span> answer <span class="keyword">then</span> [answer[<span class="number">0</span>] + <span class="number">1</span>, answer[<span class="number">1</span>] + <span class="number">1</span>] <span class="keyword">else</span> <span class="literal">null</span>
-
- frames = <span class="keyword">for</span> frame <span class="keyword">in</span> stack
- <span class="keyword">break</span> <span class="keyword">if</span> frame.getFunction() <span class="keyword">is</span> exports.run
- <span class="string">" at <span class="subst">#{formatSourcePosition frame, getSourceMapping}</span>"</span>
-
- <span class="string">"<span class="subst">#{err.name}</span>: <span class="subst">#{err.message ? ''}</span>\n<span class="subst">#{frames.join '\n'}</span>\n"</span></pre></div></div>
-
- </li>
-
-
- <li id="section-33">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-33">&#182;</a>
- </div>
- <p>Based on <a href="http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js">http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js</a>
-Modified to handle sourceMap
-</p>
+positions.</p>
</div>
- <div class="content"><div class='highlight'><pre><span class="function"><span class="title">formatSourcePosition</span></span> = (frame, getSourceMapping) -&gt;
- fileName = <span class="literal">undefined</span>
- fileLocation = <span class="string">''</span>
-
- <span class="keyword">if</span> frame.isNative()
- fileLocation = <span class="string">"native"</span>
- <span class="keyword">else</span>
- <span class="keyword">if</span> frame.isEval()
- fileName = frame.getScriptNameOrSourceURL()
- fileLocation = <span class="string">"<span class="subst">#{frame.getEvalOrigin()}</span>, "</span> <span class="keyword">unless</span> fileName
- <span class="keyword">else</span>
- fileName = frame.getFileName()
+ <div class="content"><div class='highlight'><pre>Error.<span class="hljs-function"><span class="hljs-title">prepareStackTrace</span> = <span class="hljs-params">(err, stack)</span> -&gt;</span>
+ <span class="hljs-function"><span class="hljs-title">getSourceMapping</span> = <span class="hljs-params">(filename, line, column)</span> -&gt;</span>
+ sourceMap = getSourceMap filename
+ answer = sourceMap.sourceLocation [line - <span class="hljs-number">1</span>, column - <span class="hljs-number">1</span>] <span class="hljs-keyword">if</span> sourceMap
+ <span class="hljs-keyword">if</span> answer <span class="hljs-keyword">then</span> [answer[<span class="hljs-number">0</span>] + <span class="hljs-number">1</span>, answer[<span class="hljs-number">1</span>] + <span class="hljs-number">1</span>] <span class="hljs-keyword">else</span> <span class="hljs-literal">null</span>
- fileName <span class="keyword">or</span>= <span class="string">"&lt;anonymous&gt;"</span>
+ frames = <span class="hljs-keyword">for</span> frame <span class="hljs-keyword">in</span> stack
+ <span class="hljs-keyword">break</span> <span class="hljs-keyword">if</span> frame.getFunction() <span class="hljs-keyword">is</span> <span class="hljs-built_in">exports</span>.run
+ <span class="hljs-string">" at <span class="hljs-subst">#{formatSourcePosition frame, getSourceMapping}</span>"</span>
- line = frame.getLineNumber()
- column = frame.getColumnNumber()</pre></div></div>
-
- </li>
-
-
- <li id="section-34">
- <div class="annotation">
-
- <div class="pilwrap ">
- <a class="pilcrow" href="#section-34">&#182;</a>
- </div>
- <p>Check for a sourceMap position
-</p>
-
- </div>
-
- <div class="content"><div class='highlight'><pre> source = getSourceMapping fileName, line, column
- fileLocation =
- <span class="keyword">if</span> source
- <span class="string">"<span class="subst">#{fileName}</span>:<span class="subst">#{source[<span class="number">0</span>]}</span>:<span class="subst">#{source[<span class="number">1</span>]}</span>, &lt;js&gt;:<span class="subst">#{line}</span>:<span class="subst">#{column}</span>"</span>
- <span class="keyword">else</span>
- <span class="string">"<span class="subst">#{fileName}</span>:<span class="subst">#{line}</span>:<span class="subst">#{column}</span>"</span>
-
-
- functionName = frame.getFunctionName()
- isConstructor = frame.isConstructor()
- isMethodCall = <span class="keyword">not</span> (frame.isToplevel() <span class="keyword">or</span> isConstructor)
-
- <span class="keyword">if</span> isMethodCall
- methodName = frame.getMethodName()
- typeName = frame.getTypeName()
-
- <span class="keyword">if</span> functionName
- tp = as = <span class="string">''</span>
- <span class="keyword">if</span> typeName <span class="keyword">and</span> functionName.indexOf typeName
- tp = <span class="string">"<span class="subst">#{typeName}</span>."</span>
- <span class="keyword">if</span> methodName <span class="keyword">and</span> functionName.indexOf(<span class="string">".<span class="subst">#{methodName}</span>"</span>) <span class="keyword">isnt</span> functionName.length - methodName.length - <span class="number">1</span>
- as = <span class="string">" [as <span class="subst">#{methodName}</span>]"</span>
-
- <span class="string">"<span class="subst">#{tp}</span><span class="subst">#{functionName}</span><span class="subst">#{as}</span> (<span class="subst">#{fileLocation}</span>)"</span>
- <span class="keyword">else</span>
- <span class="string">"<span class="subst">#{typeName}</span>.<span class="subst">#{methodName <span class="keyword">or</span> '&lt;anonymous&gt;'}</span> (<span class="subst">#{fileLocation}</span>)"</span>
- <span class="keyword">else</span> <span class="keyword">if</span> isConstructor
- <span class="string">"new <span class="subst">#{functionName <span class="keyword">or</span> '&lt;anonymous&gt;'}</span> (<span class="subst">#{fileLocation}</span>)"</span>
- <span class="keyword">else</span> <span class="keyword">if</span> functionName
- <span class="string">"<span class="subst">#{functionName}</span> (<span class="subst">#{fileLocation}</span>)"</span>
- <span class="keyword">else</span>
- fileLocation</pre></div></div>
+ <span class="hljs-string">"<span class="hljs-subst">#{err.name}</span>: <span class="hljs-subst">#{err.message ? <span class="hljs-string">''</span>}</span>\n<span class="hljs-subst">#{frames.join <span class="hljs-string">'\n'</span>}</span>\n"</span></pre></div></div>
</li>
View
636 documentation/docs/command.html
@@ -69,6 +69,11 @@
</a>
+ <a class="source" href="register.html">
+ register.coffee
+ </a>
+
+
<a class="source" href="repl.html">
repl.coffee
</a>
@@ -112,11 +117,22 @@
into various forms: saved into <code>.js</code> files or printed to stdout
or recompiled every time the source is saved,
printed as a token stream or as the syntax tree, or launch an
-interactive REPL.
-</p>
+interactive REPL.</p>
+<p>External dependencies.</p>
</div>
+ <div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
+path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
+helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
+optparse = <span class="hljs-built_in">require</span> <span class="hljs-string">'./optparse'</span>
+CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span>
+mkdirp = <span class="hljs-built_in">require</span> <span class="hljs-string">'mkdirp'</span>
+{spawn, exec} = <span class="hljs-built_in">require</span> <span class="hljs-string">'child_process'</span>
+{EventEmitter} = <span class="hljs-built_in">require</span> <span class="hljs-string">'events'</span>
+
+useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs-string">'\\'</span></pre></div></div>
+
</li>
@@ -126,21 +142,16 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
- <p>External dependencies.
-</p>
+ <p>Allow CoffeeScript to emit Node.js events.</p>
</div>
- <div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
-path = require <span class="string">'path'</span>
-helpers = require <span class="string">'./helpers'</span>
-optparse = require <span class="string">'./optparse'</span>
-CoffeeScript = require <span class="string">'./coffee-script'</span>
-{spawn, exec} = require <span class="string">'child_process'</span>
-{EventEmitter} = require <span class="string">'events'</span>
+ <div class="content"><div class='highlight'><pre>helpers.extend CoffeeScript, <span class="hljs-keyword">new</span> EventEmitter
-exists = fs.exists <span class="keyword">or</span> path.exists
-useWinPathSep = path.sep <span class="keyword">is</span> <span class="string">'\\'</span></pre></div></div>
+<span class="hljs-function"><span class="hljs-title">printLine</span> = <span class="hljs-params">(line)</span> -&gt;</span> process.stdout.write line + <span class="hljs-string">'\n'</span>
+<span class="hljs-function"><span class="hljs-title">printWarn</span> = <span class="hljs-params">(line)</span> -&gt;</span> process.stderr.write line + <span class="hljs-string">'\n'</span>
+
+<span class="hljs-function"><span class="hljs-title">hidden</span> = <span class="hljs-params">(file)</span> -&gt;</span> <span class="hljs-regexp">/^\.|~$/</span>.test file</pre></div></div>
</li>
@@ -151,17 +162,15 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
- <p>Allow CoffeeScript to emit Node.js events.
-</p>
+ <p>The help banner that is printed in conjunction with <code>-h</code>/<code>--help</code>.</p>
</div>
- <div class="content"><div class='highlight'><pre>helpers.extend CoffeeScript, <span class="keyword">new</span> EventEmitter
-
-<span class="function"><span class="title">printLine</span></span> = (line) -&gt; process.stdout.write line + <span class="string">'\n'</span>
-<span class="function"><span class="title">printWarn</span></span> = (line) -&gt; process.stderr.write line + <span class="string">'\n'</span>