added compiler warning functionality for head warnings (untested)

pull/18151/head
Elvin Seudieu 3 months ago
parent 8e7319063a
commit f9abdb6428

@ -697,6 +697,12 @@ Using `on:%name%` to listen to the %name% event is deprecated. Use the event att
See [the migration guide](v5-migration-guide#Event-changes) for more info.
### head_in_component
```
A `<head>` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use `<svelte:head>`?
```
### export_let_unused
```

@ -83,6 +83,9 @@ In a future version of Svelte, self-closing tags may be upgraded from a warning
See [the migration guide](v5-migration-guide#Event-changes) for more info.
## head_in_component
> A `<head>` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use `<svelte:head>`?
## node_invalid_placement_ssr
> %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning

@ -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, 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.head_in_component(node, filename, component_name, `${locator(node.start).line}`);
}
node.metadata.has_spread = node.attributes.some(
(attribute) => attribute.type === 'SpreadAttribute'
);

@ -113,6 +113,7 @@ export const codes = [
'element_implicitly_closed',
'element_invalid_self_closing_tag',
'event_directive_deprecated',
'head_in_component',
'node_invalid_placement_ssr',
'script_context_deprecated',
'script_unknown_attribute',
@ -785,6 +786,17 @@ 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\nhttps://svelte.dev/e/event_directive_deprecated`);
}
/**
* A `<head>` tag was detected in file `%filename%`, component `%component%`, at line %line%. This can lead to runtime errors. Did you mean to use `<svelte:head>`?
* @param {null | NodeLike} node
* @param {string} filename
* @param {string} component
* @param {string} line
*/
export function head_in_component(node, filename, component, line) {
w(node, 'head_in_component', `A \`<head>\` tag was detected in file \`${filename}\`, component \`${component}\`, at line ${line}. This can lead to runtime errors. Did you mean to use \`<svelte:head>\`?\nhttps://svelte.dev/e/head_in_component`);
}
/**
* %message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning
* @param {null | NodeLike} node

Loading…
Cancel
Save