Skip to content

Commit e88619a

Browse files
committed
Merge branch 'master' into 2
# Conflicts: # documentation/sections/resources.md # lib/coffee-script/browser.js # lib/coffee-script/cake.js # lib/coffee-script/coffee-script.js # lib/coffee-script/command.js # lib/coffee-script/grammar.js # lib/coffee-script/helpers.js # lib/coffee-script/index.js # lib/coffee-script/lexer.js # lib/coffee-script/nodes.js # lib/coffee-script/optparse.js # lib/coffee-script/register.js # lib/coffee-script/repl.js # lib/coffee-script/rewriter.js # lib/coffee-script/scope.js # lib/coffee-script/sourcemap.js # package.json
2 parents d1d2c16 + 91e3f72 commit e88619a

File tree

17 files changed

+912
-645
lines changed

17 files changed

+912
-645
lines changed

Cakefile

Lines changed: 118 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,31 @@ header = """
2424
*/
2525
"""
2626

27-
# Used in folder names like docs/v1
27+
# Used in folder names like `docs/v1`.
2828
majorVersion = parseInt CoffeeScript.VERSION.split('.')[0], 10
2929

30-
# Build the CoffeeScript language from source.
31-
build = (cb) ->
32-
files = fs.readdirSync 'src'
33-
files = ('src/' + file for file in files when file.match(/\.(lit)?coffee$/))
34-
run ['-c', '-o', 'lib/coffee-script'].concat(files), cb
35-
36-
# Run a CoffeeScript through our node/coffee interpreter.
37-
run = (args, cb) ->
38-
proc = spawn 'node', ['bin/coffee'].concat(args)
39-
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
40-
proc.on 'exit', (status) ->
41-
process.exit(1) if status isnt 0
42-
cb() if typeof cb is 'function'
4330

4431
# Log a message with a color.
4532
log = (message, color, explanation) ->
4633
console.log color + message + reset + ' ' + (explanation or '')
4734

48-
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
49-
50-
task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
51-
base = options.prefix or '/usr/local'
52-
lib = "#{base}/lib/coffee-script"
53-
bin = "#{base}/bin"
54-
node = "~/.node_libraries/coffee-script"
55-
console.log "Installing CoffeeScript to #{lib}"
56-
console.log "Linking to #{node}"
57-
console.log "Linking 'coffee' to #{bin}/coffee"
58-
exec([
59-
"mkdir -p #{lib} #{bin}"
60-
"cp -rf bin lib LICENSE README.md package.json src #{lib}"
61-
"ln -sfn #{lib}/bin/coffee #{bin}/coffee"
62-
"ln -sfn #{lib}/bin/cake #{bin}/cake"
63-
"mkdir -p ~/.node_libraries"
64-
"ln -sfn #{lib}/lib/coffee-script #{node}"
65-
].join(' && '), (err, stdout, stderr) ->
66-
if err then console.log stderr.trim() else log 'done', green
67-
)
68-
69-
70-
task 'build', 'build the CoffeeScript language from source', build
71-
72-
task 'build:full', 'rebuild the source twice, and run the tests', ->
73-
build ->
74-
build ->
75-
csPath = './lib/coffee-script'
76-
csDir = path.dirname require.resolve csPath
7735

78-
for mod of require.cache when csDir is mod[0 ... csDir.length]
79-
delete require.cache[mod]
36+
spawnNodeProcess = (args, output = 'stderr', callback) ->
37+
relayOutput = (buffer) -> console.log buffer.toString()
38+
proc = spawn 'node', args
39+
proc.stdout.on 'data', relayOutput if output is 'both' or output is 'stdout'
40+
proc.stderr.on 'data', relayOutput if output is 'both' or output is 'stderr'
41+
proc.on 'exit', (status) -> callback(status) if typeof callback is 'function'
8042

81-
unless runTests require csPath
82-
process.exit 1
43+
# Run a CoffeeScript through our node/coffee interpreter.
44+
run = (args, callback) ->
45+
spawnNodeProcess ['bin/coffee'].concat(args), 'stderr', (status) ->
46+
process.exit(1) if status isnt 0
47+
callback() if typeof callback is 'function'
8348

8449

85-
task 'build:parser', 'rebuild the Jison parser (run build first)', ->
50+
# Build the CoffeeScript language from source.
51+
buildParser = ->
8652
helpers.extend global, require 'util'
8753
require 'jison'
8854
parser = require('./lib/coffee-script/grammar').parser.generate()
@@ -95,8 +61,62 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
9561
source = fs"""
9662
fs.writeFileSync 'lib/coffee-script/parser.js', parser
9763

64+
buildExceptParser = (callback) ->
65+
files = fs.readdirSync 'src'
66+
files = ('src/' + file for file in files when file.match(/\.(lit)?coffee$/))
67+
run ['-c', '-o', 'lib/coffee-script'].concat(files), callback
68+
69+
build = (callback) ->
70+
buildParser()
71+
buildExceptParser callback
72+
73+
testBuiltCode = (watch = no) ->
74+
csPath = './lib/coffee-script'
75+
csDir = path.dirname require.resolve csPath
76+
77+
for mod of require.cache when csDir is mod[0 ... csDir.length]
78+
delete require.cache[mod]
79+
80+
testResults = runTests require csPath
81+
unless watch
82+
process.exit 1 unless testResults
83+
84+
buildAndTest = (includingParser = yes, harmony = no) ->
85+
process.stdout.write '\x1Bc' # Clear terminal screen.
86+
execSync 'git checkout lib/*', stdio: [0,1,2] # Reset the generated compiler.
87+
88+
buildArgs = ['bin/cake']
89+
buildArgs.push if includingParser then 'build' else 'build:except-parser'
90+
log "building#{if includingParser then ', including parser' else ''}...", green
91+
spawnNodeProcess buildArgs, 'both', ->
92+
log 'testing...', green
93+
testArgs = if harmony then ['--harmony'] else []
94+
testArgs = testArgs.concat ['bin/cake', 'test']
95+
spawnNodeProcess testArgs, 'both'
9896

99-
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
97+
watchAndBuildAndTest = (harmony = no) ->
98+
buildAndTest yes, harmony
99+
fs.watch 'src/', interval: 200, (eventType, filename) ->
100+
if eventType is 'change'
101+
log "src/#{filename} changed, rebuilding..."
102+
buildAndTest (filename is 'grammar.coffee'), harmony
103+
fs.watch 'test/', {interval: 200, recursive: yes}, (eventType, filename) ->
104+
if eventType is 'change'
105+
log "test/#{filename} changed, rebuilding..."
106+
buildAndTest no, harmony
107+
108+
109+
task 'build', 'build the CoffeeScript compiler from source', build
110+
111+
task 'build:parser', 'build the Jison parser only', buildParser
112+
113+
task 'build:except-parser', 'build the CoffeeScript compiler, except for the Jison parser', buildExceptParser
114+
115+
task 'build:full', 'build the CoffeeScript compiler from source twice, and run the tests', ->
116+
build ->
117+
build testBuiltCode
118+
119+
task 'build:browser', 'build the merged script for inclusion in the browser', ->
100120
code = """
101121
require['../../package.json'] = (function() {
102122
return #{fs.readFileSync "./package.json"};
@@ -145,8 +165,14 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
145165
console.log "built ... running browser tests:"
146166
invoke 'test:browser'
147167

168+
task 'build:watch', 'watch and continually rebuild the CoffeeScript compiler, running tests on each build', ->
169+
watchAndBuildAndTest()
170+
171+
task 'build:watch:harmony', 'watch and continually rebuild the CoffeeScript compiler, running harmony tests on each build', ->
172+
watchAndBuildAndTest yes
173+
148174

149-
task 'doc:site', 'watch and continually rebuild the documentation for the website', ->
175+
buildDocs = (watch = no) ->
150176
# Constants
151177
indexFile = 'documentation/index.html'
152178
versionedSourceFolder = "documentation/v#{majorVersion}"
@@ -219,12 +245,19 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
219245
fs.symlinkSync "v#{majorVersion}/index.html", 'docs/index.html'
220246
catch exception
221247

222-
for target in [indexFile, versionedSourceFolder, examplesSourceFolder, sectionsSourceFolder]
223-
fs.watch target, interval: 200, renderIndex
224-
log 'watching...' , green
248+
if watch
249+
for target in [indexFile, versionedSourceFolder, examplesSourceFolder, sectionsSourceFolder]
250+
fs.watch target, interval: 200, renderIndex
251+
log 'watching...', green
225252

253+
task 'doc:site', 'build the documentation for the website', ->
254+
buildDocs()
226255

227-
task 'doc:test', 'watch and continually rebuild the browser-based tests', ->
256+
task 'doc:site:watch', 'watch and continually rebuild the documentation for the website', ->
257+
buildDocs yes
258+
259+
260+
buildDocTests = (watch = no) ->
228261
# Constants
229262
testFile = 'documentation/test.html'
230263
testsSourceFolder = 'test'
@@ -262,14 +295,40 @@ task 'doc:test', 'watch and continually rebuild the browser-based tests', ->
262295
fs.writeFileSync "#{outputFolder}/test.html", output
263296
log 'compiled', green, "#{testFile}#{outputFolder}/test.html"
264297

265-
for target in [testFile, testsSourceFolder]
266-
fs.watch target, interval: 200, renderTest
267-
log 'watching...' , green
298+
if watch
299+
for target in [testFile, testsSourceFolder]
300+
fs.watch target, interval: 200, renderTest
301+
log 'watching...', green
302+
303+
task 'doc:test', 'build the browser-based tests', ->
304+
buildDocTests()
305+
306+
task 'doc:test:watch', 'watch and continually rebuild the browser-based tests', ->
307+
buildDocTests yes
308+
309+
310+
buildAnnotatedSource = (watch = no) ->
311+
do generateAnnotatedSource = ->
312+
exec "node_modules/docco/bin/docco src/*.*coffee --output docs/v#{majorVersion}/annotated-source", (err) -> throw err if err
313+
log 'generated', green, "annotated source in docs/v#{majorVersion}/annotated-source/"
314+
315+
if watch
316+
fs.watch 'src/', interval: 200, generateAnnotatedSource
317+
log 'watching...', green
318+
319+
task 'doc:source', 'build the annotated source documentation', ->
320+
buildAnnotatedSource()
268321

322+
task 'doc:source:watch', 'watch and continually rebuild the annotated source documentation', ->
323+
buildAnnotatedSource yes
269324

270-
task 'doc:source', 'rebuild the annotated source documentation', ->
271-
exec "node_modules/docco/bin/docco src/*.*coffee --output docs/v#{majorVersion}/annotated-source", (err) -> throw err if err
272325

326+
task 'release', 'build and test the CoffeeScript source, and build the documentation', ->
327+
invoke 'build:full'
328+
invoke 'build:browser'
329+
invoke 'doc:site'
330+
invoke 'doc:test'
331+
invoke 'doc:source'
273332

274333
task 'bench', 'quick benchmark of compilation time', ->
275334
{Rewriter} = require './lib/coffee-script/rewriter'

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ CoffeeScript is a little language that compiles into JavaScript.
2525
If you have the node package manager, npm, installed:
2626

2727
```shell
28-
npm install -g coffee-script
28+
npm install --global coffee-script
2929
```
3030

31-
Leave off the `-g` if you don't wish to install globally. If you don't wish to use npm:
32-
33-
```shell
34-
git clone https://github.com/jashkenas/coffeescript.git
35-
sudo coffeescript/bin/cake install
36-
```
31+
Leave off the `--global` if you don’t wish to install globally.
3732

3833
## Getting Started
3934

@@ -53,7 +48,7 @@ For documentation, usage, and examples, see: http://coffeescript.org/
5348

5449
To suggest a feature or report a bug: http://github.com/jashkenas/coffeescript/issues
5550

56-
If you'd like to chat, drop by #coffeescript on Freenode IRC.
51+
If youd like to chat, drop by #coffeescript on Freenode IRC.
5752

5853
The source repository: https://github.com/jashkenas/coffeescript.git
5954

docs/v1/annotated-source/coffee-script.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ <h1>coffee-script.coffee</h1>
941941
answer = compile sources[filename],
942942
filename: filename
943943
sourceMap: <span class="hljs-literal">yes</span>
944+
literate: helpers.isLiterate filename
944945
answer.sourceMap
945946
<span class="hljs-keyword">else</span>
946947
<span class="hljs-literal">null</span></pre></div></div>

docs/v1/annotated-source/lexer.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ <h2 id="tokenizers">Tokenizers</h2>
710710
@token <span class="hljs-string">'CALL_START'</span>, <span class="hljs-string">'('</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>
711711
@mergeInterpolationTokens tokens, {delimiter: <span class="hljs-string">'"'</span>, double: <span class="hljs-literal">yes</span>}, @formatHeregex
712712
<span class="hljs-keyword">if</span> flags
713-
@token <span class="hljs-string">','</span>, <span class="hljs-string">','</span>, index, <span class="hljs-number">0</span>
714-
@token <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'"'</span> + flags + <span class="hljs-string">'"'</span>, index, flags.length
715-
@token <span class="hljs-string">')'</span>, <span class="hljs-string">')'</span>, end, <span class="hljs-number">0</span>
716-
@token <span class="hljs-string">'REGEX_END'</span>, <span class="hljs-string">')'</span>, end, <span class="hljs-number">0</span>
713+
@token <span class="hljs-string">','</span>, <span class="hljs-string">','</span>, index - <span class="hljs-number">1</span>, <span class="hljs-number">0</span>
714+
@token <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'"'</span> + flags + <span class="hljs-string">'"'</span>, index - <span class="hljs-number">1</span>, flags.length
715+
@token <span class="hljs-string">')'</span>, <span class="hljs-string">')'</span>, end - <span class="hljs-number">1</span>, <span class="hljs-number">0</span>
716+
@token <span class="hljs-string">'REGEX_END'</span>, <span class="hljs-string">')'</span>, end - <span class="hljs-number">1</span>, <span class="hljs-number">0</span>
717717

718718
end</pre></div></div>
719719

0 commit comments

Comments
 (0)