mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Reverting #2490
This commit is contained in:
parent
c7da623d4b
commit
dbb99f31a7
6 changed files with 83 additions and 142 deletions
|
@ -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, runScripts, 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, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
|
@ -49,26 +49,32 @@
|
|||
optionParser = null;
|
||||
|
||||
exports.run = function() {
|
||||
var literals, source, _i, _len, _results;
|
||||
parseOptions();
|
||||
if (opts.nodejs) {
|
||||
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]);
|
||||
} else if (opts.interactive) {
|
||||
return require('./repl').start();
|
||||
} else {
|
||||
return runScripts;
|
||||
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 compileScript(null, sources[0]);
|
||||
}
|
||||
if (!sources.length) {
|
||||
return require('./repl').start();
|
||||
}
|
||||
};
|
||||
|
||||
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';
|
||||
|
@ -470,7 +476,6 @@
|
|||
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;
|
||||
|
|
|
@ -515,20 +515,6 @@
|
|||
return $1.addElse(new If($4, $5, {
|
||||
type: $3
|
||||
}));
|
||||
}), o('IF INDENT GuardBlock OUTDENT', function() {
|
||||
$3.type = $1;
|
||||
return $3;
|
||||
}), o('IF INDENT GuardBlock ELSE Block OUTDENT', function() {
|
||||
$3.type = $1;
|
||||
$3.addElse($5);
|
||||
return $3;
|
||||
})
|
||||
],
|
||||
GuardBlock: [
|
||||
o('Expression Block', function() {
|
||||
return new If($1, $2);
|
||||
}), o('GuardBlock TERMINATOR Expression Block', function() {
|
||||
return $1.addElse(new If($3, $4));
|
||||
})
|
||||
],
|
||||
If: [
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -63,17 +63,15 @@ optionParser = null
|
|||
# `--` will be passed verbatim to your script as arguments in `process.argv`
|
||||
exports.run = ->
|
||||
parseOptions()
|
||||
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 = ->
|
||||
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
|
||||
literals = if opts.run then sources.splice 1 else []
|
||||
process.argv = process.argv[0..1].concat literals
|
||||
process.argv[0] = 'coffee'
|
||||
|
@ -110,6 +108,7 @@ 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.
|
||||
|
@ -119,31 +118,27 @@ compileScript = (file, input, base=null) ->
|
|||
try
|
||||
t = task = {file, input, options}
|
||||
CoffeeScript.emit 'compile', task
|
||||
if
|
||||
o.tokens
|
||||
printTokens CoffeeScript.tokens t.input, t.options
|
||||
o.nodes
|
||||
printLine CoffeeScript.nodes(t.input, t.options).toString().trim()
|
||||
o.run
|
||||
CoffeeScript.run t.input, t.options
|
||||
o.join and t.file isnt o.join
|
||||
t.input = helpers.invertLiterate t.input if helpers.isLiterate file
|
||||
sourceCode[sources.indexOf(t.file)] = t.input
|
||||
compileJoin()
|
||||
else
|
||||
compiled = CoffeeScript.compile t.input, t.options
|
||||
t.output = compiled
|
||||
if o.map
|
||||
t.output = compiled.js
|
||||
t.sourceMap = compiled.v3SourceMap
|
||||
CoffeeScript.emit 'success', task
|
||||
if
|
||||
o.print
|
||||
printLine t.output.trim()
|
||||
o.compile or o.map
|
||||
writeJs base, t.file, t.output, options.jsPath, t.sourceMap
|
||||
o.lint
|
||||
lint t.file, t.output
|
||||
if o.tokens then printTokens CoffeeScript.tokens t.input, t.options
|
||||
else if o.nodes then printLine CoffeeScript.nodes(t.input, t.options).toString().trim()
|
||||
else if o.run then CoffeeScript.run t.input, t.options
|
||||
else if o.join and t.file isnt o.join
|
||||
t.input = helpers.invertLiterate t.input if helpers.isLiterate file
|
||||
sourceCode[sources.indexOf(t.file)] = t.input
|
||||
compileJoin()
|
||||
else
|
||||
compiled = CoffeeScript.compile t.input, t.options
|
||||
t.output = compiled
|
||||
if o.map
|
||||
t.output = compiled.js
|
||||
t.sourceMap = compiled.v3SourceMap
|
||||
|
||||
CoffeeScript.emit 'success', task
|
||||
if o.print
|
||||
printLine t.output.trim()
|
||||
else if o.compile || o.map
|
||||
writeJs base, t.file, t.output, options.jsPath, t.sourceMap
|
||||
else if o.lint
|
||||
lint t.file, t.output
|
||||
catch err
|
||||
CoffeeScript.emit 'failure', err, task
|
||||
return if CoffeeScript.listeners('failure').length
|
||||
|
@ -323,7 +318,6 @@ 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
|
||||
|
||||
|
|
|
@ -512,15 +512,6 @@ grammar =
|
|||
IfBlock: [
|
||||
o 'IF Expression Block', -> new If $2, $3, type: $1
|
||||
o 'IfBlock ELSE IF Expression Block', -> $1.addElse new If $4, $5, type: $3
|
||||
o 'IF INDENT GuardBlock OUTDENT', -> $3.type = $1; $3
|
||||
o 'IF INDENT GuardBlock ELSE Block OUTDENT',-> $3.type = $1; $3.addElse $5; $3
|
||||
]
|
||||
|
||||
# The guard-style form of *if*, where each expression serves as the truthy
|
||||
# conditional.
|
||||
GuardBlock: [
|
||||
o 'Expression Block', -> new If $1, $2
|
||||
o 'GuardBlock TERMINATOR Expression Block', -> $1.addElse new If $3, $4
|
||||
]
|
||||
|
||||
# The full complement of *if* expressions, including postfix one-liner
|
||||
|
|
|
@ -427,23 +427,3 @@ test "Throw should be usable as an expression.", ->
|
|||
throw new Error 'failed'
|
||||
catch e
|
||||
ok e is 'up'
|
||||
|
||||
|
||||
test "#2490. Block-style, guard-style if/else chain.", ->
|
||||
result = if
|
||||
1 - 1
|
||||
false
|
||||
process.someUndefinedThing
|
||||
false
|
||||
1 + 1
|
||||
'correct'
|
||||
|
||||
eq result, 'correct'
|
||||
|
||||
func = -> if
|
||||
null
|
||||
false
|
||||
else
|
||||
'correct'
|
||||
|
||||
eq func(), 'correct'
|
||||
|
|
Loading…
Reference in a new issue