Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-cobras-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

feat: warn for lowercase `object.component` rendering
4 changes: 4 additions & 0 deletions packages/svelte/messages/compile-warnings/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

> Using `on:%name%` to listen to the %name% event is deprecated. Use the event attribute `on%name%` instead

## lowercase_component_rendering

> Are you trying to render `%component%`? Component names should be uppercase.

## node_invalid_placement_ssr

> %thing% is invalid inside `<%parent%>`. When rendering this component on the server, the resulting HTML will be modified by the browser, likely resulting in a `hydration_mismatch` warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export function RegularElement(node, context) {
}

const binding = context.state.scope.get(node.name);

if (context.state.analysis.runes && node.name.includes('.')) {
const [maybe_object] = node.name.split('.');
const object_binding = context.state.scope.get(maybe_object);

if (object_binding) {
w.lowercase_component_rendering(node, node.name);
}
}

if (
binding !== null &&
binding.declaration_kind === 'import' &&
Expand Down
10 changes: 10 additions & 0 deletions packages/svelte/src/compiler/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const codes = [
"component_name_lowercase",
"element_invalid_self_closing_tag",
"event_directive_deprecated",
"lowercase_component_rendering",
"node_invalid_placement_ssr",
"slot_element_deprecated",
"svelte_element_invalid_this"
Expand Down Expand Up @@ -749,6 +750,15 @@ export function event_directive_deprecated(node, name) {
w(node, "event_directive_deprecated", `Using \`on:${name}\` to listen to the ${name} event is deprecated. Use the event attribute \`on${name}\` instead`);
}

/**
* Are you trying to render `%component%`? Component names should be uppercase.
* @param {null | NodeLike} node
* @param {string} component
*/
export function lowercase_component_rendering(node, component) {
w(node, "lowercase_component_rendering", `Are you trying to render \`${component}\`? Component names should be uppercase.`);
}

/**
* %thing% is invalid inside `<%parent%>`. When rendering this component on the server, the resulting HTML will be modified by the browser, likely resulting in a `hydration_mismatch` warning
* @param {null | NodeLike} node
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
const component = $state({});
</script>

<component.component></component.component>

<weird.element></weird.element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "lowercase_component_rendering",
"message": "Are you trying to render `component.component`? Component names should be uppercase.",
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 5,
"column": 43
}
}
]