Skip to content

Commit 94b4268

Browse files
authored
chore: markdown runtime errors/warnings (#11304)
* chore: markdown runtime warnings * on second thoughts * start adding errors too * lint * centralise
1 parent 8808860 commit 94b4268

File tree

27 files changed

+243
-45
lines changed

27 files changed

+243
-45
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ packages/**/config/*.js
55
packages/svelte/messages/**/*.md
66
packages/svelte/src/compiler/errors.js
77
packages/svelte/src/compiler/warnings.js
8+
packages/svelte/src/internal/client/errors.js
9+
packages/svelte/src/internal/client/warnings.js
10+
packages/svelte/src/internal/shared/warnings.js
811
packages/svelte/tests/**/*.svelte
912
packages/svelte/tests/**/_expected*
1013
packages/svelte/tests/**/_actual*

eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export default [
3535
'**/tests',
3636
'packages/svelte/scripts/process-messages/templates/*.js',
3737
'packages/svelte/src/compiler/errors.js',
38+
'packages/svelte/src/internal/client/errors.js',
39+
'packages/svelte/src/internal/client/warnings.js',
40+
'packages/svelte/src/internal/shared/warnings.js',
3841
'packages/svelte/compiler/index.js',
3942
// documentation can contain invalid examples
4043
'documentation',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## effect_update_depth_exceeded
2+
3+
Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## lifecycle_outside_component
2+
3+
`%name%(...)` can only be used during component initialisation
4+
5+
## lifecycle_legacy_only
6+
7+
`%name%(...)` cannot be used in runes mode
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## lifecycle_double_unmount
2+
3+
Tried to unmount a component that was not mounted
4+
5+
## ownership_invalid_binding
6+
7+
%parent% passed a value to %child% with `bind:`, but the value is owned by %owner%. Consider creating a binding between %owner% and %parent%
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## dynamic_void_element_content
2+
3+
`<svelte:element this="%tag%">` is a void element — it cannot have content

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,7 @@ function transform(name, dest) {
220220

221221
transform('compile-errors', 'src/compiler/errors.js');
222222
transform('compile-warnings', 'src/compiler/warnings.js');
223+
224+
transform('client-warnings', 'src/internal/client/warnings.js');
225+
transform('client-errors', 'src/internal/client/errors.js');
226+
transform('shared-warnings', 'src/internal/shared/warnings.js');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { DEV } from 'esm-env';
2+
3+
/**
4+
* MESSAGE
5+
* @param {string} PARAMETER
6+
* @returns {never}
7+
*/
8+
export function CODE(PARAMETER) {
9+
if (DEV) {
10+
const error = new Error(`${'CODE'}\n${MESSAGE}`);
11+
error.name = 'Svelte error';
12+
throw error;
13+
} else {
14+
// TODO print a link to the documentation
15+
throw new Error('CODE');
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { DEV } from 'esm-env';
2+
3+
var bold = 'font-weight: bold';
4+
var normal = 'font-weight: normal';
5+
6+
/**
7+
* MESSAGE
8+
* @param {string} PARAMETER
9+
*/
10+
export function CODE(PARAMETER) {
11+
if (DEV) {
12+
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
13+
} else {
14+
// TODO print a link to the documentation
15+
console.warn('CODE');
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DEV } from 'esm-env';
2+
3+
var bold = 'font-weight: bold';
4+
var normal = 'font-weight: normal';
5+
6+
/**
7+
* MESSAGE
8+
* @param {boolean} trace
9+
* @param {string} PARAMETER
10+
*/
11+
export function CODE(trace, PARAMETER) {
12+
if (DEV) {
13+
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
14+
if (trace) console.trace('stack trace');
15+
} else {
16+
// TODO print a link to the documentation
17+
console.warn('CODE');
18+
}
19+
}

0 commit comments

Comments
 (0)