#2490 -- implementing a conditional in terms of the guard style.

This commit is contained in:
Jeremy Ashkenas
2013-03-10 06:44:45 +08:00
parent c53df12ec1
commit b44435ab8a
2 changed files with 29 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.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, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, runScripts, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
fs = require('fs');
@@ -49,32 +49,26 @@
optionParser = null;
exports.run = function() {
var literals, source, _i, _len, _results;
parseOptions();
if (opts.nodejs) {
return forkNode();
}
if (opts.help) {
return usage();
}
if (opts.version) {
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 + ".");
}
if (opts.stdio) {
return compileStdio();
}
if (opts["eval"]) {
return forkNode;
} else if (opts.help) {
return usage;
} else if (opts.version) {
return version;
} else if (opts.stdio) {
return compileStdio;
} else if (opts["eval"]) {
return compileScript(null, sources[0]);
}
if (!sources.length) {
} else if (opts.interactive) {
return require('./repl').start();
} else {
return runScripts;
}
};
runScripts = function() {
var literals, source, _i, _len, _results;
literals = opts.run ? sources.splice(1) : [];
process.argv = process.argv.slice(0, 2).concat(literals);
process.argv[0] = 'coffee';
@@ -476,6 +470,7 @@
o.run = !(o.compile || o.print || o.lint || o.map);
o.print = !!(o.print || (o["eval"] || o.stdio && o.compile));
sources = o["arguments"];
o.interactive || (o.interactive = sources.length === 0);
for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) {
source = sources[i];
sourceCode[i] = null;

View File

@@ -63,15 +63,17 @@ optionParser = null
# `--` will be passed verbatim to your script as arguments in `process.argv`
exports.run = ->
parseOptions()
return forkNode() if opts.nodejs
return usage() if opts.help
return version() if opts.version
return require('./repl').start() if opts.interactive
if opts.watch and !fs.watch
return printWarn "The --watch feature depends on Node v0.6.0+. You are running #{process.version}."
return compileStdio() if opts.stdio
return compileScript null, sources[0] if opts.eval
return require('./repl').start() unless sources.length
if
opts.nodejs then forkNode
opts.help then usage
opts.version then version
opts.stdio then compileStdio
opts.eval then compileScript null, sources[0]
opts.interactive then require('./repl').start()
else runScripts
# Run passed CoffeeScript files by evaluating them, in order.
runScripts = ->
literals = if opts.run then sources.splice 1 else []
process.argv = process.argv[0..1].concat literals
process.argv[0] = 'coffee'
@@ -108,7 +110,6 @@ compilePath = (source, topLevel, base) ->
notSources[source] = yes
removeSource source, base
# 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.
@@ -318,6 +319,7 @@ parseOptions = ->
o.run = not (o.compile or o.print or o.lint or o.map)
o.print = !! (o.print or (o.eval or o.stdio and o.compile))
sources = o.arguments
o.interactive or= sources.length is 0
sourceCode[i] = null for source, i in sources
return