diff --git a/lib/browser.js b/lib/browser.js index 2d18c96c..c0c9bcdf 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -18,9 +18,7 @@ xhr.overrideMimeType('text/plain'); } xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - return CoffeeScript.run(xhr.responseText, options); - } + return xhr.readyState === 4 ? CoffeeScript.run(xhr.responseText, options) : null; }; return xhr.send(null); }; diff --git a/lib/cake.js b/lib/cake.js index 1b7342ba..43930c32 100755 --- a/lib/cake.js +++ b/lib/cake.js @@ -67,9 +67,7 @@ desc = task.description ? ("# " + (task.description)) : ''; puts("cake " + (name) + (spaces) + " " + (desc)); } - if (switches.length) { - return puts(oparse.help()); - } + return switches.length ? puts(oparse.help()) : null; }; missingTask = function(task) { puts("No such task: \"" + (task) + "\""); diff --git a/lib/command.js b/lib/command.js index 8b14bcfb..ed44defa 100644 --- a/lib/command.js +++ b/lib/command.js @@ -81,9 +81,7 @@ fs.readFile(source, function(err, code) { return compileScript(source, code.toString(), base); }); - if (opts.watch) { - return watch(source, base); - } + return opts.watch ? watch(source, base) : null; } }); }); @@ -121,13 +119,7 @@ } else { t.output = CoffeeScript.compile(t.input, t.options); CoffeeScript.emit('success', task); - if (o.print) { - return print(t.output); - } else if (o.compile) { - return writeJs(t.file, t.output, base); - } else if (o.lint) { - return lint(t.output); - } + return o.print ? print(t.output) : (o.compile ? writeJs(t.file, t.output, base) : (o.lint ? lint(t.output) : null)); } } catch (err) { CoffeeScript.emit('failure', err, task); @@ -146,9 +138,7 @@ code = ''; stdin = process.openStdin(); stdin.on('data', function(buffer) { - if (buffer) { - return code += buffer.toString(); - } + return buffer ? code += buffer.toString() : null; }); return stdin.on('end', function() { return compileScript('stdio', code); @@ -182,9 +172,7 @@ js = ' '; } return fs.writeFile(jsPath, js, function(err) { - if (opts.compile && opts.watch) { - return puts("Compiled " + (source)); - } + return opts.compile && opts.watch ? puts("Compiled " + (source)) : null; }); }; return path.exists(dir, function(exists) { diff --git a/lib/grammar.js b/lib/grammar.js index 2e44043a..cbd9e0a4 100644 --- a/lib/grammar.js +++ b/lib/grammar.js @@ -529,7 +529,7 @@ invert: true }); }), o("IfBlock ELSE IF Expression Block", function() { - return $1.addElse((new IfNode($4, $5)).forceStatement()); + return $1.addElse(new IfNode($4, $5)); }), o("IfBlock ELSE Block", function() { return $1.addElse($3); }) diff --git a/lib/nodes.js b/lib/nodes.js index eb649c83..e50cbe98 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -146,9 +146,7 @@ BaseNode.prototype.traverseChildren = function(crossScope, func) { return this.eachChild(function(child) { func.apply(this, arguments); - if (child instanceof BaseNode) { - return child.traverseChildren(crossScope, func); - } + return child instanceof BaseNode ? child.traverseChildren(crossScope, func) : null; }); }; BaseNode.prototype["class"] = 'BaseNode'; @@ -1135,9 +1133,7 @@ return true; }; CodeNode.prototype.traverseChildren = function(crossScope, func) { - if (crossScope) { - return CodeNode.__super__.traverseChildren.call(this, crossScope, func); - } + return crossScope ? CodeNode.__super__.traverseChildren.call(this, crossScope, func) : null; }; CodeNode.prototype.toString = function(idt) { var _i, _len, _ref2, _result, child, children; @@ -1663,15 +1659,7 @@ if (!(topLevel)) { rvar = scope.freeVariable('result'); } - ivar = (function() { - if (codeInBody) { - return scope.freeVariable('i'); - } else if (range) { - return name; - } else { - return index || scope.freeVariable('i'); - } - })(); + ivar = codeInBody ? scope.freeVariable('i') : (range ? name : index || scope.freeVariable('i')); varPart = ''; guardPart = ''; body = Expressions.wrap([this.body]); @@ -1829,10 +1817,6 @@ IfNode.prototype.elseBodyNode = function() { return this.elseBody == null ? undefined : this.elseBody.unwrap(); }; - IfNode.prototype.forceStatement = function() { - this.tags.statement = true; - return this; - }; IfNode.prototype.addElse = function(elseBody, statement) { if (this.isChain) { this.elseBodyNode().addElse(elseBody, statement); @@ -1843,7 +1827,7 @@ return this; }; IfNode.prototype.isStatement = function(o) { - return this.statement || (this.statement = (!!((o && o.top) || this.tags.statement || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o))))); + return this.statement || (this.statement = (!!((o && o.top) || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o))))); }; IfNode.prototype.compileCondition = function(o) { var _i, _len, _ref2, _result, cond, conditions; diff --git a/lib/parser.js b/lib/parser.js index 561371b5..32c603f6 100755 --- a/lib/parser.js +++ b/lib/parser.js @@ -433,7 +433,7 @@ case 188:this.$ = new yy.IfNode($$[$0-3+2-1], $$[$0-3+3-1], { invert: true }); break; -case 189:this.$ = $$[$0-5+1-1].addElse((new yy.IfNode($$[$0-5+4-1], $$[$0-5+5-1])).forceStatement()); +case 189:this.$ = $$[$0-5+1-1].addElse(new yy.IfNode($$[$0-5+4-1], $$[$0-5+5-1])); break; case 190:this.$ = $$[$0-3+1-1].addElse($$[$0-3+3-1]); break; @@ -701,7 +701,7 @@ exports.main = function commonjsMain(args) { } return exports.parser.parse(source); } -if (typeof module !== 'undefined' && require.main === module) { +if (typeof module !== "undefined" && require.main === module) { exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args); } } \ No newline at end of file diff --git a/lib/rewriter.js b/lib/rewriter.js index 6d7d3d48..f41a0e9a 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -273,9 +273,7 @@ return ('TERMINATOR' === (_ref2 = token[0]) || 'INDENT' === _ref2); }; action = function(token, i) { - if (token[0] !== 'INDENT') { - return (original[0] = 'POST_' + original[0]); - } + return token[0] !== 'INDENT' ? (original[0] = 'POST_' + original[0]) : null; }; this.detectEnd(i + 1, condition, action); return 1; diff --git a/src/grammar.coffee b/src/grammar.coffee index 512b1b64..9413a7c7 100644 --- a/src/grammar.coffee +++ b/src/grammar.coffee @@ -511,7 +511,7 @@ grammar = IfBlock: [ o "IF Expression Block", -> new IfNode $2, $3 o "UNLESS Expression Block", -> new IfNode $2, $3, invert: true - o "IfBlock ELSE IF Expression Block", -> $1.addElse (new IfNode($4, $5)).forceStatement() + o "IfBlock ELSE IF Expression Block", -> $1.addElse new IfNode $4, $5 o "IfBlock ELSE Block", -> $1.addElse $3 ] diff --git a/src/nodes.coffee b/src/nodes.coffee index 69bcd5f0..a5155180 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1488,10 +1488,6 @@ exports.IfNode = class IfNode extends BaseNode bodyNode: -> @body?.unwrap() elseBodyNode: -> @elseBody?.unwrap() - forceStatement: -> - @tags.statement = true - this - # Rewrite a chain of **IfNodes** to add a default case as the final *else*. addElse: (elseBody, statement) -> if @isChain @@ -1504,7 +1500,7 @@ exports.IfNode = class IfNode extends BaseNode # The **IfNode** only compiles into a statement if either of its bodies needs # to be a statement. Otherwise a ternary is safe. isStatement: (o) -> - @statement or= !!((o and o.top) or @tags.statement or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o))) + @statement or= !!((o and o.top) or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o))) compileCondition: (o) -> conditions = flatten [@condition]