Skip to content

Commit

Permalink
AST fix for empty switch statement (tntim96/JSCover#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
tntim96 committed Jan 14, 2015
1 parent a36ad19 commit 6516dbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -13,7 +13,7 @@

<groupId>com.github.tntim96</groupId>
<artifactId>rhino</artifactId>
<version>1.7R5pre04</version>
<version>1.7R5pre05-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Mozilla Rhino</name>
Expand Down
7 changes: 4 additions & 3 deletions src/org/mozilla/javascript/ast/SwitchStatement.java
Expand Up @@ -155,9 +155,10 @@ public String toSource(int depth) {
sb.append("switch (");
sb.append(expression.toSource(0));
sb.append(") {\n");
for (SwitchCase sc : cases) {
sb.append(sc.toSource(depth + 1));
}
if (cases != null)
for (SwitchCase sc : cases) {
sb.append(sc.toSource(depth + 1));
}
sb.append(pad);
sb.append("}\n");
return sb.toString();
Expand Down
6 changes: 6 additions & 0 deletions testsrc/org/mozilla/javascript/tests/Bug491621Test.java
Expand Up @@ -114,4 +114,10 @@ public void testHexOctDecLiteralToSource()
{
assertSource("0xff;\n9;\n07;\n1;", "0xff;\n9;\n07;\n1;\n");
}

@Test
public void testEmptySwitchToSource()
{
assertSource("switch(1){}", "switch (1) {\n}\n");
}
}

0 comments on commit 6516dbc

Please sign in to comment.