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

Ruby 3.1 shorthand syntax doesn't work for nested hashes #1138

Open
mockdeep opened this issue Mar 20, 2023 · 3 comments
Open

Ruby 3.1 shorthand syntax doesn't work for nested hashes #1138

mockdeep opened this issue Mar 20, 2023 · 3 comments

Comments

@mockdeep
Copy link

I have the following template:

= turbo_frame_tag 'dialog-container' do
  %div{ data: { dialog_target: 'redirect', redirect_to: } }

And I render it by passing a local:

module DialogsHelper
  def dialog_redirect_to(path)
    render(partial: 'dialogs/redirect', locals: { redirect_to: path })
  end
end

This raises an error:

ActionView::Template::Error:
        undefined local variable or method `redirect_to' for #<Haml::AttributeCompiler:0x00007fbd19072d70 @identity=#<Haml::Identity:0x00007fbd190733b0 @unique_id=1>, @quote="'", @format=:html, @escape_attrs=true>  

The template works as expected, however, when I pull out the data hash:

 = turbo_frame_tag 'dialog-container' do
-  %div{ data: { dialog_target: 'redirect', redirect_to: } }
+  - data = { dialog_target: 'redirect', redirect_to: }
+  %div{ data: }
@k0kubun
Copy link
Member

k0kubun commented Oct 4, 2023

I cannot reproduce the issue.

$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

$ haml version
6.2.3

$ cat /tmp/a.haml
- redirect_to = 'path'
- data = { dialog_target: 'redirect', redirect_to: }
%div{ data: }

$ haml render /tmp/a.haml
<div data-dialog-target='redirect' data-redirect-to='path'></div>

Could you consider the following things and reopen this? Thanks in advance.

  1. Provide the version of Haml and Ruby
  2. Provide a repository that reproduces the issue, or remove third-party dependencies from the reported template, e.g. turbo_frame_tag
  3. If (2) is too hard: Provide the full error backtrace with line numbers.

@k0kubun k0kubun closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
@mockdeep
Copy link
Author

@k0kubun did you try it with the nesting happening on the element line? I see an error with the following template:

- redirect_to = '/some/path'
%div{ data: { redirect_to: } }
$ haml render /tmp/a.haml
(eval):1:in `compile_data!': undefined local variable or method `redirect_to' for #<Haml::AttributeCompiler:0x00007f4372837950 @identity=#<Haml::Identity:0x00007f437287b6a0 @unique_id=0>, @quote="'", @format=:html, @escape_attrs=true> (NameError)
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/attribute_compiler.rb:92:in `eval'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/attribute_compiler.rb:92:in `compile_data!'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/attribute_compiler.rb:59:in `block in static_compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/attribute_compiler.rb:49:in `each'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/attribute_compiler.rb:49:in `static_compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/attribute_compiler.rb:33:in `compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler/tag_compiler.rb:16:in `compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler.rb:87:in `compile_tag'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler.rb:50:in `compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler.rb:59:in `block in compile_children'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler/children_compiler.rb:20:in `block (2 levels) in compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler/children_compiler.rb:49:in `moving_lineno'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler/children_compiler.rb:20:in `block in compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler/children_compiler.rb:17:in `each'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler/children_compiler.rb:17:in `compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler.rb:59:in `compile_children'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler.rb:36:in `compile'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/compiler.rb:26:in `call'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/temple-0.10.3/lib/temple/engine.rb:51:in `block in call'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/temple-0.10.3/lib/temple/engine.rb:51:in `each'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/temple-0.10.3/lib/temple/engine.rb:51:in `inject'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/temple-0.10.3/lib/temple/engine.rb:51:in `call'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/cli.rb:91:in `generate_code'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/lib/haml/cli.rb:15:in `render'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
	from /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/haml-6.2.3/exe/haml:6:in `<top (required)>'
	from /home/fletch/.asdf/installs/ruby/3.2.2/bin/haml:25:in `load'
	from /home/fletch/.asdf/installs/ruby/3.2.2/bin/haml:25:in `<main>'
	from /home/fletch/.asdf/installs/ruby/3.2.2/bin/ruby_executable_hooks:22:in `eval'
	from /home/fletch/.asdf/installs/ruby/3.2.2/bin/ruby_executable_hooks:22:in `<main>'
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

$ haml version
6.2.3

@k0kubun
Copy link
Member

k0kubun commented Oct 14, 2023

Oh, good point. I have no idea why I didn't try an example closer to what you provided.

It appears that Temple::StaticAnalyzer.static? fails to recognize that the argument has a dynamic part, which is redirect_to. I can fix that on the temple side.

@k0kubun k0kubun reopened this Oct 14, 2023
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

2 participants