mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 09:17:55 -05:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
533ad8afe9 | ||
|
|
1961f06e08 | ||
|
|
4503e2716e | ||
|
|
e4d81005be | ||
|
|
b6012c4617 | ||
|
|
feee6954a6 | ||
|
|
fea058c53a | ||
|
|
25d97aa136 | ||
|
|
7c8849cc21 | ||
|
|
b362bd672c | ||
|
|
a4f510501c | ||
|
|
e3f6e19950 | ||
|
|
b49b41320e | ||
|
|
6bc3157793 | ||
|
|
dc8a2b17d0 | ||
|
|
c3ae2328af | ||
|
|
57846ea5c0 | ||
|
|
3da88b9b3f | ||
|
|
8130e63e43 | ||
|
|
dc44ebbdaa | ||
|
|
88ad059d54 | ||
|
|
76c076db55 | ||
|
|
5698e6c72a | ||
|
|
e0e4967ad8 | ||
|
|
53c7891599 | ||
|
|
94a17cb74a | ||
|
|
5d139596f8 | ||
|
|
213225418a | ||
|
|
3b3e52097a | ||
|
|
72ceec5680 | ||
|
|
5a220d4e13 | ||
|
|
92e5ab2857 | ||
|
|
64632e3332 | ||
|
|
c0e1f23f23 | ||
|
|
ee8f889cbd | ||
|
|
ffa25aae77 | ||
|
|
04b30a6cc4 | ||
|
|
996a171a4e | ||
|
|
17a271af06 | ||
|
|
f8c366c479 | ||
|
|
934bd2acc7 | ||
|
|
dd0ec84ebe | ||
|
|
e9a372dff5 | ||
|
|
4d7a0d2470 | ||
|
|
c2abe253a1 | ||
|
|
3ddd3115eb | ||
|
|
a3096eab91 | ||
|
|
3fd004b852 | ||
|
|
0a9c7a3257 |
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2009-2014 Jeremy Ashkenas
|
||||
Copyright (c) 2009-2015 Jeremy Ashkenas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "coffee-script",
|
||||
"version": "1.9.0",
|
||||
"version": "1.9.1",
|
||||
"main": [
|
||||
"lib/coffee-script/coffee-script.js"
|
||||
],
|
||||
|
||||
@@ -140,7 +140,7 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
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.r<span class="hljs-function"><span class="hljs-title">un</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<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>
|
||||
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.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>
|
||||
<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>
|
||||
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.o<span class="hljs-function"><span class="hljs-title">nreadystatechange</span> = -></span>
|
||||
xhr.<span class="hljs-function"><span class="hljs-title">onreadystatechange</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>exports.r<span class="hljs-function"><span class="hljs-title">un</span> = -></span>
|
||||
<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>
|
||||
<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>exports.VERSION = <span class="hljs-string">'1.9.0'</span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.VERSION = <span class="hljs-string">'1.9.1'</span>
|
||||
|
||||
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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -161,7 +161,7 @@ exports.FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'</span>, <span cla
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.helpers = helpers</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.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,7 +203,7 @@ lookups.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.compile = compile = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -></span>
|
||||
<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>
|
||||
{merge, extend} = helpers
|
||||
options = extend {}, options
|
||||
|
||||
@@ -222,14 +222,12 @@ lookups.</p>
|
||||
<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>
|
||||
the same name.</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>
|
||||
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
|
||||
)
|
||||
|
||||
fragments = parser.parse(tokens).compileToFragments options
|
||||
@@ -307,7 +305,7 @@ optimization.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.tokens = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(code, options)</span> -></span>
|
||||
<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>
|
||||
@@ -325,7 +323,7 @@ or traverse it by using <code>.traverseChildren()</code> with a callback.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.nodes = withPrettyErrors <span class="hljs-function"><span class="hljs-params">(source, options)</span> -></span>
|
||||
<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>
|
||||
@@ -345,7 +343,7 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
||||
|
||||
</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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
@@ -431,7 +429,7 @@ The CoffeeScript REPL uses this to run the input.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> code = code.trim()
|
||||
createContext = vm.Script.createContext ? vm.createContext
|
||||
|
||||
@@ -467,7 +465,7 @@ 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>
|
||||
|
||||
@@ -485,7 +483,7 @@ The CoffeeScript REPL uses this to run the input.</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
|
||||
_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>
|
||||
@@ -495,7 +493,7 @@ The CoffeeScript REPL uses this to run the input.</p>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
@@ -517,7 +515,7 @@ exports.r<span class="hljs-function"><span class="hljs-title">egister</span> = -
|
||||
Use CoffeeScript.register() or require the coffee-script/register module to require <span class="hljs-subst">#{ext}</span> files.
|
||||
"""</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>
|
||||
<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>
|
||||
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
|
||||
|
||||
@@ -619,7 +617,7 @@ directly as a “Jison lexer”.</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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -639,12 +637,15 @@ the error is caused by a generated token which might refer to its origin.</p>
|
||||
<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>]
|
||||
<span class="hljs-string">'end of input'</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'INDENT'</span>, <span class="hljs-string">'OUTDENT'</span>]
|
||||
<span class="hljs-string">'indentation'</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
helpers.nameWhitespaceCharacter errorText</pre></div></div>
|
||||
errorText = <span class="hljs-keyword">switch</span>
|
||||
<span class="hljs-keyword">when</span> errorToken <span class="hljs-keyword">is</span> tokens[tokens.length - <span class="hljs-number">1</span>]
|
||||
<span class="hljs-string">'end of input'</span>
|
||||
<span class="hljs-keyword">when</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'INDENT'</span>, <span class="hljs-string">'OUTDENT'</span>]
|
||||
<span class="hljs-string">'indentation'</span>
|
||||
<span class="hljs-keyword">when</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'IDENTIFIER'</span>, <span class="hljs-string">'NUMBER'</span>, <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'STRING_START'</span>, <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">'REGEX_START'</span>]
|
||||
errorTag.replace(<span class="hljs-regexp">/_START$/</span>, <span class="hljs-string">''</span>).toLowerCase()
|
||||
<span class="hljs-keyword">else</span>
|
||||
helpers.nameWhitespaceCharacter errorText</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -771,8 +772,8 @@ 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> exports.FILE_EXTENSIONS
|
||||
answer = exports._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> <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>
|
||||
sourceMaps[filename] = answer.sourceMap</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -791,14 +792,14 @@ positions.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
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> exports.run
|
||||
<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-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>
|
||||
|
||||
@@ -160,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>
|
||||
|
||||
@@ -236,7 +236,8 @@ sources = []
|
||||
sourceCode = []
|
||||
notSources = {}
|
||||
watchedDirs = {}
|
||||
optionParser = <span class="hljs-literal">null</span></pre></div></div>
|
||||
optionParser = <span class="hljs-literal">null</span>
|
||||
jsToSources = {}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -253,7 +254,7 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.r<span class="hljs-function"><span class="hljs-title">un</span> = -></span>
|
||||
<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>
|
||||
parseOptions()</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -356,8 +357,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>
|
||||
@@ -460,9 +461,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)</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>
|
||||
<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>
|
||||
compileScript opts.join, sourceCode.join(<span class="hljs-string">'\n'</span>), opts.join</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -484,8 +485,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>
|
||||
@@ -494,8 +495,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>
|
||||
@@ -508,15 +509,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()
|
||||
|
||||
@@ -541,8 +542,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>
|
||||
@@ -557,8 +558,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
|
||||
|
||||
@@ -567,8 +568,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
|
||||
@@ -598,8 +599,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
|
||||
@@ -645,7 +646,7 @@ the compiled JS version as well.</p>
|
||||
<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>
|
||||
<span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-title">mkdirs</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()
|
||||
@@ -675,7 +676,13 @@ 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-keyword">if</span> jsPath <span class="hljs-keyword">of</span> jsToSources
|
||||
printLine <span class="hljs-string">"Error: The two following source files have the same output file:"</span>
|
||||
printLine <span class="hljs-string">" "</span> + jsToSources[jsPath]
|
||||
printLine <span class="hljs-string">" "</span> + sourcePath
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
jsToSources[jsPath] = sourcePath
|
||||
<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>
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'novecento-bold';
|
||||
src: url('public/fonts/novecento-bold.eot');
|
||||
src: url('public/fonts/novecento-bold.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/novecento-bold.woff') format('woff'),
|
||||
url('public/fonts/novecento-bold.ttf') format('truetype');
|
||||
font-family: 'roboto-black';
|
||||
src: url('public/fonts/roboto-black.eot');
|
||||
src: url('public/fonts/roboto-black.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/roboto-black.woff') format('woff'),
|
||||
url('public/fonts/roboto-black.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ h1, h2, h3, h4, h5, h6 {
|
||||
color: #112233;
|
||||
line-height: 1em;
|
||||
font-weight: normal;
|
||||
font-family: "novecento-bold";
|
||||
font-family: "roboto-black";
|
||||
text-transform: uppercase;
|
||||
margin: 30px 0 15px 0;
|
||||
}
|
||||
@@ -75,6 +75,9 @@ h1, h2, h3, h4, h5, h6 {
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.26em;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
|
||||
@@ -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>
|
||||
@@ -460,7 +460,17 @@ they can also serve as keys in object literals.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">AlphaNumeric</span>: [
|
||||
o <span class="hljs-string">'NUMBER'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Literal $<span class="hljs-number">1</span>
|
||||
o <span class="hljs-string">'String'</span>
|
||||
]
|
||||
|
||||
<span class="hljs-attribute">String</span>: [
|
||||
o <span class="hljs-string">'STRING'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Literal $<span class="hljs-number">1</span>
|
||||
o <span class="hljs-string">'STRING_START Body STRING_END'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Parens $<span class="hljs-number">2</span>
|
||||
]
|
||||
|
||||
<span class="hljs-attribute">Regex</span>: [
|
||||
o <span class="hljs-string">'REGEX'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Literal $<span class="hljs-number">1</span>
|
||||
o <span class="hljs-string">'REGEX_START Invocation REGEX_END'</span>,<span class="hljs-function"> -></span> $<span class="hljs-number">2</span>
|
||||
]</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -480,7 +490,7 @@ through and printed to JavaScript.</p>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">Literal</span>: [
|
||||
o <span class="hljs-string">'AlphaNumeric'</span>
|
||||
o <span class="hljs-string">'JS'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Literal $<span class="hljs-number">1</span>
|
||||
o <span class="hljs-string">'REGEX'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Literal $<span class="hljs-number">1</span>
|
||||
o <span class="hljs-string">'Regex'</span>
|
||||
o <span class="hljs-string">'DEBUGGER'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Literal $<span class="hljs-number">1</span>
|
||||
o <span class="hljs-string">'UNDEFINED'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Undefined
|
||||
o <span class="hljs-string">'NULL'</span>,<span class="hljs-function"> -></span> <span class="hljs-keyword">new</span> Null
|
||||
@@ -1593,7 +1603,7 @@ precedence from low to high, and we have it high to low
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.parser = <span class="hljs-keyword">new</span> Parser
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.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>exports.s<span class="hljs-function"><span class="hljs-title">tarts</span> = <span class="hljs-params">(string, literal, start)</span> -></span>
|
||||
<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>
|
||||
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>exports.e<span class="hljs-function"><span class="hljs-title">nds</span> = <span class="hljs-params">(string, literal, back)</span> -></span>
|
||||
<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>
|
||||
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>exports.repeat = r<span class="hljs-function"><span class="hljs-title">epeat</span> = <span class="hljs-params">(str, n)</span> -></span></pre></div></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>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -202,7 +202,7 @@ arrays, count characters, that sort of thing.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
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>exports.c<span class="hljs-function"><span class="hljs-title">ount</span> = <span class="hljs-params">(string, substr)</span> -></span>
|
||||
<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>
|
||||
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>exports.m<span class="hljs-function"><span class="hljs-title">erge</span> = <span class="hljs-params">(options, overrides)</span> -></span>
|
||||
<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>
|
||||
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 = exports.e<span class="hljs-function"><span class="hljs-title">xtend</span> = <span class="hljs-params">(object, properties)</span> -></span>
|
||||
<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>
|
||||
<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>exports.flatten = f<span class="hljs-function"><span class="hljs-title">latten</span> = <span class="hljs-params">(array)</span> -></span>
|
||||
<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>
|
||||
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>exports.d<span class="hljs-function"><span class="hljs-title">el</span> = <span class="hljs-params">(obj, key)</span> -></span>
|
||||
<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>
|
||||
val = obj[key]
|
||||
<span class="hljs-keyword">delete</span> obj[key]
|
||||
val</pre></div></div>
|
||||
@@ -311,11 +311,13 @@ looking for a particular method in an options hash.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Gets the last item of an array(-like) object.</p>
|
||||
<p>Typical Array::some</p>
|
||||
|
||||
</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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -326,30 +328,13 @@ looking for a particular method in an options hash.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Typical Array::some</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Simple function for inverting Literate CoffeeScript code by putting the
|
||||
documentation in comments, producing a string of CoffeeScript code that
|
||||
can be compiled “normally”.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.i<span class="hljs-function"><span class="hljs-title">nvertLiterate</span> = <span class="hljs-params">(code)</span> -></span>
|
||||
<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>
|
||||
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
|
||||
@@ -363,11 +348,11 @@ can be compiled “normally”.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Merge two jison-style location data objects together.
|
||||
If <code>last</code> is not provided, this will simply return <code>first</code>.</p>
|
||||
@@ -386,11 +371,11 @@ If <code>last</code> is not provided, this will simply return <code>first</code>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>This returns a function which takes an object as a parameter, and if that
|
||||
object is an AST node, updates that object’s locationData.
|
||||
@@ -398,8 +383,8 @@ The object is returned either way.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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)
|
||||
|
||||
@@ -408,18 +393,18 @@ The object is returned either way.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>Convert jison location data to a string.
|
||||
<code>obj</code> can be a token, or a locationData.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.l<span class="hljs-function"><span class="hljs-title">ocationDataToString</span> = <span class="hljs-params">(obj)</span> -></span>
|
||||
<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>
|
||||
<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
|
||||
|
||||
@@ -432,18 +417,18 @@ The object is returned either way.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>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>
|
||||
<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>/
|
||||
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>
|
||||
@@ -455,17 +440,32 @@ The object is returned either way.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a CoffeeScript file.</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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a CoffeeScript file.</p>
|
||||
<p>Determine if a filename represents a Literate CoffeeScript file.</p>
|
||||
|
||||
</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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -476,11 +476,17 @@ The object is returned either way.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a Literate CoffeeScript file.</p>
|
||||
<p>Throws a SyntaxError from a given location.
|
||||
The error’s <code>toString</code> will return an error message following the “standard”
|
||||
format <filename>:<line>:<col>: <message> plus the line with the error and a
|
||||
marker showing where the error is.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>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>
|
||||
<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>
|
||||
error = <span class="hljs-keyword">new</span> SyntaxError message
|
||||
error.location = location
|
||||
error.toString = syntaxErrorToString</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -491,27 +497,6 @@ The object is returned either way.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Throws a SyntaxError from a given location.
|
||||
The error’s <code>toString</code> will return an error message following the “standard”
|
||||
format <filename>:<line>:<col>: <message> plus the line with the error and a
|
||||
marker showing where the error is.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Instead of showing the compiler’s stacktrace, show our custom error message
|
||||
(this is useful when the error bubbles up in Node.js applications that
|
||||
compile CoffeeScript for example).</p>
|
||||
@@ -525,27 +510,27 @@ compile CoffeeScript for example).</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Update a compiler SyntaxError with source code information if it didn’t have
|
||||
it already.</p>
|
||||
|
||||
</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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>Avoid screwing up the <code>stack</code> property of other errors (i.e. possible bugs).</p>
|
||||
|
||||
@@ -556,8 +541,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>
|
||||
@@ -571,11 +556,11 @@ it already.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Show only the first line on multi-line errors.</p>
|
||||
|
||||
@@ -587,11 +572,11 @@ it already.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
<p>Check to see if we’re running on a color-enabled TTY.</p>
|
||||
|
||||
@@ -601,7 +586,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 +596,7 @@ it already.</p>
|
||||
<span class="hljs-subst">#{marker}</span>
|
||||
"""</span>
|
||||
|
||||
exports.n<span class="hljs-function"><span class="hljs-title">ameWhitespaceCharacter</span> = <span class="hljs-params">(string)</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>
|
||||
<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>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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ are read by jison in the <code>parser.lexer</code> function defined in coffee-sc
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>{count, starts, compact, last, repeat, invertLiterate,
|
||||
<div class="content"><div class='highlight'><pre>{count, starts, compact, repeat, invertLiterate,
|
||||
locationDataToString, throwSyntaxError} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -185,7 +185,7 @@ pushing some extra smarts into the Lexer.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.Lexer = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Lexer</span></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Lexer = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Lexer</span></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -271,7 +271,7 @@ short-circuiting if any of them succeed. Their order determines precedence:
|
||||
<span class="hljs-keyword">return</span> {<span class="hljs-property">@tokens</span>, <span class="hljs-attribute">index</span>: i} <span class="hljs-keyword">if</span> opts.untilBalanced <span class="hljs-keyword">and</span> <span class="hljs-property">@ends</span>.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
|
||||
<span class="hljs-property">@closeIndentation</span>()
|
||||
throwSyntaxError <span class="hljs-string">"missing <span class="hljs-subst">#{end.tag}</span>"</span>, end.origin[<span class="hljs-number">2</span>] <span class="hljs-keyword">if</span> end = <span class="hljs-property">@ends</span>.pop()
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"missing <span class="hljs-subst">#{end.tag}</span>"</span>, end.origin[<span class="hljs-number">2</span>] <span class="hljs-keyword">if</span> end = <span class="hljs-property">@ends</span>.pop()
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@tokens</span> <span class="hljs-keyword">if</span> opts.rewrite <span class="hljs-keyword">is</span> <span class="hljs-literal">off</span>
|
||||
(<span class="hljs-keyword">new</span> Rewriter).rewrite <span class="hljs-property">@tokens</span></pre></div></div>
|
||||
|
||||
@@ -368,8 +368,9 @@ though <code>is</code> means <code>===</code> otherwise.</p>
|
||||
<span class="hljs-keyword">if</span> id <span class="hljs-keyword">is</span> <span class="hljs-string">'from'</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@tag</span>() <span class="hljs-keyword">is</span> <span class="hljs-string">'YIELD'</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'FROM'</span>, id
|
||||
<span class="hljs-keyword">return</span> id.length
|
||||
forcedIdentifier = colon <span class="hljs-keyword">or</span>
|
||||
(prev = last <span class="hljs-property">@tokens</span>) <span class="hljs-keyword">and</span> (prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">'.'</span>, <span class="hljs-string">'?.'</span>, <span class="hljs-string">'::'</span>, <span class="hljs-string">'?::'</span>] <span class="hljs-keyword">or</span>
|
||||
[..., prev] = <span class="hljs-property">@tokens</span>
|
||||
forcedIdentifier = colon <span class="hljs-keyword">or</span> prev? <span class="hljs-keyword">and</span>
|
||||
(prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">'.'</span>, <span class="hljs-string">'?.'</span>, <span class="hljs-string">'::'</span>, <span class="hljs-string">'?::'</span>] <span class="hljs-keyword">or</span>
|
||||
<span class="hljs-keyword">not</span> prev.spaced <span class="hljs-keyword">and</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'@'</span>)
|
||||
tag = <span class="hljs-string">'IDENTIFIER'</span>
|
||||
|
||||
@@ -399,7 +400,7 @@ though <code>is</code> means <code>===</code> otherwise.</p>
|
||||
id = <span class="hljs-keyword">new</span> String id
|
||||
id.reserved = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> id <span class="hljs-keyword">in</span> RESERVED
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"reserved word \"<span class="hljs-subst">#{id}</span>\""</span>
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"reserved word '<span class="hljs-subst">#{id}</span>'"</span>, <span class="hljs-attribute">length</span>: id.length
|
||||
|
||||
<span class="hljs-keyword">unless</span> forcedIdentifier
|
||||
id = COFFEE_ALIAS_MAP[id] <span class="hljs-keyword">if</span> id <span class="hljs-keyword">in</span> COFFEE_ALIASES
|
||||
@@ -439,15 +440,16 @@ Be careful not to interfere with ranges-in-progress.</p>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">numberToken</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span> <span class="hljs-keyword">unless</span> match = NUMBER.exec <span class="hljs-property">@chunk</span>
|
||||
number = match[<span class="hljs-number">0</span>]
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-regexp">/^0[BOX]/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"radix prefix '<span class="hljs-subst">#{number}</span>' must be lowercase"</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-regexp">/E/</span>.test(number) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-regexp">/^0x/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"exponential notation '<span class="hljs-subst">#{number}</span>' must be indicated with a lowercase 'e'"</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-regexp">/^0\d*[89]/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"decimal literal '<span class="hljs-subst">#{number}</span>' must not be prefixed with '0'"</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-regexp">/^0\d+/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"octal literal '<span class="hljs-subst">#{number}</span>' must be prefixed with '0o'"</span>
|
||||
lexedLength = number.length
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-regexp">/^0[BOX]/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"radix prefix in '<span class="hljs-subst">#{number}</span>' must be lowercase"</span>, <span class="hljs-attribute">offset</span>: <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-regexp">/E/</span>.test(number) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-regexp">/^0x/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"exponential notation in '<span class="hljs-subst">#{number}</span>' must be indicated with a lowercase 'e'"</span>,
|
||||
<span class="hljs-attribute">offset</span>: number.indexOf(<span class="hljs-string">'E'</span>)
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-regexp">/^0\d*[89]/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"decimal literal '<span class="hljs-subst">#{number}</span>' must not be prefixed with '0'"</span>, <span class="hljs-attribute">length</span>: lexedLength
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-regexp">/^0\d+/</span>.test number
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"octal literal '<span class="hljs-subst">#{number}</span>' must be prefixed with '0o'"</span>, <span class="hljs-attribute">length</span>: lexedLength
|
||||
<span class="hljs-keyword">if</span> octalLiteral = <span class="hljs-regexp">/^0o([0-7]+)/</span>.exec number
|
||||
number = <span class="hljs-string">'0x'</span> + parseInt(octalLiteral[<span class="hljs-number">1</span>], <span class="hljs-number">8</span>).toString <span class="hljs-number">16</span>
|
||||
<span class="hljs-keyword">if</span> binaryLiteral = <span class="hljs-regexp">/^0b([01]+)/</span>.exec number
|
||||
@@ -479,10 +481,10 @@ interpolation.</p>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'"""'</span> <span class="hljs-keyword">then</span> HEREDOC_DOUBLE
|
||||
heredoc = quote.length <span class="hljs-keyword">is</span> <span class="hljs-number">3</span>
|
||||
|
||||
start = quote.length
|
||||
{tokens, <span class="hljs-attribute">index</span>: end} = <span class="hljs-property">@matchWithInterpolations</span> <span class="hljs-property">@chunk</span>[start..], regex, quote, start
|
||||
{tokens, <span class="hljs-attribute">index</span>: end} = <span class="hljs-property">@matchWithInterpolations</span> regex, quote
|
||||
$ = tokens.length - <span class="hljs-number">1</span>
|
||||
|
||||
delimiter = quote[<span class="hljs-number">0</span>]
|
||||
<span class="hljs-keyword">if</span> heredoc</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -504,17 +506,16 @@ interpolation.</p>
|
||||
attempt = match[<span class="hljs-number">1</span>]
|
||||
indent = attempt <span class="hljs-keyword">if</span> indent <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">or</span> <span class="hljs-number">0</span> < attempt.length < indent.length
|
||||
indentRegex = <span class="hljs-regexp">/// ^<span class="hljs-subst">#{indent}</span> ///</span>gm <span class="hljs-keyword">if</span> indent
|
||||
<span class="hljs-property">@mergeInterpolationTokens</span> tokens, {<span class="hljs-attribute">quote</span>: quote[<span class="hljs-number">0</span>], start, end}, <span class="hljs-function"><span class="hljs-params">(value, i)</span> =></span>
|
||||
<span class="hljs-property">@mergeInterpolationTokens</span> tokens, {delimiter}, <span class="hljs-function"><span class="hljs-params">(value, i)</span> =></span>
|
||||
value = <span class="hljs-property">@formatString</span> value
|
||||
value = value.replace LEADING_BLANK_LINE, <span class="hljs-string">''</span> <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
value = value.replace TRAILING_BLANK_LINE, <span class="hljs-string">''</span> <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> $
|
||||
value = value.replace indentRegex, <span class="hljs-string">''</span>
|
||||
value = value.replace MULTILINER, <span class="hljs-string">'\\n'</span>
|
||||
value = value.replace indentRegex, <span class="hljs-string">''</span> <span class="hljs-keyword">if</span> indentRegex
|
||||
value
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-property">@mergeInterpolationTokens</span> tokens, {quote, start, end}, <span class="hljs-function"><span class="hljs-params">(value, i)</span> =></span>
|
||||
<span class="hljs-property">@mergeInterpolationTokens</span> tokens, {delimiter}, <span class="hljs-function"><span class="hljs-params">(value, i)</span> =></span>
|
||||
value = <span class="hljs-property">@formatString</span> value
|
||||
value = value.replace STRING_OMIT, <span class="hljs-function"><span class="hljs-params">(match, offset)</span> -></span>
|
||||
value = value.replace SIMPLE_STRING_OMIT, <span class="hljs-function"><span class="hljs-params">(match, offset)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> (i <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> offset <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>) <span class="hljs-keyword">or</span>
|
||||
(i <span class="hljs-keyword">is</span> $ <span class="hljs-keyword">and</span> offset + match.length <span class="hljs-keyword">is</span> value.length)
|
||||
<span class="hljs-string">''</span>
|
||||
@@ -542,7 +543,8 @@ interpolation.</p>
|
||||
[comment, here] = match
|
||||
<span class="hljs-keyword">if</span> here
|
||||
<span class="hljs-keyword">if</span> match = HERECOMMENT_ILLEGAL.exec comment
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"block comments cannot contain <span class="hljs-subst">#{match[<span class="hljs-number">0</span>]}</span>"</span>, match.index
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"block comments cannot contain <span class="hljs-subst">#{match[<span class="hljs-number">0</span>]}</span>"</span>,
|
||||
<span class="hljs-attribute">offset</span>: match.index, <span class="hljs-attribute">length</span>: match[<span class="hljs-number">0</span>].length
|
||||
<span class="hljs-keyword">if</span> here.indexOf(<span class="hljs-string">'\n'</span>) >= <span class="hljs-number">0</span>
|
||||
here = here.replace <span class="hljs-regexp">/// \n <span class="hljs-subst">#{repeat <span class="hljs-string">' '</span>, <span class="hljs-property">@indent</span>}</span> ///</span>g, <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'HERECOMMENT'</span>, here, <span class="hljs-number">0</span>, comment.length
|
||||
@@ -584,15 +586,17 @@ borrow some basic heuristics from JavaScript and Ruby.</p>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">regexToken</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-keyword">switch</span>
|
||||
<span class="hljs-keyword">when</span> match = REGEX_ILLEGAL.exec <span class="hljs-property">@chunk</span>
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"regular expressions cannot begin with <span class="hljs-subst">#{match[<span class="hljs-number">2</span>]}</span>"</span>, match.index + match[<span class="hljs-number">1</span>].length
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-property">@chunk</span>[..<span class="hljs-number">.3</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'///'</span>
|
||||
{tokens, index} = <span class="hljs-property">@matchWithInterpolations</span> <span class="hljs-property">@chunk</span>[<span class="hljs-number">3.</span>.], HEREGEX, <span class="hljs-string">'///'</span>, <span class="hljs-number">3</span>
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"regular expressions cannot begin with <span class="hljs-subst">#{match[<span class="hljs-number">2</span>]}</span>"</span>,
|
||||
<span class="hljs-attribute">offset</span>: match.index + match[<span class="hljs-number">1</span>].length
|
||||
<span class="hljs-keyword">when</span> match = <span class="hljs-property">@matchWithInterpolations</span> HEREGEX, <span class="hljs-string">'///'</span>
|
||||
{tokens, index} = match
|
||||
<span class="hljs-keyword">when</span> match = REGEX.exec <span class="hljs-property">@chunk</span>
|
||||
[regex, closed] = match
|
||||
[regex, body, closed] = match
|
||||
<span class="hljs-property">@validateEscapes</span> body, <span class="hljs-attribute">isRegex</span>: <span class="hljs-literal">yes</span>, <span class="hljs-attribute">offsetInChunk</span>: <span class="hljs-number">1</span>
|
||||
index = regex.length
|
||||
prev = last <span class="hljs-property">@tokens</span>
|
||||
[..., prev] = <span class="hljs-property">@tokens</span>
|
||||
<span class="hljs-keyword">if</span> prev
|
||||
<span class="hljs-keyword">if</span> prev.spaced <span class="hljs-keyword">and</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> CALLABLE <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> prev.stringEnd <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> prev.regexEnd
|
||||
<span class="hljs-keyword">if</span> prev.spaced <span class="hljs-keyword">and</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> CALLABLE
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> closed <span class="hljs-keyword">or</span> POSSIBLY_DIVISION.test regex
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> NOT_REGEX
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
|
||||
@@ -602,24 +606,23 @@ borrow some basic heuristics from JavaScript and Ruby.</p>
|
||||
|
||||
[flags] = REGEX_FLAGS.exec <span class="hljs-property">@chunk</span>[index..]
|
||||
end = index + flags.length
|
||||
origin = <span class="hljs-property">@makeToken</span> <span class="hljs-string">'REGEX'</span>, <span class="hljs-literal">null</span>, <span class="hljs-number">0</span>, end
|
||||
<span class="hljs-keyword">switch</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-keyword">not</span> VALID_FLAGS.test flags
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"invalid regular expression flags <span class="hljs-subst">#{flags}</span>"</span>, index
|
||||
<span class="hljs-keyword">when</span> regex
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">"<span class="hljs-subst">#{regex}</span><span class="hljs-subst">#{flags}</span>"</span>
|
||||
<span class="hljs-keyword">when</span> tokens.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span>
|
||||
re = <span class="hljs-property">@formatHeregex</span>(tokens[<span class="hljs-number">0</span>][<span class="hljs-number">1</span>]).replace(<span class="hljs-regexp">/\//g</span>, <span class="hljs-string">'\\/'</span>)
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">"/<span class="hljs-subst">#{ re <span class="hljs-keyword">or</span> <span class="hljs-string">'(?:)'</span> }</span>/<span class="hljs-subst">#{flags}</span>"</span>
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"invalid regular expression flags <span class="hljs-subst">#{flags}</span>"</span>, <span class="hljs-attribute">offset</span>: index, <span class="hljs-attribute">length</span>: flags.length
|
||||
<span class="hljs-keyword">when</span> regex <span class="hljs-keyword">or</span> tokens.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span>
|
||||
body ?= <span class="hljs-property">@formatHeregex</span> tokens[<span class="hljs-number">0</span>][<span class="hljs-number">1</span>]
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@makeDelimitedLiteral</span> body, delimiter: <span class="hljs-string">'/'</span>}</span><span class="hljs-subst">#{flags}</span>"</span>, <span class="hljs-number">0</span>, end, origin
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'REGEX_START'</span>, <span class="hljs-string">'('</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, origin
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'IDENTIFIER'</span>, <span class="hljs-string">'RegExp'</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'CALL_START'</span>, <span class="hljs-string">'('</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>
|
||||
<span class="hljs-property">@mergeInterpolationTokens</span> tokens, {<span class="hljs-attribute">quote</span>: <span class="hljs-string">'"'</span>, <span class="hljs-attribute">start</span>: <span class="hljs-number">3</span>, end}, <span class="hljs-function"><span class="hljs-params">(value)</span> =></span>
|
||||
<span class="hljs-property">@formatHeregex</span>(value).replace(<span class="hljs-regexp">/\\/g</span>, <span class="hljs-string">'\\\\'</span>)
|
||||
<span class="hljs-property">@mergeInterpolationTokens</span> tokens, {<span class="hljs-attribute">delimiter</span>: <span class="hljs-string">'"'</span>, <span class="hljs-attribute">double</span>: <span class="hljs-literal">yes</span>}, <span class="hljs-property">@formatHeregex</span>
|
||||
<span class="hljs-keyword">if</span> flags
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">','</span>, <span class="hljs-string">','</span>, index, <span class="hljs-number">0</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'"'</span> + flags + <span class="hljs-string">'"'</span>, index, flags.length
|
||||
rparen = <span class="hljs-property">@token</span> <span class="hljs-string">')'</span>, <span class="hljs-string">')'</span>, end, <span class="hljs-number">0</span>
|
||||
rparen.regexEnd = <span class="hljs-literal">true</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">')'</span>, <span class="hljs-string">')'</span>, end, <span class="hljs-number">0</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'REGEX_END'</span>, <span class="hljs-string">')'</span>, end, <span class="hljs-number">0</span>
|
||||
|
||||
end</pre></div></div>
|
||||
|
||||
@@ -668,7 +671,7 @@ can close multiple indents, so we need to know how far in we happen to be.</p>
|
||||
<span class="hljs-property">@outdebt</span> = <span class="hljs-property">@indebt</span> = <span class="hljs-number">0</span>
|
||||
<span class="hljs-property">@indent</span> = size
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> size < <span class="hljs-property">@baseIndent</span>
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">'missing indentation'</span>, indent.length
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">'missing indentation'</span>, <span class="hljs-attribute">offset</span>: indent.length
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-property">@indebt</span> = <span class="hljs-number">0</span>
|
||||
<span class="hljs-property">@outdentToken</span> <span class="hljs-property">@indent</span> - size, noNewlines, indent.length
|
||||
@@ -747,7 +750,7 @@ as being “spaced”, because there are some cases where it makes a difference.
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">whitespaceToken</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span> <span class="hljs-keyword">unless</span> (match = WHITESPACE.exec <span class="hljs-property">@chunk</span>) <span class="hljs-keyword">or</span>
|
||||
(nline = <span class="hljs-property">@chunk</span>.charAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'\n'</span>)
|
||||
prev = last <span class="hljs-property">@tokens</span>
|
||||
[..., prev] = <span class="hljs-property">@tokens</span>
|
||||
prev[<span class="hljs-keyword">if</span> match <span class="hljs-keyword">then</span> <span class="hljs-string">'spaced'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'newLine'</span>] = <span class="hljs-literal">true</span> <span class="hljs-keyword">if</span> prev
|
||||
<span class="hljs-keyword">if</span> match <span class="hljs-keyword">then</span> match[<span class="hljs-number">0</span>].length <span class="hljs-keyword">else</span> <span class="hljs-number">0</span></pre></div></div>
|
||||
|
||||
@@ -811,10 +814,10 @@ parentheses that indicate a method call from regular parentheses, and so on.</p>
|
||||
<span class="hljs-keyword">else</span>
|
||||
value = <span class="hljs-property">@chunk</span>.charAt <span class="hljs-number">0</span>
|
||||
tag = value
|
||||
prev = last <span class="hljs-property">@tokens</span>
|
||||
[..., prev] = <span class="hljs-property">@tokens</span>
|
||||
<span class="hljs-keyword">if</span> value <span class="hljs-keyword">is</span> <span class="hljs-string">'='</span> <span class="hljs-keyword">and</span> prev
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> prev[<span class="hljs-number">1</span>].reserved <span class="hljs-keyword">and</span> prev[<span class="hljs-number">1</span>] <span class="hljs-keyword">in</span> JS_FORBIDDEN
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"reserved word \"<span class="hljs-subst">#{<span class="hljs-property">@value</span>()}</span>\" can't be assigned"</span>
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"reserved word '<span class="hljs-subst">#{prev[<span class="hljs-number">1</span>]}</span>' can't be assigned"</span>, prev[<span class="hljs-number">2</span>]
|
||||
<span class="hljs-keyword">if</span> prev[<span class="hljs-number">1</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">'||'</span>, <span class="hljs-string">'&&'</span>]
|
||||
prev[<span class="hljs-number">0</span>] = <span class="hljs-string">'COMPOUND_ASSIGN'</span>
|
||||
prev[<span class="hljs-number">1</span>] += <span class="hljs-string">'='</span>
|
||||
@@ -830,7 +833,7 @@ parentheses that indicate a method call from regular parentheses, and so on.</p>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> value <span class="hljs-keyword">in</span> SHIFT <span class="hljs-keyword">then</span> tag = <span class="hljs-string">'SHIFT'</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> value <span class="hljs-keyword">in</span> LOGIC <span class="hljs-keyword">or</span> value <span class="hljs-keyword">is</span> <span class="hljs-string">'?'</span> <span class="hljs-keyword">and</span> prev?.spaced <span class="hljs-keyword">then</span> tag = <span class="hljs-string">'LOGIC'</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> prev <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> prev.spaced
|
||||
<span class="hljs-keyword">if</span> value <span class="hljs-keyword">is</span> <span class="hljs-string">'('</span> <span class="hljs-keyword">and</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> CALLABLE <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> prev.stringEnd <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> prev.regexEnd
|
||||
<span class="hljs-keyword">if</span> value <span class="hljs-keyword">is</span> <span class="hljs-string">'('</span> <span class="hljs-keyword">and</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> CALLABLE
|
||||
prev[<span class="hljs-number">0</span>] = <span class="hljs-string">'FUNC_EXIST'</span> <span class="hljs-keyword">if</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'?'</span>
|
||||
tag = <span class="hljs-string">'CALL_START'</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> value <span class="hljs-keyword">is</span> <span class="hljs-string">'['</span> <span class="hljs-keyword">and</span> prev[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> INDEXABLE
|
||||
@@ -934,24 +937,25 @@ expressions.</p>
|
||||
</code></pre><p>If it encounters an interpolation, this method will recursively create a new
|
||||
Lexer and tokenize until the <code>{</code> of <code>#{</code> is balanced with a <code>}</code>.</p>
|
||||
<ul>
|
||||
<li><code>str</code> is the start of the token contents (with the starting delimiter
|
||||
stripped off.)</li>
|
||||
<li><code>regex</code> matches the contents of a token (but not <code>end</code>, and not <code>#{</code> if
|
||||
interpolations are desired).</li>
|
||||
<li><code>end</code> is the terminator of the token.</li>
|
||||
<li><code>offsetInChunk</code> is the start of the interpolated string in the current
|
||||
chunk, including the starting delimiter.</li>
|
||||
<li><code>regex</code> matches the contents of a token (but not <code>delimiter</code>, and not
|
||||
<code>#{</code> if interpolations are desired).</li>
|
||||
<li><code>delimiter</code> is the delimiter of the token. Examples are <code>'</code>, <code>"</code>, <code>'''</code>,
|
||||
<code>"""</code> and <code>///</code>.</li>
|
||||
</ul>
|
||||
<p>Examples of delimiters are <code>'</code>, <code>"</code>, <code>'''</code>, <code>"""</code> and <code>///</code>.</p>
|
||||
<p>This method allows us to have strings within interpolations within strings,
|
||||
ad infinitum.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">matchWithInterpolations</span>: <span class="hljs-function"><span class="hljs-params">(str, regex, end, offsetInChunk)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">matchWithInterpolations</span>: <span class="hljs-function"><span class="hljs-params">(regex, delimiter)</span> -></span>
|
||||
tokens = []
|
||||
offsetInChunk = delimiter.length
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@chunk</span>[...offsetInChunk] <span class="hljs-keyword">is</span> delimiter
|
||||
str = <span class="hljs-property">@chunk</span>[offsetInChunk..]
|
||||
<span class="hljs-keyword">loop</span>
|
||||
[strPart] = regex.exec str</pre></div></div>
|
||||
[strPart] = regex.exec str
|
||||
|
||||
<span class="hljs-property">@validateEscapes</span> strPart, {<span class="hljs-attribute">isRegex</span>: delimiter.charAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'/'</span>, offsetInChunk}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1057,10 +1061,15 @@ parentheses will be removed later.</p>
|
||||
str = str[index..]
|
||||
offsetInChunk += index
|
||||
|
||||
<span class="hljs-keyword">unless</span> str[...end.length] <span class="hljs-keyword">is</span> end
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"missing <span class="hljs-subst">#{end}</span>"</span>
|
||||
<span class="hljs-keyword">unless</span> str[...delimiter.length] <span class="hljs-keyword">is</span> delimiter
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"missing <span class="hljs-subst">#{delimiter}</span>"</span>, <span class="hljs-attribute">length</span>: delimiter.length
|
||||
|
||||
{tokens, <span class="hljs-attribute">index</span>: offsetInChunk + end.length}</pre></div></div>
|
||||
[firstToken, ..., lastToken] = tokens
|
||||
firstToken[<span class="hljs-number">2</span>].first_column -= delimiter.length
|
||||
lastToken[<span class="hljs-number">2</span>].last_column += delimiter.length
|
||||
lastToken[<span class="hljs-number">2</span>].last_column -= <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> lastToken[<span class="hljs-number">1</span>].length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
|
||||
{tokens, <span class="hljs-attribute">index</span>: offsetInChunk + delimiter.length}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1074,15 +1083,13 @@ parentheses will be removed later.</p>
|
||||
<p>Merge the array <code>tokens</code> of the fake token types ‘TOKENS’ and ‘NEOSTRING’
|
||||
(as returned by <code>matchWithInterpolations</code>) into the token stream. The value
|
||||
of ‘NEOSTRING’s are converted using <code>fn</code> and turned into strings using
|
||||
<code>quote</code> first. The tokens are wrapped in parentheses if needed, using
|
||||
<code>start</code> and <code>end</code> for their location data.</p>
|
||||
<code>options</code> first.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">mergeInterpolationTokens</span>: <span class="hljs-function"><span class="hljs-params">(tokens, {quote, start, end}, fn)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> interpolated = tokens.length > <span class="hljs-number">1</span>
|
||||
errorToken = <span class="hljs-property">@makeToken</span> <span class="hljs-string">''</span>, <span class="hljs-string">'interpolation'</span>, start + tokens[<span class="hljs-number">0</span>][<span class="hljs-number">1</span>].length, <span class="hljs-number">2</span>
|
||||
<span class="hljs-property">@token</span> <span class="hljs-string">'('</span>, <span class="hljs-string">'('</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, errorToken
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">mergeInterpolationTokens</span>: <span class="hljs-function"><span class="hljs-params">(tokens, options, fn)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> tokens.length > <span class="hljs-number">1</span>
|
||||
lparen = <span class="hljs-property">@token</span> <span class="hljs-string">'STRING_START'</span>, <span class="hljs-string">'('</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>
|
||||
|
||||
firstIndex = <span class="hljs-property">@tokens</span>.length
|
||||
<span class="hljs-keyword">for</span> token, i <span class="hljs-keyword">in</span> tokens
|
||||
@@ -1176,7 +1183,7 @@ empty string.</p>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> firstEmptyStringIndex?
|
||||
<span class="hljs-property">@tokens</span>.splice firstEmptyStringIndex, <span class="hljs-number">2</span> <span class="hljs-comment"># Remove empty string and the plus.</span>
|
||||
token[<span class="hljs-number">0</span>] = <span class="hljs-string">'STRING'</span>
|
||||
token[<span class="hljs-number">1</span>] = <span class="hljs-property">@makeString</span> converted, quote
|
||||
token[<span class="hljs-number">1</span>] = <span class="hljs-property">@makeDelimitedLiteral</span> converted, options
|
||||
locationToken = token
|
||||
tokensToPush = [token]
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@tokens</span>.length > firstIndex</pre></div></div>
|
||||
@@ -1202,9 +1209,20 @@ empty string.</p>
|
||||
<span class="hljs-attribute">last_column</span>: locationToken[<span class="hljs-number">2</span>].first_column
|
||||
<span class="hljs-property">@tokens</span>.push tokensToPush...
|
||||
|
||||
<span class="hljs-keyword">if</span> interpolated
|
||||
rparen = <span class="hljs-property">@token</span> <span class="hljs-string">')'</span>, <span class="hljs-string">')'</span>, end, <span class="hljs-number">0</span>
|
||||
rparen.stringEnd = <span class="hljs-literal">true</span></pre></div></div>
|
||||
<span class="hljs-keyword">if</span> lparen
|
||||
[..., lastToken] = tokens
|
||||
lparen.origin = [<span class="hljs-string">'STRING'</span>, <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attribute">first_line</span>: lparen[<span class="hljs-number">2</span>].first_line
|
||||
<span class="hljs-attribute">first_column</span>: lparen[<span class="hljs-number">2</span>].first_column
|
||||
<span class="hljs-attribute">last_line</span>: lastToken[<span class="hljs-number">2</span>].last_line
|
||||
<span class="hljs-attribute">last_column</span>: lastToken[<span class="hljs-number">2</span>].last_column
|
||||
]
|
||||
rparen = <span class="hljs-property">@token</span> <span class="hljs-string">'STRING_END'</span>, <span class="hljs-string">')'</span>
|
||||
rparen[<span class="hljs-number">2</span>] =
|
||||
<span class="hljs-attribute">first_line</span>: lastToken[<span class="hljs-number">2</span>].last_line
|
||||
<span class="hljs-attribute">first_column</span>: lastToken[<span class="hljs-number">2</span>].last_column
|
||||
<span class="hljs-attribute">last_line</span>: lastToken[<span class="hljs-number">2</span>].last_line
|
||||
<span class="hljs-attribute">last_column</span>: lastToken[<span class="hljs-number">2</span>].last_column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1221,7 +1239,8 @@ correctly balanced throughout the course of the token stream.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">pair</span>: <span class="hljs-function"><span class="hljs-params">(tag)</span> -></span>
|
||||
<span class="hljs-keyword">unless</span> tag <span class="hljs-keyword">is</span> wanted = last(<span class="hljs-property">@ends</span>)?.tag
|
||||
[..., prev] = <span class="hljs-property">@ends</span>
|
||||
<span class="hljs-keyword">unless</span> tag <span class="hljs-keyword">is</span> wanted = prev?.tag
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"unmatched <span class="hljs-subst">#{tag}</span>"</span> <span class="hljs-keyword">unless</span> <span class="hljs-string">'OUTDENT'</span> <span class="hljs-keyword">is</span> wanted</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -1234,12 +1253,13 @@ correctly balanced throughout the course of the token stream.</p>
|
||||
<a class="pilcrow" href="#section-46">¶</a>
|
||||
</div>
|
||||
<p>Auto-close INDENT to support syntax like this:</p>
|
||||
<pre><code>el.click(<span class="hljs-function"><span class="hljs-params">(event)</span> -></span>
|
||||
el.hide())
|
||||
<pre><code>el.click<span class="hljs-function"><span class="hljs-params">((event) ->
|
||||
el.hide())</span></span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-property">@outdentToken</span> last(<span class="hljs-property">@indents</span>), <span class="hljs-literal">true</span>
|
||||
<div class="content"><div class='highlight'><pre> [..., lastIndent] = <span class="hljs-property">@indents</span>
|
||||
<span class="hljs-property">@outdentToken</span> lastIndent, <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@pair</span> tag
|
||||
<span class="hljs-property">@ends</span>.pop()</pre></div></div>
|
||||
|
||||
@@ -1295,8 +1315,8 @@ correctly balanced throughout the course of the token stream.</p>
|
||||
|
||||
column = <span class="hljs-property">@chunkColumn</span>
|
||||
<span class="hljs-keyword">if</span> lineCount > <span class="hljs-number">0</span>
|
||||
lines = string.split <span class="hljs-string">'\n'</span>
|
||||
column = last(lines).length
|
||||
[..., lastLine] = string.split <span class="hljs-string">'\n'</span>
|
||||
column = lastLine.length
|
||||
<span class="hljs-keyword">else</span>
|
||||
column += string.length
|
||||
|
||||
@@ -1375,12 +1395,13 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-53">¶</a>
|
||||
</div>
|
||||
<p>Peek at a tag in the current token stream.</p>
|
||||
<p>Peek at the last tag in the token stream.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">tag</span>: <span class="hljs-function"><span class="hljs-params">(index, tag)</span> -></span>
|
||||
(tok = last <span class="hljs-property">@tokens</span>, index) <span class="hljs-keyword">and</span> <span class="hljs-keyword">if</span> tag <span class="hljs-keyword">then</span> tok[<span class="hljs-number">0</span>] = tag <span class="hljs-keyword">else</span> tok[<span class="hljs-number">0</span>]</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">tag</span>:<span class="hljs-function"> -></span>
|
||||
[..., token] = <span class="hljs-property">@tokens</span>
|
||||
token?[<span class="hljs-number">0</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1391,12 +1412,13 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-54">¶</a>
|
||||
</div>
|
||||
<p>Peek at a value in the current token stream.</p>
|
||||
<p>Peek at the last value in the token stream.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">value</span>: <span class="hljs-function"><span class="hljs-params">(index, val)</span> -></span>
|
||||
(tok = last <span class="hljs-property">@tokens</span>, index) <span class="hljs-keyword">and</span> <span class="hljs-keyword">if</span> val <span class="hljs-keyword">then</span> tok[<span class="hljs-number">1</span>] = val <span class="hljs-keyword">else</span> tok[<span class="hljs-number">1</span>]</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">value</span>:<span class="hljs-function"> -></span>
|
||||
[..., token] = <span class="hljs-property">@tokens</span>
|
||||
token?[<span class="hljs-number">1</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1416,7 +1438,11 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<span class="hljs-property">@tag</span>() <span class="hljs-keyword">in</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">'UNARY'</span>, <span class="hljs-string">'MATH'</span>, <span class="hljs-string">'UNARY_MATH'</span>, <span class="hljs-string">'+'</span>, <span class="hljs-string">'-'</span>, <span class="hljs-string">'YIELD'</span>,
|
||||
<span class="hljs-string">'**'</span>, <span class="hljs-string">'SHIFT'</span>, <span class="hljs-string">'RELATION'</span>, <span class="hljs-string">'COMPARE'</span>, <span class="hljs-string">'LOGIC'</span>, <span class="hljs-string">'THROW'</span>, <span class="hljs-string">'EXTENDS'</span>]
|
||||
|
||||
<span class="hljs-attribute">formatString</span>: <span class="hljs-function"><span class="hljs-params">(str)</span> -></span></pre></div></div>
|
||||
<span class="hljs-attribute">formatString</span>: <span class="hljs-function"><span class="hljs-params">(str)</span> -></span>
|
||||
str.replace STRING_OMIT, <span class="hljs-string">'$1'</span>
|
||||
|
||||
<span class="hljs-attribute">formatHeregex</span>: <span class="hljs-function"><span class="hljs-params">(str)</span> -></span>
|
||||
str.replace HEREGEX_OMIT, <span class="hljs-string">'$1$2'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1427,15 +1453,24 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-56">¶</a>
|
||||
</div>
|
||||
<p>Ignore escaped backslashes and remove escaped newlines.</p>
|
||||
<p>Validates escapes in strings and regexes.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> str.replace <span class="hljs-regexp">/\\[^\S\n]*(\n|\\)\s*/g</span>, <span class="hljs-function"><span class="hljs-params">(escaped, character)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> character <span class="hljs-keyword">is</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">''</span> <span class="hljs-keyword">else</span> escaped
|
||||
|
||||
<span class="hljs-attribute">formatHeregex</span>: <span class="hljs-function"><span class="hljs-params">(str)</span> -></span>
|
||||
str.replace(HEREGEX_OMIT, <span class="hljs-string">'$1$2'</span>).replace(MULTILINER, <span class="hljs-string">'\\n'</span>)</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">validateEscapes</span>: <span class="hljs-function"><span class="hljs-params">(str, options = {})</span> -></span>
|
||||
match = INVALID_ESCAPE.exec str
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> match
|
||||
[[], before, octal, hex, unicode] = match
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> options.isRegex <span class="hljs-keyword">and</span> octal <span class="hljs-keyword">and</span> octal.charAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">isnt</span> <span class="hljs-string">'0'</span>
|
||||
message =
|
||||
<span class="hljs-keyword">if</span> octal
|
||||
<span class="hljs-string">"octal escape sequences are not allowed"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">"invalid escape sequence"</span>
|
||||
invalidEscape = <span class="hljs-string">"\\<span class="hljs-subst">#{octal <span class="hljs-keyword">or</span> hex <span class="hljs-keyword">or</span> unicode}</span>"</span>
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"<span class="hljs-subst">#{message}</span> <span class="hljs-subst">#{invalidEscape}</span>"</span>,
|
||||
<span class="hljs-attribute">offset</span>: (options.offsetInChunk ? <span class="hljs-number">0</span>) + match.index + before.length
|
||||
<span class="hljs-attribute">length</span>: invalidEscape.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1446,12 +1481,20 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-57">¶</a>
|
||||
</div>
|
||||
<p>Constructs a string token by escaping quotes.</p>
|
||||
<p>Constructs a string or regex by escaping certain characters.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">makeString</span>: <span class="hljs-function"><span class="hljs-params">(body, quote)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> quote + quote <span class="hljs-keyword">unless</span> body</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">makeDelimitedLiteral</span>: <span class="hljs-function"><span class="hljs-params">(body, options = {})</span> -></span>
|
||||
body = <span class="hljs-string">'(?:)'</span> <span class="hljs-keyword">if</span> body <span class="hljs-keyword">is</span> <span class="hljs-string">''</span> <span class="hljs-keyword">and</span> options.delimiter <span class="hljs-keyword">is</span> <span class="hljs-string">'/'</span>
|
||||
regex = <span class="hljs-regexp">///
|
||||
(\\\\) <span class="hljs-comment"># escaped backslash</span>
|
||||
| (\\0(?=[1-7])) <span class="hljs-comment"># nul character mistaken as octal escape</span>
|
||||
| \\?(<span class="hljs-subst">#{options.delimiter}</span>) <span class="hljs-comment"># (possibly escaped) delimiter</span>
|
||||
| \\?(?: (\n)|(\r)|(\u2028)|(\u2029) ) <span class="hljs-comment"># (possibly escaped) newlines</span>
|
||||
| (\\.) <span class="hljs-comment"># other escapes</span>
|
||||
///</span>g
|
||||
body = body.replace regex, <span class="hljs-function"><span class="hljs-params">(match, backslash, nul, delimiter, lf, cr, ls, ps, other)</span> -></span> <span class="hljs-keyword">switch</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1462,16 +1505,19 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-58">¶</a>
|
||||
</div>
|
||||
<p>Ignore escaped backslashes and unescape quotes.</p>
|
||||
<p>Ignore escaped backslashes.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> body = body.replace <span class="hljs-regexp">/// \\( <span class="hljs-subst">#{quote}</span> | \\ ) ///</span>g, <span class="hljs-function"><span class="hljs-params">(match, contents)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> contents <span class="hljs-keyword">is</span> quote <span class="hljs-keyword">then</span> contents <span class="hljs-keyword">else</span> match
|
||||
body = body.replace <span class="hljs-regexp">/// <span class="hljs-subst">#{quote}</span> ///</span>g, <span class="hljs-string">'\\$&'</span>
|
||||
<span class="hljs-keyword">if</span> match = OCTAL_ESCAPE.exec body
|
||||
<span class="hljs-property">@error</span> <span class="hljs-string">"octal escape sequences are not allowed <span class="hljs-subst">#{match[<span class="hljs-number">2</span>]}</span>"</span>, match.index + match[<span class="hljs-number">1</span>].length + <span class="hljs-number">1</span>
|
||||
quote + body + quote</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">when</span> backslash <span class="hljs-keyword">then</span> (<span class="hljs-keyword">if</span> options.double <span class="hljs-keyword">then</span> backslash + backslash <span class="hljs-keyword">else</span> backslash)
|
||||
<span class="hljs-keyword">when</span> nul <span class="hljs-keyword">then</span> <span class="hljs-string">'\\x00'</span>
|
||||
<span class="hljs-keyword">when</span> delimiter <span class="hljs-keyword">then</span> <span class="hljs-string">"\\<span class="hljs-subst">#{delimiter}</span>"</span>
|
||||
<span class="hljs-keyword">when</span> lf <span class="hljs-keyword">then</span> <span class="hljs-string">'\\n'</span>
|
||||
<span class="hljs-keyword">when</span> cr <span class="hljs-keyword">then</span> <span class="hljs-string">'\\r'</span>
|
||||
<span class="hljs-keyword">when</span> ls <span class="hljs-keyword">then</span> <span class="hljs-string">'\\u2028'</span>
|
||||
<span class="hljs-keyword">when</span> ps <span class="hljs-keyword">then</span> <span class="hljs-string">'\\u2029'</span>
|
||||
<span class="hljs-keyword">when</span> other <span class="hljs-keyword">then</span> (<span class="hljs-keyword">if</span> options.double <span class="hljs-keyword">then</span> <span class="hljs-string">"\\<span class="hljs-subst">#{other}</span>"</span> <span class="hljs-keyword">else</span> other)
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{options.delimiter}</span><span class="hljs-subst">#{body}</span><span class="hljs-subst">#{options.delimiter}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1482,11 +1528,19 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-59">¶</a>
|
||||
</div>
|
||||
<p>Throws a compiler error on the current position.</p>
|
||||
<p>Throws an error at either a given offset from the current chunk or at the
|
||||
location of a token (<code>token[2]</code>).</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">error</span>: <span class="hljs-function"><span class="hljs-params">(message, offset = <span class="hljs-number">0</span>)</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">error</span>: <span class="hljs-function"><span class="hljs-params">(message, options = {})</span> -></span>
|
||||
location =
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-string">'first_line'</span> <span class="hljs-keyword">of</span> options
|
||||
options
|
||||
<span class="hljs-keyword">else</span>
|
||||
[first_line, first_column] = <span class="hljs-property">@getLineAndColumnFromChunk</span> options.offset ? <span class="hljs-number">0</span>
|
||||
{first_line, first_column, <span class="hljs-attribute">last_column</span>: first_column + (options.length ? <span class="hljs-number">1</span>) - <span class="hljs-number">1</span>}
|
||||
throwSyntaxError message, location</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1497,14 +1551,10 @@ not specified, the length of <code>value</code> will be used.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-60">¶</a>
|
||||
</div>
|
||||
<p>TODO: Are there some cases we could improve the error line number by
|
||||
passing the offset in the chunk where the error happened?</p>
|
||||
<h2 id="constants">Constants</h2>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> [first_line, first_column] = <span class="hljs-property">@getLineAndColumnFromChunk</span> offset
|
||||
throwSyntaxError message, {first_line, first_column}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -1514,8 +1564,7 @@ passing the offset in the chunk where the error happened?</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-61">¶</a>
|
||||
</div>
|
||||
<h2 id="constants">Constants</h2>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
@@ -1527,18 +1576,6 @@ passing the offset in the chunk where the error happened?</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-62">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-63">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-63">¶</a>
|
||||
</div>
|
||||
<p>Keywords that CoffeeScript shares in common with JavaScript.</p>
|
||||
|
||||
</div>
|
||||
@@ -1554,11 +1591,11 @@ passing the offset in the chunk where the error happened?</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-64">
|
||||
<li id="section-63">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-64">¶</a>
|
||||
<a class="pilcrow" href="#section-63">¶</a>
|
||||
</div>
|
||||
<p>CoffeeScript-only keywords.</p>
|
||||
|
||||
@@ -1583,11 +1620,11 @@ COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat COFFEE_ALIASES</pre></div></div>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-65">
|
||||
<li id="section-64">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-65">¶</a>
|
||||
<a class="pilcrow" href="#section-64">¶</a>
|
||||
</div>
|
||||
<p>The list of keywords that are reserved by JavaScript, but not used, or are
|
||||
used by CoffeeScript internally. We throw an error when these are encountered,
|
||||
@@ -1606,11 +1643,11 @@ STRICT_PROSCRIBED = [<span class="hljs-string">'arguments'</span>, <span class="
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-66">
|
||||
<li id="section-65">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-66">¶</a>
|
||||
<a class="pilcrow" href="#section-65">¶</a>
|
||||
</div>
|
||||
<p>The superset of both JavaScript keywords and reserved words, none of which may
|
||||
be used as identifiers or properties.</p>
|
||||
@@ -1619,17 +1656,17 @@ be used as identifiers or properties.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED)
|
||||
|
||||
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED)
|
||||
exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED</pre></div></div>
|
||||
<span class="hljs-built_in">exports</span>.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED)
|
||||
<span class="hljs-built_in">exports</span>.STRICT_PROSCRIBED = STRICT_PROSCRIBED</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-67">
|
||||
<li id="section-66">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-67">¶</a>
|
||||
<a class="pilcrow" href="#section-66">¶</a>
|
||||
</div>
|
||||
<p>The character code of the nasty Microsoft madness otherwise known as the BOM.</p>
|
||||
|
||||
@@ -1640,11 +1677,11 @@ exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED</pre></div></div>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-68">
|
||||
<li id="section-67">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-68">¶</a>
|
||||
<a class="pilcrow" href="#section-67">¶</a>
|
||||
</div>
|
||||
<p>Token matching regexes.</p>
|
||||
|
||||
@@ -1686,11 +1723,11 @@ JSTOKEN = <span class="hljs-regexp">/^`[^\\`]*(?:\\.[^\\`]*)*`/</span></pre><
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-69">
|
||||
<li id="section-68">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-69">¶</a>
|
||||
<a class="pilcrow" href="#section-68">¶</a>
|
||||
</div>
|
||||
<p>String-matching-regexes.</p>
|
||||
|
||||
@@ -1703,30 +1740,34 @@ STRING_DOUBLE = <span class="hljs-regexp">/// ^(?: [^\\"<span class="hljs-comme
|
||||
HEREDOC_SINGLE = ///</span> ^(?: [^\\<span class="hljs-string">'] | \\[\s\S] | '</span>(?!<span class="hljs-string">''</span>) )* <span class="hljs-regexp">///
|
||||
HEREDOC_DOUBLE = ///</span> ^(?: [^\\<span class="hljs-string">"#] | \\[\s\S] | "</span>(?!<span class="hljs-string">""</span>) | \<span class="hljs-comment">#(?!\{) )* ///</span>
|
||||
|
||||
STRING_OMIT = <span class="hljs-regexp">/\s*\n\s*/g</span>
|
||||
HEREDOC_INDENT = <span class="hljs-regexp">/\n+([^\n\S]*)(?=\S)/g</span></pre></div></div>
|
||||
STRING_OMIT = <span class="hljs-regexp">///
|
||||
((?:\\\\)+) <span class="hljs-comment"># consume (and preserve) an even number of backslashes</span>
|
||||
| \\[^\S\n]*\n\s* <span class="hljs-comment"># remove escaped newlines</span>
|
||||
///</span>g
|
||||
SIMPLE_STRING_OMIT = <span class="hljs-regexp">/\s*\n\s*/g</span>
|
||||
HEREDOC_INDENT = <span class="hljs-regexp">/\n+([^\n\S]*)(?=\S)/g</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-70">
|
||||
<li id="section-69">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-70">¶</a>
|
||||
<a class="pilcrow" href="#section-69">¶</a>
|
||||
</div>
|
||||
<p>Regex-matching-regexes.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>REGEX = <span class="hljs-regexp">/// ^
|
||||
/ (?!/) (
|
||||
/ (?!/) ((
|
||||
?: [^ [ / \n \\ ] <span class="hljs-comment"># every other thing</span>
|
||||
| \\. <span class="hljs-comment"># anything (but newlines) escaped</span>
|
||||
| \\[^\n] <span class="hljs-comment"># anything but newlines escaped</span>
|
||||
| \[ <span class="hljs-comment"># character class</span>
|
||||
(?: \\. | [^ \] \n \\ ] )*
|
||||
(?: \\[^\n] | [^ \] \n \\ ] )*
|
||||
]
|
||||
)* (/)?
|
||||
)*) (/)?
|
||||
///</span>
|
||||
|
||||
REGEX_FLAGS = <span class="hljs-regexp">/^\w*/</span>
|
||||
@@ -1736,7 +1777,7 @@ HEREGEX = <span class="hljs-regexp">/// ^(?: [^\\/<span class="hljs-comment
|
||||
|
||||
HEREGEX_OMIT = ///</span>
|
||||
((?:\\\\)+) <span class="hljs-comment"># consume (and preserve) an even number of backslashes</span>
|
||||
| \\(\s|/) <span class="hljs-comment"># preserve escaped whitespace and "de-escape" slashes</span>
|
||||
| \\(\s) <span class="hljs-comment"># preserve escaped whitespace</span>
|
||||
| \s+(?:<span class="hljs-comment">#.*)? # remove whitespace and comments</span>
|
||||
<span class="hljs-regexp">///g
|
||||
|
||||
@@ -1747,23 +1788,28 @@ POSSIBLY_DIVISION = <span class="hljs-regexp">/// ^ /=?\s ///</span></pre></di
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-71">
|
||||
<li id="section-70">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-71">¶</a>
|
||||
<a class="pilcrow" href="#section-70">¶</a>
|
||||
</div>
|
||||
<p>Other regexes.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>MULTILINER = <span class="hljs-regexp">/\n/g</span>
|
||||
|
||||
HERECOMMENT_ILLEGAL = <span class="hljs-regexp">/\*\//</span>
|
||||
<div class="content"><div class='highlight'><pre>HERECOMMENT_ILLEGAL = <span class="hljs-regexp">/\*\//</span>
|
||||
|
||||
LINE_CONTINUER = <span class="hljs-regexp">/// ^ \s* (?: , | \??\.(?![.\d]) | :: ) ///</span>
|
||||
|
||||
OCTAL_ESCAPE = <span class="hljs-regexp">/// ^ ((?: \\. | [^\\] )*) (\\ (?: 0[0-7] | [1-7] )) ///</span>
|
||||
INVALID_ESCAPE = <span class="hljs-regexp">///
|
||||
( (?:^|[^\\]) (?:\\\\)* ) <span class="hljs-comment"># make sure the escape isn’t escaped</span>
|
||||
\\ (
|
||||
?: (0[0-7]|[1-7]) <span class="hljs-comment"># octal escape</span>
|
||||
| (x(?![\da-fA-F]{2}).{0,2}) <span class="hljs-comment"># hex escape</span>
|
||||
| (u(?![\da-fA-F]{4}).{0,4}) <span class="hljs-comment"># unicode escape</span>
|
||||
)
|
||||
///</span>
|
||||
|
||||
LEADING_BLANK_LINE = <span class="hljs-regexp">/^[^\n\S]*\n/</span>
|
||||
TRAILING_BLANK_LINE = <span class="hljs-regexp">/\n[^\n\S]*$/</span>
|
||||
@@ -1773,11 +1819,11 @@ TRAILING_SPACES = <span class="hljs-regexp">/\s+$/</span></pre></div></div>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-72">
|
||||
<li id="section-71">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-72">¶</a>
|
||||
<a class="pilcrow" href="#section-71">¶</a>
|
||||
</div>
|
||||
<p>Compound assignment tokens.</p>
|
||||
|
||||
@@ -1791,11 +1837,11 @@ TRAILING_SPACES = <span class="hljs-regexp">/\s+$/</span></pre></div></div>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-73">
|
||||
<li id="section-72">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-73">¶</a>
|
||||
<a class="pilcrow" href="#section-72">¶</a>
|
||||
</div>
|
||||
<p>Unary tokens.</p>
|
||||
|
||||
@@ -1808,11 +1854,11 @@ UNARY_MATH = [<span class="hljs-string">'!'</span>, <span class="hljs-string">'~
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-74">
|
||||
<li id="section-73">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-74">¶</a>
|
||||
<a class="pilcrow" href="#section-73">¶</a>
|
||||
</div>
|
||||
<p>Logical tokens.</p>
|
||||
|
||||
@@ -1823,11 +1869,11 @@ UNARY_MATH = [<span class="hljs-string">'!'</span>, <span class="hljs-string">'~
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-75">
|
||||
<li id="section-74">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-75">¶</a>
|
||||
<a class="pilcrow" href="#section-74">¶</a>
|
||||
</div>
|
||||
<p>Bit-shifting tokens.</p>
|
||||
|
||||
@@ -1838,11 +1884,11 @@ UNARY_MATH = [<span class="hljs-string">'!'</span>, <span class="hljs-string">'~
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-76">
|
||||
<li id="section-75">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-76">¶</a>
|
||||
<a class="pilcrow" href="#section-75">¶</a>
|
||||
</div>
|
||||
<p>Comparison tokens.</p>
|
||||
|
||||
@@ -1853,11 +1899,11 @@ UNARY_MATH = [<span class="hljs-string">'!'</span>, <span class="hljs-string">'~
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-77">
|
||||
<li id="section-76">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-77">¶</a>
|
||||
<a class="pilcrow" href="#section-76">¶</a>
|
||||
</div>
|
||||
<p>Mathematical tokens.</p>
|
||||
|
||||
@@ -1868,11 +1914,11 @@ UNARY_MATH = [<span class="hljs-string">'!'</span>, <span class="hljs-string">'~
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-78">
|
||||
<li id="section-77">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-78">¶</a>
|
||||
<a class="pilcrow" href="#section-77">¶</a>
|
||||
</div>
|
||||
<p>Relational tokens that are negatable with <code>not</code> prefix.</p>
|
||||
|
||||
@@ -1883,11 +1929,11 @@ UNARY_MATH = [<span class="hljs-string">'!'</span>, <span class="hljs-string">'~
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-79">
|
||||
<li id="section-78">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-79">¶</a>
|
||||
<a class="pilcrow" href="#section-78">¶</a>
|
||||
</div>
|
||||
<p>Boolean tokens.</p>
|
||||
|
||||
@@ -1898,11 +1944,11 @@ UNARY_MATH = [<span class="hljs-string">'!'</span>, <span class="hljs-string">'~
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-80">
|
||||
<li id="section-79">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-80">¶</a>
|
||||
<a class="pilcrow" href="#section-79">¶</a>
|
||||
</div>
|
||||
<p>Tokens which could legitimately be invoked or indexed. An opening
|
||||
parentheses or bracket following these tokens will be recorded as the start
|
||||
@@ -1911,16 +1957,19 @@ of a function invocation or indexing operation.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CALLABLE = [<span class="hljs-string">'IDENTIFIER'</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">'THIS'</span>, <span class="hljs-string">'SUPER'</span>]
|
||||
INDEXABLE = CALLABLE.concat [<span class="hljs-string">'NUMBER'</span>, <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">'BOOL'</span>, <span class="hljs-string">'NULL'</span>, <span class="hljs-string">'UNDEFINED'</span>, <span class="hljs-string">'}'</span>, <span class="hljs-string">'::'</span>]</pre></div></div>
|
||||
INDEXABLE = CALLABLE.concat [
|
||||
<span class="hljs-string">'NUMBER'</span>, <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'STRING_END'</span>, <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">'REGEX_END'</span>
|
||||
<span class="hljs-string">'BOOL'</span>, <span class="hljs-string">'NULL'</span>, <span class="hljs-string">'UNDEFINED'</span>, <span class="hljs-string">'}'</span>, <span class="hljs-string">'::'</span>
|
||||
]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-81">
|
||||
<li id="section-80">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-81">¶</a>
|
||||
<a class="pilcrow" href="#section-80">¶</a>
|
||||
</div>
|
||||
<p>Tokens which a regular expression will never immediately follow (except spaced
|
||||
CALLABLEs in some cases), but which a division operator can.</p>
|
||||
@@ -1933,11 +1982,11 @@ CALLABLEs in some cases), but which a division operator can.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-82">
|
||||
<li id="section-81">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-82">¶</a>
|
||||
<a class="pilcrow" href="#section-81">¶</a>
|
||||
</div>
|
||||
<p>Tokens that, when immediately preceding a <code>WHEN</code>, indicate that the <code>WHEN</code>
|
||||
occurs at the start of a line. We disambiguate these from trailing whens to
|
||||
@@ -1950,11 +1999,11 @@ avoid an ambiguity in the grammar.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-83">
|
||||
<li id="section-82">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-83">¶</a>
|
||||
<a class="pilcrow" href="#section-82">¶</a>
|
||||
</div>
|
||||
<p>Additional indent in front of these is ignored.</p>
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ Error.stackTraceLimit = Infinity
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>{compact, flatten, extend, merge, del, starts, ends, last, some,
|
||||
<div class="content"><div class='highlight'><pre>{compact, flatten, extend, merge, del, starts, ends, some,
|
||||
addLocationDataFn, locationDataToString, throwSyntaxError} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -157,8 +157,8 @@ addLocationDataFn, locationDataToString, throwSyntaxError} = <span class="hljs-b
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.extend = extend
|
||||
exports.addLocationDataFn = addLocationDataFn</pre></div></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>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -207,7 +207,7 @@ all the CodeFragments’ <code>code</code> snippets, in order.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>exports.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><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>
|
||||
|
||||
<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>
|
||||
@@ -351,14 +351,15 @@ the two values are raw nodes which have not been compiled.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">cache</span>: <span class="hljs-function"><span class="hljs-params">(o, level, reused)</span> -></span>
|
||||
<span class="hljs-keyword">unless</span> <span class="hljs-property">@isComplex</span>()
|
||||
ref = <span class="hljs-keyword">if</span> level <span class="hljs-keyword">then</span> <span class="hljs-property">@compileToFragments</span> o, level <span class="hljs-keyword">else</span> <span class="hljs-keyword">this</span>
|
||||
[ref, ref]
|
||||
<span class="hljs-keyword">else</span>
|
||||
ref = <span class="hljs-keyword">new</span> Literal reused <span class="hljs-keyword">or</span> o.scope.freeVariable <span class="hljs-string">'ref'</span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">cache</span>: <span class="hljs-function"><span class="hljs-params">(o, level, isComplex)</span> -></span>
|
||||
complex = <span class="hljs-keyword">if</span> isComplex? <span class="hljs-keyword">then</span> isComplex <span class="hljs-keyword">this</span> <span class="hljs-keyword">else</span> <span class="hljs-property">@isComplex</span>()
|
||||
<span class="hljs-keyword">if</span> complex
|
||||
ref = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'ref'</span>
|
||||
sub = <span class="hljs-keyword">new</span> Assign ref, <span class="hljs-keyword">this</span>
|
||||
<span class="hljs-keyword">if</span> level <span class="hljs-keyword">then</span> [sub.compileToFragments(o, level), [<span class="hljs-property">@makeCode</span>(ref.value)]] <span class="hljs-keyword">else</span> [sub, ref]
|
||||
<span class="hljs-keyword">else</span>
|
||||
ref = <span class="hljs-keyword">if</span> level <span class="hljs-keyword">then</span> <span class="hljs-property">@compileToFragments</span> o, level <span class="hljs-keyword">else</span> <span class="hljs-keyword">this</span>
|
||||
[ref, ref]
|
||||
|
||||
<span class="hljs-attribute">cacheToCodeFragments</span>: <span class="hljs-function"><span class="hljs-params">(cacheValues)</span> -></span>
|
||||
[fragmentsToText(cacheValues[<span class="hljs-number">0</span>]), fragmentsToText(cacheValues[<span class="hljs-number">1</span>])]</pre></div></div>
|
||||
@@ -613,7 +614,7 @@ indented block of code — the implementation of a function, a clause in an
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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> []
|
||||
|
||||
@@ -955,7 +956,7 @@ JavaScript without translation, such as: strings, numbers,
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -1033,7 +1034,7 @@ make sense.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -1047,7 +1048,8 @@ make sense.</p>
|
||||
<span class="hljs-keyword">if</span> expr <span class="hljs-keyword">and</span> expr <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Return <span class="hljs-keyword">then</span> expr.compileToFragments o, level <span class="hljs-keyword">else</span> <span class="hljs-keyword">super</span> o, level
|
||||
|
||||
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
answer = []</pre></div></div>
|
||||
answer = []
|
||||
exprIsYieldReturn = <span class="hljs-property">@expression</span>?.isYieldReturn?()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1062,10 +1064,11 @@ make sense.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-property">@tab</span> + <span class="hljs-string">"return<span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-property">@expression</span> <span class="hljs-keyword">then</span> <span class="hljs-string">" "</span> <span class="hljs-keyword">else</span> <span class="hljs-string">""</span>}</span>"</span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> exprIsYieldReturn
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-property">@tab</span> + <span class="hljs-string">"return<span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-property">@expression</span> <span class="hljs-keyword">then</span> <span class="hljs-string">" "</span> <span class="hljs-keyword">else</span> <span class="hljs-string">""</span>}</span>"</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@expression</span>
|
||||
answer = answer.concat <span class="hljs-property">@expression</span>.compileToFragments o, LEVEL_PAREN
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">";"</span>
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">";"</span> <span class="hljs-keyword">unless</span> exprIsYieldReturn
|
||||
<span class="hljs-keyword">return</span> answer</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -1095,7 +1098,7 @@ or vanilla.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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
|
||||
@@ -1165,10 +1168,11 @@ or vanilla.</p>
|
||||
(<span class="hljs-property">@base</span> <span class="hljs-keyword">instanceof</span> Obj) <span class="hljs-keyword">and</span> (<span class="hljs-keyword">not</span> onlyGenerated <span class="hljs-keyword">or</span> <span class="hljs-property">@base</span>.generated)
|
||||
|
||||
<span class="hljs-attribute">isSplice</span>:<span class="hljs-function"> -></span>
|
||||
last(<span class="hljs-property">@properties</span>) <span class="hljs-keyword">instanceof</span> Slice
|
||||
[..., lastProp] = <span class="hljs-property">@properties</span>
|
||||
lastProp <span class="hljs-keyword">instanceof</span> Slice
|
||||
|
||||
<span class="hljs-attribute">looksStatic</span>: <span class="hljs-function"><span class="hljs-params">(className)</span> -></span>
|
||||
<span class="hljs-property">@base</span>.value <span class="hljs-keyword">is</span> className <span class="hljs-keyword">and</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-property">@base</span>.value <span class="hljs-keyword">is</span> className <span class="hljs-keyword">and</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-property">@properties</span>[<span class="hljs-number">0</span>].name?.value <span class="hljs-keyword">isnt</span> <span class="hljs-string">'prototype'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -1204,7 +1208,7 @@ We cache them separately for compiling complex expressions.
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">cacheReference</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
name = last <span class="hljs-property">@properties</span>
|
||||
[..., name] = <span class="hljs-property">@properties</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@properties</span>.length < <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@base</span>.isComplex() <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> name?.isComplex()
|
||||
<span class="hljs-keyword">return</span> [<span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>] <span class="hljs-comment"># `a` `a.b`</span>
|
||||
base = <span class="hljs-keyword">new</span> Value <span class="hljs-property">@base</span>, <span class="hljs-property">@properties</span>[...-<span class="hljs-number">1</span>]
|
||||
@@ -1258,7 +1262,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
|
||||
@@ -1300,7 +1304,7 @@ at the same position.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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
|
||||
@@ -1339,7 +1343,7 @@ calls against the prototype’s function of the same name.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -1387,10 +1391,21 @@ method.</p>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">superReference</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
method = o.scope.namedMethod()
|
||||
<span class="hljs-keyword">if</span> method?.klass
|
||||
accesses = [<span class="hljs-keyword">new</span> Access(<span class="hljs-keyword">new</span> Literal <span class="hljs-string">'__super__'</span>)]
|
||||
{klass, name, variable} = method
|
||||
<span class="hljs-keyword">if</span> klass.isComplex()
|
||||
bref = <span class="hljs-keyword">new</span> Literal o.scope.parent.freeVariable <span class="hljs-string">'base'</span>
|
||||
base = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Parens <span class="hljs-keyword">new</span> Assign bref, klass
|
||||
variable.base = base
|
||||
variable.properties.splice <span class="hljs-number">0</span>, klass.properties.length
|
||||
<span class="hljs-keyword">if</span> name.isComplex() <span class="hljs-keyword">or</span> (name <span class="hljs-keyword">instanceof</span> Index <span class="hljs-keyword">and</span> name.index.isAssignable())
|
||||
nref = <span class="hljs-keyword">new</span> Literal o.scope.parent.freeVariable <span class="hljs-string">'name'</span>
|
||||
name = <span class="hljs-keyword">new</span> Index <span class="hljs-keyword">new</span> Assign nref, name.index
|
||||
variable.properties.pop()
|
||||
variable.properties.push name
|
||||
accesses = [<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'__super__'</span>]
|
||||
accesses.push <span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'constructor'</span> <span class="hljs-keyword">if</span> method.static
|
||||
accesses.push <span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal method.name
|
||||
(<span class="hljs-keyword">new</span> Value (<span class="hljs-keyword">new</span> Literal method.klass), accesses).compile o
|
||||
accesses.push <span class="hljs-keyword">if</span> nref? <span class="hljs-keyword">then</span> <span class="hljs-keyword">new</span> Index nref <span class="hljs-keyword">else</span> name
|
||||
(<span class="hljs-keyword">new</span> Value bref ? klass, accesses).compile o
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> method?.ctor
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{method.name}</span>.__super__.constructor"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
@@ -1573,7 +1588,7 @@ After <code>goog.inherits</code> from the
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -1592,7 +1607,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>, o), [<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">'extend'</span>, o), [<span class="hljs-property">@child</span>, <span class="hljs-property">@parent</span>]).compileToFragments o</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1621,7 +1636,7 @@ an access into the object’s prototype.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -1665,7 +1680,7 @@ an access into the object’s prototype.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -1704,7 +1719,7 @@ corresponding array of integers at runtime.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'from'</span>, <span class="hljs-string">'to'</span>]
|
||||
|
||||
@@ -1728,9 +1743,10 @@ But only if they need to be cached to avoid double evaluation.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileVariables</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
o = merge o, <span class="hljs-attribute">top</span>: <span class="hljs-literal">true</span>
|
||||
[<span class="hljs-property">@fromC</span>, <span class="hljs-property">@fromVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@from</span>.cache o, LEVEL_LIST
|
||||
[<span class="hljs-property">@toC</span>, <span class="hljs-property">@toVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@to</span>.cache o, LEVEL_LIST
|
||||
[<span class="hljs-property">@step</span>, <span class="hljs-property">@stepVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> step.cache o, LEVEL_LIST <span class="hljs-keyword">if</span> step = del o, <span class="hljs-string">'step'</span>
|
||||
isComplex = del o, <span class="hljs-string">'isComplex'</span>
|
||||
[<span class="hljs-property">@fromC</span>, <span class="hljs-property">@fromVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@from</span>.cache o, LEVEL_LIST, isComplex
|
||||
[<span class="hljs-property">@toC</span>, <span class="hljs-property">@toVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@to</span>.cache o, LEVEL_LIST, isComplex
|
||||
[<span class="hljs-property">@step</span>, <span class="hljs-property">@stepVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> step.cache o, LEVEL_LIST, isComplex <span class="hljs-keyword">if</span> step = del o, <span class="hljs-string">'step'</span>
|
||||
[<span class="hljs-property">@fromNum</span>, <span class="hljs-property">@toNum</span>] = [<span class="hljs-property">@fromVar</span>.match(NUMBER), <span class="hljs-property">@toVar</span>.match(NUMBER)]
|
||||
<span class="hljs-property">@stepNum</span> = <span class="hljs-property">@stepVar</span>.match(NUMBER) <span class="hljs-keyword">if</span> <span class="hljs-property">@stepVar</span></pre></div></div>
|
||||
|
||||
@@ -1859,7 +1875,7 @@ needed to iterate over the values in the range. Used by comprehensions.</p>
|
||||
range.pop() <span class="hljs-keyword">if</span> <span class="hljs-property">@exclusive</span>
|
||||
<span class="hljs-keyword">return</span> [<span class="hljs-property">@makeCode</span> <span class="hljs-string">"[<span class="hljs-subst">#{ range.join(<span class="hljs-string">', '</span>) }</span>]"</span>]
|
||||
idt = <span class="hljs-property">@tab</span> + TAB
|
||||
i = o.scope.freeVariable <span class="hljs-string">'i'</span>
|
||||
i = o.scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</span>
|
||||
result = o.scope.freeVariable <span class="hljs-string">'results'</span>
|
||||
pre = <span class="hljs-string">"\n<span class="hljs-subst">#{idt}</span><span class="hljs-subst">#{result}</span> = [];"</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@fromNum</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@toNum</span>
|
||||
@@ -1870,7 +1886,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>
|
||||
|
||||
@@ -1902,7 +1918,7 @@ is the index of the beginning.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'range'</span>]
|
||||
|
||||
@@ -1980,7 +1996,7 @@ is the index of the beginning.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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> []
|
||||
|
||||
@@ -1988,35 +2004,54 @@ is the index of the beginning.</p>
|
||||
|
||||
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
props = <span class="hljs-property">@properties</span>
|
||||
<span class="hljs-keyword">return</span> [<span class="hljs-property">@makeCode</span>(<span class="hljs-keyword">if</span> <span class="hljs-property">@front</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'({})'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'{}'</span>)] <span class="hljs-keyword">unless</span> props.length
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@generated</span>
|
||||
<span class="hljs-keyword">for</span> node <span class="hljs-keyword">in</span> props <span class="hljs-keyword">when</span> node <span class="hljs-keyword">instanceof</span> Value
|
||||
node.error <span class="hljs-string">'cannot have an implicit value in an implicit object'</span>
|
||||
<span class="hljs-keyword">break</span> <span class="hljs-keyword">for</span> prop, dynamicIndex <span class="hljs-keyword">in</span> props <span class="hljs-keyword">when</span> (prop.variable <span class="hljs-keyword">or</span> prop).base <span class="hljs-keyword">instanceof</span> Parens
|
||||
hasDynamic = dynamicIndex < props.length
|
||||
idt = o.indent += TAB
|
||||
lastNoncom = <span class="hljs-property">@lastNonComment</span> <span class="hljs-property">@properties</span>
|
||||
answer = []
|
||||
<span class="hljs-keyword">if</span> hasDynamic
|
||||
oref = o.scope.freeVariable <span class="hljs-string">'obj'</span>
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"(\n<span class="hljs-subst">#{idt}</span><span class="hljs-subst">#{oref}</span> = "</span>
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"{<span class="hljs-subst">#{<span class="hljs-keyword">if</span> props.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">or</span> dynamicIndex <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'}'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'\n'</span>}</span>"</span>
|
||||
<span class="hljs-keyword">for</span> prop, i <span class="hljs-keyword">in</span> props
|
||||
join = <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> props.length - <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> dynamicIndex
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n<span class="hljs-subst">#{idt}</span>}"</span> <span class="hljs-keyword">unless</span> i <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">',\n'</span>
|
||||
join = <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> props.length - <span class="hljs-number">1</span> <span class="hljs-keyword">or</span> i <span class="hljs-keyword">is</span> dynamicIndex - <span class="hljs-number">1</span>
|
||||
<span class="hljs-string">''</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> prop <span class="hljs-keyword">is</span> lastNoncom <span class="hljs-keyword">or</span> prop <span class="hljs-keyword">instanceof</span> Comment
|
||||
<span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">',\n'</span>
|
||||
indent = <span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Comment <span class="hljs-keyword">then</span> <span class="hljs-string">''</span> <span class="hljs-keyword">else</span> idt
|
||||
indent += TAB <span class="hljs-keyword">if</span> hasDynamic <span class="hljs-keyword">and</span> i < dynamicIndex
|
||||
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Assign <span class="hljs-keyword">and</span> prop.variable <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> prop.variable.hasProperties()
|
||||
prop.variable.error <span class="hljs-string">'Invalid object key'</span>
|
||||
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> prop.<span class="hljs-keyword">this</span>
|
||||
prop = <span class="hljs-keyword">new</span> Assign prop.properties[<span class="hljs-number">0</span>].name, prop, <span class="hljs-string">'object'</span>
|
||||
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Comment
|
||||
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Assign
|
||||
prop = <span class="hljs-keyword">new</span> Assign prop, prop, <span class="hljs-string">'object'</span>
|
||||
(prop.variable.base <span class="hljs-keyword">or</span> prop.variable).asKey = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">if</span> i < dynamicIndex
|
||||
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Assign
|
||||
prop = <span class="hljs-keyword">new</span> Assign prop, prop, <span class="hljs-string">'object'</span>
|
||||
(prop.variable.base <span class="hljs-keyword">or</span> prop.variable).asKey = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Assign
|
||||
key = prop.variable
|
||||
value = prop.value
|
||||
<span class="hljs-keyword">else</span>
|
||||
[key, value] = prop.base.cache o
|
||||
prop = <span class="hljs-keyword">new</span> Assign (<span class="hljs-keyword">new</span> Value (<span class="hljs-keyword">new</span> Literal oref), [<span class="hljs-keyword">new</span> Access key]), value
|
||||
<span class="hljs-keyword">if</span> indent <span class="hljs-keyword">then</span> answer.push <span class="hljs-property">@makeCode</span> indent
|
||||
answer.push prop.compileToFragments(o, LEVEL_TOP)...
|
||||
<span class="hljs-keyword">if</span> join <span class="hljs-keyword">then</span> answer.push <span class="hljs-property">@makeCode</span> join
|
||||
answer.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"{<span class="hljs-subst">#{ props.length <span class="hljs-keyword">and</span> <span class="hljs-string">'\n'</span> }</span>"</span>
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"<span class="hljs-subst">#{ props.length <span class="hljs-keyword">and</span> <span class="hljs-string">'\n'</span> + <span class="hljs-property">@tab</span> }</span>}"</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@front</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> answer <span class="hljs-keyword">else</span> answer
|
||||
<span class="hljs-keyword">if</span> hasDynamic
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">",\n<span class="hljs-subst">#{idt}</span><span class="hljs-subst">#{oref}</span>\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>)"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}"</span> <span class="hljs-keyword">unless</span> props.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@front</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> hasDynamic <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> answer <span class="hljs-keyword">else</span> answer
|
||||
|
||||
<span class="hljs-attribute">assigns</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> prop <span class="hljs-keyword">in</span> <span class="hljs-property">@properties</span> <span class="hljs-keyword">when</span> prop.assigns name <span class="hljs-keyword">then</span> <span class="hljs-keyword">return</span> <span class="hljs-literal">yes</span>
|
||||
@@ -2048,7 +2083,7 @@ is the index of the beginning.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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> []
|
||||
|
||||
@@ -2106,7 +2141,7 @@ list of prototype property assignments.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -2128,7 +2163,8 @@ list of prototype property assignments.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">determineName</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@variable</span>
|
||||
decl = <span class="hljs-keyword">if</span> tail = last <span class="hljs-property">@variable</span>.properties
|
||||
[..., tail] = <span class="hljs-property">@variable</span>.properties
|
||||
decl = <span class="hljs-keyword">if</span> tail
|
||||
tail <span class="hljs-keyword">instanceof</span> Access <span class="hljs-keyword">and</span> tail.name.value
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-property">@variable</span>.base.value
|
||||
@@ -2156,7 +2192,6 @@ list of prototype property assignments.</p>
|
||||
<span class="hljs-keyword">if</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>
|
||||
node.value = name
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Code
|
||||
node.klass = name
|
||||
node.context = name <span class="hljs-keyword">if</span> node.bound</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -2214,7 +2249,8 @@ on the class.</p>
|
||||
<span class="hljs-keyword">if</span> assign.variable.<span class="hljs-keyword">this</span>
|
||||
func.static = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
assign.variable = <span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Literal(name), [(<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'prototype'</span>), <span class="hljs-keyword">new</span> Access base])
|
||||
acc = <span class="hljs-keyword">if</span> base.isComplex() <span class="hljs-keyword">then</span> <span class="hljs-keyword">new</span> Index base <span class="hljs-keyword">else</span> <span class="hljs-keyword">new</span> Access base
|
||||
assign.variable = <span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Literal(name), [(<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'prototype'</span>), acc])
|
||||
<span class="hljs-keyword">if</span> func <span class="hljs-keyword">instanceof</span> Code <span class="hljs-keyword">and</span> func.bound
|
||||
<span class="hljs-property">@boundFuncs</span>.push base
|
||||
func.bound = <span class="hljs-literal">no</span>
|
||||
@@ -2335,7 +2371,7 @@ constructor, property assignments, and inheritance getting built out below.</p>
|
||||
<span class="hljs-property">@body</span>.expressions.push lname
|
||||
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@parent</span>
|
||||
superClass = <span class="hljs-keyword">new</span> Literal o.classScope.freeVariable <span class="hljs-string">'super'</span>, <span class="hljs-literal">no</span>
|
||||
superClass = <span class="hljs-keyword">new</span> Literal o.classScope.freeVariable <span class="hljs-string">'superClass'</span>, <span class="hljs-attribute">reserve</span>: <span class="hljs-literal">no</span>
|
||||
<span class="hljs-property">@body</span>.expressions.unshift <span class="hljs-keyword">new</span> Extends lname, superClass
|
||||
func.params.push <span class="hljs-keyword">new</span> Param superClass
|
||||
args.push <span class="hljs-property">@parent</span>
|
||||
@@ -2373,7 +2409,7 @@ property of an object — including within object literals.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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
|
||||
@@ -2414,21 +2450,28 @@ has not been seen yet within the current scope, declare it.</p>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileSplice</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@variable</span>.isSplice()
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileConditional</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'||='</span>, <span class="hljs-string">'&&='</span>, <span class="hljs-string">'?='</span>]
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileSpecialMath</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'**='</span>, <span class="hljs-string">'//='</span>, <span class="hljs-string">'%%='</span>]
|
||||
compiledName = <span class="hljs-property">@variable</span>.compileToFragments o, LEVEL_LIST
|
||||
name = fragmentsToText compiledName
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@value</span> <span class="hljs-keyword">instanceof</span> Code
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@value</span>.static
|
||||
<span class="hljs-property">@value</span>.klass = <span class="hljs-property">@variable</span>.base
|
||||
<span class="hljs-property">@value</span>.name = <span class="hljs-property">@variable</span>.properties[<span class="hljs-number">0</span>]
|
||||
<span class="hljs-property">@value</span>.variable = <span class="hljs-property">@variable</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@variable</span>.properties?.length >= <span class="hljs-number">2</span>
|
||||
[properties..., prototype, name] = <span class="hljs-property">@variable</span>.properties
|
||||
<span class="hljs-keyword">if</span> prototype.name?.value <span class="hljs-keyword">is</span> <span class="hljs-string">'prototype'</span>
|
||||
<span class="hljs-property">@value</span>.klass = <span class="hljs-keyword">new</span> Value <span class="hljs-property">@variable</span>.base, properties
|
||||
<span class="hljs-property">@value</span>.name = name
|
||||
<span class="hljs-property">@value</span>.variable = <span class="hljs-property">@variable</span>
|
||||
<span class="hljs-keyword">unless</span> <span class="hljs-property">@context</span>
|
||||
varBase = <span class="hljs-property">@variable</span>.unwrapAll()
|
||||
<span class="hljs-keyword">unless</span> varBase.isAssignable()
|
||||
<span class="hljs-property">@variable</span>.error <span class="hljs-string">"\"<span class="hljs-subst">#{<span class="hljs-property">@variable</span>.compile o}</span>\" cannot be assigned"</span>
|
||||
<span class="hljs-keyword">unless</span> varBase.hasProperties?()
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@param</span>
|
||||
o.scope.add name, <span class="hljs-string">'var'</span>
|
||||
o.scope.add varBase.value, <span class="hljs-string">'var'</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
o.scope.find name
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@value</span> <span class="hljs-keyword">instanceof</span> Code <span class="hljs-keyword">and</span> match = METHOD_DEF.exec name
|
||||
<span class="hljs-property">@value</span>.klass = match[<span class="hljs-number">1</span>] <span class="hljs-keyword">if</span> match[<span class="hljs-number">2</span>]
|
||||
<span class="hljs-property">@value</span>.name = match[<span class="hljs-number">3</span>] ? match[<span class="hljs-number">4</span>] ? match[<span class="hljs-number">5</span>]
|
||||
o.scope.find varBase.value
|
||||
val = <span class="hljs-property">@value</span>.compileToFragments o, LEVEL_LIST
|
||||
compiledName = <span class="hljs-property">@variable</span>.compileToFragments o, LEVEL_LIST
|
||||
<span class="hljs-keyword">return</span> (compiledName.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">": "</span>), val) <span class="hljs-keyword">if</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span>
|
||||
answer = compiledName.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" <span class="hljs-subst">#{ <span class="hljs-property">@context</span> <span class="hljs-keyword">or</span> <span class="hljs-string">'='</span> }</span> "</span>), val
|
||||
<span class="hljs-keyword">if</span> o.level <= LEVEL_LIST <span class="hljs-keyword">then</span> answer <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> answer</pre></div></div>
|
||||
@@ -2564,7 +2607,7 @@ for details.</p>
|
||||
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>, 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>
|
||||
ivar = o.scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</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>
|
||||
<span class="hljs-keyword">else</span>
|
||||
val += <span class="hljs-string">") : []"</span>
|
||||
@@ -2575,7 +2618,7 @@ for details.</p>
|
||||
<span class="hljs-keyword">if</span> rest <span class="hljs-keyword">is</span> <span class="hljs-number">1</span>
|
||||
expandedIdx = <span class="hljs-string">"<span class="hljs-subst">#{vvarText}</span>.length - 1"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
ivar = o.scope.freeVariable <span class="hljs-string">'i'</span>
|
||||
ivar = o.scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</span>
|
||||
val = <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span> = <span class="hljs-subst">#{vvarText}</span>.length - <span class="hljs-subst">#{rest}</span>"</span>
|
||||
expandedIdx = <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span>++"</span>
|
||||
assigns.push val.compileToFragments o, LEVEL_LIST
|
||||
@@ -2719,7 +2762,7 @@ has no <em>children</em> — they’re within the inner scope.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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
|
||||
@@ -2878,7 +2921,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>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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -2892,7 +2935,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>
|
||||
name = <span class="hljs-string">"at_<span class="hljs-subst">#{node.properties[<span class="hljs-number">0</span>].name.value}</span>"</span>
|
||||
name = node.properties[<span class="hljs-number">0</span>].name.value
|
||||
name = <span class="hljs-string">"_<span class="hljs-subst">#{name}</span>"</span> <span class="hljs-keyword">if</span> name.reserved
|
||||
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>
|
||||
@@ -2923,7 +2967,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> 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>
|
||||
<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>
|
||||
|
||||
@@ -3081,7 +3125,7 @@ or as part of a destructuring assignment.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'name'</span>]
|
||||
|
||||
@@ -3134,7 +3178,8 @@ splats, to a proper array.</p>
|
||||
base = (node.compileToFragments o, LEVEL_LIST <span class="hljs-keyword">for</span> node <span class="hljs-keyword">in</span> list[...index])
|
||||
base = list[<span class="hljs-number">0</span>].joinFragmentArrays base, <span class="hljs-string">', '</span>
|
||||
concatPart = list[index].joinFragmentArrays args, <span class="hljs-string">', '</span>
|
||||
[].concat list[<span class="hljs-number">0</span>].makeCode(<span class="hljs-string">"["</span>), base, list[index].makeCode(<span class="hljs-string">"].concat("</span>), concatPart, (last list).makeCode(<span class="hljs-string">")"</span>)</pre></div></div>
|
||||
[..., last] = list
|
||||
[].concat list[<span class="hljs-number">0</span>].makeCode(<span class="hljs-string">"["</span>), base, list[index].makeCode(<span class="hljs-string">"].concat("</span>), concatPart, last.makeCode(<span class="hljs-string">")"</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -3163,7 +3208,7 @@ parameter list.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<span class="hljs-attribute">isComplex</span>: NO
|
||||
|
||||
@@ -3203,7 +3248,7 @@ flexibility or more speed than a comprehension can provide.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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
|
||||
@@ -3293,7 +3338,7 @@ CoffeeScript operations into their JavaScript equivalents.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -3350,6 +3395,9 @@ CoffeeScript operations into their JavaScript equivalents.</p>
|
||||
<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">isYieldReturn</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-property">@isYield</span>() <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Return
|
||||
|
||||
<span class="hljs-attribute">isUnary</span>:<span class="hljs-function"> -></span>
|
||||
<span class="hljs-keyword">not</span> <span class="hljs-property">@second</span>
|
||||
|
||||
@@ -3537,8 +3585,11 @@ used sequentially. For example:</p>
|
||||
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">if</span> <span class="hljs-string">'expression'</span> <span class="hljs-keyword">in</span> Object.keys(<span class="hljs-property">@first</span>) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> (<span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Throw)
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@isYieldReturn</span>()
|
||||
parts.push <span class="hljs-property">@first</span>.compileToFragments o, LEVEL_TOP
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@first</span>.expression?
|
||||
parts.push <span class="hljs-property">@first</span>.expression.compileToFragments o, LEVEL_OP
|
||||
<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
|
||||
@@ -3588,7 +3639,7 @@ used sequentially. For example:</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -3663,7 +3714,7 @@ used sequentially. For example:</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -3738,7 +3789,7 @@ is optional, the <em>catch</em> is not.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -3792,7 +3843,7 @@ table.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -3852,7 +3903,7 @@ parentheses, but no longer — you can put in as many as you please.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -3901,7 +3952,7 @@ you can map and filter in a single pass.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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]
|
||||
@@ -3935,29 +3986,30 @@ some cannot.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
|
||||
body = Block.wrap [<span class="hljs-property">@body</span>]
|
||||
lastJumps = last(body.expressions)?.jumps()
|
||||
<span class="hljs-property">@returns</span> = <span class="hljs-literal">no</span> <span class="hljs-keyword">if</span> lastJumps <span class="hljs-keyword">and</span> lastJumps <span class="hljs-keyword">instanceof</span> Return
|
||||
source = <span class="hljs-keyword">if</span> <span class="hljs-property">@range</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@source</span>.base <span class="hljs-keyword">else</span> <span class="hljs-property">@source</span>
|
||||
scope = o.scope
|
||||
name = <span class="hljs-property">@name</span> <span class="hljs-keyword">and</span> (<span class="hljs-property">@name</span>.compile o, LEVEL_LIST) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@pattern</span>
|
||||
index = <span class="hljs-property">@index</span> <span class="hljs-keyword">and</span> (<span class="hljs-property">@index</span>.compile o, LEVEL_LIST)
|
||||
body = Block.wrap [<span class="hljs-property">@body</span>]
|
||||
[..., last] = body.expressions
|
||||
<span class="hljs-property">@returns</span> = <span class="hljs-literal">no</span> <span class="hljs-keyword">if</span> last?.jumps() <span class="hljs-keyword">instanceof</span> Return
|
||||
source = <span class="hljs-keyword">if</span> <span class="hljs-property">@range</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@source</span>.base <span class="hljs-keyword">else</span> <span class="hljs-property">@source</span>
|
||||
scope = o.scope
|
||||
name = <span class="hljs-property">@name</span> <span class="hljs-keyword">and</span> (<span class="hljs-property">@name</span>.compile o, LEVEL_LIST) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@pattern</span>
|
||||
index = <span class="hljs-property">@index</span> <span class="hljs-keyword">and</span> (<span class="hljs-property">@index</span>.compile o, LEVEL_LIST)
|
||||
scope.find(name) <span class="hljs-keyword">if</span> name <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@pattern</span>
|
||||
scope.find(index) <span class="hljs-keyword">if</span> index
|
||||
rvar = scope.freeVariable <span class="hljs-string">'results'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@returns</span>
|
||||
ivar = (<span class="hljs-property">@object</span> <span class="hljs-keyword">and</span> index) <span class="hljs-keyword">or</span> scope.freeVariable <span class="hljs-string">'i'</span>
|
||||
kvar = (<span class="hljs-property">@range</span> <span class="hljs-keyword">and</span> name) <span class="hljs-keyword">or</span> index <span class="hljs-keyword">or</span> ivar
|
||||
kvarAssign = <span class="hljs-keyword">if</span> kvar <span class="hljs-keyword">isnt</span> ivar <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{kvar}</span> = "</span> <span class="hljs-keyword">else</span> <span class="hljs-string">""</span>
|
||||
rvar = scope.freeVariable <span class="hljs-string">'results'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@returns</span>
|
||||
ivar = (<span class="hljs-property">@object</span> <span class="hljs-keyword">and</span> index) <span class="hljs-keyword">or</span> scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</span>
|
||||
kvar = (<span class="hljs-property">@range</span> <span class="hljs-keyword">and</span> name) <span class="hljs-keyword">or</span> index <span class="hljs-keyword">or</span> ivar
|
||||
kvarAssign = <span class="hljs-keyword">if</span> kvar <span class="hljs-keyword">isnt</span> ivar <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{kvar}</span> = "</span> <span class="hljs-keyword">else</span> <span class="hljs-string">""</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@step</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@range</span>
|
||||
[step, stepVar] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@step</span>.cache o, LEVEL_LIST
|
||||
[step, stepVar] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@step</span>.cache o, LEVEL_LIST, isComplexOrAssignable
|
||||
stepNum = stepVar.match NUMBER
|
||||
name = ivar <span class="hljs-keyword">if</span> <span class="hljs-property">@pattern</span>
|
||||
varPart = <span class="hljs-string">''</span>
|
||||
guardPart = <span class="hljs-string">''</span>
|
||||
defPart = <span class="hljs-string">''</span>
|
||||
idt1 = <span class="hljs-property">@tab</span> + TAB
|
||||
name = ivar <span class="hljs-keyword">if</span> <span class="hljs-property">@pattern</span>
|
||||
varPart = <span class="hljs-string">''</span>
|
||||
guardPart = <span class="hljs-string">''</span>
|
||||
defPart = <span class="hljs-string">''</span>
|
||||
idt1 = <span class="hljs-property">@tab</span> + TAB
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-property">@range</span>
|
||||
forPartFragments = source.compileToFragments merge(o, {<span class="hljs-attribute">index</span>: ivar, name, <span class="hljs-property">@step</span>})
|
||||
forPartFragments = source.compileToFragments merge o,
|
||||
{<span class="hljs-attribute">index</span>: ivar, name, <span class="hljs-property">@step</span>, <span class="hljs-attribute">isComplex</span>: isComplexOrAssignable}
|
||||
<span class="hljs-keyword">else</span>
|
||||
svar = <span class="hljs-property">@source</span>.compile o, LEVEL_LIST
|
||||
<span class="hljs-keyword">if</span> (name <span class="hljs-keyword">or</span> <span class="hljs-property">@own</span>) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> IDENTIFIER.test svar
|
||||
@@ -4053,7 +4105,7 @@ some cannot.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>]
|
||||
@@ -4120,7 +4172,7 @@ because ternaries are already proper expressions, and don’t need conversion.</
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -4286,7 +4338,7 @@ 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 class="hljs-params">(o)</span> -></span> <span class="hljs-string">"
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">extend</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>, o}</span>.call(parent, key)) child[key] = parent[key];
|
||||
@@ -4400,23 +4452,13 @@ LEVEL_ACCESS = <span class="hljs-number">6</span> <span class="hljs-comment">#
|
||||
|
||||
<div class="content"><div class='highlight'><pre>TAB = <span class="hljs-string">' '</span>
|
||||
|
||||
IDENTIFIER_STR = <span class="hljs-string">"[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*"</span>
|
||||
IDENTIFIER = <span class="hljs-regexp">/// ^ <span class="hljs-subst">#{IDENTIFIER_STR}</span> $ ///</span>
|
||||
IDENTIFIER = <span class="hljs-regexp">/// ^ (?!\d) [$\w\x7f-\uffff]+ $ ///</span>
|
||||
SIMPLENUM = <span class="hljs-regexp">/^[+-]?\d+$/</span>
|
||||
HEXNUM = <span class="hljs-regexp">/^[+-]?0x[\da-f]+/i</span>
|
||||
NUMBER = <span class="hljs-regexp">///^[+-]?(?:
|
||||
0x[\da-f]+ | <span class="hljs-comment"># hex</span>
|
||||
\d*\.?\d+ (?:e[+-]?\d+)? <span class="hljs-comment"># decimal</span>
|
||||
)$///</span>i
|
||||
|
||||
METHOD_DEF = <span class="hljs-regexp">/// ^
|
||||
(<span class="hljs-subst">#{IDENTIFIER_STR}</span>)
|
||||
(\.prototype)?
|
||||
(?: \.(<span class="hljs-subst">#{IDENTIFIER_STR}</span>)
|
||||
| \[("(?:[^\\"\r\n]|\\.)*"|'(?:[^\\'\r\n]|\\.)*')\]
|
||||
| \[(0x[\da-fA-F]+ | \d*\.?\d+ (?:[eE][+-]?\d+)?)\]
|
||||
)
|
||||
$ ///</span></pre></div></div>
|
||||
)$///</span>i</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -4477,11 +4519,11 @@ IS_REGEX = <span class="hljs-regexp">/^\//</span></pre></div></div>
|
||||
<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>
|
||||
ref = root.freeVariable name
|
||||
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>
|
||||
|
||||
<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>
|
||||
|
||||
@@ -4506,14 +4548,16 @@ 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>
|
||||
(node <span class="hljs-keyword">instanceof</span> Call <span class="hljs-keyword">and</span> node.isSuper)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-title">isComplexOrAssignable</span> = <span class="hljs-params">(node)</span> -></span> node.isComplex() <span class="hljs-keyword">or</span> node.isAssignable?()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ option) list, and all subsequent arguments are left unparsed.</p>
|
||||
|
||||
</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>
|
||||
<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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
0
documentation/docs/public/fonts/aller-bold.eot
Executable file → Normal file
0
documentation/docs/public/fonts/aller-bold.eot
Executable file → Normal file
0
documentation/docs/public/fonts/aller-bold.ttf
Executable file → Normal file
0
documentation/docs/public/fonts/aller-bold.ttf
Executable file → Normal file
0
documentation/docs/public/fonts/aller-bold.woff
Executable file → Normal file
0
documentation/docs/public/fonts/aller-bold.woff
Executable file → Normal file
0
documentation/docs/public/fonts/aller-light.eot
Executable file → Normal file
0
documentation/docs/public/fonts/aller-light.eot
Executable file → Normal file
0
documentation/docs/public/fonts/aller-light.ttf
Executable file → Normal file
0
documentation/docs/public/fonts/aller-light.ttf
Executable file → Normal file
0
documentation/docs/public/fonts/aller-light.woff
Executable file → Normal file
0
documentation/docs/public/fonts/aller-light.woff
Executable file → Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
documentation/docs/public/fonts/roboto-black.eot
Executable file
BIN
documentation/docs/public/fonts/roboto-black.eot
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/roboto-black.ttf
Executable file
BIN
documentation/docs/public/fonts/roboto-black.ttf
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/roboto-black.woff
Executable file
BIN
documentation/docs/public/fonts/roboto-black.woff
Executable file
Binary file not shown.
@@ -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>::l<span class="hljs-function"><span class="hljs-title">oad</span> = <span class="hljs-params">(filename)</span> -></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-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.f<span class="hljs-function"><span class="hljs-title">ork</span> = <span class="hljs-params">(path, args, options)</span> -></span>
|
||||
child_process.<span class="hljs-function"><span class="hljs-title">fork</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> {}
|
||||
|
||||
@@ -208,7 +208,7 @@ parens. Unwrap all that.</p>
|
||||
</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>
|
||||
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
|
||||
)</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -265,8 +265,8 @@ parens. Unwrap all that.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<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>
|
||||
@@ -545,8 +545,8 @@ 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>
|
||||
|
||||
@@ -564,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>.exports =
|
||||
<span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> =
|
||||
<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-string">'.'</span>).map <span class="hljs-function"><span class="hljs-params">(n)</span> -></span> parseInt(n)
|
||||
[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)
|
||||
|
||||
<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>
|
||||
|
||||
@@ -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>
|
||||
@@ -315,20 +315,20 @@ Match it with its paired close.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Match tags in token stream starting at i with pattern, skipping HERECOMMENTs
|
||||
Pattern may consist of strings (equality), an array of strings (one of)
|
||||
or null (wildcard)</p>
|
||||
<p>Match tags in token stream starting at <code>i</code> with <code>pattern</code>, skipping ‘HERECOMMENT’s.
|
||||
<code>pattern</code> may consist of strings (equality), an array of strings (one of)
|
||||
or null (wildcard). Returns the index of the match or -1 if no match.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">matchTags</span>: <span class="hljs-function"><span class="hljs-params">(i, pattern...)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">indexOfTag</span>: <span class="hljs-function"><span class="hljs-params">(i, pattern...)</span> -></span>
|
||||
fuzz = <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> [<span class="hljs-number">0</span> ... pattern.length]
|
||||
fuzz += <span class="hljs-number">2</span> <span class="hljs-keyword">while</span> <span class="hljs-property">@tag</span>(i + j + fuzz) <span class="hljs-keyword">is</span> <span class="hljs-string">'HERECOMMENT'</span>
|
||||
<span class="hljs-keyword">continue</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> pattern[j]?
|
||||
pattern[j] = [pattern[j]] <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> pattern[j] <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">no</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@tag</span>(i + j + fuzz) <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> pattern[j]
|
||||
<span class="hljs-literal">yes</span></pre></div></div>
|
||||
<span class="hljs-keyword">return</span> -<span class="hljs-number">1</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@tag</span>(i + j + fuzz) <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> pattern[j]
|
||||
i + j + fuzz - <span class="hljs-number">1</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -339,13 +339,22 @@ or null (wildcard)</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>yes iff standing in front of something looking like
|
||||
@<x>: or <x>:, skipping over ‘HERECOMMENT’s</p>
|
||||
<p>Returns <code>yes</code> if standing in front of something looking like
|
||||
<code>@<x>:</code>, <code><x>:</code> or <code><EXPRESSION_START><x>...<EXPRESSION_END>:</code>,
|
||||
skipping over ‘HERECOMMENT’s.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">looksObjectish</span>: <span class="hljs-function"><span class="hljs-params">(j)</span> -></span>
|
||||
<span class="hljs-property">@matchTags</span>(j, <span class="hljs-string">'@'</span>, <span class="hljs-literal">null</span>, <span class="hljs-string">':'</span>) <span class="hljs-keyword">or</span> <span class="hljs-property">@matchTags</span>(j, <span class="hljs-literal">null</span>, <span class="hljs-string">':'</span>)</pre></div></div>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">yes</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@indexOfTag</span>(j, <span class="hljs-string">'@'</span>, <span class="hljs-literal">null</span>, <span class="hljs-string">':'</span>) > -<span class="hljs-number">1</span> <span class="hljs-keyword">or</span> <span class="hljs-property">@indexOfTag</span>(j, <span class="hljs-literal">null</span>, <span class="hljs-string">':'</span>) > -<span class="hljs-number">1</span>
|
||||
index = <span class="hljs-property">@indexOfTag</span>(j, EXPRESSION_START)
|
||||
<span class="hljs-keyword">if</span> index > -<span class="hljs-number">1</span>
|
||||
end = <span class="hljs-literal">null</span>
|
||||
<span class="hljs-property">@detectEnd</span> index + <span class="hljs-number">1</span>, <span class="hljs-function"><span class="hljs-params">((token) -> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> EXPRESSION_END)</span>, <span class="hljs-params">((token, i) -> end = i)</span>
|
||||
<span class="hljs-title">return</span> <span class="hljs-title">yes</span> <span class="hljs-title">if</span> @<span class="hljs-title">tag</span><span class="hljs-params">(end + <span class="hljs-number">1</span>)</span> <span class="hljs-title">is</span> ':'
|
||||
<span class="hljs-title">no</span>
|
||||
|
||||
</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -356,7 +365,7 @@ or null (wildcard)</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>yes iff current line of tokens contain an element of tags on same
|
||||
<p>Returns <code>yes</code> if current line of tokens contain an element of tags on same
|
||||
expression level. Stop searching at LINEBREAKS or explicit start of
|
||||
containing balanced expression.</p>
|
||||
|
||||
@@ -403,12 +412,13 @@ add them.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> stack = []
|
||||
start = <span class="hljs-literal">null</span>
|
||||
|
||||
<span class="hljs-property">@scanTokens</span> <span class="hljs-function"><span class="hljs-params">(token, i, tokens)</span> -></span>
|
||||
[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 +435,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 +450,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 +468,28 @@ 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>, [<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
|
||||
val = <span class="hljs-keyword">new</span> String <span class="hljs-string">'{'</span>
|
||||
val.generated = <span class="hljs-literal">yes</span>
|
||||
tokens.splice idx, <span class="hljs-number">0</span>, generate <span class="hljs-string">'{'</span>, val, 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
|
||||
@@ -564,7 +576,7 @@ class declaration or if-conditionals)</p>
|
||||
endImplicitObject()
|
||||
<span class="hljs-keyword">else</span>
|
||||
stack.pop()
|
||||
stack.pop()</pre></div></div>
|
||||
start = stack.pop()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -580,7 +592,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">and</span> <span class="hljs-keyword">not</span> token.regexEnd <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">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,8 +631,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-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>
|
||||
<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">@indexOfTag</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-number">1</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>
|
||||
@@ -655,7 +667,10 @@ that creates grammatical ambiguities.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> <span class="hljs-property">@tag</span>(i - <span class="hljs-number">2</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'@'</span> <span class="hljs-keyword">then</span> s = i - <span class="hljs-number">2</span> <span class="hljs-keyword">else</span> s = i - <span class="hljs-number">1</span>
|
||||
<div class="content"><div class='highlight'><pre> s = <span class="hljs-keyword">switch</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-property">@tag</span>(i - <span class="hljs-number">1</span>) <span class="hljs-keyword">in</span> EXPRESSION_END <span class="hljs-keyword">then</span> start[<span class="hljs-number">1</span>]
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-property">@tag</span>(i - <span class="hljs-number">2</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'@'</span> <span class="hljs-keyword">then</span> i - <span class="hljs-number">2</span>
|
||||
<span class="hljs-keyword">else</span> i - <span class="hljs-number">1</span>
|
||||
s -= <span class="hljs-number">2</span> <span class="hljs-keyword">while</span> <span class="hljs-property">@tag</span>(s - <span class="hljs-number">2</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'HERECOMMENT'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -708,7 +723,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
|
||||
@@ -759,7 +774,7 @@ return a: 1, b: 2 unless true</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> inImplicitObject() <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@insideForDeclaration</span> <span class="hljs-keyword">and</span> sameLine <span class="hljs-keyword">and</span>
|
||||
tag <span class="hljs-keyword">isnt</span> <span class="hljs-string">'TERMINATOR'</span> <span class="hljs-keyword">and</span> prevTag <span class="hljs-keyword">isnt</span> <span class="hljs-string">':'</span> <span class="hljs-keyword">and</span>
|
||||
tag <span class="hljs-keyword">isnt</span> <span class="hljs-string">'TERMINATOR'</span> <span class="hljs-keyword">and</span> prevTag <span class="hljs-keyword">isnt</span> <span class="hljs-string">':'</span>
|
||||
endImplicitObject()</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -779,6 +794,7 @@ the continuation of an object.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> inImplicitObject() <span class="hljs-keyword">and</span> tag <span class="hljs-keyword">is</span> <span class="hljs-string">'TERMINATOR'</span> <span class="hljs-keyword">and</span> prevTag <span class="hljs-keyword">isnt</span> <span class="hljs-string">','</span> <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-keyword">not</span> (startsLine <span class="hljs-keyword">and</span> <span class="hljs-property">@looksObjectish</span>(i + <span class="hljs-number">1</span>))
|
||||
<span class="hljs-keyword">return</span> forward <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> nextTag <span class="hljs-keyword">is</span> <span class="hljs-string">'HERECOMMENT'</span>
|
||||
endImplicitObject()
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-keyword">break</span></pre></div></div>
|
||||
@@ -879,15 +895,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>
|
||||
@@ -931,13 +947,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>]
|
||||
|
||||
@@ -1033,6 +1049,8 @@ different precedence.</p>
|
||||
[<span class="hljs-string">'CALL_START'</span>, <span class="hljs-string">'CALL_END'</span>]
|
||||
[<span class="hljs-string">'PARAM_START'</span>, <span class="hljs-string">'PARAM_END'</span>]
|
||||
[<span class="hljs-string">'INDEX_START'</span>, <span class="hljs-string">'INDEX_END'</span>]
|
||||
[<span class="hljs-string">'STRING_START'</span>, <span class="hljs-string">'STRING_END'</span>]
|
||||
[<span class="hljs-string">'REGEX_START'</span>, <span class="hljs-string">'REGEX_END'</span>]
|
||||
]</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -1049,7 +1067,7 @@ look things up from either end.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.INVERSES = INVERSES = {}</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.INVERSES = INVERSES = {}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1115,9 +1133,10 @@ EXPRESSION_END = []
|
||||
</div>
|
||||
|
||||
<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">'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>
|
||||
<span class="hljs-string">'IDENTIFIER'</span>, <span class="hljs-string">'NUMBER'</span>, <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'STRING_START'</span>, <span class="hljs-string">'JS'</span>, <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">'REGEX_START'</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">'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>
|
||||
]
|
||||
|
||||
IMPLICIT_UNSPACED_CALL = [<span class="hljs-string">'+'</span>, <span class="hljs-string">'-'</span>]</pre></div></div>
|
||||
|
||||
@@ -121,13 +121,10 @@ function bodies. Each scope knows about the variables declared within it,
|
||||
and has a reference to its parent enclosing scope. In this way, we know which
|
||||
variables are new and need to be declared with <code>var</code>, and which are shared
|
||||
with external scopes.</p>
|
||||
<p>Import the helpers we plan to use.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>{extend, last} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
|
||||
exports.Scope = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Scope</span></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><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>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -274,11 +271,11 @@ walks up to the root scope.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">temporary</span>: <span class="hljs-function"><span class="hljs-params">(name, index)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> name.length > <span class="hljs-number">1</span>
|
||||
<span class="hljs-string">'_'</span> + name + <span class="hljs-keyword">if</span> index > <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> index - <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">temporary</span>: <span class="hljs-function"><span class="hljs-params">(name, index, single=<span class="hljs-literal">false</span>)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> single
|
||||
(index + parseInt name, <span class="hljs-number">36</span>).toString(<span class="hljs-number">36</span>).replace <span class="hljs-regexp">/\d/g</span>, <span class="hljs-string">'a'</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">'_'</span> + (index + parseInt name, <span class="hljs-number">36</span>).toString(<span class="hljs-number">36</span>).replace <span class="hljs-regexp">/\d/g</span>, <span class="hljs-string">'a'</span></pre></div></div>
|
||||
name + (index <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -311,13 +308,13 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
||||
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">freeVariable</span>: <span class="hljs-function"><span class="hljs-params">(name, options={})</span> -></span>
|
||||
index = <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">loop</span>
|
||||
temp = <span class="hljs-property">@temporary</span> name, index
|
||||
temp = <span class="hljs-property">@temporary</span> name, index, options.single
|
||||
<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
|
||||
<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> options.reserve ? <span class="hljs-literal">true</span>
|
||||
temp</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -368,11 +365,7 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">declaredVariables</span>:<span class="hljs-function"> -></span>
|
||||
realVars = []
|
||||
tempVars = []
|
||||
<span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> <span class="hljs-property">@variables</span> <span class="hljs-keyword">when</span> v.type <span class="hljs-keyword">is</span> <span class="hljs-string">'var'</span>
|
||||
(<span class="hljs-keyword">if</span> v.name.charAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-string">'_'</span> <span class="hljs-keyword">then</span> tempVars <span class="hljs-keyword">else</span> realVars).push v.name
|
||||
realVars.sort().concat tempVars.sort()</pre></div></div>
|
||||
(v.name <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> <span class="hljs-property">@variables</span> <span class="hljs-keyword">when</span> v.type <span class="hljs-keyword">is</span> <span class="hljs-string">'var'</span>).sort()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -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>.exports = SourceMap</pre></div></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>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -110,7 +110,7 @@
|
||||
|
||||
<p>
|
||||
<b>Latest Version:</b>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.9.0">1.9.0</a>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.9.1">1.9.1</a>
|
||||
</p>
|
||||
|
||||
<pre>npm install -g coffee-script</pre>
|
||||
@@ -1203,6 +1203,28 @@ Expressions
|
||||
Change Log
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
<%= releaseHeader('2015-02-18', '1.9.1', '1.9.0') %>
|
||||
<ul>
|
||||
<li>
|
||||
Interpolation now works in object literal keys (again). You can use this to
|
||||
dynamically name properties.
|
||||
</li>
|
||||
<li>
|
||||
Internal compiler names no longer start with underscores. This makes
|
||||
the generated JavaScript a bit prettier, and also fixes an issue with
|
||||
the completely broken and ungodly way that AngularJS "parses" function
|
||||
arguments.
|
||||
</li>
|
||||
<li>
|
||||
Fixed a few <tt>yield</tt>-related bugs.
|
||||
</li>
|
||||
<li>
|
||||
Minor bug fixes and various improvements to compiler error messages.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= releaseHeader('2015-01-29', '1.9.0', '1.8.0') %>
|
||||
<ul>
|
||||
@@ -1211,13 +1233,19 @@ Expressions
|
||||
that <tt>yield</tt>s.
|
||||
</li>
|
||||
<li>
|
||||
Improved error reporting for string interpolation.
|
||||
More robust parsing and improved error messages for strings and regexes —
|
||||
especially with respect to interpolation.
|
||||
</li>
|
||||
<li>
|
||||
Changed strategy for the generation of internal compiler variable names.
|
||||
Note that this means that <tt>@example</tt> function parameters are no longer
|
||||
available as naked <tt>example</tt> variables within the function body.
|
||||
</li>
|
||||
<li>
|
||||
Fixed REPL compatibility with latest versions of Node and IO.js.
|
||||
Fixed REPL compatibility with latest versions of Node and Io.js.
|
||||
</li>
|
||||
<li>
|
||||
Various minor bug fixes.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var volume, winner;
|
||||
|
||||
if (ignition === true) {
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var courses, dish, food, foods, i, j, k, l, len, len1, len2, ref;
|
||||
|
||||
_ref = ['toast', 'cheese', 'wine'];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
food = _ref[_i];
|
||||
ref = ['toast', 'cheese', 'wine'];
|
||||
for (j = 0, len = ref.length; j < len; j++) {
|
||||
food = ref[j];
|
||||
eat(food);
|
||||
}
|
||||
|
||||
courses = ['greens', 'caviar', 'truffles', 'roast', 'cake'];
|
||||
|
||||
for (i = _j = 0, _len1 = courses.length; _j < _len1; i = ++_j) {
|
||||
for (i = k = 0, len1 = courses.length; k < len1; i = ++k) {
|
||||
dish = courses[i];
|
||||
menu(i + 1, dish);
|
||||
}
|
||||
|
||||
foods = ['broccoli', 'spinach', 'chocolate'];
|
||||
|
||||
for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
|
||||
food = foods[_k];
|
||||
for (l = 0, len2 = foods.length; l < len2; l++) {
|
||||
food = foods[l];
|
||||
if (food !== 'chocolate') {
|
||||
eat(food);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
|
||||
/*
|
||||
SkinnyMochaHalfCaffScript Compiler v1.0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var fs;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
$('body').click(function(e) {
|
||||
return $('.box').fadeIn('fast').addClass('.active');
|
||||
}).css('background', 'white');
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
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;
|
||||
extend = 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(_at_name) {
|
||||
this.name = _at_name;
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Animal.prototype.move = function(meters) {
|
||||
@@ -16,8 +16,8 @@ Animal = (function() {
|
||||
|
||||
})();
|
||||
|
||||
Snake = (function(_super) {
|
||||
__extends(Snake, _super);
|
||||
Snake = (function(superClass) {
|
||||
extend(Snake, superClass);
|
||||
|
||||
function Snake() {
|
||||
return Snake.__super__.constructor.apply(this, arguments);
|
||||
@@ -32,8 +32,8 @@ Snake = (function(_super) {
|
||||
|
||||
})(Animal);
|
||||
|
||||
Horse = (function(_super) {
|
||||
__extends(Horse, _super);
|
||||
Horse = (function(superClass) {
|
||||
extend(Horse, superClass);
|
||||
|
||||
function Horse() {
|
||||
return Horse.__super__.constructor.apply(this, arguments);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var cholesterol, healthy;
|
||||
|
||||
cholesterol = 127;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var date, mood;
|
||||
|
||||
if (singing) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var Person, tim;
|
||||
|
||||
Person = (function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var fill;
|
||||
|
||||
fill = function(container, liquid) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var filename, _fn, _i, _len;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var filename, fn, i, len;
|
||||
|
||||
_fn = function(filename) {
|
||||
fn = function(filename) {
|
||||
return fs.readFile(filename, function(err, contents) {
|
||||
return compile(filename, contents.toString());
|
||||
});
|
||||
};
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
filename = list[_i];
|
||||
_fn(filename);
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
filename = list[i];
|
||||
fn(filename);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var hi;
|
||||
|
||||
hi = function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var footprints, solipsism, speed;
|
||||
|
||||
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var first, last, text, _ref;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var first, last, ref, text;
|
||||
|
||||
text = "Every literary critic believes he will outwit history and have the last word";
|
||||
|
||||
_ref = text.split(" "), first = _ref[0], last = _ref[_ref.length - 1];
|
||||
ref = text.split(" "), first = ref[0], last = ref[ref.length - 1];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var eldest, grade;
|
||||
|
||||
grade = function(student) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var one, six, three, two;
|
||||
|
||||
six = (one = 1) + (two = 2) + (three = 3);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var globals, name;
|
||||
|
||||
globals = ((function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
var results;
|
||||
results = [];
|
||||
for (name in window) {
|
||||
_results.push(name);
|
||||
results.push(name);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})()).slice(0, 10);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var error;
|
||||
|
||||
alert((function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var Account;
|
||||
|
||||
Account = function(customer, cart) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var cube, square;
|
||||
|
||||
square = function(x) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var perfectSquares;
|
||||
|
||||
perfectSquares = function*() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var html;
|
||||
|
||||
html = "<strong>\n cup of coffeescript\n</strong>";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var OPERATOR;
|
||||
|
||||
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var city, forecast, temp, weatherReport, _ref;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var city, forecast, ref, temp, weatherReport;
|
||||
|
||||
weatherReport = function(location) {
|
||||
return [location, 72, "Mostly Sunny"];
|
||||
};
|
||||
|
||||
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];
|
||||
ref = weatherReport("Berkeley, CA"), city = ref[0], temp = ref[1], forecast = ref[2];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var age, ages, child, yearsOld;
|
||||
|
||||
yearsOld = {
|
||||
@@ -8,11 +8,11 @@ yearsOld = {
|
||||
};
|
||||
|
||||
ages = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
var results;
|
||||
results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
_results.push(child + " is " + age);
|
||||
results.push(child + " is " + age);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var city, futurists, name, street, _ref, _ref1;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var city, futurists, name, ref, ref1, street;
|
||||
|
||||
futurists = {
|
||||
sculptor: "Umberto Boccioni",
|
||||
@@ -10,4 +10,4 @@ futurists = {
|
||||
}
|
||||
};
|
||||
|
||||
_ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[0], city = _ref1[1]);
|
||||
ref = futurists.poet, name = ref.name, (ref1 = ref.address, street = ref1[0], city = ref1[1]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var bitlist, kids, singers, song;
|
||||
|
||||
song = ["do", "re", "mi", "fa", "so"];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
$('.account').attr({
|
||||
"class": 'active'
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var cubes, list, math, num, number, opposite, race, square,
|
||||
__slice = [].slice;
|
||||
slice = [].slice;
|
||||
|
||||
number = 42;
|
||||
|
||||
@@ -26,7 +26,7 @@ math = {
|
||||
|
||||
race = function() {
|
||||
var runners, winner;
|
||||
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
winner = arguments[0], runners = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||
return print(winner, runners);
|
||||
};
|
||||
|
||||
@@ -35,11 +35,11 @@ if (typeof elvis !== "undefined" && elvis !== null) {
|
||||
}
|
||||
|
||||
cubes = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
num = list[_i];
|
||||
_results.push(math.cube(num));
|
||||
var i, len, results;
|
||||
results = [];
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
num = list[i];
|
||||
results.push(math.cube(num));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var theBait, theSwitch, _ref;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var ref, theBait, theSwitch;
|
||||
|
||||
theBait = 1000;
|
||||
|
||||
theSwitch = 0;
|
||||
|
||||
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
|
||||
ref = [theSwitch, theBait], theBait = ref[0], theSwitch = ref[1];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var close, contents, open, tag, _i, _ref,
|
||||
__slice = [].slice;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var close, contents, i, open, ref, tag,
|
||||
slice = [].slice;
|
||||
|
||||
tag = "<impossible>";
|
||||
|
||||
_ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call(_ref, 1, _i = _ref.length - 1) : (_i = 1, []), close = _ref[_i++];
|
||||
ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++];
|
||||
|
||||
2
documentation/js/prototypes.js
vendored
2
documentation/js/prototypes.js
vendored
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
String.prototype.dasherize = function() {
|
||||
return this.replace(/_/g, "-");
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var countdown, num;
|
||||
|
||||
countdown = (function() {
|
||||
var _i, _results;
|
||||
_results = [];
|
||||
for (num = _i = 10; _i >= 1; num = --_i) {
|
||||
_results.push(num);
|
||||
var i, results;
|
||||
results = [];
|
||||
for (num = i = 10; i >= 1; num = --i) {
|
||||
results.push(num);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var changeNumbers, inner, outer;
|
||||
|
||||
outer = 1;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var copy, end, middle, numbers, start;
|
||||
|
||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var zip, _ref;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var ref, zip;
|
||||
|
||||
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;
|
||||
zip = typeof lottery.drawWinner === "function" ? (ref = lottery.drawWinner().address) != null ? ref.zipcode : void 0 : void 0;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var awardMedals, contenders, gold, rest, silver,
|
||||
__slice = [].slice;
|
||||
slice = [].slice;
|
||||
|
||||
gold = silver = rest = "unknown";
|
||||
|
||||
awardMedals = function() {
|
||||
var first, others, second;
|
||||
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
||||
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
||||
gold = first;
|
||||
silver = second;
|
||||
return rest = others;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
var numbers, _ref;
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var numbers, ref;
|
||||
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
[].splice.apply(numbers, [3, 4].concat(_ref = [-3, -4, -5, -6])), _ref;
|
||||
[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
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.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
switch (day) {
|
||||
case "Mon":
|
||||
go(work);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var grade, score;
|
||||
|
||||
score = 76;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var error;
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
var lyrics, num;
|
||||
|
||||
if (this.studyingEconomics) {
|
||||
@@ -13,10 +13,10 @@ if (this.studyingEconomics) {
|
||||
num = 6;
|
||||
|
||||
lyrics = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
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;
|
||||
return results;
|
||||
})();
|
||||
|
||||
File diff suppressed because one or more lines are too long
258
index.html
258
index.html
@@ -110,7 +110,7 @@
|
||||
|
||||
<p>
|
||||
<b>Latest Version:</b>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.9.0">1.9.0</a>
|
||||
<a href="http://github.com/jashkenas/coffeescript/tarball/1.9.1">1.9.1</a>
|
||||
</p>
|
||||
|
||||
<pre>npm install -g coffee-script</pre>
|
||||
@@ -151,7 +151,7 @@ alert <span class="string">"I knew it!"</span> <span class="keyword">if</span> e
|
||||
<span class="comment"># Array comprehensions:</span>
|
||||
cubes = (math.cube num <span class="keyword">for</span> num <span class="keyword">in</span> list)
|
||||
</code></pre><pre><code><span class="keyword">var</span> cubes, list, math, num, number, opposite, race, square,
|
||||
__slice = [].slice;
|
||||
slice = [].slice;
|
||||
|
||||
number = <span class="number">42</span>;
|
||||
|
||||
@@ -177,7 +177,7 @@ math = {
|
||||
|
||||
race = <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> runners, winner;
|
||||
winner = <span class="built_in">arguments</span>[<span class="number">0</span>], runners = <span class="number">2</span> <= <span class="built_in">arguments</span>.length ? __slice.call(<span class="built_in">arguments</span>, <span class="number">1</span>) : [];
|
||||
winner = <span class="built_in">arguments</span>[<span class="number">0</span>], runners = <span class="number">2</span> <= <span class="built_in">arguments</span>.length ? slice.call(<span class="built_in">arguments</span>, <span class="number">1</span>) : [];
|
||||
<span class="keyword">return</span> print(winner, runners);
|
||||
};
|
||||
|
||||
@@ -186,16 +186,16 @@ race = <span class="function"><span class="keyword">function</span><span class="
|
||||
}
|
||||
|
||||
cubes = (<span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> _i, _len, _results;
|
||||
_results = [];
|
||||
<span class="keyword">for</span> (_i = <span class="number">0</span>, _len = list.length; _i < _len; _i++) {
|
||||
num = list[_i];
|
||||
_results.push(math.cube(num));
|
||||
<span class="keyword">var</span> i, len, results;
|
||||
results = [];
|
||||
<span class="keyword">for</span> (i = <span class="number">0</span>, len = list.length; i < len; i++) {
|
||||
num = list[i];
|
||||
results.push(math.cube(num));
|
||||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
<span class="keyword">return</span> results;
|
||||
})();
|
||||
</code></pre><script>window.example1 = "# Assignment:\nnumber = 42\nopposite = true\n\n# Conditions:\nnumber = -42 if opposite\n\n# Functions:\nsquare = (x) -> x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)\n"</script><div class='minibutton ok' onclick='javascript: var cubes, list, math, num, number, opposite, race, square,
|
||||
__slice = [].slice;
|
||||
slice = [].slice;
|
||||
|
||||
number = 42;
|
||||
|
||||
@@ -221,7 +221,7 @@ math = {
|
||||
|
||||
race = function() {
|
||||
var runners, winner;
|
||||
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
winner = arguments[0], runners = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||
return print(winner, runners);
|
||||
};
|
||||
|
||||
@@ -230,13 +230,13 @@ if (typeof elvis !== "undefined" && elvis !== null) {
|
||||
}
|
||||
|
||||
cubes = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
num = list[_i];
|
||||
_results.push(math.cube(num));
|
||||
var i, len, results;
|
||||
results = [];
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
num = list[i];
|
||||
results.push(math.cube(num));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
;alert(cubes);'>run: cubes</div><br class='clear' /></div>
|
||||
|
||||
@@ -807,13 +807,13 @@ alert <span class="string">"The Field: "</span> + rest
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> awardMedals, contenders, gold, rest, silver,
|
||||
__slice = [].slice;
|
||||
slice = [].slice;
|
||||
|
||||
gold = silver = rest = <span class="string">"unknown"</span>;
|
||||
|
||||
awardMedals = <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> first, others, second;
|
||||
first = <span class="built_in">arguments</span>[<span class="number">0</span>], second = <span class="built_in">arguments</span>[<span class="number">1</span>], others = <span class="number">3</span> <= <span class="built_in">arguments</span>.length ? __slice.call(<span class="built_in">arguments</span>, <span class="number">2</span>) : [];
|
||||
first = <span class="built_in">arguments</span>[<span class="number">0</span>], second = <span class="built_in">arguments</span>[<span class="number">1</span>], others = <span class="number">3</span> <= <span class="built_in">arguments</span>.length ? slice.call(<span class="built_in">arguments</span>, <span class="number">2</span>) : [];
|
||||
gold = first;
|
||||
silver = second;
|
||||
<span class="keyword">return</span> rest = others;
|
||||
@@ -829,13 +829,13 @@ 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,
|
||||
__slice = [].slice;
|
||||
slice = [].slice;
|
||||
|
||||
gold = silver = rest = "unknown";
|
||||
|
||||
awardMedals = function() {
|
||||
var first, others, second;
|
||||
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
||||
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
||||
gold = first;
|
||||
silver = second;
|
||||
return rest = others;
|
||||
@@ -871,25 +871,25 @@ menu i + <span class="number">1</span>, dish <span class="keyword">for</span> di
|
||||
<span class="comment"># Health conscious meal.</span>
|
||||
foods = [<span class="string">'broccoli'</span>, <span class="string">'spinach'</span>, <span class="string">'chocolate'</span>]
|
||||
eat food <span class="keyword">for</span> food <span class="keyword">in</span> foods <span class="keyword">when</span> food <span class="keyword">isnt</span> <span class="string">'chocolate'</span>
|
||||
</code></pre><pre><code><span class="keyword">var</span> courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
|
||||
</code></pre><pre><code><span class="keyword">var</span> courses, dish, food, foods, i, j, k, l, len, len1, len2, ref;
|
||||
|
||||
_ref = [<span class="string">'toast'</span>, <span class="string">'cheese'</span>, <span class="string">'wine'</span>];
|
||||
<span class="keyword">for</span> (_i = <span class="number">0</span>, _len = _ref.length; _i < _len; _i++) {
|
||||
food = _ref[_i];
|
||||
ref = [<span class="string">'toast'</span>, <span class="string">'cheese'</span>, <span class="string">'wine'</span>];
|
||||
<span class="keyword">for</span> (j = <span class="number">0</span>, len = ref.length; j < len; j++) {
|
||||
food = ref[j];
|
||||
eat(food);
|
||||
}
|
||||
|
||||
courses = [<span class="string">'greens'</span>, <span class="string">'caviar'</span>, <span class="string">'truffles'</span>, <span class="string">'roast'</span>, <span class="string">'cake'</span>];
|
||||
|
||||
<span class="keyword">for</span> (i = _j = <span class="number">0</span>, _len1 = courses.length; _j < _len1; i = ++_j) {
|
||||
<span class="keyword">for</span> (i = k = <span class="number">0</span>, len1 = courses.length; k < len1; i = ++k) {
|
||||
dish = courses[i];
|
||||
menu(i + <span class="number">1</span>, dish);
|
||||
}
|
||||
|
||||
foods = [<span class="string">'broccoli'</span>, <span class="string">'spinach'</span>, <span class="string">'chocolate'</span>];
|
||||
|
||||
<span class="keyword">for</span> (_k = <span class="number">0</span>, _len2 = foods.length; _k < _len2; _k++) {
|
||||
food = foods[_k];
|
||||
<span class="keyword">for</span> (l = <span class="number">0</span>, len2 = foods.length; l < len2; l++) {
|
||||
food = foods[l];
|
||||
<span class="keyword">if</span> (food !== <span class="string">'chocolate'</span>) {
|
||||
eat(food);
|
||||
}
|
||||
@@ -908,22 +908,22 @@ foods = [<span class="string">'broccoli'</span>, <span class="string">'spinach'<
|
||||
</code></pre><pre><code><span class="keyword">var</span> countdown, num;
|
||||
|
||||
countdown = (<span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> _i, _results;
|
||||
_results = [];
|
||||
<span class="keyword">for</span> (num = _i = <span class="number">10</span>; _i >= <span class="number">1</span>; num = --_i) {
|
||||
_results.push(num);
|
||||
<span class="keyword">var</span> i, results;
|
||||
results = [];
|
||||
<span class="keyword">for</span> (num = i = <span class="number">10</span>; i >= <span class="number">1</span>; num = --i) {
|
||||
results.push(num);
|
||||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
<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;
|
||||
|
||||
countdown = (function() {
|
||||
var _i, _results;
|
||||
_results = [];
|
||||
for (num = _i = 10; _i >= 1; num = --_i) {
|
||||
_results.push(num);
|
||||
var i, results;
|
||||
results = [];
|
||||
for (num = i = 10; i >= 1; num = --i) {
|
||||
results.push(num);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
;alert(countdown);'>run: countdown</div><br class='clear' /></div>
|
||||
<p>
|
||||
@@ -958,13 +958,13 @@ yearsOld = {
|
||||
};
|
||||
|
||||
ages = (<span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> _results;
|
||||
_results = [];
|
||||
<span class="keyword">var</span> results;
|
||||
results = [];
|
||||
<span class="keyword">for</span> (child <span class="keyword">in</span> yearsOld) {
|
||||
age = yearsOld[child];
|
||||
_results.push(child + <span class="string">" is "</span> + age);
|
||||
results.push(child + <span class="string">" is "</span> + age);
|
||||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
<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;
|
||||
|
||||
@@ -975,13 +975,13 @@ yearsOld = {
|
||||
};
|
||||
|
||||
ages = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
var results;
|
||||
results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
_results.push(child + " is " + age);
|
||||
results.push(child + " is " + age);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
;alert(ages.join(", "));'>run: ages.join(", ")</div><br class='clear' /></div>
|
||||
<p>
|
||||
@@ -1020,12 +1020,12 @@ lyrics = <span class="keyword">while</span> num -= <span class="number">1</span>
|
||||
num = <span class="number">6</span>;
|
||||
|
||||
lyrics = (<span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> _results;
|
||||
_results = [];
|
||||
<span class="keyword">var</span> results;
|
||||
results = [];
|
||||
<span class="keyword">while</span> (num -= <span class="number">1</span>) {
|
||||
_results.push(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;
|
||||
<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;
|
||||
|
||||
@@ -1041,12 +1041,12 @@ if (this.studyingEconomics) {
|
||||
num = 6;
|
||||
|
||||
lyrics = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
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;
|
||||
return results;
|
||||
})();
|
||||
;alert(lyrics.join("
|
||||
"));'>run: lyrics.join("
|
||||
@@ -1065,16 +1065,16 @@ lyrics = (function() {
|
||||
<div class='code'><pre><code><span class="keyword">for</span> filename <span class="keyword">in</span> list
|
||||
<span class="keyword">do</span> <span class="function"><span class="params">(filename)</span> -></span>
|
||||
fs.readFile filename, <span class="function"><span class="params">(err, contents)</span> -></span>
|
||||
compile filename, contents.toString()</code></pre><pre><code><span class="keyword">var</span> filename, _fn, _i, _len;
|
||||
compile filename, contents.toString()</code></pre><pre><code><span class="keyword">var</span> filename, fn, i, len;
|
||||
|
||||
_fn = <span class="function"><span class="keyword">function</span><span class="params">(filename)</span> {</span>
|
||||
fn = <span class="function"><span class="keyword">function</span><span class="params">(filename)</span> {</span>
|
||||
<span class="keyword">return</span> fs.readFile(filename, <span class="function"><span class="keyword">function</span><span class="params">(err, contents)</span> {</span>
|
||||
<span class="keyword">return</span> compile(filename, contents.toString());
|
||||
});
|
||||
};
|
||||
<span class="keyword">for</span> (_i = <span class="number">0</span>, _len = list.length; _i < _len; _i++) {
|
||||
filename = list[_i];
|
||||
_fn(filename);
|
||||
<span class="keyword">for</span> (i = <span class="number">0</span>, len = list.length; i < len; i++) {
|
||||
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>
|
||||
|
||||
@@ -1129,16 +1129,16 @@ numbers[<span class="number">3.</span><span class="number">.6</span>] = [-<span
|
||||
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> numbers, _ref;
|
||||
</code></pre><pre><code><span class="keyword">var</span> numbers, ref;
|
||||
|
||||
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;
|
||||
[].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;
|
||||
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
[].splice.apply(numbers, [3, 4].concat(_ref = [-3, -4, -5, -6])), _ref;
|
||||
[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
|
||||
;alert(numbers);'>run: numbers</div><br class='clear' /></div>
|
||||
<p>
|
||||
Note that JavaScript strings are immutable, and can't be spliced.
|
||||
@@ -1226,22 +1226,22 @@ six = (one = 1) + (two = 2) + (three = 3);
|
||||
globals = (name <span class="keyword">for</span> name <span class="keyword">of</span> <span class="built_in">window</span>)[<span class="number">0.</span>.<span class="number">.10</span>]</code></pre><pre><code><span class="keyword">var</span> globals, name;
|
||||
|
||||
globals = ((<span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">var</span> _results;
|
||||
_results = [];
|
||||
<span class="keyword">var</span> results;
|
||||
results = [];
|
||||
<span class="keyword">for</span> (name <span class="keyword">in</span> window) {
|
||||
_results.push(name);
|
||||
results.push(name);
|
||||
}
|
||||
<span class="keyword">return</span> _results;
|
||||
<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;
|
||||
|
||||
globals = ((function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
var results;
|
||||
results = [];
|
||||
for (name in window) {
|
||||
_results.push(name);
|
||||
results.push(name);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})()).slice(0, 10);
|
||||
;alert(globals);'>run: globals</div><br class='clear' /></div>
|
||||
<p>
|
||||
@@ -1439,9 +1439,9 @@ footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear";
|
||||
the <b>TypeError</b> that would be raised otherwise.
|
||||
</p>
|
||||
<div class='code'><pre><code>zip = lottery.drawWinner?().address?.zipcode
|
||||
</code></pre><pre><code><span class="keyword">var</span> zip, _ref;
|
||||
</code></pre><pre><code><span class="keyword">var</span> ref, zip;
|
||||
|
||||
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>;
|
||||
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>
|
||||
<p>
|
||||
Soaking up nulls is similar to Ruby's
|
||||
@@ -1501,12 +1501,12 @@ tom.move()
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> Animal, Horse, Snake, sam, tom,
|
||||
__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;
|
||||
extend = <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">(_at_name)</span> {</span>
|
||||
<span class="keyword">this</span>.name = _at_name;
|
||||
<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;
|
||||
}
|
||||
|
||||
Animal.prototype.move = <span class="function"><span class="keyword">function</span><span class="params">(meters)</span> {</span>
|
||||
@@ -1517,8 +1517,8 @@ Animal = (<span class="function"><span class="keyword">function</span><span clas
|
||||
|
||||
})();
|
||||
|
||||
Snake = (<span class="function"><span class="keyword">function</span><span class="params">(_super)</span> {</span>
|
||||
__extends(Snake, _super);
|
||||
Snake = (<span class="function"><span class="keyword">function</span><span class="params">(superClass)</span> {</span>
|
||||
extend(Snake, superClass);
|
||||
|
||||
<span class="function"><span class="keyword">function</span> <span class="title">Snake</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">return</span> Snake.__super__.constructor.apply(<span class="keyword">this</span>, <span class="built_in">arguments</span>);
|
||||
@@ -1533,8 +1533,8 @@ Snake = (<span class="function"><span class="keyword">function</span><span class
|
||||
|
||||
})(Animal);
|
||||
|
||||
Horse = (<span class="function"><span class="keyword">function</span><span class="params">(_super)</span> {</span>
|
||||
__extends(Horse, _super);
|
||||
Horse = (<span class="function"><span class="keyword">function</span><span class="params">(superClass)</span> {</span>
|
||||
extend(Horse, superClass);
|
||||
|
||||
<span class="function"><span class="keyword">function</span> <span class="title">Horse</span><span class="params">()</span> {</span>
|
||||
<span class="keyword">return</span> Horse.__super__.constructor.apply(<span class="keyword">this</span>, <span class="built_in">arguments</span>);
|
||||
@@ -1557,12 +1557,12 @@ 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,
|
||||
__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;
|
||||
extend = 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(_at_name) {
|
||||
this.name = _at_name;
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Animal.prototype.move = function(meters) {
|
||||
@@ -1573,8 +1573,8 @@ Animal = (function() {
|
||||
|
||||
})();
|
||||
|
||||
Snake = (function(_super) {
|
||||
__extends(Snake, _super);
|
||||
Snake = (function(superClass) {
|
||||
extend(Snake, superClass);
|
||||
|
||||
function Snake() {
|
||||
return Snake.__super__.constructor.apply(this, arguments);
|
||||
@@ -1589,8 +1589,8 @@ Snake = (function(_super) {
|
||||
|
||||
})(Animal);
|
||||
|
||||
Horse = (function(_super) {
|
||||
__extends(Horse, _super);
|
||||
Horse = (function(superClass) {
|
||||
extend(Horse, superClass);
|
||||
|
||||
function Horse() {
|
||||
return Horse.__super__.constructor.apply(this, arguments);
|
||||
@@ -1658,20 +1658,20 @@ theSwitch = <span class="number">0</span>
|
||||
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> theBait, theSwitch, _ref;
|
||||
</code></pre><pre><code><span class="keyword">var</span> ref, theBait, theSwitch;
|
||||
|
||||
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;
|
||||
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 ref, theBait, theSwitch;
|
||||
|
||||
theBait = 1000;
|
||||
|
||||
theSwitch = 0;
|
||||
|
||||
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
|
||||
ref = [theSwitch, theBait], theBait = ref[0], theSwitch = ref[1];
|
||||
;alert(theBait);'>run: theBait</div><br class='clear' /></div>
|
||||
<p>
|
||||
But it's also helpful for dealing with functions that return multiple
|
||||
@@ -1686,20 +1686,20 @@ _ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
|
||||
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> city, forecast, temp, weatherReport, _ref;
|
||||
</code></pre><pre><code><span class="keyword">var</span> city, forecast, ref, temp, weatherReport;
|
||||
|
||||
weatherReport = <span class="function"><span class="keyword">function</span><span class="params">(location)</span> {</span>
|
||||
<span class="keyword">return</span> [location, <span class="number">72</span>, <span class="string">"Mostly Sunny"</span>];
|
||||
};
|
||||
|
||||
_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;
|
||||
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, ref, temp, weatherReport;
|
||||
|
||||
weatherReport = function(location) {
|
||||
return [location, 72, "Mostly Sunny"];
|
||||
};
|
||||
|
||||
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];
|
||||
ref = weatherReport("Berkeley, CA"), city = ref[0], temp = ref[1], forecast = ref[2];
|
||||
;alert(forecast);'>run: forecast</div><br class='clear' /></div>
|
||||
<p>
|
||||
Destructuring assignment can be used with any depth of array and object nesting,
|
||||
@@ -1719,7 +1719,7 @@ _ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast =
|
||||
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> city, futurists, name, street, _ref, _ref1;
|
||||
</code></pre><pre><code><span class="keyword">var</span> city, futurists, name, ref, ref1, street;
|
||||
|
||||
futurists = {
|
||||
sculptor: <span class="string">"Umberto Boccioni"</span>,
|
||||
@@ -1730,8 +1730,8 @@ 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;
|
||||
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, ref, ref1, street;
|
||||
|
||||
futurists = {
|
||||
sculptor: "Umberto Boccioni",
|
||||
@@ -1742,7 +1742,7 @@ futurists = {
|
||||
}
|
||||
};
|
||||
|
||||
_ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[0], city = _ref1[1]);
|
||||
ref = futurists.poet, name = ref.name, (ref1 = ref.address, street = ref1[0], city = ref1[1]);
|
||||
;alert(name + "-" + street);'>run: name + "-" + street</div><br class='clear' /></div>
|
||||
<p>
|
||||
Destructuring assignment can even be combined with splats.
|
||||
@@ -1756,18 +1756,18 @@ _ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[0
|
||||
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> close, contents, open, tag, _i, _ref,
|
||||
__slice = [].slice;
|
||||
</code></pre><pre><code><span class="keyword">var</span> close, contents, i, open, ref, tag,
|
||||
slice = [].slice;
|
||||
|
||||
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,
|
||||
__slice = [].slice;
|
||||
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, i, open, ref, tag,
|
||||
slice = [].slice;
|
||||
|
||||
tag = "<impossible>";
|
||||
|
||||
_ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call(_ref, 1, _i = _ref.length - 1) : (_i = 1, []), close = _ref[_i++];
|
||||
ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++];
|
||||
;alert(contents.join(""));'>run: contents.join("")</div><br class='clear' /></div>
|
||||
<p>
|
||||
Expansion can be used to retrieve elements from the end of an array without having to assign the rest of its values. It works in function parameter lists as well.
|
||||
@@ -1779,16 +1779,16 @@ _ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call
|
||||
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> first, last, text, _ref;
|
||||
</code></pre><pre><code><span class="keyword">var</span> first, last, ref, text;
|
||||
|
||||
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;
|
||||
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, ref, text;
|
||||
|
||||
text = "Every literary critic believes he will outwit history and have the last word";
|
||||
|
||||
_ref = text.split(" "), first = _ref[0], last = _ref[_ref.length - 1];
|
||||
ref = text.split(" "), first = ref[0], last = ref[ref.length - 1];
|
||||
;alert(first + " " + last);'>run: first + " " + last</div><br class='clear' /></div>
|
||||
<p>
|
||||
Destructuring assignment is also useful when combined with class constructors
|
||||
@@ -2491,6 +2491,32 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
||||
Change Log
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
<div class="anchor" id="1.9.1"></div>
|
||||
<b class="header">
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/1.9.0...1.9.1">1.9.1</a>
|
||||
<span class="timestamp"> — <time datetime="2015-02-18">February 18, 2015</time></span>
|
||||
</b>
|
||||
<ul>
|
||||
<li>
|
||||
Interpolation now works in object literal keys (again). You can use this to
|
||||
dynamically name properties.
|
||||
</li>
|
||||
<li>
|
||||
Internal compiler names no longer start with underscores. This makes
|
||||
the generated JavaScript a bit prettier, and also fixes an issue with
|
||||
the completely broken and ungodly way that AngularJS "parses" function
|
||||
arguments.
|
||||
</li>
|
||||
<li>
|
||||
Fixed a few <tt>yield</tt>-related bugs.
|
||||
</li>
|
||||
<li>
|
||||
Minor bug fixes and various improvements to compiler error messages.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<div class="anchor" id="1.9.0"></div>
|
||||
<b class="header">
|
||||
@@ -2503,13 +2529,19 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
||||
that <tt>yield</tt>s.
|
||||
</li>
|
||||
<li>
|
||||
Improved error reporting for string interpolation.
|
||||
More robust parsing and improved error messages for strings and regexes —
|
||||
especially with respect to interpolation.
|
||||
</li>
|
||||
<li>
|
||||
Changed strategy for the generation of internal compiler variable names.
|
||||
Note that this means that <tt>@example</tt> function parameters are no longer
|
||||
available as naked <tt>example</tt> variables within the function body.
|
||||
</li>
|
||||
<li>
|
||||
Fixed REPL compatibility with latest versions of Node and IO.js.
|
||||
Fixed REPL compatibility with latest versions of Node and Io.js.
|
||||
</li>
|
||||
<li>
|
||||
Various minor bug fixes.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(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; };
|
||||
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; };
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
@@ -34,13 +34,13 @@
|
||||
|
||||
if ((typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null) && (typeof unescape !== "undefined" && unescape !== null) && (typeof encodeURIComponent !== "undefined" && encodeURIComponent !== null)) {
|
||||
compile = function(code, options) {
|
||||
var js, v3SourceMap, _ref;
|
||||
var js, ref, v3SourceMap;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
options.sourceMap = true;
|
||||
options.inline = true;
|
||||
_ref = CoffeeScript.compile(code, options), js = _ref.js, v3SourceMap = _ref.v3SourceMap;
|
||||
ref = CoffeeScript.compile(code, options), js = ref.js, v3SourceMap = ref.v3SourceMap;
|
||||
return js + "\n//# sourceMappingURL=data:application/json;base64," + (btoa(unescape(encodeURIComponent(v3SourceMap)))) + "\n//# sourceURL=coffeescript";
|
||||
};
|
||||
}
|
||||
@@ -60,9 +60,9 @@
|
||||
xhr.overrideMimeType('text/plain');
|
||||
}
|
||||
xhr.onreadystatechange = function() {
|
||||
var param, _ref;
|
||||
var param, ref;
|
||||
if (xhr.readyState === 4) {
|
||||
if ((_ref = xhr.status) === 0 || _ref === 200) {
|
||||
if ((ref = xhr.status) === 0 || ref === 200) {
|
||||
param = [xhr.responseText, options];
|
||||
if (!hold) {
|
||||
CoffeeScript.run.apply(CoffeeScript, param);
|
||||
@@ -79,19 +79,19 @@
|
||||
};
|
||||
|
||||
runScripts = function() {
|
||||
var coffees, coffeetypes, execute, i, index, s, script, scripts, _fn, _i, _len;
|
||||
var coffees, coffeetypes, execute, fn, i, index, j, len, s, script, scripts;
|
||||
scripts = window.document.getElementsByTagName('script');
|
||||
coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
|
||||
coffees = (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
|
||||
s = scripts[_i];
|
||||
if (_ref = s.type, __indexOf.call(coffeetypes, _ref) >= 0) {
|
||||
_results.push(s);
|
||||
var j, len, ref, results;
|
||||
results = [];
|
||||
for (j = 0, len = scripts.length; j < len; j++) {
|
||||
s = scripts[j];
|
||||
if (ref = s.type, indexOf.call(coffeetypes, ref) >= 0) {
|
||||
results.push(s);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
index = 0;
|
||||
execute = function() {
|
||||
@@ -103,7 +103,7 @@
|
||||
return execute();
|
||||
}
|
||||
};
|
||||
_fn = function(script, i) {
|
||||
fn = function(script, i) {
|
||||
var options;
|
||||
options = {
|
||||
literate: script.type === coffeetypes[1]
|
||||
@@ -118,9 +118,9 @@
|
||||
return coffees[i] = [script.innerHTML, options];
|
||||
}
|
||||
};
|
||||
for (i = _i = 0, _len = coffees.length; _i < _len; i = ++_i) {
|
||||
for (i = j = 0, len = coffees.length; j < len; i = ++j) {
|
||||
script = coffees[i];
|
||||
_fn(script, i);
|
||||
fn(script, i);
|
||||
}
|
||||
return execute();
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
|
||||
helpers.extend(global, {
|
||||
task: function(name, description, action) {
|
||||
var _ref;
|
||||
var ref;
|
||||
if (!action) {
|
||||
_ref = [description, action], action = _ref[0], description = _ref[1];
|
||||
ref = [description, action], action = ref[0], description = ref[1];
|
||||
}
|
||||
return tasks[name] = {
|
||||
name: name,
|
||||
@@ -46,7 +46,7 @@
|
||||
});
|
||||
|
||||
exports.run = function() {
|
||||
var arg, args, e, _i, _len, _ref, _results;
|
||||
var arg, args, e, i, len, ref, results;
|
||||
global.__originalDirname = fs.realpathSync('.');
|
||||
process.chdir(cakefileDirectory(__originalDirname));
|
||||
args = process.argv.slice(2);
|
||||
@@ -63,13 +63,13 @@
|
||||
e = _error;
|
||||
return fatalError("" + e);
|
||||
}
|
||||
_ref = options["arguments"];
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
arg = _ref[_i];
|
||||
_results.push(invoke(arg));
|
||||
ref = options["arguments"];
|
||||
results = [];
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
arg = ref[i];
|
||||
results.push(invoke(arg));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
};
|
||||
|
||||
printTasks = function() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var Lexer, SourceMap, compile, ext, formatSourcePosition, fs, getSourceMap, helpers, lexer, parser, path, sourceMaps, vm, withPrettyErrors, _base, _i, _len, _ref,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__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; };
|
||||
var Lexer, SourceMap, base, compile, ext, formatSourcePosition, fs, getSourceMap, helpers, i, len, lexer, parser, path, ref, sourceMaps, vm, withPrettyErrors,
|
||||
hasProp = {}.hasOwnProperty,
|
||||
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; };
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
SourceMap = require('./sourcemap');
|
||||
|
||||
exports.VERSION = '1.9.0';
|
||||
exports.VERSION = '1.9.1';
|
||||
|
||||
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
};
|
||||
|
||||
exports.compile = compile = withPrettyErrors(function(code, options) {
|
||||
var answer, currentColumn, currentLine, extend, fragment, fragments, header, js, map, merge, newLines, token, tokens, _i, _len;
|
||||
var answer, currentColumn, currentLine, extend, fragment, fragments, header, i, js, len, map, merge, newLines, token, tokens;
|
||||
merge = helpers.merge, extend = helpers.extend;
|
||||
options = extend({}, options);
|
||||
if (options.sourceMap) {
|
||||
@@ -48,15 +48,15 @@
|
||||
}
|
||||
tokens = lexer.tokenize(code, options);
|
||||
options.referencedVars = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
||||
token = tokens[_i];
|
||||
if (token.variable && token[1].charAt(0) === '_') {
|
||||
_results.push(token[1]);
|
||||
var i, len, results;
|
||||
results = [];
|
||||
for (i = 0, len = tokens.length; i < len; i++) {
|
||||
token = tokens[i];
|
||||
if (token.variable) {
|
||||
results.push(token[1]);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
fragments = parser.parse(tokens).compileToFragments(options);
|
||||
currentLine = 0;
|
||||
@@ -68,8 +68,8 @@
|
||||
}
|
||||
currentColumn = 0;
|
||||
js = "";
|
||||
for (_i = 0, _len = fragments.length; _i < _len; _i++) {
|
||||
fragment = fragments[_i];
|
||||
for (i = 0, len = fragments.length; i < len; i++) {
|
||||
fragment = fragments[i];
|
||||
if (options.sourceMap) {
|
||||
if (fragment.locationData) {
|
||||
map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
|
||||
@@ -115,7 +115,7 @@
|
||||
});
|
||||
|
||||
exports.run = function(code, options) {
|
||||
var answer, dir, mainModule, _ref;
|
||||
var answer, dir, mainModule, ref;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
@@ -126,21 +126,21 @@
|
||||
mainModule.paths = require('module')._nodeModulePaths(dir);
|
||||
if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
|
||||
answer = compile(code, options);
|
||||
code = (_ref = answer.js) != null ? _ref : answer;
|
||||
code = (ref = answer.js) != null ? ref : answer;
|
||||
}
|
||||
return mainModule._compile(code, mainModule.filename);
|
||||
};
|
||||
|
||||
exports["eval"] = function(code, options) {
|
||||
var Module, createContext, isContext, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _ref2, _ref3, _require;
|
||||
var Module, _module, _require, createContext, i, isContext, js, k, len, o, r, ref, ref1, ref2, ref3, sandbox, v;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (!(code = code.trim())) {
|
||||
return;
|
||||
}
|
||||
createContext = (_ref = vm.Script.createContext) != null ? _ref : vm.createContext;
|
||||
isContext = (_ref1 = vm.isContext) != null ? _ref1 : function(ctx) {
|
||||
createContext = (ref = vm.Script.createContext) != null ? ref : vm.createContext;
|
||||
isContext = (ref1 = vm.isContext) != null ? ref1 : function(ctx) {
|
||||
return options.sandbox instanceof createContext().constructor;
|
||||
};
|
||||
if (createContext) {
|
||||
@@ -149,10 +149,10 @@
|
||||
sandbox = options.sandbox;
|
||||
} else {
|
||||
sandbox = createContext();
|
||||
_ref2 = options.sandbox;
|
||||
for (k in _ref2) {
|
||||
if (!__hasProp.call(_ref2, k)) continue;
|
||||
v = _ref2[k];
|
||||
ref2 = options.sandbox;
|
||||
for (k in ref2) {
|
||||
if (!hasProp.call(ref2, k)) continue;
|
||||
v = ref2[k];
|
||||
sandbox[k] = v;
|
||||
}
|
||||
}
|
||||
@@ -169,9 +169,9 @@
|
||||
return Module._load(path, _module, true);
|
||||
};
|
||||
_module.filename = sandbox.__filename;
|
||||
_ref3 = Object.getOwnPropertyNames(require);
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
||||
r = _ref3[_i];
|
||||
ref3 = Object.getOwnPropertyNames(require);
|
||||
for (i = 0, len = ref3.length; i < len; i++) {
|
||||
r = ref3[i];
|
||||
if (r !== 'paths') {
|
||||
_require[r] = require[r];
|
||||
}
|
||||
@@ -184,7 +184,7 @@
|
||||
}
|
||||
o = {};
|
||||
for (k in options) {
|
||||
if (!__hasProp.call(options, k)) continue;
|
||||
if (!hasProp.call(options, k)) continue;
|
||||
v = options[k];
|
||||
o[k] = v;
|
||||
}
|
||||
@@ -202,11 +202,11 @@
|
||||
};
|
||||
|
||||
if (require.extensions) {
|
||||
_ref = this.FILE_EXTENSIONS;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
ext = _ref[_i];
|
||||
if ((_base = require.extensions)[ext] == null) {
|
||||
_base[ext] = function() {
|
||||
ref = this.FILE_EXTENSIONS;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
ext = ref[i];
|
||||
if ((base = require.extensions)[ext] == null) {
|
||||
base[ext] = function() {
|
||||
throw new Error("Use CoffeeScript.register() or require the coffee-script/register module to require " + ext + " files.");
|
||||
};
|
||||
}
|
||||
@@ -259,12 +259,23 @@
|
||||
|
||||
parser.yy = require('./nodes');
|
||||
|
||||
parser.yy.parseError = function(message, _arg) {
|
||||
parser.yy.parseError = function(message, arg) {
|
||||
var errorLoc, errorTag, errorText, errorToken, token, tokens;
|
||||
token = _arg.token;
|
||||
token = arg.token;
|
||||
errorToken = parser.errorToken, tokens = parser.tokens;
|
||||
errorTag = errorToken[0], errorText = errorToken[1], errorLoc = errorToken[2];
|
||||
errorText = errorToken === tokens[tokens.length - 1] ? 'end of input' : errorTag === 'INDENT' || errorTag === 'OUTDENT' ? 'indentation' : helpers.nameWhitespaceCharacter(errorText);
|
||||
errorText = (function() {
|
||||
switch (false) {
|
||||
case errorToken !== tokens[tokens.length - 1]:
|
||||
return 'end of input';
|
||||
case errorTag !== 'INDENT' && errorTag !== 'OUTDENT':
|
||||
return 'indentation';
|
||||
case errorTag !== 'IDENTIFIER' && errorTag !== 'NUMBER' && errorTag !== 'STRING' && errorTag !== 'STRING_START' && errorTag !== 'REGEX' && errorTag !== 'REGEX_START':
|
||||
return errorTag.replace(/_START$/, '').toLowerCase();
|
||||
default:
|
||||
return helpers.nameWhitespaceCharacter(errorText);
|
||||
}
|
||||
})();
|
||||
return helpers.throwSyntaxError("unexpected " + errorText, errorLoc);
|
||||
};
|
||||
|
||||
@@ -319,11 +330,11 @@
|
||||
sourceMaps = {};
|
||||
|
||||
getSourceMap = function(filename) {
|
||||
var answer, _ref1;
|
||||
var answer, ref1;
|
||||
if (sourceMaps[filename]) {
|
||||
return sourceMaps[filename];
|
||||
}
|
||||
if (_ref1 = path != null ? path.extname(filename) : void 0, __indexOf.call(exports.FILE_EXTENSIONS, _ref1) < 0) {
|
||||
if (ref1 = path != null ? path.extname(filename) : void 0, indexOf.call(exports.FILE_EXTENSIONS, ref1) < 0) {
|
||||
return;
|
||||
}
|
||||
answer = exports._compileFile(filename, true);
|
||||
@@ -345,16 +356,16 @@
|
||||
}
|
||||
};
|
||||
frames = (function() {
|
||||
var _j, _len1, _results;
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = stack.length; _j < _len1; _j++) {
|
||||
frame = stack[_j];
|
||||
var j, len1, results;
|
||||
results = [];
|
||||
for (j = 0, len1 = stack.length; j < len1; j++) {
|
||||
frame = stack[j];
|
||||
if (frame.getFunction() === exports.run) {
|
||||
break;
|
||||
}
|
||||
_results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));
|
||||
results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
return (err.toString()) + "\n" + (frames.join('\n')) + "\n";
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(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; };
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, jsToSources, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, ref, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs,
|
||||
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; };
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
_ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec;
|
||||
ref = require('child_process'), spawn = ref.spawn, exec = ref.exec;
|
||||
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
@@ -49,8 +49,10 @@
|
||||
|
||||
optionParser = null;
|
||||
|
||||
jsToSources = {};
|
||||
|
||||
exports.run = function() {
|
||||
var literals, replCliOpts, source, _i, _len, _ref1, _results;
|
||||
var i, len, literals, ref1, replCliOpts, results, source;
|
||||
parseOptions();
|
||||
replCliOpts = {
|
||||
useGlobal: true
|
||||
@@ -86,19 +88,19 @@
|
||||
opts.join = path.resolve(opts.join);
|
||||
console.error('\nThe --join option is deprecated and will be removed in a future version.\n\nIf for some reason it\'s necessary to share local variables between files,\nreplace...\n\n $ coffee --compile --join bundle.js -- a.coffee b.coffee c.coffee\n\nwith...\n\n $ cat a.coffee b.coffee c.coffee | coffee --compile --stdio > bundle.js\n');
|
||||
}
|
||||
_ref1 = opts["arguments"];
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
source = _ref1[_i];
|
||||
ref1 = opts["arguments"];
|
||||
results = [];
|
||||
for (i = 0, len = ref1.length; i < len; i++) {
|
||||
source = ref1[i];
|
||||
source = path.resolve(source);
|
||||
_results.push(compilePath(source, true, source));
|
||||
results.push(compilePath(source, true, source));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
};
|
||||
|
||||
compilePath = function(source, topLevel, base) {
|
||||
var code, err, file, files, stats, _i, _len, _results;
|
||||
if (__indexOf.call(sources, source) >= 0 || watchedDirs[source] || !topLevel && (notSources[source] || hidden(source))) {
|
||||
var code, err, file, files, i, len, results, stats;
|
||||
if (indexOf.call(sources, source) >= 0 || watchedDirs[source] || !topLevel && (notSources[source] || hidden(source))) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -133,12 +135,12 @@
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
_results.push(compilePath(path.join(source, file), false, base));
|
||||
results = [];
|
||||
for (i = 0, len = files.length; i < len; i++) {
|
||||
file = files[i];
|
||||
results.push(compilePath(path.join(source, file), false, base));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
} else if (topLevel || helpers.isCoffee(source)) {
|
||||
sources.push(source);
|
||||
sourceCode.push(null);
|
||||
@@ -163,10 +165,10 @@
|
||||
};
|
||||
|
||||
findDirectoryIndex = function(source) {
|
||||
var err, ext, index, _i, _len, _ref1;
|
||||
_ref1 = CoffeeScript.FILE_EXTENSIONS;
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
ext = _ref1[_i];
|
||||
var err, ext, i, index, len, ref1;
|
||||
ref1 = CoffeeScript.FILE_EXTENSIONS;
|
||||
for (i = 0, len = ref1.length; i < len; i++) {
|
||||
ext = ref1[i];
|
||||
index = path.join(source, "index" + ext);
|
||||
try {
|
||||
if ((fs.statSync(index)).isFile()) {
|
||||
@@ -279,7 +281,7 @@
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
if (__indexOf.call(sources, source) < 0) {
|
||||
if (indexOf.call(sources, source) < 0) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -346,7 +348,7 @@
|
||||
}).on('change', function() {
|
||||
clearTimeout(readdirTimeout);
|
||||
return readdirTimeout = wait(25, function() {
|
||||
var err, file, files, _i, _len, _results;
|
||||
var err, file, files, i, len, results;
|
||||
try {
|
||||
files = fs.readdirSync(source);
|
||||
} catch (_error) {
|
||||
@@ -356,12 +358,12 @@
|
||||
}
|
||||
return stopWatcher();
|
||||
}
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
_results.push(compilePath(path.join(source, file), false, base));
|
||||
results = [];
|
||||
for (i = 0, len = files.length; i < len; i++) {
|
||||
file = files[i];
|
||||
results.push(compilePath(path.join(source, file), false, base));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -381,11 +383,11 @@
|
||||
};
|
||||
|
||||
removeSourceDir = function(source, base) {
|
||||
var file, sourcesChanged, _i, _len;
|
||||
var file, i, len, sourcesChanged;
|
||||
delete watchedDirs[source];
|
||||
sourcesChanged = false;
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
for (i = 0, len = sources.length; i < len; i++) {
|
||||
file = sources[i];
|
||||
if (!(source === path.dirname(file))) {
|
||||
continue;
|
||||
}
|
||||
@@ -410,12 +412,12 @@
|
||||
};
|
||||
|
||||
silentUnlink = function(path) {
|
||||
var err, _ref1;
|
||||
var err, ref1;
|
||||
try {
|
||||
return fs.unlinkSync(path);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if ((_ref1 = err.code) !== 'ENOENT' && _ref1 !== 'EPERM') {
|
||||
if ((ref1 = err.code) !== 'ENOENT' && ref1 !== 'EPERM') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -466,6 +468,13 @@
|
||||
}
|
||||
sourceMapPath = outputPath(sourcePath, base, ".js.map");
|
||||
jsDir = path.dirname(jsPath);
|
||||
if (jsPath in jsToSources) {
|
||||
printLine("Error: The two following source files have the same output file:");
|
||||
printLine(" " + jsToSources[jsPath]);
|
||||
printLine(" " + sourcePath);
|
||||
process.exit(1);
|
||||
}
|
||||
jsToSources[jsPath] = sourcePath;
|
||||
compile = function() {
|
||||
if (opts.compile) {
|
||||
if (js.length <= 0) {
|
||||
@@ -512,15 +521,15 @@
|
||||
printTokens = function(tokens) {
|
||||
var strings, tag, token, value;
|
||||
strings = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
||||
token = tokens[_i];
|
||||
var i, len, results;
|
||||
results = [];
|
||||
for (i = 0, len = tokens.length; i < len; i++) {
|
||||
token = tokens[i];
|
||||
tag = token[0];
|
||||
value = token[1].toString().replace(/\n/, '\\n');
|
||||
_results.push("[" + tag + " " + value + "]");
|
||||
results.push("[" + tag + " " + value + "]");
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
return printLine(strings.join(' '));
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||
|
||||
@@ -63,16 +63,26 @@
|
||||
AlphaNumeric: [
|
||||
o('NUMBER', function() {
|
||||
return new Literal($1);
|
||||
}), o('STRING', function() {
|
||||
}), o('String')
|
||||
],
|
||||
String: [
|
||||
o('STRING', function() {
|
||||
return new Literal($1);
|
||||
}), o('STRING_START Body STRING_END', function() {
|
||||
return new Parens($2);
|
||||
})
|
||||
],
|
||||
Regex: [
|
||||
o('REGEX', function() {
|
||||
return new Literal($1);
|
||||
}), o('REGEX_START Invocation REGEX_END', function() {
|
||||
return $2;
|
||||
})
|
||||
],
|
||||
Literal: [
|
||||
o('AlphaNumeric'), o('JS', function() {
|
||||
return new Literal($1);
|
||||
}), o('REGEX', function() {
|
||||
return new Literal($1);
|
||||
}), o('DEBUGGER', function() {
|
||||
}), o('Regex'), o('DEBUGGER', function() {
|
||||
return new Literal($1);
|
||||
}), o('UNDEFINED', function() {
|
||||
return new Undefined;
|
||||
@@ -612,13 +622,13 @@
|
||||
for (name in grammar) {
|
||||
alternatives = grammar[name];
|
||||
grammar[name] = (function() {
|
||||
var _i, _j, _len, _len1, _ref, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
|
||||
alt = alternatives[_i];
|
||||
_ref = alt[0].split(' ');
|
||||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
||||
token = _ref[_j];
|
||||
var i, j, len, len1, ref, results;
|
||||
results = [];
|
||||
for (i = 0, len = alternatives.length; i < len; i++) {
|
||||
alt = alternatives[i];
|
||||
ref = alt[0].split(' ');
|
||||
for (j = 0, len1 = ref.length; j < len1; j++) {
|
||||
token = ref[j];
|
||||
if (!grammar[token]) {
|
||||
tokens.push(token);
|
||||
}
|
||||
@@ -626,9 +636,9 @@
|
||||
if (name === 'Root') {
|
||||
alt[1] = "return " + alt[1];
|
||||
}
|
||||
_results.push(alt);
|
||||
results.push(alt);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
|
||||
var buildLocationData, extend, flatten, ref, repeat, syntaxErrorToString;
|
||||
|
||||
exports.starts = function(string, literal, start) {
|
||||
return literal === string.substr(start, literal.length);
|
||||
@@ -26,15 +26,15 @@
|
||||
};
|
||||
|
||||
exports.compact = function(array) {
|
||||
var item, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||
item = array[_i];
|
||||
var i, item, len1, results;
|
||||
results = [];
|
||||
for (i = 0, len1 = array.length; i < len1; i++) {
|
||||
item = array[i];
|
||||
if (item) {
|
||||
_results.push(item);
|
||||
results.push(item);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
};
|
||||
|
||||
exports.count = function(string, substr) {
|
||||
@@ -63,10 +63,10 @@
|
||||
};
|
||||
|
||||
exports.flatten = flatten = function(array) {
|
||||
var element, flattened, _i, _len;
|
||||
var element, flattened, i, len1;
|
||||
flattened = [];
|
||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||
element = array[_i];
|
||||
for (i = 0, len1 = array.length; i < len1; i++) {
|
||||
element = array[i];
|
||||
if (element instanceof Array) {
|
||||
flattened = flattened.concat(flatten(element));
|
||||
} else {
|
||||
@@ -83,14 +83,10 @@
|
||||
return val;
|
||||
};
|
||||
|
||||
exports.last = last = function(array, back) {
|
||||
return array[array.length - (back || 0) - 1];
|
||||
};
|
||||
|
||||
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
|
||||
var e, _i, _len;
|
||||
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
||||
e = this[_i];
|
||||
exports.some = (ref = Array.prototype.some) != null ? ref : function(fn) {
|
||||
var e, i, len1;
|
||||
for (i = 0, len1 = this.length; i < len1; i++) {
|
||||
e = this[i];
|
||||
if (fn(e)) {
|
||||
return true;
|
||||
}
|
||||
@@ -102,20 +98,20 @@
|
||||
var line, lines, maybe_code;
|
||||
maybe_code = true;
|
||||
lines = (function() {
|
||||
var _i, _len, _ref1, _results;
|
||||
_ref1 = code.split('\n');
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
line = _ref1[_i];
|
||||
var i, len1, ref1, results;
|
||||
ref1 = code.split('\n');
|
||||
results = [];
|
||||
for (i = 0, len1 = ref1.length; i < len1; i++) {
|
||||
line = ref1[i];
|
||||
if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
|
||||
_results.push(line);
|
||||
results.push(line);
|
||||
} else if (maybe_code = /^\s*$/.test(line)) {
|
||||
_results.push(line);
|
||||
results.push(line);
|
||||
} else {
|
||||
_results.push('# ' + line);
|
||||
results.push('# ' + line);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
return lines.join('\n');
|
||||
};
|
||||
@@ -205,11 +201,11 @@
|
||||
};
|
||||
|
||||
syntaxErrorToString = function() {
|
||||
var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
|
||||
var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, ref1, ref2, start;
|
||||
if (!(this.code && this.location)) {
|
||||
return Error.prototype.toString.call(this);
|
||||
}
|
||||
_ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
|
||||
ref1 = this.location, first_line = ref1.first_line, first_column = ref1.first_column, last_line = ref1.last_line, last_column = ref1.last_column;
|
||||
if (last_line == null) {
|
||||
last_line = first_line;
|
||||
}
|
||||
@@ -224,7 +220,7 @@
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
|
||||
}
|
||||
if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
|
||||
if ((ref2 = this.colorful) != null ? ref2 : colorsEnabled) {
|
||||
colorize = function(str) {
|
||||
return "\x1B[1;31m" + str + "\x1B[0m";
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var key, val, _ref;
|
||||
var key, ref, val;
|
||||
|
||||
_ref = require('./coffee-script');
|
||||
for (key in _ref) {
|
||||
val = _ref[key];
|
||||
ref = require('./coffee-script');
|
||||
for (key in ref) {
|
||||
val = ref[key];
|
||||
exports[key] = val;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(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; };
|
||||
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, INVALID_ESCAPE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, RELATION, RESERVED, Rewriter, SHIFT, SIMPLE_STRING_OMIT, 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, locationDataToString, ref, ref1, repeat, starts, throwSyntaxError,
|
||||
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; };
|
||||
|
||||
_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
|
||||
ref = require('./rewriter'), Rewriter = ref.Rewriter, INVERSES = ref.INVERSES;
|
||||
|
||||
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, repeat = _ref1.repeat, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
|
||||
ref1 = require('./helpers'), count = ref1.count, starts = ref1.starts, compact = ref1.compact, repeat = ref1.repeat, invertLiterate = ref1.invertLiterate, locationDataToString = ref1.locationDataToString, throwSyntaxError = ref1.throwSyntaxError;
|
||||
|
||||
exports.Lexer = Lexer = (function() {
|
||||
function Lexer() {}
|
||||
|
||||
Lexer.prototype.tokenize = function(code, opts) {
|
||||
var consumed, end, i, _ref2;
|
||||
var consumed, end, i, ref2;
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
@@ -29,7 +29,7 @@
|
||||
i = 0;
|
||||
while (this.chunk = code.slice(i)) {
|
||||
consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
||||
_ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];
|
||||
ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = ref2[0], this.chunkColumn = ref2[1];
|
||||
i += consumed;
|
||||
if (opts.untilBalanced && this.ends.length === 0) {
|
||||
return {
|
||||
@@ -40,7 +40,7 @@
|
||||
}
|
||||
this.closeIndentation();
|
||||
if (end = this.ends.pop()) {
|
||||
throwSyntaxError("missing " + end.tag, end.origin[2]);
|
||||
this.error("missing " + end.tag, end.origin[2]);
|
||||
}
|
||||
if (opts.rewrite === false) {
|
||||
return this.tokens;
|
||||
@@ -64,7 +64,7 @@
|
||||
};
|
||||
|
||||
Lexer.prototype.identifierToken = function() {
|
||||
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
|
||||
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, ref2, ref3, ref4, ref5, tag, tagToken;
|
||||
if (!(match = IDENTIFIER.exec(this.chunk))) {
|
||||
return 0;
|
||||
}
|
||||
@@ -79,19 +79,20 @@
|
||||
this.token('FROM', id);
|
||||
return id.length;
|
||||
}
|
||||
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');
|
||||
ref2 = this.tokens, prev = ref2[ref2.length - 1];
|
||||
forcedIdentifier = colon || (prev != null) && (((ref3 = prev[0]) === '.' || ref3 === '?.' || ref3 === '::' || ref3 === '?::') || !prev.spaced && prev[0] === '@');
|
||||
tag = 'IDENTIFIER';
|
||||
if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
|
||||
if (!forcedIdentifier && (indexOf.call(JS_KEYWORDS, id) >= 0 || indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
|
||||
tag = id.toUpperCase();
|
||||
if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
|
||||
if (tag === 'WHEN' && (ref4 = this.tag(), indexOf.call(LINE_BREAK, ref4) >= 0)) {
|
||||
tag = 'LEADING_WHEN';
|
||||
} else if (tag === 'FOR') {
|
||||
this.seenFor = true;
|
||||
} else if (tag === 'UNLESS') {
|
||||
tag = 'IF';
|
||||
} else if (__indexOf.call(UNARY, tag) >= 0) {
|
||||
} else if (indexOf.call(UNARY, tag) >= 0) {
|
||||
tag = 'UNARY';
|
||||
} else if (__indexOf.call(RELATION, tag) >= 0) {
|
||||
} else if (indexOf.call(RELATION, tag) >= 0) {
|
||||
if (tag !== 'INSTANCEOF' && this.seenFor) {
|
||||
tag = 'FOR' + tag;
|
||||
this.seenFor = false;
|
||||
@@ -104,17 +105,19 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {
|
||||
if (indexOf.call(JS_FORBIDDEN, id) >= 0) {
|
||||
if (forcedIdentifier) {
|
||||
tag = 'IDENTIFIER';
|
||||
id = new String(id);
|
||||
id.reserved = true;
|
||||
} else if (__indexOf.call(RESERVED, id) >= 0) {
|
||||
this.error("reserved word \"" + id + "\"");
|
||||
} else if (indexOf.call(RESERVED, id) >= 0) {
|
||||
this.error("reserved word '" + id + "'", {
|
||||
length: id.length
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!forcedIdentifier) {
|
||||
if (__indexOf.call(COFFEE_ALIASES, id) >= 0) {
|
||||
if (indexOf.call(COFFEE_ALIASES, id) >= 0) {
|
||||
id = COFFEE_ALIAS_MAP[id];
|
||||
}
|
||||
tag = (function() {
|
||||
@@ -141,7 +144,7 @@
|
||||
tagToken = this.token(tag, id, 0, idLength);
|
||||
tagToken.variable = !forcedIdentifier;
|
||||
if (poppedToken) {
|
||||
_ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];
|
||||
ref5 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = ref5[0], tagToken[2].first_column = ref5[1];
|
||||
}
|
||||
if (colon) {
|
||||
colonOffset = input.lastIndexOf(':');
|
||||
@@ -156,16 +159,24 @@
|
||||
return 0;
|
||||
}
|
||||
number = match[0];
|
||||
if (/^0[BOX]/.test(number)) {
|
||||
this.error("radix prefix '" + number + "' must be lowercase");
|
||||
} else if (/E/.test(number) && !/^0x/.test(number)) {
|
||||
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
|
||||
} else if (/^0\d*[89]/.test(number)) {
|
||||
this.error("decimal literal '" + number + "' must not be prefixed with '0'");
|
||||
} else if (/^0\d+/.test(number)) {
|
||||
this.error("octal literal '" + number + "' must be prefixed with '0o'");
|
||||
}
|
||||
lexedLength = number.length;
|
||||
if (/^0[BOX]/.test(number)) {
|
||||
this.error("radix prefix in '" + number + "' must be lowercase", {
|
||||
offset: 1
|
||||
});
|
||||
} else if (/E/.test(number) && !/^0x/.test(number)) {
|
||||
this.error("exponential notation in '" + number + "' must be indicated with a lowercase 'e'", {
|
||||
offset: number.indexOf('E')
|
||||
});
|
||||
} else if (/^0\d*[89]/.test(number)) {
|
||||
this.error("decimal literal '" + number + "' must not be prefixed with '0'", {
|
||||
length: lexedLength
|
||||
});
|
||||
} else if (/^0\d+/.test(number)) {
|
||||
this.error("octal literal '" + number + "' must be prefixed with '0o'", {
|
||||
length: lexedLength
|
||||
});
|
||||
}
|
||||
if (octalLiteral = /^0o([0-7]+)/.exec(number)) {
|
||||
number = '0x' + parseInt(octalLiteral[1], 8).toString(16);
|
||||
}
|
||||
@@ -177,7 +188,7 @@
|
||||
};
|
||||
|
||||
Lexer.prototype.stringToken = function() {
|
||||
var $, attempt, doc, end, heredoc, i, indent, indentRegex, match, quote, regex, start, token, tokens, _ref2, _ref3;
|
||||
var $, attempt, delimiter, doc, end, heredoc, i, indent, indentRegex, match, quote, ref2, ref3, regex, token, tokens;
|
||||
quote = (STRING_START.exec(this.chunk) || [])[0];
|
||||
if (!quote) {
|
||||
return 0;
|
||||
@@ -195,25 +206,25 @@
|
||||
}
|
||||
})();
|
||||
heredoc = quote.length === 3;
|
||||
start = quote.length;
|
||||
_ref2 = this.matchWithInterpolations(this.chunk.slice(start), regex, quote, start), tokens = _ref2.tokens, end = _ref2.index;
|
||||
ref2 = this.matchWithInterpolations(regex, quote), tokens = ref2.tokens, end = ref2.index;
|
||||
$ = tokens.length - 1;
|
||||
delimiter = quote[0];
|
||||
if (heredoc) {
|
||||
indent = null;
|
||||
doc = ((function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
|
||||
var j, len, results;
|
||||
results = [];
|
||||
for (i = j = 0, len = tokens.length; j < len; i = ++j) {
|
||||
token = tokens[i];
|
||||
if (token[0] === 'NEOSTRING') {
|
||||
_results.push(token[1]);
|
||||
results.push(token[1]);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})()).join('#{}');
|
||||
while (match = HEREDOC_INDENT.exec(doc)) {
|
||||
attempt = match[1];
|
||||
if (indent === null || (0 < (_ref3 = attempt.length) && _ref3 < indent.length)) {
|
||||
if (indent === null || (0 < (ref3 = attempt.length) && ref3 < indent.length)) {
|
||||
indent = attempt;
|
||||
}
|
||||
}
|
||||
@@ -221,9 +232,7 @@
|
||||
indentRegex = RegExp("^" + indent, "gm");
|
||||
}
|
||||
this.mergeInterpolationTokens(tokens, {
|
||||
quote: quote[0],
|
||||
start: start,
|
||||
end: end
|
||||
delimiter: delimiter
|
||||
}, (function(_this) {
|
||||
return function(value, i) {
|
||||
value = _this.formatString(value);
|
||||
@@ -233,20 +242,19 @@
|
||||
if (i === $) {
|
||||
value = value.replace(TRAILING_BLANK_LINE, '');
|
||||
}
|
||||
value = value.replace(indentRegex, '');
|
||||
value = value.replace(MULTILINER, '\\n');
|
||||
if (indentRegex) {
|
||||
value = value.replace(indentRegex, '');
|
||||
}
|
||||
return value;
|
||||
};
|
||||
})(this));
|
||||
} else {
|
||||
this.mergeInterpolationTokens(tokens, {
|
||||
quote: quote,
|
||||
start: start,
|
||||
end: end
|
||||
delimiter: delimiter
|
||||
}, (function(_this) {
|
||||
return function(value, i) {
|
||||
value = _this.formatString(value);
|
||||
value = value.replace(STRING_OMIT, function(match, offset) {
|
||||
value = value.replace(SIMPLE_STRING_OMIT, function(match, offset) {
|
||||
if ((i === 0 && offset === 0) || (i === $ && offset + match.length === value.length)) {
|
||||
return '';
|
||||
} else {
|
||||
@@ -268,7 +276,10 @@
|
||||
comment = match[0], here = match[1];
|
||||
if (here) {
|
||||
if (match = HERECOMMENT_ILLEGAL.exec(comment)) {
|
||||
this.error("block comments cannot contain " + match[0], match.index);
|
||||
this.error("block comments cannot contain " + match[0], {
|
||||
offset: match.index,
|
||||
length: match[0].length
|
||||
});
|
||||
}
|
||||
if (here.indexOf('\n') >= 0) {
|
||||
here = here.replace(RegExp("\\n" + (repeat(' ', this.indent)), "g"), '\n');
|
||||
@@ -288,24 +299,30 @@
|
||||
};
|
||||
|
||||
Lexer.prototype.regexToken = function() {
|
||||
var closed, end, flags, index, match, prev, re, regex, rparen, tokens, _ref2, _ref3, _ref4;
|
||||
var body, closed, end, flags, index, match, origin, prev, ref2, ref3, ref4, regex, tokens;
|
||||
switch (false) {
|
||||
case !(match = REGEX_ILLEGAL.exec(this.chunk)):
|
||||
this.error("regular expressions cannot begin with " + match[2], match.index + match[1].length);
|
||||
this.error("regular expressions cannot begin with " + match[2], {
|
||||
offset: match.index + match[1].length
|
||||
});
|
||||
break;
|
||||
case this.chunk.slice(0, 3) !== '///':
|
||||
_ref2 = this.matchWithInterpolations(this.chunk.slice(3), HEREGEX, '///', 3), tokens = _ref2.tokens, index = _ref2.index;
|
||||
case !(match = this.matchWithInterpolations(HEREGEX, '///')):
|
||||
tokens = match.tokens, index = match.index;
|
||||
break;
|
||||
case !(match = REGEX.exec(this.chunk)):
|
||||
regex = match[0], closed = match[1];
|
||||
regex = match[0], body = match[1], closed = match[2];
|
||||
this.validateEscapes(body, {
|
||||
isRegex: true,
|
||||
offsetInChunk: 1
|
||||
});
|
||||
index = regex.length;
|
||||
prev = last(this.tokens);
|
||||
ref2 = this.tokens, prev = ref2[ref2.length - 1];
|
||||
if (prev) {
|
||||
if (prev.spaced && (_ref3 = prev[0], __indexOf.call(CALLABLE, _ref3) >= 0) && !prev.stringEnd && !prev.regexEnd) {
|
||||
if (prev.spaced && (ref3 = prev[0], indexOf.call(CALLABLE, ref3) >= 0)) {
|
||||
if (!closed || POSSIBLY_DIVISION.test(regex)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (_ref4 = prev[0], __indexOf.call(NOT_REGEX, _ref4) >= 0) {
|
||||
} else if (ref4 = prev[0], indexOf.call(NOT_REGEX, ref4) >= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -318,35 +335,36 @@
|
||||
}
|
||||
flags = REGEX_FLAGS.exec(this.chunk.slice(index))[0];
|
||||
end = index + flags.length;
|
||||
origin = this.makeToken('REGEX', null, 0, end);
|
||||
switch (false) {
|
||||
case !!VALID_FLAGS.test(flags):
|
||||
this.error("invalid regular expression flags " + flags, index);
|
||||
this.error("invalid regular expression flags " + flags, {
|
||||
offset: index,
|
||||
length: flags.length
|
||||
});
|
||||
break;
|
||||
case !regex:
|
||||
this.token('REGEX', "" + regex + flags);
|
||||
break;
|
||||
case tokens.length !== 1:
|
||||
re = this.formatHeregex(tokens[0][1]).replace(/\//g, '\\/');
|
||||
this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
|
||||
case !(regex || tokens.length === 1):
|
||||
if (body == null) {
|
||||
body = this.formatHeregex(tokens[0][1]);
|
||||
}
|
||||
this.token('REGEX', "" + (this.makeDelimitedLiteral(body, {
|
||||
delimiter: '/'
|
||||
})) + flags, 0, end, origin);
|
||||
break;
|
||||
default:
|
||||
this.token('REGEX_START', '(', 0, 0, origin);
|
||||
this.token('IDENTIFIER', 'RegExp', 0, 0);
|
||||
this.token('CALL_START', '(', 0, 0);
|
||||
this.mergeInterpolationTokens(tokens, {
|
||||
quote: '"',
|
||||
start: 3,
|
||||
end: end
|
||||
}, (function(_this) {
|
||||
return function(value) {
|
||||
return _this.formatHeregex(value).replace(/\\/g, '\\\\');
|
||||
};
|
||||
})(this));
|
||||
delimiter: '"',
|
||||
double: true
|
||||
}, this.formatHeregex);
|
||||
if (flags) {
|
||||
this.token(',', ',', index, 0);
|
||||
this.token('STRING', '"' + flags + '"', index, flags.length);
|
||||
}
|
||||
rparen = this.token(')', ')', end, 0);
|
||||
rparen.regexEnd = true;
|
||||
this.token(')', ')', end, 0);
|
||||
this.token('REGEX_END', ')', end, 0);
|
||||
}
|
||||
return end;
|
||||
};
|
||||
@@ -387,7 +405,9 @@
|
||||
this.outdebt = this.indebt = 0;
|
||||
this.indent = size;
|
||||
} else if (size < this.baseIndent) {
|
||||
this.error('missing indentation', indent.length);
|
||||
this.error('missing indentation', {
|
||||
offset: indent.length
|
||||
});
|
||||
} else {
|
||||
this.indebt = 0;
|
||||
this.outdentToken(this.indent - size, noNewlines, indent.length);
|
||||
@@ -396,7 +416,7 @@
|
||||
};
|
||||
|
||||
Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
|
||||
var decreasedIndent, dent, lastIndent, _ref2;
|
||||
var decreasedIndent, dent, lastIndent, ref2;
|
||||
decreasedIndent = this.indent - moveOut;
|
||||
while (moveOut > 0) {
|
||||
lastIndent = this.indents[this.indents.length - 1];
|
||||
@@ -410,7 +430,7 @@
|
||||
moveOut -= lastIndent;
|
||||
} else {
|
||||
dent = this.indents.pop() + this.outdebt;
|
||||
if (outdentLength && (_ref2 = this.chunk[outdentLength], __indexOf.call(INDENTABLE_CLOSERS, _ref2) >= 0)) {
|
||||
if (outdentLength && (ref2 = this.chunk[outdentLength], indexOf.call(INDENTABLE_CLOSERS, ref2) >= 0)) {
|
||||
decreasedIndent -= dent - moveOut;
|
||||
moveOut = dent;
|
||||
}
|
||||
@@ -434,11 +454,11 @@
|
||||
};
|
||||
|
||||
Lexer.prototype.whitespaceToken = function() {
|
||||
var match, nline, prev;
|
||||
var match, nline, prev, ref2;
|
||||
if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
|
||||
return 0;
|
||||
}
|
||||
prev = last(this.tokens);
|
||||
ref2 = this.tokens, prev = ref2[ref2.length - 1];
|
||||
if (prev) {
|
||||
prev[match ? 'spaced' : 'newLine'] = true;
|
||||
}
|
||||
@@ -467,7 +487,7 @@
|
||||
};
|
||||
|
||||
Lexer.prototype.literalToken = function() {
|
||||
var match, prev, tag, token, value, _ref2, _ref3, _ref4, _ref5;
|
||||
var match, prev, ref2, ref3, ref4, ref5, ref6, tag, token, value;
|
||||
if (match = OPERATOR.exec(this.chunk)) {
|
||||
value = match[0];
|
||||
if (CODE.test(value)) {
|
||||
@@ -477,12 +497,12 @@
|
||||
value = this.chunk.charAt(0);
|
||||
}
|
||||
tag = value;
|
||||
prev = last(this.tokens);
|
||||
ref2 = this.tokens, prev = ref2[ref2.length - 1];
|
||||
if (value === '=' && prev) {
|
||||
if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
|
||||
this.error("reserved word \"" + (this.value()) + "\" can't be assigned");
|
||||
if (!prev[1].reserved && (ref3 = prev[1], indexOf.call(JS_FORBIDDEN, ref3) >= 0)) {
|
||||
this.error("reserved word '" + prev[1] + "' can't be assigned", prev[2]);
|
||||
}
|
||||
if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
|
||||
if ((ref4 = prev[1]) === '||' || ref4 === '&&') {
|
||||
prev[0] = 'COMPOUND_ASSIGN';
|
||||
prev[1] += '=';
|
||||
return value.length;
|
||||
@@ -491,27 +511,27 @@
|
||||
if (value === ';') {
|
||||
this.seenFor = false;
|
||||
tag = 'TERMINATOR';
|
||||
} else if (__indexOf.call(MATH, value) >= 0) {
|
||||
} else if (indexOf.call(MATH, value) >= 0) {
|
||||
tag = 'MATH';
|
||||
} else if (__indexOf.call(COMPARE, value) >= 0) {
|
||||
} else if (indexOf.call(COMPARE, value) >= 0) {
|
||||
tag = 'COMPARE';
|
||||
} else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
|
||||
} else if (indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
|
||||
tag = 'COMPOUND_ASSIGN';
|
||||
} else if (__indexOf.call(UNARY, value) >= 0) {
|
||||
} else if (indexOf.call(UNARY, value) >= 0) {
|
||||
tag = 'UNARY';
|
||||
} else if (__indexOf.call(UNARY_MATH, value) >= 0) {
|
||||
} else if (indexOf.call(UNARY_MATH, value) >= 0) {
|
||||
tag = 'UNARY_MATH';
|
||||
} else if (__indexOf.call(SHIFT, value) >= 0) {
|
||||
} else if (indexOf.call(SHIFT, value) >= 0) {
|
||||
tag = 'SHIFT';
|
||||
} else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
|
||||
} else if (indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
|
||||
tag = 'LOGIC';
|
||||
} else if (prev && !prev.spaced) {
|
||||
if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0) && !prev.stringEnd && !prev.regexEnd) {
|
||||
if (value === '(' && (ref5 = prev[0], indexOf.call(CALLABLE, ref5) >= 0)) {
|
||||
if (prev[0] === '?') {
|
||||
prev[0] = 'FUNC_EXIST';
|
||||
}
|
||||
tag = 'CALL_START';
|
||||
} else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) {
|
||||
} else if (value === '[' && (ref6 = prev[0], indexOf.call(INDEXABLE, ref6) >= 0)) {
|
||||
tag = 'INDEX_START';
|
||||
switch (prev[0]) {
|
||||
case '?':
|
||||
@@ -571,53 +591,68 @@
|
||||
return this.outdentToken(this.indent);
|
||||
};
|
||||
|
||||
Lexer.prototype.matchWithInterpolations = function(str, regex, end, offsetInChunk) {
|
||||
var close, column, index, line, nested, open, strPart, tokens, _ref2, _ref3, _ref4;
|
||||
Lexer.prototype.matchWithInterpolations = function(regex, delimiter) {
|
||||
var close, column, firstToken, index, lastToken, line, nested, offsetInChunk, open, ref2, ref3, ref4, str, strPart, tokens;
|
||||
tokens = [];
|
||||
offsetInChunk = delimiter.length;
|
||||
if (this.chunk.slice(0, offsetInChunk) !== delimiter) {
|
||||
return null;
|
||||
}
|
||||
str = this.chunk.slice(offsetInChunk);
|
||||
while (true) {
|
||||
strPart = regex.exec(str)[0];
|
||||
this.validateEscapes(strPart, {
|
||||
isRegex: delimiter.charAt(0) === '/',
|
||||
offsetInChunk: offsetInChunk
|
||||
});
|
||||
tokens.push(this.makeToken('NEOSTRING', strPart, offsetInChunk));
|
||||
str = str.slice(strPart.length);
|
||||
offsetInChunk += strPart.length;
|
||||
if (str.slice(0, 2) !== '#{') {
|
||||
break;
|
||||
}
|
||||
_ref2 = this.getLineAndColumnFromChunk(offsetInChunk + 1), line = _ref2[0], column = _ref2[1];
|
||||
_ref3 = new Lexer().tokenize(str.slice(1), {
|
||||
ref2 = this.getLineAndColumnFromChunk(offsetInChunk + 1), line = ref2[0], column = ref2[1];
|
||||
ref3 = new Lexer().tokenize(str.slice(1), {
|
||||
line: line,
|
||||
column: column,
|
||||
untilBalanced: true
|
||||
}), nested = _ref3.tokens, index = _ref3.index;
|
||||
}), nested = ref3.tokens, index = ref3.index;
|
||||
index += 1;
|
||||
open = nested[0], close = nested[nested.length - 1];
|
||||
open[0] = open[1] = '(';
|
||||
close[0] = close[1] = ')';
|
||||
close.origin = ['', 'end of interpolation', close[2]];
|
||||
if (((_ref4 = nested[1]) != null ? _ref4[0] : void 0) === 'TERMINATOR') {
|
||||
if (((ref4 = nested[1]) != null ? ref4[0] : void 0) === 'TERMINATOR') {
|
||||
nested.splice(1, 1);
|
||||
}
|
||||
tokens.push(['TOKENS', nested]);
|
||||
str = str.slice(index);
|
||||
offsetInChunk += index;
|
||||
}
|
||||
if (str.slice(0, end.length) !== end) {
|
||||
this.error("missing " + end);
|
||||
if (str.slice(0, delimiter.length) !== delimiter) {
|
||||
this.error("missing " + delimiter, {
|
||||
length: delimiter.length
|
||||
});
|
||||
}
|
||||
firstToken = tokens[0], lastToken = tokens[tokens.length - 1];
|
||||
firstToken[2].first_column -= delimiter.length;
|
||||
lastToken[2].last_column += delimiter.length;
|
||||
if (lastToken[1].length === 0) {
|
||||
lastToken[2].last_column -= 1;
|
||||
}
|
||||
return {
|
||||
tokens: tokens,
|
||||
index: offsetInChunk + end.length
|
||||
index: offsetInChunk + delimiter.length
|
||||
};
|
||||
};
|
||||
|
||||
Lexer.prototype.mergeInterpolationTokens = function(tokens, _arg, fn) {
|
||||
var converted, end, errorToken, firstEmptyStringIndex, firstIndex, i, interpolated, locationToken, plusToken, quote, rparen, start, tag, token, tokensToPush, value, _i, _len, _ref2;
|
||||
quote = _arg.quote, start = _arg.start, end = _arg.end;
|
||||
if (interpolated = tokens.length > 1) {
|
||||
errorToken = this.makeToken('', 'interpolation', start + tokens[0][1].length, 2);
|
||||
this.token('(', '(', 0, 0, errorToken);
|
||||
Lexer.prototype.mergeInterpolationTokens = function(tokens, options, fn) {
|
||||
var converted, firstEmptyStringIndex, firstIndex, i, j, lastToken, len, locationToken, lparen, plusToken, ref2, rparen, tag, token, tokensToPush, value;
|
||||
if (tokens.length > 1) {
|
||||
lparen = this.token('STRING_START', '(', 0, 0);
|
||||
}
|
||||
firstIndex = this.tokens.length;
|
||||
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
|
||||
for (i = j = 0, len = tokens.length; j < len; i = ++j) {
|
||||
token = tokens[i];
|
||||
tag = token[0], value = token[1];
|
||||
switch (tag) {
|
||||
@@ -641,7 +676,7 @@
|
||||
this.tokens.splice(firstEmptyStringIndex, 2);
|
||||
}
|
||||
token[0] = 'STRING';
|
||||
token[1] = this.makeString(converted, quote);
|
||||
token[1] = this.makeDelimitedLiteral(converted, options);
|
||||
locationToken = token;
|
||||
tokensToPush = [token];
|
||||
}
|
||||
@@ -654,28 +689,44 @@
|
||||
last_column: locationToken[2].first_column
|
||||
};
|
||||
}
|
||||
(_ref2 = this.tokens).push.apply(_ref2, tokensToPush);
|
||||
(ref2 = this.tokens).push.apply(ref2, tokensToPush);
|
||||
}
|
||||
if (interpolated) {
|
||||
rparen = this.token(')', ')', end, 0);
|
||||
return rparen.stringEnd = true;
|
||||
if (lparen) {
|
||||
lastToken = tokens[tokens.length - 1];
|
||||
lparen.origin = [
|
||||
'STRING', null, {
|
||||
first_line: lparen[2].first_line,
|
||||
first_column: lparen[2].first_column,
|
||||
last_line: lastToken[2].last_line,
|
||||
last_column: lastToken[2].last_column
|
||||
}
|
||||
];
|
||||
rparen = this.token('STRING_END', ')');
|
||||
return rparen[2] = {
|
||||
first_line: lastToken[2].last_line,
|
||||
first_column: lastToken[2].last_column,
|
||||
last_line: lastToken[2].last_line,
|
||||
last_column: lastToken[2].last_column
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Lexer.prototype.pair = function(tag) {
|
||||
var wanted, _ref2;
|
||||
if (tag !== (wanted = (_ref2 = last(this.ends)) != null ? _ref2.tag : void 0)) {
|
||||
var lastIndent, prev, ref2, ref3, wanted;
|
||||
ref2 = this.ends, prev = ref2[ref2.length - 1];
|
||||
if (tag !== (wanted = prev != null ? prev.tag : void 0)) {
|
||||
if ('OUTDENT' !== wanted) {
|
||||
this.error("unmatched " + tag);
|
||||
}
|
||||
this.outdentToken(last(this.indents), true);
|
||||
ref3 = this.indents, lastIndent = ref3[ref3.length - 1];
|
||||
this.outdentToken(lastIndent, true);
|
||||
return this.pair(tag);
|
||||
}
|
||||
return this.ends.pop();
|
||||
};
|
||||
|
||||
Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
|
||||
var column, lineCount, lines, string;
|
||||
var column, lastLine, lineCount, ref2, string;
|
||||
if (offset === 0) {
|
||||
return [this.chunkLine, this.chunkColumn];
|
||||
}
|
||||
@@ -687,8 +738,8 @@
|
||||
lineCount = count(string, '\n');
|
||||
column = this.chunkColumn;
|
||||
if (lineCount > 0) {
|
||||
lines = string.split('\n');
|
||||
column = last(lines).length;
|
||||
ref2 = string.split('\n'), lastLine = ref2[ref2.length - 1];
|
||||
column = lastLine.length;
|
||||
} else {
|
||||
column += string.length;
|
||||
}
|
||||
@@ -696,7 +747,7 @@
|
||||
};
|
||||
|
||||
Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
|
||||
var lastCharacter, locationData, token, _ref2, _ref3;
|
||||
var lastCharacter, locationData, ref2, ref3, token;
|
||||
if (offsetInChunk == null) {
|
||||
offsetInChunk = 0;
|
||||
}
|
||||
@@ -704,9 +755,9 @@
|
||||
length = value.length;
|
||||
}
|
||||
locationData = {};
|
||||
_ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];
|
||||
ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = ref2[0], locationData.first_column = ref2[1];
|
||||
lastCharacter = Math.max(0, length - 1);
|
||||
_ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];
|
||||
ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = ref3[0], locationData.last_column = ref3[1];
|
||||
token = [tag, value, locationData];
|
||||
return token;
|
||||
};
|
||||
@@ -721,64 +772,103 @@
|
||||
return token;
|
||||
};
|
||||
|
||||
Lexer.prototype.tag = function(index, tag) {
|
||||
var tok;
|
||||
return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
|
||||
Lexer.prototype.tag = function() {
|
||||
var ref2, token;
|
||||
ref2 = this.tokens, token = ref2[ref2.length - 1];
|
||||
return token != null ? token[0] : void 0;
|
||||
};
|
||||
|
||||
Lexer.prototype.value = function(index, val) {
|
||||
var tok;
|
||||
return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
|
||||
Lexer.prototype.value = function() {
|
||||
var ref2, token;
|
||||
ref2 = this.tokens, token = ref2[ref2.length - 1];
|
||||
return token != null ? token[1] : void 0;
|
||||
};
|
||||
|
||||
Lexer.prototype.unfinished = function() {
|
||||
var _ref2;
|
||||
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === 'UNARY_MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'YIELD' || _ref2 === '**' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
|
||||
var ref2;
|
||||
return LINE_CONTINUER.test(this.chunk) || ((ref2 = this.tag()) === '\\' || ref2 === '.' || ref2 === '?.' || ref2 === '?::' || ref2 === 'UNARY' || ref2 === 'MATH' || ref2 === 'UNARY_MATH' || ref2 === '+' || ref2 === '-' || ref2 === 'YIELD' || ref2 === '**' || ref2 === 'SHIFT' || ref2 === 'RELATION' || ref2 === 'COMPARE' || ref2 === 'LOGIC' || ref2 === 'THROW' || ref2 === 'EXTENDS');
|
||||
};
|
||||
|
||||
Lexer.prototype.formatString = function(str) {
|
||||
return str.replace(/\\[^\S\n]*(\n|\\)\s*/g, function(escaped, character) {
|
||||
if (character === '\n') {
|
||||
return '';
|
||||
} else {
|
||||
return escaped;
|
||||
}
|
||||
});
|
||||
return str.replace(STRING_OMIT, '$1');
|
||||
};
|
||||
|
||||
Lexer.prototype.formatHeregex = function(str) {
|
||||
return str.replace(HEREGEX_OMIT, '$1$2').replace(MULTILINER, '\\n');
|
||||
return str.replace(HEREGEX_OMIT, '$1$2');
|
||||
};
|
||||
|
||||
Lexer.prototype.makeString = function(body, quote) {
|
||||
var match;
|
||||
if (!body) {
|
||||
return quote + quote;
|
||||
Lexer.prototype.validateEscapes = function(str, options) {
|
||||
var before, hex, invalidEscape, match, message, octal, ref2, unicode;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
body = body.replace(RegExp("\\\\(" + quote + "|\\\\)", "g"), function(match, contents) {
|
||||
if (contents === quote) {
|
||||
return contents;
|
||||
} else {
|
||||
return match;
|
||||
match = INVALID_ESCAPE.exec(str);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
match[0], before = match[1], octal = match[2], hex = match[3], unicode = match[4];
|
||||
if (options.isRegex && octal && octal.charAt(0) !== '0') {
|
||||
return;
|
||||
}
|
||||
message = octal ? "octal escape sequences are not allowed" : "invalid escape sequence";
|
||||
invalidEscape = "\\" + (octal || hex || unicode);
|
||||
return this.error(message + " " + invalidEscape, {
|
||||
offset: ((ref2 = options.offsetInChunk) != null ? ref2 : 0) + match.index + before.length,
|
||||
length: invalidEscape.length
|
||||
});
|
||||
};
|
||||
|
||||
Lexer.prototype.makeDelimitedLiteral = function(body, options) {
|
||||
var regex;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (body === '' && options.delimiter === '/') {
|
||||
body = '(?:)';
|
||||
}
|
||||
regex = RegExp("(\\\\\\\\)|(\\\\0(?=[1-7]))|\\\\?(" + options.delimiter + ")|\\\\?(?:(\\n)|(\\r)|(\\u2028)|(\\u2029))|(\\\\.)", "g");
|
||||
body = body.replace(regex, function(match, backslash, nul, delimiter, lf, cr, ls, ps, other) {
|
||||
switch (false) {
|
||||
case !backslash:
|
||||
if (options.double) {
|
||||
return backslash + backslash;
|
||||
} else {
|
||||
return backslash;
|
||||
}
|
||||
case !nul:
|
||||
return '\\x00';
|
||||
case !delimiter:
|
||||
return "\\" + delimiter;
|
||||
case !lf:
|
||||
return '\\n';
|
||||
case !cr:
|
||||
return '\\r';
|
||||
case !ls:
|
||||
return '\\u2028';
|
||||
case !ps:
|
||||
return '\\u2029';
|
||||
case !other:
|
||||
if (options.double) {
|
||||
return "\\" + other;
|
||||
} else {
|
||||
return other;
|
||||
}
|
||||
}
|
||||
});
|
||||
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
||||
if (match = OCTAL_ESCAPE.exec(body)) {
|
||||
this.error("octal escape sequences are not allowed " + match[2], match.index + match[1].length + 1);
|
||||
}
|
||||
return quote + body + quote;
|
||||
return "" + options.delimiter + body + options.delimiter;
|
||||
};
|
||||
|
||||
Lexer.prototype.error = function(message, offset) {
|
||||
var first_column, first_line, _ref2;
|
||||
if (offset == null) {
|
||||
offset = 0;
|
||||
Lexer.prototype.error = function(message, options) {
|
||||
var first_column, first_line, location, ref2, ref3, ref4;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
_ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
|
||||
return throwSyntaxError(message, {
|
||||
location = 'first_line' in options ? options : ((ref3 = this.getLineAndColumnFromChunk((ref2 = options.offset) != null ? ref2 : 0), first_line = ref3[0], first_column = ref3[1], ref3), {
|
||||
first_line: first_line,
|
||||
first_column: first_column
|
||||
first_column: first_column,
|
||||
last_column: first_column + ((ref4 = options.length) != null ? ref4 : 1) - 1
|
||||
});
|
||||
return throwSyntaxError(message, location);
|
||||
};
|
||||
|
||||
return Lexer;
|
||||
@@ -802,12 +892,12 @@
|
||||
};
|
||||
|
||||
COFFEE_ALIASES = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
var results;
|
||||
results = [];
|
||||
for (key in COFFEE_ALIAS_MAP) {
|
||||
_results.push(key);
|
||||
results.push(key);
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
|
||||
COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
|
||||
@@ -850,11 +940,13 @@
|
||||
|
||||
HEREDOC_DOUBLE = /^(?:[^\\"#]|\\[\s\S]|"(?!"")|\#(?!\{))*/;
|
||||
|
||||
STRING_OMIT = /\s*\n\s*/g;
|
||||
STRING_OMIT = /((?:\\\\)+)|\\[^\S\n]*\n\s*/g;
|
||||
|
||||
SIMPLE_STRING_OMIT = /\s*\n\s*/g;
|
||||
|
||||
HEREDOC_INDENT = /\n+([^\n\S]*)(?=\S)/g;
|
||||
|
||||
REGEX = /^\/(?!\/)(?:[^[\/\n\\]|\\.|\[(?:\\.|[^\]\n\\])*])*(\/)?/;
|
||||
REGEX = /^\/(?!\/)((?:[^[\/\n\\]|\\[^\n]|\[(?:\\[^\n]|[^\]\n\\])*])*)(\/)?/;
|
||||
|
||||
REGEX_FLAGS = /^\w*/;
|
||||
|
||||
@@ -862,19 +954,17 @@
|
||||
|
||||
HEREGEX = /^(?:[^\\\/#]|\\[\s\S]|\/(?!\/\/)|\#(?!\{))*/;
|
||||
|
||||
HEREGEX_OMIT = /((?:\\\\)+)|\\(\s|\/)|\s+(?:#.*)?/g;
|
||||
HEREGEX_OMIT = /((?:\\\\)+)|\\(\s)|\s+(?:#.*)?/g;
|
||||
|
||||
REGEX_ILLEGAL = /^(\/|\/{3}\s*)(\*)/;
|
||||
|
||||
POSSIBLY_DIVISION = /^\/=?\s/;
|
||||
|
||||
MULTILINER = /\n/g;
|
||||
|
||||
HERECOMMENT_ILLEGAL = /\*\//;
|
||||
|
||||
LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;
|
||||
|
||||
OCTAL_ESCAPE = /^((?:\\.|[^\\])*)(\\(?:0[0-7]|[1-7]))/;
|
||||
INVALID_ESCAPE = /((?:^|[^\\])(?:\\\\)*)\\(?:(0[0-7]|[1-7])|(x(?![\da-fA-F]{2}).{0,2})|(u(?![\da-fA-F]{4}).{0,4}))/;
|
||||
|
||||
LEADING_BLANK_LINE = /^[^\n\S]*\n/;
|
||||
|
||||
@@ -902,7 +992,7 @@
|
||||
|
||||
CALLABLE = ['IDENTIFIER', ')', ']', '?', '@', 'THIS', 'SUPER'];
|
||||
|
||||
INDEXABLE = CALLABLE.concat(['NUMBER', 'STRING', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '}', '::']);
|
||||
INDEXABLE = CALLABLE.concat(['NUMBER', 'STRING', 'STRING_END', 'REGEX', 'REGEX_END', 'BOOL', 'NULL', 'UNDEFINED', '}', '::']);
|
||||
|
||||
NOT_REGEX = INDEXABLE.concat(['++', '--']);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,24 +1,24 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments, repeat;
|
||||
|
||||
repeat = require('./helpers').repeat;
|
||||
|
||||
exports.OptionParser = OptionParser = (function() {
|
||||
function OptionParser(rules, _at_banner) {
|
||||
this.banner = _at_banner;
|
||||
function OptionParser(rules, banner) {
|
||||
this.banner = banner;
|
||||
this.rules = buildRules(rules);
|
||||
}
|
||||
|
||||
OptionParser.prototype.parse = function(args) {
|
||||
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, seenNonOptionArg, skippingArgument, value, _i, _j, _len, _len1, _ref;
|
||||
var arg, i, isOption, j, k, len, len1, matchedRule, options, originalArgs, pos, ref, rule, seenNonOptionArg, skippingArgument, value;
|
||||
options = {
|
||||
"arguments": []
|
||||
};
|
||||
skippingArgument = false;
|
||||
originalArgs = args;
|
||||
args = normalizeArguments(args);
|
||||
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
|
||||
for (i = j = 0, len = args.length; j < len; i = ++j) {
|
||||
arg = args[i];
|
||||
if (skippingArgument) {
|
||||
skippingArgument = false;
|
||||
@@ -33,9 +33,9 @@
|
||||
seenNonOptionArg = options["arguments"].length > 0;
|
||||
if (!seenNonOptionArg) {
|
||||
matchedRule = false;
|
||||
_ref = this.rules;
|
||||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
||||
rule = _ref[_j];
|
||||
ref = this.rules;
|
||||
for (k = 0, len1 = ref.length; k < len1; k++) {
|
||||
rule = ref[k];
|
||||
if (rule.shortFlag === arg || rule.longFlag === arg) {
|
||||
value = true;
|
||||
if (rule.hasArgument) {
|
||||
@@ -59,14 +59,14 @@
|
||||
};
|
||||
|
||||
OptionParser.prototype.help = function() {
|
||||
var letPart, lines, rule, spaces, _i, _len, _ref;
|
||||
var j, len, letPart, lines, ref, rule, spaces;
|
||||
lines = [];
|
||||
if (this.banner) {
|
||||
lines.unshift(this.banner + "\n");
|
||||
}
|
||||
_ref = this.rules;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
rule = _ref[_i];
|
||||
ref = this.rules;
|
||||
for (j = 0, len = ref.length; j < len; j++) {
|
||||
rule = ref[j];
|
||||
spaces = 15 - rule.longFlag.length;
|
||||
spaces = spaces > 0 ? repeat(' ', spaces) : '';
|
||||
letPart = rule.shortFlag ? rule.shortFlag + ', ' : ' ';
|
||||
@@ -88,16 +88,16 @@
|
||||
OPTIONAL = /\[(\w+(\*?))\]/;
|
||||
|
||||
buildRules = function(rules) {
|
||||
var tuple, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = rules.length; _i < _len; _i++) {
|
||||
tuple = rules[_i];
|
||||
var j, len, results, tuple;
|
||||
results = [];
|
||||
for (j = 0, len = rules.length; j < len; j++) {
|
||||
tuple = rules[j];
|
||||
if (tuple.length < 3) {
|
||||
tuple.unshift(null);
|
||||
}
|
||||
_results.push(buildRule.apply(null, tuple));
|
||||
results.push(buildRule.apply(null, tuple));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
};
|
||||
|
||||
buildRule = function(shortFlag, longFlag, description, options) {
|
||||
@@ -118,15 +118,15 @@
|
||||
};
|
||||
|
||||
normalizeArguments = function(args) {
|
||||
var arg, l, match, result, _i, _j, _len, _len1, _ref;
|
||||
var arg, j, k, l, len, len1, match, ref, result;
|
||||
args = args.slice(0);
|
||||
result = [];
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
arg = args[_i];
|
||||
for (j = 0, len = args.length; j < len; j++) {
|
||||
arg = args[j];
|
||||
if (match = arg.match(MULTI_FLAG)) {
|
||||
_ref = match[1].split('');
|
||||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
||||
l = _ref[_j];
|
||||
ref = match[1].split('');
|
||||
for (k = 0, len1 = ref.length; k < len1; k++) {
|
||||
l = ref[k];
|
||||
result.push('-' + l);
|
||||
}
|
||||
} else {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, loadFile, path, _i, _len, _ref;
|
||||
var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, i, len, loadFile, path, ref;
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
};
|
||||
|
||||
if (require.extensions) {
|
||||
_ref = CoffeeScript.FILE_EXTENSIONS;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
ext = _ref[_i];
|
||||
ref = CoffeeScript.FILE_EXTENSIONS;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
ext = ref[i];
|
||||
require.extensions[ext] = loadFile;
|
||||
}
|
||||
Module = require('module');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, replDefaults, updateSyntaxError, vm, _ref;
|
||||
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, ref, replDefaults, updateSyntaxError, vm;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -12,29 +12,29 @@
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
_ref = require('./helpers'), merge = _ref.merge, updateSyntaxError = _ref.updateSyntaxError;
|
||||
ref = require('./helpers'), merge = ref.merge, updateSyntaxError = ref.updateSyntaxError;
|
||||
|
||||
replDefaults = {
|
||||
prompt: 'coffee> ',
|
||||
historyFile: process.env.HOME ? path.join(process.env.HOME, '.coffee_history') : void 0,
|
||||
historyMaxInputSize: 10240,
|
||||
"eval": function(input, context, filename, cb) {
|
||||
var Assign, Block, Literal, Value, ast, err, js, referencedVars, result, token, tokens, _ref1;
|
||||
var Assign, Block, Literal, Value, ast, err, js, ref1, referencedVars, result, token, tokens;
|
||||
input = input.replace(/\uFF00/g, '\n');
|
||||
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
|
||||
_ref1 = require('./nodes'), Block = _ref1.Block, Assign = _ref1.Assign, Value = _ref1.Value, Literal = _ref1.Literal;
|
||||
ref1 = require('./nodes'), Block = ref1.Block, Assign = ref1.Assign, Value = ref1.Value, Literal = ref1.Literal;
|
||||
try {
|
||||
tokens = CoffeeScript.tokens(input);
|
||||
referencedVars = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
||||
token = tokens[_i];
|
||||
if (token.variable && token[1].charAt(0) === '_') {
|
||||
_results.push(token[1]);
|
||||
var i, len, results;
|
||||
results = [];
|
||||
for (i = 0, len = tokens.length; i < len; i++) {
|
||||
token = tokens[i];
|
||||
if (token.variable) {
|
||||
results.push(token[1]);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
ast = CoffeeScript.nodes(tokens);
|
||||
ast = new Block([new Assign(new Value(new Literal('_')), ast, '=')]);
|
||||
@@ -54,9 +54,9 @@
|
||||
};
|
||||
|
||||
addMultilineHandler = function(repl) {
|
||||
var inputStream, multiline, nodeLineListener, origPrompt, outputStream, rli, _ref1;
|
||||
var inputStream, multiline, nodeLineListener, origPrompt, outputStream, ref1, rli;
|
||||
rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream;
|
||||
origPrompt = (_ref1 = repl._prompt) != null ? _ref1 : repl.prompt;
|
||||
origPrompt = (ref1 = repl._prompt) != null ? ref1 : repl.prompt;
|
||||
multiline = {
|
||||
enabled: false,
|
||||
initialPrompt: origPrompt.replace(/^[^> ]*/, function(x) {
|
||||
@@ -159,13 +159,13 @@
|
||||
|
||||
module.exports = {
|
||||
start: function(opts) {
|
||||
var build, major, minor, repl, _ref1;
|
||||
var build, major, minor, ref1, repl;
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
_ref1 = process.versions.node.split('.').map(function(n) {
|
||||
ref1 = process.versions.node.split('.').map(function(n) {
|
||||
return parseInt(n);
|
||||
}), major = _ref1[0], minor = _ref1[1], build = _ref1[2];
|
||||
}), major = ref1[0], minor = ref1[1], build = ref1[2];
|
||||
if (major === 0 && minor < 8) {
|
||||
console.warn("Node 0.8.0+ required for CoffeeScript REPL");
|
||||
process.exit(1);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(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; },
|
||||
__slice = [].slice;
|
||||
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, k, left, len, ref, rite,
|
||||
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; },
|
||||
slice = [].slice;
|
||||
|
||||
generate = function(tag, value, origin) {
|
||||
var tok;
|
||||
@@ -17,8 +17,8 @@
|
||||
exports.Rewriter = (function() {
|
||||
function Rewriter() {}
|
||||
|
||||
Rewriter.prototype.rewrite = function(_at_tokens) {
|
||||
this.tokens = _at_tokens;
|
||||
Rewriter.prototype.rewrite = function(tokens1) {
|
||||
this.tokens = tokens1;
|
||||
this.removeLeadingNewlines();
|
||||
this.closeOpenCalls();
|
||||
this.closeOpenIndexes();
|
||||
@@ -40,7 +40,7 @@
|
||||
};
|
||||
|
||||
Rewriter.prototype.detectEnd = function(i, condition, action) {
|
||||
var levels, token, tokens, _ref, _ref1;
|
||||
var levels, ref, ref1, token, tokens;
|
||||
tokens = this.tokens;
|
||||
levels = 0;
|
||||
while (token = tokens[i]) {
|
||||
@@ -50,9 +50,9 @@
|
||||
if (!token || levels < 0) {
|
||||
return action.call(this, token, i - 1);
|
||||
}
|
||||
if (_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) {
|
||||
if (ref = token[0], indexOf.call(EXPRESSION_START, ref) >= 0) {
|
||||
levels += 1;
|
||||
} else if (_ref1 = token[0], __indexOf.call(EXPRESSION_END, _ref1) >= 0) {
|
||||
} else if (ref1 = token[0], indexOf.call(EXPRESSION_END, ref1) >= 0) {
|
||||
levels -= 1;
|
||||
}
|
||||
i += 1;
|
||||
@@ -61,10 +61,10 @@
|
||||
};
|
||||
|
||||
Rewriter.prototype.removeLeadingNewlines = function() {
|
||||
var i, tag, _i, _len, _ref;
|
||||
_ref = this.tokens;
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
tag = _ref[i][0];
|
||||
var i, k, len, ref, tag;
|
||||
ref = this.tokens;
|
||||
for (i = k = 0, len = ref.length; k < len; i = ++k) {
|
||||
tag = ref[i][0];
|
||||
if (tag !== 'TERMINATOR') {
|
||||
break;
|
||||
}
|
||||
@@ -77,8 +77,8 @@
|
||||
Rewriter.prototype.closeOpenCalls = function() {
|
||||
var action, condition;
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
||||
var ref;
|
||||
return ((ref = token[0]) === ')' || ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
||||
};
|
||||
action = function(token, i) {
|
||||
return this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END';
|
||||
@@ -94,8 +94,8 @@
|
||||
Rewriter.prototype.closeOpenIndexes = function() {
|
||||
var action, condition;
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
return (_ref = token[0]) === ']' || _ref === 'INDEX_END';
|
||||
var ref;
|
||||
return (ref = token[0]) === ']' || ref === 'INDEX_END';
|
||||
};
|
||||
action = function(token, i) {
|
||||
return token[0] = 'INDEX_END';
|
||||
@@ -108,11 +108,11 @@
|
||||
});
|
||||
};
|
||||
|
||||
Rewriter.prototype.matchTags = function() {
|
||||
var fuzz, i, j, pattern, _i, _ref, _ref1;
|
||||
i = arguments[0], pattern = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
Rewriter.prototype.indexOfTag = function() {
|
||||
var fuzz, i, j, k, pattern, ref, ref1;
|
||||
i = arguments[0], pattern = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||
fuzz = 0;
|
||||
for (j = _i = 0, _ref = pattern.length; 0 <= _ref ? _i < _ref : _i > _ref; j = 0 <= _ref ? ++_i : --_i) {
|
||||
for (j = k = 0, ref = pattern.length; 0 <= ref ? k < ref : k > ref; j = 0 <= ref ? ++k : --k) {
|
||||
while (this.tag(i + j + fuzz) === 'HERECOMMENT') {
|
||||
fuzz += 2;
|
||||
}
|
||||
@@ -122,37 +122,55 @@
|
||||
if (typeof pattern[j] === 'string') {
|
||||
pattern[j] = [pattern[j]];
|
||||
}
|
||||
if (_ref1 = this.tag(i + j + fuzz), __indexOf.call(pattern[j], _ref1) < 0) {
|
||||
return false;
|
||||
if (ref1 = this.tag(i + j + fuzz), indexOf.call(pattern[j], ref1) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return i + j + fuzz - 1;
|
||||
};
|
||||
|
||||
Rewriter.prototype.looksObjectish = function(j) {
|
||||
return this.matchTags(j, '@', null, ':') || this.matchTags(j, null, ':');
|
||||
var end, index;
|
||||
if (this.indexOfTag(j, '@', null, ':') > -1 || this.indexOfTag(j, null, ':') > -1) {
|
||||
return true;
|
||||
}
|
||||
index = this.indexOfTag(j, EXPRESSION_START);
|
||||
if (index > -1) {
|
||||
end = null;
|
||||
this.detectEnd(index + 1, (function(token) {
|
||||
var ref;
|
||||
return ref = token[0], indexOf.call(EXPRESSION_END, ref) >= 0;
|
||||
}), (function(token, i) {
|
||||
return end = i;
|
||||
}));
|
||||
if (this.tag(end + 1) === ':') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Rewriter.prototype.findTagsBackwards = function(i, tags) {
|
||||
var backStack, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
||||
var backStack, ref, ref1, ref2, ref3, ref4, ref5;
|
||||
backStack = [];
|
||||
while (i >= 0 && (backStack.length || (_ref2 = this.tag(i), __indexOf.call(tags, _ref2) < 0) && ((_ref3 = this.tag(i), __indexOf.call(EXPRESSION_START, _ref3) < 0) || this.tokens[i].generated) && (_ref4 = this.tag(i), __indexOf.call(LINEBREAKS, _ref4) < 0))) {
|
||||
if (_ref = this.tag(i), __indexOf.call(EXPRESSION_END, _ref) >= 0) {
|
||||
while (i >= 0 && (backStack.length || (ref2 = this.tag(i), indexOf.call(tags, ref2) < 0) && ((ref3 = this.tag(i), indexOf.call(EXPRESSION_START, ref3) < 0) || this.tokens[i].generated) && (ref4 = this.tag(i), indexOf.call(LINEBREAKS, ref4) < 0))) {
|
||||
if (ref = this.tag(i), indexOf.call(EXPRESSION_END, ref) >= 0) {
|
||||
backStack.push(this.tag(i));
|
||||
}
|
||||
if ((_ref1 = this.tag(i), __indexOf.call(EXPRESSION_START, _ref1) >= 0) && backStack.length) {
|
||||
if ((ref1 = this.tag(i), indexOf.call(EXPRESSION_START, ref1) >= 0) && backStack.length) {
|
||||
backStack.pop();
|
||||
}
|
||||
i -= 1;
|
||||
}
|
||||
return _ref5 = this.tag(i), __indexOf.call(tags, _ref5) >= 0;
|
||||
return ref5 = this.tag(i), indexOf.call(tags, ref5) >= 0;
|
||||
};
|
||||
|
||||
Rewriter.prototype.addImplicitBracesAndParens = function() {
|
||||
var stack;
|
||||
var stack, start;
|
||||
stack = [];
|
||||
start = null;
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, newLine, nextTag, offset, prevTag, prevToken, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
||||
var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, newLine, nextTag, offset, prevTag, prevToken, ref, ref1, ref2, ref3, ref4, ref5, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag;
|
||||
tag = token[0];
|
||||
prevTag = (prevToken = i > 0 ? tokens[i - 1] : [])[0];
|
||||
nextTag = (i < tokens.length - 1 ? tokens[i + 1] : [])[0];
|
||||
@@ -164,20 +182,20 @@
|
||||
return i - startIdx + n;
|
||||
};
|
||||
inImplicit = function() {
|
||||
var _ref, _ref1;
|
||||
return (_ref = stackTop()) != null ? (_ref1 = _ref[2]) != null ? _ref1.ours : void 0 : void 0;
|
||||
var ref, ref1;
|
||||
return (ref = stackTop()) != null ? (ref1 = ref[2]) != null ? ref1.ours : void 0 : void 0;
|
||||
};
|
||||
inImplicitCall = function() {
|
||||
var _ref;
|
||||
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '(';
|
||||
var ref;
|
||||
return inImplicit() && ((ref = stackTop()) != null ? ref[0] : void 0) === '(';
|
||||
};
|
||||
inImplicitObject = function() {
|
||||
var _ref;
|
||||
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '{';
|
||||
var ref;
|
||||
return inImplicit() && ((ref = stackTop()) != null ? ref[0] : void 0) === '{';
|
||||
};
|
||||
inImplicitControl = function() {
|
||||
var _ref;
|
||||
return inImplicit && ((_ref = stackTop()) != null ? _ref[0] : void 0) === 'CONTROL';
|
||||
var ref;
|
||||
return inImplicit && ((ref = stackTop()) != null ? ref[0] : void 0) === 'CONTROL';
|
||||
};
|
||||
startImplicitCall = function(j) {
|
||||
var idx;
|
||||
@@ -198,7 +216,7 @@
|
||||
return i += 1;
|
||||
};
|
||||
startImplicitObject = function(j, startsLine) {
|
||||
var idx;
|
||||
var idx, val;
|
||||
if (startsLine == null) {
|
||||
startsLine = true;
|
||||
}
|
||||
@@ -210,7 +228,9 @@
|
||||
ours: true
|
||||
}
|
||||
]);
|
||||
tokens.splice(idx, 0, generate('{', generate(new String('{')), token));
|
||||
val = new String('{');
|
||||
val.generated = true;
|
||||
tokens.splice(idx, 0, generate('{', val, token));
|
||||
if (j == null) {
|
||||
return i += 1;
|
||||
}
|
||||
@@ -241,11 +261,11 @@
|
||||
stack.push([tag, i]);
|
||||
return forward(1);
|
||||
}
|
||||
if (__indexOf.call(EXPRESSION_START, tag) >= 0) {
|
||||
if (indexOf.call(EXPRESSION_START, tag) >= 0) {
|
||||
stack.push([tag, i]);
|
||||
return forward(1);
|
||||
}
|
||||
if (__indexOf.call(EXPRESSION_END, tag) >= 0) {
|
||||
if (indexOf.call(EXPRESSION_END, tag) >= 0) {
|
||||
while (inImplicit()) {
|
||||
if (inImplicitCall()) {
|
||||
endImplicitCall();
|
||||
@@ -255,33 +275,39 @@
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
stack.pop();
|
||||
start = stack.pop();
|
||||
}
|
||||
if ((__indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced && !token.stringEnd && !token.regexEnd || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (__indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || __indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !((_ref = tokens[i + 1]) != null ? _ref.spaced : void 0) && !((_ref1 = tokens[i + 1]) != null ? _ref1.newLine : void 0))) {
|
||||
if ((indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !((ref = tokens[i + 1]) != null ? ref.spaced : void 0) && !((ref1 = tokens[i + 1]) != null ? ref1.newLine : void 0))) {
|
||||
if (tag === '?') {
|
||||
tag = token[0] = 'FUNC_EXIST';
|
||||
}
|
||||
startImplicitCall(i + 1);
|
||||
return forward(2);
|
||||
}
|
||||
if (__indexOf.call(IMPLICIT_FUNC, tag) >= 0 && !token.stringEnd && !token.regexEnd && this.matchTags(i + 1, 'INDENT', null, ':') && !this.findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH', 'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])) {
|
||||
if (indexOf.call(IMPLICIT_FUNC, tag) >= 0 && this.indexOfTag(i + 1, 'INDENT', null, ':') > -1 && !this.findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH', 'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])) {
|
||||
startImplicitCall(i + 1);
|
||||
stack.push(['INDENT', i + 2]);
|
||||
return forward(3);
|
||||
}
|
||||
if (tag === ':') {
|
||||
if (this.tag(i - 2) === '@') {
|
||||
s = i - 2;
|
||||
} else {
|
||||
s = i - 1;
|
||||
}
|
||||
s = (function() {
|
||||
var ref2;
|
||||
switch (false) {
|
||||
case ref2 = this.tag(i - 1), indexOf.call(EXPRESSION_END, ref2) < 0:
|
||||
return start[1];
|
||||
case this.tag(i - 2) !== '@':
|
||||
return i - 2;
|
||||
default:
|
||||
return i - 1;
|
||||
}
|
||||
}).call(this);
|
||||
while (this.tag(s - 2) === 'HERECOMMENT') {
|
||||
s -= 2;
|
||||
}
|
||||
this.insideForDeclaration = nextTag === 'FOR';
|
||||
startsLine = s === 0 || (_ref2 = this.tag(s - 1), __indexOf.call(LINEBREAKS, _ref2) >= 0) || tokens[s - 1].newLine;
|
||||
startsLine = s === 0 || (ref2 = this.tag(s - 1), indexOf.call(LINEBREAKS, ref2) >= 0) || tokens[s - 1].newLine;
|
||||
if (stackTop()) {
|
||||
_ref3 = stackTop(), stackTag = _ref3[0], stackIdx = _ref3[1];
|
||||
ref3 = stackTop(), stackTag = ref3[0], stackIdx = ref3[1];
|
||||
if ((stackTag === '{' || stackTag === 'INDENT' && this.tag(stackIdx - 1) === '{') && (startsLine || this.tag(s - 1) === ',' || this.tag(s - 1) === '{')) {
|
||||
return forward(1);
|
||||
}
|
||||
@@ -289,18 +315,21 @@
|
||||
startImplicitObject(s, !!startsLine);
|
||||
return forward(2);
|
||||
}
|
||||
if (inImplicitObject() && __indexOf.call(LINEBREAKS, tag) >= 0) {
|
||||
if (inImplicitObject() && indexOf.call(LINEBREAKS, tag) >= 0) {
|
||||
stackTop()[2].sameLine = false;
|
||||
}
|
||||
newLine = prevTag === 'OUTDENT' || prevToken.newLine;
|
||||
if (__indexOf.call(IMPLICIT_END, tag) >= 0 || __indexOf.call(CALL_CLOSERS, tag) >= 0 && newLine) {
|
||||
if (indexOf.call(IMPLICIT_END, tag) >= 0 || indexOf.call(CALL_CLOSERS, tag) >= 0 && newLine) {
|
||||
while (inImplicit()) {
|
||||
_ref4 = stackTop(), stackTag = _ref4[0], stackIdx = _ref4[1], (_ref5 = _ref4[2], sameLine = _ref5.sameLine, startsLine = _ref5.startsLine);
|
||||
ref4 = stackTop(), stackTag = ref4[0], stackIdx = ref4[1], (ref5 = ref4[2], sameLine = ref5.sameLine, startsLine = ref5.startsLine);
|
||||
if (inImplicitCall() && prevTag !== ',') {
|
||||
endImplicitCall();
|
||||
} else if (inImplicitObject() && !this.insideForDeclaration && sameLine && tag !== 'TERMINATOR' && prevTag !== ':' && endImplicitObject()) {
|
||||
|
||||
} else if (inImplicitObject() && !this.insideForDeclaration && sameLine && tag !== 'TERMINATOR' && prevTag !== ':') {
|
||||
endImplicitObject();
|
||||
} else if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) {
|
||||
if (nextTag === 'HERECOMMENT') {
|
||||
return forward(1);
|
||||
}
|
||||
endImplicitObject();
|
||||
} else {
|
||||
break;
|
||||
@@ -319,16 +348,16 @@
|
||||
|
||||
Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var column, line, nextLocation, prevLocation, _ref, _ref1;
|
||||
var column, line, nextLocation, prevLocation, ref, ref1;
|
||||
if (token[2]) {
|
||||
return 1;
|
||||
}
|
||||
if (!(token.generated || token.explicit)) {
|
||||
return 1;
|
||||
}
|
||||
if (token[0] === '{' && (nextLocation = (_ref = tokens[i + 1]) != null ? _ref[2] : void 0)) {
|
||||
if (token[0] === '{' && (nextLocation = (ref = tokens[i + 1]) != null ? ref[2] : void 0)) {
|
||||
line = nextLocation.first_line, column = nextLocation.first_column;
|
||||
} else if (prevLocation = (_ref1 = tokens[i - 1]) != null ? _ref1[2] : void 0) {
|
||||
} else if (prevLocation = (ref1 = tokens[i - 1]) != null ? ref1[2] : void 0) {
|
||||
line = prevLocation.last_line, column = prevLocation.last_column;
|
||||
} else {
|
||||
line = column = 0;
|
||||
@@ -347,37 +376,37 @@
|
||||
var action, condition, indent, outdent, starter;
|
||||
starter = indent = outdent = null;
|
||||
condition = function(token, i) {
|
||||
var _ref, _ref1, _ref2, _ref3;
|
||||
return token[1] !== ';' && (_ref = token[0], __indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'TERMINATOR' && (_ref1 = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref1) >= 0)) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((_ref2 = token[0]) === 'CATCH' || _ref2 === 'FINALLY') && (starter === '->' || starter === '=>')) || (_ref3 = token[0], __indexOf.call(CALL_CLOSERS, _ref3) >= 0) && this.tokens[i - 1].newLine;
|
||||
var ref, ref1, ref2, ref3;
|
||||
return token[1] !== ';' && (ref = token[0], indexOf.call(SINGLE_CLOSERS, ref) >= 0) && !(token[0] === 'TERMINATOR' && (ref1 = this.tag(i + 1), indexOf.call(EXPRESSION_CLOSE, ref1) >= 0)) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((ref2 = token[0]) === 'CATCH' || ref2 === 'FINALLY') && (starter === '->' || starter === '=>')) || (ref3 = token[0], indexOf.call(CALL_CLOSERS, ref3) >= 0) && this.tokens[i - 1].newLine;
|
||||
};
|
||||
action = function(token, i) {
|
||||
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
|
||||
};
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var j, tag, _i, _ref, _ref1, _ref2;
|
||||
var j, k, ref, ref1, ref2, tag;
|
||||
tag = token[0];
|
||||
if (tag === 'TERMINATOR') {
|
||||
if (this.tag(i + 1) === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
|
||||
tokens.splice.apply(tokens, [i, 1].concat(__slice.call(this.indentation())));
|
||||
tokens.splice.apply(tokens, [i, 1].concat(slice.call(this.indentation())));
|
||||
return 1;
|
||||
}
|
||||
if (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0) {
|
||||
if (ref = this.tag(i + 1), indexOf.call(EXPRESSION_CLOSE, ref) >= 0) {
|
||||
tokens.splice(i, 1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (tag === 'CATCH') {
|
||||
for (j = _i = 1; _i <= 2; j = ++_i) {
|
||||
if (!((_ref1 = this.tag(i + j)) === 'OUTDENT' || _ref1 === 'TERMINATOR' || _ref1 === 'FINALLY')) {
|
||||
for (j = k = 1; k <= 2; j = ++k) {
|
||||
if (!((ref1 = this.tag(i + j)) === 'OUTDENT' || ref1 === 'TERMINATOR' || ref1 === 'FINALLY')) {
|
||||
continue;
|
||||
}
|
||||
tokens.splice.apply(tokens, [i + j, 0].concat(__slice.call(this.indentation())));
|
||||
tokens.splice.apply(tokens, [i + j, 0].concat(slice.call(this.indentation())));
|
||||
return 2 + j;
|
||||
}
|
||||
}
|
||||
if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
||||
if (indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
||||
starter = tag;
|
||||
_ref2 = this.indentation(tokens[i]), indent = _ref2[0], outdent = _ref2[1];
|
||||
ref2 = this.indentation(tokens[i]), indent = ref2[0], outdent = ref2[1];
|
||||
if (starter === 'THEN') {
|
||||
indent.fromThen = true;
|
||||
}
|
||||
@@ -399,7 +428,7 @@
|
||||
var prevTag, tag;
|
||||
tag = token[0];
|
||||
prevTag = this.tokens[i - 1][0];
|
||||
return tag === 'TERMINATOR' || (tag === 'INDENT' && __indexOf.call(SINGLE_LINERS, prevTag) < 0);
|
||||
return tag === 'TERMINATOR' || (tag === 'INDENT' && indexOf.call(SINGLE_LINERS, prevTag) < 0);
|
||||
};
|
||||
action = function(token, i) {
|
||||
if (token[0] !== 'INDENT' || (token.generated && !token.fromThen)) {
|
||||
@@ -432,15 +461,15 @@
|
||||
Rewriter.prototype.generate = generate;
|
||||
|
||||
Rewriter.prototype.tag = function(i) {
|
||||
var _ref;
|
||||
return (_ref = this.tokens[i]) != null ? _ref[0] : void 0;
|
||||
var ref;
|
||||
return (ref = this.tokens[i]) != null ? ref[0] : void 0;
|
||||
};
|
||||
|
||||
return Rewriter;
|
||||
|
||||
})();
|
||||
|
||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['CALL_START', 'CALL_END'], ['PARAM_START', 'PARAM_END'], ['INDEX_START', 'INDEX_END']];
|
||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['CALL_START', 'CALL_END'], ['PARAM_START', 'PARAM_END'], ['INDEX_START', 'INDEX_END'], ['STRING_START', 'STRING_END'], ['REGEX_START', 'REGEX_END']];
|
||||
|
||||
exports.INVERSES = INVERSES = {};
|
||||
|
||||
@@ -448,8 +477,8 @@
|
||||
|
||||
EXPRESSION_END = [];
|
||||
|
||||
for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; _i++) {
|
||||
_ref = BALANCED_PAIRS[_i], left = _ref[0], rite = _ref[1];
|
||||
for (k = 0, len = BALANCED_PAIRS.length; k < len; k++) {
|
||||
ref = BALANCED_PAIRS[k], left = ref[0], rite = ref[1];
|
||||
EXPRESSION_START.push(INVERSES[rite] = left);
|
||||
EXPRESSION_END.push(INVERSES[left] = rite);
|
||||
}
|
||||
@@ -458,7 +487,7 @@
|
||||
|
||||
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
|
||||
|
||||
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'YIELD', 'UNARY_MATH', 'SUPER', 'THROW', '@', '->', '=>', '[', '(', '{', '--', '++'];
|
||||
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'STRING_START', 'JS', 'REGEX', 'REGEX_START', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL', 'UNDEFINED', 'UNARY', 'YIELD', 'UNARY_MATH', 'SUPER', 'THROW', '@', '->', '=>', '[', '(', '{', '--', '++'];
|
||||
|
||||
IMPLICIT_UNSPACED_CALL = ['+', '-'];
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(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; };
|
||||
|
||||
_ref = require('./helpers'), extend = _ref.extend, last = _ref.last;
|
||||
var Scope,
|
||||
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; };
|
||||
|
||||
exports.Scope = Scope = (function() {
|
||||
function Scope(_at_parent, _at_expressions, _at_method, _at_referencedVars) {
|
||||
var _ref1, _ref2;
|
||||
this.parent = _at_parent;
|
||||
this.expressions = _at_expressions;
|
||||
this.method = _at_method;
|
||||
this.referencedVars = _at_referencedVars;
|
||||
function Scope(parent, expressions, method, referencedVars) {
|
||||
var ref, ref1;
|
||||
this.parent = parent;
|
||||
this.expressions = expressions;
|
||||
this.method = method;
|
||||
this.referencedVars = referencedVars;
|
||||
this.variables = [
|
||||
{
|
||||
name: 'arguments',
|
||||
@@ -22,7 +20,7 @@
|
||||
if (!this.parent) {
|
||||
this.utilities = {};
|
||||
}
|
||||
this.root = (_ref1 = (_ref2 = this.parent) != null ? _ref2.root : void 0) != null ? _ref1 : this;
|
||||
this.root = (ref = (ref1 = this.parent) != null ? ref1.root : void 0) != null ? ref : this;
|
||||
}
|
||||
|
||||
Scope.prototype.add = function(name, type, immediate) {
|
||||
@@ -40,8 +38,8 @@
|
||||
};
|
||||
|
||||
Scope.prototype.namedMethod = function() {
|
||||
var _ref1;
|
||||
if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) {
|
||||
var ref;
|
||||
if (((ref = this.method) != null ? ref.name : void 0) || !this.parent) {
|
||||
return this.method;
|
||||
}
|
||||
return this.parent.namedMethod();
|
||||
@@ -63,23 +61,26 @@
|
||||
};
|
||||
|
||||
Scope.prototype.check = function(name) {
|
||||
var _ref1;
|
||||
return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));
|
||||
var ref;
|
||||
return !!(this.type(name) || ((ref = this.parent) != null ? ref.check(name) : void 0));
|
||||
};
|
||||
|
||||
Scope.prototype.temporary = function(name, index) {
|
||||
if (name.length > 1) {
|
||||
return '_' + name + (index > 1 ? index - 1 : '');
|
||||
Scope.prototype.temporary = function(name, index, single) {
|
||||
if (single == null) {
|
||||
single = false;
|
||||
}
|
||||
if (single) {
|
||||
return (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');
|
||||
} else {
|
||||
return '_' + (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');
|
||||
return name + (index || '');
|
||||
}
|
||||
};
|
||||
|
||||
Scope.prototype.type = function(name) {
|
||||
var v, _i, _len, _ref1;
|
||||
_ref1 = this.variables;
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
v = _ref1[_i];
|
||||
var i, len, ref, v;
|
||||
ref = this.variables;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
v = ref[i];
|
||||
if (v.name === name) {
|
||||
return v.type;
|
||||
}
|
||||
@@ -87,20 +88,20 @@
|
||||
return null;
|
||||
};
|
||||
|
||||
Scope.prototype.freeVariable = function(name, reserve) {
|
||||
var index, temp;
|
||||
if (reserve == null) {
|
||||
reserve = true;
|
||||
Scope.prototype.freeVariable = function(name, options) {
|
||||
var index, ref, temp;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
index = 0;
|
||||
while (true) {
|
||||
temp = this.temporary(name, index);
|
||||
if (!(this.check(temp) || __indexOf.call(this.root.referencedVars, temp) >= 0)) {
|
||||
temp = this.temporary(name, index, options.single);
|
||||
if (!(this.check(temp) || indexOf.call(this.root.referencedVars, temp) >= 0)) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (reserve) {
|
||||
if ((ref = options.reserve) != null ? ref : true) {
|
||||
this.add(temp, 'var', true);
|
||||
}
|
||||
return temp;
|
||||
@@ -119,30 +120,32 @@
|
||||
};
|
||||
|
||||
Scope.prototype.declaredVariables = function() {
|
||||
var realVars, tempVars, v, _i, _len, _ref1;
|
||||
realVars = [];
|
||||
tempVars = [];
|
||||
_ref1 = this.variables;
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
v = _ref1[_i];
|
||||
if (v.type === 'var') {
|
||||
(v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name);
|
||||
var v;
|
||||
return ((function() {
|
||||
var i, len, ref, results;
|
||||
ref = this.variables;
|
||||
results = [];
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
v = ref[i];
|
||||
if (v.type === 'var') {
|
||||
results.push(v.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return realVars.sort().concat(tempVars.sort());
|
||||
return results;
|
||||
}).call(this)).sort();
|
||||
};
|
||||
|
||||
Scope.prototype.assignedVariables = function() {
|
||||
var v, _i, _len, _ref1, _results;
|
||||
_ref1 = this.variables;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
v = _ref1[_i];
|
||||
var i, len, ref, results, v;
|
||||
ref = this.variables;
|
||||
results = [];
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
v = ref[i];
|
||||
if (v.type.assigned) {
|
||||
_results.push(v.name + " = " + v.type.value);
|
||||
results.push(v.name + " = " + v.type.value);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
};
|
||||
|
||||
return Scope;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// Generated by CoffeeScript 1.9.0
|
||||
// Generated by CoffeeScript 1.9.1
|
||||
(function() {
|
||||
var LineMap, SourceMap;
|
||||
|
||||
LineMap = (function() {
|
||||
function LineMap(_at_line) {
|
||||
this.line = _at_line;
|
||||
function LineMap(line1) {
|
||||
this.line = line1;
|
||||
this.columns = [];
|
||||
}
|
||||
|
||||
LineMap.prototype.add = function(column, _arg, options) {
|
||||
LineMap.prototype.add = function(column, arg, options) {
|
||||
var sourceColumn, sourceLine;
|
||||
sourceLine = _arg[0], sourceColumn = _arg[1];
|
||||
sourceLine = arg[0], sourceColumn = arg[1];
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
@@ -45,18 +45,18 @@
|
||||
}
|
||||
|
||||
SourceMap.prototype.add = function(sourceLocation, generatedLocation, options) {
|
||||
var column, line, lineMap, _base;
|
||||
var base, column, line, lineMap;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
line = generatedLocation[0], column = generatedLocation[1];
|
||||
lineMap = ((_base = this.lines)[line] || (_base[line] = new LineMap(line)));
|
||||
lineMap = ((base = this.lines)[line] || (base[line] = new LineMap(line)));
|
||||
return lineMap.add(column, sourceLocation, options);
|
||||
};
|
||||
|
||||
SourceMap.prototype.sourceLocation = function(_arg) {
|
||||
SourceMap.prototype.sourceLocation = function(arg) {
|
||||
var column, line, lineMap;
|
||||
line = _arg[0], column = _arg[1];
|
||||
line = arg[0], column = arg[1];
|
||||
while (!((lineMap = this.lines[line]) || (line <= 0))) {
|
||||
line--;
|
||||
}
|
||||
@@ -64,7 +64,7 @@
|
||||
};
|
||||
|
||||
SourceMap.prototype.generate = function(options, code) {
|
||||
var buffer, lastColumn, lastSourceColumn, lastSourceLine, lineMap, lineNumber, mapping, needComma, v3, writingline, _i, _j, _len, _len1, _ref, _ref1;
|
||||
var buffer, i, j, lastColumn, lastSourceColumn, lastSourceLine, len, len1, lineMap, lineNumber, mapping, needComma, ref, ref1, v3, writingline;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
@@ -77,13 +77,13 @@
|
||||
lastSourceColumn = 0;
|
||||
needComma = false;
|
||||
buffer = "";
|
||||
_ref = this.lines;
|
||||
for (lineNumber = _i = 0, _len = _ref.length; _i < _len; lineNumber = ++_i) {
|
||||
lineMap = _ref[lineNumber];
|
||||
ref = this.lines;
|
||||
for (lineNumber = i = 0, len = ref.length; i < len; lineNumber = ++i) {
|
||||
lineMap = ref[lineNumber];
|
||||
if (lineMap) {
|
||||
_ref1 = lineMap.columns;
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
mapping = _ref1[_j];
|
||||
ref1 = lineMap.columns;
|
||||
for (j = 0, len1 = ref1.length; j < len1; j++) {
|
||||
mapping = ref1[j];
|
||||
if (!(mapping)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"compiler"
|
||||
],
|
||||
"author": "Jeremy Ashkenas",
|
||||
"version": "1.9.0",
|
||||
"version": "1.9.1",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
@@ -37,6 +37,6 @@
|
||||
"jison": ">=0.2.0",
|
||||
"highlight.js": "~8.0.0",
|
||||
"underscore": "~1.5.2",
|
||||
"docco": "~0.6.2"
|
||||
"docco": "~0.7.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ helpers = require './helpers'
|
||||
SourceMap = require './sourcemap'
|
||||
|
||||
# The current CoffeeScript version number.
|
||||
exports.VERSION = '1.9.0'
|
||||
exports.VERSION = '1.9.1'
|
||||
|
||||
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']
|
||||
|
||||
@@ -47,11 +47,9 @@ exports.compile = compile = withPrettyErrors (code, options) ->
|
||||
tokens = lexer.tokenize code, options
|
||||
|
||||
# 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.
|
||||
# the same name.
|
||||
options.referencedVars = (
|
||||
token[1] for token in tokens when token.variable and token[1].charAt(0) is '_'
|
||||
token[1] for token in tokens when token.variable
|
||||
)
|
||||
|
||||
fragments = parser.parse(tokens).compileToFragments options
|
||||
@@ -227,12 +225,15 @@ parser.yy.parseError = (message, {token}) ->
|
||||
{errorToken, tokens} = parser
|
||||
[errorTag, errorText, errorLoc] = errorToken
|
||||
|
||||
errorText = if errorToken is tokens[tokens.length - 1]
|
||||
'end of input'
|
||||
else if errorTag in ['INDENT', 'OUTDENT']
|
||||
'indentation'
|
||||
else
|
||||
helpers.nameWhitespaceCharacter errorText
|
||||
errorText = switch
|
||||
when errorToken is tokens[tokens.length - 1]
|
||||
'end of input'
|
||||
when errorTag in ['INDENT', 'OUTDENT']
|
||||
'indentation'
|
||||
when errorTag in ['IDENTIFIER', 'NUMBER', 'STRING', 'STRING_START', 'REGEX', 'REGEX_START']
|
||||
errorTag.replace(/_START$/, '').toLowerCase()
|
||||
else
|
||||
helpers.nameWhitespaceCharacter errorText
|
||||
|
||||
# The second argument has a `loc` property, which should have the location
|
||||
# data for this token. Unfortunately, Jison seems to send an outdated `loc`
|
||||
|
||||
@@ -58,6 +58,7 @@ sourceCode = []
|
||||
notSources = {}
|
||||
watchedDirs = {}
|
||||
optionParser = null
|
||||
jsToSources = {}
|
||||
|
||||
# Run `coffee` by parsing passed options and determining what action to take.
|
||||
# Many flags cause us to divert before compiling anything. Flags passed after
|
||||
@@ -352,6 +353,12 @@ mkdirp = (dir, fn) ->
|
||||
writeJs = (base, sourcePath, js, jsPath, generatedSourceMap = null) ->
|
||||
sourceMapPath = outputPath sourcePath, base, ".js.map"
|
||||
jsDir = path.dirname jsPath
|
||||
if jsPath of jsToSources
|
||||
printLine "Error: The two following source files have the same output file:"
|
||||
printLine " " + jsToSources[jsPath]
|
||||
printLine " " + sourcePath
|
||||
process.exit 1
|
||||
jsToSources[jsPath] = sourcePath
|
||||
compile = ->
|
||||
if opts.compile
|
||||
js = ' ' if js.length <= 0
|
||||
|
||||
@@ -132,7 +132,17 @@ grammar =
|
||||
# they can also serve as keys in object literals.
|
||||
AlphaNumeric: [
|
||||
o 'NUMBER', -> new Literal $1
|
||||
o 'String'
|
||||
]
|
||||
|
||||
String: [
|
||||
o 'STRING', -> new Literal $1
|
||||
o 'STRING_START Body STRING_END', -> new Parens $2
|
||||
]
|
||||
|
||||
Regex: [
|
||||
o 'REGEX', -> new Literal $1
|
||||
o 'REGEX_START Invocation REGEX_END', -> $2
|
||||
]
|
||||
|
||||
# All of our immediate values. Generally these can be passed straight
|
||||
@@ -140,7 +150,7 @@ grammar =
|
||||
Literal: [
|
||||
o 'AlphaNumeric'
|
||||
o 'JS', -> new Literal $1
|
||||
o 'REGEX', -> new Literal $1
|
||||
o 'Regex'
|
||||
o 'DEBUGGER', -> new Literal $1
|
||||
o 'UNDEFINED', -> new Undefined
|
||||
o 'NULL', -> new Null
|
||||
|
||||
@@ -62,9 +62,6 @@ exports.del = (obj, key) ->
|
||||
delete obj[key]
|
||||
val
|
||||
|
||||
# Gets the last item of an array(-like) object.
|
||||
exports.last = last = (array, back) -> array[array.length - (back or 0) - 1]
|
||||
|
||||
# Typical Array::some
|
||||
exports.some = Array::some ? (fn) ->
|
||||
return true for e in this when fn e
|
||||
|
||||
274
src/lexer.coffee
274
src/lexer.coffee
@@ -12,7 +12,7 @@
|
||||
{Rewriter, INVERSES} = require './rewriter'
|
||||
|
||||
# Import the helpers we need.
|
||||
{count, starts, compact, last, repeat, invertLiterate,
|
||||
{count, starts, compact, repeat, invertLiterate,
|
||||
locationDataToString, throwSyntaxError} = require './helpers'
|
||||
|
||||
# The Lexer Class
|
||||
@@ -73,7 +73,7 @@ exports.Lexer = class Lexer
|
||||
return {@tokens, index: i} if opts.untilBalanced and @ends.length is 0
|
||||
|
||||
@closeIndentation()
|
||||
throwSyntaxError "missing #{end.tag}", end.origin[2] if end = @ends.pop()
|
||||
@error "missing #{end.tag}", end.origin[2] if end = @ends.pop()
|
||||
return @tokens if opts.rewrite is off
|
||||
(new Rewriter).rewrite @tokens
|
||||
|
||||
@@ -112,8 +112,9 @@ exports.Lexer = class Lexer
|
||||
if id is 'from' and @tag() is 'YIELD'
|
||||
@token 'FROM', id
|
||||
return id.length
|
||||
forcedIdentifier = colon or
|
||||
(prev = last @tokens) and (prev[0] in ['.', '?.', '::', '?::'] or
|
||||
[..., prev] = @tokens
|
||||
forcedIdentifier = colon or prev? and
|
||||
(prev[0] in ['.', '?.', '::', '?::'] or
|
||||
not prev.spaced and prev[0] is '@')
|
||||
tag = 'IDENTIFIER'
|
||||
|
||||
@@ -143,7 +144,7 @@ exports.Lexer = class Lexer
|
||||
id = new String id
|
||||
id.reserved = yes
|
||||
else if id in RESERVED
|
||||
@error "reserved word \"#{id}\""
|
||||
@error "reserved word '#{id}'", length: id.length
|
||||
|
||||
unless forcedIdentifier
|
||||
id = COFFEE_ALIAS_MAP[id] if id in COFFEE_ALIASES
|
||||
@@ -171,15 +172,16 @@ exports.Lexer = class Lexer
|
||||
numberToken: ->
|
||||
return 0 unless match = NUMBER.exec @chunk
|
||||
number = match[0]
|
||||
if /^0[BOX]/.test number
|
||||
@error "radix prefix '#{number}' must be lowercase"
|
||||
else if /E/.test(number) and not /^0x/.test number
|
||||
@error "exponential notation '#{number}' must be indicated with a lowercase 'e'"
|
||||
else if /^0\d*[89]/.test number
|
||||
@error "decimal literal '#{number}' must not be prefixed with '0'"
|
||||
else if /^0\d+/.test number
|
||||
@error "octal literal '#{number}' must be prefixed with '0o'"
|
||||
lexedLength = number.length
|
||||
if /^0[BOX]/.test number
|
||||
@error "radix prefix in '#{number}' must be lowercase", offset: 1
|
||||
else if /E/.test(number) and not /^0x/.test number
|
||||
@error "exponential notation in '#{number}' must be indicated with a lowercase 'e'",
|
||||
offset: number.indexOf('E')
|
||||
else if /^0\d*[89]/.test number
|
||||
@error "decimal literal '#{number}' must not be prefixed with '0'", length: lexedLength
|
||||
else if /^0\d+/.test number
|
||||
@error "octal literal '#{number}' must be prefixed with '0o'", length: lexedLength
|
||||
if octalLiteral = /^0o([0-7]+)/.exec number
|
||||
number = '0x' + parseInt(octalLiteral[1], 8).toString 16
|
||||
if binaryLiteral = /^0b([01]+)/.exec number
|
||||
@@ -199,10 +201,10 @@ exports.Lexer = class Lexer
|
||||
when '"""' then HEREDOC_DOUBLE
|
||||
heredoc = quote.length is 3
|
||||
|
||||
start = quote.length
|
||||
{tokens, index: end} = @matchWithInterpolations @chunk[start..], regex, quote, start
|
||||
{tokens, index: end} = @matchWithInterpolations regex, quote
|
||||
$ = tokens.length - 1
|
||||
|
||||
delimiter = quote[0]
|
||||
if heredoc
|
||||
# Find the smallest indentation. It will be removed from all lines later.
|
||||
indent = null
|
||||
@@ -211,17 +213,16 @@ exports.Lexer = class Lexer
|
||||
attempt = match[1]
|
||||
indent = attempt if indent is null or 0 < attempt.length < indent.length
|
||||
indentRegex = /// ^#{indent} ///gm if indent
|
||||
@mergeInterpolationTokens tokens, {quote: quote[0], start, end}, (value, i) =>
|
||||
@mergeInterpolationTokens tokens, {delimiter}, (value, i) =>
|
||||
value = @formatString value
|
||||
value = value.replace LEADING_BLANK_LINE, '' if i is 0
|
||||
value = value.replace TRAILING_BLANK_LINE, '' if i is $
|
||||
value = value.replace indentRegex, ''
|
||||
value = value.replace MULTILINER, '\\n'
|
||||
value = value.replace indentRegex, '' if indentRegex
|
||||
value
|
||||
else
|
||||
@mergeInterpolationTokens tokens, {quote, start, end}, (value, i) =>
|
||||
@mergeInterpolationTokens tokens, {delimiter}, (value, i) =>
|
||||
value = @formatString value
|
||||
value = value.replace STRING_OMIT, (match, offset) ->
|
||||
value = value.replace SIMPLE_STRING_OMIT, (match, offset) ->
|
||||
if (i is 0 and offset is 0) or
|
||||
(i is $ and offset + match.length is value.length)
|
||||
''
|
||||
@@ -237,7 +238,8 @@ exports.Lexer = class Lexer
|
||||
[comment, here] = match
|
||||
if here
|
||||
if match = HERECOMMENT_ILLEGAL.exec comment
|
||||
@error "block comments cannot contain #{match[0]}", match.index
|
||||
@error "block comments cannot contain #{match[0]}",
|
||||
offset: match.index, length: match[0].length
|
||||
if here.indexOf('\n') >= 0
|
||||
here = here.replace /// \n #{repeat ' ', @indent} ///g, '\n'
|
||||
@token 'HERECOMMENT', here, 0, comment.length
|
||||
@@ -255,15 +257,17 @@ exports.Lexer = class Lexer
|
||||
regexToken: ->
|
||||
switch
|
||||
when match = REGEX_ILLEGAL.exec @chunk
|
||||
@error "regular expressions cannot begin with #{match[2]}", match.index + match[1].length
|
||||
when @chunk[...3] is '///'
|
||||
{tokens, index} = @matchWithInterpolations @chunk[3..], HEREGEX, '///', 3
|
||||
@error "regular expressions cannot begin with #{match[2]}",
|
||||
offset: match.index + match[1].length
|
||||
when match = @matchWithInterpolations HEREGEX, '///'
|
||||
{tokens, index} = match
|
||||
when match = REGEX.exec @chunk
|
||||
[regex, closed] = match
|
||||
[regex, body, closed] = match
|
||||
@validateEscapes body, isRegex: yes, offsetInChunk: 1
|
||||
index = regex.length
|
||||
prev = last @tokens
|
||||
[..., prev] = @tokens
|
||||
if prev
|
||||
if prev.spaced and prev[0] in CALLABLE and not prev.stringEnd and not prev.regexEnd
|
||||
if prev.spaced and prev[0] in CALLABLE
|
||||
return 0 if not closed or POSSIBLY_DIVISION.test regex
|
||||
else if prev[0] in NOT_REGEX
|
||||
return 0
|
||||
@@ -273,24 +277,23 @@ exports.Lexer = class Lexer
|
||||
|
||||
[flags] = REGEX_FLAGS.exec @chunk[index..]
|
||||
end = index + flags.length
|
||||
origin = @makeToken 'REGEX', null, 0, end
|
||||
switch
|
||||
when not VALID_FLAGS.test flags
|
||||
@error "invalid regular expression flags #{flags}", index
|
||||
when regex
|
||||
@token 'REGEX', "#{regex}#{flags}"
|
||||
when tokens.length is 1
|
||||
re = @formatHeregex(tokens[0][1]).replace(/\//g, '\\/')
|
||||
@token 'REGEX', "/#{ re or '(?:)' }/#{flags}"
|
||||
@error "invalid regular expression flags #{flags}", offset: index, length: flags.length
|
||||
when regex or tokens.length is 1
|
||||
body ?= @formatHeregex tokens[0][1]
|
||||
@token 'REGEX', "#{@makeDelimitedLiteral body, delimiter: '/'}#{flags}", 0, end, origin
|
||||
else
|
||||
@token 'REGEX_START', '(', 0, 0, origin
|
||||
@token 'IDENTIFIER', 'RegExp', 0, 0
|
||||
@token 'CALL_START', '(', 0, 0
|
||||
@mergeInterpolationTokens tokens, {quote: '"', start: 3, end}, (value) =>
|
||||
@formatHeregex(value).replace(/\\/g, '\\\\')
|
||||
@mergeInterpolationTokens tokens, {delimiter: '"', double: yes}, @formatHeregex
|
||||
if flags
|
||||
@token ',', ',', index, 0
|
||||
@token 'STRING', '"' + flags + '"', index, flags.length
|
||||
rparen = @token ')', ')', end, 0
|
||||
rparen.regexEnd = true
|
||||
@token ')', ')', end, 0
|
||||
@token 'REGEX_END', ')', end, 0
|
||||
|
||||
end
|
||||
|
||||
@@ -329,7 +332,7 @@ exports.Lexer = class Lexer
|
||||
@outdebt = @indebt = 0
|
||||
@indent = size
|
||||
else if size < @baseIndent
|
||||
@error 'missing indentation', indent.length
|
||||
@error 'missing indentation', offset: indent.length
|
||||
else
|
||||
@indebt = 0
|
||||
@outdentToken @indent - size, noNewlines, indent.length
|
||||
@@ -371,7 +374,7 @@ exports.Lexer = class Lexer
|
||||
whitespaceToken: ->
|
||||
return 0 unless (match = WHITESPACE.exec @chunk) or
|
||||
(nline = @chunk.charAt(0) is '\n')
|
||||
prev = last @tokens
|
||||
[..., prev] = @tokens
|
||||
prev[if match then 'spaced' else 'newLine'] = true if prev
|
||||
if match then match[0].length else 0
|
||||
|
||||
@@ -399,10 +402,10 @@ exports.Lexer = class Lexer
|
||||
else
|
||||
value = @chunk.charAt 0
|
||||
tag = value
|
||||
prev = last @tokens
|
||||
[..., prev] = @tokens
|
||||
if value is '=' and prev
|
||||
if not prev[1].reserved and prev[1] in JS_FORBIDDEN
|
||||
@error "reserved word \"#{@value()}\" can't be assigned"
|
||||
@error "reserved word '#{prev[1]}' can't be assigned", prev[2]
|
||||
if prev[1] in ['||', '&&']
|
||||
prev[0] = 'COMPOUND_ASSIGN'
|
||||
prev[1] += '='
|
||||
@@ -418,7 +421,7 @@ exports.Lexer = class Lexer
|
||||
else if value in SHIFT then tag = 'SHIFT'
|
||||
else if value in LOGIC or value is '?' and prev?.spaced then tag = 'LOGIC'
|
||||
else if prev and not prev.spaced
|
||||
if value is '(' and prev[0] in CALLABLE and not prev.stringEnd and not prev.regexEnd
|
||||
if value is '(' and prev[0] in CALLABLE
|
||||
prev[0] = 'FUNC_EXIST' if prev[0] is '?'
|
||||
tag = 'CALL_START'
|
||||
else if value is '[' and prev[0] in INDEXABLE
|
||||
@@ -469,23 +472,23 @@ exports.Lexer = class Lexer
|
||||
# If it encounters an interpolation, this method will recursively create a new
|
||||
# Lexer and tokenize until the `{` of `#{` is balanced with a `}`.
|
||||
#
|
||||
# - `str` is the start of the token contents (with the starting delimiter
|
||||
# stripped off.)
|
||||
# - `regex` matches the contents of a token (but not `end`, and not `#{` if
|
||||
# interpolations are desired).
|
||||
# - `end` is the terminator of the token.
|
||||
# - `offsetInChunk` is the start of the interpolated string in the current
|
||||
# chunk, including the starting delimiter.
|
||||
#
|
||||
# Examples of delimiters are `'`, `"`, `'''`, `"""` and `///`.
|
||||
# - `regex` matches the contents of a token (but not `delimiter`, and not
|
||||
# `#{` if interpolations are desired).
|
||||
# - `delimiter` is the delimiter of the token. Examples are `'`, `"`, `'''`,
|
||||
# `"""` and `///`.
|
||||
#
|
||||
# This method allows us to have strings within interpolations within strings,
|
||||
# ad infinitum.
|
||||
matchWithInterpolations: (str, regex, end, offsetInChunk) ->
|
||||
matchWithInterpolations: (regex, delimiter) ->
|
||||
tokens = []
|
||||
offsetInChunk = delimiter.length
|
||||
return null unless @chunk[...offsetInChunk] is delimiter
|
||||
str = @chunk[offsetInChunk..]
|
||||
loop
|
||||
[strPart] = regex.exec str
|
||||
|
||||
@validateEscapes strPart, {isRegex: delimiter.charAt(0) is '/', offsetInChunk}
|
||||
|
||||
# Push a fake 'NEOSTRING' token, which will get turned into a real string later.
|
||||
tokens.push @makeToken 'NEOSTRING', strPart, offsetInChunk
|
||||
|
||||
@@ -517,20 +520,23 @@ exports.Lexer = class Lexer
|
||||
str = str[index..]
|
||||
offsetInChunk += index
|
||||
|
||||
unless str[...end.length] is end
|
||||
@error "missing #{end}"
|
||||
unless str[...delimiter.length] is delimiter
|
||||
@error "missing #{delimiter}", length: delimiter.length
|
||||
|
||||
{tokens, index: offsetInChunk + end.length}
|
||||
[firstToken, ..., lastToken] = tokens
|
||||
firstToken[2].first_column -= delimiter.length
|
||||
lastToken[2].last_column += delimiter.length
|
||||
lastToken[2].last_column -= 1 if lastToken[1].length is 0
|
||||
|
||||
{tokens, index: offsetInChunk + delimiter.length}
|
||||
|
||||
# Merge the array `tokens` of the fake token types 'TOKENS' and 'NEOSTRING'
|
||||
# (as returned by `matchWithInterpolations`) into the token stream. The value
|
||||
# of 'NEOSTRING's are converted using `fn` and turned into strings using
|
||||
# `quote` first. The tokens are wrapped in parentheses if needed, using
|
||||
# `start` and `end` for their location data.
|
||||
mergeInterpolationTokens: (tokens, {quote, start, end}, fn) ->
|
||||
if interpolated = tokens.length > 1
|
||||
errorToken = @makeToken '', 'interpolation', start + tokens[0][1].length, 2
|
||||
@token '(', '(', 0, 0, errorToken
|
||||
# `options` first.
|
||||
mergeInterpolationTokens: (tokens, options, fn) ->
|
||||
if tokens.length > 1
|
||||
lparen = @token 'STRING_START', '(', 0, 0
|
||||
|
||||
firstIndex = @tokens.length
|
||||
for token, i in tokens
|
||||
@@ -559,7 +565,7 @@ exports.Lexer = class Lexer
|
||||
if i is 2 and firstEmptyStringIndex?
|
||||
@tokens.splice firstEmptyStringIndex, 2 # Remove empty string and the plus.
|
||||
token[0] = 'STRING'
|
||||
token[1] = @makeString converted, quote
|
||||
token[1] = @makeDelimitedLiteral converted, options
|
||||
locationToken = token
|
||||
tokensToPush = [token]
|
||||
if @tokens.length > firstIndex
|
||||
@@ -572,21 +578,34 @@ exports.Lexer = class Lexer
|
||||
last_column: locationToken[2].first_column
|
||||
@tokens.push tokensToPush...
|
||||
|
||||
if interpolated
|
||||
rparen = @token ')', ')', end, 0
|
||||
rparen.stringEnd = true
|
||||
if lparen
|
||||
[..., lastToken] = tokens
|
||||
lparen.origin = ['STRING', null,
|
||||
first_line: lparen[2].first_line
|
||||
first_column: lparen[2].first_column
|
||||
last_line: lastToken[2].last_line
|
||||
last_column: lastToken[2].last_column
|
||||
]
|
||||
rparen = @token 'STRING_END', ')'
|
||||
rparen[2] =
|
||||
first_line: lastToken[2].last_line
|
||||
first_column: lastToken[2].last_column
|
||||
last_line: lastToken[2].last_line
|
||||
last_column: lastToken[2].last_column
|
||||
|
||||
# Pairs up a closing token, ensuring that all listed pairs of tokens are
|
||||
# correctly balanced throughout the course of the token stream.
|
||||
pair: (tag) ->
|
||||
unless tag is wanted = last(@ends)?.tag
|
||||
[..., prev] = @ends
|
||||
unless tag is wanted = prev?.tag
|
||||
@error "unmatched #{tag}" unless 'OUTDENT' is wanted
|
||||
# Auto-close INDENT to support syntax like this:
|
||||
#
|
||||
# el.click((event) ->
|
||||
# el.hide())
|
||||
#
|
||||
@outdentToken last(@indents), true
|
||||
[..., lastIndent] = @indents
|
||||
@outdentToken lastIndent, true
|
||||
return @pair tag
|
||||
@ends.pop()
|
||||
|
||||
@@ -609,8 +628,8 @@ exports.Lexer = class Lexer
|
||||
|
||||
column = @chunkColumn
|
||||
if lineCount > 0
|
||||
lines = string.split '\n'
|
||||
column = last(lines).length
|
||||
[..., lastLine] = string.split '\n'
|
||||
column = lastLine.length
|
||||
else
|
||||
column += string.length
|
||||
|
||||
@@ -645,13 +664,15 @@ exports.Lexer = class Lexer
|
||||
@tokens.push token
|
||||
token
|
||||
|
||||
# Peek at a tag in the current token stream.
|
||||
tag: (index, tag) ->
|
||||
(tok = last @tokens, index) and if tag then tok[0] = tag else tok[0]
|
||||
# Peek at the last tag in the token stream.
|
||||
tag: ->
|
||||
[..., token] = @tokens
|
||||
token?[0]
|
||||
|
||||
# Peek at a value in the current token stream.
|
||||
value: (index, val) ->
|
||||
(tok = last @tokens, index) and if val then tok[1] = val else tok[1]
|
||||
# Peek at the last value in the token stream.
|
||||
value: ->
|
||||
[..., token] = @tokens
|
||||
token?[1]
|
||||
|
||||
# Are we in the midst of an unfinished expression?
|
||||
unfinished: ->
|
||||
@@ -660,30 +681,59 @@ exports.Lexer = class Lexer
|
||||
'**', 'SHIFT', 'RELATION', 'COMPARE', 'LOGIC', 'THROW', 'EXTENDS']
|
||||
|
||||
formatString: (str) ->
|
||||
# Ignore escaped backslashes and remove escaped newlines.
|
||||
str.replace /\\[^\S\n]*(\n|\\)\s*/g, (escaped, character) ->
|
||||
if character is '\n' then '' else escaped
|
||||
str.replace STRING_OMIT, '$1'
|
||||
|
||||
formatHeregex: (str) ->
|
||||
str.replace(HEREGEX_OMIT, '$1$2').replace(MULTILINER, '\\n')
|
||||
str.replace HEREGEX_OMIT, '$1$2'
|
||||
|
||||
# Constructs a string token by escaping quotes.
|
||||
makeString: (body, quote) ->
|
||||
return quote + quote unless body
|
||||
# Ignore escaped backslashes and unescape quotes.
|
||||
body = body.replace /// \\( #{quote} | \\ ) ///g, (match, contents) ->
|
||||
if contents is quote then contents else match
|
||||
body = body.replace /// #{quote} ///g, '\\$&'
|
||||
if match = OCTAL_ESCAPE.exec body
|
||||
@error "octal escape sequences are not allowed #{match[2]}", match.index + match[1].length + 1
|
||||
quote + body + quote
|
||||
# Validates escapes in strings and regexes.
|
||||
validateEscapes: (str, options = {}) ->
|
||||
match = INVALID_ESCAPE.exec str
|
||||
return unless match
|
||||
[[], before, octal, hex, unicode] = match
|
||||
return if options.isRegex and octal and octal.charAt(0) isnt '0'
|
||||
message =
|
||||
if octal
|
||||
"octal escape sequences are not allowed"
|
||||
else
|
||||
"invalid escape sequence"
|
||||
invalidEscape = "\\#{octal or hex or unicode}"
|
||||
@error "#{message} #{invalidEscape}",
|
||||
offset: (options.offsetInChunk ? 0) + match.index + before.length
|
||||
length: invalidEscape.length
|
||||
|
||||
# Throws a compiler error on the current position.
|
||||
error: (message, offset = 0) ->
|
||||
# TODO: Are there some cases we could improve the error line number by
|
||||
# passing the offset in the chunk where the error happened?
|
||||
[first_line, first_column] = @getLineAndColumnFromChunk offset
|
||||
throwSyntaxError message, {first_line, first_column}
|
||||
# Constructs a string or regex by escaping certain characters.
|
||||
makeDelimitedLiteral: (body, options = {}) ->
|
||||
body = '(?:)' if body is '' and options.delimiter is '/'
|
||||
regex = ///
|
||||
(\\\\) # escaped backslash
|
||||
| (\\0(?=[1-7])) # nul character mistaken as octal escape
|
||||
| \\?(#{options.delimiter}) # (possibly escaped) delimiter
|
||||
| \\?(?: (\n)|(\r)|(\u2028)|(\u2029) ) # (possibly escaped) newlines
|
||||
| (\\.) # other escapes
|
||||
///g
|
||||
body = body.replace regex, (match, backslash, nul, delimiter, lf, cr, ls, ps, other) -> switch
|
||||
# Ignore escaped backslashes.
|
||||
when backslash then (if options.double then backslash + backslash else backslash)
|
||||
when nul then '\\x00'
|
||||
when delimiter then "\\#{delimiter}"
|
||||
when lf then '\\n'
|
||||
when cr then '\\r'
|
||||
when ls then '\\u2028'
|
||||
when ps then '\\u2029'
|
||||
when other then (if options.double then "\\#{other}" else other)
|
||||
"#{options.delimiter}#{body}#{options.delimiter}"
|
||||
|
||||
# Throws an error at either a given offset from the current chunk or at the
|
||||
# location of a token (`token[2]`).
|
||||
error: (message, options = {}) ->
|
||||
location =
|
||||
if 'first_line' of options
|
||||
options
|
||||
else
|
||||
[first_line, first_column] = @getLineAndColumnFromChunk options.offset ? 0
|
||||
{first_line, first_column, last_column: first_column + (options.length ? 1) - 1}
|
||||
throwSyntaxError message, location
|
||||
|
||||
# Constants
|
||||
# ---------
|
||||
@@ -777,18 +827,22 @@ STRING_DOUBLE = /// ^(?: [^\\"#] | \\[\s\S] | \#(?!\{) )* ///
|
||||
HEREDOC_SINGLE = /// ^(?: [^\\'] | \\[\s\S] | '(?!'') )* ///
|
||||
HEREDOC_DOUBLE = /// ^(?: [^\\"#] | \\[\s\S] | "(?!"") | \#(?!\{) )* ///
|
||||
|
||||
STRING_OMIT = /\s*\n\s*/g
|
||||
HEREDOC_INDENT = /\n+([^\n\S]*)(?=\S)/g
|
||||
STRING_OMIT = ///
|
||||
((?:\\\\)+) # consume (and preserve) an even number of backslashes
|
||||
| \\[^\S\n]*\n\s* # remove escaped newlines
|
||||
///g
|
||||
SIMPLE_STRING_OMIT = /\s*\n\s*/g
|
||||
HEREDOC_INDENT = /\n+([^\n\S]*)(?=\S)/g
|
||||
|
||||
# Regex-matching-regexes.
|
||||
REGEX = /// ^
|
||||
/ (?!/) (
|
||||
/ (?!/) ((
|
||||
?: [^ [ / \n \\ ] # every other thing
|
||||
| \\. # anything (but newlines) escaped
|
||||
| \\[^\n] # anything but newlines escaped
|
||||
| \[ # character class
|
||||
(?: \\. | [^ \] \n \\ ] )*
|
||||
(?: \\[^\n] | [^ \] \n \\ ] )*
|
||||
]
|
||||
)* (/)?
|
||||
)*) (/)?
|
||||
///
|
||||
|
||||
REGEX_FLAGS = /^\w*/
|
||||
@@ -798,7 +852,7 @@ HEREGEX = /// ^(?: [^\\/#] | \\[\s\S] | /(?!//) | \#(?!\{) )* ///
|
||||
|
||||
HEREGEX_OMIT = ///
|
||||
((?:\\\\)+) # consume (and preserve) an even number of backslashes
|
||||
| \\(\s|/) # preserve escaped whitespace and "de-escape" slashes
|
||||
| \\(\s) # preserve escaped whitespace
|
||||
| \s+(?:#.*)? # remove whitespace and comments
|
||||
///g
|
||||
|
||||
@@ -807,13 +861,18 @@ REGEX_ILLEGAL = /// ^ ( / | /{3}\s*) (\*) ///
|
||||
POSSIBLY_DIVISION = /// ^ /=?\s ///
|
||||
|
||||
# Other regexes.
|
||||
MULTILINER = /\n/g
|
||||
|
||||
HERECOMMENT_ILLEGAL = /\*\//
|
||||
|
||||
LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?![.\d]) | :: ) ///
|
||||
|
||||
OCTAL_ESCAPE = /// ^ ((?: \\. | [^\\] )*) (\\ (?: 0[0-7] | [1-7] )) ///
|
||||
INVALID_ESCAPE = ///
|
||||
( (?:^|[^\\]) (?:\\\\)* ) # make sure the escape isn’t escaped
|
||||
\\ (
|
||||
?: (0[0-7]|[1-7]) # octal escape
|
||||
| (x(?![\da-fA-F]{2}).{0,2}) # hex escape
|
||||
| (u(?![\da-fA-F]{4}).{0,4}) # unicode escape
|
||||
)
|
||||
///
|
||||
|
||||
LEADING_BLANK_LINE = /^[^\n\S]*\n/
|
||||
TRAILING_BLANK_LINE = /\n[^\n\S]*$/
|
||||
@@ -853,7 +912,10 @@ BOOL = ['TRUE', 'FALSE']
|
||||
# parentheses or bracket following these tokens will be recorded as the start
|
||||
# of a function invocation or indexing operation.
|
||||
CALLABLE = ['IDENTIFIER', ')', ']', '?', '@', 'THIS', 'SUPER']
|
||||
INDEXABLE = CALLABLE.concat ['NUMBER', 'STRING', 'REGEX', 'BOOL', 'NULL', 'UNDEFINED', '}', '::']
|
||||
INDEXABLE = CALLABLE.concat [
|
||||
'NUMBER', 'STRING', 'STRING_END', 'REGEX', 'REGEX_END'
|
||||
'BOOL', 'NULL', 'UNDEFINED', '}', '::'
|
||||
]
|
||||
|
||||
# Tokens which a regular expression will never immediately follow (except spaced
|
||||
# CALLABLEs in some cases), but which a division operator can.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user