pull/18151/merge
Elvin Seudieu Jr. 7 days ago committed by GitHub
commit 10f7013fd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: warn when bare `<head>` is used in a component

@ -982,6 +982,12 @@ A derived value may be used in other contexts:
See [the note in the docs](legacy-svelte-self) for more info.
### unexpected_head
```
Using `<head>` (%location%) will likely lead to runtime errors. Use [`<svelte:head>`](https://svelte.dev/docs/svelte/svelte-head) instead
```
### unknown_code
```

@ -159,3 +159,7 @@ A derived value may be used in other contexts:
> `<svelte:self>` is deprecated — use self-imports (e.g. `import %name% from './%basename%'`) instead
See [the note in the docs](legacy-svelte-self) for more info.
## unexpected_head
> Using `<head>` (%location%) will likely lead to runtime errors. Use [`<svelte:head>`](https://svelte.dev/docs/svelte/svelte-head) instead

@ -17,7 +17,7 @@ import { check_element } from './shared/a11y/index.js';
import { validate_element } from './shared/element.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
import { object } from '../../../utils/ast.js';
import { runes } from '../../../state.js';
import { component_name, filename, locate_node, locator, runes } from '../../../state.js';
/**
* @param {AST.RegularElement} node
@ -126,6 +126,10 @@ export function RegularElement(node, context) {
w.component_name_lowercase(node, node.name);
}
if (node.name === 'head' && !context.state.parent_element) {
w.unexpected_head(node, locate_node(node));
}
node.metadata.has_spread = node.attributes.some(
(attribute) => attribute.type === 'SpreadAttribute'
);

@ -119,7 +119,8 @@ export const codes = [
'slot_element_deprecated',
'svelte_component_deprecated',
'svelte_element_invalid_this',
'svelte_self_deprecated'
'svelte_self_deprecated',
'unexpected_head'
];
/**
@ -843,4 +844,13 @@ export function svelte_element_invalid_this(node) {
*/
export function svelte_self_deprecated(node, name, basename) {
w(node, 'svelte_self_deprecated', `\`<svelte:self>\` is deprecated — use self-imports (e.g. \`import ${name} from './${basename}'\`) instead\nhttps://svelte.dev/e/svelte_self_deprecated`);
}
/**
* Using `<head>` (%location%) will likely lead to runtime errors. Use [`<svelte:head>`](https://svelte.dev/docs/svelte/svelte-head) instead
* @param {null | NodeLike} node
* @param {string} location
*/
export function unexpected_head(node, location) {
w(node, 'unexpected_head', `Using \`<head>\` (${location}) will likely lead to runtime errors. Use [\`<svelte:head>\`](https://svelte.dev/docs/svelte/svelte-head) instead\nhttps://svelte.dev/e/unexpected_head`);
}

@ -0,0 +1,3 @@
<head>
<meta name="description" content="some description" />
</head>

@ -0,0 +1,14 @@
[
{
"code": "unexpected_head",
"message": "Using `<head>` ((unknown):1:0) will likely lead to runtime errors. Use [`<svelte:head>`](https://svelte.dev/docs/svelte/svelte-head) instead",
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 7
}
}
]
Loading…
Cancel
Save