PHP-Parser
PHP-Parser copied to clipboard
Is there a way to modify or remove 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?
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', []).