1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

CoffeeScript 1.6.2

This commit is contained in:
Jeremy Ashkenas 2013-03-18 13:06:33 +08:00
parent 4f815ea978
commit a3e8de338a
91 changed files with 8587 additions and 7766 deletions

View file

@ -1,4 +1,4 @@
Copyright (c) 2009-2012 Jeremy Ashkenas Copyright (c) 2009-2013 Jeremy Ashkenas
Permission is hereby granted, free of charge, to any person Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation obtaining a copy of this software and associated documentation

View file

@ -1,5 +1,5 @@
### ###
CoffeeScript Compiler v1.6.1 SkinnyMochaHalfCaffScript Compiler v1.0
Released under the MIT License Released under the MIT License
### ###

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>browser.coffee</h1> <h1>browser.coffee</h1>
@ -100,162 +101,184 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
<p>Override exported methods for non-Node.js engines. <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> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">&#39;./coffee-script&#39;</span> <div class="content"><div class='highlight'><pre>CoffeeScript = require <span class="string">'./coffee-script'</span>
<span class="nv">CoffeeScript.require = </span><span class="nx">require</span></pre></div></div> CoffeeScript.require = require
compile = CoffeeScript.compile</pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>Use standard JavaScript <code>eval</code> to eval code. <p>Use standard JavaScript <code>eval</code> to eval code.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript.eval = </span><span class="nf">(code, options = {}) -&gt;</span> <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">eval</span></span> = (code, options = {}) -&gt;
<span class="nx">options</span><span class="p">.</span><span class="nx">bare</span> <span class="o">?=</span> <span class="kc">on</span> options.bare ?= <span class="literal">on</span>
<span class="nb">eval</span> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span></pre></div></div> eval compile code, options</pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>Running code does not provide access to this scope. <p>Running code does not provide access to this scope.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript.run = </span><span class="nf">(code, options = {}) -&gt;</span> <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">run</span></span> = (code, options = {}) -&gt;
<span class="nv">options.bare = </span><span class="kc">on</span> options.bare = <span class="literal">on</span>
<span class="nb">Function</span><span class="p">(</span><span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)()</span></pre></div></div> Function(compile code, options)()</pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>If we&#39;re not in a browser environment, we&#39;re finished with the public API. <p>If we&#39;re not in a browser environment, we&#39;re finished with the public API.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="k">return</span> <span class="k">unless</span> <span class="nb">window</span><span class="o">?</span></pre></div></div> <div class="content"><div class='highlight'><pre><span class="keyword">return</span> <span class="keyword">unless</span> window?</pre></div></div>
</li> </li>
<li id="section-5"> <li id="section-5">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a> <a class="pilcrow" href="#section-5">&#182;</a>
</div> </div>
<p>Include source maps where possible. If we&#39;ve got a base64 encoder, and a
<p>Load a remote script from the current domain via XHR. JSON serializer, we&#39;re good to go.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript.load = </span><span class="nf">(url, callback, options = {}) -&gt;</span> <div class="content"><div class='highlight'><pre><span class="keyword">if</span> btoa? <span class="keyword">and</span> JSON?
<span class="nv">xhr = </span><span class="k">if</span> <span class="nb">window</span><span class="p">.</span><span class="nx">ActiveXObject</span> <span class="function"><span class="title">compile</span></span> = (code, options = {}) -&gt;
<span class="k">new</span> <span class="nb">window</span><span class="p">.</span><span class="nx">ActiveXObject</span><span class="p">(</span><span class="s">&#39;Microsoft.XMLHTTP&#39;</span><span class="p">)</span> options.sourceMap = <span class="literal">true</span>
<span class="k">else</span> options.inline = <span class="literal">true</span>
<span class="k">new</span> <span class="nx">XMLHttpRequest</span><span class="p">()</span> {js, v3SourceMap} = CoffeeScript.compile code, options
<span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span> <span class="s">&#39;GET&#39;</span><span class="p">,</span> <span class="nx">url</span><span class="p">,</span> <span class="kc">true</span> <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="nx">xhr</span><span class="p">.</span><span class="nx">overrideMimeType</span> <span class="s">&#39;text/plain&#39;</span> <span class="k">if</span> <span class="s">&#39;overrideMimeType&#39;</span> <span class="k">of</span> <span class="nx">xhr</span>
<span class="nv">xhr.onreadystatechange = </span><span class="nf">-&gt;</span>
<span class="k">if</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">is</span> <span class="mi">4</span>
<span class="k">if</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">status</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">200</span><span class="p">]</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">responseText</span><span class="p">,</span> <span class="nx">options</span>
<span class="k">else</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;Could not load </span><span class="si">#{</span><span class="nx">url</span><span class="si">}</span><span class="s">&quot;</span>
<span class="nx">callback</span><span class="p">()</span> <span class="k">if</span> <span class="nx">callback</span>
<span class="nx">xhr</span><span class="p">.</span><span class="nx">send</span> <span class="kc">null</span></pre></div></div>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<p>Load a remote script from the current domain via XHR.
<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> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">runScripts = </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">load</span></span> = (url, callback, options = {}) -&gt;
<span class="nv">scripts = </span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span> <span class="s">&#39;script&#39;</span> options.sourceFiles = [url]
<span class="nv">coffeetypes = </span><span class="p">[</span><span class="s">&#39;text/coffeescript&#39;</span><span class="p">,</span> <span class="s">&#39;text/literate-coffeescript&#39;</span><span class="p">]</span> xhr = <span class="keyword">if</span> window.ActiveXObject
<span class="nv">coffees = </span><span class="p">(</span><span class="nx">s</span> <span class="k">for</span> <span class="nx">s</span> <span class="k">in</span> <span class="nx">scripts</span> <span class="k">when</span> <span class="nx">s</span><span class="p">.</span><span class="nx">type</span> <span class="k">in</span> <span class="nx">coffeetypes</span><span class="p">)</span> <span class="keyword">new</span> window.ActiveXObject(<span class="string">'Microsoft.XMLHTTP'</span>)
<span class="nv">index = </span><span class="mi">0</span> <span class="keyword">else</span>
<span class="nv">length = </span><span class="nx">coffees</span><span class="p">.</span><span class="nx">length</span> <span class="keyword">new</span> XMLHttpRequest()
<span class="nx">do</span> <span class="nv">execute = </span><span class="nf">-&gt;</span> xhr.open <span class="string">'GET'</span>, url, <span class="literal">true</span>
<span class="nv">script = </span><span class="nx">coffees</span><span class="p">[</span><span class="nx">index</span><span class="o">++</span><span class="p">]</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
<span class="nv">mediatype = </span><span class="nx">script</span><span class="o">?</span><span class="p">.</span><span class="nx">type</span> xhr.<span class="function"><span class="title">onreadystatechange</span></span> = -&gt;
<span class="k">if</span> <span class="nx">mediatype</span> <span class="k">in</span> <span class="nx">coffeetypes</span> <span class="keyword">if</span> xhr.readyState <span class="keyword">is</span> <span class="number">4</span>
<span class="nv">options = </span><span class="p">{</span><span class="nv">literate: </span><span class="nx">mediatype</span> <span class="o">is</span> <span class="s">&#39;text/literate-coffeescript&#39;</span><span class="p">}</span> <span class="keyword">if</span> xhr.status <span class="keyword">in</span> [<span class="number">0</span>, <span class="number">200</span>]
<span class="k">if</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span> CoffeeScript.run xhr.responseText, options
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">load</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span><span class="p">,</span> <span class="nx">execute</span><span class="p">,</span> <span class="nx">options</span> <span class="keyword">else</span>
<span class="k">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>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">script</span><span class="p">.</span><span class="nx">innerHTML</span><span class="p">,</span> <span class="nx">options</span> callback() <span class="keyword">if</span> callback
<span class="nx">execute</span><span class="p">()</span> xhr.send <span class="literal">null</span></pre></div></div>
<span class="kc">null</span></pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Activate CoffeeScript in the browser by having it compile and evaluate
<p>Listen for window load, both in browsers and in IE. all script tags with a content-type of <code>text/coffeescript</code>.
This happens on page load.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="k">if</span> <span class="nb">window</span><span class="p">.</span><span class="nx">addEventListener</span> <div class="content"><div class='highlight'><pre><span class="function"><span class="title">runScripts</span></span> = -&gt;
<span class="nx">addEventListener</span> <span class="s">&#39;DOMContentLoaded&#39;</span><span class="p">,</span> <span class="nx">runScripts</span><span class="p">,</span> <span class="kc">no</span> scripts = document.getElementsByTagName <span class="string">'script'</span>
<span class="k">else</span> coffeetypes = [<span class="string">'text/coffeescript'</span>, <span class="string">'text/literate-coffeescript'</span>]
<span class="nx">attachEvent</span> <span class="s">&#39;onload&#39;</span><span class="p">,</span> <span class="nx">runScripts</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>
</pre></div></div> </li>
<li id="section-8">
<div class="annotation">
<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>
</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>
<span class="keyword">else</span>
attachEvent <span class="string">'onload'</span>, runScripts</pre></div></div>
</li> </li>

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>cake.coffee</h1> <h1>cake.coffee</h1>
@ -100,8 +101,10 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
@ -116,216 +119,205 @@ current directory&#39;s Cakefile.
</p> </p>
<p>External dependencies. <p>External dependencies.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s">&#39;fs&#39;</span> <div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
<span class="nv">path = </span><span class="nx">require</span> <span class="s">&#39;path&#39;</span> path = require <span class="string">'path'</span>
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s">&#39;./helpers&#39;</span> helpers = require <span class="string">'./helpers'</span>
<span class="nv">optparse = </span><span class="nx">require</span> <span class="s">&#39;./optparse&#39;</span> optparse = require <span class="string">'./optparse'</span>
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">&#39;./coffee-script&#39;</span> CoffeeScript = require <span class="string">'./coffee-script'</span>
<span class="nv">existsSync = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">existsSync</span> <span class="o">or</span> <span class="nx">path</span><span class="p">.</span><span class="nx">existsSync</span></pre></div></div> existsSync = fs.existsSync <span class="keyword">or</span> path.existsSync</pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>Keep track of the list of defined tasks, the accepted options, and so on. <p>Keep track of the list of defined tasks, the accepted options, and so on.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">tasks = </span><span class="p">{}</span> <div class="content"><div class='highlight'><pre>tasks = {}
<span class="nv">options = </span><span class="p">{}</span> options = {}
<span class="nv">switches = </span><span class="p">[]</span> switches = []
<span class="nv">oparse = </span><span class="kc">null</span></pre></div></div> oparse = <span class="literal">null</span></pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>Mixin the top-level Cake functions for Cakefiles to use directly. <p>Mixin the top-level Cake functions for Cakefiles to use directly.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nx">helpers</span><span class="p">.</span><span class="nx">extend</span> <span class="nx">global</span><span class="p">,</span></pre></div></div> <div class="content"><div class='highlight'><pre>helpers.extend global,</pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>Define a Cake task with a short name, an optional sentence description, <p>Define a Cake task with a short name, an optional sentence description,
and the function to run as the action itself. and the function to run as the action itself.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">task: </span><span class="nf">(name, description, action) -&gt;</span> <div class="content"><div class='highlight'><pre> task: (name, description, action) -&gt;
<span class="p">[</span><span class="nx">action</span><span class="p">,</span> <span class="nx">description</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">description</span><span class="p">,</span> <span class="nx">action</span><span class="p">]</span> <span class="k">unless</span> <span class="nx">action</span> [action, description] = [description, action] <span class="keyword">unless</span> action
<span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nx">name</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nx">action</span><span class="p">}</span></pre></div></div> tasks[name] = {name, description, action}</pre></div></div>
</li> </li>
<li id="section-5"> <li id="section-5">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a> <a class="pilcrow" href="#section-5">&#182;</a>
</div> </div>
<p>Define an option that the Cakefile accepts. The parsed options hash, <p>Define an option that the Cakefile accepts. The parsed options hash,
containing all of the command-line options passed, will be made available containing all of the command-line options passed, will be made available
as the first argument to the action. as the first argument to the action.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">option: </span><span class="nf">(letter, flag, description) -&gt;</span> <div class="content"><div class='highlight'><pre> option: (letter, flag, description) -&gt;
<span class="nx">switches</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="nx">letter</span><span class="p">,</span> <span class="nx">flag</span><span class="p">,</span> <span class="nx">description</span><span class="p">]</span></pre></div></div> switches.push [letter, flag, description]</pre></div></div>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<p>Invoke another task in the current Cakefile. <p>Invoke another task in the current Cakefile.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">invoke: </span><span class="nf">(name) -&gt;</span> <div class="content"><div class='highlight'><pre> invoke: (name) -&gt;
<span class="nx">missingTask</span> <span class="nx">name</span> <span class="k">unless</span> <span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> missingTask name <span class="keyword">unless</span> tasks[name]
<span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">].</span><span class="nx">action</span> <span class="nx">options</span></pre></div></div> tasks[name].action options</pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node&#39;s <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. 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 If no tasks are passed, print the help screen. Keep a reference to the
original directory name, when running Cake tasks from subdirectories. original directory name, when running Cake tasks from subdirectories.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.run = </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = -&gt;
<span class="nv">global.__originalDirname = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span> <span class="s">&#39;.&#39;</span> global.__originalDirname = fs.realpathSync <span class="string">'.'</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">chdir</span> <span class="nx">cakefileDirectory</span> <span class="nx">__originalDirname</span> process.chdir cakefileDirectory __originalDirname
<span class="nv">args = </span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">..]</span> args = process.argv[<span class="number">2.</span>.]
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="s">&#39;Cakefile&#39;</span><span class="p">).</span><span class="nx">toString</span><span class="p">(),</span> <span class="nv">filename: </span><span class="s">&#39;Cakefile&#39;</span> CoffeeScript.run fs.readFileSync(<span class="string">'Cakefile'</span>).toString(), filename: <span class="string">'Cakefile'</span>
<span class="nv">oparse = </span><span class="k">new</span> <span class="nx">optparse</span><span class="p">.</span><span class="nx">OptionParser</span> <span class="nx">switches</span> oparse = <span class="keyword">new</span> optparse.OptionParser switches
<span class="k">return</span> <span class="nx">printTasks</span><span class="p">()</span> <span class="k">unless</span> <span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="keyword">return</span> printTasks() <span class="keyword">unless</span> args.length
<span class="k">try</span> <span class="keyword">try</span>
<span class="nv">options = </span><span class="nx">oparse</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">args</span><span class="p">)</span> options = oparse.parse(args)
<span class="k">catch</span> <span class="nx">e</span> <span class="keyword">catch</span> e
<span class="k">return</span> <span class="nx">fatalError</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">e</span><span class="si">}</span><span class="s">&quot;</span> <span class="keyword">return</span> fatalError <span class="string">"<span class="subst">#{e}</span>"</span>
<span class="nx">invoke</span> <span class="nx">arg</span> <span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span></pre></div></div> invoke arg <span class="keyword">for</span> arg <span class="keyword">in</span> options.arguments</pre></div></div>
</li> </li>
<li id="section-8"> <li id="section-8">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a> <a class="pilcrow" href="#section-8">&#182;</a>
</div> </div>
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code> <p>Display the list of Cake tasks in a format similar to <code>rake -T</code>
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">printTasks = </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre><span class="function"><span class="title">printTasks</span></span> = -&gt;
<span class="nv">relative = </span><span class="nx">path</span><span class="p">.</span><span class="nx">relative</span> <span class="o">or</span> <span class="nx">path</span><span class="p">.</span><span class="nx">resolve</span> relative = path.relative <span class="keyword">or</span> path.resolve
<span class="nv">cakefilePath = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">relative</span><span class="p">(</span><span class="nx">__originalDirname</span><span class="p">,</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()),</span> <span class="s">&#39;Cakefile&#39;</span> cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="string">'Cakefile'</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">cakefilePath</span><span class="si">}</span><span class="s"> defines the following tasks:\n&quot;</span> console.log <span class="string">"<span class="subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
<span class="k">for</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">task</span> <span class="k">of</span> <span class="nx">tasks</span> <span class="keyword">for</span> name, task <span class="keyword">of</span> tasks
<span class="nv">spaces = </span><span class="mi">20</span> <span class="o">-</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span> spaces = <span class="number">20</span> - name.length
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">then</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">spaces</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">)</span> <span class="k">else</span> <span class="s">&#39;&#39;</span> 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>
<span class="nv">desc = </span><span class="k">if</span> <span class="nx">task</span><span class="p">.</span><span class="nx">description</span> <span class="k">then</span> <span class="s">&quot;</span><span class="err">#</span><span class="s"> </span><span class="si">#{</span><span class="nx">task</span><span class="p">.</span><span class="nx">description</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">else</span> <span class="s">&#39;&#39;</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>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">&quot;cake </span><span class="si">#{</span><span class="nx">name</span><span class="si">}#{</span><span class="nx">spaces</span><span class="si">}</span><span class="s"> </span><span class="si">#{</span><span class="nx">desc</span><span class="si">}</span><span class="s">&quot;</span> console.log <span class="string">"cake <span class="subst">#{name}</span><span class="subst">#{spaces}</span> <span class="subst">#{desc}</span>"</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">oparse</span><span class="p">.</span><span class="nx">help</span><span class="p">()</span> <span class="k">if</span> <span class="nx">switches</span><span class="p">.</span><span class="nx">length</span></pre></div></div> console.log oparse.help() <span class="keyword">if</span> switches.length</pre></div></div>
</li> </li>
<li id="section-9"> <li id="section-9">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a> <a class="pilcrow" href="#section-9">&#182;</a>
</div> </div>
<p>Print an error and exit when attempting to use an invalid task/option. <p>Print an error and exit when attempting to use an invalid task/option.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">fatalError = </span><span class="nf">(message) -&gt;</span> <div class="content"><div class='highlight'><pre><span class="function"><span class="title">fatalError</span></span> = (message) -&gt;
<span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="nx">message</span> <span class="o">+</span> <span class="s">&#39;\n&#39;</span> console.error message + <span class="string">'\n'</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">&#39;To see a list of all tasks/options, run &quot;cake&quot;&#39;</span> console.log <span class="string">'To see a list of all tasks/options, run "cake"'</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">1</span> process.exit <span class="number">1</span>
<span class="nv">missingTask = </span><span class="nf">(task) -&gt;</span> <span class="nx">fatalError</span> <span class="s">&quot;No such task: </span><span class="si">#{</span><span class="nx">task</span><span class="si">}</span><span class="s">&quot;</span></pre></div></div> <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>
</li> </li>
<li id="section-10"> <li id="section-10">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a> <a class="pilcrow" href="#section-10">&#182;</a>
</div> </div>
<p>When <code>cake</code> is invoked, search in the current and all parent directories <p>When <code>cake</code> is invoked, search in the current and all parent directories
to find the relevant Cakefile. to find the relevant Cakefile.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">cakefileDirectory = </span><span class="nf">(dir) -&gt;</span> <div class="content"><div class='highlight'><pre><span class="function"><span class="title">cakefileDirectory</span></span> = (dir) -&gt;
<span class="k">return</span> <span class="nx">dir</span> <span class="k">if</span> <span class="nx">existsSync</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">dir</span><span class="p">,</span> <span class="s">&#39;Cakefile&#39;</span> <span class="keyword">return</span> dir <span class="keyword">if</span> existsSync path.join dir, <span class="string">'Cakefile'</span>
<span class="nv">parent = </span><span class="nx">path</span><span class="p">.</span><span class="nx">normalize</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">dir</span><span class="p">,</span> <span class="s">&#39;..&#39;</span> parent = path.normalize path.join dir, <span class="string">'..'</span>
<span class="k">return</span> <span class="nx">cakefileDirectory</span> <span class="nx">parent</span> <span class="k">unless</span> <span class="nx">parent</span> <span class="o">is</span> <span class="nx">dir</span> <span class="keyword">return</span> cakefileDirectory parent <span class="keyword">unless</span> parent <span class="keyword">is</span> dir
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;Cakefile not found in </span><span class="si">#{</span><span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()</span><span class="si">}</span><span class="s">&quot;</span> <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>
</pre></div></div>
</li> </li>

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>coffee-script.coffee</h1> <h1>coffee-script.coffee</h1>
@ -100,100 +101,72 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
<p>CoffeeScript can be used both on the server, as a command-line compiler based <p>CoffeeScript can be used both on the server, as a command-line compiler based
on Node.js/V8, or to run CoffeeScripts directly in the browser. This module on Node.js/V8, or to run CoffeeScript directly in the browser. This module
contains the main entry functions for tokenizing, parsing, and compiling contains the main entry functions for tokenizing, parsing, and compiling
source CoffeeScript into JavaScript. source CoffeeScript into JavaScript.
</p>
<p>If included on a webpage, it will automatically sniff out, compile, and
execute all scripts present in <code>text/coffeescript</code> tags.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s">&#39;fs&#39;</span> <div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
<span class="nv">path = </span><span class="nx">require</span> <span class="s">&#39;path&#39;</span> vm = require <span class="string">'vm'</span>
<span class="p">{</span><span class="nx">Lexer</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">&#39;./lexer&#39;</span> path = require <span class="string">'path'</span>
<span class="p">{</span><span class="nx">parser</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">&#39;./parser&#39;</span> child_process = require <span class="string">'child_process'</span>
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s">&#39;./helpers&#39;</span> {Lexer} = require <span class="string">'./lexer'</span>
<span class="nv">vm = </span><span class="nx">require</span> <span class="s">&#39;vm&#39;</span> {parser} = require <span class="string">'./parser'</span>
<span class="nv">sourcemap = </span><span class="nx">require</span> <span class="s">&#39;./sourcemap&#39;</span></pre></div></div> helpers = require <span class="string">'./helpers'</span>
sourcemap = require <span class="string">'./sourcemap'</span></pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>The current CoffeeScript version number.
<p>Load and run a CoffeeScript file for Node, stripping any <code>BOM</code>s.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">loadFile = </span><span class="nf">(module, filename) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.VERSION = <span class="string">'1.6.2'</span></pre></div></div>
<span class="nv">raw = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span> <span class="nx">filename</span><span class="p">,</span> <span class="s">&#39;utf8&#39;</span>
<span class="nv">stripped = </span><span class="k">if</span> <span class="nx">raw</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">is</span> <span class="mh">0xFEFF</span> <span class="k">then</span> <span class="nx">raw</span><span class="p">.</span><span class="nx">substring</span> <span class="mi">1</span> <span class="k">else</span> <span class="nx">raw</span>
<span class="nx">module</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">compile</span><span class="p">(</span><span class="nx">stripped</span><span class="p">,</span> <span class="p">{</span><span class="nx">filename</span><span class="p">,</span> <span class="nv">literate: </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">isLiterate</span> <span class="nx">filename</span><span class="p">}),</span> <span class="nx">filename</span>
<span class="k">if</span> <span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span>
<span class="k">for</span> <span class="nx">ext</span> <span class="k">in</span> <span class="p">[</span><span class="s">&#39;.coffee&#39;</span><span class="p">,</span> <span class="s">&#39;.litcoffee&#39;</span><span class="p">,</span> <span class="s">&#39;.md&#39;</span><span class="p">,</span> <span class="s">&#39;.coffee.md&#39;</span><span class="p">]</span>
<span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span><span class="p">[</span><span class="nx">ext</span><span class="p">]</span> <span class="o">=</span> <span class="nx">loadFile</span></pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>Expose helpers for testing.
<p>The current CoffeeScript version number.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.VERSION = </span><span class="s">&#39;1.6.1&#39;</span></pre></div></div> <div class="content"><div class='highlight'><pre>exports.helpers = helpers</pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>Expose helpers for testing.
</p>
</div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.helpers = </span><span class="nx">helpers</span></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>Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
</p> </p>
@ -205,401 +178,466 @@ options that can be passed to <code>generateV3SourceMap()</code> may also be pas
in which case this returns a `{js, v3SourceMap, sourceMap} in which case this returns a `{js, v3SourceMap, sourceMap}
object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for doing programatic object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for doing programatic
lookups. lookups.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.compile = compile = </span><span class="nf">(code, options = {}) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.compile = <span class="function"><span class="title">compile</span></span> = (code, options = {}) -&gt;
<span class="p">{</span><span class="nx">merge</span><span class="p">}</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">helpers</span> {merge} = exports.helpers
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sourceMap</span> <span class="keyword">if</span> options.sourceMap
<span class="nv">sourceMap = </span><span class="k">new</span> <span class="nx">sourcemap</span><span class="p">.</span><span class="nx">SourceMap</span><span class="p">()</span> sourceMap = <span class="keyword">new</span> sourcemap.SourceMap()
<span class="nv">fragments = </span><span class="p">(</span><span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)).</span><span class="nx">compileToFragments</span> <span class="nx">options</span> fragments = (parser.parse lexer.tokenize(code, options)).compileToFragments options
<span class="nv">currentLine = </span><span class="mi">0</span> currentLine = <span class="number">0</span>
<span class="nx">currentLine</span> <span class="o">+=</span> <span class="mi">1</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">header</span> currentLine += <span class="number">1</span> <span class="keyword">if</span> options.header <span class="keyword">or</span> options.inline
<span class="nv">currentColumn = </span><span class="mi">0</span> currentColumn = <span class="number">0</span>
<span class="nv">js = </span><span class="s">&quot;&quot;</span> js = <span class="string">""</span>
<span class="k">for</span> <span class="nx">fragment</span> <span class="k">in</span> <span class="nx">fragments</span></pre></div></div> <span class="keyword">for</span> fragment <span class="keyword">in</span> fragments</pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Update the sourcemap with data from each fragment
</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">if</span> sourceMap
<span class="keyword">if</span> fragment.locationData
sourceMap.addMapping(
[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>
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>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<p>Copy the code from each fragment into the final JavaScript.
<p>Update the sourcemap with data from each fragment
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">if</span> <span class="nx">sourceMap</span> <div class="content"><div class='highlight'><pre> js += fragment.code
<span class="k">if</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">locationData</span>
<span class="nx">sourceMap</span><span class="p">.</span><span class="nx">addMapping</span><span class="p">(</span> <span class="keyword">if</span> options.header
<span class="p">[</span><span class="nx">fragment</span><span class="p">.</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_line</span><span class="p">,</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_column</span><span class="p">],</span> header = <span class="string">"Generated by CoffeeScript <span class="subst">#{@VERSION}</span>"</span>
<span class="p">[</span><span class="nx">currentLine</span><span class="p">,</span> <span class="nx">currentColumn</span><span class="p">],</span> js = <span class="string">"// <span class="subst">#{header}</span>\n<span class="subst">#{js}</span>"</span>
<span class="p">{</span><span class="nv">noReplace: </span><span class="kc">true</span><span class="p">})</span>
<span class="nv">newLines = </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">count</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span><span class="p">,</span> <span class="s">&quot;\n&quot;</span> <span class="keyword">if</span> options.sourceMap
<span class="nx">currentLine</span> <span class="o">+=</span> <span class="nx">newLines</span> answer = {js}
<span class="nv">currentColumn = </span><span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="p">(</span><span class="k">if</span> <span class="nx">newLines</span> <span class="k">then</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span><span class="p">.</span><span class="nx">lastIndexOf</span> <span class="s">&quot;\n&quot;</span> <span class="k">else</span> <span class="mi">0</span><span class="p">)</span></pre></div></div> <span class="keyword">if</span> sourceMap
answer.sourceMap = sourceMap
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, options, code)
answer
<span class="keyword">else</span>
js</pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Tokenize a string of CoffeeScript code, and return the array of tokens.
<p>Copy the code from each fragment into the final JavaScript.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">js</span> <span class="o">+=</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">tokens</span></span> = (code, options) -&gt;
lexer.tokenize code, options</pre></div></div>
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">header</span>
<span class="nv">header = </span><span class="s">&quot;Generated by CoffeeScript </span><span class="si">#{</span><span class="nx">@VERSION</span><span class="si">}</span><span class="s">&quot;</span>
<span class="nv">js = </span><span class="s">&quot;// </span><span class="si">#{</span><span class="nx">header</span><span class="si">}</span><span class="s">\n</span><span class="si">#{</span><span class="nx">js</span><span class="si">}</span><span class="s">&quot;</span>
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sourceMap</span>
<span class="nv">answer = </span><span class="p">{</span><span class="nx">js</span><span class="p">}</span>
<span class="k">if</span> <span class="nx">sourceMap</span>
<span class="nv">answer.sourceMap = </span><span class="nx">sourceMap</span>
<span class="nv">answer.v3SourceMap = </span><span class="nx">sourcemap</span><span class="p">.</span><span class="nx">generateV3SourceMap</span><span class="p">(</span><span class="nx">sourceMap</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span>
<span class="nx">answer</span>
<span class="k">else</span>
<span class="nx">js</span></pre></div></div>
</li> </li>
<li id="section-8"> <li id="section-8">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a> <a class="pilcrow" href="#section-8">&#182;</a>
</div> </div>
<p>Parse a string of CoffeeScript code or an array of lexed tokens, and
<p>Tokenize a string of CoffeeScript code, and return the array of tokens. 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> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.tokens = </span><span class="nf">(code, options) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">nodes</span></span> = (source, options) -&gt;
<span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span></pre></div></div> <span class="keyword">if</span> <span class="keyword">typeof</span> source <span class="keyword">is</span> <span class="string">'string'</span>
parser.parse lexer.tokenize source, options
<span class="keyword">else</span>
parser.parse source</pre></div></div>
</li> </li>
<li id="section-9"> <li id="section-9">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a> <a class="pilcrow" href="#section-9">&#182;</a>
</div> </div>
<p>Compile and execute a string of CoffeeScript (on the server), correctly
<p>Parse a string of CoffeeScript code or an array of lexed tokens, and setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.
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> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.nodes = </span><span class="nf">(source, options) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = (code, options = {}) -&gt;
<span class="k">if</span> <span class="k">typeof</span> <span class="nx">source</span> <span class="o">is</span> <span class="s">&#39;string&#39;</span> mainModule = require.main
<span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">source</span><span class="p">,</span> <span class="nx">options</span> options.sourceMap ?= <span class="literal">true</span></pre></div></div>
<span class="k">else</span>
<span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">source</span></pre></div></div>
</li> </li>
<li id="section-10"> <li id="section-10">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a> <a class="pilcrow" href="#section-10">&#182;</a>
</div> </div>
<p>Set the filename.
<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> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.run = </span><span class="nf">(code, options = {}) -&gt;</span> <div class="content"><div class='highlight'><pre> mainModule.filename = process.argv[<span class="number">1</span>] =
<span class="nv">mainModule = </span><span class="nx">require</span><span class="p">.</span><span class="nx">main</span></pre></div></div> <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>
</li> </li>
<li id="section-11"> <li id="section-11">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a> <a class="pilcrow" href="#section-11">&#182;</a>
</div> </div>
<p>Clear the module cache.
<p>Set the filename.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">mainModule.filename = </span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <div class="content"><div class='highlight'><pre> mainModule.moduleCache <span class="keyword">and</span>= {}</pre></div></div>
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">filename</span> <span class="k">then</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">filename</span><span class="p">)</span> <span class="k">else</span> <span class="s">&#39;.&#39;</span></pre></div></div>
</li> </li>
<li id="section-12"> <li id="section-12">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a> <a class="pilcrow" href="#section-12">&#182;</a>
</div> </div>
<p>Assign paths for node_modules loading
<p>Clear the module cache.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">mainModule</span><span class="p">.</span><span class="nx">moduleCache</span> <span class="o">and=</span> <span class="p">{}</span></pre></div></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>
</li> </li>
<li id="section-13"> <li id="section-13">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a> <a class="pilcrow" href="#section-13">&#182;</a>
</div> </div>
<p>Compile.
<p>Assign paths for node_modules loading
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">mainModule.paths = </span><span class="nx">require</span><span class="p">(</span><span class="s">&#39;module&#39;</span><span class="p">).</span><span class="nx">_nodeModulePaths</span> <span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span> <span class="nx">options</span><span class="p">.</span><span class="nx">filename</span></pre></div></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>
</li> </li>
<li id="section-14"> <li id="section-14">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a> <a class="pilcrow" href="#section-14">&#182;</a>
</div> </div>
<p>Attach sourceMap object to mainModule._sourceMaps[options.filename] so that
<p>Compile. it is accessible by Error.prepareStackTrace.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">if</span> <span class="o">not</span> <span class="nx">helpers</span><span class="p">.</span><span class="nx">isCoffee</span><span class="p">(</span><span class="nx">mainModule</span><span class="p">.</span><span class="nx">filename</span><span class="p">)</span> <span class="o">or</span> <span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span> <div class="content"><div class='highlight'><pre> <span class="keyword">do</span> patchStackTrace
<span class="nx">mainModule</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">compile</span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">),</span> <span class="nx">mainModule</span><span class="p">.</span><span class="nx">filename</span> mainModule._sourceMaps[mainModule.filename] = answer.sourceMap
<span class="k">else</span> mainModule._compile answer.js, mainModule.filename
<span class="nx">mainModule</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">mainModule</span><span class="p">.</span><span class="nx">filename</span></pre></div></div> <span class="keyword">else</span>
mainModule._compile code, mainModule.filename</pre></div></div>
</li> </li>
<li id="section-15"> <li id="section-15">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</a> <a class="pilcrow" href="#section-15">&#182;</a>
</div> </div>
<p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment). <p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
The CoffeeScript REPL uses this to run the input. The CoffeeScript REPL uses this to run the input.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.eval = </span><span class="nf">(code, options = {}) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">eval</span></span> = (code, options = {}) -&gt;
<span class="k">return</span> <span class="k">unless</span> <span class="nv">code = </span><span class="nx">code</span><span class="p">.</span><span class="nx">trim</span><span class="p">()</span> <span class="keyword">return</span> <span class="keyword">unless</span> code = code.trim()
<span class="nv">Script = </span><span class="nx">vm</span><span class="p">.</span><span class="nx">Script</span> Script = vm.Script
<span class="k">if</span> <span class="nx">Script</span> <span class="keyword">if</span> Script
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span><span class="o">?</span> <span class="keyword">if</span> options.sandbox?
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span> <span class="k">instanceof</span> <span class="nx">Script</span><span class="p">.</span><span class="nx">createContext</span><span class="p">().</span><span class="nx">constructor</span> <span class="keyword">if</span> options.sandbox <span class="keyword">instanceof</span> Script.createContext().constructor
<span class="nv">sandbox = </span><span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span> sandbox = options.sandbox
<span class="k">else</span> <span class="keyword">else</span>
<span class="nv">sandbox = </span><span class="nx">Script</span><span class="p">.</span><span class="nx">createContext</span><span class="p">()</span> sandbox = Script.createContext()
<span class="nx">sandbox</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span> <span class="k">for</span> <span class="k">own</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span> <span class="k">of</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span> sandbox[k] = v <span class="keyword">for</span> own k, v <span class="keyword">of</span> options.sandbox
<span class="nv">sandbox.global = sandbox.root = sandbox.GLOBAL = </span><span class="nx">sandbox</span> sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
<span class="k">else</span> <span class="keyword">else</span>
<span class="nv">sandbox = </span><span class="nx">global</span> sandbox = global
<span class="nv">sandbox.__filename = </span><span class="nx">options</span><span class="p">.</span><span class="nx">filename</span> <span class="o">||</span> <span class="s">&#39;eval&#39;</span> sandbox.__filename = options.filename || <span class="string">'eval'</span>
<span class="nv">sandbox.__dirname = </span><span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span> <span class="nx">sandbox</span><span class="p">.</span><span class="nx">__filename</span></pre></div></div> sandbox.__dirname = path.dirname sandbox.__filename</pre></div></div>
</li> </li>
<li id="section-16"> <li id="section-16">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</a> <a class="pilcrow" href="#section-16">&#182;</a>
</div> </div>
<p>define module/require only if they chose not to specify their own <p>define module/require only if they chose not to specify their own
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">unless</span> <span class="nx">sandbox</span> <span class="o">isnt</span> <span class="nx">global</span> <span class="o">or</span> <span class="nx">sandbox</span><span class="p">.</span><span class="nx">module</span> <span class="o">or</span> <span class="nx">sandbox</span><span class="p">.</span><span class="nx">require</span> <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
<span class="nv">Module = </span><span class="nx">require</span> <span class="s">&#39;module&#39;</span> Module = require <span class="string">'module'</span>
<span class="nv">sandbox.module = _module = </span><span class="k">new</span> <span class="nx">Module</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">modulename</span> <span class="o">||</span> <span class="s">&#39;eval&#39;</span><span class="p">)</span> sandbox.module = _module = <span class="keyword">new</span> Module(options.modulename || <span class="string">'eval'</span>)
<span class="nv">sandbox.require = _require = </span><span class="nf">(path) -&gt;</span> <span class="nx">Module</span><span class="p">.</span><span class="nx">_load</span> <span class="nx">path</span><span class="p">,</span> <span class="nx">_module</span><span class="p">,</span> <span class="kc">true</span> sandbox.require = <span class="function"><span class="title">_require</span></span> = (path) -&gt; Module._load path, _module, <span class="literal">true</span>
<span class="nv">_module.filename = </span><span class="nx">sandbox</span><span class="p">.</span><span class="nx">__filename</span> _module.filename = sandbox.__filename
<span class="nx">_require</span><span class="p">[</span><span class="nx">r</span><span class="p">]</span> <span class="o">=</span> <span class="nx">require</span><span class="p">[</span><span class="nx">r</span><span class="p">]</span> <span class="k">for</span> <span class="nx">r</span> <span class="k">in</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">getOwnPropertyNames</span> <span class="nx">require</span> <span class="k">when</span> <span class="nx">r</span> <span class="o">isnt</span> <span class="s">&#39;paths&#39;</span></pre></div></div> _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>
</li> </li>
<li id="section-17"> <li id="section-17">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a> <a class="pilcrow" href="#section-17">&#182;</a>
</div> </div>
<p>use the same hack node currently uses for their own REPL <p>use the same hack node currently uses for their own REPL
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">_require.paths = _module.paths = </span><span class="nx">Module</span><span class="p">.</span><span class="nx">_nodeModulePaths</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()</span> <div class="content"><div class='highlight'><pre> _require.paths = _module.paths = Module._nodeModulePaths process.cwd()
<span class="nv">_require.resolve = </span><span class="nf">(request) -&gt;</span> <span class="nx">Module</span><span class="p">.</span><span class="nx">_resolveFilename</span> <span class="nx">request</span><span class="p">,</span> <span class="nx">_module</span> _require.<span class="function"><span class="title">resolve</span></span> = (request) -&gt; Module._resolveFilename request, _module
<span class="nv">o = </span><span class="p">{}</span> o = {}
<span class="nx">o</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span> <span class="k">for</span> <span class="k">own</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span> <span class="k">of</span> <span class="nx">options</span> o[k] = v <span class="keyword">for</span> own k, v <span class="keyword">of</span> options
<span class="nv">o.bare = </span><span class="kc">on</span> <span class="c1"># ensure return value</span> o.bare = <span class="literal">on</span> <span class="comment"># ensure return value</span>
<span class="nv">js = </span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">o</span> js = compile code, o
<span class="k">if</span> <span class="nx">sandbox</span> <span class="o">is</span> <span class="nx">global</span> <span class="keyword">if</span> sandbox <span class="keyword">is</span> global
<span class="nx">vm</span><span class="p">.</span><span class="nx">runInThisContext</span> <span class="nx">js</span> vm.runInThisContext js
<span class="k">else</span> <span class="keyword">else</span>
<span class="nx">vm</span><span class="p">.</span><span class="nx">runInContext</span> <span class="nx">js</span><span class="p">,</span> <span class="nx">sandbox</span></pre></div></div> vm.runInContext js, sandbox</pre></div></div>
</li> </li>
<li id="section-18"> <li id="section-18">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a> <a class="pilcrow" href="#section-18">&#182;</a>
</div> </div>
<p>Load and run a CoffeeScript file for Node, stripping any <code>BOM</code>s.
<p>Instantiate a Lexer for our use here.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">lexer = </span><span class="k">new</span> <span class="nx">Lexer</span></pre></div></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
module._compile compile(stripped, {filename, literate: helpers.isLiterate filename}), filename</pre></div></div>
</li> </li>
<li id="section-19"> <li id="section-19">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-19">&#182;</a> <a class="pilcrow" href="#section-19">&#182;</a>
</div> </div>
<p>If the installed version of Node supports <code>require.extensions</code>, register
<p>The real Lexer produces a generic stream of tokens. This object provides a CoffeeScript as an extension.
thin wrapper around it, compatible with the Jison API. We can then pass it
directly as a &quot;Jison lexer&quot;.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">parser.lexer =</span> <div class="content"><div class='highlight'><pre><span class="keyword">if</span> require.extensions
<span class="nv">lex: </span><span class="nf">-&gt;</span> <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>]
<span class="nv">token = </span><span class="nx">@tokens</span><span class="p">[</span><span class="nx">@pos</span><span class="o">++</span><span class="p">]</span> require.extensions[ext] = loadFile</pre></div></div>
<span class="k">if</span> <span class="nx">token</span>
<span class="p">[</span><span class="nx">tag</span><span class="p">,</span> <span class="nx">@yytext</span><span class="p">,</span> <span class="nx">@yylloc</span><span class="p">]</span> <span class="o">=</span> <span class="nx">token</span>
<span class="vi">@yylineno = </span><span class="nx">@yylloc</span><span class="p">.</span><span class="nx">first_line</span>
<span class="k">else</span>
<span class="nv">tag = </span><span class="s">&#39;&#39;</span>
<span class="nx">tag</span>
<span class="nv">setInput: </span><span class="nf">(@tokens) -&gt;</span>
<span class="vi">@pos = </span><span class="mi">0</span>
<span class="nv">upcomingInput: </span><span class="nf">-&gt;</span>
<span class="s">&quot;&quot;</span></pre></div></div>
</li> </li>
<li id="section-20"> <li id="section-20">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-20">&#182;</a> <a class="pilcrow" href="#section-20">&#182;</a>
</div> </div>
<p>If we&#39;re on Node, patch <code>child_process.fork</code> so that Coffee scripts are able
<p>Make all the AST nodes visible to the parser. to fork both CoffeeScript files, and JavaScript files, directly.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">parser.yy = </span><span class="nx">require</span> <span class="s">&#39;./nodes&#39;</span></pre></div></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>
</li> </li>
<li id="section-21"> <li id="section-21">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a> <a class="pilcrow" href="#section-21">&#182;</a>
</div> </div>
<p>Instantiate a Lexer for our use here.
<p>Override Jison&#39;s default error handling function.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">parser.yy.parseError = </span><span class="nf">(message, {token}) -&gt;</span></pre></div></div> <div class="content"><div class='highlight'><pre>lexer = <span class="keyword">new</span> Lexer</pre></div></div>
</li> </li>
<li id="section-22"> <li id="section-22">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a> <a class="pilcrow" href="#section-22">&#182;</a>
</div> </div>
<p>The real Lexer produces a generic stream of tokens. This object provides a
<p>Disregard Jison&#39;s message, it contains redundant line numer information. thin wrapper around it, compatible with the Jison API. We can then pass it
directly as a &quot;Jison lexer&quot;.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">message = </span><span class="s">&quot;unexpected </span><span class="si">#{</span><span class="k">if</span> <span class="nx">token</span> <span class="o">is</span> <span class="mi">1</span> <span class="k">then</span> <span class="s">&#39;end of input&#39;</span> <span class="k">else</span> <span class="nx">token</span><span class="si">}</span><span class="s">&quot;</span></pre></div></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>
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>
</li> </li>
<li id="section-23"> <li id="section-23">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a> <a class="pilcrow" href="#section-23">&#182;</a>
</div> </div>
<p>Make all the AST nodes visible to the parser.
</p>
</div>
<div class="content"><div class='highlight'><pre>parser.yy = require <span class="string">'./nodes'</span></pre></div></div>
</li>
<li id="section-24">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</a>
</div>
<p>Override Jison&#39;s default error handling function.
</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>
</li>
<li id="section-25">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">&#182;</a>
</div>
<p>Disregard Jison&#39;s message, it contains redundant line numer information.
</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>
</li>
<li id="section-26">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-26">&#182;</a>
</div>
<p>The second argument has a <code>loc</code> property, which should have the location <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> 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 previous token), so we take the location information directly
@ -608,9 +646,158 @@ from the lexer.
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">helpers</span><span class="p">.</span><span class="nx">throwSyntaxError</span> <span class="nx">message</span><span class="p">,</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">lexer</span><span class="p">.</span><span class="nx">yylloc</span> <div class="content"><div class='highlight'><pre> helpers.throwSyntaxError message, parser.lexer.yylloc</pre></div></div>
</pre></div></div> </li>
<li id="section-27">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-27">&#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>
<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-28">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-28">&#182;</a>
</div>
<p>Map of filenames -&gt; sourceMap object.
</p>
</div>
<div class="content"><div class='highlight'><pre> mainModule._sourceMaps = {}</pre></div></div>
</li>
<li id="section-29">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-29">&#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 = mainModule._sourceMaps[filename]
answer = sourceMap.getSourcePosition [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-30">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-30">&#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>
</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()
fileName <span class="keyword">or</span>= <span class="string">"&lt;anonymous&gt;"</span>
line = frame.getLineNumber()
column = frame.getColumnNumber()</pre></div></div>
</li>
<li id="section-31">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-31">&#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>
</li> </li>

File diff suppressed because it is too large Load diff

View file

@ -1,28 +1,66 @@
/*--------------------- Layout and Typography ----------------------------*/ /*--------------------- Typography ----------------------------*/
@font-face {
font-family: 'aller-light';
src: url('public/fonts/aller-light.eot');
src: url('public/fonts/aller-light.eot?#iefix') format('embedded-opentype'),
url('public/fonts/aller-light.woff') format('woff'),
url('public/fonts/aller-light.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'aller-bold';
src: url('public/fonts/aller-bold.eot');
src: url('public/fonts/aller-bold.eot?#iefix') format('embedded-opentype'),
url('public/fonts/aller-bold.woff') format('woff'),
url('public/fonts/aller-bold.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'novecento-bold';
src: url('public/fonts/novecento-bold.eot');
src: url('public/fonts/novecento-bold.eot?#iefix') format('embedded-opentype'),
url('public/fonts/novecento-bold.woff') format('woff'),
url('public/fonts/novecento-bold.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
/*--------------------- Layout ----------------------------*/
html { height: 100%; } html { height: 100%; }
body { body {
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; font-family: "aller-light";
font-size: 14px; font-size: 14px;
line-height: 16px; line-height: 18px;
color: #252519; color: #30404f;
margin: 0; padding: 0; margin: 0; padding: 0;
height:100%; height:100%;
} }
#container { min-height: 100%; } #container { min-height: 100%; }
a { a {
color: #261a3b; color: #000;
} }
a:visited { b, strong {
color: #261a3b; font-weight: normal;
font-family: "aller-bold";
} }
p, ul, ol { p, ul, ol {
margin: 15px 0; margin: 15px 0 0px;
} }
h1, h2, h3, h4, h5, h6 { h1, h2, h3, h4, h5, h6 {
color: #112233;
line-height: 1em;
font-weight: normal;
font-family: "novecento-bold";
text-transform: uppercase;
margin: 30px 0 15px 0; margin: 30px 0 15px 0;
} }
@ -31,8 +69,8 @@ h1 {
} }
hr { hr {
border: 0 none; border: 0;
border-top: 1px solid #e5e5ee; background: 1px solid #ddd;
height: 1px; height: 1px;
margin: 20px 0; margin: 20px 0;
} }
@ -42,6 +80,35 @@ pre, tt, code {
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace; font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0; margin: 0; padding: 0;
} }
.annotation pre {
display: block;
margin: 0;
padding: 7px 10px;
background: #fcfcfc;
-moz-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
-webkit-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
overflow-x: auto;
}
.annotation pre code {
border: 0;
padding: 0;
background: transparent;
}
blockquote {
border-left: 5px solid #ccc;
margin: 0;
padding: 1px 0 1px 1em;
}
.sections blockquote p {
font-family: Menlo, Consolas, Monaco, monospace;
font-size: 12px; line-height: 16px;
color: #999;
margin: 10px 0 0;
white-space: pre-wrap;
}
ul.sections { ul.sections {
list-style: none; list-style: none;
@ -133,10 +200,6 @@ ul.sections > li > div {
padding:5px 10px 0 10px; padding:5px 10px 0 10px;
} }
ul.sections > li > div.annotation {
background: #fff;
}
ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol { ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
padding-left: 30px; padding-left: 30px;
} }
@ -172,11 +235,15 @@ ul.sections > li > div {
body { body {
background-color: #F5F5FF; background-color: #F5F5FF;
font-size: 15px; font-size: 15px;
line-height: 22px; line-height: 21px;
} }
pre, tt, code { pre, tt, code {
line-height: 18px; line-height: 18px;
} }
p, ul, ol {
margin: 0 0 15px;
}
#jump_to { #jump_to {
padding: 5px 10px; padding: 5px 10px;
@ -204,7 +271,7 @@ ul.sections > li > div {
position: absolute; position: absolute;
top: 0; bottom: 0; top: 0; bottom: 0;
width: 350px; width: 350px;
background: #ffffff; background: #fff;
border-right: 1px solid #e5e5ee; border-right: 1px solid #e5e5ee;
z-index: -1; z-index: -1;
} }
@ -260,6 +327,12 @@ ul.sections > li > div {
opacity: 0; opacity: 0;
-webkit-transition: opacity 0.2s linear; -webkit-transition: opacity 0.2s linear;
} }
.for-h1 .pilcrow {
top: 47px;
}
.for-h2 .pilcrow, .for-h3 .pilcrow, .for-h4 .pilcrow {
top: 35px;
}
ul.sections > li > div.annotation:hover .pilcrow { ul.sections > li > div.annotation:hover .pilcrow {
opacity: 1; opacity: 1;
@ -269,6 +342,11 @@ ul.sections > li > div {
/*---------------------- (> 1025px) ---------------------*/ /*---------------------- (> 1025px) ---------------------*/
@media only screen and (min-width: 1025px) { @media only screen and (min-width: 1025px) {
body {
font-size: 16px;
line-height: 24px;
}
#background { #background {
width: 525px; width: 525px;
} }
@ -278,71 +356,145 @@ ul.sections > li > div {
padding: 10px 25px 1px 50px; padding: 10px 25px 1px 50px;
} }
ul.sections > li > div.content { ul.sections > li > div.content {
padding: 14px 15px 16px 25px; padding: 9px 15px 16px 25px;
} }
} }
/*---------------------- Syntax Highlighting -----------------------------*/ /*---------------------- Syntax Highlighting -----------------------------*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; } td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
body .hll { background-color: #ffffcc } /*
body .c { color: #408080; font-style: italic } /* Comment */
body .err { border: 1px solid #FF0000 } /* Error */ github.com style (c) Vasily Polovnyov <vast@whiteants.net>
body .k { color: #954121 } /* Keyword */
body .o { color: #666666 } /* Operator */ */
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
body .cp { color: #BC7A00 } /* Comment.Preproc */ pre code {
body .c1 { color: #408080; font-style: italic } /* Comment.Single */ display: block; padding: 0.5em;
body .cs { color: #408080; font-style: italic } /* Comment.Special */ color: #000;
body .gd { color: #A00000 } /* Generic.Deleted */ background: #f8f8ff
body .ge { font-style: italic } /* Generic.Emph */ }
body .gr { color: #FF0000 } /* Generic.Error */
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */ pre .comment,
body .gi { color: #00A000 } /* Generic.Inserted */ pre .template_comment,
body .go { color: #808080 } /* Generic.Output */ pre .diff .header,
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ pre .javadoc {
body .gs { font-weight: bold } /* Generic.Strong */ color: #408080;
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ font-style: italic
body .gt { color: #0040D0 } /* Generic.Traceback */ }
body .kc { color: #954121 } /* Keyword.Constant */
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */ pre .keyword,
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */ pre .assignment,
body .kp { color: #954121 } /* Keyword.Pseudo */ pre .literal,
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */ pre .css .rule .keyword,
body .kt { color: #B00040 } /* Keyword.Type */ pre .winutils,
body .m { color: #666666 } /* Literal.Number */ pre .javascript .title,
body .s { color: #219161 } /* Literal.String */ pre .lisp .title,
body .na { color: #7D9029 } /* Name.Attribute */ pre .subst {
body .nb { color: #954121 } /* Name.Builtin */ color: #954121;
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */ /*font-weight: bold*/
body .no { color: #880000 } /* Name.Constant */ }
body .nd { color: #AA22FF } /* Name.Decorator */
body .ni { color: #999999; font-weight: bold } /* Name.Entity */ pre .number,
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ pre .hexcolor {
body .nf { color: #0000FF } /* Name.Function */ color: #40a070
body .nl { color: #A0A000 } /* Name.Label */ }
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
body .nt { color: #954121; font-weight: bold } /* Name.Tag */ pre .string,
body .nv { color: #19469D } /* Name.Variable */ pre .tag .value,
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ pre .phpdoc,
body .w { color: #bbbbbb } /* Text.Whitespace */ pre .tex .formula {
body .mf { color: #666666 } /* Literal.Number.Float */ color: #219161;
body .mh { color: #666666 } /* Literal.Number.Hex */ }
body .mi { color: #666666 } /* Literal.Number.Integer */
body .mo { color: #666666 } /* Literal.Number.Oct */ pre .title,
body .sb { color: #219161 } /* Literal.String.Backtick */ pre .id {
body .sc { color: #219161 } /* Literal.String.Char */ color: #19469D;
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */ }
body .s2 { color: #219161 } /* Literal.String.Double */ pre .params {
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ color: #00F;
body .sh { color: #219161 } /* Literal.String.Heredoc */ }
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
body .sx { color: #954121 } /* Literal.String.Other */ pre .javascript .title,
body .sr { color: #BB6688 } /* Literal.String.Regex */ pre .lisp .title,
body .s1 { color: #219161 } /* Literal.String.Single */ pre .subst {
body .ss { color: #19469D } /* Literal.String.Symbol */ font-weight: normal
body .bp { color: #954121 } /* Name.Builtin.Pseudo */ }
body .vc { color: #19469D } /* Name.Variable.Class */
body .vg { color: #19469D } /* Name.Variable.Global */ pre .class .title,
body .vi { color: #19469D } /* Name.Variable.Instance */ pre .haskell .label,
body .il { color: #666666 } /* Literal.Number.Integer.Long */ pre .tex .command {
color: #458;
font-weight: bold
}
pre .tag,
pre .tag .title,
pre .rules .property,
pre .django .tag .keyword {
color: #000080;
font-weight: normal
}
pre .attribute,
pre .variable,
pre .instancevar,
pre .lisp .body {
color: #008080
}
pre .regexp {
color: #B68
}
pre .class {
color: #458;
font-weight: bold
}
pre .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .lisp .keyword,
pre .tex .special,
pre .input_number {
color: #990073
}
pre .builtin,
pre .constructor,
pre .built_in,
pre .lisp .title {
color: #0086b3
}
pre .preprocessor,
pre .pi,
pre .doctype,
pre .shebang,
pre .cdata {
color: #999;
font-weight: bold
}
pre .deletion {
background: #fdd
}
pre .addition {
background: #dfd
}
pre .diff .change {
background: #0086b3
}
pre .chunk {
color: #aaa
}
pre .tex .formula {
opacity: 0.5;
}

File diff suppressed because it is too large Load diff

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>helpers.coffee</h1> <h1>helpers.coffee</h1>
@ -100,8 +101,10 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
@ -111,477 +114,458 @@ arrays, count characters, that sort of thing.
</p> </p>
<p>Peek at the beginning of a given string to see if it matches a sequence. <p>Peek at the beginning of a given string to see if it matches a sequence.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.starts = </span><span class="nf">(string, literal, start) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">starts</span></span> = (string, literal, start) -&gt;
<span class="nx">literal</span> <span class="o">is</span> <span class="nx">string</span><span class="p">.</span><span class="nx">substr</span> <span class="nx">start</span><span class="p">,</span> <span class="nx">literal</span><span class="p">.</span><span class="nx">length</span></pre></div></div> literal <span class="keyword">is</span> string.substr start, literal.length</pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>Peek at the end of a given string to see if it matches a sequence. <p>Peek at the end of a given string to see if it matches a sequence.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.ends = </span><span class="nf">(string, literal, back) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">ends</span></span> = (string, literal, back) -&gt;
<span class="nv">len = </span><span class="nx">literal</span><span class="p">.</span><span class="nx">length</span> len = literal.length
<span class="nx">literal</span> <span class="o">is</span> <span class="nx">string</span><span class="p">.</span><span class="nx">substr</span> <span class="nx">string</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="nx">len</span> <span class="o">-</span> <span class="p">(</span><span class="nx">back</span> <span class="o">or</span> <span class="mi">0</span><span class="p">),</span> <span class="nx">len</span></pre></div></div> literal <span class="keyword">is</span> string.substr string.length - len - (back <span class="keyword">or</span> <span class="number">0</span>), len</pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>Repeat a string <code>n</code> times. <p>Repeat a string <code>n</code> times.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.repeat = repeat = </span><span class="nf">(str, n) -&gt;</span></pre></div></div> <div class="content"><div class='highlight'><pre>exports.repeat = <span class="function"><span class="title">repeat</span></span> = (str, n) -&gt;</pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>Use clever algorithm to have O(log(n)) string concatenation operations. <p>Use clever algorithm to have O(log(n)) string concatenation operations.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">res = </span><span class="s">&#39;&#39;</span> <div class="content"><div class='highlight'><pre> res = <span class="string">''</span>
<span class="k">while</span> <span class="nx">n</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="keyword">while</span> n &gt; <span class="number">0</span>
<span class="nx">res</span> <span class="o">+=</span> <span class="nx">str</span> <span class="k">if</span> <span class="nx">n</span> <span class="o">&amp;</span> <span class="mi">1</span> res += str <span class="keyword">if</span> n &amp; <span class="number">1</span>
<span class="nx">n</span> <span class="o">&gt;&gt;&gt;=</span> <span class="mi">1</span> n &gt;&gt;&gt;= <span class="number">1</span>
<span class="nx">str</span> <span class="o">+=</span> <span class="nx">str</span> str += str
<span class="nx">res</span></pre></div></div> res</pre></div></div>
</li> </li>
<li id="section-5"> <li id="section-5">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a> <a class="pilcrow" href="#section-5">&#182;</a>
</div> </div>
<p>Trim out all falsy values from an array. <p>Trim out all falsy values from an array.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.compact = </span><span class="nf">(array) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">compact</span></span> = (array) -&gt;
<span class="nx">item</span> <span class="k">for</span> <span class="nx">item</span> <span class="k">in</span> <span class="nx">array</span> <span class="k">when</span> <span class="nx">item</span></pre></div></div> item <span class="keyword">for</span> item <span class="keyword">in</span> array <span class="keyword">when</span> item</pre></div></div>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<p>Count the number of occurrences of a string in a string. <p>Count the number of occurrences of a string in a string.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.count = </span><span class="nf">(string, substr) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">count</span></span> = (string, substr) -&gt;
<span class="nv">num = pos = </span><span class="mi">0</span> num = pos = <span class="number">0</span>
<span class="k">return</span> <span class="mi">1</span><span class="o">/</span><span class="mi">0</span> <span class="k">unless</span> <span class="nx">substr</span><span class="p">.</span><span class="nx">length</span> <span class="keyword">return</span> <span class="number">1</span>/<span class="number">0</span> <span class="keyword">unless</span> substr.length
<span class="nx">num</span><span class="o">++</span> <span class="k">while</span> <span class="nv">pos = </span><span class="mi">1</span> <span class="o">+</span> <span class="nx">string</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">substr</span><span class="p">,</span> <span class="nx">pos</span> num++ <span class="keyword">while</span> pos = <span class="number">1</span> + string.indexOf substr, pos
<span class="nx">num</span></pre></div></div> num</pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Merge objects, returning a fresh copy with attributes from both sides. <p>Merge objects, returning a fresh copy with attributes from both sides.
Used every time <code>Base#compile</code> is called, to allow properties in the Used every time <code>Base#compile</code> is called, to allow properties in the
options hash to propagate down the tree without polluting other branches. options hash to propagate down the tree without polluting other branches.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.merge = </span><span class="nf">(options, overrides) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">merge</span></span> = (options, overrides) -&gt;
<span class="nx">extend</span> <span class="p">(</span><span class="nx">extend</span> <span class="p">{},</span> <span class="nx">options</span><span class="p">),</span> <span class="nx">overrides</span></pre></div></div> extend (extend {}, options), overrides</pre></div></div>
</li> </li>
<li id="section-8"> <li id="section-8">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a> <a class="pilcrow" href="#section-8">&#182;</a>
</div> </div>
<p>Extend a source object with the properties of another object (shallow copy). <p>Extend a source object with the properties of another object (shallow copy).
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">extend = exports.extend = </span><span class="nf">(object, properties) -&gt;</span> <div class="content"><div class='highlight'><pre>extend = exports.<span class="function"><span class="title">extend</span></span> = (object, properties) -&gt;
<span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">properties</span> <span class="keyword">for</span> key, val <span class="keyword">of</span> properties
<span class="nx">object</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span> object[key] = val
<span class="nx">object</span></pre></div></div> object</pre></div></div>
</li> </li>
<li id="section-9"> <li id="section-9">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a> <a class="pilcrow" href="#section-9">&#182;</a>
</div> </div>
<p>Return a flattened version of an array. <p>Return a flattened version of an array.
Handy for getting a list of <code>children</code> from the nodes. Handy for getting a list of <code>children</code> from the nodes.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.flatten = flatten = </span><span class="nf">(array) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.flatten = <span class="function"><span class="title">flatten</span></span> = (array) -&gt;
<span class="nv">flattened = </span><span class="p">[]</span> flattened = []
<span class="k">for</span> <span class="nx">element</span> <span class="k">in</span> <span class="nx">array</span> <span class="keyword">for</span> element <span class="keyword">in</span> array
<span class="k">if</span> <span class="nx">element</span> <span class="k">instanceof</span> <span class="nb">Array</span> <span class="keyword">if</span> element <span class="keyword">instanceof</span> Array
<span class="nv">flattened = </span><span class="nx">flattened</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">flatten</span> <span class="nx">element</span> flattened = flattened.concat flatten element
<span class="k">else</span> <span class="keyword">else</span>
<span class="nx">flattened</span><span class="p">.</span><span class="nx">push</span> <span class="nx">element</span> flattened.push element
<span class="nx">flattened</span></pre></div></div> flattened</pre></div></div>
</li> </li>
<li id="section-10"> <li id="section-10">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a> <a class="pilcrow" href="#section-10">&#182;</a>
</div> </div>
<p>Delete a key from an object, returning the value. Useful when a node is <p>Delete a key from an object, returning the value. Useful when a node is
looking for a particular method in an options hash. looking for a particular method in an options hash.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.del = </span><span class="nf">(obj, key) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">del</span></span> = (obj, key) -&gt;
<span class="nv">val = </span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> val = obj[key]
<span class="k">delete</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="keyword">delete</span> obj[key]
<span class="nx">val</span></pre></div></div> val</pre></div></div>
</li> </li>
<li id="section-11"> <li id="section-11">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a> <a class="pilcrow" href="#section-11">&#182;</a>
</div> </div>
<p>Gets the last item of an array(-like) object. <p>Gets the last item of an array(-like) object.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.last = last = </span><span class="nf">(array, back) -&gt;</span> <span class="nx">array</span><span class="p">[</span><span class="nx">array</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="p">(</span><span class="nx">back</span> <span class="o">or</span> <span class="mi">0</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span></pre></div></div> <div class="content"><div class='highlight'><pre>exports.last = <span class="function"><span class="title">last</span></span> = (array, back) -&gt; array[array.length - (back <span class="keyword">or</span> <span class="number">0</span>) - <span class="number">1</span>]</pre></div></div>
</li> </li>
<li id="section-12"> <li id="section-12">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a> <a class="pilcrow" href="#section-12">&#182;</a>
</div> </div>
<p>Typical Array::some <p>Typical Array::some
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.some = </span><span class="nb">Array</span><span class="o">::</span><span class="nx">some</span> <span class="o">?</span> <span class="nf">(fn) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.some = Array::some ? (fn) -&gt;
<span class="k">return</span> <span class="kc">true</span> <span class="k">for</span> <span class="nx">e</span> <span class="k">in</span> <span class="k">this</span> <span class="k">when</span> <span class="nx">fn</span> <span class="nx">e</span> <span class="keyword">return</span> <span class="literal">true</span> <span class="keyword">for</span> e <span class="keyword">in</span> <span class="keyword">this</span> <span class="keyword">when</span> fn e
<span class="kc">false</span></pre></div></div> <span class="literal">false</span></pre></div></div>
</li> </li>
<li id="section-13"> <li id="section-13">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a> <a class="pilcrow" href="#section-13">&#182;</a>
</div> </div>
<p>Simple function for inverting Literate CoffeeScript code by putting the <p>Simple function for inverting Literate CoffeeScript code by putting the
documentation in comments, and bumping the actual code back out to the edge ... documentation in comments, producing a string of CoffeeScript code that
producing a string of CoffeeScript code that can be compiled &quot;normally&quot;. can be compiled &quot;normally&quot;.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.invertLiterate = </span><span class="nf">(code) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">invertLiterate</span></span> = (code) -&gt;
<span class="nv">lines = </span><span class="k">for</span> <span class="nx">line</span> <span class="k">in</span> <span class="nx">code</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;\n&#39;</span><span class="p">)</span> maybe_code = <span class="literal">true</span>
<span class="k">if</span> <span class="nv">match = </span><span class="p">(</span><span class="sr">/^([ ]{4}|\t)/</span><span class="p">).</span><span class="nx">exec</span> <span class="nx">line</span> lines = <span class="keyword">for</span> line <span class="keyword">in</span> code.split(<span class="string">'\n'</span>)
<span class="nx">line</span><span class="p">[</span><span class="nx">match</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">length</span><span class="p">..]</span> <span class="keyword">if</span> maybe_code <span class="keyword">and</span> <span class="regexp">/^([ ]{4}|[ ]{0,3}\t)/</span>.test line
<span class="k">else</span> line
<span class="s">&#39;# &#39;</span> <span class="o">+</span> <span class="nx">line</span> <span class="keyword">else</span> <span class="keyword">if</span> maybe_code = <span class="regexp">/^\s*$/</span>.test line
<span class="nx">lines</span><span class="p">.</span><span class="nx">join</span> <span class="s">&#39;\n&#39;</span></pre></div></div> line
<span class="keyword">else</span>
<span class="string">'# '</span> + line
lines.join <span class="string">'\n'</span></pre></div></div>
</li> </li>
<li id="section-14"> <li id="section-14">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a> <a class="pilcrow" href="#section-14">&#182;</a>
</div> </div>
<p>Merge two jison-style location data objects together. <p>Merge two jison-style location data objects together.
If <code>last</code> is not provided, this will simply return <code>first</code>. If <code>last</code> is not provided, this will simply return <code>first</code>.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">buildLocationData = </span><span class="nf">(first, last) -&gt;</span> <div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildLocationData</span></span> = (first, last) -&gt;
<span class="k">if</span> <span class="o">not</span> <span class="nx">last</span> <span class="keyword">if</span> <span class="keyword">not</span> last
<span class="nx">first</span> first
<span class="k">else</span> <span class="keyword">else</span>
<span class="nv">first_line: </span><span class="nx">first</span><span class="p">.</span><span class="nx">first_line</span> first_line: first.first_line
<span class="nv">first_column: </span><span class="nx">first</span><span class="p">.</span><span class="nx">first_column</span> first_column: first.first_column
<span class="nv">last_line: </span><span class="nx">last</span><span class="p">.</span><span class="nx">last_line</span> last_line: last.last_line
<span class="nv">last_column: </span><span class="nx">last</span><span class="p">.</span><span class="nx">last_column</span></pre></div></div> last_column: last.last_column</pre></div></div>
</li> </li>
<li id="section-15"> <li id="section-15">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</a> <a class="pilcrow" href="#section-15">&#182;</a>
</div> </div>
<p>This returns a function which takes an object as a parameter, and if that <p>This returns a function which takes an object as a parameter, and if that
object is an AST node, updates that object&#39;s locationData. object is an AST node, updates that object&#39;s locationData.
The object is returned either way. The object is returned either way.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.addLocationDataFn = </span><span class="nf">(first, last) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">addLocationDataFn</span></span> = (first, last) -&gt;
<span class="nf">(obj) -&gt;</span> (obj) -&gt;
<span class="k">if</span> <span class="p">((</span><span class="k">typeof</span> <span class="nx">obj</span><span class="p">)</span> <span class="o">is</span> <span class="s">&#39;object&#39;</span><span class="p">)</span> <span class="o">and</span> <span class="p">(</span><span class="o">!!</span><span class="nx">obj</span><span class="p">[</span><span class="s">&#39;updateLocationDataIfMissing&#39;</span><span class="p">])</span> <span class="keyword">if</span> ((<span class="keyword">typeof</span> obj) <span class="keyword">is</span> <span class="string">'object'</span>) <span class="keyword">and</span> (!!obj[<span class="string">'updateLocationDataIfMissing'</span>])
<span class="nx">obj</span><span class="p">.</span><span class="nx">updateLocationDataIfMissing</span> <span class="nx">buildLocationData</span><span class="p">(</span><span class="nx">first</span><span class="p">,</span> <span class="nx">last</span><span class="p">)</span> obj.updateLocationDataIfMissing buildLocationData(first, last)
<span class="k">return</span> <span class="nx">obj</span></pre></div></div> <span class="keyword">return</span> obj</pre></div></div>
</li> </li>
<li id="section-16"> <li id="section-16">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</a> <a class="pilcrow" href="#section-16">&#182;</a>
</div> </div>
<p>Convert jison location data to a string. <p>Convert jison location data to a string.
<code>obj</code> can be a token, or a locationData. <code>obj</code> can be a token, or a locationData.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.locationDataToString = </span><span class="nf">(obj) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">locationDataToString</span></span> = (obj) -&gt;
<span class="k">if</span> <span class="p">(</span><span class="s">&quot;2&quot;</span> <span class="k">of</span> <span class="nx">obj</span><span class="p">)</span> <span class="o">and</span> <span class="p">(</span><span class="s">&quot;first_line&quot;</span> <span class="k">of</span> <span class="nx">obj</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="k">then</span> <span class="nv">locationData = </span><span class="nx">obj</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="keyword">if</span> (<span class="string">"2"</span> <span class="keyword">of</span> obj) <span class="keyword">and</span> (<span class="string">"first_line"</span> <span class="keyword">of</span> obj[<span class="number">2</span>]) <span class="keyword">then</span> locationData = obj[<span class="number">2</span>]
<span class="k">else</span> <span class="k">if</span> <span class="s">&quot;first_line&quot;</span> <span class="k">of</span> <span class="nx">obj</span> <span class="k">then</span> <span class="nv">locationData = </span><span class="nx">obj</span> <span class="keyword">else</span> <span class="keyword">if</span> <span class="string">"first_line"</span> <span class="keyword">of</span> obj <span class="keyword">then</span> locationData = obj
<span class="k">if</span> <span class="nx">locationData</span> <span class="keyword">if</span> locationData
<span class="s">&quot;</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_line</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">:</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_column</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">-&quot;</span> <span class="o">+</span> <span class="string">"<span class="subst">#{locationData.first_line + <span class="number">1</span>}</span>:<span class="subst">#{locationData.first_column + <span class="number">1</span>}</span>-"</span> +
<span class="s">&quot;</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">last_line</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">:</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">last_column</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">&quot;</span> <span class="string">"<span class="subst">#{locationData.last_line + <span class="number">1</span>}</span>:<span class="subst">#{locationData.last_column + <span class="number">1</span>}</span>"</span>
<span class="k">else</span> <span class="keyword">else</span>
<span class="s">&quot;No location data&quot;</span></pre></div></div> <span class="string">"No location data"</span></pre></div></div>
</li> </li>
<li id="section-17"> <li id="section-17">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a> <a class="pilcrow" href="#section-17">&#182;</a>
</div> </div>
<p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension. <p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.baseFileName = </span><span class="nf">(file, stripExt = no) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">baseFileName</span></span> = (file, stripExt = <span class="literal">no</span>, pathSep = <span class="string">'/'</span>) -&gt;
<span class="nv">parts = </span><span class="nx">file</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)</span> parts = file.split(pathSep)
<span class="nv">file = </span><span class="nx">parts</span><span class="p">[</span><span class="nx">parts</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> file = parts[parts.length - <span class="number">1</span>]
<span class="k">return</span> <span class="nx">file</span> <span class="k">unless</span> <span class="nx">stripExt</span> <span class="keyword">return</span> file <span class="keyword">unless</span> stripExt
<span class="nv">parts = </span><span class="nx">file</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span> parts = file.split(<span class="string">'.'</span>)
<span class="nx">parts</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span> parts.pop()
<span class="nx">parts</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span> <span class="k">if</span> <span class="nx">parts</span><span class="p">[</span><span class="nx">parts</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">is</span> <span class="s">&#39;coffee&#39;</span> <span class="o">and</span> <span class="nx">parts</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span> parts.pop() <span class="keyword">if</span> parts[parts.length - <span class="number">1</span>] <span class="keyword">is</span> <span class="string">'coffee'</span> <span class="keyword">and</span> parts.length &gt; <span class="number">1</span>
<span class="nx">parts</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span></pre></div></div> parts.join(<span class="string">'.'</span>)</pre></div></div>
</li> </li>
<li id="section-18"> <li id="section-18">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a> <a class="pilcrow" href="#section-18">&#182;</a>
</div> </div>
<p>Determine if a filename represents a CoffeeScript file. <p>Determine if a filename represents a CoffeeScript file.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.isCoffee = </span><span class="nf">(file) -&gt;</span> <span class="o">/</span><span class="err">\</span><span class="p">.((</span><span class="nx">lit</span><span class="p">)</span><span class="o">?</span><span class="nx">coffee</span><span class="o">|</span><span class="nx">coffee</span><span class="err">\</span><span class="p">.</span><span class="nx">md</span><span class="p">)</span><span class="nx">$</span><span class="o">/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">file</span></pre></div></div> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">isCoffee</span></span> = (file) -&gt; <span class="regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
</li> </li>
<li id="section-19"> <li id="section-19">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-19">&#182;</a> <a class="pilcrow" href="#section-19">&#182;</a>
</div> </div>
<p>Determine if a filename represents a Literate CoffeeScript file. <p>Determine if a filename represents a Literate CoffeeScript file.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.isLiterate = </span><span class="nf">(file) -&gt;</span> <span class="o">/</span><span class="err">\</span><span class="p">.(</span><span class="nx">litcoffee</span><span class="o">|</span><span class="nx">coffee</span><span class="err">\</span><span class="p">.</span><span class="nx">md</span><span class="p">)</span><span class="nx">$</span><span class="o">/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">file</span></pre></div></div> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">isLiterate</span></span> = (file) -&gt; <span class="regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
</li> </li>
<li id="section-20"> <li id="section-20">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-20">&#182;</a> <a class="pilcrow" href="#section-20">&#182;</a>
</div> </div>
<p>Throws a SyntaxError with a source file location data attached to it in a <p>Throws a SyntaxError with a source file location data attached to it in a
property called <code>location</code>. property called <code>location</code>.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.throwSyntaxError = </span><span class="nf">(message, location) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">throwSyntaxError</span></span> = (message, location) -&gt;
<span class="nx">location</span><span class="p">.</span><span class="nx">last_line</span> <span class="o">?=</span> <span class="nx">location</span><span class="p">.</span><span class="nx">first_line</span> location.last_line ?= location.first_line
<span class="nx">location</span><span class="p">.</span><span class="nx">last_column</span> <span class="o">?=</span> <span class="nx">location</span><span class="p">.</span><span class="nx">first_column</span> location.last_column ?= location.first_column
<span class="nv">error = </span><span class="k">new</span> <span class="nx">SyntaxError</span> <span class="nx">message</span> error = <span class="keyword">new</span> SyntaxError message
<span class="nv">error.location = </span><span class="nx">location</span> error.location = location
<span class="k">throw</span> <span class="nx">error</span></pre></div></div> <span class="keyword">throw</span> error</pre></div></div>
</li> </li>
<li id="section-21"> <li id="section-21">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a> <a class="pilcrow" href="#section-21">&#182;</a>
</div> </div>
<p>Creates a nice error message like, following the &quot;standard&quot; format <p>Creates a nice error message like, following the &quot;standard&quot; format
</p> </p>
<p><filename>:<line>:<col>: <message> plus the line with the error and a marker <p><filename>:<line>:<col>: <message> plus the line with the error and a marker
showing where the error is. showing where the error is.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.prettyErrorMessage = </span><span class="nf">(error, fileName, code, useColors) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">prettyErrorMessage</span></span> = (error, fileName, code, useColors) -&gt;
<span class="k">return</span> <span class="nx">error</span><span class="p">.</span><span class="nx">stack</span> <span class="o">or</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">error</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">unless</span> <span class="nx">error</span><span class="p">.</span><span class="nx">location</span> <span class="keyword">return</span> error.stack <span class="keyword">or</span> <span class="string">"<span class="subst">#{error}</span>"</span> <span class="keyword">unless</span> error.location
<span class="p">{</span><span class="nx">first_line</span><span class="p">,</span> <span class="nx">first_column</span><span class="p">,</span> <span class="nx">last_line</span><span class="p">,</span> <span class="nx">last_column</span><span class="p">}</span> <span class="o">=</span> <span class="nx">error</span><span class="p">.</span><span class="nx">location</span> {first_line, first_column, last_line, last_column} = error.location
<span class="nv">codeLine = </span><span class="nx">code</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;\n&#39;</span><span class="p">)[</span><span class="nx">first_line</span><span class="p">]</span> codeLine = code.split(<span class="string">'\n'</span>)[first_line]
<span class="nv">start = </span><span class="nx">first_column</span></pre></div></div> start = first_column</pre></div></div>
</li> </li>
<li id="section-22"> <li id="section-22">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a> <a class="pilcrow" href="#section-22">&#182;</a>
</div> </div>
<p>Show only the first line on multi-line errors. <p>Show only the first line on multi-line errors.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">end = </span><span class="k">if</span> <span class="nx">first_line</span> <span class="o">is</span> <span class="nx">last_line</span> <span class="k">then</span> <span class="nx">last_column</span> <span class="o">+</span> <span class="mi">1</span> <span class="k">else</span> <span class="nx">codeLine</span><span class="p">.</span><span class="nx">length</span> <div class="content"><div class='highlight'><pre> end = <span class="keyword">if</span> first_line <span class="keyword">is</span> last_line <span class="keyword">then</span> last_column + <span class="number">1</span> <span class="keyword">else</span> codeLine.length
<span class="nv">marker = </span><span class="nx">repeat</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">,</span> <span class="nx">start</span><span class="p">)</span> <span class="o">+</span> <span class="nx">repeat</span><span class="p">(</span><span class="s">&#39;^&#39;</span><span class="p">,</span> <span class="nx">end</span> <span class="o">-</span> <span class="nx">start</span><span class="p">)</span> marker = repeat(<span class="string">' '</span>, start) + repeat(<span class="string">'^'</span>, end - start)
<span class="k">if</span> <span class="nx">useColors</span> <span class="keyword">if</span> useColors
<span class="nv">colorize = </span><span class="nf">(str) -&gt;</span> <span class="s">&quot;\x1B[1;31m</span><span class="si">#{</span><span class="nx">str</span><span class="si">}</span><span class="s">\x1B[0m&quot;</span> <span class="function"><span class="title">colorize</span></span> = (str) -&gt; <span class="string">"\x1B[1;31m<span class="subst">#{str}</span>\x1B[0m"</span>
<span class="nv">codeLine = </span><span class="nx">codeLine</span><span class="p">[...</span><span class="nx">start</span><span class="p">]</span> <span class="o">+</span> <span class="nx">colorize</span><span class="p">(</span><span class="nx">codeLine</span><span class="p">[</span><span class="nx">start</span><span class="p">...</span><span class="nx">end</span><span class="p">])</span> <span class="o">+</span> <span class="nx">codeLine</span><span class="p">[</span><span class="nx">end</span><span class="p">..]</span> codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
<span class="nv">marker = </span><span class="nx">colorize</span> <span class="nx">marker</span> marker = colorize marker
<span class="nv">message = </span><span class="s">&quot;&quot;&quot;</span> message = <span class="string">"""
<span class="s"> </span><span class="si">#{</span><span class="nx">fileName</span><span class="si">}</span><span class="s">:</span><span class="si">#{</span><span class="nx">first_line</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">:</span><span class="si">#{</span><span class="nx">first_column</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">: error: </span><span class="si">#{</span><span class="nx">error</span><span class="p">.</span><span class="nx">message</span><span class="si">}</span><span class="s"></span> <span class="subst">#{fileName}</span>:<span class="subst">#{first_line + <span class="number">1</span>}</span>:<span class="subst">#{first_column + <span class="number">1</span>}</span>: error: <span class="subst">#{error.message}</span>
<span class="s"> </span><span class="si">#{</span><span class="nx">codeLine</span><span class="si">}</span><span class="s"></span> <span class="subst">#{codeLine}</span>
<span class="s"> </span><span class="si">#{</span><span class="nx">marker</span><span class="si">}</span><span class="s"></span> <span class="subst">#{marker}</span>
<span class="s"> &quot;&quot;&quot;</span></pre></div></div> """</span></pre></div></div>
</li> </li>
<li id="section-23"> <li id="section-23">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a> <a class="pilcrow" href="#section-23">&#182;</a>
</div> </div>
<p>Uncomment to add stacktrace. <p>Uncomment to add stacktrace.
message += &quot;\n#{error.stack}&quot; message += &quot;\n#{error.stack}&quot;
@ -589,9 +573,7 @@ message += &quot;\n#{error.stack}&quot;
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">message</span> <div class="content"><div class='highlight'><pre> message</pre></div></div>
</pre></div></div>
</li> </li>

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>index.coffee</h1> <h1>index.coffee</h1>
@ -100,8 +101,10 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
@ -110,9 +113,7 @@
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">require</span> <span class="s">&#39;./coffee-script&#39;</span> <div class="content"><div class='highlight'><pre>exports[key] = val <span class="keyword">for</span> key, val <span class="keyword">of</span> require <span class="string">'./coffee-script'</span></pre></div></div>
</pre></div></div>
</li> </li>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>optparse.coffee</h1> <h1>optparse.coffee</h1>
@ -100,8 +101,10 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
@ -113,225 +116,227 @@ Use it like so:
options = parser.parse process.argv</code></pre> options = parser.parse process.argv</code></pre>
<p>The first non-option is considered to be the start of the file (and file <p>The first non-option is considered to be the start of the file (and file
option) list, and all subsequent arguments are left unparsed. option) list, and all subsequent arguments are left unparsed.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.OptionParser = </span><span class="k">class</span> <span class="nx">OptionParser</span></pre></div></div> <div class="content"><div class='highlight'><pre>exports.OptionParser = <span class="class"><span class="keyword">class</span> <span class="title">OptionParser</span></span></pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>Initialize with a list of valid options, in the form: <p>Initialize with a list of valid options, in the form:
</p> </p>
<pre><code>[short-flag, long-flag, description]</code></pre> <pre><code>[short-flag, long-flag, description]</code></pre>
<p>Along with an an optional banner for the usage help. <p>Along with an an optional banner for the usage help.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(rules, @banner) -&gt;</span> <div class="content"><div class='highlight'><pre> constructor: (rules, <span class="property">@banner</span>) -&gt;
<span class="vi">@rules = </span><span class="nx">buildRules</span> <span class="nx">rules</span></pre></div></div> <span class="property">@rules</span> = buildRules rules</pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>Parse the list of arguments, populating an <code>options</code> object with all of the <p>Parse the list of arguments, populating an <code>options</code> object with all of the
specified options, and return it. Options after the first non-option specified options, and return it. Options after the first non-option
argument are treated as arguments. <code>options.arguments</code> will be an array argument are treated as arguments. <code>options.arguments</code> will be an array
containing the remaining arguments. This is a simpler API than many option containing the remaining arguments. This is a simpler API than many option
parsers that allow you to attach callback actions for every flag. Instead, parsers that allow you to attach callback actions for every flag. Instead,
you&#39;re responsible for interpreting the options object. you&#39;re responsible for interpreting the options object.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">parse: </span><span class="nf">(args) -&gt;</span> <div class="content"><div class='highlight'><pre> parse: (args) -&gt;
<span class="nv">options = arguments: </span><span class="p">[]</span> options = arguments: []
<span class="nv">skippingArgument = </span><span class="kc">no</span> skippingArgument = <span class="literal">no</span>
<span class="nv">originalArgs = </span><span class="nx">args</span> originalArgs = args
<span class="nv">args = </span><span class="nx">normalizeArguments</span> <span class="nx">args</span> args = normalizeArguments args
<span class="k">for</span> <span class="nx">arg</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">args</span> <span class="keyword">for</span> arg, i <span class="keyword">in</span> args
<span class="k">if</span> <span class="nx">skippingArgument</span> <span class="keyword">if</span> skippingArgument
<span class="nv">skippingArgument = </span><span class="kc">no</span> skippingArgument = <span class="literal">no</span>
<span class="k">continue</span> <span class="keyword">continue</span>
<span class="k">if</span> <span class="nx">arg</span> <span class="o">is</span> <span class="s">&#39;--&#39;</span> <span class="keyword">if</span> arg <span class="keyword">is</span> <span class="string">'--'</span>
<span class="nv">pos = </span><span class="nx">originalArgs</span><span class="p">.</span><span class="nx">indexOf</span> <span class="s">&#39;--&#39;</span> pos = originalArgs.indexOf <span class="string">'--'</span>
<span class="nv">options.arguments = </span><span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">originalArgs</span><span class="p">[(</span><span class="nx">pos</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)..]</span> options.arguments = options.arguments.concat originalArgs[(pos + <span class="number">1</span>)..]
<span class="k">break</span> <span class="keyword">break</span>
<span class="nv">isOption = </span><span class="o">!!</span><span class="p">(</span><span class="nx">arg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">LONG_FLAG</span><span class="p">)</span> <span class="o">or</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">SHORT_FLAG</span><span class="p">))</span></pre></div></div> isOption = !!(arg.match(LONG_FLAG) <span class="keyword">or</span> arg.match(SHORT_FLAG))</pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>the CS option parser is a little odd; options after the first <p>the CS option parser is a little odd; options after the first
non-option argument are treated as non-option arguments themselves non-option argument are treated as non-option arguments themselves
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">seenNonOptionArg = </span><span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span> <div class="content"><div class='highlight'><pre> seenNonOptionArg = options.arguments.length &gt; <span class="number">0</span>
<span class="k">unless</span> <span class="nx">seenNonOptionArg</span> <span class="keyword">unless</span> seenNonOptionArg
<span class="nv">matchedRule = </span><span class="kc">no</span> matchedRule = <span class="literal">no</span>
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@rules</span> <span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</span>
<span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="o">is</span> <span class="nx">arg</span> <span class="o">or</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span> <span class="o">is</span> <span class="nx">arg</span> <span class="keyword">if</span> rule.shortFlag <span class="keyword">is</span> arg <span class="keyword">or</span> rule.longFlag <span class="keyword">is</span> arg
<span class="nv">value = </span><span class="kc">true</span> value = <span class="literal">true</span>
<span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">hasArgument</span> <span class="keyword">if</span> rule.hasArgument
<span class="nv">skippingArgument = </span><span class="kc">yes</span> skippingArgument = <span class="literal">yes</span>
<span class="nv">value = </span><span class="nx">args</span><span class="p">[</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> value = args[i + <span class="number">1</span>]
<span class="nx">options</span><span class="p">[</span><span class="nx">rule</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">isList</span> <span class="k">then</span> <span class="p">(</span><span class="nx">options</span><span class="p">[</span><span class="nx">rule</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">or</span> <span class="p">[]).</span><span class="nx">concat</span> <span class="nx">value</span> <span class="k">else</span> <span class="nx">value</span> options[rule.name] = <span class="keyword">if</span> rule.isList <span class="keyword">then</span> (options[rule.name] <span class="keyword">or</span> []).concat value <span class="keyword">else</span> value
<span class="nv">matchedRule = </span><span class="kc">yes</span> matchedRule = <span class="literal">yes</span>
<span class="k">break</span> <span class="keyword">break</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;unrecognized option: </span><span class="si">#{</span><span class="nx">arg</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">if</span> <span class="nx">isOption</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">matchedRule</span> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"unrecognized option: <span class="subst">#{arg}</span>"</span> <span class="keyword">if</span> isOption <span class="keyword">and</span> <span class="keyword">not</span> matchedRule
<span class="k">if</span> <span class="nx">seenNonOptionArg</span> <span class="o">or</span> <span class="o">not</span> <span class="nx">isOption</span> <span class="keyword">if</span> seenNonOptionArg <span class="keyword">or</span> <span class="keyword">not</span> isOption
<span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">push</span> <span class="nx">arg</span> options.arguments.push arg
<span class="nx">options</span></pre></div></div> options</pre></div></div>
</li> </li>
<li id="section-5"> <li id="section-5">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a> <a class="pilcrow" href="#section-5">&#182;</a>
</div> </div>
<p>Return the help text for this <strong>OptionParser</strong>, listing and describing all <p>Return the help text for this <strong>OptionParser</strong>, listing and describing all
of the valid options, for <code>--help</code> and such. of the valid options, for <code>--help</code> and such.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">help: </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre> help: -&gt;
<span class="nv">lines = </span><span class="p">[]</span> lines = []
<span class="nx">lines</span><span class="p">.</span><span class="nx">unshift</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">@banner</span><span class="si">}</span><span class="s">\n&quot;</span> <span class="k">if</span> <span class="nx">@banner</span> lines.unshift <span class="string">"<span class="subst">#{@banner}</span>\n"</span> <span class="keyword">if</span> <span class="property">@banner</span>
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@rules</span> <span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</span>
<span class="nv">spaces = </span><span class="mi">15</span> <span class="o">-</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">length</span> spaces = <span class="number">15</span> - rule.longFlag.length
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">then</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">spaces</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">)</span> <span class="k">else</span> <span class="s">&#39;&#39;</span> 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>
<span class="nv">letPart = </span><span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="k">then</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="o">+</span> <span class="s">&#39;, &#39;</span> <span class="k">else</span> <span class="s">&#39; &#39;</span> letPart = <span class="keyword">if</span> rule.shortFlag <span class="keyword">then</span> rule.shortFlag + <span class="string">', '</span> <span class="keyword">else</span> <span class="string">' '</span>
<span class="nx">lines</span><span class="p">.</span><span class="nx">push</span> <span class="s">&#39; &#39;</span> <span class="o">+</span> <span class="nx">letPart</span> <span class="o">+</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span> <span class="o">+</span> <span class="nx">spaces</span> <span class="o">+</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">description</span> lines.push <span class="string">' '</span> + letPart + rule.longFlag + spaces + rule.description
<span class="s">&quot;\n</span><span class="si">#{</span> <span class="nx">lines</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39;\n&#39;</span><span class="p">)</span> <span class="si">}</span><span class="s">\n&quot;</span></pre></div></div> <span class="string">"\n<span class="subst">#{ lines.join('\n') }</span>\n"</span></pre></div></div>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap">
<div class="pilwrap for-h2">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<h2>Helpers</h2> <h2>Helpers</h2>
<p>Regex matchers for option flags.
</p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">LONG_FLAG = </span><span class="sr">/^(--\w[\w\-]*)/</span>
<span class="nv">SHORT_FLAG = </span><span class="sr">/^(-\w)$/</span>
<span class="nv">MULTI_FLAG = </span><span class="sr">/^-(\w{2,})/</span>
<span class="nv">OPTIONAL = </span><span class="sr">/\[(\w+(\*?))\]/</span></pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Regex matchers for option flags.
<p>Build and return the list of option rules. If the optional <em>short-flag</em> is
unspecified, leave it out by padding with <code>null</code>.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">buildRules = </span><span class="nf">(rules) -&gt;</span> <div class="content"><div class='highlight'><pre>LONG_FLAG = <span class="regexp">/^(--\w[\w\-]*)/</span>
<span class="k">for</span> <span class="nx">tuple</span> <span class="k">in</span> <span class="nx">rules</span> SHORT_FLAG = <span class="regexp">/^(-\w)$/</span>
<span class="nx">tuple</span><span class="p">.</span><span class="nx">unshift</span> <span class="kc">null</span> <span class="k">if</span> <span class="nx">tuple</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="mi">3</span> MULTI_FLAG = <span class="regexp">/^-(\w{2,})/</span>
<span class="nx">buildRule</span> <span class="nx">tuple</span><span class="p">...</span></pre></div></div> OPTIONAL = <span class="regexp">/\[(\w+(\*?))\]/</span></pre></div></div>
</li> </li>
<li id="section-8"> <li id="section-8">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a> <a class="pilcrow" href="#section-8">&#182;</a>
</div> </div>
<p>Build and return the list of option rules. If the optional <em>short-flag</em> is
<p>Build a rule from a <code>-o</code> short flag, a <code>--output [DIR]</code> long flag, and the unspecified, leave it out by padding with <code>null</code>.
description of what the option does.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">buildRule = </span><span class="nf">(shortFlag, longFlag, description, options = {}) -&gt;</span> <div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildRules</span></span> = (rules) -&gt;
<span class="nv">match = </span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">OPTIONAL</span><span class="p">)</span> <span class="keyword">for</span> tuple <span class="keyword">in</span> rules
<span class="nv">longFlag = </span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">LONG_FLAG</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span> tuple.unshift <span class="literal">null</span> <span class="keyword">if</span> tuple.length &lt; <span class="number">3</span>
<span class="p">{</span> buildRule tuple...</pre></div></div>
<span class="nv">name: </span> <span class="nx">longFlag</span><span class="p">.</span><span class="nx">substr</span> <span class="mi">2</span>
<span class="nv">shortFlag: </span> <span class="nx">shortFlag</span>
<span class="nv">longFlag: </span> <span class="nx">longFlag</span>
<span class="nv">description: </span> <span class="nx">description</span>
<span class="nv">hasArgument: </span> <span class="o">!!</span><span class="p">(</span><span class="nx">match</span> <span class="o">and</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="nv">isList: </span> <span class="o">!!</span><span class="p">(</span><span class="nx">match</span> <span class="o">and</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="p">}</span></pre></div></div>
</li> </li>
<li id="section-9"> <li id="section-9">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a> <a class="pilcrow" href="#section-9">&#182;</a>
</div> </div>
<p>Build a rule from a <code>-o</code> short flag, a <code>--output [DIR]</code> long flag, and the
description of what the option does.
</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildRule</span></span> = (shortFlag, longFlag, description, options = {}) -&gt;
match = longFlag.match(OPTIONAL)
longFlag = longFlag.match(LONG_FLAG)[<span class="number">1</span>]
{
name: longFlag.substr <span class="number">2</span>
shortFlag: shortFlag
longFlag: longFlag
description: description
hasArgument: !!(match <span class="keyword">and</span> match[<span class="number">1</span>])
isList: !!(match <span class="keyword">and</span> match[<span class="number">2</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>Normalize arguments by expanding merged flags into multiple flags. This allows <p>Normalize arguments by expanding merged flags into multiple flags. This allows
you to have <code>-wl</code> be the same as <code>--watch --lint</code>. you to have <code>-wl</code> be the same as <code>--watch --lint</code>.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">normalizeArguments = </span><span class="nf">(args) -&gt;</span> <div class="content"><div class='highlight'><pre><span class="function"><span class="title">normalizeArguments</span></span> = (args) -&gt;
<span class="nv">args = </span><span class="nx">args</span><span class="p">[..]</span> args = args[..]
<span class="nv">result = </span><span class="p">[]</span> result = []
<span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">args</span> <span class="keyword">for</span> arg <span class="keyword">in</span> args
<span class="k">if</span> <span class="nv">match = </span><span class="nx">arg</span><span class="p">.</span><span class="nx">match</span> <span class="nx">MULTI_FLAG</span> <span class="keyword">if</span> match = arg.match MULTI_FLAG
<span class="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="s">&#39;-&#39;</span> <span class="o">+</span> <span class="nx">l</span> <span class="k">for</span> <span class="nx">l</span> <span class="k">in</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">split</span> <span class="s">&#39;&#39;</span> result.push <span class="string">'-'</span> + l <span class="keyword">for</span> l <span class="keyword">in</span> match[<span class="number">1</span>].split <span class="string">''</span>
<span class="k">else</span> <span class="keyword">else</span>
<span class="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="nx">arg</span> result.push arg
<span class="nx">result</span> result</pre></div></div>
</pre></div></div>
</li> </li>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,375 @@
/*! normalize.css v2.0.1 | MIT License | git.io/normalize */
/* ==========================================================================
HTML5 display definitions
========================================================================== */
/*
* Corrects `block` display not defined in IE 8/9.
*/
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
nav,
section,
summary {
display: block;
}
/*
* Corrects `inline-block` display not defined in IE 8/9.
*/
audio,
canvas,
video {
display: inline-block;
}
/*
* Prevents modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/*
* Addresses styling for `hidden` attribute not present in IE 8/9.
*/
[hidden] {
display: none;
}
/* ==========================================================================
Base
========================================================================== */
/*
* 1. Sets default font family to sans-serif.
* 2. Prevents iOS text size adjust after orientation change, without disabling
* user zoom.
*/
html {
font-family: sans-serif; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
-ms-text-size-adjust: 100%; /* 2 */
}
/*
* Removes default margin.
*/
body {
margin: 0;
}
/* ==========================================================================
Links
========================================================================== */
/*
* Addresses `outline` inconsistency between Chrome and other browsers.
*/
a:focus {
outline: thin dotted;
}
/*
* Improves readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
/* ==========================================================================
Typography
========================================================================== */
/*
* Addresses `h1` font sizes within `section` and `article` in Firefox 4+,
* Safari 5, and Chrome.
*/
h1 {
font-size: 2em;
}
/*
* Addresses styling not present in IE 8/9, Safari 5, and Chrome.
*/
abbr[title] {
border-bottom: 1px dotted;
}
/*
* Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
*/
b,
strong {
font-weight: bold;
}
/*
* Addresses styling not present in Safari 5 and Chrome.
*/
dfn {
font-style: italic;
}
/*
* Addresses styling not present in IE 8/9.
*/
mark {
background: #ff0;
color: #000;
}
/*
* Corrects font family set oddly in Safari 5 and Chrome.
*/
code,
kbd,
pre,
samp {
font-family: monospace, serif;
font-size: 1em;
}
/*
* Improves readability of pre-formatted text in all browsers.
*/
pre {
white-space: pre;
white-space: pre-wrap;
word-wrap: break-word;
}
/*
* Sets consistent quote types.
*/
q {
quotes: "\201C" "\201D" "\2018" "\2019";
}
/*
* Addresses inconsistent and variable font size in all browsers.
*/
small {
font-size: 80%;
}
/*
* Prevents `sub` and `sup` affecting `line-height` in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
/* ==========================================================================
Embedded content
========================================================================== */
/*
* Removes border when inside `a` element in IE 8/9.
*/
img {
border: 0;
}
/*
* Corrects overflow displayed oddly in IE 9.
*/
svg:not(:root) {
overflow: hidden;
}
/* ==========================================================================
Figures
========================================================================== */
/*
* Addresses margin not present in IE 8/9 and Safari 5.
*/
figure {
margin: 0;
}
/* ==========================================================================
Forms
========================================================================== */
/*
* Define consistent border, margin, and padding.
*/
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}
/*
* 1. Corrects color not being inherited in IE 8/9.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/
legend {
border: 0; /* 1 */
padding: 0; /* 2 */
}
/*
* 1. Corrects font family not being inherited in all browsers.
* 2. Corrects font size not being inherited in all browsers.
* 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome
*/
button,
input,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 2 */
margin: 0; /* 3 */
}
/*
* Addresses Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
button,
input {
line-height: normal;
}
/*
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Corrects inability to style clickable `input` types in iOS.
* 3. Improves usability and consistency of cursor style between image-type
* `input` and others.
*/
button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button; /* 2 */
cursor: pointer; /* 3 */
}
/*
* Re-set default cursor for disabled elements.
*/
button[disabled],
input[disabled] {
cursor: default;
}
/*
* 1. Addresses box sizing set to `content-box` in IE 8/9.
* 2. Removes excess padding in IE 8/9.
*/
input[type="checkbox"],
input[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/*
* 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome.
* 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome
* (include `-moz` to future-proof).
*/
input[type="search"] {
-webkit-appearance: textfield; /* 1 */
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box; /* 2 */
box-sizing: content-box;
}
/*
* Removes inner padding and search cancel button in Safari 5 and Chrome
* on OS X.
*/
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/*
* Removes inner padding and border in Firefox 4+.
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
/*
* 1. Removes default vertical scrollbar in IE 8/9.
* 2. Improves readability and alignment in all browsers.
*/
textarea {
overflow: auto; /* 1 */
vertical-align: top; /* 2 */
}
/* ==========================================================================
Tables
========================================================================== */
/*
* Remove most spacing between table cells.
*/
table {
border-collapse: collapse;
border-spacing: 0;
}

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>repl.coffee</h1> <h1>repl.coffee</h1>
@ -100,277 +101,258 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">vm = </span><span class="nx">require</span> <span class="s">&#39;vm&#39;</span> <div class="content"><div class='highlight'><pre>vm = require <span class="string">'vm'</span>
<span class="nv">nodeREPL = </span><span class="nx">require</span> <span class="s">&#39;repl&#39;</span> nodeREPL = require <span class="string">'repl'</span>
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">&#39;./coffee-script&#39;</span> CoffeeScript = require <span class="string">'./coffee-script'</span>
<span class="p">{</span><span class="nx">merge</span><span class="p">,</span> <span class="nx">prettyErrorMessage</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">&#39;./helpers&#39;</span> {merge, prettyErrorMessage} = require <span class="string">'./helpers'</span>
<span class="nv">replDefaults =</span> replDefaults =
<span class="nv">prompt: </span><span class="s">&#39;coffee&gt; &#39;</span><span class="p">,</span> prompt: <span class="string">'coffee&gt; '</span>,
<span class="nb">eval</span><span class="o">:</span> <span class="nf">(input, context, filename, cb) -&gt;</span></pre></div></div> eval: (input, context, filename, cb) -&gt;</pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>XXX: multiline hack. <p>XXX: multiline hack.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">input = </span><span class="nx">input</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\uFF00/g</span><span class="p">,</span> <span class="s">&#39;\n&#39;</span></pre></div></div> <div class="content"><div class='highlight'><pre> input = input.replace <span class="regexp">/\uFF00/g</span>, <span class="string">'\n'</span></pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>Node&#39;s REPL sends the input ending with a newline and then wrapped in <p>Node&#39;s REPL sends the input ending with a newline and then wrapped in
parens. Unwrap all that. parens. Unwrap all that.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">input = </span><span class="nx">input</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/^\(([\s\S]*)\n\)$/m</span><span class="p">,</span> <span class="s">&#39;$1&#39;</span></pre></div></div> <div class="content"><div class='highlight'><pre> input = input.replace <span class="regexp">/^\(([\s\S]*)\n\)$/m</span>, <span class="string">'$1'</span></pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>Require AST nodes to do some AST manipulation. <p>Require AST nodes to do some AST manipulation.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="p">{</span><span class="nx">Block</span><span class="p">,</span> <span class="nx">Assign</span><span class="p">,</span> <span class="nx">Value</span><span class="p">,</span> <span class="nx">Literal</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">&#39;./nodes&#39;</span></pre></div></div> <div class="content"><div class='highlight'><pre> {Block, Assign, Value, Literal} = require <span class="string">'./nodes'</span>
<span class="keyword">try</span></pre></div></div>
</li> </li>
<li id="section-5"> <li id="section-5">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a> <a class="pilcrow" href="#section-5">&#182;</a>
</div> </div>
<p>Generate the AST of the clean input.
<p>TODO: fix #1829: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">try</span></pre></div></div> <div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes input</pre></div></div>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<p>Add assignment to <code>_</code> variable to force the input to be an expression.
<p>Generate the AST of the clean input.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">ast = </span><span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">nodes</span> <span class="nx">input</span></pre></div></div> <div class="content"><div class='highlight'><pre> ast = <span class="keyword">new</span> Block [
<span class="keyword">new</span> Assign (<span class="keyword">new</span> Value <span class="keyword">new</span> Literal <span class="string">'_'</span>), ast, <span class="string">'='</span>
]
js = ast.compile bare: <span class="literal">yes</span>, locals: Object.keys(context)
cb <span class="literal">null</span>, vm.runInContext(js, context, filename)
<span class="keyword">catch</span> err
cb prettyErrorMessage(err, filename, input, <span class="literal">yes</span>)
<span class="function"><span class="title">addMultilineHandler</span></span> = (repl) -&gt;
{rli, inputStream, outputStream} = repl
multiline =
enabled: <span class="literal">off</span>
initialPrompt: repl.prompt.replace(<span class="regexp">/^[^&gt; ]*/, (x) -&gt; x.replace /./g</span>, <span class="string">'-'</span>)
prompt: repl.prompt.replace(<span class="regexp">/^[^&gt; ]*&gt;?/, (x) -&gt; x.replace /./g</span>, <span class="string">'.'</span>)
buffer: <span class="string">''</span></pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Proxy node&#39;s line listener
<p>Add assignment to <code>_</code> variable to force the input to be an expression.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">ast = </span><span class="k">new</span> <span class="nx">Block</span> <span class="p">[</span> <div class="content"><div class='highlight'><pre> nodeLineListener = rli.listeners(<span class="string">'line'</span>)[<span class="number">0</span>]
<span class="k">new</span> <span class="nx">Assign</span> <span class="p">(</span><span class="k">new</span> <span class="nx">Value</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="s">&#39;_&#39;</span><span class="p">),</span> <span class="nx">ast</span><span class="p">,</span> <span class="s">&#39;=&#39;</span> rli.removeListener <span class="string">'line'</span>, nodeLineListener
<span class="p">]</span> rli.<span class="literal">on</span> <span class="string">'line'</span>, (cmd) -&gt;
<span class="nv">js = </span><span class="nx">ast</span><span class="p">.</span><span class="nx">compile</span> <span class="nv">bare: </span><span class="kc">yes</span> <span class="keyword">if</span> multiline.enabled
<span class="k">catch</span> <span class="nx">err</span> multiline.buffer += <span class="string">"<span class="subst">#{cmd}</span>\n"</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">prettyErrorMessage</span> <span class="nx">err</span><span class="p">,</span> <span class="nx">filename</span><span class="p">,</span> <span class="nx">input</span><span class="p">,</span> <span class="kc">yes</span> rli.setPrompt multiline.prompt
<span class="nx">cb</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">vm</span><span class="p">.</span><span class="nx">runInContext</span><span class="p">(</span><span class="nx">js</span><span class="p">,</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">filename</span><span class="p">)</span> rli.prompt <span class="literal">true</span>
<span class="keyword">else</span>
<span class="nv">addMultilineHandler = </span><span class="nf">(repl) -&gt;</span> nodeLineListener cmd
<span class="p">{</span><span class="nx">rli</span><span class="p">,</span> <span class="nx">inputStream</span><span class="p">,</span> <span class="nx">outputStream</span><span class="p">}</span> <span class="o">=</span> <span class="nx">repl</span> <span class="keyword">return</span></pre></div></div>
<span class="nv">multiline =</span>
<span class="nv">enabled: </span><span class="kc">off</span>
<span class="nv">initialPrompt: </span><span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^[^&gt; ]*/</span><span class="p">,</span> <span class="nf">(x) -&gt;</span> <span class="nx">x</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/./g</span><span class="p">,</span> <span class="s">&#39;-&#39;</span><span class="p">)</span>
<span class="nv">prompt: </span><span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^[^&gt; ]*&gt;?/</span><span class="p">,</span> <span class="nf">(x) -&gt;</span> <span class="nx">x</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/./g</span><span class="p">,</span> <span class="s">&#39;.&#39;</span><span class="p">)</span>
<span class="nv">buffer: </span><span class="s">&#39;&#39;</span></pre></div></div>
</li> </li>
<li id="section-8"> <li id="section-8">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a> <a class="pilcrow" href="#section-8">&#182;</a>
</div> </div>
<p>Handle Ctrl-v
<p>Proxy node&#39;s line listener
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">nodeLineListener = </span><span class="nx">rli</span><span class="p">.</span><span class="nx">listeners</span><span class="p">(</span><span class="s">&#39;line&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <div class="content"><div class='highlight'><pre> inputStream.<span class="literal">on</span> <span class="string">'keypress'</span>, (char, key) -&gt;
<span class="nx">rli</span><span class="p">.</span><span class="nx">removeListener</span> <span class="s">&#39;line&#39;</span><span class="p">,</span> <span class="nx">nodeLineListener</span> <span class="keyword">return</span> <span class="keyword">unless</span> key <span class="keyword">and</span> key.ctrl <span class="keyword">and</span> <span class="keyword">not</span> key.meta <span class="keyword">and</span> <span class="keyword">not</span> key.shift <span class="keyword">and</span> key.name <span class="keyword">is</span> <span class="string">'v'</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">on</span> <span class="s">&#39;line&#39;</span><span class="p">,</span> <span class="nf">(cmd) -&gt;</span> <span class="keyword">if</span> multiline.enabled</pre></div></div>
<span class="k">if</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span>
<span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">#{</span><span class="nx">cmd</span><span class="si">}</span><span class="s">\n&quot;</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">setPrompt</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">prompt</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">prompt</span> <span class="kc">true</span>
<span class="k">else</span>
<span class="nx">nodeLineListener</span> <span class="nx">cmd</span>
<span class="k">return</span></pre></div></div>
</li> </li>
<li id="section-9"> <li id="section-9">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a> <a class="pilcrow" href="#section-9">&#182;</a>
</div> </div>
<p>allow arbitrarily switching between modes any time before multiple lines are entered
<p>Handle Ctrl-v
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">inputStream</span><span class="p">.</span><span class="nx">on</span> <span class="s">&#39;keypress&#39;</span><span class="p">,</span> <span class="nf">(char, key) -&gt;</span> <div class="content"><div class='highlight'><pre> <span class="keyword">unless</span> multiline.buffer.match <span class="regexp">/\n/</span>
<span class="k">return</span> <span class="k">unless</span> <span class="nx">key</span> <span class="o">and</span> <span class="nx">key</span><span class="p">.</span><span class="nx">ctrl</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">key</span><span class="p">.</span><span class="nx">meta</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">key</span><span class="p">.</span><span class="nx">shift</span> <span class="o">and</span> <span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">is</span> <span class="s">&#39;v&#39;</span> multiline.enabled = <span class="keyword">not</span> multiline.enabled
<span class="k">if</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span></pre></div></div> rli.setPrompt repl.prompt
rli.prompt <span class="literal">true</span>
<span class="keyword">return</span></pre></div></div>
</li> </li>
<li id="section-10"> <li id="section-10">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a> <a class="pilcrow" href="#section-10">&#182;</a>
</div> </div>
<p>no-op unless the current line is empty
<p>allow arbitrarily switching between modes any time before multiple lines are entered
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">unless</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span><span class="p">.</span><span class="nx">match</span> <span class="sr">/\n/</span> <div class="content"><div class='highlight'><pre> <span class="keyword">return</span> <span class="keyword">if</span> rli.line? <span class="keyword">and</span> <span class="keyword">not</span> rli.line.match <span class="regexp">/^\s*$/</span></pre></div></div>
<span class="nv">multiline.enabled = </span><span class="o">not</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">setPrompt</span> <span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">prompt</span> <span class="kc">true</span>
<span class="k">return</span></pre></div></div>
</li> </li>
<li id="section-11"> <li id="section-11">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a> <a class="pilcrow" href="#section-11">&#182;</a>
</div> </div>
<p>eval, print, loop
<p>no-op unless the current line is empty
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">return</span> <span class="k">if</span> <span class="nx">rli</span><span class="p">.</span><span class="nx">line</span><span class="o">?</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">rli</span><span class="p">.</span><span class="nx">line</span><span class="p">.</span><span class="nx">match</span> <span class="sr">/^\s*$/</span></pre></div></div> <div class="content"><div class='highlight'><pre> multiline.enabled = <span class="keyword">not</span> multiline.enabled
rli.line = <span class="string">''</span>
rli.cursor = <span class="number">0</span>
rli.output.cursorTo <span class="number">0</span>
rli.output.clearLine <span class="number">1</span></pre></div></div>
</li> </li>
<li id="section-12"> <li id="section-12">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a> <a class="pilcrow" href="#section-12">&#182;</a>
</div> </div>
<p>eval, print, loop
</p>
</div>
<div class="content"><div class="highlight"><pre> <span class="nv">multiline.enabled = </span><span class="o">not</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span>
<span class="nv">rli.line = </span><span class="s">&#39;&#39;</span>
<span class="nv">rli.cursor = </span><span class="mi">0</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">output</span><span class="p">.</span><span class="nx">cursorTo</span> <span class="mi">0</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">output</span><span class="p">.</span><span class="nx">clearLine</span> <span class="mi">1</span></pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="pilwrap">
<a class="pilcrow" href="#section-13">&#182;</a>
</div>
<p>XXX: multiline hack <p>XXX: multiline hack
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">multiline.buffer = </span><span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\n/g</span><span class="p">,</span> <span class="s">&#39;\uFF00&#39;</span> <div class="content"><div class='highlight'><pre> multiline.buffer = multiline.buffer.replace <span class="regexp">/\n/g</span>, <span class="string">'\uFF00'</span>
<span class="nx">rli</span><span class="p">.</span><span class="nx">emit</span> <span class="s">&#39;line&#39;</span><span class="p">,</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span> rli.emit <span class="string">'line'</span>, multiline.buffer
<span class="nv">multiline.buffer = </span><span class="s">&#39;&#39;</span> multiline.buffer = <span class="string">''</span>
<span class="k">else</span> <span class="keyword">else</span>
<span class="nv">multiline.enabled = </span><span class="o">not</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span> multiline.enabled = <span class="keyword">not</span> multiline.enabled
<span class="nx">rli</span><span class="p">.</span><span class="nx">setPrompt</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">initialPrompt</span> rli.setPrompt multiline.initialPrompt
<span class="nx">rli</span><span class="p">.</span><span class="nx">prompt</span> <span class="kc">true</span> rli.prompt <span class="literal">true</span>
<span class="k">return</span> <span class="keyword">return</span>
<span class="nv">module.exports =</span> module.exports =
<span class="nv">start: </span><span class="nf">(opts = {}) -&gt;</span> start: (opts = {}) -&gt;
<span class="nv">opts = </span><span class="nx">merge</span> <span class="nx">replDefaults</span><span class="p">,</span> <span class="nx">opts</span> [major, minor, build] = process.versions.node.split(<span class="string">'.'</span>).map (n) -&gt; parseInt(n)
<span class="nv">repl = </span><span class="nx">nodeREPL</span><span class="p">.</span><span class="nx">start</span> <span class="nx">opts</span>
<span class="nx">repl</span><span class="p">.</span><span class="nx">on</span> <span class="s">&#39;exit&#39;</span><span class="p">,</span> <span class="nf">-&gt;</span> <span class="nx">repl</span><span class="p">.</span><span class="nx">outputStream</span><span class="p">.</span><span class="nx">write</span> <span class="s">&#39;\n&#39;</span>
<span class="nx">addMultilineHandler</span> <span class="nx">repl</span>
<span class="nx">repl</span>
</pre></div></div> <span class="keyword">if</span> major <span class="keyword">is</span> <span class="number">0</span> <span class="keyword">and</span> minor &lt; <span class="number">8</span>
console.warn <span class="string">"Node 0.8.0+ required for CoffeeScript REPL"</span>
process.exit <span class="number">1</span>
opts = merge replDefaults, opts
repl = nodeREPL.start opts
repl.<span class="literal">on</span> <span class="string">'exit'</span>, -&gt; repl.outputStream.write <span class="string">'\n'</span>
addMultilineHandler repl
repl</pre></div></div>
</li> </li>

File diff suppressed because it is too large Load diff

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>scope.litcoffee</h1> <h1>scope.litcoffee</h1>
@ -100,8 +101,10 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
@ -115,304 +118,290 @@ with external scopes.
</p> </p>
<p>Import the helpers we plan to use. <p>Import the helpers we plan to use.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="p">{</span><span class="nx">extend</span><span class="p">,</span> <span class="nx">last</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">&#39;./helpers&#39;</span> <div class="content"><div class='highlight'><pre>{extend, last} = require <span class="string">'./helpers'</span>
<span class="nv">exports.Scope = </span><span class="k">class</span> <span class="nx">Scope</span></pre></div></div> exports.Scope = <span class="class"><span class="keyword">class</span> <span class="title">Scope</span></span></pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>The <code>root</code> is the top-level <strong>Scope</strong> object for a given file. <p>The <code>root</code> is the top-level <strong>Scope</strong> object for a given file.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="vi">@root: </span><span class="kc">null</span></pre></div></div> <div class="content"><div class='highlight'><pre> <span class="property">@root</span>: <span class="literal">null</span></pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>Initialize a scope with its parent, for lookups up the chain, <p>Initialize a scope with its parent, for lookups up the chain,
as well as a reference to the <strong>Block</strong> node it belongs to, which is as well as a reference to the <strong>Block</strong> node it belongs to, which is
where it should declare its variables, and a reference to the function that where it should declare its variables, and a reference to the function that
it belongs to. it belongs to.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(@parent, @expressions, @method) -&gt;</span> <div class="content"><div class='highlight'><pre> constructor: (<span class="property">@parent</span>, <span class="property">@expressions</span>, <span class="property">@method</span>) -&gt;
<span class="vi">@variables = </span><span class="p">[{</span><span class="nv">name: </span><span class="s">&#39;arguments&#39;</span><span class="p">,</span> <span class="nv">type: </span><span class="s">&#39;arguments&#39;</span><span class="p">}]</span> <span class="property">@variables</span> = [{name: <span class="string">'arguments'</span>, type: <span class="string">'arguments'</span>}]
<span class="vi">@positions = </span><span class="p">{}</span> <span class="property">@positions</span> = {}
<span class="nv">Scope.root = </span><span class="k">this</span> <span class="k">unless</span> <span class="nx">@parent</span></pre></div></div> Scope.root = <span class="keyword">this</span> <span class="keyword">unless</span> <span class="property">@parent</span></pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>Adds a new variable or overrides an existing one. <p>Adds a new variable or overrides an existing one.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">add: </span><span class="nf">(name, type, immediate) -&gt;</span> <div class="content"><div class='highlight'><pre> add: (name, type, immediate) -&gt;
<span class="k">return</span> <span class="nx">@parent</span><span class="p">.</span><span class="nx">add</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">type</span><span class="p">,</span> <span class="nx">immediate</span> <span class="k">if</span> <span class="nx">@shared</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">immediate</span> <span class="keyword">return</span> <span class="property">@parent</span>.add name, type, immediate <span class="keyword">if</span> <span class="property">@shared</span> <span class="keyword">and</span> <span class="keyword">not</span> immediate
<span class="k">if</span> <span class="nb">Object</span><span class="o">::</span><span class="nx">hasOwnProperty</span><span class="p">.</span><span class="nx">call</span> <span class="nx">@positions</span><span class="p">,</span> <span class="nx">name</span> <span class="keyword">if</span> Object::hasOwnProperty.call <span class="property">@positions</span>, name
<span class="nx">@variables</span><span class="p">[</span><span class="nx">@positions</span><span class="p">[</span><span class="nx">name</span><span class="p">]].</span><span class="nv">type = </span><span class="nx">type</span> <span class="property">@variables</span>[<span class="property">@positions</span>[name]].type = type
<span class="k">else</span> <span class="keyword">else</span>
<span class="nx">@positions</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@variables</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span><span class="nx">name</span><span class="p">,</span> <span class="nx">type</span><span class="p">})</span> <span class="o">-</span> <span class="mi">1</span></pre></div></div> <span class="property">@positions</span>[name] = <span class="property">@variables</span>.push({name, type}) - <span class="number">1</span></pre></div></div>
</li> </li>
<li id="section-5"> <li id="section-5">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a> <a class="pilcrow" href="#section-5">&#182;</a>
</div> </div>
<p>When <code>super</code> is called, we need to find the name of the current method we&#39;re <p>When <code>super</code> is called, we need to find the name of the current method we&#39;re
in, so that we know how to invoke the same method of the parent class. This in, so that we know how to invoke the same method of the parent class. This
can get complicated if super is being called from an inner function. can get complicated if super is being called from an inner function.
<code>namedMethod</code> will walk up the scope tree until it either finds the first <code>namedMethod</code> will walk up the scope tree until it either finds the first
function object that has a name filled in, or bottoms out. function object that has a name filled in, or bottoms out.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">namedMethod: </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre> namedMethod: -&gt;
<span class="k">return</span> <span class="nx">@method</span> <span class="k">if</span> <span class="nx">@method</span><span class="o">?</span><span class="p">.</span><span class="nx">name</span> <span class="o">or</span> <span class="o">!</span><span class="nx">@parent</span> <span class="keyword">return</span> <span class="property">@method</span> <span class="keyword">if</span> <span class="property">@method</span>?.name <span class="keyword">or</span> !<span class="property">@parent</span>
<span class="nx">@parent</span><span class="p">.</span><span class="nx">namedMethod</span><span class="p">()</span></pre></div></div> <span class="property">@parent</span>.namedMethod()</pre></div></div>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<p>Look up a variable name in lexical scope, and declare it if it does not <p>Look up a variable name in lexical scope, and declare it if it does not
already exist. already exist.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">find: </span><span class="nf">(name) -&gt;</span> <div class="content"><div class='highlight'><pre> find: (name) -&gt;
<span class="k">return</span> <span class="kc">yes</span> <span class="k">if</span> <span class="nx">@check</span> <span class="nx">name</span> <span class="keyword">return</span> <span class="literal">yes</span> <span class="keyword">if</span> <span class="property">@check</span> name
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s">&#39;var&#39;</span> <span class="property">@add</span> name, <span class="string">'var'</span>
<span class="kc">no</span></pre></div></div> <span class="literal">no</span></pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Reserve a variable name as originating from a function parameter for this <p>Reserve a variable name as originating from a function parameter for this
scope. No <code>var</code> required for internal references. scope. No <code>var</code> required for internal references.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">parameter: </span><span class="nf">(name) -&gt;</span> <div class="content"><div class='highlight'><pre> parameter: (name) -&gt;
<span class="k">return</span> <span class="k">if</span> <span class="nx">@shared</span> <span class="o">and</span> <span class="nx">@parent</span><span class="p">.</span><span class="nx">check</span> <span class="nx">name</span><span class="p">,</span> <span class="kc">yes</span> <span class="keyword">return</span> <span class="keyword">if</span> <span class="property">@shared</span> <span class="keyword">and</span> <span class="property">@parent</span>.check name, <span class="literal">yes</span>
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s">&#39;param&#39;</span></pre></div></div> <span class="property">@add</span> name, <span class="string">'param'</span></pre></div></div>
</li> </li>
<li id="section-8"> <li id="section-8">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a> <a class="pilcrow" href="#section-8">&#182;</a>
</div> </div>
<p>Just check to see if a variable has already been declared, without reserving, <p>Just check to see if a variable has already been declared, without reserving,
walks up to the root scope. walks up to the root scope.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">check: </span><span class="nf">(name) -&gt;</span> <div class="content"><div class='highlight'><pre> check: (name) -&gt;
<span class="o">!!</span><span class="p">(</span><span class="nx">@type</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">or</span> <span class="nx">@parent</span><span class="o">?</span><span class="p">.</span><span class="nx">check</span><span class="p">(</span><span class="nx">name</span><span class="p">))</span></pre></div></div> !!(<span class="property">@type</span>(name) <span class="keyword">or</span> <span class="property">@parent</span>?.check(name))</pre></div></div>
</li> </li>
<li id="section-9"> <li id="section-9">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a> <a class="pilcrow" href="#section-9">&#182;</a>
</div> </div>
<p>Generate a temporary variable name at the given index. <p>Generate a temporary variable name at the given index.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">temporary: </span><span class="nf">(name, index) -&gt;</span> <div class="content"><div class='highlight'><pre> temporary: (name, index) -&gt;
<span class="k">if</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="keyword">if</span> name.length &gt; <span class="number">1</span>
<span class="s">&#39;_&#39;</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="k">if</span> <span class="nx">index</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="k">then</span> <span class="nx">index</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">else</span> <span class="s">&#39;&#39;</span> <span class="string">'_'</span> + name + <span class="keyword">if</span> index &gt; <span class="number">1</span> <span class="keyword">then</span> index - <span class="number">1</span> <span class="keyword">else</span> <span class="string">''</span>
<span class="k">else</span> <span class="keyword">else</span>
<span class="s">&#39;_&#39;</span> <span class="o">+</span> <span class="p">(</span><span class="nx">index</span> <span class="o">+</span> <span class="nb">parseInt</span> <span class="nx">name</span><span class="p">,</span> <span class="mi">36</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">36</span><span class="p">).</span><span class="nx">replace</span> <span class="sr">/\d/g</span><span class="p">,</span> <span class="s">&#39;a&#39;</span></pre></div></div> <span class="string">'_'</span> + (index + parseInt name, <span class="number">36</span>).toString(<span class="number">36</span>).replace <span class="regexp">/\d/g</span>, <span class="string">'a'</span></pre></div></div>
</li> </li>
<li id="section-10"> <li id="section-10">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a> <a class="pilcrow" href="#section-10">&#182;</a>
</div> </div>
<p>Gets the type of a variable. <p>Gets the type of a variable.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">type: </span><span class="nf">(name) -&gt;</span> <div class="content"><div class='highlight'><pre> type: (name) -&gt;
<span class="k">return</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span> <span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span> <span class="o">is</span> <span class="nx">name</span> <span class="keyword">return</span> v.type <span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.name <span class="keyword">is</span> name
<span class="kc">null</span></pre></div></div> <span class="literal">null</span></pre></div></div>
</li> </li>
<li id="section-11"> <li id="section-11">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a> <a class="pilcrow" href="#section-11">&#182;</a>
</div> </div>
<p>If we need to store an intermediate result, find an available name for a <p>If we need to store an intermediate result, find an available name for a
compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on... compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on...
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">freeVariable: </span><span class="nf">(name, reserve=true) -&gt;</span> <div class="content"><div class='highlight'><pre> freeVariable: (name, reserve=<span class="literal">true</span>) -&gt;
<span class="nv">index = </span><span class="mi">0</span> index = <span class="number">0</span>
<span class="nx">index</span><span class="o">++</span> <span class="k">while</span> <span class="nx">@check</span><span class="p">((</span><span class="nv">temp = </span><span class="nx">@temporary</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">index</span><span class="p">))</span> index++ <span class="keyword">while</span> <span class="property">@check</span>((temp = <span class="property">@temporary</span> name, index))
<span class="nx">@add</span> <span class="nx">temp</span><span class="p">,</span> <span class="s">&#39;var&#39;</span><span class="p">,</span> <span class="kc">yes</span> <span class="k">if</span> <span class="nx">reserve</span> <span class="property">@add</span> temp, <span class="string">'var'</span>, <span class="literal">yes</span> <span class="keyword">if</span> reserve
<span class="nx">temp</span></pre></div></div> temp</pre></div></div>
</li> </li>
<li id="section-12"> <li id="section-12">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a> <a class="pilcrow" href="#section-12">&#182;</a>
</div> </div>
<p>Ensure that an assignment is made at the top of this scope <p>Ensure that an assignment is made at the top of this scope
(or at the top-level scope, if requested). (or at the top-level scope, if requested).
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">assign: </span><span class="nf">(name, value) -&gt;</span> <div class="content"><div class='highlight'><pre> assign: (name, value) -&gt;
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="p">{</span><span class="nx">value</span><span class="p">,</span> <span class="nv">assigned: </span><span class="kc">yes</span><span class="p">},</span> <span class="kc">yes</span> <span class="property">@add</span> name, {value, assigned: <span class="literal">yes</span>}, <span class="literal">yes</span>
<span class="vi">@hasAssignments = </span><span class="kc">yes</span></pre></div></div> <span class="property">@hasAssignments</span> = <span class="literal">yes</span></pre></div></div>
</li> </li>
<li id="section-13"> <li id="section-13">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a> <a class="pilcrow" href="#section-13">&#182;</a>
</div> </div>
<p>Does this scope have any declared variables? <p>Does this scope have any declared variables?
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">hasDeclarations: </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre> hasDeclarations: -&gt;
<span class="o">!!</span><span class="nx">@declaredVariables</span><span class="p">().</span><span class="nx">length</span></pre></div></div> !!<span class="property">@declaredVariables</span>().length</pre></div></div>
</li> </li>
<li id="section-14"> <li id="section-14">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a> <a class="pilcrow" href="#section-14">&#182;</a>
</div> </div>
<p>Return the list of variables first declared in this scope. <p>Return the list of variables first declared in this scope.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">declaredVariables: </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre> declaredVariables: -&gt;
<span class="nv">realVars = </span><span class="p">[]</span> realVars = []
<span class="nv">tempVars = </span><span class="p">[]</span> tempVars = []
<span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span> <span class="o">is</span> <span class="s">&#39;var&#39;</span> <span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.type <span class="keyword">is</span> <span class="string">'var'</span>
<span class="p">(</span><span class="k">if</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">is</span> <span class="s">&#39;_&#39;</span> <span class="k">then</span> <span class="nx">tempVars</span> <span class="k">else</span> <span class="nx">realVars</span><span class="p">).</span><span class="nx">push</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span> (<span class="keyword">if</span> v.name.charAt(<span class="number">0</span>) <span class="keyword">is</span> <span class="string">'_'</span> <span class="keyword">then</span> tempVars <span class="keyword">else</span> realVars).push v.name
<span class="nx">realVars</span><span class="p">.</span><span class="nx">sort</span><span class="p">().</span><span class="nx">concat</span> <span class="nx">tempVars</span><span class="p">.</span><span class="nx">sort</span><span class="p">()</span></pre></div></div> realVars.sort().concat tempVars.sort()</pre></div></div>
</li> </li>
<li id="section-15"> <li id="section-15">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</a> <a class="pilcrow" href="#section-15">&#182;</a>
</div> </div>
<p>Return the list of assignments that are supposed to be made at the top <p>Return the list of assignments that are supposed to be made at the top
of this scope. of this scope.
@ -420,10 +409,8 @@ of this scope.
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">assignedVariables: </span><span class="nf">-&gt;</span> <div class="content"><div class='highlight'><pre> assignedVariables: -&gt;
<span class="s">&quot;</span><span class="si">#{</span><span class="nx">v</span><span class="p">.</span><span class="nx">name</span><span class="si">}</span><span class="s"> = </span><span class="si">#{</span><span class="nx">v</span><span class="p">.</span><span class="nx">type</span><span class="p">.</span><span class="nx">value</span><span class="si">}</span><span class="s">&quot;</span> <span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span><span class="p">.</span><span class="nx">assigned</span> <span class="string">"<span class="subst">#{v.name}</span> = <span class="subst">#{v.type.value}</span>"</span> <span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.type.assigned</pre></div></div>
</pre></div></div>
</li> </li>

View file

@ -93,6 +93,7 @@
</ul> </ul>
<ul class="sections"> <ul class="sections">
<li id="title"> <li id="title">
<div class="annotation"> <div class="annotation">
<h1>sourcemap.coffee</h1> <h1>sourcemap.coffee</h1>
@ -100,106 +101,104 @@
</li> </li>
<li id="section-1"> <li id="section-1">
<div class="annotation"> <div class="annotation">
<div class="pilwrap">
<div class="pilwrap for-h3">
<a class="pilcrow" href="#section-1">&#182;</a> <a class="pilcrow" href="#section-1">&#182;</a>
</div> </div>
<h3>LineMapping</h3> <h3>LineMapping</h3>
<p>Hold data about mappings for one line of generated source code. <p>Hold data about mappings for one line of generated source code.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="k">class</span> <span class="nx">LineMapping</span> <div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">LineMapping</span></span>
<span class="nv">constructor: </span><span class="nf">(@generatedLine) -&gt;</span></pre></div></div> constructor: (<span class="property">@generatedLine</span>) -&gt;</pre></div></div>
</li> </li>
<li id="section-2"> <li id="section-2">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a> <a class="pilcrow" href="#section-2">&#182;</a>
</div> </div>
<p>columnMap keeps track of which columns we&#39;ve already mapped. <p>columnMap keeps track of which columns we&#39;ve already mapped.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="vi">@columnMap = </span><span class="p">{}</span></pre></div></div> <div class="content"><div class='highlight'><pre> <span class="property">@columnMap</span> = {}</pre></div></div>
</li> </li>
<li id="section-3"> <li id="section-3">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a> <a class="pilcrow" href="#section-3">&#182;</a>
</div> </div>
<p>columnMappings is an array of all column mappings, sorted by generated-column. <p>columnMappings is an array of all column mappings, sorted by generated-column.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="vi">@columnMappings = </span><span class="p">[]</span> <div class="content"><div class='highlight'><pre> <span class="property">@columnMappings</span> = []
<span class="nv">addMapping: </span><span class="nf">(generatedColumn, [sourceLine, sourceColumn], options={}) -&gt;</span> addMapping: (generatedColumn, [sourceLine, sourceColumn], options={}) -&gt;
<span class="k">if</span> <span class="nx">@columnMap</span><span class="p">[</span><span class="nx">generatedColumn</span><span class="p">]</span> <span class="o">and</span> <span class="nx">options</span><span class="p">.</span><span class="nx">noReplace</span></pre></div></div> <span class="keyword">if</span> <span class="property">@columnMap</span>[generatedColumn] <span class="keyword">and</span> options.noReplace</pre></div></div>
</li> </li>
<li id="section-4"> <li id="section-4">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a> <a class="pilcrow" href="#section-4">&#182;</a>
</div> </div>
<p>We already have a mapping for this column. <p>We already have a mapping for this column.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">return</span> <div class="content"><div class='highlight'><pre> <span class="keyword">return</span>
<span class="nx">@columnMap</span><span class="p">[</span><span class="nx">generatedColumn</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> <span class="property">@columnMap</span>[generatedColumn] = {
<span class="nv">generatedLine: </span><span class="nx">@generatedLine</span> generatedLine: <span class="property">@generatedLine</span>
<span class="nx">generatedColumn</span> generatedColumn
<span class="nx">sourceLine</span> sourceLine
<span class="nx">sourceColumn</span> sourceColumn
<span class="p">}</span> }
<span class="nx">@columnMappings</span><span class="p">.</span><span class="nx">push</span> <span class="nx">@columnMap</span><span class="p">[</span><span class="nx">generatedColumn</span><span class="p">]</span> <span class="property">@columnMappings</span>.push <span class="property">@columnMap</span>[generatedColumn]
<span class="nx">@columnMappings</span><span class="p">.</span><span class="nx">sort</span> <span class="nf">(a,b) -&gt;</span> <span class="nx">a</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="o">-</span> <span class="nx">b</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="property">@columnMappings</span>.sort (a,b) -&gt; a.generatedColumn - b.generatedColumn
<span class="nv">getSourcePosition: </span><span class="nf">(generatedColumn) -&gt;</span> getSourcePosition: (generatedColumn) -&gt;
<span class="nv">answer = </span><span class="kc">null</span> answer = <span class="literal">null</span>
<span class="nv">lastColumnMapping = </span><span class="kc">null</span> lastColumnMapping = <span class="literal">null</span>
<span class="k">for</span> <span class="nx">columnMapping</span> <span class="k">in</span> <span class="nx">@columnMappings</span> <span class="keyword">for</span> columnMapping <span class="keyword">in</span> <span class="property">@columnMappings</span>
<span class="k">if</span> <span class="nx">columnMapping</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="o">&gt;</span> <span class="nx">generatedColumn</span> <span class="keyword">if</span> columnMapping.generatedColumn &gt; generatedColumn
<span class="k">break</span> <span class="keyword">break</span>
<span class="k">else</span> <span class="keyword">else</span>
<span class="nv">lastColumnMapping = </span><span class="nx">columnMapping</span> lastColumnMapping = columnMapping
<span class="k">if</span> <span class="nx">lastColumnMapping</span> <span class="keyword">if</span> lastColumnMapping
<span class="nv">answer = </span><span class="p">[</span><span class="nx">lastColumnMapping</span><span class="p">.</span><span class="nx">sourceLine</span><span class="p">,</span> <span class="nx">lastColumnMapping</span><span class="p">.</span><span class="nx">sourceColumn</span><span class="p">]</span></pre></div></div> answer = [lastColumnMapping.sourceLine, lastColumnMapping.sourceColumn]</pre></div></div>
</li> </li>
<li id="section-5"> <li id="section-5">
<div class="annotation"> <div class="annotation">
<div class="pilwrap">
<div class="pilwrap for-h3">
<a class="pilcrow" href="#section-5">&#182;</a> <a class="pilcrow" href="#section-5">&#182;</a>
</div> </div>
<h3>SourceMap</h3> <h3>SourceMap</h3>
<p>Maps locations in a generated source file back to locations in the original source file. <p>Maps locations in a generated source file back to locations in the original source file.
@ -208,40 +207,38 @@
SourceMap can be converted to a &quot;v3&quot; style sourcemap with <code>#generateV3SourceMap()</code>, for example SourceMap can be converted to a &quot;v3&quot; style sourcemap with <code>#generateV3SourceMap()</code>, for example
but the SourceMap class itself knows nothing about v3 source maps. but the SourceMap class itself knows nothing about v3 source maps.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="k">class</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">SourceMap</span> <div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">exports</span>.<span class="title">SourceMap</span></span>
<span class="nv">constructor: </span><span class="p">()</span> <span class="nf">-&gt;</span></pre></div></div> constructor: () -&gt;</pre></div></div>
</li> </li>
<li id="section-6"> <li id="section-6">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a> <a class="pilcrow" href="#section-6">&#182;</a>
</div> </div>
<p><code>generatedLines</code> is an array of LineMappings, one per generated line. <p><code>generatedLines</code> is an array of LineMappings, one per generated line.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="vi">@generatedLines = </span><span class="p">[]</span></pre></div></div> <div class="content"><div class='highlight'><pre> <span class="property">@generatedLines</span> = []</pre></div></div>
</li> </li>
<li id="section-7"> <li id="section-7">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a> <a class="pilcrow" href="#section-7">&#182;</a>
</div> </div>
<p>Adds a mapping to this SourceMap. <p>Adds a mapping to this SourceMap.
</p> </p>
@ -250,93 +247,89 @@ but the SourceMap class itself knows nothing about v3 source maps.
</p> </p>
<p>If <code>options.noReplace</code> is true, then if there is already a mapping for <p>If <code>options.noReplace</code> is true, then if there is already a mapping for
the specified <code>generatedLine</code> and <code>generatedColumn</code>, this will have no effect. the specified <code>generatedLine</code> and <code>generatedColumn</code>, this will have no effect.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">addMapping: </span><span class="nf">(sourceLocation, generatedLocation, options={}) -&gt;</span> <div class="content"><div class='highlight'><pre> addMapping: (sourceLocation, generatedLocation, options={}) -&gt;
<span class="p">[</span><span class="nx">generatedLine</span><span class="p">,</span> <span class="nx">generatedColumn</span><span class="p">]</span> <span class="o">=</span> <span class="nx">generatedLocation</span> [generatedLine, generatedColumn] = generatedLocation
<span class="nv">lineMapping = </span><span class="nx">@generatedLines</span><span class="p">[</span><span class="nx">generatedLine</span><span class="p">]</span> lineMapping = <span class="property">@generatedLines</span>[generatedLine]
<span class="k">if</span> <span class="o">not</span> <span class="nx">lineMapping</span> <span class="keyword">if</span> <span class="keyword">not</span> lineMapping
<span class="nv">lineMapping = </span><span class="nx">@generatedLines</span><span class="p">[</span><span class="nx">generatedLine</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">LineMapping</span><span class="p">(</span><span class="nx">generatedLine</span><span class="p">)</span> lineMapping = <span class="property">@generatedLines</span>[generatedLine] = <span class="keyword">new</span> LineMapping(generatedLine)
<span class="nx">lineMapping</span><span class="p">.</span><span class="nx">addMapping</span> <span class="nx">generatedColumn</span><span class="p">,</span> <span class="nx">sourceLocation</span><span class="p">,</span> <span class="nx">options</span></pre></div></div> lineMapping.addMapping generatedColumn, sourceLocation, options</pre></div></div>
</li> </li>
<li id="section-8"> <li id="section-8">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a> <a class="pilcrow" href="#section-8">&#182;</a>
</div> </div>
<p>Returns [sourceLine, sourceColumn], or null if no mapping could be found. <p>Returns [sourceLine, sourceColumn], or null if no mapping could be found.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">getSourcePosition: </span><span class="nf">([generatedLine, generatedColumn]) -&gt;</span> <div class="content"><div class='highlight'><pre> getSourcePosition: ([generatedLine, generatedColumn]) -&gt;
<span class="nv">answer = </span><span class="kc">null</span> answer = <span class="literal">null</span>
<span class="nv">lineMapping = </span><span class="nx">@generatedLines</span><span class="p">[</span><span class="nx">generatedLine</span><span class="p">]</span> lineMapping = <span class="property">@generatedLines</span>[generatedLine]
<span class="k">if</span> <span class="o">not</span> <span class="nx">lineMapping</span></pre></div></div> <span class="keyword">if</span> <span class="keyword">not</span> lineMapping</pre></div></div>
</li> </li>
<li id="section-9"> <li id="section-9">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a> <a class="pilcrow" href="#section-9">&#182;</a>
</div> </div>
<p>TODO: Search backwards for the line? <p>TODO: Search backwards for the line?
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">else</span> <div class="content"><div class='highlight'><pre> <span class="keyword">else</span>
<span class="nv">answer = </span><span class="nx">lineMapping</span><span class="p">.</span><span class="nx">getSourcePosition</span> <span class="nx">generatedColumn</span> answer = lineMapping.getSourcePosition generatedColumn
<span class="nx">answer</span></pre></div></div> answer</pre></div></div>
</li> </li>
<li id="section-10"> <li id="section-10">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a> <a class="pilcrow" href="#section-10">&#182;</a>
</div> </div>
<p><code>fn</code> will be called once for every recorded mapping, in the order in <p><code>fn</code> will be called once for every recorded mapping, in the order in
which they occur in the generated source. <code>fn</code> will be passed an object which they occur in the generated source. <code>fn</code> will be passed an object
with four properties: sourceLine, sourceColumn, generatedLine, and with four properties: sourceLine, sourceColumn, generatedLine, and
generatedColumn. generatedColumn.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">forEachMapping: </span><span class="nf">(fn) -&gt;</span> <div class="content"><div class='highlight'><pre> forEachMapping: (fn) -&gt;
<span class="k">for</span> <span class="nx">lineMapping</span><span class="p">,</span> <span class="nx">generatedLineNumber</span> <span class="k">in</span> <span class="nx">@generatedLines</span> <span class="keyword">for</span> lineMapping, generatedLineNumber <span class="keyword">in</span> <span class="property">@generatedLines</span>
<span class="k">if</span> <span class="nx">lineMapping</span> <span class="keyword">if</span> lineMapping
<span class="k">for</span> <span class="nx">columnMapping</span> <span class="k">in</span> <span class="nx">lineMapping</span><span class="p">.</span><span class="nx">columnMappings</span> <span class="keyword">for</span> columnMapping <span class="keyword">in</span> lineMapping.columnMappings
<span class="nx">fn</span><span class="p">(</span><span class="nx">columnMapping</span><span class="p">)</span></pre></div></div> fn(columnMapping)</pre></div></div>
</li> </li>
<li id="section-11"> <li id="section-11">
<div class="annotation"> <div class="annotation">
<div class="pilwrap">
<div class="pilwrap for-h3">
<a class="pilcrow" href="#section-11">&#182;</a> <a class="pilcrow" href="#section-11">&#182;</a>
</div> </div>
<h3>generateV3SourceMap</h3> <h3>generateV3SourceMap</h3>
<p>Builds a V3 source map from a SourceMap object. <p>Builds a V3 source map from a SourceMap object.
Returns the generated JSON as a string. Returns the generated JSON as a string.
@ -346,59 +339,57 @@ Returns the generated JSON as a string.
<code>options.sourceFiles</code> and <code>options.generatedFile</code> may be passed to set &quot;sources&quot; and &quot;file&quot;, <code>options.sourceFiles</code> and <code>options.generatedFile</code> may be passed to set &quot;sources&quot; and &quot;file&quot;,
respectively. Note that <code>sourceFiles</code> must be an array. respectively. Note that <code>sourceFiles</code> must be an array.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.generateV3SourceMap = </span><span class="nf">(sourceMap, options={}) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">generateV3SourceMap</span></span> = (sourceMap, options={}, code) -&gt;
<span class="nv">sourceRoot = </span><span class="nx">options</span><span class="p">.</span><span class="nx">sourceRoot</span> <span class="o">or</span> <span class="s">&quot;&quot;</span> sourceRoot = options.sourceRoot <span class="keyword">or</span> <span class="string">""</span>
<span class="nv">sourceFiles = </span><span class="nx">options</span><span class="p">.</span><span class="nx">sourceFiles</span> <span class="o">or</span> <span class="p">[</span><span class="s">&quot;&quot;</span><span class="p">]</span> sourceFiles = options.sourceFiles <span class="keyword">or</span> [<span class="string">""</span>]
<span class="nv">generatedFile = </span><span class="nx">options</span><span class="p">.</span><span class="nx">generatedFile</span> <span class="o">or</span> <span class="s">&quot;&quot;</span> generatedFile = options.generatedFile <span class="keyword">or</span> <span class="string">""</span>
<span class="nv">writingGeneratedLine = </span><span class="mi">0</span> writingGeneratedLine = <span class="number">0</span>
<span class="nv">lastGeneratedColumnWritten = </span><span class="mi">0</span> lastGeneratedColumnWritten = <span class="number">0</span>
<span class="nv">lastSourceLineWritten = </span><span class="mi">0</span> lastSourceLineWritten = <span class="number">0</span>
<span class="nv">lastSourceColumnWritten = </span><span class="mi">0</span> lastSourceColumnWritten = <span class="number">0</span>
<span class="nv">needComma = </span><span class="kc">no</span> needComma = <span class="literal">no</span>
<span class="nv">mappings = </span><span class="s">&quot;&quot;</span> mappings = <span class="string">""</span>
<span class="nx">sourceMap</span><span class="p">.</span><span class="nx">forEachMapping</span> <span class="nf">(mapping) -&gt;</span> sourceMap.forEachMapping (mapping) -&gt;
<span class="k">while</span> <span class="nx">writingGeneratedLine</span> <span class="o">&lt;</span> <span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedLine</span> <span class="keyword">while</span> writingGeneratedLine &lt; mapping.generatedLine
<span class="nv">lastGeneratedColumnWritten = </span><span class="mi">0</span> lastGeneratedColumnWritten = <span class="number">0</span>
<span class="nv">needComma = </span><span class="kc">no</span> needComma = <span class="literal">no</span>
<span class="nx">mappings</span> <span class="o">+=</span> <span class="s">&quot;;&quot;</span> mappings += <span class="string">";"</span>
<span class="nx">writingGeneratedLine</span><span class="o">++</span></pre></div></div> writingGeneratedLine++</pre></div></div>
</li> </li>
<li id="section-12"> <li id="section-12">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a> <a class="pilcrow" href="#section-12">&#182;</a>
</div> </div>
<p>Write a comma if we&#39;ve already written a segment on this line. <p>Write a comma if we&#39;ve already written a segment on this line.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">if</span> <span class="nx">needComma</span> <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> needComma
<span class="nx">mappings</span> <span class="o">+=</span> <span class="s">&quot;,&quot;</span> mappings += <span class="string">","</span>
<span class="nv">needComma = </span><span class="kc">no</span></pre></div></div> needComma = <span class="literal">no</span></pre></div></div>
</li> </li>
<li id="section-13"> <li id="section-13">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a> <a class="pilcrow" href="#section-13">&#182;</a>
</div> </div>
<p>Write the next segment. <p>Write the next segment.
Segments can be 1, 4, or 5 values. If just one, then it is a generated column which Segments can be 1, 4, or 5 values. If just one, then it is a generated column which
doesn&#39;t match anything in the source code. doesn&#39;t match anything in the source code.
@ -413,152 +404,147 @@ doesn&#39;t match anything in the source code.
</p> </p>
<p>Add the generated start-column <p>Add the generated start-column
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="o">-</span> <span class="nx">lastGeneratedColumnWritten</span><span class="p">)</span> <div class="content"><div class='highlight'><pre> mappings += exports.vlqEncodeValue(mapping.generatedColumn - lastGeneratedColumnWritten)
<span class="nv">lastGeneratedColumnWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedColumn</span></pre></div></div> lastGeneratedColumnWritten = mapping.generatedColumn</pre></div></div>
</li> </li>
<li id="section-14"> <li id="section-14">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a> <a class="pilcrow" href="#section-14">&#182;</a>
</div> </div>
<p>Add the index into the sources list <p>Add the index into the sources list
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></pre></div></div> <div class="content"><div class='highlight'><pre> mappings += exports.vlqEncodeValue(<span class="number">0</span>)</pre></div></div>
</li> </li>
<li id="section-15"> <li id="section-15">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</a> <a class="pilcrow" href="#section-15">&#182;</a>
</div> </div>
<p>Add the source start-line <p>Add the source start-line
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceLine</span> <span class="o">-</span> <span class="nx">lastSourceLineWritten</span><span class="p">)</span> <div class="content"><div class='highlight'><pre> mappings += exports.vlqEncodeValue(mapping.sourceLine - lastSourceLineWritten)
<span class="nv">lastSourceLineWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceLine</span></pre></div></div> lastSourceLineWritten = mapping.sourceLine</pre></div></div>
</li> </li>
<li id="section-16"> <li id="section-16">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</a> <a class="pilcrow" href="#section-16">&#182;</a>
</div> </div>
<p>Add the source start-column <p>Add the source start-column
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceColumn</span> <span class="o">-</span> <span class="nx">lastSourceColumnWritten</span><span class="p">)</span> <div class="content"><div class='highlight'><pre> mappings += exports.vlqEncodeValue(mapping.sourceColumn - lastSourceColumnWritten)
<span class="nv">lastSourceColumnWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceColumn</span></pre></div></div> lastSourceColumnWritten = mapping.sourceColumn</pre></div></div>
</li> </li>
<li id="section-17"> <li id="section-17">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a> <a class="pilcrow" href="#section-17">&#182;</a>
</div> </div>
<p>TODO: Do we care about symbol names for CoffeeScript? Probably not. <p>TODO: Do we care about symbol names for CoffeeScript? Probably not.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">needComma = </span><span class="kc">yes</span> <div class="content"><div class='highlight'><pre> needComma = <span class="literal">yes</span>
<span class="nv">answer = </span><span class="p">{</span> answer = {
<span class="nv">version: </span><span class="mi">3</span> version: <span class="number">3</span>
<span class="nv">file: </span><span class="nx">generatedFile</span> file: generatedFile
<span class="nx">sourceRoot</span> sourceRoot
<span class="nv">sources: </span><span class="nx">sourceFiles</span> sources: sourceFiles
<span class="nv">names: </span><span class="p">[]</span> names: []
<span class="nx">mappings</span> mappings
<span class="p">}</span> }
answer.sourcesContent = [code] <span class="keyword">if</span> options.inline
<span class="k">return</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span> <span class="nx">answer</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="mi">2</span></pre></div></div> <span class="keyword">return</span> JSON.stringify answer, <span class="literal">null</span>, <span class="number">2</span></pre></div></div>
</li> </li>
<li id="section-18"> <li id="section-18">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a> <a class="pilcrow" href="#section-18">&#182;</a>
</div> </div>
<p>Load a SourceMap from a JSON string. Returns the SourceMap object. <p>Load a SourceMap from a JSON string. Returns the SourceMap object.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.loadV3SourceMap = </span><span class="nf">(sourceMap) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">loadV3SourceMap</span></span> = (sourceMap) -&gt;
<span class="nx">todo</span><span class="p">()</span></pre></div></div> todo()</pre></div></div>
</li> </li>
<li id="section-19"> <li id="section-19">
<div class="annotation"> <div class="annotation">
<div class="pilwrap">
<div class="pilwrap for-h3">
<a class="pilcrow" href="#section-19">&#182;</a> <a class="pilcrow" href="#section-19">&#182;</a>
</div> </div>
<h3>Base64 encoding helpers</h3> <h3>Base64 encoding helpers</h3>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">BASE64_CHARS = </span><span class="s">&#39;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/&#39;</span> <div class="content"><div class='highlight'><pre>BASE64_CHARS = <span class="string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
<span class="nv">MAX_BASE64_VALUE = </span><span class="nx">BASE64_CHARS</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span> MAX_BASE64_VALUE = BASE64_CHARS.length - <span class="number">1</span>
<span class="nv">encodeBase64Char = </span><span class="nf">(value) -&gt;</span> <span class="function"><span class="title">encodeBase64Char</span></span> = (value) -&gt;
<span class="k">if</span> <span class="nx">value</span> <span class="o">&gt;</span> <span class="nx">MAX_BASE64_VALUE</span> <span class="keyword">if</span> value &gt; MAX_BASE64_VALUE
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;Cannot encode value </span><span class="si">#{</span><span class="nx">value</span><span class="si">}</span><span class="s"> &gt; </span><span class="si">#{</span><span class="nx">MAX_BASE64_VALUE</span><span class="si">}</span><span class="s">&quot;</span> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cannot encode value <span class="subst">#{value}</span> &gt; <span class="subst">#{MAX_BASE64_VALUE}</span>"</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">value</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="keyword">else</span> <span class="keyword">if</span> value &lt; <span class="number">0</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;Cannot encode value </span><span class="si">#{</span><span class="nx">value</span><span class="si">}</span><span class="s"> &lt; 0&quot;</span> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cannot encode value <span class="subst">#{value}</span> &lt; 0"</span>
<span class="nx">BASE64_CHARS</span><span class="p">[</span><span class="nx">value</span><span class="p">]</span> BASE64_CHARS[value]
<span class="nv">decodeBase64Char = </span><span class="nf">(char) -&gt;</span> <span class="function"><span class="title">decodeBase64Char</span></span> = (char) -&gt;
<span class="nv">value = </span><span class="nx">BASE64_CHARS</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">char</span> value = BASE64_CHARS.indexOf char
<span class="k">if</span> <span class="nx">value</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span> <span class="keyword">if</span> value == -<span class="number">1</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&quot;Invalid Base 64 character: </span><span class="si">#{</span><span class="nx">char</span><span class="si">}</span><span class="s">&quot;</span> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Invalid Base 64 character: <span class="subst">#{char}</span>"</span>
<span class="nx">value</span></pre></div></div> value</pre></div></div>
</li> </li>
<li id="section-20"> <li id="section-20">
<div class="annotation"> <div class="annotation">
<div class="pilwrap">
<div class="pilwrap for-h3">
<a class="pilcrow" href="#section-20">&#182;</a> <a class="pilcrow" href="#section-20">&#182;</a>
</div> </div>
<h3>Base 64 VLQ encoding/decoding helpers</h3> <h3>Base 64 VLQ encoding/decoding helpers</h3>
<p>Note that SourceMap VLQ encoding is &quot;backwards&quot;. MIDI style VLQ encoding puts the <p>Note that SourceMap VLQ encoding is &quot;backwards&quot;. MIDI style VLQ encoding puts the
most-significant-bit (MSB) from the original value into the MSB of the VLQ encoded value most-significant-bit (MSB) from the original value into the MSB of the VLQ encoded value
@ -566,188 +552,178 @@ most-significant-bit (MSB) from the original value into the MSB of the VLQ encod
the other way around, with the least significat four bits of the original value encoded the other way around, with the least significat four bits of the original value encoded
into the first byte of the VLQ encoded value. into the first byte of the VLQ encoded value.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">VLQ_SHIFT = </span><span class="mi">5</span> <div class="content"><div class='highlight'><pre>VLQ_SHIFT = <span class="number">5</span>
<span class="nv">VLQ_CONTINUATION_BIT = </span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="nx">VLQ_SHIFT</span> <span class="c1"># 0010 0000</span> VLQ_CONTINUATION_BIT = <span class="number">1</span> &lt;&lt; VLQ_SHIFT <span class="comment"># 0010 0000</span>
<span class="nv">VLQ_VALUE_MASK = </span><span class="nx">VLQ_CONTINUATION_BIT</span> <span class="o">-</span> <span class="mi">1</span> <span class="c1"># 0001 1111</span></pre></div></div> VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - <span class="number">1</span> <span class="comment"># 0001 1111</span></pre></div></div>
</li> </li>
<li id="section-21"> <li id="section-21">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a> <a class="pilcrow" href="#section-21">&#182;</a>
</div> </div>
<p>Encode a value as Base 64 VLQ. <p>Encode a value as Base 64 VLQ.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.vlqEncodeValue = </span><span class="nf">(value) -&gt;</span></pre></div></div> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">vlqEncodeValue</span></span> = (value) -&gt;</pre></div></div>
</li> </li>
<li id="section-22"> <li id="section-22">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a> <a class="pilcrow" href="#section-22">&#182;</a>
</div> </div>
<p>Least significant bit represents the sign. <p>Least significant bit represents the sign.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">signBit = </span><span class="k">if</span> <span class="nx">value</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="k">then</span> <span class="mi">1</span> <span class="k">else</span> <span class="mi">0</span></pre></div></div> <div class="content"><div class='highlight'><pre> signBit = <span class="keyword">if</span> value &lt; <span class="number">0</span> <span class="keyword">then</span> <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span></pre></div></div>
</li> </li>
<li id="section-23"> <li id="section-23">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a> <a class="pilcrow" href="#section-23">&#182;</a>
</div> </div>
<p>Next bits are the actual value <p>Next bits are the actual value
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">valueToEncode = </span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nx">signBit</span> <div class="content"><div class='highlight'><pre> valueToEncode = (Math.abs(value) &lt;&lt; <span class="number">1</span>) + signBit
<span class="nv">answer = </span><span class="s">&quot;&quot;</span></pre></div></div> answer = <span class="string">""</span></pre></div></div>
</li> </li>
<li id="section-24"> <li id="section-24">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</a> <a class="pilcrow" href="#section-24">&#182;</a>
</div> </div>
<p>Make sure we encode at least one character, even if valueToEncode is 0. <p>Make sure we encode at least one character, even if valueToEncode is 0.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="k">while</span> <span class="nx">valueToEncode</span> <span class="o">||</span> <span class="o">!</span><span class="nx">answer</span> <div class="content"><div class='highlight'><pre> <span class="keyword">while</span> valueToEncode || !answer
<span class="nv">nextVlqChunk = </span><span class="nx">valueToEncode</span> <span class="o">&amp;</span> <span class="nx">VLQ_VALUE_MASK</span> nextVlqChunk = valueToEncode &amp; VLQ_VALUE_MASK
<span class="nv">valueToEncode = </span><span class="nx">valueToEncode</span> <span class="o">&gt;&gt;</span> <span class="nx">VLQ_SHIFT</span> valueToEncode = valueToEncode &gt;&gt; VLQ_SHIFT
<span class="k">if</span> <span class="nx">valueToEncode</span> <span class="keyword">if</span> valueToEncode
<span class="nx">nextVlqChunk</span> <span class="o">|=</span> <span class="nx">VLQ_CONTINUATION_BIT</span> nextVlqChunk |= VLQ_CONTINUATION_BIT
<span class="nx">answer</span> <span class="o">+=</span> <span class="nx">encodeBase64Char</span><span class="p">(</span><span class="nx">nextVlqChunk</span><span class="p">)</span> answer += encodeBase64Char(nextVlqChunk)
<span class="k">return</span> <span class="nx">answer</span></pre></div></div> <span class="keyword">return</span> answer</pre></div></div>
</li> </li>
<li id="section-25"> <li id="section-25">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-25">&#182;</a> <a class="pilcrow" href="#section-25">&#182;</a>
</div> </div>
<p>Decode a Base 64 VLQ value. <p>Decode a Base 64 VLQ value.
</p> </p>
<p>Returns <code>[value, consumed]</code> where <code>value</code> is the decoded value, and <code>consumed</code> is the number <p>Returns <code>[value, consumed]</code> where <code>value</code> is the decoded value, and <code>consumed</code> is the number
of characters consumed from <code>str</code>. of characters consumed from <code>str</code>.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre><span class="nv">exports.vlqDecodeValue = </span><span class="nf">(str, offset=0) -&gt;</span> <div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">vlqDecodeValue</span></span> = (str, offset=<span class="number">0</span>) -&gt;
<span class="nv">position = </span><span class="nx">offset</span> position = offset
<span class="nv">done = </span><span class="kc">false</span> done = <span class="literal">false</span>
<span class="nv">value = </span><span class="mi">0</span> value = <span class="number">0</span>
<span class="nv">continuationShift = </span><span class="mi">0</span> continuationShift = <span class="number">0</span>
<span class="k">while</span> <span class="o">!</span><span class="nx">done</span> <span class="keyword">while</span> !done
<span class="nv">nextVlqChunk = </span><span class="nx">decodeBase64Char</span><span class="p">(</span><span class="nx">str</span><span class="p">[</span><span class="nx">position</span><span class="p">])</span> nextVlqChunk = decodeBase64Char(str[position])
<span class="nx">position</span> <span class="o">+=</span> <span class="mi">1</span> position += <span class="number">1</span>
<span class="nv">nextChunkValue = </span><span class="nx">nextVlqChunk</span> <span class="o">&amp;</span> <span class="nx">VLQ_VALUE_MASK</span> nextChunkValue = nextVlqChunk &amp; VLQ_VALUE_MASK
<span class="nx">value</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">nextChunkValue</span> <span class="o">&lt;&lt;</span> <span class="nx">continuationShift</span><span class="p">)</span> value += (nextChunkValue &lt;&lt; continuationShift)
<span class="k">if</span> <span class="o">!</span><span class="p">(</span><span class="nx">nextVlqChunk</span> <span class="o">&amp;</span> <span class="nx">VLQ_CONTINUATION_BIT</span><span class="p">)</span></pre></div></div> <span class="keyword">if</span> !(nextVlqChunk &amp; VLQ_CONTINUATION_BIT)</pre></div></div>
</li> </li>
<li id="section-26"> <li id="section-26">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-26">&#182;</a> <a class="pilcrow" href="#section-26">&#182;</a>
</div> </div>
<p>We&#39;ll be done after this character. <p>We&#39;ll be done after this character.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">done = </span><span class="kc">true</span></pre></div></div> <div class="content"><div class='highlight'><pre> done = <span class="literal">true</span></pre></div></div>
</li> </li>
<li id="section-27"> <li id="section-27">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-27">&#182;</a> <a class="pilcrow" href="#section-27">&#182;</a>
</div> </div>
<p>Bits are encoded least-significant first (opposite of MIDI VLQ). Increase the <p>Bits are encoded least-significant first (opposite of MIDI VLQ). Increase the
continuationShift, so the next byte will end up where it should in the value. continuationShift, so the next byte will end up where it should in the value.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nx">continuationShift</span> <span class="o">+=</span> <span class="nx">VLQ_SHIFT</span> <div class="content"><div class='highlight'><pre> continuationShift += VLQ_SHIFT
<span class="nv">consumed = </span><span class="nx">position</span> <span class="o">-</span> <span class="nx">offset</span></pre></div></div> consumed = position - offset</pre></div></div>
</li> </li>
<li id="section-28"> <li id="section-28">
<div class="annotation"> <div class="annotation">
<div class="pilwrap "> <div class="pilwrap ">
<a class="pilcrow" href="#section-28">&#182;</a> <a class="pilcrow" href="#section-28">&#182;</a>
</div> </div>
<p>Least significant bit represents the sign. <p>Least significant bit represents the sign.
</p> </p>
</div> </div>
<div class="content"><div class="highlight"><pre> <span class="nv">signBit = </span><span class="nx">value</span> <span class="o">&amp;</span> <span class="mi">1</span> <div class="content"><div class='highlight'><pre> signBit = value &amp; <span class="number">1</span>
<span class="nv">value = </span><span class="nx">value</span> <span class="o">&gt;&gt;</span> <span class="mi">1</span> value = value &gt;&gt; <span class="number">1</span>
<span class="k">if</span> <span class="nx">signBit</span> <span class="k">then</span> <span class="nv">value = </span><span class="o">-</span><span class="nx">value</span> <span class="keyword">if</span> signBit <span class="keyword">then</span> value = -value
<span class="k">return</span> <span class="p">[</span><span class="nx">value</span><span class="p">,</span> <span class="nx">consumed</span><span class="p">]</span> <span class="keyword">return</span> [value, consumed]</pre></div></div>
</pre></div></div>
</li> </li>

View file

@ -139,7 +139,7 @@
<p> <p>
<b>Latest Version:</b> <b>Latest Version:</b>
<a href="http://github.com/jashkenas/coffee-script/tarball/1.6.1">1.6.1</a> <a href="http://github.com/jashkenas/coffee-script/tarball/1.6.2">1.6.2</a>
</p> </p>
<pre> <pre>
@ -1202,6 +1202,35 @@ Expressions
Change Log Change Log
</h2> </h2>
<p>
<b class="header" style="margin-top: 20px;">
<a href="https://github.com/jashkenas/coffee-script/compare/1.6.1...1.6.2">1.6.2</a>
<span class="timestamp"> &ndash; <small>March 18, 2013</small></span>
</b>
<ul>
<li>
Source maps have been used to provide automatic line-mapping when
running CoffeeScript directly via the <tt>coffee</tt> command, and
for automatic line-mapping when running CoffeeScript directly in the
browser. Also, to provide better error messages for semantic errors
thrown by the compiler &mdash;
<a href="http://cl.ly/NdOA">with colors, even</a>.
</li>
<li>
Improved support for mixed literate/vanilla-style CoffeeScript projects,
and generating source maps for both at the same time.
</li>
<li>
Fixes for <b>1.6.x</b> regressions with overriding inherited bound
functions, and for Windows file path management.
</li>
<li>
The <tt>coffee</tt> command can now correctly <tt>fork()</tt>
both <tt>.coffee</tt> and <tt>.js</tt> files. (Requires Node.js 0.9+)
</li>
</ul>
</p>
<p> <p>
<b class="header" style="margin-top: 20px;"> <b class="header" style="margin-top: 20px;">
<a href="https://github.com/jashkenas/coffee-script/compare/1.5.0...1.6.1">1.6.1</a> <a href="https://github.com/jashkenas/coffee-script/compare/1.5.0...1.6.1">1.6.1</a>

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var volume, winner; var volume, winner;
if (ignition === true) { if (ignition === true) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref; var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
_ref = ['toast', 'cheese', 'wine']; _ref = ['toast', 'cheese', 'wine'];

View file

@ -1,7 +1,6 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
/* /*
CoffeeScript Compiler v1.6.1 SkinnyMochaHalfCaffScript Compiler v1.0
Released under the MIT License Released under the MIT License
*/ */

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var fs; var fs;
fs = require('fs'); fs = require('fs');
@ -7,6 +7,7 @@ option('-o', '--output [DIR]', 'directory for compiled code');
task('build:parser', 'rebuild the Jison parser', function(options) { task('build:parser', 'rebuild the Jison parser', function(options) {
var code, dir; var code, dir;
require('jison'); require('jison');
code = require('./lib/grammar').parser.generate(); code = require('./lib/grammar').parser.generate();
dir = options.output || 'lib'; dir = options.output || 'lib';

View file

@ -1,10 +1,9 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var Animal, Horse, Snake, sam, tom, var Animal, Horse, Snake, sam, tom, _ref, _ref1,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Animal = (function() { Animal = (function() {
function Animal(name) { function Animal(name) {
this.name = name; this.name = name;
} }
@ -18,11 +17,11 @@ Animal = (function() {
})(); })();
Snake = (function(_super) { Snake = (function(_super) {
__extends(Snake, _super); __extends(Snake, _super);
function Snake() { function Snake() {
return Snake.__super__.constructor.apply(this, arguments); _ref = Snake.__super__.constructor.apply(this, arguments);
return _ref;
} }
Snake.prototype.move = function() { Snake.prototype.move = function() {
@ -35,11 +34,11 @@ Snake = (function(_super) {
})(Animal); })(Animal);
Horse = (function(_super) { Horse = (function(_super) {
__extends(Horse, _super); __extends(Horse, _super);
function Horse() { function Horse() {
return Horse.__super__.constructor.apply(this, arguments); _ref1 = Horse.__super__.constructor.apply(this, arguments);
return _ref1;
} }
Horse.prototype.move = function() { Horse.prototype.move = function() {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var cholesterol, healthy; var cholesterol, healthy;
cholesterol = 127; cholesterol = 127;

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var date, mood; var date, mood;
if (singing) { if (singing) {

View file

@ -1,8 +1,7 @@
// Generated by CoffeeScript 1.3.3 // Generated by CoffeeScript 1.6.2
var Person; var Person;
Person = (function() { Person = (function() {
function Person(options) { function Person(options) {
this.name = options.name, this.age = options.age, this.height = options.height; this.name = options.name, this.age = options.age, this.height = options.height;
} }

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var fill; var fill;
fill = function(container, liquid) { fill = function(container, liquid) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var filename, _fn, _i, _len; var filename, _fn, _i, _len;
_fn = function(filename) { _fn = function(filename) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var hi; var hi;
hi = function() { hi = function() {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var footprints, solipsism, speed; var footprints, solipsism, speed;
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) { if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var eldest, grade; var eldest, grade;
grade = function(student) { grade = function(student) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var one, six, three, two; var one, six, three, two;
six = (one = 1) + (two = 2) + (three = 3); six = (one = 1) + (two = 2) + (three = 3);

View file

@ -1,8 +1,9 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var globals, name; var globals, name;
globals = ((function() { globals = ((function() {
var _results; var _results;
_results = []; _results = [];
for (name in window) { for (name in window) {
_results.push(name); _results.push(name);

View file

@ -1,9 +1,11 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var error;
alert((function() { alert((function() {
try { try {
return nonexistent / void 0; return nonexistent / void 0;
} catch (error) { } catch (_error) {
error = _error;
return "And the error is ... " + error; return "And the error is ... " + error;
} }
})()); })());

View file

@ -1,8 +1,9 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var Account; var Account;
Account = function(customer, cart) { Account = function(customer, cart) {
var _this = this; var _this = this;
this.customer = customer; this.customer = customer;
this.cart = cart; this.cart = cart;
return $('.shopping_cart').bind('click', function(event) { return $('.shopping_cart').bind('click', function(event) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var cube, square; var cube, square;
square = function(x) { square = function(x) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var html; var html;
html = "<strong>\n cup of coffeescript\n</strong>"; html = "<strong>\n cup of coffeescript\n</strong>";

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var OPERATOR; var OPERATOR;
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/; OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var author, quote, sentence; var author, quote, sentence;
author = "Wittgenstein"; author = "Wittgenstein";

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var city, forecast, temp, weatherReport, _ref; var city, forecast, temp, weatherReport, _ref;
weatherReport = function(location) { weatherReport = function(location) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var age, ages, child, yearsOld; var age, ages, child, yearsOld;
yearsOld = { yearsOld = {
@ -9,6 +9,7 @@ yearsOld = {
ages = (function() { ages = (function() {
var _results; var _results;
_results = []; _results = [];
for (child in yearsOld) { for (child in yearsOld) {
age = yearsOld[child]; age = yearsOld[child];

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var city, futurists, name, street, _ref, _ref1; var city, futurists, name, street, _ref, _ref1;
futurists = { futurists = {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var bitlist, kids, singers, song; var bitlist, kids, singers, song;
song = ["do", "re", "mi", "fa", "so"]; song = ["do", "re", "mi", "fa", "so"];

View file

@ -1,5 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
$('.account').attr({ $('.account').attr({
"class": 'active' "class": 'active'
}); });

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var cubes, list, math, num, number, opposite, race, square, var cubes, list, math, num, number, opposite, race, square,
__slice = [].slice; __slice = [].slice;
@ -26,6 +26,7 @@ math = {
race = function() { race = function() {
var runners, winner; var runners, winner;
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners); return print(winner, runners);
}; };
@ -36,6 +37,7 @@ if (typeof elvis !== "undefined" && elvis !== null) {
cubes = (function() { cubes = (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) { for (_i = 0, _len = list.length; _i < _len; _i++) {
num = list[_i]; num = list[_i];

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var theBait, theSwitch, _ref; var theBait, theSwitch, _ref;
theBait = 1000; theBait = 1000;

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var close, contents, open, tag, _i, _ref, var close, contents, open, tag, _i, _ref,
__slice = [].slice; __slice = [].slice;

View file

@ -1,5 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
String.prototype.dasherize = function() { String.prototype.dasherize = function() {
return this.replace(/_/g, "-"); return this.replace(/_/g, "-");
}; };

View file

@ -1,8 +1,9 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var countdown, num; var countdown, num;
countdown = (function() { countdown = (function() {
var _i, _results; var _i, _results;
_results = []; _results = [];
for (num = _i = 10; _i >= 1; num = --_i) { for (num = _i = 10; _i >= 1; num = --_i) {
_results.push(num); _results.push(num);

View file

@ -1,10 +1,11 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var changeNumbers, inner, outer; var changeNumbers, inner, outer;
outer = 1; outer = 1;
changeNumbers = function() { changeNumbers = function() {
var inner; var inner;
inner = -1; inner = -1;
return outer = 10; return outer = 10;
}; };

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var copy, end, middle, numbers, start; var copy, end, middle, numbers, start;
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var zip, _ref; var zip, _ref;
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0; zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var awardMedals, contenders, gold, rest, silver, var awardMedals, contenders, gold, rest, silver,
__slice = [].slice; __slice = [].slice;
@ -6,6 +6,7 @@ gold = silver = rest = "unknown";
awardMedals = function() { awardMedals = function() {
var first, others, second; var first, others, second;
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : []; first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
gold = first; gold = first;
silver = second; silver = second;

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var numbers, _ref; var numbers, _ref;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var mobyDick; var mobyDick;
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world..."; mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";

View file

@ -1,5 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
switch (day) { switch (day) {
case "Mon": case "Mon":
go(work); go(work);

View file

@ -0,0 +1,19 @@
// Generated by CoffeeScript 1.6.2
var grade, score;
score = 76;
grade = (function() {
switch (false) {
case !(score < 60):
return 'F';
case !(score < 70):
return 'D';
case !(score < 80):
return 'C';
case !(score < 90):
return 'B';
default:
return 'A';
}
})();

View file

@ -1,9 +1,11 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var error;
try { try {
allHellBreaksLoose(); allHellBreaksLoose();
catsAndDogsLivingTogether(); catsAndDogsLivingTogether();
} catch (error) { } catch (_error) {
error = _error;
print(error); print(error);
} finally { } finally {
cleanUp(); cleanUp();

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
var lyrics, num; var lyrics, num;
if (this.studyingEconomics) { if (this.studyingEconomics) {
@ -14,6 +14,7 @@ num = 6;
lyrics = (function() { lyrics = (function() {
var _results; var _results;
_results = []; _results = [];
while (num -= 1) { while (num -= 1) {
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head."); _results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");

File diff suppressed because one or more lines are too long

View file

@ -116,7 +116,7 @@
<p> <p>
<b>Latest Version:</b> <b>Latest Version:</b>
<a href="http://github.com/jashkenas/coffee-script/tarball/1.6.1">1.6.1</a> <a href="http://github.com/jashkenas/coffee-script/tarball/1.6.2">1.6.2</a>
</p> </p>
<pre> <pre>
@ -184,6 +184,7 @@ math <span class="Keyword">=</span> {
<span class="FunctionName">race</span> = <span class="Storage">function</span>() { <span class="FunctionName">race</span> = <span class="Storage">function</span>() {
<span class="Storage">var</span> runners, winner; <span class="Storage">var</span> runners, winner;
winner <span class="Keyword">=</span> arguments[<span class="Number">0</span>], runners <span class="Keyword">=</span> <span class="Number">2</span> <span class="Keyword">&lt;=</span> arguments.<span class="LibraryConstant">length</span> ? __slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">1</span>) : []; winner <span class="Keyword">=</span> arguments[<span class="Number">0</span>], runners <span class="Keyword">=</span> <span class="Number">2</span> <span class="Keyword">&lt;=</span> arguments.<span class="LibraryConstant">length</span> ? __slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">1</span>) : [];
<span class="Keyword">return</span> <span class="LibraryFunction">print</span>(winner, runners); <span class="Keyword">return</span> <span class="LibraryFunction">print</span>(winner, runners);
}; };
@ -194,6 +195,7 @@ math <span class="Keyword">=</span> {
cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() { cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Storage">var</span> _i, _len, _results; <span class="Storage">var</span> _i, _len, _results;
_results <span class="Keyword">=</span> []; _results <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> list.<span class="LibraryConstant">length</span>; _i <span class="Keyword">&lt;</span> _len; _i<span class="Keyword">++</span>) { <span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> list.<span class="LibraryConstant">length</span>; _i <span class="Keyword">&lt;</span> _len; _i<span class="Keyword">++</span>) {
num <span class="Keyword">=</span> list[_i]; num <span class="Keyword">=</span> list[_i];
@ -228,6 +230,7 @@ math = {
race = function() { race = function() {
var runners, winner; var runners, winner;
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners); return print(winner, runners);
}; };
@ -238,6 +241,7 @@ if (typeof elvis !== "undefined" && elvis !== null) {
cubes = (function() { cubes = (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) { for (_i = 0, _len = list.length; _i < _len; _i++) {
num = list[_i]; num = list[_i];
@ -384,13 +388,6 @@ sudo bin/cake install</pre>
command line. For example:<br /><tt>coffee -e "console.log num for num in [10..1]"</tt> command line. For example:<br /><tt>coffee -e "console.log num for num in [10..1]"</tt>
</td> </td>
</tr> </tr>
<tr>
<td><code>-r, --require</code></td>
<td>
Load a library before compiling or executing your script. Can be used
to hook in to the compiler (to add Growl notifications, for example).
</td>
</tr>
<tr> <tr>
<td><code>-b, --bare</code></td> <td><code>-b, --bare</code></td>
<td> <td>
@ -671,8 +668,7 @@ kids = {
log object.<span class="Storage">class</span> log object.<span class="Storage">class</span>
</pre><pre class="idle"> </pre><pre class="idle"><span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).attr({
<span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).attr({
<span class="String"><span class="String">&quot;</span>class<span class="String">&quot;</span></span>: <span class="String"><span class="String">'</span>active<span class="String">'</span></span> <span class="String"><span class="String">&quot;</span>class<span class="String">&quot;</span></span>: <span class="String"><span class="String">'</span>active<span class="String">'</span></span>
}); });
@ -697,6 +693,7 @@ outer <span class="Keyword">=</span> <span class="Number">1</span>;
<span class="FunctionName">changeNumbers</span> = <span class="Storage">function</span>() { <span class="FunctionName">changeNumbers</span> = <span class="Storage">function</span>() {
<span class="Storage">var</span> inner; <span class="Storage">var</span> inner;
inner <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">1</span>; inner <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">1</span>;
<span class="Keyword">return</span> outer <span class="Keyword">=</span> <span class="Number">10</span>; <span class="Keyword">return</span> outer <span class="Keyword">=</span> <span class="Number">10</span>;
}; };
@ -708,6 +705,7 @@ outer = 1;
changeNumbers = function() { changeNumbers = function() {
var inner; var inner;
inner = -1; inner = -1;
return outer = 10; return outer = 10;
}; };
@ -828,6 +826,7 @@ gold <span class="Keyword">=</span> silver <span class="Keyword">=</span> rest <
<span class="FunctionName">awardMedals</span> = <span class="Storage">function</span>() { <span class="FunctionName">awardMedals</span> = <span class="Storage">function</span>() {
<span class="Storage">var</span> first, others, second; <span class="Storage">var</span> first, others, second;
first <span class="Keyword">=</span> arguments[<span class="Number">0</span>], second <span class="Keyword">=</span> arguments[<span class="Number">1</span>], others <span class="Keyword">=</span> <span class="Number">3</span> <span class="Keyword">&lt;=</span> arguments.<span class="LibraryConstant">length</span> ? __slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">2</span>) : []; first <span class="Keyword">=</span> arguments[<span class="Number">0</span>], second <span class="Keyword">=</span> arguments[<span class="Number">1</span>], others <span class="Keyword">=</span> <span class="Number">3</span> <span class="Keyword">&lt;=</span> arguments.<span class="LibraryConstant">length</span> ? __slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">2</span>) : [];
gold <span class="Keyword">=</span> first; gold <span class="Keyword">=</span> first;
silver <span class="Keyword">=</span> second; silver <span class="Keyword">=</span> second;
@ -850,6 +849,7 @@ gold = silver = rest = "unknown";
awardMedals = function() { awardMedals = function() {
var first, others, second; var first, others, second;
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : []; first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
gold = first; gold = first;
silver = second; silver = second;
@ -924,6 +924,7 @@ foods <span class="Keyword">=</span> [<span class="String"><span class="String">
countdown <span class="Keyword">=</span> (<span class="Storage">function</span>() { countdown <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Storage">var</span> _i, _results; <span class="Storage">var</span> _i, _results;
_results <span class="Keyword">=</span> []; _results <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (num <span class="Keyword">=</span> _i <span class="Keyword">=</span> <span class="Number">10</span>; _i <span class="Keyword">&gt;=</span> <span class="Number">1</span>; num <span class="Keyword">=</span> <span class="Keyword">--</span>_i) { <span class="Keyword">for</span> (num <span class="Keyword">=</span> _i <span class="Keyword">=</span> <span class="Number">10</span>; _i <span class="Keyword">&gt;=</span> <span class="Number">1</span>; num <span class="Keyword">=</span> <span class="Keyword">--</span>_i) {
_results.<span class="LibraryFunction">push</span>(num); _results.<span class="LibraryFunction">push</span>(num);
@ -934,6 +935,7 @@ countdown <span class="Keyword">=</span> (<span class="Storage">function</span>(
countdown = (function() { countdown = (function() {
var _i, _results; var _i, _results;
_results = []; _results = [];
for (num = _i = 10; _i >= 1; num = --_i) { for (num = _i = 10; _i >= 1; num = --_i) {
_results.push(num); _results.push(num);
@ -974,6 +976,7 @@ yearsOld <span class="Keyword">=</span> {
ages <span class="Keyword">=</span> (<span class="Storage">function</span>() { ages <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Storage">var</span> _results; <span class="Storage">var</span> _results;
_results <span class="Keyword">=</span> []; _results <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (child <span class="Keyword">in</span> yearsOld) { <span class="Keyword">for</span> (child <span class="Keyword">in</span> yearsOld) {
age <span class="Keyword">=</span> yearsOld[child]; age <span class="Keyword">=</span> yearsOld[child];
@ -991,6 +994,7 @@ yearsOld = {
ages = (function() { ages = (function() {
var _results; var _results;
_results = []; _results = [];
for (child in yearsOld) { for (child in yearsOld) {
age = yearsOld[child]; age = yearsOld[child];
@ -1036,6 +1040,7 @@ num <span class="Keyword">=</span> <span class="Number">6</span>;
lyrics <span class="Keyword">=</span> (<span class="Storage">function</span>() { lyrics <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Storage">var</span> _results; <span class="Storage">var</span> _results;
_results <span class="Keyword">=</span> []; _results <span class="Keyword">=</span> [];
<span class="Keyword">while</span> (num <span class="Keyword">-</span><span class="Keyword">=</span> <span class="Number">1</span>) { <span class="Keyword">while</span> (num <span class="Keyword">-</span><span class="Keyword">=</span> <span class="Number">1</span>) {
_results.<span class="LibraryFunction">push</span>(<span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">+</span> num <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> little monkeys, jumping on the bed. One fell out and bumped his head.<span class="String">&quot;</span></span>); _results.<span class="LibraryFunction">push</span>(<span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">+</span> num <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> little monkeys, jumping on the bed. One fell out and bumped his head.<span class="String">&quot;</span></span>);
@ -1057,6 +1062,7 @@ num = 6;
lyrics = (function() { lyrics = (function() {
var _results; var _results;
_results = []; _results = [];
while (num -= 1) { while (num -= 1) {
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head."); _results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
@ -1244,6 +1250,7 @@ globals <span class="Keyword">=</span> (name <span class="Keyword">for</span> na
globals <span class="Keyword">=</span> ((<span class="Storage">function</span>() { globals <span class="Keyword">=</span> ((<span class="Storage">function</span>() {
<span class="Storage">var</span> _results; <span class="Storage">var</span> _results;
_results <span class="Keyword">=</span> []; _results <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (name <span class="Keyword">in</span> <span class="LibraryClassType">window</span>) { <span class="Keyword">for</span> (name <span class="Keyword">in</span> <span class="LibraryClassType">window</span>) {
_results.<span class="LibraryFunction">push</span>(name); _results.<span class="LibraryFunction">push</span>(name);
@ -1254,6 +1261,7 @@ globals <span class="Keyword">=</span> ((<span class="Storage">function</span>()
globals = ((function() { globals = ((function() {
var _results; var _results;
_results = []; _results = [];
for (name in window) { for (name in window) {
_results.push(name); _results.push(name);
@ -1272,19 +1280,23 @@ globals = ((function() {
<span class="String"><span class="String">&quot;</span>And the error is ... <span class="String"><span class="String">#{</span>error<span class="String">}</span></span><span class="String">&quot;</span></span> <span class="String"><span class="String">&quot;</span>And the error is ... <span class="String"><span class="String">#{</span>error<span class="String">}</span></span><span class="String">&quot;</span></span>
) )
</pre><pre class="idle"> </pre><pre class="idle"><span class="Storage">var</span> error;
<span class="LibraryFunction">alert</span>((<span class="Storage">function</span>() { <span class="LibraryFunction">alert</span>((<span class="Storage">function</span>() {
<span class="Keyword">try</span> { <span class="Keyword">try</span> {
<span class="Keyword">return</span> nonexistent / <span class="Storage">void</span> <span class="Number">0</span>; <span class="Keyword">return</span> nonexistent / <span class="Storage">void</span> <span class="Number">0</span>;
} <span class="Keyword">catch</span> (error) { } <span class="Keyword">catch</span> (_error) {
error <span class="Keyword">=</span> _error;
<span class="Keyword">return</span> <span class="String"><span class="String">&quot;</span>And the error is ... <span class="String">&quot;</span></span> <span class="Keyword">+</span> error; <span class="Keyword">return</span> <span class="String"><span class="String">&quot;</span>And the error is ... <span class="String">&quot;</span></span> <span class="Keyword">+</span> error;
} }
})()); })());
</pre><script>window.example19 = "alert(\n try\n nonexistent / undefined\n catch error\n \"And the error is ... #{error}\"\n)\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example19);'>load</div><div class='minibutton ok' onclick='javascript: </pre><script>window.example19 = "alert(\n try\n nonexistent / undefined\n catch error\n \"And the error is ... #{error}\"\n)\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example19);'>load</div><div class='minibutton ok' onclick='javascript: var error;
alert((function() { alert((function() {
try { try {
return nonexistent / void 0; return nonexistent / void 0;
} catch (error) { } catch (_error) {
error = _error;
return "And the error is ... " + error; return "And the error is ... " + error;
} }
})()); })());
@ -1509,12 +1521,11 @@ tom.move()
</pre><pre class="idle"><span class="Storage">var</span> Animal, Horse, Snake, sam, tom, </pre><pre class="idle"><span class="Storage">var</span> Animal, Horse, Snake, sam, tom, _ref, _ref1,
__hasProp <span class="Keyword">=</span> {}.hasOwnProperty, __hasProp <span class="Keyword">=</span> {}.hasOwnProperty,
<span class="FunctionName">__extends</span> = <span class="Storage">function</span>(<span class="FunctionArgument">child, parent</span>) { <span class="Keyword">for</span> (<span class="Storage">var</span> key <span class="Keyword">in</span> parent) { <span class="Keyword">if</span> (__hasProp.<span class="LibraryFunction">call</span>(parent, key)) child[key] <span class="Keyword">=</span> parent[key]; } <span class="Storage">function</span> <span class="FunctionName">ctor</span>() { <span class="Variable">this</span>.<span class="LibraryConstant">constructor</span> <span class="Keyword">=</span> child; } <span class="LibraryClassType">ctor</span>.<span class="LibraryConstant">prototype</span> = parent.<span class="LibraryConstant">prototype</span>; <span class="LibraryClassType">child</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">ctor</span>(); child.__super__ <span class="Keyword">=</span> parent.<span class="LibraryConstant">prototype</span>; <span class="Keyword">return</span> child; }; <span class="FunctionName">__extends</span> = <span class="Storage">function</span>(<span class="FunctionArgument">child, parent</span>) { <span class="Keyword">for</span> (<span class="Storage">var</span> key <span class="Keyword">in</span> parent) { <span class="Keyword">if</span> (__hasProp.<span class="LibraryFunction">call</span>(parent, key)) child[key] <span class="Keyword">=</span> parent[key]; } <span class="Storage">function</span> <span class="FunctionName">ctor</span>() { <span class="Variable">this</span>.<span class="LibraryConstant">constructor</span> <span class="Keyword">=</span> child; } <span class="LibraryClassType">ctor</span>.<span class="LibraryConstant">prototype</span> = parent.<span class="LibraryConstant">prototype</span>; <span class="LibraryClassType">child</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">ctor</span>(); child.__super__ <span class="Keyword">=</span> parent.<span class="LibraryConstant">prototype</span>; <span class="Keyword">return</span> child; };
Animal <span class="Keyword">=</span> (<span class="Storage">function</span>() { Animal <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Storage">function</span> <span class="FunctionName">Animal</span>(<span class="FunctionArgument">name</span>) { <span class="Storage">function</span> <span class="FunctionName">Animal</span>(<span class="FunctionArgument">name</span>) {
<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name; <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
} }
@ -1528,11 +1539,11 @@ Animal <span class="Keyword">=</span> (<span class="Storage">function</span>() {
})(); })();
Snake <span class="Keyword">=</span> (<span class="Storage">function</span>(_super) { Snake <span class="Keyword">=</span> (<span class="Storage">function</span>(_super) {
__extends(Snake, _super); __extends(Snake, _super);
<span class="Storage">function</span> <span class="FunctionName">Snake</span>() { <span class="Storage">function</span> <span class="FunctionName">Snake</span>() {
<span class="Keyword">return</span> Snake.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments); _ref <span class="Keyword">=</span> Snake.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
<span class="Keyword">return</span> _ref;
} }
<span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() { <span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() {
@ -1545,11 +1556,11 @@ Snake <span class="Keyword">=</span> (<span class="Storage">function</span>(_sup
})(Animal); })(Animal);
Horse <span class="Keyword">=</span> (<span class="Storage">function</span>(_super) { Horse <span class="Keyword">=</span> (<span class="Storage">function</span>(_super) {
__extends(Horse, _super); __extends(Horse, _super);
<span class="Storage">function</span> <span class="FunctionName">Horse</span>() { <span class="Storage">function</span> <span class="FunctionName">Horse</span>() {
<span class="Keyword">return</span> Horse.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments); _ref1 <span class="Keyword">=</span> Horse.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
<span class="Keyword">return</span> _ref1;
} }
<span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() { <span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() {
@ -1568,12 +1579,11 @@ tom <span class="Keyword">=</span> <span class="Keyword">new</span> <span class=
sam.move(); sam.move();
tom.move(); tom.move();
</pre><script>window.example23 = "class Animal\n constructor: (@name) ->\n\n move: (meters) ->\n alert @name + \" moved #{meters}m.\"\n\nclass Snake extends Animal\n move: ->\n alert \"Slithering...\"\n super 5\n\nclass Horse extends Animal\n move: ->\n alert \"Galloping...\"\n super 45\n\nsam = new Snake \"Sammy the Python\"\ntom = new Horse \"Tommy the Palomino\"\n\nsam.move()\ntom.move()\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example23);'>load</div><div class='minibutton ok' onclick='javascript: var Animal, Horse, Snake, sam, tom, </pre><script>window.example23 = "class Animal\n constructor: (@name) ->\n\n move: (meters) ->\n alert @name + \" moved #{meters}m.\"\n\nclass Snake extends Animal\n move: ->\n alert \"Slithering...\"\n super 5\n\nclass Horse extends Animal\n move: ->\n alert \"Galloping...\"\n super 45\n\nsam = new Snake \"Sammy the Python\"\ntom = new Horse \"Tommy the Palomino\"\n\nsam.move()\ntom.move()\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example23);'>load</div><div class='minibutton ok' onclick='javascript: var Animal, Horse, Snake, sam, tom, _ref, _ref1,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Animal = (function() { Animal = (function() {
function Animal(name) { function Animal(name) {
this.name = name; this.name = name;
} }
@ -1587,11 +1597,11 @@ Animal = (function() {
})(); })();
Snake = (function(_super) { Snake = (function(_super) {
__extends(Snake, _super); __extends(Snake, _super);
function Snake() { function Snake() {
return Snake.__super__.constructor.apply(this, arguments); _ref = Snake.__super__.constructor.apply(this, arguments);
return _ref;
} }
Snake.prototype.move = function() { Snake.prototype.move = function() {
@ -1604,11 +1614,11 @@ Snake = (function(_super) {
})(Animal); })(Animal);
Horse = (function(_super) { Horse = (function(_super) {
__extends(Horse, _super); __extends(Horse, _super);
function Horse() { function Horse() {
return Horse.__super__.constructor.apply(this, arguments); _ref1 = Horse.__super__.constructor.apply(this, arguments);
return _ref1;
} }
Horse.prototype.move = function() { Horse.prototype.move = function() {
@ -1639,12 +1649,10 @@ tom.move();
<div class='code'><pre class="idle"><span class="FunctionName">String::dasherize </span><span class="Keyword">=</span> <span class="Keyword">-</span><span class="Keyword">&gt;</span> <div class='code'><pre class="idle"><span class="FunctionName">String::dasherize </span><span class="Keyword">=</span> <span class="Keyword">-</span><span class="Keyword">&gt;</span>
<span class="Variable">this</span>.replace <span class="String">/_/g</span>, <span class="String"><span class="String">&quot;</span>-<span class="String">&quot;</span></span> <span class="Variable">this</span>.replace <span class="String">/_/g</span>, <span class="String"><span class="String">&quot;</span>-<span class="String">&quot;</span></span>
</pre><pre class="idle"> </pre><pre class="idle"><span class="LibraryClassType">String</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">dasherize</span> = <span class="Storage">function</span>() {
<span class="LibraryClassType">String</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">dasherize</span> = <span class="Storage">function</span>() {
<span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryFunction">replace</span>(<span class="String"><span class="String">/</span>_<span class="String">/</span>g</span>, <span class="String"><span class="String">&quot;</span>-<span class="String">&quot;</span></span>); <span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryFunction">replace</span>(<span class="String"><span class="String">/</span>_<span class="String">/</span>g</span>, <span class="String"><span class="String">&quot;</span>-<span class="String">&quot;</span></span>);
}; };
</pre><script>window.example24 = "String::dasherize = ->\n this.replace /_/g, \"-\"\n\nalert \"one_two\".dasherize()"</script><div class='minibutton load' onclick='javascript: loadConsole(example24);'>load</div><div class='minibutton ok' onclick='javascript: </pre><script>window.example24 = "String::dasherize = ->\n this.replace /_/g, \"-\"\n\nalert \"one_two\".dasherize()"</script><div class='minibutton load' onclick='javascript: loadConsole(example24);'>load</div><div class='minibutton ok' onclick='javascript: String.prototype.dasherize = function() {
String.prototype.dasherize = function() {
return this.replace(/_/g, "-"); return this.replace(/_/g, "-");
}; };
;alert("one_two".dasherize());'>run: "one_two".dasherize()</div><br class='clear' /></div> ;alert("one_two".dasherize());'>run: "one_two".dasherize()</div><br class='clear' /></div>
@ -1791,14 +1799,13 @@ _ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call
Destructuring assignment is also useful when combined with class constructors Destructuring assignment is also useful when combined with class constructors
to assign propeties to your instance from an options object passed to the constructor. to assign propeties to your instance from an options object passed to the constructor.
</p> </p>
<div class='code'><pre class="idle">class Person <div class='code'><pre class="idle"><span class="Storage">class</span> <span class="TypeName">Person</span>
constructor: (options) -&gt; <span class="FunctionName">constructor</span><span class="Keyword">:</span> <span class="FunctionArgument">(options)</span> <span class="Storage">-&gt;</span>
{@name, @age, @height} = options <span class="Keyword">{</span><span class="Variable">@name</span>, <span class="Variable">@age</span>, <span class="Variable">@height</span><span class="Keyword">} =</span> options
</pre><pre class="idle"><span class="Storage">var</span> Person; </pre><pre class="idle"><span class="Storage">var</span> Person;
Person <span class="Keyword">=</span> (<span class="Storage">function</span>() { Person <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Storage">function</span> <span class="FunctionName">Person</span>(<span class="FunctionArgument">options</span>) { <span class="Storage">function</span> <span class="FunctionName">Person</span>(<span class="FunctionArgument">options</span>) {
<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> options.<span class="LibraryConstant">name</span>, <span class="Variable">this</span>.age <span class="Keyword">=</span> options.age, <span class="Variable">this</span>.<span class="LibraryConstant">height</span> <span class="Keyword">=</span> options.<span class="LibraryConstant">height</span>; <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> options.<span class="LibraryConstant">name</span>, <span class="Variable">this</span>.age <span class="Keyword">=</span> options.age, <span class="Variable">this</span>.<span class="LibraryConstant">height</span> <span class="Keyword">=</span> options.<span class="LibraryConstant">height</span>;
} }
@ -1809,7 +1816,6 @@ Person <span class="Keyword">=</span> (<span class="Storage">function</span>() {
</pre><script>window.example29 = "class Person\n constructor: (options) -> \n {@name, @age, @height} = options\n\nalert contents.join(\"\")"</script><div class='minibutton load' onclick='javascript: loadConsole(example29);'>load</div><div class='minibutton ok' onclick='javascript: var Person; </pre><script>window.example29 = "class Person\n constructor: (options) -> \n {@name, @age, @height} = options\n\nalert contents.join(\"\")"</script><div class='minibutton load' onclick='javascript: loadConsole(example29);'>load</div><div class='minibutton ok' onclick='javascript: var Person;
Person = (function() { Person = (function() {
function Person(options) { function Person(options) {
this.name = options.name, this.age = options.age, this.height = options.height; this.name = options.name, this.age = options.age, this.height = options.height;
} }
@ -1847,13 +1853,14 @@ Person = (function() {
<span class="FunctionName">Account</span> = <span class="Storage">function</span>(<span class="FunctionArgument">customer, cart</span>) { <span class="FunctionName">Account</span> = <span class="Storage">function</span>(<span class="FunctionArgument">customer, cart</span>) {
<span class="Storage">var</span> _this <span class="Keyword">=</span> <span class="Variable">this</span>; <span class="Storage">var</span> _this <span class="Keyword">=</span> <span class="Variable">this</span>;
<span class="Variable">this</span>.customer <span class="Keyword">=</span> customer; <span class="Variable">this</span>.customer <span class="Keyword">=</span> customer;
<span class="Variable">this</span>.cart <span class="Keyword">=</span> cart; <span class="Variable">this</span>.cart <span class="Keyword">=</span> cart;
<span class="Keyword">return</span> <span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.shopping_cart<span class="String">'</span></span>).bind(<span class="String"><span class="String">'</span>click<span class="String">'</span></span>, <span class="Storage">function</span>(<span class="LibraryClassType">event</span>) { <span class="Keyword">return</span> <span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.shopping_cart<span class="String">'</span></span>).bind(<span class="String"><span class="String">'</span>click<span class="String">'</span></span>, <span class="Storage">function</span>(<span class="LibraryClassType">event</span>) {
<span class="Keyword">return</span> _this.customer.purchase(_this.cart); <span class="Keyword">return</span> _this.customer.purchase(_this.cart);
}); });
}; };
</pre><script>window.example29 = "Account = (customer, cart) ->\n @customer = customer\n @cart = cart\n\n $('.shopping_cart').bind 'click', (event) =>\n @customer.purchase @cart"</script><div class='minibutton load' onclick='javascript: loadConsole(example29);'>load</div><br class='clear' /></div> </pre><script>window.example30 = "Account = (customer, cart) ->\n @customer = customer\n @cart = cart\n\n $('.shopping_cart').bind 'click', (event) =>\n @customer.purchase @cart"</script><div class='minibutton load' onclick='javascript: loadConsole(example30);'>load</div><br class='clear' /></div>
<p> <p>
If we had used <tt>-&gt;</tt> in the callback above, <tt>@customer</tt> would If we had used <tt>-&gt;</tt> in the callback above, <tt>@customer</tt> would
have referred to the undefined "customer" property of the DOM element, have referred to the undefined "customer" property of the DOM element,
@ -1883,7 +1890,7 @@ Person = (function() {
<span class="FunctionName">hi</span> = <span class="Storage">function</span>() { <span class="FunctionName">hi</span> = <span class="Storage">function</span>() {
<span class="Keyword">return</span> [<span class="LibraryClassType">document</span>.<span class="LibraryConstant">title</span>, <span class="String"><span class="String">&quot;</span>Hello JavaScript<span class="String">&quot;</span></span>].<span class="LibraryFunction">join</span>(<span class="String"><span class="String">&quot;</span>: <span class="String">&quot;</span></span>); <span class="Keyword">return</span> [<span class="LibraryClassType">document</span>.<span class="LibraryConstant">title</span>, <span class="String"><span class="String">&quot;</span>Hello JavaScript<span class="String">&quot;</span></span>].<span class="LibraryFunction">join</span>(<span class="String"><span class="String">&quot;</span>: <span class="String">&quot;</span></span>);
}; };
</pre><script>window.example30 = "hi = `function() {\n return [document.title, \"Hello JavaScript\"].join(\": \");\n}`\n\nalert hi()"</script><div class='minibutton load' onclick='javascript: loadConsole(example30);'>load</div><div class='minibutton ok' onclick='javascript: var hi; </pre><script>window.example31 = "hi = `function() {\n return [document.title, \"Hello JavaScript\"].join(\": \");\n}`\n\nalert hi()"</script><div class='minibutton load' onclick='javascript: loadConsole(example31);'>load</div><div class='minibutton ok' onclick='javascript: var hi;
hi = function() { hi = function() {
return [document.title, "Hello JavaScript"].join(": "); return [document.title, "Hello JavaScript"].join(": ");
@ -1915,8 +1922,7 @@ hi = function() {
go dancing go dancing
<span class="Keyword">when</span> <span class="String"><span class="String">&quot;</span>Sun<span class="String">&quot;</span></span> <span class="Keyword">then</span> go church <span class="Keyword">when</span> <span class="String"><span class="String">&quot;</span>Sun<span class="String">&quot;</span></span> <span class="Keyword">then</span> go church
<span class="Keyword">else</span> go work <span class="Keyword">else</span> go work
</pre><pre class="idle"> </pre><pre class="idle"><span class="Keyword">switch</span> (day) {
<span class="Keyword">switch</span> (day) {
<span class="Keyword">case</span> <span class="String"><span class="String">&quot;</span>Mon<span class="String">&quot;</span></span>: <span class="Keyword">case</span> <span class="String"><span class="String">&quot;</span>Mon<span class="String">&quot;</span></span>:
<span class="LibraryFunction">go</span>(work); <span class="LibraryFunction">go</span>(work);
<span class="Keyword">break</span>; <span class="Keyword">break</span>;
@ -1939,7 +1945,38 @@ hi = function() {
<span class="Keyword">default</span>: <span class="Keyword">default</span>:
<span class="LibraryFunction">go</span>(work); <span class="LibraryFunction">go</span>(work);
} }
</pre><script>window.example31 = "switch day\n when \"Mon\" then go work\n when \"Tue\" then go relax\n when \"Thu\" then go iceFishing\n when \"Fri\", \"Sat\"\n if day is bingoDay\n go bingo\n go dancing\n when \"Sun\" then go church\n else go work"</script><div class='minibutton load' onclick='javascript: loadConsole(example31);'>load</div><br class='clear' /></div> </pre><script>window.example32 = "switch day\n when \"Mon\" then go work\n when \"Tue\" then go relax\n when \"Thu\" then go iceFishing\n when \"Fri\", \"Sat\"\n if day is bingoDay\n go bingo\n go dancing\n when \"Sun\" then go church\n else go work"</script><div class='minibutton load' onclick='javascript: loadConsole(example32);'>load</div><br class='clear' /></div>
<p>
Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains.
</p>
<div class='code'><pre class="idle">score <span class="Keyword">=</span> <span class="Number">76</span>
grade <span class="Keyword">=</span> <span class="Keyword">switch</span>
<span class="Keyword">when</span> score <span class="Keyword">&lt;</span> <span class="Number">60</span> <span class="Keyword">then</span> <span class="String"><span class="String">'</span>F<span class="String">'</span></span>
<span class="Keyword">when</span> score <span class="Keyword">&lt;</span> <span class="Number">70</span> <span class="Keyword">then</span> <span class="String"><span class="String">'</span>D<span class="String">'</span></span>
<span class="Keyword">when</span> score <span class="Keyword">&lt;</span> <span class="Number">80</span> <span class="Keyword">then</span> <span class="String"><span class="String">'</span>C<span class="String">'</span></span>
<span class="Keyword">when</span> score <span class="Keyword">&lt;</span> <span class="Number">90</span> <span class="Keyword">then</span> <span class="String"><span class="String">'</span>B<span class="String">'</span></span>
<span class="Keyword">else</span> <span class="String"><span class="String">'</span>A<span class="String">'</span></span>
<span class="Comment"><span class="Comment">#</span> grade == 'C'</span>
</pre><pre class="idle"><span class="Storage">var</span> grade, score;
score <span class="Keyword">=</span> <span class="Number">76</span>;
grade <span class="Keyword">=</span> (<span class="Storage">function</span>() {
<span class="Keyword">switch</span> (<span class="BuiltInConstant">false</span>) {
<span class="Keyword">case</span> <span class="Keyword">!</span>(score <span class="Keyword">&lt;</span> <span class="Number">60</span>):
<span class="Keyword">return</span> <span class="String"><span class="String">'</span>F<span class="String">'</span></span>;
<span class="Keyword">case</span> <span class="Keyword">!</span>(score <span class="Keyword">&lt;</span> <span class="Number">70</span>):
<span class="Keyword">return</span> <span class="String"><span class="String">'</span>D<span class="String">'</span></span>;
<span class="Keyword">case</span> <span class="Keyword">!</span>(score <span class="Keyword">&lt;</span> <span class="Number">80</span>):
<span class="Keyword">return</span> <span class="String"><span class="String">'</span>C<span class="String">'</span></span>;
<span class="Keyword">case</span> <span class="Keyword">!</span>(score <span class="Keyword">&lt;</span> <span class="Number">90</span>):
<span class="Keyword">return</span> <span class="String"><span class="String">'</span>B<span class="String">'</span></span>;
<span class="Keyword">default</span>:
<span class="Keyword">return</span> <span class="String"><span class="String">'</span>A<span class="String">'</span></span>;
}
})();
</pre><script>window.example33 = "score = 76\ngrade = switch\n when score < 60 then 'F'\n when score < 70 then 'D'\n when score < 80 then 'C'\n when score < 90 then 'B'\n else 'A'\n# grade == 'C'\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example33);'>load</div><br class='clear' /></div>
<p> <p>
<span id="try" class="bookmark"></span> <span id="try" class="bookmark"></span>
@ -1955,16 +1992,18 @@ hi = function() {
<span class="Keyword">finally</span> <span class="Keyword">finally</span>
cleanUp() cleanUp()
</pre><pre class="idle"> </pre><pre class="idle"><span class="Storage">var</span> error;
<span class="Keyword">try</span> { <span class="Keyword">try</span> {
allHellBreaksLoose(); allHellBreaksLoose();
catsAndDogsLivingTogether(); catsAndDogsLivingTogether();
} <span class="Keyword">catch</span> (error) { } <span class="Keyword">catch</span> (_error) {
error <span class="Keyword">=</span> _error;
<span class="LibraryFunction">print</span>(error); <span class="LibraryFunction">print</span>(error);
} <span class="Keyword">finally</span> { } <span class="Keyword">finally</span> {
cleanUp(); cleanUp();
} }
</pre><script>window.example32 = "try\n allHellBreaksLoose()\n catsAndDogsLivingTogether()\ncatch error\n print error\nfinally\n cleanUp()\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example32);'>load</div><br class='clear' /></div> </pre><script>window.example34 = "try\n allHellBreaksLoose()\n catsAndDogsLivingTogether()\ncatch error\n print error\nfinally\n cleanUp()\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example34);'>load</div><br class='clear' /></div>
<p> <p>
<span id="comparisons" class="bookmark"></span> <span id="comparisons" class="bookmark"></span>
@ -1984,7 +2023,7 @@ healthy <span class="Keyword">=</span> <span class="Number">200</span> <span cla
cholesterol <span class="Keyword">=</span> <span class="Number">127</span>; cholesterol <span class="Keyword">=</span> <span class="Number">127</span>;
healthy <span class="Keyword">=</span> (<span class="Number">200</span> <span class="Keyword">&gt;</span> cholesterol <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> cholesterol <span class="Keyword">&gt;</span> <span class="Number">60</span>); healthy <span class="Keyword">=</span> (<span class="Number">200</span> <span class="Keyword">&gt;</span> cholesterol <span class="Keyword">&amp;</span><span class="Keyword">&amp;</span> cholesterol <span class="Keyword">&gt;</span> <span class="Number">60</span>);
</pre><script>window.example33 = "cholesterol = 127\n\nhealthy = 200 > cholesterol > 60\n\nalert healthy"</script><div class='minibutton load' onclick='javascript: loadConsole(example33);'>load</div><div class='minibutton ok' onclick='javascript: var cholesterol, healthy; </pre><script>window.example35 = "cholesterol = 127\n\nhealthy = 200 > cholesterol > 60\n\nalert healthy"</script><div class='minibutton load' onclick='javascript: loadConsole(example35);'>load</div><div class='minibutton ok' onclick='javascript: var cholesterol, healthy;
cholesterol = 127; cholesterol = 127;
@ -2014,7 +2053,7 @@ author <span class="Keyword">=</span> <span class="String"><span class="String">
quote <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>A picture is a fact. -- <span class="String">&quot;</span></span> <span class="Keyword">+</span> author; quote <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>A picture is a fact. -- <span class="String">&quot;</span></span> <span class="Keyword">+</span> author;
sentence <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">+</span> (<span class="Number">22</span> / <span class="Number">7</span>) <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> is a decent approximation of π<span class="String">&quot;</span></span>; sentence <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">+</span> (<span class="Number">22</span> / <span class="Number">7</span>) <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> is a decent approximation of π<span class="String">&quot;</span></span>;
</pre><script>window.example34 = "author = \"Wittgenstein\"\nquote = \"A picture is a fact. -- #{ author }\"\n\nsentence = \"#{ 22 / 7 } is a decent approximation of π\"\n\nalert sentence"</script><div class='minibutton load' onclick='javascript: loadConsole(example34);'>load</div><div class='minibutton ok' onclick='javascript: var author, quote, sentence; </pre><script>window.example36 = "author = \"Wittgenstein\"\nquote = \"A picture is a fact. -- #{ author }\"\n\nsentence = \"#{ 22 / 7 } is a decent approximation of π\"\n\nalert sentence"</script><div class='minibutton load' onclick='javascript: loadConsole(example36);'>load</div><div class='minibutton ok' onclick='javascript: var author, quote, sentence;
author = "Wittgenstein"; author = "Wittgenstein";
@ -2036,7 +2075,7 @@ sentence = "" + (22 / 7) + " is a decent approximation of π";
</pre><pre class="idle"><span class="Storage">var</span> mobyDick; </pre><pre class="idle"><span class="Storage">var</span> mobyDick;
mobyDick <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...<span class="String">&quot;</span></span>; mobyDick <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...<span class="String">&quot;</span></span>;
</pre><script>window.example35 = "mobyDick = \"Call me Ishmael. Some years ago --\n never mind how long precisely -- having little\n or no money in my purse, and nothing particular\n to interest me on shore, I thought I would sail\n about a little and see the watery part of the\n world...\"\n\nalert mobyDick"</script><div class='minibutton load' onclick='javascript: loadConsole(example35);'>load</div><div class='minibutton ok' onclick='javascript: var mobyDick; </pre><script>window.example37 = "mobyDick = \"Call me Ishmael. Some years ago --\n never mind how long precisely -- having little\n or no money in my purse, and nothing particular\n to interest me on shore, I thought I would sail\n about a little and see the watery part of the\n world...\"\n\nalert mobyDick"</script><div class='minibutton load' onclick='javascript: loadConsole(example37);'>load</div><div class='minibutton ok' onclick='javascript: var mobyDick;
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world..."; mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";
;alert(mobyDick);'>run: mobyDick</div><br class='clear' /></div> ;alert(mobyDick);'>run: mobyDick</div><br class='clear' /></div>
@ -2055,7 +2094,7 @@ mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely --
</pre><pre class="idle"><span class="Storage">var</span> html; </pre><pre class="idle"><span class="Storage">var</span> html;
html <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>&lt;strong&gt;<span class="UserDefinedConstant">\n</span> cup of coffeescript<span class="UserDefinedConstant">\n</span>&lt;/strong&gt;<span class="String">&quot;</span></span>; html <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>&lt;strong&gt;<span class="UserDefinedConstant">\n</span> cup of coffeescript<span class="UserDefinedConstant">\n</span>&lt;/strong&gt;<span class="String">&quot;</span></span>;
</pre><script>window.example36 = "html = \"\"\"\n <strong>\n cup of coffeescript\n </strong>\n \"\"\"\n\nalert html"</script><div class='minibutton load' onclick='javascript: loadConsole(example36);'>load</div><div class='minibutton ok' onclick='javascript: var html; </pre><script>window.example38 = "html = \"\"\"\n <strong>\n cup of coffeescript\n </strong>\n \"\"\"\n\nalert html"</script><div class='minibutton load' onclick='javascript: loadConsole(example38);'>load</div><div class='minibutton ok' onclick='javascript: var html;
html = "<strong>\n cup of coffeescript\n</strong>"; html = "<strong>\n cup of coffeescript\n</strong>";
;alert(html);'>run: html</div><br class='clear' /></div> ;alert(html);'>run: html</div><br class='clear' /></div>
@ -2069,25 +2108,24 @@ html = "<strong>\n cup of coffeescript\n</strong>";
are preserved in the generated code. are preserved in the generated code.
</p> </p>
<div class='code'><pre class="idle"><span class="Comment"><span class="Comment">###</span></span> <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">###</span></span>
<span class="Comment">CoffeeScript Compiler v1.6.1</span> <span class="Comment">SkinnyMochaHalfCaffScript Compiler v1.0</span>
<span class="Comment">Released under the MIT License</span> <span class="Comment">Released under the MIT License</span>
<span class="Comment"><span class="Comment">###</span></span> <span class="Comment"><span class="Comment">###</span></span>
</pre><pre class="idle"><span class="Comment"><span class="Comment">/*</span></span> </pre><pre class="idle"><span class="Comment"><span class="Comment">/*</span></span>
<span class="Comment">CoffeeScript Compiler v1.6.1</span> <span class="Comment">SkinnyMochaHalfCaffScript Compiler v1.0</span>
<span class="Comment">Released under the MIT License</span> <span class="Comment">Released under the MIT License</span>
<span class="Comment"><span class="Comment">*/</span></span> <span class="Comment"><span class="Comment">*/</span></span>
</pre><script>window.example39 = "###\nSkinnyMochaHalfCaffScript Compiler v1.0\nReleased under the MIT License\n###\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example39);'>load</div><br class='clear' /></div>
</pre><script>window.example37 = "###\nCoffeeScript Compiler v1.6.1\nReleased under the MIT License\n###\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example37);'>load</div><br class='clear' /></div>
<p> <p>
<span id="regexes" class="bookmark"></span> <span id="regexes" class="bookmark"></span>
<b class="header">Block Regular Expressions</b> <b class="header">Block Regular Expressions</b>
Similar to block strings and comments, CoffeeScript supports block regexes &mdash; Similar to block strings and comments, CoffeeScript supports block regexes &mdash;
extended regular expressions that ignore internal whitespace and can contain extended regular expressions that ignore internal whitespace and can contain
comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeSctipt's comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeScript's
block regexes are delimited by <tt>///</tt> and go a long way towards making complex block regexes are delimited by <tt>///</tt> and go a long way towards making complex
regular expressions readable. To quote from the CoffeeScript source: regular expressions readable. To quote from the CoffeeScript source:
</p> </p>
@ -2105,7 +2143,7 @@ html = "<strong>\n cup of coffeescript\n</strong>";
</pre><pre class="idle"><span class="Storage">var</span> OPERATOR; </pre><pre class="idle"><span class="Storage">var</span> OPERATOR;
OPERATOR <span class="Keyword">=</span><span class="String"> <span class="String">/</span>^(?:[-=]&gt;|[-+*<span class="UserDefinedConstant">\/</span>%&lt;&gt;&amp;|^!?=]=|&gt;&gt;&gt;=?|([-+:])<span class="UserDefinedConstant">\1</span>|([&amp;|&lt;&gt;])<span class="UserDefinedConstant">\2</span>=?|<span class="UserDefinedConstant">\?</span><span class="UserDefinedConstant">\.</span>|<span class="UserDefinedConstant">\.</span>{2,3})<span class="String">/</span></span>; OPERATOR <span class="Keyword">=</span><span class="String"> <span class="String">/</span>^(?:[-=]&gt;|[-+*<span class="UserDefinedConstant">\/</span>%&lt;&gt;&amp;|^!?=]=|&gt;&gt;&gt;=?|([-+:])<span class="UserDefinedConstant">\1</span>|([&amp;|&lt;&gt;])<span class="UserDefinedConstant">\2</span>=?|<span class="UserDefinedConstant">\?</span><span class="UserDefinedConstant">\.</span>|<span class="UserDefinedConstant">\.</span>{2,3})<span class="String">/</span></span>;
</pre><script>window.example38 = "OPERATOR = /// ^ (\n ?: [-=]> # function\n | [-+*/%<>&|^!?=]= # compound assign / compare\n | >>>=? # zero-fill right shift\n | ([-+:])\\1 # doubles\n | ([&|<>])\\2=? # logic / shift\n | \\?\\. # soak access\n | \\.{2,3} # range or splat\n) ///\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example38);'>load</div><br class='clear' /></div> </pre><script>window.example40 = "OPERATOR = /// ^ (\n ?: [-=]> # function\n | [-+*/%<>&|^!?=]= # compound assign / compare\n | >>>=? # zero-fill right shift\n | ([-+:])\\1 # doubles\n | ([&|<>])\\2=? # logic / shift\n | \\?\\. # soak access\n | \\.{2,3} # range or splat\n) ///\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example40);'>load</div><br class='clear' /></div>
<h2> <h2>
@ -2148,12 +2186,13 @@ option(<span class="String"><span class="String">'</span>-o<span class="String">
task(<span class="String"><span class="String">'</span>build:parser<span class="String">'</span></span>, <span class="String"><span class="String">'</span>rebuild the Jison parser<span class="String">'</span></span>, <span class="Storage">function</span>(options) { task(<span class="String"><span class="String">'</span>build:parser<span class="String">'</span></span>, <span class="String"><span class="String">'</span>rebuild the Jison parser<span class="String">'</span></span>, <span class="Storage">function</span>(options) {
<span class="Storage">var</span> code, dir; <span class="Storage">var</span> code, dir;
require(<span class="String"><span class="String">'</span>jison<span class="String">'</span></span>); require(<span class="String"><span class="String">'</span>jison<span class="String">'</span></span>);
code <span class="Keyword">=</span> require(<span class="String"><span class="String">'</span>./lib/grammar<span class="String">'</span></span>).parser.generate(); code <span class="Keyword">=</span> require(<span class="String"><span class="String">'</span>./lib/grammar<span class="String">'</span></span>).parser.generate();
dir <span class="Keyword">=</span> options.output <span class="Keyword">||</span> <span class="String"><span class="String">'</span>lib<span class="String">'</span></span>; dir <span class="Keyword">=</span> options.output <span class="Keyword">||</span> <span class="String"><span class="String">'</span>lib<span class="String">'</span></span>;
<span class="Keyword">return</span> fs.writeFile(<span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">+</span> dir <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span>/parser.js<span class="String">&quot;</span></span>, code); <span class="Keyword">return</span> fs.writeFile(<span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">+</span> dir <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span>/parser.js<span class="String">&quot;</span></span>, code);
}); });
</pre><script>window.example39 = "fs = require 'fs'\n\noption '-o', '--output [DIR]', 'directory for compiled code'\n\ntask 'build:parser', 'rebuild the Jison parser', (options) ->\n require 'jison'\n code = require('./lib/grammar').parser.generate()\n dir = options.output or 'lib'\n fs.writeFile \"#{dir}/parser.js\", code"</script><div class='minibutton load' onclick='javascript: loadConsole(example39);'>load</div><br class='clear' /></div> </pre><script>window.example41 = "fs = require 'fs'\n\noption '-o', '--output [DIR]', 'directory for compiled code'\n\ntask 'build:parser', 'rebuild the Jison parser', (options) ->\n require 'jison'\n code = require('./lib/grammar').parser.generate()\n dir = options.output or 'lib'\n fs.writeFile \"#{dir}/parser.js\", code"</script><div class='minibutton load' onclick='javascript: loadConsole(example41);'>load</div><br class='clear' /></div>
<p> <p>
If you need to invoke one task before another &mdash; for example, running If you need to invoke one task before another &mdash; for example, running
<tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function: <tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function:
@ -2366,6 +2405,13 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
<a href="http://github.com/jashkenas/coffee-script/wiki/FAQ">The FAQ</a><br /> <a href="http://github.com/jashkenas/coffee-script/wiki/FAQ">The FAQ</a><br />
Perhaps your CoffeeScript-related question has been asked before. Check the FAQ first. Perhaps your CoffeeScript-related question has been asked before. Check the FAQ first.
</li> </li>
<li>
<a href="http://js2coffee.org">JS2Coffee</a><br />
Is a very well done reverse JavaScript-to-CoffeeScript compiler. It's
not going to be perfect (infer what your JavaScript classes are, when
you need bound functions, and so on...) &mdash; but it's a great starting
point for converting simple scripts.
</li>
<li> <li>
<a href="https://github.com/jashkenas/coffee-script/downloads">High-Rez Logo</a><br /> <a href="https://github.com/jashkenas/coffee-script/downloads">High-Rez Logo</a><br />
The CoffeeScript logo is available in Illustrator, EPS and PSD formats, for use The CoffeeScript logo is available in Illustrator, EPS and PSD formats, for use
@ -2393,6 +2439,35 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
Change Log Change Log
</h2> </h2>
<p>
<b class="header" style="margin-top: 20px;">
<a href="https://github.com/jashkenas/coffee-script/compare/1.6.1...1.6.2">1.6.2</a>
<span class="timestamp"> &ndash; <small>March 18, 2013</small></span>
</b>
<ul>
<li>
Source maps have been used to provide automatic line-mapping when
running CoffeeScript directly via the <tt>coffee</tt> command, and
for automatic line-mapping when running CoffeeScript directly in the
browser. Also, to provide better error messages for semantic errors
thrown by the compiler &mdash;
<a href="http://cl.ly/NdOA">with colors, even</a>.
</li>
<li>
Improved support for mixed literate/vanilla-style CoffeeScript projects,
and generating source maps for both at the same time.
</li>
<li>
Fixes for <b>1.6.x</b> regressions with overriding inherited bound
functions, and for Windows file path management.
</li>
<li>
The <tt>coffee</tt> command can now correctly <tt>fork()</tt>
both <tt>.coffee</tt> and <tt>.js</tt> files. (Requires Node.js 0.9+)
</li>
</ul>
</p>
<p> <p>
<b class="header" style="margin-top: 20px;"> <b class="header" style="margin-top: 20px;">
<a href="https://github.com/jashkenas/coffee-script/compare/1.5.0...1.6.1">1.6.1</a> <a href="https://github.com/jashkenas/coffee-script/compare/1.5.0...1.6.1">1.6.1</a>
@ -3140,8 +3215,10 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
else else
$(el).text window.compiledJS $(el).text window.compiledJS
$('#error').hide() $('#error').hide()
catch error catch {location, message}
$('#error').text(error.message).show() if location?
message = "Error on line #{location.first_line + 1}: #{message}"
$('#error').text(message).show()
# Update permalink # Update permalink
$('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}" $('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}"

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var CoffeeScript, compile, runScripts, var CoffeeScript, compile, runScripts,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
@ -7,19 +7,11 @@
CoffeeScript.require = require; CoffeeScript.require = require;
compile = (typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null) ? function(code, options) { compile = CoffeeScript.compile;
var js, v3SourceMap, _ref;
if (options == null) {
options = {};
}
options.sourceMap = true;
options.inline = true;
_ref = CoffeeScript.compile(code, options), js = _ref.js, v3SourceMap = _ref.v3SourceMap;
return "" + js + "\n//@ sourceMappingURL=data:application/json;base64," + (btoa(v3SourceMap)) + "\n//@ sourceURL=coffeescript";
} : CoffeeScript.compile;
CoffeeScript["eval"] = function(code, options) { CoffeeScript["eval"] = function(code, options) {
var _ref; var _ref;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -41,8 +33,23 @@
return; return;
} }
if ((typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null)) {
compile = function(code, options) {
var js, v3SourceMap, _ref;
if (options == null) {
options = {};
}
options.sourceMap = true;
options.inline = true;
_ref = CoffeeScript.compile(code, options), js = _ref.js, v3SourceMap = _ref.v3SourceMap;
return "" + js + "\n//@ sourceMappingURL=data:application/json;base64," + (btoa(v3SourceMap)) + "\n//@ sourceURL=coffeescript";
};
}
CoffeeScript.load = function(url, callback, options) { CoffeeScript.load = function(url, callback, options) {
var xhr; var xhr;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -54,6 +61,7 @@
} }
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
var _ref; var _ref;
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if ((_ref = xhr.status) === 0 || _ref === 200) { if ((_ref = xhr.status) === 0 || _ref === 200) {
CoffeeScript.run(xhr.responseText, options); CoffeeScript.run(xhr.responseText, options);
@ -70,10 +78,12 @@
runScripts = function() { runScripts = function() {
var coffees, coffeetypes, execute, index, length, s, scripts; var coffees, coffeetypes, execute, index, length, s, scripts;
scripts = document.getElementsByTagName('script'); scripts = document.getElementsByTagName('script');
coffeetypes = ['text/coffeescript', 'text/literate-coffeescript']; coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
coffees = (function() { coffees = (function() {
var _i, _len, _ref, _results; var _i, _len, _ref, _results;
_results = []; _results = [];
for (_i = 0, _len = scripts.length; _i < _len; _i++) { for (_i = 0, _len = scripts.length; _i < _len; _i++) {
s = scripts[_i]; s = scripts[_i];
@ -87,6 +97,7 @@
length = coffees.length; length = coffees.length;
(execute = function() { (execute = function() {
var mediatype, options, script; var mediatype, options, script;
script = coffees[index++]; script = coffees[index++];
mediatype = script != null ? script.type : void 0; mediatype = script != null ? script.type : void 0;
if (__indexOf.call(coffeetypes, mediatype) >= 0) { if (__indexOf.call(coffeetypes, mediatype) >= 0) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var CoffeeScript, cakefileDirectory, existsSync, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; var CoffeeScript, cakefileDirectory, existsSync, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
@ -25,6 +25,7 @@
helpers.extend(global, { helpers.extend(global, {
task: function(name, description, action) { task: function(name, description, action) {
var _ref; var _ref;
if (!action) { if (!action) {
_ref = [description, action], action = _ref[0], description = _ref[1]; _ref = [description, action], action = _ref[0], description = _ref[1];
} }
@ -47,6 +48,7 @@
exports.run = function() { exports.run = function() {
var arg, args, e, _i, _len, _ref, _results; var arg, args, e, _i, _len, _ref, _results;
global.__originalDirname = fs.realpathSync('.'); global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname)); process.chdir(cakefileDirectory(__originalDirname));
args = process.argv.slice(2); args = process.argv.slice(2);
@ -74,6 +76,7 @@
printTasks = function() { printTasks = function() {
var cakefilePath, desc, name, relative, spaces, task; var cakefilePath, desc, name, relative, spaces, task;
relative = path.relative || path.resolve; relative = path.relative || path.resolve;
cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile'); cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
console.log("" + cakefilePath + " defines the following tasks:\n"); console.log("" + cakefilePath + " defines the following tasks:\n");
@ -101,6 +104,7 @@
cakefileDirectory = function(dir) { cakefileDirectory = function(dir) {
var parent; var parent;
if (existsSync(path.join(dir, 'Cakefile'))) { if (existsSync(path.join(dir, 'Cakefile'))) {
return dir; return dir;
} }

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var Lexer, child_process, compile, ext, fork, formatSourcePosition, fs, helpers, lexer, loadFile, parser, patchStackTrace, patched, path, sourcemap, vm, _i, _len, _ref, var Lexer, child_process, compile, ext, fork, formatSourcePosition, fs, helpers, lexer, loadFile, parser, patchStackTrace, patched, path, sourcemap, vm, _i, _len, _ref,
__hasProp = {}.hasOwnProperty; __hasProp = {}.hasOwnProperty;
@ -19,12 +19,13 @@
sourcemap = require('./sourcemap'); sourcemap = require('./sourcemap');
exports.VERSION = '1.6.1'; exports.VERSION = '1.6.2';
exports.helpers = helpers; exports.helpers = helpers;
exports.compile = compile = function(code, options) { exports.compile = compile = function(code, options) {
var answer, currentColumn, currentLine, fragment, fragments, header, js, merge, newLines, sourceMap, _i, _len; var answer, currentColumn, currentLine, fragment, fragments, header, js, merge, newLines, sourceMap, _i, _len;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -85,6 +86,7 @@
exports.run = function(code, options) { exports.run = function(code, options) {
var answer, mainModule, _ref; var answer, mainModule, _ref;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -107,6 +109,7 @@
exports["eval"] = function(code, options) { exports["eval"] = function(code, options) {
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _require; var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _require;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -170,6 +173,7 @@
loadFile = function(module, filename) { loadFile = function(module, filename) {
var raw, stripped; var raw, stripped;
raw = fs.readFileSync(filename, 'utf8'); raw = fs.readFileSync(filename, 'utf8');
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw; stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
return module._compile(compile(stripped, { return module._compile(compile(stripped, {
@ -186,10 +190,11 @@
} }
} }
if (child_process) {
fork = child_process.fork; fork = child_process.fork;
child_process.fork = function(path, args, options) { child_process.fork = function(path, args, options) {
var execPath; var execPath;
if (args == null) { if (args == null) {
args = []; args = [];
} }
@ -204,12 +209,14 @@
options.execPath || (options.execPath = execPath); options.execPath || (options.execPath = execPath);
return fork(path, args, options); return fork(path, args, options);
}; };
}
lexer = new Lexer; lexer = new Lexer;
parser.lexer = { parser.lexer = {
lex: function() { lex: function() {
var tag, token; var tag, token;
token = this.tokens[this.pos++]; token = this.tokens[this.pos++];
if (token) { if (token) {
tag = token[0], this.yytext = token[1], this.yylloc = token[2]; tag = token[0], this.yytext = token[1], this.yylloc = token[2];
@ -232,6 +239,7 @@
parser.yy.parseError = function(message, _arg) { parser.yy.parseError = function(message, _arg) {
var token; var token;
token = _arg.token; token = _arg.token;
message = "unexpected " + (token === 1 ? 'end of input' : token); message = "unexpected " + (token === 1 ? 'end of input' : token);
return helpers.throwSyntaxError(message, parser.lexer.yylloc); return helpers.throwSyntaxError(message, parser.lexer.yylloc);
@ -241,6 +249,7 @@
patchStackTrace = function() { patchStackTrace = function() {
var mainModule; var mainModule;
if (patched) { if (patched) {
return; return;
} }
@ -249,9 +258,11 @@
mainModule._sourceMaps = {}; mainModule._sourceMaps = {};
return Error.prepareStackTrace = function(err, stack) { return Error.prepareStackTrace = function(err, stack) {
var frame, frames, getSourceMapping, sourceFiles, _ref1; var frame, frames, getSourceMapping, sourceFiles, _ref1;
sourceFiles = {}; sourceFiles = {};
getSourceMapping = function(filename, line, column) { getSourceMapping = function(filename, line, column) {
var answer, sourceMap; var answer, sourceMap;
sourceMap = mainModule._sourceMaps[filename]; sourceMap = mainModule._sourceMaps[filename];
if (sourceMap) { if (sourceMap) {
answer = sourceMap.getSourcePosition([line - 1, column - 1]); answer = sourceMap.getSourcePosition([line - 1, column - 1]);
@ -264,6 +275,7 @@
}; };
frames = (function() { frames = (function() {
var _j, _len1, _results; var _j, _len1, _results;
_results = []; _results = [];
for (_j = 0, _len1 = stack.length; _j < _len1; _j++) { for (_j = 0, _len1 = stack.length; _j < _len1; _j++) {
frame = stack[_j]; frame = stack[_j];
@ -280,6 +292,7 @@
formatSourcePosition = function(frame, getSourceMapping) { formatSourcePosition = function(frame, getSourceMapping) {
var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName; var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
fileName = void 0; fileName = void 0;
fileLocation = ''; fileLocation = '';
if (frame.isNative()) { if (frame.isNative()) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref; var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
@ -50,6 +50,7 @@
exports.run = function() { exports.run = function() {
var literals, source, _i, _len, _results; var literals, source, _i, _len, _results;
parseOptions(); parseOptions();
if (opts.nodejs) { if (opts.nodejs) {
return forkNode(); return forkNode();
@ -101,6 +102,7 @@
} }
return fs.readdir(source, function(err, files) { return fs.readdir(source, function(err, files) {
var file, index, _ref1, _ref2; var file, index, _ref1, _ref2;
if (err && err.code !== 'ENOENT') { if (err && err.code !== 'ENOENT') {
throw err; throw err;
} }
@ -113,6 +115,7 @@
}); });
[].splice.apply(sources, [index, index - index + 1].concat(_ref1 = (function() { [].splice.apply(sources, [index, index - index + 1].concat(_ref1 = (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) { for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i]; file = files[_i];
@ -149,6 +152,7 @@
compileScript = function(file, input, base) { compileScript = function(file, input, base) {
var compiled, err, message, o, options, t, task, useColors; var compiled, err, message, o, options, t, task, useColors;
if (base == null) { if (base == null) {
base = null; base = null;
} }
@ -208,6 +212,7 @@
compileStdio = function() { compileStdio = function() {
var code, stdin; var code, stdin;
code = ''; code = '';
stdin = process.openStdin(); stdin = process.openStdin();
stdin.on('data', function(buffer) { stdin.on('data', function(buffer) {
@ -238,6 +243,7 @@
watch = function(source, base) { watch = function(source, base) {
var compile, compileTimeout, e, prevStats, rewatch, watchErr, watcher; var compile, compileTimeout, e, prevStats, rewatch, watchErr, watcher;
prevStats = null; prevStats = null;
compileTimeout = null; compileTimeout = null;
watchErr = function(e) { watchErr = function(e) {
@ -294,6 +300,7 @@
watchDir = function(source, base) { watchDir = function(source, base) {
var e, readdirTimeout, watcher; var e, readdirTimeout, watcher;
readdirTimeout = null; readdirTimeout = null;
try { try {
return watcher = fs.watch(source, function() { return watcher = fs.watch(source, function() {
@ -301,6 +308,7 @@
return readdirTimeout = wait(25, function() { return readdirTimeout = wait(25, function() {
return fs.readdir(source, function(err, files) { return fs.readdir(source, function(err, files) {
var file, _i, _len, _results; var file, _i, _len, _results;
if (err) { if (err) {
if (err.code !== 'ENOENT') { if (err.code !== 'ENOENT') {
throw err; throw err;
@ -338,9 +346,11 @@
unwatchDir = function(source, base) { unwatchDir = function(source, base) {
var file, prevSources, toRemove, _i, _len; var file, prevSources, toRemove, _i, _len;
prevSources = sources.slice(0); prevSources = sources.slice(0);
toRemove = (function() { toRemove = (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = sources.length; _i < _len; _i++) { for (_i = 0, _len = sources.length; _i < _len; _i++) {
file = sources[_i]; file = sources[_i];
@ -364,6 +374,7 @@
removeSource = function(source, base, removeJs) { removeSource = function(source, base, removeJs) {
var index, jsPath; var index, jsPath;
index = sources.indexOf(source); index = sources.indexOf(source);
sources.splice(index, 1); sources.splice(index, 1);
sourceCode.splice(index, 1); sourceCode.splice(index, 1);
@ -384,6 +395,7 @@
outputPath = function(source, base, extension) { outputPath = function(source, base, extension) {
var baseDir, basename, dir, srcDir; var baseDir, basename, dir, srcDir;
if (extension == null) { if (extension == null) {
extension = ".js"; extension = ".js";
} }
@ -396,6 +408,7 @@
writeJs = function(base, sourcePath, js, jsPath, generatedSourceMap) { writeJs = function(base, sourcePath, js, jsPath, generatedSourceMap) {
var compile, jsDir, sourceMapPath; var compile, jsDir, sourceMapPath;
if (generatedSourceMap == null) { if (generatedSourceMap == null) {
generatedSourceMap = null; generatedSourceMap = null;
} }
@ -444,6 +457,7 @@
lint = function(file, js) { lint = function(file, js) {
var conf, jsl, printIt; var conf, jsl, printIt;
printIt = function(buffer) { printIt = function(buffer) {
return printLine(file + ':\t' + buffer.toString().trim()); return printLine(file + ':\t' + buffer.toString().trim());
}; };
@ -457,8 +471,10 @@
printTokens = function(tokens) { printTokens = function(tokens) {
var strings, tag, token, value; var strings, tag, token, value;
strings = (function() { strings = (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = tokens.length; _i < _len; _i++) { for (_i = 0, _len = tokens.length; _i < _len; _i++) {
token = tokens[_i]; token = tokens[_i];
@ -473,6 +489,7 @@
parseOptions = function() { parseOptions = function() {
var i, o, source, _i, _len; var i, o, source, _i, _len;
optionParser = new optparse.OptionParser(SWITCHES, BANNER); optionParser = new optparse.OptionParser(SWITCHES, BANNER);
o = opts = optionParser.parse(process.argv.slice(2)); o = opts = optionParser.parse(process.argv.slice(2));
o.compile || (o.compile = !!o.output); o.compile || (o.compile = !!o.output);
@ -487,6 +504,7 @@
compileOptions = function(filename, base) { compileOptions = function(filename, base) {
var answer, cwd, jsDir, jsPath; var answer, cwd, jsDir, jsPath;
answer = { answer = {
filename: filename, filename: filename,
literate: helpers.isLiterate(filename), literate: helpers.isLiterate(filename),
@ -518,6 +536,7 @@
forkNode = function() { forkNode = function() {
var args, nodeArgs; var args, nodeArgs;
nodeArgs = opts.nodejs.split(/\s+/); nodeArgs = opts.nodejs.split(/\s+/);
args = process.argv.slice(1); args = process.argv.slice(1);
args.splice(args.indexOf('--nodejs'), 2); args.splice(args.indexOf('--nodejs'), 2);

View file

@ -1,53 +0,0 @@
// Generated by CoffeeScript 1.6.1
(function() {
var CompilerError, repeat,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
repeat = require('./helpers').repeat;
exports.CompilerError = CompilerError = (function(_super) {
__extends(CompilerError, _super);
CompilerError.prototype.name = 'CompilerError';
function CompilerError(message, startLine, startColumn, endLine, endColumn) {
this.message = message;
this.startLine = startLine;
this.startColumn = startColumn;
this.endLine = endLine != null ? endLine : this.startLine;
this.endColumn = endColumn != null ? endColumn : this.startColumn;
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, CompilerError);
}
}
CompilerError.fromLocationData = function(message, _arg) {
var first_column, first_line, last_column, last_line;
first_line = _arg.first_line, first_column = _arg.first_column, last_line = _arg.last_line, last_column = _arg.last_column;
return new CompilerError(message, first_line, first_column, last_line, last_column);
};
CompilerError.prototype.prettyMessage = function(fileName, code, useColors) {
var colorize, end, errorLine, marker, message, start;
errorLine = code.split('\n')[this.startLine];
start = this.startColumn;
end = this.startLine === this.endLine ? this.endColumn + 1 : errorLine.length;
marker = repeat(' ', start) + repeat('^', end - start);
if (useColors) {
colorize = function(str) {
return "\x1B[1;31m" + str + "\x1B[0m";
};
errorLine = errorLine.slice(0, start) + colorize(errorLine.slice(start, end)) + errorLine.slice(end);
marker = colorize(marker);
}
message = "" + fileName + ":" + (this.startLine + 1) + ":" + (this.startColumn + 1) + ": error: " + this.message + "\n" + errorLine + "\n" + marker;
return message;
};
return CompilerError;
})(Error);
}).call(this);

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap; var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
@ -8,6 +8,7 @@
o = function(patternString, action, options) { o = function(patternString, action, options) {
var addLocationDataFn, match, patternCount; var addLocationDataFn, match, patternCount;
patternString = patternString.replace(/\s{2,}/g, ' '); patternString = patternString.replace(/\s{2,}/g, ' ');
patternCount = patternString.split(' ').length; patternCount = patternString.split(' ').length;
if (!action) { if (!action) {
@ -594,6 +595,7 @@
alternatives = grammar[name]; alternatives = grammar[name];
grammar[name] = (function() { grammar[name] = (function() {
var _i, _j, _len, _len1, _ref, _results; var _i, _j, _len, _len1, _ref, _results;
_results = []; _results = [];
for (_i = 0, _len = alternatives.length; _i < _len; _i++) { for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
alt = alternatives[_i]; alt = alternatives[_i];

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var buildLocationData, extend, flatten, last, repeat, _ref; var buildLocationData, extend, flatten, last, repeat, _ref;
@ -8,12 +8,14 @@
exports.ends = function(string, literal, back) { exports.ends = function(string, literal, back) {
var len; var len;
len = literal.length; len = literal.length;
return literal === string.substr(string.length - len - (back || 0), len); return literal === string.substr(string.length - len - (back || 0), len);
}; };
exports.repeat = repeat = function(str, n) { exports.repeat = repeat = function(str, n) {
var res; var res;
res = ''; res = '';
while (n > 0) { while (n > 0) {
if (n & 1) { if (n & 1) {
@ -27,6 +29,7 @@
exports.compact = function(array) { exports.compact = function(array) {
var item, _i, _len, _results; var item, _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = array.length; _i < _len; _i++) { for (_i = 0, _len = array.length; _i < _len; _i++) {
item = array[_i]; item = array[_i];
@ -39,6 +42,7 @@
exports.count = function(string, substr) { exports.count = function(string, substr) {
var num, pos; var num, pos;
num = pos = 0; num = pos = 0;
if (!substr.length) { if (!substr.length) {
return 1 / 0; return 1 / 0;
@ -55,6 +59,7 @@
extend = exports.extend = function(object, properties) { extend = exports.extend = function(object, properties) {
var key, val; var key, val;
for (key in properties) { for (key in properties) {
val = properties[key]; val = properties[key];
object[key] = val; object[key] = val;
@ -64,6 +69,7 @@
exports.flatten = flatten = function(array) { exports.flatten = flatten = function(array) {
var element, flattened, _i, _len; var element, flattened, _i, _len;
flattened = []; flattened = [];
for (_i = 0, _len = array.length; _i < _len; _i++) { for (_i = 0, _len = array.length; _i < _len; _i++) {
element = array[_i]; element = array[_i];
@ -78,6 +84,7 @@
exports.del = function(obj, key) { exports.del = function(obj, key) {
var val; var val;
val = obj[key]; val = obj[key];
delete obj[key]; delete obj[key];
return val; return val;
@ -89,6 +96,7 @@
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) { exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
var e, _i, _len; var e, _i, _len;
for (_i = 0, _len = this.length; _i < _len; _i++) { for (_i = 0, _len = this.length; _i < _len; _i++) {
e = this[_i]; e = this[_i];
if (fn(e)) { if (fn(e)) {
@ -100,9 +108,11 @@
exports.invertLiterate = function(code) { exports.invertLiterate = function(code) {
var line, lines, maybe_code; var line, lines, maybe_code;
maybe_code = true; maybe_code = true;
lines = (function() { lines = (function() {
var _i, _len, _ref1, _results; var _i, _len, _ref1, _results;
_ref1 = code.split('\n'); _ref1 = code.split('\n');
_results = []; _results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
@ -144,6 +154,7 @@
exports.locationDataToString = function(obj) { exports.locationDataToString = function(obj) {
var locationData; var locationData;
if (("2" in obj) && ("first_line" in obj[2])) { if (("2" in obj) && ("first_line" in obj[2])) {
locationData = obj[2]; locationData = obj[2];
} else if ("first_line" in obj) { } else if ("first_line" in obj) {
@ -158,6 +169,7 @@
exports.baseFileName = function(file, stripExt, pathSep) { exports.baseFileName = function(file, stripExt, pathSep) {
var parts; var parts;
if (stripExt == null) { if (stripExt == null) {
stripExt = false; stripExt = false;
} }
@ -187,6 +199,7 @@
exports.throwSyntaxError = function(message, location) { exports.throwSyntaxError = function(message, location) {
var error, _ref1, _ref2; var error, _ref1, _ref2;
if ((_ref1 = location.last_line) == null) { if ((_ref1 = location.last_line) == null) {
location.last_line = location.first_line; location.last_line = location.first_line;
} }
@ -200,6 +213,7 @@
exports.prettyErrorMessage = function(error, fileName, code, useColors) { exports.prettyErrorMessage = function(error, fileName, code, useColors) {
var codeLine, colorize, end, first_column, first_line, last_column, last_line, marker, message, start, _ref1; var codeLine, colorize, end, first_column, first_line, last_column, last_line, marker, message, start, _ref1;
if (!error.location) { if (!error.location) {
return error.stack || ("" + error); return error.stack || ("" + error);
} }

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var key, val, _ref; var key, val, _ref;

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, starts, throwSyntaxError, _ref, _ref1, var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, starts, throwSyntaxError, _ref, _ref1,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
@ -8,11 +8,11 @@
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError; _ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
exports.Lexer = Lexer = (function() { exports.Lexer = Lexer = (function() {
function Lexer() {} function Lexer() {}
Lexer.prototype.tokenize = function(code, opts) { Lexer.prototype.tokenize = function(code, opts) {
var consumed, i, tag, _ref2; var consumed, i, tag, _ref2;
if (opts == null) { if (opts == null) {
opts = {}; opts = {};
} }
@ -59,6 +59,7 @@
Lexer.prototype.identifierToken = function() { Lexer.prototype.identifierToken = function() {
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4; var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
if (!(match = IDENTIFIER.exec(this.chunk))) { if (!(match = IDENTIFIER.exec(this.chunk))) {
return 0; return 0;
} }
@ -141,6 +142,7 @@
Lexer.prototype.numberToken = function() { Lexer.prototype.numberToken = function() {
var binaryLiteral, lexedLength, match, number, octalLiteral; var binaryLiteral, lexedLength, match, number, octalLiteral;
if (!(match = NUMBER.exec(this.chunk))) { if (!(match = NUMBER.exec(this.chunk))) {
return 0; return 0;
} }
@ -167,6 +169,7 @@
Lexer.prototype.stringToken = function() { Lexer.prototype.stringToken = function() {
var match, octalEsc, string; var match, octalEsc, string;
switch (this.chunk.charAt(0)) { switch (this.chunk.charAt(0)) {
case "'": case "'":
if (!(match = SIMPLESTR.exec(this.chunk))) { if (!(match = SIMPLESTR.exec(this.chunk))) {
@ -199,6 +202,7 @@
Lexer.prototype.heredocToken = function() { Lexer.prototype.heredocToken = function() {
var doc, heredoc, match, quote; var doc, heredoc, match, quote;
if (!(match = HEREDOC.exec(this.chunk))) { if (!(match = HEREDOC.exec(this.chunk))) {
return 0; return 0;
} }
@ -222,6 +226,7 @@
Lexer.prototype.commentToken = function() { Lexer.prototype.commentToken = function() {
var comment, here, match; var comment, here, match;
if (!(match = this.chunk.match(COMMENT))) { if (!(match = this.chunk.match(COMMENT))) {
return 0; return 0;
} }
@ -237,6 +242,7 @@
Lexer.prototype.jsToken = function() { Lexer.prototype.jsToken = function() {
var match, script; var match, script;
if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) { if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
return 0; return 0;
} }
@ -246,6 +252,7 @@
Lexer.prototype.regexToken = function() { Lexer.prototype.regexToken = function() {
var flags, length, match, prev, regex, _ref2, _ref3; var flags, length, match, prev, regex, _ref2, _ref3;
if (this.chunk.charAt(0) !== '/') { if (this.chunk.charAt(0) !== '/') {
return 0; return 0;
} }
@ -273,6 +280,7 @@
Lexer.prototype.heregexToken = function(match) { Lexer.prototype.heregexToken = function(match) {
var body, flags, flagsOffset, heregex, plusToken, prev, re, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4; var body, flags, flagsOffset, heregex, plusToken, prev, re, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
heregex = match[0], body = match[1], flags = match[2]; heregex = match[0], body = match[1], flags = match[2];
if (0 > body.indexOf('#{')) { if (0 > body.indexOf('#{')) {
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/'); re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
@ -326,6 +334,7 @@
Lexer.prototype.lineToken = function() { Lexer.prototype.lineToken = function() {
var diff, indent, match, noNewlines, size; var diff, indent, match, noNewlines, size;
if (!(match = MULTI_DENT.exec(this.chunk))) { if (!(match = MULTI_DENT.exec(this.chunk))) {
return 0; return 0;
} }
@ -362,6 +371,7 @@
Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) { Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
var dent, len; var dent, len;
while (moveOut > 0) { while (moveOut > 0) {
len = this.indents.length - 1; len = this.indents.length - 1;
if (this.indents[len] === void 0) { if (this.indents[len] === void 0) {
@ -394,6 +404,7 @@
Lexer.prototype.whitespaceToken = function() { Lexer.prototype.whitespaceToken = function() {
var match, nline, prev; var match, nline, prev;
if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) { if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
return 0; return 0;
} }
@ -427,6 +438,7 @@
Lexer.prototype.literalToken = function() { Lexer.prototype.literalToken = function() {
var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5; var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
if (match = OPERATOR.exec(this.chunk)) { if (match = OPERATOR.exec(this.chunk)) {
value = match[0]; value = match[0];
if (CODE.test(value)) { if (CODE.test(value)) {
@ -493,6 +505,7 @@
Lexer.prototype.sanitizeHeredoc = function(doc, options) { Lexer.prototype.sanitizeHeredoc = function(doc, options) {
var attempt, herecomment, indent, match, _ref2; var attempt, herecomment, indent, match, _ref2;
indent = options.indent, herecomment = options.herecomment; indent = options.indent, herecomment = options.herecomment;
if (herecomment) { if (herecomment) {
if (HEREDOC_ILLEGAL.test(doc)) { if (HEREDOC_ILLEGAL.test(doc)) {
@ -520,6 +533,7 @@
Lexer.prototype.tagParameters = function() { Lexer.prototype.tagParameters = function() {
var i, stack, tok, tokens; var i, stack, tok, tokens;
if (this.tag() !== ')') { if (this.tag() !== ')') {
return this; return this;
} }
@ -553,6 +567,7 @@
Lexer.prototype.balancedString = function(str, end) { Lexer.prototype.balancedString = function(str, end) {
var continueCount, i, letter, match, prev, stack, _i, _ref2; var continueCount, i, letter, match, prev, stack, _i, _ref2;
continueCount = 0; continueCount = 0;
stack = [end]; stack = [end];
for (i = _i = 1, _ref2 = str.length; 1 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 1 <= _ref2 ? ++_i : --_i) { for (i = _i = 1, _ref2 = str.length; 1 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 1 <= _ref2 ? ++_i : --_i) {
@ -588,6 +603,7 @@
Lexer.prototype.interpolateString = function(str, options) { Lexer.prototype.interpolateString = function(str, options) {
var column, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, rparen, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4; var column, expr, heredoc, i, inner, interpolated, len, letter, lexedLength, line, locationToken, nested, offsetInChunk, pi, plusToken, popped, regex, rparen, strOffset, tag, token, tokens, value, _i, _len, _ref2, _ref3, _ref4;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -686,6 +702,7 @@
Lexer.prototype.pair = function(tag) { Lexer.prototype.pair = function(tag) {
var size, wanted; var size, wanted;
if (tag !== (wanted = last(this.ends))) { if (tag !== (wanted = last(this.ends))) {
if ('OUTDENT' !== wanted) { if ('OUTDENT' !== wanted) {
this.error("unmatched " + tag); this.error("unmatched " + tag);
@ -699,6 +716,7 @@
Lexer.prototype.getLineAndColumnFromChunk = function(offset) { Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
var column, lineCount, lines, string; var column, lineCount, lines, string;
if (offset === 0) { if (offset === 0) {
return [this.chunkLine, this.chunkColumn]; return [this.chunkLine, this.chunkColumn];
} }
@ -720,6 +738,7 @@
Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) { Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
var lastCharacter, locationData, token, _ref2, _ref3; var lastCharacter, locationData, token, _ref2, _ref3;
if (offsetInChunk == null) { if (offsetInChunk == null) {
offsetInChunk = 0; offsetInChunk = 0;
} }
@ -736,6 +755,7 @@
Lexer.prototype.token = function(tag, value, offsetInChunk, length) { Lexer.prototype.token = function(tag, value, offsetInChunk, length) {
var token; var token;
token = this.makeToken(tag, value, offsetInChunk, length); token = this.makeToken(tag, value, offsetInChunk, length);
this.tokens.push(token); this.tokens.push(token);
return token; return token;
@ -743,16 +763,19 @@
Lexer.prototype.tag = function(index, tag) { Lexer.prototype.tag = function(index, tag) {
var tok; var tok;
return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]); return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
}; };
Lexer.prototype.value = function(index, val) { Lexer.prototype.value = function(index, val) {
var tok; var tok;
return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]); return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
}; };
Lexer.prototype.unfinished = function() { Lexer.prototype.unfinished = function() {
var _ref2; var _ref2;
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS'); return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
}; };
@ -804,6 +827,7 @@
COFFEE_ALIASES = (function() { COFFEE_ALIASES = (function() {
var _results; var _results;
_results = []; _results = [];
for (key in COFFEE_ALIAS_MAP) { for (key in COFFEE_ALIAS_MAP) {
_results.push(key); _results.push(key);

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, CodeFragment, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, last, locationDataToString, merge, multident, some, starts, throwSyntaxError, unfoldSoak, utility, _ref, _ref1, _ref2, _ref3, var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, CodeFragment, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, last, locationDataToString, merge, multident, some, starts, throwSyntaxError, unfoldSoak, utility, _ref, _ref1, _ref2, _ref3,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
@ -36,9 +36,9 @@
}; };
exports.CodeFragment = CodeFragment = (function() { exports.CodeFragment = CodeFragment = (function() {
function CodeFragment(parent, code) { function CodeFragment(parent, code) {
var _ref2; var _ref2;
this.code = "" + code; this.code = "" + code;
this.locationData = parent != null ? parent.locationData : void 0; this.locationData = parent != null ? parent.locationData : void 0;
this.type = (parent != null ? (_ref2 = parent.constructor) != null ? _ref2.name : void 0 : void 0) || 'unknown'; this.type = (parent != null ? (_ref2 = parent.constructor) != null ? _ref2.name : void 0 : void 0) || 'unknown';
@ -54,8 +54,10 @@
fragmentsToText = function(fragments) { fragmentsToText = function(fragments) {
var fragment; var fragment;
return ((function() { return ((function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = fragments.length; _i < _len; _i++) { for (_i = 0, _len = fragments.length; _i < _len; _i++) {
fragment = fragments[_i]; fragment = fragments[_i];
@ -66,7 +68,6 @@
}; };
exports.Base = Base = (function() { exports.Base = Base = (function() {
function Base() {} function Base() {}
Base.prototype.compile = function(o, lvl) { Base.prototype.compile = function(o, lvl) {
@ -75,6 +76,7 @@
Base.prototype.compileToFragments = function(o, lvl) { Base.prototype.compileToFragments = function(o, lvl) {
var node; var node;
o = extend({}, o); o = extend({}, o);
if (lvl) { if (lvl) {
o.level = lvl; o.level = lvl;
@ -90,6 +92,7 @@
Base.prototype.compileClosure = function(o) { Base.prototype.compileClosure = function(o) {
var jumpNode; var jumpNode;
if (jumpNode = this.jumps()) { if (jumpNode = this.jumps()) {
jumpNode.error('cannot use a pure statement in an expression'); jumpNode.error('cannot use a pure statement in an expression');
} }
@ -99,6 +102,7 @@
Base.prototype.cache = function(o, level, reused) { Base.prototype.cache = function(o, level, reused) {
var ref, sub; var ref, sub;
if (!this.isComplex()) { if (!this.isComplex()) {
ref = level ? this.compileToFragments(o, level) : this; ref = level ? this.compileToFragments(o, level) : this;
return [ref, ref]; return [ref, ref];
@ -119,6 +123,7 @@
Base.prototype.makeReturn = function(res) { Base.prototype.makeReturn = function(res) {
var me; var me;
me = this.unwrapAll(); me = this.unwrapAll();
if (res) { if (res) {
return new Call(new Literal("" + res + ".push"), [me]); return new Call(new Literal("" + res + ".push"), [me]);
@ -129,6 +134,7 @@
Base.prototype.contains = function(pred) { Base.prototype.contains = function(pred) {
var node; var node;
node = void 0; node = void 0;
this.traverseChildren(false, function(n) { this.traverseChildren(false, function(n) {
if (pred(n)) { if (pred(n)) {
@ -141,6 +147,7 @@
Base.prototype.lastNonComment = function(list) { Base.prototype.lastNonComment = function(list) {
var i; var i;
i = list.length; i = list.length;
while (i--) { while (i--) {
if (!(list[i] instanceof Comment)) { if (!(list[i] instanceof Comment)) {
@ -152,6 +159,7 @@
Base.prototype.toString = function(idt, name) { Base.prototype.toString = function(idt, name) {
var tree; var tree;
if (idt == null) { if (idt == null) {
idt = ''; idt = '';
} }
@ -170,6 +178,7 @@
Base.prototype.eachChild = function(func) { Base.prototype.eachChild = function(func) {
var attr, child, _i, _j, _len, _len1, _ref2, _ref3; var attr, child, _i, _j, _len, _len1, _ref2, _ref3;
if (!this.children) { if (!this.children) {
return this; return this;
} }
@ -204,6 +213,7 @@
Base.prototype.unwrapAll = function() { Base.prototype.unwrapAll = function() {
var node; var node;
node = this; node = this;
while (node !== (node = node.unwrap())) { while (node !== (node = node.unwrap())) {
continue; continue;
@ -250,6 +260,7 @@
Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) { Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) {
var answer, fragments, i, _i, _len; var answer, fragments, i, _i, _len;
answer = []; answer = [];
for (i = _i = 0, _len = fragmentsList.length; _i < _len; i = ++_i) { for (i = _i = 0, _len = fragmentsList.length; _i < _len; i = ++_i) {
fragments = fragmentsList[i]; fragments = fragmentsList[i];
@ -266,7 +277,6 @@
})(); })();
exports.Block = Block = (function(_super) { exports.Block = Block = (function(_super) {
__extends(Block, _super); __extends(Block, _super);
function Block(nodes) { function Block(nodes) {
@ -303,6 +313,7 @@
Block.prototype.isStatement = function(o) { Block.prototype.isStatement = function(o) {
var exp, _i, _len, _ref2; var exp, _i, _len, _ref2;
_ref2 = this.expressions; _ref2 = this.expressions;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
exp = _ref2[_i]; exp = _ref2[_i];
@ -315,6 +326,7 @@
Block.prototype.jumps = function(o) { Block.prototype.jumps = function(o) {
var exp, _i, _len, _ref2; var exp, _i, _len, _ref2;
_ref2 = this.expressions; _ref2 = this.expressions;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
exp = _ref2[_i]; exp = _ref2[_i];
@ -326,6 +338,7 @@
Block.prototype.makeReturn = function(res) { Block.prototype.makeReturn = function(res) {
var expr, len; var expr, len;
len = this.expressions.length; len = this.expressions.length;
while (len--) { while (len--) {
expr = this.expressions[len]; expr = this.expressions[len];
@ -353,6 +366,7 @@
Block.prototype.compileNode = function(o) { Block.prototype.compileNode = function(o) {
var answer, compiledNodes, fragments, index, node, top, _i, _len, _ref2; var answer, compiledNodes, fragments, index, node, top, _i, _len, _ref2;
this.tab = o.indent; this.tab = o.indent;
top = o.level === LEVEL_TOP; top = o.level === LEVEL_TOP;
compiledNodes = []; compiledNodes = [];
@ -377,7 +391,7 @@
} }
if (top) { if (top) {
if (this.spaced) { if (this.spaced) {
return [].concat(this.makeCode("\n"), this.joinFragmentArrays(compiledNodes, '\n\n'), this.makeCode("\n")); return [].concat(this.joinFragmentArrays(compiledNodes, '\n\n'), this.makeCode("\n"));
} else { } else {
return this.joinFragmentArrays(compiledNodes, '\n'); return this.joinFragmentArrays(compiledNodes, '\n');
} }
@ -396,6 +410,7 @@
Block.prototype.compileRoot = function(o) { Block.prototype.compileRoot = function(o) {
var exp, fragments, i, name, prelude, preludeExps, rest, _i, _len, _ref2; var exp, fragments, i, name, prelude, preludeExps, rest, _i, _len, _ref2;
o.indent = o.bare ? '' : TAB; o.indent = o.bare ? '' : TAB;
o.level = LEVEL_TOP; o.level = LEVEL_TOP;
this.spaced = true; this.spaced = true;
@ -409,6 +424,7 @@
if (!o.bare) { if (!o.bare) {
preludeExps = (function() { preludeExps = (function() {
var _j, _len1, _ref3, _results; var _j, _len1, _ref3, _results;
_ref3 = this.expressions; _ref3 = this.expressions;
_results = []; _results = [];
for (i = _j = 0, _len1 = _ref3.length; _j < _len1; i = ++_j) { for (i = _j = 0, _len1 = _ref3.length; _j < _len1; i = ++_j) {
@ -439,6 +455,7 @@
Block.prototype.compileWithDeclarations = function(o) { Block.prototype.compileWithDeclarations = function(o) {
var assigns, declars, exp, fragments, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4; var assigns, declars, exp, fragments, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
fragments = []; fragments = [];
post = []; post = [];
_ref2 = this.expressions; _ref2 = this.expressions;
@ -477,7 +494,7 @@
} }
fragments.push(this.makeCode(scope.assignedVariables().join(",\n" + (this.tab + TAB)))); fragments.push(this.makeCode(scope.assignedVariables().join(",\n" + (this.tab + TAB))));
} }
fragments.push(this.makeCode(';\n')); fragments.push(this.makeCode(';\n\n'));
} }
} }
return fragments.concat(post); return fragments.concat(post);
@ -495,7 +512,6 @@
})(Base); })(Base);
exports.Literal = Literal = (function(_super) { exports.Literal = Literal = (function(_super) {
__extends(Literal, _super); __extends(Literal, _super);
function Literal(value) { function Literal(value) {
@ -516,6 +532,7 @@
Literal.prototype.isStatement = function() { Literal.prototype.isStatement = function() {
var _ref2; var _ref2;
return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger'; return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
}; };
@ -536,6 +553,7 @@
Literal.prototype.compileNode = function(o) { Literal.prototype.compileNode = function(o) {
var answer, code, _ref2; var answer, code, _ref2;
code = this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value; code = this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value;
answer = this.isStatement() ? "" + this.tab + code + ";" : code; answer = this.isStatement() ? "" + this.tab + code + ";" : code;
return [this.makeCode(answer)]; return [this.makeCode(answer)];
@ -550,7 +568,6 @@
})(Base); })(Base);
exports.Undefined = (function(_super) { exports.Undefined = (function(_super) {
__extends(Undefined, _super); __extends(Undefined, _super);
function Undefined() { function Undefined() {
@ -571,7 +588,6 @@
})(Base); })(Base);
exports.Null = (function(_super) { exports.Null = (function(_super) {
__extends(Null, _super); __extends(Null, _super);
function Null() { function Null() {
@ -592,7 +608,6 @@
})(Base); })(Base);
exports.Bool = (function(_super) { exports.Bool = (function(_super) {
__extends(Bool, _super); __extends(Bool, _super);
Bool.prototype.isAssignable = NO; Bool.prototype.isAssignable = NO;
@ -612,7 +627,6 @@
})(Base); })(Base);
exports.Return = Return = (function(_super) { exports.Return = Return = (function(_super) {
__extends(Return, _super); __extends(Return, _super);
function Return(expr) { function Return(expr) {
@ -631,6 +645,7 @@
Return.prototype.compileToFragments = function(o, level) { Return.prototype.compileToFragments = function(o, level) {
var expr, _ref4; var expr, _ref4;
expr = (_ref4 = this.expression) != null ? _ref4.makeReturn() : void 0; expr = (_ref4 = this.expression) != null ? _ref4.makeReturn() : void 0;
if (expr && !(expr instanceof Return)) { if (expr && !(expr instanceof Return)) {
return expr.compileToFragments(o, level); return expr.compileToFragments(o, level);
@ -641,6 +656,7 @@
Return.prototype.compileNode = function(o) { Return.prototype.compileNode = function(o) {
var answer; var answer;
answer = []; answer = [];
answer.push(this.makeCode(this.tab + ("return" + [this.expression ? " " : void 0]))); answer.push(this.makeCode(this.tab + ("return" + [this.expression ? " " : void 0])));
if (this.expression) { if (this.expression) {
@ -655,7 +671,6 @@
})(Base); })(Base);
exports.Value = Value = (function(_super) { exports.Value = Value = (function(_super) {
__extends(Value, _super); __extends(Value, _super);
function Value(base, props, tag) { function Value(base, props, tag) {
@ -703,6 +718,7 @@
Value.prototype.isAtomic = function() { Value.prototype.isAtomic = function() {
var node, _i, _len, _ref4; var node, _i, _len, _ref4;
_ref4 = this.properties.concat(this.base); _ref4 = this.properties.concat(this.base);
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
node = _ref4[_i]; node = _ref4[_i];
@ -746,6 +762,7 @@
Value.prototype.cacheReference = function(o) { Value.prototype.cacheReference = function(o) {
var base, bref, name, nref; var base, bref, name, nref;
name = last(this.properties); name = last(this.properties);
if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) { if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
return [this, this]; return [this, this];
@ -768,6 +785,7 @@
Value.prototype.compileNode = function(o) { Value.prototype.compileNode = function(o) {
var fragments, prop, props, _i, _len; var fragments, prop, props, _i, _len;
this.base.front = this.front; this.base.front = this.front;
props = this.properties; props = this.properties;
fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null)); fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null));
@ -784,8 +802,10 @@
Value.prototype.unfoldSoak = function(o) { Value.prototype.unfoldSoak = function(o) {
var _ref4, var _ref4,
_this = this; _this = this;
return (_ref4 = this.unfoldedSoak) != null ? _ref4 : this.unfoldedSoak = (function() { return (_ref4 = this.unfoldedSoak) != null ? _ref4 : this.unfoldedSoak = (function() {
var fst, i, ifn, prop, ref, snd, _i, _len, _ref5, _ref6; var fst, i, ifn, prop, ref, snd, _i, _len, _ref5, _ref6;
if (ifn = _this.base.unfoldSoak(o)) { if (ifn = _this.base.unfoldSoak(o)) {
(_ref5 = ifn.body.properties).push.apply(_ref5, _this.properties); (_ref5 = ifn.body.properties).push.apply(_ref5, _this.properties);
return ifn; return ifn;
@ -817,7 +837,6 @@
})(Base); })(Base);
exports.Comment = Comment = (function(_super) { exports.Comment = Comment = (function(_super) {
__extends(Comment, _super); __extends(Comment, _super);
function Comment(comment) { function Comment(comment) {
@ -830,6 +849,7 @@
Comment.prototype.compileNode = function(o, level) { Comment.prototype.compileNode = function(o, level) {
var code; var code;
code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n"); code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n");
if ((level || o.level) === LEVEL_TOP) { if ((level || o.level) === LEVEL_TOP) {
code = o.indent + code; code = o.indent + code;
@ -842,7 +862,6 @@
})(Base); })(Base);
exports.Call = Call = (function(_super) { exports.Call = Call = (function(_super) {
__extends(Call, _super); __extends(Call, _super);
function Call(variable, args, soak) { function Call(variable, args, soak) {
@ -857,6 +876,7 @@
Call.prototype.newInstance = function() { Call.prototype.newInstance = function() {
var base, _ref4; var base, _ref4;
base = ((_ref4 = this.variable) != null ? _ref4.base : void 0) || this.variable; base = ((_ref4 = this.variable) != null ? _ref4.base : void 0) || this.variable;
if (base instanceof Call && !base.isNew) { if (base instanceof Call && !base.isNew) {
base.newInstance(); base.newInstance();
@ -868,6 +888,7 @@
Call.prototype.superReference = function(o) { Call.prototype.superReference = function(o) {
var accesses, method; var accesses, method;
method = o.scope.namedMethod(); method = o.scope.namedMethod();
if (method != null ? method.klass : void 0) { if (method != null ? method.klass : void 0) {
accesses = [new Access(new Literal('__super__'))]; accesses = [new Access(new Literal('__super__'))];
@ -885,12 +906,14 @@
Call.prototype.superThis = function(o) { Call.prototype.superThis = function(o) {
var method; var method;
method = o.scope.method; method = o.scope.method;
return (method && !method.klass && method.context) || "this"; return (method && !method.klass && method.context) || "this";
}; };
Call.prototype.unfoldSoak = function(o) { Call.prototype.unfoldSoak = function(o) {
var call, ifn, left, list, rite, _i, _len, _ref4, _ref5; var call, ifn, left, list, rite, _i, _len, _ref4, _ref5;
if (this.soak) { if (this.soak) {
if (this.variable) { if (this.variable) {
if (ifn = unfoldSoak(o, this, 'variable')) { if (ifn = unfoldSoak(o, this, 'variable')) {
@ -941,6 +964,7 @@
Call.prototype.compileNode = function(o) { Call.prototype.compileNode = function(o) {
var arg, argIndex, compiledArgs, compiledArray, fragments, preface, _i, _len, _ref4, _ref5; var arg, argIndex, compiledArgs, compiledArray, fragments, preface, _i, _len, _ref4, _ref5;
if ((_ref4 = this.variable) != null) { if ((_ref4 = this.variable) != null) {
_ref4.front = this.front; _ref4.front = this.front;
} }
@ -978,6 +1002,7 @@
Call.prototype.compileSplat = function(o, splatArgs) { Call.prototype.compileSplat = function(o, splatArgs) {
var answer, base, fun, idt, name, ref; var answer, base, fun, idt, name, ref;
if (this.isSuper) { if (this.isSuper) {
return [].concat(this.makeCode("" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")")); return [].concat(this.makeCode("" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")"));
} }
@ -1011,7 +1036,6 @@
})(Base); })(Base);
exports.Extends = Extends = (function(_super) { exports.Extends = Extends = (function(_super) {
__extends(Extends, _super); __extends(Extends, _super);
function Extends(child, parent) { function Extends(child, parent) {
@ -1030,7 +1054,6 @@
})(Base); })(Base);
exports.Access = Access = (function(_super) { exports.Access = Access = (function(_super) {
__extends(Access, _super); __extends(Access, _super);
function Access(name, tag) { function Access(name, tag) {
@ -1043,6 +1066,7 @@
Access.prototype.compileToFragments = function(o) { Access.prototype.compileToFragments = function(o) {
var name; var name;
name = this.name.compileToFragments(o); name = this.name.compileToFragments(o);
if (IDENTIFIER.test(fragmentsToText(name))) { if (IDENTIFIER.test(fragmentsToText(name))) {
name.unshift(this.makeCode(".")); name.unshift(this.makeCode("."));
@ -1060,7 +1084,6 @@
})(Base); })(Base);
exports.Index = Index = (function(_super) { exports.Index = Index = (function(_super) {
__extends(Index, _super); __extends(Index, _super);
function Index(index) { function Index(index) {
@ -1082,7 +1105,6 @@
})(Base); })(Base);
exports.Range = Range = (function(_super) { exports.Range = Range = (function(_super) {
__extends(Range, _super); __extends(Range, _super);
Range.prototype.children = ['from', 'to']; Range.prototype.children = ['from', 'to'];
@ -1096,6 +1118,7 @@
Range.prototype.compileVariables = function(o) { Range.prototype.compileVariables = function(o) {
var step, _ref4, _ref5, _ref6, _ref7; var step, _ref4, _ref5, _ref6, _ref7;
o = merge(o, { o = merge(o, {
top: true top: true
}); });
@ -1112,6 +1135,7 @@
Range.prototype.compileNode = function(o) { Range.prototype.compileNode = function(o) {
var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref4, _ref5; var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref4, _ref5;
if (!this.fromVar) { if (!this.fromVar) {
this.compileVariables(o); this.compileVariables(o);
} }
@ -1143,6 +1167,7 @@
Range.prototype.compileArray = function(o) { Range.prototype.compileArray = function(o) {
var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref4, _ref5, _results; var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref4, _ref5, _results;
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) { if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
range = (function() { range = (function() {
_results = []; _results = [];
@ -1183,7 +1208,6 @@
})(Base); })(Base);
exports.Slice = Slice = (function(_super) { exports.Slice = Slice = (function(_super) {
__extends(Slice, _super); __extends(Slice, _super);
Slice.prototype.children = ['range']; Slice.prototype.children = ['range'];
@ -1195,6 +1219,7 @@
Slice.prototype.compileNode = function(o) { Slice.prototype.compileNode = function(o) {
var compiled, compiledText, from, fromCompiled, to, toStr, _ref4; var compiled, compiledText, from, fromCompiled, to, toStr, _ref4;
_ref4 = this.range, to = _ref4.to, from = _ref4.from; _ref4 = this.range, to = _ref4.to, from = _ref4.from;
fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')]; fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')];
if (to) { if (to) {
@ -1212,7 +1237,6 @@
})(Base); })(Base);
exports.Obj = Obj = (function(_super) { exports.Obj = Obj = (function(_super) {
__extends(Obj, _super); __extends(Obj, _super);
function Obj(props, generated) { function Obj(props, generated) {
@ -1224,6 +1248,7 @@
Obj.prototype.compileNode = function(o) { Obj.prototype.compileNode = function(o) {
var answer, i, idt, indent, join, lastNoncom, node, prop, props, _i, _j, _len, _len1; var answer, i, idt, indent, join, lastNoncom, node, prop, props, _i, _j, _len, _len1;
props = this.properties; props = this.properties;
if (!props.length) { if (!props.length) {
return [this.makeCode(this.front ? '({})' : '{}')]; return [this.makeCode(this.front ? '({})' : '{}')];
@ -1274,6 +1299,7 @@
Obj.prototype.assigns = function(name) { Obj.prototype.assigns = function(name) {
var prop, _i, _len, _ref4; var prop, _i, _len, _ref4;
_ref4 = this.properties; _ref4 = this.properties;
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
prop = _ref4[_i]; prop = _ref4[_i];
@ -1289,7 +1315,6 @@
})(Base); })(Base);
exports.Arr = Arr = (function(_super) { exports.Arr = Arr = (function(_super) {
__extends(Arr, _super); __extends(Arr, _super);
function Arr(objs) { function Arr(objs) {
@ -1300,6 +1325,7 @@
Arr.prototype.compileNode = function(o) { Arr.prototype.compileNode = function(o) {
var answer, compiledObjs, fragments, index, obj, _i, _len; var answer, compiledObjs, fragments, index, obj, _i, _len;
if (!this.objects.length) { if (!this.objects.length) {
return [this.makeCode('[]')]; return [this.makeCode('[]')];
} }
@ -1311,6 +1337,7 @@
answer = []; answer = [];
compiledObjs = (function() { compiledObjs = (function() {
var _i, _len, _ref4, _results; var _i, _len, _ref4, _results;
_ref4 = this.objects; _ref4 = this.objects;
_results = []; _results = [];
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
@ -1338,6 +1365,7 @@
Arr.prototype.assigns = function(name) { Arr.prototype.assigns = function(name) {
var obj, _i, _len, _ref4; var obj, _i, _len, _ref4;
_ref4 = this.objects; _ref4 = this.objects;
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
obj = _ref4[_i]; obj = _ref4[_i];
@ -1353,7 +1381,6 @@
})(Base); })(Base);
exports.Class = Class = (function(_super) { exports.Class = Class = (function(_super) {
__extends(Class, _super); __extends(Class, _super);
function Class(variable, parent, body) { function Class(variable, parent, body) {
@ -1368,6 +1395,7 @@
Class.prototype.determineName = function() { Class.prototype.determineName = function() {
var decl, tail; var decl, tail;
if (!this.variable) { if (!this.variable) {
return null; return null;
} }
@ -1396,6 +1424,7 @@
Class.prototype.addBoundFunctions = function(o) { Class.prototype.addBoundFunctions = function(o) {
var bvar, lhs, _i, _len, _ref4; var bvar, lhs, _i, _len, _ref4;
_ref4 = this.boundFuncs; _ref4 = this.boundFuncs;
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
bvar = _ref4[_i]; bvar = _ref4[_i];
@ -1406,9 +1435,11 @@
Class.prototype.addProperties = function(node, name, o) { Class.prototype.addProperties = function(node, name, o) {
var assign, base, exprs, func, props; var assign, base, exprs, func, props;
props = node.base.properties.slice(0); props = node.base.properties.slice(0);
exprs = (function() { exprs = (function() {
var _results; var _results;
_results = []; _results = [];
while (assign = props.shift()) { while (assign = props.shift()) {
if (assign instanceof Assign) { if (assign instanceof Assign) {
@ -1452,8 +1483,10 @@
Class.prototype.walkBody = function(name, o) { Class.prototype.walkBody = function(name, o) {
var _this = this; var _this = this;
return this.traverseChildren(false, function(child) { return this.traverseChildren(false, function(child) {
var cont, exps, i, node, _i, _len, _ref4; var cont, exps, i, node, _i, _len, _ref4;
cont = true; cont = true;
if (child instanceof Class) { if (child instanceof Class) {
return false; return false;
@ -1475,6 +1508,7 @@
Class.prototype.hoistDirectivePrologue = function() { Class.prototype.hoistDirectivePrologue = function() {
var expressions, index, node; var expressions, index, node;
index = 0; index = 0;
expressions = this.body.expressions; expressions = this.body.expressions;
while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) { while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
@ -1485,6 +1519,7 @@
Class.prototype.ensureConstructor = function(name, o) { Class.prototype.ensureConstructor = function(name, o) {
var missing, ref, superCall; var missing, ref, superCall;
missing = !this.ctor; missing = !this.ctor;
this.ctor || (this.ctor = new Code); this.ctor || (this.ctor = new Code);
this.ctor.ctor = this.ctor.name = name; this.ctor.ctor = this.ctor.name = name;
@ -1514,6 +1549,7 @@
Class.prototype.compileNode = function(o) { Class.prototype.compileNode = function(o) {
var call, decl, klass, lname, name, params, _ref4; var call, decl, klass, lname, name, params, _ref4;
decl = this.determineName(); decl = this.determineName();
name = decl || '_Class'; name = decl || '_Class';
if (name.reserved) { if (name.reserved) {
@ -1550,11 +1586,11 @@
})(Base); })(Base);
exports.Assign = Assign = (function(_super) { exports.Assign = Assign = (function(_super) {
__extends(Assign, _super); __extends(Assign, _super);
function Assign(variable, value, context, options) { function Assign(variable, value, context, options) {
var forbidden, name, _ref4; var forbidden, name, _ref4;
this.variable = variable; this.variable = variable;
this.value = value; this.value = value;
this.context = context; this.context = context;
@ -1582,6 +1618,7 @@
Assign.prototype.compileNode = function(o) { Assign.prototype.compileNode = function(o) {
var answer, compiledName, isValue, match, name, val, varBase, _ref4, _ref5, _ref6, _ref7; var answer, compiledName, isValue, match, name, val, varBase, _ref4, _ref5, _ref6, _ref7;
if (isValue = this.variable instanceof Value) { if (isValue = this.variable instanceof Value) {
if (this.variable.isArray() || this.variable.isObject()) { if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o); return this.compilePatternMatch(o);
@ -1628,6 +1665,7 @@
Assign.prototype.compilePatternMatch = function(o) { Assign.prototype.compilePatternMatch = function(o) {
var acc, assigns, code, fragments, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, vvarText, _i, _len, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; var acc, assigns, code, fragments, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, vvarText, _i, _len, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
top = o.level === LEVEL_TOP; top = o.level === LEVEL_TOP;
value = this.value; value = this.value;
objects = this.variable.base.objects; objects = this.variable.base.objects;
@ -1725,6 +1763,7 @@
Assign.prototype.compileConditional = function(o) { Assign.prototype.compileConditional = function(o) {
var left, right, _ref4; var left, right, _ref4;
_ref4 = this.variable.cacheReference(o), left = _ref4[0], right = _ref4[1]; _ref4 = this.variable.cacheReference(o), left = _ref4[0], right = _ref4[1];
if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) { if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {
this.variable.error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been declared before"); this.variable.error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been declared before");
@ -1737,6 +1776,7 @@
Assign.prototype.compileSplice = function(o) { Assign.prototype.compileSplice = function(o) {
var answer, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref4, _ref5, _ref6; var answer, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref4, _ref5, _ref6;
_ref4 = this.variable.properties.pop().range, from = _ref4.from, to = _ref4.to, exclusive = _ref4.exclusive; _ref4 = this.variable.properties.pop().range, from = _ref4.from, to = _ref4.to, exclusive = _ref4.exclusive;
name = this.variable.compile(o); name = this.variable.compile(o);
if (from) { if (from) {
@ -1773,7 +1813,6 @@
})(Base); })(Base);
exports.Code = Code = (function(_super) { exports.Code = Code = (function(_super) {
__extends(Code, _super); __extends(Code, _super);
function Code(params, body, tag) { function Code(params, body, tag) {
@ -1795,6 +1834,7 @@
Code.prototype.compileNode = function(o) { Code.prototype.compileNode = function(o) {
var answer, code, exprs, i, idt, lit, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref4, _ref5, _ref6, _ref7, _ref8; var answer, code, exprs, i, idt, lit, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref4, _ref5, _ref6, _ref7, _ref8;
o.scope = new Scope(o.scope, this.body, this); o.scope = new Scope(o.scope, this.body, this);
o.scope.shared = del(o, 'sharedScope'); o.scope.shared = del(o, 'sharedScope');
o.indent += TAB; o.indent += TAB;
@ -1825,6 +1865,7 @@
} }
splats = new Assign(new Value(new Arr((function() { splats = new Assign(new Value(new Arr((function() {
var _k, _len2, _ref6, _results; var _k, _len2, _ref6, _results;
_ref6 = this.params; _ref6 = this.params;
_results = []; _results = [];
for (_k = 0, _len2 = _ref6.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref6.length; _k < _len2; _k++) {
@ -1918,6 +1959,7 @@
Code.prototype.eachParamName = function(iterator) { Code.prototype.eachParamName = function(iterator) {
var param, _i, _len, _ref4, _results; var param, _i, _len, _ref4, _results;
_ref4 = this.params; _ref4 = this.params;
_results = []; _results = [];
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
@ -1938,11 +1980,11 @@
})(Base); })(Base);
exports.Param = Param = (function(_super) { exports.Param = Param = (function(_super) {
__extends(Param, _super); __extends(Param, _super);
function Param(name, value, splat) { function Param(name, value, splat) {
var _ref4; var _ref4;
this.name = name; this.name = name;
this.value = value; this.value = value;
this.splat = splat; this.splat = splat;
@ -1959,6 +2001,7 @@
Param.prototype.asReference = function(o) { Param.prototype.asReference = function(o) {
var node; var node;
if (this.reference) { if (this.reference) {
return this.reference; return this.reference;
} }
@ -1984,11 +2027,13 @@
Param.prototype.eachName = function(iterator, name) { Param.prototype.eachName = function(iterator, name) {
var atParam, node, obj, _i, _len, _ref4; var atParam, node, obj, _i, _len, _ref4;
if (name == null) { if (name == null) {
name = this.name; name = this.name;
} }
atParam = function(obj) { atParam = function(obj) {
var node; var node;
node = obj.properties[0].name; node = obj.properties[0].name;
if (!node.value.reserved) { if (!node.value.reserved) {
return iterator(node.value, node); return iterator(node.value, node);
@ -2027,7 +2072,6 @@
})(Base); })(Base);
exports.Splat = Splat = (function(_super) { exports.Splat = Splat = (function(_super) {
__extends(Splat, _super); __extends(Splat, _super);
Splat.prototype.children = ['name']; Splat.prototype.children = ['name'];
@ -2052,6 +2096,7 @@
Splat.compileSplattedArray = function(o, list, apply) { Splat.compileSplattedArray = function(o, list, apply) {
var args, base, compiledNode, concatPart, fragments, i, index, node, _i, _len; var args, base, compiledNode, concatPart, fragments, i, index, node, _i, _len;
index = -1; index = -1;
while ((node = list[++index]) && !(node instanceof Splat)) { while ((node = list[++index]) && !(node instanceof Splat)) {
continue; continue;
@ -2080,6 +2125,7 @@
} }
base = (function() { base = (function() {
var _j, _len1, _ref4, _results; var _j, _len1, _ref4, _results;
_ref4 = list.slice(0, index); _ref4 = list.slice(0, index);
_results = []; _results = [];
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
@ -2098,7 +2144,6 @@
})(Base); })(Base);
exports.While = While = (function(_super) { exports.While = While = (function(_super) {
__extends(While, _super); __extends(While, _super);
function While(condition, options) { function While(condition, options) {
@ -2128,6 +2173,7 @@
While.prototype.jumps = function() { While.prototype.jumps = function() {
var expressions, node, _i, _len; var expressions, node, _i, _len;
expressions = this.body.expressions; expressions = this.body.expressions;
if (!expressions.length) { if (!expressions.length) {
return false; return false;
@ -2145,6 +2191,7 @@
While.prototype.compileNode = function(o) { While.prototype.compileNode = function(o) {
var answer, body, rvar, set; var answer, body, rvar, set;
o.indent += TAB; o.indent += TAB;
set = ''; set = '';
body = this.body; body = this.body;
@ -2225,16 +2272,19 @@
Op.prototype.isComplex = function() { Op.prototype.isComplex = function() {
var _ref4; var _ref4;
return !(this.isUnary() && ((_ref4 = this.operator) === '+' || _ref4 === '-')) || this.first.isComplex(); return !(this.isUnary() && ((_ref4 = this.operator) === '+' || _ref4 === '-')) || this.first.isComplex();
}; };
Op.prototype.isChainable = function() { Op.prototype.isChainable = function() {
var _ref4; var _ref4;
return (_ref4 = this.operator) === '<' || _ref4 === '>' || _ref4 === '>=' || _ref4 === '<=' || _ref4 === '===' || _ref4 === '!=='; return (_ref4 = this.operator) === '<' || _ref4 === '>' || _ref4 === '>=' || _ref4 === '<=' || _ref4 === '===' || _ref4 === '!==';
}; };
Op.prototype.invert = function() { Op.prototype.invert = function() {
var allInvertable, curr, fst, op, _ref4; var allInvertable, curr, fst, op, _ref4;
if (this.isChainable() && this.first.isChainable()) { if (this.isChainable() && this.first.isChainable()) {
allInvertable = true; allInvertable = true;
curr = this; curr = this;
@ -2269,11 +2319,13 @@
Op.prototype.unfoldSoak = function(o) { Op.prototype.unfoldSoak = function(o) {
var _ref4; var _ref4;
return ((_ref4 = this.operator) === '++' || _ref4 === '--' || _ref4 === 'delete') && unfoldSoak(o, this, 'first'); return ((_ref4 = this.operator) === '++' || _ref4 === '--' || _ref4 === 'delete') && unfoldSoak(o, this, 'first');
}; };
Op.prototype.generateDo = function(exp) { Op.prototype.generateDo = function(exp) {
var call, func, param, passedParams, ref, _i, _len, _ref4; var call, func, param, passedParams, ref, _i, _len, _ref4;
passedParams = []; passedParams = [];
func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp; func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
_ref4 = func.params || []; _ref4 = func.params || [];
@ -2293,6 +2345,7 @@
Op.prototype.compileNode = function(o) { Op.prototype.compileNode = function(o) {
var answer, isChain, _ref4, _ref5; var answer, isChain, _ref4, _ref5;
isChain = this.isChainable() && this.first.isChainable(); isChain = this.isChainable() && this.first.isChainable();
if (!isChain) { if (!isChain) {
this.first.front = this.front; this.first.front = this.front;
@ -2322,6 +2375,7 @@
Op.prototype.compileChain = function(o) { Op.prototype.compileChain = function(o) {
var fragments, fst, shared, _ref4; var fragments, fst, shared, _ref4;
_ref4 = this.first.second.cache(o), this.first.second = _ref4[0], shared = _ref4[1]; _ref4 = this.first.second.cache(o), this.first.second = _ref4[0], shared = _ref4[1];
fst = this.first.compileToFragments(o, LEVEL_OP); fst = this.first.compileToFragments(o, LEVEL_OP);
fragments = fst.concat(this.makeCode(" " + (this.invert ? '&&' : '||') + " "), shared.compileToFragments(o), this.makeCode(" " + this.operator + " "), this.second.compileToFragments(o, LEVEL_OP)); fragments = fst.concat(this.makeCode(" " + (this.invert ? '&&' : '||') + " "), shared.compileToFragments(o), this.makeCode(" " + this.operator + " "), this.second.compileToFragments(o, LEVEL_OP));
@ -2330,6 +2384,7 @@
Op.prototype.compileExistence = function(o) { Op.prototype.compileExistence = function(o) {
var fst, ref; var fst, ref;
if (this.first.isComplex()) { if (this.first.isComplex()) {
ref = new Literal(o.scope.freeVariable('ref')); ref = new Literal(o.scope.freeVariable('ref'));
fst = new Parens(new Assign(ref, this.first)); fst = new Parens(new Assign(ref, this.first));
@ -2344,6 +2399,7 @@
Op.prototype.compileUnary = function(o) { Op.prototype.compileUnary = function(o) {
var op, parts, plusMinus; var op, parts, plusMinus;
parts = []; parts = [];
op = this.operator; op = this.operator;
parts.push([this.makeCode(op)]); parts.push([this.makeCode(op)]);
@ -2377,7 +2433,6 @@
})(Base); })(Base);
exports.In = In = (function(_super) { exports.In = In = (function(_super) {
__extends(In, _super); __extends(In, _super);
function In(object, array) { function In(object, array) {
@ -2391,6 +2446,7 @@
In.prototype.compileNode = function(o) { In.prototype.compileNode = function(o) {
var hasSplat, obj, _i, _len, _ref4; var hasSplat, obj, _i, _len, _ref4;
if (this.array instanceof Value && this.array.isArray()) { if (this.array instanceof Value && this.array.isArray()) {
_ref4 = this.array.base.objects; _ref4 = this.array.base.objects;
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
@ -2410,6 +2466,7 @@
In.prototype.compileOrTest = function(o) { In.prototype.compileOrTest = function(o) {
var cmp, cnj, i, item, ref, sub, tests, _i, _len, _ref4, _ref5, _ref6; var cmp, cnj, i, item, ref, sub, tests, _i, _len, _ref4, _ref5, _ref6;
if (this.array.base.objects.length === 0) { if (this.array.base.objects.length === 0) {
return [this.makeCode("" + (!!this.negated))]; return [this.makeCode("" + (!!this.negated))];
} }
@ -2433,6 +2490,7 @@
In.prototype.compileLoopTest = function(o) { In.prototype.compileLoopTest = function(o) {
var fragments, ref, sub, _ref4; var fragments, ref, sub, _ref4;
_ref4 = this.object.cache(o, LEVEL_LIST), sub = _ref4[0], ref = _ref4[1]; _ref4 = this.object.cache(o, LEVEL_LIST), sub = _ref4[0], ref = _ref4[1];
fragments = [].concat(this.makeCode(utility('indexOf') + ".call("), this.array.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), ref, this.makeCode(") " + (this.negated ? '< 0' : '>= 0'))); fragments = [].concat(this.makeCode(utility('indexOf') + ".call("), this.array.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), ref, this.makeCode(") " + (this.negated ? '< 0' : '>= 0')));
if ((fragmentsToText(sub)) === (fragmentsToText(ref))) { if ((fragmentsToText(sub)) === (fragmentsToText(ref))) {
@ -2455,7 +2513,6 @@
})(Base); })(Base);
exports.Try = Try = (function(_super) { exports.Try = Try = (function(_super) {
__extends(Try, _super); __extends(Try, _super);
function Try(attempt, errorVariable, recovery, ensure) { function Try(attempt, errorVariable, recovery, ensure) {
@ -2471,6 +2528,7 @@
Try.prototype.jumps = function(o) { Try.prototype.jumps = function(o) {
var _ref4; var _ref4;
return this.attempt.jumps(o) || ((_ref4 = this.recovery) != null ? _ref4.jumps(o) : void 0); return this.attempt.jumps(o) || ((_ref4 = this.recovery) != null ? _ref4.jumps(o) : void 0);
}; };
@ -2486,6 +2544,7 @@
Try.prototype.compileNode = function(o) { Try.prototype.compileNode = function(o) {
var catchPart, ensurePart, placeholder, tryPart, _ref4; var catchPart, ensurePart, placeholder, tryPart, _ref4;
o.indent += TAB; o.indent += TAB;
tryPart = this.attempt.compileToFragments(o, LEVEL_TOP); tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);
catchPart = this.recovery ? (placeholder = new Literal('_error'), this.recovery.unshift(new Assign(this.errorVariable, placeholder)), this.errorVariable = placeholder, (_ref4 = this.errorVariable.value, __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0) ? this.errorVariable.error("catch variable may not be \"" + this.errorVariable.value + "\"") : void 0, [].concat(this.makeCode(" catch ("), this.errorVariable.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(' catch (_error) {}')] : []; catchPart = this.recovery ? (placeholder = new Literal('_error'), this.recovery.unshift(new Assign(this.errorVariable, placeholder)), this.errorVariable = placeholder, (_ref4 = this.errorVariable.value, __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0) ? this.errorVariable.error("catch variable may not be \"" + this.errorVariable.value + "\"") : void 0, [].concat(this.makeCode(" catch ("), this.errorVariable.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(' catch (_error) {}')] : [];
@ -2498,7 +2557,6 @@
})(Base); })(Base);
exports.Throw = Throw = (function(_super) { exports.Throw = Throw = (function(_super) {
__extends(Throw, _super); __extends(Throw, _super);
function Throw(expression) { function Throw(expression) {
@ -2522,7 +2580,6 @@
})(Base); })(Base);
exports.Existence = Existence = (function(_super) { exports.Existence = Existence = (function(_super) {
__extends(Existence, _super); __extends(Existence, _super);
function Existence(expression) { function Existence(expression) {
@ -2535,6 +2592,7 @@
Existence.prototype.compileNode = function(o) { Existence.prototype.compileNode = function(o) {
var cmp, cnj, code, _ref4; var cmp, cnj, code, _ref4;
this.expression.front = this.front; this.expression.front = this.front;
code = this.expression.compile(o, LEVEL_OP); code = this.expression.compile(o, LEVEL_OP);
if (IDENTIFIER.test(code) && !o.scope.check(code)) { if (IDENTIFIER.test(code) && !o.scope.check(code)) {
@ -2551,7 +2609,6 @@
})(Base); })(Base);
exports.Parens = Parens = (function(_super) { exports.Parens = Parens = (function(_super) {
__extends(Parens, _super); __extends(Parens, _super);
function Parens(body) { function Parens(body) {
@ -2570,6 +2627,7 @@
Parens.prototype.compileNode = function(o) { Parens.prototype.compileNode = function(o) {
var bare, expr, fragments; var bare, expr, fragments;
expr = this.body.unwrap(); expr = this.body.unwrap();
if (expr instanceof Value && expr.isAtomic()) { if (expr instanceof Value && expr.isAtomic()) {
expr.front = this.front; expr.front = this.front;
@ -2589,11 +2647,11 @@
})(Base); })(Base);
exports.For = For = (function(_super) { exports.For = For = (function(_super) {
__extends(For, _super); __extends(For, _super);
function For(body, source) { function For(body, source) {
var _ref4; var _ref4;
this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index; this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
this.body = Block.wrap([body]); this.body = Block.wrap([body]);
this.own = !!source.own; this.own = !!source.own;
@ -2619,6 +2677,7 @@
For.prototype.compileNode = function(o) { For.prototype.compileNode = function(o) {
var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, defPartFragments, down, forPartFragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart, _ref4, _ref5; var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, defPartFragments, down, forPartFragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart, _ref4, _ref5;
body = Block.wrap([this.body]); body = Block.wrap([this.body]);
lastJumps = (_ref4 = last(body.expressions)) != null ? _ref4.jumps() : void 0; lastJumps = (_ref4 = last(body.expressions)) != null ? _ref4.jumps() : void 0;
if (lastJumps && lastJumps instanceof Return) { if (lastJumps && lastJumps instanceof Return) {
@ -2732,6 +2791,7 @@
For.prototype.pluckDirectCall = function(o, body) { For.prototype.pluckDirectCall = function(o, body) {
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; var base, defs, expr, fn, idx, ref, val, _i, _len, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
defs = []; defs = [];
_ref4 = body.expressions; _ref4 = body.expressions;
for (idx = _i = 0, _len = _ref4.length; _i < _len; idx = ++_i) { for (idx = _i = 0, _len = _ref4.length; _i < _len; idx = ++_i) {
@ -2761,7 +2821,6 @@
})(While); })(While);
exports.Switch = Switch = (function(_super) { exports.Switch = Switch = (function(_super) {
__extends(Switch, _super); __extends(Switch, _super);
function Switch(subject, cases, otherwise) { function Switch(subject, cases, otherwise) {
@ -2776,6 +2835,7 @@
Switch.prototype.jumps = function(o) { Switch.prototype.jumps = function(o) {
var block, conds, _i, _len, _ref4, _ref5, _ref6; var block, conds, _i, _len, _ref4, _ref5, _ref6;
if (o == null) { if (o == null) {
o = { o = {
block: true block: true
@ -2793,6 +2853,7 @@
Switch.prototype.makeReturn = function(res) { Switch.prototype.makeReturn = function(res) {
var pair, _i, _len, _ref4, _ref5; var pair, _i, _len, _ref4, _ref5;
_ref4 = this.cases; _ref4 = this.cases;
for (_i = 0, _len = _ref4.length; _i < _len; _i++) { for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
pair = _ref4[_i]; pair = _ref4[_i];
@ -2809,6 +2870,7 @@
Switch.prototype.compileNode = function(o) { Switch.prototype.compileNode = function(o) {
var block, body, cond, conditions, expr, fragments, i, idt1, idt2, _i, _j, _len, _len1, _ref4, _ref5, _ref6; var block, body, cond, conditions, expr, fragments, i, idt1, idt2, _i, _j, _len, _len1, _ref4, _ref5, _ref6;
idt1 = o.indent + TAB; idt1 = o.indent + TAB;
idt2 = o.indent = idt1 + TAB; idt2 = o.indent = idt1 + TAB;
fragments = [].concat(this.makeCode(this.tab + "switch ("), (this.subject ? this.subject.compileToFragments(o, LEVEL_PAREN) : this.makeCode("false")), this.makeCode(") {\n")); fragments = [].concat(this.makeCode(this.tab + "switch ("), (this.subject ? this.subject.compileToFragments(o, LEVEL_PAREN) : this.makeCode("false")), this.makeCode(") {\n"));
@ -2847,7 +2909,6 @@
})(Base); })(Base);
exports.If = If = (function(_super) { exports.If = If = (function(_super) {
__extends(If, _super); __extends(If, _super);
function If(condition, body, options) { function If(condition, body, options) {
@ -2865,11 +2926,13 @@
If.prototype.bodyNode = function() { If.prototype.bodyNode = function() {
var _ref4; var _ref4;
return (_ref4 = this.body) != null ? _ref4.unwrap() : void 0; return (_ref4 = this.body) != null ? _ref4.unwrap() : void 0;
}; };
If.prototype.elseBodyNode = function() { If.prototype.elseBodyNode = function() {
var _ref4; var _ref4;
return (_ref4 = this.elseBody) != null ? _ref4.unwrap() : void 0; return (_ref4 = this.elseBody) != null ? _ref4.unwrap() : void 0;
}; };
@ -2885,11 +2948,13 @@
If.prototype.isStatement = function(o) { If.prototype.isStatement = function(o) {
var _ref4; var _ref4;
return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref4 = this.elseBodyNode()) != null ? _ref4.isStatement(o) : void 0); return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref4 = this.elseBodyNode()) != null ? _ref4.isStatement(o) : void 0);
}; };
If.prototype.jumps = function(o) { If.prototype.jumps = function(o) {
var _ref4; var _ref4;
return this.body.jumps(o) || ((_ref4 = this.elseBody) != null ? _ref4.jumps(o) : void 0); return this.body.jumps(o) || ((_ref4 = this.elseBody) != null ? _ref4.jumps(o) : void 0);
}; };
@ -2920,6 +2985,7 @@
If.prototype.compileStatement = function(o) { If.prototype.compileStatement = function(o) {
var answer, body, child, cond, exeq, ifPart, indent; var answer, body, child, cond, exeq, ifPart, indent;
child = del(o, 'chainChild'); child = del(o, 'chainChild');
exeq = del(o, 'isExistentialEquals'); exeq = del(o, 'isExistentialEquals');
if (exeq) { if (exeq) {
@ -2953,6 +3019,7 @@
If.prototype.compileExpression = function(o) { If.prototype.compileExpression = function(o) {
var alt, body, cond, fragments; var alt, body, cond, fragments;
cond = this.condition.compileToFragments(o, LEVEL_COND); cond = this.condition.compileToFragments(o, LEVEL_COND);
body = this.bodyNode().compileToFragments(o, LEVEL_LIST); body = this.bodyNode().compileToFragments(o, LEVEL_LIST);
alt = this.elseBodyNode() ? this.elseBodyNode().compileToFragments(o, LEVEL_LIST) : [this.makeCode('void 0')]; alt = this.elseBodyNode() ? this.elseBodyNode().compileToFragments(o, LEVEL_LIST) : [this.makeCode('void 0')];
@ -2975,6 +3042,7 @@
Closure = { Closure = {
wrap: function(expressions, statement, noReturn) { wrap: function(expressions, statement, noReturn) {
var args, argumentsNode, call, func, meth; var args, argumentsNode, call, func, meth;
if (expressions.jumps()) { if (expressions.jumps()) {
return expressions; return expressions;
} }
@ -3010,6 +3078,7 @@
unfoldSoak = function(o, parent, name) { unfoldSoak = function(o, parent, name) {
var ifn; var ifn;
if (!(ifn = parent[name].unfoldSoak(o))) { if (!(ifn = parent[name].unfoldSoak(o))) {
return; return;
} }
@ -3062,6 +3131,7 @@
utility = function(name) { utility = function(name) {
var ref; var ref;
ref = "__" + name; ref = "__" + name;
Scope.root.assign(ref, UTILITIES[name]()); Scope.root.assign(ref, UTILITIES[name]());
return ref; return ref;

View file

@ -1,9 +1,8 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments; var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments;
exports.OptionParser = OptionParser = (function() { exports.OptionParser = OptionParser = (function() {
function OptionParser(rules, banner) { function OptionParser(rules, banner) {
this.banner = banner; this.banner = banner;
this.rules = buildRules(rules); this.rules = buildRules(rules);
@ -11,6 +10,7 @@
OptionParser.prototype.parse = function(args) { OptionParser.prototype.parse = function(args) {
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, seenNonOptionArg, skippingArgument, value, _i, _j, _len, _len1, _ref; var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, seenNonOptionArg, skippingArgument, value, _i, _j, _len, _len1, _ref;
options = { options = {
"arguments": [] "arguments": []
}; };
@ -59,6 +59,7 @@
OptionParser.prototype.help = function() { OptionParser.prototype.help = function() {
var letPart, lines, rule, spaces, _i, _len, _ref; var letPart, lines, rule, spaces, _i, _len, _ref;
lines = []; lines = [];
if (this.banner) { if (this.banner) {
lines.unshift("" + this.banner + "\n"); lines.unshift("" + this.banner + "\n");
@ -88,6 +89,7 @@
buildRules = function(rules) { buildRules = function(rules) {
var tuple, _i, _len, _results; var tuple, _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = rules.length; _i < _len; _i++) { for (_i = 0, _len = rules.length; _i < _len; _i++) {
tuple = rules[_i]; tuple = rules[_i];
@ -101,6 +103,7 @@
buildRule = function(shortFlag, longFlag, description, options) { buildRule = function(shortFlag, longFlag, description, options) {
var match; var match;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -118,6 +121,7 @@
normalizeArguments = function(args) { normalizeArguments = function(args) {
var arg, l, match, result, _i, _j, _len, _len1, _ref; var arg, l, match, result, _i, _j, _len, _len1, _ref;
args = args.slice(0); args = args.slice(0);
result = []; result = [];
for (_i = 0, _len = args.length; _i < _len; _i++) { for (_i = 0, _len = args.length; _i < _len; _i++) {

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var CoffeeScript, addMultilineHandler, merge, nodeREPL, prettyErrorMessage, replDefaults, vm, _ref; var CoffeeScript, addMultilineHandler, merge, nodeREPL, prettyErrorMessage, replDefaults, vm, _ref;
@ -14,6 +14,7 @@
prompt: 'coffee> ', prompt: 'coffee> ',
"eval": function(input, context, filename, cb) { "eval": function(input, context, filename, cb) {
var Assign, Block, Literal, Value, ast, err, js, _ref1; var Assign, Block, Literal, Value, ast, err, js, _ref1;
input = input.replace(/\uFF00/g, '\n'); input = input.replace(/\uFF00/g, '\n');
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1'); input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
_ref1 = require('./nodes'), Block = _ref1.Block, Assign = _ref1.Assign, Value = _ref1.Value, Literal = _ref1.Literal; _ref1 = require('./nodes'), Block = _ref1.Block, Assign = _ref1.Assign, Value = _ref1.Value, Literal = _ref1.Literal;
@ -34,6 +35,7 @@
addMultilineHandler = function(repl) { addMultilineHandler = function(repl) {
var inputStream, multiline, nodeLineListener, outputStream, rli; var inputStream, multiline, nodeLineListener, outputStream, rli;
rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream; rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream;
multiline = { multiline = {
enabled: false, enabled: false,
@ -89,6 +91,7 @@
module.exports = { module.exports = {
start: function(opts) { start: function(opts) {
var build, major, minor, repl, _ref1; var build, major, minor, repl, _ref1;
if (opts == null) { if (opts == null) {
opts = {}; opts = {};
} }

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, generate, left, rite, _i, _len, _ref, var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, generate, left, rite, _i, _len, _ref,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
@ -6,13 +6,13 @@
generate = function(tag, value) { generate = function(tag, value) {
var tok; var tok;
tok = [tag, value]; tok = [tag, value];
tok.generated = true; tok.generated = true;
return tok; return tok;
}; };
exports.Rewriter = (function() { exports.Rewriter = (function() {
function Rewriter() {} function Rewriter() {}
Rewriter.prototype.rewrite = function(tokens) { Rewriter.prototype.rewrite = function(tokens) {
@ -30,6 +30,7 @@
Rewriter.prototype.scanTokens = function(block) { Rewriter.prototype.scanTokens = function(block) {
var i, token, tokens; var i, token, tokens;
tokens = this.tokens; tokens = this.tokens;
i = 0; i = 0;
while (token = tokens[i]) { while (token = tokens[i]) {
@ -40,6 +41,7 @@
Rewriter.prototype.detectEnd = function(i, condition, action) { Rewriter.prototype.detectEnd = function(i, condition, action) {
var levels, token, tokens, _ref, _ref1; var levels, token, tokens, _ref, _ref1;
tokens = this.tokens; tokens = this.tokens;
levels = 0; levels = 0;
while (token = tokens[i]) { while (token = tokens[i]) {
@ -61,6 +63,7 @@
Rewriter.prototype.removeLeadingNewlines = function() { Rewriter.prototype.removeLeadingNewlines = function() {
var i, tag, _i, _len, _ref; var i, tag, _i, _len, _ref;
_ref = this.tokens; _ref = this.tokens;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
tag = _ref[i][0]; tag = _ref[i][0];
@ -76,6 +79,7 @@
Rewriter.prototype.removeMidExpressionNewlines = function() { Rewriter.prototype.removeMidExpressionNewlines = function() {
return this.scanTokens(function(token, i, tokens) { return this.scanTokens(function(token, i, tokens) {
var _ref; var _ref;
if (!(token[0] === 'TERMINATOR' && (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0))) { if (!(token[0] === 'TERMINATOR' && (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0))) {
return 1; return 1;
} }
@ -86,8 +90,10 @@
Rewriter.prototype.closeOpenCalls = function() { Rewriter.prototype.closeOpenCalls = function() {
var action, condition; var action, condition;
condition = function(token, i) { condition = function(token, i) {
var _ref; var _ref;
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')'; return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
}; };
action = function(token, i) { action = function(token, i) {
@ -103,8 +109,10 @@
Rewriter.prototype.closeOpenIndexes = function() { Rewriter.prototype.closeOpenIndexes = function() {
var action, condition; var action, condition;
condition = function(token, i) { condition = function(token, i) {
var _ref; var _ref;
return (_ref = token[0]) === ']' || _ref === 'INDEX_END'; return (_ref = token[0]) === ']' || _ref === 'INDEX_END';
}; };
action = function(token, i) { action = function(token, i) {
@ -120,6 +128,7 @@
Rewriter.prototype.matchTags = function() { Rewriter.prototype.matchTags = function() {
var fuzz, i, j, pattern, _i, _ref, _ref1; var fuzz, i, j, pattern, _i, _ref, _ref1;
i = arguments[0], pattern = 2 <= arguments.length ? __slice.call(arguments, 1) : []; i = arguments[0], pattern = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
fuzz = 0; fuzz = 0;
for (j = _i = 0, _ref = pattern.length; 0 <= _ref ? _i < _ref : _i > _ref; j = 0 <= _ref ? ++_i : --_i) { for (j = _i = 0, _ref = pattern.length; 0 <= _ref ? _i < _ref : _i > _ref; j = 0 <= _ref ? ++_i : --_i) {
@ -145,6 +154,7 @@
Rewriter.prototype.findTagsBackwards = function(i, tags) { Rewriter.prototype.findTagsBackwards = function(i, tags) {
var backStack, _ref, _ref1, _ref2, _ref3, _ref4, _ref5; var backStack, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
backStack = []; backStack = [];
while (i >= 0 && (backStack.length || (_ref2 = this.tag(i), __indexOf.call(tags, _ref2) < 0) && ((_ref3 = this.tag(i), __indexOf.call(EXPRESSION_START, _ref3) < 0) || this.tokens[i].generated) && (_ref4 = this.tag(i), __indexOf.call(LINEBREAKS, _ref4) < 0))) { while (i >= 0 && (backStack.length || (_ref2 = this.tag(i), __indexOf.call(tags, _ref2) < 0) && ((_ref3 = this.tag(i), __indexOf.call(EXPRESSION_START, _ref3) < 0) || this.tokens[i].generated) && (_ref4 = this.tag(i), __indexOf.call(LINEBREAKS, _ref4) < 0))) {
if (_ref = this.tag(i), __indexOf.call(EXPRESSION_END, _ref) >= 0) { if (_ref = this.tag(i), __indexOf.call(EXPRESSION_END, _ref) >= 0) {
@ -160,9 +170,11 @@
Rewriter.prototype.addImplicitBracesAndParens = function() { Rewriter.prototype.addImplicitBracesAndParens = function() {
var stack; var stack;
stack = []; stack = [];
return this.scanTokens(function(token, i, tokens) { return this.scanTokens(function(token, i, tokens) {
var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, nextTag, offset, prevTag, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag, _ref, _ref1, _ref2, _ref3, _ref4, _ref5; var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, nextTag, offset, prevTag, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
tag = token[0]; tag = token[0];
prevTag = (i > 0 ? tokens[i - 1] : [])[0]; prevTag = (i > 0 ? tokens[i - 1] : [])[0];
nextTag = (i < tokens.length - 1 ? tokens[i + 1] : [])[0]; nextTag = (i < tokens.length - 1 ? tokens[i + 1] : [])[0];
@ -175,22 +187,27 @@
}; };
inImplicit = function() { inImplicit = function() {
var _ref, _ref1; var _ref, _ref1;
return (_ref = stackTop()) != null ? (_ref1 = _ref[2]) != null ? _ref1.ours : void 0 : void 0; return (_ref = stackTop()) != null ? (_ref1 = _ref[2]) != null ? _ref1.ours : void 0 : void 0;
}; };
inImplicitCall = function() { inImplicitCall = function() {
var _ref; var _ref;
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '('; return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '(';
}; };
inImplicitObject = function() { inImplicitObject = function() {
var _ref; var _ref;
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '{'; return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '{';
}; };
inImplicitControl = function() { inImplicitControl = function() {
var _ref; var _ref;
return inImplicit && ((_ref = stackTop()) != null ? _ref[0] : void 0) === 'CONTROL'; return inImplicit && ((_ref = stackTop()) != null ? _ref[0] : void 0) === 'CONTROL';
}; };
startImplicitCall = function(j) { startImplicitCall = function(j) {
var idx; var idx;
idx = j != null ? j : i; idx = j != null ? j : i;
stack.push([ stack.push([
'(', idx, { '(', idx, {
@ -209,6 +226,7 @@
}; };
startImplicitObject = function(j, startsLine) { startImplicitObject = function(j, startsLine) {
var idx; var idx;
if (startsLine == null) { if (startsLine == null) {
startsLine = true; startsLine = true;
} }
@ -332,6 +350,7 @@
Rewriter.prototype.addLocationDataToGeneratedTokens = function() { Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
return this.scanTokens(function(token, i, tokens) { return this.scanTokens(function(token, i, tokens) {
var column, line, nextLocation, prevLocation, _ref, _ref1; var column, line, nextLocation, prevLocation, _ref, _ref1;
if (token[2]) { if (token[2]) {
return 1; return 1;
} }
@ -357,9 +376,11 @@
Rewriter.prototype.addImplicitIndentation = function() { Rewriter.prototype.addImplicitIndentation = function() {
var action, condition, indent, outdent, starter; var action, condition, indent, outdent, starter;
starter = indent = outdent = null; starter = indent = outdent = null;
condition = function(token, i) { condition = function(token, i) {
var _ref; var _ref;
return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN')); return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN'));
}; };
action = function(token, i) { action = function(token, i) {
@ -367,6 +388,7 @@
}; };
return this.scanTokens(function(token, i, tokens) { return this.scanTokens(function(token, i, tokens) {
var tag, _ref, _ref1; var tag, _ref, _ref1;
tag = token[0]; tag = token[0];
if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') { if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') {
tokens.splice(i, 1); tokens.splice(i, 1);
@ -399,9 +421,11 @@
Rewriter.prototype.tagPostfixConditionals = function() { Rewriter.prototype.tagPostfixConditionals = function() {
var action, condition, original; var action, condition, original;
original = null; original = null;
condition = function(token, i) { condition = function(token, i) {
var prevTag, tag; var prevTag, tag;
tag = token[0]; tag = token[0];
prevTag = this.tokens[i - 1][0]; prevTag = this.tokens[i - 1][0];
return tag === 'TERMINATOR' || (tag === 'INDENT' && __indexOf.call(SINGLE_LINERS, prevTag) < 0); return tag === 'TERMINATOR' || (tag === 'INDENT' && __indexOf.call(SINGLE_LINERS, prevTag) < 0);
@ -423,6 +447,7 @@
Rewriter.prototype.indentation = function(implicit) { Rewriter.prototype.indentation = function(implicit) {
var indent, outdent; var indent, outdent;
if (implicit == null) { if (implicit == null) {
implicit = false; implicit = false;
} }
@ -441,6 +466,7 @@
Rewriter.prototype.tag = function(i) { Rewriter.prototype.tag = function(i) {
var _ref; var _ref;
return (_ref = this.tokens[i]) != null ? _ref[0] : void 0; return (_ref = this.tokens[i]) != null ? _ref[0] : void 0;
}; };
@ -466,7 +492,7 @@
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS']; IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'SUPER', '@', '->', '=>', '[', '(', '{', '--', '++']; IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'SUPER', 'THROW', '@', '->', '=>', '[', '(', '{', '--', '++'];
IMPLICIT_UNSPACED_CALL = ['+', '-']; IMPLICIT_UNSPACED_CALL = ['+', '-'];

View file

@ -1,11 +1,10 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var Scope, extend, last, _ref; var Scope, extend, last, _ref;
_ref = require('./helpers'), extend = _ref.extend, last = _ref.last; _ref = require('./helpers'), extend = _ref.extend, last = _ref.last;
exports.Scope = Scope = (function() { exports.Scope = Scope = (function() {
Scope.root = null; Scope.root = null;
function Scope(parent, expressions, method) { function Scope(parent, expressions, method) {
@ -40,6 +39,7 @@
Scope.prototype.namedMethod = function() { Scope.prototype.namedMethod = function() {
var _ref1; var _ref1;
if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) { if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) {
return this.method; return this.method;
} }
@ -63,6 +63,7 @@
Scope.prototype.check = function(name) { Scope.prototype.check = function(name) {
var _ref1; var _ref1;
return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0)); return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));
}; };
@ -76,6 +77,7 @@
Scope.prototype.type = function(name) { Scope.prototype.type = function(name) {
var v, _i, _len, _ref1; var v, _i, _len, _ref1;
_ref1 = this.variables; _ref1 = this.variables;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
v = _ref1[_i]; v = _ref1[_i];
@ -88,6 +90,7 @@
Scope.prototype.freeVariable = function(name, reserve) { Scope.prototype.freeVariable = function(name, reserve) {
var index, temp; var index, temp;
if (reserve == null) { if (reserve == null) {
reserve = true; reserve = true;
} }
@ -115,6 +118,7 @@
Scope.prototype.declaredVariables = function() { Scope.prototype.declaredVariables = function() {
var realVars, tempVars, v, _i, _len, _ref1; var realVars, tempVars, v, _i, _len, _ref1;
realVars = []; realVars = [];
tempVars = []; tempVars = [];
_ref1 = this.variables; _ref1 = this.variables;
@ -129,6 +133,7 @@
Scope.prototype.assignedVariables = function() { Scope.prototype.assignedVariables = function() {
var v, _i, _len, _ref1, _results; var v, _i, _len, _ref1, _results;
_ref1 = this.variables; _ref1 = this.variables;
_results = []; _results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {

View file

@ -1,9 +1,8 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.2
(function() { (function() {
var BASE64_CHARS, LineMapping, MAX_BASE64_VALUE, VLQ_CONTINUATION_BIT, VLQ_SHIFT, VLQ_VALUE_MASK, decodeBase64Char, encodeBase64Char; var BASE64_CHARS, LineMapping, MAX_BASE64_VALUE, VLQ_CONTINUATION_BIT, VLQ_SHIFT, VLQ_VALUE_MASK, decodeBase64Char, encodeBase64Char;
LineMapping = (function() { LineMapping = (function() {
function LineMapping(generatedLine) { function LineMapping(generatedLine) {
this.generatedLine = generatedLine; this.generatedLine = generatedLine;
this.columnMap = {}; this.columnMap = {};
@ -12,6 +11,7 @@
LineMapping.prototype.addMapping = function(generatedColumn, _arg, options) { LineMapping.prototype.addMapping = function(generatedColumn, _arg, options) {
var sourceColumn, sourceLine; var sourceColumn, sourceLine;
sourceLine = _arg[0], sourceColumn = _arg[1]; sourceLine = _arg[0], sourceColumn = _arg[1];
if (options == null) { if (options == null) {
options = {}; options = {};
@ -33,6 +33,7 @@
LineMapping.prototype.getSourcePosition = function(generatedColumn) { LineMapping.prototype.getSourcePosition = function(generatedColumn) {
var answer, columnMapping, lastColumnMapping, _i, _len, _ref; var answer, columnMapping, lastColumnMapping, _i, _len, _ref;
answer = null; answer = null;
lastColumnMapping = null; lastColumnMapping = null;
_ref = this.columnMappings; _ref = this.columnMappings;
@ -54,13 +55,13 @@
})(); })();
exports.SourceMap = (function() { exports.SourceMap = (function() {
function SourceMap() { function SourceMap() {
this.generatedLines = []; this.generatedLines = [];
} }
SourceMap.prototype.addMapping = function(sourceLocation, generatedLocation, options) { SourceMap.prototype.addMapping = function(sourceLocation, generatedLocation, options) {
var generatedColumn, generatedLine, lineMapping; var generatedColumn, generatedLine, lineMapping;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -74,6 +75,7 @@
SourceMap.prototype.getSourcePosition = function(_arg) { SourceMap.prototype.getSourcePosition = function(_arg) {
var answer, generatedColumn, generatedLine, lineMapping; var answer, generatedColumn, generatedLine, lineMapping;
generatedLine = _arg[0], generatedColumn = _arg[1]; generatedLine = _arg[0], generatedColumn = _arg[1];
answer = null; answer = null;
lineMapping = this.generatedLines[generatedLine]; lineMapping = this.generatedLines[generatedLine];
@ -87,6 +89,7 @@
SourceMap.prototype.forEachMapping = function(fn) { SourceMap.prototype.forEachMapping = function(fn) {
var columnMapping, generatedLineNumber, lineMapping, _i, _len, _ref, _results; var columnMapping, generatedLineNumber, lineMapping, _i, _len, _ref, _results;
_ref = this.generatedLines; _ref = this.generatedLines;
_results = []; _results = [];
for (generatedLineNumber = _i = 0, _len = _ref.length; _i < _len; generatedLineNumber = ++_i) { for (generatedLineNumber = _i = 0, _len = _ref.length; _i < _len; generatedLineNumber = ++_i) {
@ -94,6 +97,7 @@
if (lineMapping) { if (lineMapping) {
_results.push((function() { _results.push((function() {
var _j, _len1, _ref1, _results1; var _j, _len1, _ref1, _results1;
_ref1 = lineMapping.columnMappings; _ref1 = lineMapping.columnMappings;
_results1 = []; _results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
@ -115,6 +119,7 @@
exports.generateV3SourceMap = function(sourceMap, options, code) { exports.generateV3SourceMap = function(sourceMap, options, code) {
var answer, generatedFile, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, sourceFiles, sourceRoot, writingGeneratedLine; var answer, generatedFile, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, sourceFiles, sourceRoot, writingGeneratedLine;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -180,6 +185,7 @@
decodeBase64Char = function(char) { decodeBase64Char = function(char) {
var value; var value;
value = BASE64_CHARS.indexOf(char); value = BASE64_CHARS.indexOf(char);
if (value === -1) { if (value === -1) {
throw new Error("Invalid Base 64 character: " + char); throw new Error("Invalid Base 64 character: " + char);
@ -195,6 +201,7 @@
exports.vlqEncodeValue = function(value) { exports.vlqEncodeValue = function(value) {
var answer, nextVlqChunk, signBit, valueToEncode; var answer, nextVlqChunk, signBit, valueToEncode;
signBit = value < 0 ? 1 : 0; signBit = value < 0 ? 1 : 0;
valueToEncode = (Math.abs(value) << 1) + signBit; valueToEncode = (Math.abs(value) << 1) + signBit;
answer = ""; answer = "";
@ -211,6 +218,7 @@
exports.vlqDecodeValue = function(str, offset) { exports.vlqDecodeValue = function(str, offset) {
var consumed, continuationShift, done, nextChunkValue, nextVlqChunk, position, signBit, value; var consumed, continuationShift, done, nextChunkValue, nextVlqChunk, position, signBit, value;
if (offset == null) { if (offset == null) {
offset = 0; offset = 0;
} }

View file

@ -3,7 +3,7 @@
"description": "Unfancy JavaScript", "description": "Unfancy JavaScript",
"keywords": ["javascript", "language", "coffeescript", "compiler"], "keywords": ["javascript", "language", "coffeescript", "compiler"],
"author": "Jeremy Ashkenas", "author": "Jeremy Ashkenas",
"version": "1.6.1", "version": "1.6.2",
"licenses": [{ "licenses": [{
"type": "MIT", "type": "MIT",
"url": "https://raw.github.com/jashkenas/coffee-script/master/LICENSE" "url": "https://raw.github.com/jashkenas/coffee-script/master/LICENSE"

View file

@ -1,18 +1,11 @@
# Override exported methods for non-Node.js engines. # This **Browser** 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 **XHR**, and
# `text/coffeescript` script tags, source maps via data-URLs, and so on.
CoffeeScript = require './coffee-script' CoffeeScript = require './coffee-script'
CoffeeScript.require = require CoffeeScript.require = require
compile = CoffeeScript.compile
compile =
# if we are able, inline the source map using a data URI
if btoa? and JSON?
(code, options = {}) ->
options.sourceMap = true
options.inline = true
{js, v3SourceMap} = CoffeeScript.compile code, options
"#{js}\n//@ sourceMappingURL=data:application/json;base64,#{btoa v3SourceMap}\n//@ sourceURL=coffeescript"
else
CoffeeScript.compile
# Use standard JavaScript `eval` to eval code. # Use standard JavaScript `eval` to eval code.
CoffeeScript.eval = (code, options = {}) -> CoffeeScript.eval = (code, options = {}) ->
@ -27,6 +20,15 @@ CoffeeScript.run = (code, options = {}) ->
# If we're not in a browser environment, we're finished with the public API. # If we're not in a browser environment, we're finished with the public API.
return unless window? return unless window?
# Include source maps where possible. If we've got a base64 encoder, and a
# JSON serializer, we're good to go.
if btoa? and JSON?
compile = (code, options = {}) ->
options.sourceMap = true
options.inline = true
{js, v3SourceMap} = CoffeeScript.compile code, options
"#{js}\n//@ sourceMappingURL=data:application/json;base64,#{btoa v3SourceMap}\n//@ sourceURL=coffeescript"
# Load a remote script from the current domain via XHR. # Load a remote script from the current domain via XHR.
CoffeeScript.load = (url, callback, options = {}) -> CoffeeScript.load = (url, callback, options = {}) ->
options.sourceFiles = [url] options.sourceFiles = [url]
@ -67,7 +69,7 @@ runScripts = ->
execute() execute()
null null
# Listen for window load, both in browsers and in IE. # Listen for window load, both in decent browsers and in IE.
if window.addEventListener if window.addEventListener
addEventListener 'DOMContentLoaded', runScripts, no addEventListener 'DOMContentLoaded', runScripts, no
else else

View file

@ -1,10 +1,7 @@
# CoffeeScript can be used both on the server, as a command-line compiler based # CoffeeScript can be used both on the server, as a command-line compiler based
# on Node.js/V8, or to run CoffeeScripts directly in the browser. This module # on Node.js/V8, or to run CoffeeScript directly in the browser. This module
# contains the main entry functions for tokenizing, parsing, and compiling # contains the main entry functions for tokenizing, parsing, and compiling
# source CoffeeScript into JavaScript. # source CoffeeScript into JavaScript.
#
# If included on a webpage, it will automatically sniff out, compile, and
# execute all scripts present in `text/coffeescript` tags.
fs = require 'fs' fs = require 'fs'
vm = require 'vm' vm = require 'vm'
@ -16,7 +13,7 @@ helpers = require './helpers'
sourcemap = require './sourcemap' sourcemap = require './sourcemap'
# The current CoffeeScript version number. # The current CoffeeScript version number.
exports.VERSION = '1.6.1' exports.VERSION = '1.6.2'
# Expose helpers for testing. # Expose helpers for testing.
exports.helpers = helpers exports.helpers = helpers
@ -157,8 +154,9 @@ if require.extensions
for ext in ['.coffee', '.litcoffee', '.coffee.md'] for ext in ['.coffee', '.litcoffee', '.coffee.md']
require.extensions[ext] = loadFile require.extensions[ext] = loadFile
# Patch `child_process.fork` so that Coffee scripts are able to fork both # If we're on Node, patch `child_process.fork` so that Coffee scripts are able
# CoffeeScript files, and JavaScript files, directly. # to fork both CoffeeScript files, and JavaScript files, directly.
if child_process
{fork} = child_process {fork} = child_process
child_process.fork = (path, args = [], options = {}) -> child_process.fork = (path, args = [], options = {}) ->
execPath = if helpers.isCoffee(path) then 'coffee' else null execPath = if helpers.isCoffee(path) then 'coffee' else null

View file

@ -288,7 +288,7 @@ exports.Block = class Block extends Base
compiledNodes.push node.compileToFragments o, LEVEL_LIST compiledNodes.push node.compileToFragments o, LEVEL_LIST
if top if top
if @spaced if @spaced
return [].concat @makeCode("\n"), @joinFragmentArrays(compiledNodes, '\n\n'), @makeCode("\n") return [].concat @joinFragmentArrays(compiledNodes, '\n\n'), @makeCode("\n")
else else
return @joinFragmentArrays(compiledNodes, '\n') return @joinFragmentArrays(compiledNodes, '\n')
if compiledNodes.length if compiledNodes.length
@ -351,7 +351,7 @@ exports.Block = class Block extends Base
if assigns if assigns
fragments.push @makeCode ",\n#{@tab + TAB}" if declars fragments.push @makeCode ",\n#{@tab + TAB}" if declars
fragments.push @makeCode (scope.assignedVariables().join ",\n#{@tab + TAB}") fragments.push @makeCode (scope.assignedVariables().join ",\n#{@tab + TAB}")
fragments.push @makeCode ';\n' fragments.push @makeCode ';\n\n'
fragments.concat post fragments.concat post
# Wrap up the given nodes as a **Block**, unless it already happens # Wrap up the given nodes as a **Block**, unless it already happens

View file

@ -16,6 +16,7 @@ generate = (tag, value) ->
class exports.Rewriter class exports.Rewriter
# Helpful snippet for debugging: # Helpful snippet for debugging:
#
# console.log (t[0] + '/' + t[1] for t in @tokens).join ' ' # console.log (t[0] + '/' + t[1] for t in @tokens).join ' '
# Rewrite the token stream in multiple passes, one logical filter at # Rewrite the token stream in multiple passes, one logical filter at
@ -186,9 +187,12 @@ class exports.Rewriter
return forward(1) return forward(1)
if tag is 'INDENT' and inImplicit() if tag is 'INDENT' and inImplicit()
# An INDENT closes an implicit call unless
# 1. We have seen a CONTROL argument on the line. # An `INDENT` closes an implicit call unless
#
# 1. We have seen a `CONTROL` argument on the line.
# 2. The last token before the indent is part of the list below # 2. The last token before the indent is part of the list below
#
if prevTag not in ['=>', '->', '[', '(', ',', '{', 'TRY', 'ELSE', '='] if prevTag not in ['=>', '->', '[', '(', ',', '{', 'TRY', 'ELSE', '=']
endImplicitCall() while inImplicitCall() endImplicitCall() while inImplicitCall()
stack.pop() if inImplicitControl() stack.pop() if inImplicitControl()
@ -223,20 +227,27 @@ class exports.Rewriter
return forward(2) return forward(2)
# Implicit call taking an implicit indented object as first argument. # Implicit call taking an implicit indented object as first argument.
#
# f # f
# a: b # a: b
# c: d # c: d
#
# and # and
#
# f # f
# 1 # 1
# a: b # a: b
# b: c # b: c
#
# Don't accept implicit calls of this type, when on the same line # Don't accept implicit calls of this type, when on the same line
# as the control strucutures below as that may misinterpret constructs like: # as the control strucutures below as that may misinterpret constructs like:
#
# if f # if f
# a: 1 # a: 1
# as # as
#
# if f(a: 1) # if f(a: 1)
#
# which is probably always unintended. # which is probably always unintended.
# Furthermore don't allow this in literal arrays, as # Furthermore don't allow this in literal arrays, as
# that creates grammatical ambiguities. # that creates grammatical ambiguities.
@ -266,11 +277,13 @@ class exports.Rewriter
# End implicit calls when chaining method calls # End implicit calls when chaining method calls
# like e.g.: # like e.g.:
#
# f -> # f ->
# a # a
# .g b, -> # .g b, ->
# c # c
# .h a # .h a
#
if prevTag is 'OUTDENT' and inImplicitCall() and tag in ['.', '?.', '::', '?::'] if prevTag is 'OUTDENT' and inImplicitCall() and tag in ['.', '?.', '::', '?::']
endImplicitCall() endImplicitCall()
return forward(1) return forward(1)
@ -299,6 +312,7 @@ class exports.Rewriter
# Close implicit object if comma is the last character # Close implicit object if comma is the last character
# and what comes after doesn't look like it belongs. # and what comes after doesn't look like it belongs.
# This is used for trailing commas and calls, like: # This is used for trailing commas and calls, like:
#
# x = # x =
# a: b, # a: b,
# c: d, # c: d,
@ -307,6 +321,7 @@ class exports.Rewriter
# and # and
# #
# f a, b: c, d: e, f, g: h: i, j # f a, b: c, d: e, f, g: h: i, j
#
if tag is ',' and not @looksObjectish(i + 1) and inImplicitObject() and if tag is ',' and not @looksObjectish(i + 1) and inImplicitObject() and
(nextTag isnt 'TERMINATOR' or not @looksObjectish(i + 2)) (nextTag isnt 'TERMINATOR' or not @looksObjectish(i + 2))
# When nextTag is OUTDENT the comma is insignificant and # When nextTag is OUTDENT the comma is insignificant and
@ -444,7 +459,7 @@ IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@
IMPLICIT_CALL = [ IMPLICIT_CALL = [
'IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS' 'IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS'
'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'SUPER' 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'SUPER'
'@', '->', '=>', '[', '(', '{', '--', '++' 'THROW', '@', '->', '=>', '[', '(', '{', '--', '++'
] ]
IMPLICIT_UNSPACED_CALL = ['+', '-'] IMPLICIT_UNSPACED_CALL = ['+', '-']