nodes are created as the result of actions in the <ahref="grammar.html">grammar</a>,
but some are created by other nodes as a method of code generation. To convert
the syntax tree into a string of JavaScript code, call <code>compile()</code> on the root.</p></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-2"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-2">#</a></div><p>Set up for both <strong>Node.js</strong> and the browser, by
including the <ahref="scope.html">Scope</a> class and the <ahref="helpers.html">helper</a> functions.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">if</span><spanclass="nx">process</span><spanclass="o">?</span>
<spanclass="nv">Scope: </span><spanclass="k">this</span><spanclass="p">.</span><spanclass="nx">Scope</span></pre></div></td></tr><trid="section-3"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-3">#</a></div><p>Import the helpers we plan to use.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="p">{</span><spanclass="nx">compact</span><spanclass="p">,</span><spanclass="nx">flatten</span><spanclass="p">,</span><spanclass="nx">merge</span><spanclass="p">,</span><spanclass="nx">del</span><spanclass="p">,</span><spanclass="nx">include</span><spanclass="p">,</span><spanclass="nx">indexOf</span><spanclass="p">,</span><spanclass="nx">starts</span><spanclass="p">}</span><spanclass="o">:</span><spanclass="nx">helpers</span></pre></div></td></tr><trid="section-4"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-4">#</a></div><h3>BaseNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-5"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-5">#</a></div><p>The <strong>BaseNode</strong> is the abstract base class for all nodes in the syntax tree.
Each subclass implements the <code>compileNode</code> method, which performs the
scope, and indentation level.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.BaseNode: </span><spanclass="nx">class</span><spanclass="nx">BaseNode</span></pre></div></td></tr><trid="section-6"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-6">#</a></div><p>Common logic for determining whether to wrap this node in a closure before
depending on whether it's being used as part of a larger expression, or is a
top-level statement within the function body.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compile: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">closure</span><spanclass="k">then</span><spanclass="nx">@compileClosure</span><spanclass="p">(</span><spanclass="nx">@options</span><spanclass="p">)</span><spanclass="k">else</span><spanclass="nx">@compileNode</span><spanclass="p">(</span><spanclass="nx">@options</span><spanclass="p">)</span></pre></div></td></tr><trid="section-7"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-7">#</a></div><p>Statements converted into expressions via closure-wrapping share a scope
object with their parent closure, to preserve the expected lexical scope.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileClosure: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">ClosureNode</span><spanclass="p">.</span><spanclass="nx">wrap</span><spanclass="p">(</span><spanclass="k">this</span><spanclass="p">).</span><spanclass="nx">compile</span><spanclass="nx">o</span></pre></div></td></tr><trid="section-8"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-8">#</a></div><p>If the code generation wishes to use the result of a complex expression
by assigning it to a temporary variable.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileReference: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">,</span><spanclass="nx">options</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="p">[</span><spanclass="nx">pair</span><spanclass="p">[</span><spanclass="mi">0</span><spanclass="p">].</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">),</span><spanclass="nx">pair</span><spanclass="p">[</span><spanclass="mi">1</span><spanclass="p">].</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)]</span></pre></div></td></tr><trid="section-9"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-9">#</a></div><p>Convenience method to grab the current indentation level, plus tabbing in.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">idt: </span><spanclass="p">(</span><spanclass="nx">tabs</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">idt</span></pre></div></td></tr><trid="section-10"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-10">#</a></div><p>Construct a node that returns the current node's result.
many statement nodes (eg IfNode, ForNode)...</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">makeReturn: </span><spanclass="o">-></span>
<spanclass="k">new</span><spanclass="nx">ReturnNode</span><spanclass="k">this</span></pre></div></td></tr><trid="section-11"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-11">#</a></div><p>Does this node, or any of its children, contain a node of a certain kind?
<spanclass="nx">contains</span></pre></div></td></tr><trid="section-12"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-12">#</a></div><p>Is this node of a certain type, or does it contain the type?</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">containsType: </span><spanclass="p">(</span><spanclass="nx">type</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">this</span><spanclass="k">instanceof</span><spanclass="nx">type</span><spanclass="o">or</span><spanclass="nx">@contains</span><spanclass="p">(</span><spanclass="nx">n</span><spanclass="p">)</span><spanclass="o">-></span><spanclass="nx">n</span><spanclass="k">instanceof</span><spanclass="nx">type</span></pre></div></td></tr><trid="section-13"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-13">#</a></div><p>Convenience for the most common use of contains. Does the node contain
a pure statement?</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">containsPureStatement: </span><spanclass="o">-></span>
<spanclass="nx">@isPureStatement</span><spanclass="p">()</span><spanclass="o">or</span><spanclass="nx">@contains</span><spanclass="p">(</span><spanclass="nx">n</span><spanclass="p">)</span><spanclass="o">-></span><spanclass="nx">n</span><spanclass="p">.</span><spanclass="nx">isPureStatement</span><spanclass="p">()</span></pre></div></td></tr><trid="section-14"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-14">#</a></div><p>Perform an in-order traversal of the AST. Crosses scope boundaries.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">traverse: </span><spanclass="p">(</span><spanclass="nx">block</span><spanclass="p">)</span><spanclass="o">-></span><spanclass="nx">@traverseChildren</span><spanclass="kc">true</span><spanclass="p">,</span><spanclass="nx">block</span></pre></div></td></tr><trid="section-15"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-15">#</a></div><p><code>toString</code> representation of the node, for inspecting the parse tree.
This is what <code>coffee --nodes</code> prints out.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">toString: </span><spanclass="p">(</span><spanclass="nx">idt</span><spanclass="p">,</span><spanclass="nx">override</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">child</span><spanclass="p">.</span><spanclass="nx">traverseChildren</span><spanclass="p">(</span><spanclass="nx">crossScope</span><spanclass="p">,</span><spanclass="nx">func</span><spanclass="p">)</span><spanclass="k">if</span><spanclass="nx">child</span><spanclass="k">instanceof</span><spanclass="nx">BaseNode</span></pre></div></td></tr><trid="section-16"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-16">#</a></div><p>Default implementations of the common node properties and methods. Nodes
will override these with custom logic, if needed.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">class: </span><spanclass="s1">'BaseNode'</span>
<spanclass="nv">topSensitive: </span><spanclass="o">-></span><spanclass="kc">no</span></pre></div></td></tr><trid="section-17"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-17">#</a></div><h3>Expressions</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-18"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-18">#</a></div><p>The expressions body is the list of expressions that forms the body of an
indented block of code -- the implementation of a function, a clause in an
<code>if</code>, <code>switch</code>, or <code>try</code>, and so on...</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.Expressions: </span><spanclass="nx">class</span><spanclass="nx">Expressions</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="vi">@expressions: </span><spanclass="nx">compact</span><spanclass="nx">flatten</span><spanclass="nx">nodes</span><spanclass="o">or</span><spanclass="p">[]</span></pre></div></td></tr><trid="section-19"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-19">#</a></div><p>Tack an expression on to the end of this expression list.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">push: </span><spanclass="p">(</span><spanclass="nx">node</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-20"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-20">#</a></div><p>Add an expression at the beginning of this expression list.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">unshift: </span><spanclass="p">(</span><spanclass="nx">node</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-21"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-21">#</a></div><p>If this Expressions consists of just a single node, unwrap it by pulling
<spanclass="k">if</span><spanclass="nx">@expressions</span><spanclass="p">.</span><spanclass="nx">length</span><spanclass="o">is</span><spanclass="mi">1</span><spanclass="k">then</span><spanclass="nx">@expressions</span><spanclass="p">[</span><spanclass="mi">0</span><spanclass="p">]</span><spanclass="k">else</span><spanclass="k">this</span></pre></div></td></tr><trid="section-22"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-22">#</a></div><p>Is this an empty block of code?</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">empty: </span><spanclass="o">-></span>
<spanclass="nx">@expressions</span><spanclass="p">.</span><spanclass="nx">length</span><spanclass="o">is</span><spanclass="mi">0</span></pre></div></td></tr><trid="section-23"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-23">#</a></div><p>An Expressions node does not return its entire body, rather it
ensures that the final expression is returned.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">makeReturn: </span><spanclass="o">-></span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-24"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-24">#</a></div><p>An <strong>Expressions</strong> is the only node that can serve as the root.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compile: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="p">(</span><spanclass="nx">@compileExpression</span><spanclass="p">(</span><spanclass="nx">node</span><spanclass="p">,</span><spanclass="nx">merge</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">))</span><spanclass="k">for</span><spanclass="nx">node</span><spanclass="k">in</span><spanclass="nx">@expressions</span><spanclass="p">).</span><spanclass="nx">join</span><spanclass="p">(</span><spanclass="s2">"\n"</span><spanclass="p">)</span></pre></div></td></tr><trid="section-25"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-25">#</a></div><p>If we happen to be the top-level <strong>Expressions</strong>, wrap everything in
a safety closure, unless requested not to.
It would be better not to generate them in the first place, but for now,
clean up obvious double-parentheses.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileRoot: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">o</span><spanclass="p">.</span><spanclass="nx">noWrap</span><spanclass="k">then</span><spanclass="nx">code</span><spanclass="k">else</span><spanclass="s2">"(function(){\n$code\n})();\n"</span></pre></div></td></tr><trid="section-26"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-26">#</a></div><p>Compile the expressions body for the contents of a function, with
declarations of all inner variables pushed up to the top.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileWithDeclarations: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">code</span></pre></div></td></tr><trid="section-27"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-27">#</a></div><p>Compiles a single expression within the expressions body. If we need to
statement, ask the statement to do so.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileExpression: </span><spanclass="p">(</span><spanclass="nx">node</span><spanclass="p">,</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">node</span><spanclass="p">.</span><spanclass="nx">isStatement</span><spanclass="p">()</span><spanclass="k">then</span><spanclass="nx">compiledNode</span><spanclass="k">else</span><spanclass="s2">"${@idt()}$compiledNode;"</span></pre></div></td></tr><trid="section-28"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-28">#</a></div><p>Wrap up the given nodes as an <strong>Expressions</strong>, unless it already happens
to be one.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">Expressions.wrap: </span><spanclass="p">(</span><spanclass="nx">nodes</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">new</span><spanclass="nx">Expressions</span><spanclass="p">(</span><spanclass="nx">nodes</span><spanclass="p">)</span></pre></div></td></tr><trid="section-29"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-29">#</a></div><h3>LiteralNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-30"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-30">#</a></div><p>Literals are static values that can be passed through directly into
<spanclass="vi">@value: </span><spanclass="nx">value</span></pre></div></td></tr><trid="section-31"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-31">#</a></div><p>Break and continue must be treated as pure statements -- they lose their
meaning when wrapped in a closure.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">isStatement: </span><spanclass="o">-></span>
<spanclass="s2">" \"$@value\""</span></pre></div></td></tr><trid="section-32"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-32">#</a></div><h3>ReturnNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-33"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-33">#</a></div><p>A <code>return</code> is a <em>pureStatement</em> -- wrapping it in a closure wouldn't
make sense.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.ReturnNode: </span><spanclass="nx">class</span><spanclass="nx">ReturnNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="s2">"${@tab}return ${@expression.compile(o)};"</span></pre></div></td></tr><trid="section-34"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-34">#</a></div><h3>ValueNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-35"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-35">#</a></div><p>A value, variable or literal or parenthesized, indexed or dotted into,
or vanilla.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.ValueNode: </span><spanclass="nx">class</span><spanclass="nx">ValueNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="nv">children: </span><spanclass="p">[</span><spanclass="s1">'base'</span><spanclass="p">,</span><spanclass="s1">'properties'</span><spanclass="p">]</span></pre></div></td></tr><trid="section-36"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-36">#</a></div><p>A <strong>ValueNode</strong> has a base and a list of property accesses.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">constructor: </span><spanclass="p">(</span><spanclass="nx">base</span><spanclass="p">,</span><spanclass="nx">properties</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="vi">@properties: </span><spanclass="p">(</span><spanclass="nx">properties</span><spanclass="o">or</span><spanclass="p">[])</span></pre></div></td></tr><trid="section-37"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-37">#</a></div><p>Add a property access to the list.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">push: </span><spanclass="p">(</span><spanclass="nx">prop</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="o">!!</span><spanclass="nx">@properties</span><spanclass="p">.</span><spanclass="nx">length</span></pre></div></td></tr><trid="section-38"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-38">#</a></div><p>Some boolean checks for the benefit of other nodes.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">isArray: </span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">@hasProperties</span><spanclass="p">()</span><spanclass="k">then</span><spanclass="k">super</span><spanclass="p">()</span><spanclass="k">else</span><spanclass="nx">@base</span><spanclass="p">.</span><spanclass="nx">makeReturn</span><spanclass="p">()</span></pre></div></td></tr><trid="section-39"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-39">#</a></div><p>The value can be unwrapped as its inner node, if there are no attached
<spanclass="k">if</span><spanclass="nx">@properties</span><spanclass="p">.</span><spanclass="nx">length</span><spanclass="k">then</span><spanclass="k">this</span><spanclass="k">else</span><spanclass="nx">@base</span></pre></div></td></tr><trid="section-40"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-40">#</a></div><p>Values are considered to be statements if their base is a statement.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">isStatement: </span><spanclass="o">-></span>
<spanclass="nx">@base</span><spanclass="k">instanceof</span><spanclass="nx">LiteralNode</span><spanclass="o">and</span><spanclass="nx">@base</span><spanclass="p">.</span><spanclass="nx">value</span><spanclass="p">.</span><spanclass="nx">match</span><spanclass="nx">NUMBER</span></pre></div></td></tr><trid="section-41"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-41">#</a></div><p>Works out if the value is the start of a chain.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">isStart: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">node</span><spanclass="o">is</span><spanclass="k">this</span></pre></div></td></tr><trid="section-42"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-42">#</a></div><p>Override compile to unwrap the value when possible.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compile: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="o">not</span><spanclass="nx">o</span><spanclass="p">.</span><spanclass="nx">top</span><spanclass="o">or</span><spanclass="nx">@properties</span><spanclass="p">.</span><spanclass="nx">length</span><spanclass="k">then</span><spanclass="k">super</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="k">else</span><spanclass="nx">@base</span><spanclass="p">.</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span></pre></div></td></tr><trid="section-43"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-43">#</a></div><p>We compile a value to JavaScript by compiling and joining each property.
evaluate a anything twice when building the soak chain.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">op</span><spanclass="o">and</span><spanclass="nx">@wrapped</span><spanclass="k">then</span><spanclass="s2">"($complete)"</span><spanclass="k">else</span><spanclass="nx">complete</span></pre></div></td></tr><trid="section-44"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-44">#</a></div><h3>CommentNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-45"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-45">#</a></div><p>CoffeeScript passes through block comments as JavaScript block comments
at the same position.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.CommentNode: </span><spanclass="nx">class</span><spanclass="nx">CommentNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="s2">"$@tab/*$sep${ @lines.join(sep) }\n$@tab*/"</span></pre></div></td></tr><trid="section-46"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-46">#</a></div><h3>CallNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-47"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-47">#</a></div><p>Node for a function invocation. Takes care of converting <code>super()</code> calls into
calls against the prototype's function of the same name.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.CallNode: </span><spanclass="nx">class</span><spanclass="nx">CallNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="nx">SplatNode</span><spanclass="p">.</span><spanclass="nx">compileMixedArray</span><spanclass="p">.</span><spanclass="nx">call</span><spanclass="p">(</span><spanclass="k">this</span><spanclass="p">,</span><spanclass="nx">@args</span><spanclass="p">,</span><spanclass="nx">o</span><spanclass="p">)</span></pre></div></td></tr><trid="section-48"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-48">#</a></div><p>Tag this invocation as creating a new instance.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">newInstance: </span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">@isNew</span><spanclass="k">then</span><spanclass="s1">'new '</span><spanclass="k">else</span><spanclass="s1">''</span></pre></div></td></tr><trid="section-49"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-49">#</a></div><p>Grab the reference to the superclass' implementation of the current method.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">superReference: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">else</span><spanclass="k">throw</span><spanclass="k">new</span><spanclass="nb">Error</span><spanclass="s2">"cannot call super on an anonymous function."</span></pre></div></td></tr><trid="section-50"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-50">#</a></div><p>Compile a vanilla function call.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">o</span><spanclass="p">.</span><spanclass="nx">operation</span><spanclass="o">and</span><spanclass="nx">@wrapped</span><spanclass="k">then</span><spanclass="s2">"($compilation)"</span><spanclass="k">else</span><spanclass="nx">compilation</span></pre></div></td></tr><trid="section-51"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-51">#</a></div><p><code>super()</code> is converted into a call against the superclass's implementation
of the current function.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileSuper: </span><spanclass="p">(</span><spanclass="nx">args</span><spanclass="p">,</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"${@superReference(o)}.call(this${ if args.length then ', ' else '' }$args)"</span></pre></div></td></tr><trid="section-52"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-52">#</a></div><p>If you call a function with a splat, it's converted into a JavaScript
<code>.apply()</code> call to allow an array of arguments to be passed.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileSplat: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"${@prefix()}${meth}.apply($obj, ${ @compileSplatArguments(o) })"</span></pre></div></td></tr><trid="section-53"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-53">#</a></div><h3>ExtendsNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-54"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-54">#</a></div><p>Node to extend an object's prototype with an ancestor object.
<spanclass="vi">@parent: </span><spanclass="nx">parent</span></pre></div></td></tr><trid="section-55"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-55">#</a></div><p>Hooks one constructor into another's prototype chain.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="p">(</span><spanclass="k">new</span><spanclass="nx">CallNode</span><spanclass="nx">ref</span><spanclass="p">,</span><spanclass="p">[</span><spanclass="nx">@child</span><spanclass="p">,</span><spanclass="nx">@parent</span><spanclass="p">]).</span><spanclass="nx">compile</span><spanclass="nx">o</span></pre></div></td></tr><trid="section-56"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-56">#</a></div><h3>AccessorNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-57"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-57">#</a></div><p>A <code>.</code> accessor into a property of a value, or the <code>::</code> shorthand for
an accessor into the object's prototype.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.AccessorNode: </span><spanclass="nx">class</span><spanclass="nx">AccessorNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="nx">@prototype</span><spanclass="o">+</span><spanclass="nx">namePart</span></pre></div></td></tr><trid="section-58"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-58">#</a></div><h3>IndexNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-59"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-59">#</a></div><p>A <code>[ ... ]</code> indexed accessor into an array or object.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.IndexNode: </span><spanclass="nx">class</span><spanclass="nx">IndexNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="s2">"$prefix[$idx]"</span></pre></div></td></tr><trid="section-60"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-60">#</a></div><h3>RangeNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-61"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-61">#</a></div><p>A range literal. Ranges can be used to extract portions (slices) of arrays,
to specify a range for comprehensions, or as a value, to be expanded into the
corresponding array of integers at runtime.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.RangeNode: </span><spanclass="nx">class</span><spanclass="nx">RangeNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="vi">@exclusive: </span><spanclass="o">!!</span><spanclass="nx">exclusive</span></pre></div></td></tr><trid="section-62"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-62">#</a></div><p>Compiles the range's source variables -- where it starts and where it ends.
But only if they need to be cached to avoid double evaluation.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileVariables: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">parts</span><spanclass="p">.</span><spanclass="nx">length</span><spanclass="k">then</span><spanclass="s2">"${parts.join('; ')};"</span><spanclass="k">else</span><spanclass="s1">''</span></pre></div></td></tr><trid="section-63"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-63">#</a></div><p>When compiled normally, the range returns the contents of the <em>for loop</em>
needed to iterate over the values in the range. Used by comprehensions.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"$vars; ${idx} $op ${@toVar.compile(o)}; $idx += $step"</span></pre></div></td></tr><trid="section-64"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-64">#</a></div><p>When used as a value, expand the range into the equivalent array.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileArray: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
is the index of the beginning.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.SliceNode: </span><spanclass="nx">class</span><spanclass="nx">SliceNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="s2">"[$objects]"</span></pre></div></td></tr><trid="section-71"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-71">#</a></div><h3>ClassNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-72"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-72">#</a></div><p>The CoffeeScript class definition.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.ClassNode: </span><spanclass="nx">class</span><spanclass="nx">ClassNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="nv">isStatement: </span><spanclass="o">-></span><spanclass="kc">yes</span></pre></div></td></tr><trid="section-73"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-73">#</a></div><p>Initialize a <strong>ClassNode</strong> with its name, an optional superclass, and a
list of prototype property assignments.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">constructor: </span><spanclass="p">(</span><spanclass="nx">variable</span><spanclass="p">,</span><spanclass="nx">parent</span><spanclass="p">,</span><spanclass="nx">props</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-74"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-74">#</a></div><p>Instead of generating the JavaScript string directly, we build up the
constructor, property assignments, and inheritance getting built out below.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">throw</span><spanclass="k">new</span><spanclass="nb">Error</span><spanclass="s2">"cannot define a constructor as a bound function."</span><spanclass="k">if</span><spanclass="nx">func</span><spanclass="p">.</span><spanclass="nx">bound</span>
<spanclass="s2">"$construct$extension$props$returns"</span></pre></div></td></tr><trid="section-75"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-75">#</a></div><h3>AssignNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-76"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-76">#</a></div><p>The <strong>AssignNode</strong> is used to assign a local variable to value, or to set the
property of an object -- including within object literals.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.AssignNode: </span><spanclass="nx">class</span><spanclass="nx">AssignNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span></pre></div></td></tr><trid="section-77"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-77">#</a></div><p>Matchers for detecting prototype assignments.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">PROTO_ASSIGN: </span><spanclass="sr">/^(\S+)\.prototype/</span>
<spanclass="nx">@isValue</span><spanclass="p">()</span><spanclass="o">and</span><spanclass="p">(</span><spanclass="nx">@variable</span><spanclass="p">.</span><spanclass="nx">isArray</span><spanclass="p">()</span><spanclass="o">or</span><spanclass="nx">@variable</span><spanclass="p">.</span><spanclass="nx">isObject</span><spanclass="p">())</span></pre></div></td></tr><trid="section-78"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-78">#</a></div><p>Compile an assignment, delegating to <code>compilePatternMatch</code> or
has not been seen yet within the current scope, declare it.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">top</span><spanclass="k">then</span><spanclass="nx">val</span><spanclass="k">else</span><spanclass="s2">"($val)"</span></pre></div></td></tr><trid="section-79"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-79">#</a></div><p>Brief implementation of recursive pattern matching, when assigning array or
for details.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compilePatternMatch: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">throw</span><spanclass="k">new</span><spanclass="nb">Error</span><spanclass="s1">'pattern matching must use only identifiers on the left-hand side.'</span>
<spanclass="nx">code</span></pre></div></td></tr><trid="section-83"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-83">#</a></div><p>Compile the assignment from an array splice literal, using JavaScript's
<spanclass="s2">"${name}.splice.apply($name, [$from, $to].concat($val))"</span></pre></div></td></tr><trid="section-84"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-84">#</a></div><h3>CodeNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-85"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-85">#</a></div><p>A function definition. This is the only node that creates a new Scope.
When for the purposes of walking the contents of a function body, the CodeNode
has no <em>children</em> -- they're within the inner scope.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.CodeNode: </span><spanclass="nx">class</span><spanclass="nx">CodeNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="vi">@bound: </span><spanclass="nx">tag</span><spanclass="o">is</span><spanclass="s1">'boundfunc'</span></pre></div></td></tr><trid="section-86"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-86">#</a></div><p>Compilation creates a new scope unless explicitly asked to share with the
a closure.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="kc">true</span></pre></div></td></tr><trid="section-87"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-87">#</a></div><p>Short-circuit traverseChildren method to prevent it from crossing scope boundaries
unless crossScope is true</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">traverseChildren: </span><spanclass="p">(</span><spanclass="nx">crossScope</span><spanclass="p">,</span><spanclass="nx">func</span><spanclass="p">)</span><spanclass="o">-></span><spanclass="k">super</span><spanclass="p">(</span><spanclass="nx">crossScope</span><spanclass="p">,</span><spanclass="nx">func</span><spanclass="p">)</span><spanclass="k">if</span><spanclass="nx">crossScope</span>
<spanclass="s2">"\n$idt$children"</span></pre></div></td></tr><trid="section-88"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-88">#</a></div><h3>SplatNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-89"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-89">#</a></div><p>A splat, either as a parameter to a function, an argument to a call,
or as part of a destructuring assignment.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.SplatNode: </span><spanclass="nx">class</span><spanclass="nx">SplatNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="k">if</span><spanclass="nx">@index</span><spanclass="o">?</span><spanclass="k">then</span><spanclass="nx">@compileParam</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="k">else</span><spanclass="nx">@name</span><spanclass="p">.</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span></pre></div></td></tr><trid="section-90"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-90">#</a></div><p>Compiling a parameter splat means recovering the parameters that succeed
the splat in the parameter list, by slicing the arguments object.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileParam: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"$name = ${utility('slice')}.call(arguments, $@index, $len - ${@trailings.length})"</span></pre></div></td></tr><trid="section-91"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-91">#</a></div><p>A compiling a splat as a destructuring assignment means slicing arguments
from the right-hand-side's corresponding array.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileValue: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">,</span><spanclass="nx">name</span><spanclass="p">,</span><spanclass="nx">index</span><spanclass="p">,</span><spanclass="nx">trailings</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"${utility 'slice'}.call($name, $index$trail)"</span></pre></div></td></tr><trid="section-92"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-92">#</a></div><p>Utility function that converts arbitrary number of elements, mixed with
splats, to a proper array</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="vi">@compileMixedArray: </span><spanclass="p">(</span><spanclass="nx">list</span><spanclass="p">,</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">args</span><spanclass="p">.</span><spanclass="nx">join</span><spanclass="p">(</span><spanclass="s1">''</span><spanclass="p">)</span></pre></div></td></tr><trid="section-93"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-93">#</a></div><h3>WhileNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-94"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-94">#</a></div><p>A while loop, the only sort of low-level loop exposed by CoffeeScript. From
it, all other loops can be manufactured. Useful in cases where you need more
flexibility or more speed than a comprehension can provide.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.WhileNode: </span><spanclass="nx">class</span><spanclass="nx">WhileNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="kc">true</span></pre></div></td></tr><trid="section-95"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-95">#</a></div><p>The main difference from a JavaScript <em>while</em> is that the CoffeeScript
return an array containing the computed result of each iteration.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"$pre {\n${ @body.compile(o) }\n$@tab}$post"</span></pre></div></td></tr><trid="section-96"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-96">#</a></div><h3>OpNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-97"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-97">#</a></div><p>Simple Arithmetic and logical operations. Performs some conversion from
CoffeeScript operations into their JavaScript equivalents.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.OpNode: </span><spanclass="nx">class</span><spanclass="nx">OpNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span></pre></div></td></tr><trid="section-98"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-98">#</a></div><p>The map of conversions from CoffeeScript to JavaScript symbols.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">CONVERSIONS: </span><spanclass="p">{</span>
<spanclass="p">}</span></pre></div></td></tr><trid="section-99"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-99">#</a></div><p>The list of operators for which we perform
<ahref="http://docs.python.org/reference/expressions.html#notin">Python-style comparison chaining</a>.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">CHAINABLE: </span><spanclass="p">[</span><spanclass="s1">'<'</span><spanclass="p">,</span><spanclass="s1">'>'</span><spanclass="p">,</span><spanclass="s1">'>='</span><spanclass="p">,</span><spanclass="s1">'<='</span><spanclass="p">,</span><spanclass="s1">'==='</span><spanclass="p">,</span><spanclass="s1">'!=='</span><spanclass="p">]</span></pre></div></td></tr><trid="section-100"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-100">#</a></div><p>Our assignment operators that have no JavaScript equivalent.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">ASSIGNMENT: </span><spanclass="p">[</span><spanclass="s1">'||='</span><spanclass="p">,</span><spanclass="s1">'&&='</span><spanclass="p">,</span><spanclass="s1">'?='</span><spanclass="p">]</span></pre></div></td></tr><trid="section-101"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-101">#</a></div><p>Operators must come before their operands with a space.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">PREFIX_OPERATORS: </span><spanclass="p">[</span><spanclass="s1">'typeof'</span><spanclass="p">,</span><spanclass="s1">'delete'</span><spanclass="p">]</span>
<spanclass="p">[</span><spanclass="nx">@first</span><spanclass="p">.</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">),</span><spanclass="nx">@operator</span><spanclass="p">,</span><spanclass="nx">@second</span><spanclass="p">.</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)].</span><spanclass="nx">join</span><spanclass="s1">''</span></pre></div></td></tr><trid="section-102"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-102">#</a></div><p>Mimic Python's chained comparisons when multiple comparison operators are
<spanclass="s2">"($first) && ($shared $@operator $second)"</span></pre></div></td></tr><trid="section-103"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-103">#</a></div><p>When compiling a conditional assignment, take care to ensure that the
more than once.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileAssignment: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"$first = $first ${ @operator.substr(0, 2) } $second"</span></pre></div></td></tr><trid="section-104"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-104">#</a></div><p>If this is an existence operator, we delegate to <code>ExistenceNode.compileTest</code>
to give us the safe references for the variables.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileExistence: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-109"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-109">#</a></div><p>Compilation is more or less as you would expect -- the <em>finally</em> clause
is optional, the <em>catch</em> is not.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"${@tab}try {\n$attemptPart\n$@tab}$catchPart$finallyPart"</span></pre></div></td></tr><trid="section-110"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-110">#</a></div><h3>ThrowNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-111"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-111">#</a></div><p>Simple node to throw an exception.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.ThrowNode: </span><spanclass="nx">class</span><spanclass="nx">ThrowNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="vi">@expression: </span><spanclass="nx">expression</span></pre></div></td></tr><trid="section-112"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-112">#</a></div><p>A <strong>ThrowNode</strong> is already a return, of sorts...</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">makeReturn: </span><spanclass="o">-></span>
<spanclass="s2">"${@tab}throw ${@expression.compile(o)};"</span></pre></div></td></tr><trid="section-113"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-113">#</a></div><h3>ExistenceNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-114"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-114">#</a></div><p>Checks a variable for existence -- not <em>null</em> and not <em>undefined</em>. This is
<spanclass="nx">ExistenceNode</span><spanclass="p">.</span><spanclass="nx">compileTest</span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">,</span><spanclass="nx">@expression</span><spanclass="p">)</span></pre></div></td></tr><trid="section-115"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-115">#</a></div><p>The meat of the <strong>ExistenceNode</strong> is in this static <code>compileTest</code> method
Be careful not to double-evaluate anything.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="vi">@compileTest: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">,</span><spanclass="nx">variable</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"(typeof ${first.compile(o)} !== \"undefined\"&& ${second.compile(o)} !== null)"</span></pre></div></td></tr><trid="section-116"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-116">#</a></div><h3>ParentheticalNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-117"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-117">#</a></div><p>An extra set of parentheses, specified explicitly in the source. At one time
we tried to clean up the results by detecting and removing redundant
parentheses, but no longer -- you can put in as many as you please.</p>
<p>Parentheses are a good way to force any statement to become an expression.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.ParentheticalNode: </span><spanclass="nx">class</span><spanclass="nx">ParentheticalNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="k">if</span><spanclass="nx">@expression</span><spanclass="k">instanceof</span><spanclass="nx">AssignNode</span><spanclass="k">then</span><spanclass="nx">code</span><spanclass="k">else</span><spanclass="s2">"($code)"</span></pre></div></td></tr><trid="section-118"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-118">#</a></div><h3>ForNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-119"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-119">#</a></div><p>CoffeeScript's replacement for the <em>for</em> loop is our array and object
comprehensions, that compile into <em>for</em> loops here. They also act as an
expression, able to return the result of each filtered iteration.</p>
<p>Unlike Python array comprehensions, they can be multi-line, and you can pass
the current index of the loop as a second parameter. Unlike Ruby blocks,
you can map and filter in a single pass.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.ForNode: </span><spanclass="nx">class</span><spanclass="nx">ForNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="k">throw</span><spanclass="k">new</span><spanclass="nb">Error</span><spanclass="p">(</span><spanclass="s1">'index cannot be a pattern matching expression'</span><spanclass="p">)</span><spanclass="k">if</span><spanclass="nx">@index</span><spanclass="k">instanceof</span><spanclass="nx">ValueNode</span>
<spanclass="s1">''</span></pre></div></td></tr><trid="section-120"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-120">#</a></div><p>Welcome to the hairiest method in all of CoffeeScript. Handles the inner
some cannot.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileNode: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"${sourcePart}for ($forPart) {\n$varPart$body\n$@tab$close$returnResult"</span></pre></div></td></tr><trid="section-121"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-121">#</a></div><h3>IfNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-122"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-122">#</a></div><p><em>If/else</em> statements. Our <em>switch/when</em> will be compiled into this. Acts as an
expression by pushing down requested returns to the last line of each clause.</p>
<p>Single-expression <strong>IfNodes</strong> are compiled into ternary operators if possible,
because ternaries are already proper expressions, and don't need conversion.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.IfNode: </span><spanclass="nx">class</span><spanclass="nx">IfNode</span><spanclass="k">extends</span><spanclass="nx">BaseNode</span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-123"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-123">#</a></div><p>Tag a chain of <strong>IfNodes</strong> with their object(s) to switch on for equality
tests. <code>rewriteSwitch</code> will perform the actual change at compile time.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">switchesOver: </span><spanclass="p">(</span><spanclass="nx">expression</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-124"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-124">#</a></div><p>Rewrite a chain of <strong>IfNodes</strong> with their switch condition for equality.
Ensure that the switch expression isn't evaluated more than once.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">rewriteSwitch: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">@elseBodyNode</span><spanclass="p">().</span><spanclass="nx">switchesOver</span><spanclass="p">(</span><spanclass="nx">@switchSubject</span><spanclass="p">)</span><spanclass="k">if</span><spanclass="nx">@isChain</span></pre></div></td></tr><trid="section-125"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-125">#</a></div><p>prevent this rewrite from happening again</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="vi">@switchSubject: </span><spanclass="kc">undefined</span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-126"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-126">#</a></div><p>Rewrite a chain of <strong>IfNodes</strong> to add a default case as the final <em>else</em>.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">addElse: </span><spanclass="p">(</span><spanclass="nx">elseBody</span><spanclass="p">,</span><spanclass="nx">statement</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">this</span></pre></div></td></tr><trid="section-127"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-127">#</a></div><p>The <strong>IfNode</strong> only compiles into a statement if either of its bodies needs
to be a statement. Otherwise a ternary is safe.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">isStatement: </span><spanclass="o">-></span>
<spanclass="k">if</span><spanclass="nx">node</span><spanclass="k">instanceof</span><spanclass="nx">Expressions</span><spanclass="k">then</span><spanclass="nx">node</span><spanclass="k">else</span><spanclass="k">new</span><spanclass="nx">Expressions</span><spanclass="p">[</span><spanclass="nx">node</span><spanclass="p">]</span></pre></div></td></tr><trid="section-128"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-128">#</a></div><p>Compile the <strong>IfNode</strong> as a regular <em>if-else</em> statement. Flattened chains
force inner <em>else</em> bodies into statement form.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileStatement: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"$ifPart$elsePart"</span></pre></div></td></tr><trid="section-129"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-129">#</a></div><p>Compile the IfNode as a ternary operator.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">compileTernary: </span><spanclass="p">(</span><spanclass="nx">o</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="s2">"$ifPart : $elsePart"</span></pre></div></td></tr><trid="section-130"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-130">#</a></div><h2>Faux-Nodes</h2></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-131"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-131">#</a></div><h3>PushNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-132"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-132">#</a></div><p>Faux-nodes are never created by the grammar, but are used during code
generation to generate other combinations of nodes. The <strong>PushNode</strong> creates
the tree for <code>array.push(value)</code>, which is helpful for recording the result
arrays from comprehensions.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">PushNode: exports.PushNode: </span><spanclass="p">{</span>
<spanclass="p">}</span></pre></div></td></tr><trid="section-133"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-133">#</a></div><h3>ClosureNode</h3></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-134"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-134">#</a></div><p>A faux-node used to wrap an expressions body in a closure.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">ClosureNode: exports.ClosureNode: </span><spanclass="p">{</span></pre></div></td></tr><trid="section-135"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-135">#</a></div><p>Wrap the expressions body, unless it contains a pure statement,
in which case, no dice. If the body mentions <code>this</code> or <code>arguments</code>,
then make sure that the closure wrapper preserves the original values.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">wrap: </span><spanclass="p">(</span><spanclass="nx">expressions</span><spanclass="p">,</span><spanclass="nx">statement</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="p">}</span></pre></div></td></tr><trid="section-136"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-136">#</a></div><h2>Utility Functions</h2></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">UTILITIES: </span><spanclass="p">{</span></pre></div></td></tr><trid="section-137"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-137">#</a></div><p>Correctly set up a prototype chain for inheritance, including a reference
<spanclass="s2">"""</span></pre></div></td></tr><trid="section-138"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-138">#</a></div><p>Shortcuts to speed up the lookup time for native functions.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">__hasProp: </span><spanclass="s1">'Object.prototype.hasOwnProperty'</span>
<spanclass="p">}</span></pre></div></td></tr><trid="section-139"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-139">#</a></div><h2>Constants</h2></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-140"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-140">#</a></div><p>Tabs are two spaces for pretty printing.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">TAB: </span><spanclass="s1">''</span></pre></div></td></tr><trid="section-141"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-141">#</a></div><p>Trim out all trailing whitespace, so that the generated code plays nice
with Git.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">TRAILING_WHITESPACE: </span><spanclass="sr">/[ \t]+$/gm</span></pre></div></td></tr><trid="section-142"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-142">#</a></div><p>Obvious redundant parentheses should be removed.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">DOUBLE_PARENS: </span><spanclass="sr">/\(\(([^\(\)\n]*)\)\)/g</span></pre></div></td></tr><trid="section-143"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-143">#</a></div><p>Keep these identifier regexes in sync with the Lexer.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">IDENTIFIER: </span><spanclass="sr">/^[a-zA-Z\$_](\w|\$)*$/</span>
<spanclass="nv">NUMBER : </span><spanclass="sr">/^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b$/i</span></pre></div></td></tr><trid="section-144"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-144">#</a></div><p>Is a literal value a string?</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">IS_STRING: </span><spanclass="sr">/^['"]/</span></pre></div></td></tr><trid="section-145"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-145">#</a></div><h2>Utility Functions</h2></td><tdclass="code"><divclass="highlight"><pre></pre></div></td></tr><trid="section-146"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-146">#</a></div><p>Handy helper for a generating LiteralNode.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">literal: </span><spanclass="p">(</span><spanclass="nx">name</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="k">new</span><spanclass="nx">LiteralNode</span><spanclass="p">(</span><spanclass="nx">name</span><spanclass="p">)</span></pre></div></td></tr><trid="section-147"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-147">#</a></div><p>Helper for ensuring that utility functions are assigned at the top level.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">utility: </span><spanclass="p">(</span><spanclass="nx">name</span><spanclass="p">)</span><spanclass="o">-></span>