chore: update proxy reassignment code (#13014)

pull/13015/head
Rich Harris 1 year ago committed by GitHub
parent e7e7ef6d00
commit 574d26071c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -47,19 +47,10 @@ export function build_getter(node, state) {
/**
* @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);
}
/**

@ -48,7 +48,7 @@ function build_assignment(operator, left, right, context) {
value =
private_state.kind === 'raw_state'
? value
: build_proxy_reassignment(value, private_state.id);
: build_proxy_reassignment(value, b.member(b.this, private_state.id));
}
if (!context.state.in_constructor) {
@ -95,7 +95,7 @@ function build_assignment(operator, left, right, context) {
context.state.analysis.runes &&
should_proxy(value, context.state.scope)
) {
value = binding.kind === 'raw_state' ? value : build_proxy_reassignment(value, object.name);
value = binding.kind === 'raw_state' ? value : build_proxy_reassignment(value, object);
}
return transform.assign(object, value);

@ -139,12 +139,14 @@ export function ClassBody(node, context) {
if (field.kind === 'state') {
// set foo(value) { this.#foo = value; }
const value = b.id('value');
const prev = b.member(b.this, field.id);
body.push(
b.method(
'set',
definition.key,
[value],
[b.stmt(b.call('$.set', member, build_proxy_reassignment(value, field.id)))]
[b.stmt(b.call('$.set', member, build_proxy_reassignment(value, prev)))]
)
);
}

Loading…
Cancel
Save