dedicated binding.kind for legacy reactive imports

proxied-state-each-blocks
Rich Harris 9 months ago
parent 1e2f6cbdba
commit c01fa5c8c8

@ -177,7 +177,7 @@ function get_delegated_event(node, context) {
// or any normal not reactive bindings that are mutated.
binding.kind === 'normal' ||
// or any reactive imports (those are rewritten) (can only happen in legacy mode)
(binding.kind === 'state' && binding.declaration_kind === 'import')) &&
binding.kind === 'legacy_reactive_import') &&
binding.mutated
) {
return non_hoistable;
@ -532,7 +532,7 @@ const legacy_scope_tweaker = {
(state.reactive_statement || state.ast_type === 'template') &&
parent.type === 'MemberExpression'
) {
binding.kind = 'state';
binding.kind = 'legacy_reactive_import';
}
} else if (
binding.mutated &&

@ -159,7 +159,7 @@ export function client_component(source, analysis, options) {
// Very very dirty way of making import statements reactive in legacy mode if needed
if (!analysis.runes) {
for (const [name, binding] of analysis.module.scope.declarations) {
if (binding.kind === 'state' && binding.declaration_kind === 'import') {
if (binding.kind === 'legacy_reactive_import') {
instance.body.unshift(
b.var('$$_import_' + name, b.call('$.reactive_import', b.thunk(b.id(name))))
);

@ -74,7 +74,7 @@ export function serialize_get_binding(node, state) {
return b.call(node);
}
if (binding.kind === 'state' && binding.declaration_kind === 'import') {
if (binding.kind === 'legacy_reactive_import') {
return b.call('$$_import_' + node.name);
}
@ -175,7 +175,7 @@ export function serialize_set_binding(node, context, fallback) {
return binding.mutation(node, context);
}
if (binding.kind === 'state' && binding.declaration_kind === 'import') {
if (binding.kind === 'legacy_reactive_import') {
return b.call(
'$$_import_' + binding.node.name,
b.assignment(

@ -250,6 +250,7 @@ export interface Binding {
* - `each`: An each block context variable
* - `store_sub`: A $store value
* - `legacy_reactive`: A `$:` declaration
* - `legacy_reactive_import`: An imported binding that is mutated inside the component
*/
kind:
| 'normal'
@ -259,7 +260,8 @@ export interface Binding {
| 'derived'
| 'each'
| 'store_sub'
| 'legacy_reactive';
| 'legacy_reactive'
| 'legacy_reactive_import';
declaration_kind: DeclarationKind;
/**
* What the value was initialized with.

Loading…
Cancel
Save