mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Nicer-looking --tokenize, more in line with what Ruby's doing
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
return posix.cat(source).addCallback(function(code) {
|
||||
var js;
|
||||
if (opts.tokens) {
|
||||
puts(coffee.tokenize(code).join(' '));
|
||||
puts(exports.tokenize(code));
|
||||
} else if (opts.tree) {
|
||||
puts(coffee.tree(code).toString());
|
||||
} else {
|
||||
@@ -83,6 +83,14 @@
|
||||
return posix.write(fd, js);
|
||||
});
|
||||
};
|
||||
// Pretty-print the token stream.
|
||||
exports.tokenize = function tokenize(code) {
|
||||
var strings;
|
||||
strings = coffee.tokenize(code).map(function(token) {
|
||||
return '[' + token[0] + ' ' + token[1].toString().replace(/\n/, '\\n') + ']';
|
||||
});
|
||||
return strings.join(' ');
|
||||
};
|
||||
// Pipe compiled JS through JSLint (requires a working 'jsl' command).
|
||||
exports.lint = function lint(js) {
|
||||
var jsl;
|
||||
|
||||
@@ -63,7 +63,7 @@ exports.compile_scripts: ->
|
||||
return unless source: @sources.shift()
|
||||
opts: @options
|
||||
posix.cat(source).addCallback (code) ->
|
||||
if opts.tokens then puts coffee.tokenize(code).join(' ')
|
||||
if opts.tokens then puts exports.tokenize(code)
|
||||
else if opts.tree then puts coffee.tree(code).toString()
|
||||
else
|
||||
js: coffee.compile code
|
||||
@@ -81,6 +81,12 @@ exports.write_js: (source, js) ->
|
||||
posix.open(js_path, process.O_CREAT | process.O_WRONLY | process.O_TRUNC, parseInt('0755', 8)).addCallback (fd) ->
|
||||
posix.write(fd, js)
|
||||
|
||||
# Pretty-print the token stream.
|
||||
exports.tokenize: (code) ->
|
||||
strings: coffee.tokenize(code).map (token) ->
|
||||
'[' + token[0] + ' ' + token[1].toString().replace(/\n/, '\\n') + ']'
|
||||
strings.join(' ')
|
||||
|
||||
# Pipe compiled JS through JSLint (requires a working 'jsl' command).
|
||||
exports.lint: (js) ->
|
||||
jsl: process.createChildProcess('jsl', ['-nologo', '-stdin'])
|
||||
|
||||
Reference in New Issue
Block a user