Skip to content

Commit 33c28c4

Browse files
committed
#381 - fix location on bin nodes
1 parent cf461ca commit 33c28c4

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

src/ast.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ AST.prototype.resolvePrecedence = function(result, parser) {
235235
result.right = result.right.left;
236236
this.swapLocations(result, result.left, result.right, parser);
237237
buffer.left = this.resolvePrecedence(result, parser);
238+
this.swapLocations(buffer, buffer.left, buffer.right, parser);
238239
result = buffer;
239240
}
240241
} else if (result.right.kind === "retif") {

test/ast.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ describe("Test AST class (edge cases)", function() {
1111
const ast = test.parseEval('echo $foo;');
1212
const echo = ast.children[0];
1313
expect(echo.loc.source).toBe("echo $foo;");
14-
expect(echo.loc.start).toBeNull();
15-
expect(echo.loc.end).toBeNull();
14+
expect(echo.loc.start).not.toBeNull();
15+
expect(echo.loc.end).not.toBeNull();
1616

1717
const variable = echo.expressions[0];
1818
expect(variable.loc.source).toBe("$foo");

test/debug.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
const util = require('util');
1818
const parser = require("../src/index");
1919
const ast = parser.parseEval(`
20-
$bar = &$foo;
20+
$a = 1
21+
* // A
22+
2
23+
* // B
24+
3;
2125
`, {
2226
parser: {
2327
debug: true,
24-
php73: true,
25-
extractDoc: true
28+
php73: true
2629
},
2730
ast: {
2831
withPositions: true,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3647,11 +3647,11 @@ Program {
36473647
"line": 85,
36483648
"offset": 1727,
36493649
},
3650-
"source": "5 || false",
3650+
"source": "rand(0, 10)>5 || false",
36513651
"start": Position {
3652-
"column": 19,
3652+
"column": 7,
36533653
"line": 85,
3654-
"offset": 1717,
3654+
"offset": 1705,
36553655
},
36563656
},
36573657
"right": Boolean {

test/snapshot/__snapshots__/location.test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -473,21 +473,21 @@ Program {
473473
"line": 1,
474474
"offset": 22,
475475
},
476-
"source": "$var2 + $var3;",
476+
"source": "$var1 + $var2 + $var3;",
477477
"start": Position {
478-
"column": 8,
478+
"column": 0,
479479
"line": 1,
480-
"offset": 8,
480+
"offset": 0,
481481
},
482482
},
483483
"right": Variable {
484484
"curly": false,
485485
"kind": "variable",
486486
"loc": Location {
487487
"end": Position {
488-
"column": 21,
488+
"column": 22,
489489
"line": 1,
490-
"offset": 21,
490+
"offset": 22,
491491
},
492492
"source": "$var3",
493493
"start": Position {
@@ -2090,20 +2090,20 @@ Program {
20902090
"line": 1,
20912091
"offset": 19,
20922092
},
2093-
"source": "$var + 2112;",
2093+
"source": "$var + $var + 2112;",
20942094
"start": Position {
2095-
"column": 7,
2095+
"column": 0,
20962096
"line": 1,
2097-
"offset": 7,
2097+
"offset": 0,
20982098
},
20992099
},
21002100
"right": Number {
21012101
"kind": "number",
21022102
"loc": Location {
21032103
"end": Position {
2104-
"column": 18,
2104+
"column": 19,
21052105
"line": 1,
2106-
"offset": 18,
2106+
"offset": 19,
21072107
},
21082108
"source": "2112",
21092109
"start": Position {
@@ -2214,21 +2214,21 @@ Program {
22142214
"line": 1,
22152215
"offset": 19,
22162216
},
2217-
"source": "2112 + $var;",
2217+
"source": "$var + 2112 + $var;",
22182218
"start": Position {
2219-
"column": 7,
2219+
"column": 0,
22202220
"line": 1,
2221-
"offset": 7,
2221+
"offset": 0,
22222222
},
22232223
},
22242224
"right": Variable {
22252225
"curly": false,
22262226
"kind": "variable",
22272227
"loc": Location {
22282228
"end": Position {
2229-
"column": 18,
2229+
"column": 19,
22302230
"line": 1,
2231-
"offset": 18,
2231+
"offset": 19,
22322232
},
22332233
"source": "$var",
22342234
"start": Position {

0 commit comments

Comments
 (0)