fix: error on incorrect attributes for svelte:body (#13084)

* fix: error on spreading attributes for svelte:body

* tweak
pull/13090/head
Dominic Gannaway 1 year ago committed by GitHub
parent 2af9b193ce
commit cf6b64c6c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: error on incorrect attributes for svelte:body

@ -274,6 +274,10 @@ HTML restricts where certain elements can appear. In case of a violation the bro
> A component can have a single top-level `<style>` element > A component can have a single top-level `<style>` element
## svelte_body_illegal_attribute
> `<svelte:body>` does not support non-event attributes or spread attributes
## svelte_component_invalid_this ## svelte_component_invalid_this
> Invalid component definition — must be an `{expression}` > Invalid component definition — must be an `{expression}`

@ -1183,6 +1183,15 @@ export function style_duplicate(node) {
e(node, "style_duplicate", "A component can have a single top-level `<style>` element"); e(node, "style_duplicate", "A component can have a single top-level `<style>` element");
} }
/**
* `<svelte:body>` does not support non-event attributes or spread attributes
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function svelte_body_illegal_attribute(node) {
e(node, "svelte_body_illegal_attribute", "`<svelte:body>` does not support non-event attributes or spread attributes");
}
/** /**
* Invalid component definition must be an `{expression}` * Invalid component definition must be an `{expression}`
* @param {null | number | NodeLike} node * @param {null | number | NodeLike} node

@ -1,5 +1,7 @@
/** @import { SvelteBody } from '#compiler' */ /** @import { SvelteBody } from '#compiler' */
/** @import { Context } from '../types' */ /** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { is_event_attribute } from '../../../utils/ast.js';
import { disallow_children } from './shared/special-element.js'; import { disallow_children } from './shared/special-element.js';
/** /**
@ -8,5 +10,13 @@ import { disallow_children } from './shared/special-element.js';
*/ */
export function SvelteBody(node, context) { export function SvelteBody(node, context) {
disallow_children(node); disallow_children(node);
for (const attribute of node.attributes) {
if (
attribute.type === 'SpreadAttribute' ||
(attribute.type === 'Attribute' && !is_event_attribute(attribute))
) {
e.svelte_body_illegal_attribute(attribute);
}
}
context.next(); context.next();
} }

@ -1,7 +1,6 @@
/** @import { Expression } from 'estree' */ /** @import { Expression } from 'estree' */
/** @import { SvelteBody, SvelteDocument, SvelteWindow } from '#compiler' */ /** @import { SvelteBody, SvelteDocument, SvelteWindow } from '#compiler' */
/** @import { ComponentContext } from '../../types' */ /** @import { ComponentContext } from '../../types' */
import { is_event_attribute } from '../../../../../utils/ast.js';
import * as b from '../../../../../utils/builders.js'; import * as b from '../../../../../utils/builders.js';
/** /**

Loading…
Cancel
Save