diff --git a/.changeset/breezy-feet-knock.md b/.changeset/breezy-feet-knock.md new file mode 100644 index 000000000000..60e05c9e4ad3 --- /dev/null +++ b/.changeset/breezy-feet-knock.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +chore: provide links to documentation for errors/warnings diff --git a/packages/svelte/scripts/process-messages/index.js b/packages/svelte/scripts/process-messages/index.js index 3360b2480284..bbe257498ecd 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,12 @@ function transform(name, dest) { } if (message.type === 'TemplateLiteral') { - quasi.value.raw += message.quasis[0].value.raw + q.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/scripts/process-messages/templates/client-errors.js b/packages/svelte/scripts/process-messages/templates/client-errors.js index c63a22da96a4..c72e9f9d5e7a 100644 --- a/packages/svelte/scripts/process-messages/templates/client-errors.js +++ b/packages/svelte/scripts/process-messages/templates/client-errors.js @@ -7,11 +7,10 @@ import { DEV } from 'esm-env'; */ export function CODE(PARAMETER) { if (DEV) { - const error = new Error(`${'CODE'}\n${MESSAGE}`); + const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`); error.name = 'Svelte error'; throw error; } else { - // TODO print a link to the documentation - throw new Error('CODE'); + throw new Error(`https://svelte.dev/e/${'CODE'}`); } } diff --git a/packages/svelte/scripts/process-messages/templates/client-warnings.js b/packages/svelte/scripts/process-messages/templates/client-warnings.js index d40a59ec0c8d..8a9b87b76011 100644 --- a/packages/svelte/scripts/process-messages/templates/client-warnings.js +++ b/packages/svelte/scripts/process-messages/templates/client-warnings.js @@ -9,9 +9,12 @@ var normal = 'font-weight: normal'; */ export function CODE(PARAMETER) { if (DEV) { - console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal); + console.warn( + `%c[svelte] ${'CODE'}\n%c${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`, + bold, + normal + ); } else { - // TODO print a link to the documentation - console.warn('CODE'); + console.warn(`https://svelte.dev/e/${'CODE'}`); } } diff --git a/packages/svelte/scripts/process-messages/templates/compile-errors.js b/packages/svelte/scripts/process-messages/templates/compile-errors.js index 0dc30b2c01b3..445f5d14e627 100644 --- a/packages/svelte/scripts/process-messages/templates/compile-errors.js +++ b/packages/svelte/scripts/process-messages/templates/compile-errors.js @@ -56,5 +56,5 @@ function e(node, code, message) { * @returns {never} */ export function CODE(node, PARAMETER) { - e(node, 'CODE', MESSAGE); + e(node, 'CODE', `${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`); } diff --git a/packages/svelte/scripts/process-messages/templates/compile-warnings.js b/packages/svelte/scripts/process-messages/templates/compile-warnings.js index 8300d803d5d4..e0c970c66409 100644 --- a/packages/svelte/scripts/process-messages/templates/compile-warnings.js +++ b/packages/svelte/scripts/process-messages/templates/compile-warnings.js @@ -47,5 +47,5 @@ export const codes = CODES; * @param {string} PARAMETER */ export function CODE(node, PARAMETER) { - w(node, 'CODE', MESSAGE); + w(node, 'CODE', `${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`); } diff --git a/packages/svelte/scripts/process-messages/templates/server-errors.js b/packages/svelte/scripts/process-messages/templates/server-errors.js index 302b0941a1b7..6fb792456470 100644 --- a/packages/svelte/scripts/process-messages/templates/server-errors.js +++ b/packages/svelte/scripts/process-messages/templates/server-errors.js @@ -4,7 +4,7 @@ * @returns {never} */ export function CODE(PARAMETER) { - const error = new Error(`${'CODE'}\n${MESSAGE}`); + const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`); error.name = 'Svelte error'; throw error; } diff --git a/packages/svelte/scripts/process-messages/templates/shared-errors.js b/packages/svelte/scripts/process-messages/templates/shared-errors.js index c63a22da96a4..b90994fd96d8 100644 --- a/packages/svelte/scripts/process-messages/templates/shared-errors.js +++ b/packages/svelte/scripts/process-messages/templates/shared-errors.js @@ -7,11 +7,11 @@ import { DEV } from 'esm-env'; */ export function CODE(PARAMETER) { if (DEV) { - const error = new Error(`${'CODE'}\n${MESSAGE}`); + const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`); error.name = 'Svelte error'; throw error; } else { // TODO print a link to the documentation - throw new Error('CODE'); + throw new Error(`https://svelte.dev/e/${'CODE'}`); } } diff --git a/packages/svelte/scripts/process-messages/templates/shared-warnings.js b/packages/svelte/scripts/process-messages/templates/shared-warnings.js index d40a59ec0c8d..0814475a059d 100644 --- a/packages/svelte/scripts/process-messages/templates/shared-warnings.js +++ b/packages/svelte/scripts/process-messages/templates/shared-warnings.js @@ -9,9 +9,13 @@ var normal = 'font-weight: normal'; */ export function CODE(PARAMETER) { if (DEV) { - console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal); + console.warn( + `%c[svelte] ${'CODE'}\n%c${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`, + bold, + normal + ); } else { // TODO print a link to the documentation - console.warn('CODE'); + console.warn(`https://svelte.dev/e/${'CODE'}`); } } diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 1a4525ef5cb9..fd509eb3ab75 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -52,7 +52,7 @@ function e(node, code, message) { * @returns {never} */ export function options_invalid_value(node, details) { - e(node, "options_invalid_value", `Invalid compiler option: ${details}`); + e(node, "options_invalid_value", `Invalid compiler option: ${details}\nhttps://svelte.dev/e/options_invalid_value`); } /** @@ -62,7 +62,7 @@ export function options_invalid_value(node, details) { * @returns {never} */ export function options_removed(node, details) { - e(node, "options_removed", `Invalid compiler option: ${details}`); + e(node, "options_removed", `Invalid compiler option: ${details}\nhttps://svelte.dev/e/options_removed`); } /** @@ -72,7 +72,7 @@ export function options_removed(node, details) { * @returns {never} */ export function options_unrecognised(node, keypath) { - e(node, "options_unrecognised", `Unrecognised compiler option ${keypath}`); + e(node, "options_unrecognised", `Unrecognised compiler option ${keypath}\nhttps://svelte.dev/e/options_unrecognised`); } /** @@ -81,7 +81,7 @@ export function options_unrecognised(node, keypath) { * @returns {never} */ export function bindable_invalid_location(node) { - e(node, "bindable_invalid_location", "`$bindable()` can only be used inside a `$props()` declaration"); + e(node, "bindable_invalid_location", `\`$bindable()\` can only be used inside a \`$props()\` declaration\nhttps://svelte.dev/e/bindable_invalid_location`); } /** @@ -91,7 +91,7 @@ export function bindable_invalid_location(node) { * @returns {never} */ export function constant_assignment(node, thing) { - e(node, "constant_assignment", `Cannot assign to ${thing}`); + e(node, "constant_assignment", `Cannot assign to ${thing}\nhttps://svelte.dev/e/constant_assignment`); } /** @@ -101,7 +101,7 @@ export function constant_assignment(node, thing) { * @returns {never} */ export function constant_binding(node, thing) { - e(node, "constant_binding", `Cannot bind to ${thing}`); + e(node, "constant_binding", `Cannot bind to ${thing}\nhttps://svelte.dev/e/constant_binding`); } /** @@ -111,7 +111,7 @@ export function constant_binding(node, thing) { * @returns {never} */ export function declaration_duplicate(node, name) { - e(node, "declaration_duplicate", `\`${name}\` has already been declared`); + e(node, "declaration_duplicate", `\`${name}\` has already been declared\nhttps://svelte.dev/e/declaration_duplicate`); } /** @@ -120,7 +120,7 @@ export function declaration_duplicate(node, name) { * @returns {never} */ export function declaration_duplicate_module_import(node) { - e(node, "declaration_duplicate_module_import", "Cannot declare a variable with the same name as an import inside `