-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
alternate builder / copier #122
Comments
Here is my copyTree function in typescript. paths are relative to ast-nodes/script and it relies on immutable-js. It takes a different approach, I like the simplicity of yours. They are actually different, I realize - copyTree generates a JSON serializable structure, and one that can be passed into the builder's 'from' function after deserialization.
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An idea I've been playing with:
I have got a situation where I am going to take my custom AST, perform some optimizing transforms, and then use that AST to build nodes that actually perform the work. In my case, I intend to target two different platforms (primitive
Strings
and Node.jsStreams
), and the built nodes will be so drastically different, I intend to just create separate instances for each. Also there will be some optimizing transforms that I will only want to perform for one platform or the other (so I need a way to create an identical deep copy after I perform the common transforms).My idea is to provide a
copy
function that takes an alternatebuilders
implementation to create the copy. If an alternatebuilders
implementation is not provided, it uses the default one (types.builders
), essentially creating a deep copy of the AST. Providing an alternatebuilders
implementation requires you provide all the methods intypes.builders
(with identical signatures), but you are free to return whatever you want from each method (whatever you return will be used as an argument to the buildFn of the parent element).Was my explanation clear? Is this worth including in
ast-types
, or is it to niche?This relies on the buildFn metadata exposed by #121.
P.S. As this is a completely custom AST I'm working with, I anxiously await the resolution of #57.
The text was updated successfully, but these errors were encountered: