From d124a931b6063d0c25707e6163590ec0f5e73d29 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 9 Dec 2024 14:54:12 +0100 Subject: [PATCH 1/7] chore: provide links to documentation for errors/warnings closes #11305 --- .../svelte/scripts/process-messages/index.js | 3 +- .../templates/client-errors.js | 7 +- .../templates/client-warnings.js | 9 +- .../templates/compile-errors.js | 2 +- .../templates/compile-warnings.js | 2 +- .../templates/server-errors.js | 4 +- .../templates/shared-errors.js | 6 +- .../templates/shared-warnings.js | 8 +- packages/svelte/src/compiler/errors.js | 324 +++++++++--------- packages/svelte/src/compiler/warnings.js | 156 ++++----- packages/svelte/src/internal/client/errors.js | 105 +++--- .../svelte/src/internal/client/warnings.js | 70 ++-- packages/svelte/src/internal/server/errors.js | 2 +- packages/svelte/src/internal/shared/errors.js | 16 +- .../svelte/src/internal/shared/warnings.js | 8 +- 15 files changed, 350 insertions(+), 372 deletions(-) diff --git a/packages/svelte/scripts/process-messages/index.js b/packages/svelte/scripts/process-messages/index.js index 3360b2480284..c71e4cfda28b 100644 --- a/packages/svelte/scripts/process-messages/index.js +++ b/packages/svelte/scripts/process-messages/index.js @@ -355,10 +355,11 @@ function transform(name, dest) { } if (message.type === 'TemplateLiteral') { - quasi.value.raw += message.quasis[0].value.raw + q.value.raw; + 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]; + 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..36ae416d42da 100644 --- a/packages/svelte/scripts/process-messages/templates/client-errors.js +++ b/packages/svelte/scripts/process-messages/templates/client-errors.js @@ -7,11 +7,12 @@ 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}\nSee https://svelte.dev/e/${'CODE'} for more info` + ); 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..194c6e673e03 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}\nSee https://svelte.dev/e/${'CODE'} for more info`, + 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..4625562e9c8e 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}\nSee https://svelte.dev/e/${'CODE'} for more info`); } diff --git a/packages/svelte/scripts/process-messages/templates/compile-warnings.js b/packages/svelte/scripts/process-messages/templates/compile-warnings.js index 8300d803d5d4..7cffc8a82b57 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}\nSee https://svelte.dev/e/${'CODE'} for more info`); } diff --git a/packages/svelte/scripts/process-messages/templates/server-errors.js b/packages/svelte/scripts/process-messages/templates/server-errors.js index 302b0941a1b7..d40e7fbaf716 100644 --- a/packages/svelte/scripts/process-messages/templates/server-errors.js +++ b/packages/svelte/scripts/process-messages/templates/server-errors.js @@ -4,7 +4,9 @@ * @returns {never} */ export function CODE(PARAMETER) { - const error = new Error(`${'CODE'}\n${MESSAGE}`); + const error = new Error( + `${'CODE'}\n${MESSAGE}\nSee https://svelte.dev/e/${'CODE'} for more info` + ); 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..11f6ad583785 100644 --- a/packages/svelte/scripts/process-messages/templates/shared-errors.js +++ b/packages/svelte/scripts/process-messages/templates/shared-errors.js @@ -7,11 +7,13 @@ 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}\nSee https://svelte.dev/e/${'CODE'} for more info` + ); 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..3f79a7211e27 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}\nSee https://svelte.dev/e/${'CODE'} for more info`, + 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..1763678c675b 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}\nSee https://svelte.dev/e/options_invalid_value for more info`); } /** @@ -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}\nSee https://svelte.dev/e/options_removed for more info`); } /** @@ -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}\nSee https://svelte.dev/e/options_unrecognised for more info`); } /** @@ -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\nSee https://svelte.dev/e/bindable_invalid_location for more info`); } /** @@ -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}\nSee https://svelte.dev/e/constant_assignment for more info`); } /** @@ -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}\nSee https://svelte.dev/e/constant_binding for more info`); } /** @@ -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\nSee https://svelte.dev/e/declaration_duplicate for more info`); } /** @@ -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 `