<!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="background"></div><divid="jump_to"> Jump To …<divid="jump_wrapper"><divid="jump_page"><aclass="source"href="browser.html"> browser.coffee </a><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="helpers.html"> helpers.coffee </a><aclass="source"href="index.html"> index.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
execute all scripts present in <code>text/coffeescript</code> tags.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">path = </span><spanclass="nx">require</span><spanclass="s1">'path'</span>
<spanclass="nx">require</span><spanclass="p">.</span><spanclass="nx">registerExtension</span><spanclass="s1">'.coffee'</span><spanclass="p">,</span><spanclass="p">(</span><spanclass="nx">content</span><spanclass="p">)</span><spanclass="o">-></span><spanclass="nx">compile</span><spanclass="nx">content</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.9.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="k">throw</span><spanclass="nx">err</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
<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>Compile and execute a string of CoffeeScript (on the server), correctly
<spanclass="nv">root = </span><spanclass="nx">root</span><spanclass="p">.</span><spanclass="nx">parent</span></pre></div></td></tr><trid="section-9"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-9">#</a></div><p>Set the filename</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">root.filename = __filename = </span><spanclass="s2">"#{options.fileName} (compiled)"</span></pre></div></td></tr><trid="section-10"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-10">#</a></div><p>Clear the module cache</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">root.moduleCache = </span><spanclass="p">{}</span><spanclass="k">if</span><spanclass="nx">root</span><spanclass="p">.</span><spanclass="nx">moduleCache</span></pre></div></td></tr><trid="section-11"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-11">#</a></div><p>Compile</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">root</span><spanclass="p">.</span><spanclass="nx">_compile</span><spanclass="nx">exports</span><spanclass="p">.</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">code</span><spanclass="p">,</span><spanclass="nx">options</span><spanclass="p">),</span><spanclass="nx">root</span><spanclass="p">.</span><spanclass="nx">filename</span></pre></div></td></tr><trid="section-12"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-12">#</a></div><p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
The CoffeeScript REPL uses this to run the input.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">exports.eval = </span><spanclass="p">(</span><spanclass="nx">code</span><spanclass="p">,</span><spanclass="nx">options</span><spanclass="p">)</span><spanclass="o">-></span>
<spanclass="nb">eval</span><spanclass="nx">exports</span><spanclass="p">.</span><spanclass="nx">compile</span><spanclass="p">(</span><spanclass="nx">code</span><spanclass="p">,</span><spanclass="nx">options</span><spanclass="p">)</span></pre></div></td></tr><trid="section-13"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-13">#</a></div><p>Instantiate a Lexer for our use here.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nv">lexer = </span><spanclass="k">new</span><spanclass="nx">Lexer</span></pre></div></td></tr><trid="section-14"><tdclass="docs"><divclass="octowrap"><aclass="octothorpe"href="#section-14">#</a></div><p>The real Lexer produces a generic stream of tokens. This object provides a