From f9f94db4f016434cccb78d4a340de67ccae084e3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 22 Apr 2024 14:08:10 -0400 Subject: [PATCH] more --- .../messages/compile-errors/attributes.md | 30 +++++---- packages/svelte/src/compiler/errors-tmp.js | 1 - packages/svelte/src/compiler/errors.js | 61 +++++++++++------- .../compiler/phases/1-parse/state/element.js | 5 +- .../compiler/phases/2-analyze/validation.js | 63 ++++++++++--------- 5 files changed, 93 insertions(+), 67 deletions(-) diff --git a/packages/svelte/messages/compile-errors/attributes.md b/packages/svelte/messages/compile-errors/attributes.md index e59391fb9a..239b71a43c 100644 --- a/packages/svelte/messages/compile-errors/attributes.md +++ b/packages/svelte/messages/compile-errors/attributes.md @@ -14,29 +14,37 @@ Event attribute must be a JavaScript expression, not a string '%name%' is not a valid attribute name -## invalid_animation +## animation_invalid_placement -An element that uses the animate directive must be the immediate child of a keyed each block` - : type === 'each-key' - ? `An element that uses the animate directive must be used inside a keyed each block. Did you forget to add a key to your each block?` - : `An element that uses the animate directive must be the sole child of a keyed each block +An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block -## duplicate_animation +## animation_missing_key + +An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block. Did you forget to add a key to your each block? + +## animation_duplicate An element can only have one 'animate' directive ## invalid_event_modifier -Valid event modifiers are %modifiers.slice(0, -1).join(', ')% or %modifiers.slice(-1)%` - : `Event modifiers other than 'once' can only be used on DOM elements +Valid event modifiers are %list% + +## invalid_component_event_modifier + +Event modifiers other than 'once' can only be used on DOM elements ## invalid_event_modifier_combination The '%modifier1%' and '%modifier2%' modifiers cannot be used together -## duplicate_transition +## transition_duplicate -TODO +Cannot use multiple `%type%:` directives on a single element + +## transition_conflict + +Cannot use `%type%:` alongside existing `%existing%:` directive ## invalid_let_directive_placement @@ -48,4 +56,4 @@ Invalid 'style:' modifier. Valid modifiers are: 'important' ## invalid_sequence_expression -Sequence expressions are not allowed as attribute/directive values in runes mode, unless wrapped in parentheses \ No newline at end of file +Sequence expressions are not allowed as attribute/directive values in runes mode, unless wrapped in parentheses diff --git a/packages/svelte/src/compiler/errors-tmp.js b/packages/svelte/src/compiler/errors-tmp.js index 4eea9e160e..00f16c3be5 100644 --- a/packages/svelte/src/compiler/errors-tmp.js +++ b/packages/svelte/src/compiler/errors-tmp.js @@ -149,7 +149,6 @@ const const_tag = { /** @satisfies {Errors} */ const errors = { ...internal, - ...attributes, ...slots, ...bindings, ...variables, diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 3e8bd54ce9..eb66c3fc9c 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -98,8 +98,8 @@ export function invalid_attribute_name(node, name) { * @returns {never} */ -export function invalid_animation(node) { - e(node, "invalid_animation", "An element that uses the animate directive must be the immediate child of a keyed each block`\n\t\t\t: type === 'each-key'\n\t\t\t\t? `An element that uses the animate directive must be used inside a keyed each block. Did you forget to add a key to your each block?`\n\t\t\t\t: `An element that uses the animate directive must be the sole child of a keyed each block"); +export function animation_invalid_placement(node) { + e(node, "animation_invalid_placement", "An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block"); } /** @@ -107,8 +107,8 @@ export function invalid_animation(node) { * @returns {never} */ -export function duplicate_animation(node) { - e(node, "duplicate_animation", "An element can only have one 'animate' directive"); +export function animation_missing_key(node) { + e(node, "animation_missing_key", "An element that uses the `animate:` directive must be the only child of a keyed `{#each ...}` block. Did you forget to add a key to your each block?"); } /** @@ -116,8 +116,26 @@ export function duplicate_animation(node) { * @returns {never} */ -export function invalid_event_modifier(node) { - e(node, "invalid_event_modifier", "Valid event modifiers are %modifiers.slice(0, -1).join(', ')% or %modifiers.slice(-1)%`\n\t\t\t: `Event modifiers other than 'once' can only be used on DOM elements"); +export function animation_duplicate(node) { + e(node, "animation_duplicate", "An element can only have one 'animate' directive"); +} + +/** + * @param {number | NodeLike} node + * @param {string} list + * @returns {never} + */ +export function invalid_event_modifier(node, list) { + e(node, "invalid_event_modifier", `Valid event modifiers are ${list}`); +} + +/** + * @param {number | NodeLike} node + + * @returns {never} + */ +export function invalid_component_event_modifier(node) { + e(node, "invalid_component_event_modifier", "Event modifiers other than 'once' can only be used on DOM elements"); } /** @@ -132,11 +150,21 @@ export function invalid_event_modifier_combination(node, modifier1, modifier2) { /** * @param {number | NodeLike} node + * @param {string} type + * @returns {never} + */ +export function transition_duplicate(node, type) { + e(node, "transition_duplicate", `Cannot use multiple \`${type}:\` directives on a single element`); +} +/** + * @param {number | NodeLike} node + * @param {string} type + * @param {string} existing * @returns {never} */ -export function duplicate_transition(node) { - e(node, "duplicate_transition", "TODO"); +export function transition_conflict(node, type, existing) { + e(node, "transition_conflict", `Cannot use \`${type}:\` alongside existing \`${existing}:\` directive`); } /** @@ -397,7 +425,7 @@ export function invalid_css_declaration(node) { * @returns {never} */ export function invalid_textarea_content(node) { - e(node, "invalid_textarea_content", "A