|
|
|
@ -137,86 +137,7 @@ export function ClassBody(node, context) {
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (definition.type === 'PropertyDefinition') {
|
|
|
|
|
// const original_name = get_name(definition.key);
|
|
|
|
|
// if (original_name === null) continue;
|
|
|
|
|
|
|
|
|
|
// const name = definition_names[original_name];
|
|
|
|
|
|
|
|
|
|
// const is_private = definition.key.type === 'PrivateIdentifier';
|
|
|
|
|
// const field = (is_private ? private_state : public_state).get(name);
|
|
|
|
|
|
|
|
|
|
// if (definition.value?.type === 'CallExpression' && field !== undefined) {
|
|
|
|
|
// let value = null;
|
|
|
|
|
|
|
|
|
|
// if (definition.value.arguments.length > 0) {
|
|
|
|
|
// const init = /** @type {Expression} **/ (
|
|
|
|
|
// context.visit(definition.value.arguments[0], child_state)
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// value =
|
|
|
|
|
// field.kind === 'state'
|
|
|
|
|
// ? b.call(
|
|
|
|
|
// '$.state',
|
|
|
|
|
// should_proxy(init, context.state.scope) ? b.call('$.proxy', init) : init
|
|
|
|
|
// )
|
|
|
|
|
// : field.kind === 'raw_state'
|
|
|
|
|
// ? b.call('$.state', init)
|
|
|
|
|
// : field.kind === 'derived_by'
|
|
|
|
|
// ? b.call('$.derived', init)
|
|
|
|
|
// : b.call('$.derived', b.thunk(init));
|
|
|
|
|
// } else {
|
|
|
|
|
// // if no arguments, we know it's state as `$derived()` is a compile error
|
|
|
|
|
// value = b.call('$.state');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (is_private) {
|
|
|
|
|
// body.push(b.prop_def(field.id, value));
|
|
|
|
|
// } else {
|
|
|
|
|
// // #foo;
|
|
|
|
|
// const member = b.member(b.this, field.id);
|
|
|
|
|
// body.push(b.prop_def(field.id, value));
|
|
|
|
|
|
|
|
|
|
// // get foo() { return this.#foo; }
|
|
|
|
|
// body.push(b.method('get', definition.key, [], [b.return(b.call('$.get', member))]));
|
|
|
|
|
|
|
|
|
|
// // set foo(value) { this.#foo = value; }
|
|
|
|
|
// const val = b.id('value');
|
|
|
|
|
|
|
|
|
|
// body.push(
|
|
|
|
|
// b.method(
|
|
|
|
|
// 'set',
|
|
|
|
|
// definition.key,
|
|
|
|
|
// [val],
|
|
|
|
|
// [b.stmt(b.call('$.set', member, val, field.kind === 'state' && b.true))]
|
|
|
|
|
// )
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// body.push(/** @type {MethodDefinition} **/ (context.visit(definition, child_state)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { ...node, body };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @param {Map<string, StateField>} public_state
|
|
|
|
|
*/
|
|
|
|
|
function get_deconflicted_name(name, public_state) {
|
|
|
|
|
name = name.replace(regex_invalid_identifier_chars, '_');
|
|
|
|
|
|
|
|
|
|
// the above could generate conflicts because it has to generate a valid identifier
|
|
|
|
|
// so stuff like `0` and `1` or `state%` and `state^` will result in the same string
|
|
|
|
|
// so we have to de-conflict. We can only check `public_state` because private state
|
|
|
|
|
// can't have literal keys
|
|
|
|
|
while (name && public_state.has(name)) {
|
|
|
|
|
name = '_' + name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|