mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 19:11:22 -05:00
enabling the --eval option for the self-compiler
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
coffee = require('coffee-script');
|
coffee = require('coffee-script');
|
||||||
optparse = require('./../../vendor/optparse-js/src/optparse');
|
optparse = require('./../../vendor/optparse-js/src/optparse');
|
||||||
BANNER = "coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee";
|
BANNER = "coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee";
|
||||||
SWITCHES = [['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-r', '--run', 'compile and run a CoffeeScript'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-e', '--eval', 'compile a cli scriptlet or read from stdin'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['--tree', 'print the parse tree that Jison produces'], ['-n', '--no-wrap', 'raw output, no function safety wrapper'], ['-g', '--globals', 'attach all top-level variables as globals'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
SWITCHES = [['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-r', '--run', 'compile and run a CoffeeScript'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-e', '--eval', 'compile a string from the command line'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-tr', '--tree', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
||||||
WATCH_INTERVAL = 0.5;
|
WATCH_INTERVAL = 0.5;
|
||||||
options = {};
|
options = {};
|
||||||
sources = [];
|
sources = [];
|
||||||
@@ -16,6 +16,9 @@
|
|||||||
if (options.interactive) {
|
if (options.interactive) {
|
||||||
return require('./repl');
|
return require('./repl');
|
||||||
}
|
}
|
||||||
|
if (options.eval) {
|
||||||
|
return puts(coffee.compile(sources[0]));
|
||||||
|
}
|
||||||
if (!(sources.length)) {
|
if (!(sources.length)) {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,9 @@ SWITCHES: [
|
|||||||
['-w', '--watch', 'watch scripts for changes, and recompile']
|
['-w', '--watch', 'watch scripts for changes, and recompile']
|
||||||
['-p', '--print', 'print the compiled JavaScript to stdout']
|
['-p', '--print', 'print the compiled JavaScript to stdout']
|
||||||
['-l', '--lint', 'pipe the compiled JavaScript through JSLint']
|
['-l', '--lint', 'pipe the compiled JavaScript through JSLint']
|
||||||
['-e', '--eval', 'compile a cli scriptlet or read from stdin']
|
['-e', '--eval', 'compile a string from the command line']
|
||||||
['-t', '--tokens', 'print the tokens that the lexer produces']
|
['-t', '--tokens', 'print the tokens that the lexer produces']
|
||||||
[ '--tree', 'print the parse tree that Jison produces']
|
['-tr','--tree', 'print the parse tree that Jison produces']
|
||||||
['-n', '--no-wrap', 'raw output, no function safety wrapper']
|
|
||||||
['-g', '--globals', 'attach all top-level variables as globals']
|
|
||||||
['-v', '--version', 'display CoffeeScript version']
|
['-v', '--version', 'display CoffeeScript version']
|
||||||
['-h', '--help', 'display this help message']
|
['-h', '--help', 'display this help message']
|
||||||
]
|
]
|
||||||
@@ -36,6 +34,7 @@ option_parser: null
|
|||||||
exports.run: ->
|
exports.run: ->
|
||||||
parse_options()
|
parse_options()
|
||||||
return require './repl' if options.interactive
|
return require './repl' if options.interactive
|
||||||
|
return puts coffee.compile sources[0] if options.eval
|
||||||
usage() unless sources.length
|
usage() unless sources.length
|
||||||
compile_scripts()
|
compile_scripts()
|
||||||
this
|
this
|
||||||
|
|||||||
Reference in New Issue
Block a user