Hello,
I'm trying to parse the following file:
<?php
/** function 1 summary
* @param Type $var Description
**/
function FunctionName1(Type $var = null)
{
}
/** function 2 summary
* @param Type $var Description
**/
function FunctionName2(Type $var = null)
{
}
The output of the library is as follows:
...
{
"kind": "function",
"leadingComments": [{"kind": "commentblock","value": "/** function 1 summary\r\n * @param Type $var Description\r\n **/"}],
"name": {
"kind": "identifier",
"name": "FunctionName1"
},
...
"body": {
"kind": "block",
"children": [],
"trailingComments": [{"kind": "commentblock","value": "/** function 2 summary\r\n * @param Type $var Description\r\n **/"}]
}
}
...
The problem is that the documentation of the FunctionName2 is treated as a trailing comment on the body of FunctionName1 instead of a leading comment on FunctionName2.
What happens if you move the "summary" text onto a line below the /** - does it still produce this problem?
eg instead of:
/** function 1 summary
* @param Type $var Description
**/
have
/**
* function 1 summary
* @param Type $var Description
**/
That comes from the parser, the way it was implemented. In some cases the documentation block may be attached as trailingComments, only if no other tag comes after, on the same level ...
Here another bug, on the same idea - // bar is attached to foo as a trailingComments
foo();
// bar
bar();
I'll try another approach - the first implementation was way too simplistic :smile:
Hi @aameen951,
The bug should be fixed from my latest commit - it will be released soon.
@ichiriac Thank you!
I'll find a way to tell npm to install php-parser with this fix or I might just wait until prerelease.9
I hope to release it this month but meanwhile use the commit id it will be safer as the current version may be introduce breaking changes
@ichiriac Any update on this? You can reproduce the bug as well with this (using v3.0.0-prerelease.8): https://astexplorer.net/#/gist/d493a13a7b2ed670ccab73f6aea0c872/latest
@danilopolani, it's normal, actually not yet released - will be done this week-end