mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-03 07:36:16 +00:00
Merge pull request #1984 from mrcarlberg/if-empty-statement
Fixed: Compiler now generates correct empty statement after 'if (a);'
This commit is contained in:
@@ -580,7 +580,8 @@ IfStatement: function(node, st, c) {
|
||||
buffer.concat("if (");
|
||||
}
|
||||
c(node.test, st, "Expression");
|
||||
if (generate) buffer.concat(")\n");
|
||||
// We don't want EmptyStatements to generate an extra parenthesis except when it is in a while, for, ...
|
||||
if (generate) buffer.concat(node.consequent.type === "EmptyStatement" ? ");\n" : ")\n");
|
||||
indentation += indentStep;
|
||||
c(node.consequent, st, "Statement");
|
||||
indentation = indentation.substring(indentationSpaces);
|
||||
@@ -588,8 +589,10 @@ IfStatement: function(node, st, c) {
|
||||
if (alternate) {
|
||||
var alternateNotIf = alternate.type !== "IfStatement";
|
||||
if (generate) {
|
||||
var emptyStatement = alternate.type === "EmptyStatement";
|
||||
buffer.concat(indentation);
|
||||
buffer.concat(alternateNotIf ? "else\n" : "else ");
|
||||
// We don't want EmptyStatements to generate an extra parenthesis except when it is in a while, for, ...
|
||||
buffer.concat(alternateNotIf ? emptyStatement ? "else;\n" : "else\n" : "else ");
|
||||
}
|
||||
if (alternateNotIf)
|
||||
indentation += indentStep;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
function f(x) {
|
||||
var a = 2, b = 1;
|
||||
while (a < b);
|
||||
for (;;);
|
||||
if (a < b); else;
|
||||
do {} while (a < b);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
f = function(x)
|
||||
{
|
||||
var a = 2,
|
||||
b = 1;
|
||||
while (a < b);
|
||||
for (; ; );
|
||||
if (a < b);
|
||||
else;
|
||||
do
|
||||
{
|
||||
}
|
||||
while (a < b);
|
||||
}
|
||||
@@ -18,6 +18,7 @@ var FILENAMES = [
|
||||
"Misc/preprocess-if-directives",
|
||||
"Misc/regex-simple-char-classes",
|
||||
"Misc/empty-loops",
|
||||
"Misc/empty-statements",
|
||||
];
|
||||
|
||||
@implementation OutputTest : OJTestCase
|
||||
|
||||
Reference in New Issue
Block a user