Comparing version 5.0.0-next.237 to 5.0.0-next.238
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.0-next.237", | ||
"version": "5.0.0-next.238", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -210,3 +210,3 @@ /** @import * as ESTree from 'estree' */ | ||
if (binding.kind === 'legacy_reactive') { | ||
legacy_reactive_declarations.push(b.const(name, b.call('$.mutable_source'))); | ||
legacy_reactive_declarations.push(b.const(name, b.call('$.mutable_state'))); | ||
} | ||
@@ -213,0 +213,0 @@ if (binding.kind === 'store_sub') { |
@@ -50,15 +50,6 @@ /** @import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression, Identifier, Pattern, PrivateIdentifier, Statement } from 'estree' */ | ||
* @param {Expression} value | ||
* @param {PrivateIdentifier | string} proxy_reference | ||
* @param {Expression} previous | ||
*/ | ||
export function build_proxy_reassignment(value, proxy_reference) { | ||
return dev | ||
? b.call( | ||
'$.proxy', | ||
value, | ||
b.null, | ||
typeof proxy_reference === 'string' | ||
? b.id(proxy_reference) | ||
: b.member(b.this, proxy_reference) | ||
) | ||
: b.call('$.proxy', value); | ||
export function build_proxy_reassignment(value, previous) { | ||
return dev ? b.call('$.proxy', value, b.null, previous) : b.call('$.proxy', value); | ||
} | ||
@@ -65,0 +56,0 @@ |
@@ -51,3 +51,3 @@ /** @import { AssignmentExpression, AssignmentOperator, Expression, Pattern } from 'estree' */ | ||
? value | ||
: build_proxy_reassignment(value, private_state.id); | ||
: build_proxy_reassignment(value, b.member(b.this, private_state.id)); | ||
} | ||
@@ -99,3 +99,3 @@ | ||
) { | ||
value = binding.kind === 'raw_state' ? value : build_proxy_reassignment(value, object.name); | ||
value = binding.kind === 'raw_state' ? value : build_proxy_reassignment(value, object); | ||
} | ||
@@ -102,0 +102,0 @@ |
@@ -116,7 +116,7 @@ /** @import { ClassBody, Expression, Identifier, Literal, MethodDefinition, PrivateIdentifier, PropertyDefinition } from 'estree' */ | ||
? b.call( | ||
'$.source', | ||
'$.state', | ||
should_proxy(init, context.state.scope) ? b.call('$.proxy', init) : init | ||
) | ||
: field.kind === 'raw_state' | ||
? b.call('$.source', init) | ||
? b.call('$.state', init) | ||
: field.kind === 'derived_by' | ||
@@ -127,3 +127,3 @@ ? b.call('$.derived', init) | ||
// if no arguments, we know it's state as `$derived()` is a compile error | ||
value = b.call('$.source'); | ||
value = b.call('$.state'); | ||
} | ||
@@ -144,2 +144,4 @@ | ||
const value = b.id('value'); | ||
const prev = b.member(b.this, field.id); | ||
body.push( | ||
@@ -150,3 +152,3 @@ b.method( | ||
[value], | ||
[b.stmt(b.call('$.set', member, build_proxy_reassignment(value, field.id)))] | ||
[b.stmt(b.call('$.set', member, build_proxy_reassignment(value, prev)))] | ||
) | ||
@@ -153,0 +155,0 @@ ); |
@@ -63,5 +63,5 @@ /** @import { Expression } from 'estree' */ | ||
function flush_sequence(sequence) { | ||
if (sequence.length === 1 && sequence[0].type === 'Text') { | ||
if (sequence.every((node) => node.type === 'Text')) { | ||
skipped += 1; | ||
state.template.push(sequence[0].raw); | ||
state.template.push(sequence.map((node) => node.raw).join('')); | ||
return; | ||
@@ -68,0 +68,0 @@ } |
@@ -129,3 +129,3 @@ /** @import { CallExpression, Expression, Identifier, Literal, VariableDeclaration, VariableDeclarator } from 'estree' */ | ||
if (is_state_source(binding, context.state.analysis)) { | ||
value = b.call('$.source', value); | ||
value = b.call('$.state', value); | ||
} | ||
@@ -295,3 +295,3 @@ return value; | ||
if (declarator.id.type === 'Identifier') { | ||
return [b.declarator(declarator.id, b.call('$.mutable_source', value))]; | ||
return [b.declarator(declarator.id, b.call('$.mutable_state', value))]; | ||
} | ||
@@ -308,3 +308,3 @@ | ||
path.node, | ||
binding?.kind === 'state' ? b.call('$.mutable_source', value) : value | ||
binding?.kind === 'state' ? b.call('$.mutable_state', value) : value | ||
); | ||
@@ -311,0 +311,0 @@ }) |
@@ -55,6 +55,4 @@ /** @import { Effect, Source, TemplateNode } from '#client' */ | ||
var input_source = runes | ||
? source(/** @type {V} */ (undefined)) | ||
: mutable_source(/** @type {V} */ (undefined)); | ||
var error_source = runes ? source(undefined) : mutable_source(undefined); | ||
var input_source = (runes ? source : mutable_source)(/** @type {V} */ (undefined)); | ||
var error_source = (runes ? source : mutable_source)(undefined); | ||
var resolved = false; | ||
@@ -61,0 +59,0 @@ |
@@ -108,3 +108,3 @@ export { FILENAME, HMR } from '../../constants.js'; | ||
} from './reactivity/effects.js'; | ||
export { mutable_source, mutate, source, set } from './reactivity/sources.js'; | ||
export { mutable_state, mutate, set, state } from './reactivity/sources.js'; | ||
export { | ||
@@ -111,0 +111,0 @@ prop, |
@@ -22,3 +22,3 @@ /** @import { ProxyMetadata, ProxyStateObject, Source } from '#client' */ | ||
* @param {Source<T>} [prev] dev mode only | ||
* @returns {ProxyStateObject<T> | T} | ||
* @returns {T} | ||
*/ | ||
@@ -95,13 +95,13 @@ export function proxy(value, parent = null, prev) { | ||
var s = sources.get(prop); | ||
var exists = s !== undefined ? s.v !== UNINITIALIZED : prop in target; | ||
if (s !== undefined) { | ||
if (s === undefined) { | ||
if (prop in target) { | ||
sources.set(prop, source(UNINITIALIZED)); | ||
} | ||
} else { | ||
set(s, UNINITIALIZED); | ||
} | ||
if (exists) { | ||
update_version(version); | ||
} | ||
return exists; | ||
return true; | ||
}, | ||
@@ -123,3 +123,3 @@ | ||
if (s === undefined && (!exists || get_descriptor(target, prop)?.writable)) { | ||
s = source(proxy(exists ? target[prop] : UNINITIALIZED, metadata), null); | ||
s = source(proxy(exists ? target[prop] : UNINITIALIZED, metadata)); | ||
sources.set(prop, s); | ||
@@ -176,3 +176,3 @@ } | ||
if (s === undefined) { | ||
s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED, null); | ||
s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED); | ||
sources.set(prop, s); | ||
@@ -179,0 +179,0 @@ } |
@@ -37,8 +37,6 @@ /** @import { Derived, Effect, Reaction, Source, Value } from '#client' */ | ||
* @param {V} v | ||
* @param {Reaction | null} [owner] | ||
* @returns {Source<V>} | ||
*/ | ||
/*#__NO_SIDE_EFFECTS__*/ | ||
export function source(v, owner = current_reaction) { | ||
var source = { | ||
export function source(v) { | ||
return { | ||
f: 0, // TODO ideally we could skip this altogether, but it causes type errors | ||
@@ -50,12 +48,10 @@ v, | ||
}; | ||
} | ||
if (owner !== null && (owner.f & DERIVED) !== 0) { | ||
if (derived_sources === null) { | ||
set_derived_sources([source]); | ||
} else { | ||
derived_sources.push(source); | ||
} | ||
} | ||
return source; | ||
/** | ||
* @template V | ||
* @param {V} v | ||
*/ | ||
export function state(v) { | ||
return push_derived_source(source(v)); | ||
} | ||
@@ -66,8 +62,7 @@ | ||
* @param {V} initial_value | ||
* @param {Reaction | null} [owner] | ||
* @returns {Source<V>} | ||
*/ | ||
/*#__NO_SIDE_EFFECTS__*/ | ||
export function mutable_source(initial_value, owner) { | ||
const s = source(initial_value, owner); | ||
export function mutable_source(initial_value) { | ||
const s = source(initial_value); | ||
s.equals = safe_equals; | ||
@@ -86,2 +81,28 @@ | ||
* @template V | ||
* @param {V} v | ||
* @returns {Source<V>} | ||
*/ | ||
export function mutable_state(v) { | ||
return push_derived_source(mutable_source(v)); | ||
} | ||
/** | ||
* @template V | ||
* @param {Source<V>} source | ||
*/ | ||
/*#__NO_SIDE_EFFECTS__*/ | ||
function push_derived_source(source) { | ||
if (current_reaction !== null && (current_reaction.f & DERIVED) !== 0) { | ||
if (derived_sources === null) { | ||
set_derived_sources([source]); | ||
} else { | ||
derived_sources.push(source); | ||
} | ||
} | ||
return source; | ||
} | ||
/** | ||
* @template V | ||
* @param {Value<V>} source | ||
@@ -88,0 +109,0 @@ * @param {V} value |
@@ -22,3 +22,3 @@ /** @import { StoreReferencesContainer } from '#client' */ | ||
store: null, | ||
source: mutable_source(undefined, null), | ||
source: mutable_source(undefined), | ||
unsubscribe: noop | ||
@@ -25,0 +25,0 @@ }); |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.0.0-next.237'; | ||
export const VERSION = '5.0.0-next.238'; | ||
export const PUBLIC_VERSION = '5'; |
Sorry, the diff of this file is too big to display
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
2208681
48948