Editing one node of the syntax tree

Is there a way to update a single mode in Swift Syntax that isn’t using the Rewriter class?

The syntax tree is immutable, you cannot 'update' it. What you can do is get a new tree with your modification applied. All the with* (e.g. withIdentifier()) functions give you a new node with the modification applied and new parent nodes all the way to a new root node.

1 Like

Thanks. Is using that method more or less expensive than using the Swift Rewriter?

I'm not sure if there is significant difference and whether the difference applies always or it depends on the use pattern. I'd recommend to do some measurements based on the intended pattern of modifications.

Terms of Service

Privacy Policy

Cookie Policy