removed extra lines from the compilation of trailing `then` with `if`/`switch`

This commit is contained in:
satyr 2010-10-25 22:19:02 +09:00
parent 1e984e78ca
commit 2aa093b65c
2 changed files with 11 additions and 5 deletions

View File

@ -1651,7 +1651,7 @@
return this;
};
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);
idt2 = o.indent = this.idt(2);
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 += block.compile(o, LEVEL_TOP) + '\n';
if (body = block.compile(o, LEVEL_TOP)) {
code += body + '\n';
}
if (i === this.cases.length - 1 && !this.otherwise) {
break;
}
@ -1744,7 +1746,10 @@
cond = this.condition.compile(o, LEVEL_PAREN);
o.indent = this.idt(1);
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) {
ifPart = this.tab + ifPart;
}

View File

@ -1367,7 +1367,7 @@ exports.Switch = class Switch extends Base
for cond in flatten [conditions]
cond = cond.invert() unless @subject
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
for expr in block.expressions by -1 when expr not instanceof Comment
code += idt2 + 'break;\n' unless expr instanceof Return
@ -1432,7 +1432,8 @@ exports.If = class If extends Base
cond = @condition.compile o, LEVEL_PAREN
o.indent = @idt 1
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
return ifPart unless @elseBody
ifPart + ' else ' + if @isChain