Skip to content

Commit

Permalink
feat: interpolated attributes without names
Browse files Browse the repository at this point in the history
Fixes #28.
  • Loading branch information
virchau13 committed Apr 23, 2024
1 parent 8624ff8 commit 4be1807
Show file tree
Hide file tree
Showing 5 changed files with 1,613 additions and 1,474 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ These are used as tags that aren't actually present in the final HTML.
These are implemented by special-casing unnamed elements in the external lexer.

#### Attribute interpolations
These are special attributes that evaluate to the result of a TypeScript expression. Astro's docs call these "expressions".
These are special attributes that evaluate to the result of a TypeScript expression. Astro's docs call these "expressions". They come in two forms:
```astro
<div style={styleMap}></div>
<div {...attrMap}></div>
```
These are just handled as injected TypeScript.

Expand Down
26 changes: 26 additions & 0 deletions corpus/interpolated-attribute-map.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
===
Interpolated attribute map (without equal sign or name)
===

<div regattr="hi" {...specialinterp} reginterp={interp}>
</div>

-------

(document
(element
(start_tag
(tag_name)
(attribute
(attribute_name)
(quoted_attribute_value
(attribute_value)))
(attribute
(attribute_interpolation
(attribute_js_expr)))
(attribute
(attribute_name)
(attribute_interpolation
(attribute_js_expr))))
(end_tag
(tag_name))))
3 changes: 3 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ module.exports = grammar(HTML, {
$.attribute_backtick_string,
),
),
// Astro directly allows attributes without equal signs,
// e.g. <div {...attrs} />
$.attribute_interpolation,
),

attribute_interpolation: $ => seq(
Expand Down
4 changes: 4 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@
]
}
]
},
{
"type": "SYMBOL",
"name": "attribute_interpolation"
}
]
},
Expand Down
Loading

0 comments on commit 4be1807

Please sign in to comment.