Skip to content

Commit 5094cb9

Browse files
authored
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
1 parent 09db339 commit 5094cb9

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

.changeset/gold-students-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
feat: treat tag with `.` as a component, even if lowercase

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function parent_is_shadowroot_template(stack) {
7474

7575
const regex_closing_textarea_tag = /^<\/textarea(\s[^>]*)?>/i;
7676
const regex_closing_comment = /-->/;
77-
const regex_capital_letter = /[A-Z]/;
77+
const regex_component_name = /^(?:[A-Z]|[A-Za-z][A-Za-z0-9_$]*\.)/;
7878

7979
/** @param {Parser} parser */
8080
export default function element(parser) {
@@ -127,7 +127,7 @@ export default function element(parser) {
127127

128128
const type = meta_tags.has(name)
129129
? meta_tags.get(name)
130-
: regex_capital_letter.test(name[0])
130+
: regex_component_name.test(name)
131131
? 'Component'
132132
: name === 'title' && parent_is_head(parser.stack)
133133
? 'TitleElement'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: '<h1>hello</h1>'
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>hello</h1>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import child from './child.svelte';
3+
4+
const components = { child };
5+
</script>
6+
7+
<components.child />

sites/svelte-5-preview/src/routes/docs/content/03-appendix/02-breaking-changes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ Svelte now use Mutation Observers instead of IFrames to measure dimensions for `
161161

162162
Content inside component tags becomes a [snippet prop](/docs/snippets) called `children`. You cannot have a separate prop by that name.
163163

164+
## Dot notation indicates a component
165+
166+
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:
167+
168+
```svelte
169+
{#each items as item}
170+
<item.component {...item.props} />
171+
{/each}
172+
```
173+
164174
## Breaking changes in runes mode
165175

166176
Some breaking changes only apply once your component is in runes mode.

0 commit comments

Comments
 (0)