Commit f7f94c9
authored
Parser: Introduce
This pull request updates the parser to introduce a new
`VoidElementContentError` that gets added to a `HTMLElementNode` that
was transformed from a `tag` or `content_tag` call when the tag used is
a void element.
For example:
```erb
<%= content_tag :img, "/image.png" %>
```
Now gets parsed as the following with `action_view_helpers: true`:
```js
@ DocumentNode (location: (1:0)-(1:37))
βββ children: (1 item)
βββ @ HTMLElementNode (location: (1:0)-(1:37))
βββ errors: (1 error)
β βββ @ VoidElementContentError (location: (1:0)-(1:37))
β βββ message: "Void element `img` cannot have content. `img` does not accept positional arguments."
β βββ tag_name: "img" (location: (1:4)-(1:15))
β
βββ open_tag:
β βββ @ ERBOpenTagNode (location: (1:0)-(1:37))
β βββ tag_opening: "<%=" (location: (1:0)-(1:3))
β βββ content: " content_tag :img, "/image.png" " (location: (1:3)-(1:35))
β βββ tag_closing: "%>" (location: (1:35)-(1:37))
β βββ tag_name: "img" (location: (1:4)-(1:15))
β βββ children: []
β
βββ tag_name: "img" (location: (1:4)-(1:15))
βββ body: (1 item)
β βββ @ HTMLTextNode (location: (1:0)-(1:37))
β βββ content: "/image.png"
β
βββ close_tag: β
βββ is_void: true
βββ element_source: "ActionView::Helpers::TagHelper#content_tag"
```
It also catches:
```erb
<%= tag.img "/image.png" %>
```
```js
@ DocumentNode (location: (1:0)-(1:27))
βββ children: (1 item)
βββ @ HTMLElementNode (location: (1:0)-(1:27))
βββ errors: (1 error)
β βββ @ VoidElementContentError (location: (1:0)-(1:27))
β βββ message: "Void element `img` cannot have content. `img` does not accept positional arguments."
β βββ tag_name: "img" (location: (1:8)-(1:11))
β
βββ open_tag:
β βββ @ ERBOpenTagNode (location: (1:0)-(1:27))
β βββ tag_opening: "<%=" (location: (1:0)-(1:3))
β βββ content: " tag.img "/image.png" " (location: (1:3)-(1:25))
β βββ tag_closing: "%>" (location: (1:25)-(1:27))
β βββ tag_name: "img" (location: (1:8)-(1:11))
β βββ children: []
β
βββ tag_name: "img" (location: (1:8)-(1:11))
βββ body: (1 item)
β βββ @ HTMLTextNode (location: (1:0)-(1:27))
β βββ content: "/image.png"
β
βββ close_tag: β
βββ is_void: true
βββ element_source: "ActionView::Helpers::TagHelper#tag"
```VoidElementContentError (#1454)1 parent 5db6954 commit f7f94c9
File tree
12 files changed
+227
-18
lines changed- sig/herb
- src/analyze/action_view
- test
- analyze/action_view/tag_helper
- snapshots/analyze/action_view/tag_helper
- content_tag_test
- tag_test
12 files changed
+227
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
461 | 472 | | |
462 | 473 | | |
463 | 474 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
431 | 432 | | |
432 | 433 | | |
433 | 434 | | |
434 | | - | |
435 | | - | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
436 | 439 | | |
437 | 440 | | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
438 | 451 | | |
439 | 452 | | |
440 | 453 | | |
| |||
468 | 481 | | |
469 | 482 | | |
470 | 483 | | |
471 | | - | |
| 484 | + | |
472 | 485 | | |
473 | 486 | | |
474 | 487 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
260 | 272 | | |
261 | 273 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
349 | 361 | | |
350 | 362 | | |
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.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments