mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
removed extra lines from the compilation of trailing then
with if
/switch
This commit is contained in:
parent
1e984e78ca
commit
2aa093b65c
2 changed files with 11 additions and 5 deletions
11
lib/nodes.js
11
lib/nodes.js
|
@ -1651,7 +1651,7 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Switch.prototype.compileNode = function(o) {
|
Switch.prototype.compileNode = function(o) {
|
||||||
var _i, _j, _len, _len2, _ref2, _ref3, _ref4, _ref5, block, code, cond, conditions, expr, i, idt1, idt2;
|
var _i, _j, _len, _len2, _ref2, _ref3, _ref4, _ref5, block, body, code, cond, conditions, expr, i, idt1, idt2;
|
||||||
idt1 = this.idt(1);
|
idt1 = this.idt(1);
|
||||||
idt2 = o.indent = this.idt(2);
|
idt2 = o.indent = this.idt(2);
|
||||||
code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : undefined) || false) + ") {\n");
|
code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : undefined) || false) + ") {\n");
|
||||||
|
@ -1665,7 +1665,9 @@
|
||||||
}
|
}
|
||||||
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
|
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
|
||||||
}
|
}
|
||||||
code += block.compile(o, LEVEL_TOP) + '\n';
|
if (body = block.compile(o, LEVEL_TOP)) {
|
||||||
|
code += body + '\n';
|
||||||
|
}
|
||||||
if (i === this.cases.length - 1 && !this.otherwise) {
|
if (i === this.cases.length - 1 && !this.otherwise) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1744,7 +1746,10 @@
|
||||||
cond = this.condition.compile(o, LEVEL_PAREN);
|
cond = this.condition.compile(o, LEVEL_PAREN);
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
body = this.ensureExpressions(this.body).compile(o);
|
body = this.ensureExpressions(this.body).compile(o);
|
||||||
ifPart = "if (" + cond + ") {\n" + body + "\n" + this.tab + "}";
|
if (body) {
|
||||||
|
body = "\n" + body + "\n" + this.tab;
|
||||||
|
}
|
||||||
|
ifPart = "if (" + cond + ") {" + body + "}";
|
||||||
if (!child) {
|
if (!child) {
|
||||||
ifPart = this.tab + ifPart;
|
ifPart = this.tab + ifPart;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1367,7 +1367,7 @@ exports.Switch = class Switch extends Base
|
||||||
for cond in flatten [conditions]
|
for cond in flatten [conditions]
|
||||||
cond = cond.invert() unless @subject
|
cond = cond.invert() unless @subject
|
||||||
code += idt1 + "case #{ cond.compile o, LEVEL_PAREN }:\n"
|
code += idt1 + "case #{ cond.compile o, LEVEL_PAREN }:\n"
|
||||||
code += block.compile(o, LEVEL_TOP) + '\n'
|
code += body + '\n' if body = block.compile o, LEVEL_TOP
|
||||||
break if i is @cases.length - 1 and not @otherwise
|
break if i is @cases.length - 1 and not @otherwise
|
||||||
for expr in block.expressions by -1 when expr not instanceof Comment
|
for expr in block.expressions by -1 when expr not instanceof Comment
|
||||||
code += idt2 + 'break;\n' unless expr instanceof Return
|
code += idt2 + 'break;\n' unless expr instanceof Return
|
||||||
|
@ -1432,7 +1432,8 @@ exports.If = class If extends Base
|
||||||
cond = @condition.compile o, LEVEL_PAREN
|
cond = @condition.compile o, LEVEL_PAREN
|
||||||
o.indent = @idt 1
|
o.indent = @idt 1
|
||||||
body = @ensureExpressions(@body).compile o
|
body = @ensureExpressions(@body).compile o
|
||||||
ifPart = "if (#{cond}) {\n#{body}\n#{@tab}}"
|
body = "\n#{body}\n#{@tab}" if body
|
||||||
|
ifPart = "if (#{cond}) {#{body}}"
|
||||||
ifPart = @tab + ifPart unless child
|
ifPart = @tab + ifPart unless child
|
||||||
return ifPart unless @elseBody
|
return ifPart unless @elseBody
|
||||||
ifPart + ' else ' + if @isChain
|
ifPart + ' else ' + if @isChain
|
||||||
|
|
Loading…
Add table
Reference in a new issue