esprima-dotnet
esprima-dotnet copied to clipboard
About how to easily add, delete, modify the AST node structure
- I read the source code and documentation, did not find a convenient way to modify the ATS node, usually to parse the js script, is need to operate on it, why some attributes to set read-only?
- I am now using AstRewriter to modify nodes by recreating them, but how do I delete them? thanks.
class ChangeVisitor : AstRewriter {
private T ForceNewObject<T>(T node, Func<T, T> createNew) {
return createNew(node);
}
protected override object? VisitProperty(Property property) {
return ForceNewObject((Property)base.VisitProperty(property)!, node => new Property(property.Kind, node.Key, property.Computed, obj, property.Method, property.Shorthand));
}
}