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

[Feature] Allow parsing top-level yield in Ruby 3.3 #457

Open
davidwessman opened this issue Apr 25, 2024 · 2 comments
Open

[Feature] Allow parsing top-level yield in Ruby 3.3 #457

davidwessman opened this issue Apr 25, 2024 · 2 comments

Comments

@davidwessman
Copy link

Hello, thank you for a great gem!

I am working on https://github.com/davidwessman/syntax_tree-erb and ran into some errors when upgrading to Ruby 3.3.

In ERB-template rendered by Rails calls to yield will not raise an error for top-level yield. Probably because Rails compile the templates somehow. When I parse the ruby-code in an ERB-template I parse each tag by itself.

This causes errors:

Ruby 3.2.4, syntax_tree 6.2.0

stree ast -e 'yield'
(program (statements ((yield nil))))

Ruby 3.3.1, syntax_tree 6.2.0

stree ast -e 'yield'  
Error: Invalid yield
> 1 | yield
    | ^

I am using the Ruby-api, SyntaxTree.parse("yield"), would there be anyway to add some support to allow the top-level yield?
Or do I need to wrap all the code I parse or something? That would make formatting much harder.

@davidwessman
Copy link
Author

My solution for now is to replace yield with a placeholder:
davidwessman/syntax_tree-erb#78

@davidwessman
Copy link
Author

Discussed it with Jean Boussier in Rails Performance Slack and he encouraged me to make an issue here and see if you had any better idea 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant