From bfa094edcc1a70d082ca38a07a27d52a59c02725 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 9 Dec 2024 16:55:02 +0100 Subject: [PATCH] fix mutations messing with nodes between runs --- .../svelte/scripts/process-messages/index.js | 11 +- packages/svelte/src/compiler/errors.js | 174 +++++++++--------- packages/svelte/src/compiler/warnings.js | 76 ++++---- packages/svelte/src/internal/client/errors.js | 28 +-- .../svelte/src/internal/client/warnings.js | 26 +-- 5 files changed, 158 insertions(+), 157 deletions(-) diff --git a/packages/svelte/scripts/process-messages/index.js b/packages/svelte/scripts/process-messages/index.js index c71e4cfda2..bbe257498e 100644 --- a/packages/svelte/scripts/process-messages/index.js +++ b/packages/svelte/scripts/process-messages/index.js @@ -339,7 +339,7 @@ function transform(name, dest) { }; for (let i = 0; i < node.expressions.length; i += 1) { - const q = node.quasis[i + 1]; + const q = structuredClone(node.quasis[i + 1]); const e = node.expressions[i]; if (e.type === 'Literal' && e.value === 'CODE') { @@ -355,10 +355,11 @@ function transform(name, dest) { } if (message.type === 'TemplateLiteral') { - quasi.value.raw += message.quasis[0].value.raw; - out.quasis.push(...message.quasis.slice(1)); - out.expressions.push(...message.expressions); - quasi = message.quasis[message.quasis.length - 1]; + const m = structuredClone(message); + quasi.value.raw += m.quasis[0].value.raw; + out.quasis.push(...m.quasis.slice(1)); + out.expressions.push(...m.expressions); + quasi = m.quasis[m.quasis.length - 1]; quasi.value.raw += q.value.raw; continue; } diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 1763678c67..716855c66e 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -751,7 +751,7 @@ export function bind_invalid_name(node, name, explanation) { * @returns {never} */ export function bind_invalid_parens(node, name) { - e(node, "bind_invalid_parens", `\`bind:${name}={get, set}\` must not have surrounding parentheses\nSee https://svelte.dev/e/bind_invalid_name for more infobind_invalid_parens for more info`); + e(node, "bind_invalid_parens", `\`bind:${name}={get, set}\` must not have surrounding parentheses\nSee https://svelte.dev/e/bind_invalid_parens for more info`); } /** @@ -762,7 +762,7 @@ export function bind_invalid_parens(node, name) { * @returns {never} */ export function bind_invalid_target(node, name, elements) { - e(node, "bind_invalid_target", `\`bind:${name}\` can only be used with ${elements}\nSee https://svelte.dev/e/bind_invalid_name for more infobind_invalid_target for more info`); + e(node, "bind_invalid_target", `\`bind:${name}\` can only be used with ${elements}\nSee https://svelte.dev/e/bind_invalid_target for more info`); } /** @@ -771,7 +771,7 @@ export function bind_invalid_target(node, name, elements) { * @returns {never} */ export function bind_invalid_value(node) { - e(node, "bind_invalid_value", `Can only bind to state or props\nSee https://svelte.dev/e/bind_invalid_name for more infobind_invalid_value for more info`); + e(node, "bind_invalid_value", `Can only bind to state or props\nSee https://svelte.dev/e/bind_invalid_value for more info`); } /** @@ -781,7 +781,7 @@ export function bind_invalid_value(node) { * @returns {never} */ export function block_duplicate_clause(node, name) { - e(node, "block_duplicate_clause", `${name} cannot appear more than once within a block\nSee https://svelte.dev/e/bind_invalid_name for more infoblock_duplicate_clause for more info`); + e(node, "block_duplicate_clause", `${name} cannot appear more than once within a block\nSee https://svelte.dev/e/block_duplicate_clause for more info`); } /** @@ -790,7 +790,7 @@ export function block_duplicate_clause(node, name) { * @returns {never} */ export function block_invalid_continuation_placement(node) { - e(node, "block_invalid_continuation_placement", `{:...} block is invalid at this position (did you forget to close the preceding element or block?)\nSee https://svelte.dev/e/bind_invalid_name for more infoblock_invalid_continuation_placement for more info`); + e(node, "block_invalid_continuation_placement", `{:...} block is invalid at this position (did you forget to close the preceding element or block?)\nSee https://svelte.dev/e/block_invalid_continuation_placement for more info`); } /** @@ -799,7 +799,7 @@ export function block_invalid_continuation_placement(node) { * @returns {never} */ export function block_invalid_elseif(node) { - e(node, "block_invalid_elseif", `'elseif' should be 'else if'\nSee https://svelte.dev/e/bind_invalid_name for more infoblock_invalid_elseif for more info`); + e(node, "block_invalid_elseif", `'elseif' should be 'else if'\nSee https://svelte.dev/e/block_invalid_elseif for more info`); } /** @@ -810,7 +810,7 @@ export function block_invalid_elseif(node) { * @returns {never} */ export function block_invalid_placement(node, name, location) { - e(node, "block_invalid_placement", `{#${name} ...} block cannot be ${location}\nSee https://svelte.dev/e/bind_invalid_name for more infoblock_invalid_placement for more info`); + e(node, "block_invalid_placement", `{#${name} ...} block cannot be ${location}\nSee https://svelte.dev/e/block_invalid_placement for more info`); } /** @@ -819,7 +819,7 @@ export function block_invalid_placement(node, name, location) { * @returns {never} */ export function block_unclosed(node) { - e(node, "block_unclosed", `Block was left open\nSee https://svelte.dev/e/bind_invalid_name for more infoblock_unclosed for more info`); + e(node, "block_unclosed", `Block was left open\nSee https://svelte.dev/e/block_unclosed for more info`); } /** @@ -829,7 +829,7 @@ export function block_unclosed(node) { * @returns {never} */ export function block_unexpected_character(node, character) { - e(node, "block_unexpected_character", `Expected a \`${character}\` character immediately following the opening bracket\nSee https://svelte.dev/e/bind_invalid_name for more infoblock_unexpected_character for more info`); + e(node, "block_unexpected_character", `Expected a \`${character}\` character immediately following the opening bracket\nSee https://svelte.dev/e/block_unexpected_character for more info`); } /** @@ -838,7 +838,7 @@ export function block_unexpected_character(node, character) { * @returns {never} */ export function block_unexpected_close(node) { - e(node, "block_unexpected_close", `Unexpected block closing tag\nSee https://svelte.dev/e/bind_invalid_name for more infoblock_unexpected_close for more info`); + e(node, "block_unexpected_close", `Unexpected block closing tag\nSee https://svelte.dev/e/block_unexpected_close for more info`); } /** @@ -847,7 +847,7 @@ export function block_unexpected_close(node) { * @returns {never} */ export function component_invalid_directive(node) { - e(node, "component_invalid_directive", `This type of directive is not valid on components\nSee https://svelte.dev/e/bind_invalid_name for more infocomponent_invalid_directive for more info`); + e(node, "component_invalid_directive", `This type of directive is not valid on components\nSee https://svelte.dev/e/component_invalid_directive for more info`); } /** @@ -857,7 +857,7 @@ export function component_invalid_directive(node) { * @returns {never} */ export function const_tag_cycle(node, cycle) { - e(node, "const_tag_cycle", `Cyclical dependency detected: ${cycle}\nSee https://svelte.dev/e/bind_invalid_name for more infoconst_tag_cycle for more info`); + e(node, "const_tag_cycle", `Cyclical dependency detected: ${cycle}\nSee https://svelte.dev/e/const_tag_cycle for more info`); } /** @@ -866,7 +866,7 @@ export function const_tag_cycle(node, cycle) { * @returns {never} */ export function const_tag_invalid_expression(node) { - e(node, "const_tag_invalid_expression", `{@const ...} must consist of a single variable declaration\nSee https://svelte.dev/e/bind_invalid_name for more infoconst_tag_invalid_expression for more info`); + e(node, "const_tag_invalid_expression", `{@const ...} must consist of a single variable declaration\nSee https://svelte.dev/e/const_tag_invalid_expression for more info`); } /** @@ -875,7 +875,7 @@ export function const_tag_invalid_expression(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}\`, \`\` or \`\`\nSee https://svelte.dev/e/bind_invalid_name for more infoconst_tag_invalid_placement for more info`); + e(node, "const_tag_invalid_placement", `\`{@const}\` must be the immediate child of \`{#snippet}\`, \`{#if}\`, \`{:else if}\`, \`{:else}\`, \`{#each}\`, \`{:then}\`, \`{:catch}\`, \`\` or \`\`\nSee https://svelte.dev/e/const_tag_invalid_placement for more info`); } /** @@ -884,7 +884,7 @@ export function const_tag_invalid_placement(node) { * @returns {never} */ export function debug_tag_invalid_arguments(node) { - e(node, "debug_tag_invalid_arguments", `{@debug ...} arguments must be identifiers, not arbitrary expressions\nSee https://svelte.dev/e/bind_invalid_name for more infodebug_tag_invalid_arguments for more info`); + e(node, "debug_tag_invalid_arguments", `{@debug ...} arguments must be identifiers, not arbitrary expressions\nSee https://svelte.dev/e/debug_tag_invalid_arguments for more info`); } /** @@ -893,7 +893,7 @@ export function debug_tag_invalid_arguments(node) { * @returns {never} */ export function directive_invalid_value(node) { - e(node, "directive_invalid_value", `Directive value must be a JavaScript expression enclosed in curly braces\nSee https://svelte.dev/e/bind_invalid_name for more infodirective_invalid_value for more info`); + e(node, "directive_invalid_value", `Directive value must be a JavaScript expression enclosed in curly braces\nSee https://svelte.dev/e/directive_invalid_value for more info`); } /** @@ -903,7 +903,7 @@ export function directive_invalid_value(node) { * @returns {never} */ export function directive_missing_name(node, type) { - e(node, "directive_missing_name", `\`${type}\` name cannot be empty\nSee https://svelte.dev/e/bind_invalid_name for more infodirective_missing_name for more info`); + e(node, "directive_missing_name", `\`${type}\` name cannot be empty\nSee https://svelte.dev/e/directive_missing_name for more info`); } /** @@ -913,7 +913,7 @@ export function directive_missing_name(node, type) { * @returns {never} */ export function element_invalid_closing_tag(node, name) { - e(node, "element_invalid_closing_tag", `\`\` attempted to close an element that was not open\nSee https://svelte.dev/e/bind_invalid_name for more infoelement_invalid_closing_tag for more info`); + e(node, "element_invalid_closing_tag", `\`\` attempted to close an element that was not open\nSee https://svelte.dev/e/element_invalid_closing_tag for more info`); } /** @@ -924,7 +924,7 @@ export function element_invalid_closing_tag(node, name) { * @returns {never} */ export function element_invalid_closing_tag_autoclosed(node, name, reason) { - e(node, "element_invalid_closing_tag_autoclosed", `\`\` attempted to close element that was already automatically closed by \`<${reason}>\` (cannot nest \`<${reason}>\` inside \`<${name}>\`)\nSee https://svelte.dev/e/bind_invalid_name for more infoelement_invalid_closing_tag_autoclosed for more info`); + e(node, "element_invalid_closing_tag_autoclosed", `\`\` attempted to close element that was already automatically closed by \`<${reason}>\` (cannot nest \`<${reason}>\` inside \`<${name}>\`)\nSee https://svelte.dev/e/element_invalid_closing_tag_autoclosed for more info`); } /** @@ -934,7 +934,7 @@ export function element_invalid_closing_tag_autoclosed(node, name, reason) { * @returns {never} */ export function element_unclosed(node, name) { - e(node, "element_unclosed", `\`<${name}>\` was left open\nSee https://svelte.dev/e/bind_invalid_name for more infoelement_unclosed for more info`); + e(node, "element_unclosed", `\`<${name}>\` was left open\nSee https://svelte.dev/e/element_unclosed for more info`); } /** @@ -943,7 +943,7 @@ export function element_unclosed(node, name) { * @returns {never} */ export function event_handler_invalid_component_modifier(node) { - e(node, "event_handler_invalid_component_modifier", `Event modifiers other than 'once' can only be used on DOM elements\nSee https://svelte.dev/e/bind_invalid_name for more infoevent_handler_invalid_component_modifier for more info`); + e(node, "event_handler_invalid_component_modifier", `Event modifiers other than 'once' can only be used on DOM elements\nSee https://svelte.dev/e/event_handler_invalid_component_modifier for more info`); } /** @@ -953,7 +953,7 @@ export function event_handler_invalid_component_modifier(node) { * @returns {never} */ export function event_handler_invalid_modifier(node, list) { - e(node, "event_handler_invalid_modifier", `Valid event modifiers are ${list}\nSee https://svelte.dev/e/bind_invalid_name for more infoevent_handler_invalid_modifier for more info`); + e(node, "event_handler_invalid_modifier", `Valid event modifiers are ${list}\nSee https://svelte.dev/e/event_handler_invalid_modifier for more info`); } /** @@ -964,7 +964,7 @@ export function event_handler_invalid_modifier(node, list) { * @returns {never} */ export function event_handler_invalid_modifier_combination(node, modifier1, modifier2) { - e(node, "event_handler_invalid_modifier_combination", `The '${modifier1}' and '${modifier2}' modifiers cannot be used together\nSee https://svelte.dev/e/bind_invalid_name for more infoevent_handler_invalid_modifier_combination for more info`); + e(node, "event_handler_invalid_modifier_combination", `The '${modifier1}' and '${modifier2}' modifiers cannot be used together\nSee https://svelte.dev/e/event_handler_invalid_modifier_combination for more info`); } /** @@ -973,7 +973,7 @@ export function event_handler_invalid_modifier_combination(node, modifier1, modi * @returns {never} */ export function expected_attribute_value(node) { - e(node, "expected_attribute_value", `Expected attribute value\nSee https://svelte.dev/e/bind_invalid_name for more infoexpected_attribute_value for more info`); + e(node, "expected_attribute_value", `Expected attribute value\nSee https://svelte.dev/e/expected_attribute_value for more info`); } /** @@ -982,7 +982,7 @@ export function expected_attribute_value(node) { * @returns {never} */ export function expected_block_type(node) { - e(node, "expected_block_type", `Expected 'if', 'each', 'await', 'key' or 'snippet'\nSee https://svelte.dev/e/bind_invalid_name for more infoexpected_block_type for more info`); + e(node, "expected_block_type", `Expected 'if', 'each', 'await', 'key' or 'snippet'\nSee https://svelte.dev/e/expected_block_type for more info`); } /** @@ -991,7 +991,7 @@ export function expected_block_type(node) { * @returns {never} */ export function expected_identifier(node) { - e(node, "expected_identifier", `Expected an identifier\nSee https://svelte.dev/e/bind_invalid_name for more infoexpected_identifier for more info`); + e(node, "expected_identifier", `Expected an identifier\nSee https://svelte.dev/e/expected_identifier for more info`); } /** @@ -1000,7 +1000,7 @@ export function expected_identifier(node) { * @returns {never} */ export function expected_pattern(node) { - e(node, "expected_pattern", `Expected identifier or destructure pattern\nSee https://svelte.dev/e/bind_invalid_name for more infoexpected_pattern for more info`); + e(node, "expected_pattern", `Expected identifier or destructure pattern\nSee https://svelte.dev/e/expected_pattern for more info`); } /** @@ -1010,7 +1010,7 @@ export function expected_pattern(node) { * @returns {never} */ export function expected_token(node, token) { - e(node, "expected_token", `Expected token ${token}\nSee https://svelte.dev/e/bind_invalid_name for more infoexpected_token for more info`); + e(node, "expected_token", `Expected token ${token}\nSee https://svelte.dev/e/expected_token for more info`); } /** @@ -1019,7 +1019,7 @@ export function expected_token(node, token) { * @returns {never} */ export function expected_whitespace(node) { - e(node, "expected_whitespace", `Expected whitespace\nSee https://svelte.dev/e/bind_invalid_name for more infoexpected_whitespace for more info`); + e(node, "expected_whitespace", `Expected whitespace\nSee https://svelte.dev/e/expected_whitespace for more info`); } /** @@ -1029,7 +1029,7 @@ export function expected_whitespace(node) { * @returns {never} */ export function illegal_element_attribute(node, name) { - e(node, "illegal_element_attribute", `\`<${name}>\` does not support non-event attributes or spread attributes\nSee https://svelte.dev/e/bind_invalid_name for more infoillegal_element_attribute for more info`); + e(node, "illegal_element_attribute", `\`<${name}>\` does not support non-event attributes or spread attributes\nSee https://svelte.dev/e/illegal_element_attribute for more info`); } /** @@ -1039,7 +1039,7 @@ export function illegal_element_attribute(node, name) { * @returns {never} */ export function js_parse_error(node, message) { - e(node, "js_parse_error", `${message}\nSee https://svelte.dev/e/bind_invalid_name for more infojs_parse_error for more info`); + e(node, "js_parse_error", `${message}\nSee https://svelte.dev/e/js_parse_error for more info`); } /** @@ -1048,7 +1048,7 @@ export function js_parse_error(node, message) { * @returns {never} */ export function let_directive_invalid_placement(node) { - e(node, "let_directive_invalid_placement", `\`let:\` directive at invalid position\nSee https://svelte.dev/e/bind_invalid_name for more infolet_directive_invalid_placement for more info`); + e(node, "let_directive_invalid_placement", `\`let:\` directive at invalid position\nSee https://svelte.dev/e/let_directive_invalid_placement for more info`); } /** @@ -1058,7 +1058,7 @@ export function let_directive_invalid_placement(node) { * @returns {never} */ export function mixed_event_handler_syntaxes(node, name) { - e(node, "mixed_event_handler_syntaxes", `Mixing old (on:${name}) and new syntaxes for event handling is not allowed. Use only the on${name} syntax\nSee https://svelte.dev/e/bind_invalid_name for more infomixed_event_handler_syntaxes for more info`); + e(node, "mixed_event_handler_syntaxes", `Mixing old (on:${name}) and new syntaxes for event handling is not allowed. Use only the on${name} syntax\nSee https://svelte.dev/e/mixed_event_handler_syntaxes for more info`); } /** @@ -1068,7 +1068,7 @@ export function mixed_event_handler_syntaxes(node, name) { * @returns {never} */ export function node_invalid_placement(node, message) { - e(node, "node_invalid_placement", `${message}. The browser will 'repair' the HTML (by moving, removing, or inserting elements) which breaks Svelte's assumptions about the structure of your components.\nSee https://svelte.dev/e/bind_invalid_name for more infonode_invalid_placement for more info`); + e(node, "node_invalid_placement", `${message}. The browser will 'repair' the HTML (by moving, removing, or inserting elements) which breaks Svelte's assumptions about the structure of your components.\nSee https://svelte.dev/e/node_invalid_placement for more info`); } /** @@ -1077,7 +1077,7 @@ export function node_invalid_placement(node, message) { * @returns {never} */ export function render_tag_invalid_call_expression(node) { - e(node, "render_tag_invalid_call_expression", `Calling a snippet function using apply, bind or call is not allowed\nSee https://svelte.dev/e/bind_invalid_name for more inforender_tag_invalid_call_expression for more info`); + e(node, "render_tag_invalid_call_expression", `Calling a snippet function using apply, bind or call is not allowed\nSee https://svelte.dev/e/render_tag_invalid_call_expression for more info`); } /** @@ -1086,7 +1086,7 @@ export function render_tag_invalid_call_expression(node) { * @returns {never} */ export function render_tag_invalid_expression(node) { - e(node, "render_tag_invalid_expression", `\`{@render ...}\` tags can only contain call expressions\nSee https://svelte.dev/e/bind_invalid_name for more inforender_tag_invalid_expression for more info`); + e(node, "render_tag_invalid_expression", `\`{@render ...}\` tags can only contain call expressions\nSee https://svelte.dev/e/render_tag_invalid_expression for more info`); } /** @@ -1095,7 +1095,7 @@ export function render_tag_invalid_expression(node) { * @returns {never} */ export function render_tag_invalid_spread_argument(node) { - e(node, "render_tag_invalid_spread_argument", `cannot use spread arguments in \`{@render ...}\` tags\nSee https://svelte.dev/e/bind_invalid_name for more inforender_tag_invalid_spread_argument for more info`); + e(node, "render_tag_invalid_spread_argument", `cannot use spread arguments in \`{@render ...}\` tags\nSee https://svelte.dev/e/render_tag_invalid_spread_argument for more info`); } /** @@ -1104,7 +1104,7 @@ export function render_tag_invalid_spread_argument(node) { * @returns {never} */ export function script_duplicate(node) { - e(node, "script_duplicate", `A component can have a single top-level \`