Commit 875047f
authored
Parser: Transform Action View tag helpers inside control flow blocks (#1447)
This pull request fixes a bug in the `action_view_helpers` parser
analysis where tag helpers inside control flow blocks were not being
transformed into `HTMLElementNode` AST representations. They remained as
`ERBContentNode`, making them invisible to consumers relying on the
transformed AST.
For example, the following template with `action_view_helpers: true`:
```erb
<% if condition? %>
<%= tag.img src: "/image.png", alt: "Photo" %>
<% end %>
```
Previously produced:
```js
@ ERBIfNode (location: (1:0)-(3:9))
├── statements: (1 item)
│ └── @ ERBContentNode (location: (2:2)-(2:48))
│ ├── tag_opening: "<%=" (location: (2:2)-(2:5))
│ ├── content: " tag.img src: \"/image.png\", alt: \"Photo\" " (location: (2:5)-(2:46))
│ └── tag_closing: "%>" (location: (2:46)-(2:48))
```
Now correctly produces:
```js
@ ERBIfNode (location: (1:0)-(3:9))
├── statements: (1 item)
│ └── @ HTMLElementNode (location: (2:2)-(2:48))
│ ├── open_tag:
│ │ └── @ ERBOpenTagNode (location: (2:2)-(2:48))
│ │ ├── tag_opening: "<%=" (location: (2:2)-(2:5))
│ │ ├── content: " tag.img src: \"/image.png\", alt: \"Photo\" " (location: (2:5)-(2:46))
│ │ ├── tag_closing: "%>" (location: (2:46)-(2:48))
│ │ ├── tag_name: "img" (location: (2:10)-(2:13))
│ │ └── children: (2 items)
│ │ ├── @ HTMLAttributeNode (name: "src", value: "/image.png")
│ │ └── @ HTMLAttributeNode (name: "alt", value: "Photo")
│ │
│ ├── tag_name: "img" (location: (2:10)-(2:13))
│ ├── body: []
│ ├── close_tag: ∅
│ ├── is_void: true
│ └── element_source: "ActionView::Helpers::TagHelper#tag"
```1 parent 8477bea commit 875047f
File tree
7 files changed
+629
-15
lines changed- src/analyze/action_view
- test
- analyze/action_view/tag_helper
- snapshots/analyze/action_view/tag_helper/tag_test
7 files changed
+629
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
1075 | | - | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
| 1065 | + | |
| 1066 | + | |
1080 | 1067 | | |
1081 | 1068 | | |
1082 | 1069 | | |
| |||
1231 | 1218 | | |
1232 | 1219 | | |
1233 | 1220 | | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
1234 | 1260 | | |
1235 | 1261 | | |
1236 | 1262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
282 | 337 | | |
283 | 338 | | |
Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments