1
+ import { DEV } from 'esm-env' ;
1
2
import { subscribe_to_store } from '../../store/utils.js' ;
2
- import { EMPTY_FUNC } from '../common.js' ;
3
+ import { EMPTY_FUNC , run_all } from '../common.js' ;
3
4
import { unwrap } from './render.js' ;
4
5
import { is_array } from './utils.js' ;
5
6
@@ -21,7 +22,6 @@ const IS_EFFECT = EFFECT | PRE_EFFECT | RENDER_EFFECT | SYNC_EFFECT;
21
22
22
23
const FLUSH_MICROTASK = 0 ;
23
24
const FLUSH_SYNC = 1 ;
24
- const MAX_SAFE_INT = Number . MAX_SAFE_INTEGER ;
25
25
26
26
export const UNINITIALIZED = Symbol ( ) ;
27
27
@@ -457,8 +457,11 @@ function flush_queued_effects(effects) {
457
457
if ( length > 0 ) {
458
458
if ( flush_count > 100 ) {
459
459
throw new Error (
460
- 'Maximum update depth exceeded. This can happen when a reactive block or effect ' +
461
- 'repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops.'
460
+ 'ERR_SVELTE_TOO_MANY_UPDATES' +
461
+ ( DEV
462
+ ? ': Maximum update depth exceeded. This can happen when a reactive block or effect ' +
463
+ 'repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops.'
464
+ : '' )
462
465
) ;
463
466
}
464
467
flush_count ++ ;
@@ -524,9 +527,7 @@ function process_task() {
524
527
is_task_queued = false ;
525
528
const tasks = current_queued_tasks . slice ( ) ;
526
529
current_queued_tasks = [ ] ;
527
- for ( let i = 0 ; i < tasks . length ; i ++ ) {
528
- tasks [ i ] ( ) ;
529
- }
530
+ run_all ( tasks ) ;
530
531
}
531
532
532
533
/**
@@ -968,9 +969,12 @@ export function set_signal_value(signal, value) {
968
969
( current_consumer . f & DERIVED ) !== 0
969
970
) {
970
971
throw new Error (
971
- "Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. " +
972
- 'This can lead to unexpected errors and possibly cause infinite loops.\n\nIf this mutation is not meant ' +
973
- 'to be reactive do not use the "$state" rune for that declaration.'
972
+ 'ERR_SVELTE_UNSAFE_MUTATION' +
973
+ ( DEV
974
+ ? ": Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. " +
975
+ 'This can lead to unexpected errors and possibly cause infinite loops.\n\nIf this mutation is not meant ' +
976
+ 'to be reactive do not use the "$state" rune for that declaration.'
977
+ : '' )
974
978
) ;
975
979
}
976
980
if (
@@ -1005,10 +1009,10 @@ export function set_signal_value(signal, value) {
1005
1009
if ( current_effect === null && current_queued_pre_and_render_effects . length === 0 ) {
1006
1010
const update_callbacks = component_context ?. u ;
1007
1011
if ( update_callbacks != null ) {
1008
- update_callbacks . b . forEach ( /** @param { any } c */ ( c ) => c ( ) ) ;
1012
+ run_all ( update_callbacks . b ) ;
1009
1013
const managed = managed_effect ( ( ) => {
1010
1014
destroy_signal ( managed ) ;
1011
- update_callbacks . a . forEach ( /** @param { any } c */ ( c ) => c ( ) ) ;
1015
+ run_all ( update_callbacks . a ) ;
1012
1016
} ) ;
1013
1017
}
1014
1018
}
@@ -1026,21 +1030,20 @@ export function destroy_signal(signal) {
1026
1030
const flags = signal . f ;
1027
1031
destroy_references ( signal ) ;
1028
1032
remove_consumer ( signal , 0 , true ) ;
1029
- signal . i = null ;
1030
- signal . r = null ;
1031
- signal . y = null ;
1032
- signal . x = null ;
1033
- signal . b = null ;
1034
- signal . v = /** @type {V } */ ( null ) ;
1035
- signal . d = null ;
1036
- signal . c = null ;
1033
+ signal . i =
1034
+ signal . r =
1035
+ signal . y =
1036
+ signal . x =
1037
+ signal . b =
1038
+ // @ts -expect-error - this is fine, since we're assigning to null to clear out a destroyed signal
1039
+ signal . v =
1040
+ signal . d =
1041
+ signal . c =
1042
+ null ;
1037
1043
set_signal_status ( signal , DESTROYED ) ;
1038
1044
if ( destroy !== null ) {
1039
1045
if ( is_array ( destroy ) ) {
1040
- let i ;
1041
- for ( i = 0 ; i < destroy . length ; i ++ ) {
1042
- destroy [ i ] ( ) ;
1043
- }
1046
+ run_all ( destroy ) ;
1044
1047
} else {
1045
1048
destroy ( ) ;
1046
1049
}
@@ -1146,7 +1149,10 @@ function internal_create_effect(type, init, sync, block, schedule) {
1146
1149
*/
1147
1150
export function user_effect ( init ) {
1148
1151
if ( current_effect === null ) {
1149
- throw new Error ( 'The Svelte $effect rune can only be used during component initialisation.' ) ;
1152
+ throw new Error (
1153
+ 'ERR_SVELTE_ORPHAN_EFFECT' +
1154
+ ( DEV ? ': The Svelte $effect rune can only be used during component initialisation.' : '' )
1155
+ ) ;
1150
1156
}
1151
1157
const apply_component_effect_heuristics =
1152
1158
current_effect . f & RENDER_EFFECT &&
@@ -1203,7 +1209,10 @@ export function managed_pre_effect(init, sync) {
1203
1209
export function pre_effect ( init ) {
1204
1210
if ( current_effect === null ) {
1205
1211
throw new Error (
1206
- 'The Svelte $effect.pre rune can only be used during component initialisation.'
1212
+ 'ERR_SVELTE_ORPHAN_EFFECT' +
1213
+ ( DEV
1214
+ ? ': The Svelte $effect.pre rune can only be used during component initialisation.'
1215
+ : '' )
1207
1216
) ;
1208
1217
}
1209
1218
const sync = current_effect !== null && ( current_effect . f & RENDER_EFFECT ) !== 0 ;
@@ -1273,24 +1282,15 @@ export function push_destroy_fn(signal, destroy_fn) {
1273
1282
}
1274
1283
}
1275
1284
1285
+ const STATUS_MASK = ~ ( DIRTY | MAYBE_DIRTY | CLEAN ) ;
1276
1286
/**
1277
1287
* @template V
1278
1288
* @param {import('./types.js').Signal<V> } signal
1279
1289
* @param {number } status
1280
1290
* @returns {void }
1281
1291
*/
1282
1292
export function set_signal_status ( signal , status ) {
1283
- const flags = signal . f ;
1284
- if ( ( flags & status ) === 0 ) {
1285
- if ( ( flags & MAYBE_DIRTY ) !== 0 ) {
1286
- signal . f ^= MAYBE_DIRTY ;
1287
- } else if ( ( flags & CLEAN ) !== 0 ) {
1288
- signal . f ^= CLEAN ;
1289
- } else if ( ( flags & DIRTY ) !== 0 ) {
1290
- signal . f ^= DIRTY ;
1291
- }
1292
- signal . f ^= status ;
1293
- }
1293
+ signal . f = ( signal . f & STATUS_MASK ) | status ;
1294
1294
}
1295
1295
1296
1296
/**
@@ -1484,7 +1484,10 @@ export function safe_equal(a, b) {
1484
1484
export function get_or_init_context_map ( ) {
1485
1485
const component_context = current_component_context ;
1486
1486
if ( component_context === null ) {
1487
- throw new Error ( 'Context can only be used during component initialisation.' ) ;
1487
+ throw new Error (
1488
+ 'ERR_SVELTE_ORPHAN_CONTEXT' +
1489
+ ( DEV ? 'Context can only be used during component initialisation.' : '' )
1490
+ ) ;
1488
1491
}
1489
1492
let context_map = component_context . c ;
1490
1493
if ( context_map === null ) {
0 commit comments