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

Parser syntax error when using shorthand hash syntax #401

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mbaird
Copy link

@mbaird mbaird commented Apr 14, 2024

What are you trying to accomplish?

Advice on how to approach/fix the failing test reproduction for #278 as suggested.

This isn't a fix, so happy to move this to the issue discussion instead.

What approach did you choose and why?

I'm not sure on the best approach to fix this, so looking for guidance.

This change fails the valid ERB parser test with the error:

Error:
Packwerk::Parsers::ErbTest#test__call_returns_node_with_valid_file:
Packwerk::Parsers::ParseError: Syntax error: unexpected string beginning, expecting end-of-input
    lib/packwerk/parsers/ruby.rb:50:in `rescue in call'
    lib/packwerk/parsers/ruby.rb:40:in `call'
    /Users/michael/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11346/lib/types/private/methods/call_validation.rb:167:in `bind_call'
    /Users/michael/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11346/lib/types/private/methods/call_validation.rb:167:in `validate_call_skip_block_type'
    /Users/michael/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11346/lib/types/private/methods/call_validation.rb:109:in `block in create_validator_slow_skip_block_type'
    lib/packwerk/parsers/erb.rb:57:in `to_ruby_ast'
...

For the code added to valid.erb in this PR, the ruby code extracted from the erb ast in to_ruby_ast is:

 render 'thing', thing:
 render 'thing'

Which understandably fails parsing when attempted via prism.

This code works fine in practice, because ERB parsing results in the following:

"#coding:UTF-8\n_erbout = +''; 
erbout.<<(( render 'thing', thing: ).to_s); 
_erbout.<< \"\\n\".freeze\n; 
_erbout.<<(( render 'thing' ).to_s); 
_erbout"

It seems this issue might be with the ERB parser better-html.

Thanks for looking.

What should reviewers focus on?

Type of Change

  • Bugfix
  • New feature
  • Non-breaking change (a change that doesn't alter functionality - i.e., code refactor, configs, etc.)

Additional Release Notes

  • Breaking change (fix or feature that would cause existing functionality to change)

Include any notes here to include in the release description. For example, if you selected "breaking change" above, leave notes on how users can transition to this version.

If no additional notes are necessary, delete this section or leave it unchanged.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • It is safe to rollback this change.

@mbaird mbaird requested a review from a team as a code owner April 14, 2024 12:01
@mbaird mbaird changed the title Add failing example code to valid ERB test Parser syntax error when using shorthand hash syntax Apr 14, 2024
@mbaird
Copy link
Author

mbaird commented Apr 14, 2024

I have signed the CLA!

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.

None yet

1 participant