PHP-Parser icon indicating copy to clipboard operation
PHP-Parser copied to clipboard

Is there a way to modify or remove comments?

Open jokey35 opened this issue 1 year ago • 1 comments

In the AST, there is no comment node, but after generating code again from AST, there are the original comments. Can I at least remove them when generating code from AST?

jokey35 avatar Mar 20 '24 19:03 jokey35

The comments are stored as attributes on the node. There are some APIs for manipulating them: https://github.com/nikic/PHP-Parser/blob/46be4560c4cd4bab2b74882c0da39a4548a5cfbe/lib/PhpParser/Node.php#L90-L113

There is no direct API to drop comments, but you can use $node->setAttribute('comments', []).

nikic avatar Mar 20 '24 21:03 nikic