Skip to content

Commit fd254f0

Browse files
fix: location
1 parent 268330e commit fd254f0

File tree

6 files changed

+3067
-21
lines changed

6 files changed

+3067
-21
lines changed

src/parser/loops.js

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
*/
1717
read_while: function() {
1818
const result = this.node("while");
19+
this.expect(this.tok.T_WHILE) && this.next();
1920
let test = null;
2021
let body = null;
2122
let shortForm = false;
@@ -40,6 +41,7 @@ module.exports = {
4041
*/
4142
read_do: function() {
4243
const result = this.node("do");
44+
this.expect(this.tok.T_DO) && this.next();
4345
let test = null;
4446
let body = null;
4547
body = this.read_statement();
@@ -63,6 +65,7 @@ module.exports = {
6365
*/
6466
read_for: function() {
6567
const result = this.node("for");
68+
this.expect(this.tok.T_FOR) && this.next();
6669
let init = [];
6770
let test = [];
6871
let increment = [];
@@ -105,6 +108,7 @@ module.exports = {
105108
*/
106109
read_foreach: function() {
107110
const result = this.node("foreach");
111+
this.expect(this.tok.T_FOREACH) && this.next();
108112
let source = null;
109113
let key = null;
110114
let value = null;

src/parser/statement.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,16 @@ module.exports = {
204204
return this.read_switch();
205205

206206
case this.tok.T_FOR:
207-
return this.next().read_for();
207+
return this.read_for();
208208

209209
case this.tok.T_FOREACH:
210-
return this.next().read_foreach();
210+
return this.read_foreach();
211211

212212
case this.tok.T_WHILE:
213-
return this.next().read_while();
213+
return this.read_while();
214214

215215
case this.tok.T_DO:
216-
return this.next().read_do();
216+
return this.read_do();
217217

218218
case this.tok.T_COMMENT:
219219
return this.read_comment();

src/parser/switch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module.exports = {
1515
* @see http://php.net/manual/en/control-structures.switch.php
1616
*/
1717
read_switch: function() {
18-
this.expect(this.tok.T_SWITCH) && this.next();
1918
const result = this.node("switch");
19+
this.expect(this.tok.T_SWITCH) && this.next();
2020
this.expect("(") && this.next();
2121
const test = this.read_expr();
2222
this.expect(")") && this.next();

test/snapshot/__snapshots__/acid.test.js.snap

+15-15
Original file line numberDiff line numberDiff line change
@@ -1065,14 +1065,14 @@ Program {
10651065
"line": 44,
10661066
"offset": 887,
10671067
},
1068-
"source": "($this->dwarf as $name => $greeting) {
1068+
"source": "foreach($this->dwarf as $name => $greeting) {
10691069
echo \\"Hey ho $name, $greeting !\\";
10701070
continue $foo;
10711071
}",
10721072
"start": Position {
1073-
"column": 13,
1073+
"column": 6,
10741074
"line": 41,
1075-
"offset": 776,
1075+
"offset": 769,
10761076
},
10771077
},
10781078
"shortForm": false,
@@ -2228,7 +2228,7 @@ Program {
22282228
"line": 70,
22292229
"offset": 1450,
22302230
},
2231-
"source": "($this->style) {
2231+
"source": "switch($this->style) {
22322232
case 'dot':
22332233
case 'point':
22342234
$body = '......';
@@ -2238,9 +2238,9 @@ Program {
22382238
break;
22392239
}",
22402240
"start": Position {
2241-
"column": 12,
2241+
"column": 6,
22422242
"line": 62,
2243-
"offset": 1278,
2243+
"offset": 1272,
22442244
},
22452245
},
22462246
"shortForm": false,
@@ -4328,14 +4328,14 @@ next:
43284328
"line": 126,
43294329
"offset": 2773,
43304330
},
4331-
"source": "($i = 0; $i < count($this->banana); $i++) {
4331+
"source": "for($i = 0; $i < count($this->banana); $i++) {
43324332
$x %= ($i * 2) / ($i - 1);
43334333
$what = $this->$x[++$i] ? 'yes!': 'noo!';
43344334
}",
43354335
"start": Position {
4336-
"column": 9,
4336+
"column": 6,
43374337
"line": 123,
4338-
"offset": 2637,
4338+
"offset": 2634,
43394339
},
43404340
},
43414341
"shortForm": false,
@@ -5872,15 +5872,15 @@ next:
58725872
"line": 102,
58735873
"offset": 2111,
58745874
},
5875-
"source": "($bar) {
5875+
"source": "while($bar) {
58765876
if ((int)calculateMeaningOfLife() === 42) {
58775877
break foo;
58785878
} else continue;
58795879
}",
58805880
"start": Position {
5881-
"column": 11,
5881+
"column": 6,
58825882
"line": 98,
5883-
"offset": 1997,
5883+
"offset": 1992,
58845884
},
58855885
},
58865886
"shortForm": false,
@@ -5956,15 +5956,15 @@ next:
59565956
"line": 107,
59575957
"offset": 2196,
59585958
},
5959-
"source": "{
5959+
"source": "do {
59605960
?>
59615961
Caesar: here I was
59625962
<?php
59635963
} while(false);",
59645964
"start": Position {
5965-
"column": 9,
5965+
"column": 6,
59665966
"line": 103,
5967-
"offset": 2121,
5967+
"offset": 2118,
59685968
},
59695969
},
59705970
"test": Boolean {

0 commit comments

Comments
 (0)