php-parser icon indicating copy to clipboard operation
php-parser copied to clipboard

Missing last leading comments with namespace

Open abdul-alhasany opened this issue 5 years ago • 0 comments

Hi, I am trying to parse a file with a file level comment. This parse works fine when not using a namespace. However, with namespace the leadingComments node is missing the last one. The comment exists in the comments node.

When I try the code on ASTexplore everything is fine. The problem only occurs when using node.

This is what I have at top level:

/**
 * File leve comment
 *
 * @package testing
 */

/**
 * namespace comment
 *
 * Another top level comment
 */

// Testing another comment

/*
One more comment
*/

and this is the json produced:

[{
    "kind": "commentblock",
    "loc": {
        "source": null,
        "start": {
            "line": 2,
            "column": 0,
            "offset": 6
        },
        "end": {
            "line": 6,
            "column": 3,
            "offset": 57
        }
    },
    "value": "/**\n * File leve comment\n *\n * @package testing\n */",
    "offset": 6
}, {
    "kind": "commentblock",
    "loc": {
        "source": null,
        "start": {
            "line": 8,
            "column": 0,
            "offset": 59
        },
        "end": {
            "line": 12,
            "column": 3,
            "offset": 119
        }
    },
    "value": "/**\n * namespace comment\n *\n * Another top level comment\n */",
    "offset": 59
}, {
    "kind": "commentline",
    "loc": {
        "source": null,
        "start": {
            "line": 14,
            "column": 0,
            "offset": 121
        },
        "end": {
            "line": 15,
            "column": 0,
            "offset": 148
        }
    },
    "value": "// Testing another comment\n",
    "offset": 121
}]

abdul-alhasany avatar Aug 15 '20 13:08 abdul-alhasany