New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

svelte

Package Overview
Dependencies
Maintainers
3
Versions
841
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte - npm Package Compare versions

Comparing version 5.19.4 to 5.19.5

src/internal/client/context.js

2

package.json

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "5.19.4",
"version": "5.19.5",
"type": "module",

@@ -8,0 +8,0 @@ "types": "./types/index.d.ts",

@@ -641,6 +641,7 @@ /** @import * as Compiler from '#compiler' */

// ...then walk them, starting from the node after the one
// containing the element in question
// ...then walk them, starting from the node containing the element in question
// skipping nodes that appears before the element
const seen = new Set();
let skip = true;

@@ -651,6 +652,16 @@ /** @param {Compiler.AST.SvelteNode} node */

RegularElement(node) {
siblings.push(node);
if (node === element) {
skip = false;
if (include_self) siblings.push(node);
} else if (!skip) {
siblings.push(node);
}
},
SvelteElement(node) {
siblings.push(node);
if (node === element) {
skip = false;
if (include_self) siblings.push(node);
} else if (!skip) {
siblings.push(node);
}
},

@@ -668,10 +679,6 @@ RenderTag(node) {

for (const node of nodes.slice(nodes.indexOf(start) + 1)) {
for (const node of nodes.slice(nodes.indexOf(start))) {
get_siblings(node);
}
if (include_self) {
siblings.push(element);
}
return siblings;

@@ -678,0 +685,0 @@ }

/** @import { ComponentContext, ComponentContextLegacy } from '#client' */
/** @import { EventDispatcher } from './index.js' */
/** @import { NotFunction } from './internal/types.js' */
import { component_context, flush_sync, untrack } from './internal/client/runtime.js';
import { flush_sync, untrack } from './internal/client/runtime.js';
import { is_array } from './internal/shared/utils.js';

@@ -10,2 +10,3 @@ import { user_effect } from './internal/client/index.js';

import { legacy_mode_flag } from './internal/flags/index.js';
import { component_context } from './internal/client/context.js';

@@ -183,13 +184,5 @@ /**

export { getContext, getAllContexts, hasContext, setContext } from './internal/client/context.js';
export { hydrate, mount, unmount } from './internal/client/render.js';
export {
getContext,
getAllContexts,
hasContext,
setContext,
tick,
untrack
} from './internal/client/runtime.js';
export { tick, untrack } from './internal/client/runtime.js';
export { createRawSnippet } from './internal/client/dom/blocks/snippet.js';
import * as e from '../errors.js';
import { component_context } from '../runtime.js';
import { component_context } from '../context.js';
import { FILENAME } from '../../../constants.js';

@@ -4,0 +4,0 @@ import { get_component } from './ownership.js';

@@ -6,3 +6,3 @@ /** @import { ProxyMetadata } from '#client' */

import { render_effect, user_pre_effect } from '../reactivity/effects.js';
import { dev_current_component_function } from '../runtime.js';
import { dev_current_component_function } from '../context.js';
import { get_prototype_of } from '../../shared/utils.js';

@@ -9,0 +9,0 @@ import * as w from '../warnings.js';

@@ -6,14 +6,11 @@ /** @import { Effect, Source, TemplateNode } from '#client' */

import { internal_set, mutable_source, source } from '../../reactivity/sources.js';
import { flush_sync, is_runes, set_active_effect, set_active_reaction } from '../../runtime.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
import { queue_micro_task } from '../task.js';
import { UNINITIALIZED } from '../../../../constants.js';
import {
component_context,
flush_sync,
is_runes,
set_active_effect,
set_active_reaction,
set_component_context,
set_dev_current_component_function
} from '../../runtime.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
import { queue_micro_task } from '../task.js';
import { UNINITIALIZED } from '../../../../constants.js';
} from '../../context.js';

@@ -20,0 +17,0 @@ const PENDING = 0;

/** @import { Effect, TemplateNode, } from '#client' */
import { BOUNDARY_EFFECT, EFFECT_TRANSPARENT } from '../../constants.js';
import { component_context, set_component_context } from '../../context.js';
import { block, branch, destroy_effect, pause_effect } from '../../reactivity/effects.js';

@@ -8,7 +9,5 @@ import {

active_reaction,
component_context,
handle_error,
set_active_effect,
set_active_reaction,
set_component_context,
reset_is_throwing_error

@@ -15,0 +14,0 @@ } from '../../runtime.js';

@@ -10,3 +10,3 @@ /** @import { Effect, TemplateNode } from '#client' */

import { DEV } from 'esm-env';
import { dev_current_component_function } from '../../runtime.js';
import { dev_current_component_function } from '../../context.js';
import { get_first_child, get_next_sibling } from '../operations.js';

@@ -13,0 +13,0 @@

@@ -9,3 +9,3 @@ /** @import { Snippet } from 'svelte' */

set_dev_current_component_function
} from '../../runtime.js';
} from '../../context.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';

@@ -12,0 +12,0 @@ import { create_fragment_from_html } from '../reconciler.js';

@@ -20,3 +20,4 @@ /** @import { Effect, TemplateNode } from '#client' */

import { current_each_item, set_current_each_item } from './each.js';
import { component_context, active_effect } from '../../runtime.js';
import { active_effect } from '../../runtime.js';
import { component_context } from '../../context.js';
import { DEV } from 'esm-env';

@@ -23,0 +24,0 @@ import { EFFECT_TRANSPARENT } from '../../constants.js';

/** @import { ComponentContextLegacy } from '#client' */
import { run, run_all } from '../../../shared/utils.js';
import { component_context } from '../../context.js';
import { derived } from '../../reactivity/deriveds.js';
import { user_pre_effect, user_effect } from '../../reactivity/effects.js';
import { component_context, deep_read_state, get, untrack } from '../../runtime.js';
import { deep_read_state, get, untrack } from '../../runtime.js';

@@ -7,0 +8,0 @@ /**

export { FILENAME, HMR, NAMESPACE_SVG } from '../../constants.js';
export { push, pop } from './context.js';
export { assign, assign_and, assign_or, assign_nullish } from './dev/assign.js';

@@ -144,10 +145,4 @@ export { cleanup_styles } from './dev/css.js';

exclude_from_object,
pop,
push,
deep_read,
deep_read_state,
getAllContexts,
getContext,
setContext,
hasContext
deep_read_state
} from './runtime.js';

@@ -154,0 +149,0 @@ export { validate_binding, validate_each_keys } from './validate.js';

@@ -1,4 +0,5 @@

/** @import { ProxyMetadata, ProxyStateObject, Source } from '#client' */
/** @import { ProxyMetadata, Source } from '#client' */
import { DEV } from 'esm-env';
import { get, component_context, active_effect } from './runtime.js';
import { get, active_effect } from './runtime.js';
import { component_context } from './context.js';
import {

@@ -5,0 +6,0 @@ array_prototype,

@@ -20,4 +20,3 @@ /** @import { Derived, Effect } from '#client' */

increment_write_version,
set_active_effect,
component_context
set_active_effect
} from '../runtime.js';

@@ -30,2 +29,3 @@ import { equals, safe_equals } from './equality.js';

import { tracing_mode_flag } from '../../flags/index.js';
import { component_context } from '../context.js';

@@ -40,4 +40,8 @@ /**

var flags = DERIVED | DIRTY;
var parent_derived =
active_reaction !== null && (active_reaction.f & DERIVED) !== 0
? /** @type {Derived} */ (active_reaction)
: null;
if (active_effect === null) {
if (active_effect === null || (parent_derived !== null && (parent_derived.f & UNOWNED) !== 0)) {
flags |= UNOWNED;

@@ -50,12 +54,7 @@ } else {

var parent_derived =
active_reaction !== null && (active_reaction.f & DERIVED) !== 0
? /** @type {Derived} */ (active_reaction)
: null;
/** @type {Derived<V>} */
const signal = {
children: null,
ctx: component_context,
deps: null,
effects: null,
equals,

@@ -94,15 +93,10 @@ f: flags,

*/
function destroy_derived_children(derived) {
var children = derived.children;
export function destroy_derived_effects(derived) {
var effects = derived.effects;
if (children !== null) {
derived.children = null;
if (effects !== null) {
derived.effects = null;
for (var i = 0; i < children.length; i += 1) {
var child = children[i];
if ((child.f & DERIVED) !== 0) {
destroy_derived(/** @type {Derived} */ (child));
} else {
destroy_effect(/** @type {Effect} */ (child));
}
for (var i = 0; i < effects.length; i += 1) {
destroy_effect(/** @type {Effect} */ (effects[i]));
}

@@ -155,3 +149,3 @@ }

destroy_derived_children(derived);
destroy_derived_effects(derived);
value = update_reaction(derived);

@@ -165,3 +159,3 @@ } finally {

try {
destroy_derived_children(derived);
destroy_derived_effects(derived);
value = update_reaction(derived);

@@ -198,7 +192,7 @@ } finally {

export function destroy_derived(derived) {
destroy_derived_children(derived);
destroy_derived_effects(derived);
remove_reactions(derived, 0);
set_signal_status(derived, DESTROYED);
derived.v = derived.children = derived.deps = derived.ctx = derived.reactions = null;
derived.v = derived.deps = derived.ctx = derived.reactions = null;
}
/** @import { ComponentContext, ComponentContextLegacy, Derived, Effect, TemplateNode, TransitionManager } from '#client' */
import {
check_dirtiness,
component_context,
active_effect,
active_reaction,
dev_current_component_function,
update_effect,

@@ -48,2 +46,3 @@ get,

import { derived, destroy_derived } from './deriveds.js';
import { component_context, dev_current_component_function } from '../context.js';

@@ -58,3 +57,3 @@ /**

if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0) {
if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0 && active_effect === null) {
e.effect_in_unowned_derived();

@@ -105,3 +104,2 @@ }

deps: null,
deriveds: null,
nodes_start: null,

@@ -160,3 +158,3 @@ nodes_end: null,

var derived = /** @type {Derived} */ (active_reaction);
(derived.children ??= []).push(effect);
(derived.effects ??= []).push(effect);
}

@@ -405,18 +403,2 @@ }

* @param {Effect} signal
* @returns {void}
*/
export function destroy_effect_deriveds(signal) {
var deriveds = signal.deriveds;
if (deriveds !== null) {
signal.deriveds = null;
for (var i = 0; i < deriveds.length; i += 1) {
destroy_derived(deriveds[i]);
}
}
}
/**
* @param {Effect} signal
* @param {boolean} remove_dom

@@ -477,3 +459,2 @@ * @returns {void}

destroy_effect_children(effect, remove_dom && !removed);
destroy_effect_deriveds(effect);
remove_reactions(effect, 0);

@@ -480,0 +461,0 @@ set_signal_status(effect, DESTROYED);

/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
import { DEV } from 'esm-env';
import {
component_context,
active_reaction,

@@ -38,2 +37,3 @@ active_effect,

import { get_stack } from '../dev/tracing.js';
import { component_context } from '../context.js';

@@ -40,0 +40,0 @@ export let inspect_effects = new Set();

@@ -39,4 +39,4 @@ import type { ComponentContext, Dom, Equals, TemplateNode, TransitionManager } from '#client';

fn: () => V;
/** Reactions created inside this signal */
children: null | Reaction[];
/** Effects created inside this signal */
effects: null | Effect[];
/** Parent effect or derived */

@@ -55,4 +55,2 @@ parent: Effect | Derived | null;

nodes_end: null | TemplateNode;
/** Reactions created inside this signal */
deriveds: null | Derived[];
/** The effect function */

@@ -59,0 +57,0 @@ fn: null | (() => void | (() => void));

@@ -12,3 +12,4 @@ /** @import { ComponentContext, Effect, TemplateNode } from '#client' */

import { HYDRATION_END, HYDRATION_ERROR, HYDRATION_START } from '../../constants.js';
import { push, pop, component_context, active_effect } from './runtime.js';
import { active_effect } from './runtime.js';
import { push, pop, component_context } from './context.js';
import { component_root, branch } from './reactivity/effects.js';

@@ -15,0 +16,0 @@ import {

@@ -7,4 +7,2 @@ /** @import { ComponentContext, Derived, Effect, Reaction, Signal, Source, Value } from '#client' */

destroy_effect_children,
destroy_effect_deriveds,
effect,
execute_effect_teardown,

@@ -32,10 +30,19 @@ unlink_effect

import { flush_tasks } from './dom/task.js';
import { add_owner } from './dev/ownership.js';
import { internal_set, set, source } from './reactivity/sources.js';
import { destroy_derived, execute_derived, update_derived } from './reactivity/deriveds.js';
import { internal_set, set } from './reactivity/sources.js';
import {
destroy_derived,
destroy_derived_effects,
execute_derived,
update_derived
} from './reactivity/deriveds.js';
import * as e from './errors.js';
import { lifecycle_outside_component } from '../shared/errors.js';
import { FILENAME } from '../../constants.js';
import { legacy_mode_flag, tracing_mode_flag } from '../flags/index.js';
import { tracing_expressions, get_stack } from './dev/tracing.js';
import {
component_context,
dev_current_component_function,
set_component_context,
set_dev_current_component_function
} from './context.js';

@@ -155,28 +162,2 @@ const FLUSH_MICROTASK = 0;

// Handling runtime component context
/** @type {ComponentContext | null} */
export let component_context = null;
/** @param {ComponentContext | null} context */
export function set_component_context(context) {
component_context = context;
}
/**
* The current component function. Different from current component context:
* ```html
* <!-- App.svelte -->
* <Foo>
* <Bar /> <!-- context == Foo.svelte, function == App.svelte -->
* </Foo>
* ```
* @type {ComponentContext['function']}
*/
export let dev_current_component_function = null;
/** @param {ComponentContext['function']} fn */
export function set_dev_current_component_function(fn) {
dev_current_component_function = fn;
}
export function increment_write_version() {

@@ -438,5 +419,14 @@ return ++write_version;

active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
skip_reaction = !is_flushing_effect && (flags & UNOWNED) !== 0;
// prettier-ignore
skip_reaction =
(flags & UNOWNED) !== 0 &&
(!is_flushing_effect ||
// If we were previously not in a reactive context and we're reading an unowned derived
// that was created inside another reaction, then we don't fully know the real owner and thus
// we need to skip adding any reactions for this unowned
((previous_reaction === null || previous_untracking) &&
/** @type {Derived} */ (reaction).parent !== null));
derived_sources = null;
component_context = reaction.ctx;
set_component_context(reaction.ctx);
untracking = false;

@@ -505,3 +495,3 @@ read_version++;

derived_sources = prev_derived_sources;
component_context = previous_component_context;
set_component_context(previous_component_context);
untracking = previous_untracking;

@@ -548,2 +538,4 @@ }

}
// Disconnect any reactions owned by this reaction
destroy_derived_effects(/** @type {Derived} **/ (dependency));
remove_reactions(/** @type {Derived} **/ (dependency), 0);

@@ -587,3 +579,3 @@ }

var previous_component_fn = dev_current_component_function;
dev_current_component_function = effect.component_function;
set_dev_current_component_function(effect.component_function);
}

@@ -597,3 +589,2 @@

}
destroy_effect_deriveds(effect);

@@ -631,3 +622,3 @@ execute_effect_teardown(effect);

if (DEV) {
dev_current_component_function = previous_component_fn;
set_dev_current_component_function(previous_component_fn);
}

@@ -969,8 +960,6 @@ }

}
}
if (
} else if (
is_derived &&
/** @type {Derived} */ (signal).deps === null &&
(active_reaction === null || untracking || (active_reaction.f & DERIVED) !== 0)
/** @type {Derived} */ (signal).effects === null
) {

@@ -981,15 +970,7 @@ var derived = /** @type {Derived} */ (signal);

if (parent !== null) {
// Attach the derived to the nearest parent effect or derived
if ((parent.f & DERIVED) !== 0) {
var parent_derived = /** @type {Derived} */ (parent);
if (!parent_derived.children?.includes(derived)) {
(parent_derived.children ??= []).push(derived);
}
} else {
var parent_effect = /** @type {Effect} */ (parent);
if (!parent_effect.deriveds?.includes(derived)) {
(parent_effect.deriveds ??= []).push(derived);
}
// If the derived is owned by another derived then mark it as unowned
// as the derived value might have been referenced in a different context
// since and thus its parent might not be its true owner anymore
if ((parent.f & UNOWNED) === 0) {
derived.f ^= UNOWNED;
}

@@ -1129,105 +1110,2 @@ }

/**
* Retrieves the context that belongs to the closest parent component with the specified `key`.
* Must be called during component initialisation.
*
* @template T
* @param {any} key
* @returns {T}
*/
export function getContext(key) {
const context_map = get_or_init_context_map('getContext');
const result = /** @type {T} */ (context_map.get(key));
if (DEV) {
const fn = /** @type {ComponentContext} */ (component_context).function;
if (fn) {
add_owner(result, fn, true);
}
}
return result;
}
/**
* Associates an arbitrary `context` object with the current component and the specified `key`
* and returns that object. The context is then available to children of the component
* (including slotted content) with `getContext`.
*
* Like lifecycle functions, this must be called during component initialisation.
*
* @template T
* @param {any} key
* @param {T} context
* @returns {T}
*/
export function setContext(key, context) {
const context_map = get_or_init_context_map('setContext');
context_map.set(key, context);
return context;
}
/**
* Checks whether a given `key` has been set in the context of a parent component.
* Must be called during component initialisation.
*
* @param {any} key
* @returns {boolean}
*/
export function hasContext(key) {
const context_map = get_or_init_context_map('hasContext');
return context_map.has(key);
}
/**
* Retrieves the whole context map that belongs to the closest parent component.
* Must be called during component initialisation. Useful, for example, if you
* programmatically create a component and want to pass the existing context to it.
*
* @template {Map<any, any>} [T=Map<any, any>]
* @returns {T}
*/
export function getAllContexts() {
const context_map = get_or_init_context_map('getAllContexts');
if (DEV) {
const fn = component_context?.function;
if (fn) {
for (const value of context_map.values()) {
add_owner(value, fn, true);
}
}
}
return /** @type {T} */ (context_map);
}
/**
* @param {string} name
* @returns {Map<unknown, unknown>}
*/
function get_or_init_context_map(name) {
if (component_context === null) {
lifecycle_outside_component(name);
}
return (component_context.c ??= new Map(get_parent_context(component_context) || undefined));
}
/**
* @param {ComponentContext} component_context
* @returns {Map<unknown, unknown> | null}
*/
function get_parent_context(component_context) {
let parent = component_context.p;
while (parent !== null) {
const context_map = parent.c;
if (context_map !== null) {
return context_map;
}
parent = parent.p;
}
return null;
}
/**
* @template {number | bigint} T

@@ -1280,74 +1158,2 @@ * @param {Value<T>} signal

/**
* @param {Record<string, unknown>} props
* @param {any} runes
* @param {Function} [fn]
* @returns {void}
*/
export function push(props, runes = false, fn) {
component_context = {
p: component_context,
c: null,
e: null,
m: false,
s: props,
x: null,
l: null
};
if (legacy_mode_flag && !runes) {
component_context.l = {
s: null,
u: null,
r1: [],
r2: source(false)
};
}
if (DEV) {
// component function
component_context.function = fn;
dev_current_component_function = fn;
}
}
/**
* @template {Record<string, any>} T
* @param {T} [component]
* @returns {T}
*/
export function pop(component) {
const context_stack_item = component_context;
if (context_stack_item !== null) {
if (component !== undefined) {
context_stack_item.x = component;
}
const component_effects = context_stack_item.e;
if (component_effects !== null) {
var previous_effect = active_effect;
var previous_reaction = active_reaction;
context_stack_item.e = null;
try {
for (var i = 0; i < component_effects.length; i++) {
var component_effect = component_effects[i];
set_active_effect(component_effect.effect);
set_active_reaction(component_effect.reaction);
effect(component_effect.fn);
}
} finally {
set_active_effect(previous_effect);
set_active_reaction(previous_reaction);
}
}
component_context = context_stack_item.p;
if (DEV) {
dev_current_component_function = context_stack_item.p?.function ?? null;
}
context_stack_item.m = true;
}
// Micro-optimization: Don't set .a above to the empty object
// so it can be garbage-collected when the return here is unused
return component || /** @type {T} */ ({});
}
/**
* Possibly traverse an object and read all its properties so that they're all reactive in case this is `$state`.

@@ -1354,0 +1160,0 @@ * Does only check first level of an object for performance reasons (heuristic should be good for 99% of all cases).

@@ -1,2 +0,2 @@

import { dev_current_component_function } from './runtime.js';
import { dev_current_component_function } from './context.js';
import { is_array } from '../shared/utils.js';

@@ -3,0 +3,0 @@ import * as e from './errors.js';

@@ -6,10 +6,3 @@ /** @import { ComponentConstructorOptions, ComponentType, SvelteComponent, Component } from 'svelte' */

import { hydrate, mount, unmount } from '../internal/client/render.js';
import {
active_effect,
component_context,
dev_current_component_function,
flush_sync,
get,
set_signal_status
} from '../internal/client/runtime.js';
import { active_effect, flush_sync, get, set_signal_status } from '../internal/client/runtime.js';
import { lifecycle_outside_component } from '../internal/shared/errors.js';

@@ -20,2 +13,3 @@ import { define_property, is_array } from '../internal/shared/utils.js';

import { FILENAME } from '../constants.js';
import { component_context, dev_current_component_function } from '../internal/client/context.js';

@@ -22,0 +16,0 @@ /**

@@ -7,3 +7,3 @@ // generated during release, do not modify

*/
export const VERSION = '5.19.4';
export const VERSION = '5.19.5';
export const PUBLIC_VERSION = '5';

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc