Comparing version 5.0.0-next.247 to 5.0.0-next.248
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.0-next.247", | ||
"version": "5.0.0-next.248", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -57,6 +57,3 @@ import type { | ||
/** The HTML template string */ | ||
readonly template: { | ||
push_quasi: (q: string) => void; | ||
push_expression: (e: Expression) => void; | ||
}; | ||
readonly template: Array<string | Expression>; | ||
readonly locations: SourceLocation[]; | ||
@@ -63,0 +60,0 @@ readonly metadata: { |
@@ -12,3 +12,3 @@ /** @import { BlockStatement, Expression, Pattern, Statement } from 'estree' */ | ||
export function AwaitBlock(node, context) { | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
@@ -15,0 +15,0 @@ // Visit {#await <expression>} first to ensure that scopes are in the correct order |
@@ -39,9 +39,16 @@ /** @import { CallExpression, Expression, MemberExpression } from 'estree' */ | ||
const getter = b.thunk(/** @type {Expression} */ (context.visit(expression))); | ||
const get = b.thunk(/** @type {Expression} */ (context.visit(expression))); | ||
const setter = b.arrow( | ||
[b.id('$$value')], | ||
/** @type {Expression} */ (context.visit(b.assignment('=', expression, b.id('$$value')))) | ||
/** @type {Expression | undefined} */ | ||
let set = b.unthunk( | ||
b.arrow( | ||
[b.id('$$value')], | ||
/** @type {Expression} */ (context.visit(b.assignment('=', expression, b.id('$$value')))) | ||
) | ||
); | ||
if (get === set) { | ||
set = undefined; | ||
} | ||
/** @type {CallExpression} */ | ||
@@ -56,4 +63,4 @@ let call; | ||
context.state.node, | ||
setter, | ||
property.bidirectional && getter | ||
set ?? get, | ||
property.bidirectional && get | ||
); | ||
@@ -65,3 +72,3 @@ } else { | ||
case 'online': | ||
call = b.call(`$.bind_online`, setter); | ||
call = b.call(`$.bind_online`, set ?? get); | ||
break; | ||
@@ -74,4 +81,4 @@ | ||
b.literal(node.name === 'scrollX' ? 'x' : 'y'), | ||
getter, | ||
setter | ||
get, | ||
set | ||
); | ||
@@ -84,3 +91,3 @@ break; | ||
case 'outerHeight': | ||
call = b.call('$.bind_window_size', b.literal(node.name), setter); | ||
call = b.call('$.bind_window_size', b.literal(node.name), set ?? get); | ||
break; | ||
@@ -90,3 +97,3 @@ | ||
case 'activeElement': | ||
call = b.call('$.bind_active_element', setter); | ||
call = b.call('$.bind_active_element', set ?? get); | ||
break; | ||
@@ -96,33 +103,33 @@ | ||
case 'muted': | ||
call = b.call(`$.bind_muted`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_muted`, context.state.node, get, set); | ||
break; | ||
case 'paused': | ||
call = b.call(`$.bind_paused`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_paused`, context.state.node, get, set); | ||
break; | ||
case 'volume': | ||
call = b.call(`$.bind_volume`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_volume`, context.state.node, get, set); | ||
break; | ||
case 'playbackRate': | ||
call = b.call(`$.bind_playback_rate`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_playback_rate`, context.state.node, get, set); | ||
break; | ||
case 'currentTime': | ||
call = b.call(`$.bind_current_time`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_current_time`, context.state.node, get, set); | ||
break; | ||
case 'buffered': | ||
call = b.call(`$.bind_buffered`, context.state.node, setter); | ||
call = b.call(`$.bind_buffered`, context.state.node, set ?? get); | ||
break; | ||
case 'played': | ||
call = b.call(`$.bind_played`, context.state.node, setter); | ||
call = b.call(`$.bind_played`, context.state.node, set ?? get); | ||
break; | ||
case 'seekable': | ||
call = b.call(`$.bind_seekable`, context.state.node, setter); | ||
call = b.call(`$.bind_seekable`, context.state.node, set ?? get); | ||
break; | ||
case 'seeking': | ||
call = b.call(`$.bind_seeking`, context.state.node, setter); | ||
call = b.call(`$.bind_seeking`, context.state.node, set ?? get); | ||
break; | ||
case 'ended': | ||
call = b.call(`$.bind_ended`, context.state.node, setter); | ||
call = b.call(`$.bind_ended`, context.state.node, set ?? get); | ||
break; | ||
case 'readyState': | ||
call = b.call(`$.bind_ready_state`, context.state.node, setter); | ||
call = b.call(`$.bind_ready_state`, context.state.node, set ?? get); | ||
break; | ||
@@ -135,3 +142,8 @@ | ||
case 'devicePixelContentBoxSize': | ||
call = b.call('$.bind_resize_observer', context.state.node, b.literal(node.name), setter); | ||
call = b.call( | ||
'$.bind_resize_observer', | ||
context.state.node, | ||
b.literal(node.name), | ||
set ?? get | ||
); | ||
break; | ||
@@ -143,3 +155,3 @@ | ||
case 'offsetHeight': | ||
call = b.call('$.bind_element_size', context.state.node, b.literal(node.name), setter); | ||
call = b.call('$.bind_element_size', context.state.node, b.literal(node.name), set ?? get); | ||
break; | ||
@@ -150,5 +162,5 @@ | ||
if (parent?.type === 'RegularElement' && parent.name === 'select') { | ||
call = b.call(`$.bind_select_value`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_select_value`, context.state.node, get, set); | ||
} else { | ||
call = b.call(`$.bind_value`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_value`, context.state.node, get, set); | ||
} | ||
@@ -159,3 +171,3 @@ break; | ||
case 'files': | ||
call = b.call(`$.bind_files`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_files`, context.state.node, get, set); | ||
break; | ||
@@ -174,4 +186,4 @@ | ||
context.state.node, | ||
getter, | ||
setter | ||
get, | ||
set | ||
); | ||
@@ -182,7 +194,7 @@ break; | ||
case 'checked': | ||
call = b.call(`$.bind_checked`, context.state.node, getter, setter); | ||
call = b.call(`$.bind_checked`, context.state.node, get, set); | ||
break; | ||
case 'focused': | ||
call = b.call(`$.bind_focused`, context.state.node, setter); | ||
call = b.call(`$.bind_focused`, context.state.node, set ?? get); | ||
break; | ||
@@ -200,3 +212,3 @@ | ||
// so that when the value is updated, the group binding is updated | ||
let group_getter = getter; | ||
let group_getter = get; | ||
@@ -232,3 +244,3 @@ if (parent?.type === 'RegularElement') { | ||
group_getter, | ||
setter | ||
set ?? get | ||
); | ||
@@ -235,0 +247,0 @@ break; |
/** @import { CallExpression, Expression } from 'estree' */ | ||
/** @import { Context } from '../types' */ | ||
import { is_ignored } from '../../../../state.js'; | ||
import { dev, is_ignored } from '../../../../state.js'; | ||
import * as b from '../../../../utils/builders.js'; | ||
@@ -38,3 +38,26 @@ import { get_rune } from '../../../scope.js'; | ||
if ( | ||
dev && | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'console' && | ||
context.state.scope.get('console') === null && | ||
node.callee.property.type === 'Identifier' && | ||
['debug', 'dir', 'error', 'group', 'groupCollapsed', 'info', 'log', 'trace', 'warn'].includes( | ||
node.callee.property.name | ||
) | ||
) { | ||
return b.call( | ||
node.callee, | ||
b.spread( | ||
b.call( | ||
'$.log_if_contains_state', | ||
b.literal(node.callee.property.name), | ||
.../** @type {Expression[]} */ (node.arguments.map((arg) => context.visit(arg))) | ||
) | ||
) | ||
); | ||
} | ||
context.next(); | ||
} |
@@ -10,3 +10,3 @@ /** @import { AST } from '#compiler' */ | ||
// We'll only get here if comments are not filtered out, which they are unless preserveComments is true | ||
context.state.template.push_quasi(`<!--${node.data}-->`); | ||
context.state.template.push(`<!--${node.data}-->`); | ||
} |
@@ -35,3 +35,3 @@ /** @import { BlockStatement, Expression, Identifier, Pattern, Statement } from 'estree' */ | ||
if (!each_node_meta.is_controlled) { | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
} | ||
@@ -38,0 +38,0 @@ |
@@ -8,2 +8,3 @@ /** @import { Expression, Identifier, Statement } from 'estree' */ | ||
import * as b from '../../../../utils/builders.js'; | ||
import { sanitize_template_string } from '../../../../utils/sanitize_template_string.js'; | ||
import { clean_nodes, infer_namespace } from '../../utils.js'; | ||
@@ -61,7 +62,2 @@ import { process_children } from './shared/fragment.js'; | ||
/** @type {string[]} */ | ||
const quasi = []; | ||
/** @type {Expression[]} */ | ||
const expressions = []; | ||
/** @type {ComponentClientTransformState} */ | ||
@@ -74,18 +70,3 @@ const state = { | ||
after_update: [], | ||
template: { | ||
push_quasi: (/** @type {string} */ quasi_to_add) => { | ||
if (quasi.length === 0) { | ||
quasi.push(quasi_to_add); | ||
return; | ||
} | ||
quasi[quasi.length - 1] = quasi[quasi.length - 1].concat(quasi_to_add); | ||
}, | ||
push_expression: (/** @type {Expression} */ expression_to_add) => { | ||
if (quasi.length === 0) { | ||
quasi.push(''); | ||
} | ||
expressions.push(expression_to_add); | ||
quasi.push(''); | ||
} | ||
}, | ||
template: [], | ||
locations: [], | ||
@@ -141,8 +122,3 @@ transform: { ...context.state.transform }, | ||
/** @type {Expression[]} */ | ||
const args = [ | ||
b.template( | ||
quasi.map((q) => b.quasi(q, true)), | ||
expressions | ||
) | ||
]; | ||
const args = [join_template(state.template)]; | ||
@@ -202,13 +178,7 @@ if (state.metadata.context.template_needs_import_node) { | ||
if (quasi.length === 1 && quasi[0] === '<!>') { | ||
if (state.template.length === 1 && state.template[0] === '<!>') { | ||
// special case — we can use `$.comment` instead of creating a unique template | ||
body.push(b.var(id, b.call('$.comment'))); | ||
} else { | ||
add_template(template_name, [ | ||
b.template( | ||
quasi.map((q) => b.quasi(q, true)), | ||
expressions | ||
), | ||
b.literal(flags) | ||
]); | ||
add_template(template_name, [join_template(state.template), b.literal(flags)]); | ||
@@ -244,2 +214,27 @@ body.push(b.var(id, b.call(template_name))); | ||
/** | ||
* @param {Array<string | Expression>} items | ||
*/ | ||
function join_template(items) { | ||
let quasi = b.quasi(''); | ||
const template = b.template([quasi], []); | ||
for (const item of items) { | ||
if (typeof item === 'string') { | ||
quasi.value.cooked += item; | ||
} else { | ||
template.expressions.push(item); | ||
template.quasis.push((quasi = b.quasi(''))); | ||
} | ||
} | ||
for (const quasi of template.quasis) { | ||
quasi.value.raw = sanitize_template_string(/** @type {string} */ (quasi.value.cooked)); | ||
} | ||
quasi.tail = true; | ||
return template; | ||
} | ||
/** | ||
* | ||
@@ -246,0 +241,0 @@ * @param {Namespace} namespace |
@@ -12,3 +12,3 @@ /** @import { Expression } from 'estree' */ | ||
export function HtmlTag(node, context) { | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
@@ -15,0 +15,0 @@ // push into init, so that bindings run afterwards, which might trigger another run and override hydration |
@@ -11,3 +11,3 @@ /** @import { BlockStatement, Expression } from 'estree' */ | ||
export function IfBlock(node, context) { | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
@@ -14,0 +14,0 @@ const consequent = /** @type {BlockStatement} */ (context.visit(node.consequent)); |
@@ -11,3 +11,3 @@ /** @import { Expression } from 'estree' */ | ||
export function KeyBlock(node, context) { | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
@@ -14,0 +14,0 @@ const key = /** @type {Expression} */ (context.visit(node.expression)); |
@@ -57,3 +57,3 @@ /** @import { Expression, ExpressionStatement, Identifier, MemberExpression, ObjectExpression, Statement } from 'estree' */ | ||
if (node.name === 'noscript') { | ||
context.state.template.push_quasi('<noscript></noscript>'); | ||
context.state.template.push('<noscript></noscript>'); | ||
return; | ||
@@ -72,3 +72,3 @@ } | ||
context.state.template.push_quasi(`<${node.name}`); | ||
context.state.template.push(`<${node.name}`); | ||
@@ -247,3 +247,3 @@ /** @type {Array<AST.Attribute | AST.SpreadAttribute>} */ | ||
if (name !== 'class' || value) { | ||
context.state.template.push_quasi( | ||
context.state.template.push( | ||
` ${attribute.name}${ | ||
@@ -285,3 +285,3 @@ is_boolean_attribute(name) && value === true | ||
context.state.template.push_quasi('>'); | ||
context.state.template.push('>'); | ||
@@ -391,3 +391,3 @@ /** @type {SourceLocation[]} */ | ||
if (!is_void(node.name)) { | ||
context.state.template.push_quasi(`</${node.name}>`); | ||
context.state.template.push(`</${node.name}>`); | ||
} | ||
@@ -480,3 +480,3 @@ } | ||
) { | ||
context.state.template.push_quasi(` is="${escape_html(value.value, true)}"`); | ||
context.state.template.push(` is="${escape_html(value.value, true)}"`); | ||
continue; | ||
@@ -639,5 +639,3 @@ } | ||
if (inlinable_expression) { | ||
context.state.template.push_quasi(` ${name}="`); | ||
context.state.template.push_expression(value); | ||
context.state.template.push_quasi('"'); | ||
context.state.template.push(` ${name}="`, value, '"'); | ||
} else { | ||
@@ -644,0 +642,0 @@ state.init.push(update); |
@@ -12,3 +12,3 @@ /** @import { Expression } from 'estree' */ | ||
export function RenderTag(node, context) { | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
const callee = unwrap_optional(node.expression).callee; | ||
@@ -15,0 +15,0 @@ const raw_args = unwrap_optional(node.expression).arguments; |
@@ -360,3 +360,3 @@ /** @import { BlockStatement, Expression, ExpressionStatement, Identifier, MemberExpression, Property, Statement } from 'estree' */ | ||
if (Object.keys(custom_css_props).length > 0) { | ||
context.state.template.push_quasi( | ||
context.state.template.push( | ||
context.state.metadata.namespace === 'svg' | ||
@@ -373,3 +373,3 @@ ? '<g><!></g>' | ||
} else { | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
statements.push(b.stmt(fn(anchor))); | ||
@@ -376,0 +376,0 @@ } |
@@ -65,7 +65,7 @@ /** @import { Expression } from 'estree' */ | ||
skipped += 1; | ||
state.template.push_quasi(sequence.map((node) => node.raw).join('')); | ||
state.template.push(sequence.map((node) => node.raw).join('')); | ||
return; | ||
} | ||
state.template.push_quasi(' '); | ||
state.template.push(' '); | ||
@@ -72,0 +72,0 @@ const { has_state, has_call, value } = build_template_literal(sequence, visit, state); |
@@ -13,3 +13,3 @@ /** @import { BlockStatement, Expression, ExpressionStatement, Property } from 'estree' */ | ||
// <slot {a}>fallback</slot> --> $.slot($$slots.default, { get a() { .. } }, () => ...fallback); | ||
context.state.template.push_quasi('<!>'); | ||
context.state.template.push('<!>'); | ||
@@ -16,0 +16,0 @@ /** @type {Property[]} */ |
@@ -24,3 +24,3 @@ /** @import { BlockStatement, Expression, ExpressionStatement, Identifier, ObjectExpression, Statement } from 'estree' */ | ||
export function SvelteElement(node, context) { | ||
context.state.template.push_quasi(`<!>`); | ||
context.state.template.push(`<!>`); | ||
@@ -27,0 +27,0 @@ /** @type {Array<AST.Attribute | AST.SpreadAttribute>} */ |
@@ -422,15 +422,27 @@ /** @import * as ESTree from 'estree' */ | ||
export function thunk(expression, async = false) { | ||
const fn = arrow([], expression); | ||
if (async) fn.async = true; | ||
return unthunk(fn); | ||
} | ||
/** | ||
* Replace "(arg) => func(arg)" to "func" | ||
* @param {ESTree.Expression} expression | ||
* @returns {ESTree.Expression} | ||
*/ | ||
export function unthunk(expression) { | ||
if ( | ||
expression.type === 'CallExpression' && | ||
expression.callee.type !== 'Super' && | ||
expression.callee.type !== 'MemberExpression' && | ||
expression.callee.type !== 'CallExpression' && | ||
expression.arguments.length === 0 | ||
expression.type === 'ArrowFunctionExpression' && | ||
expression.async === false && | ||
expression.body.type === 'CallExpression' && | ||
expression.body.callee.type === 'Identifier' && | ||
expression.params.length === expression.body.arguments.length && | ||
expression.params.every((param, index) => { | ||
const arg = /** @type {ESTree.SimpleCallExpression} */ (expression.body).arguments[index]; | ||
return param.type === 'Identifier' && arg.type === 'Identifier' && param.name === arg.name; | ||
}) | ||
) { | ||
return expression.callee; | ||
return expression.body.callee; | ||
} | ||
const fn = arrow([], expression); | ||
if (async) fn.async = true; | ||
return fn; | ||
return expression; | ||
} | ||
@@ -437,0 +449,0 @@ |
/** @import { ComponentContext, ComponentContextLegacy } from '#client' */ | ||
/** @import { EventDispatcher } from './index.js' */ | ||
/** @import { NotFunction } from './internal/types.js' */ | ||
import { current_component_context, flush_sync, untrack } from './internal/client/runtime.js'; | ||
import { component_context, flush_sync, untrack } from './internal/client/runtime.js'; | ||
import { is_array } from './internal/shared/utils.js'; | ||
@@ -25,8 +25,8 @@ import { user_effect } from './internal/client/index.js'; | ||
export function onMount(fn) { | ||
if (current_component_context === null) { | ||
if (component_context === null) { | ||
lifecycle_outside_component('onMount'); | ||
} | ||
if (current_component_context.l !== null) { | ||
init_update_callbacks(current_component_context).m.push(fn); | ||
if (component_context.l !== null) { | ||
init_update_callbacks(component_context).m.push(fn); | ||
} else { | ||
@@ -51,3 +51,3 @@ user_effect(() => { | ||
export function onDestroy(fn) { | ||
if (current_component_context === null) { | ||
if (component_context === null) { | ||
lifecycle_outside_component('onDestroy'); | ||
@@ -95,4 +95,4 @@ } | ||
export function createEventDispatcher() { | ||
const component_context = current_component_context; | ||
if (component_context === null) { | ||
const active_component_context = component_context; | ||
if (active_component_context === null) { | ||
lifecycle_outside_component('createEventDispatcher'); | ||
@@ -103,3 +103,3 @@ } | ||
const events = /** @type {Record<string, Function | Function[]>} */ ( | ||
component_context.s.$$events | ||
active_component_context.s.$$events | ||
)?.[/** @type {any} */ (type)]; | ||
@@ -113,3 +113,3 @@ | ||
for (const fn of callbacks) { | ||
fn.call(component_context.x, event); | ||
fn.call(active_component_context.x, event); | ||
} | ||
@@ -138,11 +138,11 @@ return !event.defaultPrevented; | ||
export function beforeUpdate(fn) { | ||
if (current_component_context === null) { | ||
if (component_context === null) { | ||
lifecycle_outside_component('beforeUpdate'); | ||
} | ||
if (current_component_context.l === null) { | ||
if (component_context.l === null) { | ||
e.lifecycle_legacy_only('beforeUpdate'); | ||
} | ||
init_update_callbacks(current_component_context).b.push(fn); | ||
init_update_callbacks(component_context).b.push(fn); | ||
} | ||
@@ -163,11 +163,11 @@ | ||
export function afterUpdate(fn) { | ||
if (current_component_context === null) { | ||
if (component_context === null) { | ||
lifecycle_outside_component('afterUpdate'); | ||
} | ||
if (current_component_context.l === null) { | ||
if (component_context.l === null) { | ||
e.lifecycle_legacy_only('afterUpdate'); | ||
} | ||
init_update_callbacks(current_component_context).a.push(fn); | ||
init_update_callbacks(component_context).a.push(fn); | ||
} | ||
@@ -174,0 +174,0 @@ |
import * as e from '../errors.js'; | ||
import { current_component_context } from '../runtime.js'; | ||
import { component_context } from '../runtime.js'; | ||
import { FILENAME } from '../../../constants.js'; | ||
@@ -14,3 +14,3 @@ import { get_component } from './ownership.js'; | ||
export function legacy_api() { | ||
const component = current_component_context?.function; | ||
const component = component_context?.function; | ||
@@ -17,0 +17,0 @@ /** @param {string} method */ |
/** @import { Effect, Source, TemplateNode } from '#client' */ | ||
import { is_promise, noop } from '../../../shared/utils.js'; | ||
import { | ||
current_component_context, | ||
component_context, | ||
flush_sync, | ||
is_runes, | ||
set_current_component_context, | ||
set_current_effect, | ||
set_current_reaction, | ||
set_component_context, | ||
set_active_effect, | ||
set_active_reaction, | ||
set_dev_current_component_function | ||
@@ -38,3 +38,3 @@ } from '../../runtime.js'; | ||
var runes = is_runes(); | ||
var component_context = current_component_context; | ||
var active_component_context = component_context; | ||
@@ -68,5 +68,5 @@ /** @type {any} */ | ||
if (restore) { | ||
set_current_effect(effect); | ||
set_current_reaction(effect); // TODO do we need both? | ||
set_current_component_context(component_context); | ||
set_active_effect(effect); | ||
set_active_reaction(effect); // TODO do we need both? | ||
set_component_context(active_component_context); | ||
if (DEV) set_dev_current_component_function(component_function); | ||
@@ -104,5 +104,5 @@ } | ||
if (DEV) set_dev_current_component_function(null); | ||
set_current_component_context(null); | ||
set_current_reaction(null); | ||
set_current_effect(null); | ||
set_component_context(null); | ||
set_active_reaction(null); | ||
set_active_effect(null); | ||
@@ -109,0 +109,0 @@ // without this, the DOM does not update until two ticks after the promise |
@@ -38,3 +38,3 @@ /** @import { EachItem, EachState, Effect, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */ | ||
import { queue_micro_task } from '../task.js'; | ||
import { current_effect } from '../../runtime.js'; | ||
import { active_effect } from '../../runtime.js'; | ||
@@ -430,4 +430,4 @@ /** | ||
/** @type {Effect} */ (current_effect).first = state.first && state.first.e; | ||
/** @type {Effect} */ (current_effect).last = prev && prev.e; | ||
/** @type {Effect} */ (active_effect).first = state.first && state.first.e; | ||
/** @type {Effect} */ (active_effect).last = prev && prev.e; | ||
} | ||
@@ -434,0 +434,0 @@ |
@@ -20,3 +20,3 @@ /** @import { Effect, TemplateNode } from '#client' */ | ||
import { current_each_item, set_current_each_item } from './each.js'; | ||
import { current_component_context, current_effect } from '../../runtime.js'; | ||
import { component_context, active_effect } from '../../runtime.js'; | ||
import { DEV } from 'esm-env'; | ||
@@ -42,3 +42,3 @@ import { EFFECT_TRANSPARENT } from '../../constants.js'; | ||
var filename = DEV && location && current_component_context?.function[FILENAME]; | ||
var filename = DEV && location && component_context?.function[FILENAME]; | ||
@@ -143,3 +143,3 @@ /** @type {string | null} */ | ||
// we do this after calling `render_fn` so that child effects don't override `nodes.end` | ||
/** @type {Effect} */ (current_effect).nodes_end = element; | ||
/** @type {Effect} */ (active_effect).nodes_end = element; | ||
@@ -146,0 +146,0 @@ anchor.before(element); |
@@ -11,7 +11,7 @@ import { DEV } from 'esm-env'; | ||
* @param {HTMLInputElement} input | ||
* @param {() => unknown} get_value | ||
* @param {(value: unknown) => void} update | ||
* @param {() => unknown} get | ||
* @param {(value: unknown) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_value(input, get_value, update) { | ||
export function bind_value(input, get, set = get) { | ||
listen_to_event_and_reset_event(input, 'input', () => { | ||
@@ -23,3 +23,3 @@ if (DEV && input.type === 'checkbox') { | ||
update(is_numberlike_input(input) ? to_number(input.value) : input.value); | ||
set(is_numberlike_input(input) ? to_number(input.value) : input.value); | ||
}); | ||
@@ -33,3 +33,3 @@ | ||
var value = get_value(); | ||
var value = get(); | ||
@@ -39,3 +39,3 @@ // If we are hydrating and the value has since changed, then use the update value | ||
if (hydrating && input.defaultValue !== input.value) { | ||
update(input.value); | ||
set(input.value); | ||
return; | ||
@@ -67,7 +67,7 @@ } | ||
* @param {HTMLInputElement} input | ||
* @param {() => unknown} get_value | ||
* @param {(value: unknown) => void} update | ||
* @param {() => unknown} get | ||
* @param {(value: unknown) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_group(inputs, group_index, input, get_value, update) { | ||
export function bind_group(inputs, group_index, input, get, set = get) { | ||
var is_checkbox = input.getAttribute('type') === 'checkbox'; | ||
@@ -99,10 +99,10 @@ var binding_group = inputs; | ||
update(value); | ||
set(value); | ||
}, | ||
// TODO better default value handling | ||
() => update(is_checkbox ? [] : null) | ||
() => set(is_checkbox ? [] : null) | ||
); | ||
render_effect(() => { | ||
var value = get_value(); | ||
var value = get(); | ||
@@ -156,3 +156,3 @@ // If we are hydrating and the value has since changed, then use the update value | ||
update(value); | ||
set(value); | ||
} | ||
@@ -164,18 +164,18 @@ }); | ||
* @param {HTMLInputElement} input | ||
* @param {() => unknown} get_value | ||
* @param {(value: unknown) => void} update | ||
* @param {() => unknown} get | ||
* @param {(value: unknown) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_checked(input, get_value, update) { | ||
export function bind_checked(input, get, set = get) { | ||
listen_to_event_and_reset_event(input, 'change', () => { | ||
var value = input.checked; | ||
update(value); | ||
set(value); | ||
}); | ||
if (get_value() == undefined) { | ||
update(false); | ||
if (get() == undefined) { | ||
set(false); | ||
} | ||
render_effect(() => { | ||
var value = get_value(); | ||
var value = get(); | ||
input.checked = Boolean(value); | ||
@@ -226,13 +226,13 @@ }); | ||
* @param {HTMLInputElement} input | ||
* @param {() => FileList | null} get_value | ||
* @param {(value: FileList | null) => void} update | ||
* @param {() => FileList | null} get | ||
* @param {(value: FileList | null) => void} set | ||
*/ | ||
export function bind_files(input, get_value, update) { | ||
export function bind_files(input, get, set = get) { | ||
listen_to_event_and_reset_event(input, 'change', () => { | ||
update(input.files); | ||
set(input.files); | ||
}); | ||
render_effect(() => { | ||
input.files = get_value(); | ||
input.files = get(); | ||
}); | ||
} |
@@ -18,7 +18,7 @@ import { hydrating } from '../../hydration.js'; | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {() => number | undefined} get_value | ||
* @param {(value: number) => void} update | ||
* @param {() => number | undefined} get | ||
* @param {(value: number) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_current_time(media, get_value, update) { | ||
export function bind_current_time(media, get, set = get) { | ||
/** @type {number} */ | ||
@@ -41,3 +41,3 @@ var raf_id; | ||
if (value !== next_value) { | ||
update((value = next_value)); | ||
set((value = next_value)); | ||
} | ||
@@ -50,3 +50,3 @@ }; | ||
render_effect(() => { | ||
var next_value = Number(get_value()); | ||
var next_value = Number(get()); | ||
@@ -63,6 +63,6 @@ if (value !== next_value && !isNaN(/** @type {any} */ (next_value))) { | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {(array: Array<{ start: number; end: number }>) => void} update | ||
* @param {(array: Array<{ start: number; end: number }>) => void} set | ||
*/ | ||
export function bind_buffered(media, update) { | ||
listen(media, ['loadedmetadata', 'progress'], () => update(time_ranges_to_array(media.buffered))); | ||
export function bind_buffered(media, set) { | ||
listen(media, ['loadedmetadata', 'progress'], () => set(time_ranges_to_array(media.buffered))); | ||
} | ||
@@ -72,6 +72,6 @@ | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {(array: Array<{ start: number; end: number }>) => void} update | ||
* @param {(array: Array<{ start: number; end: number }>) => void} set | ||
*/ | ||
export function bind_seekable(media, update) { | ||
listen(media, ['loadedmetadata'], () => update(time_ranges_to_array(media.seekable))); | ||
export function bind_seekable(media, set) { | ||
listen(media, ['loadedmetadata'], () => set(time_ranges_to_array(media.seekable))); | ||
} | ||
@@ -81,6 +81,6 @@ | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {(array: Array<{ start: number; end: number }>) => void} update | ||
* @param {(array: Array<{ start: number; end: number }>) => void} set | ||
*/ | ||
export function bind_played(media, update) { | ||
listen(media, ['timeupdate'], () => update(time_ranges_to_array(media.played))); | ||
export function bind_played(media, set) { | ||
listen(media, ['timeupdate'], () => set(time_ranges_to_array(media.played))); | ||
} | ||
@@ -90,6 +90,6 @@ | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {(seeking: boolean) => void} update | ||
* @param {(seeking: boolean) => void} set | ||
*/ | ||
export function bind_seeking(media, update) { | ||
listen(media, ['seeking', 'seeked'], () => update(media.seeking)); | ||
export function bind_seeking(media, set) { | ||
listen(media, ['seeking', 'seeked'], () => set(media.seeking)); | ||
} | ||
@@ -99,6 +99,6 @@ | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {(seeking: boolean) => void} update | ||
* @param {(seeking: boolean) => void} set | ||
*/ | ||
export function bind_ended(media, update) { | ||
listen(media, ['timeupdate', 'ended'], () => update(media.ended)); | ||
export function bind_ended(media, set) { | ||
listen(media, ['timeupdate', 'ended'], () => set(media.ended)); | ||
} | ||
@@ -108,9 +108,9 @@ | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {(ready_state: number) => void} update | ||
* @param {(ready_state: number) => void} set | ||
*/ | ||
export function bind_ready_state(media, update) { | ||
export function bind_ready_state(media, set) { | ||
listen( | ||
media, | ||
['loadedmetadata', 'loadeddata', 'canplay', 'canplaythrough', 'playing', 'waiting', 'emptied'], | ||
() => update(media.readyState) | ||
() => set(media.readyState) | ||
); | ||
@@ -121,10 +121,10 @@ } | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {() => number | undefined} get_value | ||
* @param {(playback_rate: number) => void} update | ||
* @param {() => number | undefined} get | ||
* @param {(playback_rate: number) => void} set | ||
*/ | ||
export function bind_playback_rate(media, get_value, update) { | ||
export function bind_playback_rate(media, get, set = get) { | ||
// Needs to happen after element is inserted into the dom (which is guaranteed by using effect), | ||
// else playback will be set back to 1 by the browser | ||
effect(() => { | ||
var value = Number(get_value()); | ||
var value = Number(get()); | ||
@@ -140,3 +140,3 @@ if (value !== media.playbackRate && !isNaN(value)) { | ||
listen(media, ['ratechange'], () => { | ||
update(media.playbackRate); | ||
set(media.playbackRate); | ||
}); | ||
@@ -148,8 +148,8 @@ }); | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {() => boolean | undefined} get_value | ||
* @param {(paused: boolean) => void} update | ||
* @param {() => boolean | undefined} get | ||
* @param {(paused: boolean) => void} set | ||
*/ | ||
export function bind_paused(media, get_value, update) { | ||
export function bind_paused(media, get, set = get) { | ||
var mounted = hydrating; | ||
var paused = get_value(); | ||
var paused = get(); | ||
@@ -159,3 +159,3 @@ var callback = () => { | ||
paused = media.paused; | ||
update((paused = media.paused)); | ||
set((paused = media.paused)); | ||
} | ||
@@ -176,3 +176,3 @@ }; | ||
render_effect(() => { | ||
paused = !!get_value(); | ||
paused = !!get(); | ||
@@ -186,3 +186,3 @@ if (paused !== media.paused) { | ||
media.play().catch(() => { | ||
update((paused = true)); | ||
set((paused = true)); | ||
}); | ||
@@ -213,11 +213,11 @@ } | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {() => number | undefined} get_value | ||
* @param {(volume: number) => void} update | ||
* @param {() => number | undefined} get | ||
* @param {(volume: number) => void} set | ||
*/ | ||
export function bind_volume(media, get_value, update) { | ||
export function bind_volume(media, get, set = get) { | ||
var callback = () => { | ||
update(media.volume); | ||
set(media.volume); | ||
}; | ||
if (get_value() == null) { | ||
if (get() == null) { | ||
callback(); | ||
@@ -229,3 +229,3 @@ } | ||
render_effect(() => { | ||
var value = Number(get_value()); | ||
var value = Number(get()); | ||
@@ -240,11 +240,11 @@ if (value !== media.volume && !isNaN(value)) { | ||
* @param {HTMLVideoElement | HTMLAudioElement} media | ||
* @param {() => boolean | undefined} get_value | ||
* @param {(muted: boolean) => void} update | ||
* @param {() => boolean | undefined} get | ||
* @param {(muted: boolean) => void} set | ||
*/ | ||
export function bind_muted(media, get_value, update) { | ||
export function bind_muted(media, get, set = get) { | ||
var callback = () => { | ||
update(media.muted); | ||
set(media.muted); | ||
}; | ||
if (get_value() == null) { | ||
if (get() == null) { | ||
callback(); | ||
@@ -256,3 +256,3 @@ } | ||
render_effect(() => { | ||
var value = !!get_value(); | ||
var value = !!get(); | ||
@@ -259,0 +259,0 @@ if (media.muted !== value) media.muted = value; |
@@ -76,7 +76,7 @@ import { effect } from '../../../reactivity/effects.js'; | ||
* @param {HTMLSelectElement} select | ||
* @param {() => unknown} get_value | ||
* @param {(value: unknown) => void} update | ||
* @param {() => unknown} get | ||
* @param {(value: unknown) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_select_value(select, get_value, update) { | ||
export function bind_select_value(select, get, set = get) { | ||
var mounting = true; | ||
@@ -96,3 +96,3 @@ | ||
update(value); | ||
set(value); | ||
}); | ||
@@ -102,3 +102,3 @@ | ||
effect(() => { | ||
var value = get_value(); | ||
var value = get(); | ||
select_option(select, value, mounting); | ||
@@ -112,3 +112,3 @@ | ||
value = get_option_value(selected_option); | ||
update(value); | ||
set(value); | ||
} | ||
@@ -115,0 +115,0 @@ } |
@@ -81,5 +81,5 @@ import { effect, teardown } from '../../../reactivity/effects.js'; | ||
* @param {'contentRect' | 'contentBoxSize' | 'borderBoxSize' | 'devicePixelContentBoxSize'} type | ||
* @param {(entry: keyof ResizeObserverEntry) => void} update | ||
* @param {(entry: keyof ResizeObserverEntry) => void} set | ||
*/ | ||
export function bind_resize_observer(element, type, update) { | ||
export function bind_resize_observer(element, type, set) { | ||
var observer = | ||
@@ -92,3 +92,3 @@ type === 'contentRect' || type === 'contentBoxSize' | ||
var unsub = observer.observe(element, /** @param {any} entry */ (entry) => update(entry[type])); | ||
var unsub = observer.observe(element, /** @param {any} entry */ (entry) => set(entry[type])); | ||
teardown(unsub); | ||
@@ -100,12 +100,12 @@ } | ||
* @param {'clientWidth' | 'clientHeight' | 'offsetWidth' | 'offsetHeight'} type | ||
* @param {(size: number) => void} update | ||
* @param {(size: number) => void} set | ||
*/ | ||
export function bind_element_size(element, type, update) { | ||
var unsub = resize_observer_border_box.observe(element, () => update(element[type])); | ||
export function bind_element_size(element, type, set) { | ||
var unsub = resize_observer_border_box.observe(element, () => set(element[type])); | ||
effect(() => { | ||
// The update could contain reads which should be ignored | ||
untrack(() => update(element[type])); | ||
untrack(() => set(element[type])); | ||
return unsub; | ||
}); | ||
} |
@@ -7,14 +7,14 @@ import { render_effect, teardown } from '../../../reactivity/effects.js'; | ||
* @param {HTMLElement} element | ||
* @param {() => unknown} get_value | ||
* @param {(value: unknown) => void} update | ||
* @param {() => unknown} get | ||
* @param {(value: unknown) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_content_editable(property, element, get_value, update) { | ||
export function bind_content_editable(property, element, get, set = get) { | ||
element.addEventListener('input', () => { | ||
// @ts-ignore | ||
update(element[property]); | ||
set(element[property]); | ||
}); | ||
render_effect(() => { | ||
var value = get_value(); | ||
var value = get(); | ||
@@ -25,3 +25,3 @@ if (element[property] !== value) { | ||
var non_null_value = element[property]; | ||
update(non_null_value); | ||
set(non_null_value); | ||
} else { | ||
@@ -70,9 +70,9 @@ // @ts-ignore | ||
* @param {HTMLElement} element | ||
* @param {(value: unknown) => void} update | ||
* @param {(value: unknown) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_focused(element, update) { | ||
export function bind_focused(element, set) { | ||
listen(element, ['focus', 'blur'], () => { | ||
update(element === document.activeElement); | ||
set(element === document.activeElement); | ||
}); | ||
} |
@@ -6,7 +6,7 @@ import { effect, render_effect, teardown } from '../../../reactivity/effects.js'; | ||
* @param {'x' | 'y'} type | ||
* @param {() => number} get_value | ||
* @param {(value: number) => void} update | ||
* @param {() => number} get | ||
* @param {(value: number) => void} set | ||
* @returns {void} | ||
*/ | ||
export function bind_window_scroll(type, get_value, update) { | ||
export function bind_window_scroll(type, get, set = get) { | ||
var is_scrolling_x = type === 'x'; | ||
@@ -19,3 +19,3 @@ | ||
update(window[is_scrolling_x ? 'scrollX' : 'scrollY']); | ||
set(window[is_scrolling_x ? 'scrollX' : 'scrollY']); | ||
}; | ||
@@ -37,3 +37,3 @@ | ||
render_effect(() => { | ||
var latest_value = get_value(); | ||
var latest_value = get(); | ||
// Don't scroll to the initial value for accessibility reasons | ||
@@ -64,6 +64,6 @@ if (first) { | ||
* @param {'innerWidth' | 'innerHeight' | 'outerWidth' | 'outerHeight'} type | ||
* @param {(size: number) => void} update | ||
* @param {(size: number) => void} set | ||
*/ | ||
export function bind_window_size(type, update) { | ||
listen(window, ['resize'], () => update(window[type])); | ||
export function bind_window_size(type, set) { | ||
listen(window, ['resize'], () => set(window[type])); | ||
} |
/** @import { AnimateFn, Animation, AnimationConfig, EachItem, Effect, TransitionFn, TransitionManager } from '#client' */ | ||
import { noop, is_function } from '../../../shared/utils.js'; | ||
import { effect } from '../../reactivity/effects.js'; | ||
import { current_effect, untrack } from '../../runtime.js'; | ||
import { active_effect, untrack } from '../../runtime.js'; | ||
import { loop } from '../../loop.js'; | ||
@@ -246,3 +246,3 @@ import { should_intro } from '../../render.js'; | ||
var e = /** @type {Effect} */ (current_effect); | ||
var e = /** @type {Effect} */ (active_effect); | ||
@@ -249,0 +249,0 @@ (e.transitions ??= []).push(transition); |
/** @import { ComponentContextLegacy } from '#client' */ | ||
import { run, run_all } from '../../../shared/utils.js'; | ||
import { user_pre_effect, user_effect } from '../../reactivity/effects.js'; | ||
import { current_component_context, deep_read_state, get, untrack } from '../../runtime.js'; | ||
import { component_context, deep_read_state, get, untrack } from '../../runtime.js'; | ||
@@ -10,3 +10,3 @@ /** | ||
export function init() { | ||
const context = /** @type {ComponentContextLegacy} */ (current_component_context); | ||
const context = /** @type {ComponentContextLegacy} */ (component_context); | ||
@@ -13,0 +13,0 @@ const callbacks = context.l.u; |
@@ -5,3 +5,3 @@ /** @import { Effect, TemplateNode } from '#client' */ | ||
import { create_fragment_from_html } from './reconciler.js'; | ||
import { current_effect } from '../runtime.js'; | ||
import { active_effect } from '../runtime.js'; | ||
import { TEMPLATE_FRAGMENT, TEMPLATE_USE_IMPORT_NODE } from '../../../constants.js'; | ||
@@ -15,3 +15,3 @@ import { queue_micro_task } from './task.js'; | ||
export function assign_nodes(start, end) { | ||
var effect = /** @type {Effect} */ (current_effect); | ||
var effect = /** @type {Effect} */ (active_effect); | ||
if (effect.nodes_start === null) { | ||
@@ -197,3 +197,3 @@ effect.nodes_start = start; | ||
: node.querySelectorAll('script'); | ||
const effect = /** @type {Effect} */ (current_effect); | ||
const effect = /** @type {Effect} */ (active_effect); | ||
@@ -280,3 +280,3 @@ for (const script of scripts) { | ||
if (hydrating) { | ||
/** @type {Effect} */ (current_effect).nodes_end = hydrate_node; | ||
/** @type {Effect} */ (active_effect).nodes_end = hydrate_node; | ||
hydrate_next(); | ||
@@ -283,0 +283,0 @@ return; |
@@ -167,1 +167,2 @@ export { FILENAME, HMR } from '../../constants.js'; | ||
export { strict_equals, equals } from './dev/equality.js'; | ||
export { log_if_contains_state } from './dev/console-log.js'; |
/** @import { ProxyMetadata, ProxyStateObject, Source } from '#client' */ | ||
import { DEV } from 'esm-env'; | ||
import { get, current_component_context, untrack, current_effect } from './runtime.js'; | ||
import { get, component_context, active_effect } from './runtime.js'; | ||
import { | ||
@@ -65,4 +65,4 @@ array_prototype, | ||
parent === null | ||
? current_component_context !== null | ||
? new Set([current_component_context.function]) | ||
? component_context !== null | ||
? new Set([component_context.function]) | ||
: null | ||
@@ -194,3 +194,3 @@ : new Set(); | ||
s !== undefined || | ||
(current_effect !== null && (!has || get_descriptor(target, prop)?.writable)) | ||
(active_effect !== null && (!has || get_descriptor(target, prop)?.writable)) | ||
) { | ||
@@ -197,0 +197,0 @@ if (s === undefined) { |
@@ -5,7 +5,7 @@ /** @import { Derived, Effect } from '#client' */ | ||
import { | ||
current_reaction, | ||
current_effect, | ||
active_reaction, | ||
active_effect, | ||
remove_reactions, | ||
set_signal_status, | ||
current_skip_reaction, | ||
skip_reaction, | ||
update_reaction, | ||
@@ -27,3 +27,3 @@ increment_version | ||
let flags = DERIVED | DIRTY; | ||
if (current_effect === null) flags |= UNOWNED; | ||
if (active_effect === null) flags |= UNOWNED; | ||
@@ -42,4 +42,4 @@ /** @type {Derived<V>} */ | ||
if (current_reaction !== null && (current_reaction.f & DERIVED) !== 0) { | ||
var derived = /** @type {Derived} */ (current_reaction); | ||
if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) { | ||
var derived = /** @type {Derived} */ (active_reaction); | ||
(derived.children ??= []).push(signal); | ||
@@ -120,5 +120,3 @@ } | ||
var status = | ||
(current_skip_reaction || (derived.f & UNOWNED) !== 0) && derived.deps !== null | ||
? MAYBE_DIRTY | ||
: CLEAN; | ||
(skip_reaction || (derived.f & UNOWNED) !== 0) && derived.deps !== null ? MAYBE_DIRTY : CLEAN; | ||
@@ -125,0 +123,0 @@ set_signal_status(derived, status); |
/** @import { ComponentContext, ComponentContextLegacy, Derived, Effect, Reaction, TemplateNode, TransitionManager } from '#client' */ | ||
import { | ||
check_dirtiness, | ||
current_component_context, | ||
current_effect, | ||
current_reaction, | ||
component_context, | ||
active_effect, | ||
active_reaction, | ||
destroy_effect_children, | ||
@@ -15,3 +15,3 @@ dev_current_component_function, | ||
schedule_effect, | ||
set_current_reaction, | ||
set_active_reaction, | ||
set_is_destroying_effect, | ||
@@ -50,7 +50,7 @@ set_is_flushing_effect, | ||
export function validate_effect(rune) { | ||
if (current_effect === null && current_reaction === null) { | ||
if (active_effect === null && active_reaction === null) { | ||
e.effect_orphan(rune); | ||
} | ||
if (current_reaction !== null && (current_reaction.f & UNOWNED) !== 0) { | ||
if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0) { | ||
e.effect_in_unowned_derived(); | ||
@@ -88,3 +88,3 @@ } | ||
var is_root = (type & ROOT_EFFECT) !== 0; | ||
var parent_effect = current_effect; | ||
var parent_effect = active_effect; | ||
@@ -100,3 +100,3 @@ if (DEV) { | ||
var effect = { | ||
ctx: current_component_context, | ||
ctx: component_context, | ||
deps: null, | ||
@@ -153,4 +153,4 @@ nodes_start: null, | ||
// if we're in a derived, add the effect there too | ||
if (current_reaction !== null && (current_reaction.f & DERIVED) !== 0) { | ||
var derived = /** @type {Derived} */ (current_reaction); | ||
if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) { | ||
var derived = /** @type {Derived} */ (active_reaction); | ||
(derived.children ??= []).push(effect); | ||
@@ -168,7 +168,7 @@ } | ||
export function effect_tracking() { | ||
if (current_reaction === null) { | ||
if (active_reaction === null) { | ||
return false; | ||
} | ||
return (current_reaction.f & UNOWNED) === 0; | ||
return (active_reaction.f & UNOWNED) === 0; | ||
} | ||
@@ -196,7 +196,7 @@ | ||
var defer = | ||
current_effect !== null && | ||
(current_effect.f & RENDER_EFFECT) !== 0 && | ||
active_effect !== null && | ||
(active_effect.f & RENDER_EFFECT) !== 0 && | ||
// TODO do we actually need this? removing them changes nothing | ||
current_component_context !== null && | ||
!current_component_context.m; | ||
component_context !== null && | ||
!component_context.m; | ||
@@ -210,4 +210,7 @@ if (DEV) { | ||
if (defer) { | ||
var context = /** @type {ComponentContext} */ (current_component_context); | ||
(context.e ??= []).push(fn); | ||
var context = /** @type {ComponentContext} */ (component_context); | ||
(context.e ??= []).push({ | ||
fn, | ||
parent: active_effect | ||
}); | ||
} else { | ||
@@ -265,3 +268,3 @@ var signal = effect(fn); | ||
export function legacy_pre_effect(deps, fn) { | ||
var context = /** @type {ComponentContextLegacy} */ (current_component_context); | ||
var context = /** @type {ComponentContextLegacy} */ (component_context); | ||
@@ -286,3 +289,3 @@ /** @type {{ effect: null | Effect, ran: boolean }} */ | ||
export function legacy_pre_effect_reset() { | ||
var context = /** @type {ComponentContextLegacy} */ (current_component_context); | ||
var context = /** @type {ComponentContextLegacy} */ (component_context); | ||
@@ -357,5 +360,5 @@ render_effect(() => { | ||
const previously_destroying_effect = is_destroying_effect; | ||
const previous_reaction = current_reaction; | ||
const previous_reaction = active_reaction; | ||
set_is_destroying_effect(true); | ||
set_current_reaction(null); | ||
set_active_reaction(null); | ||
try { | ||
@@ -365,3 +368,3 @@ teardown.call(null); | ||
set_is_destroying_effect(previously_destroying_effect); | ||
set_current_reaction(previous_reaction); | ||
set_active_reaction(previous_reaction); | ||
} | ||
@@ -368,0 +371,0 @@ } |
/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */ | ||
import { DEV } from 'esm-env'; | ||
import { | ||
current_component_context, | ||
current_reaction, | ||
component_context, | ||
active_reaction, | ||
new_deps, | ||
current_effect, | ||
current_untracked_writes, | ||
active_effect, | ||
untracked_writes, | ||
get, | ||
is_runes, | ||
schedule_effect, | ||
set_current_untracked_writes, | ||
set_untracked_writes, | ||
set_signal_status, | ||
@@ -79,4 +79,4 @@ untrack, | ||
// track updates to trigger beforeUpdate/afterUpdate callbacks | ||
if (current_component_context !== null && current_component_context.l !== null) { | ||
(current_component_context.l.s ??= []).push(s); | ||
if (component_context !== null && component_context.l !== null) { | ||
(component_context.l.s ??= []).push(s); | ||
} | ||
@@ -102,3 +102,3 @@ | ||
function push_derived_source(source) { | ||
if (current_reaction !== null && (current_reaction.f & DERIVED) !== 0) { | ||
if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) { | ||
if (derived_sources === null) { | ||
@@ -135,5 +135,5 @@ set_derived_sources([source]); | ||
if ( | ||
current_reaction !== null && | ||
active_reaction !== null && | ||
is_runes() && | ||
(current_reaction.f & DERIVED) !== 0 && | ||
(active_reaction.f & DERIVED) !== 0 && | ||
// If the source was created locally within the current derived, then | ||
@@ -159,14 +159,14 @@ // we allow the mutation. | ||
is_runes() && | ||
current_effect !== null && | ||
(current_effect.f & CLEAN) !== 0 && | ||
(current_effect.f & BRANCH_EFFECT) === 0 | ||
active_effect !== null && | ||
(active_effect.f & CLEAN) !== 0 && | ||
(active_effect.f & BRANCH_EFFECT) === 0 | ||
) { | ||
if (new_deps !== null && new_deps.includes(source)) { | ||
set_signal_status(current_effect, DIRTY); | ||
schedule_effect(current_effect); | ||
set_signal_status(active_effect, DIRTY); | ||
schedule_effect(active_effect); | ||
} else { | ||
if (current_untracked_writes === null) { | ||
set_current_untracked_writes([source]); | ||
if (untracked_writes === null) { | ||
set_untracked_writes([source]); | ||
} else { | ||
current_untracked_writes.push(source); | ||
untracked_writes.push(source); | ||
} | ||
@@ -221,3 +221,3 @@ } | ||
// In legacy mode, skip the current effect to prevent infinite loops | ||
if (!runes && reaction === current_effect) continue; | ||
if (!runes && reaction === active_effect) continue; | ||
@@ -224,0 +224,0 @@ // Inspect effects need to run immediately, so that the stack trace makes sense |
@@ -12,3 +12,3 @@ /** @import { ComponentContext, Effect, TemplateNode } from '#client' */ | ||
import { HYDRATION_END, HYDRATION_ERROR, HYDRATION_START } from '../../constants.js'; | ||
import { push, pop, current_component_context, current_effect } from './runtime.js'; | ||
import { push, pop, component_context, active_effect } from './runtime.js'; | ||
import { effect_root, branch } from './reactivity/effects.js'; | ||
@@ -232,3 +232,3 @@ import { | ||
push({}); | ||
var ctx = /** @type {ComponentContext} */ (current_component_context); | ||
var ctx = /** @type {ComponentContext} */ (component_context); | ||
ctx.c = context; | ||
@@ -252,3 +252,3 @@ } | ||
if (hydrating) { | ||
/** @type {Effect} */ (current_effect).nodes_end = hydrate_node; | ||
/** @type {Effect} */ (active_effect).nodes_end = hydrate_node; | ||
} | ||
@@ -255,0 +255,0 @@ |
@@ -42,3 +42,3 @@ /** @import { ComponentContext, Derived, Effect, Reaction, Signal, Source, Value } from '#client' */ | ||
// Used for controlling the flush of effects. | ||
let current_scheduler_mode = FLUSH_MICROTASK; | ||
let scheduler_mode = FLUSH_MICROTASK; | ||
// Used for handling scheduling | ||
@@ -63,3 +63,3 @@ let is_micro_task_queued = false; | ||
/** @type {Effect[]} */ | ||
let current_queued_root_effects = []; | ||
let queued_root_effects = []; | ||
@@ -72,15 +72,15 @@ let flush_count = 0; | ||
/** @type {null | Reaction} */ | ||
export let current_reaction = null; | ||
export let active_reaction = null; | ||
/** @param {null | Reaction} reaction */ | ||
export function set_current_reaction(reaction) { | ||
current_reaction = reaction; | ||
export function set_active_reaction(reaction) { | ||
active_reaction = reaction; | ||
} | ||
/** @type {null | Effect} */ | ||
export let current_effect = null; | ||
export let active_effect = null; | ||
/** @param {null | Effect} effect */ | ||
export function set_current_effect(effect) { | ||
current_effect = effect; | ||
export function set_active_effect(effect) { | ||
active_effect = effect; | ||
} | ||
@@ -117,7 +117,7 @@ | ||
*/ | ||
export let current_untracked_writes = null; | ||
export let untracked_writes = null; | ||
/** @param {null | Source[]} value */ | ||
export function set_current_untracked_writes(value) { | ||
current_untracked_writes = value; | ||
export function set_untracked_writes(value) { | ||
untracked_writes = value; | ||
} | ||
@@ -130,3 +130,3 @@ | ||
// to prevent memory leaks, we skip adding the reaction. | ||
export let current_skip_reaction = false; | ||
export let skip_reaction = false; | ||
// Handle collecting all signals which are read during a specific time frame | ||
@@ -138,7 +138,7 @@ export let is_signals_recorded = false; | ||
/** @type {ComponentContext | null} */ | ||
export let current_component_context = null; | ||
export let component_context = null; | ||
/** @param {ComponentContext | null} context */ | ||
export function set_current_component_context(context) { | ||
current_component_context = context; | ||
export function set_component_context(context) { | ||
component_context = context; | ||
} | ||
@@ -169,3 +169,3 @@ | ||
export function is_runes() { | ||
return current_component_context !== null && current_component_context.l === null; | ||
return component_context !== null && component_context.l === null; | ||
} | ||
@@ -208,3 +208,3 @@ | ||
// If we are working with an unowned signal as part of an effect (due to !current_skip_reaction) | ||
// If we are working with an unowned signal as part of an effect (due to !skip_reaction) | ||
// and the version hasn't changed, we still need to check that this reaction | ||
@@ -214,4 +214,4 @@ // is linked to the dependency source – otherwise future updates will not be caught. | ||
is_unowned && | ||
current_effect !== null && | ||
!current_skip_reaction && | ||
active_effect !== null && | ||
!skip_reaction && | ||
!dependency?.reactions?.includes(reaction) | ||
@@ -308,5 +308,5 @@ ) { | ||
var previous_skipped_deps = skipped_deps; | ||
var previous_untracked_writes = current_untracked_writes; | ||
var previous_reaction = current_reaction; | ||
var previous_skip_reaction = current_skip_reaction; | ||
var previous_untracked_writes = untracked_writes; | ||
var previous_reaction = active_reaction; | ||
var previous_skip_reaction = skip_reaction; | ||
var prev_derived_sources = derived_sources; | ||
@@ -316,5 +316,5 @@ | ||
skipped_deps = 0; | ||
current_untracked_writes = null; | ||
current_reaction = (reaction.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null; | ||
current_skip_reaction = !is_flushing_effect && (reaction.f & UNOWNED) !== 0; | ||
untracked_writes = null; | ||
active_reaction = (reaction.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null; | ||
skip_reaction = !is_flushing_effect && (reaction.f & UNOWNED) !== 0; | ||
derived_sources = null; | ||
@@ -340,3 +340,3 @@ | ||
if (!current_skip_reaction) { | ||
if (!skip_reaction) { | ||
for (i = skipped_deps; i < deps.length; i++) { | ||
@@ -355,5 +355,5 @@ (deps[i].reactions ??= []).push(reaction); | ||
skipped_deps = previous_skipped_deps; | ||
current_untracked_writes = previous_untracked_writes; | ||
current_reaction = previous_reaction; | ||
current_skip_reaction = previous_skip_reaction; | ||
untracked_writes = previous_untracked_writes; | ||
active_reaction = previous_reaction; | ||
skip_reaction = previous_skip_reaction; | ||
derived_sources = prev_derived_sources; | ||
@@ -440,10 +440,8 @@ } | ||
var component_context = effect.ctx; | ||
var previous_effect = active_effect; | ||
var previous_component_context = component_context; | ||
var previous_effect = current_effect; | ||
var previous_component_context = current_component_context; | ||
active_effect = effect; | ||
component_context = effect.ctx; | ||
current_effect = effect; | ||
current_component_context = component_context; | ||
if (DEV) { | ||
@@ -468,6 +466,6 @@ var previous_component_fn = dev_current_component_function; | ||
} catch (error) { | ||
handle_error(/** @type {Error} */ (error), effect, current_component_context); | ||
handle_error(/** @type {Error} */ (error), effect, previous_component_context); | ||
} finally { | ||
current_effect = previous_effect; | ||
current_component_context = previous_component_context; | ||
active_effect = previous_effect; | ||
component_context = previous_component_context; | ||
@@ -577,4 +575,4 @@ if (DEV) { | ||
} | ||
const previous_queued_root_effects = current_queued_root_effects; | ||
current_queued_root_effects = []; | ||
const previous_queued_root_effects = queued_root_effects; | ||
queued_root_effects = []; | ||
flush_queued_root_effects(previous_queued_root_effects); | ||
@@ -594,3 +592,3 @@ if (!is_micro_task_queued) { | ||
export function schedule_effect(signal) { | ||
if (current_scheduler_mode === FLUSH_MICROTASK) { | ||
if (scheduler_mode === FLUSH_MICROTASK) { | ||
if (!is_micro_task_queued) { | ||
@@ -614,3 +612,3 @@ is_micro_task_queued = true; | ||
current_queued_root_effects.push(effect); | ||
queued_root_effects.push(effect); | ||
} | ||
@@ -706,4 +704,4 @@ | ||
export function flush_sync(fn) { | ||
var previous_scheduler_mode = current_scheduler_mode; | ||
var previous_queued_root_effects = current_queued_root_effects; | ||
var previous_scheduler_mode = scheduler_mode; | ||
var previous_queued_root_effects = queued_root_effects; | ||
@@ -716,4 +714,4 @@ try { | ||
current_scheduler_mode = FLUSH_SYNC; | ||
current_queued_root_effects = root_effects; | ||
scheduler_mode = FLUSH_SYNC; | ||
queued_root_effects = root_effects; | ||
is_micro_task_queued = false; | ||
@@ -726,3 +724,3 @@ | ||
flush_tasks(); | ||
if (current_queued_root_effects.length > 0 || root_effects.length > 0) { | ||
if (queued_root_effects.length > 0 || root_effects.length > 0) { | ||
flush_sync(); | ||
@@ -738,4 +736,4 @@ } | ||
} finally { | ||
current_scheduler_mode = previous_scheduler_mode; | ||
current_queued_root_effects = previous_queued_root_effects; | ||
scheduler_mode = previous_scheduler_mode; | ||
queued_root_effects = previous_queued_root_effects; | ||
} | ||
@@ -772,7 +770,7 @@ } | ||
// Register the dependency on the current reaction signal. | ||
if (current_reaction !== null) { | ||
if (active_reaction !== null) { | ||
if (derived_sources !== null && derived_sources.includes(signal)) { | ||
e.state_unsafe_local_read(); | ||
} | ||
var deps = current_reaction.deps; | ||
var deps = active_reaction.deps; | ||
@@ -791,10 +789,10 @@ // If the signal is accessing the same dependencies in the same | ||
if ( | ||
current_untracked_writes !== null && | ||
current_effect !== null && | ||
(current_effect.f & CLEAN) !== 0 && | ||
(current_effect.f & BRANCH_EFFECT) === 0 && | ||
current_untracked_writes.includes(signal) | ||
untracked_writes !== null && | ||
active_effect !== null && | ||
(active_effect.f & CLEAN) !== 0 && | ||
(active_effect.f & BRANCH_EFFECT) === 0 && | ||
untracked_writes.includes(signal) | ||
) { | ||
set_signal_status(current_effect, DIRTY); | ||
schedule_effect(current_effect); | ||
set_signal_status(active_effect, DIRTY); | ||
schedule_effect(active_effect); | ||
} | ||
@@ -870,8 +868,8 @@ } | ||
export function untrack(fn) { | ||
const previous_reaction = current_reaction; | ||
const previous_reaction = active_reaction; | ||
try { | ||
current_reaction = null; | ||
active_reaction = null; | ||
return fn(); | ||
} finally { | ||
current_reaction = previous_reaction; | ||
active_reaction = previous_reaction; | ||
} | ||
@@ -905,3 +903,3 @@ } | ||
if (DEV) { | ||
const fn = /** @type {ComponentContext} */ (current_component_context).function; | ||
const fn = /** @type {ComponentContext} */ (component_context).function; | ||
if (fn) { | ||
@@ -960,3 +958,3 @@ add_owner(result, fn, true); | ||
if (DEV) { | ||
const fn = current_component_context?.function; | ||
const fn = component_context?.function; | ||
if (fn) { | ||
@@ -977,9 +975,7 @@ for (const value of context_map.values()) { | ||
function get_or_init_context_map(name) { | ||
if (current_component_context === null) { | ||
if (component_context === null) { | ||
lifecycle_outside_component(name); | ||
} | ||
return (current_component_context.c ??= new Map( | ||
get_parent_context(current_component_context) || undefined | ||
)); | ||
return (component_context.c ??= new Map(get_parent_context(component_context) || undefined)); | ||
} | ||
@@ -1048,4 +1044,4 @@ | ||
export function push(props, runes = false, fn) { | ||
current_component_context = { | ||
p: current_component_context, | ||
component_context = { | ||
p: component_context, | ||
c: null, | ||
@@ -1060,3 +1056,3 @@ e: null, | ||
if (!runes) { | ||
current_component_context.l = { | ||
component_context.l = { | ||
s: null, | ||
@@ -1071,3 +1067,3 @@ u: null, | ||
// component function | ||
current_component_context.function = fn; | ||
component_context.function = fn; | ||
dev_current_component_function = fn; | ||
@@ -1083,3 +1079,3 @@ } | ||
export function pop(component) { | ||
const context_stack_item = current_component_context; | ||
const context_stack_item = component_context; | ||
if (context_stack_item !== null) { | ||
@@ -1089,10 +1085,17 @@ if (component !== undefined) { | ||
} | ||
const effects = context_stack_item.e; | ||
if (effects !== null) { | ||
const component_effects = context_stack_item.e; | ||
if (component_effects !== null) { | ||
var previous_effect = active_effect; | ||
context_stack_item.e = null; | ||
for (var i = 0; i < effects.length; i++) { | ||
effect(effects[i]); | ||
try { | ||
for (var i = 0; i < component_effects.length; i++) { | ||
var component_effect = component_effects[i]; | ||
set_active_effect(component_effect.parent); | ||
effect(component_effect.fn); | ||
} | ||
} finally { | ||
set_active_effect(previous_effect); | ||
} | ||
} | ||
current_component_context = context_stack_item.p; | ||
component_context = context_stack_item.p; | ||
if (DEV) { | ||
@@ -1099,0 +1102,0 @@ dev_current_component_function = context_stack_item.p?.function ?? null; |
@@ -18,3 +18,3 @@ import type { Store } from '#shared'; | ||
/** deferred effects */ | ||
e: null | Array<() => void | (() => void)>; | ||
e: null | Array<{ fn: () => void | (() => void); parent: null | Effect }>; | ||
/** mounted */ | ||
@@ -21,0 +21,0 @@ m: boolean; |
@@ -23,2 +23,15 @@ /* This file is generated by scripts/process-messages/index.js. Do not edit! */ | ||
/** | ||
* Your `console.%method%` contained `$state` proxies. Consider using `$inspect(...)` or `$state.snapshot(...)` instead | ||
* @param {string} method | ||
*/ | ||
export function console_log_state(method) { | ||
if (DEV) { | ||
console.warn(`%c[svelte] console_log_state\n%cYour \`console.${method}\` contained \`$state\` proxies. Consider using \`$inspect(...)\` or \`$state.snapshot(...)\` instead`, bold, normal); | ||
} else { | ||
// TODO print a link to the documentation | ||
console.warn("console_log_state"); | ||
} | ||
} | ||
/** | ||
* %handler% should be a function. Did you mean to %suggestion%? | ||
@@ -25,0 +38,0 @@ * @param {string} handler |
@@ -21,3 +21,3 @@ /** @import { Snapshot } from './types' */ | ||
export function snapshot(value, skip_warning = false) { | ||
if (DEV) { | ||
if (DEV && !skip_warning) { | ||
/** @type {string[]} */ | ||
@@ -27,6 +27,6 @@ const paths = []; | ||
const copy = clone(value, new Map(), '', paths); | ||
if (paths.length === 1 && paths[0] === '' && !skip_warning) { | ||
if (paths.length === 1 && paths[0] === '') { | ||
// value could not be cloned | ||
w.state_snapshot_uncloneable(); | ||
} else if (paths.length > 0 && !skip_warning) { | ||
} else if (paths.length > 0) { | ||
// some properties could not be cloned | ||
@@ -33,0 +33,0 @@ const slice = paths.length > 10 ? paths.slice(0, 7) : paths.slice(0, 10); |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.0.0-next.247'; | ||
export const VERSION = '5.0.0-next.248'; | ||
export const PUBLIC_VERSION = '5'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2215846
361
49012