Skip to content

Commit ced1ae3

Browse files
committed
fix continue/break statement with optional level expression
1 parent 05b0eb3 commit ced1ae3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/parser/statement.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,15 @@ module.exports = {
215215
this.expectEndOfStatement();
216216
return result(expr);
217217

218+
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L429
218219
case this.tok.T_BREAK:
219220
case this.tok.T_CONTINUE:
220221
var result = this.node(
221222
this.token === this.tok.T_CONTINUE ? 'continue' : 'break'
222223
), level = null;
223-
if(this.next().token === this.tok.T_LNUMBER) {
224-
level = this.node('number');
225-
var value = this.text();
226-
this.next();
227-
level = level(value);
224+
this.next(); // look ahead
225+
if (this.token !== ';' && this.token !== this.tok.T_CLOSE_TAG) {
226+
level = this.read_expr();
228227
}
229228
this.expectEndOfStatement();
230229
return result(level);

test/loopTests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ describe('Test loops statements (for, while)', function() {
5454
'echo $i;',
5555
'for(;;):',
5656
'echo $ok;',
57-
'continue 5;;',
57+
'continue 5;',
58+
'continue(5);',
5859
'endfor;'
5960
].join('\n'), {
6061
parser: { debug: false }

0 commit comments

Comments
 (0)