Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 779d8ee

Browse files
fix: location
1 parent eed5703 commit 779d8ee

File tree

6 files changed

+7474
-1579
lines changed

6 files changed

+7474
-1579
lines changed

src/parser/class.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = {
6868

6969
// check T_USE trait
7070
if (this.token === this.tok.T_USE) {
71-
result = result.concat(this.next().read_trait_use_statement());
71+
result = result.concat(this.read_trait_use_statement());
7272
continue;
7373
}
7474

@@ -365,6 +365,7 @@ module.exports = {
365365
read_trait_use_statement: function() {
366366
// defines use statements
367367
const node = this.node("traituse");
368+
this.expect(this.tok.T_USE) && this.next();
368369
const traits = [this.read_namespace_name()];
369370
let adaptations = null;
370371
while (this.token === ",") {

src/parser/expr.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module.exports = {
135135

136136
if (this.token === "`") {
137137
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1048
138-
return this.next().read_encapsed_string("`");
138+
return this.read_encapsed_string("`");
139139
}
140140

141141
if (this.token === this.tok.T_LIST) {
@@ -207,7 +207,7 @@ module.exports = {
207207
);
208208

209209
case this.tok.T_NEW:
210-
return this.next().read_new_expr();
210+
return this.read_new_expr();
211211

212212
case this.tok.T_ISSET: {
213213
result = this.node("isset");
@@ -354,7 +354,7 @@ module.exports = {
354354
let right;
355355
if (this.next().token == "&") {
356356
if (this.next().token === this.tok.T_NEW) {
357-
right = this.next().read_new_expr();
357+
right = this.read_new_expr();
358358
} else {
359359
right = this.read_variable(false, false, true);
360360
}
@@ -456,6 +456,7 @@ module.exports = {
456456
*/
457457
read_new_expr: function() {
458458
const result = this.node("new");
459+
this.expect(this.tok.T_NEW) && this.next();
459460
let args = [];
460461
if (this.token === this.tok.T_CLASS) {
461462
const what = this.node("class");

src/parser/scalar.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,24 @@ module.exports = {
100100
start,
101101
this.lexer.yylloc.last_offset
102102
);
103+
this.expect(this.tok.T_END_HEREDOC) && this.next();
103104
node = node(
104105
value,
105106
raw,
106107
this.lexer.heredoc_label,
107108
raw[3] === '"' || raw[3] === "'"
108109
);
109-
this.expect(this.tok.T_END_HEREDOC) && this.next();
110110
return node;
111111
} else {
112-
return this.next().read_encapsed_string(this.tok.T_END_HEREDOC);
112+
return this.read_encapsed_string(this.tok.T_END_HEREDOC);
113113
}
114114

115115
case '"':
116-
return this.next().read_encapsed_string('"');
116+
return this.read_encapsed_string('"');
117117

118118
case 'b"':
119119
case 'B"': {
120-
this.next();
121-
this.lexer.yylloc.prev_offset -= 1;
122-
return this.read_encapsed_string('"');
120+
return this.read_encapsed_string('"', true);
123121
}
124122

125123
// NUMERIC
@@ -267,9 +265,10 @@ module.exports = {
267265
/**
268266
* Reads an encapsed string
269267
*/
270-
read_encapsed_string: function(expect) {
271-
const start = this.lexer.yylloc.prev_offset;
268+
read_encapsed_string: function(expect, isBinary = false) {
272269
let node = this.node("encapsed");
270+
this.next();
271+
const start = this.lexer.yylloc.prev_offset - (isBinary ? 1 : 0);
273272
const value = [];
274273
let type = null;
275274

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

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ Program {
442442
"line": 26,
443443
"offset": 455,
444444
},
445-
"source": "Line;",
445+
"source": "use Line;",
446446
"start": Position {
447-
"column": 8,
447+
"column": 4,
448448
"line": 26,
449-
"offset": 450,
449+
"offset": 446,
450450
},
451451
},
452452
"traits": Array [
@@ -572,14 +572,14 @@ Program {
572572
"line": 30,
573573
"offset": 533,
574574
},
575-
"source": "foo, bar {
575+
"source": "use foo, bar {
576576
foo::baz insteadof bar;
577577
bar::foo as baz;
578578
}",
579579
"start": Position {
580-
"column": 8,
580+
"column": 4,
581581
"line": 27,
582-
"offset": 464,
582+
"offset": 460,
583583
},
584584
},
585585
"traits": Array [
@@ -837,11 +837,11 @@ Program {
837837
"line": 42,
838838
"offset": 855,
839839
},
840-
"source": "Hey ho $name, $greeting !\\"",
840+
"source": "\\"Hey ho $name, $greeting !\\"",
841841
"start": Position {
842-
"column": 14,
842+
"column": 13,
843843
"line": 42,
844-
"offset": 829,
844+
"offset": 828,
845845
},
846846
},
847847
"raw": "\\"Hey ho $name, $greeting !\\"",
@@ -1193,11 +1193,11 @@ Program {
11931193
"line": 45,
11941194
"offset": 927,
11951195
},
1196-
"source": "\\\\ComeToHome('Thats it')",
1196+
"source": "new \\\\ComeToHome('Thats it')",
11971197
"start": Position {
1198-
"column": 16,
1198+
"column": 12,
11991199
"line": 45,
1200-
"offset": 904,
1200+
"offset": 900,
12011201
},
12021202
},
12031203
"what": ClassReference {
@@ -4770,15 +4770,15 @@ next:
47704770
"line": 120,
47714771
"offset": 2594,
47724772
},
4773-
"source": "class extends fooBar {
4773+
"source": "new class extends fooBar {
47744774
function goatIt() {
47754775
return \\"meeeh\\";
47764776
}
47774777
}",
47784778
"start": Position {
4779-
"column": 20,
4779+
"column": 16,
47804780
"line": 116,
4781-
"offset": 2492,
4781+
"offset": 2488,
47824782
},
47834783
},
47844784
"parenthesizedExpression": true,
@@ -6391,11 +6391,11 @@ next:
63916391
"line": 136,
63926392
"offset": 2947,
63936393
},
6394-
"source": "ls -larth\`",
6394+
"source": "\`ls -larth\`",
63956395
"start": Position {
6396-
"column": 10,
6396+
"column": 9,
63976397
"line": 136,
6398-
"offset": 2937,
6398+
"offset": 2936,
63996399
},
64006400
},
64016401
"raw": "\`ls -larth\`",
@@ -6504,11 +6504,11 @@ next:
65046504
"line": 134,
65056505
"offset": 2908,
65066506
},
6507-
"source": "bar&\`",
6507+
"source": "\`bar&\`",
65086508
"start": Position {
6509-
"column": 10,
6509+
"column": 9,
65106510
"line": 134,
6511-
"offset": 2903,
6511+
"offset": 2902,
65126512
},
65136513
},
65146514
"raw": "\`bar&\`",
@@ -7009,12 +7009,13 @@ next:
70097009
"line": 144,
70107010
"offset": 3074,
70117011
},
7012-
"source": " Hello world
7012+
"source": "<<<BAZ
7013+
Hello world
70137014
BAZ",
70147015
"start": Position {
7015-
"column": 0,
7016-
"line": 143,
7017-
"offset": 3057,
7016+
"column": 8,
7017+
"line": 142,
7018+
"offset": 3050,
70187019
},
70197020
},
70207021
"parenthesizedExpression": true,
@@ -7111,13 +7112,13 @@ BAR
71117112
"label": "BAR",
71127113
"loc": Location {
71137114
"end": Position {
7114-
"column": 0,
7115+
"column": 3,
71157116
"line": 148,
7116-
"offset": 3112,
7117+
"offset": 3115,
71177118
},
71187119
"source": "<<<'BAR'
71197120
$foo + $bar
7120-
",
7121+
BAR",
71217122
"start": Position {
71227123
"column": 11,
71237124
"line": 146,
@@ -7226,12 +7227,13 @@ FOO
72267227
"line": 152,
72277228
"offset": 3166,
72287229
},
7229-
"source": " return 'This is madness!';
7230+
"source": "<<<FOO
7231+
return 'This is madness!';
72307232
FOO",
72317233
"start": Position {
7232-
"column": 0,
7233-
"line": 151,
7234-
"offset": 3134,
7234+
"column": 7,
7235+
"line": 150,
7236+
"offset": 3127,
72357237
},
72367238
},
72377239
"raw": "

0 commit comments

Comments
 (0)