esprima-dotnet icon indicating copy to clipboard operation
esprima-dotnet copied to clipboard

About how to easily add, delete, modify the AST node structure

Open jeffxjh opened this issue 1 month ago • 0 comments

  • 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));
    }
}

jeffxjh avatar May 30 '24 15:05 jeffxjh