svelte
Advanced tools
Comparing version 5.0.0-next.121 to 5.0.0-next.123
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.0-next.121", | ||
"version": "5.0.0-next.123", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -65,2 +65,23 @@ declare module '*.svelte' { | ||
export function snapshot<T>(state: T): T; | ||
// prevent intellisense from being unhelpful | ||
/** @deprecated */ | ||
export const apply: never; | ||
/** @deprecated */ | ||
// @ts-ignore | ||
export const arguments: never; | ||
/** @deprecated */ | ||
export const bind: never; | ||
/** @deprecated */ | ||
export const call: never; | ||
/** @deprecated */ | ||
export const caller: never; | ||
/** @deprecated */ | ||
export const length: never; | ||
/** @deprecated */ | ||
export const name: never; | ||
/** @deprecated */ | ||
export const prototype: never; | ||
/** @deprecated */ | ||
export const toString: never; | ||
} | ||
@@ -102,2 +123,23 @@ | ||
export function by<T>(fn: () => T): T; | ||
// prevent intellisense from being unhelpful | ||
/** @deprecated */ | ||
export const apply: never; | ||
/** @deprecated */ | ||
// @ts-ignore | ||
export const arguments: never; | ||
/** @deprecated */ | ||
export const bind: never; | ||
/** @deprecated */ | ||
export const call: never; | ||
/** @deprecated */ | ||
export const caller: never; | ||
/** @deprecated */ | ||
export const length: never; | ||
/** @deprecated */ | ||
export const name: never; | ||
/** @deprecated */ | ||
export const prototype: never; | ||
/** @deprecated */ | ||
export const toString: never; | ||
} | ||
@@ -191,2 +233,23 @@ | ||
export function root(fn: () => void | (() => void)): () => void; | ||
// prevent intellisense from being unhelpful | ||
/** @deprecated */ | ||
export const apply: never; | ||
/** @deprecated */ | ||
// @ts-ignore | ||
export const arguments: never; | ||
/** @deprecated */ | ||
export const bind: never; | ||
/** @deprecated */ | ||
export const call: never; | ||
/** @deprecated */ | ||
export const caller: never; | ||
/** @deprecated */ | ||
export const length: never; | ||
/** @deprecated */ | ||
export const name: never; | ||
/** @deprecated */ | ||
export const prototype: never; | ||
/** @deprecated */ | ||
export const toString: never; | ||
} | ||
@@ -193,0 +256,0 @@ |
@@ -452,2 +452,45 @@ import is_reference from 'is-reference'; | ||
} | ||
// warn on any nonstate declarations that are a) reassigned and b) referenced in the template | ||
for (const scope of [module.scope, instance.scope]) { | ||
outer: for (const [name, binding] of scope.declarations) { | ||
if (binding.kind === 'normal' && binding.reassigned) { | ||
inner: for (const { path } of binding.references) { | ||
if (path[0].type !== 'Fragment') continue; | ||
for (let i = 1; i < path.length; i += 1) { | ||
const type = path[i].type; | ||
if ( | ||
type === 'FunctionDeclaration' || | ||
type === 'FunctionExpression' || | ||
type === 'ArrowFunctionExpression' | ||
) { | ||
continue inner; | ||
} | ||
// bind:this doesn't need to be a state reference if it will never change | ||
if ( | ||
type === 'BindDirective' && | ||
/** @type {import('#compiler').BindDirective} */ (path[i]).name === 'this' | ||
) { | ||
for (let j = i - 1; j >= 0; j -= 1) { | ||
const type = path[j].type; | ||
if ( | ||
type === 'IfBlock' || | ||
type === 'EachBlock' || | ||
type === 'AwaitBlock' || | ||
type === 'KeyBlock' | ||
) { | ||
w.non_reactive_update(binding.node, name); | ||
continue outer; | ||
} | ||
} | ||
continue inner; | ||
} | ||
} | ||
w.non_reactive_update(binding.node, name); | ||
continue outer; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
@@ -512,45 +555,2 @@ instance.scope.declare(b.id('$$props'), 'rest_prop', 'synthetic'); | ||
// warn on any nonstate declarations that are a) reassigned and b) referenced in the template | ||
for (const scope of [module.scope, instance.scope]) { | ||
outer: for (const [name, binding] of scope.declarations) { | ||
if (binding.kind === 'normal' && binding.reassigned) { | ||
inner: for (const { path } of binding.references) { | ||
if (path[0].type !== 'Fragment') continue; | ||
for (let i = 1; i < path.length; i += 1) { | ||
const type = path[i].type; | ||
if ( | ||
type === 'FunctionDeclaration' || | ||
type === 'FunctionExpression' || | ||
type === 'ArrowFunctionExpression' | ||
) { | ||
continue inner; | ||
} | ||
// bind:this doesn't need to be a state reference if it will never change | ||
if ( | ||
type === 'BindDirective' && | ||
/** @type {import('#compiler').BindDirective} */ (path[i]).name === 'this' | ||
) { | ||
for (let j = i - 1; j >= 0; j -= 1) { | ||
const type = path[j].type; | ||
if ( | ||
type === 'IfBlock' || | ||
type === 'EachBlock' || | ||
type === 'AwaitBlock' || | ||
type === 'KeyBlock' | ||
) { | ||
w.non_reactive_update(binding.node, name); | ||
continue outer; | ||
} | ||
} | ||
continue inner; | ||
} | ||
} | ||
w.non_reactive_update(binding.node, name); | ||
continue outer; | ||
} | ||
} | ||
} | ||
} | ||
if (analysis.css.ast) { | ||
@@ -557,0 +557,0 @@ analyze_css(analysis.css.ast, analysis); |
import { snapshot } from '../proxy.js'; | ||
import { render_effect, validate_effect } from '../reactivity/effects.js'; | ||
import { current_effect, deep_read } from '../runtime.js'; | ||
import { current_effect, deep_read, untrack } from '../runtime.js'; | ||
import { array_prototype, get_prototype_of, object_prototype } from '../utils.js'; | ||
@@ -31,3 +31,3 @@ | ||
var fn = () => { | ||
const value = deep_snapshot(get_value()); | ||
const value = untrack(() => deep_snapshot(get_value())); | ||
inspector(initial ? 'init' : 'update', ...value); | ||
@@ -34,0 +34,0 @@ }; |
/** @typedef {{ file: string, line: number, column: number }} Location */ | ||
import { STATE_SYMBOL } from '../constants.js'; | ||
import { render_effect } from '../reactivity/effects.js'; | ||
import { current_component_context, untrack } from '../runtime.js'; | ||
import { render_effect, user_pre_effect } from '../reactivity/effects.js'; | ||
import { dev_current_component_function, set_dev_current_component_function } from '../runtime.js'; | ||
import { get_prototype_of } from '../utils.js'; | ||
@@ -112,4 +112,3 @@ import * as w from '../warnings.js'; | ||
if (object && !global) { | ||
// @ts-expect-error | ||
const component = current_component_context.function; | ||
const component = dev_current_component_function; | ||
const metadata = object[STATE_SYMBOL]; | ||
@@ -129,2 +128,16 @@ if (metadata && !has_owner(metadata, component)) { | ||
/** | ||
* @param {() => unknown} get_object | ||
* @param {any} Component | ||
*/ | ||
export function add_owner_effect(get_object, Component) { | ||
var component = dev_current_component_function; | ||
user_pre_effect(() => { | ||
var prev = dev_current_component_function; | ||
set_dev_current_component_function(component); | ||
add_owner(get_object(), Component); | ||
set_dev_current_component_function(prev); | ||
}); | ||
} | ||
/** | ||
* @param {import('#client').ProxyMetadata<any> | null} from | ||
@@ -131,0 +144,0 @@ * @param {import('#client').ProxyMetadata<any>} to |
import { add_snippet_symbol } from '../../../shared/validate.js'; | ||
import { EFFECT_TRANSPARENT } from '../../constants.js'; | ||
import { branch, block, destroy_effect } from '../../reactivity/effects.js'; | ||
import { current_component_context, set_current_component_context } from '../../runtime.js'; | ||
import { | ||
current_component_context, | ||
dev_current_component_function, | ||
set_dev_current_component_function | ||
} from '../../runtime.js'; | ||
@@ -41,8 +45,8 @@ /** | ||
export function wrap_snippet(fn) { | ||
let component = current_component_context; | ||
let component = /** @type {import('#client').ComponentContext} */ (current_component_context); | ||
return add_snippet_symbol( | ||
(/** @type {import('#client').TemplateNode} */ node, /** @type {any[]} */ ...args) => { | ||
var previous_component_context = current_component_context; | ||
set_current_component_context(component); | ||
var previous_component_function = dev_current_component_function; | ||
set_dev_current_component_function(component.function); | ||
@@ -52,3 +56,3 @@ try { | ||
} finally { | ||
set_current_component_context(previous_component_context); | ||
set_dev_current_component_function(previous_component_function); | ||
} | ||
@@ -55,0 +59,0 @@ } |
export { hmr } from './dev/hmr.js'; | ||
export { ADD_OWNER, add_owner, mark_module_start, mark_module_end } from './dev/ownership.js'; | ||
export { | ||
ADD_OWNER, | ||
add_owner, | ||
mark_module_start, | ||
mark_module_end, | ||
add_owner_effect | ||
} from './dev/ownership.js'; | ||
export { inspect } from './dev/inspect.js'; | ||
@@ -4,0 +10,0 @@ export { await_block as await } from './dom/blocks/await.js'; |
@@ -78,4 +78,3 @@ import { DEV } from 'esm-env'; | ||
? current_component_context !== null | ||
? // @ts-expect-error | ||
new Set([current_component_context.function]) | ||
? new Set([current_component_context.function]) | ||
: null | ||
@@ -82,0 +81,0 @@ : new Set(); |
@@ -116,4 +116,24 @@ import { DEV } from 'esm-env'; | ||
current_component_context = context; | ||
if (DEV) { | ||
dev_current_component_function = context?.function; | ||
} | ||
} | ||
/** | ||
* The current component function. Different from current component context: | ||
* ```html | ||
* <!-- App.svelte --> | ||
* <Foo> | ||
* <Bar /> <!-- context == Foo.svelte, function == App.svelte --> | ||
* </Foo> | ||
* ``` | ||
* @type {import('#client').ComponentContext['function']} | ||
*/ | ||
export let dev_current_component_function = null; | ||
/** @param {import('#client').ComponentContext['function']} fn */ | ||
export function set_dev_current_component_function(fn) { | ||
dev_current_component_function = fn; | ||
} | ||
/** @returns {boolean} */ | ||
@@ -404,3 +424,3 @@ export function is_runes() { | ||
current_effect = effect; | ||
current_component_context = component_context; | ||
set_current_component_context(component_context); | ||
@@ -417,3 +437,3 @@ try { | ||
current_effect = previous_effect; | ||
current_component_context = previous_component_context; | ||
set_current_component_context(previous_component_context); | ||
} | ||
@@ -891,4 +911,4 @@ } | ||
if (DEV) { | ||
// @ts-expect-error | ||
const fn = current_component_context.function; | ||
const fn = /** @type {import('#client').ComponentContext} */ (current_component_context) | ||
.function; | ||
if (fn) { | ||
@@ -947,3 +967,2 @@ add_owner(result, fn, true); | ||
if (DEV) { | ||
// @ts-expect-error | ||
const fn = current_component_context?.function; | ||
@@ -1074,4 +1093,4 @@ if (fn) { | ||
// component function | ||
// @ts-expect-error | ||
current_component_context.function = fn; | ||
dev_current_component_function = fn; | ||
} | ||
@@ -1098,3 +1117,3 @@ } | ||
} | ||
current_component_context = context_stack_item.p; | ||
set_current_component_context(context_stack_item.p); | ||
context_stack_item.m = true; | ||
@@ -1101,0 +1120,0 @@ } |
@@ -52,2 +52,6 @@ import type { Store } from '#shared'; | ||
}; | ||
/** | ||
* dev mode only: the component function | ||
*/ | ||
function?: any; | ||
}; | ||
@@ -54,0 +58,0 @@ |
@@ -114,3 +114,3 @@ import { noop, run_all } from '../internal/shared/utils.js'; | ||
* @param {S} stores | ||
* @param {(values: import('./private.js').StoresValues<S>) => T} fn | ||
* @param {(values: import('./private.js').StoresValues<S>, set: (value: T) => void, update: (fn: import('./public.js').Updater<T>) => void) => import('./public.js').Unsubscriber | void} fn | ||
* @param {T} [initial_value] | ||
@@ -128,3 +128,3 @@ * @returns {import('./public.js').Readable<T>} | ||
* @param {S} stores | ||
* @param {(values: import('./private.js').StoresValues<S>, set: (value: T) => void, update: (fn: import('./public.js').Updater<T>) => void) => import('./public.js').Unsubscriber | void} fn | ||
* @param {(values: import('./private.js').StoresValues<S>) => T} fn | ||
* @param {T} [initial_value] | ||
@@ -131,0 +131,0 @@ * @returns {import('./public.js').Readable<T>} |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.0.0-next.121'; | ||
export const VERSION = '5.0.0-next.123'; | ||
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 too big to display
Sorry, the diff of this file is not supported yet
2050215
44781