Skip to content

Commit

Permalink
chore: provide links to documentation for errors/warnings (#14629)
Browse files Browse the repository at this point in the history
* chore: provide links to documentation for errors/warnings

closes #11305

* changeset

* fix most of the tests

* fix mutations messing with nodes between runs

* more concise

* more test fixes

* last one
  • Loading branch information
dummdidumm authored Dec 9, 2024
1 parent 3dcd5a4 commit cfc1fb7
Show file tree
Hide file tree
Showing 25 changed files with 417 additions and 389 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-feet-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: provide links to documentation for errors/warnings
12 changes: 7 additions & 5 deletions packages/svelte/scripts/process-messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`);
}
}
Loading

0 comments on commit cfc1fb7

Please sign in to comment.