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 {Expression} value
* @param {PrivateIdentifier | string} proxy_reference * @param {Expression} previous
*/ */
export function build_proxy_reassignment(value, proxy_reference) { export function build_proxy_reassignment(value, previous) {
return dev return dev ? b.call('$.proxy', value, b.null, previous) : b.call('$.proxy', value);
? b.call(
'$.proxy',
value,
b.null,
typeof proxy_reference === 'string'
? b.id(proxy_reference)
: b.member(b.this, proxy_reference)
)
: b.call('$.proxy', value);
} }
/** /**

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

@ -139,12 +139,14 @@ export function ClassBody(node, context) {
if (field.kind === 'state') { if (field.kind === 'state') {
// set foo(value) { this.#foo = value; } // set foo(value) { this.#foo = value; }
const value = b.id('value'); const value = b.id('value');
const prev = b.member(b.this, field.id);
body.push( body.push(
b.method( b.method(
'set', 'set',
definition.key, definition.key,
[value], [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