Skip to content
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

Using grass as a sass parser without the transformation #82

Closed
bradzacher opened this issue Jun 29, 2023 · 3 comments
Closed

Using grass as a sass parser without the transformation #82

bradzacher opened this issue Jun 29, 2023 · 3 comments
Labels
fixed in master This issue has been resolved, but the change hasn't been released to crates.io

Comments

@bradzacher
Copy link

I'm working on some tooling to do dependency analysis of my company's sass files.
In a nutshell I want to parse a sass file, extract the "imports" (eg @use, @include, etc) and build a dependency graph across our rather large codebase.

I was looking into the grass_compiler internals (correct me if I'm wrong) but it looks like most of the infra required to parse and traverse a sass file is pub(crate) - making it unusable externally.

I saw #77 mentions

AST traversal can be built through the internals crate grass_compiler.

Does this mean that you want to support this sort of usecase for 1.0?

@connorskees
Copy link
Owner

GitHub seems to be having trouble with my comment, as the tab keeps crashing from OOM while I'm trying to reply.

As you mention, the AST internals necessary for doing traversal are not currently exposed. So far no one has asked for such functionality, and I haven't been able to decide on an API I like.

I was interested in the problem you described, and made a small attempt at it. I wrote some code using grass that traverses the AST of a large Sass library and ouputs a dotviz file of the dependency graph. You can find this sample here https://gist.github.com/connorskees/7af84cfe4b3157e0120dad06f33cd112. It's quite hacky and I really don't like the API, but it does function correctly.

I made public all of the necessary internals in 8b34d0e. I'm not sure when this will release to crates.io, but in the meantime you should be able to access this commit by cloning the repo locally and using a path dependency.

Please let me know if there's anything more you would need to implement what you have described.

@connorskees
Copy link
Owner

@connorskees connorskees added the fixed in master This issue has been resolved, but the change hasn't been released to crates.io label Jul 9, 2023
@connorskees
Copy link
Owner

The changes described in my previous comment have been released to crates.io as version 0.13.0. I will note that there have been some changes to the AST field names that will require updating in the code sample I posted.

If there is additional functionality you are interested in using grass for, please do open another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in master This issue has been resolved, but the change hasn't been released to crates.io
Projects
None yet
Development

No branches or pull requests

2 participants