Skip to content

Commit f05e332

Browse files
authored
Merge pull request glayzzle#383 from glayzzle/refactor-and-test-switch
refactor and test switch statement
2 parents 6481747 + c75e4e7 commit f05e332

File tree

3 files changed

+2133
-10
lines changed

3 files changed

+2133
-10
lines changed

src/parser/switch.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ module.exports = {
4242
} else {
4343
this.expect(["{", ":"]);
4444
}
45+
this.next();
4546
// OPTIONNAL ';'
4647
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L570
47-
if (this.next().token === ";") {
48+
if (this.token === ";") {
4849
this.next();
4950
}
5051
// EXTRACTING CASES
@@ -66,20 +67,20 @@ module.exports = {
6667
read_case_list: function(stopToken) {
6768
const result = this.node("case");
6869
let test = null;
69-
let body = null;
70-
const items = [];
7170
if (this.token === this.tok.T_CASE) {
7271
test = this.next().read_expr();
7372
} else if (this.token === this.tok.T_DEFAULT) {
74-
// the defaut entry - no condition
73+
// the default entry - no condition
7574
this.next();
7675
} else {
7776
this.expect([this.tok.T_CASE, this.tok.T_DEFAULT]);
7877
}
78+
// case_separator
7979
this.expect([":", ";"]) && this.next();
80-
body = this.node("block");
80+
const body = this.node("block");
81+
const items = [];
8182
while (
82-
this.token != this.EOF &&
83+
this.token !== this.EOF &&
8384
this.token !== stopToken &&
8485
this.token !== this.tok.T_CASE &&
8586
this.token !== this.tok.T_DEFAULT

0 commit comments

Comments
 (0)