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:
parent
4f815ea978
commit
a3e8de338a
91 changed files with 8587 additions and 7766 deletions
4
LICENSE
4
LICENSE
|
@ -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
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
###
|
||||
CoffeeScript Compiler v1.6.1
|
||||
SkinnyMochaHalfCaffScript Compiler v1.0
|
||||
Released under the MIT License
|
||||
###
|
||||
|
||||
|
|
|
@ -92,174 +92,197 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>browser.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>browser.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p>Override exported methods for non-Node.js engines.
|
||||
|
||||
</div>
|
||||
<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>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">'./coffee-script'</span>
|
||||
<span class="nv">CoffeeScript.require = </span><span class="nx">require</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript = require <span class="string">'./coffee-script'</span>
|
||||
CoffeeScript.require = require
|
||||
compile = CoffeeScript.compile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Use standard JavaScript <code>eval</code> to eval code.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>Use standard JavaScript <code>eval</code> to eval code.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript.eval = </span><span class="nf">(code, options = {}) -></span>
|
||||
<span class="nx">options</span><span class="p">.</span><span class="nx">bare</span> <span class="o">?=</span> <span class="kc">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>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">eval</span></span> = (code, options = {}) ->
|
||||
options.bare ?= <span class="literal">on</span>
|
||||
eval compile code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Running code does not provide access to this scope.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Running code does not provide access to this scope.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript.run = </span><span class="nf">(code, options = {}) -></span>
|
||||
<span class="nv">options.bare = </span><span class="kc">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>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">run</span></span> = (code, options = {}) ->
|
||||
options.bare = <span class="literal">on</span>
|
||||
Function(compile code, options)()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
<p>If we're not in a browser environment, we're finished with the public API.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>If we're not in a browser environment, we're finished with the public API.
|
||||
</p>
|
||||
|
||||
</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 id="section-5">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Load a remote script from the current domain via XHR.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Include source maps where possible. If we've got a base64 encoder, and a
|
||||
JSON serializer, we're good to go.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">CoffeeScript.load = </span><span class="nf">(url, callback, options = {}) -></span>
|
||||
<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="k">new</span> <span class="nb">window</span><span class="p">.</span><span class="nx">ActiveXObject</span><span class="p">(</span><span class="s">'Microsoft.XMLHTTP'</span><span class="p">)</span>
|
||||
<span class="k">else</span>
|
||||
<span class="k">new</span> <span class="nx">XMLHttpRequest</span><span class="p">()</span>
|
||||
<span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span> <span class="s">'GET'</span><span class="p">,</span> <span class="nx">url</span><span class="p">,</span> <span class="kc">true</span>
|
||||
<span class="nx">xhr</span><span class="p">.</span><span class="nx">overrideMimeType</span> <span class="s">'text/plain'</span> <span class="k">if</span> <span class="s">'overrideMimeType'</span> <span class="k">of</span> <span class="nx">xhr</span>
|
||||
<span class="nv">xhr.onreadystatechange = </span><span class="nf">-></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">"Could not load </span><span class="si">#{</span><span class="nx">url</span><span class="si">}</span><span class="s">"</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>
|
||||
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> btoa? <span class="keyword">and</span> JSON?
|
||||
<span class="function"><span class="title">compile</span></span> = (code, options = {}) ->
|
||||
options.sourceMap = <span class="literal">true</span>
|
||||
options.inline = <span class="literal">true</span>
|
||||
{js, v3SourceMap} = CoffeeScript.compile code, options
|
||||
<span class="string">"<span class="subst">#{js}</span>\n//@ sourceMappingURL=data:application/json;base64,<span class="subst">#{btoa v3SourceMap}</span>\n//@ sourceURL=coffeescript"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Activate CoffeeScript in the browser by having it compile and evaluate
|
||||
all script tags with a content-type of <code>text/coffeescript</code>.
|
||||
This happens on page load.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Load a remote script from the current domain via XHR.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">runScripts = </span><span class="nf">-></span>
|
||||
<span class="nv">scripts = </span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span> <span class="s">'script'</span>
|
||||
<span class="nv">coffeetypes = </span><span class="p">[</span><span class="s">'text/coffeescript'</span><span class="p">,</span> <span class="s">'text/literate-coffeescript'</span><span class="p">]</span>
|
||||
<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="nv">index = </span><span class="mi">0</span>
|
||||
<span class="nv">length = </span><span class="nx">coffees</span><span class="p">.</span><span class="nx">length</span>
|
||||
<span class="nx">do</span> <span class="nv">execute = </span><span class="nf">-></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>
|
||||
<span class="nv">mediatype = </span><span class="nx">script</span><span class="o">?</span><span class="p">.</span><span class="nx">type</span>
|
||||
<span class="k">if</span> <span class="nx">mediatype</span> <span class="k">in</span> <span class="nx">coffeetypes</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">'text/literate-coffeescript'</span><span class="p">}</span>
|
||||
<span class="k">if</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span>
|
||||
<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="k">else</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>
|
||||
<span class="nx">execute</span><span class="p">()</span>
|
||||
<span class="kc">null</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">load</span></span> = (url, callback, options = {}) ->
|
||||
options.sourceFiles = [url]
|
||||
xhr = <span class="keyword">if</span> window.ActiveXObject
|
||||
<span class="keyword">new</span> window.ActiveXObject(<span class="string">'Microsoft.XMLHTTP'</span>)
|
||||
<span class="keyword">else</span>
|
||||
<span class="keyword">new</span> XMLHttpRequest()
|
||||
xhr.open <span class="string">'GET'</span>, url, <span class="literal">true</span>
|
||||
xhr.overrideMimeType <span class="string">'text/plain'</span> <span class="keyword">if</span> <span class="string">'overrideMimeType'</span> <span class="keyword">of</span> xhr
|
||||
xhr.<span class="function"><span class="title">onreadystatechange</span></span> = ->
|
||||
<span class="keyword">if</span> xhr.readyState <span class="keyword">is</span> <span class="number">4</span>
|
||||
<span class="keyword">if</span> xhr.status <span class="keyword">in</span> [<span class="number">0</span>, <span class="number">200</span>]
|
||||
CoffeeScript.run xhr.responseText, options
|
||||
<span class="keyword">else</span>
|
||||
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Could not load <span class="subst">#{url}</span>"</span>
|
||||
callback() <span class="keyword">if</span> callback
|
||||
xhr.send <span class="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Listen for window load, both in browsers and in IE.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Activate CoffeeScript in the browser by having it compile and evaluate
|
||||
all script tags with a content-type of <code>text/coffeescript</code>.
|
||||
This happens on page load.
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nx">addEventListener</span> <span class="s">'DOMContentLoaded'</span><span class="p">,</span> <span class="nx">runScripts</span><span class="p">,</span> <span class="kc">no</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">attachEvent</span> <span class="s">'onload'</span><span class="p">,</span> <span class="nx">runScripts</span>
|
||||
|
||||
</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">runScripts</span></span> = ->
|
||||
scripts = document.getElementsByTagName <span class="string">'script'</span>
|
||||
coffeetypes = [<span class="string">'text/coffeescript'</span>, <span class="string">'text/literate-coffeescript'</span>]
|
||||
coffees = (s <span class="keyword">for</span> s <span class="keyword">in</span> scripts <span class="keyword">when</span> s.type <span class="keyword">in</span> coffeetypes)
|
||||
index = <span class="number">0</span>
|
||||
length = coffees.length
|
||||
<span class="keyword">do</span> <span class="function"><span class="title">execute</span></span> = ->
|
||||
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>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</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>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -92,19 +92,22 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>cake.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>cake.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
</div>
|
||||
<p><code>cake</code> is a simplified version of <a href="http://www.gnu.org/software/make/">Make</a>
|
||||
(<a href="http://rake.rubyforge.org/">Rake</a>, <a href="http://github.com/280north/jake">Jake</a>)
|
||||
for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
|
||||
|
@ -116,220 +119,209 @@ current directory's Cakefile.
|
|||
|
||||
</p>
|
||||
<p>External dependencies.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s">'fs'</span>
|
||||
<span class="nv">path = </span><span class="nx">require</span> <span class="s">'path'</span>
|
||||
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s">'./helpers'</span>
|
||||
<span class="nv">optparse = </span><span class="nx">require</span> <span class="s">'./optparse'</span>
|
||||
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">'./coffee-script'</span>
|
||||
<div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
|
||||
path = require <span class="string">'path'</span>
|
||||
helpers = require <span class="string">'./helpers'</span>
|
||||
optparse = require <span class="string">'./optparse'</span>
|
||||
CoffeeScript = require <span class="string">'./coffee-script'</span>
|
||||
|
||||
<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 id="section-2">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Keep track of the list of defined tasks, the accepted options, and so on.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>Keep track of the list of defined tasks, the accepted options, and so on.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">tasks = </span><span class="p">{}</span>
|
||||
<span class="nv">options = </span><span class="p">{}</span>
|
||||
<span class="nv">switches = </span><span class="p">[]</span>
|
||||
<span class="nv">oparse = </span><span class="kc">null</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>tasks = {}
|
||||
options = {}
|
||||
switches = []
|
||||
oparse = <span class="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Mixin the top-level Cake functions for Cakefiles to use directly.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Mixin the top-level Cake functions for Cakefiles to use directly.
|
||||
</p>
|
||||
|
||||
</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 id="section-4">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Define a Cake task with a short name, an optional sentence description,
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Define a Cake task with a short name, an optional sentence description,
|
||||
and the function to run as the action itself.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">task: </span><span class="nf">(name, description, action) -></span>
|
||||
<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>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre> task: (name, description, action) ->
|
||||
[action, description] = [description, action] <span class="keyword">unless</span> action
|
||||
tasks[name] = {name, description, action}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Define an option that the Cakefile accepts. The parsed options hash,
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Define an option that the Cakefile accepts. The parsed options hash,
|
||||
containing all of the command-line options passed, will be made available
|
||||
as the first argument to the action.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">option: </span><span class="nf">(letter, flag, description) -></span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre> option: (letter, flag, description) ->
|
||||
switches.push [letter, flag, description]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Invoke another task in the current Cakefile.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Invoke another task in the current Cakefile.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">invoke: </span><span class="nf">(name) -></span>
|
||||
<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>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre> invoke: (name) ->
|
||||
missingTask name <span class="keyword">unless</span> tasks[name]
|
||||
tasks[name].action options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node's
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node's
|
||||
asynchrony may cause tasks to execute in a different order than you'd expect.
|
||||
If no tasks are passed, print the help screen. Keep a reference to the
|
||||
original directory name, when running Cake tasks from subdirectories.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.run = </span><span class="nf">-></span>
|
||||
<span class="nv">global.__originalDirname = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span> <span class="s">'.'</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>
|
||||
<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>
|
||||
<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">'Cakefile'</span><span class="p">).</span><span class="nx">toString</span><span class="p">(),</span> <span class="nv">filename: </span><span class="s">'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>
|
||||
<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="k">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>
|
||||
<span class="k">catch</span> <span class="nx">e</span>
|
||||
<span class="k">return</span> <span class="nx">fatalError</span> <span class="s">"</span><span class="si">#{</span><span class="nx">e</span><span class="si">}</span><span class="s">"</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>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = ->
|
||||
global.__originalDirname = fs.realpathSync <span class="string">'.'</span>
|
||||
process.chdir cakefileDirectory __originalDirname
|
||||
args = process.argv[<span class="number">2.</span>.]
|
||||
CoffeeScript.run fs.readFileSync(<span class="string">'Cakefile'</span>).toString(), filename: <span class="string">'Cakefile'</span>
|
||||
oparse = <span class="keyword">new</span> optparse.OptionParser switches
|
||||
<span class="keyword">return</span> printTasks() <span class="keyword">unless</span> args.length
|
||||
<span class="keyword">try</span>
|
||||
options = oparse.parse(args)
|
||||
<span class="keyword">catch</span> e
|
||||
<span class="keyword">return</span> fatalError <span class="string">"<span class="subst">#{e}</span>"</span>
|
||||
invoke arg <span class="keyword">for</span> arg <span class="keyword">in</span> options.arguments</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code>
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">printTasks = </span><span class="nf">-></span>
|
||||
<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>
|
||||
<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">'Cakefile'</span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">"</span><span class="si">#{</span><span class="nx">cakefilePath</span><span class="si">}</span><span class="s"> 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="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>
|
||||
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">></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">' '</span><span class="p">)</span> <span class="k">else</span> <span class="s">''</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">"</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">"</span> <span class="k">else</span> <span class="s">''</span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">"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">"</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>
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">printTasks</span></span> = ->
|
||||
relative = path.relative <span class="keyword">or</span> path.resolve
|
||||
cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="string">'Cakefile'</span>
|
||||
console.log <span class="string">"<span class="subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
|
||||
<span class="keyword">for</span> name, task <span class="keyword">of</span> tasks
|
||||
spaces = <span class="number">20</span> - name.length
|
||||
spaces = <span class="keyword">if</span> spaces > <span class="number">0</span> <span class="keyword">then</span> Array(spaces + <span class="number">1</span>).join(<span class="string">' '</span>) <span class="keyword">else</span> <span class="string">''</span>
|
||||
desc = <span class="keyword">if</span> task.description <span class="keyword">then</span> <span class="string">"# <span class="subst">#{task.description}</span>"</span> <span class="keyword">else</span> <span class="string">''</span>
|
||||
console.log <span class="string">"cake <span class="subst">#{name}</span><span class="subst">#{spaces}</span> <span class="subst">#{desc}</span>"</span>
|
||||
console.log oparse.help() <span class="keyword">if</span> switches.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Print an error and exit when attempting to use an invalid task/option.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Print an error and exit when attempting to use an invalid task/option.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">fatalError = </span><span class="nf">(message) -></span>
|
||||
<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">'\n'</span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">'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>
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">fatalError</span></span> = (message) ->
|
||||
console.error message + <span class="string">'\n'</span>
|
||||
console.log <span class="string">'To see a list of all tasks/options, run "cake"'</span>
|
||||
process.exit <span class="number">1</span>
|
||||
|
||||
<span class="nv">missingTask = </span><span class="nf">(task) -></span> <span class="nx">fatalError</span> <span class="s">"No such task: </span><span class="si">#{</span><span class="nx">task</span><span class="si">}</span><span class="s">"</span></pre></div></div>
|
||||
<span class="function"><span class="title">missingTask</span></span> = (task) -> fatalError <span class="string">"No such task: <span class="subst">#{task}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
|
||||
<p>When <code>cake</code> is invoked, search in the current and all parent directories
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>When <code>cake</code> is invoked, search in the current and all parent directories
|
||||
to find the relevant Cakefile.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">cakefileDirectory = </span><span class="nf">(dir) -></span>
|
||||
<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">'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">'..'</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="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"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">"</span>
|
||||
|
||||
</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">cakefileDirectory</span></span> = (dir) ->
|
||||
<span class="keyword">return</span> dir <span class="keyword">if</span> existsSync path.join dir, <span class="string">'Cakefile'</span>
|
||||
parent = path.normalize path.join dir, <span class="string">'..'</span>
|
||||
<span class="keyword">return</span> cakefileDirectory parent <span class="keyword">unless</span> parent <span class="keyword">is</span> dir
|
||||
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cakefile not found in <span class="subst">#{process.cwd()}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -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%; }
|
||||
body {
|
||||
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
|
||||
font-family: "aller-light";
|
||||
font-size: 14px;
|
||||
line-height: 16px;
|
||||
color: #252519;
|
||||
line-height: 18px;
|
||||
color: #30404f;
|
||||
margin: 0; padding: 0;
|
||||
height:100%;
|
||||
}
|
||||
#container { min-height: 100%; }
|
||||
|
||||
a {
|
||||
color: #261a3b;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #261a3b;
|
||||
b, strong {
|
||||
font-weight: normal;
|
||||
font-family: "aller-bold";
|
||||
}
|
||||
|
||||
p, ul, ol {
|
||||
margin: 15px 0;
|
||||
margin: 15px 0 0px;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -31,8 +69,8 @@ h1 {
|
|||
}
|
||||
|
||||
hr {
|
||||
border: 0 none;
|
||||
border-top: 1px solid #e5e5ee;
|
||||
border: 0;
|
||||
background: 1px solid #ddd;
|
||||
height: 1px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
@ -42,6 +80,35 @@ pre, tt, code {
|
|||
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
|
||||
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 {
|
||||
list-style: none;
|
||||
|
@ -133,10 +200,6 @@ ul.sections > li > div {
|
|||
padding:5px 10px 0 10px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
@ -172,11 +235,15 @@ ul.sections > li > div {
|
|||
body {
|
||||
background-color: #F5F5FF;
|
||||
font-size: 15px;
|
||||
line-height: 22px;
|
||||
line-height: 21px;
|
||||
}
|
||||
pre, tt, code {
|
||||
line-height: 18px;
|
||||
}
|
||||
p, ul, ol {
|
||||
margin: 0 0 15px;
|
||||
}
|
||||
|
||||
|
||||
#jump_to {
|
||||
padding: 5px 10px;
|
||||
|
@ -204,7 +271,7 @@ ul.sections > li > div {
|
|||
position: absolute;
|
||||
top: 0; bottom: 0;
|
||||
width: 350px;
|
||||
background: #ffffff;
|
||||
background: #fff;
|
||||
border-right: 1px solid #e5e5ee;
|
||||
z-index: -1;
|
||||
}
|
||||
|
@ -260,6 +327,12 @@ ul.sections > li > div {
|
|||
opacity: 0;
|
||||
-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 {
|
||||
opacity: 1;
|
||||
|
@ -269,6 +342,11 @@ ul.sections > li > div {
|
|||
/*---------------------- (> 1025px) ---------------------*/
|
||||
@media only screen and (min-width: 1025px) {
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
|
||||
#background {
|
||||
width: 525px;
|
||||
}
|
||||
|
@ -278,71 +356,145 @@ ul.sections > li > div {
|
|||
padding: 10px 25px 1px 50px;
|
||||
}
|
||||
ul.sections > li > div.content {
|
||||
padding: 14px 15px 16px 25px;
|
||||
padding: 9px 15px 16px 25px;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------- Syntax Highlighting -----------------------------*/
|
||||
|
||||
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
|
||||
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 */
|
||||
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 */
|
||||
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
|
||||
body .cs { color: #408080; font-style: italic } /* Comment.Special */
|
||||
body .gd { color: #A00000 } /* Generic.Deleted */
|
||||
body .ge { font-style: italic } /* Generic.Emph */
|
||||
body .gr { color: #FF0000 } /* Generic.Error */
|
||||
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
body .gi { color: #00A000 } /* Generic.Inserted */
|
||||
body .go { color: #808080 } /* Generic.Output */
|
||||
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
||||
body .gs { font-weight: bold } /* Generic.Strong */
|
||||
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
body .gt { color: #0040D0 } /* Generic.Traceback */
|
||||
body .kc { color: #954121 } /* Keyword.Constant */
|
||||
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
|
||||
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
|
||||
body .kp { color: #954121 } /* Keyword.Pseudo */
|
||||
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
|
||||
body .kt { color: #B00040 } /* Keyword.Type */
|
||||
body .m { color: #666666 } /* Literal.Number */
|
||||
body .s { color: #219161 } /* Literal.String */
|
||||
body .na { color: #7D9029 } /* Name.Attribute */
|
||||
body .nb { color: #954121 } /* Name.Builtin */
|
||||
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
||||
body .no { color: #880000 } /* Name.Constant */
|
||||
body .nd { color: #AA22FF } /* Name.Decorator */
|
||||
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
||||
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
|
||||
body .nf { color: #0000FF } /* Name.Function */
|
||||
body .nl { color: #A0A000 } /* Name.Label */
|
||||
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
||||
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
|
||||
body .nv { color: #19469D } /* Name.Variable */
|
||||
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
||||
body .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
body .mf { color: #666666 } /* Literal.Number.Float */
|
||||
body .mh { color: #666666 } /* Literal.Number.Hex */
|
||||
body .mi { color: #666666 } /* Literal.Number.Integer */
|
||||
body .mo { color: #666666 } /* Literal.Number.Oct */
|
||||
body .sb { color: #219161 } /* Literal.String.Backtick */
|
||||
body .sc { color: #219161 } /* Literal.String.Char */
|
||||
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
|
||||
body .s2 { color: #219161 } /* Literal.String.Double */
|
||||
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
|
||||
body .sh { color: #219161 } /* Literal.String.Heredoc */
|
||||
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
|
||||
body .sx { color: #954121 } /* Literal.String.Other */
|
||||
body .sr { color: #BB6688 } /* Literal.String.Regex */
|
||||
body .s1 { color: #219161 } /* Literal.String.Single */
|
||||
body .ss { color: #19469D } /* Literal.String.Symbol */
|
||||
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
|
||||
body .vc { color: #19469D } /* Name.Variable.Class */
|
||||
body .vg { color: #19469D } /* Name.Variable.Global */
|
||||
body .vi { color: #19469D } /* Name.Variable.Instance */
|
||||
body .il { color: #666666 } /* Literal.Number.Integer.Long */
|
||||
/*
|
||||
|
||||
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
|
||||
|
||||
*/
|
||||
|
||||
pre code {
|
||||
display: block; padding: 0.5em;
|
||||
color: #000;
|
||||
background: #f8f8ff
|
||||
}
|
||||
|
||||
pre .comment,
|
||||
pre .template_comment,
|
||||
pre .diff .header,
|
||||
pre .javadoc {
|
||||
color: #408080;
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
pre .keyword,
|
||||
pre .assignment,
|
||||
pre .literal,
|
||||
pre .css .rule .keyword,
|
||||
pre .winutils,
|
||||
pre .javascript .title,
|
||||
pre .lisp .title,
|
||||
pre .subst {
|
||||
color: #954121;
|
||||
/*font-weight: bold*/
|
||||
}
|
||||
|
||||
pre .number,
|
||||
pre .hexcolor {
|
||||
color: #40a070
|
||||
}
|
||||
|
||||
pre .string,
|
||||
pre .tag .value,
|
||||
pre .phpdoc,
|
||||
pre .tex .formula {
|
||||
color: #219161;
|
||||
}
|
||||
|
||||
pre .title,
|
||||
pre .id {
|
||||
color: #19469D;
|
||||
}
|
||||
pre .params {
|
||||
color: #00F;
|
||||
}
|
||||
|
||||
pre .javascript .title,
|
||||
pre .lisp .title,
|
||||
pre .subst {
|
||||
font-weight: normal
|
||||
}
|
||||
|
||||
pre .class .title,
|
||||
pre .haskell .label,
|
||||
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
|
@ -92,510 +92,492 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>helpers.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>helpers.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
</div>
|
||||
<p>This file contains the common helper functions that we'd like to share among
|
||||
the <strong>Lexer</strong>, <strong>Rewriter</strong>, and the <strong>Nodes</strong>. Merge objects, flatten
|
||||
arrays, count characters, that sort of thing.
|
||||
|
||||
</p>
|
||||
<p>Peek at the beginning of a given string to see if it matches a sequence.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.starts = </span><span class="nf">(string, literal, start) -></span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">starts</span></span> = (string, literal, start) ->
|
||||
literal <span class="keyword">is</span> string.substr start, literal.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Peek at the end of a given string to see if it matches a sequence.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>Peek at the end of a given string to see if it matches a sequence.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.ends = </span><span class="nf">(string, literal, back) -></span>
|
||||
<span class="nv">len = </span><span class="nx">literal</span><span class="p">.</span><span class="nx">length</span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">ends</span></span> = (string, literal, back) ->
|
||||
len = literal.length
|
||||
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 id="section-3">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Repeat a string <code>n</code> times.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Repeat a string <code>n</code> times.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.repeat = repeat = </span><span class="nf">(str, n) -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.repeat = <span class="function"><span class="title">repeat</span></span> = (str, n) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Use clever algorithm to have O(log(n)) string concatenation operations.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Use clever algorithm to have O(log(n)) string concatenation operations.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">res = </span><span class="s">''</span>
|
||||
<span class="k">while</span> <span class="nx">n</span> <span class="o">></span> <span class="mi">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">&</span> <span class="mi">1</span>
|
||||
<span class="nx">n</span> <span class="o">>>>=</span> <span class="mi">1</span>
|
||||
<span class="nx">str</span> <span class="o">+=</span> <span class="nx">str</span>
|
||||
<span class="nx">res</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> res = <span class="string">''</span>
|
||||
<span class="keyword">while</span> n > <span class="number">0</span>
|
||||
res += str <span class="keyword">if</span> n & <span class="number">1</span>
|
||||
n >>>= <span class="number">1</span>
|
||||
str += str
|
||||
res</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Trim out all falsy values from an array.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Trim out all falsy values from an array.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.compact = </span><span class="nf">(array) -></span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">compact</span></span> = (array) ->
|
||||
item <span class="keyword">for</span> item <span class="keyword">in</span> array <span class="keyword">when</span> item</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Count the number of occurrences of a string in a string.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Count the number of occurrences of a string in a string.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.count = </span><span class="nf">(string, substr) -></span>
|
||||
<span class="nv">num = pos = </span><span class="mi">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="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>
|
||||
<span class="nx">num</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">count</span></span> = (string, substr) ->
|
||||
num = pos = <span class="number">0</span>
|
||||
<span class="keyword">return</span> <span class="number">1</span>/<span class="number">0</span> <span class="keyword">unless</span> substr.length
|
||||
num++ <span class="keyword">while</span> pos = <span class="number">1</span> + string.indexOf substr, pos
|
||||
num</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Merge objects, returning a fresh copy with attributes from both sides.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<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
|
||||
options hash to propagate down the tree without polluting other branches.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.merge = </span><span class="nf">(options, overrides) -></span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">merge</span></span> = (options, overrides) ->
|
||||
extend (extend {}, options), overrides</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Extend a source object with the properties of another object (shallow copy).
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Extend a source object with the properties of another object (shallow copy).
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">extend = exports.extend = </span><span class="nf">(object, properties) -></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">properties</span>
|
||||
<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>
|
||||
<span class="nx">object</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>extend = exports.<span class="function"><span class="title">extend</span></span> = (object, properties) ->
|
||||
<span class="keyword">for</span> key, val <span class="keyword">of</span> properties
|
||||
object[key] = val
|
||||
object</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Return a flattened version of an array.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Return a flattened version of an array.
|
||||
Handy for getting a list of <code>children</code> from the nodes.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.flatten = flatten = </span><span class="nf">(array) -></span>
|
||||
<span class="nv">flattened = </span><span class="p">[]</span>
|
||||
<span class="k">for</span> <span class="nx">element</span> <span class="k">in</span> <span class="nx">array</span>
|
||||
<span class="k">if</span> <span class="nx">element</span> <span class="k">instanceof</span> <span class="nb">Array</span>
|
||||
<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>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">flattened</span><span class="p">.</span><span class="nx">push</span> <span class="nx">element</span>
|
||||
<span class="nx">flattened</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.flatten = <span class="function"><span class="title">flatten</span></span> = (array) ->
|
||||
flattened = []
|
||||
<span class="keyword">for</span> element <span class="keyword">in</span> array
|
||||
<span class="keyword">if</span> element <span class="keyword">instanceof</span> Array
|
||||
flattened = flattened.concat flatten element
|
||||
<span class="keyword">else</span>
|
||||
flattened.push element
|
||||
flattened</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Delete a key from an object, returning the value. Useful when a node is
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Delete a key from an object, returning the value. Useful when a node is
|
||||
looking for a particular method in an options hash.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.del = </span><span class="nf">(obj, key) -></span>
|
||||
<span class="nv">val = </span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span>
|
||||
<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="nx">val</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">del</span></span> = (obj, key) ->
|
||||
val = obj[key]
|
||||
<span class="keyword">delete</span> obj[key]
|
||||
val</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Gets the last item of an array(-like) object.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Gets the last item of an array(-like) object.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.last = last = </span><span class="nf">(array, back) -></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) -> array[array.length - (back <span class="keyword">or</span> <span class="number">0</span>) - <span class="number">1</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Typical Array::some
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Typical Array::some
|
||||
</p>
|
||||
|
||||
</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) -></span>
|
||||
<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="kc">false</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.some = Array::some ? (fn) ->
|
||||
<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="literal">false</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Simple function for inverting Literate CoffeeScript code by putting the
|
||||
documentation in comments, and bumping the actual code back out to the edge ...
|
||||
producing a string of CoffeeScript code that can be compiled "normally".
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Simple function for inverting Literate CoffeeScript code by putting the
|
||||
documentation in comments, producing a string of CoffeeScript code that
|
||||
can be compiled "normally".
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.invertLiterate = </span><span class="nf">(code) -></span>
|
||||
<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">'\n'</span><span class="p">)</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>
|
||||
<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="k">else</span>
|
||||
<span class="s">'# '</span> <span class="o">+</span> <span class="nx">line</span>
|
||||
<span class="nx">lines</span><span class="p">.</span><span class="nx">join</span> <span class="s">'\n'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">invertLiterate</span></span> = (code) ->
|
||||
maybe_code = <span class="literal">true</span>
|
||||
lines = <span class="keyword">for</span> line <span class="keyword">in</span> code.split(<span class="string">'\n'</span>)
|
||||
<span class="keyword">if</span> maybe_code <span class="keyword">and</span> <span class="regexp">/^([ ]{4}|[ ]{0,3}\t)/</span>.test line
|
||||
line
|
||||
<span class="keyword">else</span> <span class="keyword">if</span> maybe_code = <span class="regexp">/^\s*$/</span>.test line
|
||||
line
|
||||
<span class="keyword">else</span>
|
||||
<span class="string">'# '</span> + line
|
||||
lines.join <span class="string">'\n'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Merge two jison-style location data objects together.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Merge two jison-style location data objects together.
|
||||
If <code>last</code> is not provided, this will simply return <code>first</code>.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">buildLocationData = </span><span class="nf">(first, last) -></span>
|
||||
<span class="k">if</span> <span class="o">not</span> <span class="nx">last</span>
|
||||
<span class="nx">first</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">first_line: </span><span class="nx">first</span><span class="p">.</span><span class="nx">first_line</span>
|
||||
<span class="nv">first_column: </span><span class="nx">first</span><span class="p">.</span><span class="nx">first_column</span>
|
||||
<span class="nv">last_line: </span><span class="nx">last</span><span class="p">.</span><span class="nx">last_line</span>
|
||||
<span class="nv">last_column: </span><span class="nx">last</span><span class="p">.</span><span class="nx">last_column</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildLocationData</span></span> = (first, last) ->
|
||||
<span class="keyword">if</span> <span class="keyword">not</span> last
|
||||
first
|
||||
<span class="keyword">else</span>
|
||||
first_line: first.first_line
|
||||
first_column: first.first_column
|
||||
last_line: last.last_line
|
||||
last_column: last.last_column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
|
||||
<p>This returns a function which takes an object as a parameter, and if that
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>This returns a function which takes an object as a parameter, and if that
|
||||
object is an AST node, updates that object's locationData.
|
||||
The object is returned either way.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.addLocationDataFn = </span><span class="nf">(first, last) -></span>
|
||||
<span class="nf">(obj) -></span>
|
||||
<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">'object'</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">'updateLocationDataIfMissing'</span><span class="p">])</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>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">addLocationDataFn</span></span> = (first, last) ->
|
||||
(obj) ->
|
||||
<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>])
|
||||
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 id="section-16">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Convert jison location data to a string.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>Convert jison location data to a string.
|
||||
<code>obj</code> can be a token, or a locationData.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.locationDataToString = </span><span class="nf">(obj) -></span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="s">"2"</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">"first_line"</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="k">else</span> <span class="k">if</span> <span class="s">"first_line"</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>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">locationDataToString</span></span> = (obj) ->
|
||||
<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="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="s">"</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">-"</span> <span class="o">+</span>
|
||||
<span class="s">"</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">"</span>
|
||||
<span class="k">else</span>
|
||||
<span class="s">"No location data"</span></pre></div></div>
|
||||
<span class="keyword">if</span> locationData
|
||||
<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="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="keyword">else</span>
|
||||
<span class="string">"No location data"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
|
||||
<p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.baseFileName = </span><span class="nf">(file, stripExt = no) -></span>
|
||||
<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">'/'</span><span class="p">)</span>
|
||||
<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>
|
||||
<span class="k">return</span> <span class="nx">file</span> <span class="k">unless</span> <span class="nx">stripExt</span>
|
||||
<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">'.'</span><span class="p">)</span>
|
||||
<span class="nx">parts</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
|
||||
<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">'coffee'</span> <span class="o">and</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="nx">parts</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">'.'</span><span class="p">)</span></pre></div></div>
|
||||
<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>) ->
|
||||
parts = file.split(pathSep)
|
||||
file = parts[parts.length - <span class="number">1</span>]
|
||||
<span class="keyword">return</span> file <span class="keyword">unless</span> stripExt
|
||||
parts = file.split(<span class="string">'.'</span>)
|
||||
parts.pop()
|
||||
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 > <span class="number">1</span>
|
||||
parts.join(<span class="string">'.'</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Determine if a filename represents a CoffeeScript file.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a CoffeeScript file.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.isCoffee = </span><span class="nf">(file) -></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) -> <span class="regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Determine if a filename represents a Literate CoffeeScript file.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a Literate CoffeeScript file.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.isLiterate = </span><span class="nf">(file) -></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) -> <span class="regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Throws a SyntaxError with a source file location data attached to it in a
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>Throws a SyntaxError with a source file location data attached to it in a
|
||||
property called <code>location</code>.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.throwSyntaxError = </span><span class="nf">(message, location) -></span>
|
||||
<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>
|
||||
<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>
|
||||
<span class="nv">error = </span><span class="k">new</span> <span class="nx">SyntaxError</span> <span class="nx">message</span>
|
||||
<span class="nv">error.location = </span><span class="nx">location</span>
|
||||
<span class="k">throw</span> <span class="nx">error</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">throwSyntaxError</span></span> = (message, location) ->
|
||||
location.last_line ?= location.first_line
|
||||
location.last_column ?= location.first_column
|
||||
error = <span class="keyword">new</span> SyntaxError message
|
||||
error.location = location
|
||||
<span class="keyword">throw</span> error</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Creates a nice error message like, following the "standard" format
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Creates a nice error message like, following the "standard" format
|
||||
</p>
|
||||
<p><filename>:<line>:<col>: <message> plus the line with the error and a marker
|
||||
showing where the error is.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.prettyErrorMessage = </span><span class="nf">(error, fileName, code, useColors) -></span>
|
||||
<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">"</span><span class="si">#{</span><span class="nx">error</span><span class="si">}</span><span class="s">"</span> <span class="k">unless</span> <span class="nx">error</span><span class="p">.</span><span class="nx">location</span>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">prettyErrorMessage</span></span> = (error, fileName, code, useColors) ->
|
||||
<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>
|
||||
<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">'\n'</span><span class="p">)[</span><span class="nx">first_line</span><span class="p">]</span>
|
||||
<span class="nv">start = </span><span class="nx">first_column</span></pre></div></div>
|
||||
{first_line, first_column, last_line, last_column} = error.location
|
||||
codeLine = code.split(<span class="string">'\n'</span>)[first_line]
|
||||
start = first_column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Show only the first line on multi-line errors.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Show only the first line on multi-line errors.
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nv">marker = </span><span class="nx">repeat</span><span class="p">(</span><span class="s">' '</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">'^'</span><span class="p">,</span> <span class="nx">end</span> <span class="o">-</span> <span class="nx">start</span><span class="p">)</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
|
||||
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="nv">colorize = </span><span class="nf">(str) -></span> <span class="s">"\x1B[1;31m</span><span class="si">#{</span><span class="nx">str</span><span class="si">}</span><span class="s">\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>
|
||||
<span class="nv">marker = </span><span class="nx">colorize</span> <span class="nx">marker</span>
|
||||
<span class="keyword">if</span> useColors
|
||||
<span class="function"><span class="title">colorize</span></span> = (str) -> <span class="string">"\x1B[1;31m<span class="subst">#{str}</span>\x1B[0m"</span>
|
||||
codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
|
||||
marker = colorize marker
|
||||
|
||||
<span class="nv">message = </span><span class="s">"""</span>
|
||||
<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="s"> </span><span class="si">#{</span><span class="nx">codeLine</span><span class="si">}</span><span class="s"></span>
|
||||
<span class="s"> </span><span class="si">#{</span><span class="nx">marker</span><span class="si">}</span><span class="s"></span>
|
||||
<span class="s"> """</span></pre></div></div>
|
||||
message = <span class="string">"""
|
||||
<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="subst">#{codeLine}</span>
|
||||
<span class="subst">#{marker}</span>
|
||||
"""</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Uncomment to add stacktrace.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>Uncomment to add stacktrace.
|
||||
message += "\n#{error.stack}"
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nx">message</span>
|
||||
|
||||
</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> message</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -92,31 +92,32 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>index.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>index.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
</div>
|
||||
<p>Loader for CoffeeScript as a Node.js library.
|
||||
</p>
|
||||
|
||||
</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">'./coffee-script'</span>
|
||||
|
||||
</pre></div></div>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -92,19 +92,22 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>optparse.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>optparse.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
</div>
|
||||
<p>A simple <strong>OptionParser</strong> class to parse option flags from the command-line.
|
||||
Use it like so:
|
||||
|
||||
|
@ -113,229 +116,231 @@ Use it like so:
|
|||
options = parser.parse process.argv</code></pre>
|
||||
<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.
|
||||
|
||||
</p>
|
||||
|
||||
</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 id="section-2">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Initialize with a list of valid options, in the form:
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>Initialize with a list of valid options, in the form:
|
||||
|
||||
</p>
|
||||
<pre><code>[short-flag, long-flag, description]</code></pre>
|
||||
<p>Along with an an optional banner for the usage help.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(rules, @banner) -></span>
|
||||
<span class="vi">@rules = </span><span class="nx">buildRules</span> <span class="nx">rules</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> constructor: (rules, <span class="property">@banner</span>) ->
|
||||
<span class="property">@rules</span> = buildRules rules</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Parse the list of arguments, populating an <code>options</code> object with all of the
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<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
|
||||
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
|
||||
parsers that allow you to attach callback actions for every flag. Instead,
|
||||
you're responsible for interpreting the options object.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">parse: </span><span class="nf">(args) -></span>
|
||||
<span class="nv">options = arguments: </span><span class="p">[]</span>
|
||||
<span class="nv">skippingArgument = </span><span class="kc">no</span>
|
||||
<span class="nv">originalArgs = </span><span class="nx">args</span>
|
||||
<span class="nv">args = </span><span class="nx">normalizeArguments</span> <span class="nx">args</span>
|
||||
<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="k">if</span> <span class="nx">skippingArgument</span>
|
||||
<span class="nv">skippingArgument = </span><span class="kc">no</span>
|
||||
<span class="k">continue</span>
|
||||
<span class="k">if</span> <span class="nx">arg</span> <span class="o">is</span> <span class="s">'--'</span>
|
||||
<span class="nv">pos = </span><span class="nx">originalArgs</span><span class="p">.</span><span class="nx">indexOf</span> <span class="s">'--'</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>
|
||||
<span class="k">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>
|
||||
<div class="content"><div class='highlight'><pre> parse: (args) ->
|
||||
options = arguments: []
|
||||
skippingArgument = <span class="literal">no</span>
|
||||
originalArgs = args
|
||||
args = normalizeArguments args
|
||||
<span class="keyword">for</span> arg, i <span class="keyword">in</span> args
|
||||
<span class="keyword">if</span> skippingArgument
|
||||
skippingArgument = <span class="literal">no</span>
|
||||
<span class="keyword">continue</span>
|
||||
<span class="keyword">if</span> arg <span class="keyword">is</span> <span class="string">'--'</span>
|
||||
pos = originalArgs.indexOf <span class="string">'--'</span>
|
||||
options.arguments = options.arguments.concat originalArgs[(pos + <span class="number">1</span>)..]
|
||||
<span class="keyword">break</span>
|
||||
isOption = !!(arg.match(LONG_FLAG) <span class="keyword">or</span> arg.match(SHORT_FLAG))</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
<p>the CS option parser is a little odd; options after the first
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>the CS option parser is a little odd; options after the first
|
||||
non-option argument are treated as non-option arguments themselves
|
||||
|
||||
</p>
|
||||
|
||||
</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">></span> <span class="mi">0</span>
|
||||
<span class="k">unless</span> <span class="nx">seenNonOptionArg</span>
|
||||
<span class="nv">matchedRule = </span><span class="kc">no</span>
|
||||
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@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="nv">value = </span><span class="kc">true</span>
|
||||
<span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">hasArgument</span>
|
||||
<span class="nv">skippingArgument = </span><span class="kc">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>
|
||||
<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>
|
||||
<span class="nv">matchedRule = </span><span class="kc">yes</span>
|
||||
<span class="k">break</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"unrecognized option: </span><span class="si">#{</span><span class="nx">arg</span><span class="si">}</span><span class="s">"</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="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="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>
|
||||
<span class="nx">options</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> seenNonOptionArg = options.arguments.length > <span class="number">0</span>
|
||||
<span class="keyword">unless</span> seenNonOptionArg
|
||||
matchedRule = <span class="literal">no</span>
|
||||
<span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</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
|
||||
value = <span class="literal">true</span>
|
||||
<span class="keyword">if</span> rule.hasArgument
|
||||
skippingArgument = <span class="literal">yes</span>
|
||||
value = args[i + <span class="number">1</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
|
||||
matchedRule = <span class="literal">yes</span>
|
||||
<span class="keyword">break</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="keyword">if</span> seenNonOptionArg <span class="keyword">or</span> <span class="keyword">not</span> isOption
|
||||
options.arguments.push arg
|
||||
options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Return the help text for this <strong>OptionParser</strong>, listing and describing all
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Return the help text for this <strong>OptionParser</strong>, listing and describing all
|
||||
of the valid options, for <code>--help</code> and such.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">help: </span><span class="nf">-></span>
|
||||
<span class="nv">lines = </span><span class="p">[]</span>
|
||||
<span class="nx">lines</span><span class="p">.</span><span class="nx">unshift</span> <span class="s">"</span><span class="si">#{</span><span class="nx">@banner</span><span class="si">}</span><span class="s">\n"</span> <span class="k">if</span> <span class="nx">@banner</span>
|
||||
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@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>
|
||||
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">></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">' '</span><span class="p">)</span> <span class="k">else</span> <span class="s">''</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">', '</span> <span class="k">else</span> <span class="s">' '</span>
|
||||
<span class="nx">lines</span><span class="p">.</span><span class="nx">push</span> <span class="s">' '</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>
|
||||
<span class="s">"\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">'\n'</span><span class="p">)</span> <span class="si">}</span><span class="s">\n"</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> help: ->
|
||||
lines = []
|
||||
lines.unshift <span class="string">"<span class="subst">#{@banner}</span>\n"</span> <span class="keyword">if</span> <span class="property">@banner</span>
|
||||
<span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</span>
|
||||
spaces = <span class="number">15</span> - rule.longFlag.length
|
||||
spaces = <span class="keyword">if</span> spaces > <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>
|
||||
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>
|
||||
lines.push <span class="string">' '</span> + letPart + rule.longFlag + spaces + rule.description
|
||||
<span class="string">"\n<span class="subst">#{ lines.join('\n') }</span>\n"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
|
||||
<h2>Helpers</h2>
|
||||
<p>Regex matchers for option flags.
|
||||
|
||||
</p>
|
||||
<div class="pilwrap for-h2">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<h2>Helpers</h2>
|
||||
|
||||
</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 id="section-7">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
<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>.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Regex matchers for option flags.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">buildRules = </span><span class="nf">(rules) -></span>
|
||||
<span class="k">for</span> <span class="nx">tuple</span> <span class="k">in</span> <span class="nx">rules</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"><</span> <span class="mi">3</span>
|
||||
<span class="nx">buildRule</span> <span class="nx">tuple</span><span class="p">...</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>LONG_FLAG = <span class="regexp">/^(--\w[\w\-]*)/</span>
|
||||
SHORT_FLAG = <span class="regexp">/^(-\w)$/</span>
|
||||
MULTI_FLAG = <span class="regexp">/^-(\w{2,})/</span>
|
||||
OPTIONAL = <span class="regexp">/\[(\w+(\*?))\]/</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</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.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">buildRule = </span><span class="nf">(shortFlag, longFlag, description, options = {}) -></span>
|
||||
<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="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>
|
||||
<span class="p">{</span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildRules</span></span> = (rules) ->
|
||||
<span class="keyword">for</span> tuple <span class="keyword">in</span> rules
|
||||
tuple.unshift <span class="literal">null</span> <span class="keyword">if</span> tuple.length < <span class="number">3</span>
|
||||
buildRule tuple...</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Normalize arguments by expanding merged flags into multiple flags. This allows
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</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 = {}) ->
|
||||
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">¶</a>
|
||||
</div>
|
||||
<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>.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">normalizeArguments = </span><span class="nf">(args) -></span>
|
||||
<span class="nv">args = </span><span class="nx">args</span><span class="p">[..]</span>
|
||||
<span class="nv">result = </span><span class="p">[]</span>
|
||||
<span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">args</span>
|
||||
<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="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="s">'-'</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">''</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="nx">arg</span>
|
||||
<span class="nx">result</span>
|
||||
|
||||
</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">normalizeArguments</span></span> = (args) ->
|
||||
args = args[..]
|
||||
result = []
|
||||
<span class="keyword">for</span> arg <span class="keyword">in</span> args
|
||||
<span class="keyword">if</span> match = arg.match MULTI_FLAG
|
||||
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="keyword">else</span>
|
||||
result.push arg
|
||||
result</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
BIN
documentation/docs/public/fonts/aller-bold.eot
Executable file
BIN
documentation/docs/public/fonts/aller-bold.eot
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-bold.ttf
Executable file
BIN
documentation/docs/public/fonts/aller-bold.ttf
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-bold.woff
Executable file
BIN
documentation/docs/public/fonts/aller-bold.woff
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-light.eot
Executable file
BIN
documentation/docs/public/fonts/aller-light.eot
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-light.ttf
Executable file
BIN
documentation/docs/public/fonts/aller-light.ttf
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-light.woff
Executable file
BIN
documentation/docs/public/fonts/aller-light.woff
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/novecento-bold.eot
Executable file
BIN
documentation/docs/public/fonts/novecento-bold.eot
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/novecento-bold.ttf
Executable file
BIN
documentation/docs/public/fonts/novecento-bold.ttf
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/novecento-bold.woff
Executable file
BIN
documentation/docs/public/fonts/novecento-bold.woff
Executable file
Binary file not shown.
375
documentation/docs/public/stylesheets/normalize.css
vendored
Normal file
375
documentation/docs/public/stylesheets/normalize.css
vendored
Normal 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;
|
||||
}
|
|
@ -92,289 +92,271 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>repl.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>repl.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">vm = </span><span class="nx">require</span> <span class="s">'vm'</span>
|
||||
<span class="nv">nodeREPL = </span><span class="nx">require</span> <span class="s">'repl'</span>
|
||||
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">'./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">'./helpers'</span>
|
||||
<div class="content"><div class='highlight'><pre>vm = require <span class="string">'vm'</span>
|
||||
nodeREPL = require <span class="string">'repl'</span>
|
||||
CoffeeScript = require <span class="string">'./coffee-script'</span>
|
||||
{merge, prettyErrorMessage} = require <span class="string">'./helpers'</span>
|
||||
|
||||
<span class="nv">replDefaults =</span>
|
||||
<span class="nv">prompt: </span><span class="s">'coffee> '</span><span class="p">,</span>
|
||||
<span class="nb">eval</span><span class="o">:</span> <span class="nf">(input, context, filename, cb) -></span></pre></div></div>
|
||||
replDefaults =
|
||||
prompt: <span class="string">'coffee> '</span>,
|
||||
eval: (input, context, filename, cb) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
|
||||
<p>XXX: multiline hack.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>XXX: multiline hack.
|
||||
</p>
|
||||
|
||||
</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">'\n'</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 id="section-3">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Node's REPL sends the input ending with a newline and then wrapped in
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Node's REPL sends the input ending with a newline and then wrapped in
|
||||
parens. Unwrap all that.
|
||||
|
||||
</p>
|
||||
|
||||
</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">'$1'</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 id="section-4">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Require AST nodes to do some AST manipulation.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Require AST nodes to do some AST manipulation.
|
||||
</p>
|
||||
|
||||
</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">'./nodes'</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 id="section-5">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
|
||||
<p>TODO: fix #1829: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Generate the AST of the clean input.
|
||||
</p>
|
||||
|
||||
</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 id="section-6">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Generate the AST of the clean input.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Add assignment to <code>_</code> variable to force the input to be an expression.
|
||||
</p>
|
||||
|
||||
</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) ->
|
||||
{rli, inputStream, outputStream} = repl
|
||||
|
||||
multiline =
|
||||
enabled: <span class="literal">off</span>
|
||||
initialPrompt: repl.prompt.replace(<span class="regexp">/^[^> ]*/, (x) -> x.replace /./g</span>, <span class="string">'-'</span>)
|
||||
prompt: repl.prompt.replace(<span class="regexp">/^[^> ]*>?/, (x) -> x.replace /./g</span>, <span class="string">'.'</span>)
|
||||
buffer: <span class="string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Add assignment to <code>_</code> variable to force the input to be an expression.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Proxy node's line listener
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<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">'_'</span><span class="p">),</span> <span class="nx">ast</span><span class="p">,</span> <span class="s">'='</span>
|
||||
<span class="p">]</span>
|
||||
<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="k">catch</span> <span class="nx">err</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>
|
||||
<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>
|
||||
|
||||
<span class="nv">addMultilineHandler = </span><span class="nf">(repl) -></span>
|
||||
<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="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">/^[^> ]*/</span><span class="p">,</span> <span class="nf">(x) -></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">'-'</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">/^[^> ]*>?/</span><span class="p">,</span> <span class="nf">(x) -></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">'.'</span><span class="p">)</span>
|
||||
<span class="nv">buffer: </span><span class="s">''</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> nodeLineListener = rli.listeners(<span class="string">'line'</span>)[<span class="number">0</span>]
|
||||
rli.removeListener <span class="string">'line'</span>, nodeLineListener
|
||||
rli.<span class="literal">on</span> <span class="string">'line'</span>, (cmd) ->
|
||||
<span class="keyword">if</span> multiline.enabled
|
||||
multiline.buffer += <span class="string">"<span class="subst">#{cmd}</span>\n"</span>
|
||||
rli.setPrompt multiline.prompt
|
||||
rli.prompt <span class="literal">true</span>
|
||||
<span class="keyword">else</span>
|
||||
nodeLineListener cmd
|
||||
<span class="keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Proxy node's line listener
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Handle Ctrl-v
|
||||
</p>
|
||||
|
||||
</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">'line'</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">removeListener</span> <span class="s">'line'</span><span class="p">,</span> <span class="nx">nodeLineListener</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">on</span> <span class="s">'line'</span><span class="p">,</span> <span class="nf">(cmd) -></span>
|
||||
<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">"</span><span class="si">#{</span><span class="nx">cmd</span><span class="si">}</span><span class="s">\n"</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>
|
||||
<div class="content"><div class='highlight'><pre> inputStream.<span class="literal">on</span> <span class="string">'keypress'</span>, (char, key) ->
|
||||
<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="keyword">if</span> multiline.enabled</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Handle Ctrl-v
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>allow arbitrarily switching between modes any time before multiple lines are entered
|
||||
</p>
|
||||
|
||||
</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">'keypress'</span><span class="p">,</span> <span class="nf">(char, key) -></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">'v'</span>
|
||||
<span class="k">if</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">unless</span> multiline.buffer.match <span class="regexp">/\n/</span>
|
||||
multiline.enabled = <span class="keyword">not</span> multiline.enabled
|
||||
rli.setPrompt repl.prompt
|
||||
rli.prompt <span class="literal">true</span>
|
||||
<span class="keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
|
||||
<p>allow arbitrarily switching between modes any time before multiple lines are entered
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>no-op unless the current line is empty
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
|
||||
<p>no-op unless the current line is empty
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>eval, print, loop
|
||||
</p>
|
||||
|
||||
</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 id="section-12">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
|
||||
<p>eval, print, loop
|
||||
|
||||
</div>
|
||||
<p>XXX: multiline hack
|
||||
</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">''</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>
|
||||
<div class="content"><div class='highlight'><pre> multiline.buffer = multiline.buffer.replace <span class="regexp">/\n/g</span>, <span class="string">'\uFF00'</span>
|
||||
rli.emit <span class="string">'line'</span>, multiline.buffer
|
||||
multiline.buffer = <span class="string">''</span>
|
||||
<span class="keyword">else</span>
|
||||
multiline.enabled = <span class="keyword">not</span> multiline.enabled
|
||||
rli.setPrompt multiline.initialPrompt
|
||||
rli.prompt <span class="literal">true</span>
|
||||
<span class="keyword">return</span>
|
||||
|
||||
module.exports =
|
||||
start: (opts = {}) ->
|
||||
[major, minor, build] = process.versions.node.split(<span class="string">'.'</span>).map (n) -> parseInt(n)
|
||||
|
||||
<span class="keyword">if</span> major <span class="keyword">is</span> <span class="number">0</span> <span class="keyword">and</span> minor < <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>, -> repl.outputStream.write <span class="string">'\n'</span>
|
||||
addMultilineHandler repl
|
||||
repl</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
|
||||
<p>XXX: multiline hack
|
||||
</p>
|
||||
|
||||
</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">'\uFF00'</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">emit</span> <span class="s">'line'</span><span class="p">,</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span>
|
||||
<span class="nv">multiline.buffer = </span><span class="s">''</span>
|
||||
<span class="k">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>
|
||||
<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>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">prompt</span> <span class="kc">true</span>
|
||||
<span class="k">return</span>
|
||||
|
||||
<span class="nv">module.exports =</span>
|
||||
<span class="nv">start: </span><span class="nf">(opts = {}) -></span>
|
||||
<span class="nv">opts = </span><span class="nx">merge</span> <span class="nx">replDefaults</span><span class="p">,</span> <span class="nx">opts</span>
|
||||
<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">'exit'</span><span class="p">,</span> <span class="nf">-></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">'\n'</span>
|
||||
<span class="nx">addMultilineHandler</span> <span class="nx">repl</span>
|
||||
<span class="nx">repl</span>
|
||||
|
||||
</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -92,19 +92,22 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>scope.litcoffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>scope.litcoffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
</div>
|
||||
<p>The <strong>Scope</strong> class regulates lexical scoping within CoffeeScript. As you
|
||||
generate code, you create a tree of scopes in the same shape as the nested
|
||||
function bodies. Each scope knows about the variables declared within it,
|
||||
|
@ -115,319 +118,303 @@ with external scopes.
|
|||
</p>
|
||||
<p>Import the helpers we plan to use.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</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">'./helpers'</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 id="section-2">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
|
||||
<p>The <code>root</code> is the top-level <strong>Scope</strong> object for a given file.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>The <code>root</code> is the top-level <strong>Scope</strong> object for a given file.
|
||||
|
||||
</p>
|
||||
|
||||
</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 id="section-3">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Initialize a scope with its parent, for lookups up the chain,
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<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
|
||||
where it should declare its variables, and a reference to the function that
|
||||
it belongs to.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(@parent, @expressions, @method) -></span>
|
||||
<span class="vi">@variables = </span><span class="p">[{</span><span class="nv">name: </span><span class="s">'arguments'</span><span class="p">,</span> <span class="nv">type: </span><span class="s">'arguments'</span><span class="p">}]</span>
|
||||
<span class="vi">@positions = </span><span class="p">{}</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>
|
||||
<div class="content"><div class='highlight'><pre> constructor: (<span class="property">@parent</span>, <span class="property">@expressions</span>, <span class="property">@method</span>) ->
|
||||
<span class="property">@variables</span> = [{name: <span class="string">'arguments'</span>, type: <span class="string">'arguments'</span>}]
|
||||
<span class="property">@positions</span> = {}
|
||||
Scope.root = <span class="keyword">this</span> <span class="keyword">unless</span> <span class="property">@parent</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Adds a new variable or overrides an existing one.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Adds a new variable or overrides an existing one.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">add: </span><span class="nf">(name, type, immediate) -></span>
|
||||
<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="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="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="k">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>
|
||||
<div class="content"><div class='highlight'><pre> add: (name, type, immediate) ->
|
||||
<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="keyword">if</span> Object::hasOwnProperty.call <span class="property">@positions</span>, name
|
||||
<span class="property">@variables</span>[<span class="property">@positions</span>[name]].type = type
|
||||
<span class="keyword">else</span>
|
||||
<span class="property">@positions</span>[name] = <span class="property">@variables</span>.push({name, type}) - <span class="number">1</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
|
||||
<p>When <code>super</code> is called, we need to find the name of the current method we're
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>When <code>super</code> is called, we need to find the name of the current method we're
|
||||
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.
|
||||
<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.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">namedMethod: </span><span class="nf">-></span>
|
||||
<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="nx">@parent</span><span class="p">.</span><span class="nx">namedMethod</span><span class="p">()</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> namedMethod: ->
|
||||
<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="property">@parent</span>.namedMethod()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Look up a variable name in lexical scope, and declare it if it does not
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Look up a variable name in lexical scope, and declare it if it does not
|
||||
already exist.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">find: </span><span class="nf">(name) -></span>
|
||||
<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="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s">'var'</span>
|
||||
<span class="kc">no</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> find: (name) ->
|
||||
<span class="keyword">return</span> <span class="literal">yes</span> <span class="keyword">if</span> <span class="property">@check</span> name
|
||||
<span class="property">@add</span> name, <span class="string">'var'</span>
|
||||
<span class="literal">no</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Reserve a variable name as originating from a function parameter for this
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Reserve a variable name as originating from a function parameter for this
|
||||
scope. No <code>var</code> required for internal references.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">parameter: </span><span class="nf">(name) -></span>
|
||||
<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="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s">'param'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> parameter: (name) ->
|
||||
<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="property">@add</span> name, <span class="string">'param'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Just check to see if a variable has already been declared, without reserving,
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Just check to see if a variable has already been declared, without reserving,
|
||||
walks up to the root scope.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">check: </span><span class="nf">(name) -></span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre> check: (name) ->
|
||||
!!(<span class="property">@type</span>(name) <span class="keyword">or</span> <span class="property">@parent</span>?.check(name))</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Generate a temporary variable name at the given index.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Generate a temporary variable name at the given index.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">temporary: </span><span class="nf">(name, index) -></span>
|
||||
<span class="k">if</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">1</span>
|
||||
<span class="s">'_'</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">></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">''</span>
|
||||
<span class="k">else</span>
|
||||
<span class="s">'_'</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">'a'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> temporary: (name, index) ->
|
||||
<span class="keyword">if</span> name.length > <span class="number">1</span>
|
||||
<span class="string">'_'</span> + name + <span class="keyword">if</span> index > <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="keyword">else</span>
|
||||
<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 id="section-10">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Gets the type of a variable.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Gets the type of a variable.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">type: </span><span class="nf">(name) -></span>
|
||||
<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="kc">null</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> type: (name) ->
|
||||
<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="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
|
||||
<p>If we need to store an intermediate result, find an available name for a
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<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...
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">freeVariable: </span><span class="nf">(name, reserve=true) -></span>
|
||||
<span class="nv">index = </span><span class="mi">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>
|
||||
<span class="nx">@add</span> <span class="nx">temp</span><span class="p">,</span> <span class="s">'var'</span><span class="p">,</span> <span class="kc">yes</span> <span class="k">if</span> <span class="nx">reserve</span>
|
||||
<span class="nx">temp</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> freeVariable: (name, reserve=<span class="literal">true</span>) ->
|
||||
index = <span class="number">0</span>
|
||||
index++ <span class="keyword">while</span> <span class="property">@check</span>((temp = <span class="property">@temporary</span> name, index))
|
||||
<span class="property">@add</span> temp, <span class="string">'var'</span>, <span class="literal">yes</span> <span class="keyword">if</span> reserve
|
||||
temp</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Ensure that an assignment is made at the top of this scope
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Ensure that an assignment is made at the top of this scope
|
||||
(or at the top-level scope, if requested).
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">assign: </span><span class="nf">(name, value) -></span>
|
||||
<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="vi">@hasAssignments = </span><span class="kc">yes</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> assign: (name, value) ->
|
||||
<span class="property">@add</span> name, {value, assigned: <span class="literal">yes</span>}, <span class="literal">yes</span>
|
||||
<span class="property">@hasAssignments</span> = <span class="literal">yes</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Does this scope have any declared variables?
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Does this scope have any declared variables?
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">hasDeclarations: </span><span class="nf">-></span>
|
||||
<span class="o">!!</span><span class="nx">@declaredVariables</span><span class="p">().</span><span class="nx">length</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> hasDeclarations: ->
|
||||
!!<span class="property">@declaredVariables</span>().length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Return the list of variables first declared in this scope.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Return the list of variables first declared in this scope.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">declaredVariables: </span><span class="nf">-></span>
|
||||
<span class="nv">realVars = </span><span class="p">[]</span>
|
||||
<span class="nv">tempVars = </span><span class="p">[]</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="o">is</span> <span class="s">'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">'_'</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="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>
|
||||
<div class="content"><div class='highlight'><pre> declaredVariables: ->
|
||||
realVars = []
|
||||
tempVars = []
|
||||
<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="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
|
||||
realVars.sort().concat tempVars.sort()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Return the list of assignments that are supposed to be made at the top
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Return the list of assignments that are supposed to be made at the top
|
||||
of this scope.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">assignedVariables: </span><span class="nf">-></span>
|
||||
<span class="s">"</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">"</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>
|
||||
|
||||
</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> assignedVariables: ->
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -92,115 +92,114 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>sourcemap.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>sourcemap.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
|
||||
<div class="pilwrap for-h3">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
</div>
|
||||
<h3>LineMapping</h3>
|
||||
<p>Hold data about mappings for one line of generated source code.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="k">class</span> <span class="nx">LineMapping</span>
|
||||
<span class="nv">constructor: </span><span class="nf">(@generatedLine) -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">LineMapping</span></span>
|
||||
constructor: (<span class="property">@generatedLine</span>) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
|
||||
<p>columnMap keeps track of which columns we've already mapped.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>columnMap keeps track of which columns we've already mapped.
|
||||
</p>
|
||||
|
||||
</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 id="section-3">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
|
||||
<p>columnMappings is an array of all column mappings, sorted by generated-column.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>columnMappings is an array of all column mappings, sorted by generated-column.
|
||||
</p>
|
||||
|
||||
</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={}) -></span>
|
||||
<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>
|
||||
addMapping: (generatedColumn, [sourceLine, sourceColumn], options={}) ->
|
||||
<span class="keyword">if</span> <span class="property">@columnMap</span>[generatedColumn] <span class="keyword">and</span> options.noReplace</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
<p>We already have a mapping for this column.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>We already have a mapping for this column.
|
||||
</p>
|
||||
|
||||
</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="nv">generatedLine: </span><span class="nx">@generatedLine</span>
|
||||
<span class="nx">generatedColumn</span>
|
||||
<span class="nx">sourceLine</span>
|
||||
<span class="nx">sourceColumn</span>
|
||||
<span class="p">}</span>
|
||||
<span class="property">@columnMap</span>[generatedColumn] = {
|
||||
generatedLine: <span class="property">@generatedLine</span>
|
||||
generatedColumn
|
||||
sourceLine
|
||||
sourceColumn
|
||||
}
|
||||
|
||||
<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="nx">@columnMappings</span><span class="p">.</span><span class="nx">sort</span> <span class="nf">(a,b) -></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>.push <span class="property">@columnMap</span>[generatedColumn]
|
||||
<span class="property">@columnMappings</span>.sort (a,b) -> a.generatedColumn - b.generatedColumn
|
||||
|
||||
<span class="nv">getSourcePosition: </span><span class="nf">(generatedColumn) -></span>
|
||||
<span class="nv">answer = </span><span class="kc">null</span>
|
||||
<span class="nv">lastColumnMapping = </span><span class="kc">null</span>
|
||||
<span class="k">for</span> <span class="nx">columnMapping</span> <span class="k">in</span> <span class="nx">@columnMappings</span>
|
||||
<span class="k">if</span> <span class="nx">columnMapping</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="o">></span> <span class="nx">generatedColumn</span>
|
||||
<span class="k">break</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">lastColumnMapping = </span><span class="nx">columnMapping</span>
|
||||
<span class="k">if</span> <span class="nx">lastColumnMapping</span>
|
||||
<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>
|
||||
getSourcePosition: (generatedColumn) ->
|
||||
answer = <span class="literal">null</span>
|
||||
lastColumnMapping = <span class="literal">null</span>
|
||||
<span class="keyword">for</span> columnMapping <span class="keyword">in</span> <span class="property">@columnMappings</span>
|
||||
<span class="keyword">if</span> columnMapping.generatedColumn > generatedColumn
|
||||
<span class="keyword">break</span>
|
||||
<span class="keyword">else</span>
|
||||
lastColumnMapping = columnMapping
|
||||
<span class="keyword">if</span> lastColumnMapping
|
||||
answer = [lastColumnMapping.sourceLine, lastColumnMapping.sourceColumn]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
|
||||
<h3>SourceMap</h3>
|
||||
<div class="pilwrap for-h3">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<h3>SourceMap</h3>
|
||||
<p>Maps locations in a generated source file back to locations in the original source file.
|
||||
|
||||
</p>
|
||||
|
@ -208,41 +207,39 @@
|
|||
SourceMap can be converted to a "v3" style sourcemap with <code>#generateV3SourceMap()</code>, for example
|
||||
but the SourceMap class itself knows nothing about v3 source maps.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nv">constructor: </span><span class="p">()</span> <span class="nf">-></span></pre></div></div>
|
||||
<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>
|
||||
constructor: () -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
|
||||
<p><code>generatedLines</code> is an array of LineMappings, one per generated line.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p><code>generatedLines</code> is an array of LineMappings, one per generated line.
|
||||
</p>
|
||||
|
||||
</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 id="section-7">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Adds a mapping to this SourceMap.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Adds a mapping to this SourceMap.
|
||||
|
||||
</p>
|
||||
<p><code>sourceLocation</code> and <code>generatedLocation</code> are both [line, column] arrays.
|
||||
|
@ -250,94 +247,90 @@ but the SourceMap class itself knows nothing about v3 source maps.
|
|||
</p>
|
||||
<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.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">addMapping: </span><span class="nf">(sourceLocation, generatedLocation, options={}) -></span>
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre> addMapping: (sourceLocation, generatedLocation, options={}) ->
|
||||
[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>
|
||||
<span class="k">if</span> <span class="o">not</span> <span class="nx">lineMapping</span>
|
||||
<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">if</span> <span class="keyword">not</span> lineMapping
|
||||
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 id="section-8">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Returns [sourceLine, sourceColumn], or null if no mapping could be found.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Returns [sourceLine, sourceColumn], or null if no mapping could be found.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">getSourcePosition: </span><span class="nf">([generatedLine, generatedColumn]) -></span>
|
||||
<span class="nv">answer = </span><span class="kc">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>
|
||||
<span class="k">if</span> <span class="o">not</span> <span class="nx">lineMapping</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> getSourcePosition: ([generatedLine, generatedColumn]) ->
|
||||
answer = <span class="literal">null</span>
|
||||
lineMapping = <span class="property">@generatedLines</span>[generatedLine]
|
||||
<span class="keyword">if</span> <span class="keyword">not</span> lineMapping</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
|
||||
<p>TODO: Search backwards for the line?
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>TODO: Search backwards for the line?
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="k">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>
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">else</span>
|
||||
answer = lineMapping.getSourcePosition generatedColumn
|
||||
|
||||
<span class="nx">answer</span></pre></div></div>
|
||||
answer</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
|
||||
<p><code>fn</code> will be called once for every recorded mapping, in the order in
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<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
|
||||
with four properties: sourceLine, sourceColumn, generatedLine, and
|
||||
generatedColumn.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">forEachMapping: </span><span class="nf">(fn) -></span>
|
||||
<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="k">if</span> <span class="nx">lineMapping</span>
|
||||
<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="nx">fn</span><span class="p">(</span><span class="nx">columnMapping</span><span class="p">)</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> forEachMapping: (fn) ->
|
||||
<span class="keyword">for</span> lineMapping, generatedLineNumber <span class="keyword">in</span> <span class="property">@generatedLines</span>
|
||||
<span class="keyword">if</span> lineMapping
|
||||
<span class="keyword">for</span> columnMapping <span class="keyword">in</span> lineMapping.columnMappings
|
||||
fn(columnMapping)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
|
||||
<h3>generateV3SourceMap</h3>
|
||||
<div class="pilwrap for-h3">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<h3>generateV3SourceMap</h3>
|
||||
<p>Builds a V3 source map from a SourceMap object.
|
||||
Returns the generated JSON as a string.
|
||||
|
||||
|
@ -346,60 +339,58 @@ Returns the generated JSON as a string.
|
|||
<code>options.sourceFiles</code> and <code>options.generatedFile</code> may be passed to set "sources" and "file",
|
||||
respectively. Note that <code>sourceFiles</code> must be an array.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.generateV3SourceMap = </span><span class="nf">(sourceMap, options={}) -></span>
|
||||
<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">""</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">""</span><span class="p">]</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">""</span>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">generateV3SourceMap</span></span> = (sourceMap, options={}, code) ->
|
||||
sourceRoot = options.sourceRoot <span class="keyword">or</span> <span class="string">""</span>
|
||||
sourceFiles = options.sourceFiles <span class="keyword">or</span> [<span class="string">""</span>]
|
||||
generatedFile = options.generatedFile <span class="keyword">or</span> <span class="string">""</span>
|
||||
|
||||
<span class="nv">writingGeneratedLine = </span><span class="mi">0</span>
|
||||
<span class="nv">lastGeneratedColumnWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">lastSourceLineWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">lastSourceColumnWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">needComma = </span><span class="kc">no</span>
|
||||
writingGeneratedLine = <span class="number">0</span>
|
||||
lastGeneratedColumnWritten = <span class="number">0</span>
|
||||
lastSourceLineWritten = <span class="number">0</span>
|
||||
lastSourceColumnWritten = <span class="number">0</span>
|
||||
needComma = <span class="literal">no</span>
|
||||
|
||||
<span class="nv">mappings = </span><span class="s">""</span>
|
||||
mappings = <span class="string">""</span>
|
||||
|
||||
<span class="nx">sourceMap</span><span class="p">.</span><span class="nx">forEachMapping</span> <span class="nf">(mapping) -></span>
|
||||
<span class="k">while</span> <span class="nx">writingGeneratedLine</span> <span class="o"><</span> <span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedLine</span>
|
||||
<span class="nv">lastGeneratedColumnWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">needComma = </span><span class="kc">no</span>
|
||||
<span class="nx">mappings</span> <span class="o">+=</span> <span class="s">";"</span>
|
||||
<span class="nx">writingGeneratedLine</span><span class="o">++</span></pre></div></div>
|
||||
sourceMap.forEachMapping (mapping) ->
|
||||
<span class="keyword">while</span> writingGeneratedLine < mapping.generatedLine
|
||||
lastGeneratedColumnWritten = <span class="number">0</span>
|
||||
needComma = <span class="literal">no</span>
|
||||
mappings += <span class="string">";"</span>
|
||||
writingGeneratedLine++</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Write a comma if we've already written a segment on this line.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Write a comma if we've already written a segment on this line.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="k">if</span> <span class="nx">needComma</span>
|
||||
<span class="nx">mappings</span> <span class="o">+=</span> <span class="s">","</span>
|
||||
<span class="nv">needComma = </span><span class="kc">no</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">if</span> needComma
|
||||
mappings += <span class="string">","</span>
|
||||
needComma = <span class="literal">no</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Write the next segment.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Write the next segment.
|
||||
Segments can be 1, 4, or 5 values. If just one, then it is a generated column which
|
||||
doesn't match anything in the source code.
|
||||
|
||||
|
@ -413,345 +404,330 @@ doesn't match anything in the source code.
|
|||
|
||||
</p>
|
||||
<p>Add the generated start-column
|
||||
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nv">lastGeneratedColumnWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedColumn</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> mappings += exports.vlqEncodeValue(mapping.generatedColumn - lastGeneratedColumnWritten)
|
||||
lastGeneratedColumnWritten = mapping.generatedColumn</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Add the index into the sources list
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Add the index into the sources list
|
||||
</p>
|
||||
|
||||
</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 id="section-15">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Add the source start-line
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Add the source start-line
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nv">lastSourceLineWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceLine</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> mappings += exports.vlqEncodeValue(mapping.sourceLine - lastSourceLineWritten)
|
||||
lastSourceLineWritten = mapping.sourceLine</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Add the source start-column
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>Add the source start-column
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nv">lastSourceColumnWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceColumn</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> mappings += exports.vlqEncodeValue(mapping.sourceColumn - lastSourceColumnWritten)
|
||||
lastSourceColumnWritten = mapping.sourceColumn</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
|
||||
<p>TODO: Do we care about symbol names for CoffeeScript? Probably not.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>TODO: Do we care about symbol names for CoffeeScript? Probably not.
|
||||
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nv">version: </span><span class="mi">3</span>
|
||||
<span class="nv">file: </span><span class="nx">generatedFile</span>
|
||||
<span class="nx">sourceRoot</span>
|
||||
<span class="nv">sources: </span><span class="nx">sourceFiles</span>
|
||||
<span class="nv">names: </span><span class="p">[]</span>
|
||||
<span class="nx">mappings</span>
|
||||
<span class="p">}</span>
|
||||
answer = {
|
||||
version: <span class="number">3</span>
|
||||
file: generatedFile
|
||||
sourceRoot
|
||||
sources: sourceFiles
|
||||
names: []
|
||||
mappings
|
||||
}
|
||||
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 id="section-18">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Load a SourceMap from a JSON string. Returns the SourceMap object.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>Load a SourceMap from a JSON string. Returns the SourceMap object.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.loadV3SourceMap = </span><span class="nf">(sourceMap) -></span>
|
||||
<span class="nx">todo</span><span class="p">()</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">loadV3SourceMap</span></span> = (sourceMap) ->
|
||||
todo()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
|
||||
<h3>Base64 encoding helpers</h3>
|
||||
<div class="pilwrap for-h3">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<h3>Base64 encoding helpers</h3>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">BASE64_CHARS = </span><span class="s">'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>
|
||||
<div class="content"><div class='highlight'><pre>BASE64_CHARS = <span class="string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
|
||||
MAX_BASE64_VALUE = BASE64_CHARS.length - <span class="number">1</span>
|
||||
|
||||
<span class="nv">encodeBase64Char = </span><span class="nf">(value) -></span>
|
||||
<span class="k">if</span> <span class="nx">value</span> <span class="o">></span> <span class="nx">MAX_BASE64_VALUE</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Cannot encode value </span><span class="si">#{</span><span class="nx">value</span><span class="si">}</span><span class="s"> > </span><span class="si">#{</span><span class="nx">MAX_BASE64_VALUE</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="k">else</span> <span class="k">if</span> <span class="nx">value</span> <span class="o"><</span> <span class="mi">0</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Cannot encode value </span><span class="si">#{</span><span class="nx">value</span><span class="si">}</span><span class="s"> < 0"</span>
|
||||
<span class="nx">BASE64_CHARS</span><span class="p">[</span><span class="nx">value</span><span class="p">]</span>
|
||||
<span class="function"><span class="title">encodeBase64Char</span></span> = (value) ->
|
||||
<span class="keyword">if</span> value > MAX_BASE64_VALUE
|
||||
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cannot encode value <span class="subst">#{value}</span> > <span class="subst">#{MAX_BASE64_VALUE}</span>"</span>
|
||||
<span class="keyword">else</span> <span class="keyword">if</span> value < <span class="number">0</span>
|
||||
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cannot encode value <span class="subst">#{value}</span> < 0"</span>
|
||||
BASE64_CHARS[value]
|
||||
|
||||
<span class="nv">decodeBase64Char = </span><span class="nf">(char) -></span>
|
||||
<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>
|
||||
<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="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Invalid Base 64 character: </span><span class="si">#{</span><span class="nx">char</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="nx">value</span></pre></div></div>
|
||||
<span class="function"><span class="title">decodeBase64Char</span></span> = (char) ->
|
||||
value = BASE64_CHARS.indexOf char
|
||||
<span class="keyword">if</span> value == -<span class="number">1</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>
|
||||
value</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
|
||||
<h3>Base 64 VLQ encoding/decoding helpers</h3>
|
||||
<div class="pilwrap for-h3">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<h3>Base 64 VLQ encoding/decoding helpers</h3>
|
||||
<p>Note that SourceMap VLQ encoding is "backwards". MIDI style VLQ encoding puts the
|
||||
most-significant-bit (MSB) from the original value into the MSB of the VLQ encoded value
|
||||
(see <a href="http://en.wikipedia.org/wiki/File:Uintvar_coding.svg">http://en.wikipedia.org/wiki/File:Uintvar_coding.svg</a>). SourceMap VLQ does things
|
||||
the other way around, with the least significat four bits of the original value encoded
|
||||
into the first byte of the VLQ encoded value.
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">VLQ_SHIFT = </span><span class="mi">5</span>
|
||||
<span class="nv">VLQ_CONTINUATION_BIT = </span><span class="mi">1</span> <span class="o"><<</span> <span class="nx">VLQ_SHIFT</span> <span class="c1"># 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>
|
||||
<div class="content"><div class='highlight'><pre>VLQ_SHIFT = <span class="number">5</span>
|
||||
VLQ_CONTINUATION_BIT = <span class="number">1</span> << VLQ_SHIFT <span class="comment"># 0010 0000</span>
|
||||
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - <span class="number">1</span> <span class="comment"># 0001 1111</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Encode a value as Base 64 VLQ.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Encode a value as Base 64 VLQ.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.vlqEncodeValue = </span><span class="nf">(value) -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">vlqEncodeValue</span></span> = (value) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Least significant bit represents the sign.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Least significant bit represents the sign.
|
||||
</p>
|
||||
|
||||
</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"><</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 < <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 id="section-23">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Next bits are the actual value
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>Next bits are the actual value
|
||||
</p>
|
||||
|
||||
</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"><<</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) << <span class="number">1</span>) + signBit
|
||||
|
||||
<span class="nv">answer = </span><span class="s">""</span></pre></div></div>
|
||||
answer = <span class="string">""</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Make sure we encode at least one character, even if valueToEncode is 0.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Make sure we encode at least one character, even if valueToEncode is 0.
|
||||
</p>
|
||||
|
||||
</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>
|
||||
<span class="nv">nextVlqChunk = </span><span class="nx">valueToEncode</span> <span class="o">&</span> <span class="nx">VLQ_VALUE_MASK</span>
|
||||
<span class="nv">valueToEncode = </span><span class="nx">valueToEncode</span> <span class="o">>></span> <span class="nx">VLQ_SHIFT</span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">while</span> valueToEncode || !answer
|
||||
nextVlqChunk = valueToEncode & VLQ_VALUE_MASK
|
||||
valueToEncode = valueToEncode >> VLQ_SHIFT
|
||||
|
||||
<span class="k">if</span> <span class="nx">valueToEncode</span>
|
||||
<span class="nx">nextVlqChunk</span> <span class="o">|=</span> <span class="nx">VLQ_CONTINUATION_BIT</span>
|
||||
<span class="keyword">if</span> valueToEncode
|
||||
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 id="section-25">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Decode a Base 64 VLQ value.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
<p>Decode a Base 64 VLQ value.
|
||||
|
||||
</p>
|
||||
<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>.
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre><span class="nv">exports.vlqDecodeValue = </span><span class="nf">(str, offset=0) -></span>
|
||||
<span class="nv">position = </span><span class="nx">offset</span>
|
||||
<span class="nv">done = </span><span class="kc">false</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>) ->
|
||||
position = offset
|
||||
done = <span class="literal">false</span>
|
||||
|
||||
<span class="nv">value = </span><span class="mi">0</span>
|
||||
<span class="nv">continuationShift = </span><span class="mi">0</span>
|
||||
value = <span class="number">0</span>
|
||||
continuationShift = <span class="number">0</span>
|
||||
|
||||
<span class="k">while</span> <span class="o">!</span><span class="nx">done</span>
|
||||
<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>
|
||||
<span class="nx">position</span> <span class="o">+=</span> <span class="mi">1</span>
|
||||
<span class="keyword">while</span> !done
|
||||
nextVlqChunk = decodeBase64Char(str[position])
|
||||
position += <span class="number">1</span>
|
||||
|
||||
<span class="nv">nextChunkValue = </span><span class="nx">nextVlqChunk</span> <span class="o">&</span> <span class="nx">VLQ_VALUE_MASK</span>
|
||||
<span class="nx">value</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">nextChunkValue</span> <span class="o"><<</span> <span class="nx">continuationShift</span><span class="p">)</span>
|
||||
nextChunkValue = nextVlqChunk & VLQ_VALUE_MASK
|
||||
value += (nextChunkValue << continuationShift)
|
||||
|
||||
<span class="k">if</span> <span class="o">!</span><span class="p">(</span><span class="nx">nextVlqChunk</span> <span class="o">&</span> <span class="nx">VLQ_CONTINUATION_BIT</span><span class="p">)</span></pre></div></div>
|
||||
<span class="keyword">if</span> !(nextVlqChunk & VLQ_CONTINUATION_BIT)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
|
||||
<p>We'll be done after this character.
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
<p>We'll be done after this character.
|
||||
</p>
|
||||
|
||||
</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 id="section-27">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Bits are encoded least-significant first (opposite of MIDI VLQ). Increase the
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
</div>
|
||||
<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.
|
||||
|
||||
</p>
|
||||
|
||||
</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 id="section-28">
|
||||
<div class="annotation">
|
||||
<div class="pilwrap">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
</div>
|
||||
|
||||
<p>Least significant bit represents the sign.
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
</div>
|
||||
<p>Least significant bit represents the sign.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class="highlight"><pre> <span class="nv">signBit = </span><span class="nx">value</span> <span class="o">&</span> <span class="mi">1</span>
|
||||
<span class="nv">value = </span><span class="nx">value</span> <span class="o">>></span> <span class="mi">1</span>
|
||||
<div class="content"><div class='highlight'><pre> signBit = value & <span class="number">1</span>
|
||||
value = value >> <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>
|
||||
|
||||
</pre></div></div>
|
||||
<span class="keyword">return</span> [value, consumed]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
|
||||
<p>
|
||||
<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>
|
||||
|
||||
<pre>
|
||||
|
@ -1202,6 +1202,35 @@ Expressions
|
|||
Change Log
|
||||
</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"> – <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 —
|
||||
<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>
|
||||
<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>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var volume, winner;
|
||||
|
||||
if (ignition === true) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
_ref = ['toast', 'cheese', 'wine'];
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var 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) {
|
||||
var code, dir;
|
||||
|
||||
require('jison');
|
||||
code = require('./lib/grammar').parser.generate();
|
||||
dir = options.output || 'lib';
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
var Animal, Horse, Snake, sam, tom,
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var Animal, Horse, Snake, sam, tom, _ref, _ref1,
|
||||
__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; };
|
||||
|
||||
Animal = (function() {
|
||||
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -18,11 +17,11 @@ Animal = (function() {
|
|||
})();
|
||||
|
||||
Snake = (function(_super) {
|
||||
|
||||
__extends(Snake, _super);
|
||||
|
||||
function Snake() {
|
||||
return Snake.__super__.constructor.apply(this, arguments);
|
||||
_ref = Snake.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
Snake.prototype.move = function() {
|
||||
|
@ -35,11 +34,11 @@ Snake = (function(_super) {
|
|||
})(Animal);
|
||||
|
||||
Horse = (function(_super) {
|
||||
|
||||
__extends(Horse, _super);
|
||||
|
||||
function Horse() {
|
||||
return Horse.__super__.constructor.apply(this, arguments);
|
||||
_ref1 = Horse.__super__.constructor.apply(this, arguments);
|
||||
return _ref1;
|
||||
}
|
||||
|
||||
Horse.prototype.move = function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var cholesterol, healthy;
|
||||
|
||||
cholesterol = 127;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var date, mood;
|
||||
|
||||
if (singing) {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// Generated by CoffeeScript 1.3.3
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var Person;
|
||||
|
||||
Person = (function() {
|
||||
|
||||
function Person(options) {
|
||||
this.name = options.name, this.age = options.age, this.height = options.height;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var fill;
|
||||
|
||||
fill = function(container, liquid) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var filename, _fn, _i, _len;
|
||||
|
||||
_fn = function(filename) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var hi;
|
||||
|
||||
hi = function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var footprints, solipsism, speed;
|
||||
|
||||
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var eldest, grade;
|
||||
|
||||
grade = function(student) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var one, six, three, two;
|
||||
|
||||
six = (one = 1) + (two = 2) + (three = 3);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var globals, name;
|
||||
|
||||
globals = ((function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
for (name in window) {
|
||||
_results.push(name);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var error;
|
||||
|
||||
alert((function() {
|
||||
try {
|
||||
return nonexistent / void 0;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
error = _error;
|
||||
return "And the error is ... " + error;
|
||||
}
|
||||
})());
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var Account;
|
||||
|
||||
Account = function(customer, cart) {
|
||||
var _this = this;
|
||||
|
||||
this.customer = customer;
|
||||
this.cart = cart;
|
||||
return $('.shopping_cart').bind('click', function(event) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var cube, square;
|
||||
|
||||
square = function(x) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var html;
|
||||
|
||||
html = "<strong>\n cup of coffeescript\n</strong>";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var OPERATOR;
|
||||
|
||||
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var city, forecast, temp, weatherReport, _ref;
|
||||
|
||||
weatherReport = function(location) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var age, ages, child, yearsOld;
|
||||
|
||||
yearsOld = {
|
||||
|
@ -9,6 +9,7 @@ yearsOld = {
|
|||
|
||||
ages = (function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var city, futurists, name, street, _ref, _ref1;
|
||||
|
||||
futurists = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var bitlist, kids, singers, song;
|
||||
|
||||
song = ["do", "re", "mi", "fa", "so"];
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
$('.account').attr({
|
||||
"class": 'active'
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
__slice = [].slice;
|
||||
|
||||
|
@ -26,6 +26,7 @@ math = {
|
|||
|
||||
race = function() {
|
||||
var runners, winner;
|
||||
|
||||
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
return print(winner, runners);
|
||||
};
|
||||
|
@ -36,6 +37,7 @@ if (typeof elvis !== "undefined" && elvis !== null) {
|
|||
|
||||
cubes = (function() {
|
||||
var _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
num = list[_i];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var theBait, theSwitch, _ref;
|
||||
|
||||
theBait = 1000;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var close, contents, open, tag, _i, _ref,
|
||||
__slice = [].slice;
|
||||
|
||||
|
|
3
documentation/js/prototypes.js
vendored
3
documentation/js/prototypes.js
vendored
|
@ -1,5 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
String.prototype.dasherize = function() {
|
||||
return this.replace(/_/g, "-");
|
||||
};
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var countdown, num;
|
||||
|
||||
countdown = (function() {
|
||||
var _i, _results;
|
||||
|
||||
_results = [];
|
||||
for (num = _i = 10; _i >= 1; num = --_i) {
|
||||
_results.push(num);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var changeNumbers, inner, outer;
|
||||
|
||||
outer = 1;
|
||||
|
||||
changeNumbers = function() {
|
||||
var inner;
|
||||
|
||||
inner = -1;
|
||||
return outer = 10;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var copy, end, middle, numbers, start;
|
||||
|
||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var zip, _ref;
|
||||
|
||||
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var awardMedals, contenders, gold, rest, silver,
|
||||
__slice = [].slice;
|
||||
|
||||
|
@ -6,6 +6,7 @@ gold = silver = rest = "unknown";
|
|||
|
||||
awardMedals = function() {
|
||||
var first, others, second;
|
||||
|
||||
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
||||
gold = first;
|
||||
silver = second;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var numbers, _ref;
|
||||
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
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...";
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
switch (day) {
|
||||
case "Mon":
|
||||
go(work);
|
||||
|
|
19
documentation/js/switch_with_no_expression.js
Normal file
19
documentation/js/switch_with_no_expression.js
Normal 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';
|
||||
}
|
||||
})();
|
|
@ -1,9 +1,11 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var error;
|
||||
|
||||
try {
|
||||
allHellBreaksLoose();
|
||||
catsAndDogsLivingTogether();
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
error = _error;
|
||||
print(error);
|
||||
} finally {
|
||||
cleanUp();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
var lyrics, num;
|
||||
|
||||
if (this.studyingEconomics) {
|
||||
|
@ -14,6 +14,7 @@ num = 6;
|
|||
|
||||
lyrics = (function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
while (num -= 1) {
|
||||
_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
191
index.html
191
index.html
|
@ -116,7 +116,7 @@
|
|||
|
||||
<p>
|
||||
<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>
|
||||
|
||||
<pre>
|
||||
|
@ -184,6 +184,7 @@ math <span class="Keyword">=</span> {
|
|||
|
||||
<span class="FunctionName">race</span> = <span class="Storage">function</span>() {
|
||||
<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"><=</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);
|
||||
};
|
||||
|
@ -194,6 +195,7 @@ math <span class="Keyword">=</span> {
|
|||
|
||||
cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _i, _len, _results;
|
||||
|
||||
_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"><</span> _len; _i<span class="Keyword">++</span>) {
|
||||
num <span class="Keyword">=</span> list[_i];
|
||||
|
@ -228,6 +230,7 @@ math = {
|
|||
|
||||
race = function() {
|
||||
var runners, winner;
|
||||
|
||||
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
return print(winner, runners);
|
||||
};
|
||||
|
@ -238,6 +241,7 @@ if (typeof elvis !== "undefined" && elvis !== null) {
|
|||
|
||||
cubes = (function() {
|
||||
var _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _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>
|
||||
</td>
|
||||
</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>
|
||||
<td><code>-b, --bare</code></td>
|
||||
<td>
|
||||
|
@ -671,8 +668,7 @@ kids = {
|
|||
log object.<span class="Storage">class</span>
|
||||
|
||||
|
||||
</pre><pre class="idle">
|
||||
<span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).attr({
|
||||
</pre><pre class="idle"><span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).attr({
|
||||
<span class="String"><span class="String">"</span>class<span class="String">"</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="Storage">var</span> inner;
|
||||
|
||||
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>;
|
||||
};
|
||||
|
@ -708,6 +705,7 @@ outer = 1;
|
|||
|
||||
changeNumbers = function() {
|
||||
var inner;
|
||||
|
||||
inner = -1;
|
||||
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="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"><=</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;
|
||||
silver <span class="Keyword">=</span> second;
|
||||
|
@ -850,6 +849,7 @@ gold = silver = rest = "unknown";
|
|||
|
||||
awardMedals = function() {
|
||||
var first, others, second;
|
||||
|
||||
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
||||
gold = first;
|
||||
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>() {
|
||||
<span class="Storage">var</span> _i, _results;
|
||||
|
||||
_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">>=</span> <span class="Number">1</span>; num <span class="Keyword">=</span> <span class="Keyword">--</span>_i) {
|
||||
_results.<span class="LibraryFunction">push</span>(num);
|
||||
|
@ -934,6 +935,7 @@ countdown <span class="Keyword">=</span> (<span class="Storage">function</span>(
|
|||
|
||||
countdown = (function() {
|
||||
var _i, _results;
|
||||
|
||||
_results = [];
|
||||
for (num = _i = 10; _i >= 1; num = --_i) {
|
||||
_results.push(num);
|
||||
|
@ -974,6 +976,7 @@ yearsOld <span class="Keyword">=</span> {
|
|||
|
||||
ages <span class="Keyword">=</span> (<span class="Storage">function</span>() {
|
||||
<span class="Storage">var</span> _results;
|
||||
|
||||
_results <span class="Keyword">=</span> [];
|
||||
<span class="Keyword">for</span> (child <span class="Keyword">in</span> yearsOld) {
|
||||
age <span class="Keyword">=</span> yearsOld[child];
|
||||
|
@ -991,6 +994,7 @@ yearsOld = {
|
|||
|
||||
ages = (function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
for (child in yearsOld) {
|
||||
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>() {
|
||||
<span class="Storage">var</span> _results;
|
||||
|
||||
_results <span class="Keyword">=</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">"</span><span class="String">"</span></span> <span class="Keyword">+</span> num <span class="Keyword">+</span> <span class="String"><span class="String">"</span> little monkeys, jumping on the bed. One fell out and bumped his head.<span class="String">"</span></span>);
|
||||
|
@ -1057,6 +1062,7 @@ num = 6;
|
|||
|
||||
lyrics = (function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
while (num -= 1) {
|
||||
_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>() {
|
||||
<span class="Storage">var</span> _results;
|
||||
|
||||
_results <span class="Keyword">=</span> [];
|
||||
<span class="Keyword">for</span> (name <span class="Keyword">in</span> <span class="LibraryClassType">window</span>) {
|
||||
_results.<span class="LibraryFunction">push</span>(name);
|
||||
|
@ -1254,6 +1261,7 @@ globals <span class="Keyword">=</span> ((<span class="Storage">function</span>()
|
|||
|
||||
globals = ((function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
for (name in window) {
|
||||
_results.push(name);
|
||||
|
@ -1272,19 +1280,23 @@ globals = ((function() {
|
|||
<span class="String"><span class="String">"</span>And the error is ... <span class="String"><span class="String">#{</span>error<span class="String">}</span></span><span class="String">"</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="Keyword">try</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">"</span>And the error is ... <span class="String">"</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() {
|
||||
try {
|
||||
return nonexistent / void 0;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
error = _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,
|
||||
<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>() {
|
||||
|
||||
<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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
||||
__extends(Snake, _super);
|
||||
|
||||
<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>() {
|
||||
|
@ -1545,11 +1556,11 @@ Snake <span class="Keyword">=</span> (<span class="Storage">function</span>(_sup
|
|||
})(Animal);
|
||||
|
||||
Horse <span class="Keyword">=</span> (<span class="Storage">function</span>(_super) {
|
||||
|
||||
__extends(Horse, _super);
|
||||
|
||||
<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>() {
|
||||
|
@ -1568,12 +1579,11 @@ tom <span class="Keyword">=</span> <span class="Keyword">new</span> <span class=
|
|||
sam.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,
|
||||
__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() {
|
||||
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -1587,11 +1597,11 @@ Animal = (function() {
|
|||
})();
|
||||
|
||||
Snake = (function(_super) {
|
||||
|
||||
__extends(Snake, _super);
|
||||
|
||||
function Snake() {
|
||||
return Snake.__super__.constructor.apply(this, arguments);
|
||||
_ref = Snake.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
Snake.prototype.move = function() {
|
||||
|
@ -1604,11 +1614,11 @@ Snake = (function(_super) {
|
|||
})(Animal);
|
||||
|
||||
Horse = (function(_super) {
|
||||
|
||||
__extends(Horse, _super);
|
||||
|
||||
function Horse() {
|
||||
return Horse.__super__.constructor.apply(this, arguments);
|
||||
_ref1 = Horse.__super__.constructor.apply(this, arguments);
|
||||
return _ref1;
|
||||
}
|
||||
|
||||
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">></span>
|
||||
<span class="Variable">this</span>.replace <span class="String">/_/g</span>, <span class="String"><span class="String">"</span>-<span class="String">"</span></span>
|
||||
|
||||
</pre><pre class="idle">
|
||||
<span class="LibraryClassType">String</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">dasherize</span> = <span class="Storage">function</span>() {
|
||||
</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="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">"</span>-<span class="String">"</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:
|
||||
String.prototype.dasherize = function() {
|
||||
</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() {
|
||||
return this.replace(/_/g, "-");
|
||||
};
|
||||
;alert("one_two".dasherize());'>run: "one_two".dasherize()</div><br class='clear' /></div>
|
||||
|
@ -1788,17 +1796,16 @@ tag = "<impossible>";
|
|||
_ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call(_ref, 1, _i = _ref.length - 1) : (_i = 1, []), close = _ref[_i++];
|
||||
;alert(contents.join(""));'>run: contents.join("")</div><br class='clear' /></div>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<div class='code'><pre class="idle">class Person
|
||||
constructor: (options) ->
|
||||
{@name, @age, @height} = options
|
||||
<div class='code'><pre class="idle"><span class="Storage">class</span> <span class="TypeName">Person</span>
|
||||
<span class="FunctionName">constructor</span><span class="Keyword">:</span> <span class="FunctionArgument">(options)</span> <span class="Storage">-></span>
|
||||
<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;
|
||||
|
||||
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="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;
|
||||
|
||||
Person = (function() {
|
||||
|
||||
function Person(options) {
|
||||
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="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>.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> _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>
|
||||
If we had used <tt>-></tt> in the callback above, <tt>@customer</tt> would
|
||||
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="Keyword">return</span> [<span class="LibraryClassType">document</span>.<span class="LibraryConstant">title</span>, <span class="String"><span class="String">"</span>Hello JavaScript<span class="String">"</span></span>].<span class="LibraryFunction">join</span>(<span class="String"><span class="String">"</span>: <span class="String">"</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() {
|
||||
return [document.title, "Hello JavaScript"].join(": ");
|
||||
|
@ -1915,8 +1922,7 @@ hi = function() {
|
|||
go dancing
|
||||
<span class="Keyword">when</span> <span class="String"><span class="String">"</span>Sun<span class="String">"</span></span> <span class="Keyword">then</span> go church
|
||||
<span class="Keyword">else</span> go work
|
||||
</pre><pre class="idle">
|
||||
<span class="Keyword">switch</span> (day) {
|
||||
</pre><pre class="idle"><span class="Keyword">switch</span> (day) {
|
||||
<span class="Keyword">case</span> <span class="String"><span class="String">"</span>Mon<span class="String">"</span></span>:
|
||||
<span class="LibraryFunction">go</span>(work);
|
||||
<span class="Keyword">break</span>;
|
||||
|
@ -1939,7 +1945,38 @@ hi = function() {
|
|||
<span class="Keyword">default</span>:
|
||||
<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"><</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"><</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"><</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"><</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"><</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"><</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"><</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"><</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>
|
||||
<span id="try" class="bookmark"></span>
|
||||
|
@ -1955,16 +1992,18 @@ hi = function() {
|
|||
<span class="Keyword">finally</span>
|
||||
cleanUp()
|
||||
|
||||
</pre><pre class="idle">
|
||||
</pre><pre class="idle"><span class="Storage">var</span> error;
|
||||
|
||||
<span class="Keyword">try</span> {
|
||||
allHellBreaksLoose();
|
||||
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="Keyword">finally</span> {
|
||||
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>
|
||||
<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>;
|
||||
|
||||
healthy <span class="Keyword">=</span> (<span class="Number">200</span> <span class="Keyword">></span> cholesterol <span class="Keyword">&</span><span class="Keyword">&</span> cholesterol <span class="Keyword">></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;
|
||||
|
||||
|
@ -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">"</span>A picture is a fact. -- <span class="String">"</span></span> <span class="Keyword">+</span> author;
|
||||
|
||||
sentence <span class="Keyword">=</span> <span class="String"><span class="String">"</span><span class="String">"</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">"</span> is a decent approximation of π<span class="String">"</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";
|
||||
|
||||
|
@ -2036,7 +2075,7 @@ sentence = "" + (22 / 7) + " is a decent approximation of π";
|
|||
</pre><pre class="idle"><span class="Storage">var</span> mobyDick;
|
||||
|
||||
mobyDick <span class="Keyword">=</span> <span class="String"><span class="String">"</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">"</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...";
|
||||
;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;
|
||||
|
||||
html <span class="Keyword">=</span> <span class="String"><span class="String">"</span><strong><span class="UserDefinedConstant">\n</span> cup of coffeescript<span class="UserDefinedConstant">\n</span></strong><span class="String">"</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>";
|
||||
;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.
|
||||
</p>
|
||||
<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"><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"><span class="Comment">*/</span></span>
|
||||
|
||||
|
||||
</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>
|
||||
</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>
|
||||
|
||||
<p>
|
||||
<span id="regexes" class="bookmark"></span>
|
||||
<b class="header">Block Regular Expressions</b>
|
||||
Similar to block strings and comments, CoffeeScript supports block regexes —
|
||||
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
|
||||
regular expressions readable. To quote from the CoffeeScript source:
|
||||
</p>
|
||||
|
@ -2105,7 +2143,7 @@ html = "<strong>\n cup of coffeescript\n</strong>";
|
|||
</pre><pre class="idle"><span class="Storage">var</span> OPERATOR;
|
||||
|
||||
OPERATOR <span class="Keyword">=</span><span class="String"> <span class="String">/</span>^(?:[-=]>|[-+*<span class="UserDefinedConstant">\/</span>%<>&|^!?=]=|>>>=?|([-+:])<span class="UserDefinedConstant">\1</span>|([&|<>])<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>
|
||||
|
@ -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) {
|
||||
<span class="Storage">var</span> code, dir;
|
||||
|
||||
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();
|
||||
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">"</span><span class="String">"</span></span> <span class="Keyword">+</span> dir <span class="Keyword">+</span> <span class="String"><span class="String">"</span>/parser.js<span class="String">"</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>
|
||||
If you need to invoke one task before another — for example, running
|
||||
<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 />
|
||||
Perhaps your CoffeeScript-related question has been asked before. Check the FAQ first.
|
||||
</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...) — but it's a great starting
|
||||
point for converting simple scripts.
|
||||
</li>
|
||||
<li>
|
||||
<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
|
||||
|
@ -2393,6 +2439,35 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
|
|||
Change Log
|
||||
</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"> – <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 —
|
||||
<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>
|
||||
<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>
|
||||
|
@ -3140,8 +3215,10 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
|
|||
else
|
||||
$(el).text window.compiledJS
|
||||
$('#error').hide()
|
||||
catch error
|
||||
$('#error').text(error.message).show()
|
||||
catch {location, message}
|
||||
if location?
|
||||
message = "Error on line #{location.first_line + 1}: #{message}"
|
||||
$('#error').text(message).show()
|
||||
|
||||
# Update permalink
|
||||
$('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
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; };
|
||||
|
@ -7,19 +7,11 @@
|
|||
|
||||
CoffeeScript.require = require;
|
||||
|
||||
compile = (typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null) ? 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.compile;
|
||||
compile = CoffeeScript.compile;
|
||||
|
||||
CoffeeScript["eval"] = function(code, options) {
|
||||
var _ref;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -41,8 +33,23 @@
|
|||
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) {
|
||||
var xhr;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -54,6 +61,7 @@
|
|||
}
|
||||
xhr.onreadystatechange = function() {
|
||||
var _ref;
|
||||
|
||||
if (xhr.readyState === 4) {
|
||||
if ((_ref = xhr.status) === 0 || _ref === 200) {
|
||||
CoffeeScript.run(xhr.responseText, options);
|
||||
|
@ -70,10 +78,12 @@
|
|||
|
||||
runScripts = function() {
|
||||
var coffees, coffeetypes, execute, index, length, s, scripts;
|
||||
|
||||
scripts = document.getElementsByTagName('script');
|
||||
coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
|
||||
coffees = (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
|
||||
s = scripts[_i];
|
||||
|
@ -87,6 +97,7 @@
|
|||
length = coffees.length;
|
||||
(execute = function() {
|
||||
var mediatype, options, script;
|
||||
|
||||
script = coffees[index++];
|
||||
mediatype = script != null ? script.type : void 0;
|
||||
if (__indexOf.call(coffeetypes, mediatype) >= 0) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var CoffeeScript, cakefileDirectory, existsSync, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
|||
helpers.extend(global, {
|
||||
task: function(name, description, action) {
|
||||
var _ref;
|
||||
|
||||
if (!action) {
|
||||
_ref = [description, action], action = _ref[0], description = _ref[1];
|
||||
}
|
||||
|
@ -47,6 +48,7 @@
|
|||
|
||||
exports.run = function() {
|
||||
var arg, args, e, _i, _len, _ref, _results;
|
||||
|
||||
global.__originalDirname = fs.realpathSync('.');
|
||||
process.chdir(cakefileDirectory(__originalDirname));
|
||||
args = process.argv.slice(2);
|
||||
|
@ -74,6 +76,7 @@
|
|||
|
||||
printTasks = function() {
|
||||
var cakefilePath, desc, name, relative, spaces, task;
|
||||
|
||||
relative = path.relative || path.resolve;
|
||||
cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
|
||||
console.log("" + cakefilePath + " defines the following tasks:\n");
|
||||
|
@ -101,6 +104,7 @@
|
|||
|
||||
cakefileDirectory = function(dir) {
|
||||
var parent;
|
||||
|
||||
if (existsSync(path.join(dir, 'Cakefile'))) {
|
||||
return dir;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var Lexer, child_process, compile, ext, fork, formatSourcePosition, fs, helpers, lexer, loadFile, parser, patchStackTrace, patched, path, sourcemap, vm, _i, _len, _ref,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
@ -19,12 +19,13 @@
|
|||
|
||||
sourcemap = require('./sourcemap');
|
||||
|
||||
exports.VERSION = '1.6.1';
|
||||
exports.VERSION = '1.6.2';
|
||||
|
||||
exports.helpers = helpers;
|
||||
|
||||
exports.compile = compile = function(code, options) {
|
||||
var answer, currentColumn, currentLine, fragment, fragments, header, js, merge, newLines, sourceMap, _i, _len;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -85,6 +86,7 @@
|
|||
|
||||
exports.run = function(code, options) {
|
||||
var answer, mainModule, _ref;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -107,6 +109,7 @@
|
|||
|
||||
exports["eval"] = function(code, options) {
|
||||
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _require;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -170,6 +173,7 @@
|
|||
|
||||
loadFile = function(module, filename) {
|
||||
var raw, stripped;
|
||||
|
||||
raw = fs.readFileSync(filename, 'utf8');
|
||||
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
|
||||
return module._compile(compile(stripped, {
|
||||
|
@ -186,30 +190,33 @@
|
|||
}
|
||||
}
|
||||
|
||||
fork = child_process.fork;
|
||||
if (child_process) {
|
||||
fork = child_process.fork;
|
||||
child_process.fork = function(path, args, options) {
|
||||
var execPath;
|
||||
|
||||
child_process.fork = function(path, args, options) {
|
||||
var execPath;
|
||||
if (args == null) {
|
||||
args = [];
|
||||
}
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
execPath = helpers.isCoffee(path) ? 'coffee' : null;
|
||||
if (!Array.isArray(args)) {
|
||||
args = [];
|
||||
options = args || {};
|
||||
}
|
||||
options.execPath || (options.execPath = execPath);
|
||||
return fork(path, args, options);
|
||||
};
|
||||
if (args == null) {
|
||||
args = [];
|
||||
}
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
execPath = helpers.isCoffee(path) ? 'coffee' : null;
|
||||
if (!Array.isArray(args)) {
|
||||
args = [];
|
||||
options = args || {};
|
||||
}
|
||||
options.execPath || (options.execPath = execPath);
|
||||
return fork(path, args, options);
|
||||
};
|
||||
}
|
||||
|
||||
lexer = new Lexer;
|
||||
|
||||
parser.lexer = {
|
||||
lex: function() {
|
||||
var tag, token;
|
||||
|
||||
token = this.tokens[this.pos++];
|
||||
if (token) {
|
||||
tag = token[0], this.yytext = token[1], this.yylloc = token[2];
|
||||
|
@ -232,6 +239,7 @@
|
|||
|
||||
parser.yy.parseError = function(message, _arg) {
|
||||
var token;
|
||||
|
||||
token = _arg.token;
|
||||
message = "unexpected " + (token === 1 ? 'end of input' : token);
|
||||
return helpers.throwSyntaxError(message, parser.lexer.yylloc);
|
||||
|
@ -241,6 +249,7 @@
|
|||
|
||||
patchStackTrace = function() {
|
||||
var mainModule;
|
||||
|
||||
if (patched) {
|
||||
return;
|
||||
}
|
||||
|
@ -249,9 +258,11 @@
|
|||
mainModule._sourceMaps = {};
|
||||
return Error.prepareStackTrace = function(err, stack) {
|
||||
var frame, frames, getSourceMapping, sourceFiles, _ref1;
|
||||
|
||||
sourceFiles = {};
|
||||
getSourceMapping = function(filename, line, column) {
|
||||
var answer, sourceMap;
|
||||
|
||||
sourceMap = mainModule._sourceMaps[filename];
|
||||
if (sourceMap) {
|
||||
answer = sourceMap.getSourcePosition([line - 1, column - 1]);
|
||||
|
@ -264,6 +275,7 @@
|
|||
};
|
||||
frames = (function() {
|
||||
var _j, _len1, _results;
|
||||
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = stack.length; _j < _len1; _j++) {
|
||||
frame = stack[_j];
|
||||
|
@ -280,6 +292,7 @@
|
|||
|
||||
formatSourcePosition = function(frame, getSourceMapping) {
|
||||
var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
|
||||
|
||||
fileName = void 0;
|
||||
fileLocation = '';
|
||||
if (frame.isNative()) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(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;
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
|||
|
||||
exports.run = function() {
|
||||
var literals, source, _i, _len, _results;
|
||||
|
||||
parseOptions();
|
||||
if (opts.nodejs) {
|
||||
return forkNode();
|
||||
|
@ -101,6 +102,7 @@
|
|||
}
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, index, _ref1, _ref2;
|
||||
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
|
@ -113,6 +115,7 @@
|
|||
});
|
||||
[].splice.apply(sources, [index, index - index + 1].concat(_ref1 = (function() {
|
||||
var _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
|
@ -149,6 +152,7 @@
|
|||
|
||||
compileScript = function(file, input, base) {
|
||||
var compiled, err, message, o, options, t, task, useColors;
|
||||
|
||||
if (base == null) {
|
||||
base = null;
|
||||
}
|
||||
|
@ -208,6 +212,7 @@
|
|||
|
||||
compileStdio = function() {
|
||||
var code, stdin;
|
||||
|
||||
code = '';
|
||||
stdin = process.openStdin();
|
||||
stdin.on('data', function(buffer) {
|
||||
|
@ -238,6 +243,7 @@
|
|||
|
||||
watch = function(source, base) {
|
||||
var compile, compileTimeout, e, prevStats, rewatch, watchErr, watcher;
|
||||
|
||||
prevStats = null;
|
||||
compileTimeout = null;
|
||||
watchErr = function(e) {
|
||||
|
@ -294,6 +300,7 @@
|
|||
|
||||
watchDir = function(source, base) {
|
||||
var e, readdirTimeout, watcher;
|
||||
|
||||
readdirTimeout = null;
|
||||
try {
|
||||
return watcher = fs.watch(source, function() {
|
||||
|
@ -301,6 +308,7 @@
|
|||
return readdirTimeout = wait(25, function() {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, _i, _len, _results;
|
||||
|
||||
if (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
|
@ -338,9 +346,11 @@
|
|||
|
||||
unwatchDir = function(source, base) {
|
||||
var file, prevSources, toRemove, _i, _len;
|
||||
|
||||
prevSources = sources.slice(0);
|
||||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
|
@ -364,6 +374,7 @@
|
|||
|
||||
removeSource = function(source, base, removeJs) {
|
||||
var index, jsPath;
|
||||
|
||||
index = sources.indexOf(source);
|
||||
sources.splice(index, 1);
|
||||
sourceCode.splice(index, 1);
|
||||
|
@ -384,6 +395,7 @@
|
|||
|
||||
outputPath = function(source, base, extension) {
|
||||
var baseDir, basename, dir, srcDir;
|
||||
|
||||
if (extension == null) {
|
||||
extension = ".js";
|
||||
}
|
||||
|
@ -396,6 +408,7 @@
|
|||
|
||||
writeJs = function(base, sourcePath, js, jsPath, generatedSourceMap) {
|
||||
var compile, jsDir, sourceMapPath;
|
||||
|
||||
if (generatedSourceMap == null) {
|
||||
generatedSourceMap = null;
|
||||
}
|
||||
|
@ -444,6 +457,7 @@
|
|||
|
||||
lint = function(file, js) {
|
||||
var conf, jsl, printIt;
|
||||
|
||||
printIt = function(buffer) {
|
||||
return printLine(file + ':\t' + buffer.toString().trim());
|
||||
};
|
||||
|
@ -457,8 +471,10 @@
|
|||
|
||||
printTokens = function(tokens) {
|
||||
var strings, tag, token, value;
|
||||
|
||||
strings = (function() {
|
||||
var _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
||||
token = tokens[_i];
|
||||
|
@ -473,6 +489,7 @@
|
|||
|
||||
parseOptions = function() {
|
||||
var i, o, source, _i, _len;
|
||||
|
||||
optionParser = new optparse.OptionParser(SWITCHES, BANNER);
|
||||
o = opts = optionParser.parse(process.argv.slice(2));
|
||||
o.compile || (o.compile = !!o.output);
|
||||
|
@ -487,6 +504,7 @@
|
|||
|
||||
compileOptions = function(filename, base) {
|
||||
var answer, cwd, jsDir, jsPath;
|
||||
|
||||
answer = {
|
||||
filename: filename,
|
||||
literate: helpers.isLiterate(filename),
|
||||
|
@ -518,6 +536,7 @@
|
|||
|
||||
forkNode = function() {
|
||||
var args, nodeArgs;
|
||||
|
||||
nodeArgs = opts.nodejs.split(/\s+/);
|
||||
args = process.argv.slice(1);
|
||||
args.splice(args.indexOf('--nodejs'), 2);
|
||||
|
|
|
@ -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);
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
|||
|
||||
o = function(patternString, action, options) {
|
||||
var addLocationDataFn, match, patternCount;
|
||||
|
||||
patternString = patternString.replace(/\s{2,}/g, ' ');
|
||||
patternCount = patternString.split(' ').length;
|
||||
if (!action) {
|
||||
|
@ -594,6 +595,7 @@
|
|||
alternatives = grammar[name];
|
||||
grammar[name] = (function() {
|
||||
var _i, _j, _len, _len1, _ref, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
|
||||
alt = alternatives[_i];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var buildLocationData, extend, flatten, last, repeat, _ref;
|
||||
|
||||
|
@ -8,12 +8,14 @@
|
|||
|
||||
exports.ends = function(string, literal, back) {
|
||||
var len;
|
||||
|
||||
len = literal.length;
|
||||
return literal === string.substr(string.length - len - (back || 0), len);
|
||||
};
|
||||
|
||||
exports.repeat = repeat = function(str, n) {
|
||||
var res;
|
||||
|
||||
res = '';
|
||||
while (n > 0) {
|
||||
if (n & 1) {
|
||||
|
@ -27,6 +29,7 @@
|
|||
|
||||
exports.compact = function(array) {
|
||||
var item, _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||
item = array[_i];
|
||||
|
@ -39,6 +42,7 @@
|
|||
|
||||
exports.count = function(string, substr) {
|
||||
var num, pos;
|
||||
|
||||
num = pos = 0;
|
||||
if (!substr.length) {
|
||||
return 1 / 0;
|
||||
|
@ -55,6 +59,7 @@
|
|||
|
||||
extend = exports.extend = function(object, properties) {
|
||||
var key, val;
|
||||
|
||||
for (key in properties) {
|
||||
val = properties[key];
|
||||
object[key] = val;
|
||||
|
@ -64,6 +69,7 @@
|
|||
|
||||
exports.flatten = flatten = function(array) {
|
||||
var element, flattened, _i, _len;
|
||||
|
||||
flattened = [];
|
||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||
element = array[_i];
|
||||
|
@ -78,6 +84,7 @@
|
|||
|
||||
exports.del = function(obj, key) {
|
||||
var val;
|
||||
|
||||
val = obj[key];
|
||||
delete obj[key];
|
||||
return val;
|
||||
|
@ -89,6 +96,7 @@
|
|||
|
||||
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
|
||||
var e, _i, _len;
|
||||
|
||||
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
||||
e = this[_i];
|
||||
if (fn(e)) {
|
||||
|
@ -100,9 +108,11 @@
|
|||
|
||||
exports.invertLiterate = function(code) {
|
||||
var line, lines, maybe_code;
|
||||
|
||||
maybe_code = true;
|
||||
lines = (function() {
|
||||
var _i, _len, _ref1, _results;
|
||||
|
||||
_ref1 = code.split('\n');
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
|
@ -144,6 +154,7 @@
|
|||
|
||||
exports.locationDataToString = function(obj) {
|
||||
var locationData;
|
||||
|
||||
if (("2" in obj) && ("first_line" in obj[2])) {
|
||||
locationData = obj[2];
|
||||
} else if ("first_line" in obj) {
|
||||
|
@ -158,6 +169,7 @@
|
|||
|
||||
exports.baseFileName = function(file, stripExt, pathSep) {
|
||||
var parts;
|
||||
|
||||
if (stripExt == null) {
|
||||
stripExt = false;
|
||||
}
|
||||
|
@ -187,6 +199,7 @@
|
|||
|
||||
exports.throwSyntaxError = function(message, location) {
|
||||
var error, _ref1, _ref2;
|
||||
|
||||
if ((_ref1 = location.last_line) == null) {
|
||||
location.last_line = location.first_line;
|
||||
}
|
||||
|
@ -200,6 +213,7 @@
|
|||
|
||||
exports.prettyErrorMessage = function(error, fileName, code, useColors) {
|
||||
var codeLine, colorize, end, first_column, first_line, last_column, last_line, marker, message, start, _ref1;
|
||||
|
||||
if (!error.location) {
|
||||
return error.stack || ("" + error);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var key, val, _ref;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(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,
|
||||
__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;
|
||||
|
||||
exports.Lexer = Lexer = (function() {
|
||||
|
||||
function Lexer() {}
|
||||
|
||||
Lexer.prototype.tokenize = function(code, opts) {
|
||||
var consumed, i, tag, _ref2;
|
||||
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
|
@ -59,6 +59,7 @@
|
|||
|
||||
Lexer.prototype.identifierToken = function() {
|
||||
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
|
||||
|
||||
if (!(match = IDENTIFIER.exec(this.chunk))) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -141,6 +142,7 @@
|
|||
|
||||
Lexer.prototype.numberToken = function() {
|
||||
var binaryLiteral, lexedLength, match, number, octalLiteral;
|
||||
|
||||
if (!(match = NUMBER.exec(this.chunk))) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -167,6 +169,7 @@
|
|||
|
||||
Lexer.prototype.stringToken = function() {
|
||||
var match, octalEsc, string;
|
||||
|
||||
switch (this.chunk.charAt(0)) {
|
||||
case "'":
|
||||
if (!(match = SIMPLESTR.exec(this.chunk))) {
|
||||
|
@ -199,6 +202,7 @@
|
|||
|
||||
Lexer.prototype.heredocToken = function() {
|
||||
var doc, heredoc, match, quote;
|
||||
|
||||
if (!(match = HEREDOC.exec(this.chunk))) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -222,6 +226,7 @@
|
|||
|
||||
Lexer.prototype.commentToken = function() {
|
||||
var comment, here, match;
|
||||
|
||||
if (!(match = this.chunk.match(COMMENT))) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -237,6 +242,7 @@
|
|||
|
||||
Lexer.prototype.jsToken = function() {
|
||||
var match, script;
|
||||
|
||||
if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -246,6 +252,7 @@
|
|||
|
||||
Lexer.prototype.regexToken = function() {
|
||||
var flags, length, match, prev, regex, _ref2, _ref3;
|
||||
|
||||
if (this.chunk.charAt(0) !== '/') {
|
||||
return 0;
|
||||
}
|
||||
|
@ -273,6 +280,7 @@
|
|||
|
||||
Lexer.prototype.heregexToken = function(match) {
|
||||
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];
|
||||
if (0 > body.indexOf('#{')) {
|
||||
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
|
||||
|
@ -326,6 +334,7 @@
|
|||
|
||||
Lexer.prototype.lineToken = function() {
|
||||
var diff, indent, match, noNewlines, size;
|
||||
|
||||
if (!(match = MULTI_DENT.exec(this.chunk))) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -362,6 +371,7 @@
|
|||
|
||||
Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
|
||||
var dent, len;
|
||||
|
||||
while (moveOut > 0) {
|
||||
len = this.indents.length - 1;
|
||||
if (this.indents[len] === void 0) {
|
||||
|
@ -394,6 +404,7 @@
|
|||
|
||||
Lexer.prototype.whitespaceToken = function() {
|
||||
var match, nline, prev;
|
||||
|
||||
if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -427,6 +438,7 @@
|
|||
|
||||
Lexer.prototype.literalToken = function() {
|
||||
var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5;
|
||||
|
||||
if (match = OPERATOR.exec(this.chunk)) {
|
||||
value = match[0];
|
||||
if (CODE.test(value)) {
|
||||
|
@ -493,6 +505,7 @@
|
|||
|
||||
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
||||
var attempt, herecomment, indent, match, _ref2;
|
||||
|
||||
indent = options.indent, herecomment = options.herecomment;
|
||||
if (herecomment) {
|
||||
if (HEREDOC_ILLEGAL.test(doc)) {
|
||||
|
@ -520,6 +533,7 @@
|
|||
|
||||
Lexer.prototype.tagParameters = function() {
|
||||
var i, stack, tok, tokens;
|
||||
|
||||
if (this.tag() !== ')') {
|
||||
return this;
|
||||
}
|
||||
|
@ -553,6 +567,7 @@
|
|||
|
||||
Lexer.prototype.balancedString = function(str, end) {
|
||||
var continueCount, i, letter, match, prev, stack, _i, _ref2;
|
||||
|
||||
continueCount = 0;
|
||||
stack = [end];
|
||||
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) {
|
||||
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) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -686,6 +702,7 @@
|
|||
|
||||
Lexer.prototype.pair = function(tag) {
|
||||
var size, wanted;
|
||||
|
||||
if (tag !== (wanted = last(this.ends))) {
|
||||
if ('OUTDENT' !== wanted) {
|
||||
this.error("unmatched " + tag);
|
||||
|
@ -699,6 +716,7 @@
|
|||
|
||||
Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
|
||||
var column, lineCount, lines, string;
|
||||
|
||||
if (offset === 0) {
|
||||
return [this.chunkLine, this.chunkColumn];
|
||||
}
|
||||
|
@ -720,6 +738,7 @@
|
|||
|
||||
Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
|
||||
var lastCharacter, locationData, token, _ref2, _ref3;
|
||||
|
||||
if (offsetInChunk == null) {
|
||||
offsetInChunk = 0;
|
||||
}
|
||||
|
@ -736,6 +755,7 @@
|
|||
|
||||
Lexer.prototype.token = function(tag, value, offsetInChunk, length) {
|
||||
var token;
|
||||
|
||||
token = this.makeToken(tag, value, offsetInChunk, length);
|
||||
this.tokens.push(token);
|
||||
return token;
|
||||
|
@ -743,16 +763,19 @@
|
|||
|
||||
Lexer.prototype.tag = function(index, tag) {
|
||||
var tok;
|
||||
|
||||
return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
|
||||
};
|
||||
|
||||
Lexer.prototype.value = function(index, val) {
|
||||
var tok;
|
||||
|
||||
return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
|
||||
};
|
||||
|
||||
Lexer.prototype.unfinished = function() {
|
||||
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');
|
||||
};
|
||||
|
||||
|
@ -804,6 +827,7 @@
|
|||
|
||||
COFFEE_ALIASES = (function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
for (key in COFFEE_ALIAS_MAP) {
|
||||
_results.push(key);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(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,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
|
@ -36,9 +36,9 @@
|
|||
};
|
||||
|
||||
exports.CodeFragment = CodeFragment = (function() {
|
||||
|
||||
function CodeFragment(parent, code) {
|
||||
var _ref2;
|
||||
|
||||
this.code = "" + code;
|
||||
this.locationData = parent != null ? parent.locationData : void 0;
|
||||
this.type = (parent != null ? (_ref2 = parent.constructor) != null ? _ref2.name : void 0 : void 0) || 'unknown';
|
||||
|
@ -54,8 +54,10 @@
|
|||
|
||||
fragmentsToText = function(fragments) {
|
||||
var fragment;
|
||||
|
||||
return ((function() {
|
||||
var _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = fragments.length; _i < _len; _i++) {
|
||||
fragment = fragments[_i];
|
||||
|
@ -66,7 +68,6 @@
|
|||
};
|
||||
|
||||
exports.Base = Base = (function() {
|
||||
|
||||
function Base() {}
|
||||
|
||||
Base.prototype.compile = function(o, lvl) {
|
||||
|
@ -75,6 +76,7 @@
|
|||
|
||||
Base.prototype.compileToFragments = function(o, lvl) {
|
||||
var node;
|
||||
|
||||
o = extend({}, o);
|
||||
if (lvl) {
|
||||
o.level = lvl;
|
||||
|
@ -90,6 +92,7 @@
|
|||
|
||||
Base.prototype.compileClosure = function(o) {
|
||||
var jumpNode;
|
||||
|
||||
if (jumpNode = this.jumps()) {
|
||||
jumpNode.error('cannot use a pure statement in an expression');
|
||||
}
|
||||
|
@ -99,6 +102,7 @@
|
|||
|
||||
Base.prototype.cache = function(o, level, reused) {
|
||||
var ref, sub;
|
||||
|
||||
if (!this.isComplex()) {
|
||||
ref = level ? this.compileToFragments(o, level) : this;
|
||||
return [ref, ref];
|
||||
|
@ -119,6 +123,7 @@
|
|||
|
||||
Base.prototype.makeReturn = function(res) {
|
||||
var me;
|
||||
|
||||
me = this.unwrapAll();
|
||||
if (res) {
|
||||
return new Call(new Literal("" + res + ".push"), [me]);
|
||||
|
@ -129,6 +134,7 @@
|
|||
|
||||
Base.prototype.contains = function(pred) {
|
||||
var node;
|
||||
|
||||
node = void 0;
|
||||
this.traverseChildren(false, function(n) {
|
||||
if (pred(n)) {
|
||||
|
@ -141,6 +147,7 @@
|
|||
|
||||
Base.prototype.lastNonComment = function(list) {
|
||||
var i;
|
||||
|
||||
i = list.length;
|
||||
while (i--) {
|
||||
if (!(list[i] instanceof Comment)) {
|
||||
|
@ -152,6 +159,7 @@
|
|||
|
||||
Base.prototype.toString = function(idt, name) {
|
||||
var tree;
|
||||
|
||||
if (idt == null) {
|
||||
idt = '';
|
||||
}
|
||||
|
@ -170,6 +178,7 @@
|
|||
|
||||
Base.prototype.eachChild = function(func) {
|
||||
var attr, child, _i, _j, _len, _len1, _ref2, _ref3;
|
||||
|
||||
if (!this.children) {
|
||||
return this;
|
||||
}
|
||||
|
@ -204,6 +213,7 @@
|
|||
|
||||
Base.prototype.unwrapAll = function() {
|
||||
var node;
|
||||
|
||||
node = this;
|
||||
while (node !== (node = node.unwrap())) {
|
||||
continue;
|
||||
|
@ -250,6 +260,7 @@
|
|||
|
||||
Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) {
|
||||
var answer, fragments, i, _i, _len;
|
||||
|
||||
answer = [];
|
||||
for (i = _i = 0, _len = fragmentsList.length; _i < _len; i = ++_i) {
|
||||
fragments = fragmentsList[i];
|
||||
|
@ -266,7 +277,6 @@
|
|||
})();
|
||||
|
||||
exports.Block = Block = (function(_super) {
|
||||
|
||||
__extends(Block, _super);
|
||||
|
||||
function Block(nodes) {
|
||||
|
@ -303,6 +313,7 @@
|
|||
|
||||
Block.prototype.isStatement = function(o) {
|
||||
var exp, _i, _len, _ref2;
|
||||
|
||||
_ref2 = this.expressions;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
exp = _ref2[_i];
|
||||
|
@ -315,6 +326,7 @@
|
|||
|
||||
Block.prototype.jumps = function(o) {
|
||||
var exp, _i, _len, _ref2;
|
||||
|
||||
_ref2 = this.expressions;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
exp = _ref2[_i];
|
||||
|
@ -326,6 +338,7 @@
|
|||
|
||||
Block.prototype.makeReturn = function(res) {
|
||||
var expr, len;
|
||||
|
||||
len = this.expressions.length;
|
||||
while (len--) {
|
||||
expr = this.expressions[len];
|
||||
|
@ -353,6 +366,7 @@
|
|||
|
||||
Block.prototype.compileNode = function(o) {
|
||||
var answer, compiledNodes, fragments, index, node, top, _i, _len, _ref2;
|
||||
|
||||
this.tab = o.indent;
|
||||
top = o.level === LEVEL_TOP;
|
||||
compiledNodes = [];
|
||||
|
@ -377,7 +391,7 @@
|
|||
}
|
||||
if (top) {
|
||||
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 {
|
||||
return this.joinFragmentArrays(compiledNodes, '\n');
|
||||
}
|
||||
|
@ -396,6 +410,7 @@
|
|||
|
||||
Block.prototype.compileRoot = function(o) {
|
||||
var exp, fragments, i, name, prelude, preludeExps, rest, _i, _len, _ref2;
|
||||
|
||||
o.indent = o.bare ? '' : TAB;
|
||||
o.level = LEVEL_TOP;
|
||||
this.spaced = true;
|
||||
|
@ -409,6 +424,7 @@
|
|||
if (!o.bare) {
|
||||
preludeExps = (function() {
|
||||
var _j, _len1, _ref3, _results;
|
||||
|
||||
_ref3 = this.expressions;
|
||||
_results = [];
|
||||
for (i = _j = 0, _len1 = _ref3.length; _j < _len1; i = ++_j) {
|
||||
|
@ -439,6 +455,7 @@
|
|||
|
||||
Block.prototype.compileWithDeclarations = function(o) {
|
||||
var assigns, declars, exp, fragments, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
|
||||
|
||||
fragments = [];
|
||||
post = [];
|
||||
_ref2 = this.expressions;
|
||||
|
@ -477,7 +494,7 @@
|
|||
}
|
||||
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);
|
||||
|
@ -495,7 +512,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Literal = Literal = (function(_super) {
|
||||
|
||||
__extends(Literal, _super);
|
||||
|
||||
function Literal(value) {
|
||||
|
@ -516,6 +532,7 @@
|
|||
|
||||
Literal.prototype.isStatement = function() {
|
||||
var _ref2;
|
||||
|
||||
return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
|
||||
};
|
||||
|
||||
|
@ -536,6 +553,7 @@
|
|||
|
||||
Literal.prototype.compileNode = function(o) {
|
||||
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;
|
||||
answer = this.isStatement() ? "" + this.tab + code + ";" : code;
|
||||
return [this.makeCode(answer)];
|
||||
|
@ -550,7 +568,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Undefined = (function(_super) {
|
||||
|
||||
__extends(Undefined, _super);
|
||||
|
||||
function Undefined() {
|
||||
|
@ -571,7 +588,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Null = (function(_super) {
|
||||
|
||||
__extends(Null, _super);
|
||||
|
||||
function Null() {
|
||||
|
@ -592,7 +608,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Bool = (function(_super) {
|
||||
|
||||
__extends(Bool, _super);
|
||||
|
||||
Bool.prototype.isAssignable = NO;
|
||||
|
@ -612,7 +627,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Return = Return = (function(_super) {
|
||||
|
||||
__extends(Return, _super);
|
||||
|
||||
function Return(expr) {
|
||||
|
@ -631,6 +645,7 @@
|
|||
|
||||
Return.prototype.compileToFragments = function(o, level) {
|
||||
var expr, _ref4;
|
||||
|
||||
expr = (_ref4 = this.expression) != null ? _ref4.makeReturn() : void 0;
|
||||
if (expr && !(expr instanceof Return)) {
|
||||
return expr.compileToFragments(o, level);
|
||||
|
@ -641,6 +656,7 @@
|
|||
|
||||
Return.prototype.compileNode = function(o) {
|
||||
var answer;
|
||||
|
||||
answer = [];
|
||||
answer.push(this.makeCode(this.tab + ("return" + [this.expression ? " " : void 0])));
|
||||
if (this.expression) {
|
||||
|
@ -655,7 +671,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Value = Value = (function(_super) {
|
||||
|
||||
__extends(Value, _super);
|
||||
|
||||
function Value(base, props, tag) {
|
||||
|
@ -703,6 +718,7 @@
|
|||
|
||||
Value.prototype.isAtomic = function() {
|
||||
var node, _i, _len, _ref4;
|
||||
|
||||
_ref4 = this.properties.concat(this.base);
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
node = _ref4[_i];
|
||||
|
@ -746,6 +762,7 @@
|
|||
|
||||
Value.prototype.cacheReference = function(o) {
|
||||
var base, bref, name, nref;
|
||||
|
||||
name = last(this.properties);
|
||||
if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
|
||||
return [this, this];
|
||||
|
@ -768,6 +785,7 @@
|
|||
|
||||
Value.prototype.compileNode = function(o) {
|
||||
var fragments, prop, props, _i, _len;
|
||||
|
||||
this.base.front = this.front;
|
||||
props = this.properties;
|
||||
fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null));
|
||||
|
@ -784,8 +802,10 @@
|
|||
Value.prototype.unfoldSoak = function(o) {
|
||||
var _ref4,
|
||||
_this = this;
|
||||
|
||||
return (_ref4 = this.unfoldedSoak) != null ? _ref4 : this.unfoldedSoak = (function() {
|
||||
var fst, i, ifn, prop, ref, snd, _i, _len, _ref5, _ref6;
|
||||
|
||||
if (ifn = _this.base.unfoldSoak(o)) {
|
||||
(_ref5 = ifn.body.properties).push.apply(_ref5, _this.properties);
|
||||
return ifn;
|
||||
|
@ -817,7 +837,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Comment = Comment = (function(_super) {
|
||||
|
||||
__extends(Comment, _super);
|
||||
|
||||
function Comment(comment) {
|
||||
|
@ -830,6 +849,7 @@
|
|||
|
||||
Comment.prototype.compileNode = function(o, level) {
|
||||
var code;
|
||||
|
||||
code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n");
|
||||
if ((level || o.level) === LEVEL_TOP) {
|
||||
code = o.indent + code;
|
||||
|
@ -842,7 +862,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Call = Call = (function(_super) {
|
||||
|
||||
__extends(Call, _super);
|
||||
|
||||
function Call(variable, args, soak) {
|
||||
|
@ -857,6 +876,7 @@
|
|||
|
||||
Call.prototype.newInstance = function() {
|
||||
var base, _ref4;
|
||||
|
||||
base = ((_ref4 = this.variable) != null ? _ref4.base : void 0) || this.variable;
|
||||
if (base instanceof Call && !base.isNew) {
|
||||
base.newInstance();
|
||||
|
@ -868,6 +888,7 @@
|
|||
|
||||
Call.prototype.superReference = function(o) {
|
||||
var accesses, method;
|
||||
|
||||
method = o.scope.namedMethod();
|
||||
if (method != null ? method.klass : void 0) {
|
||||
accesses = [new Access(new Literal('__super__'))];
|
||||
|
@ -885,12 +906,14 @@
|
|||
|
||||
Call.prototype.superThis = function(o) {
|
||||
var method;
|
||||
|
||||
method = o.scope.method;
|
||||
return (method && !method.klass && method.context) || "this";
|
||||
};
|
||||
|
||||
Call.prototype.unfoldSoak = function(o) {
|
||||
var call, ifn, left, list, rite, _i, _len, _ref4, _ref5;
|
||||
|
||||
if (this.soak) {
|
||||
if (this.variable) {
|
||||
if (ifn = unfoldSoak(o, this, 'variable')) {
|
||||
|
@ -941,6 +964,7 @@
|
|||
|
||||
Call.prototype.compileNode = function(o) {
|
||||
var arg, argIndex, compiledArgs, compiledArray, fragments, preface, _i, _len, _ref4, _ref5;
|
||||
|
||||
if ((_ref4 = this.variable) != null) {
|
||||
_ref4.front = this.front;
|
||||
}
|
||||
|
@ -978,6 +1002,7 @@
|
|||
|
||||
Call.prototype.compileSplat = function(o, splatArgs) {
|
||||
var answer, base, fun, idt, name, ref;
|
||||
|
||||
if (this.isSuper) {
|
||||
return [].concat(this.makeCode("" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")"));
|
||||
}
|
||||
|
@ -1011,7 +1036,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Extends = Extends = (function(_super) {
|
||||
|
||||
__extends(Extends, _super);
|
||||
|
||||
function Extends(child, parent) {
|
||||
|
@ -1030,7 +1054,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Access = Access = (function(_super) {
|
||||
|
||||
__extends(Access, _super);
|
||||
|
||||
function Access(name, tag) {
|
||||
|
@ -1043,6 +1066,7 @@
|
|||
|
||||
Access.prototype.compileToFragments = function(o) {
|
||||
var name;
|
||||
|
||||
name = this.name.compileToFragments(o);
|
||||
if (IDENTIFIER.test(fragmentsToText(name))) {
|
||||
name.unshift(this.makeCode("."));
|
||||
|
@ -1060,7 +1084,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Index = Index = (function(_super) {
|
||||
|
||||
__extends(Index, _super);
|
||||
|
||||
function Index(index) {
|
||||
|
@ -1082,7 +1105,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Range = Range = (function(_super) {
|
||||
|
||||
__extends(Range, _super);
|
||||
|
||||
Range.prototype.children = ['from', 'to'];
|
||||
|
@ -1096,6 +1118,7 @@
|
|||
|
||||
Range.prototype.compileVariables = function(o) {
|
||||
var step, _ref4, _ref5, _ref6, _ref7;
|
||||
|
||||
o = merge(o, {
|
||||
top: true
|
||||
});
|
||||
|
@ -1112,6 +1135,7 @@
|
|||
|
||||
Range.prototype.compileNode = function(o) {
|
||||
var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref4, _ref5;
|
||||
|
||||
if (!this.fromVar) {
|
||||
this.compileVariables(o);
|
||||
}
|
||||
|
@ -1143,6 +1167,7 @@
|
|||
|
||||
Range.prototype.compileArray = function(o) {
|
||||
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) {
|
||||
range = (function() {
|
||||
_results = [];
|
||||
|
@ -1183,7 +1208,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Slice = Slice = (function(_super) {
|
||||
|
||||
__extends(Slice, _super);
|
||||
|
||||
Slice.prototype.children = ['range'];
|
||||
|
@ -1195,6 +1219,7 @@
|
|||
|
||||
Slice.prototype.compileNode = function(o) {
|
||||
var compiled, compiledText, from, fromCompiled, to, toStr, _ref4;
|
||||
|
||||
_ref4 = this.range, to = _ref4.to, from = _ref4.from;
|
||||
fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')];
|
||||
if (to) {
|
||||
|
@ -1212,7 +1237,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Obj = Obj = (function(_super) {
|
||||
|
||||
__extends(Obj, _super);
|
||||
|
||||
function Obj(props, generated) {
|
||||
|
@ -1224,6 +1248,7 @@
|
|||
|
||||
Obj.prototype.compileNode = function(o) {
|
||||
var answer, i, idt, indent, join, lastNoncom, node, prop, props, _i, _j, _len, _len1;
|
||||
|
||||
props = this.properties;
|
||||
if (!props.length) {
|
||||
return [this.makeCode(this.front ? '({})' : '{}')];
|
||||
|
@ -1274,6 +1299,7 @@
|
|||
|
||||
Obj.prototype.assigns = function(name) {
|
||||
var prop, _i, _len, _ref4;
|
||||
|
||||
_ref4 = this.properties;
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
prop = _ref4[_i];
|
||||
|
@ -1289,7 +1315,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Arr = Arr = (function(_super) {
|
||||
|
||||
__extends(Arr, _super);
|
||||
|
||||
function Arr(objs) {
|
||||
|
@ -1300,6 +1325,7 @@
|
|||
|
||||
Arr.prototype.compileNode = function(o) {
|
||||
var answer, compiledObjs, fragments, index, obj, _i, _len;
|
||||
|
||||
if (!this.objects.length) {
|
||||
return [this.makeCode('[]')];
|
||||
}
|
||||
|
@ -1311,6 +1337,7 @@
|
|||
answer = [];
|
||||
compiledObjs = (function() {
|
||||
var _i, _len, _ref4, _results;
|
||||
|
||||
_ref4 = this.objects;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
|
@ -1338,6 +1365,7 @@
|
|||
|
||||
Arr.prototype.assigns = function(name) {
|
||||
var obj, _i, _len, _ref4;
|
||||
|
||||
_ref4 = this.objects;
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
obj = _ref4[_i];
|
||||
|
@ -1353,7 +1381,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Class = Class = (function(_super) {
|
||||
|
||||
__extends(Class, _super);
|
||||
|
||||
function Class(variable, parent, body) {
|
||||
|
@ -1368,6 +1395,7 @@
|
|||
|
||||
Class.prototype.determineName = function() {
|
||||
var decl, tail;
|
||||
|
||||
if (!this.variable) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1396,6 +1424,7 @@
|
|||
|
||||
Class.prototype.addBoundFunctions = function(o) {
|
||||
var bvar, lhs, _i, _len, _ref4;
|
||||
|
||||
_ref4 = this.boundFuncs;
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
bvar = _ref4[_i];
|
||||
|
@ -1406,9 +1435,11 @@
|
|||
|
||||
Class.prototype.addProperties = function(node, name, o) {
|
||||
var assign, base, exprs, func, props;
|
||||
|
||||
props = node.base.properties.slice(0);
|
||||
exprs = (function() {
|
||||
var _results;
|
||||
|
||||
_results = [];
|
||||
while (assign = props.shift()) {
|
||||
if (assign instanceof Assign) {
|
||||
|
@ -1452,8 +1483,10 @@
|
|||
|
||||
Class.prototype.walkBody = function(name, o) {
|
||||
var _this = this;
|
||||
|
||||
return this.traverseChildren(false, function(child) {
|
||||
var cont, exps, i, node, _i, _len, _ref4;
|
||||
|
||||
cont = true;
|
||||
if (child instanceof Class) {
|
||||
return false;
|
||||
|
@ -1475,6 +1508,7 @@
|
|||
|
||||
Class.prototype.hoistDirectivePrologue = function() {
|
||||
var expressions, index, node;
|
||||
|
||||
index = 0;
|
||||
expressions = this.body.expressions;
|
||||
while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
|
||||
|
@ -1485,6 +1519,7 @@
|
|||
|
||||
Class.prototype.ensureConstructor = function(name, o) {
|
||||
var missing, ref, superCall;
|
||||
|
||||
missing = !this.ctor;
|
||||
this.ctor || (this.ctor = new Code);
|
||||
this.ctor.ctor = this.ctor.name = name;
|
||||
|
@ -1514,6 +1549,7 @@
|
|||
|
||||
Class.prototype.compileNode = function(o) {
|
||||
var call, decl, klass, lname, name, params, _ref4;
|
||||
|
||||
decl = this.determineName();
|
||||
name = decl || '_Class';
|
||||
if (name.reserved) {
|
||||
|
@ -1550,11 +1586,11 @@
|
|||
})(Base);
|
||||
|
||||
exports.Assign = Assign = (function(_super) {
|
||||
|
||||
__extends(Assign, _super);
|
||||
|
||||
function Assign(variable, value, context, options) {
|
||||
var forbidden, name, _ref4;
|
||||
|
||||
this.variable = variable;
|
||||
this.value = value;
|
||||
this.context = context;
|
||||
|
@ -1582,6 +1618,7 @@
|
|||
|
||||
Assign.prototype.compileNode = function(o) {
|
||||
var answer, compiledName, isValue, match, name, val, varBase, _ref4, _ref5, _ref6, _ref7;
|
||||
|
||||
if (isValue = this.variable instanceof Value) {
|
||||
if (this.variable.isArray() || this.variable.isObject()) {
|
||||
return this.compilePatternMatch(o);
|
||||
|
@ -1628,6 +1665,7 @@
|
|||
|
||||
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;
|
||||
|
||||
top = o.level === LEVEL_TOP;
|
||||
value = this.value;
|
||||
objects = this.variable.base.objects;
|
||||
|
@ -1725,6 +1763,7 @@
|
|||
|
||||
Assign.prototype.compileConditional = function(o) {
|
||||
var left, right, _ref4;
|
||||
|
||||
_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)) {
|
||||
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) {
|
||||
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;
|
||||
name = this.variable.compile(o);
|
||||
if (from) {
|
||||
|
@ -1773,7 +1813,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Code = Code = (function(_super) {
|
||||
|
||||
__extends(Code, _super);
|
||||
|
||||
function Code(params, body, tag) {
|
||||
|
@ -1795,6 +1834,7 @@
|
|||
|
||||
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;
|
||||
|
||||
o.scope = new Scope(o.scope, this.body, this);
|
||||
o.scope.shared = del(o, 'sharedScope');
|
||||
o.indent += TAB;
|
||||
|
@ -1825,6 +1865,7 @@
|
|||
}
|
||||
splats = new Assign(new Value(new Arr((function() {
|
||||
var _k, _len2, _ref6, _results;
|
||||
|
||||
_ref6 = this.params;
|
||||
_results = [];
|
||||
for (_k = 0, _len2 = _ref6.length; _k < _len2; _k++) {
|
||||
|
@ -1918,6 +1959,7 @@
|
|||
|
||||
Code.prototype.eachParamName = function(iterator) {
|
||||
var param, _i, _len, _ref4, _results;
|
||||
|
||||
_ref4 = this.params;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
|
@ -1938,11 +1980,11 @@
|
|||
})(Base);
|
||||
|
||||
exports.Param = Param = (function(_super) {
|
||||
|
||||
__extends(Param, _super);
|
||||
|
||||
function Param(name, value, splat) {
|
||||
var _ref4;
|
||||
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.splat = splat;
|
||||
|
@ -1959,6 +2001,7 @@
|
|||
|
||||
Param.prototype.asReference = function(o) {
|
||||
var node;
|
||||
|
||||
if (this.reference) {
|
||||
return this.reference;
|
||||
}
|
||||
|
@ -1984,11 +2027,13 @@
|
|||
|
||||
Param.prototype.eachName = function(iterator, name) {
|
||||
var atParam, node, obj, _i, _len, _ref4;
|
||||
|
||||
if (name == null) {
|
||||
name = this.name;
|
||||
}
|
||||
atParam = function(obj) {
|
||||
var node;
|
||||
|
||||
node = obj.properties[0].name;
|
||||
if (!node.value.reserved) {
|
||||
return iterator(node.value, node);
|
||||
|
@ -2027,7 +2072,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Splat = Splat = (function(_super) {
|
||||
|
||||
__extends(Splat, _super);
|
||||
|
||||
Splat.prototype.children = ['name'];
|
||||
|
@ -2052,6 +2096,7 @@
|
|||
|
||||
Splat.compileSplattedArray = function(o, list, apply) {
|
||||
var args, base, compiledNode, concatPart, fragments, i, index, node, _i, _len;
|
||||
|
||||
index = -1;
|
||||
while ((node = list[++index]) && !(node instanceof Splat)) {
|
||||
continue;
|
||||
|
@ -2080,6 +2125,7 @@
|
|||
}
|
||||
base = (function() {
|
||||
var _j, _len1, _ref4, _results;
|
||||
|
||||
_ref4 = list.slice(0, index);
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
|
||||
|
@ -2098,7 +2144,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.While = While = (function(_super) {
|
||||
|
||||
__extends(While, _super);
|
||||
|
||||
function While(condition, options) {
|
||||
|
@ -2128,6 +2173,7 @@
|
|||
|
||||
While.prototype.jumps = function() {
|
||||
var expressions, node, _i, _len;
|
||||
|
||||
expressions = this.body.expressions;
|
||||
if (!expressions.length) {
|
||||
return false;
|
||||
|
@ -2145,6 +2191,7 @@
|
|||
|
||||
While.prototype.compileNode = function(o) {
|
||||
var answer, body, rvar, set;
|
||||
|
||||
o.indent += TAB;
|
||||
set = '';
|
||||
body = this.body;
|
||||
|
@ -2225,16 +2272,19 @@
|
|||
|
||||
Op.prototype.isComplex = function() {
|
||||
var _ref4;
|
||||
|
||||
return !(this.isUnary() && ((_ref4 = this.operator) === '+' || _ref4 === '-')) || this.first.isComplex();
|
||||
};
|
||||
|
||||
Op.prototype.isChainable = function() {
|
||||
var _ref4;
|
||||
|
||||
return (_ref4 = this.operator) === '<' || _ref4 === '>' || _ref4 === '>=' || _ref4 === '<=' || _ref4 === '===' || _ref4 === '!==';
|
||||
};
|
||||
|
||||
Op.prototype.invert = function() {
|
||||
var allInvertable, curr, fst, op, _ref4;
|
||||
|
||||
if (this.isChainable() && this.first.isChainable()) {
|
||||
allInvertable = true;
|
||||
curr = this;
|
||||
|
@ -2269,11 +2319,13 @@
|
|||
|
||||
Op.prototype.unfoldSoak = function(o) {
|
||||
var _ref4;
|
||||
|
||||
return ((_ref4 = this.operator) === '++' || _ref4 === '--' || _ref4 === 'delete') && unfoldSoak(o, this, 'first');
|
||||
};
|
||||
|
||||
Op.prototype.generateDo = function(exp) {
|
||||
var call, func, param, passedParams, ref, _i, _len, _ref4;
|
||||
|
||||
passedParams = [];
|
||||
func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
|
||||
_ref4 = func.params || [];
|
||||
|
@ -2293,6 +2345,7 @@
|
|||
|
||||
Op.prototype.compileNode = function(o) {
|
||||
var answer, isChain, _ref4, _ref5;
|
||||
|
||||
isChain = this.isChainable() && this.first.isChainable();
|
||||
if (!isChain) {
|
||||
this.first.front = this.front;
|
||||
|
@ -2322,6 +2375,7 @@
|
|||
|
||||
Op.prototype.compileChain = function(o) {
|
||||
var fragments, fst, shared, _ref4;
|
||||
|
||||
_ref4 = this.first.second.cache(o), this.first.second = _ref4[0], shared = _ref4[1];
|
||||
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));
|
||||
|
@ -2330,6 +2384,7 @@
|
|||
|
||||
Op.prototype.compileExistence = function(o) {
|
||||
var fst, ref;
|
||||
|
||||
if (this.first.isComplex()) {
|
||||
ref = new Literal(o.scope.freeVariable('ref'));
|
||||
fst = new Parens(new Assign(ref, this.first));
|
||||
|
@ -2344,6 +2399,7 @@
|
|||
|
||||
Op.prototype.compileUnary = function(o) {
|
||||
var op, parts, plusMinus;
|
||||
|
||||
parts = [];
|
||||
op = this.operator;
|
||||
parts.push([this.makeCode(op)]);
|
||||
|
@ -2377,7 +2433,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.In = In = (function(_super) {
|
||||
|
||||
__extends(In, _super);
|
||||
|
||||
function In(object, array) {
|
||||
|
@ -2391,6 +2446,7 @@
|
|||
|
||||
In.prototype.compileNode = function(o) {
|
||||
var hasSplat, obj, _i, _len, _ref4;
|
||||
|
||||
if (this.array instanceof Value && this.array.isArray()) {
|
||||
_ref4 = this.array.base.objects;
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
|
@ -2410,6 +2466,7 @@
|
|||
|
||||
In.prototype.compileOrTest = function(o) {
|
||||
var cmp, cnj, i, item, ref, sub, tests, _i, _len, _ref4, _ref5, _ref6;
|
||||
|
||||
if (this.array.base.objects.length === 0) {
|
||||
return [this.makeCode("" + (!!this.negated))];
|
||||
}
|
||||
|
@ -2433,6 +2490,7 @@
|
|||
|
||||
In.prototype.compileLoopTest = function(o) {
|
||||
var fragments, ref, sub, _ref4;
|
||||
|
||||
_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')));
|
||||
if ((fragmentsToText(sub)) === (fragmentsToText(ref))) {
|
||||
|
@ -2455,7 +2513,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Try = Try = (function(_super) {
|
||||
|
||||
__extends(Try, _super);
|
||||
|
||||
function Try(attempt, errorVariable, recovery, ensure) {
|
||||
|
@ -2471,6 +2528,7 @@
|
|||
|
||||
Try.prototype.jumps = function(o) {
|
||||
var _ref4;
|
||||
|
||||
return this.attempt.jumps(o) || ((_ref4 = this.recovery) != null ? _ref4.jumps(o) : void 0);
|
||||
};
|
||||
|
||||
|
@ -2486,6 +2544,7 @@
|
|||
|
||||
Try.prototype.compileNode = function(o) {
|
||||
var catchPart, ensurePart, placeholder, tryPart, _ref4;
|
||||
|
||||
o.indent += TAB;
|
||||
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) {}')] : [];
|
||||
|
@ -2498,7 +2557,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Throw = Throw = (function(_super) {
|
||||
|
||||
__extends(Throw, _super);
|
||||
|
||||
function Throw(expression) {
|
||||
|
@ -2522,7 +2580,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Existence = Existence = (function(_super) {
|
||||
|
||||
__extends(Existence, _super);
|
||||
|
||||
function Existence(expression) {
|
||||
|
@ -2535,6 +2592,7 @@
|
|||
|
||||
Existence.prototype.compileNode = function(o) {
|
||||
var cmp, cnj, code, _ref4;
|
||||
|
||||
this.expression.front = this.front;
|
||||
code = this.expression.compile(o, LEVEL_OP);
|
||||
if (IDENTIFIER.test(code) && !o.scope.check(code)) {
|
||||
|
@ -2551,7 +2609,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.Parens = Parens = (function(_super) {
|
||||
|
||||
__extends(Parens, _super);
|
||||
|
||||
function Parens(body) {
|
||||
|
@ -2570,6 +2627,7 @@
|
|||
|
||||
Parens.prototype.compileNode = function(o) {
|
||||
var bare, expr, fragments;
|
||||
|
||||
expr = this.body.unwrap();
|
||||
if (expr instanceof Value && expr.isAtomic()) {
|
||||
expr.front = this.front;
|
||||
|
@ -2589,11 +2647,11 @@
|
|||
})(Base);
|
||||
|
||||
exports.For = For = (function(_super) {
|
||||
|
||||
__extends(For, _super);
|
||||
|
||||
function For(body, source) {
|
||||
var _ref4;
|
||||
|
||||
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.own = !!source.own;
|
||||
|
@ -2619,6 +2677,7 @@
|
|||
|
||||
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;
|
||||
|
||||
body = Block.wrap([this.body]);
|
||||
lastJumps = (_ref4 = last(body.expressions)) != null ? _ref4.jumps() : void 0;
|
||||
if (lastJumps && lastJumps instanceof Return) {
|
||||
|
@ -2732,6 +2791,7 @@
|
|||
|
||||
For.prototype.pluckDirectCall = function(o, body) {
|
||||
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
|
||||
|
||||
defs = [];
|
||||
_ref4 = body.expressions;
|
||||
for (idx = _i = 0, _len = _ref4.length; _i < _len; idx = ++_i) {
|
||||
|
@ -2761,7 +2821,6 @@
|
|||
})(While);
|
||||
|
||||
exports.Switch = Switch = (function(_super) {
|
||||
|
||||
__extends(Switch, _super);
|
||||
|
||||
function Switch(subject, cases, otherwise) {
|
||||
|
@ -2776,6 +2835,7 @@
|
|||
|
||||
Switch.prototype.jumps = function(o) {
|
||||
var block, conds, _i, _len, _ref4, _ref5, _ref6;
|
||||
|
||||
if (o == null) {
|
||||
o = {
|
||||
block: true
|
||||
|
@ -2793,6 +2853,7 @@
|
|||
|
||||
Switch.prototype.makeReturn = function(res) {
|
||||
var pair, _i, _len, _ref4, _ref5;
|
||||
|
||||
_ref4 = this.cases;
|
||||
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
||||
pair = _ref4[_i];
|
||||
|
@ -2809,6 +2870,7 @@
|
|||
|
||||
Switch.prototype.compileNode = function(o) {
|
||||
var block, body, cond, conditions, expr, fragments, i, idt1, idt2, _i, _j, _len, _len1, _ref4, _ref5, _ref6;
|
||||
|
||||
idt1 = o.indent + 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"));
|
||||
|
@ -2847,7 +2909,6 @@
|
|||
})(Base);
|
||||
|
||||
exports.If = If = (function(_super) {
|
||||
|
||||
__extends(If, _super);
|
||||
|
||||
function If(condition, body, options) {
|
||||
|
@ -2865,11 +2926,13 @@
|
|||
|
||||
If.prototype.bodyNode = function() {
|
||||
var _ref4;
|
||||
|
||||
return (_ref4 = this.body) != null ? _ref4.unwrap() : void 0;
|
||||
};
|
||||
|
||||
If.prototype.elseBodyNode = function() {
|
||||
var _ref4;
|
||||
|
||||
return (_ref4 = this.elseBody) != null ? _ref4.unwrap() : void 0;
|
||||
};
|
||||
|
||||
|
@ -2885,11 +2948,13 @@
|
|||
|
||||
If.prototype.isStatement = function(o) {
|
||||
var _ref4;
|
||||
|
||||
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) {
|
||||
var _ref4;
|
||||
|
||||
return this.body.jumps(o) || ((_ref4 = this.elseBody) != null ? _ref4.jumps(o) : void 0);
|
||||
};
|
||||
|
||||
|
@ -2920,6 +2985,7 @@
|
|||
|
||||
If.prototype.compileStatement = function(o) {
|
||||
var answer, body, child, cond, exeq, ifPart, indent;
|
||||
|
||||
child = del(o, 'chainChild');
|
||||
exeq = del(o, 'isExistentialEquals');
|
||||
if (exeq) {
|
||||
|
@ -2953,6 +3019,7 @@
|
|||
|
||||
If.prototype.compileExpression = function(o) {
|
||||
var alt, body, cond, fragments;
|
||||
|
||||
cond = this.condition.compileToFragments(o, LEVEL_COND);
|
||||
body = this.bodyNode().compileToFragments(o, LEVEL_LIST);
|
||||
alt = this.elseBodyNode() ? this.elseBodyNode().compileToFragments(o, LEVEL_LIST) : [this.makeCode('void 0')];
|
||||
|
@ -2975,6 +3042,7 @@
|
|||
Closure = {
|
||||
wrap: function(expressions, statement, noReturn) {
|
||||
var args, argumentsNode, call, func, meth;
|
||||
|
||||
if (expressions.jumps()) {
|
||||
return expressions;
|
||||
}
|
||||
|
@ -3010,6 +3078,7 @@
|
|||
|
||||
unfoldSoak = function(o, parent, name) {
|
||||
var ifn;
|
||||
|
||||
if (!(ifn = parent[name].unfoldSoak(o))) {
|
||||
return;
|
||||
}
|
||||
|
@ -3062,6 +3131,7 @@
|
|||
|
||||
utility = function(name) {
|
||||
var ref;
|
||||
|
||||
ref = "__" + name;
|
||||
Scope.root.assign(ref, UTILITIES[name]());
|
||||
return ref;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments;
|
||||
|
||||
exports.OptionParser = OptionParser = (function() {
|
||||
|
||||
function OptionParser(rules, banner) {
|
||||
this.banner = banner;
|
||||
this.rules = buildRules(rules);
|
||||
|
@ -11,6 +10,7 @@
|
|||
|
||||
OptionParser.prototype.parse = function(args) {
|
||||
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, seenNonOptionArg, skippingArgument, value, _i, _j, _len, _len1, _ref;
|
||||
|
||||
options = {
|
||||
"arguments": []
|
||||
};
|
||||
|
@ -59,6 +59,7 @@
|
|||
|
||||
OptionParser.prototype.help = function() {
|
||||
var letPart, lines, rule, spaces, _i, _len, _ref;
|
||||
|
||||
lines = [];
|
||||
if (this.banner) {
|
||||
lines.unshift("" + this.banner + "\n");
|
||||
|
@ -88,6 +89,7 @@
|
|||
|
||||
buildRules = function(rules) {
|
||||
var tuple, _i, _len, _results;
|
||||
|
||||
_results = [];
|
||||
for (_i = 0, _len = rules.length; _i < _len; _i++) {
|
||||
tuple = rules[_i];
|
||||
|
@ -101,6 +103,7 @@
|
|||
|
||||
buildRule = function(shortFlag, longFlag, description, options) {
|
||||
var match;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -118,6 +121,7 @@
|
|||
|
||||
normalizeArguments = function(args) {
|
||||
var arg, l, match, result, _i, _j, _len, _len1, _ref;
|
||||
|
||||
args = args.slice(0);
|
||||
result = [];
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var CoffeeScript, addMultilineHandler, merge, nodeREPL, prettyErrorMessage, replDefaults, vm, _ref;
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
|||
prompt: 'coffee> ',
|
||||
"eval": function(input, context, filename, cb) {
|
||||
var Assign, Block, Literal, Value, ast, err, js, _ref1;
|
||||
|
||||
input = input.replace(/\uFF00/g, '\n');
|
||||
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
|
||||
_ref1 = require('./nodes'), Block = _ref1.Block, Assign = _ref1.Assign, Value = _ref1.Value, Literal = _ref1.Literal;
|
||||
|
@ -34,6 +35,7 @@
|
|||
|
||||
addMultilineHandler = function(repl) {
|
||||
var inputStream, multiline, nodeLineListener, outputStream, rli;
|
||||
|
||||
rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream;
|
||||
multiline = {
|
||||
enabled: false,
|
||||
|
@ -89,6 +91,7 @@
|
|||
module.exports = {
|
||||
start: function(opts) {
|
||||
var build, major, minor, repl, _ref1;
|
||||
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(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,
|
||||
__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) {
|
||||
var tok;
|
||||
|
||||
tok = [tag, value];
|
||||
tok.generated = true;
|
||||
return tok;
|
||||
};
|
||||
|
||||
exports.Rewriter = (function() {
|
||||
|
||||
function Rewriter() {}
|
||||
|
||||
Rewriter.prototype.rewrite = function(tokens) {
|
||||
|
@ -30,6 +30,7 @@
|
|||
|
||||
Rewriter.prototype.scanTokens = function(block) {
|
||||
var i, token, tokens;
|
||||
|
||||
tokens = this.tokens;
|
||||
i = 0;
|
||||
while (token = tokens[i]) {
|
||||
|
@ -40,6 +41,7 @@
|
|||
|
||||
Rewriter.prototype.detectEnd = function(i, condition, action) {
|
||||
var levels, token, tokens, _ref, _ref1;
|
||||
|
||||
tokens = this.tokens;
|
||||
levels = 0;
|
||||
while (token = tokens[i]) {
|
||||
|
@ -61,6 +63,7 @@
|
|||
|
||||
Rewriter.prototype.removeLeadingNewlines = function() {
|
||||
var i, tag, _i, _len, _ref;
|
||||
|
||||
_ref = this.tokens;
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
tag = _ref[i][0];
|
||||
|
@ -76,6 +79,7 @@
|
|||
Rewriter.prototype.removeMidExpressionNewlines = function() {
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var _ref;
|
||||
|
||||
if (!(token[0] === 'TERMINATOR' && (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0))) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -86,8 +90,10 @@
|
|||
|
||||
Rewriter.prototype.closeOpenCalls = function() {
|
||||
var action, condition;
|
||||
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
|
||||
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
||||
};
|
||||
action = function(token, i) {
|
||||
|
@ -103,8 +109,10 @@
|
|||
|
||||
Rewriter.prototype.closeOpenIndexes = function() {
|
||||
var action, condition;
|
||||
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
|
||||
return (_ref = token[0]) === ']' || _ref === 'INDEX_END';
|
||||
};
|
||||
action = function(token, i) {
|
||||
|
@ -120,6 +128,7 @@
|
|||
|
||||
Rewriter.prototype.matchTags = function() {
|
||||
var fuzz, i, j, pattern, _i, _ref, _ref1;
|
||||
|
||||
i = arguments[0], pattern = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
fuzz = 0;
|
||||
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) {
|
||||
var backStack, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
||||
|
||||
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))) {
|
||||
if (_ref = this.tag(i), __indexOf.call(EXPRESSION_END, _ref) >= 0) {
|
||||
|
@ -160,9 +170,11 @@
|
|||
|
||||
Rewriter.prototype.addImplicitBracesAndParens = function() {
|
||||
var stack;
|
||||
|
||||
stack = [];
|
||||
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;
|
||||
|
||||
tag = token[0];
|
||||
prevTag = (i > 0 ? tokens[i - 1] : [])[0];
|
||||
nextTag = (i < tokens.length - 1 ? tokens[i + 1] : [])[0];
|
||||
|
@ -175,22 +187,27 @@
|
|||
};
|
||||
inImplicit = function() {
|
||||
var _ref, _ref1;
|
||||
|
||||
return (_ref = stackTop()) != null ? (_ref1 = _ref[2]) != null ? _ref1.ours : void 0 : void 0;
|
||||
};
|
||||
inImplicitCall = function() {
|
||||
var _ref;
|
||||
|
||||
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '(';
|
||||
};
|
||||
inImplicitObject = function() {
|
||||
var _ref;
|
||||
|
||||
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '{';
|
||||
};
|
||||
inImplicitControl = function() {
|
||||
var _ref;
|
||||
|
||||
return inImplicit && ((_ref = stackTop()) != null ? _ref[0] : void 0) === 'CONTROL';
|
||||
};
|
||||
startImplicitCall = function(j) {
|
||||
var idx;
|
||||
|
||||
idx = j != null ? j : i;
|
||||
stack.push([
|
||||
'(', idx, {
|
||||
|
@ -209,6 +226,7 @@
|
|||
};
|
||||
startImplicitObject = function(j, startsLine) {
|
||||
var idx;
|
||||
|
||||
if (startsLine == null) {
|
||||
startsLine = true;
|
||||
}
|
||||
|
@ -332,6 +350,7 @@
|
|||
Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var column, line, nextLocation, prevLocation, _ref, _ref1;
|
||||
|
||||
if (token[2]) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -357,9 +376,11 @@
|
|||
|
||||
Rewriter.prototype.addImplicitIndentation = function() {
|
||||
var action, condition, indent, outdent, starter;
|
||||
|
||||
starter = indent = outdent = null;
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
|
||||
return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN'));
|
||||
};
|
||||
action = function(token, i) {
|
||||
|
@ -367,6 +388,7 @@
|
|||
};
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var tag, _ref, _ref1;
|
||||
|
||||
tag = token[0];
|
||||
if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') {
|
||||
tokens.splice(i, 1);
|
||||
|
@ -399,9 +421,11 @@
|
|||
|
||||
Rewriter.prototype.tagPostfixConditionals = function() {
|
||||
var action, condition, original;
|
||||
|
||||
original = null;
|
||||
condition = function(token, i) {
|
||||
var prevTag, tag;
|
||||
|
||||
tag = token[0];
|
||||
prevTag = this.tokens[i - 1][0];
|
||||
return tag === 'TERMINATOR' || (tag === 'INDENT' && __indexOf.call(SINGLE_LINERS, prevTag) < 0);
|
||||
|
@ -423,6 +447,7 @@
|
|||
|
||||
Rewriter.prototype.indentation = function(implicit) {
|
||||
var indent, outdent;
|
||||
|
||||
if (implicit == null) {
|
||||
implicit = false;
|
||||
}
|
||||
|
@ -441,6 +466,7 @@
|
|||
|
||||
Rewriter.prototype.tag = function(i) {
|
||||
var _ref;
|
||||
|
||||
return (_ref = this.tokens[i]) != null ? _ref[0] : void 0;
|
||||
};
|
||||
|
||||
|
@ -466,7 +492,7 @@
|
|||
|
||||
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 = ['+', '-'];
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var Scope, extend, last, _ref;
|
||||
|
||||
_ref = require('./helpers'), extend = _ref.extend, last = _ref.last;
|
||||
|
||||
exports.Scope = Scope = (function() {
|
||||
|
||||
Scope.root = null;
|
||||
|
||||
function Scope(parent, expressions, method) {
|
||||
|
@ -40,6 +39,7 @@
|
|||
|
||||
Scope.prototype.namedMethod = function() {
|
||||
var _ref1;
|
||||
|
||||
if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) {
|
||||
return this.method;
|
||||
}
|
||||
|
@ -63,6 +63,7 @@
|
|||
|
||||
Scope.prototype.check = function(name) {
|
||||
var _ref1;
|
||||
|
||||
return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));
|
||||
};
|
||||
|
||||
|
@ -76,6 +77,7 @@
|
|||
|
||||
Scope.prototype.type = function(name) {
|
||||
var v, _i, _len, _ref1;
|
||||
|
||||
_ref1 = this.variables;
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
v = _ref1[_i];
|
||||
|
@ -88,6 +90,7 @@
|
|||
|
||||
Scope.prototype.freeVariable = function(name, reserve) {
|
||||
var index, temp;
|
||||
|
||||
if (reserve == null) {
|
||||
reserve = true;
|
||||
}
|
||||
|
@ -115,6 +118,7 @@
|
|||
|
||||
Scope.prototype.declaredVariables = function() {
|
||||
var realVars, tempVars, v, _i, _len, _ref1;
|
||||
|
||||
realVars = [];
|
||||
tempVars = [];
|
||||
_ref1 = this.variables;
|
||||
|
@ -129,6 +133,7 @@
|
|||
|
||||
Scope.prototype.assignedVariables = function() {
|
||||
var v, _i, _len, _ref1, _results;
|
||||
|
||||
_ref1 = this.variables;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var BASE64_CHARS, LineMapping, MAX_BASE64_VALUE, VLQ_CONTINUATION_BIT, VLQ_SHIFT, VLQ_VALUE_MASK, decodeBase64Char, encodeBase64Char;
|
||||
|
||||
LineMapping = (function() {
|
||||
|
||||
function LineMapping(generatedLine) {
|
||||
this.generatedLine = generatedLine;
|
||||
this.columnMap = {};
|
||||
|
@ -12,6 +11,7 @@
|
|||
|
||||
LineMapping.prototype.addMapping = function(generatedColumn, _arg, options) {
|
||||
var sourceColumn, sourceLine;
|
||||
|
||||
sourceLine = _arg[0], sourceColumn = _arg[1];
|
||||
if (options == null) {
|
||||
options = {};
|
||||
|
@ -33,6 +33,7 @@
|
|||
|
||||
LineMapping.prototype.getSourcePosition = function(generatedColumn) {
|
||||
var answer, columnMapping, lastColumnMapping, _i, _len, _ref;
|
||||
|
||||
answer = null;
|
||||
lastColumnMapping = null;
|
||||
_ref = this.columnMappings;
|
||||
|
@ -54,13 +55,13 @@
|
|||
})();
|
||||
|
||||
exports.SourceMap = (function() {
|
||||
|
||||
function SourceMap() {
|
||||
this.generatedLines = [];
|
||||
}
|
||||
|
||||
SourceMap.prototype.addMapping = function(sourceLocation, generatedLocation, options) {
|
||||
var generatedColumn, generatedLine, lineMapping;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -74,6 +75,7 @@
|
|||
|
||||
SourceMap.prototype.getSourcePosition = function(_arg) {
|
||||
var answer, generatedColumn, generatedLine, lineMapping;
|
||||
|
||||
generatedLine = _arg[0], generatedColumn = _arg[1];
|
||||
answer = null;
|
||||
lineMapping = this.generatedLines[generatedLine];
|
||||
|
@ -87,6 +89,7 @@
|
|||
|
||||
SourceMap.prototype.forEachMapping = function(fn) {
|
||||
var columnMapping, generatedLineNumber, lineMapping, _i, _len, _ref, _results;
|
||||
|
||||
_ref = this.generatedLines;
|
||||
_results = [];
|
||||
for (generatedLineNumber = _i = 0, _len = _ref.length; _i < _len; generatedLineNumber = ++_i) {
|
||||
|
@ -94,6 +97,7 @@
|
|||
if (lineMapping) {
|
||||
_results.push((function() {
|
||||
var _j, _len1, _ref1, _results1;
|
||||
|
||||
_ref1 = lineMapping.columnMappings;
|
||||
_results1 = [];
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
|
@ -115,6 +119,7 @@
|
|||
|
||||
exports.generateV3SourceMap = function(sourceMap, options, code) {
|
||||
var answer, generatedFile, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, sourceFiles, sourceRoot, writingGeneratedLine;
|
||||
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -180,6 +185,7 @@
|
|||
|
||||
decodeBase64Char = function(char) {
|
||||
var value;
|
||||
|
||||
value = BASE64_CHARS.indexOf(char);
|
||||
if (value === -1) {
|
||||
throw new Error("Invalid Base 64 character: " + char);
|
||||
|
@ -195,6 +201,7 @@
|
|||
|
||||
exports.vlqEncodeValue = function(value) {
|
||||
var answer, nextVlqChunk, signBit, valueToEncode;
|
||||
|
||||
signBit = value < 0 ? 1 : 0;
|
||||
valueToEncode = (Math.abs(value) << 1) + signBit;
|
||||
answer = "";
|
||||
|
@ -211,6 +218,7 @@
|
|||
|
||||
exports.vlqDecodeValue = function(str, offset) {
|
||||
var consumed, continuationShift, done, nextChunkValue, nextVlqChunk, position, signBit, value;
|
||||
|
||||
if (offset == null) {
|
||||
offset = 0;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"description": "Unfancy JavaScript",
|
||||
"keywords": ["javascript", "language", "coffeescript", "compiler"],
|
||||
"author": "Jeremy Ashkenas",
|
||||
"version": "1.6.1",
|
||||
"version": "1.6.2",
|
||||
"licenses": [{
|
||||
"type": "MIT",
|
||||
"url": "https://raw.github.com/jashkenas/coffee-script/master/LICENSE"
|
||||
|
|
|
@ -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 = require
|
||||
|
||||
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
|
||||
compile = CoffeeScript.compile
|
||||
|
||||
# Use standard JavaScript `eval` to eval code.
|
||||
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.
|
||||
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.
|
||||
CoffeeScript.load = (url, callback, options = {}) ->
|
||||
options.sourceFiles = [url]
|
||||
|
@ -67,7 +69,7 @@ runScripts = ->
|
|||
execute()
|
||||
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
|
||||
addEventListener 'DOMContentLoaded', runScripts, no
|
||||
else
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
# 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
|
||||
# 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'
|
||||
vm = require 'vm'
|
||||
|
@ -16,7 +13,7 @@ helpers = require './helpers'
|
|||
sourcemap = require './sourcemap'
|
||||
|
||||
# The current CoffeeScript version number.
|
||||
exports.VERSION = '1.6.1'
|
||||
exports.VERSION = '1.6.2'
|
||||
|
||||
# Expose helpers for testing.
|
||||
exports.helpers = helpers
|
||||
|
@ -157,16 +154,17 @@ if require.extensions
|
|||
for ext in ['.coffee', '.litcoffee', '.coffee.md']
|
||||
require.extensions[ext] = loadFile
|
||||
|
||||
# Patch `child_process.fork` so that Coffee scripts are able to fork both
|
||||
# CoffeeScript files, and JavaScript files, directly.
|
||||
{fork} = child_process
|
||||
child_process.fork = (path, args = [], options = {}) ->
|
||||
execPath = if helpers.isCoffee(path) then 'coffee' else null
|
||||
if not Array.isArray args
|
||||
args = []
|
||||
options = args or {}
|
||||
options.execPath or= execPath
|
||||
fork path, args, options
|
||||
# If we're on Node, patch `child_process.fork` so that Coffee scripts are able
|
||||
# to fork both CoffeeScript files, and JavaScript files, directly.
|
||||
if child_process
|
||||
{fork} = child_process
|
||||
child_process.fork = (path, args = [], options = {}) ->
|
||||
execPath = if helpers.isCoffee(path) then 'coffee' else null
|
||||
if not Array.isArray args
|
||||
args = []
|
||||
options = args or {}
|
||||
options.execPath or= execPath
|
||||
fork path, args, options
|
||||
|
||||
# Instantiate a Lexer for our use here.
|
||||
lexer = new Lexer
|
||||
|
|
|
@ -288,7 +288,7 @@ exports.Block = class Block extends Base
|
|||
compiledNodes.push node.compileToFragments o, LEVEL_LIST
|
||||
if top
|
||||
if @spaced
|
||||
return [].concat @makeCode("\n"), @joinFragmentArrays(compiledNodes, '\n\n'), @makeCode("\n")
|
||||
return [].concat @joinFragmentArrays(compiledNodes, '\n\n'), @makeCode("\n")
|
||||
else
|
||||
return @joinFragmentArrays(compiledNodes, '\n')
|
||||
if compiledNodes.length
|
||||
|
@ -351,7 +351,7 @@ exports.Block = class Block extends Base
|
|||
if assigns
|
||||
fragments.push @makeCode ",\n#{@tab + TAB}" if declars
|
||||
fragments.push @makeCode (scope.assignedVariables().join ",\n#{@tab + TAB}")
|
||||
fragments.push @makeCode ';\n'
|
||||
fragments.push @makeCode ';\n\n'
|
||||
fragments.concat post
|
||||
|
||||
# Wrap up the given nodes as a **Block**, unless it already happens
|
||||
|
@ -1343,7 +1343,7 @@ exports.Code = class Code extends Base
|
|||
|
||||
return [@makeCode(@tab), answer...] if @ctor
|
||||
if @front or (o.level >= LEVEL_ACCESS) then @wrapInBraces answer else answer
|
||||
|
||||
|
||||
eachParamName: (iterator) ->
|
||||
param.eachName iterator for param in @params
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ generate = (tag, value) ->
|
|||
class exports.Rewriter
|
||||
|
||||
# Helpful snippet for debugging:
|
||||
#
|
||||
# console.log (t[0] + '/' + t[1] for t in @tokens).join ' '
|
||||
|
||||
# Rewrite the token stream in multiple passes, one logical filter at
|
||||
|
@ -186,9 +187,12 @@ class exports.Rewriter
|
|||
return forward(1)
|
||||
|
||||
if tag is 'INDENT' and inImplicit()
|
||||
# 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
|
||||
|
||||
# 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
|
||||
#
|
||||
if prevTag not in ['=>', '->', '[', '(', ',', '{', 'TRY', 'ELSE', '=']
|
||||
endImplicitCall() while inImplicitCall()
|
||||
stack.pop() if inImplicitControl()
|
||||
|
@ -223,20 +227,27 @@ class exports.Rewriter
|
|||
return forward(2)
|
||||
|
||||
# Implicit call taking an implicit indented object as first argument.
|
||||
# f
|
||||
# a: b
|
||||
# c: d
|
||||
#
|
||||
# f
|
||||
# a: b
|
||||
# c: d
|
||||
#
|
||||
# and
|
||||
# f
|
||||
# 1
|
||||
# a: b
|
||||
# b: c
|
||||
#
|
||||
# f
|
||||
# 1
|
||||
# a: b
|
||||
# b: c
|
||||
#
|
||||
# Don't accept implicit calls of this type, when on the same line
|
||||
# as the control strucutures below as that may misinterpret constructs like:
|
||||
# if f
|
||||
# a: 1
|
||||
#
|
||||
# if f
|
||||
# a: 1
|
||||
# as
|
||||
# if f(a: 1)
|
||||
#
|
||||
# if f(a: 1)
|
||||
#
|
||||
# which is probably always unintended.
|
||||
# Furthermore don't allow this in literal arrays, as
|
||||
# that creates grammatical ambiguities.
|
||||
|
@ -266,11 +277,13 @@ class exports.Rewriter
|
|||
|
||||
# End implicit calls when chaining method calls
|
||||
# like e.g.:
|
||||
# f ->
|
||||
# a
|
||||
# .g b, ->
|
||||
# c
|
||||
# .h a
|
||||
#
|
||||
# f ->
|
||||
# a
|
||||
# .g b, ->
|
||||
# c
|
||||
# .h a
|
||||
#
|
||||
if prevTag is 'OUTDENT' and inImplicitCall() and tag in ['.', '?.', '::', '?::']
|
||||
endImplicitCall()
|
||||
return forward(1)
|
||||
|
@ -299,14 +312,16 @@ class exports.Rewriter
|
|||
# Close implicit object if comma is the last character
|
||||
# and what comes after doesn't look like it belongs.
|
||||
# This is used for trailing commas and calls, like:
|
||||
# x =
|
||||
# a: b,
|
||||
# c: d,
|
||||
# e = 2
|
||||
#
|
||||
# x =
|
||||
# a: b,
|
||||
# c: d,
|
||||
# e = 2
|
||||
#
|
||||
# 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
|
||||
(nextTag isnt 'TERMINATOR' or not @looksObjectish(i + 2))
|
||||
# When nextTag is OUTDENT the comma is insignificant and
|
||||
|
@ -444,7 +459,7 @@ IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@
|
|||
IMPLICIT_CALL = [
|
||||
'IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS'
|
||||
'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'SUPER'
|
||||
'@', '->', '=>', '[', '(', '{', '--', '++'
|
||||
'THROW', '@', '->', '=>', '[', '(', '{', '--', '++'
|
||||
]
|
||||
|
||||
IMPLICIT_UNSPACED_CALL = ['+', '-']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue