From 8fa1c554e994e1db10588c46c5c9cbcae71a0b4c Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 16 Jun 2014 10:52:30 +0100 Subject: [PATCH] Stop warning about break at the end of 'default' in switch statement --- ChangeLog | 1 + src/jsparse.c | 3 +++ tests/test_switch_default_break.js | 8 ++++++++ 3 files changed, 12 insertions(+) create mode 100644 tests/test_switch_default_break.js diff --git a/ChangeLog b/ChangeLog index ca6fbfda7..6434fb273 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,7 @@ Added throw and try..catch..finally (see #40) Fixed overriding of builtins with other Builtins Added Date.valueOf + Stop warning about break at the end of 'default' in switch statement 1v64 : Fix 'a=[2,3,4];delete a[1];' Make sure parseInt("0x01",16)==1 and parseInt("0x01")==1 but parseInt("0b01",16)==0 diff --git a/src/jsparse.c b/src/jsparse.c index 6a016b64b..6faa6a80e 100644 --- a/src/jsparse.c +++ b/src/jsparse.c @@ -1622,8 +1622,11 @@ NO_INLINE JsVar *jspeStatementSwitch() { JSP_MATCH(':'); JSP_SAVE_EXECUTE(); if (hasExecuted) jspSetNoExecute(); + else execInfo.execute |= EXEC_IN_SWITCH; while (!JSP_SHOULDNT_PARSE && execInfo.lex->tk!=LEX_EOF && execInfo.lex->tk!='}') jsvUnLock(jspeBlockOrStatement()); + if (execute && !hasExecuted) + execInfo.execute = execInfo.execute & (JsExecFlags)~EXEC_BREAK; JSP_RESTORE_EXECUTE(); } JSP_MATCH('}'); diff --git a/tests/test_switch_default_break.js b/tests/test_switch_default_break.js new file mode 100644 index 000000000..1054d2ab9 --- /dev/null +++ b/tests/test_switch_default_break.js @@ -0,0 +1,8 @@ +// Espruino complains about breaks at the end of 'default' - it shouldn't + +switch(2){ + case 1:break; + default:break; +} + +result = 1;