1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fixed lingering CoffeeScript Compiler running live in Internet Explorer bugs. Implemented helpers.index_of and removed named functions. Ticket #366

This commit is contained in:
Jeremy Ashkenas 2010-05-14 23:40:04 -04:00
parent f84eb9ed47
commit dfb3a13246
16 changed files with 319 additions and 298 deletions

View file

@ -24,7 +24,7 @@
// Run `coffee` by parsing passed options and determining what action to take.
// Many flags cause us to divert before compiling anything. Flags passed after
// `--` will be passed verbatim to your script as arguments in `process.argv`
exports.run = function run() {
exports.run = function() {
var flags, separator;
parse_options();
if (options.help) {
@ -57,14 +57,14 @@
// Asynchronously read in each CoffeeScript in a list of source files and
// compile them. If a directory is passed, recursively compile all source
// files in it and all subdirectories.
compile_scripts = function compile_scripts() {
compile_scripts = function() {
var _b, _c, _d, _e, base, compile, source;
_b = []; _d = sources;
for (_c = 0, _e = _d.length; _c < _e; _c++) {
source = _d[_c];
_b.push((function() {
base = source;
compile = function compile(source) {
compile = function(source) {
return path.exists(source, function(exists) {
if (!(exists)) {
throw new Error(("File not found: " + source));
@ -99,7 +99,7 @@
// Compile a single source script, containing the given code, according to the
// requested options. If evaluating the script directly sets `__filename`,
// `__dirname` and `module.filename` to be correct relative to the script's path.
compile_script = function compile_script(source, code, base) {
compile_script = function(source, code, base) {
var code_opts, js, o;
o = options;
code_opts = compile_options(source);
@ -130,7 +130,7 @@
};
// Attach the appropriate listeners to compile scripts incoming over **stdin**,
// and write them back to **stdout**.
compile_stdio = function compile_stdio() {
compile_stdio = function() {
var code, stdin;
code = '';
stdin = process.openStdin();
@ -146,7 +146,7 @@
// Watch a source CoffeeScript file using `fs.watchFile`, recompiling it every
// time the file is updated. May be used in combination with other options,
// such as `--lint` or `--print`.
watch = function watch(source, base) {
watch = function(source, base) {
return fs.watchFile(source, {
persistent: true,
interval: 500
@ -165,14 +165,14 @@
// Write out a JavaScript source file with the compiled code. By default, files
// are written out in `cwd` as `.js` files with the same name, but the output
// directory can be customized with `--output`.
write_js = function write_js(source, js, base) {
write_js = function(source, js, base) {
var base_dir, compile, dir, filename, js_path, src_dir;
filename = path.basename(source, path.extname(source)) + '.js';
src_dir = path.dirname(source);
base_dir = src_dir.substring(base.length);
dir = options.output ? path.join(options.output, base_dir) : src_dir;
js_path = path.join(dir, filename);
compile = function compile() {
compile = function() {
return fs.writeFile(js_path, js);
};
return path.exists(dir, function(exists) {
@ -185,9 +185,9 @@
};
// Pipe compiled JS through JSLint (requires a working `jsl` command), printing
// any errors or warnings that arise.
lint = function lint(js) {
lint = function(js) {
var jsl, print_it;
print_it = function print_it(buffer) {
print_it = function(buffer) {
return print(buffer.toString());
};
jsl = spawn('jsl', ['-nologo', '-stdin']);
@ -197,7 +197,7 @@
return jsl.stdin.end();
};
// Pretty-print a stream of tokens.
print_tokens = function print_tokens(tokens) {
print_tokens = function(tokens) {
var _b, _c, _d, _e, _f, strings, tag, token, value;
strings = (function() {
_b = []; _d = tokens;
@ -216,7 +216,7 @@
};
// Use the [OptionParser module](optparse.html) to extract all options from
// `process.argv` that are specified in `SWITCHES`.
parse_options = function parse_options() {
parse_options = function() {
var o;
option_parser = new optparse.OptionParser(SWITCHES, BANNER);
o = (options = option_parser.parse(process.argv));
@ -226,7 +226,7 @@
return sources;
};
// The compile-time options to pass to the CoffeeScript compiler.
compile_options = function compile_options(source) {
compile_options = function(source) {
var o;
o = {
source: source
@ -235,12 +235,12 @@
return o;
};
// Print the `--help` usage message and exit.
usage = function usage() {
usage = function() {
puts(option_parser.help());
return process.exit(0);
};
// Print the `--version` message and exit.
version = function version() {
version = function() {
puts(("CoffeeScript version " + CoffeeScript.VERSION));
return process.exit(0);
};