diff --git a/documentation/docs/98-reference/30-runtime-warnings.md b/documentation/docs/98-reference/30-runtime-warnings.md index b1823db956..53c7336c44 100644 --- a/documentation/docs/98-reference/30-runtime-warnings.md +++ b/documentation/docs/98-reference/30-runtime-warnings.md @@ -116,5 +116,6 @@ Value cannot be cloned with `$state.snapshot` — the original value was returne ``` The following properties cannot be cloned with `$state.snapshot` — the return value contains the originals: + %properties% ``` diff --git a/packages/svelte/scripts/process-messages/index.js b/packages/svelte/scripts/process-messages/index.js index 873d313e36..80d43a7efb 100644 --- a/packages/svelte/scripts/process-messages/index.js +++ b/packages/svelte/scripts/process-messages/index.js @@ -4,7 +4,7 @@ import * as acorn from 'acorn'; import { walk } from 'zimmerframe'; import * as esrap from 'esrap'; -/** @type {Record>} */ +/** @type {Record>} */ const messages = {}; const seen = new Set(); @@ -31,29 +31,11 @@ for (const category of fs.readdirSync('messages')) { sorted.push({ code, _ }); - const lines = text.trim().split('\n'); - let current_section = ''; - let sections = []; - let details = ''; + const sections = text.trim().split('\n\n'); + const details = []; - for (let i = 0; i < lines.length; i++) { - const line = lines[i]; - - if (line.startsWith('> ')) { - current_section += line.slice(2) + '\n'; - } else if (line === '' && lines[i + 1]) { - if (lines[i + 1].startsWith('> ')) { - sections.push(current_section.trim()); - current_section = ''; - } else { - details = lines.slice(i + 1).join('\n'); - break; - } - } - } - - if (current_section.length > 0) { - sections.push(current_section.trim()); + while (!sections[sections.length - 1].startsWith('> ')) { + details.unshift(/** @type {string} */ (sections.pop())); } if (sections.length === 0) { @@ -62,8 +44,8 @@ for (const category of fs.readdirSync('messages')) { seen.add(code); messages[category][code] = { - messages: sections, - details: details + messages: sections.map((section) => section.replace(/^> /gm, '').replace(/^>\n/gm, '\n')), + details: details.join('\n\n') }; } diff --git a/packages/svelte/src/internal/shared/warnings.js b/packages/svelte/src/internal/shared/warnings.js index b8093bbaa8..37269a674e 100644 --- a/packages/svelte/src/internal/shared/warnings.js +++ b/packages/svelte/src/internal/shared/warnings.js @@ -20,6 +20,7 @@ export function dynamic_void_element_content(tag) { /** * The following properties cannot be cloned with `$state.snapshot` — the return value contains the originals: + * * %properties% * @param {string | undefined | null} [properties] */ @@ -27,6 +28,7 @@ export function state_snapshot_uncloneable(properties) { if (DEV) { console.warn(`%c[svelte] state_snapshot_uncloneable\n%c${properties ? `The following properties cannot be cloned with \`$state.snapshot\` — the return value contains the originals: + ${properties}` : "Value cannot be cloned with `$state.snapshot` — the original value was returned"}`, bold, normal); } else {