Commit ae806a8
authored
Parser: Don't search for Action View Tag Helpers recursively (#1431)
This pull request fixes a bug in the parser analysis phase with
`action_view_helpers: true` enabled where `search_tag_helper_node` would
recursively traverse the entire Prism AST of an ERB expression, causing
tag helpers nested inside another call's arguments or block body to be
incorrectly detected and transformed as the top-level tag helper.
For example, the following template:
```erb
<% content_for :head, tag.meta(name: "viewport", content: "width=device-width, initial-scale=1") %>
```
Would incorrectly transform the `ERBContentNode` as if `tag.meta` were
the outermost call. It now correctly produces the following using
`action_view_helpers: true`:
```js
@ DocumentNode (location: (1:0)-(2:0))
└── children: (2 items)
├── @ ERBContentNode (location: (1:0)-(1:99))
│ ├── tag_opening: "<%" (location: (1:0)-(1:2))
│ ├── content: " content_for :head, tag.meta(name: "viewport", content: "width=device-width, initial-scale=1") " (location: (1:2)-(1:97))
│ ├── tag_closing: "%>" (location: (1:97)-(1:99))
│ ├── parsed: true
│ └── valid: true
│
└── @ HTMLTextNode (location: (1:99)-(2:0))
└── content: "\n"
```
The fix stops recursion at any `PM_CALL_NODE` that doesn't match a known
tag helper. A tag helper must be the outermost call in the ERB
expression, not nested inside another call's arguments or block body.
Resolves #1423
Resolves #14291 parent 2236f9d commit ae806a8
File tree
7 files changed
+130
-0
lines changed- src/analyze/action_view
- test
- analyze/action_view/tag_helper
- snapshots/analyze/action_view/tag_helper
- content_tag_test
- tag_test
7 files changed
+130
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
220 | 226 | | |
221 | 227 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
224 | 254 | | |
225 | 255 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments