fix: add validations for `svelte:dom` elements

pull/18058/head
paoloricciuti 2 weeks ago
parent 098cdebe95
commit df42e4babd

@ -605,6 +605,12 @@ Cannot use `await` in deriveds and template expressions, or at the top level of
Imports of `svelte/internal/*` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from `svelte/internal/*` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case
```
### incompatible_with_custom_renderer
```
%message% is not compatible with `customRenderer`
```
### inspect_trace_generator
```

@ -263,6 +263,10 @@ The same applies to components:
> `<%name%>` does not support non-event attributes or spread attributes
## incompatible_with_custom_renderer
> %message% is not compatible with `customRenderer`
## js_parse_error
> %message%

@ -1185,6 +1185,16 @@ export function illegal_element_attribute(node, name) {
e(node, 'illegal_element_attribute', `\`<${name}>\` does not support non-event attributes or spread attributes\nhttps://svelte.dev/e/illegal_element_attribute`);
}
/**
* %message% is not compatible with `customRenderer`
* @param {null | number | NodeLike} node
* @param {string} message
* @returns {never}
*/
export function incompatible_with_custom_renderer(node, message) {
e(node, 'incompatible_with_custom_renderer', `${message} is not compatible with \`customRenderer\`\nhttps://svelte.dev/e/incompatible_with_custom_renderer`);
}
/**
* %message%
* @param {null | number | NodeLike} node

@ -9,6 +9,10 @@ import { disallow_children } from './shared/special-element.js';
* @param {Context} context
*/
export function SvelteBody(node, context) {
if (context.state.analysis.custom_renderer) {
e.incompatible_with_custom_renderer(node, '`<svelte:body>`');
}
disallow_children(node);
for (const attribute of node.attributes) {
if (

@ -9,6 +9,10 @@ import { is_event_attribute } from '../../../utils/ast.js';
* @param {Context} context
*/
export function SvelteDocument(node, context) {
if (context.state.analysis.custom_renderer) {
e.incompatible_with_custom_renderer(node, '`<svelte:document>`');
}
disallow_children(node);
for (const attribute of node.attributes) {

@ -8,6 +8,10 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
* @param {Context} context
*/
export function SvelteHead(node, context) {
if (context.state.analysis.custom_renderer) {
e.incompatible_with_custom_renderer(node, '`<svelte:head>`');
}
for (const attribute of node.attributes) {
e.svelte_head_illegal_attribute(attribute);
}

@ -9,6 +9,10 @@ import { is_event_attribute } from '../../../utils/ast.js';
* @param {Context} context
*/
export function SvelteWindow(node, context) {
if (context.state.analysis.custom_renderer) {
e.incompatible_with_custom_renderer(node, '`<svelte:window>`');
}
disallow_children(node);
for (const attribute of node.attributes) {

@ -51,7 +51,7 @@ export function transform_template(state, namespace, flags = 0) {
flags ? b.literal(flags) : undefined
);
if (state.template.contains_script_tag) {
if (state.template.contains_script_tag && !state.analysis.custom_renderer) {
call = b.call(`$.with_script`, call);
}

@ -18,7 +18,6 @@ import { COMMENT_NODE, EFFECT_PRESERVED, HEAD_EFFECT } from '#client/constants';
* @returns {void}
*/
export function head(hash, render_fn) {
// TODO RENDERER: throw in case we are using custom renderers as this rely on the head element
// The head function may be called after the first hydration pass and ssr comment nodes may still be present,
// therefore we need to skip that when we detect that we're not in hydration mode.
let previous_hydrate_node = null;

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
compile_error: '`<svelte:body>` is not compatible with `customRenderer`'
});

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
compile_error: '`<svelte:document>` is not compatible with `customRenderer`'
});

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
compile_error: '`<svelte:head>` is not compatible with `customRenderer`'
});

@ -0,0 +1,9 @@
<script>
let color = $state('red');
</script>
<svelte:head>
<script>
console.log('hello from script');
</script>
</svelte:head>

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
compile_error: '`<svelte:window>` is not compatible with `customRenderer`'
});
Loading…
Cancel
Save