Parser: Detect javascript_tag and javascript_include_tag helpers#1374
Merged
Parser: Detect javascript_tag and javascript_include_tag helpers#1374
javascript_tag and javascript_include_tag helpers#1374Conversation
javascript_tag and javascript_include_tagjavascript_tag and javascript_include_tag helpers
commit: |
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
marcoroth
pushed a commit
that referenced
this pull request
Mar 21, 2026
closes #543 handles three things 1. html: `<script>` tags 2. erb: Rails javascript helpers, i.e. `javascript_tag`, `javascript_include_tag`, ~and `javascript_pack_tag`~ 3. erb: Rails tag helpers, i.e. `tag.script` uses #1374 to handle both `<script>` and `javascript_tag` helpers via `BaseRuleVisitor#visitHTMLElementNode`. > [!NOTE] > Does not handle `nil` values, e.g. `tag.script nonce: nil` based on the specs of the inspiration. If wanted, we can add more specs and handlers.
marcoroth
added a commit
that referenced
this pull request
Mar 21, 2026
This pull request allows the parser to be able to detect and transform
the `image_tag` helper using the `action_view_helpers` parser option.
For example:
```html+erb
<%= image_tag image_path("picture.png"), class: "image" %>
```
Gets parsed as:
```js
@ DocumentNode (location: (1:0)-(1:58))
└── children: (1 item)
└── @ HTMLElementNode (location: (1:0)-(1:58))
├── open_tag:
│ └── @ ERBOpenTagNode (location: (1:0)-(1:58))
│ ├── tag_opening: "<%=" (location: (1:0)-(1:3))
│ ├── content: " image_tag image_path("picture.png"), class: "image" " (location: (1:3)-(1:56))
│ ├── tag_closing: "%>" (location: (1:56)-(1:58))
│ ├── tag_name: "img" (location: (1:4)-(1:13))
│ └── children: (2 items)
│ ├── @ HTMLAttributeNode (location: (1:14)-(1:39))
│ │ ├── name:
│ │ │ └── @ HTMLAttributeNameNode (location: (1:14)-(1:39))
│ │ │ └── children: (1 item)
│ │ │ └── @ LiteralNode (location: (1:14)-(1:39))
│ │ │ └── content: "src"
│ │ │
│ │ ├── equals: ":" (location: (1:14)-(1:39))
│ │ └── value:
│ │ └── @ HTMLAttributeValueNode (location: (1:14)-(1:39))
│ │ ├── open_quote: ∅
│ │ ├── children: (1 item)
│ │ │ └── @ RubyLiteralNode (location: (1:14)-(1:39))
│ │ │ └── content: "image_path(\"picture.png\")"
│ │ │
│ │ ├── close_quote: ∅
│ │ └── quoted: false
│ │
│ └── @ HTMLAttributeNode (location: (1:41)-(1:48))
│ ├── name:
│ │ └── @ HTMLAttributeNameNode (location: (1:41)-(1:48))
│ │ └── children: (1 item)
│ │ └── @ LiteralNode (location: (1:41)-(1:48))
│ │ └── content: "class"
│ │
│ ├── equals: "=" (location: (1:41)-(1:48))
│ └── value:
│ └── @ HTMLAttributeValueNode (location: (1:41)-(1:48))
│ ├── open_quote: """ (location: (1:41)-(1:48))
│ ├── children: (1 item)
│ │ └── @ LiteralNode (location: (1:41)-(1:48))
│ │ └── content: "image"
│ │
│ ├── close_quote: """ (location: (1:48)-(1:48))
│ └── quoted: true
│
├── tag_name: "img" (location: (1:4)-(1:13))
├── body: []
├── close_tag: ∅
├── is_void: true
└── element_source: "ActionView::Helpers::AssetTagHelper#image_tag"
```
This pull request also updates the rewriters to be able to rewrite
from/to the `image_path` syntax. The above example can be transformed to
this and back:
```html+erb
<img src="<%= image_path("picture.png") %>" class="image" />
```
Follow up on #1122
Follow up on #1354
Follow up on #1374
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request allows the parser to be able to detect and transform the
javascript_tagandjavascript_include_taghelpers using theaction_view_helpersparser option.For example:
Gets parsed as:
This pull request also updates the rewriters to be able to rewrite from/to the
javascript_tagsyntax. The above example can be transformed to this and back:And for
javascript_include_tag, the following:gets transformed to:
Follow up on #1122
Follow up on #1354
Fixes #991