mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
CoffeeScript 1.9.0
This commit is contained in:
parent
a62e49311e
commit
e0ec8a51e4
82 changed files with 1310 additions and 1191 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coffee-script",
|
||||
"version": "1.8.0",
|
||||
"version": "1.9.0",
|
||||
"main": [
|
||||
"lib/coffee-script/coffee-script.js"
|
||||
],
|
||||
|
|
8
documentation/coffee/generators.coffee
Normal file
8
documentation/coffee/generators.coffee
Normal file
|
@ -0,0 +1,8 @@
|
|||
perfectSquares = ->
|
||||
num = 0
|
||||
loop
|
||||
num += 1
|
||||
yield num * num
|
||||
return
|
||||
|
||||
window.ps or= perfectSquares()
|
|
@ -140,7 +140,7 @@ compile = CoffeeScript.compile</pre></div></div>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">eval</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.e<span class="hljs-function"><span class="hljs-title">val</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
options.bare ?= <span class="hljs-literal">on</span>
|
||||
eval compile code, options</pre></div></div>
|
||||
|
||||
|
@ -157,7 +157,7 @@ compile = CoffeeScript.compile</pre></div></div>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">run</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.r<span class="hljs-function"><span class="hljs-title">un</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
options.bare = <span class="hljs-literal">on</span>
|
||||
options.shiftLine = <span class="hljs-literal">on</span>
|
||||
Function(compile code, options)()</pre></div></div>
|
||||
|
@ -193,7 +193,7 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> btoa? <span class="hljs-keyword">and</span> JSON? <span class="hljs-keyword">and</span> unescape? <span class="hljs-keyword">and</span> encodeURIComponent?
|
||||
<span class="hljs-function"><span class="hljs-title">compile</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-title">compile</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
options.sourceMap = <span class="hljs-literal">true</span>
|
||||
options.inline = <span class="hljs-literal">true</span>
|
||||
{js, v3SourceMap} = CoffeeScript.compile code, options
|
||||
|
@ -212,7 +212,7 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">load</span> = <span class="hljs-params">(url, callback, options = {}, hold = <span class="hljs-literal">false</span>)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.l<span class="hljs-function"><span class="hljs-title">oad</span> = <span class="hljs-params">(url, callback, options = {}, hold = <span class="hljs-literal">false</span>)</span> -></span>
|
||||
options.sourceFiles = [url]
|
||||
xhr = <span class="hljs-keyword">if</span> <span class="hljs-built_in">window</span>.ActiveXObject
|
||||
<span class="hljs-keyword">new</span> <span class="hljs-built_in">window</span>.ActiveXObject(<span class="hljs-string">'Microsoft.XMLHTTP'</span>)
|
||||
|
@ -220,7 +220,7 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
|
|||
<span class="hljs-keyword">new</span> <span class="hljs-built_in">window</span>.XMLHttpRequest()
|
||||
xhr.open <span class="hljs-string">'GET'</span>, url, <span class="hljs-literal">true</span>
|
||||
xhr.overrideMimeType <span class="hljs-string">'text/plain'</span> <span class="hljs-keyword">if</span> <span class="hljs-string">'overrideMimeType'</span> <span class="hljs-keyword">of</span> xhr
|
||||
xhr.<span class="hljs-function"><span class="hljs-title">onreadystatechange</span> = -></span>
|
||||
xhr.o<span class="hljs-function"><span class="hljs-title">nreadystatechange</span> = -></span>
|
||||
<span class="hljs-keyword">if</span> xhr.readyState <span class="hljs-keyword">is</span> <span class="hljs-number">4</span>
|
||||
<span class="hljs-keyword">if</span> xhr.status <span class="hljs-keyword">in</span> [<span class="hljs-number">0</span>, <span class="hljs-number">200</span>]
|
||||
param = [xhr.responseText, options]
|
||||
|
@ -250,8 +250,8 @@ This happens on page load.</p>
|
|||
coffeetypes = [<span class="hljs-string">'text/coffeescript'</span>, <span class="hljs-string">'text/literate-coffeescript'</span>]
|
||||
coffees = (s <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> scripts <span class="hljs-keyword">when</span> s.type <span class="hljs-keyword">in</span> coffeetypes)
|
||||
index = <span class="hljs-number">0</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">execute</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">execute</span> = -></span>
|
||||
param = coffees[index]
|
||||
<span class="hljs-keyword">if</span> param <span class="hljs-keyword">instanceof</span> Array
|
||||
CoffeeScript.run param...
|
||||
|
@ -263,7 +263,7 @@ This happens on page load.</p>
|
|||
options = <span class="hljs-attribute">literate</span>: script.type <span class="hljs-keyword">is</span> coffeetypes[<span class="hljs-number">1</span>]
|
||||
<span class="hljs-keyword">if</span> script.src
|
||||
CoffeeScript.load script.src,
|
||||
<span class="hljs-function"><span class="hljs-params">(param)</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-params">(param)</span> -></span>
|
||||
coffees[i] = param
|
||||
execute()
|
||||
options
|
||||
|
|
|
@ -260,7 +260,7 @@ original directory name, when running Cake tasks from subdirectories.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">run</span> = -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.r<span class="hljs-function"><span class="hljs-title">un</span> = -></span>
|
||||
<span class="hljs-built_in">global</span>.__originalDirname = fs.realpathSync <span class="hljs-string">'.'</span>
|
||||
process.chdir cakefileDirectory __originalDirname
|
||||
args = process.argv[<span class="hljs-number">2.</span>.]
|
||||
|
@ -314,8 +314,8 @@ original directory name, when running Cake tasks from subdirectories.</p>
|
|||
<span class="hljs-built_in">console</span>.error message + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-built_in">console</span>.log <span class="hljs-string">'To see a list of all tasks/options, run "cake"'</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">missingTask</span> = <span class="hljs-params">(task)</span> -></span> fatalError <span class="hljs-string">"No such task: <span class="hljs-subst">#{task}</span>"</span></pre></div></div>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">missingTask</span> = <span class="hljs-params">(task)</span> -></span> fatalError <span class="hljs-string">"No such task: <span class="hljs-subst">#{task}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
|
|
@ -144,9 +144,9 @@ SourceMap = <span class="hljs-built_in">require</span> <span class="hljs-str
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.VERSION = <span class="hljs-string">'1.8.0'</span>
|
||||
<div class="content"><div class='highlight'><pre>exports.VERSION = <span class="hljs-string">'1.9.0'</span>
|
||||
|
||||
<span class="hljs-built_in">exports</span>.FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'</span>, <span class="hljs-string">'.litcoffee'</span>, <span class="hljs-string">'.coffee.md'</span>]</pre></div></div>
|
||||
exports.FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'</span>, <span class="hljs-string">'.litcoffee'</span>, <span class="hljs-string">'.coffee.md'</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -161,7 +161,7 @@ SourceMap = <span class="hljs-built_in">require</span> <span class="hljs-str
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.helpers = helpers</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.helpers = helpers</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -178,7 +178,7 @@ lexer/parser/compiler.</p>
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">withPrettyErrors</span> = <span class="hljs-params">(fn)</span> -></span>
|
||||
<span class="hljs-function"><span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
fn.call @, code, options
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
|
@ -203,14 +203,36 @@ lookups.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.compile = compile = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.compile = compile = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -></span>
|
||||
{merge, extend} = helpers
|
||||
options = extend {}, options
|
||||
|
||||
<span class="hljs-keyword">if</span> options.sourceMap
|
||||
map = <span class="hljs-keyword">new</span> SourceMap
|
||||
|
||||
fragments = parser.parse(lexer.tokenize code, options).compileToFragments options
|
||||
tokens = lexer.tokenize code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Pass a list of referenced variables, so that generated variables won’t get
|
||||
the same name. Since all generated variables start with an underscore only
|
||||
referenced variables also starting with an underscore are passed, as an
|
||||
optimization.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> options.referencedVars = (
|
||||
token[<span class="hljs-number">1</span>] <span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token.variable <span class="hljs-keyword">and</span> token[<span class="hljs-number">1</span>].charAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'_'</span>
|
||||
)
|
||||
|
||||
fragments = parser.parse(tokens).compileToFragments options
|
||||
|
||||
currentLine = <span class="hljs-number">0</span>
|
||||
currentLine += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> options.header
|
||||
|
@ -222,11 +244,11 @@ lookups.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Update the sourcemap with data from each fragment</p>
|
||||
|
||||
|
@ -248,11 +270,11 @@ lookups.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Copy the code from each fragment into the final JavaScript.</p>
|
||||
|
||||
|
@ -275,39 +297,18 @@ lookups.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.tokens = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -></span>
|
||||
lexer.tokenize code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Parse a string of CoffeeScript code or an array of lexed tokens, and
|
||||
return the AST. You can then compile it by calling <code>.compile()</code> on the root,
|
||||
or traverse it by using <code>.traverseChildren()</code> with a callback.</p>
|
||||
<p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.nodes = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(source, options)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> source <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
|
||||
parser.parse lexer.tokenize source, options
|
||||
<span class="hljs-keyword">else</span>
|
||||
parser.parse source</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.tokens = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -></span>
|
||||
lexer.tokenize code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -318,13 +319,17 @@ or traverse it by using <code>.traverseChildren()</code> with a callback.</p>
|
|||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Compile and execute a string of CoffeeScript (on the server), correctly
|
||||
setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.</p>
|
||||
<p>Parse a string of CoffeeScript code or an array of lexed tokens, and
|
||||
return the AST. You can then compile it by calling <code>.compile()</code> on the root,
|
||||
or traverse it by using <code>.traverseChildren()</code> with a callback.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">run</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
mainModule = <span class="hljs-built_in">require</span>.main</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.nodes = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(source, options)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> source <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
|
||||
parser.parse lexer.tokenize source, options
|
||||
<span class="hljs-keyword">else</span>
|
||||
parser.parse source</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -335,6 +340,23 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
|||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Compile and execute a string of CoffeeScript (on the server), correctly
|
||||
setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.r<span class="hljs-function"><span class="hljs-title">un</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
mainModule = <span class="hljs-built_in">require</span>.main</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Set the filename.</p>
|
||||
|
||||
</div>
|
||||
|
@ -345,11 +367,11 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Clear the module cache.</p>
|
||||
|
||||
|
@ -360,11 +382,11 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Assign paths for node_modules loading</p>
|
||||
|
||||
|
@ -379,11 +401,11 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Compile.</p>
|
||||
|
||||
|
@ -398,26 +420,30 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<a class="pilcrow" href="#section-16">¶</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>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">eval</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.e<span class="hljs-function"><span class="hljs-title">val</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> code = code.trim()
|
||||
Script = vm.Script
|
||||
<span class="hljs-keyword">if</span> Script
|
||||
createContext = vm.Script.createContext ? vm.createContext
|
||||
|
||||
isContext = vm.isContext ? <span class="hljs-function"><span class="hljs-params">(ctx)</span> -></span>
|
||||
options.sandbox <span class="hljs-keyword">instanceof</span> createContext().constructor
|
||||
|
||||
<span class="hljs-keyword">if</span> createContext
|
||||
<span class="hljs-keyword">if</span> options.sandbox?
|
||||
<span class="hljs-keyword">if</span> options.sandbox <span class="hljs-keyword">instanceof</span> Script.createContext().constructor
|
||||
<span class="hljs-keyword">if</span> isContext options.sandbox
|
||||
sandbox = options.sandbox
|
||||
<span class="hljs-keyword">else</span>
|
||||
sandbox = Script.createContext()
|
||||
sandbox = createContext()
|
||||
sandbox[k] = v <span class="hljs-keyword">for</span> own k, v <span class="hljs-keyword">of</span> options.sandbox
|
||||
sandbox.<span class="hljs-built_in">global</span> = sandbox.root = sandbox.GLOBAL = sandbox
|
||||
<span class="hljs-keyword">else</span>
|
||||
|
@ -428,11 +454,11 @@ The CoffeeScript REPL uses this to run the input.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>define module/require only if they chose not to specify their own</p>
|
||||
|
||||
|
@ -441,45 +467,45 @@ The CoffeeScript REPL uses this to run the input.</p>
|
|||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> sandbox <span class="hljs-keyword">isnt</span> <span class="hljs-built_in">global</span> <span class="hljs-keyword">or</span> sandbox.<span class="hljs-built_in">module</span> <span class="hljs-keyword">or</span> sandbox.<span class="hljs-built_in">require</span>
|
||||
Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
|
||||
sandbox.<span class="hljs-built_in">module</span> = _module = <span class="hljs-keyword">new</span> Module(options.modulename || <span class="hljs-string">'eval'</span>)
|
||||
sandbox.<span class="hljs-built_in">require</span> = <span class="hljs-function"><span class="hljs-title">_require</span> = <span class="hljs-params">(path)</span> -></span> Module._load path, _module, <span class="hljs-literal">true</span>
|
||||
sandbox.<span class="hljs-built_in">require</span> = _<span class="hljs-function"><span class="hljs-title">require</span> = <span class="hljs-params">(path)</span> -></span> Module._load path, _module, <span class="hljs-literal">true</span>
|
||||
_module.filename = sandbox.__filename
|
||||
_require[r] = <span class="hljs-built_in">require</span>[r] <span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> Object.getOwnPropertyNames <span class="hljs-built_in">require</span> <span class="hljs-keyword">when</span> r <span class="hljs-keyword">isnt</span> <span class="hljs-string">'paths'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>use the same hack node currently uses for their own REPL</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> _require.paths = _module.paths = Module._nodeModulePaths process.cwd()
|
||||
_require.<span class="hljs-function"><span class="hljs-title">resolve</span> = <span class="hljs-params">(request)</span> -></span> Module._resolveFilename request, _module
|
||||
o = {}
|
||||
o[k] = v <span class="hljs-keyword">for</span> own k, v <span class="hljs-keyword">of</span> options
|
||||
o.bare = <span class="hljs-literal">on</span> <span class="hljs-comment"># ensure return value</span>
|
||||
js = compile code, o
|
||||
<span class="hljs-keyword">if</span> sandbox <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
|
||||
vm.runInThisContext js
|
||||
<span class="hljs-keyword">else</span>
|
||||
vm.runInContext js, sandbox
|
||||
|
||||
<span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">register</span> = -></span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./register'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>use the same hack node currently uses for their own REPL</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> _require.paths = _module.paths = Module._nodeModulePaths process.cwd()
|
||||
_require.r<span class="hljs-function"><span class="hljs-title">esolve</span> = <span class="hljs-params">(request)</span> -></span> Module._resolveFilename request, _module
|
||||
o = {}
|
||||
o[k] = v <span class="hljs-keyword">for</span> own k, v <span class="hljs-keyword">of</span> options
|
||||
o.bare = <span class="hljs-literal">on</span> <span class="hljs-comment"># ensure return value</span>
|
||||
js = compile code, o
|
||||
<span class="hljs-keyword">if</span> sandbox <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
|
||||
vm.runInThisContext js
|
||||
<span class="hljs-keyword">else</span>
|
||||
vm.runInContext js, sandbox
|
||||
|
||||
exports.r<span class="hljs-function"><span class="hljs-title">egister</span> = -></span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./register'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>Throw error with deprecation warning when depending upon implicit <code>require.extensions</code> registration</p>
|
||||
|
||||
</div>
|
||||
|
@ -491,7 +517,7 @@ The CoffeeScript REPL uses this to run the input.</p>
|
|||
Use CoffeeScript.register() or require the coffee-script/register module to require <span class="hljs-subst">#{ext}</span> files.
|
||||
"""</span>
|
||||
|
||||
<span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">_compileFile</span> = <span class="hljs-params">(filename, sourceMap = <span class="hljs-literal">no</span>)</span> -></span>
|
||||
exports._<span class="hljs-function"><span class="hljs-title">compileFile</span> = <span class="hljs-params">(filename, sourceMap = <span class="hljs-literal">no</span>)</span> -></span>
|
||||
raw = fs.readFileSync filename, <span class="hljs-string">'utf8'</span>
|
||||
stripped = <span class="hljs-keyword">if</span> raw.charCodeAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-number">0xFEFF</span> <span class="hljs-keyword">then</span> raw.substring <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> raw
|
||||
|
||||
|
@ -502,11 +528,11 @@ The CoffeeScript REPL uses this to run the input.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>As the filename and code of a dynamically loaded file will be different
|
||||
from the original file compiled with CoffeeScript.run, add that
|
||||
|
@ -521,11 +547,11 @@ information to error so it can be pretty-printed later.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Instantiate a Lexer for our use here.</p>
|
||||
|
||||
|
@ -536,11 +562,11 @@ information to error so it can be pretty-printed later.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<a class="pilcrow" href="#section-22">¶</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
|
||||
|
@ -550,16 +576,17 @@ directly as a “Jison lexer”.</p>
|
|||
|
||||
<div class="content"><div class='highlight'><pre>parser.lexer =
|
||||
<span class="hljs-attribute">lex</span>:<span class="hljs-function"> -></span>
|
||||
token = <span class="hljs-property">@tokens</span>[<span class="hljs-property">@pos</span>++]
|
||||
token = parser.tokens[<span class="hljs-property">@pos</span>++]
|
||||
<span class="hljs-keyword">if</span> token
|
||||
[tag, <span class="hljs-property">@yytext</span>, <span class="hljs-property">@yylloc</span>] = token
|
||||
<span class="hljs-property">@errorToken</span> = token.origin <span class="hljs-keyword">or</span> token
|
||||
parser.errorToken = token.origin <span class="hljs-keyword">or</span> token
|
||||
<span class="hljs-property">@yylineno</span> = <span class="hljs-property">@yylloc</span>.first_line
|
||||
<span class="hljs-keyword">else</span>
|
||||
tag = <span class="hljs-string">''</span>
|
||||
|
||||
tag
|
||||
<span class="hljs-attribute">setInput</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@tokens</span>)</span> -></span>
|
||||
<span class="hljs-attribute">setInput</span>: <span class="hljs-function"><span class="hljs-params">(tokens)</span> -></span>
|
||||
parser.tokens = tokens
|
||||
<span class="hljs-property">@pos</span> = <span class="hljs-number">0</span>
|
||||
<span class="hljs-attribute">upcomingInput</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-string">""</span></pre></div></div>
|
||||
|
@ -567,32 +594,17 @@ directly as a “Jison lexer”.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Make all the AST nodes visible to the parser.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.yy = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>Override Jison’s default error handling function.</p>
|
||||
<p>Make all the AST nodes visible to the parser.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.yy.<span class="hljs-function"><span class="hljs-title">parseError</span> = <span class="hljs-params">(message, {token})</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>parser.yy = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -603,13 +615,28 @@ directly as a “Jison lexer”.</p>
|
|||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Override Jison’s default error handling function.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.yy.p<span class="hljs-function"><span class="hljs-title">arseError</span> = <span class="hljs-params">(message, {token})</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
<p>Disregard Jison’s message, it contains redundant line numer information.
|
||||
Disregard the token, we take its value directly from the lexer in case
|
||||
the error is caused by a generated token which might refer to its origin.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> {errorToken, tokens} = parser.lexer
|
||||
<div class="content"><div class='highlight'><pre> {errorToken, tokens} = parser
|
||||
[errorTag, errorText, errorLoc] = errorToken
|
||||
|
||||
errorText = <span class="hljs-keyword">if</span> errorToken <span class="hljs-keyword">is</span> tokens[tokens.length - <span class="hljs-number">1</span>]
|
||||
|
@ -622,11 +649,11 @@ the error is caused by a generated token which might refer to its origin.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
<p>The second argument has a <code>loc</code> property, which should have the location
|
||||
data for this token. Unfortunately, Jison seems to send an outdated <code>loc</code>
|
||||
|
@ -640,11 +667,11 @@ from the lexer.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<li id="section-27">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
</div>
|
||||
<p>Based on <a href="http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js">http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js</a>
|
||||
Modified to handle sourceMap</p>
|
||||
|
@ -672,11 +699,11 @@ Modified to handle sourceMap</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<li id="section-28">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
</div>
|
||||
<p>Check for a sourceMap position</p>
|
||||
|
||||
|
@ -717,11 +744,11 @@ Modified to handle sourceMap</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-28">
|
||||
<li id="section-29">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
<a class="pilcrow" href="#section-29">¶</a>
|
||||
</div>
|
||||
<p>Map of filenames -> sourceMap object.</p>
|
||||
|
||||
|
@ -732,11 +759,11 @@ Modified to handle sourceMap</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-29">
|
||||
<li id="section-30">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-29">¶</a>
|
||||
<a class="pilcrow" href="#section-30">¶</a>
|
||||
</div>
|
||||
<p>Generates the source map for a coffee file and stores it in the local cache variable.</p>
|
||||
|
||||
|
@ -744,18 +771,18 @@ Modified to handle sourceMap</p>
|
|||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">getSourceMap</span> = <span class="hljs-params">(filename)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> sourceMaps[filename] <span class="hljs-keyword">if</span> sourceMaps[filename]
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> path?.extname(filename) <span class="hljs-keyword">in</span> <span class="hljs-built_in">exports</span>.FILE_EXTENSIONS
|
||||
answer = <span class="hljs-built_in">exports</span>._compileFile filename, <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> path?.extname(filename) <span class="hljs-keyword">in</span> exports.FILE_EXTENSIONS
|
||||
answer = exports._compileFile filename, <span class="hljs-literal">true</span>
|
||||
sourceMaps[filename] = answer.sourceMap</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-30">
|
||||
<li id="section-31">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-30">¶</a>
|
||||
<a class="pilcrow" href="#section-31">¶</a>
|
||||
</div>
|
||||
<p>Based on <a href="http://goo.gl/ZTx1p">michaelficarra/CoffeeScriptRedux</a>
|
||||
NodeJS / V8 have no support for transforming positions in stack traces using
|
||||
|
@ -764,14 +791,14 @@ positions.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Error.<span class="hljs-function"><span class="hljs-title">prepareStackTrace</span> = <span class="hljs-params">(err, stack)</span> -></span>
|
||||
<span class="hljs-function"><span class="hljs-title">getSourceMapping</span> = <span class="hljs-params">(filename, line, column)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>Error.p<span class="hljs-function"><span class="hljs-title">repareStackTrace</span> = <span class="hljs-params">(err, stack)</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-title">getSourceMapping</span> = <span class="hljs-params">(filename, line, column)</span> -></span>
|
||||
sourceMap = getSourceMap filename
|
||||
answer = sourceMap.sourceLocation [line - <span class="hljs-number">1</span>, column - <span class="hljs-number">1</span>] <span class="hljs-keyword">if</span> sourceMap
|
||||
<span class="hljs-keyword">if</span> answer <span class="hljs-keyword">then</span> [answer[<span class="hljs-number">0</span>] + <span class="hljs-number">1</span>, answer[<span class="hljs-number">1</span>] + <span class="hljs-number">1</span>] <span class="hljs-keyword">else</span> <span class="hljs-literal">null</span>
|
||||
|
||||
frames = <span class="hljs-keyword">for</span> frame <span class="hljs-keyword">in</span> stack
|
||||
<span class="hljs-keyword">break</span> <span class="hljs-keyword">if</span> frame.getFunction() <span class="hljs-keyword">is</span> <span class="hljs-built_in">exports</span>.run
|
||||
<span class="hljs-keyword">break</span> <span class="hljs-keyword">if</span> frame.getFunction() <span class="hljs-keyword">is</span> exports.run
|
||||
<span class="hljs-string">" at <span class="hljs-subst">#{formatSourcePosition frame, getSourceMapping}</span>"</span>
|
||||
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{err.toString()}</span>\n<span class="hljs-subst">#{frames.join <span class="hljs-string">'\n'</span>}</span>\n"</span></pre></div></div>
|
||||
|
|
|
@ -141,7 +141,6 @@ path = <span class="hljs-built_in">require</span> <span class="hljs-st
|
|||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
optparse = <span class="hljs-built_in">require</span> <span class="hljs-string">'./optparse'</span>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span>
|
||||
mkdirp = <span class="hljs-built_in">require</span> <span class="hljs-string">'mkdirp'</span>
|
||||
{spawn, exec} = <span class="hljs-built_in">require</span> <span class="hljs-string">'child_process'</span>
|
||||
{EventEmitter} = <span class="hljs-built_in">require</span> <span class="hljs-string">'events'</span>
|
||||
|
||||
|
@ -161,11 +160,11 @@ useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>helpers.extend CoffeeScript, <span class="hljs-keyword">new</span> EventEmitter
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">printLine</span> = <span class="hljs-params">(line)</span> -></span> process.stdout.write line + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">printLine</span> = <span class="hljs-params">(line)</span> -></span> process.stdout.write line + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-function"><span class="hljs-title">printWarn</span> = <span class="hljs-params">(line)</span> -></span> process.stderr.write line + <span class="hljs-string">'\n'</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">hidden</span> = <span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/^\.|~$/</span>.test file</pre></div></div>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">hidden</span> = <span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/^\.|~$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -254,7 +253,7 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">run</span> = -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.r<span class="hljs-function"><span class="hljs-title">un</span> = -></span>
|
||||
parseOptions()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -357,8 +356,8 @@ extension source files in it and all subdirectories.</p>
|
|||
compileScript(source, code.toString(), base)
|
||||
<span class="hljs-keyword">else</span>
|
||||
notSources[source] = <span class="hljs-literal">yes</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">findDirectoryIndex</span> = <span class="hljs-params">(source)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">findDirectoryIndex</span> = <span class="hljs-params">(source)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> ext <span class="hljs-keyword">in</span> CoffeeScript.FILE_EXTENSIONS
|
||||
index = path.join source, <span class="hljs-string">"index<span class="hljs-subst">#{ext}</span>"</span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
|
@ -461,9 +460,9 @@ them together.</p>
|
|||
<div class="content"><div class='highlight'><pre>joinTimeout = <span class="hljs-literal">null</span>
|
||||
<span class="hljs-function"><span class="hljs-title">compileJoin</span> = -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> opts.join
|
||||
<span class="hljs-keyword">unless</span> sourceCode.some<span class="hljs-function"><span class="hljs-params">((code) -> code <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span>)</span>
|
||||
<span class="hljs-title">clearTimeout</span> <span class="hljs-title">joinTimeout</span>
|
||||
<span class="hljs-title">joinTimeout</span> = <span class="hljs-title">wait</span> 100, -></span>
|
||||
<span class="hljs-keyword">unless</span> sourceCode.some(<span class="hljs-function"><span class="hljs-params">(code)</span> -></span> code <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span>)
|
||||
clearTimeout joinTimeout
|
||||
joinTimeout = wait <span class="hljs-number">100</span>,<span class="hljs-function"> -></span>
|
||||
compileScript opts.join, sourceCode.join(<span class="hljs-string">'\n'</span>), opts.join</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -485,8 +484,8 @@ such as <code>--print</code>.</p>
|
|||
watcher = <span class="hljs-literal">null</span>
|
||||
prevStats = <span class="hljs-literal">null</span>
|
||||
compileTimeout = <span class="hljs-literal">null</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">watchErr</span> = <span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">watchErr</span> = <span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> source <span class="hljs-keyword">in</span> sources
|
||||
<span class="hljs-keyword">try</span>
|
||||
|
@ -495,8 +494,8 @@ such as <code>--print</code>.</p>
|
|||
<span class="hljs-keyword">catch</span>
|
||||
removeSource source, base
|
||||
compileJoin()
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">compile</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">compile</span> = -></span>
|
||||
clearTimeout compileTimeout
|
||||
compileTimeout = wait <span class="hljs-number">25</span>,<span class="hljs-function"> -></span>
|
||||
fs.stat source, <span class="hljs-function"><span class="hljs-params">(err, stats)</span> -></span>
|
||||
|
@ -509,15 +508,15 @@ such as <code>--print</code>.</p>
|
|||
<span class="hljs-keyword">return</span> watchErr err <span class="hljs-keyword">if</span> err
|
||||
compileScript(source, code.toString(), base)
|
||||
rewatch()
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">startWatcher</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">startWatcher</span> = -></span>
|
||||
watcher = fs.watch source
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'change'</span>, compile
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'error'</span>, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'EPERM'</span>
|
||||
removeSource source, base
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">rewatch</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">rewatch</span> = -></span>
|
||||
watcher?.close()
|
||||
startWatcher()
|
||||
|
||||
|
@ -542,8 +541,8 @@ such as <code>--print</code>.</p>
|
|||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">watchDir</span> = <span class="hljs-params">(source, base)</span> -></span>
|
||||
watcher = <span class="hljs-literal">null</span>
|
||||
readdirTimeout = <span class="hljs-literal">null</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">startWatcher</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">startWatcher</span> = -></span>
|
||||
watcher = fs.watch source
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'error'</span>, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'EPERM'</span>
|
||||
|
@ -558,8 +557,8 @@ such as <code>--print</code>.</p>
|
|||
<span class="hljs-keyword">return</span> stopWatcher()
|
||||
<span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> files
|
||||
compilePath (path.join source, file), <span class="hljs-literal">no</span>, base
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">stopWatcher</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">stopWatcher</span> = -></span>
|
||||
watcher.close()
|
||||
removeSourceDir source, base
|
||||
|
||||
|
@ -568,8 +567,8 @@ such as <code>--print</code>.</p>
|
|||
startWatcher()
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">removeSourceDir</span> = <span class="hljs-params">(source, base)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">removeSourceDir</span> = <span class="hljs-params">(source, base)</span> -></span>
|
||||
<span class="hljs-keyword">delete</span> watchedDirs[source]
|
||||
sourcesChanged = <span class="hljs-literal">no</span>
|
||||
<span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> sources <span class="hljs-keyword">when</span> source <span class="hljs-keyword">is</span> path.dirname file
|
||||
|
@ -599,8 +598,8 @@ the compiled JS version as well.</p>
|
|||
silentUnlink outputPath source, base
|
||||
silentUnlink outputPath source, base, <span class="hljs-string">'.js.map'</span>
|
||||
timeLog <span class="hljs-string">"removed <span class="hljs-subst">#{source}</span>"</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">silentUnlink</span> = <span class="hljs-params">(path)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">silentUnlink</span> = <span class="hljs-params">(path)</span> -></span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
fs.unlinkSync path
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
|
@ -639,6 +638,32 @@ the compiled JS version as well.</p>
|
|||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>Recursively mkdir, like <code>mkdir -p</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">mkdirp</span> = <span class="hljs-params">(dir, fn)</span> -></span>
|
||||
mode = <span class="hljs-number">0</span>o777 & ~process.umask()
|
||||
|
||||
<span class="hljs-keyword">do</span> m<span class="hljs-function"><span class="hljs-title">kdirs</span> = <span class="hljs-params">(p = dir, fn)</span> -></span>
|
||||
fs.exists p, <span class="hljs-function"><span class="hljs-params">(exists)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> exists
|
||||
fn()
|
||||
<span class="hljs-keyword">else</span>
|
||||
mkdirs path.dirname(p),<span class="hljs-function"> -></span>
|
||||
fs.mkdir p, mode, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> fn err <span class="hljs-keyword">if</span> err
|
||||
fn()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>Write out a JavaScript source file with the compiled code. By default, files
|
||||
are written out in <code>cwd</code> as <code>.js</code> files with the same name, but the output
|
||||
directory can be customized with <code>--output</code>.</p>
|
||||
|
@ -650,7 +675,7 @@ same directory as the <code>.js</code> file.</p>
|
|||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">writeJs</span> = <span class="hljs-params">(base, sourcePath, js, jsPath, generatedSourceMap = <span class="hljs-literal">null</span>)</span> -></span>
|
||||
sourceMapPath = outputPath sourcePath, base, <span class="hljs-string">".js.map"</span>
|
||||
jsDir = path.dirname jsPath
|
||||
<span class="hljs-function"><span class="hljs-title">compile</span> = -></span>
|
||||
<span class="hljs-function"> <span class="hljs-title">compile</span> = -></span>
|
||||
<span class="hljs-keyword">if</span> opts.compile
|
||||
js = <span class="hljs-string">' '</span> <span class="hljs-keyword">if</span> js.length <= <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">if</span> generatedSourceMap <span class="hljs-keyword">then</span> js = <span class="hljs-string">"<span class="hljs-subst">#{js}</span>\n//# sourceMappingURL=<span class="hljs-subst">#{helpers.baseFileName sourceMapPath, <span class="hljs-literal">no</span>, useWinPathSep}</span>\n"</span>
|
||||
|
@ -671,11 +696,11 @@ same directory as the <code>.js</code> file.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>Convenience for cleaner setTimeouts.</p>
|
||||
|
||||
|
@ -686,11 +711,11 @@ same directory as the <code>.js</code> file.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>When watching scripts, it’s useful to log changes with the timestamp.</p>
|
||||
|
||||
|
@ -702,11 +727,11 @@ same directory as the <code>.js</code> file.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Pretty-print a stream of tokens, sans location data.</p>
|
||||
|
||||
|
@ -722,11 +747,11 @@ same directory as the <code>.js</code> file.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Use the <a href="optparse.html">OptionParser module</a> to extract all options from
|
||||
<code>process.argv</code> that are specified in <code>SWITCHES</code>.</p>
|
||||
|
@ -743,11 +768,11 @@ same directory as the <code>.js</code> file.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>The compile-time options to pass to the CoffeeScript compiler.</p>
|
||||
|
||||
|
@ -782,11 +807,11 @@ same directory as the <code>.js</code> file.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Start up a new Node.js instance with the arguments in <code>--nodejs</code> passed to
|
||||
the <code>node</code> binary, preserving the other options.</p>
|
||||
|
@ -806,11 +831,11 @@ the <code>node</code> binary, preserving the other options.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
<p>Print the <code>--help</code> usage message and exit. Deprecated switches are not
|
||||
shown.</p>
|
||||
|
@ -823,11 +848,11 @@ shown.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
<p>Print the <code>--version</code> message and exit.</p>
|
||||
|
||||
|
|
|
@ -243,7 +243,7 @@ just be passed through unaffected.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-function"><span class="hljs-title">addLocationDataFn</span> = <span class="hljs-params">(first, last)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"> <span class="hljs-title">addLocationDataFn</span> = <span class="hljs-params">(first, last)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> last
|
||||
<span class="hljs-string">"yy.addLocationDataFn(@<span class="hljs-subst">#{first}</span>)"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
|
@ -1247,7 +1247,8 @@ or postfix, with a single expression.</p>
|
|||
]
|
||||
|
||||
<span class="hljs-attribute">ForBody</span>: [
|
||||
o <span class="hljs-string">'FOR Range'</span>,<span class="hljs-function"> -></span> <span class="hljs-attribute">source</span>: LOC(<span class="hljs-number">2</span>) <span class="hljs-keyword">new</span> Value($<span class="hljs-number">2</span>)
|
||||
o <span class="hljs-string">'FOR Range'</span>,<span class="hljs-function"> -></span> <span class="hljs-attribute">source</span>: (LOC(<span class="hljs-number">2</span>) <span class="hljs-keyword">new</span> Value($<span class="hljs-number">2</span>))
|
||||
o <span class="hljs-string">'FOR Range BY Expression'</span>,<span class="hljs-function"> -></span> <span class="hljs-attribute">source</span>: (LOC(<span class="hljs-number">2</span>) <span class="hljs-keyword">new</span> Value($<span class="hljs-number">2</span>)), <span class="hljs-attribute">step</span>: $<span class="hljs-number">4</span>
|
||||
o <span class="hljs-string">'ForStart ForSource'</span>,<span class="hljs-function"> -></span> $<span class="hljs-number">2.</span>own = $<span class="hljs-number">1.</span>own; $<span class="hljs-number">2.</span>name = $<span class="hljs-number">1</span>[<span class="hljs-number">0</span>]; $<span class="hljs-number">2.</span>index = $<span class="hljs-number">1</span>[<span class="hljs-number">1</span>]; $<span class="hljs-number">2</span>
|
||||
]
|
||||
|
||||
|
@ -1416,6 +1417,9 @@ rules are necessary.</p>
|
|||
o <span class="hljs-string">'UNARY_MATH Expression'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Op $<span class="hljs-number">1</span> , $<span class="hljs-number">2</span>
|
||||
o <span class="hljs-string">'- Expression'</span>, (<span class="hljs-function">-></span> <span class="hljs-keyword">new</span> Op <span class="hljs-string">'-'</span>, $<span class="hljs-number">2</span>), <span class="hljs-attribute">prec</span>: <span class="hljs-string">'UNARY_MATH'</span>
|
||||
o <span class="hljs-string">'+ Expression'</span>, (<span class="hljs-function">-></span> <span class="hljs-keyword">new</span> Op <span class="hljs-string">'+'</span>, $<span class="hljs-number">2</span>), <span class="hljs-attribute">prec</span>: <span class="hljs-string">'UNARY_MATH'</span>
|
||||
o <span class="hljs-string">'YIELD Statement'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Op $<span class="hljs-number">1</span> , $<span class="hljs-number">2</span>
|
||||
o <span class="hljs-string">'YIELD Expression'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Op $<span class="hljs-number">1</span> , $<span class="hljs-number">2</span>
|
||||
o <span class="hljs-string">'YIELD FROM Expression'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Op $<span class="hljs-number">1.</span>concat($<span class="hljs-number">2</span>) , $<span class="hljs-number">3</span>
|
||||
|
||||
o <span class="hljs-string">'-- SimpleAssignable'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Op <span class="hljs-string">'--'</span>, $<span class="hljs-number">2</span>
|
||||
o <span class="hljs-string">'++ SimpleAssignable'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Op <span class="hljs-string">'++'</span>, $<span class="hljs-number">2</span>
|
||||
|
@ -1517,6 +1521,7 @@ down. Following these rules is what makes <code>2 + 3 * 4</code> parse as:</p>
|
|||
[<span class="hljs-string">'left'</span>, <span class="hljs-string">'COMPARE'</span>]
|
||||
[<span class="hljs-string">'left'</span>, <span class="hljs-string">'LOGIC'</span>]
|
||||
[<span class="hljs-string">'nonassoc'</span>, <span class="hljs-string">'INDENT'</span>, <span class="hljs-string">'OUTDENT'</span>]
|
||||
[<span class="hljs-string">'right'</span>, <span class="hljs-string">'YIELD'</span>]
|
||||
[<span class="hljs-string">'right'</span>, <span class="hljs-string">'='</span>, <span class="hljs-string">':'</span>, <span class="hljs-string">'COMPOUND_ASSIGN'</span>, <span class="hljs-string">'RETURN'</span>, <span class="hljs-string">'THROW'</span>, <span class="hljs-string">'EXTENDS'</span>]
|
||||
[<span class="hljs-string">'right'</span>, <span class="hljs-string">'FORIN'</span>, <span class="hljs-string">'FOROF'</span>, <span class="hljs-string">'BY'</span>, <span class="hljs-string">'WHEN'</span>]
|
||||
[<span class="hljs-string">'right'</span>, <span class="hljs-string">'IF'</span>, <span class="hljs-string">'ELSE'</span>, <span class="hljs-string">'FOR'</span>, <span class="hljs-string">'WHILE'</span>, <span class="hljs-string">'UNTIL'</span>, <span class="hljs-string">'LOOP'</span>, <span class="hljs-string">'SUPER'</span>, <span class="hljs-string">'CLASS'</span>]
|
||||
|
@ -1588,7 +1593,7 @@ precedence from low to high, and we have it high to low
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.parser = <span class="hljs-keyword">new</span> Parser
|
||||
<div class="content"><div class='highlight'><pre>exports.parser = <span class="hljs-keyword">new</span> Parser
|
||||
tokens : tokens.join <span class="hljs-string">' '</span>
|
||||
bnf : grammar
|
||||
operators : operators.reverse()
|
||||
|
|
|
@ -134,7 +134,7 @@ arrays, count characters, that sort of thing.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">starts</span> = <span class="hljs-params">(string, literal, start)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.s<span class="hljs-function"><span class="hljs-title">tarts</span> = <span class="hljs-params">(string, literal, start)</span> -></span>
|
||||
literal <span class="hljs-keyword">is</span> string.substr start, literal.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -150,7 +150,7 @@ arrays, count characters, that sort of thing.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">ends</span> = <span class="hljs-params">(string, literal, back)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.e<span class="hljs-function"><span class="hljs-title">nds</span> = <span class="hljs-params">(string, literal, back)</span> -></span>
|
||||
len = literal.length
|
||||
literal <span class="hljs-keyword">is</span> string.substr string.length - len - (back <span class="hljs-keyword">or</span> <span class="hljs-number">0</span>), len</pre></div></div>
|
||||
|
||||
|
@ -167,7 +167,7 @@ arrays, count characters, that sort of thing.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.repeat = <span class="hljs-function"><span class="hljs-title">repeat</span> = <span class="hljs-params">(str, n)</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.repeat = r<span class="hljs-function"><span class="hljs-title">epeat</span> = <span class="hljs-params">(str, n)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -202,7 +202,7 @@ arrays, count characters, that sort of thing.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">compact</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.c<span class="hljs-function"><span class="hljs-title">ompact</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
item <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> array <span class="hljs-keyword">when</span> item</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -218,7 +218,7 @@ arrays, count characters, that sort of thing.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">count</span> = <span class="hljs-params">(string, substr)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.c<span class="hljs-function"><span class="hljs-title">ount</span> = <span class="hljs-params">(string, substr)</span> -></span>
|
||||
num = pos = <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">1</span>/<span class="hljs-number">0</span> <span class="hljs-keyword">unless</span> substr.length
|
||||
num++ <span class="hljs-keyword">while</span> pos = <span class="hljs-number">1</span> + string.indexOf substr, pos
|
||||
|
@ -239,7 +239,7 @@ options hash to propagate down the tree without polluting other branches.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">merge</span> = <span class="hljs-params">(options, overrides)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.m<span class="hljs-function"><span class="hljs-title">erge</span> = <span class="hljs-params">(options, overrides)</span> -></span>
|
||||
extend (extend {}, options), overrides</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -255,7 +255,7 @@ options hash to propagate down the tree without polluting other branches.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>extend = <span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">extend</span> = <span class="hljs-params">(object, properties)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>extend = exports.e<span class="hljs-function"><span class="hljs-title">xtend</span> = <span class="hljs-params">(object, properties)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> properties
|
||||
object[key] = val
|
||||
object</pre></div></div>
|
||||
|
@ -274,7 +274,7 @@ Handy for getting a list of <code>children</code> from the nodes.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.flatten = <span class="hljs-function"><span class="hljs-title">flatten</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.flatten = f<span class="hljs-function"><span class="hljs-title">latten</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
flattened = []
|
||||
<span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> array
|
||||
<span class="hljs-keyword">if</span> element <span class="hljs-keyword">instanceof</span> Array
|
||||
|
@ -297,7 +297,7 @@ looking for a particular method in an options hash.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">del</span> = <span class="hljs-params">(obj, key)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.d<span class="hljs-function"><span class="hljs-title">el</span> = <span class="hljs-params">(obj, key)</span> -></span>
|
||||
val = obj[key]
|
||||
<span class="hljs-keyword">delete</span> obj[key]
|
||||
val</pre></div></div>
|
||||
|
@ -315,7 +315,7 @@ looking for a particular method in an options hash.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.last = <span class="hljs-function"><span class="hljs-title">last</span> = <span class="hljs-params">(array, back)</span> -></span> array[array.length - (back <span class="hljs-keyword">or</span> <span class="hljs-number">0</span>) - <span class="hljs-number">1</span>]</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.last = l<span class="hljs-function"><span class="hljs-title">ast</span> = <span class="hljs-params">(array, back)</span> -></span> array[array.length - (back <span class="hljs-keyword">or</span> <span class="hljs-number">0</span>) - <span class="hljs-number">1</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -330,7 +330,7 @@ looking for a particular method in an options hash.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.some = <span class="hljs-attribute">Array</span>::some ? <span class="hljs-function"><span class="hljs-params">(fn)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.some = <span class="hljs-attribute">Array</span>::some ? <span class="hljs-function"><span class="hljs-params">(fn)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">when</span> fn e
|
||||
<span class="hljs-literal">false</span></pre></div></div>
|
||||
|
||||
|
@ -349,7 +349,7 @@ can be compiled “normally”.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">invertLiterate</span> = <span class="hljs-params">(code)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.i<span class="hljs-function"><span class="hljs-title">nvertLiterate</span> = <span class="hljs-params">(code)</span> -></span>
|
||||
maybe_code = <span class="hljs-literal">true</span>
|
||||
lines = <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> code.split(<span class="hljs-string">'\n'</span>)
|
||||
<span class="hljs-keyword">if</span> maybe_code <span class="hljs-keyword">and</span> <span class="hljs-regexp">/^([ ]{4}|[ ]{0,3}\t)/</span>.test line
|
||||
|
@ -398,8 +398,8 @@ The object is returned either way.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">addLocationDataFn</span> = <span class="hljs-params">(first, last)</span> -></span>
|
||||
<span class="hljs-function"><span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.a<span class="hljs-function"><span class="hljs-title">ddLocationDataFn</span> = <span class="hljs-params">(first, last)</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> ((<span class="hljs-keyword">typeof</span> obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span>) <span class="hljs-keyword">and</span> (!!obj[<span class="hljs-string">'updateLocationDataIfMissing'</span>])
|
||||
obj.updateLocationDataIfMissing buildLocationData(first, last)
|
||||
|
||||
|
@ -419,7 +419,7 @@ The object is returned either way.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">locationDataToString</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.l<span class="hljs-function"><span class="hljs-title">ocationDataToString</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-string">"2"</span> <span class="hljs-keyword">of</span> obj) <span class="hljs-keyword">and</span> (<span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj[<span class="hljs-number">2</span>]) <span class="hljs-keyword">then</span> locationData = obj[<span class="hljs-number">2</span>]
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj <span class="hljs-keyword">then</span> locationData = obj
|
||||
|
||||
|
@ -442,8 +442,8 @@ The object is returned either way.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">baseFileName</span> = <span class="hljs-params">(file, stripExt = <span class="hljs-literal">no</span>, useWinPathSep = <span class="hljs-literal">no</span>)</span> -></span>
|
||||
pathSep = <span class="hljs-keyword">if</span> useWinPathSep <span class="hljs-keyword">then</span> <span class="hljs-regexp">/\\|\//</span> <span class="hljs-keyword">else</span> <span class="hljs-regexp">/\/</span>/
|
||||
<div class="content"><div class='highlight'><pre>exports.b<span class="hljs-function"><span class="hljs-title">aseFileName</span> = <span class="hljs-params">(file, stripExt = <span class="hljs-literal">no</span>, useWinPathSep = <span class="hljs-literal">no</span>)</span> -></span>
|
||||
pathSep = <span class="hljs-keyword">if</span> useWinPathSep <span class="hljs-keyword">then</span> <span class="hljs-regexp">/\\|\//</span> <span class="hljs-keyword">else</span> <span class="hljs-regexp">/\//</span>
|
||||
parts = file.split(pathSep)
|
||||
file = parts[parts.length - <span class="hljs-number">1</span>]
|
||||
<span class="hljs-keyword">return</span> file <span class="hljs-keyword">unless</span> stripExt <span class="hljs-keyword">and</span> file.indexOf(<span class="hljs-string">'.'</span>) >= <span class="hljs-number">0</span>
|
||||
|
@ -465,7 +465,7 @@ The object is returned either way.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">isCoffee</span> = <span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.i<span class="hljs-function"><span class="hljs-title">sCoffee</span> = <span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -480,7 +480,7 @@ The object is returned either way.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">isLiterate</span> = <span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.i<span class="hljs-function"><span class="hljs-title">sLiterate</span> = <span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -498,7 +498,7 @@ marker showing where the error is.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">throwSyntaxError</span> = <span class="hljs-params">(message, location)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.t<span class="hljs-function"><span class="hljs-title">hrowSyntaxError</span> = <span class="hljs-params">(message, location)</span> -></span>
|
||||
error = <span class="hljs-keyword">new</span> SyntaxError message
|
||||
error.location = location
|
||||
error.toString = syntaxErrorToString</pre></div></div>
|
||||
|
@ -536,7 +536,7 @@ it already.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">updateSyntaxError</span> = <span class="hljs-params">(error, code, filename)</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.u<span class="hljs-function"><span class="hljs-title">pdateSyntaxError</span> = <span class="hljs-params">(error, code, filename)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -556,8 +556,8 @@ it already.</p>
|
|||
error.filename <span class="hljs-keyword">or</span>= filename
|
||||
error.stack = error.toString()
|
||||
error
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">syntaxErrorToString</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">syntaxErrorToString</span> = -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-attribute">Error</span>::toString.call @ <span class="hljs-keyword">unless</span> <span class="hljs-property">@code</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@location</span>
|
||||
|
||||
{first_line, first_column, last_line, last_column} = <span class="hljs-property">@location</span>
|
||||
|
@ -601,7 +601,7 @@ it already.</p>
|
|||
colorsEnabled = process.stdout.isTTY <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> process.env.NODE_DISABLE_COLORS
|
||||
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@colorful</span> ? colorsEnabled
|
||||
<span class="hljs-function"><span class="hljs-title">colorize</span> = <span class="hljs-params">(str)</span> -></span> <span class="hljs-string">"\x1B[1;31m<span class="hljs-subst">#{str}</span>\x1B[0m"</span>
|
||||
<span class="hljs-function"> <span class="hljs-title">colorize</span> = <span class="hljs-params">(str)</span> -></span> <span class="hljs-string">"\x1B[1;31m<span class="hljs-subst">#{str}</span>\x1B[0m"</span>
|
||||
codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
|
||||
marker = colorize marker
|
||||
|
||||
|
@ -611,7 +611,7 @@ it already.</p>
|
|||
<span class="hljs-subst">#{marker}</span>
|
||||
"""</span>
|
||||
|
||||
<span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">nameWhitespaceCharacter</span> = <span class="hljs-params">(string)</span> -></span>
|
||||
exports.n<span class="hljs-function"><span class="hljs-title">ameWhitespaceCharacter</span> = <span class="hljs-params">(string)</span> -></span>
|
||||
<span class="hljs-keyword">switch</span> string
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">' '</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'space'</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'newline'</span>
|
||||
|
|
|
@ -119,7 +119,7 @@
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>[key] = val <span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports[key] = val <span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -157,8 +157,8 @@ addLocationDataFn, locationDataToString, throwSyntaxError} = <span class="hljs-b
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.extend = extend
|
||||
<span class="hljs-built_in">exports</span>.addLocationDataFn = addLocationDataFn</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.extend = extend
|
||||
exports.addLocationDataFn = addLocationDataFn</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -207,7 +207,7 @@ all the CodeFragments’ <code>code</code> snippets, in order.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.CodeFragment = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CodeFragment</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.CodeFragment = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CodeFragment</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(parent, code)</span> -></span>
|
||||
<span class="hljs-property">@code</span> = <span class="hljs-string">"<span class="hljs-subst">#{code}</span>"</span>
|
||||
<span class="hljs-property">@locationData</span> = parent?.locationData
|
||||
|
@ -266,7 +266,7 @@ scope, and indentation level.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Base = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Base = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Base</span></span>
|
||||
|
||||
<span class="hljs-attribute">compile</span>: <span class="hljs-function"><span class="hljs-params">(o, lvl)</span> -></span>
|
||||
fragmentsToText <span class="hljs-property">@compileToFragments</span> o, lvl</pre></div></div>
|
||||
|
@ -327,7 +327,11 @@ object with their parent closure, to preserve the expected lexical scope.</p>
|
|||
<span class="hljs-keyword">else</span>
|
||||
meth = <span class="hljs-string">'call'</span>
|
||||
func = <span class="hljs-keyword">new</span> Value func, [<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal meth]
|
||||
(<span class="hljs-keyword">new</span> Call func, args).compileNode o</pre></div></div>
|
||||
parts = (<span class="hljs-keyword">new</span> Call func, args).compileNode o
|
||||
<span class="hljs-keyword">if</span> func.isGenerator
|
||||
parts.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"(yield* "</span>
|
||||
parts.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">")"</span>
|
||||
parts</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -609,7 +613,7 @@ indented block of code — the implementation of a function, a clause in an
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Block = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Block</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Block = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Block</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(nodes)</span> -></span>
|
||||
<span class="hljs-property">@expressions</span> = compact flatten nodes <span class="hljs-keyword">or</span> []
|
||||
|
||||
|
@ -829,7 +833,7 @@ clean up obvious double-parentheses.</p>
|
|||
o.indent = <span class="hljs-keyword">if</span> o.bare <span class="hljs-keyword">then</span> <span class="hljs-string">''</span> <span class="hljs-keyword">else</span> TAB
|
||||
o.level = LEVEL_TOP
|
||||
<span class="hljs-property">@spaced</span> = <span class="hljs-literal">yes</span>
|
||||
o.scope = <span class="hljs-keyword">new</span> Scope <span class="hljs-literal">null</span>, <span class="hljs-keyword">this</span>, <span class="hljs-literal">null</span></pre></div></div>
|
||||
o.scope = <span class="hljs-keyword">new</span> Scope <span class="hljs-literal">null</span>, <span class="hljs-keyword">this</span>, <span class="hljs-literal">null</span>, o.referencedVars ? []</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -951,7 +955,7 @@ JavaScript without translation, such as: strings, numbers,
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Literal = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Literal</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Literal = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Literal</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@value</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">makeReturn</span>:<span class="hljs-function"> -></span>
|
||||
|
@ -1029,7 +1033,7 @@ make sense.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Return = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Return</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Return = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Return</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@expression</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'expression'</span>]
|
||||
|
@ -1091,7 +1095,7 @@ or vanilla.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Value = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Value</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Value = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Value</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(base, props, tag)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> base <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> props <span class="hljs-keyword">and</span> base <span class="hljs-keyword">instanceof</span> Value
|
||||
<span class="hljs-property">@base</span> = base
|
||||
|
@ -1254,7 +1258,7 @@ evaluate anything twice when building the soak chain.</p>
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">unfoldSoak</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
<span class="hljs-property">@unfoldedSoak</span> ?= <span class="hljs-keyword">do</span><span class="hljs-function"> =></span>
|
||||
<span class="hljs-property">@unfoldedSoak</span> ?= <span class="hljs-keyword">do</span> <span class="hljs-function">=></span>
|
||||
<span class="hljs-keyword">if</span> ifn = <span class="hljs-property">@base</span>.unfoldSoak o
|
||||
ifn.body.properties.push <span class="hljs-property">@properties</span>...
|
||||
<span class="hljs-keyword">return</span> ifn
|
||||
|
@ -1296,14 +1300,14 @@ at the same position.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Comment = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Comment</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Comment = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Comment</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@comment</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">isStatement</span>: YES
|
||||
<span class="hljs-attribute">makeReturn</span>: THIS
|
||||
|
||||
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o, level)</span> -></span>
|
||||
comment = <span class="hljs-property">@comment</span>.replace <span class="hljs-regexp">/^(\s*)#/gm</span>, <span class="hljs-string">"$1 *"</span>
|
||||
comment = <span class="hljs-property">@comment</span>.replace <span class="hljs-regexp">/^(\s*)# /gm</span>, <span class="hljs-string">"$1 * "</span>
|
||||
code = <span class="hljs-string">"/*<span class="hljs-subst">#{multident comment, <span class="hljs-property">@tab</span>}</span><span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">in</span> comment <span class="hljs-keyword">then</span> <span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>}</span> */"</span>
|
||||
code = o.indent + code <span class="hljs-keyword">if</span> (level <span class="hljs-keyword">or</span> o.level) <span class="hljs-keyword">is</span> LEVEL_TOP
|
||||
[<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>), <span class="hljs-property">@makeCode</span>(code)]</pre></div></div>
|
||||
|
@ -1335,7 +1339,7 @@ calls against the prototype’s function of the same name.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Call = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Call</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Call = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Call</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(variable, <span class="hljs-property">@args</span> = [], <span class="hljs-property">@soak</span>)</span> -></span>
|
||||
<span class="hljs-property">@isNew</span> = <span class="hljs-literal">false</span>
|
||||
<span class="hljs-property">@isSuper</span> = variable <span class="hljs-keyword">is</span> <span class="hljs-string">'super'</span>
|
||||
|
@ -1569,7 +1573,7 @@ After <code>goog.inherits</code> from the
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Extends = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Extends</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Extends = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Extends</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@child</span>, <span class="hljs-property">@parent</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'child'</span>, <span class="hljs-string">'parent'</span>]</pre></div></div>
|
||||
|
@ -1588,7 +1592,7 @@ After <code>goog.inherits</code> from the
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
<span class="hljs-keyword">new</span> Call(<span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Literal utility <span class="hljs-string">'extends'</span>), [<span class="hljs-property">@child</span>, <span class="hljs-property">@parent</span>]).compileToFragments o</pre></div></div>
|
||||
<span class="hljs-keyword">new</span> Call(<span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Literal utility <span class="hljs-string">'extends'</span>, o), [<span class="hljs-property">@child</span>, <span class="hljs-property">@parent</span>]).compileToFragments o</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1617,7 +1621,7 @@ an access into the object’s prototype.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Access = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Access</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Access = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Access</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@name</span>, tag)</span> -></span>
|
||||
<span class="hljs-property">@name</span>.asKey = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-property">@soak</span> = tag <span class="hljs-keyword">is</span> <span class="hljs-string">'soak'</span>
|
||||
|
@ -1661,7 +1665,7 @@ an access into the object’s prototype.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Index = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Index</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Index = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Index</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@index</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'index'</span>]
|
||||
|
@ -1700,7 +1704,7 @@ corresponding array of integers at runtime.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Range = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Range</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Range = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Range</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'from'</span>, <span class="hljs-string">'to'</span>]
|
||||
|
||||
|
@ -1866,7 +1870,7 @@ needed to iterate over the values in the range. Used by comprehensions.</p>
|
|||
cond = <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@fromVar</span>}</span> <= <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>"</span>
|
||||
body = <span class="hljs-string">"var <span class="hljs-subst">#{vars}</span>; <span class="hljs-subst">#{cond}</span> ? <span class="hljs-subst">#{i}</span> <<span class="hljs-subst">#{<span class="hljs-property">@equals</span>}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span> : <span class="hljs-subst">#{i}</span> ><span class="hljs-subst">#{<span class="hljs-property">@equals</span>}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>; <span class="hljs-subst">#{cond}</span> ? <span class="hljs-subst">#{i}</span>++ : <span class="hljs-subst">#{i}</span>--"</span>
|
||||
post = <span class="hljs-string">"{ <span class="hljs-subst">#{result}</span>.push(<span class="hljs-subst">#{i}</span>); }\n<span class="hljs-subst">#{idt}</span>return <span class="hljs-subst">#{result}</span>;\n<span class="hljs-subst">#{o.indent}</span>"</span>
|
||||
<span class="hljs-function"><span class="hljs-title">hasArgs</span> = <span class="hljs-params">(node)</span> -></span> node?.contains isLiteralArguments
|
||||
<span class="hljs-function"> <span class="hljs-title">hasArgs</span> = <span class="hljs-params">(node)</span> -></span> node?.contains isLiteralArguments
|
||||
args = <span class="hljs-string">', arguments'</span> <span class="hljs-keyword">if</span> hasArgs(<span class="hljs-property">@from</span>) <span class="hljs-keyword">or</span> hasArgs(<span class="hljs-property">@to</span>)
|
||||
[<span class="hljs-property">@makeCode</span> <span class="hljs-string">"(function() {<span class="hljs-subst">#{pre}</span>\n<span class="hljs-subst">#{idt}</span>for (<span class="hljs-subst">#{body}</span>)<span class="hljs-subst">#{post}</span>}).apply(this<span class="hljs-subst">#{args ? <span class="hljs-string">''</span>}</span>)"</span>]</pre></div></div>
|
||||
|
||||
|
@ -1898,7 +1902,7 @@ is the index of the beginning.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Slice = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Slice</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Slice = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Slice</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'range'</span>]
|
||||
|
||||
|
@ -1976,7 +1980,7 @@ is the index of the beginning.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Obj = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Obj</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Obj = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Obj</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(props, <span class="hljs-property">@generated</span> = <span class="hljs-literal">false</span>)</span> -></span>
|
||||
<span class="hljs-property">@objects</span> = <span class="hljs-property">@properties</span> = props <span class="hljs-keyword">or</span> []
|
||||
|
||||
|
@ -2044,7 +2048,7 @@ is the index of the beginning.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Arr = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Arr</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Arr = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Arr</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(objs)</span> -></span>
|
||||
<span class="hljs-property">@objects</span> = objs <span class="hljs-keyword">or</span> []
|
||||
|
||||
|
@ -2102,7 +2106,7 @@ list of prototype property assignments.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Class = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Class = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@variable</span>, <span class="hljs-property">@parent</span>, <span class="hljs-property">@body</span> = <span class="hljs-keyword">new</span> Block)</span> -></span>
|
||||
<span class="hljs-property">@boundFuncs</span> = []
|
||||
<span class="hljs-property">@body</span>.classBody = <span class="hljs-literal">yes</span>
|
||||
|
@ -2172,7 +2176,7 @@ constructor.</p>
|
|||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">addBoundFunctions</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> bvar <span class="hljs-keyword">in</span> <span class="hljs-property">@boundFuncs</span>
|
||||
lhs = (<span class="hljs-keyword">new</span> Value (<span class="hljs-keyword">new</span> Literal <span class="hljs-string">"this"</span>), [<span class="hljs-keyword">new</span> Access bvar]).compile o
|
||||
<span class="hljs-property">@ctor</span>.body.unshift <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{lhs}</span> = <span class="hljs-subst">#{utility <span class="hljs-string">'bind'</span>}</span>(<span class="hljs-subst">#{lhs}</span>, this)"</span>
|
||||
<span class="hljs-property">@ctor</span>.body.unshift <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{lhs}</span> = <span class="hljs-subst">#{utility <span class="hljs-string">'bind'</span>, o}</span>(<span class="hljs-subst">#{lhs}</span>, this)"</span>
|
||||
<span class="hljs-keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -2369,7 +2373,7 @@ property of an object — including within object literals.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Assign = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Assign</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Assign = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Assign</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@variable</span>, <span class="hljs-property">@value</span>, <span class="hljs-property">@context</span>, options)</span> -></span>
|
||||
<span class="hljs-property">@param</span> = options <span class="hljs-keyword">and</span> options.param
|
||||
<span class="hljs-property">@subpattern</span> = options <span class="hljs-keyword">and</span> options.subpattern
|
||||
|
@ -2558,7 +2562,7 @@ for details.</p>
|
|||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> expandedIdx <span class="hljs-keyword">and</span> obj <span class="hljs-keyword">instanceof</span> Splat
|
||||
name = obj.name.unwrap().value
|
||||
obj = obj.unwrap()
|
||||
val = <span class="hljs-string">"<span class="hljs-subst">#{olen}</span> <= <span class="hljs-subst">#{vvarText}</span>.length ? <span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span> }</span>.call(<span class="hljs-subst">#{vvarText}</span>, <span class="hljs-subst">#{i}</span>"</span>
|
||||
val = <span class="hljs-string">"<span class="hljs-subst">#{olen}</span> <= <span class="hljs-subst">#{vvarText}</span>.length ? <span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span>, o }</span>.call(<span class="hljs-subst">#{vvarText}</span>, <span class="hljs-subst">#{i}</span>"</span>
|
||||
<span class="hljs-keyword">if</span> rest = olen - i - <span class="hljs-number">1</span>
|
||||
ivar = o.scope.freeVariable <span class="hljs-string">'i'</span>
|
||||
val += <span class="hljs-string">", <span class="hljs-subst">#{ivar}</span> = <span class="hljs-subst">#{vvarText}</span>.length - <span class="hljs-subst">#{rest}</span>) : (<span class="hljs-subst">#{ivar}</span> = <span class="hljs-subst">#{i}</span>, [])"</span>
|
||||
|
@ -2715,11 +2719,13 @@ has no <em>children</em> — they’re within the inner scope.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Code = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Code</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Code = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Code</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(params, body, tag)</span> -></span>
|
||||
<span class="hljs-property">@params</span> = params <span class="hljs-keyword">or</span> []
|
||||
<span class="hljs-property">@body</span> = body <span class="hljs-keyword">or</span> <span class="hljs-keyword">new</span> Block
|
||||
<span class="hljs-property">@bound</span> = tag <span class="hljs-keyword">is</span> <span class="hljs-string">'boundfunc'</span>
|
||||
<span class="hljs-property">@isGenerator</span> = !!<span class="hljs-property">@body</span>.contains <span class="hljs-function"><span class="hljs-params">(node)</span> -></span>
|
||||
node <span class="hljs-keyword">instanceof</span> Op <span class="hljs-keyword">and</span> node.operator <span class="hljs-keyword">in</span> [<span class="hljs-string">'yield'</span>, <span class="hljs-string">'yield*'</span>]
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'params'</span>, <span class="hljs-string">'body'</span>]
|
||||
|
||||
|
@ -2781,9 +2787,8 @@ a closure.</p>
|
|||
<span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span> <span class="hljs-keyword">when</span> param <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Expansion
|
||||
o.scope.parameter param.asReference o
|
||||
<span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span> <span class="hljs-keyword">when</span> param.splat <span class="hljs-keyword">or</span> param <span class="hljs-keyword">instanceof</span> Expansion
|
||||
<span class="hljs-keyword">for</span> {<span class="hljs-attribute">name</span>: p} <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span> <span class="hljs-keyword">when</span> param <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Expansion
|
||||
<span class="hljs-keyword">if</span> p.<span class="hljs-keyword">this</span> <span class="hljs-keyword">then</span> p = p.properties[<span class="hljs-number">0</span>].name
|
||||
<span class="hljs-keyword">if</span> p.value <span class="hljs-keyword">then</span> o.scope.add p.value, <span class="hljs-string">'var'</span>, <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">for</span> p <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span> <span class="hljs-keyword">when</span> p <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Expansion <span class="hljs-keyword">and</span> p.name.value
|
||||
o.scope.add p.name.value, <span class="hljs-string">'var'</span>, <span class="hljs-literal">yes</span>
|
||||
splats = <span class="hljs-keyword">new</span> Assign <span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Arr(p.asReference o <span class="hljs-keyword">for</span> p <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span>)),
|
||||
<span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'arguments'</span>
|
||||
<span class="hljs-keyword">break</span>
|
||||
|
@ -2807,10 +2812,11 @@ a closure.</p>
|
|||
o.scope.parameter fragmentsToText params[i]
|
||||
uniqs = []
|
||||
<span class="hljs-property">@eachParamName</span> <span class="hljs-function"><span class="hljs-params">(name, node)</span> -></span>
|
||||
node.error <span class="hljs-string">"multiple parameters named '<span class="hljs-subst">#{name}</span>'"</span> <span class="hljs-keyword">if</span> name <span class="hljs-keyword">in</span> uniqs
|
||||
node.error <span class="hljs-string">"multiple parameters named <span class="hljs-subst">#{name}</span>"</span> <span class="hljs-keyword">if</span> name <span class="hljs-keyword">in</span> uniqs
|
||||
uniqs.push name
|
||||
<span class="hljs-property">@body</span>.makeReturn() <span class="hljs-keyword">unless</span> wasEmpty <span class="hljs-keyword">or</span> <span class="hljs-property">@noReturn</span>
|
||||
code = <span class="hljs-string">'function'</span>
|
||||
code += <span class="hljs-string">'*'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@isGenerator</span>
|
||||
code += <span class="hljs-string">' '</span> + <span class="hljs-property">@name</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@ctor</span>
|
||||
code += <span class="hljs-string">'('</span>
|
||||
answer = [<span class="hljs-property">@makeCode</span>(code)]
|
||||
|
@ -2872,7 +2878,7 @@ as well as be a splat, gathering up a group of parameters into an array.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Param = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Param</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Param = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Param</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@name</span>, <span class="hljs-property">@value</span>, <span class="hljs-property">@splat</span>)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> (name = <span class="hljs-property">@name</span>.unwrapAll().value) <span class="hljs-keyword">in</span> STRICT_PROSCRIBED
|
||||
<span class="hljs-property">@name</span>.error <span class="hljs-string">"parameter name \"<span class="hljs-subst">#{name}</span>\" is not allowed"</span>
|
||||
|
@ -2886,9 +2892,8 @@ as well as be a splat, gathering up a group of parameters into an array.</p>
|
|||
<span class="hljs-keyword">return</span> <span class="hljs-property">@reference</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@reference</span>
|
||||
node = <span class="hljs-property">@name</span>
|
||||
<span class="hljs-keyword">if</span> node.<span class="hljs-keyword">this</span>
|
||||
node = node.properties[<span class="hljs-number">0</span>].name
|
||||
<span class="hljs-keyword">if</span> node.value.reserved
|
||||
node = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable node.value
|
||||
name = <span class="hljs-string">"at_<span class="hljs-subst">#{node.properties[<span class="hljs-number">0</span>].name.value}</span>"</span>
|
||||
node = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable name
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> node.isComplex()
|
||||
node = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'arg'</span>
|
||||
node = <span class="hljs-keyword">new</span> Value node
|
||||
|
@ -2918,9 +2923,7 @@ to that name.</p>
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">eachName</span>: <span class="hljs-function"><span class="hljs-params">(iterator, name = <span class="hljs-property">@name</span>)</span>-></span>
|
||||
<span class="hljs-function"><span class="hljs-title">atParam</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
node = obj.properties[<span class="hljs-number">0</span>].name
|
||||
iterator node.value, node <span class="hljs-keyword">unless</span> node.value.reserved</pre></div></div>
|
||||
<span class="hljs-function"> <span class="hljs-title">atParam</span> = <span class="hljs-params">(obj)</span> -></span> iterator <span class="hljs-string">"@<span class="hljs-subst">#{obj.properties[<span class="hljs-number">0</span>].name.value}</span>"</span>, obj</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -3078,7 +3081,7 @@ or as part of a destructuring assignment.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Splat = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Splat</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Splat = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Splat</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'name'</span>]
|
||||
|
||||
|
@ -3117,12 +3120,12 @@ splats, to a proper array.</p>
|
|||
node = list[<span class="hljs-number">0</span>]
|
||||
fragments = node.compileToFragments o, LEVEL_LIST
|
||||
<span class="hljs-keyword">return</span> fragments <span class="hljs-keyword">if</span> apply
|
||||
<span class="hljs-keyword">return</span> [].concat node.makeCode(<span class="hljs-string">"<span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span> }</span>.call("</span>), fragments, node.makeCode(<span class="hljs-string">")"</span>)
|
||||
<span class="hljs-keyword">return</span> [].concat node.makeCode(<span class="hljs-string">"<span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span>, o }</span>.call("</span>), fragments, node.makeCode(<span class="hljs-string">")"</span>)
|
||||
args = list[index..]
|
||||
<span class="hljs-keyword">for</span> node, i <span class="hljs-keyword">in</span> args
|
||||
compiledNode = node.compileToFragments o, LEVEL_LIST
|
||||
args[i] = <span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Splat
|
||||
<span class="hljs-keyword">then</span> [].concat node.makeCode(<span class="hljs-string">"<span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span> }</span>.call("</span>), compiledNode, node.makeCode(<span class="hljs-string">")"</span>)
|
||||
<span class="hljs-keyword">then</span> [].concat node.makeCode(<span class="hljs-string">"<span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span>, o }</span>.call("</span>), compiledNode, node.makeCode(<span class="hljs-string">")"</span>)
|
||||
<span class="hljs-keyword">else</span> [].concat node.makeCode(<span class="hljs-string">"["</span>), compiledNode, node.makeCode(<span class="hljs-string">"]"</span>)
|
||||
<span class="hljs-keyword">if</span> index <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
node = list[<span class="hljs-number">0</span>]
|
||||
|
@ -3160,7 +3163,7 @@ parameter list.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Expansion = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Expansion</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Expansion = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Expansion</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
|
||||
<span class="hljs-attribute">isComplex</span>: NO
|
||||
|
||||
|
@ -3200,7 +3203,7 @@ flexibility or more speed than a comprehension can provide.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.While = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">While</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.While = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">While</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(condition, options)</span> -></span>
|
||||
<span class="hljs-property">@condition</span> = <span class="hljs-keyword">if</span> options?.invert <span class="hljs-keyword">then</span> condition.invert() <span class="hljs-keyword">else</span> condition
|
||||
<span class="hljs-property">@guard</span> = options?.guard
|
||||
|
@ -3290,7 +3293,7 @@ CoffeeScript operations into their JavaScript equivalents.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Op = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Op</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Op = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Op</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(op, first, second, flip )</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> In first, second <span class="hljs-keyword">if</span> op <span class="hljs-keyword">is</span> <span class="hljs-string">'in'</span>
|
||||
<span class="hljs-keyword">if</span> op <span class="hljs-keyword">is</span> <span class="hljs-string">'do'</span>
|
||||
|
@ -3320,7 +3323,8 @@ CoffeeScript operations into their JavaScript equivalents.</p>
|
|||
<div class="content"><div class='highlight'><pre> CONVERSIONS =
|
||||
<span class="hljs-string">'=='</span>: <span class="hljs-string">'==='</span>
|
||||
<span class="hljs-string">'!='</span>: <span class="hljs-string">'!=='</span>
|
||||
<span class="hljs-string">'of'</span>: <span class="hljs-string">'in'</span></pre></div></div>
|
||||
<span class="hljs-string">'of'</span>: <span class="hljs-string">'in'</span>
|
||||
<span class="hljs-string">'yieldfrom'</span>: <span class="hljs-string">'yield*'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -3343,11 +3347,15 @@ CoffeeScript operations into their JavaScript equivalents.</p>
|
|||
|
||||
<span class="hljs-attribute">isSimpleNumber</span>: NO
|
||||
|
||||
<span class="hljs-attribute">isYield</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'yield'</span>, <span class="hljs-string">'yield*'</span>]
|
||||
|
||||
<span class="hljs-attribute">isUnary</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-keyword">not</span> <span class="hljs-property">@second</span>
|
||||
|
||||
<span class="hljs-attribute">isComplex</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-keyword">not</span> (<span class="hljs-property">@isUnary</span>() <span class="hljs-keyword">and</span> <span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'+'</span>, <span class="hljs-string">'-'</span>]) <span class="hljs-keyword">or</span> <span class="hljs-property">@first</span>.isComplex()</pre></div></div>
|
||||
<span class="hljs-keyword">not</span> (<span class="hljs-property">@isUnary</span>() <span class="hljs-keyword">and</span> <span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'+'</span>, <span class="hljs-string">'-'</span>] <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.isSimpleNumber())</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -3434,6 +3442,7 @@ as the chained expression is wrapped.</p>
|
|||
<span class="hljs-property">@error</span> <span class="hljs-string">'delete operand may not be argument or var'</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'--'</span>, <span class="hljs-string">'++'</span>] <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.unwrapAll().value <span class="hljs-keyword">in</span> STRICT_PROSCRIBED
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"cannot increment/decrement \"<span class="hljs-subst">#{<span class="hljs-property">@first</span>.unwrapAll().value}</span>\""</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileYield</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@isYield</span>()
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileUnary</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@isUnary</span>()
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileChain</span> o <span class="hljs-keyword">if</span> isChain
|
||||
<span class="hljs-keyword">switch</span> <span class="hljs-property">@operator</span>
|
||||
|
@ -3523,6 +3532,19 @@ used sequentially. For example:</p>
|
|||
parts.reverse() <span class="hljs-keyword">if</span> <span class="hljs-property">@flip</span>
|
||||
<span class="hljs-property">@joinFragmentArrays</span> parts, <span class="hljs-string">''</span>
|
||||
|
||||
<span class="hljs-attribute">compileYield</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
parts = []
|
||||
op = <span class="hljs-property">@operator</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> o.scope.parent?
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">'yield statements must occur within a function generator.'</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-string">'expression'</span> <span class="hljs-keyword">in</span> Object.keys <span class="hljs-property">@first</span>
|
||||
parts.push <span class="hljs-property">@first</span>.expression.compileToFragments o, LEVEL_OP <span class="hljs-keyword">if</span> <span class="hljs-property">@first</span>.expression?
|
||||
<span class="hljs-keyword">else</span>
|
||||
parts.push [<span class="hljs-property">@makeCode</span> <span class="hljs-string">"(<span class="hljs-subst">#{op}</span> "</span>]
|
||||
parts.push <span class="hljs-property">@first</span>.compileToFragments o, LEVEL_OP
|
||||
parts.push [<span class="hljs-property">@makeCode</span> <span class="hljs-string">")"</span>]
|
||||
<span class="hljs-property">@joinFragmentArrays</span> parts, <span class="hljs-string">''</span>
|
||||
|
||||
<span class="hljs-attribute">compilePower</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -3547,7 +3569,7 @@ used sequentially. For example:</p>
|
|||
<span class="hljs-keyword">new</span> Call(floor, [div]).compileToFragments o
|
||||
|
||||
<span class="hljs-attribute">compileModulo</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
mod = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal utility <span class="hljs-string">'modulo'</span>
|
||||
mod = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal utility <span class="hljs-string">'modulo'</span>, o
|
||||
<span class="hljs-keyword">new</span> Call(mod, [<span class="hljs-property">@first</span>, <span class="hljs-property">@second</span>]).compileToFragments o
|
||||
|
||||
<span class="hljs-attribute">toString</span>: <span class="hljs-function"><span class="hljs-params">(idt)</span> -></span>
|
||||
|
@ -3566,7 +3588,7 @@ used sequentially. For example:</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.In = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">In</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.In = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">In</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@object</span>, <span class="hljs-property">@array</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'object'</span>, <span class="hljs-string">'array'</span>]
|
||||
|
@ -3606,7 +3628,7 @@ used sequentially. For example:</p>
|
|||
|
||||
<span class="hljs-attribute">compileLoopTest</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
[sub, ref] = <span class="hljs-property">@object</span>.cache o, LEVEL_LIST
|
||||
fragments = [].concat <span class="hljs-property">@makeCode</span>(utility(<span class="hljs-string">'indexOf'</span>) + <span class="hljs-string">".call("</span>), <span class="hljs-property">@array</span>.compileToFragments(o, LEVEL_LIST),
|
||||
fragments = [].concat <span class="hljs-property">@makeCode</span>(utility(<span class="hljs-string">'indexOf'</span>, o) + <span class="hljs-string">".call("</span>), <span class="hljs-property">@array</span>.compileToFragments(o, LEVEL_LIST),
|
||||
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">", "</span>), ref, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">") "</span> + <span class="hljs-keyword">if</span> <span class="hljs-property">@negated</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'< 0'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'>= 0'</span>)
|
||||
<span class="hljs-keyword">return</span> fragments <span class="hljs-keyword">if</span> fragmentsToText(sub) <span class="hljs-keyword">is</span> fragmentsToText(ref)
|
||||
fragments = sub.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">', '</span>), fragments
|
||||
|
@ -3641,7 +3663,7 @@ used sequentially. For example:</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Try = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Try</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Try = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Try</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@attempt</span>, <span class="hljs-property">@errorVariable</span>, <span class="hljs-property">@recovery</span>, <span class="hljs-property">@ensure</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'attempt'</span>, <span class="hljs-string">'recovery'</span>, <span class="hljs-string">'ensure'</span>]
|
||||
|
@ -3716,7 +3738,7 @@ is optional, the <em>catch</em> is not.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Throw = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Throw</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Throw = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Throw</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@expression</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'expression'</span>]
|
||||
|
@ -3770,7 +3792,7 @@ table.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Existence = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Existence</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Existence = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Existence</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@expression</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'expression'</span>]
|
||||
|
@ -3830,7 +3852,7 @@ parentheses, but no longer — you can put in as many as you please.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Parens = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Parens</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Parens = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Parens</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@body</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'body'</span>]
|
||||
|
@ -3879,7 +3901,7 @@ you can map and filter in a single pass.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.For = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">For</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">While</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.For = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">For</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">While</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(body, source)</span> -></span>
|
||||
{<span class="hljs-property">@source</span>, <span class="hljs-property">@guard</span>, <span class="hljs-property">@step</span>, <span class="hljs-property">@name</span>, <span class="hljs-property">@index</span>} = source
|
||||
<span class="hljs-property">@body</span> = Block.wrap [body]
|
||||
|
@ -3977,7 +3999,7 @@ some cannot.</p>
|
|||
varPart = <span class="hljs-string">"\n<span class="hljs-subst">#{idt1}</span><span class="hljs-subst">#{namePart}</span>;"</span> <span class="hljs-keyword">if</span> namePart
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@object</span>
|
||||
forPartFragments = [<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{kvar}</span> in <span class="hljs-subst">#{svar}</span>"</span>)]
|
||||
guardPart = <span class="hljs-string">"\n<span class="hljs-subst">#{idt1}</span>if (!<span class="hljs-subst">#{utility <span class="hljs-string">'hasProp'</span>}</span>.call(<span class="hljs-subst">#{svar}</span>, <span class="hljs-subst">#{kvar}</span>)) continue;"</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@own</span>
|
||||
guardPart = <span class="hljs-string">"\n<span class="hljs-subst">#{idt1}</span>if (!<span class="hljs-subst">#{utility <span class="hljs-string">'hasProp'</span>, o}</span>.call(<span class="hljs-subst">#{svar}</span>, <span class="hljs-subst">#{kvar}</span>)) continue;"</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@own</span>
|
||||
bodyFragments = body.compileToFragments merge(o, <span class="hljs-attribute">indent</span>: idt1), LEVEL_TOP
|
||||
<span class="hljs-keyword">if</span> bodyFragments <span class="hljs-keyword">and</span> (bodyFragments.length > <span class="hljs-number">0</span>)
|
||||
bodyFragments = [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>), bodyFragments, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>)
|
||||
|
@ -4031,7 +4053,7 @@ some cannot.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Switch = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Switch</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.Switch = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Switch</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@subject</span>, <span class="hljs-property">@cases</span>, <span class="hljs-property">@otherwise</span>)</span> -></span>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'subject'</span>, <span class="hljs-string">'cases'</span>, <span class="hljs-string">'otherwise'</span>]
|
||||
|
@ -4098,7 +4120,7 @@ because ternaries are already proper expressions, and don’t need conversion.</
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.If = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">If</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<div class="content"><div class='highlight'><pre>exports.If = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">If</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
|
||||
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(condition, <span class="hljs-property">@body</span>, options = {})</span> -></span>
|
||||
<span class="hljs-property">@condition</span> = <span class="hljs-keyword">if</span> options.type <span class="hljs-keyword">is</span> <span class="hljs-string">'unless'</span> <span class="hljs-keyword">then</span> condition.invert() <span class="hljs-keyword">else</span> condition
|
||||
<span class="hljs-property">@elseBody</span> = <span class="hljs-literal">null</span>
|
||||
|
@ -4264,10 +4286,10 @@ to the superclass for <code>super()</code> calls, and copies of any static prope
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">extends</span>:<span class="hljs-function"> -></span> <span class="hljs-string">"
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">extends</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span> <span class="hljs-string">"
|
||||
function(child, parent) {
|
||||
for (var key in parent) {
|
||||
if (<span class="hljs-subst">#{utility <span class="hljs-string">'hasProp'</span>}</span>.call(parent, key)) child[key] = parent[key];
|
||||
if (<span class="hljs-subst">#{utility <span class="hljs-string">'hasProp'</span>, o}</span>.call(parent, key)) child[key] = parent[key];
|
||||
}
|
||||
function ctor() {
|
||||
this.constructor = child;
|
||||
|
@ -4450,12 +4472,16 @@ IS_REGEX = <span class="hljs-regexp">/^\//</span></pre></div></div>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">utility</span> = <span class="hljs-params">(name)</span> -></span>
|
||||
ref = <span class="hljs-string">"__<span class="hljs-subst">#{name}</span>"</span>
|
||||
Scope.root.assign ref, UTILITIES[name]()
|
||||
ref
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">multident</span> = <span class="hljs-params">(code, tab)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">utility</span> = <span class="hljs-params">(name, o)</span> -></span>
|
||||
{root} = o.scope
|
||||
<span class="hljs-keyword">if</span> name <span class="hljs-keyword">of</span> root.utilities
|
||||
root.utilities[name]
|
||||
<span class="hljs-keyword">else</span>
|
||||
ref = root.freeVariable <span class="hljs-string">"_<span class="hljs-subst">#{name}</span>"</span>
|
||||
root.assign ref, UTILITIES[name] o
|
||||
root.utilities[name] = ref
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">multident</span> = <span class="hljs-params">(code, tab)</span> -></span>
|
||||
code = code.replace <span class="hljs-regexp">/\n/g</span>, <span class="hljs-string">'$&'</span> + tab
|
||||
code.replace <span class="hljs-regexp">/\s+$/</span>, <span class="hljs-string">''</span></pre></div></div>
|
||||
|
||||
|
@ -4480,11 +4506,11 @@ Examples: 0, -1, 1, 2e3, 2e-3, -0xfe, 0xfe</p>
|
|||
parseInt x, <span class="hljs-number">16</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
parseFloat x
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">isLiteralArguments</span> = <span class="hljs-params">(node)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">isLiteralArguments</span> = <span class="hljs-params">(node)</span> -></span>
|
||||
node <span class="hljs-keyword">instanceof</span> Literal <span class="hljs-keyword">and</span> node.value <span class="hljs-keyword">is</span> <span class="hljs-string">'arguments'</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> node.asKey
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">isLiteralThis</span> = <span class="hljs-params">(node)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">isLiteralThis</span> = <span class="hljs-params">(node)</span> -></span>
|
||||
(node <span class="hljs-keyword">instanceof</span> Literal <span class="hljs-keyword">and</span> node.value <span class="hljs-keyword">is</span> <span class="hljs-string">'this'</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> node.asKey) <span class="hljs-keyword">or</span>
|
||||
(node <span class="hljs-keyword">instanceof</span> Code <span class="hljs-keyword">and</span> node.bound) <span class="hljs-keyword">or</span>
|
||||
(node <span class="hljs-keyword">instanceof</span> Call <span class="hljs-keyword">and</span> node.isSuper)</pre></div></div>
|
||||
|
|
|
@ -138,7 +138,7 @@ option) list, and all subsequent arguments are left unparsed.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.OptionParser = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OptionParser</span></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.OptionParser = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OptionParser</span></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
|
|
@ -173,8 +173,8 @@ This is a horrible thing that should not be required.</p>
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">findExtension</span> = <span class="hljs-params">(filename)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">findExtension</span> = <span class="hljs-params">(filename)</span> -></span>
|
||||
extensions = path.basename(filename).split <span class="hljs-string">'.'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -210,7 +210,7 @@ This is a horrible thing that should not be required.</p>
|
|||
<span class="hljs-keyword">return</span> curExtension <span class="hljs-keyword">if</span> Module._extensions[curExtension]
|
||||
<span class="hljs-string">'.js'</span>
|
||||
|
||||
<span class="hljs-attribute">Module</span>::<span class="hljs-function"><span class="hljs-title">load</span> = <span class="hljs-params">(filename)</span> -></span>
|
||||
<span class="hljs-attribute">Module</span>::l<span class="hljs-function"><span class="hljs-title">oad</span> = <span class="hljs-params">(filename)</span> -></span>
|
||||
<span class="hljs-property">@filename</span> = filename
|
||||
<span class="hljs-property">@paths</span> = Module._nodeModulePaths path.dirname filename
|
||||
extension = findExtension filename
|
||||
|
@ -234,7 +234,7 @@ to fork both CoffeeScript files, and JavaScript files, directly.</p>
|
|||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> child_process
|
||||
{fork} = child_process
|
||||
binary = <span class="hljs-built_in">require</span>.resolve <span class="hljs-string">'../../bin/coffee'</span>
|
||||
child_process.<span class="hljs-function"><span class="hljs-title">fork</span> = <span class="hljs-params">(path, args, options)</span> -></span>
|
||||
child_process.f<span class="hljs-function"><span class="hljs-title">ork</span> = <span class="hljs-params">(path, args, options)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> helpers.isCoffee path
|
||||
<span class="hljs-keyword">unless</span> Array.isArray args
|
||||
options = args <span class="hljs-keyword">or</span> {}
|
||||
|
|
|
@ -188,11 +188,11 @@ parens. Unwrap all that.</p>
|
|||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Generate the AST of the clean input.</p>
|
||||
<p>Tokenize the clean input.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes input</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> tokens = CoffeeScript.tokens input</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -203,20 +203,13 @@ parens. Unwrap all that.</p>
|
|||
<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>
|
||||
<p>Collect referenced variable names just like in <code>CoffeeScript.compile</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = <span class="hljs-keyword">new</span> Block [
|
||||
<span class="hljs-keyword">new</span> Assign (<span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'_'</span>), ast, <span class="hljs-string">'='</span>
|
||||
]
|
||||
js = ast.compile <span class="hljs-attribute">bare</span>: <span class="hljs-literal">yes</span>, <span class="hljs-attribute">locals</span>: Object.keys(context)
|
||||
result = <span class="hljs-keyword">if</span> context <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
|
||||
vm.runInThisContext js, filename
|
||||
<span class="hljs-keyword">else</span>
|
||||
vm.runInContext js, context, filename
|
||||
cb <span class="hljs-literal">null</span>, result
|
||||
<span class="hljs-keyword">catch</span> err</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> referencedVars = (
|
||||
token[<span class="hljs-number">1</span>] <span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token.variable <span class="hljs-keyword">and</span> token[<span class="hljs-number">1</span>].charAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'_'</span>
|
||||
)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -227,15 +220,11 @@ parens. Unwrap all that.</p>
|
|||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>AST’s <code>compile</code> does not add source code information to syntax errors.</p>
|
||||
<p>Generate the AST of the tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> updateSyntaxError err, input
|
||||
cb err
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">addMultilineHandler</span> = <span class="hljs-params">(repl)</span> -></span>
|
||||
{rli, inputStream, outputStream} = repl</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes tokens</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -246,6 +235,49 @@ parens. Unwrap all that.</p>
|
|||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</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> ast = <span class="hljs-keyword">new</span> Block [
|
||||
<span class="hljs-keyword">new</span> Assign (<span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'_'</span>), ast, <span class="hljs-string">'='</span>
|
||||
]
|
||||
js = ast.compile {<span class="hljs-attribute">bare</span>: <span class="hljs-literal">yes</span>, <span class="hljs-attribute">locals</span>: Object.keys(context), referencedVars}
|
||||
result = <span class="hljs-keyword">if</span> context <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
|
||||
vm.runInThisContext js, filename
|
||||
<span class="hljs-keyword">else</span>
|
||||
vm.runInContext js, context, filename
|
||||
cb <span class="hljs-literal">null</span>, result
|
||||
<span class="hljs-keyword">catch</span> err</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>AST’s <code>compile</code> does not add source code information to syntax errors.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> updateSyntaxError err, input
|
||||
cb err
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">addMultilineHandler</span> = <span class="hljs-params">(repl)</span> -></span>
|
||||
{rli, inputStream, outputStream} = repl</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Node 0.11.12 changed API, prompt is now _prompt.</p>
|
||||
|
||||
</div>
|
||||
|
@ -261,11 +293,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Proxy node’s line listener</p>
|
||||
|
||||
|
@ -286,11 +318,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Handle Ctrl-v</p>
|
||||
|
||||
|
@ -303,11 +335,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>allow arbitrarily switching between modes any time before multiple lines are entered</p>
|
||||
|
||||
|
@ -322,11 +354,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>no-op unless the current line is empty</p>
|
||||
|
||||
|
@ -337,11 +369,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>eval, print, loop</p>
|
||||
|
||||
|
@ -356,11 +388,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>XXX: multiline hack</p>
|
||||
|
||||
|
@ -378,11 +410,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>Store and load command history from a file</p>
|
||||
|
||||
|
@ -395,11 +427,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>Get file info and at most maxSize of command history</p>
|
||||
|
||||
|
@ -411,11 +443,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>Read last <code>size</code> bytes from the file</p>
|
||||
|
||||
|
@ -428,11 +460,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>Set the history on the interpreter</p>
|
||||
|
||||
|
@ -443,11 +475,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>If the history file was truncated we should pop off a potential partial line</p>
|
||||
|
||||
|
@ -458,11 +490,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Shift off the final blank newline</p>
|
||||
|
||||
|
@ -480,11 +512,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>Save the latest command in the file</p>
|
||||
|
||||
|
@ -498,11 +530,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Add a command to show the history stack</p>
|
||||
|
||||
|
@ -513,17 +545,17 @@ parens. Unwrap all that.</p>
|
|||
<span class="hljs-attribute">action</span>:<span class="hljs-function"> -></span>
|
||||
repl.outputStream.write <span class="hljs-string">"<span class="hljs-subst">#{repl.rli.history[..].reverse().join <span class="hljs-string">'\n'</span>}</span>\n"</span>
|
||||
repl.displayPrompt()
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">getCommandId</span> = <span class="hljs-params">(repl, commandName)</span> -></span></pre></div></div>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">getCommandId</span> = <span class="hljs-params">(repl, commandName)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
<p>Node 0.11 changed API, a command such as ‘.help’ is now stored as ‘help’</p>
|
||||
|
||||
|
@ -532,9 +564,9 @@ parens. Unwrap all that.</p>
|
|||
<div class="content"><div class='highlight'><pre> commandsHaveLeadingDot = repl.commands[<span class="hljs-string">'.help'</span>]?
|
||||
<span class="hljs-keyword">if</span> commandsHaveLeadingDot <span class="hljs-keyword">then</span> <span class="hljs-string">".<span class="hljs-subst">#{commandName}</span>"</span> <span class="hljs-keyword">else</span> commandName
|
||||
|
||||
<span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> =
|
||||
<span class="hljs-built_in">module</span>.exports =
|
||||
<span class="hljs-attribute">start</span>: <span class="hljs-function"><span class="hljs-params">(opts = {})</span> -></span>
|
||||
[major, minor, build] = process.versions.node.split<span class="hljs-function"><span class="hljs-params">(<span class="hljs-string">'.'</span>)</span>.<span class="hljs-title">map</span> <span class="hljs-params">(n)</span> -></span> parseInt(n)
|
||||
[major, minor, build] = process.versions.node.split(<span class="hljs-string">'.'</span>).map <span class="hljs-function"><span class="hljs-params">(n)</span> -></span> parseInt(n)
|
||||
|
||||
<span class="hljs-keyword">if</span> major <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> minor < <span class="hljs-number">8</span>
|
||||
<span class="hljs-built_in">console</span>.warn <span class="hljs-string">"Node 0.8.0+ required for CoffeeScript REPL"</span>
|
||||
|
@ -551,11 +583,11 @@ parens. Unwrap all that.</p>
|
|||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
<p>Adapt help inherited from the node REPL</p>
|
||||
|
||||
|
|
|
@ -270,11 +270,11 @@ calls that close on the same line, just before their outdent.</p>
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">closeOpenCalls</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-function"><span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">')'</span>, <span class="hljs-string">'CALL_END'</span>] <span class="hljs-keyword">or</span>
|
||||
token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'OUTDENT'</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@tag</span>(i - <span class="hljs-number">1</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">')'</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-property">@tokens</span>[<span class="hljs-keyword">if</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'OUTDENT'</span> <span class="hljs-keyword">then</span> i - <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> i][<span class="hljs-number">0</span>] = <span class="hljs-string">'CALL_END'</span>
|
||||
|
||||
<span class="hljs-property">@scanTokens</span> <span class="hljs-function"><span class="hljs-params">(token, i)</span> -></span>
|
||||
|
@ -296,10 +296,10 @@ Match it with its paired close.</p>
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">closeOpenIndexes</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-function"><span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">']'</span>, <span class="hljs-string">'INDEX_END'</span>]
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
token[<span class="hljs-number">0</span>] = <span class="hljs-string">'INDEX_END'</span>
|
||||
|
||||
<span class="hljs-property">@scanTokens</span> <span class="hljs-function"><span class="hljs-params">(token, i)</span> -></span>
|
||||
|
@ -408,7 +408,7 @@ add them.</p>
|
|||
[tag] = token
|
||||
[prevTag] = prevToken = <span class="hljs-keyword">if</span> i > <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> tokens[i - <span class="hljs-number">1</span>] <span class="hljs-keyword">else</span> []
|
||||
[nextTag] = <span class="hljs-keyword">if</span> i < tokens.length - <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> tokens[i + <span class="hljs-number">1</span>] <span class="hljs-keyword">else</span> []
|
||||
<span class="hljs-function"><span class="hljs-title">stackTop</span> = -></span> stack[stack.length - <span class="hljs-number">1</span>]
|
||||
<span class="hljs-function"> <span class="hljs-title">stackTop</span> = -></span> stack[stack.length - <span class="hljs-number">1</span>]
|
||||
startIdx = i</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -425,7 +425,7 @@ and spliced, when returning for getting a new token.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-function"><span class="hljs-title">forward</span> = <span class="hljs-params">(n)</span> -></span> i - startIdx + n</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"> <span class="hljs-title">forward</span> = <span class="hljs-params">(n)</span> -></span> i - startIdx + n</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -440,9 +440,9 @@ and spliced, when returning for getting a new token.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-function"><span class="hljs-title">inImplicit</span> = -></span> stackTop()?[<span class="hljs-number">2</span>]?.ours
|
||||
<span class="hljs-function"><span class="hljs-title">inImplicitCall</span> = -></span> inImplicit() <span class="hljs-keyword">and</span> stackTop()?[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'('</span>
|
||||
<span class="hljs-function"><span class="hljs-title">inImplicitObject</span> = -></span> inImplicit() <span class="hljs-keyword">and</span> stackTop()?[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'{'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"> <span class="hljs-title">inImplicit</span> = -></span> stackTop()?[<span class="hljs-number">2</span>]?.ours
|
||||
<span class="hljs-function"> <span class="hljs-title">inImplicitCall</span> = -></span> inImplicit() <span class="hljs-keyword">and</span> stackTop()?[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'('</span>
|
||||
<span class="hljs-function"> <span class="hljs-title">inImplicitObject</span> = -></span> inImplicit() <span class="hljs-keyword">and</span> stackTop()?[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'{'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -458,26 +458,26 @@ class declaration or if-conditionals)</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-function"><span class="hljs-title">inImplicitControl</span> = -></span> inImplicit <span class="hljs-keyword">and</span> stackTop()?[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'CONTROL'</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">startImplicitCall</span> = <span class="hljs-params">(j)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"> <span class="hljs-title">inImplicitControl</span> = -></span> inImplicit <span class="hljs-keyword">and</span> stackTop()?[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'CONTROL'</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">startImplicitCall</span> = <span class="hljs-params">(j)</span> -></span>
|
||||
idx = j ? i
|
||||
stack.push [<span class="hljs-string">'('</span>, idx, <span class="hljs-attribute">ours</span>: <span class="hljs-literal">yes</span>]
|
||||
tokens.splice idx, <span class="hljs-number">0</span>, generate <span class="hljs-string">'CALL_START'</span>, <span class="hljs-string">'('</span>
|
||||
i += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> j?
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">endImplicitCall</span> = -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">endImplicitCall</span> = -></span>
|
||||
stack.pop()
|
||||
tokens.splice i, <span class="hljs-number">0</span>, generate <span class="hljs-string">'CALL_END'</span>, <span class="hljs-string">')'</span>
|
||||
tokens.splice i, <span class="hljs-number">0</span>, generate <span class="hljs-string">'CALL_END'</span>, <span class="hljs-string">')'</span>, [<span class="hljs-string">''</span>, <span class="hljs-string">'end of input'</span>, token[<span class="hljs-number">2</span>]]
|
||||
i += <span class="hljs-number">1</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">startImplicitObject</span> = <span class="hljs-params">(j, startsLine = <span class="hljs-literal">yes</span>)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">startImplicitObject</span> = <span class="hljs-params">(j, startsLine = <span class="hljs-literal">yes</span>)</span> -></span>
|
||||
idx = j ? i
|
||||
stack.push [<span class="hljs-string">'{'</span>, idx, <span class="hljs-attribute">sameLine</span>: <span class="hljs-literal">yes</span>, <span class="hljs-attribute">startsLine</span>: startsLine, <span class="hljs-attribute">ours</span>: <span class="hljs-literal">yes</span>]
|
||||
tokens.splice idx, <span class="hljs-number">0</span>, generate <span class="hljs-string">'{'</span>, generate(<span class="hljs-keyword">new</span> String(<span class="hljs-string">'{'</span>)), token
|
||||
i += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> j?
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">endImplicitObject</span> = <span class="hljs-params">(j)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">endImplicitObject</span> = <span class="hljs-params">(j)</span> -></span>
|
||||
j = j ? i
|
||||
stack.pop()
|
||||
tokens.splice j, <span class="hljs-number">0</span>, generate <span class="hljs-string">'}'</span>, <span class="hljs-string">'}'</span>, token
|
||||
|
@ -580,7 +580,7 @@ f a, f() b, f? c, h[0] d etc.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (tag <span class="hljs-keyword">in</span> IMPLICIT_FUNC <span class="hljs-keyword">and</span> token.spaced <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> token.stringEnd <span class="hljs-keyword">or</span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (tag <span class="hljs-keyword">in</span> IMPLICIT_FUNC <span class="hljs-keyword">and</span> token.spaced <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> token.stringEnd <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> token.regexEnd <span class="hljs-keyword">or</span>
|
||||
tag <span class="hljs-keyword">is</span> <span class="hljs-string">'?'</span> <span class="hljs-keyword">and</span> i > <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> tokens[i - <span class="hljs-number">1</span>].spaced) <span class="hljs-keyword">and</span>
|
||||
(nextTag <span class="hljs-keyword">in</span> IMPLICIT_CALL <span class="hljs-keyword">or</span>
|
||||
nextTag <span class="hljs-keyword">in</span> IMPLICIT_UNSPACED_CALL <span class="hljs-keyword">and</span>
|
||||
|
@ -619,7 +619,8 @@ that creates grammatical ambiguities.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> tag <span class="hljs-keyword">in</span> IMPLICIT_FUNC <span class="hljs-keyword">and</span> <span class="hljs-property">@matchTags</span>(i + <span class="hljs-number">1</span>, <span class="hljs-string">'INDENT'</span>, <span class="hljs-literal">null</span>, <span class="hljs-string">':'</span>) <span class="hljs-keyword">and</span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> tag <span class="hljs-keyword">in</span> IMPLICIT_FUNC <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> token.stringEnd <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> token.regexEnd <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-property">@matchTags</span>(i + <span class="hljs-number">1</span>, <span class="hljs-string">'INDENT'</span>, <span class="hljs-literal">null</span>, <span class="hljs-string">':'</span>) <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-keyword">not</span> <span class="hljs-property">@findTagsBackwards</span>(i, [<span class="hljs-string">'CLASS'</span>, <span class="hljs-string">'EXTENDS'</span>, <span class="hljs-string">'IF'</span>, <span class="hljs-string">'CATCH'</span>,
|
||||
<span class="hljs-string">'SWITCH'</span>, <span class="hljs-string">'LEADING_WHEN'</span>, <span class="hljs-string">'FOR'</span>, <span class="hljs-string">'WHILE'</span>, <span class="hljs-string">'UNTIL'</span>])
|
||||
startImplicitCall i + <span class="hljs-number">1</span>
|
||||
|
@ -707,7 +708,7 @@ that creates grammatical ambiguities.</p>
|
|||
</div>
|
||||
<p>End implicit calls when chaining method calls
|
||||
like e.g.:</p>
|
||||
<pre><code>f<span class="hljs-function"> -></span>
|
||||
<pre><code>f <span class="hljs-function">-></span>
|
||||
a
|
||||
.g b,<span class="hljs-function"> -></span>
|
||||
c
|
||||
|
@ -878,15 +879,15 @@ blocks are added.</p>
|
|||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">normalizeLines</span>:<span class="hljs-function"> -></span>
|
||||
starter = indent = outdent = <span class="hljs-literal">null</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
token[<span class="hljs-number">1</span>] <span class="hljs-keyword">isnt</span> <span class="hljs-string">';'</span> <span class="hljs-keyword">and</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> SINGLE_CLOSERS <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-keyword">not</span> (token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'TERMINATOR'</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@tag</span>(i + <span class="hljs-number">1</span>) <span class="hljs-keyword">in</span> EXPRESSION_CLOSE) <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-keyword">not</span> (token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'ELSE'</span> <span class="hljs-keyword">and</span> starter <span class="hljs-keyword">isnt</span> <span class="hljs-string">'THEN'</span>) <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-keyword">not</span> (token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">'CATCH'</span>, <span class="hljs-string">'FINALLY'</span>] <span class="hljs-keyword">and</span> starter <span class="hljs-keyword">in</span> [<span class="hljs-string">'->'</span>, <span class="hljs-string">'=>'</span>]) <span class="hljs-keyword">or</span>
|
||||
token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> CALL_CLOSERS <span class="hljs-keyword">and</span> <span class="hljs-property">@tokens</span>[i - <span class="hljs-number">1</span>].newLine
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-property">@tokens</span>.splice (<span class="hljs-keyword">if</span> <span class="hljs-property">@tag</span>(i - <span class="hljs-number">1</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">','</span> <span class="hljs-keyword">then</span> i - <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> i), <span class="hljs-number">0</span>, outdent
|
||||
|
||||
<span class="hljs-property">@scanTokens</span> <span class="hljs-function"><span class="hljs-params">(token, i, tokens)</span> -></span>
|
||||
|
@ -930,13 +931,13 @@ different precedence.</p>
|
|||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">tagPostfixConditionals</span>:<span class="hljs-function"> -></span>
|
||||
|
||||
original = <span class="hljs-literal">null</span>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">condition</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
[tag] = token
|
||||
[prevTag] = <span class="hljs-property">@tokens</span>[i - <span class="hljs-number">1</span>]
|
||||
tag <span class="hljs-keyword">is</span> <span class="hljs-string">'TERMINATOR'</span> <span class="hljs-keyword">or</span> (tag <span class="hljs-keyword">is</span> <span class="hljs-string">'INDENT'</span> <span class="hljs-keyword">and</span> prevTag <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> SINGLE_LINERS)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">action</span> = <span class="hljs-params">(token, i)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">isnt</span> <span class="hljs-string">'INDENT'</span> <span class="hljs-keyword">or</span> (token.generated <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> token.fromThen)
|
||||
original[<span class="hljs-number">0</span>] = <span class="hljs-string">'POST_'</span> + original[<span class="hljs-number">0</span>]
|
||||
|
||||
|
@ -1048,7 +1049,7 @@ look things up from either end.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.INVERSES = INVERSES = {}</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>exports.INVERSES = INVERSES = {}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1115,7 +1116,7 @@ EXPRESSION_END = []
|
|||
|
||||
<div class="content"><div class='highlight'><pre>IMPLICIT_CALL = [
|
||||
<span class="hljs-string">'IDENTIFIER'</span>, <span class="hljs-string">'NUMBER'</span>, <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'JS'</span>, <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">'NEW'</span>, <span class="hljs-string">'PARAM_START'</span>, <span class="hljs-string">'CLASS'</span>
|
||||
<span class="hljs-string">'IF'</span>, <span class="hljs-string">'TRY'</span>, <span class="hljs-string">'SWITCH'</span>, <span class="hljs-string">'THIS'</span>, <span class="hljs-string">'BOOL'</span>, <span class="hljs-string">'NULL'</span>, <span class="hljs-string">'UNDEFINED'</span>, <span class="hljs-string">'UNARY'</span>,
|
||||
<span class="hljs-string">'IF'</span>, <span class="hljs-string">'TRY'</span>, <span class="hljs-string">'SWITCH'</span>, <span class="hljs-string">'THIS'</span>, <span class="hljs-string">'BOOL'</span>, <span class="hljs-string">'NULL'</span>, <span class="hljs-string">'UNDEFINED'</span>, <span class="hljs-string">'UNARY'</span>, <span class="hljs-string">'YIELD'</span>
|
||||
<span class="hljs-string">'UNARY_MATH'</span>, <span class="hljs-string">'SUPER'</span>, <span class="hljs-string">'THROW'</span>, <span class="hljs-string">'@'</span>, <span class="hljs-string">'->'</span>, <span class="hljs-string">'=>'</span>, <span class="hljs-string">'['</span>, <span class="hljs-string">'('</span>, <span class="hljs-string">'{'</span>, <span class="hljs-string">'--'</span>, <span class="hljs-string">'++'</span>
|
||||
]
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ with external scopes.</p>
|
|||
|
||||
<div class="content"><div class='highlight'><pre>{extend, last} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
|
||||
<span class="hljs-built_in">exports</span>.Scope = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Scope</span></span></pre></div></div>
|
||||
exports.Scope = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Scope</span></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -138,11 +138,18 @@ with external scopes.</p>
|
|||
<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>
|
||||
<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, a reference to the function that
|
||||
it belongs to, and a list of variables referenced in the source code
|
||||
and therefore should be avoided when generating variables.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-property">@root</span>: <span class="hljs-literal">null</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@parent</span>, <span class="hljs-property">@expressions</span>, <span class="hljs-property">@method</span>, <span class="hljs-property">@referencedVars</span>)</span> -></span>
|
||||
<span class="hljs-property">@variables</span> = [{<span class="hljs-attribute">name</span>: <span class="hljs-string">'arguments'</span>, <span class="hljs-attribute">type</span>: <span class="hljs-string">'arguments'</span>}]
|
||||
<span class="hljs-property">@positions</span> = {}
|
||||
<span class="hljs-property">@utilities</span> = {} <span class="hljs-keyword">unless</span> <span class="hljs-property">@parent</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -153,17 +160,11 @@ with external scopes.</p>
|
|||
<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>
|
||||
<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="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@parent</span>, <span class="hljs-property">@expressions</span>, <span class="hljs-property">@method</span>)</span> -></span>
|
||||
<span class="hljs-property">@variables</span> = [{<span class="hljs-attribute">name</span>: <span class="hljs-string">'arguments'</span>, <span class="hljs-attribute">type</span>: <span class="hljs-string">'arguments'</span>}]
|
||||
<span class="hljs-property">@positions</span> = {}
|
||||
Scope.root = <span class="hljs-keyword">this</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@parent</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-property">@root</span> = <span class="hljs-property">@parent</span>?.root ? <span class="hljs-keyword">this</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -312,7 +313,10 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
|||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">freeVariable</span>: <span class="hljs-function"><span class="hljs-params">(name, reserve=<span class="hljs-literal">true</span>)</span> -></span>
|
||||
index = <span class="hljs-number">0</span>
|
||||
index++ <span class="hljs-keyword">while</span> <span class="hljs-property">@check</span>((temp = <span class="hljs-property">@temporary</span> name, index))
|
||||
<span class="hljs-keyword">loop</span>
|
||||
temp = <span class="hljs-property">@temporary</span> name, index
|
||||
<span class="hljs-keyword">break</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@check</span>(temp) <span class="hljs-keyword">or</span> temp <span class="hljs-keyword">in</span> <span class="hljs-property">@root</span>.referencedVars
|
||||
index++
|
||||
<span class="hljs-property">@add</span> temp, <span class="hljs-string">'var'</span>, <span class="hljs-literal">yes</span> <span class="hljs-keyword">if</span> reserve
|
||||
temp</pre></div></div>
|
||||
|
||||
|
|
|
@ -513,7 +513,7 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> = SourceMap</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">module</span>.exports = SourceMap</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ nativeKeys = Object.keys</pre></div></div>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span>(<span class="hljs-built_in">exports</span>) != <span class="hljs-string">'undefined'</span> <span class="hljs-keyword">then</span> <span class="hljs-built_in">exports</span>._ = _</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span>(exports) != <span class="hljs-string">'undefined'</span> <span class="hljs-keyword">then</span> exports._ = _</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -285,7 +285,7 @@ Handles objects implementing <strong>forEach</strong>, arrays, and raw objects.<
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">each</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.e<span class="hljs-function"><span class="hljs-title">ach</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
<span class="hljs-keyword">if</span> nativeForEach <span class="hljs-keyword">and</span> obj.forEach <span class="hljs-keyword">is</span> nativeForEach
|
||||
obj.forEach iterator, context
|
||||
|
@ -311,7 +311,7 @@ Handles objects implementing <strong>forEach</strong>, arrays, and raw objects.<
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">map</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.m<span class="hljs-function"><span class="hljs-title">ap</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> obj.map(iterator, context) <span class="hljs-keyword">if</span> nativeMap <span class="hljs-keyword">and</span> obj.map <span class="hljs-keyword">is</span> nativeMap
|
||||
results = []
|
||||
_.each obj, <span class="hljs-function"><span class="hljs-params">(value, index, list)</span> -></span>
|
||||
|
@ -332,7 +332,7 @@ Handles objects implementing <strong>forEach</strong>, arrays, and raw objects.<
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">reduce</span> = <span class="hljs-params">(obj, iterator, memo, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.r<span class="hljs-function"><span class="hljs-title">educe</span> = <span class="hljs-params">(obj, iterator, memo, context)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> nativeReduce <span class="hljs-keyword">and</span> obj.reduce <span class="hljs-keyword">is</span> nativeReduce
|
||||
iterator = _.bind iterator, context <span class="hljs-keyword">if</span> context
|
||||
<span class="hljs-keyword">return</span> obj.reduce iterator, memo
|
||||
|
@ -354,7 +354,7 @@ JavaScript 1.8’s version of <strong>reduceRight</strong>, if available.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">reduceRight</span> = <span class="hljs-params">(obj, iterator, memo, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.r<span class="hljs-function"><span class="hljs-title">educeRight</span> = <span class="hljs-params">(obj, iterator, memo, context)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> nativeReduceRight <span class="hljs-keyword">and</span> obj.reduceRight <span class="hljs-keyword">is</span> nativeReduceRight
|
||||
iterator = _.bind iterator, context <span class="hljs-keyword">if</span> context
|
||||
<span class="hljs-keyword">return</span> obj.reduceRight iterator, memo
|
||||
|
@ -374,7 +374,7 @@ JavaScript 1.8’s version of <strong>reduceRight</strong>, if available.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">detect</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.d<span class="hljs-function"><span class="hljs-title">etect</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
result = <span class="hljs-literal">null</span>
|
||||
_.each obj, <span class="hljs-function"><span class="hljs-params">(value, index, list)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> iterator.call context, value, index, list
|
||||
|
@ -396,7 +396,7 @@ JavaScript 1.8’s version of <strong>reduceRight</strong>, if available.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">filter</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.f<span class="hljs-function"><span class="hljs-title">ilter</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> obj.filter iterator, context <span class="hljs-keyword">if</span> nativeFilter <span class="hljs-keyword">and</span> obj.filter <span class="hljs-keyword">is</span> nativeFilter
|
||||
results = []
|
||||
_.each obj, <span class="hljs-function"><span class="hljs-params">(value, index, list)</span> -></span>
|
||||
|
@ -416,7 +416,7 @@ JavaScript 1.8’s version of <strong>reduceRight</strong>, if available.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">reject</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.r<span class="hljs-function"><span class="hljs-title">eject</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
results = []
|
||||
_.each obj, <span class="hljs-function"><span class="hljs-params">(value, index, list)</span> -></span>
|
||||
results.push value <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> iterator.call context, value, index, list
|
||||
|
@ -436,7 +436,7 @@ JavaScript 1.6’s <strong>every</strong>, if it is present.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">every</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.e<span class="hljs-function"><span class="hljs-title">very</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
iterator ||= _.identity
|
||||
<span class="hljs-keyword">return</span> obj.every iterator, context <span class="hljs-keyword">if</span> nativeEvery <span class="hljs-keyword">and</span> obj.every <span class="hljs-keyword">is</span> nativeEvery
|
||||
result = <span class="hljs-literal">true</span>
|
||||
|
@ -458,7 +458,7 @@ JavaScript 1.6’s <strong>some</strong>, if it exists.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">some</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.s<span class="hljs-function"><span class="hljs-title">ome</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
iterator ||= _.identity
|
||||
<span class="hljs-keyword">return</span> obj.some iterator, context <span class="hljs-keyword">if</span> nativeSome <span class="hljs-keyword">and</span> obj.some <span class="hljs-keyword">is</span> nativeSome
|
||||
result = <span class="hljs-literal">false</span>
|
||||
|
@ -480,7 +480,7 @@ based on <code>===</code>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">include</span> = <span class="hljs-params">(obj, target)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">nclude</span> = <span class="hljs-params">(obj, target)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> _.indexOf(obj, target) <span class="hljs-keyword">isnt</span> -<span class="hljs-number">1</span> <span class="hljs-keyword">if</span> nativeIndexOf <span class="hljs-keyword">and</span> obj.indexOf <span class="hljs-keyword">is</span> nativeIndexOf
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">for</span> own key, val <span class="hljs-keyword">of</span> obj <span class="hljs-keyword">when</span> val <span class="hljs-keyword">is</span> target
|
||||
<span class="hljs-literal">false</span></pre></div></div>
|
||||
|
@ -498,7 +498,7 @@ based on <code>===</code>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">invoke</span> = <span class="hljs-params">(obj, method)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">nvoke</span> = <span class="hljs-params">(obj, method)</span> -></span>
|
||||
args = _.rest arguments, <span class="hljs-number">2</span>
|
||||
(<span class="hljs-keyword">if</span> method <span class="hljs-keyword">then</span> val[method] <span class="hljs-keyword">else</span> val).apply(val, args) <span class="hljs-keyword">for</span> val <span class="hljs-keyword">in</span> obj</pre></div></div>
|
||||
|
||||
|
@ -515,11 +515,8 @@ based on <code>===</code>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">pluck</span> = <span class="hljs-params">(obj, key)</span> -></span>
|
||||
_.map<span class="hljs-function"><span class="hljs-params">(obj, (val) -> val[key])</span>
|
||||
|
||||
|
||||
</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.p<span class="hljs-function"><span class="hljs-title">luck</span> = <span class="hljs-params">(obj, key)</span> -></span>
|
||||
_.map(obj, <span class="hljs-function"><span class="hljs-params">(val)</span> -></span> val[key])</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -534,7 +531,7 @@ based on <code>===</code>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">max</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.m<span class="hljs-function"><span class="hljs-title">ax</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> Math.max.apply(Math, obj) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> iterator <span class="hljs-keyword">and</span> _.isArray(obj)
|
||||
result = <span class="hljs-attribute">computed</span>: -Infinity
|
||||
_.each obj, <span class="hljs-function"><span class="hljs-params">(value, index, list)</span> -></span>
|
||||
|
@ -555,7 +552,7 @@ based on <code>===</code>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">min</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.m<span class="hljs-function"><span class="hljs-title">in</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> Math.min.apply(Math, obj) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> iterator <span class="hljs-keyword">and</span> _.isArray(obj)
|
||||
result = <span class="hljs-attribute">computed</span>: Infinity
|
||||
_.each obj, <span class="hljs-function"><span class="hljs-params">(value, index, list)</span> -></span>
|
||||
|
@ -576,16 +573,13 @@ based on <code>===</code>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">sortBy</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
_.pluck<span class="hljs-function"><span class="hljs-params">(((_.map obj, (value, index, list) ->
|
||||
<div class="content"><div class='highlight'><pre>_.s<span class="hljs-function"><span class="hljs-title">ortBy</span> = <span class="hljs-params">(obj, iterator, context)</span> -></span>
|
||||
_.pluck(<span class="hljs-function">(<span class="hljs-params">(_.map obj, (value, index, list) ->
|
||||
{value: value, criteria: iterator.call(context, value, index, list)}
|
||||
).sort((left, right) ->
|
||||
)</span>.<span class="hljs-title">sort</span>(<span class="hljs-params">(left, right)</span> -></span>
|
||||
a = left.criteria; b = right.criteria
|
||||
<span class="hljs-keyword">if</span> a < b <span class="hljs-keyword">then</span> -<span class="hljs-number">1</span> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> a > b <span class="hljs-keyword">then</span> <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> <span class="hljs-number">0</span>
|
||||
)), <span class="hljs-string">'value'</span>)</span>
|
||||
|
||||
|
||||
</span></pre></div></div>
|
||||
)), <span class="hljs-string">'value'</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -601,7 +595,7 @@ be inserted so as to maintain order. Uses binary search.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">sortedIndex</span> = <span class="hljs-params">(array, obj, iterator)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.s<span class="hljs-function"><span class="hljs-title">ortedIndex</span> = <span class="hljs-params">(array, obj, iterator)</span> -></span>
|
||||
iterator ||= _.identity
|
||||
low = <span class="hljs-number">0</span>
|
||||
high = array.length
|
||||
|
@ -623,7 +617,7 @@ be inserted so as to maintain order. Uses binary search.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">toArray</span> = <span class="hljs-params">(iterable)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.t<span class="hljs-function"><span class="hljs-title">oArray</span> = <span class="hljs-params">(iterable)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> [] <span class="hljs-keyword">if</span> (!iterable)
|
||||
<span class="hljs-keyword">return</span> iterable.toArray() <span class="hljs-keyword">if</span> (iterable.toArray)
|
||||
<span class="hljs-keyword">return</span> iterable <span class="hljs-keyword">if</span> (_.isArray(iterable))
|
||||
|
@ -643,7 +637,7 @@ be inserted so as to maintain order. Uses binary search.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">size</span> = <span class="hljs-params">(obj)</span> -></span> _.toArray(obj).length</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.s<span class="hljs-function"><span class="hljs-title">ize</span> = <span class="hljs-params">(obj)</span> -></span> _.toArray(obj).length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -685,7 +679,7 @@ with <strong>map</strong>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">first</span> = <span class="hljs-params">(array, n, guard)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.f<span class="hljs-function"><span class="hljs-title">irst</span> = <span class="hljs-params">(array, n, guard)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> n <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> guard <span class="hljs-keyword">then</span> slice.call(array, <span class="hljs-number">0</span>, n) <span class="hljs-keyword">else</span> array[<span class="hljs-number">0</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -704,7 +698,7 @@ check allows it to work with <strong>map</strong>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">rest</span> = <span class="hljs-params">(array, index, guard)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.r<span class="hljs-function"><span class="hljs-title">est</span> = <span class="hljs-params">(array, index, guard)</span> -></span>
|
||||
slice.call(array, <span class="hljs-keyword">if</span> _.isUndefined(index) <span class="hljs-keyword">or</span> guard <span class="hljs-keyword">then</span> <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> index)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -720,7 +714,7 @@ check allows it to work with <strong>map</strong>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">last</span> = <span class="hljs-params">(array)</span> -></span> array[array.length - <span class="hljs-number">1</span>]</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.l<span class="hljs-function"><span class="hljs-title">ast</span> = <span class="hljs-params">(array)</span> -></span> array[array.length - <span class="hljs-number">1</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -735,7 +729,7 @@ check allows it to work with <strong>map</strong>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">compact</span> = <span class="hljs-params">(array)</span> -></span> item <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> array <span class="hljs-keyword">when</span> item</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.c<span class="hljs-function"><span class="hljs-title">ompact</span> = <span class="hljs-params">(array)</span> -></span> item <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> array <span class="hljs-keyword">when</span> item</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -750,7 +744,7 @@ check allows it to work with <strong>map</strong>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">flatten</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.f<span class="hljs-function"><span class="hljs-title">latten</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
_.reduce array, <span class="hljs-function"><span class="hljs-params">(memo, value)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> memo.concat(_.flatten(value)) <span class="hljs-keyword">if</span> _.isArray value
|
||||
memo.push value
|
||||
|
@ -770,7 +764,7 @@ check allows it to work with <strong>map</strong>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">without</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.w<span class="hljs-function"><span class="hljs-title">ithout</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
values = _.rest arguments
|
||||
val <span class="hljs-keyword">for</span> val <span class="hljs-keyword">in</span> _.toArray(array) <span class="hljs-keyword">when</span> <span class="hljs-keyword">not</span> _.include values, val</pre></div></div>
|
||||
|
||||
|
@ -788,7 +782,7 @@ been sorted, you have the option of using a faster algorithm.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">uniq</span> = <span class="hljs-params">(array, isSorted)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.u<span class="hljs-function"><span class="hljs-title">niq</span> = <span class="hljs-params">(array, isSorted)</span> -></span>
|
||||
memo = []
|
||||
<span class="hljs-keyword">for</span> el, i <span class="hljs-keyword">in</span> _.toArray array
|
||||
memo.push el <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> || (<span class="hljs-keyword">if</span> isSorted <span class="hljs-keyword">is</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">then</span> _.last(memo) <span class="hljs-keyword">isnt</span> el <span class="hljs-keyword">else</span> <span class="hljs-keyword">not</span> _.include(memo, el))
|
||||
|
@ -808,9 +802,9 @@ passed-in arrays.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">intersect</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">ntersect</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
rest = _.rest arguments
|
||||
_.select _.uniq<span class="hljs-function"><span class="hljs-params">(array)</span>, <span class="hljs-params">(item)</span> -></span>
|
||||
_.select _.uniq(array), <span class="hljs-function"><span class="hljs-params">(item)</span> -></span>
|
||||
_.all rest, <span class="hljs-function"><span class="hljs-params">(other)</span> -></span>
|
||||
_.indexOf(other, item) >= <span class="hljs-number">0</span></pre></div></div>
|
||||
|
||||
|
@ -828,7 +822,7 @@ an index go together.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">zip</span> = -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.z<span class="hljs-function"><span class="hljs-title">ip</span> = -></span>
|
||||
length = _.max _.pluck arguments, <span class="hljs-string">'length'</span>
|
||||
results = <span class="hljs-keyword">new</span> Array length
|
||||
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> [<span class="hljs-number">0.</span>..length]
|
||||
|
@ -850,7 +844,7 @@ item in an array, or -1 if the item is not included in the array.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">indexOf</span> = <span class="hljs-params">(array, item)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">ndexOf</span> = <span class="hljs-params">(array, item)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> array.indexOf item <span class="hljs-keyword">if</span> nativeIndexOf <span class="hljs-keyword">and</span> array.indexOf <span class="hljs-keyword">is</span> nativeIndexOf
|
||||
i = <span class="hljs-number">0</span>; l = array.length
|
||||
<span class="hljs-keyword">while</span> l - i
|
||||
|
@ -871,7 +865,7 @@ if possible.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">lastIndexOf</span> = <span class="hljs-params">(array, item)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.l<span class="hljs-function"><span class="hljs-title">astIndexOf</span> = <span class="hljs-params">(array, item)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> array.lastIndexOf(item) <span class="hljs-keyword">if</span> nativeLastIndexOf <span class="hljs-keyword">and</span> array.lastIndexOf <span class="hljs-keyword">is</span> nativeLastIndexOf
|
||||
i = array.length
|
||||
<span class="hljs-keyword">while</span> i
|
||||
|
@ -892,7 +886,7 @@ if possible.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">range</span> = <span class="hljs-params">(start, stop, step)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.r<span class="hljs-function"><span class="hljs-title">ange</span> = <span class="hljs-params">(start, stop, step)</span> -></span>
|
||||
a = arguments
|
||||
solo = a.length <= <span class="hljs-number">1</span>
|
||||
i = start = <span class="hljs-keyword">if</span> solo <span class="hljs-keyword">then</span> <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> a[<span class="hljs-number">0</span>]
|
||||
|
@ -947,9 +941,9 @@ optionally). Binding with arguments is also known as <strong>curry</strong>.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">bind</span> = <span class="hljs-params">(func, obj)</span> -></span>
|
||||
args = _.rest arguments, <span class="hljs-number">2</span><span class="hljs-function">
|
||||
-></span> func.apply obj <span class="hljs-keyword">or</span> root, args.concat arguments</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.b<span class="hljs-function"><span class="hljs-title">ind</span> = <span class="hljs-params">(func, obj)</span> -></span>
|
||||
args = _.rest arguments, <span class="hljs-number">2</span>
|
||||
<span class="hljs-function"> -></span> func.apply obj <span class="hljs-keyword">or</span> root, args.concat arguments</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -965,7 +959,7 @@ all callbacks defined on an object belong to it.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">bindAll</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.b<span class="hljs-function"><span class="hljs-title">indAll</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
funcs = <span class="hljs-keyword">if</span> arguments.length > <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> _.rest(arguments) <span class="hljs-keyword">else</span> _.functions(obj)
|
||||
_.each funcs, <span class="hljs-function"><span class="hljs-params">(f)</span> -></span> obj[f] = _.bind obj[f], obj
|
||||
obj</pre></div></div>
|
||||
|
@ -984,7 +978,7 @@ it with the arguments supplied.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">delay</span> = <span class="hljs-params">(func, wait)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.d<span class="hljs-function"><span class="hljs-title">elay</span> = <span class="hljs-params">(func, wait)</span> -></span>
|
||||
args = _.rest arguments, <span class="hljs-number">2</span>
|
||||
setTimeout((<span class="hljs-function">-></span> func.apply(func, args)), wait)</pre></div></div>
|
||||
|
||||
|
@ -1001,10 +995,10 @@ it with the arguments supplied.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">memoize</span> = <span class="hljs-params">(func, hasher)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.m<span class="hljs-function"><span class="hljs-title">emoize</span> = <span class="hljs-params">(func, hasher)</span> -></span>
|
||||
memo = {}
|
||||
hasher <span class="hljs-keyword">or</span>= _.identity<span class="hljs-function">
|
||||
-></span>
|
||||
hasher <span class="hljs-keyword">or</span>= _.identity
|
||||
<span class="hljs-function"> -></span>
|
||||
key = hasher.apply <span class="hljs-keyword">this</span>, arguments
|
||||
<span class="hljs-keyword">return</span> memo[key] <span class="hljs-keyword">if</span> key <span class="hljs-keyword">of</span> memo
|
||||
memo[key] = func.apply <span class="hljs-keyword">this</span>, arguments</pre></div></div>
|
||||
|
@ -1023,7 +1017,7 @@ cleared.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">defer</span> = <span class="hljs-params">(func)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.d<span class="hljs-function"><span class="hljs-title">efer</span> = <span class="hljs-params">(func)</span> -></span>
|
||||
_.delay.apply _, [func, <span class="hljs-number">1</span>].concat _.rest arguments</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -1041,7 +1035,7 @@ conditionally execute the original function.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">wrap</span> = <span class="hljs-params">(func, wrapper)</span> -></span><span class="hljs-function">
|
||||
<div class="content"><div class='highlight'><pre>_.w<span class="hljs-function"><span class="hljs-title">rap</span> = <span class="hljs-params">(func, wrapper)</span> -></span><span class="hljs-function">
|
||||
-></span> wrapper.apply wrapper, [func].concat arguments</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -1058,9 +1052,9 @@ consuming the return value of the function that follows.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">compose</span> = -></span>
|
||||
funcs = arguments<span class="hljs-function">
|
||||
-></span>
|
||||
<div class="content"><div class='highlight'><pre>_.c<span class="hljs-function"><span class="hljs-title">ompose</span> = -></span>
|
||||
funcs = arguments
|
||||
<span class="hljs-function"> -></span>
|
||||
args = arguments
|
||||
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> [funcs.length - <span class="hljs-number">1.</span><span class="hljs-number">.0</span>] <span class="hljs-keyword">by</span> -<span class="hljs-number">1</span>
|
||||
args = [funcs[i].apply(<span class="hljs-keyword">this</span>, args)]
|
||||
|
@ -1121,7 +1115,7 @@ consuming the return value of the function that follows.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">values</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.v<span class="hljs-function"><span class="hljs-title">alues</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
_.map obj, _.identity</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -1137,11 +1131,8 @@ consuming the return value of the function that follows.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">functions</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
_.filter<span class="hljs-function"><span class="hljs-params">(_.keys(obj), (key) -> _.isFunction(obj[key]))</span>.<span class="hljs-title">sort</span><span class="hljs-params">()</span>
|
||||
|
||||
|
||||
</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.f<span class="hljs-function"><span class="hljs-title">unctions</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
_.filter(_.keys(obj), <span class="hljs-function"><span class="hljs-params">(key)</span> -></span> _.isFunction(obj[key])).sort()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1156,7 +1147,7 @@ consuming the return value of the function that follows.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">extend</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.e<span class="hljs-function"><span class="hljs-title">xtend</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> source <span class="hljs-keyword">in</span> _.rest(arguments)
|
||||
obj[key] = val <span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> source
|
||||
obj</pre></div></div>
|
||||
|
@ -1174,7 +1165,7 @@ consuming the return value of the function that follows.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">clone</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.c<span class="hljs-function"><span class="hljs-title">lone</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> obj.slice <span class="hljs-number">0</span> <span class="hljs-keyword">if</span> _.isArray obj
|
||||
_.extend {}, obj</pre></div></div>
|
||||
|
||||
|
@ -1192,7 +1183,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">tap</span> = <span class="hljs-params">(obj, interceptor)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.t<span class="hljs-function"><span class="hljs-title">ap</span> = <span class="hljs-params">(obj, interceptor)</span> -></span>
|
||||
interceptor obj
|
||||
obj</pre></div></div>
|
||||
|
||||
|
@ -1209,7 +1200,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isEqual</span> = <span class="hljs-params">(a, b)</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sEqual</span> = <span class="hljs-params">(a, b)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1425,7 +1416,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isEmpty</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sEmpty</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> obj.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">if</span> _.isArray(obj) <span class="hljs-keyword">or</span> _.isString(obj)
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">false</span> <span class="hljs-keyword">for</span> own key <span class="hljs-keyword">of</span> obj
|
||||
<span class="hljs-literal">true</span></pre></div></div>
|
||||
|
@ -1443,7 +1434,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isElement</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">and</span> obj.nodeType <span class="hljs-keyword">is</span> <span class="hljs-number">1</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sElement</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">and</span> obj.nodeType <span class="hljs-keyword">is</span> <span class="hljs-number">1</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1473,7 +1464,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isArguments</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">and</span> obj.callee</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sArguments</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">and</span> obj.callee</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1488,7 +1479,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isFunction</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">and</span> obj.constructor <span class="hljs-keyword">and</span> obj.call <span class="hljs-keyword">and</span> obj.apply)</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sFunction</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">and</span> obj.constructor <span class="hljs-keyword">and</span> obj.call <span class="hljs-keyword">and</span> obj.apply)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1503,7 +1494,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isString</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">is</span> <span class="hljs-string">''</span> <span class="hljs-keyword">or</span> (obj <span class="hljs-keyword">and</span> obj.charCodeAt <span class="hljs-keyword">and</span> obj.substr))</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sString</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">is</span> <span class="hljs-string">''</span> <span class="hljs-keyword">or</span> (obj <span class="hljs-keyword">and</span> obj.charCodeAt <span class="hljs-keyword">and</span> obj.substr))</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1518,7 +1509,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isNumber</span> = <span class="hljs-params">(obj)</span> -></span> (obj <span class="hljs-keyword">is</span> +obj) <span class="hljs-keyword">or</span> toString.call(obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'[object Number]'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sNumber</span> = <span class="hljs-params">(obj)</span> -></span> (obj <span class="hljs-keyword">is</span> +obj) <span class="hljs-keyword">or</span> toString.call(obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'[object Number]'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1533,7 +1524,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isBoolean</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">or</span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">false</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sBoolean</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">or</span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">false</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1548,7 +1539,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isDate</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">and</span> obj.getTimezoneOffset <span class="hljs-keyword">and</span> obj.setUTCFullYear)</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sDate</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">and</span> obj.getTimezoneOffset <span class="hljs-keyword">and</span> obj.setUTCFullYear)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1563,7 +1554,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isRegExp</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">and</span> obj.exec <span class="hljs-keyword">and</span> (obj.ignoreCase <span class="hljs-keyword">or</span> obj.ignoreCase <span class="hljs-keyword">is</span> <span class="hljs-literal">false</span>))</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sRegExp</span> = <span class="hljs-params">(obj)</span> -></span> !!(obj <span class="hljs-keyword">and</span> obj.exec <span class="hljs-keyword">and</span> (obj.ignoreCase <span class="hljs-keyword">or</span> obj.ignoreCase <span class="hljs-keyword">is</span> <span class="hljs-literal">false</span>))</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1579,7 +1570,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isNaN</span> = <span class="hljs-params">(obj)</span> -></span> _.isNumber(obj) <span class="hljs-keyword">and</span> <span class="hljs-built_in">window</span>.isNaN(obj)</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sNaN</span> = <span class="hljs-params">(obj)</span> -></span> _.isNumber(obj) <span class="hljs-keyword">and</span> <span class="hljs-built_in">window</span>.isNaN(obj)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1594,7 +1585,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isNull</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sNull</span> = <span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1609,7 +1600,7 @@ The primary purpose of this method is to “tap into” a method chain, in order
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">isUndefined</span> = <span class="hljs-params">(obj)</span> -></span> <span class="hljs-keyword">typeof</span> obj <span class="hljs-keyword">is</span> <span class="hljs-string">'undefined'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">sUndefined</span> = <span class="hljs-params">(obj)</span> -></span> <span class="hljs-keyword">typeof</span> obj <span class="hljs-keyword">is</span> <span class="hljs-string">'undefined'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1650,7 +1641,7 @@ previous owner. Returns a reference to the Underscore object.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">noConflict</span> = -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.n<span class="hljs-function"><span class="hljs-title">oConflict</span> = -></span>
|
||||
root._ = previousUnderscore
|
||||
<span class="hljs-keyword">this</span></pre></div></div>
|
||||
|
||||
|
@ -1667,7 +1658,7 @@ previous owner. Returns a reference to the Underscore object.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">identity</span> = <span class="hljs-params">(value)</span> -></span> value</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.i<span class="hljs-function"><span class="hljs-title">dentity</span> = <span class="hljs-params">(value)</span> -></span> value</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1682,7 +1673,7 @@ previous owner. Returns a reference to the Underscore object.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">times</span> = <span class="hljs-params">(n, iterator, context)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.t<span class="hljs-function"><span class="hljs-title">imes</span> = <span class="hljs-params">(n, iterator, context)</span> -></span>
|
||||
iterator.call context, i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> [<span class="hljs-number">0.</span>..n]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -1698,7 +1689,7 @@ previous owner. Returns a reference to the Underscore object.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">breakLoop</span> = -></span> <span class="hljs-keyword">throw</span> breaker</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>_.b<span class="hljs-function"><span class="hljs-title">reakLoop</span> = -></span> <span class="hljs-keyword">throw</span> breaker</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -1714,7 +1705,7 @@ they’re correctly added to the OOP wrapper as well.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">mixin</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.m<span class="hljs-function"><span class="hljs-title">ixin</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> _.functions(obj)
|
||||
addToWrapper name, _[name] = obj[name]</pre></div></div>
|
||||
|
||||
|
@ -1733,7 +1724,7 @@ Useful for temporary DOM ids.</p>
|
|||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>idCounter = <span class="hljs-number">0</span>
|
||||
_.<span class="hljs-function"><span class="hljs-title">uniqueId</span> = <span class="hljs-params">(prefix)</span> -></span>
|
||||
_.u<span class="hljs-function"><span class="hljs-title">niqueId</span> = <span class="hljs-params">(prefix)</span> -></span>
|
||||
(prefix <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>) + idCounter++</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
@ -1772,7 +1763,7 @@ With alterations for arbitrary delimiters, and to preserve whitespace.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>_.<span class="hljs-function"><span class="hljs-title">template</span> = <span class="hljs-params">(str, data)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>_.t<span class="hljs-function"><span class="hljs-title">emplate</span> = <span class="hljs-params">(str, data)</span> -></span>
|
||||
c = _.templateSettings
|
||||
endMatch = <span class="hljs-keyword">new</span> RegExp(<span class="hljs-string">"'(?=[^"</span>+c.end.substr(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>)+<span class="hljs-string">"]*"</span>+escapeRegExp(c.end)+<span class="hljs-string">")"</span>,<span class="hljs-string">"g"</span>)
|
||||
fn = <span class="hljs-keyword">new</span> Function <span class="hljs-string">'obj'</span>,
|
||||
|
@ -1971,7 +1962,7 @@ underscore functions. Wrapped objects may be chained.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-attribute">wrapper</span>::<span class="hljs-function"><span class="hljs-title">chain</span> = -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-attribute">wrapper</span>::c<span class="hljs-function"><span class="hljs-title">hain</span> = -></span>
|
||||
<span class="hljs-keyword">this</span>._chain = <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">this</span></pre></div></div>
|
||||
|
||||
|
@ -1988,7 +1979,7 @@ underscore functions. Wrapped objects may be chained.</p>
|
|||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-attribute">wrapper</span>::<span class="hljs-function"><span class="hljs-title">value</span> = -></span> <span class="hljs-keyword">this</span>._wrapped</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-attribute">wrapper</span>::v<span class="hljs-function"><span class="hljs-title">alue</span> = -></span> <span class="hljs-keyword">this</span>._wrapped</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
|
||||
<p>
|
||||
<b>Latest Version:</b>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.8.0">1.8.0</a>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.9.0">1.9.0</a>
|
||||
</p>
|
||||
|
||||
<pre>npm install -g coffee-script</pre>
|
||||
|
@ -416,6 +416,13 @@ Expressions
|
|||
if the incoming argument is missing (<tt>null</tt> or <tt>undefined</tt>).
|
||||
</p>
|
||||
<%= codeFor('default_args', 'fill("cup")') %>
|
||||
<p>
|
||||
CoffeeScript function support
|
||||
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*">ES6 generator functions</a>
|
||||
through the <tt>yield</tt> keyword. A generator in CoffeeScript is simply a function
|
||||
that yields.
|
||||
</p>
|
||||
<%= codeFor('generators', 'ps.next().value') %>
|
||||
|
||||
<p>
|
||||
<span id="objects_and_arrays" class="bookmark"></span>
|
||||
|
@ -1196,6 +1203,25 @@ Expressions
|
|||
Change Log
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
<%= releaseHeader('2015-01-29', '1.9.0', '1.8.0') %>
|
||||
<ul>
|
||||
<li>
|
||||
CoffeeScript now supports ES6 generators. A generator is simply a function
|
||||
that <tt>yield</tt>s.
|
||||
</li>
|
||||
<li>
|
||||
Improved error reporting for string interpolation.
|
||||
</li>
|
||||
<li>
|
||||
Changed strategy for the generation of internal compiler variable names.
|
||||
</li>
|
||||
<li>
|
||||
Fixed REPL compatibility with latest versions of Node and IO.js.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= releaseHeader('2014-08-26', '1.8.0', '1.7.1') %>
|
||||
<ul>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var volume, winner;
|
||||
|
||||
if (ignition === true) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
|
||||
|
||||
_ref = ['toast', 'cheese', 'wine'];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
|
||||
/*
|
||||
SkinnyMochaHalfCaffScript Compiler v1.0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var fs;
|
||||
|
||||
fs = require('fs');
|
||||
|
@ -10,5 +10,5 @@ task('build:parser', 'rebuild the Jison parser', function(options) {
|
|||
require('jison');
|
||||
code = require('./lib/grammar').parser.generate();
|
||||
dir = options.output || 'lib';
|
||||
return fs.writeFile("" + dir + "/parser.js", code);
|
||||
return fs.writeFile(dir + "/parser.js", code);
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
$('body').click(function(e) {
|
||||
return $('.box').fadeIn('fast').addClass('.active');
|
||||
}).css('background', 'white');
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var Animal, Horse, Snake, sam, tom,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
Animal = (function() {
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
function Animal(_at_name) {
|
||||
this.name = _at_name;
|
||||
}
|
||||
|
||||
Animal.prototype.move = function(meters) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var cholesterol, healthy;
|
||||
|
||||
cholesterol = 127;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var date, mood;
|
||||
|
||||
if (singing) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var Person, tim;
|
||||
|
||||
Person = (function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var fill;
|
||||
|
||||
fill = function(container, liquid) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var filename, _fn, _i, _len;
|
||||
|
||||
_fn = function(filename) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var hi;
|
||||
|
||||
hi = function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var footprints, solipsism, speed;
|
||||
|
||||
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var first, last, text, _ref;
|
||||
|
||||
text = "Every literary critic believes he will outwit history and have the last word";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var eldest, grade;
|
||||
|
||||
grade = function(student) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var one, six, three, two;
|
||||
|
||||
six = (one = 1) + (two = 2) + (three = 3);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var globals, name;
|
||||
|
||||
globals = ((function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var error;
|
||||
|
||||
alert((function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var Account;
|
||||
|
||||
Account = function(customer, cart) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var cube, square;
|
||||
|
||||
square = function(x) {
|
||||
|
|
13
documentation/js/generators.js
Normal file
13
documentation/js/generators.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Generated by CoffeeScript 1.9.0
|
||||
var perfectSquares;
|
||||
|
||||
perfectSquares = function*() {
|
||||
var num;
|
||||
num = 0;
|
||||
while (true) {
|
||||
num += 1;
|
||||
(yield num * num);
|
||||
}
|
||||
};
|
||||
|
||||
window.ps || (window.ps = perfectSquares());
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var html;
|
||||
|
||||
html = "<strong>\n cup of coffeescript\n</strong>";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var OPERATOR;
|
||||
|
||||
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
||||
quote = "A picture is a fact. -- " + author;
|
||||
|
||||
sentence = "" + (22 / 7) + " is a decent approximation of π";
|
||||
sentence = (22 / 7) + " is a decent approximation of π";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var city, forecast, temp, weatherReport, _ref;
|
||||
|
||||
weatherReport = function(location) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var age, ages, child, yearsOld;
|
||||
|
||||
yearsOld = {
|
||||
|
@ -12,7 +12,7 @@ ages = (function() {
|
|||
_results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
_results.push("" + child + " is " + age);
|
||||
_results.push(child + " is " + age);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var city, futurists, name, street, _ref, _ref1;
|
||||
|
||||
futurists = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var bitlist, kids, singers, song;
|
||||
|
||||
song = ["do", "re", "mi", "fa", "so"];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
$('.account').attr({
|
||||
"class": 'active'
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var cubes, list, math, num, number, opposite, race, square,
|
||||
__slice = [].slice;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var theBait, theSwitch, _ref;
|
||||
|
||||
theBait = 1000;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var close, contents, open, tag, _i, _ref,
|
||||
__slice = [].slice;
|
||||
|
||||
|
|
2
documentation/js/prototypes.js
vendored
2
documentation/js/prototypes.js
vendored
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
String.prototype.dasherize = function() {
|
||||
return this.replace(/_/g, "-");
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var countdown, num;
|
||||
|
||||
countdown = (function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var changeNumbers, inner, outer;
|
||||
|
||||
outer = 1;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var copy, end, middle, numbers, start;
|
||||
|
||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
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.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var awardMedals, contenders, gold, rest, silver,
|
||||
__slice = [].slice;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var numbers, _ref;
|
||||
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
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,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
switch (day) {
|
||||
case "Mon":
|
||||
go(work);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var grade, score;
|
||||
|
||||
score = 76;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var error;
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var lyrics, num;
|
||||
|
||||
if (this.studyingEconomics) {
|
||||
|
@ -16,7 +16,7 @@ lyrics = (function() {
|
|||
var _results;
|
||||
_results = [];
|
||||
while (num -= 1) {
|
||||
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
_results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
|
|
File diff suppressed because one or more lines are too long
187
index.html
187
index.html
|
@ -110,7 +110,7 @@
|
|||
|
||||
<p>
|
||||
<b>Latest Version:</b>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.8.0">1.8.0</a>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.9.0">1.9.0</a>
|
||||
</p>
|
||||
|
||||
<pre>npm install -g coffee-script</pre>
|
||||
|
@ -258,8 +258,8 @@ cubes = (function() {
|
|||
|
||||
<p>
|
||||
To install, first make sure you have a working copy of the latest stable version of
|
||||
<a href="http://nodejs.org/">Node.js</a>, and <a href="http://npmjs.org">npm</a>
|
||||
(the Node Package Manager). You can then install CoffeeScript globally with npm:
|
||||
<a href="http://nodejs.org/">Node.js</a>. You can then install CoffeeScript globally
|
||||
with <a href="http://npmjs.org">npm</a>:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
|
@ -576,6 +576,44 @@ fill = function(container, liquid) {
|
|||
return "Filling the " + container + " with " + liquid + "...";
|
||||
};
|
||||
;alert(fill("cup"));'>run: fill("cup")</div><br class='clear' /></div>
|
||||
<p>
|
||||
CoffeeScript function support
|
||||
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*">ES6 generator functions</a>
|
||||
through the <tt>yield</tt> keyword. A generator in CoffeeScript is simply a function
|
||||
that yields.
|
||||
</p>
|
||||
<div class='code'><pre><code><span class="function"><span class="title">perfectSquares</span> = -></span>
|
||||
num = <span class="number">0</span>
|
||||
<span class="keyword">loop</span>
|
||||
num += <span class="number">1</span>
|
||||
yield num * num
|
||||
<span class="keyword">return</span>
|
||||
|
||||
<span class="built_in">window</span>.ps <span class="keyword">or</span>= perfectSquares()</code></pre><pre><code><span class="keyword">var</span> perfectSquares;
|
||||
|
||||
perfectSquares = <span class="function"><span class="keyword">function</span>*<span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> num;
|
||||
num = <span class="number">0</span>;
|
||||
<span class="keyword">while</span> (<span class="literal">true</span>) {
|
||||
num += <span class="number">1</span>;
|
||||
(<span class="keyword">yield</span> num * num);
|
||||
}
|
||||
};
|
||||
|
||||
window.ps || (window.ps = perfectSquares());
|
||||
</code></pre><script>window.example4 = "perfectSquares = ->\n num = 0\n loop\n num += 1\n yield num * num\n return\n\nwindow.ps or= perfectSquares()"</script><div class='minibutton load' onclick='javascript: loadConsole(example4);'>load</div><div class='minibutton ok' onclick='javascript: var perfectSquares;
|
||||
|
||||
perfectSquares = function*() {
|
||||
var num;
|
||||
num = 0;
|
||||
while (true) {
|
||||
num += 1;
|
||||
(yield num * num);
|
||||
}
|
||||
};
|
||||
|
||||
window.ps || (window.ps = perfectSquares());
|
||||
;alert(ps.next().value);'>run: ps.next().value</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="objects_and_arrays" class="bookmark"></span>
|
||||
|
@ -625,7 +663,7 @@ kids = {
|
|||
age: <span class="number">9</span>
|
||||
}
|
||||
};
|
||||
</code></pre><script>window.example4 = "song = [\"do\", \"re\", \"mi\", \"fa\", \"so\"]\n\nsingers = {Jagger: \"Rock\", Elvis: \"Roll\"}\n\nbitlist = [\n 1, 0, 1\n 0, 0, 1\n 1, 1, 0\n]\n\nkids =\n brother:\n name: \"Max\"\n age: 11\n sister:\n name: \"Ida\"\n age: 9\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example4);'>load</div><div class='minibutton ok' onclick='javascript: var bitlist, kids, singers, song;
|
||||
</code></pre><script>window.example5 = "song = [\"do\", \"re\", \"mi\", \"fa\", \"so\"]\n\nsingers = {Jagger: \"Rock\", Elvis: \"Roll\"}\n\nbitlist = [\n 1, 0, 1\n 0, 0, 1\n 1, 1, 0\n]\n\nkids =\n brother:\n name: \"Max\"\n age: 11\n sister:\n name: \"Ida\"\n age: 9\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example5);'>load</div><div class='minibutton ok' onclick='javascript: var bitlist, kids, singers, song;
|
||||
|
||||
song = ["do", "re", "mi", "fa", "so"];
|
||||
|
||||
|
@ -663,7 +701,7 @@ log object.class
|
|||
});
|
||||
|
||||
log(object[<span class="string">"class"</span>]);
|
||||
</code></pre><script>window.example5 = "$('.account').attr class: 'active'\n\nlog object.class\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example5);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example6 = "$('.account').attr class: 'active'\n\nlog object.class\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example6);'>load</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="lexical-scope" class="bookmark"></span>
|
||||
|
@ -687,7 +725,7 @@ changeNumbers = <span class="function"><span class="keyword">function</span><spa
|
|||
};
|
||||
|
||||
inner = changeNumbers();
|
||||
</code></pre><script>window.example6 = "outer = 1\nchangeNumbers = ->\n inner = -1\n outer = 10\ninner = changeNumbers()"</script><div class='minibutton load' onclick='javascript: loadConsole(example6);'>load</div><div class='minibutton ok' onclick='javascript: var changeNumbers, inner, outer;
|
||||
</code></pre><script>window.example7 = "outer = 1\nchangeNumbers = ->\n inner = -1\n outer = 10\ninner = changeNumbers()"</script><div class='minibutton load' onclick='javascript: loadConsole(example7);'>load</div><div class='minibutton ok' onclick='javascript: var changeNumbers, inner, outer;
|
||||
|
||||
outer = 1;
|
||||
|
||||
|
@ -769,7 +807,7 @@ date = <span class="keyword">if</span> friday <span class="keyword">then</span>
|
|||
}
|
||||
|
||||
date = friday ? sue : jill;
|
||||
</code></pre><script>window.example7 = "mood = greatlyImproved if singing\n\nif happy and knowsIt\n clapsHands()\n chaChaCha()\nelse\n showIt()\n\ndate = if friday then sue else jill\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example7);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example8 = "mood = greatlyImproved if singing\n\nif happy and knowsIt\n clapsHands()\n chaChaCha()\nelse\n showIt()\n\ndate = if friday then sue else jill\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example8);'>load</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="splats" class="bookmark"></span>
|
||||
|
@ -828,7 +866,7 @@ alert(<span class="string">"Gold: "</span> + gold);
|
|||
alert(<span class="string">"Silver: "</span> + silver);
|
||||
|
||||
alert(<span class="string">"The Field: "</span> + rest);
|
||||
</code></pre><script>window.example8 = "gold = silver = rest = \"unknown\"\n\nawardMedals = (first, second, others...) ->\n gold = first\n silver = second\n rest = others\n\ncontenders = [\n \"Michael Phelps\"\n \"Liu Xiang\"\n \"Yao Ming\"\n \"Allyson Felix\"\n \"Shawn Johnson\"\n \"Roman Sebrle\"\n \"Guo Jingjing\"\n \"Tyson Gay\"\n \"Asafa Powell\"\n \"Usain Bolt\"\n]\n\nawardMedals contenders...\n\nalert \"Gold: \" + gold\nalert \"Silver: \" + silver\nalert \"The Field: \" + rest\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example8);'>load</div><div class='minibutton ok' onclick='javascript: var awardMedals, contenders, gold, rest, silver,
|
||||
</code></pre><script>window.example9 = "gold = silver = rest = \"unknown\"\n\nawardMedals = (first, second, others...) ->\n gold = first\n silver = second\n rest = others\n\ncontenders = [\n \"Michael Phelps\"\n \"Liu Xiang\"\n \"Yao Ming\"\n \"Allyson Felix\"\n \"Shawn Johnson\"\n \"Roman Sebrle\"\n \"Guo Jingjing\"\n \"Tyson Gay\"\n \"Asafa Powell\"\n \"Usain Bolt\"\n]\n\nawardMedals contenders...\n\nalert \"Gold: \" + gold\nalert \"Silver: \" + silver\nalert \"The Field: \" + rest\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example9);'>load</div><div class='minibutton ok' onclick='javascript: var awardMedals, contenders, gold, rest, silver,
|
||||
__slice = [].slice;
|
||||
|
||||
gold = silver = rest = "unknown";
|
||||
|
@ -894,7 +932,7 @@ foods = [<span class="string">'broccoli'</span>, <span class="string">'spinach'<
|
|||
eat(food);
|
||||
}
|
||||
}
|
||||
</code></pre><script>window.example9 = "# Eat lunch.\neat food for food in ['toast', 'cheese', 'wine']\n\n# Fine five course dining.\ncourses = ['greens', 'caviar', 'truffles', 'roast', 'cake']\nmenu i + 1, dish for dish, i in courses\n\n# Health conscious meal.\nfoods = ['broccoli', 'spinach', 'chocolate']\neat food for food in foods when food isnt 'chocolate'\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example9);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example10 = "# Eat lunch.\neat food for food in ['toast', 'cheese', 'wine']\n\n# Fine five course dining.\ncourses = ['greens', 'caviar', 'truffles', 'roast', 'cake']\nmenu i + 1, dish for dish, i in courses\n\n# Health conscious meal.\nfoods = ['broccoli', 'spinach', 'chocolate']\neat food for food in foods when food isnt 'chocolate'\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example10);'>load</div><br class='clear' /></div>
|
||||
<p>
|
||||
Comprehensions should be able to handle most places where you otherwise
|
||||
would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>, for example:
|
||||
|
@ -915,7 +953,7 @@ countdown = (<span class="function"><span class="keyword">function</span><span c
|
|||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
})();
|
||||
</code></pre><script>window.example10 = "countdown = (num for num in [10..1])\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example10);'>load</div><div class='minibutton ok' onclick='javascript: var countdown, num;
|
||||
</code></pre><script>window.example11 = "countdown = (num for num in [10..1])\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example11);'>load</div><div class='minibutton ok' onclick='javascript: var countdown, num;
|
||||
|
||||
countdown = (function() {
|
||||
var _i, _results;
|
||||
|
@ -962,11 +1000,11 @@ ages = (<span class="function"><span class="keyword">function</span><span class=
|
|||
_results = [];
|
||||
<span class="keyword">for</span> (child <span class="keyword">in</span> yearsOld) {
|
||||
age = yearsOld[child];
|
||||
_results.push(<span class="string">""</span> + child + <span class="string">" is "</span> + age);
|
||||
_results.push(child + <span class="string">" is "</span> + age);
|
||||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
})();
|
||||
</code></pre><script>window.example11 = "yearsOld = max: 10, ida: 9, tim: 11\n\nages = for child, age of yearsOld\n \"#{child} is #{age}\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example11);'>load</div><div class='minibutton ok' onclick='javascript: var age, ages, child, yearsOld;
|
||||
</code></pre><script>window.example12 = "yearsOld = max: 10, ida: 9, tim: 11\n\nages = for child, age of yearsOld\n \"#{child} is #{age}\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example12);'>load</div><div class='minibutton ok' onclick='javascript: var age, ages, child, yearsOld;
|
||||
|
||||
yearsOld = {
|
||||
max: 10,
|
||||
|
@ -979,7 +1017,7 @@ ages = (function() {
|
|||
_results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
_results.push("" + child + " is " + age);
|
||||
_results.push(child + " is " + age);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
|
@ -1023,11 +1061,11 @@ lyrics = (<span class="function"><span class="keyword">function</span><span clas
|
|||
<span class="keyword">var</span> _results;
|
||||
_results = [];
|
||||
<span class="keyword">while</span> (num -= <span class="number">1</span>) {
|
||||
_results.push(<span class="string">""</span> + num + <span class="string">" little monkeys, jumping on the bed. One fell out and bumped his head."</span>);
|
||||
_results.push(num + <span class="string">" little monkeys, jumping on the bed. One fell out and bumped his head."</span>);
|
||||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
})();
|
||||
</code></pre><script>window.example12 = "# Econ 101\nif this.studyingEconomics\n buy() while supply > demand\n sell() until supply > demand\n\n# Nursery Rhyme\nnum = 6\nlyrics = while num -= 1\n \"#{num} little monkeys, jumping on the bed.\n One fell out and bumped his head.\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example12);'>load</div><div class='minibutton ok' onclick='javascript: var lyrics, num;
|
||||
</code></pre><script>window.example13 = "# Econ 101\nif this.studyingEconomics\n buy() while supply > demand\n sell() until supply > demand\n\n# Nursery Rhyme\nnum = 6\nlyrics = while num -= 1\n \"#{num} little monkeys, jumping on the bed.\n One fell out and bumped his head.\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example13);'>load</div><div class='minibutton ok' onclick='javascript: var lyrics, num;
|
||||
|
||||
if (this.studyingEconomics) {
|
||||
while (supply > demand) {
|
||||
|
@ -1044,7 +1082,7 @@ lyrics = (function() {
|
|||
var _results;
|
||||
_results = [];
|
||||
while (num -= 1) {
|
||||
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
_results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
|
@ -1076,7 +1114,7 @@ _fn = <span class="function"><span class="keyword">function</span><span class="p
|
|||
filename = list[_i];
|
||||
_fn(filename);
|
||||
}
|
||||
</code></pre><script>window.example13 = "for filename in list\n do (filename) ->\n fs.readFile filename, (err, contents) ->\n compile filename, contents.toString()"</script><div class='minibutton load' onclick='javascript: loadConsole(example13);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example14 = "for filename in list\n do (filename) ->\n fs.readFile filename, (err, contents) ->\n compile filename, contents.toString()"</script><div class='minibutton load' onclick='javascript: loadConsole(example14);'>load</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="slices" class="bookmark"></span>
|
||||
|
@ -1107,7 +1145,7 @@ middle = numbers.slice(<span class="number">3</span>, -<span class="number">2</s
|
|||
end = numbers.slice(-<span class="number">2</span>);
|
||||
|
||||
copy = numbers.slice(<span class="number">0</span>);
|
||||
</code></pre><script>window.example14 = "numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nstart = numbers[0..2]\n\nmiddle = numbers[3...-2]\n\nend = numbers[-2..]\n\ncopy = numbers[..]\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example14);'>load</div><div class='minibutton ok' onclick='javascript: var copy, end, middle, numbers, start;
|
||||
</code></pre><script>window.example15 = "numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nstart = numbers[0..2]\n\nmiddle = numbers[3...-2]\n\nend = numbers[-2..]\n\ncopy = numbers[..]\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example15);'>load</div><div class='minibutton ok' onclick='javascript: var copy, end, middle, numbers, start;
|
||||
|
||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
|
@ -1134,7 +1172,7 @@ numbers[<span class="number">3.</span><span class="number">.6</span>] = [-<span
|
|||
numbers = [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>];
|
||||
|
||||
[].splice.apply(numbers, [<span class="number">3</span>, <span class="number">4</span>].concat(_ref = [-<span class="number">3</span>, -<span class="number">4</span>, -<span class="number">5</span>, -<span class="number">6</span>])), _ref;
|
||||
</code></pre><script>window.example15 = "numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nnumbers[3..6] = [-3, -4, -5, -6]\n\n\n\n "</script><div class='minibutton load' onclick='javascript: loadConsole(example15);'>load</div><div class='minibutton ok' onclick='javascript: var numbers, _ref;
|
||||
</code></pre><script>window.example16 = "numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nnumbers[3..6] = [-3, -4, -5, -6]\n\n\n\n "</script><div class='minibutton load' onclick='javascript: loadConsole(example16);'>load</div><div class='minibutton ok' onclick='javascript: var numbers, _ref;
|
||||
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
|
@ -1178,7 +1216,7 @@ grade = <span class="function"><span class="keyword">function</span><span class=
|
|||
};
|
||||
|
||||
eldest = <span class="number">24</span> > <span class="number">21</span> ? <span class="string">"Liz"</span> : <span class="string">"Ike"</span>;
|
||||
</code></pre><script>window.example16 = "grade = (student) ->\n if student.excellentWork\n \"A+\"\n else if student.okayStuff\n if student.triedHard then \"B\" else \"B-\"\n else\n \"C\"\n\neldest = if 24 > 21 then \"Liz\" else \"Ike\""</script><div class='minibutton load' onclick='javascript: loadConsole(example16);'>load</div><div class='minibutton ok' onclick='javascript: var eldest, grade;
|
||||
</code></pre><script>window.example17 = "grade = (student) ->\n if student.excellentWork\n \"A+\"\n else if student.okayStuff\n if student.triedHard then \"B\" else \"B-\"\n else\n \"C\"\n\neldest = if 24 > 21 then \"Liz\" else \"Ike\""</script><div class='minibutton load' onclick='javascript: loadConsole(example17);'>load</div><div class='minibutton ok' onclick='javascript: var eldest, grade;
|
||||
|
||||
grade = function(student) {
|
||||
if (student.excellentWork) {
|
||||
|
@ -1211,7 +1249,7 @@ eldest = 24 > 21 ? "Liz" : "Ike";
|
|||
</code></pre><pre><code><span class="keyword">var</span> one, six, three, two;
|
||||
|
||||
six = (one = <span class="number">1</span>) + (two = <span class="number">2</span>) + (three = <span class="number">3</span>);
|
||||
</code></pre><script>window.example17 = "six = (one = 1) + (two = 2) + (three = 3)\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example17);'>load</div><div class='minibutton ok' onclick='javascript: var one, six, three, two;
|
||||
</code></pre><script>window.example18 = "six = (one = 1) + (two = 2) + (three = 3)\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example18);'>load</div><div class='minibutton ok' onclick='javascript: var one, six, three, two;
|
||||
|
||||
six = (one = 1) + (two = 2) + (three = 3);
|
||||
;alert(six);'>run: six</div><br class='clear' /></div>
|
||||
|
@ -1233,7 +1271,7 @@ globals = ((<span class="function"><span class="keyword">function</span><span cl
|
|||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
})()).slice(<span class="number">0</span>, <span class="number">10</span>);
|
||||
</code></pre><script>window.example18 = "# The first ten global properties.\n\nglobals = (name for name of window)[0...10]"</script><div class='minibutton load' onclick='javascript: loadConsole(example18);'>load</div><div class='minibutton ok' onclick='javascript: var globals, name;
|
||||
</code></pre><script>window.example19 = "# The first ten global properties.\n\nglobals = (name for name of window)[0...10]"</script><div class='minibutton load' onclick='javascript: loadConsole(example19);'>load</div><div class='minibutton ok' onclick='javascript: var globals, name;
|
||||
|
||||
globals = ((function() {
|
||||
var _results;
|
||||
|
@ -1265,7 +1303,7 @@ alert((<span class="function"><span class="keyword">function</span><span class="
|
|||
<span class="keyword">return</span> <span class="string">"And the error is ... "</span> + error;
|
||||
}
|
||||
})());
|
||||
</code></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;
|
||||
</code></pre><script>window.example20 = "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(example20);'>load</div><div class='minibutton ok' onclick='javascript: var error;
|
||||
|
||||
alert((function() {
|
||||
try {
|
||||
|
@ -1377,7 +1415,7 @@ winner = <span class="literal">yes</span> <span class="keyword">if</span> pick <
|
|||
}
|
||||
|
||||
print(inspect(<span class="string">"My name is "</span> + <span class="keyword">this</span>.name));
|
||||
</code></pre><script>window.example20 = "launch() if ignition is on\n\nvolume = 10 if band isnt SpinalTap\n\nletTheWildRumpusBegin() unless answer is no\n\nif car.speed < limit then accelerate()\n\nwinner = yes if pick in [47, 92, 13]\n\nprint inspect \"My name is #{@name}\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example20);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example21 = "launch() if ignition is on\n\nvolume = 10 if band isnt SpinalTap\n\nletTheWildRumpusBegin() unless answer is no\n\nif car.speed < limit then accelerate()\n\nwinner = yes if pick in [47, 92, 13]\n\nprint inspect \"My name is #{@name}\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example21);'>load</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<b class="header">The Existential Operator</b>
|
||||
|
@ -1416,7 +1454,7 @@ speed = <span class="number">0</span>;
|
|||
}
|
||||
|
||||
footprints = <span class="keyword">typeof</span> yeti !== <span class="string">"undefined"</span> && yeti !== <span class="literal">null</span> ? yeti : <span class="string">"bear"</span>;
|
||||
</code></pre><script>window.example21 = "solipsism = true if mind? and not world?\n\nspeed = 0\nspeed ?= 15\n\nfootprints = yeti ? \"bear\"\n\n\n\n\n\n\n "</script><div class='minibutton load' onclick='javascript: loadConsole(example21);'>load</div><div class='minibutton ok' onclick='javascript: var footprints, solipsism, speed;
|
||||
</code></pre><script>window.example22 = "solipsism = true if mind? and not world?\n\nspeed = 0\nspeed ?= 15\n\nfootprints = yeti ? \"bear\"\n\n\n\n\n\n\n "</script><div class='minibutton load' onclick='javascript: loadConsole(example22);'>load</div><div class='minibutton ok' onclick='javascript: var footprints, solipsism, speed;
|
||||
|
||||
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
|
||||
solipsism = true;
|
||||
|
@ -1442,10 +1480,10 @@ footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear";
|
|||
</code></pre><pre><code><span class="keyword">var</span> zip, _ref;
|
||||
|
||||
zip = <span class="keyword">typeof</span> lottery.drawWinner === <span class="string">"function"</span> ? (_ref = lottery.drawWinner().address) != <span class="literal">null</span> ? _ref.zipcode : <span class="keyword">void</span> <span class="number">0</span> : <span class="keyword">void</span> <span class="number">0</span>;
|
||||
</code></pre><script>window.example22 = "zip = lottery.drawWinner?().address?.zipcode\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example22);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example23 = "zip = lottery.drawWinner?().address?.zipcode\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example23);'>load</div><br class='clear' /></div>
|
||||
<p>
|
||||
Soaking up nulls is similar to Ruby's
|
||||
<a href="http://andand.rubyforge.org/">andand gem</a>, and to the
|
||||
<a href="https://rubygems.org/gems/andand">andand gem</a>, and to the
|
||||
<a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29">safe navigation operator</a>
|
||||
in Groovy.
|
||||
</p>
|
||||
|
@ -1501,12 +1539,12 @@ tom.move()
|
|||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> Animal, Horse, Snake, sam, tom,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = <span class="function"><span class="keyword">function</span><span class="params">(child, parent)</span> {</span> <span class="keyword">for</span> (<span class="keyword">var</span> key <span class="keyword">in</span> parent) { <span class="keyword">if</span> (__hasProp.call(parent, key)) child[key] = parent[key]; } <span class="function"><span class="keyword">function</span> <span class="title">ctor</span><span class="params">()</span> {</span> <span class="keyword">this</span>.constructor = child; } ctor.prototype = parent.prototype; child.prototype = <span class="keyword">new</span> ctor(); child.__super__ = parent.prototype; <span class="keyword">return</span> child; };
|
||||
__extends = <span class="function"><span class="keyword">function</span><span class="params">(child, parent)</span> {</span> <span class="keyword">for</span> (<span class="keyword">var</span> key <span class="keyword">in</span> parent) { <span class="keyword">if</span> (__hasProp.call(parent, key)) child[key] = parent[key]; } <span class="function"><span class="keyword">function</span> <span class="title">ctor</span><span class="params">()</span> {</span> <span class="keyword">this</span>.constructor = child; } ctor.prototype = parent.prototype; child.prototype = <span class="keyword">new</span> ctor(); child.__super__ = parent.prototype; <span class="keyword">return</span> child; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
Animal = (<span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="function"><span class="keyword">function</span> <span class="title">Animal</span><span class="params">(name)</span> {</span>
|
||||
<span class="keyword">this</span>.name = name;
|
||||
<span class="function"><span class="keyword">function</span> <span class="title">Animal</span><span class="params">(_at_name)</span> {</span>
|
||||
<span class="keyword">this</span>.name = _at_name;
|
||||
}
|
||||
|
||||
Animal.prototype.move = <span class="function"><span class="keyword">function</span><span class="params">(meters)</span> {</span>
|
||||
|
@ -1556,13 +1594,13 @@ tom = <span class="keyword">new</span> Horse(<span class="string">"Tommy the Pal
|
|||
sam.move();
|
||||
|
||||
tom.move();
|
||||
</code></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,
|
||||
__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; };
|
||||
</code></pre><script>window.example24 = "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(example24);'>load</div><div class='minibutton ok' onclick='javascript: var Animal, Horse, Snake, sam, tom,
|
||||
__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; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
Animal = (function() {
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
function Animal(_at_name) {
|
||||
this.name = _at_name;
|
||||
}
|
||||
|
||||
Animal.prototype.move = function(meters) {
|
||||
|
@ -1627,7 +1665,7 @@ tom.move();
|
|||
</code></pre><pre><code><span class="built_in">String</span>.prototype.dasherize = <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">return</span> <span class="keyword">this</span>.replace(<span class="regexp">/_/g</span>, <span class="string">"-"</span>);
|
||||
};
|
||||
</code></pre><script>window.example24 = "String::dasherize = ->\n this.replace /_/g, \"-\"\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example24);'>load</div><div class='minibutton ok' onclick='javascript: String.prototype.dasherize = function() {
|
||||
</code></pre><script>window.example25 = "String::dasherize = ->\n this.replace /_/g, \"-\"\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example25);'>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>
|
||||
|
@ -1665,7 +1703,7 @@ theBait = <span class="number">1000</span>;
|
|||
theSwitch = <span class="number">0</span>;
|
||||
|
||||
_ref = [theSwitch, theBait], theBait = _ref[<span class="number">0</span>], theSwitch = _ref[<span class="number">1</span>];
|
||||
</code></pre><script>window.example25 = "theBait = 1000\ntheSwitch = 0\n\n[theBait, theSwitch] = [theSwitch, theBait]\n\n\n\n\n "</script><div class='minibutton load' onclick='javascript: loadConsole(example25);'>load</div><div class='minibutton ok' onclick='javascript: var theBait, theSwitch, _ref;
|
||||
</code></pre><script>window.example26 = "theBait = 1000\ntheSwitch = 0\n\n[theBait, theSwitch] = [theSwitch, theBait]\n\n\n\n\n "</script><div class='minibutton load' onclick='javascript: loadConsole(example26);'>load</div><div class='minibutton ok' onclick='javascript: var theBait, theSwitch, _ref;
|
||||
|
||||
theBait = 1000;
|
||||
|
||||
|
@ -1693,7 +1731,7 @@ weatherReport = <span class="function"><span class="keyword">function</span><spa
|
|||
};
|
||||
|
||||
_ref = weatherReport(<span class="string">"Berkeley, CA"</span>), city = _ref[<span class="number">0</span>], temp = _ref[<span class="number">1</span>], forecast = _ref[<span class="number">2</span>];
|
||||
</code></pre><script>window.example26 = "weatherReport = (location) ->\n # Make an Ajax request to fetch the weather...\n [location, 72, \"Mostly Sunny\"]\n\n[city, temp, forecast] = weatherReport \"Berkeley, CA\"\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example26);'>load</div><div class='minibutton ok' onclick='javascript: var city, forecast, temp, weatherReport, _ref;
|
||||
</code></pre><script>window.example27 = "weatherReport = (location) ->\n # Make an Ajax request to fetch the weather...\n [location, 72, \"Mostly Sunny\"]\n\n[city, temp, forecast] = weatherReport \"Berkeley, CA\"\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example27);'>load</div><div class='minibutton ok' onclick='javascript: var city, forecast, temp, weatherReport, _ref;
|
||||
|
||||
weatherReport = function(location) {
|
||||
return [location, 72, "Mostly Sunny"];
|
||||
|
@ -1731,7 +1769,7 @@ futurists = {
|
|||
};
|
||||
|
||||
_ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[<span class="number">0</span>], city = _ref1[<span class="number">1</span>]);
|
||||
</code></pre><script>window.example27 = "futurists =\n sculptor: \"Umberto Boccioni\"\n painter: \"Vladimir Burliuk\"\n poet:\n name: \"F.T. Marinetti\"\n address: [\n \"Via Roma 42R\"\n \"Bellagio, Italy 22021\"\n ]\n\n{poet: {name, address: [street, city]}} = futurists\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example27);'>load</div><div class='minibutton ok' onclick='javascript: var city, futurists, name, street, _ref, _ref1;
|
||||
</code></pre><script>window.example28 = "futurists =\n sculptor: \"Umberto Boccioni\"\n painter: \"Vladimir Burliuk\"\n poet:\n name: \"F.T. Marinetti\"\n address: [\n \"Via Roma 42R\"\n \"Bellagio, Italy 22021\"\n ]\n\n{poet: {name, address: [street, city]}} = futurists\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example28);'>load</div><div class='minibutton ok' onclick='javascript: var city, futurists, name, street, _ref, _ref1;
|
||||
|
||||
futurists = {
|
||||
sculptor: "Umberto Boccioni",
|
||||
|
@ -1762,7 +1800,7 @@ _ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[0
|
|||
tag = <span class="string">"<impossible>"</span>;
|
||||
|
||||
_ref = tag.split(<span class="string">""</span>), open = _ref[<span class="number">0</span>], contents = <span class="number">3</span> <= _ref.length ? __slice.call(_ref, <span class="number">1</span>, _i = _ref.length - <span class="number">1</span>) : (_i = <span class="number">1</span>, []), close = _ref[_i++];
|
||||
</code></pre><script>window.example28 = "tag = \"<impossible>\"\n\n[open, contents..., close] = tag.split(\"\")\n\n\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example28);'>load</div><div class='minibutton ok' onclick='javascript: var close, contents, open, tag, _i, _ref,
|
||||
</code></pre><script>window.example29 = "tag = \"<impossible>\"\n\n[open, contents..., close] = tag.split(\"\")\n\n\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example29);'>load</div><div class='minibutton ok' onclick='javascript: var close, contents, open, tag, _i, _ref,
|
||||
__slice = [].slice;
|
||||
|
||||
tag = "<impossible>";
|
||||
|
@ -1784,7 +1822,7 @@ _ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call
|
|||
text = <span class="string">"Every literary critic believes he will outwit history and have the last word"</span>;
|
||||
|
||||
_ref = text.split(<span class="string">" "</span>), first = _ref[<span class="number">0</span>], last = _ref[_ref.length - <span class="number">1</span>];
|
||||
</code></pre><script>window.example29 = "text = \"Every literary critic believes he will\n outwit history and have the last word\"\n\n[first, ..., last] = text.split \" \"\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example29);'>load</div><div class='minibutton ok' onclick='javascript: var first, last, text, _ref;
|
||||
</code></pre><script>window.example30 = "text = \"Every literary critic believes he will\n outwit history and have the last word\"\n\n[first, ..., last] = text.split \" \"\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example30);'>load</div><div class='minibutton ok' onclick='javascript: var first, last, text, _ref;
|
||||
|
||||
text = "Every literary critic believes he will outwit history and have the last word";
|
||||
|
||||
|
@ -1814,7 +1852,7 @@ Person = (<span class="function"><span class="keyword">function</span><span clas
|
|||
tim = <span class="keyword">new</span> Person({
|
||||
age: <span class="number">4</span>
|
||||
});
|
||||
</code></pre><script>window.example30 = "class Person\n constructor: (options) -> \n {@name, @age, @height} = options\n\ntim = new Person age: 4\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example30);'>load</div><div class='minibutton ok' onclick='javascript: var Person, tim;
|
||||
</code></pre><script>window.example31 = "class Person\n constructor: (options) -> \n {@name, @age, @height} = options\n\ntim = new Person age: 4\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example31);'>load</div><div class='minibutton ok' onclick='javascript: var Person, tim;
|
||||
|
||||
Person = (function() {
|
||||
function Person(options) {
|
||||
|
@ -1864,7 +1902,7 @@ Account = <span class="function"><span class="keyword">function</span><span clas
|
|||
};
|
||||
})(<span class="keyword">this</span>));
|
||||
};
|
||||
</code></pre><script>window.example31 = "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(example31);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example32 = "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(example32);'>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,
|
||||
|
@ -1894,7 +1932,7 @@ Account = <span class="function"><span class="keyword">function</span><span clas
|
|||
hi = <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">return</span> [document.title, <span class="string">"Hello JavaScript"</span>].join(<span class="string">": "</span>);
|
||||
};
|
||||
</code></pre><script>window.example32 = "hi = `function() {\n return [document.title, \"Hello JavaScript\"].join(\": \");\n}`\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example32);'>load</div><div class='minibutton ok' onclick='javascript: var hi;
|
||||
</code></pre><script>window.example33 = "hi = `function() {\n return [document.title, \"Hello JavaScript\"].join(\": \");\n}`\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example33);'>load</div><div class='minibutton ok' onclick='javascript: var hi;
|
||||
|
||||
hi = function() {
|
||||
return [document.title, "Hello JavaScript"].join(": ");
|
||||
|
@ -1948,7 +1986,7 @@ hi = function() {
|
|||
<span class="keyword">default</span>:
|
||||
go(work);
|
||||
}
|
||||
</code></pre><script>window.example33 = "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(example33);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example34 = "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(example34);'>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.
|
||||
|
@ -1979,7 +2017,7 @@ grade = (<span class="function"><span class="keyword">function</span><span class
|
|||
<span class="keyword">return</span> <span class="string">'A'</span>;
|
||||
}
|
||||
})();
|
||||
</code></pre><script>window.example34 = "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(example34);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example35 = "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(example35);'>load</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="try" class="bookmark"></span>
|
||||
|
@ -2006,7 +2044,7 @@ grade = (<span class="function"><span class="keyword">function</span><span class
|
|||
} <span class="keyword">finally</span> {
|
||||
cleanUp();
|
||||
}
|
||||
</code></pre><script>window.example35 = "try\n allHellBreaksLoose()\n catsAndDogsLivingTogether()\ncatch error\n print error\nfinally\n cleanUp()\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example35);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example36 = "try\n allHellBreaksLoose()\n catsAndDogsLivingTogether()\ncatch error\n print error\nfinally\n cleanUp()\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example36);'>load</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="comparisons" class="bookmark"></span>
|
||||
|
@ -2026,7 +2064,7 @@ healthy = <span class="number">200</span> > cholesterol > <span class="num
|
|||
cholesterol = <span class="number">127</span>;
|
||||
|
||||
healthy = (<span class="number">200</span> > cholesterol && cholesterol > <span class="number">60</span>);
|
||||
</code></pre><script>window.example36 = "cholesterol = 127\n\nhealthy = 200 > cholesterol > 60\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example36);'>load</div><div class='minibutton ok' onclick='javascript: var cholesterol, healthy;
|
||||
</code></pre><script>window.example37 = "cholesterol = 127\n\nhealthy = 200 > cholesterol > 60\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example37);'>load</div><div class='minibutton ok' onclick='javascript: var cholesterol, healthy;
|
||||
|
||||
cholesterol = 127;
|
||||
|
||||
|
@ -2055,14 +2093,14 @@ author = <span class="string">"Wittgenstein"</span>;
|
|||
|
||||
quote = <span class="string">"A picture is a fact. -- "</span> + author;
|
||||
|
||||
sentence = <span class="string">""</span> + (<span class="number">22</span> / <span class="number">7</span>) + <span class="string">" is a decent approximation of π"</span>;
|
||||
</code></pre><script>window.example37 = "author = \"Wittgenstein\"\nquote = \"A picture is a fact. -- #{ author }\"\n\nsentence = \"#{ 22 / 7 } is a decent approximation of π\"\n\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example37);'>load</div><div class='minibutton ok' onclick='javascript: var author, quote, sentence;
|
||||
sentence = (<span class="number">22</span> / <span class="number">7</span>) + <span class="string">" is a decent approximation of π"</span>;
|
||||
</code></pre><script>window.example38 = "author = \"Wittgenstein\"\nquote = \"A picture is a fact. -- #{ author }\"\n\nsentence = \"#{ 22 / 7 } is a decent approximation of π\"\n\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example38);'>load</div><div class='minibutton ok' onclick='javascript: var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
||||
quote = "A picture is a fact. -- " + author;
|
||||
|
||||
sentence = "" + (22 / 7) + " is a decent approximation of π";
|
||||
sentence = (22 / 7) + " is a decent approximation of π";
|
||||
;alert(sentence);'>run: sentence</div><br class='clear' /></div>
|
||||
<p>
|
||||
Multiline strings are allowed in CoffeeScript. Lines are joined by a single space unless they end with a backslash. Indentation is ignored.
|
||||
|
@ -2076,7 +2114,7 @@ sentence = "" + (22 / 7) + " is a decent approximation of π";
|
|||
</code></pre><pre><code><span class="keyword">var</span> mobyDick;
|
||||
|
||||
mobyDick = <span class="string">"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>;
|
||||
</code></pre><script>window.example38 = "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"</script><div class='minibutton load' onclick='javascript: loadConsole(example38);'>load</div><div class='minibutton ok' onclick='javascript: var mobyDick;
|
||||
</code></pre><script>window.example39 = "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"</script><div class='minibutton load' onclick='javascript: loadConsole(example39);'>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>
|
||||
|
@ -2095,7 +2133,7 @@ mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely --
|
|||
</code></pre><pre><code><span class="keyword">var</span> html;
|
||||
|
||||
html = <span class="string">"<strong>\n cup of coffeescript\n</strong>"</span>;
|
||||
</code></pre><script>window.example39 = "html = \"\"\"\n <strong>\n cup of coffeescript\n </strong>\n \"\"\"\n \n"</script><div class='minibutton load' onclick='javascript: loadConsole(example39);'>load</div><div class='minibutton ok' onclick='javascript: var html;
|
||||
</code></pre><script>window.example40 = "html = \"\"\"\n <strong>\n cup of coffeescript\n </strong>\n \"\"\"\n \n"</script><div class='minibutton load' onclick='javascript: loadConsole(example40);'>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>
|
||||
|
@ -2120,7 +2158,7 @@ SkinnyMochaHalfCaffScript Compiler v1.0
|
|||
Released under the MIT License
|
||||
*/</span>
|
||||
|
||||
</code></pre><script>window.example40 = "###\nSkinnyMochaHalfCaffScript Compiler v1.0\nReleased under the MIT License\n###\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example40);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example41 = "###\nSkinnyMochaHalfCaffScript Compiler v1.0\nReleased under the MIT License\n###\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example41);'>load</div><br class='clear' /></div>
|
||||
|
||||
<p>
|
||||
<span id="regexes" class="bookmark"></span>
|
||||
|
@ -2145,7 +2183,7 @@ Released under the MIT License
|
|||
</code></pre><pre><code><span class="keyword">var</span> OPERATOR;
|
||||
|
||||
OPERATOR = <span class="regexp">/^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/</span>;
|
||||
</code></pre><script>window.example41 = "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(example41);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example42 = "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(example42);'>load</div><br class='clear' /></div>
|
||||
|
||||
|
||||
<h2>
|
||||
|
@ -2190,9 +2228,9 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
|||
<span class="built_in">require</span>(<span class="string">'jison'</span>);
|
||||
code = <span class="built_in">require</span>(<span class="string">'./lib/grammar'</span>).parser.generate();
|
||||
dir = options.output || <span class="string">'lib'</span>;
|
||||
<span class="keyword">return</span> fs.writeFile(<span class="string">""</span> + dir + <span class="string">"/parser.js"</span>, code);
|
||||
<span class="keyword">return</span> fs.writeFile(dir + <span class="string">"/parser.js"</span>, code);
|
||||
});
|
||||
</code></pre><script>window.example42 = "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(example42);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example43 = "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(example43);'>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:
|
||||
|
@ -2302,14 +2340,18 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
|||
</li>
|
||||
<li>
|
||||
<a href="http://www.packtpub.com/coffeescript-application-development/book">CoffeeScript Application Development</a>
|
||||
is a new book from Packt Publishing that introduces CoffeeScript while
|
||||
from Packt, introduces CoffeeScript while
|
||||
walking through the process of building a demonstration web application.
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://www.manning.com/lee/">CoffeeScript in Action</a>
|
||||
is a new book from Manning Publications that covers CoffeeScript syntax, composition techniques
|
||||
from Manning Publications, covers CoffeeScript syntax, composition techniques
|
||||
and application development.
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://www.dpunkt.de/buecher/4021/coffeescript.html">CoffeeScript: Die Alternative zu JavaScript</a>
|
||||
from dpunkt.verlag, is the first CoffeeScript book in Deutsch.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>
|
||||
|
@ -2449,6 +2491,29 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
|||
Change Log
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
<div class="anchor" id="1.9.0"></div>
|
||||
<b class="header">
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/1.8.0...1.9.0">1.9.0</a>
|
||||
<span class="timestamp"> — <time datetime="2015-01-29">January 29, 2015</time></span>
|
||||
</b>
|
||||
<ul>
|
||||
<li>
|
||||
CoffeeScript now supports ES6 generators. A generator is simply a function
|
||||
that <tt>yield</tt>s.
|
||||
</li>
|
||||
<li>
|
||||
Improved error reporting for string interpolation.
|
||||
</li>
|
||||
<li>
|
||||
Changed strategy for the generation of internal compiler variable names.
|
||||
</li>
|
||||
<li>
|
||||
Fixed REPL compatibility with latest versions of Node and IO.js.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<div class="anchor" id="1.8.0"></div>
|
||||
<b class="header">
|
||||
|
@ -2532,7 +2597,7 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
|||
</code></pre><pre><code>$(<span class="string">'body'</span>).click(<span class="function"><span class="keyword">function</span><span class="params">(e)</span> {</span>
|
||||
<span class="keyword">return</span> $(<span class="string">'.box'</span>).fadeIn(<span class="string">'fast'</span>).addClass(<span class="string">'.active'</span>);
|
||||
}).css(<span class="string">'background'</span>, <span class="string">'white'</span>);
|
||||
</code></pre><script>window.example43 = "$ 'body'\n.click (e) ->\n $ '.box'\n .fadeIn 'fast'\n .addClass '.active'\n.css 'background', 'white'\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example43);'>load</div><br class='clear' /></div>
|
||||
</code></pre><script>window.example44 = "$ 'body'\n.click (e) ->\n $ '.box'\n .fadeIn 'fast'\n .addClass '.active'\n.css 'background', 'white'\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example44);'>load</div><br class='clear' /></div>
|
||||
<ul>
|
||||
<li>
|
||||
Added <tt>**</tt>, <tt>//</tt> and <tt>%%</tt> operators and <tt>...</tt> expansion in parameter lists and destructuring expressions.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(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; };
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var Lexer, SourceMap, compile, ext, formatSourcePosition, fs, getSourceMap, helpers, lexer, parser, path, sourceMaps, vm, withPrettyErrors, _base, _i, _len, _ref,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
|
@ -18,7 +18,7 @@
|
|||
|
||||
SourceMap = require('./sourcemap');
|
||||
|
||||
exports.VERSION = '1.8.0';
|
||||
exports.VERSION = '1.9.0';
|
||||
|
||||
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs, _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; };
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var key, val, _ref;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NUMBER, OCTAL_ESCAPE, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, RELATION, RESERVED, Rewriter, SHIFT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, repeat, 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; };
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var Access, Arr, Assign, Base, Block, Call, Class, Code, CodeFragment, Comment, Existence, Expansion, Extends, For, HEXNUM, IDENTIFIER, IDENTIFIER_STR, IS_REGEX, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, NUMBER, 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, isLiteralArguments, isLiteralThis, last, locationDataToString, merge, multident, parseNum, some, starts, throwSyntaxError, unfoldSoak, utility, _ref, _ref1,
|
||||
__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; },
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments, repeat;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, loadFile, path, _i, _len, _ref;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, replDefaults, updateSyntaxError, vm, _ref;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var BALANCED_PAIRS, CALL_CLOSERS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, 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; },
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var Scope, extend, last, _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; };
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated by CoffeeScript 1.8.0
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
(function() {
|
||||
var LineMap, SourceMap;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"compiler"
|
||||
],
|
||||
"author": "Jeremy Ashkenas",
|
||||
"version": "1.8.0",
|
||||
"version": "1.9.0",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
|
|
|
@ -12,7 +12,7 @@ helpers = require './helpers'
|
|||
SourceMap = require './sourcemap'
|
||||
|
||||
# The current CoffeeScript version number.
|
||||
exports.VERSION = '1.8.0'
|
||||
exports.VERSION = '1.9.0'
|
||||
|
||||
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue