Commit 4856642
authored
Parser: Add
This pull request adds support for parsing dot-notation component tags
like `<Dialog.body>` and `<Dialog.footer>` as single HTML elements. A
new `dot_notation_tags` parser option enables this syntax (defaults to
`false`).
When enabled, the parser recognizes `<Identifier.identifier>` patterns
where the first segment starts with an uppercase letter as a single tag
name. Subsequent segments can be any valid identifier (uppercase or
lowercase). This is similar to how JSX handles compound component
patterns.
For example, the following template with `dot_notation_tags: true`:
```html
<Dialog.wrapper id="demo" title="Confirm">
<Dialog.body>Are you sure?</Dialog.body>
<Dialog.footer>
<Dialog.cancel />
<Dialog.confirm autofocus />
</Dialog.footer>
</Dialog.wrapper>
```
Produces:
```js
@ DocumentNode (location: (1:0)-(9:0))
└── children: (1 item)
└── @ HTMLElementNode (location: (1:0)-(8:18))
├── open_tag:
│ └── @ HTMLOpenTagNode (location: (1:0)-(1:43))
│ ├── tag_opening: "<" (location: (1:0)-(1:1))
│ ├── tag_name: "Dialog.wrapper" (location: (1:1)-(1:15))
│ ├── tag_closing: ">" (location: (1:42)-(1:43))
│ ├── children: [...]
│ └── is_void: false
│
├── tag_name: "Dialog.wrapper" (location: (1:1)-(1:15))
├── body: [...]
├── close_tag:
│ └── @ HTMLCloseTagNode (location: (8:0)-(8:18))
│ ├── tag_name: "Dialog.wrapper" (location: (8:2)-(8:16))
│ └── ...
│
├── is_void: false
└── element_source: "HTML"
```
When `dot_notation_tags` is `true` and the first segment starts with a
lowercase letter (e.g. `<dialog.Button>`), a `DotNotationCasingError` is
reported:
```js
@ DotNotationCasingError (location: (1:1)-(1:7))
├── message: "Dot-notation component tags require the first segment to start with an uppercase letter. `dialog` does not start with an uppercase letter."
└── segment: "dialog" (location: (1:1)-(1:7))
```
This is heavily inspired by
[`Phoenix.Component`](https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html)
and [JSX](https://react.dev/learn/writing-markup-with-jsx).dot_notation_tags parser option (#1436)1 parent 7527a66 commit 4856642
File tree
31 files changed
+647
-1
lines changed- ext/herb
- javascript/packages
- core/src
- linter/test
- node
- java
- org/herb
- playground
- src/controllers
- rust/src
- sig/herb
- src
- include
- parser
- parser
- test
- lexer
- parser
- snapshots
- lexer/tags_test
- parser/tags_test
- wasm
31 files changed
+647
-1
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 | + | |
461 | 471 | | |
462 | 472 | | |
463 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
112 | 120 | | |
113 | 121 | | |
114 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
98 | 108 | | |
99 | 109 | | |
100 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| |||
74 | 79 | | |
75 | 80 | | |
76 | 81 | | |
| 82 | + | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| 97 | + | |
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
| |||
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| 116 | + | |
114 | 117 | | |
115 | 118 | | |
116 | 119 | | |
| |||
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
504 | 514 | | |
505 | 515 | | |
506 | 516 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1271 | 1271 | | |
1272 | 1272 | | |
1273 | 1273 | | |
| 1274 | + | |
1274 | 1275 | | |
1275 | 1276 | | |
1276 | 1277 | | |
| |||
0 commit comments