php-parser
php-parser copied to clipboard
Invalid start location for class constants / properties
Input:
<?php
class A
{
const test = 1;
}
AST (excerpt):
"kind": "classconstant",
"loc": {
"source": "test = 1",
"start": {
"line": 4,
"column": 10,
"offset": 26
},
"end": {
"line": 4,
"column": 18,
"offset": 34
}
},
I think the start column of the class constant is off, it should be around 4 instead of 10 in the example.
The same thing happens with class properties:
<?php
class A
{
public $test = 1;
}
AST:
"kind": "propertystatement",
"loc": {
"source": "$test = 1",
"start": {
"line": 4,
"column": 11,
"offset": 27
},
"end": {
"line": 4,
"column": 20,
"offset": 36
}
},
Yes, it is old issues :disappointed:
Maybe related to https://github.com/glayzzle/php-parser/issues/208 ?
Yes, i try to keep all in the one PR, but it's just my preference
Doesn't matter as long as we get it fixed :wink:
for const the fix is easy, but for properties / functions it's more complicated as the final / abstract / private / protected / public tokens may be eaten before creating the function or property node - one solution would be to use swapLocations on the generated and store on flags the parser position before eating modifiers tokens
Hi @evilebottnawi, it would be great if you have some time that you keep working on branch #fix-issue-511 as the fix is not fully implemented.
Remains to check interfaces, traits, use alias on traits, but the principle remains the same as in the last commit