Skip to content

Commit cfc1fb7

Browse files
authored
chore: provide links to documentation for errors/warnings (#14629)
* 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
1 parent 3dcd5a4 commit cfc1fb7

File tree

25 files changed

+417
-389
lines changed

25 files changed

+417
-389
lines changed

.changeset/breezy-feet-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: provide links to documentation for errors/warnings

packages/svelte/scripts/process-messages/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ function transform(name, dest) {
339339
};
340340

341341
for (let i = 0; i < node.expressions.length; i += 1) {
342-
const q = node.quasis[i + 1];
342+
const q = structuredClone(node.quasis[i + 1]);
343343
const e = node.expressions[i];
344344

345345
if (e.type === 'Literal' && e.value === 'CODE') {
@@ -355,10 +355,12 @@ function transform(name, dest) {
355355
}
356356

357357
if (message.type === 'TemplateLiteral') {
358-
quasi.value.raw += message.quasis[0].value.raw + q.value.raw;
359-
out.quasis.push(...message.quasis.slice(1));
360-
out.expressions.push(...message.expressions);
361-
quasi = message.quasis[message.quasis.length - 1];
358+
const m = structuredClone(message);
359+
quasi.value.raw += m.quasis[0].value.raw;
360+
out.quasis.push(...m.quasis.slice(1));
361+
out.expressions.push(...m.expressions);
362+
quasi = m.quasis[m.quasis.length - 1];
363+
quasi.value.raw += q.value.raw;
362364
continue;
363365
}
364366
}

packages/svelte/scripts/process-messages/templates/client-errors.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { DEV } from 'esm-env';
77
*/
88
export function CODE(PARAMETER) {
99
if (DEV) {
10-
const error = new Error(`${'CODE'}\n${MESSAGE}`);
10+
const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
1111
error.name = 'Svelte error';
1212
throw error;
1313
} else {
14-
// TODO print a link to the documentation
15-
throw new Error('CODE');
14+
throw new Error(`https://svelte.dev/e/${'CODE'}`);
1615
}
1716
}

packages/svelte/scripts/process-messages/templates/client-warnings.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ var normal = 'font-weight: normal';
99
*/
1010
export function CODE(PARAMETER) {
1111
if (DEV) {
12-
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
12+
console.warn(
13+
`%c[svelte] ${'CODE'}\n%c${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`,
14+
bold,
15+
normal
16+
);
1317
} else {
14-
// TODO print a link to the documentation
15-
console.warn('CODE');
18+
console.warn(`https://svelte.dev/e/${'CODE'}`);
1619
}
1720
}

packages/svelte/scripts/process-messages/templates/compile-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ function e(node, code, message) {
5656
* @returns {never}
5757
*/
5858
export function CODE(node, PARAMETER) {
59-
e(node, 'CODE', MESSAGE);
59+
e(node, 'CODE', `${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
6060
}

packages/svelte/scripts/process-messages/templates/compile-warnings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ export const codes = CODES;
4747
* @param {string} PARAMETER
4848
*/
4949
export function CODE(node, PARAMETER) {
50-
w(node, 'CODE', MESSAGE);
50+
w(node, 'CODE', `${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
5151
}

packages/svelte/scripts/process-messages/templates/server-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @returns {never}
55
*/
66
export function CODE(PARAMETER) {
7-
const error = new Error(`${'CODE'}\n${MESSAGE}`);
7+
const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
88
error.name = 'Svelte error';
99
throw error;
1010
}

packages/svelte/scripts/process-messages/templates/shared-errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { DEV } from 'esm-env';
77
*/
88
export function CODE(PARAMETER) {
99
if (DEV) {
10-
const error = new Error(`${'CODE'}\n${MESSAGE}`);
10+
const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
1111
error.name = 'Svelte error';
1212
throw error;
1313
} else {
1414
// TODO print a link to the documentation
15-
throw new Error('CODE');
15+
throw new Error(`https://svelte.dev/e/${'CODE'}`);
1616
}
1717
}

packages/svelte/scripts/process-messages/templates/shared-warnings.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ var normal = 'font-weight: normal';
99
*/
1010
export function CODE(PARAMETER) {
1111
if (DEV) {
12-
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
12+
console.warn(
13+
`%c[svelte] ${'CODE'}\n%c${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`,
14+
bold,
15+
normal
16+
);
1317
} else {
1418
// TODO print a link to the documentation
15-
console.warn('CODE');
19+
console.warn(`https://svelte.dev/e/${'CODE'}`);
1620
}
1721
}

0 commit comments

Comments
 (0)