marko 6.0.98 → 6.0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ export declare function _call<T>(fn: (v: T) => unknown, v: T): T;
1
2
  export declare function classValue(classValue: unknown): string;
2
3
  export declare function styleValue(styleValue: unknown): string;
3
4
  export declare function isEventHandler(name: string): name is `on${string}`;
package/dist/debug/dom.js CHANGED
@@ -51,6 +51,7 @@ __export(dom_exports, {
51
51
  _attrs_partial_content: () => _attrs_partial_content,
52
52
  _attrs_script: () => _attrs_script,
53
53
  _await: () => _await,
54
+ _call: () => _call,
54
55
  _child_setup: () => _child_setup,
55
56
  _closure: () => _closure,
56
57
  _closure_get: () => _closure_get,
@@ -177,6 +178,10 @@ function forUntil(until, from, step, cb) {
177
178
  }
178
179
 
179
180
  // src/common/helpers.ts
181
+ function _call(fn, v) {
182
+ fn(v);
183
+ return v;
184
+ }
180
185
  function classValue(classValue2) {
181
186
  return toDelimitedString(classValue2, " ", stringifyClassObject);
182
187
  }
@@ -569,8 +574,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
569
574
  registeredValues[lastEffect](
570
575
  scopeLookup[serialized] ||= {
571
576
  ___id: scopeId
572
- },
573
- scopeLookup[serialized]
577
+ }
574
578
  );
575
579
  } else {
576
580
  for (const scope of serialized(serializeContext)) {
@@ -972,28 +976,17 @@ function _let(valueAccessor, fn) {
972
976
  );
973
977
  }
974
978
  const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
975
- const update = (scope, value) => {
976
- if (scope[valueAccessor] !== value) {
977
- scope[valueAccessor] = value;
978
- fn && fn(scope, value);
979
- }
980
- };
981
979
  return (scope, value, valueChange) => {
982
980
  if (rendering) {
983
981
  if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.___creating) {
984
982
  scope[valueAccessor] = value;
985
- fn && fn(scope, value);
983
+ fn && fn(scope);
986
984
  }
987
985
  } else if (scope[valueChangeAccessor]) {
988
986
  scope[valueChangeAccessor](value);
989
- } else {
987
+ } else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
990
988
  schedule();
991
- queueRender(
992
- scope,
993
- update,
994
- true ? id : valueAccessor,
995
- value
996
- );
989
+ queueRender(scope, fn, true ? id : valueAccessor);
997
990
  }
998
991
  return value;
999
992
  };
@@ -1003,7 +996,7 @@ function _const(valueAccessor, fn = () => {
1003
996
  return (scope, value) => {
1004
997
  if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
1005
998
  scope[valueAccessor] = value;
1006
- fn(scope, value);
999
+ fn(scope);
1007
1000
  }
1008
1001
  };
1009
1002
  }
@@ -1020,8 +1013,7 @@ function _or(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "___id
1020
1013
  }
1021
1014
  };
1022
1015
  }
1023
- function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
1024
- const childSignal = closure(valueAccessor, fn);
1016
+ function _for_closure(ownerLoopNodeAccessor, fn) {
1025
1017
  const loopScopeAccessor = "LoopScopeArray:" /* LoopScopeArray */ + ownerLoopNodeAccessor;
1026
1018
  const loopScopeMapAccessor = "LoopScopeMap:" /* LoopScopeMap */ + ownerLoopNodeAccessor;
1027
1019
  const ownerSignal = (ownerScope) => {
@@ -1033,7 +1025,7 @@ function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
1033
1025
  () => {
1034
1026
  for (const scope of scopes) {
1035
1027
  if (!scope.___creating && !scope.___destroyed) {
1036
- childSignal(scope);
1028
+ fn(scope);
1037
1029
  }
1038
1030
  }
1039
1031
  },
@@ -1043,20 +1035,19 @@ function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
1043
1035
  );
1044
1036
  }
1045
1037
  };
1046
- ownerSignal._ = childSignal;
1038
+ ownerSignal._ = fn;
1047
1039
  return ownerSignal;
1048
1040
  }
1049
- function _if_closure(valueAccessor, ownerConditionalNodeAccessor, branch, fn) {
1050
- const childSignal = closure(valueAccessor, fn);
1041
+ function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
1051
1042
  const scopeAccessor = "ConditionalScope:" /* ConditionalScope */ + ownerConditionalNodeAccessor;
1052
1043
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
1053
1044
  const ownerSignal = (scope) => {
1054
1045
  const ifScope = scope[scopeAccessor];
1055
1046
  if (ifScope && !ifScope.___creating && (scope[branchAccessor] || 0) === branch) {
1056
- queueRender(ifScope, childSignal, -1);
1047
+ queueRender(ifScope, fn, -1);
1057
1048
  }
1058
1049
  };
1059
- ownerSignal._ = childSignal;
1050
+ ownerSignal._ = fn;
1060
1051
  return ownerSignal;
1061
1052
  }
1062
1053
  function subscribeToScopeSet(ownerScope, accessor, scope) {
@@ -1089,10 +1080,9 @@ function _closure(...closureSignals) {
1089
1080
  };
1090
1081
  }
1091
1082
  function _closure_get(valueAccessor, fn, getOwnerScope) {
1092
- const childSignal = closure(valueAccessor, fn, getOwnerScope);
1093
1083
  const closureSignal = ((scope) => {
1094
1084
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
1095
- childSignal(scope);
1085
+ fn(scope);
1096
1086
  subscribeToScopeSet(
1097
1087
  getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
1098
1088
  closureSignal.___scopeInstancesAccessor,
@@ -1103,14 +1093,6 @@ function _closure_get(valueAccessor, fn, getOwnerScope) {
1103
1093
  closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
1104
1094
  return closureSignal;
1105
1095
  }
1106
- function closure(valueAccessor, fn, getOwnerScope) {
1107
- return (scope) => {
1108
- fn(
1109
- scope,
1110
- (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */])[valueAccessor]
1111
- );
1112
- };
1113
- }
1114
1096
  function _child_setup(setup) {
1115
1097
  setup._ = (scope, owner) => {
1116
1098
  scope["_" /* Owner */] = owner;
@@ -2164,11 +2146,8 @@ function prepareEffects(fn) {
2164
2146
  return preparedEffects;
2165
2147
  }
2166
2148
  var runEffects = ((effects) => {
2167
- for (let i = 0, scope; i < effects.length; ) {
2168
- effects[i++](
2169
- scope = effects[i++],
2170
- scope
2171
- );
2149
+ for (let i = 0; i < effects.length; ) {
2150
+ effects[i++](effects[i++]);
2172
2151
  }
2173
2152
  });
2174
2153
  function runRenders() {
@@ -2227,7 +2206,7 @@ var _enable_catch = () => {
2227
2206
  scope = effects[i++];
2228
2207
  branch = scope.___closestBranch;
2229
2208
  if (!branch?.___destroyed && !(checkPending && handlePendingTry(fn, scope, branch))) {
2230
- fn(scope, scope);
2209
+ fn(scope);
2231
2210
  }
2232
2211
  }
2233
2212
  } else {
@@ -75,6 +75,10 @@ function forUntil(until, from, step, cb) {
75
75
  }
76
76
 
77
77
  // src/common/helpers.ts
78
+ function _call(fn, v) {
79
+ fn(v);
80
+ return v;
81
+ }
78
82
  function classValue(classValue2) {
79
83
  return toDelimitedString(classValue2, " ", stringifyClassObject);
80
84
  }
@@ -467,8 +471,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
467
471
  registeredValues[lastEffect](
468
472
  scopeLookup[serialized] ||= {
469
473
  ___id: scopeId
470
- },
471
- scopeLookup[serialized]
474
+ }
472
475
  );
473
476
  } else {
474
477
  for (const scope of serialized(serializeContext)) {
@@ -870,28 +873,17 @@ function _let(valueAccessor, fn) {
870
873
  );
871
874
  }
872
875
  const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
873
- const update = (scope, value) => {
874
- if (scope[valueAccessor] !== value) {
875
- scope[valueAccessor] = value;
876
- fn && fn(scope, value);
877
- }
878
- };
879
876
  return (scope, value, valueChange) => {
880
877
  if (rendering) {
881
878
  if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.___creating) {
882
879
  scope[valueAccessor] = value;
883
- fn && fn(scope, value);
880
+ fn && fn(scope);
884
881
  }
885
882
  } else if (scope[valueChangeAccessor]) {
886
883
  scope[valueChangeAccessor](value);
887
- } else {
884
+ } else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
888
885
  schedule();
889
- queueRender(
890
- scope,
891
- update,
892
- true ? id : valueAccessor,
893
- value
894
- );
886
+ queueRender(scope, fn, true ? id : valueAccessor);
895
887
  }
896
888
  return value;
897
889
  };
@@ -901,7 +893,7 @@ function _const(valueAccessor, fn = () => {
901
893
  return (scope, value) => {
902
894
  if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
903
895
  scope[valueAccessor] = value;
904
- fn(scope, value);
896
+ fn(scope);
905
897
  }
906
898
  };
907
899
  }
@@ -918,8 +910,7 @@ function _or(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "___id
918
910
  }
919
911
  };
920
912
  }
921
- function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
922
- const childSignal = closure(valueAccessor, fn);
913
+ function _for_closure(ownerLoopNodeAccessor, fn) {
923
914
  const loopScopeAccessor = "LoopScopeArray:" /* LoopScopeArray */ + ownerLoopNodeAccessor;
924
915
  const loopScopeMapAccessor = "LoopScopeMap:" /* LoopScopeMap */ + ownerLoopNodeAccessor;
925
916
  const ownerSignal = (ownerScope) => {
@@ -931,7 +922,7 @@ function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
931
922
  () => {
932
923
  for (const scope of scopes) {
933
924
  if (!scope.___creating && !scope.___destroyed) {
934
- childSignal(scope);
925
+ fn(scope);
935
926
  }
936
927
  }
937
928
  },
@@ -941,20 +932,19 @@ function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
941
932
  );
942
933
  }
943
934
  };
944
- ownerSignal._ = childSignal;
935
+ ownerSignal._ = fn;
945
936
  return ownerSignal;
946
937
  }
947
- function _if_closure(valueAccessor, ownerConditionalNodeAccessor, branch, fn) {
948
- const childSignal = closure(valueAccessor, fn);
938
+ function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
949
939
  const scopeAccessor = "ConditionalScope:" /* ConditionalScope */ + ownerConditionalNodeAccessor;
950
940
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
951
941
  const ownerSignal = (scope) => {
952
942
  const ifScope = scope[scopeAccessor];
953
943
  if (ifScope && !ifScope.___creating && (scope[branchAccessor] || 0) === branch) {
954
- queueRender(ifScope, childSignal, -1);
944
+ queueRender(ifScope, fn, -1);
955
945
  }
956
946
  };
957
- ownerSignal._ = childSignal;
947
+ ownerSignal._ = fn;
958
948
  return ownerSignal;
959
949
  }
960
950
  function subscribeToScopeSet(ownerScope, accessor, scope) {
@@ -987,10 +977,9 @@ function _closure(...closureSignals) {
987
977
  };
988
978
  }
989
979
  function _closure_get(valueAccessor, fn, getOwnerScope) {
990
- const childSignal = closure(valueAccessor, fn, getOwnerScope);
991
980
  const closureSignal = ((scope) => {
992
981
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
993
- childSignal(scope);
982
+ fn(scope);
994
983
  subscribeToScopeSet(
995
984
  getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
996
985
  closureSignal.___scopeInstancesAccessor,
@@ -1001,14 +990,6 @@ function _closure_get(valueAccessor, fn, getOwnerScope) {
1001
990
  closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
1002
991
  return closureSignal;
1003
992
  }
1004
- function closure(valueAccessor, fn, getOwnerScope) {
1005
- return (scope) => {
1006
- fn(
1007
- scope,
1008
- (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */])[valueAccessor]
1009
- );
1010
- };
1011
- }
1012
993
  function _child_setup(setup) {
1013
994
  setup._ = (scope, owner) => {
1014
995
  scope["_" /* Owner */] = owner;
@@ -2062,11 +2043,8 @@ function prepareEffects(fn) {
2062
2043
  return preparedEffects;
2063
2044
  }
2064
2045
  var runEffects = ((effects) => {
2065
- for (let i = 0, scope; i < effects.length; ) {
2066
- effects[i++](
2067
- scope = effects[i++],
2068
- scope
2069
- );
2046
+ for (let i = 0; i < effects.length; ) {
2047
+ effects[i++](effects[i++]);
2070
2048
  }
2071
2049
  });
2072
2050
  function runRenders() {
@@ -2125,7 +2103,7 @@ var _enable_catch = () => {
2125
2103
  scope = effects[i++];
2126
2104
  branch = scope.___closestBranch;
2127
2105
  if (!branch?.___destroyed && !(checkPending && handlePendingTry(fn, scope, branch))) {
2128
- fn(scope, scope);
2106
+ fn(scope);
2129
2107
  }
2130
2108
  }
2131
2109
  } else {
@@ -2387,6 +2365,7 @@ export {
2387
2365
  _attrs_partial_content,
2388
2366
  _attrs_script,
2389
2367
  _await,
2368
+ _call,
2390
2369
  _child_setup,
2391
2370
  _closure,
2392
2371
  _closure_get,
@@ -18,6 +18,6 @@ export declare function _content(id: string, template: string | 0, walks?: strin
18
18
  _: Signal<unknown>;
19
19
  } | SetupFn | 0, params?: Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
20
20
  export declare function _content_resume(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
21
- export declare function _content_closures(renderer: ReturnType<typeof _content>, closureFns: Record<Accessor, SignalFn<unknown>>): (owner: Scope, closureValues: Record<Accessor, unknown>) => Renderer;
21
+ export declare function _content_closures(renderer: ReturnType<typeof _content>, closureFns: Record<Accessor, SignalFn>): (owner: Scope, closureValues: Record<Accessor, unknown>) => Renderer;
22
22
  export declare function _content_branch(template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0): Renderer;
23
23
  export {};
@@ -1,23 +1,23 @@
1
1
  import { type Accessor, type Scope } from "../common/types";
2
- export type SignalFn<T> = (scope: Scope, value?: T) => void;
3
- export type Signal<T> = SignalFn<T> & {
2
+ export type SignalFn = (scope: Scope) => void;
3
+ export type Signal<T> = ((scope: Scope, value: T) => void) & {
4
4
  ___subscribe?(scope: Scope): void;
5
5
  };
6
- export declare function _let<T>(valueAccessor: Accessor, fn?: SignalFn<T>): (scope: Scope, value: T, valueChange?: (v: T) => void) => T;
7
- export declare function _const<T>(valueAccessor: Accessor, fn?: SignalFn<T>): Signal<T>;
8
- export declare function _or(id: number, fn: SignalFn<never>, defaultPending?: number, scopeIdAccessor?: Accessor): Signal<never>;
9
- export declare function _for_closure<T>(valueAccessor: Accessor, ownerLoopNodeAccessor: Accessor, fn: SignalFn<T>): SignalFn<T>;
10
- export declare function _if_closure<T>(valueAccessor: Accessor, ownerConditionalNodeAccessor: Accessor, branch: number, fn: SignalFn<T>): SignalFn<T>;
6
+ export declare function _let<T>(valueAccessor: Accessor, fn?: SignalFn): (scope: Scope, value: T, valueChange?: (v: T) => void) => T;
7
+ export declare function _const<T>(valueAccessor: Accessor, fn?: SignalFn): Signal<T>;
8
+ export declare function _or(id: number, fn: SignalFn, defaultPending?: number, scopeIdAccessor?: Accessor): Signal<never>;
9
+ export declare function _for_closure(ownerLoopNodeAccessor: Accessor, fn: SignalFn): SignalFn;
10
+ export declare function _if_closure(ownerConditionalNodeAccessor: Accessor, branch: number, fn: SignalFn): SignalFn;
11
11
  export declare function subscribeToScopeSet(ownerScope: Scope, accessor: Accessor, scope: Scope): void;
12
12
  export declare function _closure(...closureSignals: ReturnType<typeof _closure_get>[]): (scope: Scope) => void;
13
- export declare function _closure_get<T>(valueAccessor: Accessor, fn: Signal<T>, getOwnerScope?: (scope: Scope) => Scope): ((scope: Scope) => void) & {
13
+ export declare function _closure_get(valueAccessor: Accessor, fn: SignalFn, getOwnerScope?: (scope: Scope) => Scope): SignalFn & {
14
14
  ___scopeInstancesAccessor: string;
15
15
  ___signalIndexAccessor: string;
16
16
  ___index: number;
17
17
  };
18
18
  export declare function _child_setup(setup: Signal<never> & {
19
19
  _: Signal<Scope>;
20
- }): SignalFn<never> & {
20
+ }): ((scope: Scope, value: never) => void) & {
21
21
  ___subscribe?(scope: Scope): void;
22
22
  } & {
23
23
  _: Signal<Scope>;
package/dist/dom.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { attrTag, attrTags } from "./common/attr-tag";
2
2
  export { _assert_hoist } from "./common/errors";
3
3
  export { forIn, forOf, forTo, forUntil } from "./common/for";
4
+ export { _call } from "./common/helpers";
4
5
  export { $signal, $signalReset } from "./dom/abort-signal";
5
6
  export { compat } from "./dom/compat";
6
7
  export { _await, _dynamic_tag, _for_in, _for_of, _for_to, _for_until, _if, _try, } from "./dom/control-flow";
package/dist/dom.js CHANGED
@@ -48,6 +48,7 @@ __export(dom_exports, {
48
48
  _attrs_partial_content: () => _attrs_partial_content,
49
49
  _attrs_script: () => _attrs_script,
50
50
  _await: () => _await,
51
+ _call: () => _call,
51
52
  _child_setup: () => _child_setup,
52
53
  _closure: () => _closure,
53
54
  _closure_get: () => _closure_get,
@@ -137,6 +138,9 @@ function forUntil(until, from, step, cb) {
137
138
  }
138
139
 
139
140
  // src/common/helpers.ts
141
+ function _call(fn, v) {
142
+ return fn(v), v;
143
+ }
140
144
  function classValue(classValue2) {
141
145
  return toDelimitedString(classValue2, " ", stringifyClassObject);
142
146
  }
@@ -367,8 +371,7 @@ function init(runtimeId = "M") {
367
371
  registeredValues[lastEffect](
368
372
  scopeLookup[serialized] ||= {
369
373
  l: scopeId
370
- },
371
- scopeLookup[serialized]
374
+ }
372
375
  );
373
376
  else
374
377
  for (let scope of serialized(serializeContext))
@@ -618,20 +621,13 @@ function triggerMacroTask() {
618
621
  function _let(valueAccessor, fn) {
619
622
  if (0)
620
623
  var id;
621
- let valueChangeAccessor = "o" /* TagVariableChange */ + valueAccessor, update = (scope, value) => {
622
- scope[valueAccessor] !== value && (scope[valueAccessor] = value, fn && fn(scope, value));
623
- };
624
- return (scope, value, valueChange) => (rendering ? ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.n) && (scope[valueAccessor] = value, fn && fn(scope, value)) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : (schedule(), queueRender(
625
- scope,
626
- update,
627
- valueAccessor,
628
- value
629
- )), value);
624
+ let valueChangeAccessor = "o" /* TagVariableChange */ + valueAccessor;
625
+ return (scope, value, valueChange) => (rendering ? ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.n) && (scope[valueAccessor] = value, fn && fn(scope)) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : scope[valueAccessor] !== (scope[valueAccessor] = value) && fn && (schedule(), queueRender(scope, fn, valueAccessor)), value);
630
626
  }
631
627
  function _const(valueAccessor, fn = () => {
632
628
  }) {
633
629
  return (scope, value) => {
634
- (!(valueAccessor in scope) || scope[valueAccessor] !== value) && (scope[valueAccessor] = value, fn(scope, value));
630
+ (!(valueAccessor in scope) || scope[valueAccessor] !== value) && (scope[valueAccessor] = value, fn(scope));
635
631
  };
636
632
  }
637
633
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "l") {
@@ -639,28 +635,28 @@ function _or(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "l") {
639
635
  scope.n ? scope[id] === void 0 ? scope[id] = defaultPending : --scope[id] || fn(scope) : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
640
636
  };
641
637
  }
642
- function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
643
- let childSignal = closure(valueAccessor, fn), loopScopeAccessor = "l" /* LoopScopeArray */ + ownerLoopNodeAccessor, loopScopeMapAccessor = "m" /* LoopScopeMap */ + ownerLoopNodeAccessor, ownerSignal = (ownerScope) => {
638
+ function _for_closure(ownerLoopNodeAccessor, fn) {
639
+ let loopScopeAccessor = "l" /* LoopScopeArray */ + ownerLoopNodeAccessor, loopScopeMapAccessor = "m" /* LoopScopeMap */ + ownerLoopNodeAccessor, ownerSignal = (ownerScope) => {
644
640
  let scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [], [firstScope] = scopes;
645
641
  firstScope && queueRender(
646
642
  ownerScope,
647
643
  () => {
648
644
  for (let scope of scopes)
649
- !scope.n && !scope.z && childSignal(scope);
645
+ !scope.n && !scope.z && fn(scope);
650
646
  },
651
647
  -1,
652
648
  0,
653
649
  firstScope.l
654
650
  );
655
651
  };
656
- return ownerSignal._ = childSignal, ownerSignal;
652
+ return ownerSignal._ = fn, ownerSignal;
657
653
  }
658
- function _if_closure(valueAccessor, ownerConditionalNodeAccessor, branch, fn) {
659
- let childSignal = closure(valueAccessor, fn), scopeAccessor = "d" /* ConditionalScope */ + ownerConditionalNodeAccessor, branchAccessor = "c" /* ConditionalRenderer */ + ownerConditionalNodeAccessor, ownerSignal = (scope) => {
654
+ function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
655
+ let scopeAccessor = "d" /* ConditionalScope */ + ownerConditionalNodeAccessor, branchAccessor = "c" /* ConditionalRenderer */ + ownerConditionalNodeAccessor, ownerSignal = (scope) => {
660
656
  let ifScope = scope[scopeAccessor];
661
- ifScope && !ifScope.n && (scope[branchAccessor] || 0) === branch && queueRender(ifScope, childSignal, -1);
657
+ ifScope && !ifScope.n && (scope[branchAccessor] || 0) === branch && queueRender(ifScope, fn, -1);
662
658
  };
663
- return ownerSignal._ = childSignal, ownerSignal;
659
+ return ownerSignal._ = fn, ownerSignal;
664
660
  }
665
661
  function subscribeToScopeSet(ownerScope, accessor, scope) {
666
662
  let subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
@@ -684,8 +680,8 @@ function _closure(...closureSignals) {
684
680
  };
685
681
  }
686
682
  function _closure_get(valueAccessor, fn, getOwnerScope) {
687
- let childSignal = closure(valueAccessor, fn, getOwnerScope), closureSignal = ((scope) => {
688
- scope[closureSignal.E] = closureSignal.K, childSignal(scope), subscribeToScopeSet(
683
+ let closureSignal = ((scope) => {
684
+ scope[closureSignal.E] = closureSignal.K, fn(scope), subscribeToScopeSet(
689
685
  getOwnerScope ? getOwnerScope(scope) : scope._,
690
686
  closureSignal.D,
691
687
  scope
@@ -693,14 +689,6 @@ function _closure_get(valueAccessor, fn, getOwnerScope) {
693
689
  });
694
690
  return closureSignal.D = "a" /* ClosureScopes */ + valueAccessor, closureSignal.E = "b" /* ClosureSignalIndex */ + valueAccessor, closureSignal;
695
691
  }
696
- function closure(valueAccessor, fn, getOwnerScope) {
697
- return (scope) => {
698
- fn(
699
- scope,
700
- (getOwnerScope ? getOwnerScope(scope) : scope._)[valueAccessor]
701
- );
702
- };
703
- }
704
692
  function _child_setup(setup) {
705
693
  return setup._ = (scope, owner) => {
706
694
  scope._ = owner, queueRender(scope, setup, -1);
@@ -1388,11 +1376,8 @@ function prepareEffects(fn) {
1388
1376
  return preparedEffects;
1389
1377
  }
1390
1378
  var runEffects = ((effects) => {
1391
- for (let i = 0, scope; i < effects.length; )
1392
- effects[i++](
1393
- scope = effects[i++],
1394
- scope
1395
- );
1379
+ for (let i = 0; i < effects.length; )
1380
+ effects[i++](effects[i++]);
1396
1381
  });
1397
1382
  function runRenders() {
1398
1383
  for (; pendingRenders.length; ) {
@@ -1427,7 +1412,7 @@ var runRender = (render) => render.M(render.q, render.H), _enable_catch = () =>
1427
1412
  if (checkPending || caughtError.has(effects)) {
1428
1413
  let i = 0, fn, scope, branch;
1429
1414
  for (; i < effects.length; )
1430
- fn = effects[i++], scope = effects[i++], branch = scope.k, !branch?.z && !(checkPending && handlePendingTry(fn, scope, branch)) && fn(scope, scope);
1415
+ fn = effects[i++], scope = effects[i++], branch = scope.k, !branch?.z && !(checkPending && handlePendingTry(fn, scope, branch)) && fn(scope);
1431
1416
  } else
1432
1417
  runEffects2(effects);
1433
1418
  })(runEffects), runRender = /* @__PURE__ */ ((runRender2) => (render) => {
package/dist/dom.mjs CHANGED
@@ -38,6 +38,9 @@ function forUntil(until, from, step, cb) {
38
38
  }
39
39
 
40
40
  // src/common/helpers.ts
41
+ function _call(fn, v) {
42
+ return fn(v), v;
43
+ }
41
44
  function classValue(classValue2) {
42
45
  return toDelimitedString(classValue2, " ", stringifyClassObject);
43
46
  }
@@ -268,8 +271,7 @@ function init(runtimeId = "M") {
268
271
  registeredValues[lastEffect](
269
272
  scopeLookup[serialized] ||= {
270
273
  l: scopeId
271
- },
272
- scopeLookup[serialized]
274
+ }
273
275
  );
274
276
  else
275
277
  for (let scope of serialized(serializeContext))
@@ -519,20 +521,13 @@ function triggerMacroTask() {
519
521
  function _let(valueAccessor, fn) {
520
522
  if (0)
521
523
  var id;
522
- let valueChangeAccessor = "o" /* TagVariableChange */ + valueAccessor, update = (scope, value) => {
523
- scope[valueAccessor] !== value && (scope[valueAccessor] = value, fn && fn(scope, value));
524
- };
525
- return (scope, value, valueChange) => (rendering ? ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.n) && (scope[valueAccessor] = value, fn && fn(scope, value)) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : (schedule(), queueRender(
526
- scope,
527
- update,
528
- valueAccessor,
529
- value
530
- )), value);
524
+ let valueChangeAccessor = "o" /* TagVariableChange */ + valueAccessor;
525
+ return (scope, value, valueChange) => (rendering ? ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.n) && (scope[valueAccessor] = value, fn && fn(scope)) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : scope[valueAccessor] !== (scope[valueAccessor] = value) && fn && (schedule(), queueRender(scope, fn, valueAccessor)), value);
531
526
  }
532
527
  function _const(valueAccessor, fn = () => {
533
528
  }) {
534
529
  return (scope, value) => {
535
- (!(valueAccessor in scope) || scope[valueAccessor] !== value) && (scope[valueAccessor] = value, fn(scope, value));
530
+ (!(valueAccessor in scope) || scope[valueAccessor] !== value) && (scope[valueAccessor] = value, fn(scope));
536
531
  };
537
532
  }
538
533
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "l") {
@@ -540,28 +535,28 @@ function _or(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "l") {
540
535
  scope.n ? scope[id] === void 0 ? scope[id] = defaultPending : --scope[id] || fn(scope) : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
541
536
  };
542
537
  }
543
- function _for_closure(valueAccessor, ownerLoopNodeAccessor, fn) {
544
- let childSignal = closure(valueAccessor, fn), loopScopeAccessor = "l" /* LoopScopeArray */ + ownerLoopNodeAccessor, loopScopeMapAccessor = "m" /* LoopScopeMap */ + ownerLoopNodeAccessor, ownerSignal = (ownerScope) => {
538
+ function _for_closure(ownerLoopNodeAccessor, fn) {
539
+ let loopScopeAccessor = "l" /* LoopScopeArray */ + ownerLoopNodeAccessor, loopScopeMapAccessor = "m" /* LoopScopeMap */ + ownerLoopNodeAccessor, ownerSignal = (ownerScope) => {
545
540
  let scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [], [firstScope] = scopes;
546
541
  firstScope && queueRender(
547
542
  ownerScope,
548
543
  () => {
549
544
  for (let scope of scopes)
550
- !scope.n && !scope.z && childSignal(scope);
545
+ !scope.n && !scope.z && fn(scope);
551
546
  },
552
547
  -1,
553
548
  0,
554
549
  firstScope.l
555
550
  );
556
551
  };
557
- return ownerSignal._ = childSignal, ownerSignal;
552
+ return ownerSignal._ = fn, ownerSignal;
558
553
  }
559
- function _if_closure(valueAccessor, ownerConditionalNodeAccessor, branch, fn) {
560
- let childSignal = closure(valueAccessor, fn), scopeAccessor = "d" /* ConditionalScope */ + ownerConditionalNodeAccessor, branchAccessor = "c" /* ConditionalRenderer */ + ownerConditionalNodeAccessor, ownerSignal = (scope) => {
554
+ function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
555
+ let scopeAccessor = "d" /* ConditionalScope */ + ownerConditionalNodeAccessor, branchAccessor = "c" /* ConditionalRenderer */ + ownerConditionalNodeAccessor, ownerSignal = (scope) => {
561
556
  let ifScope = scope[scopeAccessor];
562
- ifScope && !ifScope.n && (scope[branchAccessor] || 0) === branch && queueRender(ifScope, childSignal, -1);
557
+ ifScope && !ifScope.n && (scope[branchAccessor] || 0) === branch && queueRender(ifScope, fn, -1);
563
558
  };
564
- return ownerSignal._ = childSignal, ownerSignal;
559
+ return ownerSignal._ = fn, ownerSignal;
565
560
  }
566
561
  function subscribeToScopeSet(ownerScope, accessor, scope) {
567
562
  let subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
@@ -585,8 +580,8 @@ function _closure(...closureSignals) {
585
580
  };
586
581
  }
587
582
  function _closure_get(valueAccessor, fn, getOwnerScope) {
588
- let childSignal = closure(valueAccessor, fn, getOwnerScope), closureSignal = ((scope) => {
589
- scope[closureSignal.E] = closureSignal.K, childSignal(scope), subscribeToScopeSet(
583
+ let closureSignal = ((scope) => {
584
+ scope[closureSignal.E] = closureSignal.K, fn(scope), subscribeToScopeSet(
590
585
  getOwnerScope ? getOwnerScope(scope) : scope._,
591
586
  closureSignal.D,
592
587
  scope
@@ -594,14 +589,6 @@ function _closure_get(valueAccessor, fn, getOwnerScope) {
594
589
  });
595
590
  return closureSignal.D = "a" /* ClosureScopes */ + valueAccessor, closureSignal.E = "b" /* ClosureSignalIndex */ + valueAccessor, closureSignal;
596
591
  }
597
- function closure(valueAccessor, fn, getOwnerScope) {
598
- return (scope) => {
599
- fn(
600
- scope,
601
- (getOwnerScope ? getOwnerScope(scope) : scope._)[valueAccessor]
602
- );
603
- };
604
- }
605
592
  function _child_setup(setup) {
606
593
  return setup._ = (scope, owner) => {
607
594
  scope._ = owner, queueRender(scope, setup, -1);
@@ -1289,11 +1276,8 @@ function prepareEffects(fn) {
1289
1276
  return preparedEffects;
1290
1277
  }
1291
1278
  var runEffects = ((effects) => {
1292
- for (let i = 0, scope; i < effects.length; )
1293
- effects[i++](
1294
- scope = effects[i++],
1295
- scope
1296
- );
1279
+ for (let i = 0; i < effects.length; )
1280
+ effects[i++](effects[i++]);
1297
1281
  });
1298
1282
  function runRenders() {
1299
1283
  for (; pendingRenders.length; ) {
@@ -1328,7 +1312,7 @@ var runRender = (render) => render.M(render.q, render.H), _enable_catch = () =>
1328
1312
  if (checkPending || caughtError.has(effects)) {
1329
1313
  let i = 0, fn, scope, branch;
1330
1314
  for (; i < effects.length; )
1331
- fn = effects[i++], scope = effects[i++], branch = scope.k, !branch?.z && !(checkPending && handlePendingTry(fn, scope, branch)) && fn(scope, scope);
1315
+ fn = effects[i++], scope = effects[i++], branch = scope.k, !branch?.z && !(checkPending && handlePendingTry(fn, scope, branch)) && fn(scope);
1332
1316
  } else
1333
1317
  runEffects2(effects);
1334
1318
  })(runEffects), runRender = /* @__PURE__ */ ((runRender2) => (render) => {
@@ -1511,6 +1495,7 @@ export {
1511
1495
  _attrs_partial_content,
1512
1496
  _attrs_script,
1513
1497
  _await,
1498
+ _call,
1514
1499
  _child_setup,
1515
1500
  _closure,
1516
1501
  _closure_get,
@@ -719,6 +719,20 @@ function getFnRoot(path5) {
719
719
  }
720
720
  return fnPath;
721
721
  }
722
+ function getFnParent(path5) {
723
+ let curPath = path5;
724
+ while (!isMarko(curPath)) {
725
+ if (isFunction(curPath)) {
726
+ return curPath;
727
+ }
728
+ const parentPath = curPath.parentPath;
729
+ if (parentPath) {
730
+ curPath = parentPath;
731
+ } else {
732
+ break;
733
+ }
734
+ }
735
+ }
722
736
  function getDeclarationRoot(path5) {
723
737
  let curPath = path5;
724
738
  let declPath;
@@ -3130,45 +3144,6 @@ function getDeclaredBindingExpression(binding) {
3130
3144
 
3131
3145
  // src/translator/util/scope-read.ts
3132
3146
  var import_compiler19 = require("@marko/compiler");
3133
- function createScopeReadPattern(section, referencedBindings) {
3134
- const rootDepth = section.depth;
3135
- const rootPattern = import_compiler19.types.objectPattern([]);
3136
- let nestedPatterns;
3137
- forEach(referencedBindings, (ref) => {
3138
- const propertyValue = ref.name;
3139
- if (!isValidPropertyIdentifier(propertyValue)) return;
3140
- const propertyKey = getScopeAccessor(ref);
3141
- const isShorthand = propertyKey === propertyValue;
3142
- let pattern = rootPattern;
3143
- if (ref.section !== section && ref.type !== 4 /* local */) {
3144
- if (!nestedPatterns) nestedPatterns = [rootPattern];
3145
- const relativeDepth = rootDepth - ref.section.depth;
3146
- let i = nestedPatterns.length;
3147
- let prev = nestedPatterns[i - 1];
3148
- for (; i <= relativeDepth; i++) {
3149
- const nestedPattern = import_compiler19.types.objectPattern([]);
3150
- prev.properties.push(
3151
- import_compiler19.types.objectProperty(
3152
- import_compiler19.types.identifier(getAccessorProp().Owner),
3153
- nestedPattern
3154
- )
3155
- );
3156
- nestedPatterns.push(nestedPattern);
3157
- prev = nestedPattern;
3158
- }
3159
- pattern = nestedPatterns[relativeDepth];
3160
- }
3161
- pattern.properties.push(
3162
- import_compiler19.types.objectProperty(
3163
- toPropertyName(propertyKey),
3164
- import_compiler19.types.identifier(propertyValue),
3165
- false,
3166
- isShorthand
3167
- )
3168
- );
3169
- });
3170
- return rootPattern;
3171
- }
3172
3147
  function getScopeExpression(section, targetSection) {
3173
3148
  let scope = scopeIdentifier ?? import_compiler19.types.identifier("undefined");
3174
3149
  const diff = section.depth - targetSection.depth;
@@ -3183,7 +3158,7 @@ function getScopeExpression(section, targetSection) {
3183
3158
  function createScopeReadExpression(section, reference) {
3184
3159
  const propName = toPropertyName(getScopeAccessor(reference));
3185
3160
  return import_compiler19.types.memberExpression(
3186
- getScopeExpression(section, reference.section),
3161
+ reference.type === 4 /* local */ ? scopeIdentifier : getScopeExpression(section, reference.section),
3187
3162
  propName,
3188
3163
  propName.type !== "Identifier"
3189
3164
  );
@@ -3393,20 +3368,10 @@ function signalHasStatements(signal) {
3393
3368
  function getSignalFn(signal) {
3394
3369
  const section = signal.section;
3395
3370
  const binding = signal.referencedBindings;
3396
- const params = [scopeIdentifier];
3397
3371
  const isIntersection = Array.isArray(binding);
3398
3372
  const isBinding = binding && !isIntersection;
3399
3373
  const isValue = isBinding && binding.section === section;
3400
3374
  const assertsHoists = isValue && binding.hoists.size && !isOptimize();
3401
- if (isBinding && (signal.renderReferencedBindings || assertsHoists || binding.aliases.size || binding.propertyAliases.size)) {
3402
- const valueParam = import_compiler22.types.identifier(binding.name);
3403
- if (binding.loc) {
3404
- valueParam.loc = binding.loc;
3405
- valueParam.start = binding.loc.start.index;
3406
- valueParam.end = binding.loc.end.index;
3407
- }
3408
- params.push(valueParam);
3409
- }
3410
3375
  if (isValue) {
3411
3376
  for (const alias of binding.aliases) {
3412
3377
  const aliasSignal = getSignal(alias.section, alias);
@@ -3438,7 +3403,7 @@ function getSignalFn(signal) {
3438
3403
  ...getTranslatedExtraArgs(aliasSignal)
3439
3404
  ])
3440
3405
  ),
3441
- [import_compiler22.types.identifier(binding.name)]
3406
+ [createScopeReadExpression(binding.section, binding)]
3442
3407
  )
3443
3408
  )
3444
3409
  );
@@ -3447,7 +3412,7 @@ function getSignalFn(signal) {
3447
3412
  import_compiler22.types.expressionStatement(
3448
3413
  import_compiler22.types.callExpression(aliasSignal.identifier, [
3449
3414
  scopeIdentifier,
3450
- import_compiler22.types.identifier(binding.name),
3415
+ createScopeReadExpression(binding.section, binding),
3451
3416
  ...getTranslatedExtraArgs(aliasSignal)
3452
3417
  ])
3453
3418
  )
@@ -3462,7 +3427,7 @@ function getSignalFn(signal) {
3462
3427
  import_compiler22.types.callExpression(aliasSignal.identifier, [
3463
3428
  scopeIdentifier,
3464
3429
  toMemberExpression(
3465
- import_compiler22.types.identifier(binding.name),
3430
+ createScopeReadExpression(binding.section, binding),
3466
3431
  key,
3467
3432
  binding.nullable
3468
3433
  ),
@@ -3474,7 +3439,10 @@ function getSignalFn(signal) {
3474
3439
  if (assertsHoists) {
3475
3440
  signal.render.push(
3476
3441
  import_compiler22.types.expressionStatement(
3477
- callRuntime("_assert_hoist", import_compiler22.types.identifier(binding.name))
3442
+ callRuntime(
3443
+ "_assert_hoist",
3444
+ createScopeReadExpression(binding.section, binding)
3445
+ )
3478
3446
  )
3479
3447
  );
3480
3448
  }
@@ -3556,42 +3524,25 @@ function getSignalFn(signal) {
3556
3524
  )
3557
3525
  );
3558
3526
  }
3559
- if (isIntersection && signal.renderReferencedBindings) {
3560
- signal.render.unshift(
3561
- import_compiler22.types.variableDeclaration("let", [
3562
- import_compiler22.types.variableDeclarator(
3563
- createScopeReadPattern(section, signal.renderReferencedBindings),
3564
- scopeIdentifier
3565
- )
3566
- ])
3567
- );
3568
- }
3569
3527
  if (signal.render.length === 1) {
3570
3528
  const render = signal.render[0];
3571
3529
  if (render.type === "ExpressionStatement") {
3572
3530
  const { expression } = render;
3573
3531
  if (expression.type === "CallExpression") {
3574
3532
  const args = expression.arguments;
3575
- if (params.length >= args.length) {
3576
- let i = args.length;
3577
- for (; i--; ) {
3578
- const param = params[i];
3579
- const arg = args[i];
3580
- if (arg.type !== "Identifier" || param.type !== "Identifier" || param.name !== arg.name) {
3581
- break;
3582
- }
3583
- }
3584
- if (i === -1) {
3585
- if (expression.callee.type === "MemberExpression" && expression.callee.property.type === "Identifier" && expression.callee.property.name === "_") {
3586
- return expression.callee.object;
3587
- }
3588
- return expression.callee;
3533
+ if (args.length === 1 && args[0].type === "Identifier" && args[0].name === scopeIdentifier.name) {
3534
+ if (expression.callee.type === "MemberExpression" && expression.callee.property.type === "Identifier" && expression.callee.property.name === "_") {
3535
+ return expression.callee.object;
3589
3536
  }
3537
+ return expression.callee;
3590
3538
  }
3591
3539
  }
3592
3540
  }
3593
3541
  }
3594
- return import_compiler22.types.arrowFunctionExpression(params, import_compiler22.types.blockStatement(signal.render));
3542
+ return import_compiler22.types.arrowFunctionExpression(
3543
+ [scopeIdentifier],
3544
+ import_compiler22.types.blockStatement(signal.render)
3545
+ );
3595
3546
  }
3596
3547
  var hasTranslatedExtraArgs = /* @__PURE__ */ new WeakSet();
3597
3548
  var emptyExtraArgs = [];
@@ -3758,11 +3709,11 @@ function writeSignals(section) {
3758
3709
  writeSignal(signal);
3759
3710
  }
3760
3711
  function writeSignal(signal) {
3761
- if (!signal.build || seen.has(signal)) return;
3712
+ if (seen.has(signal)) return;
3762
3713
  seen.add(signal);
3763
- for (const value2 of signal.values) {
3764
- writeSignal(value2.signal);
3765
- traverseReplace(value2, "value", replaceRenderNode);
3714
+ for (const value of signal.values) {
3715
+ writeSignal(value.signal);
3716
+ traverseReplace(value, "value", replaceRenderNode);
3766
3717
  }
3767
3718
  forEach(signal.intersection, writeSignal);
3768
3719
  traverseReplace(signal, "render", replaceRenderNode);
@@ -3772,11 +3723,6 @@ function writeSignals(section) {
3772
3723
  const effectIdentifier = import_compiler22.types.identifier(
3773
3724
  `${signal.identifier.name}__script`
3774
3725
  );
3775
- const referencedBindings = signal.effectReferencedBindings;
3776
- const referencesScope = traverseContains(
3777
- signal.effect,
3778
- isScopeIdentifier
3779
- );
3780
3726
  effectDeclarator = import_compiler22.types.variableDeclarator(
3781
3727
  effectIdentifier,
3782
3728
  callRuntime(
@@ -3785,45 +3731,47 @@ function writeSignals(section) {
3785
3731
  getResumeRegisterId(section, signal.referencedBindings)
3786
3732
  ),
3787
3733
  import_compiler22.types.arrowFunctionExpression(
3788
- referencedBindings ? referencesScope ? [
3789
- scopeIdentifier,
3790
- createScopeReadPattern(section, referencedBindings)
3791
- ] : [createScopeReadPattern(section, referencedBindings)] : referencesScope ? [scopeIdentifier] : [],
3734
+ [scopeIdentifier],
3792
3735
  toFirstExpressionOrBlock(signal.effect)
3793
3736
  )
3794
3737
  )
3795
3738
  );
3796
3739
  }
3797
- let value = signal.build();
3798
- if (!value || !signal.register && import_compiler22.types.isFunction(value) && import_compiler22.types.isBlockStatement(value.body) && !value.body.body.length) {
3799
- return;
3800
- }
3801
- if (import_compiler22.types.isCallExpression(value)) {
3802
- replaceNullishAndEmptyFunctionsWith0(value.arguments);
3803
- }
3804
- if (signal.register) {
3805
- value = callRuntime(
3806
- "_var_resume",
3807
- import_compiler22.types.stringLiteral(
3808
- getResumeRegisterId(section, signal.referencedBindings, "var")
3809
- ),
3810
- value
3811
- );
3812
- }
3813
- const signalDeclarator = import_compiler22.types.variableDeclarator(signal.identifier, value);
3814
- let signalDeclaration = !section.parent && !signal.referencedBindings && (import_compiler22.types.isFunctionExpression(value) || import_compiler22.types.isArrowFunctionExpression(value)) ? import_compiler22.types.functionDeclaration(
3815
- signal.identifier,
3816
- value.params,
3817
- import_compiler22.types.isExpression(value.body) ? import_compiler22.types.blockStatement([import_compiler22.types.expressionStatement(value.body)]) : value.body
3818
- ) : import_compiler22.types.variableDeclaration("const", [signalDeclarator]);
3819
- if (signal.export) {
3820
- signalDeclaration = import_compiler22.types.exportNamedDeclaration(signalDeclaration);
3740
+ let signalDeclaration;
3741
+ if (signal.build) {
3742
+ let value = signal.build();
3743
+ if (!value || !signal.register && import_compiler22.types.isFunction(value) && import_compiler22.types.isBlockStatement(value.body) && !value.body.body.length) {
3744
+ return;
3745
+ }
3746
+ if (import_compiler22.types.isCallExpression(value)) {
3747
+ replaceNullishAndEmptyFunctionsWith0(value.arguments);
3748
+ }
3749
+ if (signal.register) {
3750
+ value = callRuntime(
3751
+ "_var_resume",
3752
+ import_compiler22.types.stringLiteral(
3753
+ getResumeRegisterId(section, signal.referencedBindings, "var")
3754
+ ),
3755
+ value
3756
+ );
3757
+ }
3758
+ const signalDeclarator = import_compiler22.types.variableDeclarator(signal.identifier, value);
3759
+ signalDeclaration = !section.parent && !signal.referencedBindings && (import_compiler22.types.isFunctionExpression(value) || import_compiler22.types.isArrowFunctionExpression(value)) ? import_compiler22.types.functionDeclaration(
3760
+ signal.identifier,
3761
+ value.params,
3762
+ import_compiler22.types.isExpression(value.body) ? import_compiler22.types.blockStatement([import_compiler22.types.expressionStatement(value.body)]) : value.body
3763
+ ) : import_compiler22.types.variableDeclaration("const", [signalDeclarator]);
3764
+ if (signal.export) {
3765
+ signalDeclaration = import_compiler22.types.exportNamedDeclaration(signalDeclaration);
3766
+ }
3821
3767
  }
3822
3768
  const signalStatements = signal.prependStatements || [];
3823
3769
  if (effectDeclarator) {
3824
3770
  signalStatements.push(import_compiler22.types.variableDeclaration("const", [effectDeclarator]));
3825
3771
  }
3826
- signalStatements.push(signalDeclaration);
3772
+ if (signalDeclaration) {
3773
+ signalStatements.push(signalDeclaration);
3774
+ }
3827
3775
  (0, import_babel_utils15.getProgram)().node.body.push(...signalStatements);
3828
3776
  }
3829
3777
  }
@@ -3898,25 +3846,10 @@ function writeRegisteredFns() {
3898
3846
  if (registeredFns) {
3899
3847
  for (const registeredFn of registeredFns) {
3900
3848
  let fn;
3901
- const params = registeredFn.referencedBindings ? registeredFn.referencesScope ? [
3902
- scopeIdentifier,
3903
- import_compiler22.types.assignmentPattern(
3904
- createScopeReadPattern(
3905
- registeredFn.section,
3906
- registeredFn.referencedBindings
3907
- ),
3908
- scopeIdentifier
3909
- )
3910
- ] : [
3911
- createScopeReadPattern(
3912
- registeredFn.section,
3913
- registeredFn.referencedBindings
3914
- )
3915
- ] : registeredFn.referencesScope ? [scopeIdentifier] : void 0;
3916
- if (params) {
3849
+ if (registeredFn.referencedBindings || registeredFn.referencesScope) {
3917
3850
  fn = import_compiler22.types.functionDeclaration(
3918
3851
  import_compiler22.types.identifier(registeredFn.id),
3919
- params,
3852
+ [scopeIdentifier],
3920
3853
  import_compiler22.types.blockStatement(toReturnedFunction(registeredFn.node))
3921
3854
  );
3922
3855
  } else if (registeredFn.node.type === "FunctionDeclaration" && registeredFn.node.id?.name === registeredFn.id) {
@@ -4168,32 +4101,34 @@ var updateExpressions = /* @__PURE__ */ new WeakSet();
4168
4101
  function replaceAssignedNode(node) {
4169
4102
  switch (node.type) {
4170
4103
  case "ExpressionStatement": {
4171
- if (node.expression.type === "SequenceExpression" && updateExpressions.delete(node.expression)) {
4172
- node.expression = node.expression.expressions[0];
4173
- return node;
4104
+ if (node.expression.type === "BinaryExpression" && updateExpressions.delete(node.expression)) {
4105
+ node.expression = node.expression.left;
4106
+ }
4107
+ if (node.expression.type === "CallExpression" && updateExpressions.delete(node.expression)) {
4108
+ node.expression.callee = node.expression.arguments[0];
4109
+ node.expression.arguments = [node.expression.arguments[1]];
4174
4110
  }
4175
4111
  break;
4176
4112
  }
4177
4113
  case "UpdateExpression": {
4178
4114
  const { extra } = node.argument;
4179
4115
  if (isAssignedBindingExtra(extra)) {
4180
- const builtAssignment = getBuildAssignment(extra)?.(
4116
+ let builtAssignment = getBuildAssignment(extra)?.(
4181
4117
  extra.section,
4182
- node
4118
+ import_compiler22.types.binaryExpression(
4119
+ node.operator === "++" ? "+" : "-",
4120
+ createScopeReadExpression(extra.section, extra.assignment),
4121
+ import_compiler22.types.numericLiteral(1)
4122
+ )
4183
4123
  );
4184
4124
  if (builtAssignment) {
4185
4125
  if (!node.prefix) {
4186
- node.prefix = true;
4187
- const replacement = import_compiler22.types.sequenceExpression([
4126
+ builtAssignment = import_compiler22.types.binaryExpression(
4127
+ node.operator === "++" ? "-" : "+",
4188
4128
  builtAssignment,
4189
- import_compiler22.types.binaryExpression(
4190
- node.operator === "++" ? "-" : "+",
4191
- node.argument,
4192
- import_compiler22.types.numericLiteral(1)
4193
- )
4194
- ]);
4195
- updateExpressions.add(replacement);
4196
- return replacement;
4129
+ import_compiler22.types.numericLiteral(1)
4130
+ );
4131
+ updateExpressions.add(builtAssignment);
4197
4132
  }
4198
4133
  return builtAssignment;
4199
4134
  }
@@ -4207,15 +4142,15 @@ function replaceAssignedNode(node) {
4207
4142
  if (isAssignedBindingExtra(extra)) {
4208
4143
  return getBuildAssignment(extra)?.(
4209
4144
  extra.section,
4210
- bindingUtil.has(
4211
- extra.assignmentFunction.referencedBindingsInFunction,
4212
- extra.assignment
4213
- ) ? node : node.operator === "=" ? node.right : import_compiler22.types.binaryExpression(
4145
+ node.operator === "=" ? node.right : import_compiler22.types.binaryExpression(
4214
4146
  node.operator.slice(
4215
4147
  0,
4216
4148
  -1
4217
4149
  ),
4218
- node.left,
4150
+ createScopeReadExpression(
4151
+ extra.section,
4152
+ extra.assignment
4153
+ ),
4219
4154
  node.right
4220
4155
  )
4221
4156
  ) || extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
@@ -4237,12 +4172,7 @@ function replaceAssignedNode(node) {
4237
4172
  import_compiler22.types.identifier(uid)
4238
4173
  );
4239
4174
  if (builtAssignment) {
4240
- if (!bindingUtil.has(
4241
- extra.assignmentFunction.referencedBindingsInFunction,
4242
- extra.assignment
4243
- )) {
4244
- id.name = uid;
4245
- }
4175
+ id.name = uid;
4246
4176
  (params ||= []).push(import_compiler22.types.identifier(uid));
4247
4177
  (assignments ||= []).push(builtAssignment);
4248
4178
  return;
@@ -4280,8 +4210,14 @@ function replaceAssignedNode(node) {
4280
4210
  function getBuildAssignment(extra) {
4281
4211
  const { assignmentTo, assignment } = extra;
4282
4212
  if (assignmentTo) {
4283
- return (_section, value) => {
4284
- return import_compiler22.types.callExpression(import_compiler22.types.identifier(assignmentTo.name), [value]);
4213
+ return (section, value) => {
4214
+ const replacement = callRuntime(
4215
+ "_call",
4216
+ createScopeReadExpression(section, assignmentTo),
4217
+ value
4218
+ );
4219
+ updateExpressions.add(replacement);
4220
+ return replacement;
4285
4221
  };
4286
4222
  }
4287
4223
  return getSignal(assignment.section, assignment).buildAssignment;
@@ -6389,10 +6325,9 @@ var for_default = {
6389
6325
  const tagExtra = node.extra;
6390
6326
  const { referencedBindings } = tagExtra;
6391
6327
  const nodeRef = getOptimizedOnlyChildNodeBinding(tag, tagSection);
6392
- setClosureSignalBuilder(tag, (closure, render) => {
6328
+ setClosureSignalBuilder(tag, (_closure, render) => {
6393
6329
  return callRuntime(
6394
6330
  "_for_closure",
6395
- getScopeAccessorLiteral(closure),
6396
6331
  getScopeAccessorLiteral(nodeRef),
6397
6332
  render
6398
6333
  );
@@ -7998,25 +7933,28 @@ function trackReferencesForBinding(babelBinding, binding) {
7998
7933
  }
7999
7934
  }
8000
7935
  function trackAssignment(assignment, binding) {
8001
- const fnRoot = getFnRoot(assignment);
7936
+ const fnParent = getFnParent(assignment);
7937
+ if (!fnParent) {
7938
+ throw assignment.buildCodeFrameError(
7939
+ `Assignments to a tag ${binding.type === 3 /* param */ ? "parameter" : "variable"} must be within a script or function.`
7940
+ );
7941
+ }
7942
+ const fnRoot = getFnRoot(fnParent);
7943
+ const fnExtra = fnRoot && (fnRoot.node.extra ??= {});
8002
7944
  const section = getOrCreateSection(assignment);
8003
7945
  setReferencesScope(assignment);
8004
7946
  forEachIdentifierPath(assignment, (id) => {
8005
7947
  if (id.node.name === binding.name) {
8006
- if (!fnRoot) {
8007
- throw id.buildCodeFrameError(
8008
- `Assignments to a tag ${binding.type === 3 /* param */ ? "parameter" : "variable"} must be within a script or function.`
8009
- );
8010
- }
8011
- const fnExtra = fnRoot && (fnRoot.node.extra ??= {});
8012
7948
  const idExtra = id.node.extra ??= {};
8013
7949
  idExtra.assignment = binding;
8014
- idExtra.assignmentFunction = fnExtra;
8015
- fnExtra.section = idExtra.section = section;
8016
7950
  binding.assignmentSections = sectionUtil.add(
8017
7951
  binding.assignmentSections,
8018
7952
  section
8019
7953
  );
7954
+ if (fnExtra) {
7955
+ idExtra.assignmentFunction = fnExtra;
7956
+ fnExtra.section = idExtra.section = section;
7957
+ }
8020
7958
  if (binding.upstreamAlias && binding.property !== void 0) {
8021
7959
  const changePropName = binding.property + "Change";
8022
7960
  const changeBinding = binding.upstreamAlias.propertyAliases.get(changePropName) || createBinding(
@@ -8780,78 +8718,74 @@ function getSectionInstancesAccessorLiteral(section) {
8780
8718
  }
8781
8719
  function getReadReplacement(node) {
8782
8720
  const { extra } = node;
8783
- if (!extra) return;
8784
- let { binding, read } = extra;
8785
- let replacement;
8721
+ if (!extra || extra.assignment) return;
8722
+ const { read, binding } = extra;
8786
8723
  if (read) {
8724
+ const readBinding = read.binding;
8725
+ let replacement;
8787
8726
  if (read.props === void 0) {
8788
- binding = read.binding;
8789
- read = void 0;
8790
- } else {
8791
- binding = void 0;
8792
- }
8793
- }
8794
- if (binding) {
8795
- if (node.type === "Identifier") {
8796
- if (binding.type === 0 /* dom */) {
8797
- if (binding.section.domGetterBindings.has(binding) && isOutputDOM()) {
8798
- replacement = import_compiler35.types.callExpression(getBindingGetterIdentifier(binding), [
8799
- getScopeExpression(node.extra.section, binding.section)
8800
- ]);
8801
- }
8802
- } else if (binding.type === 6 /* hoist */) {
8803
- if (node.extra?.[kIsInvoked]) {
8804
- if (isOutputDOM()) {
8727
+ if (isOutputDOM()) {
8728
+ if (readBinding.type === 0 /* dom */) {
8729
+ if (!extra[kIsInvoked] && readBinding.section.domGetterBindings.has(readBinding)) {
8805
8730
  replacement = import_compiler35.types.callExpression(
8806
- getBindingGetterIdentifier(binding),
8807
- [getScopeExpression(node.extra.section, binding.section)]
8731
+ getBindingGetterIdentifier(readBinding),
8732
+ [getScopeExpression(extra.section, readBinding.section)]
8808
8733
  );
8809
8734
  }
8735
+ } else if (readBinding.type === 6 /* hoist */ && extra[kIsInvoked]) {
8736
+ replacement = import_compiler35.types.callExpression(
8737
+ getBindingGetterIdentifier(readBinding),
8738
+ [getScopeExpression(extra.section, readBinding.section)]
8739
+ );
8810
8740
  } else {
8811
- replacement = import_compiler35.types.identifier(binding.name);
8741
+ replacement = createScopeReadExpression(extra.section, readBinding);
8742
+ }
8743
+ } else {
8744
+ if (node.type !== "Identifier") {
8745
+ replacement = import_compiler35.types.identifier(readBinding.name);
8746
+ } else if (readBinding.name !== node.name && readBinding.type !== 0 /* dom */ && (readBinding.type !== 6 /* hoist */ || !extra[kIsInvoked])) {
8747
+ node.name = readBinding.name;
8812
8748
  }
8813
- } else if (binding.name !== node.name) {
8814
- node.name = binding.name;
8815
8749
  }
8816
8750
  } else {
8817
- replacement = import_compiler35.types.identifier(binding.name);
8818
- }
8819
- } else if (read) {
8820
- const props = read.props ? Array.isArray(read.props) ? read.props.slice() : [read.props] : [];
8821
- let curNode = node;
8822
- let curBinding = read.binding;
8823
- let replaceMember;
8824
- replacement = import_compiler35.types.identifier(read.binding.name);
8825
- while (props.length && (curNode.type === "MemberExpression" || curNode.type === "OptionalMemberExpression")) {
8826
- const prop = props.pop();
8827
- const memberProp = getMemberExpressionPropString(curNode);
8828
- if (memberProp !== prop) break;
8829
- replaceMember = curNode;
8830
- curNode = curNode.object;
8831
- }
8832
- for (const prop of props) {
8833
- if (curBinding) {
8834
- curBinding = curBinding.propertyAliases.get(prop);
8835
- }
8836
- replacement = toMemberExpression(
8837
- replacement,
8838
- prop,
8839
- !!curBinding?.nullable
8840
- );
8841
- }
8842
- if (replaceMember) {
8843
- if (read.binding.nullable && replaceMember.object.type !== replacement.type) {
8844
- replaceMember.type = "OptionalMemberExpression";
8845
- replaceMember.optional = true;
8751
+ const props = read.props ? Array.isArray(read.props) ? read.props.slice() : [read.props] : [];
8752
+ let curNode = node;
8753
+ let curBinding = read.binding;
8754
+ let replaceMember;
8755
+ replacement = isOutputDOM() ? createScopeReadExpression(extra.section, read.binding) : import_compiler35.types.identifier(read.binding.name);
8756
+ while (props.length && (curNode.type === "MemberExpression" || curNode.type === "OptionalMemberExpression")) {
8757
+ const prop = props.pop();
8758
+ const memberProp = getMemberExpressionPropString(curNode);
8759
+ if (memberProp !== prop) break;
8760
+ replaceMember = curNode;
8761
+ curNode = curNode.object;
8762
+ }
8763
+ for (const prop of props) {
8764
+ if (curBinding) {
8765
+ curBinding = curBinding.propertyAliases.get(prop);
8766
+ }
8767
+ replacement = toMemberExpression(
8768
+ replacement,
8769
+ prop,
8770
+ !!curBinding?.nullable
8771
+ );
8772
+ }
8773
+ if (replaceMember) {
8774
+ if (read.binding.nullable && replaceMember.object.type !== replacement.type) {
8775
+ replaceMember.type = "OptionalMemberExpression";
8776
+ replaceMember.optional = true;
8777
+ }
8778
+ replaceMember.object = withPreviousLocation(
8779
+ replacement,
8780
+ replaceMember.object
8781
+ );
8782
+ replacement = void 0;
8846
8783
  }
8847
- replaceMember.object = withPreviousLocation(
8848
- replacement,
8849
- replaceMember.object
8850
- );
8851
- replacement = void 0;
8852
8784
  }
8785
+ return replacement && withPreviousLocation(replacement, node);
8786
+ } else if (binding && node.type == "Identifier" && node.name !== binding.name) {
8787
+ node.name = binding.name;
8853
8788
  }
8854
- return replacement && withPreviousLocation(replacement, node);
8855
8789
  }
8856
8790
  function pruneBinding(bindings, binding) {
8857
8791
  let shouldPrune = !binding.downstreamExpressions.size;
@@ -8939,14 +8873,23 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
8939
8873
  const rootBindings = getRootBindings(reads);
8940
8874
  for (const read of reads) {
8941
8875
  let { binding } = read;
8942
- if (read.node && read.node.extra?.assignmentTo !== binding) {
8943
- ({ binding } = (read.node.extra ??= {}).read ??= resolveExpressionReference(rootBindings, binding));
8876
+ if (read.node) {
8877
+ const readExtra = read.node.extra ??= {};
8878
+ if (readExtra.assignmentTo !== binding) {
8879
+ readExtra.section = expr.section;
8880
+ ({ binding } = readExtra.read ??= resolveExpressionReference(
8881
+ rootBindings,
8882
+ binding
8883
+ ));
8884
+ }
8944
8885
  }
8945
8886
  referencedBindings = bindingUtil.add(referencedBindings, binding);
8946
8887
  }
8947
8888
  } else if (reads) {
8948
8889
  if (reads.node) {
8949
- (reads.node.extra ??= {}).read = createRead(reads.binding, void 0);
8890
+ const readExtra = reads.node.extra ??= {};
8891
+ readExtra.section = expr.section;
8892
+ readExtra.read = createRead(reads.binding, void 0);
8950
8893
  }
8951
8894
  referencedBindings = reads.binding;
8952
8895
  }
@@ -10658,10 +10601,9 @@ var IfTag = {
10658
10601
  const consequent = import_compiler48.types.numericLiteral(branchBodySection ? i : -1);
10659
10602
  if (branchBodySection) {
10660
10603
  rendererIdentifiers.push(import_compiler48.types.identifier(branchBodySection.name));
10661
- setClosureSignalBuilder(branchTag, (closure, render) => {
10604
+ setClosureSignalBuilder(branchTag, (_closure, render) => {
10662
10605
  return callRuntime(
10663
10606
  "_if_closure",
10664
- getScopeAccessorLiteral(closure),
10665
10607
  getScopeAccessorLiteral(nodeRef),
10666
10608
  import_compiler48.types.numericLiteral(i),
10667
10609
  render
@@ -3,5 +3,6 @@ export type MarkoExprRootPath = t.NodePath<t.MarkoTag | t.MarkoTagBody | t.Marko
3
3
  export declare function getMarkoRoot(path: t.NodePath<t.Node>): MarkoExprRootPath | null;
4
4
  export declare function getExprRoot(path: t.NodePath<t.Node>): t.NodePath<t.Node>;
5
5
  export declare function getFnRoot(path: t.NodePath<t.Node>): t.NodePath<t.ArrowFunctionExpression | t.FunctionExpression | t.ObjectMember> | undefined;
6
+ export declare function getFnParent(path: t.NodePath<t.Node>): t.NodePath<t.ArrowFunctionExpression | t.FunctionExpression | t.ObjectMember> | undefined;
6
7
  export declare function getDeclarationRoot(path: t.NodePath<t.Node>): t.NodePath<t.FunctionDeclaration | t.VariableDeclaration> | undefined;
7
8
  export declare function isMarko(path: t.NodePath<any>): path is MarkoExprRootPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.98",
3
+ "version": "6.0.99",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",