-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Make AST mutations during a walk safer #1204
Comments
Context : PostCSS and PostCSS-like libs have a very user friendly API but to achieve this they have a bunch of internal complexity. This is outside my area of expertise and I also don't care that much about the UX of the parser libs. The focus and priority has always been on correctness of tokenizing and parsing and being able to keep up with the specifications. We don't currently test for heavy mutations during AST walks. PostCSS : What I see in the code is that they provide methods for insert and remove operations. So adding nodes before the current item increments the index. I don't want to do that. Todo :
|
I think I found a way to always determine a next good index even when a list is mutated, without having to provide convenience methods for all mutations. I keep a reference to the previous state of the list and use that to look for a candidate of a next element. This seems to work and it makes mutations safe. |
@nex3 Patches for this issue have been released as part of Can you let us know if this resolves the bugs you encountered? |
@nex3 going to close this for now. |
PostCSS provides strong guarantees that modifying an AST during a walk is safe by storing the index of each active iteration and updating them as necessary when replacements are made. It would be really nice if this tool did so as well.
Originally posted by @nex3 in #1202 (comment)
The text was updated successfully, but these errors were encountered: