<!DOCTYPE html><html><head><title>coffee-script.coffee</title><metahttp-equiv="content-type"content="text/html; charset=UTF-8"><linkrel="stylesheet"media="all"href="docco.css"/></head><body><divid="container"><divid="jump_to"> Jump To …<divid="jump_wrapper"><divid="jump_page"><aclass="source"href="cake.html"> cake.coffee </a><aclass="source"href="coffee-script.html"> coffee-script.coffee </a><aclass="source"href="command.html"> command.coffee </a><aclass="source"href="grammar.html"> grammar.coffee </a><aclass="source"href="lexer.html"> lexer.coffee </a><aclass="source"href="nodes.html"> nodes.coffee </a><aclass="source"href="optparse.html"> optparse.coffee </a><aclass="source"href="repl.html"> repl.coffee </a><aclass="source"href="rewriter.html"> rewriter.coffee </a><aclass="source"href="scope.html"> scope.coffee </a></div></div></div><tablecellpadding="0"cellspacing="0"><thead><tr><thclass="docs"><h1> coffee-script.coffee </h1></th><thclass="code"></th></tr></thead><tbody><trid="section-1"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-1">#</a></div><p>CoffeeScript can be used both on the server, as a command-line compiler based
on Node.js/V8, or to run CoffeeScripts directly in the browser. This module
contains the main entry functions for tokenzing, parsing, and compiling source
CoffeeScript into JavaScript.</p>
<p>If included on a webpage, it will automatically sniff out, compile, and
execute all scripts present in <code>text/coffeescript</code> tags.</p></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 dependencies correctly for both the server and the browser.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">if</span><spanclass="nx">process</span><spanclass="o">?</span>
<spanclass="k">this</span><spanclass="p">.</span><spanclass="nv">exports: </span><spanclass="k">this</span><spanclass="p">.</span><spanclass="nv">CoffeeScript: </span><spanclass="p">{}</span></pre></div></td></tr><trid="section-3"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-3">#</a></div><p>The current CoffeeScript version number.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.VERSION: </span><spanclass="s1">'0.5.4'</span></pre></div></td></tr><trid="section-4"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-4">#</a></div><p>Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
<spanclass="p">(</span><spanclass="nx">parser</span><spanclass="p">.</span><spanclass="nx">parse</span><spanclass="nx">lexer</span><spanclass="p">.</span><spanclass="nx">tokenize</span><spanclass="nx">code</span><spanclass="p">).</span><spanclass="nx">compile</span><spanclass="nx">options</span></pre></div></td></tr><trid="section-5"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-5">#</a></div><p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.tokens: </span><spanclass="p">(</span><spanclass="nx">code</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">lexer</span><spanclass="p">.</span><spanclass="nx">tokenize</span><spanclass="nx">code</span></pre></div></td></tr><trid="section-6"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-6">#</a></div><p>Tokenize and parse a string of CoffeeScript code, and return the AST. You can
then compile it by calling <code>.compile()</code> on the root, or traverse it by using
<code>.traverse()</code> with a callback.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.nodes: </span><spanclass="p">(</span><spanclass="nx">code</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nx">parser</span><spanclass="p">.</span><spanclass="nx">parse</span><spanclass="nx">lexer</span><spanclass="p">.</span><spanclass="nx">tokenize</span><spanclass="nx">code</span></pre></div></td></tr><trid="section-7"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-7">#</a></div><p>The real Lexer produces a generic stream of tokens. This object provides a
thin wrapper around it, compatible with the Jison API. We can then pass it
directly as a "Jison lexer".</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">parser.lexer: </span><spanclass="p">{</span>
<spanclass="p">}</span></pre></div></td></tr><trid="section-8"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-8">#</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. Unfortunately, the text contents of remote scripts cannot be
accessed from the browser, so only inline script tags will work.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">if</span><spanclass="nb">document</span><spanclass="o">?</span><spanclass="o">and</span><spanclass="nb">document</span><spanclass="p">.</span><spanclass="nx">getElementsByTagName</span>