feat: treat tag with `.` as a component, even if lowercase (#12798)

* feat: treat tag with `.` as a component, even if lowercase

* changeset

* consistency

* note breaking change

* oops, wrong place
pull/12805/head
Rich Harris 3 months ago committed by GitHub
parent 09db33979d
commit 5094cb9e89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: treat tag with `.` as a component, even if lowercase

@ -74,7 +74,7 @@ function parent_is_shadowroot_template(stack) {
const regex_closing_textarea_tag = /^<\/textarea(\s[^>]*)?>/i;
const regex_closing_comment = /-->/;
const regex_capital_letter = /[A-Z]/;
const regex_component_name = /^(?:[A-Z]|[A-Za-z][A-Za-z0-9_$]*\.)/;
/** @param {Parser} parser */
export default function element(parser) {
@ -127,7 +127,7 @@ export default function element(parser) {
const type = meta_tags.has(name)
? meta_tags.get(name)
: regex_capital_letter.test(name[0])
: regex_component_name.test(name)
? 'Component'
: name === 'title' && parent_is_head(parser.stack)
? 'TitleElement'

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: '<h1>hello</h1>'
});

@ -0,0 +1,7 @@
<script>
import child from './child.svelte';
const components = { child };
</script>
<components.child />

@ -161,6 +161,16 @@ Svelte now use Mutation Observers instead of IFrames to measure dimensions for `
Content inside component tags becomes a [snippet prop](/docs/snippets) called `children`. You cannot have a separate prop by that name.
## Dot notation indicates a component
In Svelte 4, `<foo.bar>` would create an element with a tag name of `"foo.bar"`. In Svelte 5, `foo.bar` is treated as a component instead. This is particularly useful inside `each` blocks:
```svelte
{#each items as item}
<item.component {...item.props} />
{/each}
```
## Breaking changes in runes mode
Some breaking changes only apply once your component is in runes mode.

Loading…
Cancel
Save