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/templates/client-errors.js b/packages/svelte/scripts/process-messages/templates/client-errors.js index c63a22da96a4..6d2ad1f18244 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'} (https://svelte.dev/e/${'CODE'})\n${MESSAGE}`); error.name = 'Svelte error'; throw error; } else { - // TODO print a link to the documentation - throw new Error('CODE'); + throw new Error(`${'CODE'} (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..3b6f22b55fb2 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'} (https://svelte.dev/e/${'CODE'})\n%c${MESSAGE}`, + bold, + normal + ); } else { - // TODO print a link to the documentation - console.warn('CODE'); + console.warn(`${'CODE'} (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..d13739bf9cbd 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'} (https://svelte.dev/e/${'CODE'})`, MESSAGE); } diff --git a/packages/svelte/scripts/process-messages/templates/compile-warnings.js b/packages/svelte/scripts/process-messages/templates/compile-warnings.js index 8300d803d5d4..fbf1d834e13b 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'} (https://svelte.dev/e/${'CODE'})`, MESSAGE); } diff --git a/packages/svelte/scripts/process-messages/templates/server-errors.js b/packages/svelte/scripts/process-messages/templates/server-errors.js index 302b0941a1b7..d25eb97c7ce9 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'} (https://svelte.dev/e/${'CODE'})\n${MESSAGE}`); 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..1adc01a8ccbb 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'} (https://svelte.dev/e/${'CODE'})\n${MESSAGE}`); error.name = 'Svelte error'; throw error; } else { // TODO print a link to the documentation - throw new Error('CODE'); + throw new Error(`${'CODE'} (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..ddbe3efa854c 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'} (https://svelte.dev/e/${'CODE'})\n%c${MESSAGE}`, + bold, + normal + ); } else { // TODO print a link to the documentation - console.warn('CODE'); + console.warn(`${'CODE'} (https://svelte.dev/e/${'CODE'})`); } } diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 1a4525ef5cb9..0012c3b786fe 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 (https://svelte.dev/e/options_invalid_value)`, `Invalid compiler option: ${details}`); } /** @@ -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 (https://svelte.dev/e/options_removed)`, `Invalid compiler option: ${details}`); } /** @@ -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 (https://svelte.dev/e/options_unrecognised)`, `Unrecognised compiler option ${keypath}`); } /** @@ -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 (https://svelte.dev/e/bindable_invalid_location)`, "`$bindable()` can only be used inside a `$props()` declaration"); } /** @@ -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 (https://svelte.dev/e/constant_assignment)`, `Cannot assign to ${thing}`); } /** @@ -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 (https://svelte.dev/e/constant_binding)`, `Cannot bind to ${thing}`); } /** @@ -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 (https://svelte.dev/e/declaration_duplicate)`, `\`${name}\` has already been declared`); } /** @@ -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 `