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

Fix error when parsing ERB files with yield on the top level #404

Merged
merged 2 commits into from
May 2, 2024

Conversation

rafaelfranca
Copy link
Member

Top level yields are invalid Ruby on files, but are valid on eval.

They exist on ERB files, and since those files are evaluated no written to disk they are fine.

We can tell Prism to parse the code using the eval context by passing scopes: [[]] to parse, but since are are using the Prism::Translation::Parser class we have no way to do that.

A PR was proposed to Prism to always consider the code as being evaluated in the Parser translation.

For now, we can safely ignore that class of error by overriding the valid_error? method on our own parser.

Fixes #400.

@rafaelfranca rafaelfranca requested a review from a team as a code owner May 2, 2024 19:39
Top level yields are invalid Ruby on files, but are valid on `eval`.

They exist on ERB files, and since those files are evaluated no written
to disk they are fine.

We can tell Prism to parse the code using the eval context by passing
`scopes: [[]]` to `parse`, but since are are using the
`Prism::Translation::Parser` class we have no way to do that.

A [PR][1] was proposed to Prism to always consider the code as being
evaluated in the `Parser` translation.

For now, we can safely ignore that class of error by overriding the
`valid_error?` method on our own parser.

Fixes #400.

[1]: ruby/prism#2741
@gmcgibbon
Copy link
Member

rbi-0.1.12 requires ruby version >= 3.0.0, which is incompatible with the current version, 2.7.8 🤔

We might need multiple gemfiles.

@rafaelfranca
Copy link
Member Author

I'm dropping support to EOL rubies.

@rafaelfranca
Copy link
Member Author

#405

We are going to drop support to 2.7, but don't want to do before a new
release with #404.
@rafaelfranca rafaelfranca merged commit f287144 into main May 2, 2024
16 checks passed
@rafaelfranca rafaelfranca deleted the rm-fix-prism branch May 2, 2024 20:26
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

Successfully merging this pull request may close these issues.

[Bug Report] Syntax error: Invalid yield in a brand new Rails application
2 participants