mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-13 08:47:55 -05:00
Compare commits
448 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ab8503e5a | ||
|
|
114eccb459 | ||
|
|
38bd879a9a | ||
|
|
a73a6e24a6 | ||
|
|
b4d35f13a4 | ||
|
|
3fcaebb007 | ||
|
|
e543eb5101 | ||
|
|
7c4f842501 | ||
|
|
a5fef52751 | ||
|
|
734fcedc06 | ||
|
|
e4c8bcf8f6 | ||
|
|
a3ae0c5c75 | ||
|
|
46895419b3 | ||
|
|
4f6a4bab30 | ||
|
|
9e5ffaea69 | ||
|
|
928d2d7f4a | ||
|
|
10293df1f9 | ||
|
|
41c4c822ba | ||
|
|
6030ac3a23 | ||
|
|
f42329ca0a | ||
|
|
570529f526 | ||
|
|
8b8436d794 | ||
|
|
b0594aad3e | ||
|
|
04b0b94a8c | ||
|
|
e1f46cfb9b | ||
|
|
cc1b74f11b | ||
|
|
104b4666fe | ||
|
|
835fc84330 | ||
|
|
a5d6285cfd | ||
|
|
c2727d964c | ||
|
|
d687d52f9e | ||
|
|
6a43de789f | ||
|
|
1288786fdc | ||
|
|
2b4421fca1 | ||
|
|
6bdd52733e | ||
|
|
bd6b4142fe | ||
|
|
daa6ad5470 | ||
|
|
369e0545c0 | ||
|
|
5f31a3d60e | ||
|
|
8b976acac1 | ||
|
|
b00962db1a | ||
|
|
26dcf025f4 | ||
|
|
d2f90d2236 | ||
|
|
c3391e1dd8 | ||
|
|
b3463a1378 | ||
|
|
f0463e9981 | ||
|
|
1cc583b382 | ||
|
|
39cb8815f7 | ||
|
|
21db08a23d | ||
|
|
1f301d8c07 | ||
|
|
35f185440f | ||
|
|
5ce0c84907 | ||
|
|
a6891e4feb | ||
|
|
8a3ebb9181 | ||
|
|
308299fe04 | ||
|
|
1cc8463b9c | ||
|
|
d7862647d9 | ||
|
|
6c786f0fb7 | ||
|
|
cc345def46 | ||
|
|
818983b6a4 | ||
|
|
b859d92d2c | ||
|
|
8cd9ba168d | ||
|
|
08a57898a7 | ||
|
|
ba4743cc83 | ||
|
|
94e22ab819 | ||
|
|
c1b46f777f | ||
|
|
81cf9ca00f | ||
|
|
96f087ca6b | ||
|
|
bc975e556e | ||
|
|
6804c1065b | ||
|
|
74cf54a84f | ||
|
|
73af30b5d8 | ||
|
|
54633aee3f | ||
|
|
26200f4640 | ||
|
|
13f205404c | ||
|
|
563f14b178 | ||
|
|
5e4cca90a3 | ||
|
|
a61b6ee925 | ||
|
|
b11d956d53 | ||
|
|
ee9febe399 | ||
|
|
15a70f863c | ||
|
|
4eee9c318e | ||
|
|
ac6a76ee10 | ||
|
|
42aa8d256c | ||
|
|
873ed071d4 | ||
|
|
210376f7a9 | ||
|
|
35d327a304 | ||
|
|
e3e8b1c501 | ||
|
|
52a54a7681 | ||
|
|
1fe28c1fc9 | ||
|
|
89efd05a3f | ||
|
|
caafafcf4d | ||
|
|
81d8224b9a | ||
|
|
22c85e216f | ||
|
|
f047ba52b2 | ||
|
|
130899a39f | ||
|
|
6847400ccb | ||
|
|
1102567b0c | ||
|
|
8c6647849b | ||
|
|
de42ad0e1c | ||
|
|
073d025fac | ||
|
|
efe8c68c75 | ||
|
|
45d97b3dfe | ||
|
|
fcc88ca472 | ||
|
|
187ebd0374 | ||
|
|
c4999efda7 | ||
|
|
b6231e50c3 | ||
|
|
592aa33577 | ||
|
|
544c99a9ad | ||
|
|
de0e3baf1f | ||
|
|
aea0f2533b | ||
|
|
138c25fe5f | ||
|
|
e0195756dc | ||
|
|
96ae98fade | ||
|
|
efb9809d3b | ||
|
|
0dada3dd27 | ||
|
|
849c8e8ef4 | ||
|
|
9e9c83f788 | ||
|
|
d41d87a874 | ||
|
|
ab40571ffc | ||
|
|
5d13d14de9 | ||
|
|
1df8abf1cb | ||
|
|
45b60c9a52 | ||
|
|
091bc56a96 | ||
|
|
52789f5b19 | ||
|
|
9ba1d41ec8 | ||
|
|
5456bd5f89 | ||
|
|
0d662c3ad2 | ||
|
|
fa76e2dd21 | ||
|
|
08f6c65c3b | ||
|
|
54840c0cbf | ||
|
|
91ac3fa031 | ||
|
|
2853e718f2 | ||
|
|
c22707cd53 | ||
|
|
351c875576 | ||
|
|
35b64d7f18 | ||
|
|
db87d817e8 | ||
|
|
f3c5cc6774 | ||
|
|
4cc2c305a4 | ||
|
|
a5513c45d0 | ||
|
|
c820e0241e | ||
|
|
eb2ac2c64d | ||
|
|
59cf19fd1c | ||
|
|
d5a25d138d | ||
|
|
a7ecd80c92 | ||
|
|
465cffc675 | ||
|
|
302a46d093 | ||
|
|
392767a04e | ||
|
|
928f949761 | ||
|
|
8bb833d858 | ||
|
|
2b03fa9077 | ||
|
|
cfdb774da9 | ||
|
|
b173a377a6 | ||
|
|
581af4540a | ||
|
|
18e5b6b199 | ||
|
|
6da2306fe2 | ||
|
|
a8e4b78803 | ||
|
|
a3be1f6e48 | ||
|
|
89ef3d4117 | ||
|
|
4cf75ec027 | ||
|
|
830c294aea | ||
|
|
bb86e54ece | ||
|
|
359e17277f | ||
|
|
89f5f9d59d | ||
|
|
26c0f7ca2d | ||
|
|
40c1086efa | ||
|
|
999a3db499 | ||
|
|
50e13f62f2 | ||
|
|
fceff1729c | ||
|
|
1765a7ae0c | ||
|
|
ae79ff9fa3 | ||
|
|
3e9d01d6c6 | ||
|
|
ae4535d639 | ||
|
|
c5120c7980 | ||
|
|
92e83489fc | ||
|
|
1b7491d63d | ||
|
|
ce14ad764a | ||
|
|
96e807c677 | ||
|
|
70994d4b50 | ||
|
|
675095efbe | ||
|
|
0235d12927 | ||
|
|
9d24a3420d | ||
|
|
3ad332d5d4 | ||
|
|
15517df417 | ||
|
|
3c2f0d174e | ||
|
|
8cf6f62ea4 | ||
|
|
9e716b310d | ||
|
|
e44bf9ae81 | ||
|
|
f5f99b3022 | ||
|
|
dc3d70e696 | ||
|
|
77fded3c5e | ||
|
|
e644f7244d | ||
|
|
457cdfde26 | ||
|
|
910e38749c | ||
|
|
2b4a37296f | ||
|
|
3f9cdcf1fa | ||
|
|
4342bedd2f | ||
|
|
fdd5796f5e | ||
|
|
f48aa44386 | ||
|
|
51c625205b | ||
|
|
e581f7d2f0 | ||
|
|
3aa646e425 | ||
|
|
92208fec44 | ||
|
|
cdc603c794 | ||
|
|
46d8902004 | ||
|
|
34c1704286 | ||
|
|
19767a0f10 | ||
|
|
0c9f0fd099 | ||
|
|
7f1088054c | ||
|
|
ef5f58e30e | ||
|
|
13024e6911 | ||
|
|
32e8e562ea | ||
|
|
7fdac5c3b9 | ||
|
|
b68fd9d76e | ||
|
|
25c6001a6c | ||
|
|
7250fdd576 | ||
|
|
b7f8443052 | ||
|
|
4fd5e9a3ab | ||
|
|
3785996c44 | ||
|
|
eb0a222eea | ||
|
|
3d761e73e3 | ||
|
|
cc3b4e8080 | ||
|
|
ba7cb3ab69 | ||
|
|
054443c46e | ||
|
|
c8dae22cb0 | ||
|
|
183ec48308 | ||
|
|
13187b0199 | ||
|
|
3c880bf601 | ||
|
|
8e90aaefc1 | ||
|
|
426ae97e49 | ||
|
|
f277a43645 | ||
|
|
2e408648aa | ||
|
|
f2f10e85a8 | ||
|
|
84b8b5ccee | ||
|
|
7b14a6aad2 | ||
|
|
342306587c | ||
|
|
3298c9caad | ||
|
|
7089b02a74 | ||
|
|
bd451800bf | ||
|
|
5e06f7e859 | ||
|
|
0f5ae54014 | ||
|
|
5496a189bc | ||
|
|
2e6a781014 | ||
|
|
b85cf5355f | ||
|
|
f038d0514a | ||
|
|
7c4128ee3b | ||
|
|
012e3c019c | ||
|
|
b3ffd25339 | ||
|
|
46a0dc6dce | ||
|
|
30b2af820a | ||
|
|
e7d01b903f | ||
|
|
e4407dd73c | ||
|
|
2fd956d8d4 | ||
|
|
c0aac8e598 | ||
|
|
d46a44ac48 | ||
|
|
9b1bdd4b36 | ||
|
|
fd47920c63 | ||
|
|
088b8b3ec5 | ||
|
|
afd9b44dea | ||
|
|
b54db2ea07 | ||
|
|
3650d6eb4e | ||
|
|
05b74f3743 | ||
|
|
174cd7eaa0 | ||
|
|
3921e3db34 | ||
|
|
63bc7fe354 | ||
|
|
ba01e36cc2 | ||
|
|
40d2761bd8 | ||
|
|
4ff7fef3bb | ||
|
|
7be996c010 | ||
|
|
f4332475b5 | ||
|
|
4da00e8296 | ||
|
|
e8fae286be | ||
|
|
f451bb5f61 | ||
|
|
d8d7495767 | ||
|
|
e7ebdce60f | ||
|
|
fd61476106 | ||
|
|
4b4f6ac222 | ||
|
|
7b9699c5fa | ||
|
|
8a59558e2d | ||
|
|
5162472f16 | ||
|
|
1917bb69ed | ||
|
|
3b38153759 | ||
|
|
e06a17d929 | ||
|
|
71aea4b862 | ||
|
|
4b4818d819 | ||
|
|
c785e00a15 | ||
|
|
c6398e16b1 | ||
|
|
ccc7c4404d | ||
|
|
69d66a1d4d | ||
|
|
af81f6de70 | ||
|
|
f21dc7a96e | ||
|
|
cf07fcb4b1 | ||
|
|
740a7bcb45 | ||
|
|
0e2d2ea637 | ||
|
|
feaea49eac | ||
|
|
170f311101 | ||
|
|
0cadcdc097 | ||
|
|
337ebd3ce9 | ||
|
|
5d5920c5d0 | ||
|
|
8be65dee93 | ||
|
|
4dbd9dc264 | ||
|
|
2d0e45c46d | ||
|
|
d57b1aab10 | ||
|
|
cc84d6ea67 | ||
|
|
53a5f26430 | ||
|
|
a1ff4ae7b8 | ||
|
|
3251efa9c6 | ||
|
|
17a1cdb2cf | ||
|
|
1643f7df7a | ||
|
|
3c0344b954 | ||
|
|
22e8856b4d | ||
|
|
9bfafb88cb | ||
|
|
08b59aef8a | ||
|
|
fbc019171c | ||
|
|
e237abff84 | ||
|
|
718224f99a | ||
|
|
c0d1f22487 | ||
|
|
b2d6997eff | ||
|
|
e26f982c24 | ||
|
|
1b2fe69a18 | ||
|
|
c159a64b58 | ||
|
|
e091c9d6b4 | ||
|
|
67fd84fc1d | ||
|
|
57d3cfd67f | ||
|
|
6dd61626d2 | ||
|
|
1e99f887e7 | ||
|
|
78d10f30a0 | ||
|
|
7f0610d0bd | ||
|
|
4bef435e0e | ||
|
|
194baa0bd7 | ||
|
|
c8b8beb500 | ||
|
|
6786bab2ba | ||
|
|
566a7dabb2 | ||
|
|
a3e8de338a | ||
|
|
4f815ea978 | ||
|
|
417008a030 | ||
|
|
84c44c0099 | ||
|
|
2d6a856d61 | ||
|
|
011d7dc245 | ||
|
|
b2aa1798b1 | ||
|
|
5fb047930e | ||
|
|
c24e957f17 | ||
|
|
fd0b1ffc4d | ||
|
|
0bfe6394a4 | ||
|
|
9d025df9e3 | ||
|
|
2f5b11b295 | ||
|
|
c44826acc7 | ||
|
|
4386f2abc7 | ||
|
|
f217a10721 | ||
|
|
b8d695a4e1 | ||
|
|
44c2b4aa7f | ||
|
|
52ca531b7c | ||
|
|
d4254a40a9 | ||
|
|
052e3cc8eb | ||
|
|
56413ba3b4 | ||
|
|
71bb6108fb | ||
|
|
7d08dbb86c | ||
|
|
a8b65565dd | ||
|
|
54258e441d | ||
|
|
4ac223b684 | ||
|
|
707655daef | ||
|
|
70e83030a7 | ||
|
|
9787ce543d | ||
|
|
22595424a8 | ||
|
|
601189ea2d | ||
|
|
d3263dc35b | ||
|
|
e1c6b083f8 | ||
|
|
f56f5f234e | ||
|
|
4ca6da4a95 | ||
|
|
b0cbd90e64 | ||
|
|
9b6772a390 | ||
|
|
b7f0653a0e | ||
|
|
45bcd9fa2f | ||
|
|
20d98c7106 | ||
|
|
5ec658c55d | ||
|
|
64301d0d08 | ||
|
|
119ec16e5e | ||
|
|
decc0f18fc | ||
|
|
5a004425ca | ||
|
|
69f6500ba9 | ||
|
|
97980ffc7f | ||
|
|
f0fcf4aee0 | ||
|
|
838e5e1163 | ||
|
|
af0bdae675 | ||
|
|
0d45287057 | ||
|
|
09f8df9640 | ||
|
|
dbb99f31a7 | ||
|
|
c7da623d4b | ||
|
|
b44435ab8a | ||
|
|
c53df12ec1 | ||
|
|
13fae12f69 | ||
|
|
0120db0efc | ||
|
|
c4f50b52d7 | ||
|
|
242f397bfa | ||
|
|
f85d19b459 | ||
|
|
8f7f3627e0 | ||
|
|
8b134cf348 | ||
|
|
67de35ff29 | ||
|
|
774ee6a554 | ||
|
|
4be4ea3623 | ||
|
|
18fec7e202 | ||
|
|
072df5ecc9 | ||
|
|
4d7151aa5d | ||
|
|
185b2ce632 | ||
|
|
ce6772f2be | ||
|
|
d6e1a979e4 | ||
|
|
de8ec2beb0 | ||
|
|
342a796cc0 | ||
|
|
355754ed20 | ||
|
|
fbe07f1fce | ||
|
|
304432c197 | ||
|
|
5da7f6a488 | ||
|
|
f8c6b494aa | ||
|
|
1b573412d3 | ||
|
|
b400047045 | ||
|
|
51b1affbc5 | ||
|
|
903e9c994c | ||
|
|
fca68717ff | ||
|
|
22d6a4b255 | ||
|
|
26102a0970 | ||
|
|
add84bfddc | ||
|
|
dcd74d3e59 | ||
|
|
2684737b66 | ||
|
|
74181c0ec0 | ||
|
|
ebff9fbc31 | ||
|
|
97a41adf0c | ||
|
|
9ea4268b92 | ||
|
|
589d67d8b7 | ||
|
|
3127e76f4b | ||
|
|
0affb4f936 | ||
|
|
55c99dfaec | ||
|
|
c98fae59fc | ||
|
|
3182475207 | ||
|
|
5115fcb162 | ||
|
|
1db89d1589 | ||
|
|
fbc8417263 | ||
|
|
44e3a76881 | ||
|
|
f2efada0d4 | ||
|
|
5f00d6478a | ||
|
|
7e5f1b14a3 | ||
|
|
caacd892cc | ||
|
|
25091fb2a0 | ||
|
|
334dcbd162 | ||
|
|
7065538224 | ||
|
|
7fdd21b26d | ||
|
|
deae3e53f5 | ||
|
|
3bd4dea305 | ||
|
|
a4249fd573 |
61
Cakefile
61
Cakefile
@@ -1,5 +1,6 @@
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
_ = require 'underscore'
|
||||
CoffeeScript = require './lib/coffee-script'
|
||||
{spawn, exec} = require 'child_process'
|
||||
helpers = require './lib/coffee-script/helpers'
|
||||
@@ -41,6 +42,29 @@ run = (args, cb) ->
|
||||
log = (message, color, explanation) ->
|
||||
console.log color + message + reset + ' ' + (explanation or '')
|
||||
|
||||
codeFor = ->
|
||||
counter = 0
|
||||
hljs = require 'highlight.js'
|
||||
hljs.configure classPrefix: ''
|
||||
(file, executable = false, showLoad = true) ->
|
||||
counter++
|
||||
return unless fs.existsSync "documentation/js/#{file}.js"
|
||||
cs = fs.readFileSync "documentation/coffee/#{file}.coffee", 'utf-8'
|
||||
js = fs.readFileSync "documentation/js/#{file}.js", 'utf-8'
|
||||
js = js.replace /^\/\/ generated.*?\n/i, ''
|
||||
|
||||
cshtml = "<pre><code>#{hljs.highlight('coffeescript', cs).value}</code></pre>"
|
||||
jshtml = "<pre><code>#{hljs.highlight('javascript', js).value}</code></pre>"
|
||||
append = if executable is yes then '' else "alert(#{executable});"
|
||||
if executable and executable != yes
|
||||
cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}"
|
||||
run = if executable is true then 'run' else "run: #{executable}"
|
||||
name = "example#{counter}"
|
||||
script = "<script>window.#{name} = #{JSON.stringify cs}</script>"
|
||||
load = if showLoad then "<div class='minibutton load' onclick='javascript: loadConsole(#{name});'>load</div>" else ''
|
||||
button = if executable then "<div class='minibutton ok' onclick='javascript: #{js};#{append}'>#{run}</div>" else ''
|
||||
"<div class='code'>#{cshtml}#{jshtml}#{script}#{load}#{button}<br class='clear' /></div>"
|
||||
|
||||
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
|
||||
|
||||
task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
|
||||
@@ -84,21 +108,15 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
|
||||
parser = require('./lib/coffee-script/grammar').parser
|
||||
fs.writeFile 'lib/coffee-script/parser.js', parser.generate()
|
||||
|
||||
|
||||
task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
|
||||
exec 'plist2syntax ../coffee-script-tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) ->
|
||||
throw err if err
|
||||
exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax'
|
||||
|
||||
|
||||
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
|
||||
code = ''
|
||||
for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'sourcemap', 'coffee-script', 'browser']
|
||||
code += """
|
||||
require['./#{name}'] = new function() {
|
||||
var exports = this;
|
||||
require['./#{name}'] = (function() {
|
||||
var exports = {}, module = {exports: exports};
|
||||
#{fs.readFileSync "lib/coffee-script/#{name}.js"}
|
||||
};
|
||||
return module.exports;
|
||||
})();
|
||||
"""
|
||||
code = """
|
||||
(function(root) {
|
||||
@@ -123,12 +141,21 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
|
||||
|
||||
|
||||
task 'doc:site', 'watch and continually rebuild the documentation for the website', ->
|
||||
exec 'rake doc', (err) ->
|
||||
throw err if err
|
||||
source = 'documentation/index.html.js'
|
||||
exec 'bin/coffee -bc -o documentation/js documentation/coffee/*.coffee'
|
||||
|
||||
do renderIndex = ->
|
||||
codeSnippetCounter = 0
|
||||
rendered = _.template fs.readFileSync(source, 'utf-8'), codeFor: codeFor()
|
||||
fs.writeFileSync 'index.html', rendered
|
||||
log "compiled", green, "#{source}"
|
||||
|
||||
fs.watchFile source, internal: 200, renderIndex
|
||||
log "watching..." , green
|
||||
|
||||
|
||||
task 'doc:source', 'rebuild the internal documentation', ->
|
||||
exec 'docco src/*.coffee && cp -rf docs documentation && rm -r docs', (err) ->
|
||||
exec 'docco src/*.*coffee && cp -rf docs documentation && rm -r docs', (err) ->
|
||||
throw err if err
|
||||
|
||||
|
||||
@@ -160,6 +187,7 @@ task 'bench', 'quick benchmark of compilation time', ->
|
||||
|
||||
# Run the CoffeeScript test suite.
|
||||
runTests = (CoffeeScript) ->
|
||||
CoffeeScript.register()
|
||||
startTime = Date.now()
|
||||
currentFile = null
|
||||
passedTests = 0
|
||||
@@ -211,20 +239,15 @@ runTests = (CoffeeScript) ->
|
||||
log "failed #{failures.length} and #{message}", red
|
||||
for fail in failures
|
||||
{error, filename, description, source} = fail
|
||||
jsFilename = filename.replace(/\.coffee$/,'.js')
|
||||
match = error.stack?.match(new RegExp(fail.file+":(\\d+):(\\d+)"))
|
||||
match = error.stack?.match(/on line (\d+):/) unless match
|
||||
[match, line, col] = match if match
|
||||
console.log ''
|
||||
log " #{description}", red if description
|
||||
log " #{error.stack}", red
|
||||
log " #{jsFilename}: line #{line ? 'unknown'}, column #{col ? 'unknown'}", red
|
||||
console.log " #{source}" if source
|
||||
return
|
||||
|
||||
# Run every test in the `test` folder, recording failures.
|
||||
files = fs.readdirSync 'test'
|
||||
for file in files when file.match /\.(lit)?coffee$/i
|
||||
for file in files when helpers.isCoffee file
|
||||
literate = helpers.isLiterate file
|
||||
currentFile = filename = path.join 'test', file
|
||||
code = fs.readFileSync filename
|
||||
|
||||
4
LICENSE
4
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2009-2012 Jeremy Ashkenas
|
||||
Copyright (c) 2009-2014 Jeremy Ashkenas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
@@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
15
README
15
README
@@ -1,12 +1,11 @@
|
||||
|
||||
{
|
||||
} } {
|
||||
{ { } }
|
||||
} }{ {
|
||||
{ }{ } } _____ __ __
|
||||
( }{ }{ { ) / ____| / _|/ _|
|
||||
{ }{ }{ { } / ____| / _|/ _|
|
||||
.- { { } { }} -. | | ___ | |_| |_ ___ ___
|
||||
( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|
||||
( { } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|
||||
|`-..________ ..-'| | |___| (_) | | | || __/ __/
|
||||
| | \_____\___/|_| |_| \___|\___|
|
||||
| ;--.
|
||||
@@ -22,13 +21,13 @@
|
||||
|
||||
CoffeeScript is a little language that compiles into JavaScript.
|
||||
|
||||
Install Node.js, and then the CoffeeScript compiler:
|
||||
sudo bin/cake install
|
||||
|
||||
Or, if you have the Node Package Manager installed:
|
||||
If you have the Node Package Manager installed:
|
||||
npm install -g coffee-script
|
||||
(Leave off the -g if you don't wish to install globally.)
|
||||
|
||||
Or, if you don't wish to use npm:
|
||||
sudo bin/cake install
|
||||
|
||||
Execute a script:
|
||||
coffee /path/to/script.coffee
|
||||
|
||||
@@ -47,5 +46,5 @@
|
||||
The source repository:
|
||||
git://github.com/jashkenas/coffee-script.git
|
||||
|
||||
All contributors are listed here:
|
||||
Top 100 contributors are listed here:
|
||||
http://github.com/jashkenas/coffee-script/contributors
|
||||
|
||||
79
Rakefile
79
Rakefile
@@ -1,79 +0,0 @@
|
||||
require 'rubygems'
|
||||
require 'erb'
|
||||
require 'fileutils'
|
||||
require 'rake/testtask'
|
||||
require 'json'
|
||||
|
||||
desc "Build the documentation page"
|
||||
task :doc do
|
||||
source = 'documentation/index.html.erb'
|
||||
child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" }
|
||||
at_exit { Process.kill("INT", child) }
|
||||
Signal.trap("INT") { exit }
|
||||
loop do
|
||||
mtime = File.stat(source).mtime
|
||||
if !@mtime || mtime > @mtime
|
||||
rendered = ERB.new(File.read(source)).result(binding)
|
||||
File.open('index.html', 'w+') {|f| f.write(rendered) }
|
||||
end
|
||||
@mtime = mtime
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
|
||||
desc "Build coffee-script-source gem"
|
||||
task :gem do
|
||||
require 'rubygems'
|
||||
require 'rubygems/package'
|
||||
|
||||
gemspec = Gem::Specification.new do |s|
|
||||
s.name = 'coffee-script-source'
|
||||
s.version = JSON.parse(File.read('package.json'))["version"]
|
||||
s.date = Time.now.strftime("%Y-%m-%d")
|
||||
|
||||
s.homepage = "http://jashkenas.github.com/coffee-script/"
|
||||
s.summary = "The CoffeeScript Compiler"
|
||||
s.description = <<-EOS
|
||||
CoffeeScript is a little language that compiles into JavaScript.
|
||||
Underneath all of those embarrassing braces and semicolons,
|
||||
JavaScript has always had a gorgeous object model at its heart.
|
||||
CoffeeScript is an attempt to expose the good parts of JavaScript
|
||||
in a simple way.
|
||||
EOS
|
||||
|
||||
s.files = [
|
||||
'lib/coffee_script/coffee-script.js',
|
||||
'lib/coffee_script/source.rb'
|
||||
]
|
||||
|
||||
s.authors = ['Jeremy Ashkenas']
|
||||
s.email = 'jashkenas@gmail.com'
|
||||
s.rubyforge_project = 'coffee-script-source'
|
||||
s.license = "MIT"
|
||||
end
|
||||
|
||||
file = File.open("coffee-script-source.gem", "w")
|
||||
Gem::Package.open(file, 'w') do |pkg|
|
||||
pkg.metadata = gemspec.to_yaml
|
||||
|
||||
path = "lib/coffee_script/source.rb"
|
||||
contents = <<-ERUBY
|
||||
module CoffeeScript
|
||||
module Source
|
||||
def self.bundled_path
|
||||
File.expand_path("../coffee-script.js", __FILE__)
|
||||
end
|
||||
end
|
||||
end
|
||||
ERUBY
|
||||
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
|
||||
tar_io.write(contents)
|
||||
end
|
||||
|
||||
contents = File.read("extras/coffee-script.js")
|
||||
path = "lib/coffee_script/coffee-script.js"
|
||||
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
|
||||
tar_io.write(contents)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
###
|
||||
CoffeeScript Compiler v1.6.1
|
||||
SkinnyMochaHalfCaffScript Compiler v1.0
|
||||
Released under the MIT License
|
||||
###
|
||||
|
||||
|
||||
8
documentation/coffee/chaining.coffee
Normal file
8
documentation/coffee/chaining.coffee
Normal file
@@ -0,0 +1,8 @@
|
||||
$ 'body'
|
||||
.click (e) ->
|
||||
$ '.box'
|
||||
.fadeIn 'fast'
|
||||
.addClass '.active'
|
||||
.css 'background', 'white'
|
||||
|
||||
|
||||
6
documentation/coffee/constructor_destructuring.coffee
Normal file
6
documentation/coffee/constructor_destructuring.coffee
Normal file
@@ -0,0 +1,6 @@
|
||||
class Person
|
||||
constructor: (options) ->
|
||||
{@name, @age, @height} = options
|
||||
|
||||
tim = new Person age: 4
|
||||
|
||||
7
documentation/coffee/expansion.coffee
Normal file
7
documentation/coffee/expansion.coffee
Normal file
@@ -0,0 +1,7 @@
|
||||
text = "Every literary critic believes he will
|
||||
outwit history and have the last word"
|
||||
|
||||
[first, ..., last] = text.split " "
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
start = numbers[0..2]
|
||||
|
||||
middle = numbers[3...6]
|
||||
middle = numbers[3...-2]
|
||||
|
||||
end = numbers[6..]
|
||||
end = numbers[-2..]
|
||||
|
||||
copy = numbers[..]
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
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..."
|
||||
|
||||
|
||||
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..."
|
||||
|
||||
8
documentation/coffee/switch_with_no_expression.coffee
Normal file
8
documentation/coffee/switch_with_no_expression.coffee
Normal file
@@ -0,0 +1,8 @@
|
||||
score = 76
|
||||
grade = switch
|
||||
when score < 60 then 'F'
|
||||
when score < 70 then 'D'
|
||||
when score < 80 then 'C'
|
||||
when score < 90 then 'B'
|
||||
else 'A'
|
||||
# grade == 'C'
|
||||
@@ -1,64 +0,0 @@
|
||||
pre.idle .InheritedClass {
|
||||
}
|
||||
pre.idle .TypeName {
|
||||
color: #21439C;
|
||||
}
|
||||
pre.idle .Number {
|
||||
}
|
||||
pre.idle .LibraryVariable {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .Storage {
|
||||
color: #FF5600;
|
||||
}
|
||||
pre.idle .line-numbers {
|
||||
background-color: #BAD6FD;
|
||||
color: #000000;
|
||||
}
|
||||
pre.idle {
|
||||
background-color: #FFFFFF;
|
||||
color: #000000;
|
||||
}
|
||||
pre.idle .StringInterpolation {
|
||||
color: #990000;
|
||||
}
|
||||
pre.idle .TagName {
|
||||
}
|
||||
pre.idle .LibraryConstant {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .FunctionArgument {
|
||||
color: #0076ad;
|
||||
}
|
||||
pre.idle .BuiltInConstant {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .Invalid {
|
||||
background-color: #990000;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
pre.idle .LibraryClassType {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .LibraryFunction {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .TagAttribute {
|
||||
}
|
||||
pre.idle .Keyword {
|
||||
color: #FF5600;
|
||||
}
|
||||
pre.idle .UserDefinedConstant {
|
||||
}
|
||||
pre.idle .String {
|
||||
color: #00A33F;
|
||||
}
|
||||
pre.idle .FunctionName {
|
||||
color: #21439C;
|
||||
}
|
||||
pre.idle .Variable {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .Comment {
|
||||
color: #919191;
|
||||
}
|
||||
66
documentation/css/tomorrow.css
Normal file
66
documentation/css/tomorrow.css
Normal file
@@ -0,0 +1,66 @@
|
||||
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
|
||||
/* Original code:; http://softwaremaniacs.org/media/soft/highlight/styles/tomorrow.css */
|
||||
/* But forked for CoffeeScript */
|
||||
.tomorrow-comment, pre .comment, pre .title {
|
||||
color: #8e908c;
|
||||
}
|
||||
|
||||
.tomorrow-red, pre .variable, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
|
||||
color: #c82829;
|
||||
}
|
||||
|
||||
.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .params, pre .constant {
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
|
||||
color: #eab700;
|
||||
}
|
||||
|
||||
.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
|
||||
color: #718c00;
|
||||
}
|
||||
|
||||
.tomorrow-aqua, pre .css .hexcolor {
|
||||
color: #3e999f;
|
||||
}
|
||||
|
||||
.tomorrow-blue, pre .function, pre .function .title, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
|
||||
color: #21439C;
|
||||
}
|
||||
|
||||
.tomorrow-purple, pre .keyword, pre .reserved, pre .javascript .function {
|
||||
color: #FF5600;
|
||||
}
|
||||
|
||||
pre .subst {
|
||||
color: #A535AE;
|
||||
}
|
||||
|
||||
pre .literal {
|
||||
color: #A535AE;
|
||||
}
|
||||
|
||||
pre .property {
|
||||
color: #A535AE;
|
||||
}
|
||||
|
||||
pre .class .title {
|
||||
color: #21439C;
|
||||
}
|
||||
|
||||
pre code {
|
||||
display: block;
|
||||
background: white;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
pre .coffeescript .javascript,
|
||||
pre .javascript .xml,
|
||||
pre .tex .formula,
|
||||
pre .xml .javascript,
|
||||
pre .xml .vbscript,
|
||||
pre .xml .css,
|
||||
pre .xml .cdata {
|
||||
opacity: 0.5;
|
||||
}
|
||||
@@ -1,43 +1,290 @@
|
||||
<!DOCTYPE html> <html> <head> <title>browser.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> browser.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>Override exported methods for non-Node.js engines.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">'./coffee-script'</span>
|
||||
<span class="nv">CoffeeScript.require = </span><span class="nx">require</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>Use standard JavaScript <code>eval</code> to eval code.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript.eval = </span><span class="nf">(code, options = {}) -></span>
|
||||
<span class="nx">options</span><span class="p">.</span><span class="nx">bare</span> <span class="o">?=</span> <span class="kc">on</span>
|
||||
<span class="nb">eval</span> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>Running code does not provide access to this scope.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript.run = </span><span class="nf">(code, options = {}) -></span>
|
||||
<span class="nv">options.bare = </span><span class="kc">on</span>
|
||||
<span class="nb">Function</span><span class="p">(</span><span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)()</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>If we're not in a browser environment, we're finished with the public API.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">return</span> <span class="k">unless</span> <span class="nb">window</span><span class="o">?</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Load a remote script from the current domain via XHR.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript.load = </span><span class="nf">(url, callback, options = {}) -></span>
|
||||
<span class="nv">xhr = </span><span class="k">if</span> <span class="nb">window</span><span class="p">.</span><span class="nx">ActiveXObject</span>
|
||||
<span class="k">new</span> <span class="nb">window</span><span class="p">.</span><span class="nx">ActiveXObject</span><span class="p">(</span><span class="s">'Microsoft.XMLHTTP'</span><span class="p">)</span>
|
||||
<span class="k">else</span>
|
||||
<span class="k">new</span> <span class="nx">XMLHttpRequest</span><span class="p">()</span>
|
||||
<span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span> <span class="s">'GET'</span><span class="p">,</span> <span class="nx">url</span><span class="p">,</span> <span class="kc">true</span>
|
||||
<span class="nx">xhr</span><span class="p">.</span><span class="nx">overrideMimeType</span> <span class="s">'text/plain'</span> <span class="k">if</span> <span class="s">'overrideMimeType'</span> <span class="k">of</span> <span class="nx">xhr</span>
|
||||
<span class="nv">xhr.onreadystatechange = </span><span class="nf">-></span>
|
||||
<span class="k">if</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">is</span> <span class="mi">4</span>
|
||||
<span class="k">if</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">status</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">200</span><span class="p">]</span>
|
||||
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">responseText</span><span class="p">,</span> <span class="nx">options</span>
|
||||
<span class="k">else</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Could not load </span><span class="si">#{</span><span class="nx">url</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="nx">callback</span><span class="p">()</span> <span class="k">if</span> <span class="nx">callback</span>
|
||||
<span class="nx">xhr</span><span class="p">.</span><span class="nx">send</span> <span class="kc">null</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>Activate CoffeeScript in the browser by having it compile and evaluate
|
||||
all script tags with a content-type of <code>text/coffeescript</code>.
|
||||
This happens on page load.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">runScripts = </span><span class="nf">-></span>
|
||||
<span class="nv">scripts = </span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span> <span class="s">'script'</span>
|
||||
<span class="nv">coffeetypes = </span><span class="p">[</span><span class="s">'text/coffeescript'</span><span class="p">,</span> <span class="s">'text/literate-coffeescript'</span><span class="p">]</span>
|
||||
<span class="nv">coffees = </span><span class="p">(</span><span class="nx">s</span> <span class="k">for</span> <span class="nx">s</span> <span class="k">in</span> <span class="nx">scripts</span> <span class="k">when</span> <span class="nx">s</span><span class="p">.</span><span class="nx">type</span> <span class="k">in</span> <span class="nx">coffeetypes</span><span class="p">)</span>
|
||||
<span class="nv">index = </span><span class="mi">0</span>
|
||||
<span class="nv">length = </span><span class="nx">coffees</span><span class="p">.</span><span class="nx">length</span>
|
||||
<span class="nx">do</span> <span class="nv">execute = </span><span class="nf">-></span>
|
||||
<span class="nv">script = </span><span class="nx">coffees</span><span class="p">[</span><span class="nx">index</span><span class="o">++</span><span class="p">]</span>
|
||||
<span class="nv">mediatype = </span><span class="nx">script</span><span class="o">?</span><span class="p">.</span><span class="nx">type</span>
|
||||
<span class="k">if</span> <span class="nx">mediatype</span> <span class="k">in</span> <span class="nx">coffeetypes</span>
|
||||
<span class="nv">options = </span><span class="p">{</span><span class="nv">literate: </span><span class="nx">mediatype</span> <span class="o">is</span> <span class="s">'text/literate-coffeescript'</span><span class="p">}</span>
|
||||
<span class="k">if</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span>
|
||||
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">load</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span><span class="p">,</span> <span class="nx">execute</span><span class="p">,</span> <span class="nx">options</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">script</span><span class="p">.</span><span class="nx">innerHTML</span><span class="p">,</span> <span class="nx">options</span>
|
||||
<span class="nx">execute</span><span class="p">()</span>
|
||||
<span class="kc">null</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Listen for window load, both in browsers and in IE.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nb">window</span><span class="p">.</span><span class="nx">addEventListener</span>
|
||||
<span class="nx">addEventListener</span> <span class="s">'DOMContentLoaded'</span><span class="p">,</span> <span class="nx">runScripts</span><span class="p">,</span> <span class="kc">no</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">attachEvent</span> <span class="s">'onload'</span><span class="p">,</span> <span class="nx">runScripts</span>
|
||||
<!DOCTYPE html>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
<html>
|
||||
<head>
|
||||
<title>browser.coffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>browser.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p>This <strong>Browser</strong> compatibility layer extends core CoffeeScript functions
|
||||
to make things work smoothly when compiling code directly in the browser.
|
||||
We add support for loading remote Coffee scripts via <strong>XHR</strong>, and
|
||||
<code>text/coffeescript</code> script tags, source maps via data-URLs, and so on.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
CoffeeScript = require <span class="string">'./coffee-script'</span>
|
||||
CoffeeScript.require = require
|
||||
compile = CoffeeScript.compile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>Use standard JavaScript <code>eval</code> to eval code.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">eval</span></span> = (code, options = {}) ->
|
||||
options.bare ?= <span class="literal">on</span>
|
||||
eval compile code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Running code does not provide access to this scope.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">run</span></span> = (code, options = {}) ->
|
||||
options.bare = <span class="literal">on</span>
|
||||
options.shiftLine = <span class="literal">on</span>
|
||||
Function(compile code, options)()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>If we're not in a browser environment, we're finished with the public API.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="keyword">return</span> <span class="keyword">unless</span> window?</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Include source maps where possible. If we've got a base64 encoder, a
|
||||
JSON serializer, and tools for escaping unicode characters, we're good to go.
|
||||
Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">https://developer.mozilla.org/en-US/docs/DOM/window.btoa</a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> btoa? <span class="keyword">and</span> JSON? <span class="keyword">and</span> unescape? <span class="keyword">and</span> encodeURIComponent?
|
||||
<span class="function"><span class="title">compile</span></span> = (code, options = {}) ->
|
||||
options.sourceMap = <span class="literal">true</span>
|
||||
options.inline = <span class="literal">true</span>
|
||||
{js, v3SourceMap} = CoffeeScript.compile code, options
|
||||
<span class="string">"<span class="subst">#{js}</span>\n//@ sourceMappingURL=data:application/json;base64,<span class="subst">#{btoa unescape encodeURIComponent v3SourceMap}</span>\n//@ sourceURL=coffeescript"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Load a remote script from the current domain via XHR.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">load</span></span> = (url, callback, options = {}) ->
|
||||
options.sourceFiles = [url]
|
||||
xhr = <span class="keyword">if</span> window.ActiveXObject
|
||||
<span class="keyword">new</span> window.ActiveXObject(<span class="string">'Microsoft.XMLHTTP'</span>)
|
||||
<span class="keyword">else</span>
|
||||
<span class="keyword">new</span> window.XMLHttpRequest()
|
||||
xhr.open <span class="string">'GET'</span>, url, <span class="literal">true</span>
|
||||
xhr.overrideMimeType <span class="string">'text/plain'</span> <span class="keyword">if</span> <span class="string">'overrideMimeType'</span> <span class="keyword">of</span> xhr
|
||||
xhr.<span class="function"><span class="title">onreadystatechange</span></span> = ->
|
||||
<span class="keyword">if</span> xhr.readyState <span class="keyword">is</span> <span class="number">4</span>
|
||||
<span class="keyword">if</span> xhr.status <span class="keyword">in</span> [<span class="number">0</span>, <span class="number">200</span>]
|
||||
CoffeeScript.run xhr.responseText, options
|
||||
<span class="keyword">else</span>
|
||||
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Could not load <span class="subst">#{url}</span>"</span>
|
||||
callback() <span class="keyword">if</span> callback
|
||||
xhr.send <span class="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Activate CoffeeScript in the browser by having it compile and evaluate
|
||||
all script tags with a content-type of <code>text/coffeescript</code>.
|
||||
This happens on page load.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">runScripts</span></span> = ->
|
||||
scripts = window.document.getElementsByTagName <span class="string">'script'</span>
|
||||
coffeetypes = [<span class="string">'text/coffeescript'</span>, <span class="string">'text/literate-coffeescript'</span>]
|
||||
coffees = (s <span class="keyword">for</span> s <span class="keyword">in</span> scripts <span class="keyword">when</span> s.type <span class="keyword">in</span> coffeetypes)
|
||||
index = <span class="number">0</span>
|
||||
length = coffees.length
|
||||
<span class="keyword">do</span> <span class="function"><span class="title">execute</span></span> = ->
|
||||
script = coffees[index++]
|
||||
mediatype = script?.type
|
||||
<span class="keyword">if</span> mediatype <span class="keyword">in</span> coffeetypes
|
||||
options = {literate: mediatype <span class="keyword">is</span> <span class="string">'text/literate-coffeescript'</span>}
|
||||
<span class="keyword">if</span> script.src
|
||||
CoffeeScript.load script.src, execute, options
|
||||
<span class="keyword">else</span>
|
||||
options.sourceFiles = [<span class="string">'embedded'</span>]
|
||||
CoffeeScript.run script.innerHTML, options
|
||||
execute()
|
||||
<span class="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Listen for window load, both in decent browsers and in IE.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> window.addEventListener
|
||||
window.addEventListener <span class="string">'DOMContentLoaded'</span>, runScripts, <span class="literal">no</span>
|
||||
<span class="keyword">else</span>
|
||||
window.attachEvent <span class="string">'onload'</span>, runScripts</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,59 +1,338 @@
|
||||
<!DOCTYPE html> <html> <head> <title>cake.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> cake.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p><code>cake</code> is a simplified version of <a href="http://www.gnu.org/software/make/">Make</a>
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>cake.coffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>cake.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p><code>cake</code> is a simplified version of <a href="http://www.gnu.org/software/make/">Make</a>
|
||||
(<a href="http://rake.rubyforge.org/">Rake</a>, <a href="http://github.com/280north/jake">Jake</a>)
|
||||
for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
|
||||
and can call them from the command line, or invoke them from other tasks.</p>
|
||||
and can call them from the command line, or invoke them from other tasks.
|
||||
|
||||
</p>
|
||||
<p>Running <code>cake</code> with no arguments will print out a list of all the tasks in the
|
||||
current directory's Cakefile.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>External dependencies.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s">'fs'</span>
|
||||
<span class="nv">path = </span><span class="nx">require</span> <span class="s">'path'</span>
|
||||
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s">'./helpers'</span>
|
||||
<span class="nv">optparse = </span><span class="nx">require</span> <span class="s">'./optparse'</span>
|
||||
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">'./coffee-script'</span>
|
||||
current directory's Cakefile.
|
||||
</p>
|
||||
|
||||
<span class="nv">existsSync = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">existsSync</span> <span class="o">or</span> <span class="nx">path</span><span class="p">.</span><span class="nx">existsSync</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>Keep track of the list of defined tasks, the accepted options, and so on.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">tasks = </span><span class="p">{}</span>
|
||||
<span class="nv">options = </span><span class="p">{}</span>
|
||||
<span class="nv">switches = </span><span class="p">[]</span>
|
||||
<span class="nv">oparse = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>Mixin the top-level Cake functions for Cakefiles to use directly.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">helpers</span><span class="p">.</span><span class="nx">extend</span> <span class="nx">global</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Define a Cake task with a short name, an optional sentence description,
|
||||
and the function to run as the action itself.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">task: </span><span class="nf">(name, description, action) -></span>
|
||||
<span class="p">[</span><span class="nx">action</span><span class="p">,</span> <span class="nx">description</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">description</span><span class="p">,</span> <span class="nx">action</span><span class="p">]</span> <span class="k">unless</span> <span class="nx">action</span>
|
||||
<span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nx">name</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nx">action</span><span class="p">}</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>Define an option that the Cakefile accepts. The parsed options hash,
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>External dependencies.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
|
||||
path = require <span class="string">'path'</span>
|
||||
helpers = require <span class="string">'./helpers'</span>
|
||||
optparse = require <span class="string">'./optparse'</span>
|
||||
CoffeeScript = require <span class="string">'./coffee-script'</span>
|
||||
|
||||
existsSync = fs.existsSync <span class="keyword">or</span> path.existsSync</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Keep track of the list of defined tasks, the accepted options, and so on.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>tasks = {}
|
||||
options = {}
|
||||
switches = []
|
||||
oparse = <span class="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Mixin the top-level Cake functions for Cakefiles to use directly.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>helpers.extend global,</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Define a Cake task with a short name, an optional sentence description,
|
||||
and the function to run as the action itself.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> task: (name, description, action) ->
|
||||
[action, description] = [description, action] <span class="keyword">unless</span> action
|
||||
tasks[name] = {name, description, action}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Define an option that the Cakefile accepts. The parsed options hash,
|
||||
containing all of the command-line options passed, will be made available
|
||||
as the first argument to the action.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">option: </span><span class="nf">(letter, flag, description) -></span>
|
||||
<span class="nx">switches</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="nx">letter</span><span class="p">,</span> <span class="nx">flag</span><span class="p">,</span> <span class="nx">description</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Invoke another task in the current Cakefile.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">invoke: </span><span class="nf">(name) -></span>
|
||||
<span class="nx">missingTask</span> <span class="nx">name</span> <span class="k">unless</span> <span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
|
||||
<span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">].</span><span class="nx">action</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node's
|
||||
asynchrony may cause tasks to execute in a different order than you'd expect.
|
||||
as the first argument to the action.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> option: (letter, flag, description) ->
|
||||
switches.push [letter, flag, description]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Invoke another task in the current Cakefile.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> invoke: (name) ->
|
||||
missingTask name <span class="keyword">unless</span> tasks[name]
|
||||
tasks[name].action options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node's
|
||||
asynchrony may cause tasks to execute in a different order than you'd expect.
|
||||
If no tasks are passed, print the help screen. Keep a reference to the
|
||||
original directory name, when running Cake tasks from subdirectories.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.run = </span><span class="nf">-></span>
|
||||
<span class="nv">global.__originalDirname = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span> <span class="s">'.'</span>
|
||||
<span class="nx">process</span><span class="p">.</span><span class="nx">chdir</span> <span class="nx">cakefileDirectory</span> <span class="nx">__originalDirname</span>
|
||||
<span class="nv">args = </span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">..]</span>
|
||||
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="s">'Cakefile'</span><span class="p">).</span><span class="nx">toString</span><span class="p">(),</span> <span class="nv">filename: </span><span class="s">'Cakefile'</span>
|
||||
<span class="nv">oparse = </span><span class="k">new</span> <span class="nx">optparse</span><span class="p">.</span><span class="nx">OptionParser</span> <span class="nx">switches</span>
|
||||
<span class="k">return</span> <span class="nx">printTasks</span><span class="p">()</span> <span class="k">unless</span> <span class="nx">args</span><span class="p">.</span><span class="nx">length</span>
|
||||
<span class="k">try</span>
|
||||
<span class="nv">options = </span><span class="nx">oparse</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">args</span><span class="p">)</span>
|
||||
<span class="k">catch</span> <span class="nx">e</span>
|
||||
<span class="k">return</span> <span class="nx">fatalError</span> <span class="s">"</span><span class="si">#{</span><span class="nx">e</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="nx">invoke</span> <span class="nx">arg</span> <span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>Display the list of Cake tasks in a format similar to <code>rake -T</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">printTasks = </span><span class="nf">-></span>
|
||||
<span class="nv">relative = </span><span class="nx">path</span><span class="p">.</span><span class="nx">relative</span> <span class="o">or</span> <span class="nx">path</span><span class="p">.</span><span class="nx">resolve</span>
|
||||
<span class="nv">cakefilePath = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">relative</span><span class="p">(</span><span class="nx">__originalDirname</span><span class="p">,</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()),</span> <span class="s">'Cakefile'</span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">"</span><span class="si">#{</span><span class="nx">cakefilePath</span><span class="si">}</span><span class="s"> defines the following tasks:\n"</span>
|
||||
<span class="k">for</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">task</span> <span class="k">of</span> <span class="nx">tasks</span>
|
||||
<span class="nv">spaces = </span><span class="mi">20</span> <span class="o">-</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span>
|
||||
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">></span> <span class="mi">0</span> <span class="k">then</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">spaces</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s">' '</span><span class="p">)</span> <span class="k">else</span> <span class="s">''</span>
|
||||
<span class="nv">desc = </span><span class="k">if</span> <span class="nx">task</span><span class="p">.</span><span class="nx">description</span> <span class="k">then</span> <span class="s">"</span><span class="err">#</span><span class="s"> </span><span class="si">#{</span><span class="nx">task</span><span class="p">.</span><span class="nx">description</span><span class="si">}</span><span class="s">"</span> <span class="k">else</span> <span class="s">''</span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">"cake </span><span class="si">#{</span><span class="nx">name</span><span class="si">}#{</span><span class="nx">spaces</span><span class="si">}</span><span class="s"> </span><span class="si">#{</span><span class="nx">desc</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">oparse</span><span class="p">.</span><span class="nx">help</span><span class="p">()</span> <span class="k">if</span> <span class="nx">switches</span><span class="p">.</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Print an error and exit when attempting to use an invalid task/option.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fatalError = </span><span class="nf">(message) -></span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="nx">message</span> <span class="o">+</span> <span class="s">'\n'</span>
|
||||
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">'To see a list of all tasks/options, run "cake"'</span>
|
||||
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">1</span>
|
||||
original directory name, when running Cake tasks from subdirectories.
|
||||
</p>
|
||||
|
||||
<span class="nv">missingTask = </span><span class="nf">(task) -></span> <span class="nx">fatalError</span> <span class="s">"No such task: </span><span class="si">#{</span><span class="nx">task</span><span class="si">}</span><span class="s">"</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>When <code>cake</code> is invoked, search in the current and all parent directories
|
||||
to find the relevant Cakefile.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">cakefileDirectory = </span><span class="nf">(dir) -></span>
|
||||
<span class="k">return</span> <span class="nx">dir</span> <span class="k">if</span> <span class="nx">existsSync</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">dir</span><span class="p">,</span> <span class="s">'Cakefile'</span>
|
||||
<span class="nv">parent = </span><span class="nx">path</span><span class="p">.</span><span class="nx">normalize</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">dir</span><span class="p">,</span> <span class="s">'..'</span>
|
||||
<span class="k">return</span> <span class="nx">cakefileDirectory</span> <span class="nx">parent</span> <span class="k">unless</span> <span class="nx">parent</span> <span class="o">is</span> <span class="nx">dir</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Cakefile not found in </span><span class="si">#{</span><span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()</span><span class="si">}</span><span class="s">"</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = ->
|
||||
global.__originalDirname = fs.realpathSync <span class="string">'.'</span>
|
||||
process.chdir cakefileDirectory __originalDirname
|
||||
args = process.argv[<span class="number">2.</span>.]
|
||||
CoffeeScript.run fs.readFileSync(<span class="string">'Cakefile'</span>).toString(), filename: <span class="string">'Cakefile'</span>
|
||||
oparse = <span class="keyword">new</span> optparse.OptionParser switches
|
||||
<span class="keyword">return</span> printTasks() <span class="keyword">unless</span> args.length
|
||||
<span class="keyword">try</span>
|
||||
options = oparse.parse(args)
|
||||
<span class="keyword">catch</span> e
|
||||
<span class="keyword">return</span> fatalError <span class="string">"<span class="subst">#{e}</span>"</span>
|
||||
invoke arg <span class="keyword">for</span> arg <span class="keyword">in</span> options.arguments</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code>
|
||||
</p>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">printTasks</span></span> = ->
|
||||
relative = path.relative <span class="keyword">or</span> path.resolve
|
||||
cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="string">'Cakefile'</span>
|
||||
console.log <span class="string">"<span class="subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
|
||||
<span class="keyword">for</span> name, task <span class="keyword">of</span> tasks
|
||||
spaces = <span class="number">20</span> - name.length
|
||||
spaces = <span class="keyword">if</span> spaces > <span class="number">0</span> <span class="keyword">then</span> Array(spaces + <span class="number">1</span>).join(<span class="string">' '</span>) <span class="keyword">else</span> <span class="string">''</span>
|
||||
desc = <span class="keyword">if</span> task.description <span class="keyword">then</span> <span class="string">"# <span class="subst">#{task.description}</span>"</span> <span class="keyword">else</span> <span class="string">''</span>
|
||||
console.log <span class="string">"cake <span class="subst">#{name}</span><span class="subst">#{spaces}</span> <span class="subst">#{desc}</span>"</span>
|
||||
console.log oparse.help() <span class="keyword">if</span> switches.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Print an error and exit when attempting to use an invalid task/option.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">fatalError</span></span> = (message) ->
|
||||
console.error message + <span class="string">'\n'</span>
|
||||
console.log <span class="string">'To see a list of all tasks/options, run "cake"'</span>
|
||||
process.exit <span class="number">1</span>
|
||||
|
||||
<span class="function"><span class="title">missingTask</span></span> = (task) -> fatalError <span class="string">"No such task: <span class="subst">#{task}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>When <code>cake</code> is invoked, search in the current and all parent directories
|
||||
to find the relevant Cakefile.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">cakefileDirectory</span></span> = (dir) ->
|
||||
<span class="keyword">return</span> dir <span class="keyword">if</span> existsSync path.join dir, <span class="string">'Cakefile'</span>
|
||||
parent = path.normalize path.join dir, <span class="string">'..'</span>
|
||||
<span class="keyword">return</span> cakefileDirectory parent <span class="keyword">unless</span> parent <span class="keyword">is</span> dir
|
||||
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cakefile not found in <span class="subst">#{process.cwd()}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,129 +1,874 @@
|
||||
<!DOCTYPE html> <html> <head> <title>coffee-script.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> coffee-script.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>CoffeeScript can be used both on the server, as a command-line compiler based
|
||||
on Node.js/V8, or to run CoffeeScripts directly in the browser. This module
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>coffee-script.coffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>coffee-script.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p>CoffeeScript can be used both on the server, as a command-line compiler based
|
||||
on Node.js/V8, or to run CoffeeScript directly in the browser. This module
|
||||
contains the main entry functions for tokenizing, parsing, and compiling
|
||||
source CoffeeScript into JavaScript.</p>
|
||||
source CoffeeScript into JavaScript.
|
||||
</p>
|
||||
|
||||
<p>If included on a webpage, it will automatically sniff out, compile, and
|
||||
execute all scripts present in <code>text/coffeescript</code> tags.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s">'fs'</span>
|
||||
<span class="nv">path = </span><span class="nx">require</span> <span class="s">'path'</span>
|
||||
<span class="p">{</span><span class="nx">Lexer</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">'./lexer'</span>
|
||||
<span class="p">{</span><span class="nx">parser</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">'./parser'</span>
|
||||
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s">'./helpers'</span>
|
||||
<span class="nv">vm = </span><span class="nx">require</span> <span class="s">'vm'</span>
|
||||
<span class="nv">sourcemap = </span><span class="nx">require</span> <span class="s">'./sourcemap'</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>Load and run a CoffeeScript file for Node, stripping any <code>BOM</code>s.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">loadFile = </span><span class="nf">(module, filename) -></span>
|
||||
<span class="nv">raw = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span> <span class="nx">filename</span><span class="p">,</span> <span class="s">'utf8'</span>
|
||||
<span class="nv">stripped = </span><span class="k">if</span> <span class="nx">raw</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">is</span> <span class="mh">0xFEFF</span> <span class="k">then</span> <span class="nx">raw</span><span class="p">.</span><span class="nx">substring</span> <span class="mi">1</span> <span class="k">else</span> <span class="nx">raw</span>
|
||||
<span class="nx">module</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">compile</span><span class="p">(</span><span class="nx">stripped</span><span class="p">,</span> <span class="p">{</span><span class="nx">filename</span><span class="p">,</span> <span class="nv">literate: </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">isLiterate</span> <span class="nx">filename</span><span class="p">}),</span> <span class="nx">filename</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
fs = require <span class="string">'fs'</span>
|
||||
vm = require <span class="string">'vm'</span>
|
||||
path = require <span class="string">'path'</span>
|
||||
child_process = require <span class="string">'child_process'</span>
|
||||
{Lexer} = require <span class="string">'./lexer'</span>
|
||||
{parser} = require <span class="string">'./parser'</span>
|
||||
helpers = require <span class="string">'./helpers'</span>
|
||||
SourceMap = require <span class="string">'./sourcemap'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>The current CoffeeScript version number.
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span>
|
||||
<span class="k">for</span> <span class="nx">ext</span> <span class="k">in</span> <span class="p">[</span><span class="s">'.coffee'</span><span class="p">,</span> <span class="s">'.litcoffee'</span><span class="p">,</span> <span class="s">'.md'</span><span class="p">,</span> <span class="s">'.coffee.md'</span><span class="p">]</span>
|
||||
<span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span><span class="p">[</span><span class="nx">ext</span><span class="p">]</span> <span class="o">=</span> <span class="nx">loadFile</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>The current CoffeeScript version number.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.VERSION = </span><span class="s">'1.6.1'</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>Expose helpers for testing.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.helpers = </span><span class="nx">helpers</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.VERSION = <span class="string">'1.6.3'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Expose helpers for testing.
|
||||
</p>
|
||||
|
||||
<p>If <code>options.sourceMap</code> is specified, then <code>options.filename</code> must also be specified.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.helpers = helpers</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
|
||||
|
||||
</p>
|
||||
<p>If <code>options.sourceMap</code> is specified, then <code>options.filename</code> must also be specified. All
|
||||
options that can be passed to <code>SourceMap#generate</code> may also be passed here.
|
||||
|
||||
</p>
|
||||
<p>This returns a javascript string, unless <code>options.sourceMap</code> is passed,
|
||||
in which case this returns a `{js, v3SourceMap, sourceMap}
|
||||
in which case this returns a <code>{js, v3SourceMap, sourceMap}</code>
|
||||
object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for doing programatic
|
||||
lookups.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.compile = compile = </span><span class="nf">(code, options = {}) -></span>
|
||||
<span class="p">{</span><span class="nx">merge</span><span class="p">}</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">helpers</span>
|
||||
<span class="k">try</span>
|
||||
lookups.
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sourceMap</span>
|
||||
<span class="nv">coffeeFile = </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">baseFileName</span> <span class="nx">options</span><span class="p">.</span><span class="nx">filename</span>
|
||||
<span class="nv">jsFile = </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">baseFileName</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">filename</span><span class="p">,</span> <span class="kc">yes</span><span class="p">)</span> <span class="o">+</span> <span class="s">".js"</span>
|
||||
<span class="nv">sourceMap = </span><span class="k">new</span> <span class="nx">sourcemap</span><span class="p">.</span><span class="nx">SourceMap</span><span class="p">()</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.compile = <span class="function"><span class="title">compile</span></span> = (code, options = {}) ->
|
||||
{merge} = helpers
|
||||
|
||||
<span class="nv">fragments = </span><span class="p">(</span><span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)).</span><span class="nx">compileToFragments</span> <span class="nx">options</span>
|
||||
<span class="keyword">if</span> options.sourceMap
|
||||
map = <span class="keyword">new</span> SourceMap
|
||||
|
||||
<span class="nv">currentLine = </span><span class="mi">0</span>
|
||||
<span class="nx">currentLine</span> <span class="o">+=</span> <span class="mi">1</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">header</span>
|
||||
<span class="nx">currentLine</span> <span class="o">+=</span> <span class="mi">1</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sourceMap</span>
|
||||
<span class="nv">currentColumn = </span><span class="mi">0</span>
|
||||
<span class="nv">js = </span><span class="s">""</span>
|
||||
<span class="k">for</span> <span class="nx">fragment</span> <span class="k">in</span> <span class="nx">fragments</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>Update the sourcemap with data from each fragment</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">sourceMap</span>
|
||||
<span class="k">if</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">locationData</span>
|
||||
<span class="nx">sourceMap</span><span class="p">.</span><span class="nx">addMapping</span><span class="p">(</span>
|
||||
<span class="p">[</span><span class="nx">fragment</span><span class="p">.</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_line</span><span class="p">,</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_column</span><span class="p">],</span>
|
||||
<span class="p">[</span><span class="nx">currentLine</span><span class="p">,</span> <span class="nx">currentColumn</span><span class="p">],</span>
|
||||
<span class="p">{</span><span class="nv">noReplace: </span><span class="kc">true</span><span class="p">})</span>
|
||||
<span class="nv">newLines = </span><span class="nx">helpers</span><span class="p">.</span><span class="nx">count</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span><span class="p">,</span> <span class="s">"\n"</span>
|
||||
<span class="nx">currentLine</span> <span class="o">+=</span> <span class="nx">newLines</span>
|
||||
<span class="nv">currentColumn = </span><span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="p">(</span><span class="k">if</span> <span class="nx">newLines</span> <span class="k">then</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span><span class="p">.</span><span class="nx">lastIndexOf</span> <span class="s">"\n"</span> <span class="k">else</span> <span class="mi">0</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Copy the code from each fragment into the final JavaScript.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">js</span> <span class="o">+=</span> <span class="nx">fragment</span><span class="p">.</span><span class="nx">code</span>
|
||||
fragments = parser.parse(lexer.tokenize code, options).compileToFragments options
|
||||
|
||||
<span class="k">catch</span> <span class="nx">err</span>
|
||||
<span class="nv">err.message = </span><span class="s">"In </span><span class="si">#{</span><span class="nx">options</span><span class="p">.</span><span class="nx">filename</span><span class="si">}</span><span class="s">, </span><span class="si">#{</span><span class="nx">err</span><span class="p">.</span><span class="nx">message</span><span class="si">}</span><span class="s">"</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">filename</span>
|
||||
<span class="k">throw</span> <span class="nx">err</span>
|
||||
currentLine = <span class="number">0</span>
|
||||
currentLine += <span class="number">1</span> <span class="keyword">if</span> options.header
|
||||
currentLine += <span class="number">1</span> <span class="keyword">if</span> options.shiftLine
|
||||
currentColumn = <span class="number">0</span>
|
||||
js = <span class="string">""</span>
|
||||
<span class="keyword">for</span> fragment <span class="keyword">in</span> fragments</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Update the sourcemap with data from each fragment
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">header</span>
|
||||
<span class="nv">header = </span><span class="s">"Generated by CoffeeScript </span><span class="si">#{</span><span class="nx">@VERSION</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="nv">js = </span><span class="s">"// </span><span class="si">#{</span><span class="nx">header</span><span class="si">}</span><span class="s">\n</span><span class="si">#{</span><span class="nx">js</span><span class="si">}</span><span class="s">"</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">if</span> options.sourceMap
|
||||
<span class="keyword">if</span> fragment.locationData
|
||||
map.add(
|
||||
[fragment.locationData.first_line, fragment.locationData.first_column]
|
||||
[currentLine, currentColumn]
|
||||
{noReplace: <span class="literal">true</span>})
|
||||
newLines = helpers.count fragment.code, <span class="string">"\n"</span>
|
||||
currentLine += newLines
|
||||
currentColumn = fragment.code.length - (<span class="keyword">if</span> newLines <span class="keyword">then</span> fragment.code.lastIndexOf <span class="string">"\n"</span> <span class="keyword">else</span> <span class="number">0</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Copy the code from each fragment into the final JavaScript.
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sourceMap</span>
|
||||
<span class="nv">answer = </span><span class="p">{</span><span class="nx">js</span><span class="p">}</span>
|
||||
<span class="k">if</span> <span class="nx">sourceMap</span>
|
||||
<span class="nv">answer.sourceMap = </span><span class="nx">sourceMap</span>
|
||||
<span class="nv">answer.v3SourceMap = </span><span class="nx">sourcemap</span><span class="p">.</span><span class="nx">generateV3SourceMap</span> <span class="nx">sourceMap</span><span class="p">,</span> <span class="nx">coffeeFile</span><span class="p">,</span> <span class="nx">jsFile</span>
|
||||
<span class="nx">answer</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">js</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.tokens = </span><span class="nf">(code, options) -></span>
|
||||
<span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>Parse a string of CoffeeScript code or an array of lexed tokens, and
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> js += fragment.code
|
||||
|
||||
<span class="keyword">if</span> options.header
|
||||
header = <span class="string">"Generated by CoffeeScript <span class="subst">#{@VERSION}</span>"</span>
|
||||
js = <span class="string">"// <span class="subst">#{header}</span>\n<span class="subst">#{js}</span>"</span>
|
||||
|
||||
<span class="keyword">if</span> options.sourceMap
|
||||
answer = {js}
|
||||
answer.sourceMap = map
|
||||
answer.v3SourceMap = map.generate(options, code)
|
||||
answer
|
||||
<span class="keyword">else</span>
|
||||
js</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Tokenize a string of CoffeeScript code, and return the array of tokens.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">tokens</span></span> = (code, options) ->
|
||||
lexer.tokenize code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Parse a string of CoffeeScript code or an array of lexed tokens, and
|
||||
return the AST. You can then compile it by calling <code>.compile()</code> on the root,
|
||||
or traverse it by using <code>.traverseChildren()</code> with a callback.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.nodes = </span><span class="nf">(source, options) -></span>
|
||||
<span class="k">if</span> <span class="k">typeof</span> <span class="nx">source</span> <span class="o">is</span> <span class="s">'string'</span>
|
||||
<span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">source</span><span class="p">,</span> <span class="nx">options</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">source</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Compile and execute a string of CoffeeScript (on the server), correctly
|
||||
setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.run = </span><span class="nf">(code, options = {}) -></span>
|
||||
<span class="nv">mainModule = </span><span class="nx">require</span><span class="p">.</span><span class="nx">main</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>Set the filename.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">mainModule.filename = </span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span>
|
||||
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">filename</span> <span class="k">then</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">filename</span><span class="p">)</span> <span class="k">else</span> <span class="s">'.'</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">¶</a> </div> <p>Clear the module cache.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">mainModule</span><span class="p">.</span><span class="nx">moduleCache</span> <span class="o">and=</span> <span class="p">{}</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">¶</a> </div> <p>Assign paths for node_modules loading</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">mainModule.paths = </span><span class="nx">require</span><span class="p">(</span><span class="s">'module'</span><span class="p">).</span><span class="nx">_nodeModulePaths</span> <span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span> <span class="nx">options</span><span class="p">.</span><span class="nx">filename</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">¶</a> </div> <p>Compile.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="o">not</span> <span class="nx">helpers</span><span class="p">.</span><span class="nx">isCoffee</span><span class="p">(</span><span class="nx">mainModule</span><span class="p">.</span><span class="nx">filename</span><span class="p">)</span> <span class="o">or</span> <span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span>
|
||||
<span class="nx">mainModule</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">compile</span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">),</span> <span class="nx">mainModule</span><span class="p">.</span><span class="nx">filename</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">mainModule</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">mainModule</span><span class="p">.</span><span class="nx">filename</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">¶</a> </div> <p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
|
||||
The CoffeeScript REPL uses this to run the input.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.eval = </span><span class="nf">(code, options = {}) -></span>
|
||||
<span class="k">return</span> <span class="k">unless</span> <span class="nv">code = </span><span class="nx">code</span><span class="p">.</span><span class="nx">trim</span><span class="p">()</span>
|
||||
<span class="nv">Script = </span><span class="nx">vm</span><span class="p">.</span><span class="nx">Script</span>
|
||||
<span class="k">if</span> <span class="nx">Script</span>
|
||||
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span><span class="o">?</span>
|
||||
<span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span> <span class="k">instanceof</span> <span class="nx">Script</span><span class="p">.</span><span class="nx">createContext</span><span class="p">().</span><span class="nx">constructor</span>
|
||||
<span class="nv">sandbox = </span><span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">sandbox = </span><span class="nx">Script</span><span class="p">.</span><span class="nx">createContext</span><span class="p">()</span>
|
||||
<span class="nx">sandbox</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span> <span class="k">for</span> <span class="k">own</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span> <span class="k">of</span> <span class="nx">options</span><span class="p">.</span><span class="nx">sandbox</span>
|
||||
<span class="nv">sandbox.global = sandbox.root = sandbox.GLOBAL = </span><span class="nx">sandbox</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">sandbox = </span><span class="nx">global</span>
|
||||
<span class="nv">sandbox.__filename = </span><span class="nx">options</span><span class="p">.</span><span class="nx">filename</span> <span class="o">||</span> <span class="s">'eval'</span>
|
||||
<span class="nv">sandbox.__dirname = </span><span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span> <span class="nx">sandbox</span><span class="p">.</span><span class="nx">__filename</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">¶</a> </div> <p>define module/require only if they chose not to specify their own</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">unless</span> <span class="nx">sandbox</span> <span class="o">isnt</span> <span class="nx">global</span> <span class="o">or</span> <span class="nx">sandbox</span><span class="p">.</span><span class="nx">module</span> <span class="o">or</span> <span class="nx">sandbox</span><span class="p">.</span><span class="nx">require</span>
|
||||
<span class="nv">Module = </span><span class="nx">require</span> <span class="s">'module'</span>
|
||||
<span class="nv">sandbox.module = _module = </span><span class="k">new</span> <span class="nx">Module</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">modulename</span> <span class="o">||</span> <span class="s">'eval'</span><span class="p">)</span>
|
||||
<span class="nv">sandbox.require = _require = </span><span class="nf">(path) -></span> <span class="nx">Module</span><span class="p">.</span><span class="nx">_load</span> <span class="nx">path</span><span class="p">,</span> <span class="nx">_module</span><span class="p">,</span> <span class="kc">true</span>
|
||||
<span class="nv">_module.filename = </span><span class="nx">sandbox</span><span class="p">.</span><span class="nx">__filename</span>
|
||||
<span class="nx">_require</span><span class="p">[</span><span class="nx">r</span><span class="p">]</span> <span class="o">=</span> <span class="nx">require</span><span class="p">[</span><span class="nx">r</span><span class="p">]</span> <span class="k">for</span> <span class="nx">r</span> <span class="k">in</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">getOwnPropertyNames</span> <span class="nx">require</span> <span class="k">when</span> <span class="nx">r</span> <span class="o">isnt</span> <span class="s">'paths'</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">¶</a> </div> <p>use the same hack node currently uses for their own REPL</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_require.paths = _module.paths = </span><span class="nx">Module</span><span class="p">.</span><span class="nx">_nodeModulePaths</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()</span>
|
||||
<span class="nv">_require.resolve = </span><span class="nf">(request) -></span> <span class="nx">Module</span><span class="p">.</span><span class="nx">_resolveFilename</span> <span class="nx">request</span><span class="p">,</span> <span class="nx">_module</span>
|
||||
<span class="nv">o = </span><span class="p">{}</span>
|
||||
<span class="nx">o</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span> <span class="k">for</span> <span class="k">own</span> <span class="nx">k</span><span class="p">,</span> <span class="nx">v</span> <span class="k">of</span> <span class="nx">options</span>
|
||||
<span class="nv">o.bare = </span><span class="kc">on</span> <span class="c1"># ensure return value</span>
|
||||
<span class="nv">js = </span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">o</span>
|
||||
<span class="k">if</span> <span class="nx">sandbox</span> <span class="o">is</span> <span class="nx">global</span>
|
||||
<span class="nx">vm</span><span class="p">.</span><span class="nx">runInThisContext</span> <span class="nx">js</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">vm</span><span class="p">.</span><span class="nx">runInContext</span> <span class="nx">js</span><span class="p">,</span> <span class="nx">sandbox</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">¶</a> </div> <p>Instantiate a Lexer for our use here.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">lexer = </span><span class="k">new</span> <span class="nx">Lexer</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">¶</a> </div> <p>The real Lexer produces a generic stream of tokens. This object provides a
|
||||
or traverse it by using <code>.traverseChildren()</code> with a callback.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">nodes</span></span> = (source, options) ->
|
||||
<span class="keyword">if</span> <span class="keyword">typeof</span> source <span class="keyword">is</span> <span class="string">'string'</span>
|
||||
parser.parse lexer.tokenize source, options
|
||||
<span class="keyword">else</span>
|
||||
parser.parse source</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Compile and execute a string of CoffeeScript (on the server), correctly
|
||||
setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = (code, options = {}) ->
|
||||
mainModule = require.main
|
||||
options.sourceMap ?= <span class="literal">true</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Set the filename.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> mainModule.filename = process.argv[<span class="number">1</span>] =
|
||||
<span class="keyword">if</span> options.filename <span class="keyword">then</span> fs.realpathSync(options.filename) <span class="keyword">else</span> <span class="string">'.'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Clear the module cache.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> mainModule.moduleCache <span class="keyword">and</span>= {}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Assign paths for node_modules loading
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> mainModule.paths = require(<span class="string">'module'</span>)._nodeModulePaths path.dirname fs.realpathSync options.filename <span class="keyword">or</span> <span class="string">'.'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Compile.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="keyword">not</span> helpers.isCoffee(mainModule.filename) <span class="keyword">or</span> require.extensions
|
||||
answer = compile(code, options)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Attach sourceMap object to sourceMaps[options.filename] so that
|
||||
it is accessible by Error.prepareStackTrace.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">do</span> patchStackTrace
|
||||
sourceMaps[mainModule.filename] = answer.sourceMap
|
||||
mainModule._compile answer.js, mainModule.filename
|
||||
<span class="keyword">else</span>
|
||||
mainModule._compile code, mainModule.filename</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
|
||||
The CoffeeScript REPL uses this to run the input.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">eval</span></span> = (code, options = {}) ->
|
||||
<span class="keyword">return</span> <span class="keyword">unless</span> code = code.trim()
|
||||
Script = vm.Script
|
||||
<span class="keyword">if</span> Script
|
||||
<span class="keyword">if</span> options.sandbox?
|
||||
<span class="keyword">if</span> options.sandbox <span class="keyword">instanceof</span> Script.createContext().constructor
|
||||
sandbox = options.sandbox
|
||||
<span class="keyword">else</span>
|
||||
sandbox = Script.createContext()
|
||||
sandbox[k] = v <span class="keyword">for</span> own k, v <span class="keyword">of</span> options.sandbox
|
||||
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
|
||||
<span class="keyword">else</span>
|
||||
sandbox = global
|
||||
sandbox.__filename = options.filename || <span class="string">'eval'</span>
|
||||
sandbox.__dirname = path.dirname sandbox.__filename</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>define module/require only if they chose not to specify their own
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">unless</span> sandbox <span class="keyword">isnt</span> global <span class="keyword">or</span> sandbox.module <span class="keyword">or</span> sandbox.require
|
||||
Module = require <span class="string">'module'</span>
|
||||
sandbox.module = _module = <span class="keyword">new</span> Module(options.modulename || <span class="string">'eval'</span>)
|
||||
sandbox.require = <span class="function"><span class="title">_require</span></span> = (path) -> Module._load path, _module, <span class="literal">true</span>
|
||||
_module.filename = sandbox.__filename
|
||||
_require[r] = require[r] <span class="keyword">for</span> r <span class="keyword">in</span> Object.getOwnPropertyNames require <span class="keyword">when</span> r <span class="keyword">isnt</span> <span class="string">'paths'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>use the same hack node currently uses for their own REPL
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> _require.paths = _module.paths = Module._nodeModulePaths process.cwd()
|
||||
_require.<span class="function"><span class="title">resolve</span></span> = (request) -> Module._resolveFilename request, _module
|
||||
o = {}
|
||||
o[k] = v <span class="keyword">for</span> own k, v <span class="keyword">of</span> options
|
||||
o.bare = <span class="literal">on</span> <span class="comment"># ensure return value</span>
|
||||
js = compile code, o
|
||||
<span class="keyword">if</span> sandbox <span class="keyword">is</span> global
|
||||
vm.runInThisContext js
|
||||
<span class="keyword">else</span>
|
||||
vm.runInContext js, sandbox</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>Load and run a CoffeeScript file for Node, stripping any <code>BOM</code>s.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">loadFile</span></span> = (module, filename) ->
|
||||
raw = fs.readFileSync filename, <span class="string">'utf8'</span>
|
||||
stripped = <span class="keyword">if</span> raw.charCodeAt(<span class="number">0</span>) <span class="keyword">is</span> <span class="number">0xFEFF</span> <span class="keyword">then</span> raw.substring <span class="number">1</span> <span class="keyword">else</span> raw
|
||||
answer = compile(stripped, {filename, sourceMap: <span class="literal">true</span>, literate: helpers.isLiterate filename})
|
||||
sourceMaps[filename] = answer.sourceMap
|
||||
module._compile answer.js, filename</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>If the installed version of Node supports <code>require.extensions</code>, register
|
||||
CoffeeScript as an extension.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> require.extensions
|
||||
<span class="keyword">for</span> ext <span class="keyword">in</span> [<span class="string">'.coffee'</span>, <span class="string">'.litcoffee'</span>, <span class="string">'.coffee.md'</span>]
|
||||
require.extensions[ext] = loadFile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>Patch Node's module loader to be able to handle mult-dot extensions.
|
||||
This is a horrible thing that should not be required. Perhaps, one day,
|
||||
when a truly benevolent dictator comes to rule over the Republik of Node,
|
||||
it won't be.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> Module = require <span class="string">'module'</span>
|
||||
|
||||
<span class="function"><span class="title">findExtension</span></span> = (filename) ->
|
||||
extensions = path.basename(filename).split <span class="string">'.'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Remove the initial dot from dotfiles.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> extensions.shift() <span class="keyword">if</span> extensions[<span class="number">0</span>] <span class="keyword">is</span> <span class="string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Start with the longest possible extension and work our way shortwards.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">while</span> extensions.shift()
|
||||
curExtension = <span class="string">'.'</span> + extensions.join <span class="string">'.'</span>
|
||||
<span class="keyword">return</span> curExtension <span class="keyword">if</span> Module._extensions[curExtension]
|
||||
<span class="string">'.js'</span>
|
||||
|
||||
Module::<span class="function"><span class="title">load</span></span> = (filename) ->
|
||||
<span class="property">@filename</span> = filename
|
||||
<span class="property">@paths</span> = Module._nodeModulePaths path.dirname filename
|
||||
extension = findExtension filename
|
||||
Module._extensions[extension](<span class="keyword">this</span>, filename)
|
||||
<span class="property">@loaded</span> = <span class="literal">true</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>If we're on Node, patch <code>child_process.fork</code> so that Coffee scripts are able
|
||||
to fork both CoffeeScript files, and JavaScript files, directly.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> child_process
|
||||
{fork} = child_process
|
||||
child_process.<span class="function"><span class="title">fork</span></span> = (path, args = [], options = {}) ->
|
||||
execPath = <span class="keyword">if</span> helpers.isCoffee(path) <span class="keyword">then</span> <span class="string">'coffee'</span> <span class="keyword">else</span> <span class="literal">null</span>
|
||||
<span class="keyword">if</span> <span class="keyword">not</span> Array.isArray args
|
||||
args = []
|
||||
options = args <span class="keyword">or</span> {}
|
||||
options.execPath <span class="keyword">or</span>= execPath
|
||||
fork path, args, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Instantiate a Lexer for our use here.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>lexer = <span class="keyword">new</span> Lexer</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
<p>The real Lexer produces a generic stream of tokens. This object provides a
|
||||
thin wrapper around it, compatible with the Jison API. We can then pass it
|
||||
directly as a "Jison lexer".</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">parser.lexer =</span>
|
||||
<span class="nv">lex: </span><span class="nf">-></span>
|
||||
<span class="nv">token = </span><span class="nx">@tokens</span><span class="p">[</span><span class="nx">@pos</span><span class="o">++</span><span class="p">]</span>
|
||||
<span class="k">if</span> <span class="nx">token</span>
|
||||
<span class="p">[</span><span class="nx">tag</span><span class="p">,</span> <span class="nx">@yytext</span><span class="p">,</span> <span class="nx">@yylloc</span><span class="p">]</span> <span class="o">=</span> <span class="nx">token</span>
|
||||
<span class="vi">@yylineno = </span><span class="nx">@yylloc</span><span class="p">.</span><span class="nx">first_line</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">tag = </span><span class="s">''</span>
|
||||
directly as a "Jison lexer".
|
||||
</p>
|
||||
|
||||
<span class="nx">tag</span>
|
||||
<span class="nv">setInput: </span><span class="nf">(@tokens) -></span>
|
||||
<span class="vi">@pos = </span><span class="mi">0</span>
|
||||
<span class="nv">upcomingInput: </span><span class="nf">-></span>
|
||||
<span class="s">""</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.lexer =
|
||||
lex: ->
|
||||
token = <span class="property">@tokens</span>[<span class="property">@pos</span>++]
|
||||
<span class="keyword">if</span> token
|
||||
[tag, <span class="property">@yytext</span>, <span class="property">@yylloc</span>] = token
|
||||
<span class="property">@yylineno</span> = <span class="property">@yylloc</span>.first_line
|
||||
<span class="keyword">else</span>
|
||||
tag = <span class="string">''</span>
|
||||
|
||||
<span class="nv">parser.yy = </span><span class="nx">require</span> <span class="s">'./nodes'</span>
|
||||
tag
|
||||
setInput: (<span class="property">@tokens</span>) ->
|
||||
<span class="property">@pos</span> = <span class="number">0</span>
|
||||
upcomingInput: ->
|
||||
<span class="string">""</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
<p>Make all the AST nodes visible to the parser.
|
||||
</p>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.yy = require <span class="string">'./nodes'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
</div>
|
||||
<p>Override Jison's default error handling function.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.yy.<span class="function"><span class="title">parseError</span></span> = (message, {token}) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-28">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
</div>
|
||||
<p>Disregard Jison's message, it contains redundant line numer information.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> message = <span class="string">"unexpected <span class="subst">#{<span class="keyword">if</span> token <span class="keyword">is</span> <span class="number">1</span> <span class="keyword">then</span> 'end <span class="keyword">of</span> input' <span class="keyword">else</span> token}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-29">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-29">¶</a>
|
||||
</div>
|
||||
<p>The second argument has a <code>loc</code> property, which should have the location
|
||||
data for this token. Unfortunately, Jison seems to send an outdated <code>loc</code>
|
||||
(from the previous token), so we take the location information directly
|
||||
from the lexer.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> helpers.throwSyntaxError message, parser.lexer.yylloc</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-30">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-30">¶</a>
|
||||
</div>
|
||||
<p>Based on <a href="http://goo.gl/ZTx1p">michaelficarra/CoffeeScriptRedux</a>
|
||||
NodeJS / V8 have no support for transforming positions in stack traces using
|
||||
sourceMap, so we must monkey-patch Error to display CoffeeScript source
|
||||
positions.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
patched = <span class="literal">false</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-31">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-31">¶</a>
|
||||
</div>
|
||||
<p>Map of filenames -> sourceMap object.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>sourceMaps = {}
|
||||
|
||||
<span class="function"><span class="title">patchStackTrace</span></span> = ->
|
||||
<span class="keyword">return</span> <span class="keyword">if</span> patched
|
||||
patched = <span class="literal">true</span>
|
||||
mainModule = require.main</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-32">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-32">¶</a>
|
||||
</div>
|
||||
<p>(Assigning to a property of the Module object in the normal module cache is
|
||||
unsuitable, because node deletes those objects from the cache if an
|
||||
exception is thrown in the module body.)
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
Error.<span class="function"><span class="title">prepareStackTrace</span></span> = (err, stack) ->
|
||||
sourceFiles = {}
|
||||
|
||||
<span class="function"><span class="title">getSourceMapping</span></span> = (filename, line, column) ->
|
||||
sourceMap = sourceMaps[filename]
|
||||
answer = sourceMap.sourceLocation [line - <span class="number">1</span>, column - <span class="number">1</span>] <span class="keyword">if</span> sourceMap
|
||||
<span class="keyword">if</span> answer <span class="keyword">then</span> [answer[<span class="number">0</span>] + <span class="number">1</span>, answer[<span class="number">1</span>] + <span class="number">1</span>] <span class="keyword">else</span> <span class="literal">null</span>
|
||||
|
||||
frames = <span class="keyword">for</span> frame <span class="keyword">in</span> stack
|
||||
<span class="keyword">break</span> <span class="keyword">if</span> frame.getFunction() <span class="keyword">is</span> exports.run
|
||||
<span class="string">" at <span class="subst">#{formatSourcePosition frame, getSourceMapping}</span>"</span>
|
||||
|
||||
<span class="string">"<span class="subst">#{err.name}</span>: <span class="subst">#{err.message ? ''}</span>\n<span class="subst">#{frames.join '\n'}</span>\n"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-33">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-33">¶</a>
|
||||
</div>
|
||||
<p>Based on <a href="http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js">http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js</a>
|
||||
Modified to handle sourceMap
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">formatSourcePosition</span></span> = (frame, getSourceMapping) ->
|
||||
fileName = <span class="literal">undefined</span>
|
||||
fileLocation = <span class="string">''</span>
|
||||
|
||||
<span class="keyword">if</span> frame.isNative()
|
||||
fileLocation = <span class="string">"native"</span>
|
||||
<span class="keyword">else</span>
|
||||
<span class="keyword">if</span> frame.isEval()
|
||||
fileName = frame.getScriptNameOrSourceURL()
|
||||
fileLocation = <span class="string">"<span class="subst">#{frame.getEvalOrigin()}</span>, "</span> <span class="keyword">unless</span> fileName
|
||||
<span class="keyword">else</span>
|
||||
fileName = frame.getFileName()
|
||||
|
||||
fileName <span class="keyword">or</span>= <span class="string">"<anonymous>"</span>
|
||||
|
||||
line = frame.getLineNumber()
|
||||
column = frame.getColumnNumber()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-34">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-34">¶</a>
|
||||
</div>
|
||||
<p>Check for a sourceMap position
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> source = getSourceMapping fileName, line, column
|
||||
fileLocation =
|
||||
<span class="keyword">if</span> source
|
||||
<span class="string">"<span class="subst">#{fileName}</span>:<span class="subst">#{source[<span class="number">0</span>]}</span>:<span class="subst">#{source[<span class="number">1</span>]}</span>, <js>:<span class="subst">#{line}</span>:<span class="subst">#{column}</span>"</span>
|
||||
<span class="keyword">else</span>
|
||||
<span class="string">"<span class="subst">#{fileName}</span>:<span class="subst">#{line}</span>:<span class="subst">#{column}</span>"</span>
|
||||
|
||||
|
||||
functionName = frame.getFunctionName()
|
||||
isConstructor = frame.isConstructor()
|
||||
isMethodCall = <span class="keyword">not</span> (frame.isToplevel() <span class="keyword">or</span> isConstructor)
|
||||
|
||||
<span class="keyword">if</span> isMethodCall
|
||||
methodName = frame.getMethodName()
|
||||
typeName = frame.getTypeName()
|
||||
|
||||
<span class="keyword">if</span> functionName
|
||||
tp = as = <span class="string">''</span>
|
||||
<span class="keyword">if</span> typeName <span class="keyword">and</span> functionName.indexOf typeName
|
||||
tp = <span class="string">"<span class="subst">#{typeName}</span>."</span>
|
||||
<span class="keyword">if</span> methodName <span class="keyword">and</span> functionName.indexOf(<span class="string">".<span class="subst">#{methodName}</span>"</span>) <span class="keyword">isnt</span> functionName.length - methodName.length - <span class="number">1</span>
|
||||
as = <span class="string">" [as <span class="subst">#{methodName}</span>]"</span>
|
||||
|
||||
<span class="string">"<span class="subst">#{tp}</span><span class="subst">#{functionName}</span><span class="subst">#{as}</span> (<span class="subst">#{fileLocation}</span>)"</span>
|
||||
<span class="keyword">else</span>
|
||||
<span class="string">"<span class="subst">#{typeName}</span>.<span class="subst">#{methodName <span class="keyword">or</span> '<anonymous>'}</span> (<span class="subst">#{fileLocation}</span>)"</span>
|
||||
<span class="keyword">else</span> <span class="keyword">if</span> isConstructor
|
||||
<span class="string">"new <span class="subst">#{functionName <span class="keyword">or</span> '<anonymous>'}</span> (<span class="subst">#{fileLocation}</span>)"</span>
|
||||
<span class="keyword">else</span> <span class="keyword">if</span> functionName
|
||||
<span class="string">"<span class="subst">#{functionName}</span> (<span class="subst">#{fileLocation}</span>)"</span>
|
||||
<span class="keyword">else</span>
|
||||
fileLocation</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,192 +1,509 @@
|
||||
/*--------------------- Layout and Typography ----------------------------*/
|
||||
/*--------------------- Typography ----------------------------*/
|
||||
|
||||
@font-face {
|
||||
font-family: 'aller-light';
|
||||
src: url('public/fonts/aller-light.eot');
|
||||
src: url('public/fonts/aller-light.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/aller-light.woff') format('woff'),
|
||||
url('public/fonts/aller-light.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'aller-bold';
|
||||
src: url('public/fonts/aller-bold.eot');
|
||||
src: url('public/fonts/aller-bold.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/aller-bold.woff') format('woff'),
|
||||
url('public/fonts/aller-bold.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@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-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/*--------------------- Layout ----------------------------*/
|
||||
html { height: 100%; }
|
||||
body {
|
||||
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
|
||||
font-size: 15px;
|
||||
line-height: 22px;
|
||||
color: #252519;
|
||||
font-family: "aller-light";
|
||||
font-size: 14px;
|
||||
line-height: 18px;
|
||||
color: #30404f;
|
||||
margin: 0; padding: 0;
|
||||
height:100%;
|
||||
}
|
||||
#container { min-height: 100%; }
|
||||
|
||||
a {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
b, strong {
|
||||
font-weight: normal;
|
||||
font-family: "aller-bold";
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 15px 0 0px;
|
||||
}
|
||||
.annotation ul, .annotation ol {
|
||||
margin: 25px 0;
|
||||
}
|
||||
.annotation ul li, .annotation ol li {
|
||||
font-size: 14px;
|
||||
line-height: 18px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: #112233;
|
||||
line-height: 1em;
|
||||
font-weight: normal;
|
||||
font-family: "novecento-bold";
|
||||
text-transform: uppercase;
|
||||
margin: 30px 0 15px 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
background: 1px solid #ddd;
|
||||
height: 1px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
pre, tt, code {
|
||||
font-size: 12px; line-height: 16px;
|
||||
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
a {
|
||||
color: #261a3b;
|
||||
}
|
||||
a:visited {
|
||||
color: #261a3b;
|
||||
.annotation pre {
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 7px 10px;
|
||||
background: #fcfcfc;
|
||||
-moz-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
|
||||
-webkit-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
|
||||
box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
|
||||
overflow-x: auto;
|
||||
}
|
||||
p {
|
||||
margin: 0 0 15px 0;
|
||||
.annotation pre code {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
|
||||
blockquote {
|
||||
border-left: 5px solid #ccc;
|
||||
margin: 0;
|
||||
padding: 1px 0 1px 1em;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin: 0px 0 15px 0;
|
||||
}
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
.sections blockquote p {
|
||||
font-family: Menlo, Consolas, Monaco, monospace;
|
||||
font-size: 12px; line-height: 16px;
|
||||
color: #999;
|
||||
margin: 10px 0 0;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
hr {
|
||||
border: 0 none;
|
||||
border-top: 1px solid #e5e5ee;
|
||||
height: 1px;
|
||||
margin: 20px 0;
|
||||
|
||||
ul.sections {
|
||||
list-style: none;
|
||||
padding:0 0 5px 0;;
|
||||
margin:0;
|
||||
}
|
||||
#container {
|
||||
position: relative;
|
||||
}
|
||||
#background {
|
||||
position: fixed;
|
||||
top: 0; left: 525px; right: 0; bottom: 0;
|
||||
background: #f5f5ff;
|
||||
border-left: 1px solid #e5e5ee;
|
||||
z-index: -1;
|
||||
|
||||
/*
|
||||
Force border-box so that % widths fit the parent
|
||||
container without overlap because of margin/padding.
|
||||
|
||||
More Info : http://www.quirksmode.org/css/box.html
|
||||
*/
|
||||
ul.sections > li > div {
|
||||
-moz-box-sizing: border-box; /* firefox */
|
||||
-ms-box-sizing: border-box; /* ie */
|
||||
-webkit-box-sizing: border-box; /* webkit */
|
||||
-khtml-box-sizing: border-box; /* konqueror */
|
||||
box-sizing: border-box; /* css3 */
|
||||
}
|
||||
|
||||
|
||||
/*---------------------- Jump Page -----------------------------*/
|
||||
#jump_to, #jump_page {
|
||||
margin: 0;
|
||||
background: white;
|
||||
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
|
||||
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
|
||||
font: 10px Arial;
|
||||
text-transform: uppercase;
|
||||
font: 16px Arial;
|
||||
cursor: pointer;
|
||||
text-align: right;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#jump_to a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#jump_to a.large {
|
||||
display: none;
|
||||
}
|
||||
#jump_to a.small {
|
||||
font-size: 22px;
|
||||
font-weight: bold;
|
||||
color: #676767;
|
||||
}
|
||||
|
||||
#jump_to, #jump_wrapper {
|
||||
position: fixed;
|
||||
right: 0; top: 0;
|
||||
padding: 5px 10px;
|
||||
padding: 10px 15px;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
#jump_wrapper {
|
||||
display: none;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
#jump_to:hover #jump_wrapper {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#jump_page {
|
||||
padding: 5px 0 3px;
|
||||
margin: 0 0 25px 25px;
|
||||
}
|
||||
|
||||
#jump_page .source {
|
||||
display: block;
|
||||
padding: 15px;
|
||||
text-decoration: none;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
#jump_page .source:hover {
|
||||
background: #f5f5ff;
|
||||
}
|
||||
|
||||
#jump_page .source:first-child {
|
||||
}
|
||||
|
||||
/*---------------------- Low resolutions (> 320px) ---------------------*/
|
||||
@media only screen and (min-width: 320px) {
|
||||
.pilwrap { display: none; }
|
||||
|
||||
ul.sections > li > div {
|
||||
display: block;
|
||||
padding:5px 10px 0 10px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.content {
|
||||
background: #f5f5ff;
|
||||
overflow-x:auto;
|
||||
-webkit-box-shadow: inset 0 0 5px #e5e5ee;
|
||||
box-shadow: inset 0 0 5px #e5e5ee;
|
||||
border: 1px solid #dedede;
|
||||
margin:5px 10px 5px 10px;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation pre {
|
||||
margin: 7px 0 7px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation p tt, .annotation code {
|
||||
background: #f8f8ff;
|
||||
border: 1px solid #dedede;
|
||||
font-size: 12px;
|
||||
padding: 0 0.2em;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------- (> 481px) ---------------------*/
|
||||
@media only screen and (min-width: 481px) {
|
||||
#container {
|
||||
position: relative;
|
||||
}
|
||||
body {
|
||||
background-color: #F5F5FF;
|
||||
font-size: 15px;
|
||||
line-height: 21px;
|
||||
}
|
||||
pre, tt, code {
|
||||
line-height: 18px;
|
||||
}
|
||||
p, ul, ol {
|
||||
margin: 0 0 15px;
|
||||
}
|
||||
|
||||
|
||||
#jump_to {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
#jump_wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
#jump_to, #jump_page {
|
||||
font: 10px Arial;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
#jump_page .source {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
#jump_to a.large {
|
||||
display: inline-block;
|
||||
}
|
||||
#jump_to a.small {
|
||||
display: none;
|
||||
}
|
||||
#jump_to:hover #jump_wrapper {
|
||||
display: block;
|
||||
}
|
||||
#jump_page {
|
||||
padding: 5px 0 3px;
|
||||
margin: 0 0 25px 25px;
|
||||
}
|
||||
#jump_page .source {
|
||||
display: block;
|
||||
padding: 5px 10px;
|
||||
text-decoration: none;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
#jump_page .source:hover {
|
||||
background: #f5f5ff;
|
||||
}
|
||||
#jump_page .source:first-child {
|
||||
}
|
||||
table td {
|
||||
border: 0;
|
||||
outline: 0;
|
||||
}
|
||||
td.docs, th.docs {
|
||||
max-width: 450px;
|
||||
min-width: 450px;
|
||||
|
||||
|
||||
|
||||
#background {
|
||||
position: absolute;
|
||||
top: 0; bottom: 0;
|
||||
width: 350px;
|
||||
background: #fff;
|
||||
border-right: 1px solid #e5e5ee;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
|
||||
padding-left: 40px;
|
||||
}
|
||||
|
||||
ul.sections > li {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
ul.sections > li > div {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation {
|
||||
max-width: 350px;
|
||||
min-width: 350px;
|
||||
min-height: 5px;
|
||||
padding: 10px 25px 1px 50px;
|
||||
padding: 13px;
|
||||
overflow-x: hidden;
|
||||
white-space: normal;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
}
|
||||
.docs pre {
|
||||
margin: 15px 0 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
.docs p tt, .docs p code {
|
||||
background: #f8f8ff;
|
||||
border: 1px solid #dedede;
|
||||
font-size: 12px;
|
||||
padding: 0 0.2em;
|
||||
}
|
||||
.pilwrap {
|
||||
position: relative;
|
||||
}
|
||||
.pilcrow {
|
||||
font: 12px Arial;
|
||||
text-decoration: none;
|
||||
color: #454545;
|
||||
position: absolute;
|
||||
top: 3px; left: -20px;
|
||||
padding: 1px 2px;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s linear;
|
||||
}
|
||||
td.docs:hover .pilcrow {
|
||||
opacity: 1;
|
||||
}
|
||||
td.code, th.code {
|
||||
padding: 14px 15px 16px 25px;
|
||||
width: 100%;
|
||||
ul.sections > li > div.annotation pre {
|
||||
margin: 15px 0 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.content {
|
||||
padding: 13px;
|
||||
vertical-align: top;
|
||||
background: #f5f5ff;
|
||||
border-left: 1px solid #e5e5ee;
|
||||
border: none;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
pre, tt, code {
|
||||
font-size: 12px; line-height: 18px;
|
||||
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
|
||||
margin: 0; padding: 0;
|
||||
|
||||
.pilwrap {
|
||||
position: relative;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.pilcrow {
|
||||
font: 12px Arial;
|
||||
text-decoration: none;
|
||||
color: #454545;
|
||||
position: absolute;
|
||||
top: 3px; left: -20px;
|
||||
padding: 1px 2px;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s linear;
|
||||
}
|
||||
.for-h1 .pilcrow {
|
||||
top: 47px;
|
||||
}
|
||||
.for-h2 .pilcrow, .for-h3 .pilcrow, .for-h4 .pilcrow {
|
||||
top: 35px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation:hover .pilcrow {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------- (> 1025px) ---------------------*/
|
||||
@media only screen and (min-width: 1025px) {
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
|
||||
#background {
|
||||
width: 525px;
|
||||
}
|
||||
ul.sections > li > div.annotation {
|
||||
max-width: 525px;
|
||||
min-width: 525px;
|
||||
padding: 10px 25px 1px 50px;
|
||||
}
|
||||
ul.sections > li > div.content {
|
||||
padding: 9px 15px 16px 25px;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------- Syntax Highlighting -----------------------------*/
|
||||
|
||||
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
|
||||
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
|
||||
body .hll { background-color: #ffffcc }
|
||||
body .c { color: #408080; font-style: italic } /* Comment */
|
||||
body .err { border: 1px solid #FF0000 } /* Error */
|
||||
body .k { color: #954121 } /* Keyword */
|
||||
body .o { color: #666666 } /* Operator */
|
||||
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
|
||||
body .cp { color: #BC7A00 } /* Comment.Preproc */
|
||||
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
|
||||
body .cs { color: #408080; font-style: italic } /* Comment.Special */
|
||||
body .gd { color: #A00000 } /* Generic.Deleted */
|
||||
body .ge { font-style: italic } /* Generic.Emph */
|
||||
body .gr { color: #FF0000 } /* Generic.Error */
|
||||
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
body .gi { color: #00A000 } /* Generic.Inserted */
|
||||
body .go { color: #808080 } /* Generic.Output */
|
||||
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
||||
body .gs { font-weight: bold } /* Generic.Strong */
|
||||
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
body .gt { color: #0040D0 } /* Generic.Traceback */
|
||||
body .kc { color: #954121 } /* Keyword.Constant */
|
||||
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
|
||||
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
|
||||
body .kp { color: #954121 } /* Keyword.Pseudo */
|
||||
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
|
||||
body .kt { color: #B00040 } /* Keyword.Type */
|
||||
body .m { color: #666666 } /* Literal.Number */
|
||||
body .s { color: #219161 } /* Literal.String */
|
||||
body .na { color: #7D9029 } /* Name.Attribute */
|
||||
body .nb { color: #954121 } /* Name.Builtin */
|
||||
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
||||
body .no { color: #880000 } /* Name.Constant */
|
||||
body .nd { color: #AA22FF } /* Name.Decorator */
|
||||
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
||||
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
|
||||
body .nf { color: #0000FF } /* Name.Function */
|
||||
body .nl { color: #A0A000 } /* Name.Label */
|
||||
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
||||
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
|
||||
body .nv { color: #19469D } /* Name.Variable */
|
||||
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
||||
body .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
body .mf { color: #666666 } /* Literal.Number.Float */
|
||||
body .mh { color: #666666 } /* Literal.Number.Hex */
|
||||
body .mi { color: #666666 } /* Literal.Number.Integer */
|
||||
body .mo { color: #666666 } /* Literal.Number.Oct */
|
||||
body .sb { color: #219161 } /* Literal.String.Backtick */
|
||||
body .sc { color: #219161 } /* Literal.String.Char */
|
||||
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
|
||||
body .s2 { color: #219161 } /* Literal.String.Double */
|
||||
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
|
||||
body .sh { color: #219161 } /* Literal.String.Heredoc */
|
||||
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
|
||||
body .sx { color: #954121 } /* Literal.String.Other */
|
||||
body .sr { color: #BB6688 } /* Literal.String.Regex */
|
||||
body .s1 { color: #219161 } /* Literal.String.Single */
|
||||
body .ss { color: #19469D } /* Literal.String.Symbol */
|
||||
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
|
||||
body .vc { color: #19469D } /* Name.Variable.Class */
|
||||
body .vg { color: #19469D } /* Name.Variable.Global */
|
||||
body .vi { color: #19469D } /* Name.Variable.Instance */
|
||||
body .il { color: #666666 } /* Literal.Number.Integer.Long */
|
||||
/*
|
||||
|
||||
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
|
||||
|
||||
*/
|
||||
|
||||
pre code {
|
||||
display: block; padding: 0.5em;
|
||||
color: #000;
|
||||
background: #f8f8ff
|
||||
}
|
||||
|
||||
pre .comment,
|
||||
pre .template_comment,
|
||||
pre .diff .header,
|
||||
pre .javadoc {
|
||||
color: #408080;
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
pre .keyword,
|
||||
pre .assignment,
|
||||
pre .literal,
|
||||
pre .css .rule .keyword,
|
||||
pre .winutils,
|
||||
pre .javascript .title,
|
||||
pre .lisp .title,
|
||||
pre .subst,
|
||||
pre .reserved {
|
||||
color: #954121;
|
||||
/*font-weight: bold*/
|
||||
}
|
||||
|
||||
pre .number,
|
||||
pre .hexcolor {
|
||||
color: #40a070
|
||||
}
|
||||
|
||||
pre .string,
|
||||
pre .tag .value,
|
||||
pre .phpdoc,
|
||||
pre .tex .formula {
|
||||
color: #219161;
|
||||
}
|
||||
|
||||
pre .title,
|
||||
pre .id {
|
||||
color: #19469D;
|
||||
}
|
||||
pre .params {
|
||||
color: #00F;
|
||||
}
|
||||
|
||||
pre .javascript .title,
|
||||
pre .lisp .title,
|
||||
pre .subst {
|
||||
font-weight: normal
|
||||
}
|
||||
|
||||
pre .class .title,
|
||||
pre .haskell .label,
|
||||
pre .tex .command {
|
||||
color: #458;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
pre .tag,
|
||||
pre .tag .title,
|
||||
pre .rules .property,
|
||||
pre .django .tag .keyword {
|
||||
color: #000080;
|
||||
font-weight: normal
|
||||
}
|
||||
|
||||
pre .attribute,
|
||||
pre .variable,
|
||||
pre .instancevar,
|
||||
pre .lisp .body {
|
||||
color: #008080
|
||||
}
|
||||
|
||||
pre .regexp {
|
||||
color: #B68
|
||||
}
|
||||
|
||||
pre .class {
|
||||
color: #458;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
pre .symbol,
|
||||
pre .ruby .symbol .string,
|
||||
pre .ruby .symbol .keyword,
|
||||
pre .ruby .symbol .keymethods,
|
||||
pre .lisp .keyword,
|
||||
pre .tex .special,
|
||||
pre .input_number {
|
||||
color: #990073
|
||||
}
|
||||
|
||||
pre .builtin,
|
||||
pre .constructor,
|
||||
pre .built_in,
|
||||
pre .lisp .title {
|
||||
color: #0086b3
|
||||
}
|
||||
|
||||
pre .preprocessor,
|
||||
pre .pi,
|
||||
pre .doctype,
|
||||
pre .shebang,
|
||||
pre .cdata {
|
||||
color: #999;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
pre .deletion {
|
||||
background: #fdd
|
||||
}
|
||||
|
||||
pre .addition {
|
||||
background: #dfd
|
||||
}
|
||||
|
||||
pre .diff .change {
|
||||
background: #0086b3
|
||||
}
|
||||
|
||||
pre .chunk {
|
||||
color: #aaa
|
||||
}
|
||||
|
||||
pre .tex .formula {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,63 +1,595 @@
|
||||
<!DOCTYPE html> <html> <head> <title>helpers.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> helpers.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>This file contains the common helper functions that we'd like to share among
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>helpers.coffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>helpers.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p>This file contains the common helper functions that we'd like to share among
|
||||
the <strong>Lexer</strong>, <strong>Rewriter</strong>, and the <strong>Nodes</strong>. Merge objects, flatten
|
||||
arrays, count characters, that sort of thing.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>Peek at the beginning of a given string to see if it matches a sequence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.starts = </span><span class="nf">(string, literal, start) -></span>
|
||||
<span class="nx">literal</span> <span class="o">is</span> <span class="nx">string</span><span class="p">.</span><span class="nx">substr</span> <span class="nx">start</span><span class="p">,</span> <span class="nx">literal</span><span class="p">.</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>Peek at the end of a given string to see if it matches a sequence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ends = </span><span class="nf">(string, literal, back) -></span>
|
||||
<span class="nv">len = </span><span class="nx">literal</span><span class="p">.</span><span class="nx">length</span>
|
||||
<span class="nx">literal</span> <span class="o">is</span> <span class="nx">string</span><span class="p">.</span><span class="nx">substr</span> <span class="nx">string</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="nx">len</span> <span class="o">-</span> <span class="p">(</span><span class="nx">back</span> <span class="o">or</span> <span class="mi">0</span><span class="p">),</span> <span class="nx">len</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>Trim out all falsy values from an array.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.compact = </span><span class="nf">(array) -></span>
|
||||
<span class="nx">item</span> <span class="k">for</span> <span class="nx">item</span> <span class="k">in</span> <span class="nx">array</span> <span class="k">when</span> <span class="nx">item</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Count the number of occurrences of a string in a string.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.count = </span><span class="nf">(string, substr) -></span>
|
||||
<span class="nv">num = pos = </span><span class="mi">0</span>
|
||||
<span class="k">return</span> <span class="mi">1</span><span class="o">/</span><span class="mi">0</span> <span class="k">unless</span> <span class="nx">substr</span><span class="p">.</span><span class="nx">length</span>
|
||||
<span class="nx">num</span><span class="o">++</span> <span class="k">while</span> <span class="nv">pos = </span><span class="mi">1</span> <span class="o">+</span> <span class="nx">string</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">substr</span><span class="p">,</span> <span class="nx">pos</span>
|
||||
<span class="nx">num</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>Merge objects, returning a fresh copy with attributes from both sides.
|
||||
arrays, count characters, that sort of thing.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>Peek at the beginning of a given string to see if it matches a sequence.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">starts</span></span> = (string, literal, start) ->
|
||||
literal <span class="keyword">is</span> string.substr start, literal.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Peek at the end of a given string to see if it matches a sequence.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">ends</span></span> = (string, literal, back) ->
|
||||
len = literal.length
|
||||
literal <span class="keyword">is</span> string.substr string.length - len - (back <span class="keyword">or</span> <span class="number">0</span>), len</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Repeat a string <code>n</code> times.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.repeat = <span class="function"><span class="title">repeat</span></span> = (str, n) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Use clever algorithm to have O(log(n)) string concatenation operations.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> res = <span class="string">''</span>
|
||||
<span class="keyword">while</span> n > <span class="number">0</span>
|
||||
res += str <span class="keyword">if</span> n & <span class="number">1</span>
|
||||
n >>>= <span class="number">1</span>
|
||||
str += str
|
||||
res</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Trim out all falsy values from an array.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">compact</span></span> = (array) ->
|
||||
item <span class="keyword">for</span> item <span class="keyword">in</span> array <span class="keyword">when</span> item</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Count the number of occurrences of a string in a string.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">count</span></span> = (string, substr) ->
|
||||
num = pos = <span class="number">0</span>
|
||||
<span class="keyword">return</span> <span class="number">1</span>/<span class="number">0</span> <span class="keyword">unless</span> substr.length
|
||||
num++ <span class="keyword">while</span> pos = <span class="number">1</span> + string.indexOf substr, pos
|
||||
num</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Merge objects, returning a fresh copy with attributes from both sides.
|
||||
Used every time <code>Base#compile</code> is called, to allow properties in the
|
||||
options hash to propagate down the tree without polluting other branches.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.merge = </span><span class="nf">(options, overrides) -></span>
|
||||
<span class="nx">extend</span> <span class="p">(</span><span class="nx">extend</span> <span class="p">{},</span> <span class="nx">options</span><span class="p">),</span> <span class="nx">overrides</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Extend a source object with the properties of another object (shallow copy).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">extend = exports.extend = </span><span class="nf">(object, properties) -></span>
|
||||
<span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">properties</span>
|
||||
<span class="nx">object</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span>
|
||||
<span class="nx">object</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>Return a flattened version of an array.
|
||||
Handy for getting a list of <code>children</code> from the nodes.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.flatten = flatten = </span><span class="nf">(array) -></span>
|
||||
<span class="nv">flattened = </span><span class="p">[]</span>
|
||||
<span class="k">for</span> <span class="nx">element</span> <span class="k">in</span> <span class="nx">array</span>
|
||||
<span class="k">if</span> <span class="nx">element</span> <span class="k">instanceof</span> <span class="nb">Array</span>
|
||||
<span class="nv">flattened = </span><span class="nx">flattened</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">flatten</span> <span class="nx">element</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">flattened</span><span class="p">.</span><span class="nx">push</span> <span class="nx">element</span>
|
||||
<span class="nx">flattened</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>Delete a key from an object, returning the value. Useful when a node is
|
||||
looking for a particular method in an options hash.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.del = </span><span class="nf">(obj, key) -></span>
|
||||
<span class="nv">val = </span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span>
|
||||
<span class="k">delete</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span>
|
||||
<span class="nx">val</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Gets the last item of an array(-like) object.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.last = </span><span class="nf">(array, back) -></span> <span class="nx">array</span><span class="p">[</span><span class="nx">array</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="p">(</span><span class="nx">back</span> <span class="o">or</span> <span class="mi">0</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>Typical Array::some</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.some = </span><span class="nb">Array</span><span class="o">::</span><span class="nx">some</span> <span class="o">?</span> <span class="nf">(fn) -></span>
|
||||
<span class="k">return</span> <span class="kc">true</span> <span class="k">for</span> <span class="nx">e</span> <span class="k">in</span> <span class="k">this</span> <span class="k">when</span> <span class="nx">fn</span> <span class="nx">e</span>
|
||||
<span class="kc">false</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">¶</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> </td> <td class="code"> <div class="highlight"><pre><span class="nv">buildLocationData = </span><span class="nf">(first, last) -></span>
|
||||
<span class="k">if</span> <span class="o">not</span> <span class="nx">last</span>
|
||||
<span class="nx">first</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">first_line: </span><span class="nx">first</span><span class="p">.</span><span class="nx">first_line</span>
|
||||
<span class="nv">first_column: </span><span class="nx">first</span><span class="p">.</span><span class="nx">first_column</span>
|
||||
<span class="nv">last_line: </span><span class="nx">last</span><span class="p">.</span><span class="nx">last_line</span>
|
||||
<span class="nv">last_column: </span><span class="nx">last</span><span class="p">.</span><span class="nx">last_column</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">¶</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. The object is returned either way.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.addLocationDataFn = </span><span class="nf">(first, last) -></span>
|
||||
<span class="nf">(obj) -></span>
|
||||
<span class="k">if</span> <span class="p">((</span><span class="k">typeof</span> <span class="nx">obj</span><span class="p">)</span> <span class="o">is</span> <span class="s">'object'</span><span class="p">)</span> <span class="o">and</span> <span class="p">(</span><span class="o">!!</span><span class="nx">obj</span><span class="p">[</span><span class="s">'updateLocationDataIfMissing'</span><span class="p">])</span>
|
||||
<span class="nx">obj</span><span class="p">.</span><span class="nx">updateLocationDataIfMissing</span> <span class="nx">buildLocationData</span><span class="p">(</span><span class="nx">first</span><span class="p">,</span> <span class="nx">last</span><span class="p">)</span>
|
||||
options hash to propagate down the tree without polluting other branches.
|
||||
</p>
|
||||
|
||||
<span class="k">return</span> <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">¶</a> </div> <p>Convert jison location data to a string.
|
||||
<code>obj</code> can be a token, or a locationData.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.locationDataToString = </span><span class="nf">(obj) -></span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="s">"2"</span> <span class="k">of</span> <span class="nx">obj</span><span class="p">)</span> <span class="o">and</span> <span class="p">(</span><span class="s">"first_line"</span> <span class="k">of</span> <span class="nx">obj</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="k">then</span> <span class="nv">locationData = </span><span class="nx">obj</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
|
||||
<span class="k">else</span> <span class="k">if</span> <span class="s">"first_line"</span> <span class="k">of</span> <span class="nx">obj</span> <span class="k">then</span> <span class="nv">locationData = </span><span class="nx">obj</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">merge</span></span> = (options, overrides) ->
|
||||
extend (extend {}, options), overrides</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Extend a source object with the properties of another object (shallow copy).
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="nx">locationData</span>
|
||||
<span class="s">"</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_line</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">:</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">first_column</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">-"</span> <span class="o">+</span>
|
||||
<span class="s">"</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">last_line</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">:</span><span class="si">#{</span><span class="nx">locationData</span><span class="p">.</span><span class="nx">last_column</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="k">else</span>
|
||||
<span class="s">"No location data"</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">¶</a> </div> <p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.baseFileName = </span><span class="nf">(file, stripExt = no) -></span>
|
||||
<span class="nv">parts = </span><span class="nx">file</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">'/'</span><span class="p">)</span>
|
||||
<span class="nv">file = </span><span class="nx">parts</span><span class="p">[</span><span class="nx">parts</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span>
|
||||
<span class="k">return</span> <span class="nx">file</span> <span class="k">unless</span> <span class="nx">stripExt</span>
|
||||
<span class="nv">parts = </span><span class="nx">file</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">'.'</span><span class="p">)</span>
|
||||
<span class="nx">parts</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
|
||||
<span class="nx">parts</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span> <span class="k">if</span> <span class="nx">parts</span><span class="p">[</span><span class="nx">parts</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">is</span> <span class="s">'coffee'</span>
|
||||
<span class="nx">parts</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">'.'</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">¶</a> </div> <p>Determine if a filename represents a CoffeeScript file.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.isCoffee = </span><span class="nf">(file) -></span> <span class="o">/</span><span class="err">\</span><span class="p">.((</span><span class="nx">lit</span><span class="p">)</span><span class="o">?</span><span class="nx">coffee</span><span class="o">|</span><span class="nx">coffee</span><span class="err">\</span><span class="p">.</span><span class="nx">md</span><span class="p">)</span><span class="nx">$</span><span class="o">/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">file</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">¶</a> </div> <p>Determine if a filename represents a Literate CoffeeScript file.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.isLiterate = </span><span class="nf">(file) -></span> <span class="o">/</span><span class="err">\</span><span class="p">.(</span><span class="nx">litcoffee</span><span class="o">|</span><span class="nx">coffee</span><span class="err">\</span><span class="p">.</span><span class="nx">md</span><span class="p">)</span><span class="nx">$</span><span class="o">/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">file</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>extend = exports.<span class="function"><span class="title">extend</span></span> = (object, properties) ->
|
||||
<span class="keyword">for</span> key, val <span class="keyword">of</span> properties
|
||||
object[key] = val
|
||||
object</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Return a flattened version of an array.
|
||||
Handy for getting a list of <code>children</code> from the nodes.
|
||||
</p>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.flatten = <span class="function"><span class="title">flatten</span></span> = (array) ->
|
||||
flattened = []
|
||||
<span class="keyword">for</span> element <span class="keyword">in</span> array
|
||||
<span class="keyword">if</span> element <span class="keyword">instanceof</span> Array
|
||||
flattened = flattened.concat flatten element
|
||||
<span class="keyword">else</span>
|
||||
flattened.push element
|
||||
flattened</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Delete a key from an object, returning the value. Useful when a node is
|
||||
looking for a particular method in an options hash.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">del</span></span> = (obj, key) ->
|
||||
val = obj[key]
|
||||
<span class="keyword">delete</span> obj[key]
|
||||
val</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Gets the last item of an array(-like) object.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.last = <span class="function"><span class="title">last</span></span> = (array, back) -> array[array.length - (back <span class="keyword">or</span> <span class="number">0</span>) - <span class="number">1</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<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 = Array::some ? (fn) ->
|
||||
<span class="keyword">return</span> <span class="literal">true</span> <span class="keyword">for</span> e <span class="keyword">in</span> <span class="keyword">this</span> <span class="keyword">when</span> fn e
|
||||
<span class="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.<span class="function"><span class="title">invertLiterate</span></span> = (code) ->
|
||||
maybe_code = <span class="literal">true</span>
|
||||
lines = <span class="keyword">for</span> line <span class="keyword">in</span> code.split(<span class="string">'\n'</span>)
|
||||
<span class="keyword">if</span> maybe_code <span class="keyword">and</span> <span class="regexp">/^([ ]{4}|[ ]{0,3}\t)/</span>.test line
|
||||
line
|
||||
<span class="keyword">else</span> <span class="keyword">if</span> maybe_code = <span class="regexp">/^\s*$/</span>.test line
|
||||
line
|
||||
<span class="keyword">else</span>
|
||||
<span class="string">'# '</span> + line
|
||||
lines.join <span class="string">'\n'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</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>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildLocationData</span></span> = (first, last) ->
|
||||
<span class="keyword">if</span> <span class="keyword">not</span> last
|
||||
first
|
||||
<span class="keyword">else</span>
|
||||
first_line: first.first_line
|
||||
first_column: first.first_column
|
||||
last_line: last.last_line
|
||||
last_column: last.last_column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</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.
|
||||
The object is returned either way.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">addLocationDataFn</span></span> = (first, last) ->
|
||||
(obj) ->
|
||||
<span class="keyword">if</span> ((<span class="keyword">typeof</span> obj) <span class="keyword">is</span> <span class="string">'object'</span>) <span class="keyword">and</span> (!!obj[<span class="string">'updateLocationDataIfMissing'</span>])
|
||||
obj.updateLocationDataIfMissing buildLocationData(first, last)
|
||||
|
||||
<span class="keyword">return</span> obj</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</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.<span class="function"><span class="title">locationDataToString</span></span> = (obj) ->
|
||||
<span class="keyword">if</span> (<span class="string">"2"</span> <span class="keyword">of</span> obj) <span class="keyword">and</span> (<span class="string">"first_line"</span> <span class="keyword">of</span> obj[<span class="number">2</span>]) <span class="keyword">then</span> locationData = obj[<span class="number">2</span>]
|
||||
<span class="keyword">else</span> <span class="keyword">if</span> <span class="string">"first_line"</span> <span class="keyword">of</span> obj <span class="keyword">then</span> locationData = obj
|
||||
|
||||
<span class="keyword">if</span> locationData
|
||||
<span class="string">"<span class="subst">#{locationData.first_line + <span class="number">1</span>}</span>:<span class="subst">#{locationData.first_column + <span class="number">1</span>}</span>-"</span> +
|
||||
<span class="string">"<span class="subst">#{locationData.last_line + <span class="number">1</span>}</span>:<span class="subst">#{locationData.last_column + <span class="number">1</span>}</span>"</span>
|
||||
<span class="keyword">else</span>
|
||||
<span class="string">"No location data"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</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.<span class="function"><span class="title">baseFileName</span></span> = (file, stripExt = <span class="literal">no</span>, useWinPathSep = <span class="literal">no</span>) ->
|
||||
pathSep = <span class="keyword">if</span> useWinPathSep <span class="keyword">then</span> <span class="regexp">/\\|\// else /\//</span>
|
||||
parts = file.split(pathSep)
|
||||
file = parts[parts.length - <span class="number">1</span>]
|
||||
<span class="keyword">return</span> file <span class="keyword">unless</span> stripExt
|
||||
parts = file.split(<span class="string">'.'</span>)
|
||||
parts.pop()
|
||||
parts.pop() <span class="keyword">if</span> parts[parts.length - <span class="number">1</span>] <span class="keyword">is</span> <span class="string">'coffee'</span> <span class="keyword">and</span> parts.length > <span class="number">1</span>
|
||||
parts.join(<span class="string">'.'</span>)</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>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">isCoffee</span></span> = (file) -> <span class="regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a Literate CoffeeScript file.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">isLiterate</span></span> = (file) -> <span class="regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Throws a SyntaxError with a source file location data attached to it in a
|
||||
property called <code>location</code>.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">throwSyntaxError</span></span> = (message, location) ->
|
||||
location.last_line ?= location.first_line
|
||||
location.last_column ?= location.first_column
|
||||
error = <span class="keyword">new</span> SyntaxError message
|
||||
error.location = location
|
||||
<span class="keyword">throw</span> error</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<p>Creates a nice error message like, following the "standard" format
|
||||
</p>
|
||||
<p><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.<span class="function"><span class="title">prettyErrorMessage</span></span> = (error, fileName, code, useColors) ->
|
||||
<span class="keyword">return</span> error.stack <span class="keyword">or</span> <span class="string">"<span class="subst">#{error}</span>"</span> <span class="keyword">unless</span> error.location
|
||||
|
||||
{first_line, first_column, last_line, last_column} = error.location
|
||||
codeLine = code.split(<span class="string">'\n'</span>)[first_line]
|
||||
start = first_column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>Show only the first line on multi-line errors.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> end = <span class="keyword">if</span> first_line <span class="keyword">is</span> last_line <span class="keyword">then</span> last_column + <span class="number">1</span> <span class="keyword">else</span> codeLine.length
|
||||
marker = repeat(<span class="string">' '</span>, start) + repeat(<span class="string">'^'</span>, end - start)
|
||||
|
||||
<span class="keyword">if</span> useColors
|
||||
<span class="function"><span class="title">colorize</span></span> = (str) -> <span class="string">"\x1B[1;31m<span class="subst">#{str}</span>\x1B[0m"</span>
|
||||
codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
|
||||
marker = colorize marker
|
||||
|
||||
message = <span class="string">"""
|
||||
<span class="subst">#{fileName}</span>:<span class="subst">#{first_line + <span class="number">1</span>}</span>:<span class="subst">#{first_column + <span class="number">1</span>}</span>: error: <span class="subst">#{error.message}</span>
|
||||
<span class="subst">#{codeLine}</span>
|
||||
<span class="subst">#{marker}</span>
|
||||
"""</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Uncomment to add stacktrace.
|
||||
message += "\n#{error.stack}"
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
message</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,3 +1,123 @@
|
||||
<!DOCTYPE html> <html> <head> <title>index.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> index.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>Loader for CoffeeScript as a Node.js library.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">require</span> <span class="s">'./coffee-script'</span>
|
||||
<!DOCTYPE html>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
<html>
|
||||
<head>
|
||||
<title>index.coffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>index.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p>Loader for CoffeeScript as a Node.js library.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports[key] = val <span class="keyword">for</span> key, val <span class="keyword">of</span> require <span class="string">'./coffee-script'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -1,87 +1,372 @@
|
||||
<!DOCTYPE html> <html> <head> <title>optparse.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> optparse.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>A simple <strong>OptionParser</strong> class to parse option flags from the command-line.
|
||||
Use it like so:</p>
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>optparse.coffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>optparse.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>{repeat} = require <span class="string">'./helpers'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>A simple <strong>OptionParser</strong> class to parse option flags from the command-line.
|
||||
Use it like so:
|
||||
|
||||
</p>
|
||||
<pre><code>parser = new OptionParser switches, helpBanner
|
||||
options = parser.parse process.argv
|
||||
</code></pre>
|
||||
|
||||
options = parser.parse process.argv</code></pre>
|
||||
<p>The first non-option is considered to be the start of the file (and file
|
||||
option) list, and all subsequent arguments are left unparsed.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.OptionParser = </span><span class="k">class</span> <span class="nx">OptionParser</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>Initialize with a list of valid options, in the form:</p>
|
||||
option) list, and all subsequent arguments are left unparsed.
|
||||
</p>
|
||||
|
||||
<pre><code>[short-flag, long-flag, description]
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.OptionParser = <span class="class"><span class="keyword">class</span> <span class="title">OptionParser</span></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Initialize with a list of valid options, in the form:
|
||||
|
||||
<p>Along with an an optional banner for the usage help.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(rules, @banner) -></span>
|
||||
<span class="vi">@rules = </span><span class="nx">buildRules</span> <span class="nx">rules</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>Parse the list of arguments, populating an <code>options</code> object with all of the
|
||||
</p>
|
||||
<pre><code>[short-flag, long-flag, description]</code></pre>
|
||||
<p>Along with an an optional banner for the usage help.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> constructor: (rules, <span class="property">@banner</span>) ->
|
||||
<span class="property">@rules</span> = buildRules rules</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Parse the list of arguments, populating an <code>options</code> object with all of the
|
||||
specified options, and return it. Options after the first non-option
|
||||
argument are treated as arguments. <code>options.arguments</code> will be an array
|
||||
containing the remaining arguments. This is a simpler API than many option
|
||||
parsers that allow you to attach callback actions for every flag. Instead,
|
||||
you're responsible for interpreting the options object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">parse: </span><span class="nf">(args) -></span>
|
||||
<span class="nv">options = arguments: </span><span class="p">[]</span>
|
||||
<span class="nv">skippingArgument = </span><span class="kc">no</span>
|
||||
<span class="nv">originalArgs = </span><span class="nx">args</span>
|
||||
<span class="nv">args = </span><span class="nx">normalizeArguments</span> <span class="nx">args</span>
|
||||
<span class="k">for</span> <span class="nx">arg</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">args</span>
|
||||
<span class="k">if</span> <span class="nx">skippingArgument</span>
|
||||
<span class="nv">skippingArgument = </span><span class="kc">no</span>
|
||||
<span class="k">continue</span>
|
||||
<span class="k">if</span> <span class="nx">arg</span> <span class="o">is</span> <span class="s">'--'</span>
|
||||
<span class="nv">pos = </span><span class="nx">originalArgs</span><span class="p">.</span><span class="nx">indexOf</span> <span class="s">'--'</span>
|
||||
<span class="nv">options.arguments = </span><span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">originalArgs</span><span class="p">[(</span><span class="nx">pos</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)..]</span>
|
||||
<span class="k">break</span>
|
||||
<span class="nv">isOption = </span><span class="o">!!</span><span class="p">(</span><span class="nx">arg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">LONG_FLAG</span><span class="p">)</span> <span class="o">or</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">SHORT_FLAG</span><span class="p">))</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>the CS option parser is a little odd; options after the first
|
||||
non-option argument are treated as non-option arguments themselves</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">seenNonOptionArg = </span><span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">0</span>
|
||||
<span class="k">unless</span> <span class="nx">seenNonOptionArg</span>
|
||||
<span class="nv">matchedRule = </span><span class="kc">no</span>
|
||||
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@rules</span>
|
||||
<span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="o">is</span> <span class="nx">arg</span> <span class="o">or</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span> <span class="o">is</span> <span class="nx">arg</span>
|
||||
<span class="nv">value = </span><span class="kc">true</span>
|
||||
<span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">hasArgument</span>
|
||||
<span class="nv">skippingArgument = </span><span class="kc">yes</span>
|
||||
<span class="nv">value = </span><span class="nx">args</span><span class="p">[</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
|
||||
<span class="nx">options</span><span class="p">[</span><span class="nx">rule</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">isList</span> <span class="k">then</span> <span class="p">(</span><span class="nx">options</span><span class="p">[</span><span class="nx">rule</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">or</span> <span class="p">[]).</span><span class="nx">concat</span> <span class="nx">value</span> <span class="k">else</span> <span class="nx">value</span>
|
||||
<span class="nv">matchedRule = </span><span class="kc">yes</span>
|
||||
<span class="k">break</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"unrecognized option: </span><span class="si">#{</span><span class="nx">arg</span><span class="si">}</span><span class="s">"</span> <span class="k">if</span> <span class="nx">isOption</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">matchedRule</span>
|
||||
<span class="k">if</span> <span class="nx">seenNonOptionArg</span> <span class="o">or</span> <span class="o">not</span> <span class="nx">isOption</span>
|
||||
<span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">push</span> <span class="nx">arg</span>
|
||||
<span class="nx">options</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Return the help text for this <strong>OptionParser</strong>, listing and describing all
|
||||
of the valid options, for <code>--help</code> and such.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">help: </span><span class="nf">-></span>
|
||||
<span class="nv">lines = </span><span class="p">[]</span>
|
||||
<span class="nx">lines</span><span class="p">.</span><span class="nx">unshift</span> <span class="s">"</span><span class="si">#{</span><span class="nx">@banner</span><span class="si">}</span><span class="s">\n"</span> <span class="k">if</span> <span class="nx">@banner</span>
|
||||
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@rules</span>
|
||||
<span class="nv">spaces = </span><span class="mi">15</span> <span class="o">-</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">length</span>
|
||||
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">></span> <span class="mi">0</span> <span class="k">then</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">spaces</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s">' '</span><span class="p">)</span> <span class="k">else</span> <span class="s">''</span>
|
||||
<span class="nv">letPart = </span><span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="k">then</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="o">+</span> <span class="s">', '</span> <span class="k">else</span> <span class="s">' '</span>
|
||||
<span class="nx">lines</span><span class="p">.</span><span class="nx">push</span> <span class="s">' '</span> <span class="o">+</span> <span class="nx">letPart</span> <span class="o">+</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span> <span class="o">+</span> <span class="nx">spaces</span> <span class="o">+</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">description</span>
|
||||
<span class="s">"\n</span><span class="si">#{</span> <span class="nx">lines</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">'\n'</span><span class="p">)</span> <span class="si">}</span><span class="s">\n"</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <h2>Helpers</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Regex matchers for option flags.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">LONG_FLAG = </span><span class="sr">/^(--\w[\w\-]*)/</span>
|
||||
<span class="nv">SHORT_FLAG = </span><span class="sr">/^(-\w)$/</span>
|
||||
<span class="nv">MULTI_FLAG = </span><span class="sr">/^-(\w{2,})/</span>
|
||||
<span class="nv">OPTIONAL = </span><span class="sr">/\[(\w+(\*?))\]/</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>Build and return the list of option rules. If the optional <em>short-flag</em> is
|
||||
unspecified, leave it out by padding with <code>null</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">buildRules = </span><span class="nf">(rules) -></span>
|
||||
<span class="k">for</span> <span class="nx">tuple</span> <span class="k">in</span> <span class="nx">rules</span>
|
||||
<span class="nx">tuple</span><span class="p">.</span><span class="nx">unshift</span> <span class="kc">null</span> <span class="k">if</span> <span class="nx">tuple</span><span class="p">.</span><span class="nx">length</span> <span class="o"><</span> <span class="mi">3</span>
|
||||
<span class="nx">buildRule</span> <span class="nx">tuple</span><span class="p">...</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>Build a rule from a <code>-o</code> short flag, a <code>--output [DIR]</code> long flag, and the
|
||||
description of what the option does.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">buildRule = </span><span class="nf">(shortFlag, longFlag, description, options = {}) -></span>
|
||||
<span class="nv">match = </span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">OPTIONAL</span><span class="p">)</span>
|
||||
<span class="nv">longFlag = </span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">LONG_FLAG</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
|
||||
<span class="p">{</span>
|
||||
<span class="nv">name: </span> <span class="nx">longFlag</span><span class="p">.</span><span class="nx">substr</span> <span class="mi">2</span>
|
||||
<span class="nv">shortFlag: </span> <span class="nx">shortFlag</span>
|
||||
<span class="nv">longFlag: </span> <span class="nx">longFlag</span>
|
||||
<span class="nv">description: </span> <span class="nx">description</span>
|
||||
<span class="nv">hasArgument: </span> <span class="o">!!</span><span class="p">(</span><span class="nx">match</span> <span class="o">and</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
|
||||
<span class="nv">isList: </span> <span class="o">!!</span><span class="p">(</span><span class="nx">match</span> <span class="o">and</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
|
||||
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Normalize arguments by expanding merged flags into multiple flags. This allows
|
||||
you to have <code>-wl</code> be the same as <code>--watch --lint</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">normalizeArguments = </span><span class="nf">(args) -></span>
|
||||
<span class="nv">args = </span><span class="nx">args</span><span class="p">[..]</span>
|
||||
<span class="nv">result = </span><span class="p">[]</span>
|
||||
<span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">args</span>
|
||||
<span class="k">if</span> <span class="nv">match = </span><span class="nx">arg</span><span class="p">.</span><span class="nx">match</span> <span class="nx">MULTI_FLAG</span>
|
||||
<span class="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="s">'-'</span> <span class="o">+</span> <span class="nx">l</span> <span class="k">for</span> <span class="nx">l</span> <span class="k">in</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">split</span> <span class="s">''</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="nx">arg</span>
|
||||
<span class="nx">result</span>
|
||||
you're responsible for interpreting the options object.
|
||||
</p>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> parse: (args) ->
|
||||
options = arguments: []
|
||||
skippingArgument = <span class="literal">no</span>
|
||||
originalArgs = args
|
||||
args = normalizeArguments args
|
||||
<span class="keyword">for</span> arg, i <span class="keyword">in</span> args
|
||||
<span class="keyword">if</span> skippingArgument
|
||||
skippingArgument = <span class="literal">no</span>
|
||||
<span class="keyword">continue</span>
|
||||
<span class="keyword">if</span> arg <span class="keyword">is</span> <span class="string">'--'</span>
|
||||
pos = originalArgs.indexOf <span class="string">'--'</span>
|
||||
options.arguments = options.arguments.concat originalArgs[(pos + <span class="number">1</span>)..]
|
||||
<span class="keyword">break</span>
|
||||
isOption = !!(arg.match(LONG_FLAG) <span class="keyword">or</span> arg.match(SHORT_FLAG))</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>the CS option parser is a little odd; options after the first
|
||||
non-option argument are treated as non-option arguments themselves
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> seenNonOptionArg = options.arguments.length > <span class="number">0</span>
|
||||
<span class="keyword">unless</span> seenNonOptionArg
|
||||
matchedRule = <span class="literal">no</span>
|
||||
<span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</span>
|
||||
<span class="keyword">if</span> rule.shortFlag <span class="keyword">is</span> arg <span class="keyword">or</span> rule.longFlag <span class="keyword">is</span> arg
|
||||
value = <span class="literal">true</span>
|
||||
<span class="keyword">if</span> rule.hasArgument
|
||||
skippingArgument = <span class="literal">yes</span>
|
||||
value = args[i + <span class="number">1</span>]
|
||||
options[rule.name] = <span class="keyword">if</span> rule.isList <span class="keyword">then</span> (options[rule.name] <span class="keyword">or</span> []).concat value <span class="keyword">else</span> value
|
||||
matchedRule = <span class="literal">yes</span>
|
||||
<span class="keyword">break</span>
|
||||
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"unrecognized option: <span class="subst">#{arg}</span>"</span> <span class="keyword">if</span> isOption <span class="keyword">and</span> <span class="keyword">not</span> matchedRule
|
||||
<span class="keyword">if</span> seenNonOptionArg <span class="keyword">or</span> <span class="keyword">not</span> isOption
|
||||
options.arguments.push arg
|
||||
options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Return the help text for this <strong>OptionParser</strong>, listing and describing all
|
||||
of the valid options, for <code>--help</code> and such.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> help: ->
|
||||
lines = []
|
||||
lines.unshift <span class="string">"<span class="subst">#{@banner}</span>\n"</span> <span class="keyword">if</span> <span class="property">@banner</span>
|
||||
<span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</span>
|
||||
spaces = <span class="number">15</span> - rule.longFlag.length
|
||||
spaces = <span class="keyword">if</span> spaces > <span class="number">0</span> <span class="keyword">then</span> repeat <span class="string">' '</span>, spaces <span class="keyword">else</span> <span class="string">''</span>
|
||||
letPart = <span class="keyword">if</span> rule.shortFlag <span class="keyword">then</span> rule.shortFlag + <span class="string">', '</span> <span class="keyword">else</span> <span class="string">' '</span>
|
||||
lines.push <span class="string">' '</span> + letPart + rule.longFlag + spaces + rule.description
|
||||
<span class="string">"\n<span class="subst">#{ lines.join('\n') }</span>\n"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap for-h2">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<h2>Helpers</h2>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Regex matchers for option flags.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>LONG_FLAG = <span class="regexp">/^(--\w[\w\-]*)/</span>
|
||||
SHORT_FLAG = <span class="regexp">/^(-\w)$/</span>
|
||||
MULTI_FLAG = <span class="regexp">/^-(\w{2,})/</span>
|
||||
OPTIONAL = <span class="regexp">/\[(\w+(\*?))\]/</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Build and return the list of option rules. If the optional <em>short-flag</em> is
|
||||
unspecified, leave it out by padding with <code>null</code>.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildRules</span></span> = (rules) ->
|
||||
<span class="keyword">for</span> tuple <span class="keyword">in</span> rules
|
||||
tuple.unshift <span class="literal">null</span> <span class="keyword">if</span> tuple.length < <span class="number">3</span>
|
||||
buildRule tuple...</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Build a rule from a <code>-o</code> short flag, a <code>--output [DIR]</code> long flag, and the
|
||||
description of what the option does.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildRule</span></span> = (shortFlag, longFlag, description, options = {}) ->
|
||||
match = longFlag.match(OPTIONAL)
|
||||
longFlag = longFlag.match(LONG_FLAG)[<span class="number">1</span>]
|
||||
{
|
||||
name: longFlag.substr <span class="number">2</span>
|
||||
shortFlag: shortFlag
|
||||
longFlag: longFlag
|
||||
description: description
|
||||
hasArgument: !!(match <span class="keyword">and</span> match[<span class="number">1</span>])
|
||||
isList: !!(match <span class="keyword">and</span> match[<span class="number">2</span>])
|
||||
}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>Normalize arguments by expanding merged flags into multiple flags. This allows
|
||||
you to have <code>-wl</code> be the same as <code>--watch --lint</code>.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">normalizeArguments</span></span> = (args) ->
|
||||
args = args[..]
|
||||
result = []
|
||||
<span class="keyword">for</span> arg <span class="keyword">in</span> args
|
||||
<span class="keyword">if</span> match = arg.match MULTI_FLAG
|
||||
result.push <span class="string">'-'</span> + l <span class="keyword">for</span> l <span class="keyword">in</span> match[<span class="number">1</span>].split <span class="string">''</span>
|
||||
<span class="keyword">else</span>
|
||||
result.push arg
|
||||
result</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
BIN
documentation/docs/public/fonts/aller-bold.eot
Executable file
BIN
documentation/docs/public/fonts/aller-bold.eot
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-bold.ttf
Executable file
BIN
documentation/docs/public/fonts/aller-bold.ttf
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-bold.woff
Executable file
BIN
documentation/docs/public/fonts/aller-bold.woff
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-light.eot
Executable file
BIN
documentation/docs/public/fonts/aller-light.eot
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-light.ttf
Executable file
BIN
documentation/docs/public/fonts/aller-light.ttf
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/aller-light.woff
Executable file
BIN
documentation/docs/public/fonts/aller-light.woff
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/novecento-bold.eot
Executable file
BIN
documentation/docs/public/fonts/novecento-bold.eot
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/novecento-bold.ttf
Executable file
BIN
documentation/docs/public/fonts/novecento-bold.ttf
Executable file
Binary file not shown.
BIN
documentation/docs/public/fonts/novecento-bold.woff
Executable file
BIN
documentation/docs/public/fonts/novecento-bold.woff
Executable file
Binary file not shown.
375
documentation/docs/public/stylesheets/normalize.css
vendored
Normal file
375
documentation/docs/public/stylesheets/normalize.css
vendored
Normal file
@@ -0,0 +1,375 @@
|
||||
/*! normalize.css v2.0.1 | MIT License | git.io/normalize */
|
||||
|
||||
/* ==========================================================================
|
||||
HTML5 display definitions
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* Corrects `block` display not defined in IE 8/9.
|
||||
*/
|
||||
|
||||
article,
|
||||
aside,
|
||||
details,
|
||||
figcaption,
|
||||
figure,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
nav,
|
||||
section,
|
||||
summary {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/*
|
||||
* Corrects `inline-block` display not defined in IE 8/9.
|
||||
*/
|
||||
|
||||
audio,
|
||||
canvas,
|
||||
video {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevents modern browsers from displaying `audio` without controls.
|
||||
* Remove excess height in iOS 5 devices.
|
||||
*/
|
||||
|
||||
audio:not([controls]) {
|
||||
display: none;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Addresses styling for `hidden` attribute not present in IE 8/9.
|
||||
*/
|
||||
|
||||
[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Base
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* 1. Sets default font family to sans-serif.
|
||||
* 2. Prevents iOS text size adjust after orientation change, without disabling
|
||||
* user zoom.
|
||||
*/
|
||||
|
||||
html {
|
||||
font-family: sans-serif; /* 1 */
|
||||
-webkit-text-size-adjust: 100%; /* 2 */
|
||||
-ms-text-size-adjust: 100%; /* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes default margin.
|
||||
*/
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Links
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* Addresses `outline` inconsistency between Chrome and other browsers.
|
||||
*/
|
||||
|
||||
a:focus {
|
||||
outline: thin dotted;
|
||||
}
|
||||
|
||||
/*
|
||||
* Improves readability when focused and also mouse hovered in all browsers.
|
||||
*/
|
||||
|
||||
a:active,
|
||||
a:hover {
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Typography
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* Addresses `h1` font sizes within `section` and `article` in Firefox 4+,
|
||||
* Safari 5, and Chrome.
|
||||
*/
|
||||
|
||||
h1 {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
/*
|
||||
* Addresses styling not present in IE 8/9, Safari 5, and Chrome.
|
||||
*/
|
||||
|
||||
abbr[title] {
|
||||
border-bottom: 1px dotted;
|
||||
}
|
||||
|
||||
/*
|
||||
* Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
|
||||
*/
|
||||
|
||||
b,
|
||||
strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/*
|
||||
* Addresses styling not present in Safari 5 and Chrome.
|
||||
*/
|
||||
|
||||
dfn {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/*
|
||||
* Addresses styling not present in IE 8/9.
|
||||
*/
|
||||
|
||||
mark {
|
||||
background: #ff0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Corrects font family set oddly in Safari 5 and Chrome.
|
||||
*/
|
||||
|
||||
code,
|
||||
kbd,
|
||||
pre,
|
||||
samp {
|
||||
font-family: monospace, serif;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
/*
|
||||
* Improves readability of pre-formatted text in all browsers.
|
||||
*/
|
||||
|
||||
pre {
|
||||
white-space: pre;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets consistent quote types.
|
||||
*/
|
||||
|
||||
q {
|
||||
quotes: "\201C" "\201D" "\2018" "\2019";
|
||||
}
|
||||
|
||||
/*
|
||||
* Addresses inconsistent and variable font size in all browsers.
|
||||
*/
|
||||
|
||||
small {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevents `sub` and `sup` affecting `line-height` in all browsers.
|
||||
*/
|
||||
|
||||
sub,
|
||||
sup {
|
||||
font-size: 75%;
|
||||
line-height: 0;
|
||||
position: relative;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
sup {
|
||||
top: -0.5em;
|
||||
}
|
||||
|
||||
sub {
|
||||
bottom: -0.25em;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Embedded content
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* Removes border when inside `a` element in IE 8/9.
|
||||
*/
|
||||
|
||||
img {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Corrects overflow displayed oddly in IE 9.
|
||||
*/
|
||||
|
||||
svg:not(:root) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Figures
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* Addresses margin not present in IE 8/9 and Safari 5.
|
||||
*/
|
||||
|
||||
figure {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Forms
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* Define consistent border, margin, and padding.
|
||||
*/
|
||||
|
||||
fieldset {
|
||||
border: 1px solid #c0c0c0;
|
||||
margin: 0 2px;
|
||||
padding: 0.35em 0.625em 0.75em;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. Corrects color not being inherited in IE 8/9.
|
||||
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
|
||||
*/
|
||||
|
||||
legend {
|
||||
border: 0; /* 1 */
|
||||
padding: 0; /* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. Corrects font family not being inherited in all browsers.
|
||||
* 2. Corrects font size not being inherited in all browsers.
|
||||
* 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome
|
||||
*/
|
||||
|
||||
button,
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
font-family: inherit; /* 1 */
|
||||
font-size: 100%; /* 2 */
|
||||
margin: 0; /* 3 */
|
||||
}
|
||||
|
||||
/*
|
||||
* Addresses Firefox 4+ setting `line-height` on `input` using `!important` in
|
||||
* the UA stylesheet.
|
||||
*/
|
||||
|
||||
button,
|
||||
input {
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
|
||||
* and `video` controls.
|
||||
* 2. Corrects inability to style clickable `input` types in iOS.
|
||||
* 3. Improves usability and consistency of cursor style between image-type
|
||||
* `input` and others.
|
||||
*/
|
||||
|
||||
button,
|
||||
html input[type="button"], /* 1 */
|
||||
input[type="reset"],
|
||||
input[type="submit"] {
|
||||
-webkit-appearance: button; /* 2 */
|
||||
cursor: pointer; /* 3 */
|
||||
}
|
||||
|
||||
/*
|
||||
* Re-set default cursor for disabled elements.
|
||||
*/
|
||||
|
||||
button[disabled],
|
||||
input[disabled] {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. Addresses box sizing set to `content-box` in IE 8/9.
|
||||
* 2. Removes excess padding in IE 8/9.
|
||||
*/
|
||||
|
||||
input[type="checkbox"],
|
||||
input[type="radio"] {
|
||||
box-sizing: border-box; /* 1 */
|
||||
padding: 0; /* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome.
|
||||
* 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome
|
||||
* (include `-moz` to future-proof).
|
||||
*/
|
||||
|
||||
input[type="search"] {
|
||||
-webkit-appearance: textfield; /* 1 */
|
||||
-moz-box-sizing: content-box;
|
||||
-webkit-box-sizing: content-box; /* 2 */
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes inner padding and search cancel button in Safari 5 and Chrome
|
||||
* on OS X.
|
||||
*/
|
||||
|
||||
input[type="search"]::-webkit-search-cancel-button,
|
||||
input[type="search"]::-webkit-search-decoration {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes inner padding and border in Firefox 4+.
|
||||
*/
|
||||
|
||||
button::-moz-focus-inner,
|
||||
input::-moz-focus-inner {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. Removes default vertical scrollbar in IE 8/9.
|
||||
* 2. Improves readability and alignment in all browsers.
|
||||
*/
|
||||
|
||||
textarea {
|
||||
overflow: auto; /* 1 */
|
||||
vertical-align: top; /* 2 */
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Tables
|
||||
========================================================================== */
|
||||
|
||||
/*
|
||||
* Remove most spacing between table cells.
|
||||
*/
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
@@ -1,57 +1,514 @@
|
||||
<!DOCTYPE html> <html> <head> <title>repl.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> repl.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="nv">vm = </span><span class="nx">require</span> <span class="s">'vm'</span>
|
||||
<span class="nv">nodeREPL = </span><span class="nx">require</span> <span class="s">'repl'</span>
|
||||
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s">'./coffee-script'</span>
|
||||
<span class="p">{</span><span class="nx">merge</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">'./helpers'</span>
|
||||
<!DOCTYPE html>
|
||||
|
||||
<span class="nv">replDefaults =</span>
|
||||
<span class="nv">prompt: </span><span class="s">'coffee> '</span><span class="p">,</span>
|
||||
<span class="nb">eval</span><span class="o">:</span> <span class="nf">(input, context, filename, cb) -></span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>XXX: multiline hack</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">input = </span><span class="nx">input</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\uFF00/g</span><span class="p">,</span> <span class="s">'\n'</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>strip single-line comments</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">input = </span><span class="nx">input</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/(^|[\r\n]+)(\s*)##?(?:[^#\r\n][^\r\n]*|)($|[\r\n])/</span><span class="p">,</span> <span class="s">'$1$2$3'</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>empty command</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">cb</span> <span class="kc">null</span> <span class="k">if</span> <span class="sr">/^(\s*|\(\s*\))$/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">input</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>TODO: fix #1829: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">try</span>
|
||||
<span class="nv">js = </span><span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="s">"_=(</span><span class="si">#{</span><span class="nx">input</span><span class="si">}</span><span class="s">\n)"</span><span class="p">,</span> <span class="p">{</span><span class="nx">filename</span><span class="p">,</span> <span class="nv">bare: </span><span class="kc">yes</span><span class="p">}</span>
|
||||
<span class="nx">cb</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">vm</span><span class="p">.</span><span class="nx">runInContext</span><span class="p">(</span><span class="nx">js</span><span class="p">,</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">filename</span><span class="p">)</span>
|
||||
<span class="k">catch</span> <span class="nx">err</span>
|
||||
<span class="nx">cb</span> <span class="nx">err</span>
|
||||
<html>
|
||||
<head>
|
||||
<title>repl.coffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>repl.coffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
|
||||
path = require <span class="string">'path'</span>
|
||||
vm = require <span class="string">'vm'</span>
|
||||
nodeREPL = require <span class="string">'repl'</span>
|
||||
CoffeeScript = require <span class="string">'./coffee-script'</span>
|
||||
{merge, prettyErrorMessage} = require <span class="string">'./helpers'</span>
|
||||
|
||||
<span class="nv">addMultilineHandler = </span><span class="nf">(repl) -></span>
|
||||
<span class="p">{</span><span class="nx">rli</span><span class="p">,</span> <span class="nx">inputStream</span><span class="p">,</span> <span class="nx">outputStream</span><span class="p">}</span> <span class="o">=</span> <span class="nx">repl</span>
|
||||
replDefaults =
|
||||
prompt: <span class="string">'coffee> '</span>,
|
||||
historyFile: path.join process.env.HOME, <span class="string">'.coffee_history'</span> <span class="keyword">if</span> process.env.HOME
|
||||
historyMaxInputSize: <span class="number">10240</span>
|
||||
eval: (input, context, filename, cb) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>XXX: multiline hack.
|
||||
</p>
|
||||
|
||||
<span class="nv">multiline =</span>
|
||||
<span class="nv">enabled: </span><span class="kc">off</span>
|
||||
<span class="nv">initialPrompt: </span><span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^[^> ]*/</span><span class="p">,</span> <span class="nf">(x) -></span> <span class="nx">x</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/./g</span><span class="p">,</span> <span class="s">'-'</span><span class="p">)</span>
|
||||
<span class="nv">prompt: </span><span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^[^> ]*>?/</span><span class="p">,</span> <span class="nf">(x) -></span> <span class="nx">x</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/./g</span><span class="p">,</span> <span class="s">'.'</span><span class="p">)</span>
|
||||
<span class="nv">buffer: </span><span class="s">''</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>Proxy node's line listener</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">nodeLineListener = </span><span class="nx">rli</span><span class="p">.</span><span class="nx">listeners</span><span class="p">(</span><span class="s">'line'</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">removeListener</span> <span class="s">'line'</span><span class="p">,</span> <span class="nx">nodeLineListener</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">on</span> <span class="s">'line'</span><span class="p">,</span> <span class="nf">(cmd) -></span>
|
||||
<span class="k">if</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span>
|
||||
<span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span> <span class="o">+=</span> <span class="s">"</span><span class="si">#{</span><span class="nx">cmd</span><span class="si">}</span><span class="s">\n"</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">setPrompt</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">prompt</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">prompt</span> <span class="kc">true</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">nodeLineListener</span> <span class="nx">cmd</span>
|
||||
<span class="k">return</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Handle Ctrl-v</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">inputStream</span><span class="p">.</span><span class="nx">on</span> <span class="s">'keypress'</span><span class="p">,</span> <span class="nf">(char, key) -></span>
|
||||
<span class="k">return</span> <span class="k">unless</span> <span class="nx">key</span> <span class="o">and</span> <span class="nx">key</span><span class="p">.</span><span class="nx">ctrl</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">key</span><span class="p">.</span><span class="nx">meta</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">key</span><span class="p">.</span><span class="nx">shift</span> <span class="o">and</span> <span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">is</span> <span class="s">'v'</span>
|
||||
<span class="k">if</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>allow arbitrarily switching between modes any time before multiple lines are entered</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">unless</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span><span class="p">.</span><span class="nx">match</span> <span class="sr">/\n/</span>
|
||||
<span class="nv">multiline.enabled = </span><span class="o">not</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">setPrompt</span> <span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">prompt</span> <span class="kc">true</span>
|
||||
<span class="k">return</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>no-op unless the current line is empty</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="k">if</span> <span class="nx">rli</span><span class="p">.</span><span class="nx">line</span><span class="o">?</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">rli</span><span class="p">.</span><span class="nx">line</span><span class="p">.</span><span class="nx">match</span> <span class="sr">/^\s*$/</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>eval, print, loop</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">multiline.enabled = </span><span class="o">not</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span>
|
||||
<span class="nv">rli.line = </span><span class="s">''</span>
|
||||
<span class="nv">rli.cursor = </span><span class="mi">0</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">output</span><span class="p">.</span><span class="nx">cursorTo</span> <span class="mi">0</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">output</span><span class="p">.</span><span class="nx">clearLine</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>XXX: multiline hack</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">multiline.buffer = </span><span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\n/g</span><span class="p">,</span> <span class="s">'\uFF00'</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">emit</span> <span class="s">'line'</span><span class="p">,</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">buffer</span>
|
||||
<span class="nv">multiline.buffer = </span><span class="s">''</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">multiline.enabled = </span><span class="o">not</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">enabled</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">setPrompt</span> <span class="nx">multiline</span><span class="p">.</span><span class="nx">initialPrompt</span>
|
||||
<span class="nx">rli</span><span class="p">.</span><span class="nx">prompt</span> <span class="kc">true</span>
|
||||
<span class="k">return</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="regexp">/\uFF00/g</span>, <span class="string">'\n'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Node's REPL sends the input ending with a newline and then wrapped in
|
||||
parens. Unwrap all that.
|
||||
</p>
|
||||
|
||||
<span class="nv">module.exports =</span>
|
||||
<span class="nv">start: </span><span class="nf">(opts = {}) -></span>
|
||||
<span class="nv">opts = </span><span class="nx">merge</span> <span class="nx">replDefaults</span><span class="p">,</span> <span class="nx">opts</span>
|
||||
<span class="nv">repl = </span><span class="nx">nodeREPL</span><span class="p">.</span><span class="nx">start</span> <span class="nx">opts</span>
|
||||
<span class="nx">repl</span><span class="p">.</span><span class="nx">on</span> <span class="s">'exit'</span><span class="p">,</span> <span class="nf">-></span> <span class="nx">repl</span><span class="p">.</span><span class="nx">outputStream</span><span class="p">.</span><span class="nx">write</span> <span class="s">'\n'</span>
|
||||
<span class="nx">addMultilineHandler</span> <span class="nx">repl</span>
|
||||
<span class="nx">repl</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="regexp">/^\(([\s\S]*)\n\)$/m</span>, <span class="string">'$1'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Require AST nodes to do some AST manipulation.
|
||||
</p>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> {Block, Assign, Value, Literal} = require <span class="string">'./nodes'</span>
|
||||
|
||||
<span class="keyword">try</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Generate the AST of the clean input.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes input</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>Add assignment to <code>_</code> variable to force the input to be an expression.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = <span class="keyword">new</span> Block [
|
||||
<span class="keyword">new</span> Assign (<span class="keyword">new</span> Value <span class="keyword">new</span> Literal <span class="string">'_'</span>), ast, <span class="string">'='</span>
|
||||
]
|
||||
js = ast.compile bare: <span class="literal">yes</span>, locals: Object.keys(context)
|
||||
cb <span class="literal">null</span>, vm.runInContext(js, context, filename)
|
||||
<span class="keyword">catch</span> err
|
||||
cb prettyErrorMessage(err, filename, input, <span class="literal">yes</span>)
|
||||
|
||||
<span class="function"><span class="title">addMultilineHandler</span></span> = (repl) ->
|
||||
{rli, inputStream, outputStream} = repl
|
||||
|
||||
multiline =
|
||||
enabled: <span class="literal">off</span>
|
||||
initialPrompt: repl.prompt.replace <span class="regexp">/^[^> ]*/, (x) -> x.replace /./g</span>, <span class="string">'-'</span>
|
||||
prompt: repl.prompt.replace <span class="regexp">/^[^> ]*>?/, (x) -> x.replace /./g</span>, <span class="string">'.'</span>
|
||||
buffer: <span class="string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Proxy node's line listener
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> nodeLineListener = rli.listeners(<span class="string">'line'</span>)[<span class="number">0</span>]
|
||||
rli.removeListener <span class="string">'line'</span>, nodeLineListener
|
||||
rli.<span class="literal">on</span> <span class="string">'line'</span>, (cmd) ->
|
||||
<span class="keyword">if</span> multiline.enabled
|
||||
multiline.buffer += <span class="string">"<span class="subst">#{cmd}</span>\n"</span>
|
||||
rli.setPrompt multiline.prompt
|
||||
rli.prompt <span class="literal">true</span>
|
||||
<span class="keyword">else</span>
|
||||
nodeLineListener cmd
|
||||
<span class="keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Handle Ctrl-v
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> inputStream.<span class="literal">on</span> <span class="string">'keypress'</span>, (char, key) ->
|
||||
<span class="keyword">return</span> <span class="keyword">unless</span> key <span class="keyword">and</span> key.ctrl <span class="keyword">and</span> <span class="keyword">not</span> key.meta <span class="keyword">and</span> <span class="keyword">not</span> key.shift <span class="keyword">and</span> key.name <span class="keyword">is</span> <span class="string">'v'</span>
|
||||
<span class="keyword">if</span> multiline.enabled</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>allow arbitrarily switching between modes any time before multiple lines are entered
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">unless</span> multiline.buffer.match <span class="regexp">/\n/</span>
|
||||
multiline.enabled = <span class="keyword">not</span> multiline.enabled
|
||||
rli.setPrompt repl.prompt
|
||||
rli.prompt <span class="literal">true</span>
|
||||
<span class="keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>no-op unless the current line is empty
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">return</span> <span class="keyword">if</span> rli.line? <span class="keyword">and</span> <span class="keyword">not</span> rli.line.match <span class="regexp">/^\s*$/</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>eval, print, loop
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> multiline.enabled = <span class="keyword">not</span> multiline.enabled
|
||||
rli.line = <span class="string">''</span>
|
||||
rli.cursor = <span class="number">0</span>
|
||||
rli.output.cursorTo <span class="number">0</span>
|
||||
rli.output.clearLine <span class="number">1</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>XXX: multiline hack
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> multiline.buffer = multiline.buffer.replace <span class="regexp">/\n/g</span>, <span class="string">'\uFF00'</span>
|
||||
rli.emit <span class="string">'line'</span>, multiline.buffer
|
||||
multiline.buffer = <span class="string">''</span>
|
||||
<span class="keyword">else</span>
|
||||
multiline.enabled = <span class="keyword">not</span> multiline.enabled
|
||||
rli.setPrompt multiline.initialPrompt
|
||||
rli.prompt <span class="literal">true</span>
|
||||
<span class="keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Store and load command history from a file
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">addHistory</span></span> = (repl, filename, maxSize) ->
|
||||
lastLine = <span class="literal">null</span>
|
||||
<span class="keyword">try</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Get file info and at most maxSize of command history
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> stat = fs.statSync filename
|
||||
size = Math.min maxSize, stat.size</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Read last <code>size</code> bytes from the file
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> readFd = fs.openSync filename, <span class="string">'r'</span>
|
||||
buffer = <span class="keyword">new</span> Buffer(size)
|
||||
fs.readSync readFd, buffer, <span class="number">0</span>, size, stat.size - size</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>Set the history on the interpreter
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.rli.history = buffer.toString().split(<span class="string">'\n'</span>).reverse()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>If the history file was truncated we should pop off a potential partial line
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.rli.history.pop() <span class="keyword">if</span> stat.size > maxSize</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>Shift off the final blank newline
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.rli.history.shift() <span class="keyword">if</span> repl.rli.history[<span class="number">0</span>] <span class="keyword">is</span> <span class="string">''</span>
|
||||
repl.rli.historyIndex = -<span class="number">1</span>
|
||||
lastLine = repl.rli.history[<span class="number">0</span>]
|
||||
|
||||
fd = fs.openSync filename, <span class="string">'a'</span>
|
||||
|
||||
repl.rli.addListener <span class="string">'line'</span>, (code) ->
|
||||
<span class="keyword">if</span> code <span class="keyword">and</span> code.length <span class="keyword">and</span> code <span class="keyword">isnt</span> <span class="string">'.history'</span> <span class="keyword">and</span> lastLine <span class="keyword">isnt</span> code</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>Save the latest command in the file
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> fs.write fd, <span class="string">"<span class="subst">#{code}</span>\n"</span>
|
||||
lastLine = code
|
||||
|
||||
repl.rli.<span class="literal">on</span> <span class="string">'exit'</span>, -> fs.close fd</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>Add a command to show the history stack
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.commands[<span class="string">'.history'</span>] =
|
||||
help: <span class="string">'Show command history'</span>
|
||||
action: ->
|
||||
repl.outputStream.write <span class="string">"<span class="subst">#{repl.rli.history[..].reverse().join '\n'}</span>\n"</span>
|
||||
repl.displayPrompt()
|
||||
|
||||
module.exports =
|
||||
start: (opts = {}) ->
|
||||
[major, minor, build] = process.versions.node.split(<span class="string">'.'</span>).map (n) -> parseInt(n)
|
||||
|
||||
<span class="keyword">if</span> major <span class="keyword">is</span> <span class="number">0</span> <span class="keyword">and</span> minor < <span class="number">8</span>
|
||||
console.warn <span class="string">"Node 0.8.0+ required for CoffeeScript REPL"</span>
|
||||
process.exit <span class="number">1</span>
|
||||
|
||||
opts = merge replDefaults, opts
|
||||
repl = nodeREPL.start opts
|
||||
repl.<span class="literal">on</span> <span class="string">'exit'</span>, -> repl.outputStream.write <span class="string">'\n'</span>
|
||||
addMultilineHandler repl
|
||||
addHistory repl, opts.historyFile, opts.historyMaxInputSize <span class="keyword">if</span> opts.historyFile
|
||||
repl</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,58 +1,431 @@
|
||||
<!DOCTYPE html> <html> <head> <title>scope.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> scope.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <p>The <strong>Scope</strong> class regulates lexical scoping within CoffeeScript. As you
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>scope.litcoffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>scope.litcoffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p>The <strong>Scope</strong> class regulates lexical scoping within CoffeeScript. As you
|
||||
generate code, you create a tree of scopes in the same shape as the nested
|
||||
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 the outside.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>Import the helpers we plan to use.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">extend</span><span class="p">,</span> <span class="nx">last</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">'./helpers'</span>
|
||||
with external scopes.
|
||||
</p>
|
||||
|
||||
<span class="nv">exports.Scope = </span><span class="k">class</span> <span class="nx">Scope</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>The top-level <strong>Scope</strong> object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@root: </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>Initialize a scope with its parent, for lookups up the chain,
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>Import the helpers we plan to use.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
{extend, last} = require <span class="string">'./helpers'</span>
|
||||
|
||||
exports.Scope = <span class="class"><span class="keyword">class</span> <span class="title">Scope</span></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>The <code>root</code> is the top-level <strong>Scope</strong> object for a given file.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
<span class="property">@root</span>: <span class="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p>Initialize a scope with its parent, for lookups up the chain,
|
||||
as well as a reference to the <strong>Block</strong> node it belongs to, which is
|
||||
where it should declare its variables, and a reference to the function that
|
||||
it wraps.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(@parent, @expressions, @method) -></span>
|
||||
<span class="vi">@variables = </span><span class="p">[{</span><span class="nv">name: </span><span class="s">'arguments'</span><span class="p">,</span> <span class="nv">type: </span><span class="s">'arguments'</span><span class="p">}]</span>
|
||||
<span class="vi">@positions = </span><span class="p">{}</span>
|
||||
<span class="nv">Scope.root = </span><span class="k">this</span> <span class="k">unless</span> <span class="nx">@parent</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Adds a new variable or overrides an existing one.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">add: </span><span class="nf">(name, type, immediate) -></span>
|
||||
<span class="k">return</span> <span class="nx">@parent</span><span class="p">.</span><span class="nx">add</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">type</span><span class="p">,</span> <span class="nx">immediate</span> <span class="k">if</span> <span class="nx">@shared</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">immediate</span>
|
||||
<span class="k">if</span> <span class="nb">Object</span><span class="o">::</span><span class="nx">hasOwnProperty</span><span class="p">.</span><span class="nx">call</span> <span class="nx">@positions</span><span class="p">,</span> <span class="nx">name</span>
|
||||
<span class="nx">@variables</span><span class="p">[</span><span class="nx">@positions</span><span class="p">[</span><span class="nx">name</span><span class="p">]].</span><span class="nv">type = </span><span class="nx">type</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nx">@positions</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@variables</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span><span class="nx">name</span><span class="p">,</span> <span class="nx">type</span><span class="p">})</span> <span class="o">-</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>When <code>super</code> is called, we need to find the name of the current method we're
|
||||
in, so that we know how to invoke the same method of the parent class. This
|
||||
can get complicated if super is being called from an inner function.
|
||||
<code>namedMethod</code> will walk up the scope tree until it either finds the first
|
||||
function object that has a name filled in, or bottoms out.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">namedMethod: </span><span class="nf">-></span>
|
||||
<span class="k">return</span> <span class="nx">@method</span> <span class="k">if</span> <span class="nx">@method</span><span class="p">.</span><span class="nx">name</span> <span class="o">or</span> <span class="o">!</span><span class="nx">@parent</span>
|
||||
<span class="nx">@parent</span><span class="p">.</span><span class="nx">namedMethod</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Look up a variable name in lexical scope, and declare it if it does not
|
||||
already exist.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">find: </span><span class="nf">(name) -></span>
|
||||
<span class="k">return</span> <span class="kc">yes</span> <span class="k">if</span> <span class="nx">@check</span> <span class="nx">name</span>
|
||||
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s">'var'</span>
|
||||
<span class="kc">no</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p>Reserve a variable name as originating from a function parameter for this
|
||||
scope. No <code>var</code> required for internal references.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">parameter: </span><span class="nf">(name) -></span>
|
||||
<span class="k">return</span> <span class="k">if</span> <span class="nx">@shared</span> <span class="o">and</span> <span class="nx">@parent</span><span class="p">.</span><span class="nx">check</span> <span class="nx">name</span><span class="p">,</span> <span class="kc">yes</span>
|
||||
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s">'param'</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>Just check to see if a variable has already been declared, without reserving,
|
||||
walks up to the root scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">check: </span><span class="nf">(name) -></span>
|
||||
<span class="o">!!</span><span class="p">(</span><span class="nx">@type</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">or</span> <span class="nx">@parent</span><span class="o">?</span><span class="p">.</span><span class="nx">check</span><span class="p">(</span><span class="nx">name</span><span class="p">))</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Generate a temporary variable name at the given index.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">temporary: </span><span class="nf">(name, index) -></span>
|
||||
<span class="k">if</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">1</span>
|
||||
<span class="s">'_'</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="k">if</span> <span class="nx">index</span> <span class="o">></span> <span class="mi">1</span> <span class="k">then</span> <span class="nx">index</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">else</span> <span class="s">''</span>
|
||||
<span class="k">else</span>
|
||||
<span class="s">'_'</span> <span class="o">+</span> <span class="p">(</span><span class="nx">index</span> <span class="o">+</span> <span class="nb">parseInt</span> <span class="nx">name</span><span class="p">,</span> <span class="mi">36</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">36</span><span class="p">).</span><span class="nx">replace</span> <span class="sr">/\d/g</span><span class="p">,</span> <span class="s">'a'</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>Gets the type of a variable.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">type: </span><span class="nf">(name) -></span>
|
||||
<span class="k">return</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span> <span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span> <span class="o">is</span> <span class="nx">name</span>
|
||||
<span class="kc">null</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">¶</a> </div> <p>If we need to store an intermediate result, find an available name for a
|
||||
compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on...</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">freeVariable: </span><span class="nf">(name, reserve=true) -></span>
|
||||
<span class="nv">index = </span><span class="mi">0</span>
|
||||
<span class="nx">index</span><span class="o">++</span> <span class="k">while</span> <span class="nx">@check</span><span class="p">((</span><span class="nv">temp = </span><span class="nx">@temporary</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">index</span><span class="p">))</span>
|
||||
<span class="nx">@add</span> <span class="nx">temp</span><span class="p">,</span> <span class="s">'var'</span><span class="p">,</span> <span class="kc">yes</span> <span class="k">if</span> <span class="nx">reserve</span>
|
||||
<span class="nx">temp</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">¶</a> </div> <p>Ensure that an assignment is made at the top of this scope
|
||||
(or at the top-level scope, if requested).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">assign: </span><span class="nf">(name, value) -></span>
|
||||
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="p">{</span><span class="nx">value</span><span class="p">,</span> <span class="nv">assigned: </span><span class="kc">yes</span><span class="p">},</span> <span class="kc">yes</span>
|
||||
<span class="vi">@hasAssignments = </span><span class="kc">yes</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">¶</a> </div> <p>Does this scope have any declared variables?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">hasDeclarations: </span><span class="nf">-></span>
|
||||
<span class="o">!!</span><span class="nx">@declaredVariables</span><span class="p">().</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">¶</a> </div> <p>Return the list of variables first declared in this scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">declaredVariables: </span><span class="nf">-></span>
|
||||
<span class="nv">realVars = </span><span class="p">[]</span>
|
||||
<span class="nv">tempVars = </span><span class="p">[]</span>
|
||||
<span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span> <span class="o">is</span> <span class="s">'var'</span>
|
||||
<span class="p">(</span><span class="k">if</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">is</span> <span class="s">'_'</span> <span class="k">then</span> <span class="nx">tempVars</span> <span class="k">else</span> <span class="nx">realVars</span><span class="p">).</span><span class="nx">push</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span>
|
||||
<span class="nx">realVars</span><span class="p">.</span><span class="nx">sort</span><span class="p">().</span><span class="nx">concat</span> <span class="nx">tempVars</span><span class="p">.</span><span class="nx">sort</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">¶</a> </div> <p>Return the list of assignments that are supposed to be made at the top
|
||||
of this scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">assignedVariables: </span><span class="nf">-></span>
|
||||
<span class="s">"</span><span class="si">#{</span><span class="nx">v</span><span class="p">.</span><span class="nx">name</span><span class="si">}</span><span class="s"> = </span><span class="si">#{</span><span class="nx">v</span><span class="p">.</span><span class="nx">type</span><span class="p">.</span><span class="nx">value</span><span class="si">}</span><span class="s">"</span> <span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span><span class="p">.</span><span class="nx">assigned</span>
|
||||
it belongs to.
|
||||
</p>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
constructor: (<span class="property">@parent</span>, <span class="property">@expressions</span>, <span class="property">@method</span>) ->
|
||||
<span class="property">@variables</span> = [{name: <span class="string">'arguments'</span>, type: <span class="string">'arguments'</span>}]
|
||||
<span class="property">@positions</span> = {}
|
||||
Scope.root = <span class="keyword">this</span> <span class="keyword">unless</span> <span class="property">@parent</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Adds a new variable or overrides an existing one.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
add: (name, type, immediate) ->
|
||||
<span class="keyword">return</span> <span class="property">@parent</span>.add name, type, immediate <span class="keyword">if</span> <span class="property">@shared</span> <span class="keyword">and</span> <span class="keyword">not</span> immediate
|
||||
<span class="keyword">if</span> Object::hasOwnProperty.call <span class="property">@positions</span>, name
|
||||
<span class="property">@variables</span>[<span class="property">@positions</span>[name]].type = type
|
||||
<span class="keyword">else</span>
|
||||
<span class="property">@positions</span>[name] = <span class="property">@variables</span>.push({name, type}) - <span class="number">1</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<p>When <code>super</code> is called, we need to find the name of the current method we're
|
||||
in, so that we know how to invoke the same method of the parent class. This
|
||||
can get complicated if super is being called from an inner function.
|
||||
<code>namedMethod</code> will walk up the scope tree until it either finds the first
|
||||
function object that has a name filled in, or bottoms out.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
namedMethod: ->
|
||||
<span class="keyword">return</span> <span class="property">@method</span> <span class="keyword">if</span> <span class="property">@method</span>?.name <span class="keyword">or</span> !<span class="property">@parent</span>
|
||||
<span class="property">@parent</span>.namedMethod()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>Look up a variable name in lexical scope, and declare it if it does not
|
||||
already exist.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
find: (name) ->
|
||||
<span class="keyword">return</span> <span class="literal">yes</span> <span class="keyword">if</span> <span class="property">@check</span> name
|
||||
<span class="property">@add</span> name, <span class="string">'var'</span>
|
||||
<span class="literal">no</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Reserve a variable name as originating from a function parameter for this
|
||||
scope. No <code>var</code> required for internal references.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
parameter: (name) ->
|
||||
<span class="keyword">return</span> <span class="keyword">if</span> <span class="property">@shared</span> <span class="keyword">and</span> <span class="property">@parent</span>.check name, <span class="literal">yes</span>
|
||||
<span class="property">@add</span> name, <span class="string">'param'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Just check to see if a variable has already been declared, without reserving,
|
||||
walks up to the root scope.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
check: (name) ->
|
||||
!!(<span class="property">@type</span>(name) <span class="keyword">or</span> <span class="property">@parent</span>?.check(name))</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Generate a temporary variable name at the given index.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
temporary: (name, index) ->
|
||||
<span class="keyword">if</span> name.length > <span class="number">1</span>
|
||||
<span class="string">'_'</span> + name + <span class="keyword">if</span> index > <span class="number">1</span> <span class="keyword">then</span> index - <span class="number">1</span> <span class="keyword">else</span> <span class="string">''</span>
|
||||
<span class="keyword">else</span>
|
||||
<span class="string">'_'</span> + (index + parseInt name, <span class="number">36</span>).toString(<span class="number">36</span>).replace <span class="regexp">/\d/g</span>, <span class="string">'a'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Gets the type of a variable.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
type: (name) ->
|
||||
<span class="keyword">return</span> v.type <span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.name <span class="keyword">is</span> name
|
||||
<span class="literal">null</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<p>If we need to store an intermediate result, find an available name for a
|
||||
compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on...
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
freeVariable: (name, reserve=<span class="literal">true</span>) ->
|
||||
index = <span class="number">0</span>
|
||||
index++ <span class="keyword">while</span> <span class="property">@check</span>((temp = <span class="property">@temporary</span> name, index))
|
||||
<span class="property">@add</span> temp, <span class="string">'var'</span>, <span class="literal">yes</span> <span class="keyword">if</span> reserve
|
||||
temp</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<p>Ensure that an assignment is made at the top of this scope
|
||||
(or at the top-level scope, if requested).
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
assign: (name, value) ->
|
||||
<span class="property">@add</span> name, {value, assigned: <span class="literal">yes</span>}, <span class="literal">yes</span>
|
||||
<span class="property">@hasAssignments</span> = <span class="literal">yes</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Does this scope have any declared variables?
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
hasDeclarations: ->
|
||||
!!<span class="property">@declaredVariables</span>().length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Return the list of variables first declared in this scope.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
declaredVariables: ->
|
||||
realVars = []
|
||||
tempVars = []
|
||||
<span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.type <span class="keyword">is</span> <span class="string">'var'</span>
|
||||
(<span class="keyword">if</span> v.name.charAt(<span class="number">0</span>) <span class="keyword">is</span> <span class="string">'_'</span> <span class="keyword">then</span> tempVars <span class="keyword">else</span> realVars).push v.name
|
||||
realVars.sort().concat tempVars.sort()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>Return the list of assignments that are supposed to be made at the top
|
||||
of this scope.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
assignedVariables: ->
|
||||
<span class="string">"<span class="subst">#{v.name}</span> = <span class="subst">#{v.type.value}</span>"</span> <span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.type.assigned</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,155 +1,646 @@
|
||||
<!DOCTYPE html> <html> <head> <title>sourcemap.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="sourcemap.html"> sourcemap.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> sourcemap.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> <h3>LineMapping</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>Hold data about mappings for one line of generated source code.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">LineMapping</span>
|
||||
<span class="nv">constructor: </span><span class="nf">(@generatedLine) -></span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>columnMap keeps track of which columns we've already mapped.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@columnMap = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>columnMappings is an array of all column mappings, sorted by generated-column.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@columnMappings = </span><span class="p">[]</span>
|
||||
<!DOCTYPE html>
|
||||
|
||||
<span class="nv">addMapping: </span><span class="nf">(generatedColumn, [sourceLine, sourceColumn], options={}) -></span>
|
||||
<span class="k">if</span> <span class="nx">@columnMap</span><span class="p">[</span><span class="nx">generatedColumn</span><span class="p">]</span> <span class="o">and</span> <span class="nx">options</span><span class="p">.</span><span class="nx">noReplace</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>We already have a mapping for this column.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span>
|
||||
<html>
|
||||
<head>
|
||||
<title>sourcemap.litcoffee</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul id="jump_to">
|
||||
<li>
|
||||
<a class="large" href="javascript:void(0);">Jump To …</a>
|
||||
<a class="small" href="javascript:void(0);">+</a>
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
|
||||
|
||||
<a class="source" href="browser.html">
|
||||
browser.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="cake.html">
|
||||
cake.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="coffee-script.html">
|
||||
coffee-script.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="command.html">
|
||||
command.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="grammar.html">
|
||||
grammar.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="helpers.html">
|
||||
helpers.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="index.html">
|
||||
index.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="lexer.html">
|
||||
lexer.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="nodes.html">
|
||||
nodes.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="optparse.html">
|
||||
optparse.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="repl.html">
|
||||
repl.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="rewriter.html">
|
||||
rewriter.coffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="scope.html">
|
||||
scope.litcoffee
|
||||
</a>
|
||||
|
||||
|
||||
<a class="source" href="sourcemap.html">
|
||||
sourcemap.litcoffee
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>sourcemap.litcoffee</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<p>Source maps allow JavaScript runtimes to match running JavaScript back to
|
||||
the original source code that corresponds to it. This can be minified
|
||||
JavaScript, but in our case, we're concerned with mapping pretty-printed
|
||||
JavaScript back to CoffeeScript.
|
||||
</p>
|
||||
|
||||
<span class="nx">@columnMap</span><span class="p">[</span><span class="nx">generatedColumn</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="nv">generatedLine: </span><span class="nx">@generatedLine</span>
|
||||
<span class="nx">generatedColumn</span>
|
||||
<span class="nx">sourceLine</span>
|
||||
<span class="nx">sourceColumn</span>
|
||||
<span class="p">}</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<p>In order to produce maps, we must keep track of positions (line number, column number)
|
||||
that originated every node in the syntax tree, and be able to generate a
|
||||
<a href="https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit">map file</a>
|
||||
— which is a compact, VLQ-encoded representation of the JSON serialization
|
||||
of this information — to write out alongside the generated JavaScript.
|
||||
</p>
|
||||
|
||||
<span class="nx">@columnMappings</span><span class="p">.</span><span class="nx">push</span> <span class="nx">@columnMap</span><span class="p">[</span><span class="nx">generatedColumn</span><span class="p">]</span>
|
||||
<span class="nx">@columnMappings</span><span class="p">.</span><span class="nx">sort</span> <span class="nf">(a,b) -></span> <span class="nx">a</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="o">-</span> <span class="nx">b</span><span class="p">.</span><span class="nx">generatedColumn</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap for-h2">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<h2>LineMap</h2>
|
||||
|
||||
<span class="nv">getSourcePosition: </span><span class="nf">(generatedColumn) -></span>
|
||||
<span class="nv">answer = </span><span class="kc">null</span>
|
||||
<span class="nv">lastColumnMapping = </span><span class="kc">null</span>
|
||||
<span class="k">for</span> <span class="nx">columnMapping</span> <span class="k">in</span> <span class="nx">@columnMappings</span>
|
||||
<span class="k">if</span> <span class="nx">columnMapping</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="o">></span> <span class="nx">generatedColumn</span>
|
||||
<span class="k">break</span>
|
||||
<span class="k">else</span>
|
||||
<span class="nv">lastColumnMapping = </span><span class="nx">columnMapping</span>
|
||||
<span class="k">if</span> <span class="nx">lastColumnMapping</span>
|
||||
<span class="nv">answer = </span><span class="p">[</span><span class="nx">lastColumnMapping</span><span class="p">.</span><span class="nx">sourceLine</span><span class="p">,</span> <span class="nx">lastColumnMapping</span><span class="p">.</span><span class="nx">sourceColumn</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <h3>SourceMap</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>Maps locations in a generated source file back to locations in the original source file.</p>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>A <strong>LineMap</strong> object keeps track of information about original line and column
|
||||
positions for a single line of output JavaScript code.
|
||||
<strong>SourceMaps</strong> are implemented in terms of <strong>LineMaps</strong>.
|
||||
</p>
|
||||
|
||||
<p>This is intentionally agnostic towards how a source map might be represented on disk. A
|
||||
SourceMap can be converted to a "v3" style sourcemap with <code>#generateV3SourceMap()</code>, for example
|
||||
but the SourceMap class itself knows nothing about v3 source maps.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">SourceMap</span>
|
||||
<span class="nv">constructor: </span><span class="p">()</span> <span class="nf">-></span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <p><code>generatedLines</code> is an array of LineMappings, one per generated line.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@generatedLines = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <p>Adds a mapping to this SourceMap.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
<span class="class"><span class="keyword">class</span> <span class="title">LineMap</span></span>
|
||||
constructor: (<span class="property">@line</span>) ->
|
||||
<span class="property">@columns</span> = []
|
||||
|
||||
<p><code>sourceLocation</code> and <code>generatedLocation</code> are both [line, column] arrays.</p>
|
||||
add: (column, [sourceLine, sourceColumn], options={}) ->
|
||||
<span class="keyword">return</span> <span class="keyword">if</span> <span class="property">@columns</span>[column] <span class="keyword">and</span> options.noReplace
|
||||
<span class="property">@columns</span>[column] = {line: <span class="property">@line</span>, column, sourceLine, sourceColumn}
|
||||
|
||||
<p>If <code>options.noReplace</code> is true, then if there is already a mapping for
|
||||
the specified <code>generatedLine</code> and <code>generatedColumn</code>, this will have no effect.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">addMapping: </span><span class="nf">(sourceLocation, generatedLocation, options={}) -></span>
|
||||
<span class="p">[</span><span class="nx">generatedLine</span><span class="p">,</span> <span class="nx">generatedColumn</span><span class="p">]</span> <span class="o">=</span> <span class="nx">generatedLocation</span>
|
||||
sourceLocation: (column) ->
|
||||
column-- <span class="keyword">until</span> (mapping = <span class="property">@columns</span>[column]) <span class="keyword">or</span> (column <= <span class="number">0</span>)
|
||||
mapping <span class="keyword">and</span> [mapping.sourceLine, mapping.sourceColumn]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap for-h2">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<h2>SourceMap</h2>
|
||||
|
||||
<span class="nv">lineMapping = </span><span class="nx">@generatedLines</span><span class="p">[</span><span class="nx">generatedLine</span><span class="p">]</span>
|
||||
<span class="k">if</span> <span class="o">not</span> <span class="nx">lineMapping</span>
|
||||
<span class="nv">lineMapping = </span><span class="nx">@generatedLines</span><span class="p">[</span><span class="nx">generatedLine</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">LineMapping</span><span class="p">(</span><span class="nx">generatedLine</span><span class="p">)</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Maps locations in a single generated JavaScript file back to locations in
|
||||
the original CoffeeScript source file.
|
||||
</p>
|
||||
|
||||
<span class="nx">lineMapping</span><span class="p">.</span><span class="nx">addMapping</span> <span class="nx">generatedColumn</span><span class="p">,</span> <span class="nx">sourceLocation</span><span class="p">,</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Returns [sourceLine, sourceColumn], or null if no mapping could be found.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">getSourcePosition: </span><span class="nf">([generatedLine, generatedColumn]) -></span>
|
||||
<span class="nv">answer = </span><span class="kc">null</span>
|
||||
<span class="nv">lineMapping = </span><span class="nx">@generatedLines</span><span class="p">[</span><span class="nx">generatedLine</span><span class="p">]</span>
|
||||
<span class="k">if</span> <span class="o">not</span> <span class="nx">lineMapping</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">¶</a> </div> <p>TODO: Search backwards for the line?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">else</span>
|
||||
<span class="nv">answer = </span><span class="nx">lineMapping</span><span class="p">.</span><span class="nx">getSourcePosition</span> <span class="nx">generatedColumn</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>This is intentionally agnostic towards how a source map might be represented on
|
||||
disk. Once the compiler is ready to produce a "v3"-style source map, we can walk
|
||||
through the arrays of line and column buffer to produce it.
|
||||
</p>
|
||||
|
||||
<span class="nx">answer</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">¶</a> </div> <p><code>fn</code> will be called once for every recorded mapping, in the order in
|
||||
which they occur in the generated source. <code>fn</code> will be passed an object
|
||||
with four properties: sourceLine, sourceColumn, generatedLine, and
|
||||
generatedColumn.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">forEachMapping: </span><span class="nf">(fn) -></span>
|
||||
<span class="k">for</span> <span class="nx">lineMapping</span><span class="p">,</span> <span class="nx">generatedLineNumber</span> <span class="k">in</span> <span class="nx">@generatedLines</span>
|
||||
<span class="k">if</span> <span class="nx">lineMapping</span>
|
||||
<span class="k">for</span> <span class="nx">columnMapping</span> <span class="k">in</span> <span class="nx">lineMapping</span><span class="p">.</span><span class="nx">columnMappings</span>
|
||||
<span class="nx">fn</span><span class="p">(</span><span class="nx">columnMapping</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">¶</a> </div> <h3>generateV3SourceMap</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">¶</a> </div> <p>Builds a V3 source map from a SourceMap object.
|
||||
Returns the generated JSON as a string.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.generateV3SourceMap = </span><span class="nf">(sourceMap, sourceFile=null, generatedFile=null) -></span>
|
||||
<span class="nv">writingGeneratedLine = </span><span class="mi">0</span>
|
||||
<span class="nv">lastGeneratedColumnWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">lastSourceLineWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">lastSourceColumnWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">needComma = </span><span class="kc">no</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
<span class="class"><span class="keyword">class</span> <span class="title">SourceMap</span></span>
|
||||
constructor: ->
|
||||
<span class="property">@lines</span> = []</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Adds a mapping to this SourceMap. <code>sourceLocation</code> and <code>generatedLocation</code>
|
||||
are both <code>[line, column]</code> arrays. If <code>options.noReplace</code> is true, then if there
|
||||
is already a mapping for the specified <code>line</code> and <code>column</code>, this will have no
|
||||
effect.
|
||||
</p>
|
||||
|
||||
<span class="nv">mappings = </span><span class="s">""</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
add: (sourceLocation, generatedLocation, options = {}) ->
|
||||
[line, column] = generatedLocation
|
||||
lineMap = (<span class="property">@lines</span>[line] <span class="keyword">or</span>= <span class="keyword">new</span> LineMap(line))
|
||||
lineMap.add column, sourceLocation, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<p>Look up the original position of a given <code>line</code> and <code>column</code> in the generated
|
||||
code.
|
||||
</p>
|
||||
|
||||
<span class="nx">sourceMap</span><span class="p">.</span><span class="nx">forEachMapping</span> <span class="nf">(mapping) -></span>
|
||||
<span class="k">while</span> <span class="nx">writingGeneratedLine</span> <span class="o"><</span> <span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedLine</span>
|
||||
<span class="nv">lastGeneratedColumnWritten = </span><span class="mi">0</span>
|
||||
<span class="nv">needComma = </span><span class="kc">no</span>
|
||||
<span class="nx">mappings</span> <span class="o">+=</span> <span class="s">";"</span>
|
||||
<span class="nx">writingGeneratedLine</span><span class="o">++</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">¶</a> </div> <p>Write a comma if we've already written a segment on this line.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">needComma</span>
|
||||
<span class="nx">mappings</span> <span class="o">+=</span> <span class="s">","</span>
|
||||
<span class="nv">needComma = </span><span class="kc">no</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">¶</a> </div> <p>Write the next segment.
|
||||
Segments can be 1, 4, or 5 values. If just one, then it is a generated column which
|
||||
doesn't match anything in the source code.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
sourceLocation: ([line, column]) ->
|
||||
line-- <span class="keyword">until</span> (lineMap = <span class="property">@lines</span>[line]) <span class="keyword">or</span> (line <= <span class="number">0</span>)
|
||||
lineMap <span class="keyword">and</span> lineMap.sourceLocation column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap for-h2">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<h2>V3 SourceMap Generation</h2>
|
||||
|
||||
<p>Fields are all zero-based, and relative to the previous occurence unless otherwise noted:
|
||||
* starting-column in generated source, relative to previous occurence for the current line.
|
||||
* index into the "sources" list
|
||||
* starting line in the original source
|
||||
* starting column in the original source
|
||||
* index into the "names" list associated with this segment.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">¶</a> </div> <p>Add the generated start-column</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedColumn</span> <span class="o">-</span> <span class="nx">lastGeneratedColumnWritten</span><span class="p">)</span>
|
||||
<span class="nv">lastGeneratedColumnWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">generatedColumn</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">¶</a> </div> <p>Add the index into the sources list</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">¶</a> </div> <p>Add the source start-line</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceLine</span> <span class="o">-</span> <span class="nx">lastSourceLineWritten</span><span class="p">)</span>
|
||||
<span class="nv">lastSourceLineWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceLine</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">¶</a> </div> <p>Add the source start-column</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">mappings</span> <span class="o">+=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">vlqEncodeValue</span><span class="p">(</span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceColumn</span> <span class="o">-</span> <span class="nx">lastSourceColumnWritten</span><span class="p">)</span>
|
||||
<span class="nv">lastSourceColumnWritten = </span><span class="nx">mapping</span><span class="p">.</span><span class="nx">sourceColumn</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">¶</a> </div> <p>TODO: Do we care about symbol names for CoffeeScript? Probably not.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">needComma = </span><span class="kc">yes</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<p>Builds up a V3 source map, returning the generated JSON as a string.
|
||||
<code>options.sourceRoot</code> may be used to specify the sourceRoot written to the source
|
||||
map. Also, <code>options.sourceFiles</code> and <code>options.generatedFile</code> may be passed to
|
||||
set "sources" and "file", respectively.
|
||||
</p>
|
||||
|
||||
<span class="nv">answer = </span><span class="p">{</span>
|
||||
<span class="nv">version: </span><span class="mi">3</span>
|
||||
<span class="nv">file: </span><span class="nx">generatedFile</span>
|
||||
<span class="nv">sourceRoot: </span><span class="s">""</span>
|
||||
<span class="nv">sources: </span><span class="k">if</span> <span class="nx">sourceFile</span> <span class="k">then</span> <span class="p">[</span><span class="nx">sourceFile</span><span class="p">]</span> <span class="k">else</span> <span class="p">[]</span>
|
||||
<span class="nv">names: </span><span class="p">[]</span>
|
||||
<span class="nx">mappings</span>
|
||||
<span class="p">}</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
generate: (options = {}, code = <span class="literal">null</span>) ->
|
||||
writingline = <span class="number">0</span>
|
||||
lastColumn = <span class="number">0</span>
|
||||
lastSourceLine = <span class="number">0</span>
|
||||
lastSourceColumn = <span class="number">0</span>
|
||||
needComma = <span class="literal">no</span>
|
||||
buffer = <span class="string">""</span>
|
||||
|
||||
<span class="k">return</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span> <span class="nx">answer</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="mi">2</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">¶</a> </div> <p>Load a SourceMap from a JSON string. Returns the SourceMap object.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.loadV3SourceMap = </span><span class="nf">(sourceMap) -></span>
|
||||
<span class="nx">todo</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">¶</a> </div> <h3>Base64 encoding helpers</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">BASE64_CHARS = </span><span class="s">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
|
||||
<span class="nv">MAX_BASE64_VALUE = </span><span class="nx">BASE64_CHARS</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
|
||||
<span class="keyword">for</span> lineMap, lineNumber <span class="keyword">in</span> <span class="property">@lines</span> <span class="keyword">when</span> lineMap
|
||||
<span class="keyword">for</span> mapping <span class="keyword">in</span> lineMap.columns <span class="keyword">when</span> mapping
|
||||
<span class="keyword">while</span> writingline < mapping.line
|
||||
lastColumn = <span class="number">0</span>
|
||||
needComma = <span class="literal">no</span>
|
||||
buffer += <span class="string">";"</span>
|
||||
writingline++</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Write a comma if we've already written a segment on this line.
|
||||
</p>
|
||||
|
||||
<span class="nv">encodeBase64Char = </span><span class="nf">(value) -></span>
|
||||
<span class="k">if</span> <span class="nx">value</span> <span class="o">></span> <span class="nx">MAX_BASE64_VALUE</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Cannot encode value </span><span class="si">#{</span><span class="nx">value</span><span class="si">}</span><span class="s"> > </span><span class="si">#{</span><span class="nx">MAX_BASE64_VALUE</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="k">else</span> <span class="k">if</span> <span class="nx">value</span> <span class="o"><</span> <span class="mi">0</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Cannot encode value </span><span class="si">#{</span><span class="nx">value</span><span class="si">}</span><span class="s"> < 0"</span>
|
||||
<span class="nx">BASE64_CHARS</span><span class="p">[</span><span class="nx">value</span><span class="p">]</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
<span class="keyword">if</span> needComma
|
||||
buffer += <span class="string">","</span>
|
||||
needComma = <span class="literal">no</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>Write the next segment. Segments can be 1, 4, or 5 values. If just one, then it
|
||||
is a generated column which doesn't match anything in the source code.
|
||||
</p>
|
||||
|
||||
<span class="nv">decodeBase64Char = </span><span class="nf">(char) -></span>
|
||||
<span class="nv">value = </span><span class="nx">BASE64_CHARS</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">char</span>
|
||||
<span class="k">if</span> <span class="nx">value</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">"Invalid Base 64 character: </span><span class="si">#{</span><span class="nx">char</span><span class="si">}</span><span class="s">"</span>
|
||||
<span class="nx">value</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">¶</a> </div> <h3>Base 64 VLQ encoding/decoding helpers</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">¶</a> </div> <p>Note that SourceMap VLQ encoding is "backwards". MIDI style VLQ encoding puts the
|
||||
most-significant-bit (MSB) from the original value into the MSB of the VLQ encoded value
|
||||
(see http://en.wikipedia.org/wiki/File:Uintvar_coding.svg). SourceMap VLQ does things
|
||||
the other way around, with the least significat four bits of the original value encoded
|
||||
into the first byte of the VLQ encoded value.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">VLQ_SHIFT = </span><span class="mi">5</span>
|
||||
<span class="nv">VLQ_CONTINUATION_BIT = </span><span class="mi">1</span> <span class="o"><<</span> <span class="nx">VLQ_SHIFT</span> <span class="c1"># 0010 0000</span>
|
||||
<span class="nv">VLQ_VALUE_MASK = </span><span class="nx">VLQ_CONTINUATION_BIT</span> <span class="o">-</span> <span class="mi">1</span> <span class="c1"># 0001 1111</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">¶</a> </div> <p>Encode a value as Base 64 VLQ.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.vlqEncodeValue = </span><span class="nf">(value) -></span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">¶</a> </div> <p>Least significant bit represents the sign.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">signBit = </span><span class="k">if</span> <span class="nx">value</span> <span class="o"><</span> <span class="mi">0</span> <span class="k">then</span> <span class="mi">1</span> <span class="k">else</span> <span class="mi">0</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">¶</a> </div> <p>Next bits are the actual value</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">valueToEncode = </span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="o"><<</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nx">signBit</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<p>The starting column in the generated source, relative to any previous recorded
|
||||
column for the current line:
|
||||
</p>
|
||||
|
||||
<span class="nv">answer = </span><span class="s">""</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">¶</a> </div> <p>Make sure we encode at least one character, even if valueToEncode is 0.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">while</span> <span class="nx">valueToEncode</span> <span class="o">||</span> <span class="o">!</span><span class="nx">answer</span>
|
||||
<span class="nv">nextVlqChunk = </span><span class="nx">valueToEncode</span> <span class="o">&</span> <span class="nx">VLQ_VALUE_MASK</span>
|
||||
<span class="nv">valueToEncode = </span><span class="nx">valueToEncode</span> <span class="o">>></span> <span class="nx">VLQ_SHIFT</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
buffer += <span class="property">@encodeVlq</span> mapping.column - lastColumn
|
||||
lastColumn = mapping.column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<p>The index into the list of sources:
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="nx">valueToEncode</span>
|
||||
<span class="nx">nextVlqChunk</span> <span class="o">|=</span> <span class="nx">VLQ_CONTINUATION_BIT</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
buffer += <span class="property">@encodeVlq</span> <span class="number">0</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>The starting line in the original source, relative to the previous source line.
|
||||
</p>
|
||||
|
||||
<span class="nx">answer</span> <span class="o">+=</span> <span class="nx">encodeBase64Char</span><span class="p">(</span><span class="nx">nextVlqChunk</span><span class="p">)</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
buffer += <span class="property">@encodeVlq</span> mapping.sourceLine - lastSourceLine
|
||||
lastSourceLine = mapping.sourceLine</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
</div>
|
||||
<p>The starting column in the original source, relative to the previous column.
|
||||
</p>
|
||||
|
||||
<span class="k">return</span> <span class="nx">answer</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">¶</a> </div> <p>Decode a Base 64 VLQ value.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
buffer += <span class="property">@encodeVlq</span> mapping.sourceColumn - lastSourceColumn
|
||||
lastSourceColumn = mapping.sourceColumn
|
||||
needComma = <span class="literal">yes</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Produce the canonical JSON object format for a "v3" source map.
|
||||
</p>
|
||||
|
||||
<p>Returns <code>[value, consumed]</code> where <code>value</code> is the decoded value, and <code>consumed</code> is the number
|
||||
of characters consumed from <code>str</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.vlqDecodeValue = </span><span class="nf">(str, offset=0) -></span>
|
||||
<span class="nv">position = </span><span class="nx">offset</span>
|
||||
<span class="nv">done = </span><span class="kc">false</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
v3 =
|
||||
version: <span class="number">3</span>
|
||||
file: options.generatedFile <span class="keyword">or</span> <span class="string">''</span>
|
||||
sourceRoot: options.sourceRoot <span class="keyword">or</span> <span class="string">''</span>
|
||||
sources: options.sourceFiles <span class="keyword">or</span> [<span class="string">''</span>]
|
||||
names: []
|
||||
mappings: buffer
|
||||
|
||||
<span class="nv">value = </span><span class="mi">0</span>
|
||||
<span class="nv">continuationShift = </span><span class="mi">0</span>
|
||||
v3.sourcesContent = [code] <span class="keyword">if</span> options.inline
|
||||
|
||||
<span class="k">while</span> <span class="o">!</span><span class="nx">done</span>
|
||||
<span class="nv">nextVlqChunk = </span><span class="nx">decodeBase64Char</span><span class="p">(</span><span class="nx">str</span><span class="p">[</span><span class="nx">position</span><span class="p">])</span>
|
||||
<span class="nx">position</span> <span class="o">+=</span> <span class="mi">1</span>
|
||||
JSON.stringify v3, <span class="literal">null</span>, <span class="number">2</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap for-h2">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
</div>
|
||||
<h2>Base64 VLQ Encoding</h2>
|
||||
|
||||
<span class="nv">nextChunkValue = </span><span class="nx">nextVlqChunk</span> <span class="o">&</span> <span class="nx">VLQ_VALUE_MASK</span>
|
||||
<span class="nx">value</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">nextChunkValue</span> <span class="o"><<</span> <span class="nx">continuationShift</span><span class="p">)</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Note that SourceMap VLQ encoding is "backwards". MIDI-style VLQ encoding puts
|
||||
the most-significant-bit (MSB) from the original value into the MSB of the VLQ
|
||||
encoded value (see <a href="http://en.wikipedia.org/wiki/File:Uintvar_coding.svg">Wikipedia</a>).
|
||||
SourceMap VLQ does things the other way around, with the least significat four
|
||||
bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="o">!</span><span class="p">(</span><span class="nx">nextVlqChunk</span> <span class="o">&</span> <span class="nx">VLQ_CONTINUATION_BIT</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">¶</a> </div> <p>We'll be done after this character.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">done = </span><span class="kc">true</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">¶</a> </div> <p>Bits are encoded least-significant first (opposite of MIDI VLQ). Increase the
|
||||
continuationShift, so the next byte will end up where it should in the value.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">continuationShift</span> <span class="o">+=</span> <span class="nx">VLQ_SHIFT</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
VLQ_SHIFT = <span class="number">5</span>
|
||||
VLQ_CONTINUATION_BIT = <span class="number">1</span> << VLQ_SHIFT <span class="comment"># 0010 0000</span>
|
||||
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - <span class="number">1</span> <span class="comment"># 0001 1111</span>
|
||||
|
||||
<span class="nv">consumed = </span><span class="nx">position</span> <span class="o">-</span> <span class="nx">offset</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">¶</a> </div> <p>Least significant bit represents the sign.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">signBit = </span><span class="nx">value</span> <span class="o">&</span> <span class="mi">1</span>
|
||||
<span class="nv">value = </span><span class="nx">value</span> <span class="o">>></span> <span class="mi">1</span>
|
||||
encodeVlq: (value) ->
|
||||
answer = <span class="string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
</div>
|
||||
<p>Least significant bit represents the sign.
|
||||
</p>
|
||||
|
||||
<span class="k">if</span> <span class="nx">signBit</span> <span class="k">then</span> <span class="nv">value = </span><span class="o">-</span><span class="nx">value</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> signBit = <span class="keyword">if</span> value < <span class="number">0</span> <span class="keyword">then</span> <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
<p>The next bits are the actual value.
|
||||
</p>
|
||||
|
||||
<span class="k">return</span> <span class="p">[</span><span class="nx">value</span><span class="p">,</span> <span class="nx">consumed</span><span class="p">]</span>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> valueToEncode = (Math.abs(value) << <span class="number">1</span>) + signBit</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
</div>
|
||||
<p>Make sure we encode at least one character, even if valueToEncode is 0.
|
||||
</p>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">while</span> valueToEncode <span class="keyword">or</span> <span class="keyword">not</span> answer
|
||||
nextChunk = valueToEncode & VLQ_VALUE_MASK
|
||||
valueToEncode = valueToEncode >> VLQ_SHIFT
|
||||
nextChunk |= VLQ_CONTINUATION_BIT <span class="keyword">if</span> valueToEncode
|
||||
answer += <span class="property">@encodeBase64</span> nextChunk
|
||||
|
||||
answer</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-28">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap for-h2">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
</div>
|
||||
<h2>Regular Base64 Encoding</h2>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-29">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-29">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
BASE64_CHARS = <span class="string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
|
||||
|
||||
encodeBase64: (value) ->
|
||||
BASE64_CHARS[value] <span class="keyword">or</span> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cannot Base64 encode value: <span class="subst">#{value}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-30">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-30">¶</a>
|
||||
</div>
|
||||
<p>Our API for source maps is just the <code>SourceMap</code> class.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
module.exports = SourceMap</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,29 +1,3 @@
|
||||
<%
|
||||
require 'uv'
|
||||
require 'json'
|
||||
@counter = 0
|
||||
def code_for(file, executable=false, show_load=true)
|
||||
@counter += 1
|
||||
return '' unless File.exists?("documentation/js/#{file}.js")
|
||||
cs = File.read("documentation/coffee/#{file}.coffee")
|
||||
js = File.read("documentation/js/#{file}.js")
|
||||
js = js.sub(/^\/\/ generated.*?\n/i, '')
|
||||
cshtml = Uv.parse(cs, 'xhtml', 'coffeescript', false, 'idle', false)
|
||||
jshtml = Uv.parse(js, 'xhtml', 'javascript', false, 'idle', false)
|
||||
append = executable == true ? '' : "alert(#{executable});"
|
||||
if executable and executable != true
|
||||
cs.sub!(/(\S)\s*\Z/m, "\\1\n\nalert #{executable}")
|
||||
end
|
||||
run = executable == true ? 'run' : "run: #{executable}"
|
||||
name = "example#{@counter}"
|
||||
script = "<script>window.#{name} = #{cs.to_json}</script>"
|
||||
import = show_load ? "<div class='minibutton load' onclick='javascript: loadConsole(#{name});'>load</div>" : ''
|
||||
button = executable ? "<div class='minibutton ok' onclick='javascript: #{js};#{append}'>#{run}</div>" : ''
|
||||
"<div class='code'>#{cshtml}#{jshtml}#{script}#{import}#{button}<br class='clear' /></div>"
|
||||
end
|
||||
%>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -31,7 +5,7 @@
|
||||
<title>CoffeeScript</title>
|
||||
<link rel="canonical" href="http://coffeescript.org" />
|
||||
<link rel="stylesheet" type="text/css" href="documentation/css/docs.css" />
|
||||
<link rel="stylesheet" type="text/css" href="documentation/css/idle.css" />
|
||||
<link rel="stylesheet" type="text/css" href="documentation/css/tomorrow.css" />
|
||||
<link rel="shortcut icon" href="documentation/images/favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
@@ -131,15 +105,13 @@
|
||||
compiles one-to-one into the equivalent JS, and there is
|
||||
no interpretation at runtime. You can use any existing JavaScript library
|
||||
seamlessly from CoffeeScript (and vice-versa). The compiled output is
|
||||
readable and pretty-printed, passes through
|
||||
<a href="http://www.javascriptlint.com/">JavaScript Lint</a>
|
||||
without warnings, will work in every JavaScript runtime, and tends
|
||||
readable and pretty-printed, will work in every JavaScript runtime, and tends
|
||||
to run as fast or faster than the equivalent handwritten JavaScript.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Latest Version:</b>
|
||||
<a href="http://github.com/jashkenas/coffee-script/tarball/1.6.1">1.6.1</a>
|
||||
<a href="http://github.com/jashkenas/coffee-script/tarball/1.7.0">1.7.0</a>
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
@@ -152,7 +124,7 @@ sudo npm install -g coffee-script</pre>
|
||||
|
||||
<p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p>
|
||||
|
||||
<%= code_for('overview', 'cubes', false) %>
|
||||
<%= codeFor('overview', 'cubes', false) %>
|
||||
|
||||
<h2>
|
||||
<span id="installation" class="bookmark"></span>
|
||||
@@ -266,16 +238,6 @@ sudo bin/cake install</pre>
|
||||
directly to <b>stdout</b>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>-l, --lint</code></td>
|
||||
<td>
|
||||
If the <tt>jsl</tt>
|
||||
(<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
|
||||
command is installed, use it
|
||||
to check the compilation of a CoffeeScript file. (Handy in
|
||||
conjunction with <br /> <tt>--watch</tt>)
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>-s, --stdio</code></td>
|
||||
<td>
|
||||
@@ -284,6 +246,14 @@ sudo bin/cake install</pre>
|
||||
<tt>cat src/cake.coffee | coffee -sc</tt>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>-l, --literate</code></td>
|
||||
<td>
|
||||
Parses the code as Literate CoffeeScript. You only need to specify
|
||||
this when passing in code directly over <b>stdio</b>, or using some sort
|
||||
of extension-less file name.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>-e, --eval</code></td>
|
||||
<td>
|
||||
@@ -291,13 +261,6 @@ sudo bin/cake install</pre>
|
||||
command line. For example:<br /><tt>coffee -e "console.log num for num in [10..1]"</tt>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>-r, --require</code></td>
|
||||
<td>
|
||||
Load a library before compiling or executing your script. Can be used
|
||||
to hook in to the compiler (to add Growl notifications, for example).
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>-b, --bare</code></td>
|
||||
<td>
|
||||
@@ -446,12 +409,12 @@ Expressions
|
||||
an arrow, and the function body. The empty function looks like this:
|
||||
<tt>-></tt>
|
||||
</p>
|
||||
<%= code_for('functions', 'cube(5)') %>
|
||||
<%= codeFor('functions', 'cube(5)') %>
|
||||
<p>
|
||||
Functions may also have default values for arguments. Override the default
|
||||
value by passing a non-null argument.
|
||||
Functions may also have default values for arguments, which will be used
|
||||
if the incoming argument is missing (<tt>null</tt> or <tt>undefined</tt>).
|
||||
</p>
|
||||
<%= code_for('default_args', 'fill("cup")') %>
|
||||
<%= codeFor('default_args', 'fill("cup")') %>
|
||||
|
||||
<p>
|
||||
<span id="objects_and_arrays" class="bookmark"></span>
|
||||
@@ -461,14 +424,14 @@ Expressions
|
||||
the commas are optional. Objects may be created using indentation instead
|
||||
of explicit braces, similar to <a href="http://yaml.org">YAML</a>.
|
||||
</p>
|
||||
<%= code_for('objects_and_arrays', 'song.join(" ... ")') %>
|
||||
<%= codeFor('objects_and_arrays', 'song.join(" ... ")') %>
|
||||
<p>
|
||||
In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
|
||||
of an object, without quoting them as strings. CoffeeScript notices reserved words
|
||||
used as keys in objects and quotes them for you, so you don't have to worry
|
||||
about it (say, when using jQuery).
|
||||
</p>
|
||||
<%= code_for('objects_reserved') %>
|
||||
<%= codeFor('objects_reserved') %>
|
||||
|
||||
<p>
|
||||
<span id="lexical-scope" class="bookmark"></span>
|
||||
@@ -477,7 +440,7 @@ Expressions
|
||||
are properly declared within lexical scope — you never need to write
|
||||
<tt>var</tt> yourself.
|
||||
</p>
|
||||
<%= code_for('scope', 'inner') %>
|
||||
<%= codeFor('scope', 'inner') %>
|
||||
<p>
|
||||
Notice how all of the variable declarations have been pushed up to
|
||||
the top of the closest scope, the first time they appear.
|
||||
@@ -522,7 +485,7 @@ Expressions
|
||||
is no explicit ternary statement in CoffeeScript — you simply use
|
||||
a regular <b>if</b> statement on a single line.
|
||||
</p>
|
||||
<%= code_for('conditionals') %>
|
||||
<%= codeFor('conditionals') %>
|
||||
|
||||
<p>
|
||||
<span id="splats" class="bookmark"></span>
|
||||
@@ -532,7 +495,7 @@ Expressions
|
||||
splats <tt>...</tt>, both for function definition as well as invocation,
|
||||
making variable numbers of arguments a little bit more palatable.
|
||||
</p>
|
||||
<%= code_for('splats', true) %>
|
||||
<%= codeFor('splats', true) %>
|
||||
|
||||
<p>
|
||||
<span id="loops" class="bookmark"></span>
|
||||
@@ -543,7 +506,7 @@ Expressions
|
||||
Unlike for loops, array comprehensions are expressions, and can be returned
|
||||
and assigned.
|
||||
</p>
|
||||
<%= code_for('array_comprehensions') %>
|
||||
<%= codeFor('array_comprehensions') %>
|
||||
<p>
|
||||
Comprehensions should be able to handle most places where you otherwise
|
||||
would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>, for example:
|
||||
@@ -552,7 +515,7 @@ Expressions
|
||||
in fixed-size increments, you can use a range to specify the start and
|
||||
end of your comprehension.
|
||||
</p>
|
||||
<%= code_for('range_comprehensions', 'countdown') %>
|
||||
<%= codeFor('range_comprehensions', 'countdown') %>
|
||||
<p>
|
||||
Note how because we are assigning the value of the comprehensions to a
|
||||
variable in the example above, CoffeeScript is collecting the result of
|
||||
@@ -572,7 +535,7 @@ Expressions
|
||||
an object. Use <tt>of</tt> to signal comprehension over the properties of
|
||||
an object instead of the values in an array.
|
||||
</p>
|
||||
<%= code_for('object_comprehensions', 'ages.join(", ")') %>
|
||||
<%= codeFor('object_comprehensions', 'ages.join(", ")') %>
|
||||
<p>
|
||||
If you would like to iterate over just the keys that are defined on the
|
||||
object itself, by adding a <tt>hasOwnProperty</tt>
|
||||
@@ -585,7 +548,7 @@ Expressions
|
||||
as an expression, returning an array containing the result of each iteration
|
||||
through the loop.
|
||||
</p>
|
||||
<%= code_for('while', 'lyrics.join("\n")') %>
|
||||
<%= codeFor('while', 'lyrics.join("\n")') %>
|
||||
<p>
|
||||
For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>,
|
||||
and the <b>loop</b> keyword is equivalent to <tt>while true</tt>.
|
||||
@@ -597,7 +560,7 @@ Expressions
|
||||
provides the <tt>do</tt> keyword, which immediately invokes a passed function,
|
||||
forwarding any arguments.
|
||||
</p>
|
||||
<%= code_for('do') %>
|
||||
<%= codeFor('do') %>
|
||||
|
||||
<p>
|
||||
<span id="slices" class="bookmark"></span>
|
||||
@@ -608,12 +571,12 @@ Expressions
|
||||
Slices indices have useful defaults. An omitted first index defaults to
|
||||
zero and an omitted second index defaults to the size of the array.
|
||||
</p>
|
||||
<%= code_for('slices', 'middle') %>
|
||||
<%= codeFor('slices', 'middle') %>
|
||||
<p>
|
||||
The same syntax can be used with assignment to replace a segment of an array
|
||||
with new values, splicing it.
|
||||
</p>
|
||||
<%= code_for('splices', 'numbers') %>
|
||||
<%= codeFor('splices', 'numbers') %>
|
||||
<p>
|
||||
Note that JavaScript strings are immutable, and can't be spliced.
|
||||
</p>
|
||||
@@ -627,7 +590,7 @@ Expressions
|
||||
pushed down into each possible branch of execution in the function
|
||||
below.
|
||||
</p>
|
||||
<%= code_for('expressions', 'eldest') %>
|
||||
<%= codeFor('expressions', 'eldest') %>
|
||||
<p>
|
||||
Even though functions will always return their final value, it's both possible
|
||||
and encouraged to return early from a function body writing out the explicit
|
||||
@@ -637,19 +600,19 @@ Expressions
|
||||
Because variable declarations occur at the top of scope, assignment can
|
||||
be used within expressions, even for variables that haven't been seen before:
|
||||
</p>
|
||||
<%= code_for('expressions_assignment', 'six') %>
|
||||
<%= codeFor('expressions_assignment', 'six') %>
|
||||
<p>
|
||||
Things that would otherwise be statements in JavaScript, when used
|
||||
as part of an expression in CoffeeScript, are converted into expressions
|
||||
by wrapping them in a closure. This lets you do useful things, like assign
|
||||
the result of a comprehension to a variable:
|
||||
</p>
|
||||
<%= code_for('expressions_comprehension', 'globals') %>
|
||||
<%= codeFor('expressions_comprehension', 'globals') %>
|
||||
<p>
|
||||
As well as silly things, like passing a <b>try/catch</b> statement directly
|
||||
into a function call:
|
||||
</p>
|
||||
<%= code_for('expressions_try', true) %>
|
||||
<%= codeFor('expressions_try', true) %>
|
||||
<p>
|
||||
There are a handful of statements in JavaScript that can't be meaningfully
|
||||
converted into expressions, namely <tt>break</tt>, <tt>continue</tt>,
|
||||
@@ -693,7 +656,9 @@ Expressions
|
||||
You can use <tt>in</tt> to test for array presence, and <tt>of</tt> to
|
||||
test for JavaScript object-key presence.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To simplify math expressions, <tt>**</tt> can be used for exponentiation, <tt>//</tt> performs integer division and <tt>%%</tt> provides true mathematical modulo.
|
||||
</p>
|
||||
<p>
|
||||
All together now:
|
||||
</p>
|
||||
@@ -705,14 +670,17 @@ Expressions
|
||||
<tr><td><tt>not</tt></td><td><tt>!</tt></td></tr>
|
||||
<tr><td><tt>and</tt></td><td><tt>&&</tt></td></tr>
|
||||
<tr><td><tt>or</tt></td><td><tt>||</tt></td></tr>
|
||||
<tr><td><tt>true, yes, on</tt></td><td><tt>true</tt></td></tr>
|
||||
<tr><td><tt>false, no, off</tt></td><td><tt>false</tt></td></tr>
|
||||
<tr><td><tt>@, this</tt></td><td><tt>this</tt></td></tr>
|
||||
<tr><td><tt>true</tt>, <tt>yes</tt>, <tt>on</tt></td><td><tt>true</tt></td></tr>
|
||||
<tr><td><tt>false</tt>, <tt>no</tt>, <tt>off</tt></td><td><tt>false</tt></td></tr>
|
||||
<tr><td><tt>@</tt>, <tt>this</tt></td><td><tt>this</tt></td></tr>
|
||||
<tr><td><tt>of</tt></td><td><tt>in</tt></td></tr>
|
||||
<tr><td><tt>in</tt></td><td><i><small>no JS equivalent</small></i></td></tr>
|
||||
<tr><td><tt>a ** b</tt></td><td><tt>Math.pow(a, b)</tt></td></tr>
|
||||
<tr><td><tt>a // b</tt></td><td><tt>Math.floor(a / b)</tt></td></tr>
|
||||
<tr><td><tt>a %% b</tt></td><td><tt>(a % b + b) % b</tt></td></tr>
|
||||
</table>
|
||||
|
||||
<%= code_for('aliases') %>
|
||||
<%= codeFor('aliases') %>
|
||||
|
||||
<p>
|
||||
<b class="header">The Existential Operator</b>
|
||||
@@ -726,7 +694,7 @@ Expressions
|
||||
It can also be used for safer conditional assignment than <tt>||=</tt>
|
||||
provides, for cases where you may be handling numbers or strings.
|
||||
</p>
|
||||
<%= code_for('existence', 'footprints') %>
|
||||
<%= codeFor('existence', 'footprints') %>
|
||||
<p>
|
||||
The accessor variant of the existential operator <tt>?.</tt> can be used to soak
|
||||
up null references in a chain of properties. Use it instead
|
||||
@@ -735,7 +703,7 @@ Expressions
|
||||
result, if the chain is broken, <b>undefined</b> is returned instead of
|
||||
the <b>TypeError</b> that would be raised otherwise.
|
||||
</p>
|
||||
<%= code_for('soaks') %>
|
||||
<%= codeFor('soaks') %>
|
||||
<p>
|
||||
Soaking up nulls is similar to Ruby's
|
||||
<a href="http://andand.rubyforge.org/">andand gem</a>, and to the
|
||||
@@ -768,7 +736,7 @@ Expressions
|
||||
Constructor functions are named, to better support helpful stack traces.
|
||||
In the first class in the example below, <tt>this.constructor.name is "Animal"</tt>.
|
||||
</p>
|
||||
<%= code_for('classes', true) %>
|
||||
<%= codeFor('classes', true) %>
|
||||
<p>
|
||||
If structuring your prototypes classically isn't your cup of tea, CoffeeScript
|
||||
provides a couple of lower-level conveniences. The <tt>extends</tt> operator
|
||||
@@ -777,7 +745,7 @@ Expressions
|
||||
quick access to an object's prototype; and <tt>super()</tt>
|
||||
is converted into a call against the immediate ancestor's method of the same name.
|
||||
</p>
|
||||
<%= code_for('prototypes', '"one_two".dasherize()') %>
|
||||
<%= codeFor('prototypes', '"one_two".dasherize()') %>
|
||||
<p>
|
||||
Finally, class definitions are blocks of executable code, which make for interesting
|
||||
metaprogramming possibilities. Because in the context of a class definition,
|
||||
@@ -797,21 +765,30 @@ Expressions
|
||||
on the right to the variables on the left. In the simplest case, it can be
|
||||
used for parallel assignment:
|
||||
</p>
|
||||
<%= code_for('parallel_assignment', 'theBait') %>
|
||||
<%= codeFor('parallel_assignment', 'theBait') %>
|
||||
<p>
|
||||
But it's also helpful for dealing with functions that return multiple
|
||||
values.
|
||||
</p>
|
||||
<%= code_for('multiple_return_values', 'forecast') %>
|
||||
<%= codeFor('multiple_return_values', 'forecast') %>
|
||||
<p>
|
||||
Destructuring assignment can be used with any depth of array and object nesting,
|
||||
to help pull out deeply nested properties.
|
||||
</p>
|
||||
<%= code_for('object_extraction', 'name + " — " + street') %>
|
||||
<%= codeFor('object_extraction', '"name + "-" + street"') %>
|
||||
<p>
|
||||
Destructuring assignment can even be combined with splats.
|
||||
</p>
|
||||
<%= code_for('patterns_and_splats', 'contents.join("")') %>
|
||||
<%= codeFor('patterns_and_splats', 'contents.join("")') %>
|
||||
<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.
|
||||
</p>
|
||||
<%= codeFor('expansion', '"first + " " + last"') %>
|
||||
<p>
|
||||
Destructuring assignment is also useful when combined with class constructors
|
||||
to assign properties to your instance from an options object passed to the constructor.
|
||||
</p>
|
||||
<%= codeFor('constructor_destructuring', 'tim.age') %>
|
||||
|
||||
<p>
|
||||
<span id="fat-arrow" class="bookmark"></span>
|
||||
@@ -831,7 +808,7 @@ Expressions
|
||||
to use with <tt>bind</tt>. Functions created with the fat arrow are able to access
|
||||
properties of the <tt>this</tt> where they're defined.
|
||||
</p>
|
||||
<%= code_for('fat_arrow') %>
|
||||
<%= codeFor('fat_arrow') %>
|
||||
<p>
|
||||
If we had used <tt>-></tt> in the callback above, <tt>@customer</tt> would
|
||||
have referred to the undefined "customer" property of the DOM element,
|
||||
@@ -850,7 +827,7 @@ Expressions
|
||||
snippets of JavaScript within your CoffeeScript, you can
|
||||
use backticks to pass it straight through.
|
||||
</p>
|
||||
<%= code_for('embedded', 'hi()') %>
|
||||
<%= codeFor('embedded', 'hi()') %>
|
||||
|
||||
<p>
|
||||
<span id="switch" class="bookmark"></span>
|
||||
@@ -867,7 +844,12 @@ Expressions
|
||||
values for each <b>when</b> clause. If any of the values match, the clause
|
||||
runs.
|
||||
</p>
|
||||
<%= code_for('switch') %>
|
||||
<%= codeFor('switch') %>
|
||||
|
||||
<p>
|
||||
Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains.
|
||||
</p>
|
||||
<%= codeFor('switch_with_no_expression') %>
|
||||
|
||||
<p>
|
||||
<span id="try" class="bookmark"></span>
|
||||
@@ -875,7 +857,7 @@ Expressions
|
||||
Try/catch statements are just about the same as JavaScript (although
|
||||
they work as expressions).
|
||||
</p>
|
||||
<%= code_for('try') %>
|
||||
<%= codeFor('try') %>
|
||||
|
||||
<p>
|
||||
<span id="comparisons" class="bookmark"></span>
|
||||
@@ -885,7 +867,7 @@ Expressions
|
||||
from Python — making it easy to test if a value falls within a
|
||||
certain range.
|
||||
</p>
|
||||
<%= code_for('comparisons', 'healthy') %>
|
||||
<%= codeFor('comparisons', 'healthy') %>
|
||||
|
||||
<p>
|
||||
<span id="strings" class="bookmark"></span>
|
||||
@@ -894,18 +876,18 @@ Expressions
|
||||
strings allow for interpolated values, using <tt>#{ ... }</tt>,
|
||||
and single-quoted strings are literal.
|
||||
</p>
|
||||
<%= code_for('interpolation', 'sentence') %>
|
||||
<%= codeFor('interpolation', 'sentence') %>
|
||||
<p>
|
||||
Multiline strings are allowed in CoffeeScript.
|
||||
Multiline strings are allowed in CoffeeScript. Lines are joined by a single space unless they end with a backslash. Indentation is ignored.
|
||||
</p>
|
||||
<%= code_for('strings', 'mobyDick') %>
|
||||
<%= codeFor('strings', 'mobyDick') %>
|
||||
<p>
|
||||
Block strings can be used to hold formatted or indentation-sensitive text
|
||||
(or, if you just don't feel like escaping quotes and apostrophes). The
|
||||
indentation level that begins the block is maintained throughout, so
|
||||
you can keep it all aligned with the body of your code.
|
||||
</p>
|
||||
<%= code_for('heredocs', 'html') %>
|
||||
<%= codeFor('heredocs', 'html') %>
|
||||
<p>
|
||||
Double-quoted block strings, like other double-quoted strings, allow interpolation.
|
||||
</p>
|
||||
@@ -915,18 +897,18 @@ Expressions
|
||||
the top of a file. Block comments, which mirror the syntax for block strings,
|
||||
are preserved in the generated code.
|
||||
</p>
|
||||
<%= code_for('block_comment') %>
|
||||
<%= codeFor('block_comment') %>
|
||||
|
||||
<p>
|
||||
<span id="regexes" class="bookmark"></span>
|
||||
<b class="header">Block Regular Expressions</b>
|
||||
Similar to block strings and comments, CoffeeScript supports block regexes —
|
||||
extended regular expressions that ignore internal whitespace and can contain
|
||||
comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeSctipt's
|
||||
comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeScript's
|
||||
block regexes are delimited by <tt>///</tt> and go a long way towards making complex
|
||||
regular expressions readable. To quote from the CoffeeScript source:
|
||||
</p>
|
||||
<%= code_for('heregexes') %>
|
||||
<%= codeFor('heregexes') %>
|
||||
|
||||
|
||||
<h2>
|
||||
@@ -952,7 +934,7 @@ Expressions
|
||||
be made available in the <tt>options</tt> object. Here's a task that uses
|
||||
the Node.js API to rebuild CoffeeScript's parser:
|
||||
</p>
|
||||
<%= code_for('cake_tasks') %>
|
||||
<%= codeFor('cake_tasks') %>
|
||||
<p>
|
||||
If you need to invoke one task before another — for example, running
|
||||
<tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function:
|
||||
@@ -1060,6 +1042,16 @@ Expressions
|
||||
is a succinct and freely downloadable guide to building testable
|
||||
applications with CoffeeScript and Jasmine.
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://www.packtpub.com/coffeescript-application-development/book">CoffeeScript Application Development</a>
|
||||
is a new book from Packt Publishing that introduces CoffeeScript while
|
||||
walking through the process of building a demonstration web application.
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://www.manning.com/lee/">CoffeeScript in Action</a>
|
||||
is a new book from Manning Publications that covers CoffeeScript syntax, composition techniques
|
||||
and application development.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>
|
||||
@@ -1165,6 +1157,13 @@ Expressions
|
||||
<a href="http://github.com/jashkenas/coffee-script/wiki/FAQ">The FAQ</a><br />
|
||||
Perhaps your CoffeeScript-related question has been asked before. Check the FAQ first.
|
||||
</li>
|
||||
<li>
|
||||
<a href="http://js2coffee.org">JS2Coffee</a><br />
|
||||
Is a very well done reverse JavaScript-to-CoffeeScript compiler. It's
|
||||
not going to be perfect (infer what your JavaScript classes are, when
|
||||
you need bound functions, and so on...) — but it's a great starting
|
||||
point for converting simple scripts.
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/jashkenas/coffee-script/downloads">High-Rez Logo</a><br />
|
||||
The CoffeeScript logo is available in Illustrator, EPS and PSD formats, for use
|
||||
@@ -1192,6 +1191,105 @@ Expressions
|
||||
Change Log
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">
|
||||
<a href="https://github.com/jashkenas/coffee-script/compare/1.6.3...1.7.0">1.7.0</a>
|
||||
<span class="timestamp"> – <small>January 28, 2014</small></span>
|
||||
</b>
|
||||
<ul>
|
||||
<li>
|
||||
When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with <tt>require 'coffee-script/register'</tt> or <tt>CoffeeScript.register()</tt>. Also for configuration such as Mocha's, use <b>coffee-script/register</b>.
|
||||
</li>
|
||||
<li>
|
||||
Improved error messages, source maps and stack traces. Source maps now use the updated <tt>//#</tt> syntax.
|
||||
</li>
|
||||
<li>
|
||||
Leading <tt>.</tt> now closes all open calls, allowing for simpler chaining syntax.
|
||||
</li>
|
||||
</ul>
|
||||
<%= codeFor('chaining') %>
|
||||
<ul>
|
||||
<li>
|
||||
Added <tt>**</tt>, <tt>//</tt> and <tt>%%</tt> operators and <tt>...</tt> expansion in parameter lists and destructuring expressions.
|
||||
</li>
|
||||
<li>
|
||||
Multiline strings are now joined by a single space and ignore all indentation. A backslash at the end of a line can denote the amount of whitespace between lines, in both strings and heredocs. Backslashes correctly escape whitespace in block regexes.
|
||||
</li>
|
||||
<li>
|
||||
Closing brackets can now be indented and therefore no longer cause unexpected error.
|
||||
</li>
|
||||
<li>
|
||||
Several breaking compilation fixes. Non-callable literals (strings, numbers etc.) don't compile in a call now and multiple postfix conditionals compile properly. Postfix conditionals and loops always bind object literals. Conditional assignment compiles properly in subexpressions. <tt>super</tt> is disallowed outside of methods and works correctly inside <tt>for</tt> loops.
|
||||
</li>
|
||||
<li>
|
||||
Formatting of compiled block comments has been improved.
|
||||
</li>
|
||||
<li>
|
||||
No more <tt>-p</tt> folders on Windows.
|
||||
</li>
|
||||
<li>
|
||||
The <tt>options</tt> object passed to CoffeeScript is no longer mutated.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">
|
||||
<a href="https://github.com/jashkenas/coffee-script/compare/1.6.2...1.6.3">1.6.3</a>
|
||||
<span class="timestamp"> – <small>June 2, 2013</small></span>
|
||||
</b>
|
||||
<ul>
|
||||
<li>
|
||||
The CoffeeScript REPL now remembers your history between sessions.
|
||||
Just like a proper REPL should.
|
||||
</li>
|
||||
<li>
|
||||
You can now use <tt>require</tt> in Node to load <tt>.coffee.md</tt>
|
||||
Literate CoffeeScript files. In the browser,
|
||||
<tt>text/literate-coffeescript</tt> script tags.
|
||||
</li>
|
||||
<li>
|
||||
The old <tt>coffee --lint</tt> command has been removed. It was useful
|
||||
while originally working on the compiler, but has been surpassed by
|
||||
JSHint. You may now use <tt>-l</tt> to pass literate files in over
|
||||
<b>stdio</b>.
|
||||
</li>
|
||||
<li>
|
||||
Bugfixes for Windows path separators, <tt>catch</tt> without naming
|
||||
the error, and executable-class-bodies-with-
|
||||
prototypal-property-attachment.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">
|
||||
<a href="https://github.com/jashkenas/coffee-script/compare/1.6.1...1.6.2">1.6.2</a>
|
||||
<span class="timestamp"> – <small>March 18, 2013</small></span>
|
||||
</b>
|
||||
<ul>
|
||||
<li>
|
||||
Source maps have been used to provide automatic line-mapping when
|
||||
running CoffeeScript directly via the <tt>coffee</tt> command, and
|
||||
for automatic line-mapping when running CoffeeScript directly in the
|
||||
browser. Also, to provide better error messages for semantic errors
|
||||
thrown by the compiler —
|
||||
<a href="http://cl.ly/NdOA">with colors, even</a>.
|
||||
</li>
|
||||
<li>
|
||||
Improved support for mixed literate/vanilla-style CoffeeScript projects,
|
||||
and generating source maps for both at the same time.
|
||||
</li>
|
||||
<li>
|
||||
Fixes for <b>1.6.x</b> regressions with overriding inherited bound
|
||||
functions, and for Windows file path management.
|
||||
</li>
|
||||
<li>
|
||||
The <tt>coffee</tt> command can now correctly <tt>fork()</tt>
|
||||
both <tt>.coffee</tt> and <tt>.js</tt> files. (Requires Node.js 0.9+)
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b class="header" style="margin-top: 20px;">
|
||||
<a href="https://github.com/jashkenas/coffee-script/compare/1.5.0...1.6.1">1.6.1</a>
|
||||
@@ -1939,8 +2037,10 @@ Expressions
|
||||
else
|
||||
$(el).text window.compiledJS
|
||||
$('#error').hide()
|
||||
catch error
|
||||
$('#error').text(error.message).show()
|
||||
catch {location, message}
|
||||
if location?
|
||||
message = "Error on line #{location.first_line + 1}: #{message}"
|
||||
$('#error').text(message).show()
|
||||
|
||||
# Update permalink
|
||||
$('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}"
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var volume, winner;
|
||||
|
||||
if (ignition === true) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
|
||||
|
||||
_ref = ['toast', 'cheese', 'wine'];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
|
||||
/*
|
||||
CoffeeScript Compiler v1.6.1
|
||||
SkinnyMochaHalfCaffScript Compiler v1.0
|
||||
Released under the MIT License
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var fs;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
4
documentation/js/chaining.js
Normal file
4
documentation/js/chaining.js
Normal file
@@ -0,0 +1,4 @@
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
$('body').click(function(e) {
|
||||
return $('.box').fadeIn('fast').addClass('.active');
|
||||
}).css('background', 'white');
|
||||
@@ -1,10 +1,9 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var Animal, Horse, Snake, sam, tom,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Animal = (function() {
|
||||
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
}
|
||||
@@ -18,7 +17,6 @@ Animal = (function() {
|
||||
})();
|
||||
|
||||
Snake = (function(_super) {
|
||||
|
||||
__extends(Snake, _super);
|
||||
|
||||
function Snake() {
|
||||
@@ -35,7 +33,6 @@ Snake = (function(_super) {
|
||||
})(Animal);
|
||||
|
||||
Horse = (function(_super) {
|
||||
|
||||
__extends(Horse, _super);
|
||||
|
||||
function Horse() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var cholesterol, healthy;
|
||||
|
||||
cholesterol = 127;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var date, mood;
|
||||
|
||||
if (singing) {
|
||||
|
||||
15
documentation/js/constructor_destructuring.js
Normal file
15
documentation/js/constructor_destructuring.js
Normal file
@@ -0,0 +1,15 @@
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var Person, tim;
|
||||
|
||||
Person = (function() {
|
||||
function Person(options) {
|
||||
this.name = options.name, this.age = options.age, this.height = options.height;
|
||||
}
|
||||
|
||||
return Person;
|
||||
|
||||
})();
|
||||
|
||||
tim = new Person({
|
||||
age: 4
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var fill;
|
||||
|
||||
fill = function(container, liquid) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var filename, _fn, _i, _len;
|
||||
|
||||
_fn = function(filename) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var hi;
|
||||
|
||||
hi = function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var footprints, solipsism, speed;
|
||||
|
||||
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
|
||||
|
||||
6
documentation/js/expansion.js
Normal file
6
documentation/js/expansion.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var first, last, text, _ref;
|
||||
|
||||
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];
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var eldest, grade;
|
||||
|
||||
grade = function(student) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var one, six, three, two;
|
||||
|
||||
six = (one = 1) + (two = 2) + (three = 3);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var globals, name;
|
||||
|
||||
globals = ((function() {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var error;
|
||||
|
||||
alert((function() {
|
||||
try {
|
||||
return nonexistent / void 0;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
error = _error;
|
||||
return "And the error is ... " + error;
|
||||
}
|
||||
})());
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var Account;
|
||||
|
||||
Account = function(customer, cart) {
|
||||
var _this = this;
|
||||
this.customer = customer;
|
||||
this.cart = cart;
|
||||
return $('.shopping_cart').bind('click', function(event) {
|
||||
return _this.customer.purchase(_this.cart);
|
||||
});
|
||||
return $('.shopping_cart').bind('click', (function(_this) {
|
||||
return function(event) {
|
||||
return _this.customer.purchase(_this.cart);
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var cube, square;
|
||||
|
||||
square = function(x) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var html;
|
||||
|
||||
html = "<strong>\n cup of coffeescript\n</strong>";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var OPERATOR;
|
||||
|
||||
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var city, forecast, temp, weatherReport, _ref;
|
||||
|
||||
weatherReport = function(location) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var age, ages, child, yearsOld;
|
||||
|
||||
yearsOld = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var city, futurists, name, street, _ref, _ref1;
|
||||
|
||||
futurists = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var bitlist, kids, singers, song;
|
||||
|
||||
song = ["do", "re", "mi", "fa", "so"];
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
$('.account').attr({
|
||||
"class": 'active'
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var cubes, list, math, num, number, opposite, race, square,
|
||||
__slice = [].slice;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var theBait, theSwitch, _ref;
|
||||
|
||||
theBait = 1000;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var close, contents, open, tag, _i, _ref,
|
||||
__slice = [].slice;
|
||||
|
||||
|
||||
3
documentation/js/prototypes.js
vendored
3
documentation/js/prototypes.js
vendored
@@ -1,5 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
String.prototype.dasherize = function() {
|
||||
return this.replace(/_/g, "-");
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var countdown, num;
|
||||
|
||||
countdown = (function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var changeNumbers, inner, outer;
|
||||
|
||||
outer = 1;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var copy, end, middle, numbers, start;
|
||||
|
||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
start = numbers.slice(0, 3);
|
||||
|
||||
middle = numbers.slice(3, 6);
|
||||
middle = numbers.slice(3, -2);
|
||||
|
||||
end = numbers.slice(6);
|
||||
end = numbers.slice(-2);
|
||||
|
||||
copy = numbers.slice(0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var zip, _ref;
|
||||
|
||||
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var awardMedals, contenders, gold, rest, silver,
|
||||
__slice = [].slice;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var numbers, _ref;
|
||||
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var mobyDick;
|
||||
|
||||
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
switch (day) {
|
||||
case "Mon":
|
||||
go(work);
|
||||
|
||||
19
documentation/js/switch_with_no_expression.js
Normal file
19
documentation/js/switch_with_no_expression.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var grade, score;
|
||||
|
||||
score = 76;
|
||||
|
||||
grade = (function() {
|
||||
switch (false) {
|
||||
case !(score < 60):
|
||||
return 'F';
|
||||
case !(score < 70):
|
||||
return 'D';
|
||||
case !(score < 80):
|
||||
return 'C';
|
||||
case !(score < 90):
|
||||
return 'B';
|
||||
default:
|
||||
return 'A';
|
||||
}
|
||||
})();
|
||||
@@ -1,9 +1,11 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var error;
|
||||
|
||||
try {
|
||||
allHellBreaksLoose();
|
||||
catsAndDogsLivingTogether();
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
error = _error;
|
||||
print(error);
|
||||
} finally {
|
||||
cleanUp();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.0
|
||||
var lyrics, num;
|
||||
|
||||
if (this.studyingEconomics) {
|
||||
@@ -16,7 +16,7 @@ lyrics = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
while (num -= 1) {
|
||||
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
|
||||
@@ -31,7 +31,7 @@ File.open = (path, mode, block) ->
|
||||
# Write.
|
||||
write = (location, data) ->
|
||||
path = new Pathname location
|
||||
throw new Error "Location does not exist" unless fs.existsSync(location)
|
||||
throw new Error "Location does not exist" unless fs.existsSync location
|
||||
|
||||
File.open path, 'w', (file) ->
|
||||
return false if Digest.MD5.hexdigest(file.read()) is data.hash()
|
||||
|
||||
@@ -13,7 +13,7 @@ run_loop = ->
|
||||
wait()
|
||||
|
||||
# Objects:
|
||||
dense_object_literal = {one: 1, two: 2, three: 3}
|
||||
dense_object_literal = one: 1, two: 2, three: 3
|
||||
|
||||
spaced_out_multiline_object =
|
||||
pi: 3.14159
|
||||
@@ -56,7 +56,7 @@ race = ->
|
||||
run()
|
||||
walk()
|
||||
crawl()
|
||||
if tired then return sleep()
|
||||
return sleep() if tired
|
||||
race()
|
||||
|
||||
# Conditional assignment:
|
||||
@@ -64,7 +64,7 @@ good or= evil
|
||||
wine and= cheese
|
||||
|
||||
# Nested property access and calls.
|
||||
((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
|
||||
(moon.turn 360).shapes[3].move(x: 45, y: 30).position['top'].offset('x')
|
||||
|
||||
a = b = c = 5
|
||||
|
||||
@@ -79,7 +79,7 @@ try
|
||||
dogs_and_cats_living_together()
|
||||
throw "up"
|
||||
catch error
|
||||
print(error)
|
||||
print error
|
||||
finally
|
||||
clean_up()
|
||||
|
||||
@@ -130,8 +130,8 @@ wednesday = -> eat_breakfast(); go_to_work(); eat_dinner()
|
||||
|
||||
# Multiline strings with inner quotes.
|
||||
story = "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
|
||||
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
|
||||
aliquam erat volutpat. Ut wisi enim ad."
|
||||
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
|
||||
aliquam erat volutpat. Ut wisi enim ad."
|
||||
|
||||
# Inheritance and calling super.
|
||||
class Animal
|
||||
|
||||
@@ -19,7 +19,7 @@ binary_search = (items, value) ->
|
||||
|
||||
|
||||
# Test the function.
|
||||
console.log 2 is binary_search [10, 20, 30, 40, 50], 30
|
||||
console.log 4 is binary_search [-97, 35, 67, 88, 1200], 1200
|
||||
console.log 0 is binary_search [0, 45, 70], 0
|
||||
console.log(-1 is binary_search [0, 45, 70], 10)
|
||||
console.log 2 is binary_search [10, 20, 30, 40, 50], 30
|
||||
console.log 4 is binary_search [-97, 35, 67, 88, 1200], 1200
|
||||
console.log 0 is binary_search [0, 45, 70], 0
|
||||
console.log -1 is binary_search [0, 45, 70], 10
|
||||
@@ -1,8 +1,8 @@
|
||||
# A bubble sort implementation, sorting the given array in-place.
|
||||
bubble_sort = (list) ->
|
||||
for i in [0...list.length]
|
||||
for j in [0...list.length - i]
|
||||
[list[j], list[j+1]] = [list[j+1], list[j]] if list[j] > list[j+1]
|
||||
for j in [0...list.length - i] when list[j] > list[j + 1]
|
||||
[list[j], list[j+1]] = [list[j + 1], list[j]]
|
||||
list
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# "Classic" linked list implementation that doesn't keep track of its size.
|
||||
class LinkedList
|
||||
|
||||
->
|
||||
this._head = null # Pointer to the first item in the list.
|
||||
constructor: ->
|
||||
@_head = null # Pointer to the first item in the list.
|
||||
|
||||
|
||||
# Appends some data to the end of the list. This method traverses the existing
|
||||
@@ -12,10 +12,10 @@ class LinkedList
|
||||
# Create a new node object to wrap the data.
|
||||
node = data: data, next: null
|
||||
|
||||
current = this._head or= node
|
||||
current = @_head or= node
|
||||
|
||||
if this._head isnt node
|
||||
(current = current.next) while current.next
|
||||
if @_head isnt node
|
||||
current = current.next while current.next
|
||||
current.next = node
|
||||
|
||||
this
|
||||
@@ -27,11 +27,11 @@ class LinkedList
|
||||
# Check for out-of-bounds values.
|
||||
return null if index < 0
|
||||
|
||||
current = this._head or null
|
||||
current = @_head or null
|
||||
i = -1
|
||||
|
||||
# Advance through the list.
|
||||
(current = current.next) while current and index > (i += 1)
|
||||
current = current.next while current and index > ++i
|
||||
|
||||
# Return null if we've reached the end.
|
||||
current and current.data
|
||||
@@ -43,16 +43,16 @@ class LinkedList
|
||||
# Check for out-of-bounds values.
|
||||
return null if index < 0
|
||||
|
||||
current = this._head or null
|
||||
current = @_head or null
|
||||
i = -1
|
||||
|
||||
# Special case: removing the first item.
|
||||
if index is 0
|
||||
this._head = current.next
|
||||
@_head = current.next
|
||||
else
|
||||
|
||||
# Find the right location.
|
||||
([previous, current] = [current, current.next]) while index > (i += 1)
|
||||
[previous, current] = [current, current.next] while index > ++i
|
||||
|
||||
# Skip over the item to remove.
|
||||
previous.next = current.next
|
||||
@@ -63,7 +63,7 @@ class LinkedList
|
||||
|
||||
# Calculate the number of items in the list.
|
||||
size: ->
|
||||
current = this._head
|
||||
current = @_head
|
||||
count = 0
|
||||
|
||||
while current
|
||||
@@ -76,7 +76,7 @@ class LinkedList
|
||||
# Convert the list into an array.
|
||||
toArray: ->
|
||||
result = []
|
||||
current = this._head
|
||||
current = @_head
|
||||
|
||||
while current
|
||||
result.push current.data
|
||||
@@ -86,7 +86,7 @@ class LinkedList
|
||||
|
||||
|
||||
# The string representation of the linked list.
|
||||
toString: -> this.toArray().toString()
|
||||
toString: -> @toArray().toString()
|
||||
|
||||
|
||||
# Tests.
|
||||
|
||||
@@ -7,13 +7,13 @@ is_valid_identifier = (identifier) ->
|
||||
sum = 0
|
||||
alt = false
|
||||
|
||||
for i in [identifier.length - 1..0] by -1
|
||||
for c in identifier by -1
|
||||
|
||||
# Get the next digit.
|
||||
num = parseInt identifier.charAt(i), 10
|
||||
num = parseInt c, 10
|
||||
|
||||
# If it's not a valid number, abort.
|
||||
return false if isNaN(num)
|
||||
return false if isNaN num
|
||||
|
||||
# If it's an alternate number...
|
||||
if alt
|
||||
|
||||
@@ -3,13 +3,12 @@ merge_sort = (list) ->
|
||||
|
||||
return list if list.length is 1
|
||||
|
||||
result = []
|
||||
pivot = Math.floor list.length / 2
|
||||
left = merge_sort list.slice 0, pivot
|
||||
right = merge_sort list.slice pivot
|
||||
|
||||
while left.length and right.length
|
||||
result.push(if left[0] < right[0] then left.shift() else right.shift())
|
||||
result = while left.length and right.length
|
||||
if left[0] < right[0] then left.shift() else right.shift()
|
||||
|
||||
result.concat(left).concat(right)
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
# Examples from the Poignant Guide.
|
||||
# These are examples of syntax differences between CoffeeScript and Ruby,
|
||||
# they won't run.
|
||||
|
||||
# ['toast', 'cheese', 'wine'].each { |food| print food.capitalize }
|
||||
|
||||
['toast', 'wine', 'cheese'].each (food) -> print food.capitalize()
|
||||
print food.capitalize() for food in ['toast', 'wine', 'cheese']
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,10 +17,10 @@
|
||||
# end
|
||||
|
||||
LotteryTicket =
|
||||
get_picks: -> @picks
|
||||
set_picks: (@picks) ->
|
||||
get_purchased: -> @purchase
|
||||
set_purchased: (@purchased) ->
|
||||
get_picks: -> @picks
|
||||
set_picks: (@picks) ->
|
||||
get_purchased: -> @purchase
|
||||
set_purchased: (@purchased) ->
|
||||
|
||||
|
||||
|
||||
@@ -42,13 +45,10 @@ LotteryDraw =
|
||||
play: ->
|
||||
result = LotteryTicket.new_random()
|
||||
winners = {}
|
||||
this.tickets.each (buyer, ticket_list) ->
|
||||
ticket_list.each (ticket) ->
|
||||
score = ticket.score result
|
||||
return if score is 0
|
||||
winners[buyer] or= []
|
||||
winners[buyer].push [ticket, score]
|
||||
this.tickets = {}
|
||||
for buyer, ticketList of @tickets
|
||||
for ticket in ticketList when (score = ticket.score result) isnt 0
|
||||
(winners[buyer] or= []).push [ticket, score]
|
||||
@tickets = {}
|
||||
winners
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ LotteryDraw =
|
||||
|
||||
WishScanner =
|
||||
scan_for_a_wish: ->
|
||||
wish = this.read().detect (thought) -> thought.index('wish: ') is 0
|
||||
wish = @read().detect (thought) -> thought.indexOf('wish: ') is 0
|
||||
wish.replace 'wish: ', ''
|
||||
|
||||
|
||||
@@ -109,28 +109,28 @@ Creature =
|
||||
|
||||
# This method applies a hit taken during a fight.
|
||||
hit: (damage) ->
|
||||
p_up = Math.rand this.charisma
|
||||
p_up = Math.rand @charisma
|
||||
if p_up % 9 is 7
|
||||
this.life += p_up / 4
|
||||
console.log "[" + this.name + " magick powers up " + p_up + "!]"
|
||||
this.life -= damage
|
||||
if this.life <= 0 then console.log "[" + this.name + " has died.]"
|
||||
@life += p_up / 4
|
||||
console.log "[#{@name} magick powers up #{p_up}!]"
|
||||
@life -= damage
|
||||
if @life <= 0 then console.log "[#{@name} has died.]"
|
||||
|
||||
# This method takes one turn in a fight.
|
||||
fight: (enemy, weapon) ->
|
||||
if this.life <= 0 then return console.log "[" + this.name + "is too dead to fight!]"
|
||||
return console.log "[#{@name} is too dead to fight!]" if @life <= 0
|
||||
|
||||
# Attack the opponent.
|
||||
your_hit = Math.rand this.strength + weapon
|
||||
console.log "[You hit with " + your_hit + "points of damage!]"
|
||||
your_hit = Math.rand @strength + weapon
|
||||
console.log "[You hit with #{your_hit}points of damage!]"
|
||||
enemy.hit your_hit
|
||||
|
||||
# Retaliation.
|
||||
console.log enemy
|
||||
if enemy.life > 0
|
||||
enemy_hit = Math.rand enemy.strength + enemy.weapon
|
||||
console.log "[Your enemy hit with " + enemy_hit + "points of damage!]"
|
||||
this.hit enemy_hit
|
||||
console.log "[Your enemy hit with #{enemy_hit}points of damage!]"
|
||||
@hit enemy_hit
|
||||
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ code_words.each (real, code) -> idea.replace(real, code)
|
||||
# Save the jibberish to a new file
|
||||
print "File encoded. Please enter a name for this idea: "
|
||||
idea_name = gets().strip()
|
||||
File.open "idea-" + idea_name + '.txt', 'w', (file) -> file.write idea
|
||||
File.open "idea-#{idea_name}.txt", 'w', (file) -> file.write idea
|
||||
|
||||
|
||||
|
||||
@@ -174,8 +174,8 @@ File.open "idea-" + idea_name + '.txt', 'w', (file) -> file.write idea
|
||||
|
||||
wipe_mutterings_from = (sentence) ->
|
||||
throw new Error "cannot wipe mutterings" unless sentence.indexOf
|
||||
while sentence.indexOf('(') >= 0
|
||||
open = sentence.indexOf('(') - 1
|
||||
close = sentence.indexOf(')') + 1
|
||||
sentence = sentence.slice(0, open) + sentence.slice(close, sentence.length)
|
||||
while '(' in sentence
|
||||
open = sentence.indexOf('(')
|
||||
close = sentence.indexOf(')')
|
||||
sentence = "#{sentence[0...open]}#{sentence[close + 1..]}"
|
||||
sentence
|
||||
|
||||
@@ -45,7 +45,7 @@ foods[2]
|
||||
# (key, ' is a ', val) join print.
|
||||
|
||||
for key, val of {dog: 'canine', cat: 'feline', fox: 'vulpine'}
|
||||
print key + ' is a ' + val
|
||||
print "#{key} is a #{val}"
|
||||
|
||||
|
||||
# Person = class: /name, /age, /sex.
|
||||
@@ -54,7 +54,7 @@ for key, val of {dog: 'canine', cat: 'feline', fox: 'vulpine'}
|
||||
|
||||
class Person
|
||||
print: ->
|
||||
print 'My name is ' + @name + '.'
|
||||
print "My name is #{@name}."
|
||||
|
||||
|
||||
# p = Person ()
|
||||
@@ -74,7 +74,7 @@ class Policeman extends Person
|
||||
(@rank) ->
|
||||
|
||||
print: ->
|
||||
print 'My name is ' + @name + " and I'm a " + @rank + '.'
|
||||
print "My name is #{@name} and I'm a #{@rank}."
|
||||
|
||||
print new Policeman 'Constable'
|
||||
|
||||
@@ -180,7 +180,7 @@ if 3.gender?
|
||||
# session = url query ? at ('session').
|
||||
|
||||
HomePage::get = (url) ->
|
||||
session = url.query.session if url.query?
|
||||
session = url.query?.session
|
||||
|
||||
|
||||
# BTree = class: /left, /right.
|
||||
|
||||
@@ -7,6 +7,6 @@ server = http.createServer (req, res) ->
|
||||
res.write 'Hello, World!'
|
||||
res.end()
|
||||
|
||||
server.listen 3000
|
||||
server.listen PORT = 3000
|
||||
|
||||
console.log "Server running at http://localhost:3000/"
|
||||
console.log "Server running at http://localhost:#{PORT}/"
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,44 +0,0 @@
|
||||
# JavaScriptLint configuration file for CoffeeScript.
|
||||
|
||||
+no_return_value # function {0} does not always return a value
|
||||
+duplicate_formal # duplicate formal argument {0}
|
||||
-equal_as_assign # test for equality (==) mistyped as assignment (=)?{0}
|
||||
+var_hides_arg # variable {0} hides argument
|
||||
+redeclared_var # redeclaration of {0} {1}
|
||||
-anon_no_return_value # anonymous function does not always return a value
|
||||
+missing_semicolon # missing semicolon
|
||||
+meaningless_block # meaningless block; curly braces have no impact
|
||||
-comma_separated_stmts # multiple statements separated by commas (use semicolons?)
|
||||
+unreachable_code # unreachable code
|
||||
+missing_break # missing break statement
|
||||
-missing_break_for_last_case # missing break statement for last case in switch
|
||||
-comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==)
|
||||
-inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement
|
||||
-useless_void # use of the void type may be unnecessary (void is always undefined)
|
||||
+multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs
|
||||
+use_of_label # use of label
|
||||
-block_without_braces # block statement without curly braces
|
||||
+leading_decimal_point # leading decimal point may indicate a number or an object member
|
||||
+trailing_decimal_point # trailing decimal point may indicate a number or an object member
|
||||
+octal_number # leading zeros make an octal number
|
||||
+nested_comment # nested comment
|
||||
+misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma
|
||||
+ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement
|
||||
+empty_statement # empty statement or extra semicolon
|
||||
-missing_option_explicit # the "option explicit" control comment is missing
|
||||
+partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag
|
||||
+dup_option_explicit # duplicate "option explicit" control comment
|
||||
+useless_assign # useless assignment
|
||||
+ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity
|
||||
+ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent)
|
||||
-missing_default_case # missing default case in switch statement
|
||||
+duplicate_case_in_switch # duplicate case in switch statements
|
||||
+default_not_at_end # the default case is not at the end of the switch statement
|
||||
+legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax
|
||||
+jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax
|
||||
+useless_comparison # useless comparison; comparing identical expressions
|
||||
+with_statement # with statement hides undeclared variables; use temporary variable instead
|
||||
+trailing_comma_in_array # extra comma is not recommended in array initializers
|
||||
+assign_to_function_call # assignment to a function call
|
||||
+parseint_missing_radix # parseInt missing radix parameter
|
||||
+lambda_assign_requires_semicolon
|
||||
1396
index.html
1396
index.html
File diff suppressed because it is too large
Load Diff
@@ -1,21 +1,22 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
var CoffeeScript, runScripts,
|
||||
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; };
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
CoffeeScript.require = require;
|
||||
|
||||
compile = CoffeeScript.compile;
|
||||
|
||||
CoffeeScript["eval"] = function(code, options) {
|
||||
var _ref;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if ((_ref = options.bare) == null) {
|
||||
if (options.bare == null) {
|
||||
options.bare = true;
|
||||
}
|
||||
return eval(CoffeeScript.compile(code, options));
|
||||
return eval(compile(code, options));
|
||||
};
|
||||
|
||||
CoffeeScript.run = function(code, options) {
|
||||
@@ -23,33 +24,54 @@
|
||||
options = {};
|
||||
}
|
||||
options.bare = true;
|
||||
return Function(CoffeeScript.compile(code, options))();
|
||||
options.shiftLine = true;
|
||||
return Function(compile(code, options))();
|
||||
};
|
||||
|
||||
if (typeof window === "undefined" || window === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CoffeeScript.load = function(url, callback, options) {
|
||||
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;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
options.sourceMap = true;
|
||||
options.inline = true;
|
||||
_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";
|
||||
};
|
||||
}
|
||||
|
||||
CoffeeScript.load = function(url, callback, options, hold) {
|
||||
var xhr;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
|
||||
if (hold == null) {
|
||||
hold = false;
|
||||
}
|
||||
options.sourceFiles = [url];
|
||||
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new window.XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
if ('overrideMimeType' in xhr) {
|
||||
xhr.overrideMimeType('text/plain');
|
||||
}
|
||||
xhr.onreadystatechange = function() {
|
||||
var _ref;
|
||||
var param, _ref;
|
||||
if (xhr.readyState === 4) {
|
||||
if ((_ref = xhr.status) === 0 || _ref === 200) {
|
||||
CoffeeScript.run(xhr.responseText, options);
|
||||
param = [xhr.responseText, options];
|
||||
if (!hold) {
|
||||
CoffeeScript.run.apply(CoffeeScript, param);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Could not load " + url);
|
||||
}
|
||||
if (callback) {
|
||||
return callback();
|
||||
return callback(param);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -57,8 +79,8 @@
|
||||
};
|
||||
|
||||
runScripts = function() {
|
||||
var coffees, coffeetypes, execute, index, length, s, scripts;
|
||||
scripts = document.getElementsByTagName('script');
|
||||
var coffees, coffeetypes, execute, i, index, s, script, scripts, _fn, _i, _len;
|
||||
scripts = window.document.getElementsByTagName('script');
|
||||
coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
|
||||
coffees = (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
@@ -72,30 +94,41 @@
|
||||
return _results;
|
||||
})();
|
||||
index = 0;
|
||||
length = coffees.length;
|
||||
(execute = function() {
|
||||
var mediatype, options, script;
|
||||
script = coffees[index++];
|
||||
mediatype = script != null ? script.type : void 0;
|
||||
if (__indexOf.call(coffeetypes, mediatype) >= 0) {
|
||||
options = {
|
||||
literate: mediatype === 'text/literate-coffeescript'
|
||||
};
|
||||
if (script.src) {
|
||||
return CoffeeScript.load(script.src, execute, options);
|
||||
} else {
|
||||
CoffeeScript.run(script.innerHTML, options);
|
||||
return execute();
|
||||
}
|
||||
execute = function() {
|
||||
var param;
|
||||
param = coffees[index];
|
||||
if (param instanceof Array) {
|
||||
CoffeeScript.run.apply(CoffeeScript, param);
|
||||
index++;
|
||||
return execute();
|
||||
}
|
||||
})();
|
||||
return null;
|
||||
};
|
||||
_fn = function(script, i) {
|
||||
var options;
|
||||
options = {
|
||||
literate: script.type === coffeetypes[1]
|
||||
};
|
||||
if (script.src) {
|
||||
return CoffeeScript.load(script.src, function(param) {
|
||||
coffees[i] = param;
|
||||
return execute();
|
||||
}, options, true);
|
||||
} else {
|
||||
options.sourceFiles = ['embedded'];
|
||||
return coffees[i] = [script.innerHTML, options];
|
||||
}
|
||||
};
|
||||
for (i = _i = 0, _len = coffees.length; _i < _len; i = ++_i) {
|
||||
script = coffees[i];
|
||||
_fn(script, i);
|
||||
}
|
||||
return execute();
|
||||
};
|
||||
|
||||
if (window.addEventListener) {
|
||||
addEventListener('DOMContentLoaded', runScripts, false);
|
||||
window.addEventListener('DOMContentLoaded', runScripts, false);
|
||||
} else {
|
||||
attachEvent('onload', runScripts);
|
||||
window.attachEvent('onload', runScripts);
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
var CoffeeScript, cakefileDirectory, existsSync, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
||||
var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
tasks = {};
|
||||
|
||||
options = {};
|
||||
@@ -46,7 +44,7 @@
|
||||
});
|
||||
|
||||
exports.run = function() {
|
||||
var arg, args, _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);
|
||||
@@ -59,7 +57,8 @@
|
||||
}
|
||||
try {
|
||||
options = oparse.parse(args);
|
||||
} catch (e) {
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return fatalError("" + e);
|
||||
}
|
||||
_ref = options["arguments"];
|
||||
@@ -100,7 +99,7 @@
|
||||
|
||||
cakefileDirectory = function(dir) {
|
||||
var parent;
|
||||
if (existsSync(path.join(dir, 'Cakefile'))) {
|
||||
if (fs.existsSync(path.join(dir, 'Cakefile'))) {
|
||||
return dir;
|
||||
}
|
||||
parent = path.normalize(path.join(dir, '..'));
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
var Lexer, compile, ext, fs, helpers, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
var Lexer, SourceMap, compile, formatSourcePosition, fs, getSourceMap, helpers, lexer, parser, path, 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');
|
||||
|
||||
vm = require('vm');
|
||||
|
||||
path = require('path');
|
||||
|
||||
Lexer = require('./lexer').Lexer;
|
||||
@@ -13,73 +16,63 @@
|
||||
|
||||
helpers = require('./helpers');
|
||||
|
||||
vm = require('vm');
|
||||
SourceMap = require('./sourcemap');
|
||||
|
||||
sourcemap = require('./sourcemap');
|
||||
exports.VERSION = '1.7.1';
|
||||
|
||||
loadFile = function(module, filename) {
|
||||
var raw, stripped;
|
||||
raw = fs.readFileSync(filename, 'utf8');
|
||||
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
|
||||
return module._compile(compile(stripped, {
|
||||
filename: filename,
|
||||
literate: helpers.isLiterate(filename)
|
||||
}), filename);
|
||||
};
|
||||
|
||||
if (require.extensions) {
|
||||
_ref = ['.coffee', '.litcoffee', '.md', '.coffee.md'];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
ext = _ref[_i];
|
||||
require.extensions[ext] = loadFile;
|
||||
}
|
||||
}
|
||||
|
||||
exports.VERSION = '1.6.1';
|
||||
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
|
||||
|
||||
exports.helpers = helpers;
|
||||
|
||||
exports.compile = compile = function(code, options) {
|
||||
var answer, coffeeFile, currentColumn, currentLine, fragment, fragments, header, js, jsFile, merge, newLines, sourceMap, _j, _len1;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
withPrettyErrors = function(fn) {
|
||||
return function(code, options) {
|
||||
var err;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
try {
|
||||
return fn.call(this, code, options);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
throw helpers.updateSyntaxError(err, code, options.filename);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.compile = compile = withPrettyErrors(function(code, options) {
|
||||
var answer, currentColumn, currentLine, extend, fragment, fragments, header, js, map, merge, newLines, _i, _len;
|
||||
merge = helpers.merge, extend = helpers.extend;
|
||||
options = extend({}, options);
|
||||
if (options.sourceMap) {
|
||||
map = new SourceMap;
|
||||
}
|
||||
merge = exports.helpers.merge;
|
||||
try {
|
||||
fragments = parser.parse(lexer.tokenize(code, options)).compileToFragments(options);
|
||||
currentLine = 0;
|
||||
if (options.header) {
|
||||
currentLine += 1;
|
||||
}
|
||||
if (options.shiftLine) {
|
||||
currentLine += 1;
|
||||
}
|
||||
currentColumn = 0;
|
||||
js = "";
|
||||
for (_i = 0, _len = fragments.length; _i < _len; _i++) {
|
||||
fragment = fragments[_i];
|
||||
if (options.sourceMap) {
|
||||
coffeeFile = helpers.baseFileName(options.filename);
|
||||
jsFile = helpers.baseFileName(options.filename, true) + ".js";
|
||||
sourceMap = new sourcemap.SourceMap();
|
||||
}
|
||||
fragments = (parser.parse(lexer.tokenize(code, options))).compileToFragments(options);
|
||||
currentLine = 0;
|
||||
if (options.header) {
|
||||
currentLine += 1;
|
||||
}
|
||||
if (options.sourceMap) {
|
||||
currentLine += 1;
|
||||
}
|
||||
currentColumn = 0;
|
||||
js = "";
|
||||
for (_j = 0, _len1 = fragments.length; _j < _len1; _j++) {
|
||||
fragment = fragments[_j];
|
||||
if (sourceMap) {
|
||||
if (fragment.locationData) {
|
||||
sourceMap.addMapping([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
|
||||
noReplace: true
|
||||
});
|
||||
}
|
||||
newLines = helpers.count(fragment.code, "\n");
|
||||
currentLine += newLines;
|
||||
currentColumn = fragment.code.length - (newLines ? fragment.code.lastIndexOf("\n") : 0);
|
||||
if (fragment.locationData) {
|
||||
map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
|
||||
noReplace: true
|
||||
});
|
||||
}
|
||||
newLines = helpers.count(fragment.code, "\n");
|
||||
currentLine += newLines;
|
||||
if (newLines) {
|
||||
currentColumn = fragment.code.length - (fragment.code.lastIndexOf("\n") + 1);
|
||||
} else {
|
||||
currentColumn += fragment.code.length;
|
||||
}
|
||||
js += fragment.code;
|
||||
}
|
||||
} catch (err) {
|
||||
if (options.filename) {
|
||||
err.message = "In " + options.filename + ", " + err.message;
|
||||
}
|
||||
throw err;
|
||||
js += fragment.code;
|
||||
}
|
||||
if (options.header) {
|
||||
header = "Generated by CoffeeScript " + this.VERSION;
|
||||
@@ -89,46 +82,45 @@
|
||||
answer = {
|
||||
js: js
|
||||
};
|
||||
if (sourceMap) {
|
||||
answer.sourceMap = sourceMap;
|
||||
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, coffeeFile, jsFile);
|
||||
}
|
||||
answer.sourceMap = map;
|
||||
answer.v3SourceMap = map.generate(options, code);
|
||||
return answer;
|
||||
} else {
|
||||
return js;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
exports.tokens = function(code, options) {
|
||||
exports.tokens = withPrettyErrors(function(code, options) {
|
||||
return lexer.tokenize(code, options);
|
||||
};
|
||||
});
|
||||
|
||||
exports.nodes = function(source, options) {
|
||||
exports.nodes = withPrettyErrors(function(source, options) {
|
||||
if (typeof source === 'string') {
|
||||
return parser.parse(lexer.tokenize(source, options));
|
||||
} else {
|
||||
return parser.parse(source);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
exports.run = function(code, options) {
|
||||
var mainModule;
|
||||
var answer, dir, mainModule, _ref;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
mainModule = require.main;
|
||||
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
|
||||
mainModule.moduleCache && (mainModule.moduleCache = {});
|
||||
mainModule.paths = require('module')._nodeModulePaths(path.dirname(fs.realpathSync(options.filename)));
|
||||
dir = options.filename ? path.dirname(fs.realpathSync(options.filename)) : fs.realpathSync('.');
|
||||
mainModule.paths = require('module')._nodeModulePaths(dir);
|
||||
if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
|
||||
return mainModule._compile(compile(code, options), mainModule.filename);
|
||||
} else {
|
||||
return mainModule._compile(code, mainModule.filename);
|
||||
answer = compile(code, options);
|
||||
code = (_ref = answer.js) != null ? _ref : answer;
|
||||
}
|
||||
return mainModule._compile(code, mainModule.filename);
|
||||
};
|
||||
|
||||
exports["eval"] = function(code, options) {
|
||||
var Module, Script, js, k, o, r, sandbox, v, _j, _len1, _module, _ref1, _ref2, _require;
|
||||
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _require;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
@@ -142,10 +134,10 @@
|
||||
sandbox = options.sandbox;
|
||||
} else {
|
||||
sandbox = Script.createContext();
|
||||
_ref1 = options.sandbox;
|
||||
for (k in _ref1) {
|
||||
if (!__hasProp.call(_ref1, k)) continue;
|
||||
v = _ref1[k];
|
||||
_ref = options.sandbox;
|
||||
for (k in _ref) {
|
||||
if (!__hasProp.call(_ref, k)) continue;
|
||||
v = _ref[k];
|
||||
sandbox[k] = v;
|
||||
}
|
||||
}
|
||||
@@ -162,9 +154,9 @@
|
||||
return Module._load(path, _module, true);
|
||||
};
|
||||
_module.filename = sandbox.__filename;
|
||||
_ref2 = Object.getOwnPropertyNames(require);
|
||||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
||||
r = _ref2[_j];
|
||||
_ref1 = Object.getOwnPropertyNames(require);
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
r = _ref1[_i];
|
||||
if (r !== 'paths') {
|
||||
_require[r] = require[r];
|
||||
}
|
||||
@@ -190,6 +182,30 @@
|
||||
}
|
||||
};
|
||||
|
||||
exports.register = function() {
|
||||
return require('./register');
|
||||
};
|
||||
|
||||
exports._compileFile = function(filename, sourceMap) {
|
||||
var answer, err, raw, stripped;
|
||||
if (sourceMap == null) {
|
||||
sourceMap = false;
|
||||
}
|
||||
raw = fs.readFileSync(filename, 'utf8');
|
||||
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
|
||||
try {
|
||||
answer = compile(stripped, {
|
||||
filename: filename,
|
||||
sourceMap: sourceMap,
|
||||
literate: helpers.isLiterate(filename)
|
||||
});
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
throw helpers.updateSyntaxError(err, stripped, filename);
|
||||
}
|
||||
return answer;
|
||||
};
|
||||
|
||||
lexer = new Lexer;
|
||||
|
||||
parser.lexer = {
|
||||
@@ -198,6 +214,7 @@
|
||||
token = this.tokens[this.pos++];
|
||||
if (token) {
|
||||
tag = token[0], this.yytext = token[1], this.yylloc = token[2];
|
||||
this.errorToken = token.origin || token;
|
||||
this.yylineno = this.yylloc.first_line;
|
||||
} else {
|
||||
tag = '';
|
||||
@@ -215,4 +232,104 @@
|
||||
|
||||
parser.yy = require('./nodes');
|
||||
|
||||
parser.yy.parseError = function(message, _arg) {
|
||||
var errorLoc, errorTag, errorText, errorToken, token, tokens, _ref;
|
||||
token = _arg.token;
|
||||
_ref = parser.lexer, errorToken = _ref.errorToken, tokens = _ref.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);
|
||||
return helpers.throwSyntaxError("unexpected " + errorText, errorLoc);
|
||||
};
|
||||
|
||||
formatSourcePosition = function(frame, getSourceMapping) {
|
||||
var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
|
||||
fileName = void 0;
|
||||
fileLocation = '';
|
||||
if (frame.isNative()) {
|
||||
fileLocation = "native";
|
||||
} else {
|
||||
if (frame.isEval()) {
|
||||
fileName = frame.getScriptNameOrSourceURL();
|
||||
if (!fileName) {
|
||||
fileLocation = "" + (frame.getEvalOrigin()) + ", ";
|
||||
}
|
||||
} else {
|
||||
fileName = frame.getFileName();
|
||||
}
|
||||
fileName || (fileName = "<anonymous>");
|
||||
line = frame.getLineNumber();
|
||||
column = frame.getColumnNumber();
|
||||
source = getSourceMapping(fileName, line, column);
|
||||
fileLocation = source ? "" + fileName + ":" + source[0] + ":" + source[1] : "" + fileName + ":" + line + ":" + column;
|
||||
}
|
||||
functionName = frame.getFunctionName();
|
||||
isConstructor = frame.isConstructor();
|
||||
isMethodCall = !(frame.isToplevel() || isConstructor);
|
||||
if (isMethodCall) {
|
||||
methodName = frame.getMethodName();
|
||||
typeName = frame.getTypeName();
|
||||
if (functionName) {
|
||||
tp = as = '';
|
||||
if (typeName && functionName.indexOf(typeName)) {
|
||||
tp = "" + typeName + ".";
|
||||
}
|
||||
if (methodName && functionName.indexOf("." + methodName) !== functionName.length - methodName.length - 1) {
|
||||
as = " [as " + methodName + "]";
|
||||
}
|
||||
return "" + tp + functionName + as + " (" + fileLocation + ")";
|
||||
} else {
|
||||
return "" + typeName + "." + (methodName || '<anonymous>') + " (" + fileLocation + ")";
|
||||
}
|
||||
} else if (isConstructor) {
|
||||
return "new " + (functionName || '<anonymous>') + " (" + fileLocation + ")";
|
||||
} else if (functionName) {
|
||||
return "" + functionName + " (" + fileLocation + ")";
|
||||
} else {
|
||||
return fileLocation;
|
||||
}
|
||||
};
|
||||
|
||||
sourceMaps = {};
|
||||
|
||||
getSourceMap = function(filename) {
|
||||
var answer, _ref;
|
||||
if (sourceMaps[filename]) {
|
||||
return sourceMaps[filename];
|
||||
}
|
||||
if (_ref = path != null ? path.extname(filename) : void 0, __indexOf.call(exports.FILE_EXTENSIONS, _ref) < 0) {
|
||||
return;
|
||||
}
|
||||
answer = exports._compileFile(filename, true);
|
||||
return sourceMaps[filename] = answer.sourceMap;
|
||||
};
|
||||
|
||||
Error.prepareStackTrace = function(err, stack) {
|
||||
var frame, frames, getSourceMapping, _ref;
|
||||
getSourceMapping = function(filename, line, column) {
|
||||
var answer, sourceMap;
|
||||
sourceMap = getSourceMap(filename);
|
||||
if (sourceMap) {
|
||||
answer = sourceMap.sourceLocation([line - 1, column - 1]);
|
||||
}
|
||||
if (answer) {
|
||||
return [answer[0] + 1, answer[1] + 1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
frames = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = stack.length; _i < _len; _i++) {
|
||||
frame = stack[_i];
|
||||
if (frame.getFunction() === exports.run) {
|
||||
break;
|
||||
}
|
||||
_results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
return "" + err.name + ": " + ((_ref = err.message) != null ? _ref : '') + "\n" + (frames.join('\n')) + "\n";
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
||||
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; };
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -12,11 +13,13 @@
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
mkdirp = require('mkdirp');
|
||||
|
||||
_ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec;
|
||||
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
exists = fs.exists || path.exists;
|
||||
useWinPathSep = path.sep === '\\';
|
||||
|
||||
helpers.extend(CoffeeScript, new EventEmitter);
|
||||
|
||||
@@ -34,7 +37,7 @@
|
||||
|
||||
BANNER = 'Usage: coffee [options] path/to/script.coffee -- [args]\n\nIf called without options, `coffee` will run your script.';
|
||||
|
||||
SWITCHES = [['-b', '--bare', 'compile without a top-level function wrapper'], ['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-e', '--eval', 'pass a string from the command line as input'], ['-h', '--help', 'display this help message'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-j', '--join [FILE]', 'concatenate the source CoffeeScript before compiling'], ['-l', '--lint', 'pipe the compiled JavaScript through JavaScript Lint'], ['-m', '--map', 'generate source map and save as .map files'], ['-n', '--nodes', 'print out the parse tree that the parser produces'], ['--nodejs [ARGS]', 'pass options directly to the "node" binary'], ['-o', '--output [DIR]', 'set the output directory for compiled JavaScript'], ['-p', '--print', 'print out the compiled JavaScript'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-t', '--tokens', 'print out the tokens that the lexer/rewriter produce'], ['-v', '--version', 'display the version number'], ['-w', '--watch', 'watch scripts for changes and rerun commands']];
|
||||
SWITCHES = [['-b', '--bare', 'compile without a top-level function wrapper'], ['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-e', '--eval', 'pass a string from the command line as input'], ['-h', '--help', 'display this help message'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-j', '--join [FILE]', 'concatenate the source CoffeeScript before compiling'], ['-m', '--map', 'generate source map and save as .map files'], ['-n', '--nodes', 'print out the parse tree that the parser produces'], ['--nodejs [ARGS]', 'pass options directly to the "node" binary'], ['--no-header', 'suppress the "Generated by" header'], ['-o', '--output [DIR]', 'set the output directory for compiled JavaScript'], ['-p', '--print', 'print out the compiled JavaScript'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-l', '--literate', 'treat stdio as literate style coffee-script'], ['-t', '--tokens', 'print out the tokens that the lexer/rewriter produce'], ['-v', '--version', 'display the version number'], ['-w', '--watch', 'watch scripts for changes and rerun commands']];
|
||||
|
||||
opts = {};
|
||||
|
||||
@@ -44,13 +47,16 @@
|
||||
|
||||
notSources = {};
|
||||
|
||||
watchers = {};
|
||||
watchedDirs = {};
|
||||
|
||||
optionParser = null;
|
||||
|
||||
exports.run = function() {
|
||||
var literals, source, _i, _len, _results;
|
||||
var literals, replCliOpts, source, _i, _len, _ref1, _results;
|
||||
parseOptions();
|
||||
replCliOpts = {
|
||||
useGlobal: true
|
||||
};
|
||||
if (opts.nodejs) {
|
||||
return forkNode();
|
||||
}
|
||||
@@ -61,96 +67,130 @@
|
||||
return version();
|
||||
}
|
||||
if (opts.interactive) {
|
||||
return require('./repl').start();
|
||||
}
|
||||
if (opts.watch && !fs.watch) {
|
||||
return printWarn("The --watch feature depends on Node v0.6.0+. You are running " + process.version + ".");
|
||||
return require('./repl').start(replCliOpts);
|
||||
}
|
||||
if (opts.stdio) {
|
||||
return compileStdio();
|
||||
}
|
||||
if (opts["eval"]) {
|
||||
return compileScript(null, sources[0]);
|
||||
return compileScript(null, opts["arguments"][0]);
|
||||
}
|
||||
if (!sources.length) {
|
||||
return require('./repl').start();
|
||||
if (!opts["arguments"].length) {
|
||||
return require('./repl').start(replCliOpts);
|
||||
}
|
||||
literals = opts.run ? sources.splice(1) : [];
|
||||
literals = opts.run ? opts["arguments"].splice(1) : [];
|
||||
process.argv = process.argv.slice(0, 2).concat(literals);
|
||||
process.argv[0] = 'coffee';
|
||||
if (opts.output) {
|
||||
opts.output = path.resolve(opts.output);
|
||||
}
|
||||
if (opts.join) {
|
||||
opts.join = path.resolve(opts.join);
|
||||
}
|
||||
_ref1 = opts["arguments"];
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
source = sources[_i];
|
||||
_results.push(compilePath(source, true, path.normalize(source)));
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
source = _ref1[_i];
|
||||
source = path.resolve(source);
|
||||
_results.push(compilePath(source, true, source));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
compilePath = function(source, topLevel, base) {
|
||||
return fs.stat(source, function(err, stats) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
if ((err != null ? err.code : void 0) === 'ENOENT') {
|
||||
var code, err, file, files, stats, _i, _len, _results;
|
||||
if (__indexOf.call(sources, source) >= 0 || watchedDirs[source] || !topLevel && (notSources[source] || hidden(source))) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
stats = fs.statSync(source);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.code === 'ENOENT') {
|
||||
console.error("File not found: " + source);
|
||||
process.exit(1);
|
||||
}
|
||||
if (stats.isDirectory() && path.dirname(source) !== 'node_modules') {
|
||||
if (opts.watch) {
|
||||
watchDir(source, base);
|
||||
}
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, index, _ref1, _ref2;
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
if ((err != null ? err.code : void 0) === 'ENOENT') {
|
||||
return;
|
||||
}
|
||||
index = sources.indexOf(source);
|
||||
files = files.filter(function(file) {
|
||||
return !hidden(file);
|
||||
});
|
||||
[].splice.apply(sources, [index, index - index + 1].concat(_ref1 = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
_results.push(path.join(source, file));
|
||||
}
|
||||
return _results;
|
||||
})())), _ref1;
|
||||
[].splice.apply(sourceCode, [index, index - index + 1].concat(_ref2 = files.map(function() {
|
||||
return null;
|
||||
}))), _ref2;
|
||||
return files.forEach(function(file) {
|
||||
return compilePath(path.join(source, file), false, base);
|
||||
});
|
||||
});
|
||||
} else if (topLevel || helpers.isCoffee(source)) {
|
||||
if (opts.watch) {
|
||||
watch(source, base);
|
||||
}
|
||||
return fs.readFile(source, function(err, code) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
if ((err != null ? err.code : void 0) === 'ENOENT') {
|
||||
return;
|
||||
}
|
||||
return compileScript(source, code.toString(), base);
|
||||
});
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
if (stats.isDirectory()) {
|
||||
if (path.basename(source) === 'node_modules') {
|
||||
notSources[source] = true;
|
||||
return removeSource(source, base);
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (opts.run) {
|
||||
compilePath(findDirectoryIndex(source), topLevel, base);
|
||||
return;
|
||||
}
|
||||
if (opts.watch) {
|
||||
watchDir(source, base);
|
||||
}
|
||||
try {
|
||||
files = fs.readdirSync(source);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.code === 'ENOENT') {
|
||||
return;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
_results.push(compilePath(path.join(source, file), false, base));
|
||||
}
|
||||
return _results;
|
||||
} else if (topLevel || helpers.isCoffee(source)) {
|
||||
sources.push(source);
|
||||
sourceCode.push(null);
|
||||
delete notSources[source];
|
||||
if (opts.watch) {
|
||||
watch(source, base);
|
||||
}
|
||||
try {
|
||||
code = fs.readFileSync(source);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.code === 'ENOENT') {
|
||||
return;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return compileScript(source, code.toString(), base);
|
||||
} else {
|
||||
return notSources[source] = true;
|
||||
}
|
||||
};
|
||||
|
||||
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];
|
||||
index = path.join(source, "index" + ext);
|
||||
try {
|
||||
if ((fs.statSync(index)).isFile()) {
|
||||
return index;
|
||||
}
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.error("Missing index.coffee or index.litcoffee in " + source);
|
||||
return process.exit(1);
|
||||
};
|
||||
|
||||
compileScript = function(file, input, base) {
|
||||
var compiled, o, options, t, task;
|
||||
var compiled, err, message, o, options, t, task;
|
||||
if (base == null) {
|
||||
base = null;
|
||||
}
|
||||
o = opts;
|
||||
options = compileOptions(file);
|
||||
options = compileOptions(file, base);
|
||||
try {
|
||||
t = task = {
|
||||
file: file,
|
||||
@@ -163,8 +203,12 @@
|
||||
} else if (o.nodes) {
|
||||
return printLine(CoffeeScript.nodes(t.input, t.options).toString().trim());
|
||||
} else if (o.run) {
|
||||
CoffeeScript.register();
|
||||
return CoffeeScript.run(t.input, t.options);
|
||||
} else if (o.join && t.file !== o.join) {
|
||||
if (helpers.isLiterate(file)) {
|
||||
t.input = helpers.invertLiterate(t.input);
|
||||
}
|
||||
sourceCode[sources.indexOf(t.file)] = t.input;
|
||||
return compileJoin();
|
||||
} else {
|
||||
@@ -178,21 +222,22 @@
|
||||
if (o.print) {
|
||||
return printLine(t.output.trim());
|
||||
} else if (o.compile || o.map) {
|
||||
return writeJs(base, t.file, t.output, t.sourceMap);
|
||||
} else if (o.lint) {
|
||||
return lint(t.file, t.output);
|
||||
return writeJs(base, t.file, t.output, options.jsPath, t.sourceMap);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
CoffeeScript.emit('failure', err, task);
|
||||
if (CoffeeScript.listeners('failure').length) {
|
||||
return;
|
||||
}
|
||||
message = err.stack || ("" + err);
|
||||
if (o.watch) {
|
||||
return printLine(err.message + '\x07');
|
||||
return printLine(message + '\x07');
|
||||
} else {
|
||||
printWarn(message);
|
||||
return process.exit(1);
|
||||
}
|
||||
printWarn(err instanceof Error && err.stack || ("ERROR: " + err));
|
||||
return process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -227,23 +272,23 @@
|
||||
};
|
||||
|
||||
watch = function(source, base) {
|
||||
var compile, compileTimeout, prevStats, rewatch, watchErr, watcher;
|
||||
var compile, compileTimeout, err, prevStats, rewatch, startWatcher, watchErr, watcher;
|
||||
watcher = null;
|
||||
prevStats = null;
|
||||
compileTimeout = null;
|
||||
watchErr = function(e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
if (sources.indexOf(source) === -1) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
rewatch();
|
||||
return compile();
|
||||
} catch (e) {
|
||||
removeSource(source, base, true);
|
||||
return compileJoin();
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
watchErr = function(err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
if (__indexOf.call(sources, source) < 0) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
rewatch();
|
||||
return compile();
|
||||
} catch (_error) {
|
||||
removeSource(source, base);
|
||||
return compileJoin();
|
||||
}
|
||||
};
|
||||
compile = function() {
|
||||
@@ -267,126 +312,138 @@
|
||||
});
|
||||
});
|
||||
};
|
||||
try {
|
||||
watcher = fs.watch(source, compile);
|
||||
} catch (e) {
|
||||
watchErr(e);
|
||||
}
|
||||
return rewatch = function() {
|
||||
startWatcher = function() {
|
||||
return watcher = fs.watch(source).on('change', compile).on('error', function(err) {
|
||||
if (err.code !== 'EPERM') {
|
||||
throw err;
|
||||
}
|
||||
return removeSource(source, base);
|
||||
});
|
||||
};
|
||||
rewatch = function() {
|
||||
if (watcher != null) {
|
||||
watcher.close();
|
||||
}
|
||||
return watcher = fs.watch(source, compile);
|
||||
return startWatcher();
|
||||
};
|
||||
try {
|
||||
return startWatcher();
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
return watchErr(err);
|
||||
}
|
||||
};
|
||||
|
||||
watchDir = function(source, base) {
|
||||
var readdirTimeout, watcher;
|
||||
var err, readdirTimeout, startWatcher, stopWatcher, watcher;
|
||||
watcher = null;
|
||||
readdirTimeout = null;
|
||||
try {
|
||||
return watcher = fs.watch(source, function() {
|
||||
startWatcher = function() {
|
||||
return watcher = fs.watch(source).on('error', function(err) {
|
||||
if (err.code !== 'EPERM') {
|
||||
throw err;
|
||||
}
|
||||
return stopWatcher();
|
||||
}).on('change', function() {
|
||||
clearTimeout(readdirTimeout);
|
||||
return readdirTimeout = wait(25, function() {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, _i, _len, _results;
|
||||
if (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
watcher.close();
|
||||
return unwatchDir(source, base);
|
||||
var err, file, files, _i, _len, _results;
|
||||
try {
|
||||
files = fs.readdirSync(source);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
if (!(!hidden(file) && !notSources[file])) {
|
||||
continue;
|
||||
}
|
||||
file = path.join(source, file);
|
||||
if (sources.some(function(s) {
|
||||
return s.indexOf(file) >= 0;
|
||||
})) {
|
||||
continue;
|
||||
}
|
||||
sources.push(file);
|
||||
sourceCode.push(null);
|
||||
_results.push(compilePath(file, false, base));
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
return stopWatcher();
|
||||
}
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
_results.push(compilePath(path.join(source, file), false, base));
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') {
|
||||
throw e;
|
||||
};
|
||||
stopWatcher = function() {
|
||||
watcher.close();
|
||||
return removeSourceDir(source, base);
|
||||
};
|
||||
watchedDirs[source] = true;
|
||||
try {
|
||||
return startWatcher();
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
unwatchDir = function(source, base) {
|
||||
var file, prevSources, toRemove, _i, _len;
|
||||
prevSources = sources.slice(0);
|
||||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
if (file.indexOf(source) >= 0) {
|
||||
_results.push(file);
|
||||
}
|
||||
removeSourceDir = function(source, base) {
|
||||
var file, sourcesChanged, _i, _len;
|
||||
delete watchedDirs[source];
|
||||
sourcesChanged = false;
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
if (!(source === path.dirname(file))) {
|
||||
continue;
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) {
|
||||
file = toRemove[_i];
|
||||
removeSource(file, base, true);
|
||||
removeSource(file, base);
|
||||
sourcesChanged = true;
|
||||
}
|
||||
if (!sources.some(function(s, i) {
|
||||
return prevSources[i] !== s;
|
||||
})) {
|
||||
return;
|
||||
if (sourcesChanged) {
|
||||
return compileJoin();
|
||||
}
|
||||
return compileJoin();
|
||||
};
|
||||
|
||||
removeSource = function(source, base, removeJs) {
|
||||
var index, jsPath;
|
||||
removeSource = function(source, base) {
|
||||
var index;
|
||||
index = sources.indexOf(source);
|
||||
sources.splice(index, 1);
|
||||
sourceCode.splice(index, 1);
|
||||
if (removeJs && !opts.join) {
|
||||
jsPath = outputPath(source, base);
|
||||
return exists(jsPath, function(itExists) {
|
||||
if (itExists) {
|
||||
return fs.unlink(jsPath, function(err) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
return timeLog("removed " + source);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (!opts.join) {
|
||||
silentUnlink(outputPath(source, base));
|
||||
silentUnlink(outputPath(source, base, '.map'));
|
||||
return timeLog("removed " + source);
|
||||
}
|
||||
};
|
||||
|
||||
silentUnlink = function(path) {
|
||||
var err, _ref1;
|
||||
try {
|
||||
return fs.unlinkSync(path);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if ((_ref1 = err.code) !== 'ENOENT' && _ref1 !== 'EPERM') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
outputPath = function(source, base, extension) {
|
||||
var baseDir, basename, dir, srcDir;
|
||||
var basename, dir, srcDir;
|
||||
if (extension == null) {
|
||||
extension = ".js";
|
||||
}
|
||||
basename = helpers.baseFileName(source, true);
|
||||
basename = helpers.baseFileName(source, true, useWinPathSep);
|
||||
srcDir = path.dirname(source);
|
||||
baseDir = base === '.' ? srcDir : srcDir.substring(base.length);
|
||||
dir = opts.output ? path.join(opts.output, baseDir) : srcDir;
|
||||
if (!opts.output) {
|
||||
dir = srcDir;
|
||||
} else if (source === base) {
|
||||
dir = opts.output;
|
||||
} else {
|
||||
dir = path.join(opts.output, path.relative(base, srcDir));
|
||||
}
|
||||
return path.join(dir, basename + extension);
|
||||
};
|
||||
|
||||
writeJs = function(base, sourcePath, js, generatedSourceMap) {
|
||||
var compile, jsDir, jsPath, sourceMapPath;
|
||||
writeJs = function(base, sourcePath, js, jsPath, generatedSourceMap) {
|
||||
var compile, jsDir, sourceMapPath;
|
||||
if (generatedSourceMap == null) {
|
||||
generatedSourceMap = null;
|
||||
}
|
||||
jsPath = outputPath(sourcePath, base);
|
||||
sourceMapPath = outputPath(sourcePath, base, ".map");
|
||||
jsDir = path.dirname(jsPath);
|
||||
compile = function() {
|
||||
@@ -395,7 +452,7 @@
|
||||
js = ' ';
|
||||
}
|
||||
if (generatedSourceMap) {
|
||||
js = "//@ sourceMappingURL=" + (helpers.baseFileName(sourceMapPath)) + "\n" + js;
|
||||
js = "" + js + "\n//# sourceMappingURL=" + (helpers.baseFileName(sourceMapPath, false, useWinPathSep)) + "\n";
|
||||
}
|
||||
fs.writeFile(jsPath, js, function(err) {
|
||||
if (err) {
|
||||
@@ -413,11 +470,11 @@
|
||||
});
|
||||
}
|
||||
};
|
||||
return exists(jsDir, function(itExists) {
|
||||
return fs.exists(jsDir, function(itExists) {
|
||||
if (itExists) {
|
||||
return compile();
|
||||
} else {
|
||||
return exec("mkdir -p " + jsDir, compile);
|
||||
return mkdirp(jsDir, compile);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -430,19 +487,6 @@
|
||||
return console.log("" + ((new Date).toLocaleTimeString()) + " - " + message);
|
||||
};
|
||||
|
||||
lint = function(file, js) {
|
||||
var conf, jsl, printIt;
|
||||
printIt = function(buffer) {
|
||||
return printLine(file + ':\t' + buffer.toString().trim());
|
||||
};
|
||||
conf = __dirname + '/../../extras/jsl.conf';
|
||||
jsl = spawn('jsl', ['-nologo', '-stdin', '-conf', conf]);
|
||||
jsl.stdout.on('data', printIt);
|
||||
jsl.stderr.on('data', printIt);
|
||||
jsl.stdin.write(js);
|
||||
return jsl.stdin.end();
|
||||
};
|
||||
|
||||
printTokens = function(tokens) {
|
||||
var strings, tag, token, value;
|
||||
strings = (function() {
|
||||
@@ -460,39 +504,58 @@
|
||||
};
|
||||
|
||||
parseOptions = function() {
|
||||
var i, o, source, _i, _len;
|
||||
var o;
|
||||
optionParser = new optparse.OptionParser(SWITCHES, BANNER);
|
||||
o = opts = optionParser.parse(process.argv.slice(2));
|
||||
o.compile || (o.compile = !!o.output);
|
||||
o.run = !(o.compile || o.print || o.lint || o.map);
|
||||
o.print = !!(o.print || (o["eval"] || o.stdio && o.compile));
|
||||
sources = o["arguments"];
|
||||
for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) {
|
||||
source = sources[i];
|
||||
sourceCode[i] = null;
|
||||
}
|
||||
o.run = !(o.compile || o.print || o.map);
|
||||
return o.print = !!(o.print || (o["eval"] || o.stdio && o.compile));
|
||||
};
|
||||
|
||||
compileOptions = function(filename) {
|
||||
return {
|
||||
compileOptions = function(filename, base) {
|
||||
var answer, cwd, jsDir, jsPath;
|
||||
answer = {
|
||||
filename: filename,
|
||||
literate: helpers.isLiterate(filename),
|
||||
literate: opts.literate || helpers.isLiterate(filename),
|
||||
bare: opts.bare,
|
||||
header: opts.compile,
|
||||
header: opts.compile && !opts['no-header'],
|
||||
sourceMap: opts.map
|
||||
};
|
||||
if (filename) {
|
||||
if (base) {
|
||||
cwd = process.cwd();
|
||||
jsPath = outputPath(filename, base);
|
||||
jsDir = path.dirname(jsPath);
|
||||
answer = helpers.merge(answer, {
|
||||
jsPath: jsPath,
|
||||
sourceRoot: path.relative(jsDir, cwd),
|
||||
sourceFiles: [path.relative(cwd, filename)],
|
||||
generatedFile: helpers.baseFileName(jsPath, false, useWinPathSep)
|
||||
});
|
||||
} else {
|
||||
answer = helpers.merge(answer, {
|
||||
sourceRoot: "",
|
||||
sourceFiles: [helpers.baseFileName(filename, false, useWinPathSep)],
|
||||
generatedFile: helpers.baseFileName(filename, true, useWinPathSep) + ".js"
|
||||
});
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
};
|
||||
|
||||
forkNode = function() {
|
||||
var args, nodeArgs;
|
||||
var args, nodeArgs, p;
|
||||
nodeArgs = opts.nodejs.split(/\s+/);
|
||||
args = process.argv.slice(1);
|
||||
args.splice(args.indexOf('--nodejs'), 2);
|
||||
return spawn(process.execPath, nodeArgs.concat(args), {
|
||||
p = spawn(process.execPath, nodeArgs.concat(args), {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
customFds: [0, 1, 2]
|
||||
});
|
||||
return p.on('exit', function(code) {
|
||||
return process.exit(code);
|
||||
});
|
||||
};
|
||||
|
||||
usage = function() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user