As brought up by @joelhawksley in #1613 (comment)
The compile-time optimizations we introduced in #1613 are experimental and opt-in and only applies for the helpers that the registry marked as "supported":
❯ bin/console
irb(main):001> require "herb/action_view/helper_registry"
=> true
irb(main):002> Herb::ActionView::HelperRegistry.supported.map(&:name)
=> ["image_tag", "javascript_include_tag", "javascript_tag", "content_tag", "tag", "link_to", "turbo_frame_tag"]
irb(main):003>
There is currently a gap when you overwrite content_tag or any other helper. As of right now they would get compiled away. The idea I had in mind to catch cases like these was to introduce a new development-only transform visitor that compiles in some runtime inspections whenever we compile away a helper. So that it could tell you at runtime that the helper method that we compiled away wasn't the original one from ActionView.
So if you had this:
<%= tag.div do %>
Content
<% end %>
it would currently compile this template with the compile-time optimizations to this:
bin/herb compile test.html.erb --optimize
__herb = ::Herb::Engine; _buf = ::String.new; _buf << '<div>
Content
</div>'.freeze;
_buf.to_s
and I was thinking of adding a pre- or postamble in development/test to either raise, or have it collect the warnings and show them like we just did in #1660:
__herb = ::Herb::Engine; _buf = ::String.new; _buf << '<div>
Content
</div>'.freeze;
_buf.to_s
+
+ raise "Helper was overwritten" if method(:tag).owner != Herb::ActionView::HelperRegistry.get(:tag).source
Originally posted by @marcoroth in #1613 (comment)
As brought up by @joelhawksley in #1613 (comment)
The compile-time optimizations we introduced in #1613 are experimental and opt-in and only applies for the helpers that the registry marked as "supported":
There is currently a gap when you overwrite
content_tagor any other helper. As of right now they would get compiled away. The idea I had in mind to catch cases like these was to introduce a new development-only transform visitor that compiles in some runtime inspections whenever we compile away a helper. So that it could tell you at runtime that the helper method that we compiled away wasn't the original one from ActionView.So if you had this:
it would currently compile this template with the compile-time optimizations to this:
bin/herb compile test.html.erb --optimizeand I was thinking of adding a pre- or postamble in development/test to either raise, or have it collect the warnings and show them like we just did in #1660:
Originally posted by @marcoroth in #1613 (comment)