pull/11327/head
Rich Harris 2 years ago
parent ceeaa2eb6b
commit f74aa4f0d6

@ -1,3 +0,0 @@
## invalid_component_directive
> This type of directive is not valid on components

@ -1,3 +0,0 @@
## invalid_const_placement
> {@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, <svelte:fragment> or <Component>

@ -1,27 +0,0 @@
## invalid_textarea_content
> A `<textarea>` can have either a value attribute or (equivalently) child content, but not both
## invalid_void_content
> Void elements cannot have children or closing tags
## invalid_element_content
> <%name%> cannot have children
## invalid_tag_name
> Expected valid tag name
## invalid_node_placement
> %thing% is invalid inside <%parent%>
## illegal_title_attribute
> `<title>` cannot have attributes nor directives
## invalid_title_content
> `<title>` can only contain text and {tags}

@ -64,6 +64,18 @@
> Can only bind to state or props
## component_invalid_directive
> This type of directive is not valid on components
## const_tag_invalid_placement
> `{@const}` must be the immediate child of `{#snippet}`, `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `<svelte:fragment>` or `<Component>`
## element_invalid_tag_name
> Expected valid tag name
## event_handler_invalid_modifier
> Valid event modifiers are %list%
@ -80,6 +92,10 @@
> `let:` directive at invalid position
## node_invalid_placement
> %thing% is invalid inside <%parent%>
## slot_snippet_conflict
> Cannot use `<slot>` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely.
@ -128,6 +144,10 @@
> A component can only have one `<%name%>` element
## svelte_meta_invalid_content
> <%name%> cannot have children
## svelte_meta_invalid_tag
> Valid `<svelte:...>` tag names are %list%
@ -168,6 +188,18 @@
> `<svelte:self>` components can only exist inside `{#if}` blocks, `{#each}` blocks, `{#snippet}` blocks or slots passed to components
## textarea_invalid_content
> A `<textarea>` can have either a value attribute or (equivalently) child content, but not both
## title_illegal_attribute
> `<title>` cannot have attributes nor directives
## title_invalid_content
> `<title>` can only contain text and {tags}
## transition_duplicate
> Cannot use multiple `%type%:` directives on a single element
@ -175,3 +207,7 @@
## transition_conflict
> Cannot use `%type%:` alongside existing `%existing%:` directive
## void_element_invalid_content
> Void elements cannot have children or closing tags

@ -76,24 +76,6 @@ export function removed_compiler_option(node, msg) {
e(node, "removed_compiler_option", `Invalid compiler option: ${msg}`);
}
/**
* This type of directive is not valid on components
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_component_directive(node) {
e(node, "invalid_component_directive", "This type of directive is not valid on components");
}
/**
* {@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, <svelte:fragment> or <Component>
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_const_placement(node) {
e(node, "invalid_const_placement", "{@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, <svelte:fragment> or <Component>");
}
/**
* Declaration cannot be empty
* @param {null | number | NodeLike} node
@ -212,72 +194,6 @@ export function invalid_css_declaration(node) {
e(node, "invalid_css_declaration", "Declaration cannot be empty");
}
/**
* A `<textarea>` can have either a value attribute or (equivalently) child content, but not both
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_textarea_content(node) {
e(node, "invalid_textarea_content", "A `<textarea>` can have either a value attribute or (equivalently) child content, but not both");
}
/**
* Void elements cannot have children or closing tags
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_void_content(node) {
e(node, "invalid_void_content", "Void elements cannot have children or closing tags");
}
/**
* <%name%> cannot have children
* @param {null | number | NodeLike} node
* @param {string} name
* @returns {never}
*/
export function invalid_element_content(node, name) {
e(node, "invalid_element_content", `<${name}> cannot have children`);
}
/**
* Expected valid tag name
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_tag_name(node) {
e(node, "invalid_tag_name", "Expected valid tag name");
}
/**
* %thing% is invalid inside <%parent%>
* @param {null | number | NodeLike} node
* @param {string} thing
* @param {string} parent
* @returns {never}
*/
export function invalid_node_placement(node, thing, parent) {
e(node, "invalid_node_placement", `${thing} is invalid inside <${parent}>`);
}
/**
* `<title>` cannot have attributes nor directives
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function illegal_title_attribute(node) {
e(node, "illegal_title_attribute", "`<title>` cannot have attributes nor directives");
}
/**
* `<title>` can only contain text and {tags}
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_title_content(node) {
e(node, "invalid_title_content", "`<title>` can only contain text and {tags}");
}
/**
* Cyclical dependency detected: %cycle%
* @param {null | number | NodeLike} node
@ -1084,6 +1000,33 @@ export function bind_invalid_value(node) {
e(node, "bind_invalid_value", "Can only bind to state or props");
}
/**
* This type of directive is not valid on components
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function component_invalid_directive(node) {
e(node, "component_invalid_directive", "This type of directive is not valid on components");
}
/**
* `{@const}` must be the immediate child of `{#snippet}`, `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `<svelte:fragment>` or `<Component>`
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function const_tag_invalid_placement(node) {
e(node, "const_tag_invalid_placement", "`{@const}` must be the immediate child of `{#snippet}`, `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `<svelte:fragment>` or `<Component>`");
}
/**
* Expected valid tag name
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function element_invalid_tag_name(node) {
e(node, "element_invalid_tag_name", "Expected valid tag name");
}
/**
* Valid event modifiers are %list%
* @param {null | number | NodeLike} node
@ -1123,6 +1066,17 @@ export function let_directive_invalid_placement(node) {
e(node, "let_directive_invalid_placement", "`let:` directive at invalid position");
}
/**
* %thing% is invalid inside <%parent%>
* @param {null | number | NodeLike} node
* @param {string} thing
* @param {string} parent
* @returns {never}
*/
export function node_invalid_placement(node, thing, parent) {
e(node, "node_invalid_placement", `${thing} is invalid inside <${parent}>`);
}
/**
* Cannot use `<slot>` syntax and `{@render ...}` tags in the same component. Migrate towards `{@render ...}` tags completely.
* @param {null | number | NodeLike} node
@ -1233,6 +1187,16 @@ export function svelte_meta_duplicate(node, name) {
e(node, "svelte_meta_duplicate", `A component can only have one \`<${name}>\` element`);
}
/**
* <%name%> cannot have children
* @param {null | number | NodeLike} node
* @param {string} name
* @returns {never}
*/
export function svelte_meta_invalid_content(node, name) {
e(node, "svelte_meta_invalid_content", `<${name}> cannot have children`);
}
/**
* Valid `<svelte:...>` tag names are %list%
* @param {null | number | NodeLike} node
@ -1326,6 +1290,33 @@ export function svelte_self_invalid_placement(node) {
e(node, "svelte_self_invalid_placement", "`<svelte:self>` components can only exist inside `{#if}` blocks, `{#each}` blocks, `{#snippet}` blocks or slots passed to components");
}
/**
* A `<textarea>` can have either a value attribute or (equivalently) child content, but not both
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function textarea_invalid_content(node) {
e(node, "textarea_invalid_content", "A `<textarea>` can have either a value attribute or (equivalently) child content, but not both");
}
/**
* `<title>` cannot have attributes nor directives
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function title_illegal_attribute(node) {
e(node, "title_illegal_attribute", "`<title>` cannot have attributes nor directives");
}
/**
* `<title>` can only contain text and {tags}
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function title_invalid_content(node) {
e(node, "title_invalid_content", "`<title>` can only contain text and {tags}");
}
/**
* Cannot use multiple `%type%:` directives on a single element
* @param {null | number | NodeLike} node
@ -1347,6 +1338,15 @@ export function transition_conflict(node, type, existing) {
e(node, "transition_conflict", `Cannot use \`${type}:\` alongside existing \`${existing}:\` directive`);
}
/**
* Void elements cannot have children or closing tags
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function void_element_invalid_content(node) {
e(node, "void_element_invalid_content", "Void elements cannot have children or closing tags");
}
/**
* `%name%` is an illegal variable name. To reference a global variable called `%name%`, use `globalThis.%name%`
* @param {null | number | NodeLike} node

@ -101,7 +101,7 @@ export default function tag(parser) {
['svelte:options', 'svelte:window', 'svelte:body', 'svelte:document'].includes(name) &&
/** @type {import('#compiler').ElementLike} */ (parent).fragment.nodes.length
) {
e.invalid_element_content(
e.svelte_meta_invalid_content(
/** @type {import('#compiler').ElementLike} */ (parent).fragment.nodes[0].start,
name
);
@ -164,7 +164,7 @@ export default function tag(parser) {
if (is_closing_tag) {
if (is_void(name)) {
e.invalid_void_content(start);
e.void_element_invalid_content(start);
}
parser.eat('>', true);
@ -408,7 +408,7 @@ function read_tag_name(parser) {
}
if (!valid_tag_name.test(name)) {
e.invalid_tag_name(start);
e.element_invalid_tag_name(start);
}
return name;

@ -44,7 +44,7 @@ function validate_component(node, context) {
attribute.type !== 'OnDirective' &&
attribute.type !== 'BindDirective'
) {
e.invalid_component_directive(attribute);
e.component_invalid_directive(attribute);
}
if (
@ -471,7 +471,7 @@ const validation = {
((grand_parent?.type !== 'RegularElement' && grand_parent?.type !== 'SvelteElement') ||
!grand_parent.attributes.some((a) => a.type === 'Attribute' && a.name === 'slot')))
) {
e.invalid_const_placement(node);
e.const_tag_invalid_placement(node);
}
},
ImportDeclaration(node, context) {
@ -507,7 +507,7 @@ const validation = {
if (node.name === 'textarea' && node.fragment.nodes.length > 0) {
for (const attribute of node.attributes) {
if (attribute.type === 'Attribute' && attribute.name === 'value') {
e.invalid_textarea_content(node);
e.textarea_invalid_content(node);
}
}
}
@ -525,7 +525,7 @@ const validation = {
if (context.state.parent_element) {
if (!is_tag_valid_with_parent(node.name, context.state.parent_element)) {
e.invalid_node_placement(node, `<${node.name}>`, context.state.parent_element);
e.node_invalid_placement(node, `<${node.name}>`, context.state.parent_element);
}
}
@ -537,7 +537,7 @@ const validation = {
parent.name === node.name &&
interactive_elements.has(parent.name)
) {
e.invalid_node_placement(node, `<${node.name}>`, parent.name);
e.node_invalid_placement(node, `<${node.name}>`, parent.name);
}
}
}
@ -546,7 +546,7 @@ const validation = {
const path = context.path;
for (let parent of path) {
if (parent.type === 'RegularElement' && parent.name === 'p') {
e.invalid_node_placement(node, `<${node.name}>`, parent.name);
e.node_invalid_placement(node, `<${node.name}>`, parent.name);
}
}
}
@ -696,19 +696,19 @@ const validation = {
if (!node.parent) return;
if (context.state.parent_element && regex_not_whitespace.test(node.data)) {
if (!is_tag_valid_with_parent('#text', context.state.parent_element)) {
e.invalid_node_placement(node, 'Text node', context.state.parent_element);
e.node_invalid_placement(node, 'Text node', context.state.parent_element);
}
}
},
TitleElement(node) {
const attribute = node.attributes[0];
if (attribute) {
e.illegal_title_attribute(attribute);
e.title_illegal_attribute(attribute);
}
const child = node.fragment.nodes.find((n) => n.type !== 'Text' && n.type !== 'ExpressionTag');
if (child) {
e.invalid_title_content(child);
e.title_invalid_content(child);
}
},
UpdateExpression(node, context) {
@ -718,7 +718,7 @@ const validation = {
if (!node.parent) return;
if (context.state.parent_element) {
if (!is_tag_valid_with_parent('#text', context.state.parent_element)) {
e.invalid_node_placement(node, '{expression}', context.state.parent_element);
e.node_invalid_placement(node, '{expression}', context.state.parent_element);
}
}
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_element_content',
code: 'svelte_meta_invalid_content',
message: '<svelte:options> cannot have children',
position: [16, 16]
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_void_content',
code: 'void_element_invalid_content',
message: 'Void elements cannot have children or closing tags',
position: [23, 23]
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_element_content',
code: 'svelte_meta_invalid_content',
message: '<svelte:window> cannot have children',
position: [15, 15]
}

@ -1,6 +1,6 @@
[
{
"code": "invalid_component_directive",
"code": "component_invalid_directive",
"message": "This type of directive is not valid on components",
"start": {
"line": 7,

@ -1,6 +1,6 @@
[
{
"code": "invalid_component_directive",
"code": "component_invalid_directive",
"message": "This type of directive is not valid on components",
"start": {
"line": 7,

@ -1,6 +1,6 @@
[
{
"code": "invalid_component_directive",
"code": "component_invalid_directive",
"message": "This type of directive is not valid on components",
"start": {
"line": 7,

@ -1,7 +1,7 @@
[
{
"code": "invalid_const_placement",
"message": "{@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, <svelte:fragment> or <Component>",
"code": "const_tag_invalid_placement",
"message": "`{@const}` must be the immediate child of `{#snippet}`, `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `<svelte:fragment>` or `<Component>`",
"start": {
"line": 5,
"column": 0

@ -1,7 +1,7 @@
[
{
"code": "invalid_const_placement",
"message": "{@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, <svelte:fragment> or <Component>",
"code": "const_tag_invalid_placement",
"message": "`{@const}` must be the immediate child of `{#snippet}`, `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `<svelte:fragment>` or `<Component>`",
"start": {
"line": 7,
"column": 4

@ -1,6 +1,6 @@
[
{
"code": "invalid_node_placement",
"code": "node_invalid_placement",
"message": "<div> is invalid inside <p>",
"start": {
"line": 4,

@ -1,6 +1,6 @@
[
{
"code": "invalid_node_placement",
"code": "node_invalid_placement",
"message": "<a> is invalid inside <a>",
"start": {
"line": 4,

@ -1,6 +1,6 @@
[
{
"code": "invalid_textarea_content",
"code": "textarea_invalid_content",
"message": "A `<textarea>` can have either a value attribute or (equivalently) child content, but not both",
"start": {
"line": 1,

@ -1,6 +1,6 @@
[
{
"code": "illegal_title_attribute",
"code": "title_illegal_attribute",
"message": "`<title>` cannot have attributes nor directives",
"start": {
"line": 2,

@ -1,6 +1,6 @@
[
{
"code": "invalid_title_content",
"code": "title_invalid_content",
"message": "`<title>` can only contain text and {tags}",
"start": {
"line": 2,

@ -1,6 +1,6 @@
[
{
"code": "invalid_component_directive",
"code": "component_invalid_directive",
"message": "This type of directive is not valid on components",
"start": {
"line": 7,

Loading…
Cancel
Save