@geajs/vite-plugin 1.0.4 → 1.0.6

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.
Files changed (2) hide show
  1. package/dist/index.js +1811 -1015
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
- import babelGenerator from "@babel/generator";
3
- import babelTraverse from "@babel/traverse";
2
+ import babelGenerator2 from "@babel/generator";
3
+ import babelTraverse2 from "@babel/traverse";
4
4
 
5
5
  // src/parse.ts
6
6
  import { parse } from "@babel/parser";
@@ -183,8 +183,10 @@ import * as t3 from "@babel/types";
183
183
  import { id as id2, js, jsExpr } from "eszter";
184
184
 
185
185
  // src/utils.ts
186
+ import babelTraverse from "@babel/traverse";
186
187
  import * as t2 from "@babel/types";
187
188
  import { id, jsImport } from "eszter";
189
+ var traverse2 = typeof babelTraverse.default === "function" ? babelTraverse.default : babelTraverse;
188
190
  function getJSXTagName(name) {
189
191
  if (t2.isJSXIdentifier(name)) return name.name;
190
192
  if (t2.isJSXMemberExpression(name)) {
@@ -238,31 +240,31 @@ function getDirectChildElements(children) {
238
240
  });
239
241
  }
240
242
  function ensureImport(ast, source, specifier, isDefault = false) {
241
- const program9 = ast.program;
243
+ const program10 = ast.program;
242
244
  const buildSpecifier = () => isDefault ? t2.importDefaultSpecifier(t2.identifier(specifier)) : t2.importSpecifier(t2.identifier(specifier), t2.identifier(specifier));
243
245
  if (isDefault) {
244
- const alreadyHasDefault = program9.body.some(
246
+ const alreadyHasDefault = program10.body.some(
245
247
  (node) => t2.isImportDeclaration(node) && node.source.value === source && node.specifiers.some((s) => t2.isImportDefaultSpecifier(s))
246
248
  );
247
249
  if (alreadyHasDefault) return false;
248
250
  const insertIndex = Math.max(
249
251
  0,
250
- program9.body.reduce((idx, node, i) => t2.isImportDeclaration(node) ? i + 1 : idx, 0)
252
+ program10.body.reduce((idx, node, i) => t2.isImportDeclaration(node) ? i + 1 : idx, 0)
251
253
  );
252
- program9.body.splice(
254
+ program10.body.splice(
253
255
  insertIndex,
254
256
  0,
255
257
  isDefault ? jsImport`import ${id(specifier)} from ${source};` : jsImport`import { ${id(specifier)} } from ${source};`
256
258
  );
257
259
  return true;
258
260
  }
259
- const declaration = program9.body.find((node) => t2.isImportDeclaration(node) && node.source.value === source);
261
+ const declaration = program10.body.find((node) => t2.isImportDeclaration(node) && node.source.value === source);
260
262
  if (!declaration) {
261
263
  const insertIndex = Math.max(
262
264
  0,
263
- program9.body.reduce((idx, node, i) => t2.isImportDeclaration(node) ? i + 1 : idx, 0)
265
+ program10.body.reduce((idx, node, i) => t2.isImportDeclaration(node) ? i + 1 : idx, 0)
264
266
  );
265
- program9.body.splice(insertIndex, 0, jsImport`import { ${id(specifier)} } from ${source};`);
267
+ program10.body.splice(insertIndex, 0, jsImport`import { ${id(specifier)} } from ${source};`);
266
268
  return true;
267
269
  }
268
270
  const exists = declaration.specifiers.some(
@@ -345,11 +347,7 @@ function resolvePath(expr, stateRefs, context = {}) {
345
347
  return { parts: [] };
346
348
  }
347
349
  if (t2.isCallExpression(expr) && t2.isMemberExpression(expr.callee)) {
348
- return resolvePath(
349
- expr.callee.object,
350
- stateRefs,
351
- context
352
- );
350
+ return resolvePath(expr.callee.object, stateRefs, context);
353
351
  }
354
352
  if (t2.isMemberExpression(expr)) {
355
353
  const objectResult = resolvePath(
@@ -450,6 +448,10 @@ function collectAllIdentifierNames(statements, fromIndex, additionalNodes) {
450
448
  walk(node.object);
451
449
  return;
452
450
  }
451
+ if (t2.isVariableDeclarator(node)) {
452
+ walk(node.init);
453
+ return;
454
+ }
453
455
  for (const key of t2.VISITOR_KEYS[node.type] || []) {
454
456
  const child = node[key];
455
457
  if (Array.isArray(child)) {
@@ -489,6 +491,418 @@ function pruneUnusedSetupDestructuring(setupStatements, bodyNodes) {
489
491
  function replacePropRefsInExpression(expr, propNames, wholeParamName, propDefaults) {
490
492
  return replacePropRefsInNode(expr, propNames, wholeParamName, propDefaults);
491
493
  }
494
+ function isThisPropsMember(node) {
495
+ return t2.isMemberExpression(node) && !node.computed && t2.isThisExpression(node.object) && t2.isIdentifier(node.property, { name: "props" });
496
+ }
497
+ function replaceThisPropsRootWithValueParam(expr, propName) {
498
+ const visit = (e) => {
499
+ if (t2.isMemberExpression(e) && !e.computed && isThisPropsMember(e.object) && t2.isIdentifier(e.property, { name: propName })) {
500
+ return t2.identifier("value");
501
+ }
502
+ if (t2.isMemberExpression(e)) {
503
+ return t2.memberExpression(visit(e.object), e.property, e.computed);
504
+ }
505
+ if (t2.isOptionalMemberExpression(e)) {
506
+ return t2.optionalMemberExpression(
507
+ visit(e.object),
508
+ e.property,
509
+ e.computed,
510
+ e.optional
511
+ );
512
+ }
513
+ if (t2.isOptionalCallExpression(e)) {
514
+ return t2.optionalCallExpression(
515
+ visit(e.callee),
516
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a),
517
+ e.optional
518
+ );
519
+ }
520
+ if (t2.isCallExpression(e)) {
521
+ return t2.callExpression(
522
+ visit(e.callee),
523
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a)
524
+ );
525
+ }
526
+ if (t2.isConditionalExpression(e)) {
527
+ return t2.conditionalExpression(visit(e.test), visit(e.consequent), visit(e.alternate));
528
+ }
529
+ if (t2.isLogicalExpression(e)) {
530
+ return t2.logicalExpression(e.operator, visit(e.left), visit(e.right));
531
+ }
532
+ if (t2.isBinaryExpression(e)) {
533
+ return t2.binaryExpression(e.operator, visit(e.left), visit(e.right));
534
+ }
535
+ if (t2.isUnaryExpression(e)) {
536
+ return t2.unaryExpression(e.operator, visit(e.argument), e.prefix);
537
+ }
538
+ if (t2.isSequenceExpression(e)) {
539
+ return t2.sequenceExpression(e.expressions.map((x) => visit(x)));
540
+ }
541
+ if (t2.isAssignmentExpression(e)) {
542
+ return t2.assignmentExpression(e.operator, e.left, visit(e.right));
543
+ }
544
+ if (t2.isArrayExpression(e)) {
545
+ return t2.arrayExpression(
546
+ e.elements.map((el) => {
547
+ if (el === null) return null;
548
+ if (t2.isSpreadElement(el)) return t2.spreadElement(visit(el.argument));
549
+ return visit(el);
550
+ })
551
+ );
552
+ }
553
+ if (t2.isObjectExpression(e)) {
554
+ return t2.objectExpression(
555
+ e.properties.map((p) => {
556
+ if (t2.isSpreadElement(p)) return t2.spreadElement(visit(p.argument));
557
+ if (t2.isObjectProperty(p)) {
558
+ return t2.objectProperty(
559
+ p.computed ? visit(p.key) : p.key,
560
+ visit(p.value),
561
+ p.computed,
562
+ p.shorthand
563
+ );
564
+ }
565
+ return p;
566
+ })
567
+ );
568
+ }
569
+ if (t2.isTemplateLiteral(e)) {
570
+ return t2.templateLiteral(
571
+ e.quasis,
572
+ e.expressions.map((x) => visit(x))
573
+ );
574
+ }
575
+ if (t2.isTaggedTemplateExpression(e)) {
576
+ return t2.taggedTemplateExpression(visit(e.tag), visit(e.quasi));
577
+ }
578
+ if (t2.isNewExpression(e)) {
579
+ return t2.newExpression(
580
+ visit(e.callee),
581
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a)
582
+ );
583
+ }
584
+ return e;
585
+ };
586
+ return visit(expr);
587
+ }
588
+ function derivedExprGuardsValueWhenNullish(expr) {
589
+ if (!t2.isConditionalExpression(expr)) return false;
590
+ return testBranchesOnValueNullish(expr.test);
591
+ }
592
+ function unwrapExpressionRoot(e) {
593
+ let x = e;
594
+ while (t2.isParenthesizedExpression(x)) x = x.expression;
595
+ while (t2.isTSAsExpression(x) || t2.isTSSatisfiesExpression(x)) x = x.expression;
596
+ return x;
597
+ }
598
+ function expressionAccessesValueProperties(expr, setupStmts, valueId = "value") {
599
+ const body = [...setupStmts ?? []];
600
+ if (expr) body.push(t2.expressionStatement(expr));
601
+ const program10 = t2.program([t2.blockStatement(body)]);
602
+ let found = false;
603
+ traverse2(program10, {
604
+ noScope: true,
605
+ MemberExpression(path) {
606
+ if (found) return;
607
+ const obj = unwrapExpressionRoot(path.node.object);
608
+ if (t2.isIdentifier(obj, { name: valueId })) {
609
+ found = true;
610
+ path.stop();
611
+ }
612
+ }
613
+ });
614
+ return found;
615
+ }
616
+ function earlyReturnFalsyBindingName(guard) {
617
+ if (t2.isUnaryExpression(guard) && guard.operator === "!" && t2.isIdentifier(guard.argument)) {
618
+ return guard.argument.name;
619
+ }
620
+ if (t2.isBinaryExpression(guard) && (guard.operator === "==" || guard.operator === "===")) {
621
+ const nullish = (e) => t2.isNullLiteral(e) || t2.isIdentifier(e) && e.name === "undefined";
622
+ if (t2.isIdentifier(guard.left) && nullish(guard.right)) return guard.left.name;
623
+ if (t2.isIdentifier(guard.right) && nullish(guard.left)) return guard.right.name;
624
+ }
625
+ if (t2.isLogicalExpression(guard) && guard.operator === "||") {
626
+ return earlyReturnFalsyBindingName(guard.left) || earlyReturnFalsyBindingName(guard.right);
627
+ }
628
+ return null;
629
+ }
630
+ function optionalizeMemberChainsFromBindingRoot(expr, rootName) {
631
+ const visit = (e) => {
632
+ if (t2.isMemberExpression(e) && !e.computed) {
633
+ const obj = visit(e.object);
634
+ if (t2.isIdentifier(e.object, { name: rootName })) {
635
+ return t2.optionalMemberExpression(e.object, e.property, false, true);
636
+ }
637
+ if (t2.isOptionalMemberExpression(obj)) {
638
+ return t2.optionalMemberExpression(obj, e.property, false, true);
639
+ }
640
+ return t2.memberExpression(obj, e.property, false);
641
+ }
642
+ if (t2.isOptionalMemberExpression(e)) {
643
+ return t2.optionalMemberExpression(
644
+ visit(e.object),
645
+ e.property,
646
+ e.computed,
647
+ e.optional
648
+ );
649
+ }
650
+ if (t2.isOptionalCallExpression(e)) {
651
+ return t2.optionalCallExpression(
652
+ visit(e.callee),
653
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a),
654
+ e.optional
655
+ );
656
+ }
657
+ if (t2.isCallExpression(e)) {
658
+ return t2.callExpression(
659
+ visit(e.callee),
660
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a)
661
+ );
662
+ }
663
+ if (t2.isConditionalExpression(e)) {
664
+ return t2.conditionalExpression(visit(e.test), visit(e.consequent), visit(e.alternate));
665
+ }
666
+ if (t2.isLogicalExpression(e)) {
667
+ return t2.logicalExpression(e.operator, visit(e.left), visit(e.right));
668
+ }
669
+ if (t2.isBinaryExpression(e)) {
670
+ return t2.binaryExpression(e.operator, visit(e.left), visit(e.right));
671
+ }
672
+ if (t2.isUnaryExpression(e)) {
673
+ return t2.unaryExpression(e.operator, visit(e.argument), e.prefix);
674
+ }
675
+ if (t2.isSequenceExpression(e)) {
676
+ return t2.sequenceExpression(e.expressions.map((x) => visit(x)));
677
+ }
678
+ if (t2.isAssignmentExpression(e)) {
679
+ return t2.assignmentExpression(e.operator, e.left, visit(e.right));
680
+ }
681
+ if (t2.isArrayExpression(e)) {
682
+ return t2.arrayExpression(
683
+ e.elements.map((el) => {
684
+ if (el === null) return null;
685
+ if (t2.isSpreadElement(el)) return t2.spreadElement(visit(el.argument));
686
+ return visit(el);
687
+ })
688
+ );
689
+ }
690
+ if (t2.isObjectExpression(e)) {
691
+ return t2.objectExpression(
692
+ e.properties.map((p) => {
693
+ if (t2.isSpreadElement(p)) return t2.spreadElement(visit(p.argument));
694
+ if (t2.isObjectProperty(p)) {
695
+ return t2.objectProperty(
696
+ p.computed ? visit(p.key) : p.key,
697
+ visit(p.value),
698
+ p.computed,
699
+ p.shorthand
700
+ );
701
+ }
702
+ return p;
703
+ })
704
+ );
705
+ }
706
+ if (t2.isTemplateLiteral(e)) {
707
+ return t2.templateLiteral(
708
+ e.quasis,
709
+ e.expressions.map((x) => visit(x))
710
+ );
711
+ }
712
+ if (t2.isTaggedTemplateExpression(e)) {
713
+ return t2.taggedTemplateExpression(visit(e.tag), visit(e.quasi));
714
+ }
715
+ if (t2.isNewExpression(e)) {
716
+ return t2.newExpression(
717
+ visit(e.callee),
718
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a)
719
+ );
720
+ }
721
+ return e;
722
+ };
723
+ return visit(expr);
724
+ }
725
+ function optionalizeBindingRootInStatements(stmts, rootName) {
726
+ const mapStmt = (s) => {
727
+ if (t2.isVariableDeclaration(s)) {
728
+ return t2.variableDeclaration(
729
+ s.kind,
730
+ s.declarations.map(
731
+ (d) => t2.variableDeclarator(d.id, d.init ? optionalizeMemberChainsFromBindingRoot(d.init, rootName) : null)
732
+ )
733
+ );
734
+ }
735
+ if (t2.isExpressionStatement(s)) {
736
+ return t2.expressionStatement(optionalizeMemberChainsFromBindingRoot(s.expression, rootName));
737
+ }
738
+ if (t2.isReturnStatement(s)) {
739
+ return t2.returnStatement(s.argument ? optionalizeMemberChainsFromBindingRoot(s.argument, rootName) : null);
740
+ }
741
+ if (t2.isBlockStatement(s)) {
742
+ return t2.blockStatement(s.body.map(mapStmt));
743
+ }
744
+ if (t2.isIfStatement(s)) {
745
+ return t2.ifStatement(
746
+ optionalizeMemberChainsFromBindingRoot(s.test, rootName),
747
+ mapStmt(s.consequent),
748
+ s.alternate ? mapStmt(s.alternate) : null
749
+ );
750
+ }
751
+ return s;
752
+ };
753
+ return stmts.map((s) => mapStmt(t2.cloneNode(s, true)));
754
+ }
755
+ function optionalizeMemberChainsAfterComputedItemKey(expr, itemKeyName) {
756
+ const visit = (e) => {
757
+ if (t2.isMemberExpression(e) && !e.computed) {
758
+ const origObj = e.object;
759
+ const inner = visit(origObj);
760
+ if (t2.isMemberExpression(origObj) && origObj.computed && t2.isIdentifier(origObj.property, { name: itemKeyName })) {
761
+ return t2.optionalMemberExpression(inner, e.property, false, true);
762
+ }
763
+ if (t2.isOptionalMemberExpression(inner)) {
764
+ return t2.optionalMemberExpression(inner, e.property, false, true);
765
+ }
766
+ return t2.memberExpression(inner, e.property, false);
767
+ }
768
+ if (t2.isMemberExpression(e) && e.computed) {
769
+ return t2.memberExpression(
770
+ visit(e.object),
771
+ visit(e.property),
772
+ true
773
+ );
774
+ }
775
+ if (t2.isOptionalMemberExpression(e)) {
776
+ return t2.optionalMemberExpression(
777
+ visit(e.object),
778
+ e.property,
779
+ e.computed,
780
+ e.optional
781
+ );
782
+ }
783
+ if (t2.isOptionalCallExpression(e)) {
784
+ return t2.optionalCallExpression(
785
+ visit(e.callee),
786
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a),
787
+ e.optional
788
+ );
789
+ }
790
+ if (t2.isCallExpression(e)) {
791
+ return t2.callExpression(
792
+ visit(e.callee),
793
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a)
794
+ );
795
+ }
796
+ if (t2.isConditionalExpression(e)) {
797
+ return t2.conditionalExpression(visit(e.test), visit(e.consequent), visit(e.alternate));
798
+ }
799
+ if (t2.isLogicalExpression(e)) {
800
+ return t2.logicalExpression(e.operator, visit(e.left), visit(e.right));
801
+ }
802
+ if (t2.isBinaryExpression(e)) {
803
+ return t2.binaryExpression(e.operator, visit(e.left), visit(e.right));
804
+ }
805
+ if (t2.isUnaryExpression(e)) {
806
+ return t2.unaryExpression(e.operator, visit(e.argument), e.prefix);
807
+ }
808
+ if (t2.isSequenceExpression(e)) {
809
+ return t2.sequenceExpression(e.expressions.map((x) => visit(x)));
810
+ }
811
+ if (t2.isAssignmentExpression(e)) {
812
+ return t2.assignmentExpression(e.operator, e.left, visit(e.right));
813
+ }
814
+ if (t2.isArrayExpression(e)) {
815
+ return t2.arrayExpression(
816
+ e.elements.map((el) => {
817
+ if (el === null) return null;
818
+ if (t2.isSpreadElement(el)) return t2.spreadElement(visit(el.argument));
819
+ return visit(el);
820
+ })
821
+ );
822
+ }
823
+ if (t2.isObjectExpression(e)) {
824
+ return t2.objectExpression(
825
+ e.properties.map((p) => {
826
+ if (t2.isSpreadElement(p)) return t2.spreadElement(visit(p.argument));
827
+ if (t2.isObjectProperty(p)) {
828
+ return t2.objectProperty(
829
+ p.computed ? visit(p.key) : p.key,
830
+ visit(p.value),
831
+ p.computed,
832
+ p.shorthand
833
+ );
834
+ }
835
+ return p;
836
+ })
837
+ );
838
+ }
839
+ if (t2.isTemplateLiteral(e)) {
840
+ return t2.templateLiteral(
841
+ e.quasis,
842
+ e.expressions.map((x) => visit(x))
843
+ );
844
+ }
845
+ if (t2.isTaggedTemplateExpression(e)) {
846
+ return t2.taggedTemplateExpression(visit(e.tag), visit(e.quasi));
847
+ }
848
+ if (t2.isNewExpression(e)) {
849
+ return t2.newExpression(
850
+ visit(e.callee),
851
+ e.arguments.map((a) => t2.isExpression(a) ? visit(a) : a)
852
+ );
853
+ }
854
+ if (t2.isParenthesizedExpression(e)) {
855
+ return t2.parenthesizedExpression(visit(e.expression));
856
+ }
857
+ return e;
858
+ };
859
+ return visit(expr);
860
+ }
861
+ function optionalizeComputedItemKeyInStatements(stmts, itemKeyName) {
862
+ const mapStmt = (s) => {
863
+ if (t2.isVariableDeclaration(s)) {
864
+ return t2.variableDeclaration(
865
+ s.kind,
866
+ s.declarations.map(
867
+ (d) => t2.variableDeclarator(d.id, d.init ? optionalizeMemberChainsAfterComputedItemKey(d.init, itemKeyName) : null)
868
+ )
869
+ );
870
+ }
871
+ if (t2.isExpressionStatement(s)) {
872
+ return t2.expressionStatement(optionalizeMemberChainsAfterComputedItemKey(s.expression, itemKeyName));
873
+ }
874
+ if (t2.isReturnStatement(s)) {
875
+ return t2.returnStatement(s.argument ? optionalizeMemberChainsAfterComputedItemKey(s.argument, itemKeyName) : null);
876
+ }
877
+ if (t2.isBlockStatement(s)) {
878
+ return t2.blockStatement(s.body.map(mapStmt));
879
+ }
880
+ if (t2.isIfStatement(s)) {
881
+ return t2.ifStatement(
882
+ optionalizeMemberChainsAfterComputedItemKey(s.test, itemKeyName),
883
+ mapStmt(s.consequent),
884
+ s.alternate ? mapStmt(s.alternate) : null
885
+ );
886
+ }
887
+ return s;
888
+ };
889
+ return stmts.map((s) => mapStmt(t2.cloneNode(s, true)));
890
+ }
891
+ function testBranchesOnValueNullish(test) {
892
+ if (t2.isIdentifier(test, { name: "value" })) return true;
893
+ if (t2.isBinaryExpression(test) && ["==", "===", "!=", "!=="].includes(test.operator)) {
894
+ const isValue = (e) => t2.isIdentifier(e, { name: "value" });
895
+ const isNullishLit = (e) => t2.isNullLiteral(e) || t2.isIdentifier(e) && e.name === "undefined";
896
+ return isValue(test.left) && isNullishLit(test.right) || isValue(test.right) && isNullishLit(test.left);
897
+ }
898
+ if (t2.isUnaryExpression(test) && test.operator === "!" && t2.isIdentifier(test.argument, { name: "value" })) {
899
+ return true;
900
+ }
901
+ if (t2.isLogicalExpression(test)) {
902
+ return testBranchesOnValueNullish(test.left) || testBranchesOnValueNullish(test.right);
903
+ }
904
+ return false;
905
+ }
492
906
  function replacePropRefsInNode(node, propNames, wholeParamName, propDefaults) {
493
907
  if (t2.isIdentifier(node) && wholeParamName && node.name === wholeParamName) {
494
908
  return t2.memberExpression(t2.thisExpression(), t2.identifier("props"));
@@ -632,6 +1046,17 @@ function replacePropRefsInNode(node, propNames, wholeParamName, propDefaults) {
632
1046
  }
633
1047
  return node;
634
1048
  }
1049
+ function loggingCatchClause(extra = []) {
1050
+ return t2.catchClause(
1051
+ t2.identifier("__err"),
1052
+ t2.blockStatement([
1053
+ t2.expressionStatement(
1054
+ t2.callExpression(t2.memberExpression(t2.identifier("console"), t2.identifier("error")), [t2.identifier("__err")])
1055
+ ),
1056
+ ...extra
1057
+ ])
1058
+ );
1059
+ }
635
1060
 
636
1061
  // src/hmr.ts
637
1062
  import { createRequire as createRequire2 } from "module";
@@ -781,6 +1206,14 @@ function resolveExpr(expr, stateRefs) {
781
1206
  }
782
1207
  }
783
1208
  }
1209
+ if (t4.isTemplateLiteral(expr)) {
1210
+ for (const inner of expr.expressions) {
1211
+ if (t4.isExpression(inner)) {
1212
+ const result = resolveExpr(inner, stateRefs);
1213
+ if (result?.parts?.length) return result;
1214
+ }
1215
+ }
1216
+ }
784
1217
  return null;
785
1218
  }
786
1219
  function applyImportedState(binding, result, stateProps) {
@@ -855,7 +1288,8 @@ function normalizeDestructuredMapCallback(arrowFn) {
855
1288
  const rewriteNode2 = (node) => {
856
1289
  if (!node || typeof node !== "object") return;
857
1290
  for (const key of Object.keys(node)) {
858
- if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments") continue;
1291
+ if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments")
1292
+ continue;
859
1293
  const child = node[key];
860
1294
  if (Array.isArray(child)) {
861
1295
  for (let i = 0; i < child.length; i++) {
@@ -863,7 +1297,11 @@ function normalizeDestructuredMapCallback(arrowFn) {
863
1297
  if (t4.isIdentifier(child[i]) && indexMap.has(child[i].name)) {
864
1298
  if (t4.isMemberExpression(node) && key === "property" && !node.computed) continue;
865
1299
  if (t4.isObjectProperty(node) && key === "key") continue;
866
- child[i] = t4.memberExpression(t4.identifier(itemName), t4.numericLiteral(indexMap.get(child[i].name)), true);
1300
+ child[i] = t4.memberExpression(
1301
+ t4.identifier(itemName),
1302
+ t4.numericLiteral(indexMap.get(child[i].name)),
1303
+ true
1304
+ );
867
1305
  } else {
868
1306
  rewriteNode2(child[i]);
869
1307
  }
@@ -873,7 +1311,11 @@ function normalizeDestructuredMapCallback(arrowFn) {
873
1311
  if (t4.isIdentifier(child) && indexMap.has(child.name)) {
874
1312
  if (t4.isMemberExpression(node) && key === "property" && !node.computed) continue;
875
1313
  if (t4.isObjectProperty(node) && key === "key") continue;
876
- node[key] = t4.memberExpression(t4.identifier(itemName), t4.numericLiteral(indexMap.get(child.name)), true);
1314
+ node[key] = t4.memberExpression(
1315
+ t4.identifier(itemName),
1316
+ t4.numericLiteral(indexMap.get(child.name)),
1317
+ true
1318
+ );
877
1319
  } else {
878
1320
  rewriteNode2(child);
879
1321
  }
@@ -896,7 +1338,8 @@ function normalizeDestructuredMapCallback(arrowFn) {
896
1338
  const rewriteNode = (node) => {
897
1339
  if (!node || typeof node !== "object") return;
898
1340
  for (const key of Object.keys(node)) {
899
- if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments") continue;
1341
+ if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments")
1342
+ continue;
900
1343
  const child = node[key];
901
1344
  if (Array.isArray(child)) {
902
1345
  for (let i = 0; i < child.length; i++) {
@@ -1002,7 +1445,7 @@ function detectContainerSelector(node, tagName) {
1002
1445
  // src/analyze-map.ts
1003
1446
  import { createRequire as createRequire3 } from "module";
1004
1447
  var require4 = createRequire3(import.meta.url);
1005
- var traverse2 = require4("@babel/traverse").default;
1448
+ var traverse3 = require4("@babel/traverse").default;
1006
1449
  function analyzeJSXInMap(node, arrayPath, itemVar, itemBindings, relationalBindings, conditionalBindings, elementPath, isImportedState, itemIdProperty, stateRefs, childIndices = [], storeVar) {
1007
1450
  const context = { inMap: true, mapItemVar: itemVar };
1008
1451
  node.openingElement.attributes.forEach((attr) => {
@@ -1205,8 +1648,8 @@ function analyzeItemTemplateLiteral(expr, arrayPath, itemVar, itemBindings, rela
1205
1648
  function collectConditionalBindings(expr, type, attributeName, conditionalBindings, arrayPath, itemVar, elementPath, childPath, stateRefs, storeVar) {
1206
1649
  const dependencies = /* @__PURE__ */ new Map();
1207
1650
  const requiresRerender = conditionalExpressionRequiresRerender(expr);
1208
- const program9 = t5.program([t5.expressionStatement(t5.cloneNode(expr, true))]);
1209
- traverse2(program9, {
1651
+ const program10 = t5.program([t5.expressionStatement(t5.cloneNode(expr, true))]);
1652
+ traverse3(program10, {
1210
1653
  noScope: true,
1211
1654
  MemberExpression(path) {
1212
1655
  const parent = path.parentPath;
@@ -1249,8 +1692,8 @@ function collectConditionalBindings(expr, type, attributeName, conditionalBindin
1249
1692
  }
1250
1693
  function conditionalExpressionRequiresRerender(expr) {
1251
1694
  let needsRerender = false;
1252
- const program9 = t5.program([t5.expressionStatement(t5.cloneNode(expr, true))]);
1253
- traverse2(program9, {
1695
+ const program10 = t5.program([t5.expressionStatement(t5.cloneNode(expr, true))]);
1696
+ traverse3(program10, {
1254
1697
  noScope: true,
1255
1698
  JSXElement(path) {
1256
1699
  needsRerender = true;
@@ -1345,7 +1788,7 @@ function extractClassName(node) {
1345
1788
  import * as t6 from "@babel/types";
1346
1789
  import { createRequire as createRequire4 } from "module";
1347
1790
  var require5 = createRequire4(import.meta.url);
1348
- var traverse3 = require5("@babel/traverse").default;
1791
+ var traverse4 = require5("@babel/traverse").default;
1349
1792
  function buildComponentPropsExpression(jsxElement, imports, componentInstances, eventHandlers, stateRefs, templateSetupContext, transformExpression, transformFragment) {
1350
1793
  const props = [];
1351
1794
  const dependencies = /* @__PURE__ */ new Map();
@@ -1358,7 +1801,9 @@ function buildComponentPropsExpression(jsxElement, imports, componentInstances,
1358
1801
  else if (t6.isJSXExpressionContainer(attr.value) && !t6.isJSXEmptyExpression(attr.value.expression)) {
1359
1802
  const expr = attr.value.expression;
1360
1803
  propValue = transformExpression(expr);
1361
- if (propValue && (/^on[A-Z]/.test(propName) || /^(click|input|change|submit|focus|blur|keydown|keyup|keypress|mousedown|mouseup|mouseover|mouseout|mouseenter|mouseleave|touchstart|touchend|touchmove|pointerdown|pointerup|pointermove|scroll|resize|drag|dragstart|dragend|dragover|drop|reset)$/.test(propName)) && t6.isMemberExpression(propValue)) {
1804
+ if (propValue && (/^on[A-Z]/.test(propName) || /^(click|input|change|submit|focus|blur|keydown|keyup|keypress|mousedown|mouseup|mouseover|mouseout|mouseenter|mouseleave|touchstart|touchend|touchmove|pointerdown|pointerup|pointermove|scroll|resize|drag|dragstart|dragend|dragover|drop|reset)$/.test(
1805
+ propName
1806
+ )) && t6.isMemberExpression(propValue)) {
1362
1807
  const argsId = t6.identifier("args");
1363
1808
  propValue = t6.arrowFunctionExpression(
1364
1809
  [t6.restElement(argsId)],
@@ -1430,11 +1875,11 @@ function collectExpressionDependenciesInto(expr, stateRefs, dependencies, setupS
1430
1875
  });
1431
1876
  });
1432
1877
  });
1433
- const program9 = t6.program([
1878
+ const program10 = t6.program([
1434
1879
  ...setupStatements.map((statement) => t6.cloneNode(statement, true)),
1435
1880
  t6.expressionStatement(t6.cloneNode(expr, true))
1436
1881
  ]);
1437
- traverse3(program9, {
1882
+ traverse4(program10, {
1438
1883
  noScope: true,
1439
1884
  MemberExpression(path) {
1440
1885
  const parent = path.parentPath;
@@ -1514,6 +1959,28 @@ function collectTemplateSetupStatements(expr, templateSetupContext) {
1514
1959
  };
1515
1960
  collectReferencedIdentifiers(expr).forEach(includeName);
1516
1961
  ordered.sort((a, b) => a.index - b.index);
1962
+ const barrier = templateSetupContext.earlyReturnBarrierIndex;
1963
+ if (barrier !== void 0 && ordered.length > 0) {
1964
+ const stmtIndices = ordered.filter((e) => e.index >= 0).map((e) => e.index);
1965
+ if (stmtIndices.length > 0) {
1966
+ const maxIdx = Math.max(...stmtIndices);
1967
+ const minIdx = Math.min(...stmtIndices);
1968
+ if (maxIdx > barrier || minIdx <= barrier) {
1969
+ const have = new Set(ordered.map((e) => e.index));
1970
+ const extra = [];
1971
+ for (let bi = 0; bi <= barrier; bi++) {
1972
+ if (!have.has(bi)) {
1973
+ extra.push({
1974
+ index: bi,
1975
+ statement: t6.cloneNode(templateSetupContext.statements[bi], true)
1976
+ });
1977
+ }
1978
+ }
1979
+ ordered.push(...extra);
1980
+ ordered.sort((a, b) => a.index - b.index);
1981
+ }
1982
+ }
1983
+ }
1517
1984
  for (const entry of ordered) {
1518
1985
  if (entry.index !== -1) continue;
1519
1986
  if (!t6.isVariableDeclaration(entry.statement)) continue;
@@ -1559,10 +2026,10 @@ function collectPatternIdentifiers(pattern) {
1559
2026
  }
1560
2027
  function collectReferencedIdentifiers(node) {
1561
2028
  const names = /* @__PURE__ */ new Set();
1562
- const program9 = t6.program([
2029
+ const program10 = t6.program([
1563
2030
  t6.isStatement(node) ? t6.cloneNode(node, true) : t6.expressionStatement(t6.cloneNode(node, true))
1564
2031
  ]);
1565
- traverse3(program9, {
2032
+ traverse4(program10, {
1566
2033
  noScope: true,
1567
2034
  Identifier(path) {
1568
2035
  if (!path.isReferencedIdentifier()) return;
@@ -1575,7 +2042,7 @@ function collectReferencedIdentifiers(node) {
1575
2042
  // src/analyze.ts
1576
2043
  import { createRequire as createRequire5 } from "module";
1577
2044
  var require6 = createRequire5(import.meta.url);
1578
- var traverse4 = require6("@babel/traverse").default;
2045
+ var traverse5 = require6("@babel/traverse").default;
1579
2046
  function buildTextTemplateExpressionFromParts(textTemplate, textExpressions) {
1580
2047
  const templateParts = textTemplate.split(/\$\{(\d+)\}/g);
1581
2048
  const quasis = [];
@@ -1668,16 +2135,8 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
1668
2135
  conditionalSlotScopedStoreKeys: /* @__PURE__ */ new Set(),
1669
2136
  conditionalSlotNodeMap: /* @__PURE__ */ new Map()
1670
2137
  };
1671
- let earlyReturnGuard;
1672
2138
  const bodyStmts = templateMethod.body.body;
1673
- for (let i = 0; i < bodyStmts.length - 1; i++) {
1674
- const s = bodyStmts[i];
1675
- if (t7.isIfStatement(s) && !s.alternate && t7.isBlockStatement(s.consequent) && s.consequent.body.length === 1 && t7.isReturnStatement(s.consequent.body[0]) && s.consequent.body[0].argument && t7.isReturnStatement(bodyStmts[i + 1])) {
1676
- earlyReturnGuard = t7.cloneNode(s.test, true);
1677
- break;
1678
- }
1679
- }
1680
- const returnStmt = templateMethod.body.body.find((s) => t7.isReturnStatement(s) && s.argument !== null);
2139
+ const returnStmt = bodyStmts.find((s) => t7.isReturnStatement(s) && s.argument !== null);
1681
2140
  if (!returnStmt?.argument)
1682
2141
  return {
1683
2142
  bindings,
@@ -1693,7 +2152,25 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
1693
2152
  conditionalSlotScopedStoreKeys: /* @__PURE__ */ new Set(),
1694
2153
  conditionalSlotNodeMap: /* @__PURE__ */ new Map()
1695
2154
  };
1696
- const returnIndex = templateMethod.body.body.indexOf(returnStmt);
2155
+ const returnIndex = bodyStmts.indexOf(returnStmt);
2156
+ let earlyReturnGuard;
2157
+ let earlyReturnBarrierIndex;
2158
+ const earlyReturnFromIf = (s) => {
2159
+ if (t7.isReturnStatement(s.consequent) && s.consequent.argument) return s.consequent;
2160
+ if (t7.isBlockStatement(s.consequent) && s.consequent.body.length === 1 && t7.isReturnStatement(s.consequent.body[0]) && s.consequent.body[0].argument) {
2161
+ return s.consequent.body[0];
2162
+ }
2163
+ return null;
2164
+ };
2165
+ for (let i = 0; i < returnIndex; i++) {
2166
+ const s = bodyStmts[i];
2167
+ if (!t7.isIfStatement(s) || s.alternate) continue;
2168
+ const earlyRet = earlyReturnFromIf(s);
2169
+ if (!earlyRet?.argument) continue;
2170
+ earlyReturnGuard = t7.cloneNode(s.test, true);
2171
+ earlyReturnBarrierIndex = i;
2172
+ break;
2173
+ }
1697
2174
  const templateSetupContext = {
1698
2175
  params: templateMethod.params.filter(
1699
2176
  (param) => !t7.isTSParameterProperty(param)
@@ -1818,7 +2295,8 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
1818
2295
  elementPathToBindingId,
1819
2296
  conditionalSlotScopedStoreKeys,
1820
2297
  conditionalSlotNodeMap,
1821
- earlyReturnGuard
2298
+ earlyReturnGuard,
2299
+ earlyReturnBarrierIndex
1822
2300
  };
1823
2301
  }
1824
2302
  function computeConditionalSlotScopedStoreKeys(conditionalSlots, stateProps, stateRefs, templateSetupContext) {
@@ -1973,8 +2451,24 @@ function collectTextChildren(node, stateRefs, stateProps) {
1973
2451
  const expr = child.expression;
1974
2452
  const isMap = t7.isCallExpression(expr) && t7.isMemberExpression(expr.callee) && t7.isIdentifier(expr.callee.property) && expr.callee.property.name === "map";
1975
2453
  if (!isMap) {
1976
- textChildren.push({ type: "expression", expression: expr });
1977
- hasExpr = true;
2454
+ if (t7.isTemplateLiteral(expr)) {
2455
+ for (let i = 0; i < expr.quasis.length; i++) {
2456
+ const quasi = expr.quasis[i];
2457
+ if (quasi.value.raw) {
2458
+ textChildren.push({ type: "text", value: quasi.value.raw });
2459
+ }
2460
+ if (i < expr.expressions.length) {
2461
+ const innerExpr = expr.expressions[i];
2462
+ if (t7.isExpression(innerExpr)) {
2463
+ textChildren.push({ type: "expression", expression: innerExpr });
2464
+ hasExpr = true;
2465
+ }
2466
+ }
2467
+ }
2468
+ } else {
2469
+ textChildren.push({ type: "expression", expression: expr });
2470
+ hasExpr = true;
2471
+ }
1978
2472
  }
1979
2473
  }
1980
2474
  });
@@ -2123,8 +2617,8 @@ function isMapCall(expr) {
2123
2617
  function collectNestedMapCalls(expr) {
2124
2618
  if (t7.isJSXEmptyExpression(expr)) return [];
2125
2619
  const maps = [];
2126
- const program9 = t7.program([t7.expressionStatement(t7.cloneNode(expr, true))]);
2127
- traverse4(program9, {
2620
+ const program10 = t7.program([t7.expressionStatement(t7.cloneNode(expr, true))]);
2621
+ traverse5(program10, {
2128
2622
  noScope: true,
2129
2623
  CallExpression(path) {
2130
2624
  if (isMapCall(path.node)) {
@@ -2623,12 +3117,12 @@ function buildDerivedPropBindings(expr, type, attributeName, elementPath, propsP
2623
3117
  }
2624
3118
  function collectDependentPropNames(expr, setupStatements, propsParamName, destructuredPropNames, classBody2) {
2625
3119
  const names = /* @__PURE__ */ new Set();
2626
- const program9 = t7.program([
3120
+ const program10 = t7.program([
2627
3121
  ...setupStatements.map((statement) => t7.cloneNode(statement, true)),
2628
3122
  t7.expressionStatement(t7.cloneNode(expr, true))
2629
3123
  ]);
2630
3124
  const getterNamesToExpand = /* @__PURE__ */ new Set();
2631
- traverse4(program9, {
3125
+ traverse5(program10, {
2632
3126
  noScope: true,
2633
3127
  Identifier(path) {
2634
3128
  if (!path.isReferencedIdentifier()) return;
@@ -2647,7 +3141,7 @@ function collectDependentPropNames(expr, setupStatements, propsParamName, destru
2647
3141
  if (!t7.isClassMethod(member) || member.kind !== "get" || !t7.isIdentifier(member.key) || !getterNamesToExpand.has(member.key.name))
2648
3142
  continue;
2649
3143
  const getterProgram = t7.program(member.body.body.map((s) => t7.cloneNode(s, true)));
2650
- traverse4(getterProgram, {
3144
+ traverse5(getterProgram, {
2651
3145
  noScope: true,
2652
3146
  Identifier(path) {
2653
3147
  if (!path.isReferencedIdentifier()) return;
@@ -2671,13 +3165,17 @@ function collectDependentPropNames(expr, setupStatements, propsParamName, destru
2671
3165
  function collectAllStateAccesses(templateMethod, stateRefs, stateProps) {
2672
3166
  const params = templateMethod.params.filter((param) => !t7.isTSParameterProperty(param));
2673
3167
  const prog = t7.program([t7.expressionStatement(t7.arrowFunctionExpression(params, templateMethod.body))]);
2674
- traverse4(prog, {
3168
+ traverse5(prog, {
2675
3169
  noScope: true,
2676
3170
  Identifier(path) {
2677
3171
  if (!stateRefs.has(path.node.name)) return;
2678
3172
  const ref = stateRefs.get(path.node.name);
2679
- if (path.parentPath && t7.isMemberExpression(path.parentPath.node) && path.parentPath.node.object === path.node)
2680
- return;
3173
+ if (path.parentPath && t7.isMemberExpression(path.parentPath.node) && path.parentPath.node.object === path.node && t7.isIdentifier(path.parentPath.node.property) && !path.parentPath.node.computed) {
3174
+ const grandParent = path.parentPath.parentPath;
3175
+ if (!(grandParent && t7.isCallExpression(grandParent.node) && grandParent.node.callee === path.parentPath.node)) {
3176
+ return;
3177
+ }
3178
+ }
2681
3179
  if (ref.kind === "local-destructured" && ref.propName) {
2682
3180
  const observeKey = buildObserveKey([ref.propName]);
2683
3181
  if (!stateProps.has(observeKey)) stateProps.set(observeKey, [ref.propName]);
@@ -2686,11 +3184,8 @@ function collectAllStateAccesses(templateMethod, stateRefs, stateProps) {
2686
3184
  if (ref.kind === "imported-destructured" && ref.propName && ref.storeVar) {
2687
3185
  const storeRef = stateRefs.get(ref.storeVar);
2688
3186
  if (storeRef?.getterDeps?.has(ref.propName)) {
2689
- const depPaths = storeRef.getterDeps.get(ref.propName);
2690
- for (const depPath of depPaths) {
2691
- const observeKey = buildObserveKey(depPath, ref.storeVar);
2692
- if (!stateProps.has(observeKey)) stateProps.set(observeKey, [...depPath]);
2693
- }
3187
+ const observeKey = buildObserveKey([ref.propName], ref.storeVar);
3188
+ if (!stateProps.has(observeKey)) stateProps.set(observeKey, [ref.propName]);
2694
3189
  } else if (storeRef?.reactiveFields?.has(ref.propName)) {
2695
3190
  const observeKey = buildObserveKey([ref.propName], ref.storeVar);
2696
3191
  if (!stateProps.has(observeKey)) stateProps.set(observeKey, [ref.propName]);
@@ -2730,7 +3225,7 @@ function collectAllStateAccesses(templateMethod, stateRefs, stateProps) {
2730
3225
  function collectItemTemplateStoreDependencies(itemTemplate, itemVar, stateRefs, dependencies) {
2731
3226
  if (!itemTemplate) return;
2732
3227
  const prog = t7.program([t7.expressionStatement(t7.cloneNode(itemTemplate, true))]);
2733
- traverse4(prog, {
3228
+ traverse5(prog, {
2734
3229
  noScope: true,
2735
3230
  MemberExpression(path) {
2736
3231
  let root = path.node;
@@ -2890,7 +3385,8 @@ function extractSingleCallExpression(expr) {
2890
3385
  }
2891
3386
  function getHoistableRootEvent(attrName, expr, elementPath, context, selector) {
2892
3387
  if (elementPath.length !== 0 || !selector) return null;
2893
- if (attrName.startsWith("data-") || attrName === "class" || attrName === "className" || attrName === "style" || attrName === "id") return null;
3388
+ if (attrName.startsWith("data-") || attrName === "class" || attrName === "className" || attrName === "style" || attrName === "id")
3389
+ return null;
2894
3390
  const eventType = toGeaEventType(attrName);
2895
3391
  const directProp = resolvePropCallbackName(expr, context);
2896
3392
  if (directProp) return { eventType, propName: directProp, selector };
@@ -3146,6 +3642,46 @@ function pascalToKebabCase(tagName) {
3146
3642
  function camelToKebab2(name) {
3147
3643
  return name.replace(/([A-Z])/g, "-$1").toLowerCase();
3148
3644
  }
3645
+ function tryStaticClassObjectToString(expr) {
3646
+ const parts = [];
3647
+ for (const prop of expr.properties) {
3648
+ if (!t9.isObjectProperty(prop) || prop.computed) return null;
3649
+ const key = t9.isIdentifier(prop.key) ? prop.key.name : t9.isStringLiteral(prop.key) ? prop.key.value : null;
3650
+ if (!key) return null;
3651
+ if (t9.isBooleanLiteral(prop.value)) {
3652
+ if (prop.value.value) parts.push(key);
3653
+ } else {
3654
+ return null;
3655
+ }
3656
+ }
3657
+ return parts.join(" ");
3658
+ }
3659
+ function buildClassObjectExpression(expr) {
3660
+ return t9.callExpression(
3661
+ t9.memberExpression(
3662
+ t9.callExpression(
3663
+ t9.memberExpression(
3664
+ t9.callExpression(
3665
+ t9.memberExpression(
3666
+ t9.callExpression(t9.memberExpression(t9.identifier("Object"), t9.identifier("entries")), [expr]),
3667
+ t9.identifier("filter")
3668
+ ),
3669
+ [
3670
+ t9.arrowFunctionExpression(
3671
+ [t9.arrayPattern([t9.identifier("__k"), t9.identifier("__v")])],
3672
+ t9.identifier("__v")
3673
+ )
3674
+ ]
3675
+ ),
3676
+ t9.identifier("map")
3677
+ ),
3678
+ [t9.arrowFunctionExpression([t9.arrayPattern([t9.identifier("__k")])], t9.identifier("__k"))]
3679
+ ),
3680
+ t9.identifier("join")
3681
+ ),
3682
+ [t9.stringLiteral(" ")]
3683
+ );
3684
+ }
3149
3685
  function tryStaticStyleObjectToCSS(expr) {
3150
3686
  const parts = [];
3151
3687
  for (const prop of expr.properties) {
@@ -3176,10 +3712,10 @@ function buildStyleObjectExpression(expr) {
3176
3712
  t9.templateElement({ raw: "", cooked: "" }, true)
3177
3713
  ],
3178
3714
  [
3179
- t9.callExpression(
3180
- t9.memberExpression(t9.identifier("__k"), t9.identifier("replace")),
3181
- [t9.regExpLiteral("[A-Z]", "g"), t9.stringLiteral("-$&")]
3182
- ),
3715
+ t9.callExpression(t9.memberExpression(t9.identifier("__k"), t9.identifier("replace")), [
3716
+ t9.regExpLiteral("[A-Z]", "g"),
3717
+ t9.stringLiteral("-$&")
3718
+ ]),
3183
3719
  t9.conditionalExpression(
3184
3720
  t9.logicalExpression(
3185
3721
  "&&",
@@ -3223,20 +3759,20 @@ function extractHtmlTemplatesFromConditional(expr) {
3223
3759
  }
3224
3760
  return {};
3225
3761
  }
3226
- function extractEnsureChildCall(expr) {
3762
+ function extractChildInstanceRef(expr) {
3227
3763
  if (!t9.isLogicalExpression(expr) || expr.operator !== "&&") return null;
3228
3764
  const right = expr.right;
3229
- let ensureCallExpr = null;
3765
+ let memberExpr = null;
3230
3766
  if (t9.isTemplateLiteral(right) && right.expressions.length === 1) {
3231
- ensureCallExpr = right.expressions[0];
3232
- } else if (t9.isCallExpression(right)) {
3233
- ensureCallExpr = right;
3767
+ const inner = right.expressions[0];
3768
+ if (t9.isMemberExpression(inner)) memberExpr = inner;
3769
+ } else if (t9.isMemberExpression(right)) {
3770
+ memberExpr = right;
3234
3771
  }
3235
- if (!ensureCallExpr || !t9.isCallExpression(ensureCallExpr) || !t9.isMemberExpression(ensureCallExpr.callee) || !t9.isThisExpression(ensureCallExpr.callee.object) || !t9.isIdentifier(ensureCallExpr.callee.property) || !ensureCallExpr.callee.property.name.startsWith("__ensureChild_"))
3772
+ if (!memberExpr || !t9.isThisExpression(memberExpr.object) || !t9.isIdentifier(memberExpr.property) || !memberExpr.property.name.startsWith("_"))
3236
3773
  return null;
3237
- const ensureMethod = ensureCallExpr.callee.property.name;
3238
- const instanceVar = "_" + ensureMethod.replace("__ensureChild_", "");
3239
- return { instanceVar, ensureMethod, guardExpr: expr.left };
3774
+ const instanceVar = memberExpr.property.name;
3775
+ return { instanceVar, guardExpr: expr.left };
3240
3776
  }
3241
3777
  function expressionMayBeFalsy(expr) {
3242
3778
  if (t9.isLogicalExpression(expr) && expr.operator === "&&") return true;
@@ -3251,6 +3787,7 @@ function canBeBoolean(expr) {
3251
3787
  }
3252
3788
  function isAlwaysTruthy(expr) {
3253
3789
  if (t9.isStringLiteral(expr) || t9.isNumericLiteral(expr) || t9.isTemplateLiteral(expr)) return true;
3790
+ if (t9.isObjectExpression(expr) || t9.isArrayExpression(expr)) return true;
3254
3791
  if (t9.isConditionalExpression(expr)) return isAlwaysTruthy(expr.consequent) && isAlwaysTruthy(expr.alternate);
3255
3792
  return false;
3256
3793
  }
@@ -3500,10 +4037,7 @@ function replaceJSXInExpression(node, mapJSXNodes, ctx) {
3500
4037
  );
3501
4038
  }
3502
4039
  const newBody = replaceJSXInExpression(callee.body, mapJSXNodes, ctx);
3503
- return t9.callExpression(
3504
- t9.arrowFunctionExpression(callee.params, newBody, callee.async),
3505
- node.arguments
3506
- );
4040
+ return t9.callExpression(t9.arrowFunctionExpression(callee.params, newBody, callee.async), node.arguments);
3507
4041
  }
3508
4042
  return node;
3509
4043
  }
@@ -3629,13 +4163,7 @@ function processElement(node, parts, ctx, elementPath = []) {
3629
4163
  pushString(parts, "");
3630
4164
  parts.push({
3631
4165
  type: "expression",
3632
- value: t9.callExpression(
3633
- t9.memberExpression(
3634
- t9.thisExpression(),
3635
- t9.identifier(`__ensureChild_${instance.instanceVar.replace(/^_/, "")}`)
3636
- ),
3637
- []
3638
- )
4166
+ value: t9.memberExpression(t9.thisExpression(), t9.identifier(instance.instanceVar))
3639
4167
  });
3640
4168
  return;
3641
4169
  }
@@ -3860,6 +4388,21 @@ function processElement(node, parts, ctx, elementPath = []) {
3860
4388
  err.__geaCompileError = true;
3861
4389
  throw err;
3862
4390
  }
4391
+ if (propAttrName === "class" && t9.isObjectExpression(rawExpr)) {
4392
+ const staticClass = tryStaticClassObjectToString(rawExpr);
4393
+ if (staticClass !== null) {
4394
+ if (staticClass) {
4395
+ html += ` class="${staticClass}"`;
4396
+ }
4397
+ return;
4398
+ }
4399
+ parts.push({ type: "string", value: html });
4400
+ const classExpr = buildClassObjectExpression(rawExpr);
4401
+ parts.push({ type: "string", value: ` class="` });
4402
+ parts.push({ type: "expression", value: classExpr });
4403
+ html = '"';
4404
+ return;
4405
+ }
3863
4406
  if (propAttrName === "style" && t9.isObjectExpression(rawExpr)) {
3864
4407
  const staticCSS = tryStaticStyleObjectToCSS(rawExpr);
3865
4408
  if (staticCSS) {
@@ -3872,27 +4415,33 @@ function processElement(node, parts, ctx, elementPath = []) {
3872
4415
  [t9.stringLiteral("; ")]
3873
4416
  );
3874
4417
  const skipCondition2 = buildAttrSkipCondition(styleExpr, rawExpr);
3875
- parts.push({
3876
- type: "expression",
3877
- value: t9.conditionalExpression(
3878
- skipCondition2,
3879
- t9.stringLiteral(""),
3880
- t9.templateLiteral(
3881
- [
3882
- t9.templateElement({ raw: ' style="', cooked: ' style="' }, false),
3883
- t9.templateElement({ raw: '"', cooked: '"' }, true)
3884
- ],
3885
- [styleExpr]
4418
+ if (t9.isBooleanLiteral(skipCondition2) && !skipCondition2.value) {
4419
+ parts.push({ type: "string", value: ` style="` });
4420
+ parts.push({ type: "expression", value: styleExpr });
4421
+ html = '"';
4422
+ } else {
4423
+ parts.push({
4424
+ type: "expression",
4425
+ value: t9.conditionalExpression(
4426
+ skipCondition2,
4427
+ t9.stringLiteral(""),
4428
+ t9.templateLiteral(
4429
+ [
4430
+ t9.templateElement({ raw: ' style="', cooked: ' style="' }, false),
4431
+ t9.templateElement({ raw: '"', cooked: '"' }, true)
4432
+ ],
4433
+ [styleExpr]
4434
+ )
3886
4435
  )
3887
- )
3888
- });
3889
- html = "";
4436
+ });
4437
+ html = "";
4438
+ }
3890
4439
  return;
3891
4440
  }
3892
4441
  parts.push({ type: "string", value: html });
3893
4442
  const expr = transformJSXExpression(rawExpr, ctx);
3894
4443
  const skipCondition = buildAttrSkipCondition(expr, rawExpr);
3895
- const templateExpr = propAttrName === "class" ? t9.callExpression(t9.memberExpression(expr, t9.identifier("trim")), []) : expr;
4444
+ const templateExpr = expr;
3896
4445
  if (t9.isBooleanLiteral(skipCondition) && !skipCondition.value) {
3897
4446
  parts.push({ type: "string", value: ` ${propAttrName}="` });
3898
4447
  parts.push({ type: "expression", value: templateExpr });
@@ -4000,7 +4549,7 @@ function processChildren(children, parts, ctx, elementPath, dcCursor, directChil
4000
4549
  let expr = transformJSXExpression(rawExpr, ctx);
4001
4550
  const stateSlots = ctx.stateChildSlots;
4002
4551
  const stateCounter = ctx.stateChildSlotCounter;
4003
- const childCallInfo = stateSlots && stateCounter && expressionMayBeFalsy(rawExpr) ? extractEnsureChildCall(expr) : null;
4552
+ const childCallInfo = stateSlots && stateCounter && expressionMayBeFalsy(rawExpr) ? extractChildInstanceRef(expr) : null;
4004
4553
  if (childCallInfo && stateSlots && stateCounter) {
4005
4554
  const markerId = `sc${stateCounter.value}`;
4006
4555
  stateCounter.value++;
@@ -4008,7 +4557,6 @@ function processChildren(children, parts, ctx, elementPath, dcCursor, directChil
4008
4557
  stateSlots.push({
4009
4558
  markerId,
4010
4559
  childInstanceVar: childCallInfo.instanceVar,
4011
- ensureMethodName: childCallInfo.ensureMethod,
4012
4560
  guardExpr: childCallInfo.guardExpr,
4013
4561
  dependencies: collectExpressionDependencies(childCallInfo.guardExpr, ctx.stateRefs, setupStatements)
4014
4562
  });
@@ -4120,12 +4668,7 @@ function ensureMapItemHelper(classBody2, ctx, helperName) {
4120
4668
  if (ctx.arrayPathParts.length === 0) return base;
4121
4669
  const [, ...rest] = ctx.arrayPathParts;
4122
4670
  const isIndex = /^\d+$/.test(first);
4123
- const optionalFirst = t10.optionalMemberExpression(
4124
- base,
4125
- isIndex ? t10.numericLiteral(Number(first)) : t10.identifier(first),
4126
- isIndex,
4127
- true
4128
- );
4671
+ const optionalFirst = ctx.isImportedState ? t10.memberExpression(base, isIndex ? t10.numericLiteral(Number(first)) : t10.identifier(first), isIndex) : t10.optionalMemberExpression(base, isIndex ? t10.numericLiteral(Number(first)) : t10.identifier(first), isIndex, true);
4129
4672
  return rest.length > 0 ? buildMemberChainFromParts(optionalFirst, rest) : optionalFirst;
4130
4673
  })();
4131
4674
  const findPredicate = ctx.itemIdProperty && ctx.itemIdProperty !== ITEM_IS_KEY ? t10.arrowFunctionExpression(
@@ -4146,7 +4689,11 @@ function ensureMapItemHelper(classBody2, ctx, helperName) {
4146
4689
  )
4147
4690
  ) : t10.arrowFunctionExpression(
4148
4691
  [t10.identifier("_"), t10.identifier("__i")],
4149
- t10.binaryExpression("===", t10.callExpression(t10.identifier("String"), [t10.identifier("__i")]), t10.identifier("__itemId"))
4692
+ t10.binaryExpression(
4693
+ "===",
4694
+ t10.callExpression(t10.identifier("String"), [t10.identifier("__i")]),
4695
+ t10.identifier("__itemId")
4696
+ )
4150
4697
  );
4151
4698
  const method = jsMethod`${id3(helperName)}(e) {
4152
4699
  const __el = e.target.closest('[data-gea-item-id]');
@@ -4472,13 +5019,13 @@ function findClassMethod(classBody2, name) {
4472
5019
 
4473
5020
  // src/generate-components.ts
4474
5021
  import * as t11 from "@babel/types";
4475
- import { appendToBody, id as id4, js as js2, jsMethod as jsMethod2 } from "eszter";
5022
+ import { appendToBody, id as id4, jsMethod as jsMethod2 } from "eszter";
4476
5023
  import { createRequire as createRequire6 } from "module";
4477
5024
  function childHasNoProps(child) {
4478
5025
  return t11.isObjectExpression(child.propsExpression) && child.propsExpression.properties.length === 0;
4479
5026
  }
4480
5027
  var require7 = createRequire6(import.meta.url);
4481
- var traverse5 = require7("@babel/traverse").default;
5028
+ var traverse6 = require7("@babel/traverse").default;
4482
5029
  function getDirectPropMappings(child, templatePropNames) {
4483
5030
  if (!child.propsExpression || !t11.isObjectExpression(child.propsExpression)) return null;
4484
5031
  const mappings = [];
@@ -4496,9 +5043,10 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
4496
5043
  if (componentInstances.size === 0) return;
4497
5044
  const childComponents = Array.from(componentInstances.values()).flat();
4498
5045
  const constructionOrder = [...childComponents].sort((a, b) => (b.dfsIndex ?? 0) - (a.dfsIndex ?? 0));
4499
- const instanceStatements = buildInstanceStatements(constructionOrder);
5046
+ const instanceStatements = buildInstanceStatements(constructionOrder, directForwardingChildren);
5047
+ const lazyChildren = constructionOrder.filter((child) => child.lazy);
4500
5048
  let injected = false;
4501
- traverse5(ast, {
5049
+ traverse6(ast, {
4502
5050
  ClassDeclaration(path) {
4503
5051
  if (!t11.isIdentifier(path.node.superClass)) return;
4504
5052
  const existingCtor = path.node.body.body.find(
@@ -4516,22 +5064,68 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
4516
5064
  path.node.body.body.unshift(ctor);
4517
5065
  injected = true;
4518
5066
  }
5067
+ for (const child of lazyChildren) {
5068
+ const isDirect = directForwardingChildren?.has(child.instanceVar);
5069
+ const noProps = childHasNoProps(child);
5070
+ const hasPropsBuilder = !isDirect && !noProps;
5071
+ const backingField = `__lazy${child.instanceVar}`;
5072
+ let propsArg;
5073
+ if (hasPropsBuilder) {
5074
+ propsArg = t11.callExpression(
5075
+ t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
5076
+ []
5077
+ );
5078
+ } else if (child.directMappings && child.directMappings.length > 0) {
5079
+ propsArg = t11.objectExpression(
5080
+ child.directMappings.map(
5081
+ (m) => t11.objectProperty(
5082
+ t11.identifier(m.childPropName),
5083
+ t11.memberExpression(
5084
+ t11.memberExpression(t11.thisExpression(), t11.identifier("props")),
5085
+ t11.identifier(m.parentPropName)
5086
+ )
5087
+ )
5088
+ )
5089
+ );
5090
+ } else {
5091
+ propsArg = t11.objectExpression([]);
5092
+ }
5093
+ const getter = t11.classMethod(
5094
+ "get",
5095
+ t11.identifier(child.instanceVar),
5096
+ [],
5097
+ t11.blockStatement([
5098
+ t11.ifStatement(
5099
+ t11.unaryExpression("!", t11.memberExpression(t11.thisExpression(), t11.identifier(backingField))),
5100
+ t11.expressionStatement(
5101
+ t11.assignmentExpression(
5102
+ "=",
5103
+ t11.memberExpression(t11.thisExpression(), t11.identifier(backingField)),
5104
+ t11.callExpression(t11.memberExpression(t11.thisExpression(), t11.identifier("__child")), [
5105
+ t11.identifier(child.tagName),
5106
+ propsArg
5107
+ ])
5108
+ )
5109
+ )
5110
+ ),
5111
+ t11.returnStatement(t11.memberExpression(t11.thisExpression(), t11.identifier(backingField)))
5112
+ ])
5113
+ );
5114
+ path.node.body.body.push(getter);
5115
+ }
4519
5116
  childComponents.forEach((child) => {
4520
5117
  const isDirect = directForwardingChildren?.has(child.instanceVar);
4521
5118
  const noProps = childHasNoProps(child);
4522
5119
  const hasPropsBuilder = !isDirect && !noProps;
4523
5120
  if (hasPropsBuilder) {
4524
5121
  path.node.body.body.push(buildPropsBuilderMethod(child));
4525
- path.node.body.body.push(buildRefreshMethod(child));
4526
5122
  }
4527
- path.node.body.body.push(buildEnsureMethod(child, hasPropsBuilder));
4528
5123
  });
4529
- ensureDisposeMethod(path.node.body, childComponents);
4530
5124
  }
4531
5125
  });
4532
5126
  }
4533
5127
  function injectComponentRegistrations(ast, componentInstances) {
4534
- traverse5(ast, {
5128
+ traverse6(ast, {
4535
5129
  ClassMethod(path) {
4536
5130
  if (!t11.isIdentifier(path.node.key) || path.node.key.name !== "template") return;
4537
5131
  const registrations = Array.from(componentInstances.keys()).map(
@@ -4545,22 +5139,55 @@ function injectComponentRegistrations(ast, componentInstances) {
4545
5139
  }
4546
5140
  });
4547
5141
  }
4548
- function buildInstanceStatements(instances) {
5142
+ function buildInstanceStatements(instances, directForwardingChildren) {
4549
5143
  const stmts = [];
4550
5144
  instances.forEach((child) => {
4551
- stmts.push(js2`this.${id4(child.instanceVar)} = null;`);
4552
- });
4553
- return stmts;
4554
- }
4555
- function getPropsBuilderMethodName(child) {
4556
- return `__buildProps_${child.instanceVar.replace(/^_/, "")}`;
4557
- }
4558
- function getEnsureChildMethodName(child) {
4559
- return `__ensureChild_${child.instanceVar.replace(/^_/, "")}`;
4560
- }
4561
- function collectBindingNames(stmt) {
4562
- if (t11.isVariableDeclaration(stmt)) {
4563
- const names = [];
5145
+ if (child.lazy) return;
5146
+ let propsArg;
5147
+ const isDirect = directForwardingChildren?.has(child.instanceVar);
5148
+ const noProps = childHasNoProps(child);
5149
+ const hasPropsBuilder = !isDirect && !noProps;
5150
+ if (hasPropsBuilder) {
5151
+ propsArg = t11.callExpression(
5152
+ t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
5153
+ []
5154
+ );
5155
+ } else if (child.directMappings && child.directMappings.length > 0) {
5156
+ propsArg = t11.objectExpression(
5157
+ child.directMappings.map(
5158
+ (m) => t11.objectProperty(
5159
+ t11.identifier(m.childPropName),
5160
+ t11.memberExpression(
5161
+ t11.memberExpression(t11.thisExpression(), t11.identifier("props")),
5162
+ t11.identifier(m.parentPropName)
5163
+ )
5164
+ )
5165
+ )
5166
+ );
5167
+ } else {
5168
+ propsArg = t11.objectExpression([]);
5169
+ }
5170
+ stmts.push(
5171
+ t11.expressionStatement(
5172
+ t11.assignmentExpression(
5173
+ "=",
5174
+ t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)),
5175
+ t11.callExpression(t11.memberExpression(t11.thisExpression(), t11.identifier("__child")), [
5176
+ t11.identifier(child.tagName),
5177
+ propsArg
5178
+ ])
5179
+ )
5180
+ )
5181
+ );
5182
+ });
5183
+ return stmts;
5184
+ }
5185
+ function getPropsBuilderMethodName(child) {
5186
+ return `__buildProps_${child.instanceVar.replace(/^_/, "")}`;
5187
+ }
5188
+ function collectBindingNames(stmt) {
5189
+ if (t11.isVariableDeclaration(stmt)) {
5190
+ const names = [];
4564
5191
  const collect = (node) => {
4565
5192
  if (t11.isIdentifier(node)) names.push(node.name);
4566
5193
  else if (t11.isObjectPattern(node))
@@ -4621,102 +5248,16 @@ function buildPropsBuilderMethod(child) {
4621
5248
  );
4622
5249
  if (hasPropsDestructure) {
4623
5250
  const tryBlock = t11.blockStatement([...prunedSetup, returnStmt]);
4624
- const catchBlock = t11.blockStatement([t11.returnStatement(t11.objectExpression([]))]);
4625
- const tryCatch = t11.tryStatement(tryBlock, t11.catchClause(null, catchBlock));
5251
+ const tryCatch = t11.tryStatement(tryBlock, loggingCatchClause([t11.returnStatement(t11.objectExpression([]))]));
4626
5252
  return appendToBody(jsMethod2`${id4(getPropsBuilderMethodName(child))}() {}`, tryCatch);
4627
5253
  }
4628
5254
  return appendToBody(jsMethod2`${id4(getPropsBuilderMethodName(child))}() {}`, ...prunedSetup, returnStmt);
4629
5255
  }
4630
- function buildEnsureMethod(child, hasPropsBuilder = true) {
4631
- let propsArg;
4632
- if (hasPropsBuilder && !childHasNoProps(child)) {
4633
- propsArg = t11.callExpression(
4634
- t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
4635
- []
4636
- );
4637
- } else if (child.directMappings && child.directMappings.length > 0) {
4638
- propsArg = t11.objectExpression(
4639
- child.directMappings.map(
4640
- (m) => t11.objectProperty(
4641
- t11.identifier(m.childPropName),
4642
- t11.memberExpression(
4643
- t11.memberExpression(t11.thisExpression(), t11.identifier("props")),
4644
- t11.identifier(m.parentPropName)
4645
- )
4646
- )
4647
- )
4648
- );
4649
- } else {
4650
- propsArg = t11.objectExpression([]);
4651
- }
4652
- const refreshPropsStmt = hasPropsBuilder && !childHasNoProps(child) ? t11.expressionStatement(
4653
- t11.callExpression(
4654
- t11.memberExpression(
4655
- t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)),
4656
- t11.identifier("__geaUpdateProps")
4657
- ),
4658
- [
4659
- t11.callExpression(
4660
- t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
4661
- []
4662
- )
4663
- ]
4664
- )
4665
- ) : null;
4666
- return appendToBody(
4667
- jsMethod2`${id4(getEnsureChildMethodName(child))}() {}`,
4668
- t11.ifStatement(
4669
- t11.unaryExpression("!", t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar))),
4670
- t11.blockStatement([
4671
- t11.expressionStatement(
4672
- t11.assignmentExpression(
4673
- "=",
4674
- t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)),
4675
- t11.newExpression(t11.identifier(child.tagName), [propsArg])
4676
- )
4677
- ),
4678
- js2`this.${id4(child.instanceVar)}.parentComponent = this;`,
4679
- js2`this.${id4(child.instanceVar)}.__geaCompiledChild = true;`
4680
- ]),
4681
- refreshPropsStmt ? t11.blockStatement([refreshPropsStmt]) : void 0
4682
- ),
4683
- t11.returnStatement(t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)))
4684
- );
4685
- }
4686
- function buildRefreshMethod(child) {
4687
- const method = jsMethod2`${id4(`__refreshChildProps_${child.instanceVar.replace(/^_/, "")}`)}() {}`;
4688
- method.body.body.push(js2`const child = this.${id4(child.instanceVar)};`);
4689
- if (child.lazy) {
4690
- method.body.body.push(
4691
- t11.ifStatement(t11.unaryExpression("!", t11.identifier("child")), t11.blockStatement([t11.returnStatement()]))
4692
- );
4693
- } else {
4694
- method.body.body.push(
4695
- t11.ifStatement(t11.unaryExpression("!", t11.identifier("child")), t11.blockStatement([t11.returnStatement()]))
4696
- );
4697
- }
4698
- method.body.body.push(
4699
- js2`child.__geaUpdateProps(this.${id4(getPropsBuilderMethodName(child))}());`
4700
- );
4701
- return method;
4702
- }
4703
- function ensureDisposeMethod(classBody2, children) {
4704
- const disposeCalls = children.map((child) => js2`this.${id4(child.instanceVar)}?.dispose?.();`);
4705
- const existingDispose = classBody2.body.find(
4706
- (member) => t11.isClassMethod(member) && t11.isIdentifier(member.key) && member.key.name === "dispose"
4707
- );
4708
- if (existingDispose) {
4709
- existingDispose.body.body.unshift(...disposeCalls);
4710
- return;
4711
- }
4712
- classBody2.body.push(
4713
- appendToBody(jsMethod2`${id4("dispose")}() {}`, ...disposeCalls, js2`super.dispose();`)
4714
- );
4715
- }
4716
5256
 
4717
5257
  // src/apply-reactivity.ts
5258
+ import babelGenerator from "@babel/generator";
4718
5259
  import * as t18 from "@babel/types";
4719
- import { appendToBody as appendToBody5, id as id11, js as js7, jsBlockBody as jsBlockBody5, jsExpr as jsExpr5, jsMethod as jsMethod8 } from "eszter";
5260
+ import { appendToBody as appendToBody5, id as id11, js as js7, jsBlockBody as jsBlockBody4, jsExpr as jsExpr4, jsMethod as jsMethod8 } from "eszter";
4720
5261
 
4721
5262
  // src/generate-observe.ts
4722
5263
  import * as t13 from "@babel/types";
@@ -4727,7 +5268,7 @@ import * as t12 from "@babel/types";
4727
5268
  import { id as id5, js as js3, jsBlockBody as jsBlockBody2, jsExpr as jsExpr2 } from "eszter";
4728
5269
  import { createRequire as createRequire7 } from "module";
4729
5270
  var require8 = createRequire7(import.meta.url);
4730
- var traverse6 = require8("@babel/traverse").default;
5271
+ var traverse7 = require8("@babel/traverse").default;
4731
5272
  function buildPathPartsEquals(expr, parts) {
4732
5273
  return parts.reduce(
4733
5274
  (acc, part, index) => t12.logicalExpression(
@@ -4773,10 +5314,7 @@ function buildValueExpression(textExpr, stateRefs) {
4773
5314
  }
4774
5315
  if (textExpr.isImportedState && textExpr.storeVar) {
4775
5316
  return buildMemberChainFromParts(
4776
- t12.memberExpression(
4777
- t12.memberExpression(t12.thisExpression(), t12.identifier("__stores")),
4778
- t12.identifier(textExpr.storeVar)
4779
- ),
5317
+ t12.memberExpression(t12.identifier(textExpr.storeVar), t12.identifier("__store")),
4780
5318
  textExpr.pathParts
4781
5319
  );
4782
5320
  }
@@ -4784,7 +5322,7 @@ function buildValueExpression(textExpr, stateRefs) {
4784
5322
  }
4785
5323
  function rewriteStateRefs(expr, stateRefs) {
4786
5324
  const prog = t12.program([t12.expressionStatement(expr)]);
4787
- traverse6(prog, {
5325
+ traverse7(prog, {
4788
5326
  noScope: true,
4789
5327
  Identifier(path) {
4790
5328
  if (path.parentPath && t12.isMemberExpression(path.parentPath.node) && path.parentPath.node.property === path.node)
@@ -4793,13 +5331,20 @@ function rewriteStateRefs(expr, stateRefs) {
4793
5331
  const ref = stateRefs.get(path.node.name);
4794
5332
  if (ref.kind === "local") {
4795
5333
  path.replaceWith(t12.thisExpression());
4796
- } else {
5334
+ } else if (ref.kind === "imported-destructured" && ref.storeVar && ref.propName) {
4797
5335
  path.replaceWith(
4798
5336
  t12.memberExpression(
4799
- t12.memberExpression(t12.thisExpression(), t12.identifier("__stores")),
4800
- t12.identifier(path.node.name)
5337
+ t12.memberExpression(t12.identifier(ref.storeVar), t12.identifier("__store")),
5338
+ t12.identifier(ref.propName)
4801
5339
  )
4802
5340
  );
5341
+ path.skip();
5342
+ } else if (ref.kind === "local-destructured" && ref.propName) {
5343
+ path.replaceWith(t12.memberExpression(t12.thisExpression(), t12.identifier(ref.propName)));
5344
+ path.skip();
5345
+ } else {
5346
+ path.replaceWith(t12.memberExpression(t12.identifier(path.node.name), t12.identifier("__store")));
5347
+ path.skip();
4803
5348
  }
4804
5349
  }
4805
5350
  });
@@ -4834,6 +5379,10 @@ function buildSimpleUpdate(binding, param, stateRefs) {
4834
5379
  const idx = t12.numericLiteral(binding.textNodeIndex);
4835
5380
  return js3`if (${el}) { const __tn = ${jsExpr2`${el}.childNodes[${idx}]`}; if (__tn && __tn.nodeValue !== ${valueExpr}) __tn.nodeValue = ${valueExpr}; }`;
4836
5381
  }
5382
+ if (target === "textContent" && binding.bindingId && binding.bindingId !== "") {
5383
+ const suffix = t12.stringLiteral(binding.bindingId);
5384
+ return js3`${jsExpr2`this.__updateText(${suffix}, ${valueExpr})`};`;
5385
+ }
4837
5386
  return js3`if (${el}) { ${jsExpr2`${el}.${id5(target)}`} = ${valueExpr}; }`;
4838
5387
  }
4839
5388
  function buildWildcardUpdate(binding, param, stateRefs) {
@@ -4976,7 +5525,7 @@ import * as t14 from "@babel/types";
4976
5525
  import { appendToBody as appendToBody2, id as id7, js as js4, jsMethod as jsMethod4 } from "eszter";
4977
5526
  import { createRequire as createRequire8 } from "module";
4978
5527
  var require9 = createRequire8(import.meta.url);
4979
- var traverse7 = require9("@babel/traverse").default;
5528
+ var traverse8 = require9("@babel/traverse").default;
4980
5529
  var EVENT_NAMES = /* @__PURE__ */ new Set([
4981
5530
  "click",
4982
5531
  "dblclick",
@@ -5009,23 +5558,50 @@ var EVENT_NAMES = /* @__PURE__ */ new Set([
5009
5558
  "dragleave",
5010
5559
  "drop"
5011
5560
  ]);
5012
- function collectItemTemplateProps(template, itemVar) {
5013
- const props = /* @__PURE__ */ new Set();
5014
- const program9 = t14.program([t14.expressionStatement(t14.cloneNode(template, true))]);
5015
- traverse7(program9, {
5561
+ function collectItemTemplatePropTree(template, itemVar) {
5562
+ const tree = {};
5563
+ const program10 = t14.program([t14.expressionStatement(t14.cloneNode(template, true))]);
5564
+ traverse8(program10, {
5016
5565
  noScope: true,
5017
5566
  MemberExpression(path) {
5018
- if (!t14.isIdentifier(path.node.object, { name: itemVar })) return;
5019
- if (!t14.isIdentifier(path.node.property) || path.node.computed) return;
5020
- props.add(path.node.property.name);
5567
+ const chain = [];
5568
+ let node = path.node;
5569
+ while (t14.isMemberExpression(node) && !node.computed && t14.isIdentifier(node.property)) {
5570
+ chain.unshift(node.property.name);
5571
+ node = node.object;
5572
+ }
5573
+ if (!t14.isIdentifier(node, { name: itemVar }) || chain.length === 0) return;
5574
+ let cursor = tree;
5575
+ for (let i = 0; i < chain.length; i++) {
5576
+ const key = chain[i];
5577
+ if (i === chain.length - 1) {
5578
+ if (!(key in cursor)) cursor[key] = true;
5579
+ } else {
5580
+ if (!(key in cursor) || cursor[key] === true) cursor[key] = {};
5581
+ cursor = cursor[key];
5582
+ }
5583
+ }
5021
5584
  }
5022
5585
  });
5023
- return Array.from(props);
5586
+ return tree;
5587
+ }
5588
+ function buildDummyFromTree(tree, keyProp) {
5589
+ const props = [];
5590
+ for (const [key, value] of Object.entries(tree)) {
5591
+ if (key === keyProp) {
5592
+ props.push(t14.objectProperty(t14.identifier(key), t14.numericLiteral(0)));
5593
+ } else if (value === true) {
5594
+ props.push(t14.objectProperty(t14.identifier(key), t14.stringLiteral("")));
5595
+ } else {
5596
+ props.push(t14.objectProperty(t14.identifier(key), buildDummyFromTree(value, null)));
5597
+ }
5598
+ }
5599
+ return t14.objectExpression(props);
5024
5600
  }
5025
5601
  function collectPatchEntries(arrayMap) {
5026
5602
  const cloned = t14.cloneNode(arrayMap.itemTemplate, true);
5027
5603
  const tempFile = t14.file(t14.program([t14.expressionStatement(cloned)]));
5028
- traverse7(tempFile, {
5604
+ traverse8(tempFile, {
5029
5605
  Identifier(path) {
5030
5606
  if (path.node.name === arrayMap.itemVariable) path.node.name = "item";
5031
5607
  else if (arrayMap.indexVariable && path.node.name === arrayMap.indexVariable) path.node.name = "__idx";
@@ -5039,6 +5615,9 @@ function collectPatchEntries(arrayMap) {
5039
5615
  const rootIsComponent = isComponentTag(rootTagName);
5040
5616
  walkJSXForPatch(modified, [], entries, rootIsComponent);
5041
5617
  }
5618
+ for (const ent of entries) {
5619
+ ent.expression = optionalizeMemberChainsAfterComputedItemKey(ent.expression, "item");
5620
+ }
5042
5621
  return { entries, requiresRerender };
5043
5622
  }
5044
5623
  function walkJSXForPatch(node, path, entries, rootIsComponent = false) {
@@ -5125,14 +5704,17 @@ function buildElementNavExpr(base, childPath) {
5125
5704
  }
5126
5705
  return expr;
5127
5706
  }
5707
+ function childPathRefName(path) {
5708
+ return `__ref_${path.join("_")}`;
5709
+ }
5128
5710
  function hoistStoreReads(entries, storeVar) {
5129
5711
  if (!storeVar) return { hoists: [], patchedEntries: entries };
5130
5712
  const hoistMap = /* @__PURE__ */ new Map();
5131
5713
  let counter = 0;
5132
5714
  function replaceStoreReads(expr) {
5133
5715
  const cloned = t14.cloneNode(expr, true);
5134
- const program9 = t14.program([t14.expressionStatement(cloned)]);
5135
- traverse7(program9, {
5716
+ const program10 = t14.program([t14.expressionStatement(cloned)]);
5717
+ traverse8(program10, {
5136
5718
  noScope: true,
5137
5719
  MemberExpression(path) {
5138
5720
  if (!t14.isIdentifier(path.node.object, { name: storeVar })) return;
@@ -5147,7 +5729,7 @@ function hoistStoreReads(entries, storeVar) {
5147
5729
  path.replaceWith(t14.identifier(hoist.varName));
5148
5730
  }
5149
5731
  });
5150
- return program9.body[0].expression;
5732
+ return program10.body[0].expression;
5151
5733
  }
5152
5734
  const patchedEntries = entries.map((entry) => ({
5153
5735
  ...entry,
@@ -5187,7 +5769,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5187
5769
  if (setupVarNames.size > 0) {
5188
5770
  const freeVars = /* @__PURE__ */ new Set();
5189
5771
  for (const entry of entries) {
5190
- traverse7(t14.expressionStatement(t14.cloneNode(entry.expression, true)), {
5772
+ traverse8(t14.expressionStatement(t14.cloneNode(entry.expression, true)), {
5191
5773
  noScope: true,
5192
5774
  Identifier(p) {
5193
5775
  if (t14.isMemberExpression(p.parent) && p.parent.property === p.node && !p.parent.computed) return;
@@ -5240,7 +5822,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5240
5822
  if (!t14.isJSXExpressionContainer(attr.value) || t14.isJSXEmptyExpression(attr.value.expression)) continue;
5241
5823
  const exprClone = t14.cloneNode(attr.value.expression, true);
5242
5824
  const tempProg = t14.file(t14.program([t14.expressionStatement(exprClone)]));
5243
- traverse7(tempProg, {
5825
+ traverse8(tempProg, {
5244
5826
  Identifier(path) {
5245
5827
  if (path.node.name === arrayMap.itemVariable) path.node.name = "item";
5246
5828
  else if (arrayMap.indexVariable && path.node.name === arrayMap.indexVariable) path.node.name = "__idx";
@@ -5259,7 +5841,8 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5259
5841
  else if (t14.isObjectPattern(decl.id)) {
5260
5842
  for (const prop of decl.id.properties) {
5261
5843
  if (t14.isObjectProperty(prop) && t14.isIdentifier(prop.value)) setupVarNames.add(prop.value.name);
5262
- else if (t14.isRestElement(prop) && t14.isIdentifier(prop.argument)) setupVarNames.add(prop.argument.name);
5844
+ else if (t14.isRestElement(prop) && t14.isIdentifier(prop.argument))
5845
+ setupVarNames.add(prop.argument.name);
5263
5846
  }
5264
5847
  }
5265
5848
  }
@@ -5267,7 +5850,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5267
5850
  }
5268
5851
  const propsRefsFreeVars = /* @__PURE__ */ new Set();
5269
5852
  for (const prop of propsProperties) {
5270
- traverse7(t14.expressionStatement(t14.cloneNode(prop.value, true)), {
5853
+ traverse8(t14.expressionStatement(t14.cloneNode(prop.value, true)), {
5271
5854
  noScope: true,
5272
5855
  Identifier(p) {
5273
5856
  if (t14.isMemberExpression(p.parent) && p.parent.property === p.node && !p.parent.computed) return;
@@ -5287,7 +5870,11 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5287
5870
  for (const stmt of templateSetupContext.statements) {
5288
5871
  let clonedStmt = t14.cloneNode(stmt, true);
5289
5872
  if (propRefsNames.size > 0 || wholeParamName) {
5290
- clonedStmt = replacePropRefsInExpression(clonedStmt, propRefsNames, wholeParamName);
5873
+ clonedStmt = replacePropRefsInExpression(
5874
+ clonedStmt,
5875
+ propRefsNames,
5876
+ wholeParamName
5877
+ );
5291
5878
  }
5292
5879
  rerenderBody.push(clonedStmt);
5293
5880
  }
@@ -5309,7 +5896,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5309
5896
  }
5310
5897
  if (entries.length === 0) return null;
5311
5898
  const { hoists, patchedEntries } = hoistStoreReads(entries, arrayMap.storeVar);
5312
- const itemProps = collectItemTemplateProps(arrayMap.itemTemplate, arrayMap.itemVariable);
5899
+ const propTree = collectItemTemplatePropTree(arrayMap.itemTemplate, arrayMap.itemVariable);
5313
5900
  const containerRef = t14.memberExpression(t14.thisExpression(), t14.identifier(containerProp));
5314
5901
  const cVar = t14.identifier("__c");
5315
5902
  const elVar = t14.identifier("el");
@@ -5317,25 +5904,16 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5317
5904
  body.push(t14.variableDeclaration("var", [t14.variableDeclarator(cVar, containerRef)]));
5318
5905
  const isPrimitiveKey = !itemIdProperty || itemIdProperty === ITEM_IS_KEY;
5319
5906
  const dummyItem = isPrimitiveKey ? t14.stringLiteral("__dummy__") : (() => {
5320
- const dummyProps = [];
5321
- const seen = /* @__PURE__ */ new Set();
5322
- for (const prop of [itemIdProperty, ...itemProps]) {
5323
- if (seen.has(prop)) continue;
5324
- seen.add(prop);
5325
- dummyProps.push(
5326
- t14.objectProperty(t14.identifier(prop), prop === itemIdProperty ? t14.numericLiteral(0) : t14.stringLiteral(""))
5327
- );
5328
- }
5329
- return t14.objectExpression(dummyProps);
5907
+ if (itemIdProperty && !(itemIdProperty in propTree)) propTree[itemIdProperty] = true;
5908
+ return buildDummyFromTree(propTree, itemIdProperty);
5330
5909
  })();
5331
5910
  const tplInit = [
5332
5911
  t14.variableDeclaration("var", [
5333
5912
  t14.variableDeclarator(
5334
5913
  t14.identifier("__tw"),
5335
- t14.callExpression(
5336
- t14.memberExpression(t14.identifier("document"), t14.identifier("createElement")),
5337
- [t14.stringLiteral("template")]
5338
- )
5914
+ t14.callExpression(t14.memberExpression(t14.identifier("document"), t14.identifier("createElement")), [
5915
+ t14.stringLiteral("template")
5916
+ ])
5339
5917
  )
5340
5918
  ]),
5341
5919
  t14.expressionStatement(
@@ -5362,7 +5940,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5362
5940
  body.push(
5363
5941
  t14.ifStatement(
5364
5942
  t14.unaryExpression("!", t14.memberExpression(cVar, t14.identifier("__geaTpl"))),
5365
- t14.blockStatement([t14.tryStatement(t14.blockStatement(tplInit), t14.catchClause(null, t14.blockStatement([])))])
5943
+ t14.blockStatement([t14.tryStatement(t14.blockStatement(tplInit), loggingCatchClause())])
5366
5944
  )
5367
5945
  );
5368
5946
  if (arrayMap.containerBindingId) {
@@ -5401,10 +5979,9 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5401
5979
  t14.variableDeclaration("var", [
5402
5980
  t14.variableDeclarator(
5403
5981
  t14.identifier("__fw"),
5404
- t14.callExpression(
5405
- t14.memberExpression(t14.identifier("document"), t14.identifier("createElement")),
5406
- [t14.stringLiteral("template")]
5407
- )
5982
+ t14.callExpression(t14.memberExpression(t14.identifier("document"), t14.identifier("createElement")), [
5983
+ t14.stringLiteral("template")
5984
+ ])
5408
5985
  )
5409
5986
  ]),
5410
5987
  t14.expressionStatement(
@@ -5432,8 +6009,20 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5432
6009
  for (const hoist of hoists) {
5433
6010
  body.push(t14.variableDeclaration("var", [t14.variableDeclarator(t14.identifier(hoist.varName), hoist.expression)]));
5434
6011
  }
6012
+ const refMap = /* @__PURE__ */ new Map();
5435
6013
  for (const entry of patchedEntries) {
6014
+ if (entry.childPath.length === 0) continue;
6015
+ const key = entry.childPath.join("_");
6016
+ if (refMap.has(key)) continue;
6017
+ const refName = childPathRefName(entry.childPath);
5436
6018
  const navExpr = buildElementNavExpr(elVar, entry.childPath);
6019
+ body.push(
6020
+ t14.expressionStatement(t14.assignmentExpression("=", t14.memberExpression(elVar, t14.identifier(refName)), navExpr))
6021
+ );
6022
+ refMap.set(key, t14.memberExpression(elVar, t14.identifier(refName)));
6023
+ }
6024
+ for (const entry of patchedEntries) {
6025
+ const navExpr = entry.childPath.length > 0 ? refMap.get(entry.childPath.join("_")) || buildElementNavExpr(elVar, entry.childPath) : elVar;
5437
6026
  switch (entry.type) {
5438
6027
  case "className":
5439
6028
  body.push(
@@ -5475,17 +6064,26 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5475
6064
  t14.memberExpression(
5476
6065
  t14.callExpression(
5477
6066
  t14.memberExpression(
5478
- t14.callExpression(t14.memberExpression(t14.identifier("Object"), t14.identifier("entries")), [attrVal]),
6067
+ t14.callExpression(t14.memberExpression(t14.identifier("Object"), t14.identifier("entries")), [
6068
+ attrVal
6069
+ ]),
5479
6070
  t14.identifier("map")
5480
6071
  ),
5481
6072
  [
5482
6073
  t14.arrowFunctionExpression(
5483
6074
  [t14.arrayPattern([t14.identifier("k"), t14.identifier("v")])],
5484
- t14.binaryExpression("+", t14.binaryExpression(
6075
+ t14.binaryExpression(
5485
6076
  "+",
5486
- t14.callExpression(t14.memberExpression(t14.identifier("k"), t14.identifier("replace")), [t14.regExpLiteral("[A-Z]", "g"), t14.stringLiteral("-$&")]),
5487
- t14.stringLiteral(": ")
5488
- ), t14.identifier("v"))
6077
+ t14.binaryExpression(
6078
+ "+",
6079
+ t14.callExpression(t14.memberExpression(t14.identifier("k"), t14.identifier("replace")), [
6080
+ t14.regExpLiteral("[A-Z]", "g"),
6081
+ t14.stringLiteral("-$&")
6082
+ ]),
6083
+ t14.stringLiteral(": ")
6084
+ ),
6085
+ t14.identifier("v")
6086
+ )
5489
6087
  )
5490
6088
  ]
5491
6089
  ),
@@ -5561,7 +6159,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5561
6159
  if (!t14.isJSXExpressionContainer(attr.value) || t14.isJSXEmptyExpression(attr.value.expression)) continue;
5562
6160
  const exprClone = t14.cloneNode(attr.value.expression, true);
5563
6161
  const tempProg = t14.file(t14.program([t14.expressionStatement(exprClone)]));
5564
- traverse7(tempProg, {
6162
+ traverse8(tempProg, {
5565
6163
  Identifier(path) {
5566
6164
  if (path.node.name === arrayMap.itemVariable) path.node.name = "item";
5567
6165
  else if (arrayMap.indexVariable && path.node.name === arrayMap.indexVariable) path.node.name = "__idx";
@@ -5596,7 +6194,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
5596
6194
  }
5597
6195
  function templateRequiresRerender(file2) {
5598
6196
  let requiresRerender = false;
5599
- traverse7(file2, {
6197
+ traverse8(file2, {
5600
6198
  noScope: true,
5601
6199
  ConditionalExpression(path) {
5602
6200
  if (branchContainsJSX(path.node.consequent) || branchContainsJSX(path.node.alternate)) {
@@ -5615,8 +6213,8 @@ function templateRequiresRerender(file2) {
5615
6213
  }
5616
6214
  function branchContainsJSX(expr) {
5617
6215
  let containsJSX = false;
5618
- const program9 = t14.program([t14.expressionStatement(t14.cloneNode(expr, true))]);
5619
- traverse7(program9, {
6216
+ const program10 = t14.program([t14.expressionStatement(t14.cloneNode(expr, true))]);
6217
+ traverse8(program10, {
5620
6218
  noScope: true,
5621
6219
  JSXElement(path) {
5622
6220
  containsJSX = true;
@@ -5633,7 +6231,7 @@ function branchContainsJSX(expr) {
5633
6231
  // src/generate-array.ts
5634
6232
  import { createRequire as createRequire9 } from "module";
5635
6233
  var require10 = createRequire9(import.meta.url);
5636
- var traverse8 = require10("@babel/traverse").default;
6234
+ var traverse9 = require10("@babel/traverse").default;
5637
6235
  function getArrayPathParts(arrayMap) {
5638
6236
  return arrayMap.arrayPathParts || normalizePathParts(arrayMap.arrayPath || "");
5639
6237
  }
@@ -5702,22 +6300,35 @@ function buildPropPatcherFunction(binding, propName) {
5702
6300
  "=",
5703
6301
  t15.memberExpression(t15.memberExpression(target, t15.identifier("style")), t15.identifier("cssText")),
5704
6302
  t15.conditionalExpression(
5705
- t15.binaryExpression("===", t15.unaryExpression("typeof", t15.identifier("__attrValue")), t15.stringLiteral("object")),
6303
+ t15.binaryExpression(
6304
+ "===",
6305
+ t15.unaryExpression("typeof", t15.identifier("__attrValue")),
6306
+ t15.stringLiteral("object")
6307
+ ),
5706
6308
  t15.callExpression(
5707
6309
  t15.memberExpression(
5708
6310
  t15.callExpression(
5709
6311
  t15.memberExpression(
5710
- t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [t15.identifier("__attrValue")]),
6312
+ t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [
6313
+ t15.identifier("__attrValue")
6314
+ ]),
5711
6315
  t15.identifier("map")
5712
6316
  ),
5713
6317
  [
5714
6318
  t15.arrowFunctionExpression(
5715
6319
  [t15.arrayPattern([t15.identifier("k"), t15.identifier("v")])],
5716
- t15.binaryExpression("+", t15.binaryExpression(
6320
+ t15.binaryExpression(
5717
6321
  "+",
5718
- t15.callExpression(t15.memberExpression(t15.identifier("k"), t15.identifier("replace")), [t15.regExpLiteral("[A-Z]", "g"), t15.stringLiteral("-$&")]),
5719
- t15.stringLiteral(": ")
5720
- ), t15.identifier("v"))
6322
+ t15.binaryExpression(
6323
+ "+",
6324
+ t15.callExpression(t15.memberExpression(t15.identifier("k"), t15.identifier("replace")), [
6325
+ t15.regExpLiteral("[A-Z]", "g"),
6326
+ t15.stringLiteral("-$&")
6327
+ ]),
6328
+ t15.stringLiteral(": ")
6329
+ ),
6330
+ t15.identifier("v")
6331
+ )
5721
6332
  )
5722
6333
  ]
5723
6334
  ),
@@ -5783,8 +6394,8 @@ function buildPropPatcherFunction(binding, propName) {
5783
6394
  }
5784
6395
  function collectItemExpressionKeys(expr) {
5785
6396
  const keys = /* @__PURE__ */ new Set();
5786
- const program9 = t15.program([t15.expressionStatement(t15.cloneNode(expr, true))]);
5787
- traverse8(program9, {
6397
+ const program10 = t15.program([t15.expressionStatement(t15.cloneNode(expr, true))]);
6398
+ traverse9(program10, {
5788
6399
  noScope: true,
5789
6400
  MemberExpression(path) {
5790
6401
  if (!t15.isIdentifier(path.node.object, { name: "item" })) return;
@@ -5799,22 +6410,25 @@ function buildPatchEntryPropPatcher(entry) {
5799
6410
  const value = t15.identifier("value");
5800
6411
  const item = t15.identifier("item");
5801
6412
  const target = t15.identifier("__target");
5802
- const targetExpr = buildChildAccessExpr2(row, entry.childPath);
6413
+ const targetExpr = entry.childPath.length > 0 ? t15.memberExpression(row, t15.identifier(childPathRefName(entry.childPath))) : row;
5803
6414
  if (entry.type === "className") {
5804
- return t15.arrowFunctionExpression(
5805
- [row, value, item],
5806
- t15.blockStatement([
5807
- t15.variableDeclaration("const", [t15.variableDeclarator(target, targetExpr)]),
5808
- t15.ifStatement(t15.unaryExpression("!", target), t15.returnStatement()),
5809
- t15.expressionStatement(
5810
- t15.assignmentExpression(
5811
- "=",
5812
- t15.memberExpression(target, t15.identifier("className")),
5813
- t15.callExpression(t15.memberExpression(t15.cloneNode(entry.expression, true), t15.identifier("trim")), [])
5814
- )
6415
+ const isRoot2 = entry.childPath.length === 0;
6416
+ const stmts2 = [];
6417
+ if (!isRoot2) {
6418
+ stmts2.push(t15.variableDeclaration("const", [t15.variableDeclarator(target, targetExpr)]));
6419
+ stmts2.push(t15.ifStatement(t15.unaryExpression("!", target), t15.returnStatement()));
6420
+ }
6421
+ const ref2 = isRoot2 ? row : target;
6422
+ stmts2.push(
6423
+ t15.expressionStatement(
6424
+ t15.assignmentExpression(
6425
+ "=",
6426
+ t15.memberExpression(ref2, t15.identifier("className")),
6427
+ t15.cloneNode(entry.expression, true)
5815
6428
  )
5816
- ])
6429
+ )
5817
6430
  );
6431
+ return t15.arrowFunctionExpression([row, value, item], t15.blockStatement(stmts2));
5818
6432
  }
5819
6433
  if (entry.type === "attribute") {
5820
6434
  const attrName = entry.attributeName || "class";
@@ -5823,22 +6437,35 @@ function buildPatchEntryPropPatcher(entry) {
5823
6437
  "=",
5824
6438
  t15.memberExpression(t15.memberExpression(target, t15.identifier("style")), t15.identifier("cssText")),
5825
6439
  t15.conditionalExpression(
5826
- t15.binaryExpression("===", t15.unaryExpression("typeof", t15.identifier("__attrValue")), t15.stringLiteral("object")),
6440
+ t15.binaryExpression(
6441
+ "===",
6442
+ t15.unaryExpression("typeof", t15.identifier("__attrValue")),
6443
+ t15.stringLiteral("object")
6444
+ ),
5827
6445
  t15.callExpression(
5828
6446
  t15.memberExpression(
5829
6447
  t15.callExpression(
5830
6448
  t15.memberExpression(
5831
- t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [t15.identifier("__attrValue")]),
6449
+ t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [
6450
+ t15.identifier("__attrValue")
6451
+ ]),
5832
6452
  t15.identifier("map")
5833
6453
  ),
5834
6454
  [
5835
6455
  t15.arrowFunctionExpression(
5836
6456
  [t15.arrayPattern([t15.identifier("k"), t15.identifier("v")])],
5837
- t15.binaryExpression("+", t15.binaryExpression(
6457
+ t15.binaryExpression(
5838
6458
  "+",
5839
- t15.callExpression(t15.memberExpression(t15.identifier("k"), t15.identifier("replace")), [t15.regExpLiteral("[A-Z]", "g"), t15.stringLiteral("-$&")]),
5840
- t15.stringLiteral(": ")
5841
- ), t15.identifier("v"))
6459
+ t15.binaryExpression(
6460
+ "+",
6461
+ t15.callExpression(t15.memberExpression(t15.identifier("k"), t15.identifier("replace")), [
6462
+ t15.regExpLiteral("[A-Z]", "g"),
6463
+ t15.stringLiteral("-$&")
6464
+ ]),
6465
+ t15.stringLiteral(": ")
6466
+ ),
6467
+ t15.identifier("v")
6468
+ )
5842
6469
  )
5843
6470
  ]
5844
6471
  ),
@@ -5881,32 +6508,35 @@ function buildPatchEntryPropPatcher(entry) {
5881
6508
  ])
5882
6509
  );
5883
6510
  }
5884
- return t15.arrowFunctionExpression(
5885
- [row, value, item],
5886
- t15.blockStatement([
5887
- t15.variableDeclaration("const", [t15.variableDeclarator(target, targetExpr)]),
5888
- t15.ifStatement(t15.unaryExpression("!", target), t15.returnStatement()),
5889
- t15.expressionStatement(
6511
+ const isRoot = entry.childPath.length === 0;
6512
+ const stmts = [];
6513
+ if (!isRoot) {
6514
+ stmts.push(t15.variableDeclaration("const", [t15.variableDeclarator(target, targetExpr)]));
6515
+ stmts.push(t15.ifStatement(t15.unaryExpression("!", target), t15.returnStatement()));
6516
+ }
6517
+ const ref = isRoot ? row : target;
6518
+ stmts.push(
6519
+ t15.expressionStatement(
6520
+ t15.logicalExpression(
6521
+ "||",
5890
6522
  t15.logicalExpression(
5891
- "||",
5892
- t15.logicalExpression(
5893
- "&&",
5894
- t15.memberExpression(target, t15.identifier("firstChild")),
5895
- t15.assignmentExpression(
5896
- "=",
5897
- t15.memberExpression(t15.memberExpression(target, t15.identifier("firstChild")), t15.identifier("nodeValue")),
5898
- t15.cloneNode(entry.expression, true)
5899
- )
5900
- ),
6523
+ "&&",
6524
+ t15.memberExpression(ref, t15.identifier("firstChild")),
5901
6525
  t15.assignmentExpression(
5902
6526
  "=",
5903
- t15.memberExpression(target, t15.identifier("textContent")),
6527
+ t15.memberExpression(t15.memberExpression(ref, t15.identifier("firstChild")), t15.identifier("nodeValue")),
5904
6528
  t15.cloneNode(entry.expression, true)
5905
6529
  )
6530
+ ),
6531
+ t15.assignmentExpression(
6532
+ "=",
6533
+ t15.memberExpression(ref, t15.identifier("textContent")),
6534
+ t15.cloneNode(entry.expression, true)
5906
6535
  )
5907
6536
  )
5908
- ])
6537
+ )
5909
6538
  );
6539
+ return t15.arrowFunctionExpression([row, value, item], t15.blockStatement(stmts));
5910
6540
  }
5911
6541
  function buildPropPatchersObject(arrayMap) {
5912
6542
  const groups = /* @__PURE__ */ new Map();
@@ -5965,19 +6595,22 @@ function generateEnsureArrayConfigsMethod(arrayMaps) {
5965
6595
  ),
5966
6596
  t15.objectProperty(
5967
6597
  t15.identifier("render"),
5968
- t15.arrowFunctionExpression(
5969
- renderLambdaParams,
5970
- t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier(renderMethodName)), renderCallArgs)
6598
+ t15.callExpression(
6599
+ t15.memberExpression(
6600
+ t15.memberExpression(t15.thisExpression(), t15.identifier(renderMethodName)),
6601
+ t15.identifier("bind")
6602
+ ),
6603
+ [t15.thisExpression()]
5971
6604
  )
5972
6605
  ),
5973
6606
  t15.objectProperty(
5974
6607
  t15.identifier("create"),
5975
- t15.arrowFunctionExpression(
5976
- renderLambdaParams.map((p) => t15.cloneNode(p)),
5977
- t15.callExpression(
6608
+ t15.callExpression(
6609
+ t15.memberExpression(
5978
6610
  t15.memberExpression(t15.thisExpression(), t15.identifier(createMethodName)),
5979
- renderCallArgs.map((a) => t15.cloneNode(a))
5980
- )
6611
+ t15.identifier("bind")
6612
+ ),
6613
+ [t15.thisExpression()]
5981
6614
  )
5982
6615
  )
5983
6616
  ];
@@ -6065,10 +6698,7 @@ function generateArrayConditionalPatchObserver(arrayMap, bindings, methodName) {
6065
6698
  const containerName = `__${arrayPath.replace(/\./g, "_")}_container`;
6066
6699
  const containerRef = t15.memberExpression(t15.thisExpression(), t15.identifier(containerName));
6067
6700
  const proxiedArr = arrayMap.isImportedState ? buildMemberChain(
6068
- t15.memberExpression(
6069
- t15.memberExpression(t15.thisExpression(), t15.identifier("__stores")),
6070
- t15.identifier(arrayMap.storeVar || "store")
6071
- ),
6701
+ t15.memberExpression(t15.identifier(arrayMap.storeVar || "store"), t15.identifier("__store")),
6072
6702
  arrayPath
6073
6703
  ) : buildMemberChain(t15.thisExpression(), arrayPath);
6074
6704
  const rawArrExpr = t15.logicalExpression(
@@ -6126,10 +6756,7 @@ function generateArrayConditionalRerenderObserver(arrayMap, methodName) {
6126
6756
  const containerRef = t15.memberExpression(t15.thisExpression(), t15.identifier(containerName));
6127
6757
  const configRef = t15.memberExpression(t15.thisExpression(), t15.identifier(getArrayConfigPropName(arrayMap)));
6128
6758
  const proxiedArr = arrayMap.isImportedState ? buildMemberChain(
6129
- t15.memberExpression(
6130
- t15.memberExpression(t15.thisExpression(), t15.identifier("__stores")),
6131
- t15.identifier(arrayMap.storeVar || "store")
6132
- ),
6759
+ t15.memberExpression(t15.identifier(arrayMap.storeVar || "store"), t15.identifier("__store")),
6133
6760
  arrayPath
6134
6761
  ) : buildMemberChain(t15.thisExpression(), arrayPath);
6135
6762
  const rawArrExpr = t15.logicalExpression(
@@ -6212,15 +6839,8 @@ function generateArrayConditionalRerenderObserver(arrayMap, methodName) {
6212
6839
  t15.ifStatement(
6213
6840
  t15.unaryExpression("!", t15.identifier("__skipArrayConditionalRerender")),
6214
6841
  t15.blockStatement([
6215
- t15.ifStatement(
6216
- t15.binaryExpression(
6217
- "===",
6218
- t15.unaryExpression("typeof", t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs"))),
6219
- t15.stringLiteral("function")
6220
- ),
6221
- t15.expressionStatement(
6222
- t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
6223
- )
6842
+ t15.expressionStatement(
6843
+ t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
6224
6844
  ),
6225
6845
  t15.variableDeclaration("const", [
6226
6846
  t15.variableDeclarator(
@@ -6251,7 +6871,7 @@ function buildConditionalPatchStatement(binding, target, itemVariable) {
6251
6871
  return js5`${jsExpr3`${target}.textContent`} = ${expression};`;
6252
6872
  }
6253
6873
  if (binding.type === "className") {
6254
- return js5`${jsExpr3`${target}.className`} = (${expression}).trim();`;
6874
+ return js5`${jsExpr3`${target}.className`} = ${expression};`;
6255
6875
  }
6256
6876
  if (binding.attributeName === "style") {
6257
6877
  return t15.blockStatement(
@@ -6280,32 +6900,30 @@ function buildConditionalPatchStatement(binding, target, itemVariable) {
6280
6900
  }
6281
6901
  function renameItemVariable(expr, itemVariable) {
6282
6902
  const cloned = t15.cloneNode(expr, true);
6283
- const program9 = t15.program([t15.expressionStatement(cloned)]);
6284
- traverse8(program9, {
6903
+ const program10 = t15.program([t15.expressionStatement(cloned)]);
6904
+ traverse9(program10, {
6285
6905
  noScope: true,
6286
6906
  Identifier(path) {
6287
6907
  if (path.node.name === itemVariable) path.node.name = "item";
6288
6908
  }
6289
6909
  });
6290
- return program9.body[0].expression;
6910
+ return program10.body[0].expression;
6291
6911
  }
6292
6912
  function buildRelationalClassStatements(rowExpr, bindings, isMatch, phase) {
6293
6913
  return bindings.flatMap((binding, index) => {
6294
- const targetVar = `__target_${phase}_${index}`;
6295
6914
  const enabled = binding.classWhenMatch ? isMatch : !isMatch;
6296
- const targetExpr = binding.selector === ":scope" ? t15.cloneNode(rowExpr, true) : t15.cloneNode(rowExpr, true);
6297
6915
  if (binding.selector === ":scope") {
6916
+ const expr = t15.cloneNode(rowExpr, true);
6298
6917
  return jsBlockBody3`
6299
- var ${id8(targetVar)} = ${targetExpr};
6300
- if (${id8(targetVar)}) {
6301
- if (${id8(targetVar)}.className === '' || ${id8(targetVar)}.className === ${binding.classToggleName}) {
6302
- ${id8(targetVar)}.className = ${enabled ? binding.classToggleName : ""};
6303
- } else {
6304
- ${id8(targetVar)}.classList.toggle(${binding.classToggleName}, ${enabled});
6305
- }
6918
+ if (${expr}.className === '' || ${expr}.className === ${binding.classToggleName}) {
6919
+ ${expr}.className = ${enabled ? binding.classToggleName : ""};
6920
+ } else {
6921
+ ${expr}.classList.toggle(${binding.classToggleName}, ${enabled});
6306
6922
  }
6307
6923
  `;
6308
6924
  }
6925
+ const targetVar = `__target_${phase}_${index}`;
6926
+ const targetExpr = t15.cloneNode(rowExpr, true);
6309
6927
  return jsBlockBody3`
6310
6928
  var ${id8(targetVar)} = ${targetExpr};
6311
6929
  if (${id8(targetVar)}) {
@@ -6365,15 +6983,8 @@ function generateArrayHandlers(arrayMap, methodName) {
6365
6983
  t15.returnStatement()
6366
6984
  ])
6367
6985
  ),
6368
- t15.ifStatement(
6369
- t15.binaryExpression(
6370
- "===",
6371
- t15.unaryExpression("typeof", t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs"))),
6372
- t15.stringLiteral("function")
6373
- ),
6374
- t15.expressionStatement(
6375
- t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
6376
- )
6986
+ t15.expressionStatement(
6987
+ t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
6377
6988
  ),
6378
6989
  t15.expressionStatement(
6379
6990
  t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__applyListChanges")), [
@@ -6563,7 +7174,8 @@ function unwrapComparisonOperands(node) {
6563
7174
  }
6564
7175
  function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCounter, classBody2, templateSetupContext) {
6565
7176
  const renderEventHandlers = [];
6566
- if (!arrayMap.itemTemplate) return { method: null, handlers: renderEventHandlers, handlerPropsInMap: [] };
7177
+ if (!arrayMap.itemTemplate)
7178
+ return { method: null, handlers: renderEventHandlers, handlerPropsInMap: [], needsUnwrapHelper: false };
6567
7179
  const arrayPath = pathPartsToString(arrayMap.arrayPathParts || normalizePathParts(arrayMap.arrayPath || ""));
6568
7180
  const modified = t16.cloneNode(arrayMap.itemTemplate, true);
6569
7181
  const handlerPropsInMap = [];
@@ -6601,8 +7213,12 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
6601
7213
  wholeParam = templateMethod.params[0].name;
6602
7214
  }
6603
7215
  }
7216
+ const itemKey = arrayMap.itemVariable;
6604
7217
  wrapped.expressions = wrapped.expressions.map(
6605
- (expr) => replacePropRefsInExpression(unwrapComparisonOperands(expr), propNames, wholeParam)
7218
+ (expr) => optionalizeMemberChainsAfterComputedItemKey(
7219
+ replacePropRefsInExpression(unwrapComparisonOperands(expr), propNames, wholeParam),
7220
+ itemKey
7221
+ )
6606
7222
  );
6607
7223
  const handlerRegStmts = buildHandlerRegistrationStatements(
6608
7224
  handlerPropsInMap,
@@ -6616,8 +7232,14 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
6616
7232
  t16.expressionStatement(wrapped)
6617
7233
  ]) : wrapped;
6618
7234
  const setupStmts = collectTemplateSetupStatements(setupScope, templateSetupContext);
6619
- const rewrittenSetup = setupStmts.map((stmt) => replacePropRefsInStatements([t16.cloneNode(stmt, true)], propNames, wholeParam)).flat();
6620
- const rewrittenCallbackBody = callbackBodyStmts.map((stmt) => replacePropRefsInStatements([t16.cloneNode(stmt, true)], propNames, wholeParam)).flat();
7235
+ const rewrittenSetup = optionalizeComputedItemKeyInStatements(
7236
+ setupStmts.map((stmt) => replacePropRefsInStatements([t16.cloneNode(stmt, true)], propNames, wholeParam)).flat(),
7237
+ itemKey
7238
+ );
7239
+ const rewrittenCallbackBody = optionalizeComputedItemKeyInStatements(
7240
+ callbackBodyStmts.map((stmt) => replacePropRefsInStatements([t16.cloneNode(stmt, true)], propNames, wholeParam)).flat(),
7241
+ itemKey
7242
+ );
6621
7243
  const baseMethod = jsMethod6`${id9(methodName)}(${id9(arrayMap.itemVariable)}) {}`;
6622
7244
  if (arrayMap.indexVariable) {
6623
7245
  baseMethod.params.push(t16.identifier(arrayMap.indexVariable));
@@ -6638,14 +7260,7 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
6638
7260
  return false;
6639
7261
  }
6640
7262
  const needsUnwrapHelper = [...rewrittenCallbackBody, returnStmt].some((stmt) => containsVCall(stmt));
6641
- const method = appendToBody4(
6642
- baseMethod,
6643
- ...rewrittenSetup,
6644
- ...needsUnwrapHelper ? [buildValueUnwrapHelper()] : [],
6645
- ...rewrittenCallbackBody,
6646
- ...handlerRegStmts,
6647
- returnStmt
6648
- );
7263
+ const method = appendToBody4(baseMethod, ...rewrittenSetup, ...rewrittenCallbackBody, ...handlerRegStmts, returnStmt);
6649
7264
  if (handlerPropsInMap.length > 0 && classBody2) {
6650
7265
  const handleItemHandler = jsMethod6`__handleItemHandler(itemId, e) {
6651
7266
  const fn = this.__itemHandlers_?.[itemId];
@@ -6665,15 +7280,15 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
6665
7280
  };
6666
7281
  });
6667
7282
  if (eventHandlers) renderEventHandlers.forEach((h) => eventHandlers.push(h));
6668
- return { method, handlers: renderEventHandlers, handlerPropsInMap };
7283
+ return { method, handlers: renderEventHandlers, handlerPropsInMap, needsUnwrapHelper };
6669
7284
  }
6670
7285
 
6671
7286
  // src/generate-array-slot-sync.ts
6672
7287
  import * as t17 from "@babel/types";
6673
- import { id as id10, jsBlockBody as jsBlockBody4, jsExpr as jsExpr4, jsMethod as jsMethod7 } from "eszter";
7288
+ import { id as id10, jsMethod as jsMethod7 } from "eszter";
6674
7289
  import { createRequire as createRequire10 } from "module";
6675
7290
  var require11 = createRequire10(import.meta.url);
6676
- var traverse9 = require11("@babel/traverse").default;
7291
+ var traverse10 = require11("@babel/traverse").default;
6677
7292
  function isUnresolvedMapWithComponentChild(um, imports) {
6678
7293
  const template = um.itemTemplate;
6679
7294
  if (!template) return null;
@@ -6689,20 +7304,14 @@ function getArrayCapName2(arrayPropName) {
6689
7304
  function getComponentArrayItemsName(arrayPropName) {
6690
7305
  return `_${arrayPropName}Items`;
6691
7306
  }
6692
- function getComponentArrayBuildMethodName(arrayPropName) {
6693
- return `_build${getArrayCapName2(arrayPropName)}Items`;
6694
- }
6695
7307
  function getComponentArrayRefreshMethodName(arrayPropName) {
6696
7308
  return `__refresh${getArrayCapName2(arrayPropName)}Items`;
6697
7309
  }
6698
- function getComponentArrayMountMethodName(arrayPropName) {
6699
- return `__mount${getArrayCapName2(arrayPropName)}Items`;
6700
- }
6701
- function generateComponentArrayMethods(um, arrayPropName, imports, propNames, _classBody, storeArrayAccess, wholeParamName, templateSetupContext) {
7310
+ function generateComponentArrayResult(um, arrayPropName, imports, propNames, _classBody, storeArrayAccess, wholeParamName, templateSetupContext) {
6702
7311
  const comp = isUnresolvedMapWithComponentChild(um, imports);
6703
- if (!comp) return [];
7312
+ if (!comp) return null;
6704
7313
  const itemTemplate = um.itemTemplate;
6705
- if (!itemTemplate || !t17.isJSXElement(itemTemplate)) return [];
7314
+ if (!itemTemplate || !t17.isJSXElement(itemTemplate)) return null;
6706
7315
  const mapJsxCtx = {
6707
7316
  imports,
6708
7317
  componentInstances: /* @__PURE__ */ new Map(),
@@ -6733,7 +7342,7 @@ function generateComponentArrayMethods(um, arrayPropName, imports, propNames, _c
6733
7342
  let finalPropsExpr = propsExpr;
6734
7343
  if (needsRename || needsIndexRename) {
6735
7344
  const cloned = t17.cloneNode(propsExpr, true);
6736
- traverse9(cloned, {
7345
+ traverse10(cloned, {
6737
7346
  noScope: true,
6738
7347
  Identifier(path) {
6739
7348
  if (needsRename && path.node.name === itemVar) {
@@ -6761,17 +7370,6 @@ function generateComponentArrayMethods(um, arrayPropName, imports, propNames, _c
6761
7370
  finalPropsExpr = cloned;
6762
7371
  }
6763
7372
  const itemsName = getComponentArrayItemsName(arrayPropName);
6764
- const buildMethodName = getComponentArrayBuildMethodName(arrayPropName);
6765
- const refreshMethodName = getComponentArrayRefreshMethodName(arrayPropName);
6766
- const mountMethodName = `__mount${getArrayCapName2(arrayPropName)}Items`;
6767
- const containerName = `__${arrayPropName}ItemsContainer`;
6768
- const containerLookupExpr = um.containerBindingId ? t17.callExpression(t17.memberExpression(t17.identifier("document"), t17.identifier("getElementById")), [
6769
- t17.binaryExpression(
6770
- "+",
6771
- t17.memberExpression(t17.thisExpression(), t17.identifier("id")),
6772
- t17.stringLiteral(`-${um.containerBindingId}`)
6773
- )
6774
- ]) : jsExpr4`this.$(":scope")`;
6775
7373
  let arrAccessExpr;
6776
7374
  let arrSetupStatements = [];
6777
7375
  if (storeArrayAccess) {
@@ -6798,175 +7396,64 @@ function generateComponentArrayMethods(um, arrayPropName, imports, propNames, _c
6798
7396
  itemPropsCallArgs
6799
7397
  );
6800
7398
  const itemPropsSetup = collectTemplateSetupStatements(finalPropsExpr, templateSetupContext);
7399
+ const storeVarNames = /* @__PURE__ */ new Set();
7400
+ if (storeArrayAccess) storeVarNames.add(storeArrayAccess.storeVar);
7401
+ for (const stmt of [...itemPropsSetup, ...arrSetupStatements]) {
7402
+ if (!t17.isVariableDeclaration(stmt)) continue;
7403
+ for (const decl of stmt.declarations) {
7404
+ if (t17.isIdentifier(decl.init) && imports.has(decl.init.name)) {
7405
+ storeVarNames.add(decl.init.name);
7406
+ }
7407
+ }
7408
+ }
7409
+ const rewriteStoreDestructuring = (stmts) => {
7410
+ if (storeVarNames.size === 0) return;
7411
+ for (const stmt of stmts) {
7412
+ if (!t17.isVariableDeclaration(stmt)) continue;
7413
+ for (const decl of stmt.declarations) {
7414
+ if (t17.isIdentifier(decl.init) && storeVarNames.has(decl.init.name)) {
7415
+ decl.init = t17.memberExpression(t17.identifier(decl.init.name), t17.identifier("__raw"));
7416
+ }
7417
+ }
7418
+ }
7419
+ };
7420
+ rewriteStoreDestructuring(itemPropsSetup);
7421
+ rewriteStoreDestructuring(arrSetupStatements);
6801
7422
  const itemPropsMethod = jsMethod7`${id10(itemPropsMethodName)}(opt) {}`;
6802
7423
  if (indexVar) itemPropsMethod.params.push(t17.identifier("__k"));
6803
7424
  itemPropsMethod.body.body.push(...itemPropsSetup, t17.returnStatement(finalPropsExpr));
6804
7425
  const itemIdProp = um.itemIdProperty;
6805
7426
  const keyExpr = itemIdProp && itemIdProp !== ITEM_IS_KEY ? t17.callExpression(t17.identifier("String"), [t17.memberExpression(t17.identifier("opt"), t17.identifier(itemIdProp))]) : itemIdProp === ITEM_IS_KEY ? t17.callExpression(t17.identifier("String"), [t17.identifier("opt")]) : t17.binaryExpression("+", t17.stringLiteral("__idx_"), t17.identifier("__k"));
6806
- const buildMethod = jsMethod7`${id10(buildMethodName)}() {}`;
6807
- buildMethod.body.body.push(
6808
- ...arrSetupStatements,
6809
- ...itemIdProp ? jsBlockBody4`
6810
- const arr = ${arrAccessExpr} ?? [];
6811
- this.${id10(itemsName)} = arr.map((opt, __k) => {
6812
- const item = new ${id10(comp.componentTag)}(${t17.cloneNode(itemPropsCall, true)});
6813
- item.parentComponent = this;
6814
- item.__geaCompiledChild = true;
6815
- item.__geaItemKey = ${t17.cloneNode(keyExpr, true)};
6816
- return item;
6817
- });
6818
- ` : jsBlockBody4`
6819
- const arr = ${arrAccessExpr} ?? [];
6820
- this.${id10(itemsName)} = arr.map(opt => {
6821
- const item = new ${id10(comp.componentTag)}(${t17.cloneNode(itemPropsCall, true)});
6822
- item.parentComponent = this;
6823
- item.__geaCompiledChild = true;
6824
- return item;
6825
- });
6826
- `
6827
- );
6828
- const mountMethod = jsMethod7`${id10(mountMethodName)}() {}`;
6829
- mountMethod.body.body.push(
6830
- ...jsBlockBody4`
6831
- if (!this.${id10(containerName)} || !this.${id10(containerName)}.isConnected) {
6832
- this.${id10(containerName)} = ${containerLookupExpr};
6833
- }
6834
- if (!this.${id10(containerName)}) return;
6835
- for (let i = 0; i < (this.${id10(itemsName)}?.length ?? 0); i++) {
6836
- const item = this.${id10(itemsName)}[i];
6837
- if (!item) continue;
6838
- if (!this.__childComponents.includes(item)) {
6839
- this.__childComponents.push(item);
6840
- }
6841
- item.render(this.${id10(containerName)});
6842
- }
6843
- `
7427
+ const mapParams = [t17.identifier("opt")];
7428
+ if (indexVar || !itemIdProp) mapParams.push(t17.identifier("__k"));
7429
+ const childCall = t17.callExpression(t17.memberExpression(t17.thisExpression(), t17.identifier("__child")), [
7430
+ t17.identifier(comp.componentTag),
7431
+ t17.cloneNode(itemPropsCall, true),
7432
+ t17.cloneNode(keyExpr, true)
7433
+ ]);
7434
+ const mapCallback = t17.arrowFunctionExpression(mapParams, childCall);
7435
+ const nullishCoalesce = t17.logicalExpression("??", t17.cloneNode(arrAccessExpr, true), t17.arrayExpression([]));
7436
+ const parenthesized = t17.parenthesizedExpression ? t17.parenthesizedExpression(nullishCoalesce) : nullishCoalesce;
7437
+ const mapCallExpr = t17.callExpression(t17.memberExpression(parenthesized, t17.identifier("map")), [mapCallback]);
7438
+ const constructorInit = t17.expressionStatement(
7439
+ t17.assignmentExpression("=", t17.memberExpression(t17.thisExpression(), t17.identifier(itemsName)), mapCallExpr)
6844
7440
  );
6845
- const refreshMethod = jsMethod7`${id10(refreshMethodName)}() {}`;
6846
- if (itemIdProp) {
6847
- refreshMethod.body.body.push(
6848
- ...arrSetupStatements.map((stmt) => t17.cloneNode(stmt, true)),
6849
- ...jsBlockBody4`
6850
- const arr = ${t17.cloneNode(arrAccessExpr, true)} ?? [];
6851
- const __old = this.${id10(itemsName)} ?? [];
6852
- const __keyMap = new Map();
6853
- for (let __k = 0; __k < __old.length; __k++) {
6854
- if (__old[__k].__geaItemKey != null) {
6855
- __keyMap.set(__old[__k].__geaItemKey, __old[__k]);
6856
- }
6857
- }
6858
- const __new = [];
6859
- for (let __k = 0; __k < arr.length; __k++) {
6860
- const opt = arr[__k];
6861
- const __key = ${t17.cloneNode(keyExpr, true)};
6862
- const __existing = __keyMap.get(__key);
6863
- if (__existing) {
6864
- __existing.__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
6865
- __new.push(__existing);
6866
- __keyMap.delete(__key);
6867
- } else {
6868
- const __item = new ${id10(comp.componentTag)}(${t17.cloneNode(itemPropsCall, true)});
6869
- __item.parentComponent = this;
6870
- __item.__geaCompiledChild = true;
6871
- __item.__geaItemKey = __key;
6872
- __new.push(__item);
6873
- }
6874
- }
6875
- for (const [, __removed] of __keyMap) {
6876
- __removed.dispose?.();
6877
- }
6878
- if ((!this.${id10(containerName)} || !this.${id10(containerName)}.isConnected) && this.rendered_) {
6879
- this.${id10(containerName)} = ${t17.cloneNode(containerLookupExpr, true)};
6880
- }
6881
- const __container = this.${id10(containerName)};
6882
- if (__container && this.rendered_) {
6883
- for (let __k = 0; __k < __new.length; __k++) {
6884
- if (!__new[__k].rendered_) {
6885
- if (!this.__childComponents.includes(__new[__k])) {
6886
- this.__childComponents.push(__new[__k]);
6887
- }
6888
- __new[__k].render(__container);
6889
- }
6890
- }
6891
- let __cursor = __container.firstChild;
6892
- for (let __k = 0; __k < __new.length; __k++) {
6893
- let __el = __new[__k].element_;
6894
- if (!__el) continue;
6895
- while (__el.parentElement && __el.parentElement !== __container) __el = __el.parentElement;
6896
- if (__el !== __cursor) {
6897
- __container.insertBefore(__el, __cursor || null);
6898
- } else {
6899
- __cursor = __cursor.nextSibling;
6900
- }
6901
- }
6902
- }
6903
- this.${id10(itemsName)} = __new;
6904
- this.__childComponents = (this.__childComponents || []).filter(
6905
- child => !__old.includes(child) || __new.includes(child)
6906
- );
6907
- `
6908
- );
6909
- } else {
6910
- refreshMethod.body.body.push(
6911
- ...arrSetupStatements.map((stmt) => t17.cloneNode(stmt, true)),
6912
- ...jsBlockBody4`
6913
- const arr = ${t17.cloneNode(arrAccessExpr, true)} ?? [];
6914
- const __old = this.${id10(itemsName)} ?? [];
6915
- const __oldLen = __old.length;
6916
- const __newLen = arr.length;
6917
- if (__oldLen !== __newLen) {
6918
- if (__newLen > __oldLen) {
6919
- for (let __k = 0; __k < __oldLen; __k++) {
6920
- const opt = arr[__k];
6921
- __old[__k].__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
6922
- }
6923
- if ((!this.${id10(containerName)} || !this.${id10(containerName)}.isConnected) && this.rendered_) {
6924
- this.${id10(containerName)} = ${t17.cloneNode(containerLookupExpr, true)};
6925
- }
6926
- for (let __k = __oldLen; __k < __newLen; __k++) {
6927
- const opt = arr[__k];
6928
- const __item = new ${id10(comp.componentTag)}(${t17.cloneNode(itemPropsCall, true)});
6929
- __item.parentComponent = this;
6930
- __item.__geaCompiledChild = true;
6931
- this.${id10(itemsName)}.push(__item);
6932
- if (!this.__childComponents.includes(__item)) {
6933
- this.__childComponents.push(__item);
6934
- }
6935
- if (this.rendered_ && this.${id10(containerName)}) {
6936
- __item.render(this.${id10(containerName)});
6937
- }
6938
- }
6939
- return;
6940
- }
6941
- if (__newLen < __oldLen) {
6942
- for (let __k = __newLen; __k < __oldLen; __k++) {
6943
- __old[__k]?.dispose?.();
6944
- }
6945
- this.${id10(itemsName)}.length = __newLen;
6946
- this.__childComponents = (this.__childComponents || []).filter(
6947
- child => !__old.slice(__newLen).includes(child)
6948
- );
6949
- for (let __k = 0; __k < __newLen; __k++) {
6950
- const opt = arr[__k];
6951
- this.${id10(itemsName)}[__k].__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
6952
- }
6953
- return;
6954
- }
6955
- }
6956
- for (let i = 0; i < arr.length; i++) {
6957
- const opt = arr[i];
6958
- this.${id10(itemsName)}[i].__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
6959
- }
6960
- `
6961
- );
6962
- }
6963
- return [itemPropsMethod, buildMethod, mountMethod, refreshMethod];
7441
+ return {
7442
+ itemPropsMethod,
7443
+ constructorInit,
7444
+ componentTag: comp.componentTag,
7445
+ containerBindingId: um.containerBindingId,
7446
+ itemIdProperty: itemIdProp,
7447
+ arrAccessExpr,
7448
+ arrSetupStatements
7449
+ };
6964
7450
  }
6965
7451
 
6966
7452
  // src/apply-reactivity.ts
6967
7453
  import { createRequire as createRequire11 } from "module";
7454
+ var generate2 = "default" in babelGenerator ? babelGenerator.default : babelGenerator;
6968
7455
  var require12 = createRequire11(import.meta.url);
6969
- var traverse10 = require12("@babel/traverse").default;
7456
+ var traverse11 = require12("@babel/traverse").default;
6970
7457
  var BOOLEAN_HTML_ATTRS = /* @__PURE__ */ new Set([
6971
7458
  "disabled",
6972
7459
  "hidden",
@@ -6987,30 +7474,140 @@ var BOOLEAN_HTML_ATTRS = /* @__PURE__ */ new Set([
6987
7474
  ]);
6988
7475
  function rewriteTemplateBodyForImportedState(_templateMethod, _stateRefs, _storeImports) {
6989
7476
  }
6990
- function generateCreatedHooks(stores) {
6991
- const body = jsBlockBody5`
6992
- if (!this.__observer_removers__) { this.__observer_removers__ = []; }
6993
- if (!this.__stores) { this.__stores = {}; }
6994
- this.__observer_removers__.forEach(fn => fn());
6995
- this.__observer_removers__ = [];
6996
- if (typeof this.__ensureArrayConfigs === 'function') { this.__ensureArrayConfigs(); }
6997
- `;
7477
+ function generateCreatedHooks(stores, hasArrayConfigs, observeListConfigs = []) {
7478
+ const body = [];
7479
+ if (hasArrayConfigs) {
7480
+ body.push(js7`this.__ensureArrayConfigs();`);
7481
+ }
7482
+ const observeListPathKeys = /* @__PURE__ */ new Set();
7483
+ for (const config of observeListConfigs) {
7484
+ observeListPathKeys.add(`${config.storeVar}:${JSON.stringify(config.pathParts)}`);
7485
+ }
6998
7486
  for (const store of stores) {
6999
- const storeRef = t18.memberExpression(
7000
- t18.memberExpression(t18.thisExpression(), t18.identifier("__stores")),
7001
- t18.identifier(store.storeVar)
7002
- );
7003
- body.push(js7`${storeRef} = ${t18.cloneNode(store.captureExpression, true)};`);
7004
- for (const observeHandler of store.observeHandlers) {
7487
+ const byPath = /* @__PURE__ */ new Map();
7488
+ for (const handler of store.observeHandlers) {
7489
+ const pathKey = JSON.stringify(handler.pathParts);
7490
+ const listKey = `${store.storeVar}:${pathKey}`;
7491
+ if (observeListPathKeys.has(listKey)) continue;
7492
+ if (!byPath.has(pathKey)) byPath.set(pathKey, []);
7493
+ byPath.get(pathKey).push({ methodName: handler.methodName, isVia: handler.isVia, rereadExpr: handler.rereadExpr });
7494
+ }
7495
+ const storeVarExpr = t18.identifier(store.storeVar);
7496
+ for (const [pathKey, handlers] of byPath) {
7497
+ const pathParts = JSON.parse(pathKey);
7498
+ const pathArray = t18.arrayExpression(pathParts.map((part) => t18.stringLiteral(part)));
7499
+ if (handlers.length === 1 && !handlers[0].isVia) {
7500
+ body.push(
7501
+ t18.expressionStatement(
7502
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__observe")), [
7503
+ storeVarExpr,
7504
+ pathArray,
7505
+ t18.memberExpression(t18.thisExpression(), t18.identifier(handlers[0].methodName))
7506
+ ])
7507
+ )
7508
+ );
7509
+ } else {
7510
+ const vParam = t18.identifier("__v");
7511
+ const cParam = t18.identifier("__c");
7512
+ const callStmts = [];
7513
+ for (const h of handlers) {
7514
+ if (h.isVia && h.rereadExpr) {
7515
+ callStmts.push(
7516
+ t18.expressionStatement(
7517
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)), [
7518
+ t18.cloneNode(h.rereadExpr, true),
7519
+ t18.nullLiteral()
7520
+ ])
7521
+ )
7522
+ );
7523
+ } else {
7524
+ callStmts.push(
7525
+ t18.expressionStatement(
7526
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)), [vParam, cParam])
7527
+ )
7528
+ );
7529
+ }
7530
+ }
7531
+ body.push(
7532
+ t18.expressionStatement(
7533
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__observe")), [
7534
+ storeVarExpr,
7535
+ pathArray,
7536
+ t18.arrowFunctionExpression([vParam, cParam], t18.blockStatement(callStmts))
7537
+ ])
7538
+ )
7539
+ );
7540
+ }
7541
+ }
7542
+ for (const config of observeListConfigs.filter((c) => c.storeVar === store.storeVar)) {
7543
+ const pathArray = t18.arrayExpression(config.pathParts.map((part) => t18.stringLiteral(part)));
7544
+ const itemsName = getComponentArrayItemsName(config.arrayPropName);
7545
+ const itemPropsMethodName = `__itemProps_${config.arrayPropName}`;
7546
+ const configProps = [
7547
+ t18.objectProperty(t18.identifier("items"), t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName))),
7548
+ t18.objectProperty(t18.identifier("itemsKey"), t18.stringLiteral(itemsName)),
7549
+ t18.objectProperty(
7550
+ t18.identifier("container"),
7551
+ t18.arrowFunctionExpression(
7552
+ [],
7553
+ config.containerBindingId ? t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__el")), [
7554
+ t18.stringLiteral(config.containerBindingId)
7555
+ ]) : jsExpr4`this.$(":scope")`
7556
+ )
7557
+ ),
7558
+ t18.objectProperty(t18.identifier("Ctor"), t18.identifier(config.componentTag)),
7559
+ t18.objectProperty(
7560
+ t18.identifier("props"),
7561
+ t18.arrowFunctionExpression(
7562
+ [t18.identifier("opt"), t18.identifier("__k")],
7563
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(itemPropsMethodName)), [
7564
+ t18.identifier("opt"),
7565
+ t18.identifier("__k")
7566
+ ])
7567
+ )
7568
+ ),
7569
+ t18.objectProperty(
7570
+ t18.identifier("key"),
7571
+ config.itemIdProperty && config.itemIdProperty !== ITEM_IS_KEY ? t18.arrowFunctionExpression(
7572
+ [t18.identifier("opt")],
7573
+ t18.memberExpression(t18.identifier("opt"), t18.identifier(config.itemIdProperty))
7574
+ ) : config.itemIdProperty === ITEM_IS_KEY ? t18.arrowFunctionExpression([t18.identifier("opt")], t18.identifier("opt")) : t18.arrowFunctionExpression(
7575
+ [t18.identifier("opt"), t18.identifier("__k")],
7576
+ t18.binaryExpression("+", t18.stringLiteral("__idx_"), t18.identifier("__k"))
7577
+ )
7578
+ )
7579
+ ];
7580
+ const samePathHandlers = [];
7581
+ const pathKey = JSON.stringify(config.pathParts);
7582
+ for (const handler of store.observeHandlers) {
7583
+ if (JSON.stringify(handler.pathParts) === pathKey) {
7584
+ samePathHandlers.push(handler);
7585
+ }
7586
+ }
7587
+ if (samePathHandlers.length > 0) {
7588
+ const onchangeStmts = samePathHandlers.map(
7589
+ (h) => t18.expressionStatement(
7590
+ h.isVia && h.rereadExpr ? t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)), [
7591
+ t18.cloneNode(h.rereadExpr, true),
7592
+ t18.nullLiteral()
7593
+ ]) : t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)), [
7594
+ t18.memberExpression(t18.identifier(config.storeVar), t18.identifier(config.pathParts[0])),
7595
+ t18.nullLiteral()
7596
+ ])
7597
+ )
7598
+ );
7599
+ configProps.push(
7600
+ t18.objectProperty(t18.identifier("onchange"), t18.arrowFunctionExpression([], t18.blockStatement(onchangeStmts)))
7601
+ );
7602
+ }
7005
7603
  body.push(
7006
- js7`
7007
- this.__observer_removers__.push(
7008
- ${storeRef}.observe(
7009
- ${t18.arrayExpression(observeHandler.pathParts.map((part) => t18.stringLiteral(part)))},
7010
- (__v, __c) => { try { this.${id11(observeHandler.methodName)}(__v, __c) } catch(_e) {} }
7011
- )
7012
- );
7013
- `
7604
+ t18.expressionStatement(
7605
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__observeList")), [
7606
+ storeVarExpr,
7607
+ pathArray,
7608
+ t18.objectExpression(configProps)
7609
+ ])
7610
+ )
7014
7611
  );
7015
7612
  }
7016
7613
  }
@@ -7018,30 +7615,31 @@ function generateCreatedHooks(stores) {
7018
7615
  method.body.body.push(...body);
7019
7616
  return method;
7020
7617
  }
7021
- function generateLocalStateObserverSetup(observeHandlers) {
7618
+ function generateLocalStateObserverSetup(observeHandlers, hasArrayConfigs) {
7022
7619
  const localStore = t18.memberExpression(t18.thisExpression(), t18.identifier("__store"));
7023
- const body = [
7024
- js7`if (typeof this.__ensureArrayConfigs === 'function') { this.__ensureArrayConfigs(); }`,
7025
- js7`if (!${localStore}) { return; }`
7026
- ];
7027
- observeHandlers.forEach((observeHandler) => {
7620
+ const body = [];
7621
+ if (hasArrayConfigs) {
7622
+ body.push(js7`this.__ensureArrayConfigs();`);
7623
+ }
7624
+ body.push(js7`if (!${localStore}) { return; }`);
7625
+ for (const observeHandler of observeHandlers) {
7028
7626
  body.push(
7029
- js7`
7030
- this.__observer_removers__.push(
7031
- ${localStore}.observe(
7032
- ${t18.arrayExpression(observeHandler.pathParts.map((part) => t18.stringLiteral(part)))},
7033
- (__v, __c) => { try { this.${id11(observeHandler.methodName)}(__v, __c) } catch(_e) {} }
7034
- )
7035
- );
7036
- `
7627
+ t18.expressionStatement(
7628
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__observe")), [
7629
+ t18.thisExpression(),
7630
+ t18.arrayExpression(observeHandler.pathParts.map((part) => t18.stringLiteral(part))),
7631
+ t18.memberExpression(t18.thisExpression(), t18.identifier(observeHandler.methodName))
7632
+ ])
7633
+ )
7037
7634
  );
7038
- });
7635
+ }
7039
7636
  const method = jsMethod8`${id11("__setupLocalStateObservers")}() {}`;
7040
7637
  method.body.body.push(...body);
7041
7638
  return method;
7042
7639
  }
7043
7640
  function applyStaticReactivity(ast, originalAST, className, sourceFile, imports, stateRefs, storeImports, compiledChildren = [], eventIdCounter = { value: 0 }, preTransformAnalysis) {
7044
7641
  let applied = false;
7642
+ let needsModuleLevelUnwrapHelper = false;
7045
7643
  const astToTraverse = preTransformAnalysis?.has(className) ? ast : originalAST;
7046
7644
  const getAnalysis = (clsName, origPath) => {
7047
7645
  const cached = preTransformAnalysis?.get(clsName);
@@ -7049,7 +7647,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7049
7647
  const classBody2 = t18.isClassBody(origPath.parent) ? origPath.parent : void 0;
7050
7648
  return analyzeTemplate(origPath.node, stateRefs, classBody2);
7051
7649
  };
7052
- traverse10(astToTraverse, {
7650
+ traverse11(astToTraverse, {
7053
7651
  ClassMethod(origPath) {
7054
7652
  if (!t18.isIdentifier(origPath.node.key) || origPath.node.key.name !== "template") return;
7055
7653
  const analysis = getAnalysis(className, origPath);
@@ -7057,7 +7655,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7057
7655
  const hasCompiledChildStoreDeps = compiledChildren.some((child) => child.dependencies.some((dep) => dep.storeVar));
7058
7656
  if (analysis.bindings.length === 0 && analysis.propBindings.length === 0 && analysis.arrayMaps.length === 0 && analysis.stateProps.size === 0 && analysis.unresolvedMaps.length === 0 && !hasCompiledChildStoreDeps)
7059
7657
  return;
7060
- traverse10(ast, {
7658
+ traverse11(ast, {
7061
7659
  ClassDeclaration(classPath) {
7062
7660
  if (!t18.isIdentifier(classPath.node.id) || classPath.node.id.name !== className) return;
7063
7661
  const templateMethod = classPath.node.body.body.find(
@@ -7089,7 +7687,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7089
7687
  }
7090
7688
  if (renameMap.size === 0) return bodyStatements;
7091
7689
  const tempProgram = t18.program(bodyStatements);
7092
- traverse10(tempProgram, {
7690
+ traverse11(tempProgram, {
7093
7691
  noScope: true,
7094
7692
  Identifier(path) {
7095
7693
  const nextName = renameMap.get(path.node.name);
@@ -7200,23 +7798,39 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7200
7798
  consequent
7201
7799
  );
7202
7800
  } else if (pb.type === "class") {
7203
- updateStmt = t18.blockStatement([
7204
- t18.variableDeclaration("const", [
7205
- t18.variableDeclarator(
7206
- t18.identifier("__newClass"),
7207
- t18.conditionalExpression(
7208
- t18.binaryExpression("!=", valueExpr, t18.nullLiteral()),
7801
+ const isObjectClass = pb.expression && t18.isObjectExpression(pb.expression);
7802
+ const classValueExpr = isObjectClass ? t18.callExpression(
7803
+ t18.memberExpression(
7804
+ t18.callExpression(
7805
+ t18.memberExpression(
7209
7806
  t18.callExpression(
7210
7807
  t18.memberExpression(
7211
- t18.callExpression(t18.identifier("String"), [t18.cloneNode(valueExpr, true)]),
7212
- t18.identifier("trim")
7808
+ t18.callExpression(t18.memberExpression(t18.identifier("Object"), t18.identifier("entries")), [
7809
+ t18.cloneNode(valueExpr, true)
7810
+ ]),
7811
+ t18.identifier("filter")
7213
7812
  ),
7214
- []
7813
+ [
7814
+ t18.arrowFunctionExpression(
7815
+ [t18.arrayPattern([t18.identifier("__k"), t18.identifier("__v")])],
7816
+ t18.identifier("__v")
7817
+ )
7818
+ ]
7215
7819
  ),
7216
- t18.stringLiteral("")
7217
- )
7218
- )
7219
- ]),
7820
+ t18.identifier("map")
7821
+ ),
7822
+ [t18.arrowFunctionExpression([t18.arrayPattern([t18.identifier("__k")])], t18.identifier("__k"))]
7823
+ ),
7824
+ t18.identifier("join")
7825
+ ),
7826
+ [t18.stringLiteral(" ")]
7827
+ ) : t18.conditionalExpression(
7828
+ t18.binaryExpression("!=", valueExpr, t18.nullLiteral()),
7829
+ t18.callExpression(t18.identifier("String"), [t18.cloneNode(valueExpr, true)]),
7830
+ t18.stringLiteral("")
7831
+ );
7832
+ updateStmt = t18.blockStatement([
7833
+ t18.variableDeclaration("const", [t18.variableDeclarator(t18.identifier("__newClass"), classValueExpr)]),
7220
7834
  t18.ifStatement(
7221
7835
  t18.binaryExpression(
7222
7836
  "!==",
@@ -7333,22 +7947,35 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7333
7947
  } else {
7334
7948
  continue;
7335
7949
  }
7336
- const blockStatements = [
7337
- t18.variableDeclaration("const", [t18.variableDeclarator(t18.identifier("__el"), elExpr)])
7338
- ];
7339
- if (pb.expression && pb.setupStatements) {
7950
+ const useDerivedPropExpr = Boolean(pb.expression && pb.setupStatements);
7951
+ const elDecl = t18.variableDeclaration("const", [t18.variableDeclarator(t18.identifier("__el"), elExpr)]);
7952
+ const corePatch = [elDecl];
7953
+ let derivedRewrittenExpr;
7954
+ let derivedPrunedSetup = [];
7955
+ if (useDerivedPropExpr) {
7340
7956
  const rewrittenSetup = replacePropRefsInStatements(
7341
7957
  pb.setupStatements,
7342
7958
  templatePropNames,
7343
7959
  templateWholeParam
7344
7960
  );
7345
- const rewrittenExpr = replacePropRefsInExpression(pb.expression, templatePropNames, templateWholeParam);
7346
- blockStatements.push(...pruneDeadParamDestructuring(rewrittenSetup, [rewrittenExpr]));
7347
- blockStatements.push(
7961
+ let rewrittenExpr = replacePropRefsInExpression(pb.expression, templatePropNames, templateWholeParam);
7962
+ rewrittenExpr = replaceThisPropsRootWithValueParam(rewrittenExpr, pb.propName);
7963
+ derivedRewrittenExpr = rewrittenExpr;
7964
+ derivedPrunedSetup = pruneDeadParamDestructuring(rewrittenSetup, [rewrittenExpr]);
7965
+ corePatch.push(...derivedPrunedSetup);
7966
+ corePatch.push(
7348
7967
  t18.variableDeclaration("const", [t18.variableDeclarator(t18.identifier("__boundValue"), rewrittenExpr)])
7349
7968
  );
7350
7969
  }
7351
- blockStatements.push(t18.ifStatement(t18.identifier("__el"), updateStmt));
7970
+ corePatch.push(t18.ifStatement(t18.identifier("__el"), updateStmt));
7971
+ const nullishValue = t18.logicalExpression(
7972
+ "||",
7973
+ t18.binaryExpression("===", t18.identifier("value"), t18.nullLiteral()),
7974
+ t18.binaryExpression("===", t18.identifier("value"), t18.identifier("undefined"))
7975
+ );
7976
+ const guardsNullishInExpr = Boolean(derivedRewrittenExpr) && derivedExprGuardsValueWhenNullish(derivedRewrittenExpr);
7977
+ const needsValueNullishGuard = useDerivedPropExpr && !guardsNullishInExpr && expressionAccessesValueProperties(derivedRewrittenExpr, derivedPrunedSetup);
7978
+ const blockStatements = needsValueNullishGuard ? [t18.ifStatement(t18.unaryExpression("!", nullishValue), t18.blockStatement(corePatch))] : corePatch;
7352
7979
  patchStatementsByBinding.set(pb, blockStatements);
7353
7980
  applied = true;
7354
7981
  }
@@ -7394,7 +8021,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7394
8021
  }
7395
8022
  bindings.add(pb);
7396
8023
  };
7397
- traverse10(scanProg, {
8024
+ traverse11(scanProg, {
7398
8025
  noScope: true,
7399
8026
  Identifier(path) {
7400
8027
  if (path.parentPath && t18.isMemberExpression(path.parentPath.node) && path.parentPath.node.object === path.node)
@@ -7428,9 +8055,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7428
8055
  if (!hasStateOnly) continue;
7429
8056
  for (const pb of bindings) {
7430
8057
  if (pb.stateOnly) continue;
7431
- const dup = [...bindings].some(
7432
- (b) => b.stateOnly && b.selector === pb.selector && b.type === pb.type
7433
- );
8058
+ const dup = [...bindings].some((b) => b.stateOnly && b.selector === pb.selector && b.type === pb.type);
7434
8059
  if (dup) bindings.delete(pb);
7435
8060
  }
7436
8061
  }
@@ -7440,9 +8065,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7440
8065
  if (analysis.earlyReturnGuard) {
7441
8066
  const guardExpr = analysis.earlyReturnGuard;
7442
8067
  const localToStoreExpr = /* @__PURE__ */ new Map();
7443
- const setupStmts = templateMethod?.body.body.filter(
7444
- (s) => t18.isVariableDeclaration(s)
7445
- ) || [];
8068
+ const setupStmts = templateMethod?.body.body.filter((s) => t18.isVariableDeclaration(s)) || [];
7446
8069
  for (const decl of setupStmts) {
7447
8070
  for (const d of decl.declarations) {
7448
8071
  if (t18.isIdentifier(d.id) && t18.isMemberExpression(d.init)) {
@@ -7459,19 +8082,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7459
8082
  rerenderStoreKeys.push({ observeKey: key, pathParts: parts });
7460
8083
  }
7461
8084
  };
7462
- const guardScanProg = t18.program([
7463
- t18.expressionStatement(t18.cloneNode(guardExpr, true))
7464
- ]);
7465
- traverse10(guardScanProg, {
8085
+ const guardScanProg = t18.program([t18.expressionStatement(t18.cloneNode(guardExpr, true))]);
8086
+ traverse11(guardScanProg, {
7466
8087
  noScope: true,
7467
8088
  MemberExpression(path) {
7468
8089
  const resolved = resolvePath(path.node, stateRefs);
7469
8090
  if (!resolved?.parts?.length) return;
7470
8091
  if (resolved.isImportedState || resolved.storeVar) {
7471
- addRerenderDep(
7472
- resolved.parts,
7473
- resolved.isImportedState ? resolved.storeVar : void 0
7474
- );
8092
+ addRerenderDep(resolved.parts, resolved.isImportedState ? resolved.storeVar : void 0);
7475
8093
  }
7476
8094
  },
7477
8095
  Identifier(path) {
@@ -7501,7 +8119,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7501
8119
  const parsed = JSON.parse(entry.observeKey);
7502
8120
  const storeVarName = parsed.storeVar || void 0;
7503
8121
  const methodNameStr = getObserveMethodName(propPath, storeVarName);
7504
- const rerenderMethod = jsMethod8`${id11(methodNameStr)}(__v, __c) { this.__rerender(); }`;
8122
+ const prevProp = `__geaPrev_guard_${methodNameStr}`;
8123
+ const rerenderMethod = jsMethod8`${id11(methodNameStr)}(__v, __c) { if (!__v === !this.${id11(prevProp)}) return; this.${id11(prevProp)} = __v; this.__geaRequestRender(); }`;
7505
8124
  mergeObserveMethod(entry.observeKey, rerenderMethod);
7506
8125
  if (!stateProps.has(entry.observeKey)) {
7507
8126
  stateProps.set(entry.observeKey, entry.pathParts);
@@ -7514,6 +8133,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7514
8133
  const componentArrayDisposeTargets = [];
7515
8134
  const componentArrayMountMethods = [];
7516
8135
  const storeComponentArrayObservers = [];
8136
+ const observeListConfigs = [];
8137
+ const staticArrayRefreshOnMount = [];
7517
8138
  const mapItemAttrInfos = [];
7518
8139
  const tmplBody = templateMethod?.body.body ?? [];
7519
8140
  let tmplReturnIdx = -1;
@@ -7542,7 +8163,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7542
8163
  }
7543
8164
  }
7544
8165
  const propNames = getTemplatePropNames(classPath.node.body);
7545
- const methods = generateComponentArrayMethods(
8166
+ const arrayResult = generateComponentArrayResult(
7546
8167
  um,
7547
8168
  arrayPropName,
7548
8169
  imports,
@@ -7552,9 +8173,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7552
8173
  getTemplateParamIdentifier(classPath.node.body),
7553
8174
  tmplSetupCtx
7554
8175
  );
7555
- if (methods.length > 0 && templateMethod) {
7556
- methods.forEach((method2) => classPath.node.body.body.push(method2));
7557
- const importSource = imports.get(isComponentSlot.componentTag);
8176
+ if (arrayResult && templateMethod) {
8177
+ classPath.node.body.body.push(arrayResult.itemPropsMethod);
8178
+ const importSource = imports.get(arrayResult.componentTag);
7558
8179
  if (importSource) {
7559
8180
  const delegatedEvents = getHoistableRootEventsForImport(sourceFile, importSource).map((meta) => ({
7560
8181
  eventType: meta.eventType,
@@ -7567,15 +8188,93 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7567
8188
  appendCompiledEventMethods(classPath.node.body, delegatedEvents);
7568
8189
  }
7569
8190
  }
7570
- ensureConstructorCalls(classPath.node.body, getComponentArrayBuildMethodName(arrayPropName));
8191
+ inlineIntoConstructor(classPath.node.body, [
8192
+ ...arrayResult.arrSetupStatements.map((s) => t18.cloneNode(s, true)),
8193
+ arrayResult.constructorInit
8194
+ ]);
7571
8195
  if (storeArrayAccess) {
7572
- storeComponentArrayObservers.push({
8196
+ observeListConfigs.push({
7573
8197
  storeVar: storeArrayAccess.storeVar,
7574
- refreshMethodName: getComponentArrayRefreshMethodName(arrayPropName),
7575
- pathParts: [storeArrayAccess.propName]
8198
+ pathParts: [storeArrayAccess.propName],
8199
+ arrayPropName,
8200
+ componentTag: arrayResult.componentTag,
8201
+ containerBindingId: arrayResult.containerBindingId,
8202
+ itemIdProperty: arrayResult.itemIdProperty
7576
8203
  });
7577
8204
  } else {
7578
8205
  const computedDeps = (um.dependencies || collectUnresolvedDependencies([um], stateRefs, classPath.node.body)).filter((dep) => dep.storeVar || dep.pathParts[0] !== "props");
8206
+ const refreshMethodName = getComponentArrayRefreshMethodName(arrayPropName);
8207
+ const itemsName = getComponentArrayItemsName(arrayPropName);
8208
+ const itemPropsMethodNameRef = `__itemProps_${arrayPropName}`;
8209
+ const containerSuffix = arrayResult.containerBindingId;
8210
+ const containerExpr = containerSuffix ? t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__el")), [
8211
+ t18.stringLiteral(containerSuffix)
8212
+ ]) : jsExpr4`this.$(":scope")`;
8213
+ const itemIdProp = arrayResult.itemIdProperty;
8214
+ const keyFn = itemIdProp && itemIdProp !== ITEM_IS_KEY ? t18.arrowFunctionExpression(
8215
+ [t18.identifier("opt")],
8216
+ t18.memberExpression(t18.identifier("opt"), t18.identifier(itemIdProp))
8217
+ ) : itemIdProp === ITEM_IS_KEY ? t18.arrowFunctionExpression([t18.identifier("opt")], t18.identifier("opt")) : t18.arrowFunctionExpression(
8218
+ [t18.identifier("opt"), t18.identifier("__k")],
8219
+ t18.binaryExpression("+", t18.stringLiteral("__idx_"), t18.identifier("__k"))
8220
+ );
8221
+ const refreshMethod = t18.classMethod(
8222
+ "method",
8223
+ t18.identifier(refreshMethodName),
8224
+ [],
8225
+ t18.blockStatement([
8226
+ ...arrayResult.arrSetupStatements.map((s) => t18.cloneNode(s, true)),
8227
+ t18.variableDeclaration("const", [
8228
+ t18.variableDeclarator(
8229
+ t18.identifier("__arr"),
8230
+ t18.logicalExpression(
8231
+ "??",
8232
+ t18.cloneNode(arrayResult.arrAccessExpr, true),
8233
+ t18.arrayExpression([])
8234
+ )
8235
+ )
8236
+ ]),
8237
+ t18.variableDeclaration("const", [
8238
+ t18.variableDeclarator(
8239
+ t18.identifier("__new"),
8240
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__reconcileList")), [
8241
+ t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName)),
8242
+ t18.identifier("__arr"),
8243
+ t18.cloneNode(containerExpr, true),
8244
+ t18.identifier(arrayResult.componentTag),
8245
+ t18.arrowFunctionExpression(
8246
+ [t18.identifier("opt")],
8247
+ t18.callExpression(
8248
+ t18.memberExpression(t18.thisExpression(), t18.identifier(itemPropsMethodNameRef)),
8249
+ [t18.identifier("opt")]
8250
+ )
8251
+ ),
8252
+ t18.cloneNode(keyFn, true)
8253
+ ])
8254
+ )
8255
+ ]),
8256
+ t18.expressionStatement(
8257
+ t18.assignmentExpression(
8258
+ "=",
8259
+ t18.memberExpression(
8260
+ t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName)),
8261
+ t18.identifier("length")
8262
+ ),
8263
+ t18.numericLiteral(0)
8264
+ )
8265
+ ),
8266
+ t18.expressionStatement(
8267
+ t18.callExpression(
8268
+ t18.memberExpression(
8269
+ t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName)),
8270
+ t18.identifier("push")
8271
+ ),
8272
+ [t18.spreadElement(t18.identifier("__new"))]
8273
+ )
8274
+ )
8275
+ ])
8276
+ );
8277
+ classPath.node.body.body.push(refreshMethod);
7579
8278
  if (computedDeps.length > 0) {
7580
8279
  computedDeps.forEach((dep) => {
7581
8280
  mergeObserveMethod(
@@ -7587,10 +8286,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7587
8286
  t18.blockStatement([
7588
8287
  t18.expressionStatement(
7589
8288
  t18.callExpression(
7590
- t18.memberExpression(
7591
- t18.thisExpression(),
7592
- t18.identifier(getComponentArrayRefreshMethodName(arrayPropName))
7593
- ),
8289
+ t18.memberExpression(t18.thisExpression(), t18.identifier(refreshMethodName)),
7594
8290
  []
7595
8291
  )
7596
8292
  )
@@ -7600,13 +8296,13 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7600
8296
  if (dep.storeVar) {
7601
8297
  storeComponentArrayObservers.push({
7602
8298
  storeVar: dep.storeVar,
7603
- refreshMethodName: getComponentArrayRefreshMethodName(arrayPropName),
8299
+ refreshMethodName,
7604
8300
  pathParts: dep.pathParts
7605
8301
  });
7606
8302
  }
7607
8303
  });
7608
8304
  }
7609
- const itemPropsMethod = methods[0];
8305
+ const itemPropsMethod = arrayResult.itemPropsMethod;
7610
8306
  if (itemPropsMethod && t18.isBlockStatement(itemPropsMethod.body)) {
7611
8307
  const returnStmt = itemPropsMethod.body.body.find((s) => t18.isReturnStatement(s));
7612
8308
  if (returnStmt?.argument && t18.isObjectExpression(returnStmt.argument)) {
@@ -7625,28 +8321,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7625
8321
  const key = `${dep.storeVar}:${pathPartsToString(dep.pathParts)}`;
7626
8322
  if (computedDepKeys.has(key)) continue;
7627
8323
  computedDepKeys.add(key);
7628
- mergeObserveMethod(
7629
- dep.observeKey,
7630
- t18.classMethod(
7631
- "method",
7632
- t18.identifier(getObserveMethodName(dep.pathParts, dep.storeVar)),
7633
- [t18.identifier("value"), t18.identifier("change")],
7634
- t18.blockStatement([
7635
- t18.expressionStatement(
7636
- t18.callExpression(
7637
- t18.memberExpression(
7638
- t18.thisExpression(),
7639
- t18.identifier(getComponentArrayRefreshMethodName(arrayPropName))
7640
- ),
7641
- []
7642
- )
7643
- )
7644
- ])
7645
- )
7646
- );
7647
8324
  storeComponentArrayObservers.push({
7648
8325
  storeVar: dep.storeVar,
7649
- refreshMethodName: getComponentArrayRefreshMethodName(arrayPropName),
8326
+ refreshMethodName,
7650
8327
  pathParts: dep.pathParts
7651
8328
  });
7652
8329
  }
@@ -7655,17 +8332,19 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7655
8332
  const itemTemplateProps = collectPropNamesFromItemTemplate(um.itemTemplate, propNames);
7656
8333
  const allStoreManaged = computedDeps.length > 0 && computedDeps.every((dep) => dep.storeVar);
7657
8334
  componentArrayRefreshDeps.push({
7658
- methodName: getComponentArrayRefreshMethodName(arrayPropName),
8335
+ methodName: refreshMethodName,
7659
8336
  propNames: allStoreManaged ? [...itemTemplateProps] : [arrayPropName, ...itemTemplateProps]
7660
8337
  });
7661
8338
  }
7662
8339
  componentArrayDisposeTargets.push(getComponentArrayItemsName(arrayPropName));
7663
- componentArrayMountMethods.push(getComponentArrayMountMethodName(arrayPropName));
7664
- replaceMapWithComponentArrayItems(
8340
+ const wasReplacedInTemplate = replaceMapWithComponentArrayItems(
7665
8341
  templateMethod,
7666
8342
  um.computationExpr,
7667
8343
  getComponentArrayItemsName(arrayPropName)
7668
8344
  );
8345
+ if (!wasReplacedInTemplate && !storeArrayAccess) {
8346
+ staticArrayRefreshOnMount.push(getComponentArrayRefreshMethodName(arrayPropName));
8347
+ }
7669
8348
  applied = true;
7670
8349
  }
7671
8350
  return;
@@ -7684,7 +8363,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7684
8363
  };
7685
8364
  unresolvedBindings.push({ info: um, binding: syntheticBinding });
7686
8365
  const prevEventLen = unresolvedEventHandlers.length;
7687
- const { method, handlerPropsInMap } = generateRenderItemMethod(
8366
+ const { method, handlerPropsInMap, needsUnwrapHelper } = generateRenderItemMethod(
7688
8367
  syntheticBinding,
7689
8368
  imports,
7690
8369
  unresolvedEventHandlers,
@@ -7692,6 +8371,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7692
8371
  classPath.node.body,
7693
8372
  tmplSetupCtx
7694
8373
  );
8374
+ if (needsUnwrapHelper) needsModuleLevelUnwrapHelper = true;
7695
8375
  const newHandlers = unresolvedEventHandlers.slice(prevEventLen);
7696
8376
  const tokenMatch = newHandlers[0]?.selector?.match(/data-gea-event="([^"]+)"/);
7697
8377
  mapItemAttrInfos.push({
@@ -7761,10 +8441,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7761
8441
  [t18.identifier("value"), t18.identifier("change")],
7762
8442
  t18.blockStatement([
7763
8443
  t18.expressionStatement(
7764
- t18.callExpression(
7765
- t18.memberExpression(t18.thisExpression(), t18.identifier("__geaSyncMap")),
7766
- [t18.numericLiteral(mapIdx)]
7767
- )
8444
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__geaSyncMap")), [
8445
+ t18.numericLiteral(mapIdx)
8446
+ ])
7768
8447
  )
7769
8448
  ])
7770
8449
  )
@@ -7782,7 +8461,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7782
8461
  }
7783
8462
  if (scanNodes.length > 0) {
7784
8463
  const prog = t18.program(scanNodes);
7785
- traverse10(prog, {
8464
+ traverse11(prog, {
7786
8465
  noScope: true,
7787
8466
  Identifier(path) {
7788
8467
  if (templatePropNames.has(path.node.name)) usedPropNames.add(path.node.name);
@@ -7865,7 +8544,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7865
8544
  });
7866
8545
  const resolvedArrayMapDelegateKeys = /* @__PURE__ */ new Set();
7867
8546
  analysis.arrayMaps.forEach((arrayMap) => {
7868
- if (arrayMap.storeVar && arrayMap.arrayPathParts.length === 1) {
8547
+ if (arrayMap.storeVar) {
7869
8548
  const storeRef = stateRefs.get(arrayMap.storeVar);
7870
8549
  const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
7871
8550
  if (getterDepPaths && getterDepPaths.length > 0) {
@@ -7890,8 +8569,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7890
8569
  if (!t18.isClassMethod(member) || member.kind !== "get" || !t18.isIdentifier(member.key)) continue;
7891
8570
  const deps = [];
7892
8571
  const localRefs = /* @__PURE__ */ new Set();
7893
- const program9 = t18.program(member.body.body.map((s) => t18.cloneNode(s, true)));
7894
- traverse10(program9, {
8572
+ const program10 = t18.program(member.body.body.map((s) => t18.cloneNode(s, true)));
8573
+ traverse11(program10, {
7895
8574
  noScope: true,
7896
8575
  MemberExpression(mePath) {
7897
8576
  if (t18.isThisExpression(mePath.node.object) && t18.isIdentifier(mePath.node.property)) {
@@ -7939,7 +8618,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
7939
8618
  if (!t18.isIfStatement(stmt) || !(t18.isReturnStatement(stmt.consequent) || t18.isBlockStatement(stmt.consequent) && stmt.consequent.body.some((b) => t18.isReturnStatement(b))))
7940
8619
  continue;
7941
8620
  const guardProg = t18.program([t18.expressionStatement(t18.cloneNode(stmt.test, true))]);
7942
- traverse10(guardProg, {
8621
+ traverse11(guardProg, {
7943
8622
  noScope: true,
7944
8623
  Identifier(idPath) {
7945
8624
  if (t18.isMemberExpression(idPath.parent) && idPath.parent.property === idPath.node && !idPath.parent.computed)
@@ -8053,12 +8732,29 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8053
8732
  if (unresolvedMapKeys.has(observeKey)) continue;
8054
8733
  const handledByComponentArray = storeComponentArrayObservers.some(
8055
8734
  (obs) => obs.storeVar === storeVar && pathPartsToString(obs.pathParts) === pathPartsToString(propPath)
8735
+ ) || observeListConfigs.some(
8736
+ (olc) => olc.storeVar === storeVar && pathPartsToString(olc.pathParts) === pathPartsToString(propPath)
8056
8737
  );
8057
8738
  if (handledByComponentArray) continue;
8058
8739
  if (!childObserveGroups.has(observeKey)) {
8059
8740
  if (conditionalSlotIndices.length > 0) continue;
8060
8741
  if (analysis.conditionalSlotScopedStoreKeys?.has(observeKey)) continue;
8061
- mergeObserveMethod(observeKey, generateRerenderObserver(propPath, storeVar, guardStateKeys.has(observeKey)));
8742
+ if (storeVar && propPath.length >= 1) {
8743
+ const storeRef = stateRefs.get(storeVar);
8744
+ const getterDepPaths = storeRef?.getterDeps?.get(propPath[0]);
8745
+ if (getterDepPaths && getterDepPaths.length > 0) {
8746
+ const allDepsCovered = getterDepPaths.every(
8747
+ (depPath) => childObserveGroups.has(buildObserveKey(depPath, storeVar))
8748
+ );
8749
+ if (allDepsCovered) continue;
8750
+ }
8751
+ }
8752
+ mergeObserveMethod(
8753
+ observeKey,
8754
+ generateRerenderObserver(propPath, storeVar, guardStateKeys.has(observeKey))
8755
+ );
8756
+ } else if (guardStateKeys.has(observeKey)) {
8757
+ mergeObserveMethod(observeKey, generateRerenderObserver(propPath, storeVar, true));
8062
8758
  }
8063
8759
  }
8064
8760
  const childrenWithResolvedMap = /* @__PURE__ */ new Set();
@@ -8077,7 +8773,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8077
8773
  }
8078
8774
  };
8079
8775
  const wrapper = t18.expressionStatement(t18.cloneNode(childrenProp.value, true));
8080
- traverse10(t18.program([wrapper]), { noScope: true, ...check });
8776
+ traverse11(t18.program([wrapper]), { noScope: true, ...check });
8081
8777
  if (hasMap) childrenWithResolvedMap.add(child.instanceVar);
8082
8778
  });
8083
8779
  if (childrenWithResolvedMap.size > 0 && analysis.arrayMaps.length > 0) {
@@ -8116,9 +8812,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8116
8812
  for (const member of classPath.node.body.body) {
8117
8813
  if (!t18.isClassMethod(member) || !t18.isIdentifier(member.key)) continue;
8118
8814
  const methodName = member.key.name;
8119
- const isRelevant = childrenWithResolvedMap.size > 0 && (methodName.startsWith("__buildProps_") || methodName.startsWith("__refreshChildProps_"));
8815
+ const isRelevant = childrenWithResolvedMap.size > 0 && methodName.startsWith("__buildProps_");
8120
8816
  if (!isRelevant) continue;
8121
- traverse10(t18.program([t18.expressionStatement(t18.functionExpression(null, [], member.body))]), {
8817
+ traverse11(t18.program([t18.expressionStatement(t18.functionExpression(null, [], member.body))]), {
8122
8818
  noScope: true,
8123
8819
  TemplateLiteral(tlPath) {
8124
8820
  const tl = tlPath.node;
@@ -8161,19 +8857,33 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8161
8857
  return false;
8162
8858
  }
8163
8859
  return true;
8164
- }).map(
8165
- (child) => t18.expressionStatement(
8860
+ }).map((child) => {
8861
+ const updateExpr = t18.expressionStatement(
8166
8862
  t18.callExpression(
8167
8863
  t18.memberExpression(
8168
- t18.thisExpression(),
8169
- t18.identifier(`__refreshChildProps_${child.instanceVar.replace(/^_/, "")}`)
8864
+ t18.memberExpression(t18.thisExpression(), t18.identifier(child.instanceVar)),
8865
+ t18.identifier("__geaUpdateProps")
8170
8866
  ),
8171
- []
8867
+ [
8868
+ t18.callExpression(
8869
+ t18.memberExpression(
8870
+ t18.thisExpression(),
8871
+ t18.identifier(`__buildProps_${child.instanceVar.replace(/^_/, "")}`)
8872
+ ),
8873
+ []
8874
+ )
8875
+ ]
8172
8876
  )
8173
- )
8174
- );
8877
+ );
8878
+ if (!child.lazy) return updateExpr;
8879
+ const backingField = `__lazy${child.instanceVar}`;
8880
+ return t18.ifStatement(
8881
+ t18.memberExpression(t18.thisExpression(), t18.identifier(backingField)),
8882
+ t18.blockStatement([updateExpr])
8883
+ );
8884
+ });
8175
8885
  if (existing && t18.isBlockStatement(existing.body)) {
8176
- existing.body.body.push(...calls);
8886
+ existing.body.body.unshift(...calls);
8177
8887
  } else {
8178
8888
  const method = t18.classMethod(
8179
8889
  "method",
@@ -8266,10 +8976,15 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8266
8976
  addJoinToUnresolvedMapCalls(templateMethod, analysis.unresolvedMaps);
8267
8977
  }
8268
8978
  const componentArrayMaps = [];
8979
+ const componentArrayItemPropsMethods = /* @__PURE__ */ new Map();
8269
8980
  const htmlArrayMaps = [];
8270
8981
  for (const arrayMap of analysis.arrayMaps) {
8271
8982
  const compChild = isUnresolvedMapWithComponentChild(
8272
- { itemTemplate: arrayMap.itemTemplate, itemVariable: arrayMap.itemVariable, containerSelector: arrayMap.containerSelector },
8983
+ {
8984
+ itemTemplate: arrayMap.itemTemplate,
8985
+ itemVariable: arrayMap.itemVariable,
8986
+ containerSelector: arrayMap.containerSelector
8987
+ },
8273
8988
  imports
8274
8989
  );
8275
8990
  if (compChild) {
@@ -8308,7 +9023,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8308
9023
  computationExpr: computationExprSafe ?? computationExpr
8309
9024
  };
8310
9025
  const propNames = getTemplatePropNames(classPath.node.body);
8311
- const methods = generateComponentArrayMethods(
9026
+ const arrayResult = generateComponentArrayResult(
8312
9027
  um,
8313
9028
  arrayPropName,
8314
9029
  imports,
@@ -8318,11 +9033,10 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8318
9033
  getTemplateParamIdentifier(classPath.node.body),
8319
9034
  tmplSetupCtx
8320
9035
  );
8321
- if (methods.length > 0 && templateMethod) {
8322
- methods.forEach((method) => classPath.node.body.body.push(method));
8323
- const importSource = imports.get(
8324
- isUnresolvedMapWithComponentChild(um, imports).componentTag
8325
- );
9036
+ if (arrayResult && templateMethod) {
9037
+ classPath.node.body.body.push(arrayResult.itemPropsMethod);
9038
+ componentArrayItemPropsMethods.set(arrayMap, arrayResult.itemPropsMethod);
9039
+ const importSource = imports.get(arrayResult.componentTag);
8326
9040
  if (importSource) {
8327
9041
  const delegatedEvents = getHoistableRootEventsForImport(sourceFile, importSource).map((meta) => ({
8328
9042
  eventType: meta.eventType,
@@ -8335,51 +9049,125 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8335
9049
  appendCompiledEventMethods(classPath.node.body, delegatedEvents);
8336
9050
  }
8337
9051
  }
8338
- ensureConstructorCalls(classPath.node.body, getComponentArrayBuildMethodName(arrayPropName));
8339
- if (storeArrayAccess) {
8340
- storeComponentArrayObservers.push({
8341
- storeVar: storeArrayAccess.storeVar,
8342
- refreshMethodName: getComponentArrayRefreshMethodName(arrayPropName),
8343
- pathParts: [storeArrayAccess.propName]
8344
- });
8345
- } else if (arrayMap.storeVar) {
8346
- const refreshMethodName = getComponentArrayRefreshMethodName(arrayPropName);
8347
- mergeObserveMethod(
8348
- buildObserveKey(arrayMap.arrayPathParts, arrayMap.storeVar),
8349
- t18.classMethod(
8350
- "method",
8351
- t18.identifier(getObserveMethodName(arrayMap.arrayPathParts, arrayMap.storeVar)),
8352
- [t18.identifier("value"), t18.identifier("change")],
8353
- t18.blockStatement([
8354
- t18.expressionStatement(
8355
- t18.callExpression(
8356
- t18.memberExpression(t18.thisExpression(), t18.identifier(refreshMethodName)),
8357
- []
8358
- )
8359
- )
8360
- ])
8361
- )
8362
- );
8363
- storeComponentArrayObservers.push({
9052
+ inlineIntoConstructor(classPath.node.body, [
9053
+ ...arrayResult.arrSetupStatements.map((s) => t18.cloneNode(s, true)),
9054
+ arrayResult.constructorInit
9055
+ ]);
9056
+ if (arrayMap.storeVar) {
9057
+ observeListConfigs.push({
8364
9058
  storeVar: arrayMap.storeVar,
8365
- refreshMethodName,
8366
- pathParts: arrayMap.arrayPathParts
9059
+ pathParts: arrayMap.arrayPathParts,
9060
+ arrayPropName,
9061
+ componentTag: arrayResult.componentTag,
9062
+ containerBindingId: arrayResult.containerBindingId,
9063
+ itemIdProperty: arrayResult.itemIdProperty
8367
9064
  });
8368
9065
  }
8369
9066
  componentArrayDisposeTargets.push(getComponentArrayItemsName(arrayPropName));
8370
- componentArrayMountMethods.push(getComponentArrayMountMethodName(arrayPropName));
8371
9067
  const mapReplaceExpr = storeArrayAccess ? t18.memberExpression(t18.identifier(storeArrayAccess.storeVar), t18.identifier(storeArrayAccess.propName)) : computationExpr;
8372
- replaceMapWithComponentArrayItems(
9068
+ const wasReplaced = replaceMapWithComponentArrayItems(
8373
9069
  templateMethod,
8374
9070
  mapReplaceExpr,
8375
9071
  getComponentArrayItemsName(arrayPropName)
8376
9072
  );
9073
+ if (!wasReplaced && !arrayMap.storeVar) {
9074
+ staticArrayRefreshOnMount.push(getComponentArrayRefreshMethodName(arrayPropName));
9075
+ }
8377
9076
  applied = true;
8378
9077
  }
8379
9078
  }
9079
+ for (const arrayMap of componentArrayMaps) {
9080
+ if (!arrayMap.storeVar) continue;
9081
+ const storeRef = stateRefs.get(arrayMap.storeVar);
9082
+ const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
9083
+ if (!getterDepPaths || getterDepPaths.length === 0) continue;
9084
+ const pathKey = arrayMap.arrayPathParts.join(".");
9085
+ for (const depPath of getterDepPaths) {
9086
+ const depObserveKey = buildObserveKey(depPath, arrayMap.storeVar);
9087
+ const depMethodName = getObserveMethodName(depPath, arrayMap.storeVar);
9088
+ const refreshStmt = t18.expressionStatement(
9089
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__refreshList")), [
9090
+ t18.stringLiteral(pathKey)
9091
+ ])
9092
+ );
9093
+ const existing = addedMethods.get(depObserveKey);
9094
+ if (existing && t18.isBlockStatement(existing.body)) {
9095
+ const renderedGuardIdx = existing.body.body.findIndex(
9096
+ (s) => t18.isIfStatement(s) && t18.isMemberExpression(s.test) && t18.isIdentifier(s.test.property) && s.test.property.name === "rendered_"
9097
+ );
9098
+ if (renderedGuardIdx >= 0) {
9099
+ existing.body.body.splice(renderedGuardIdx, 0, refreshStmt);
9100
+ } else {
9101
+ existing.body.body.push(refreshStmt);
9102
+ }
9103
+ } else {
9104
+ const delegateMethod = t18.classMethod(
9105
+ "method",
9106
+ t18.identifier(depMethodName),
9107
+ [t18.identifier("__v"), t18.identifier("__c")],
9108
+ t18.blockStatement([refreshStmt])
9109
+ );
9110
+ mergeObserveMethod(depObserveKey, delegateMethod);
9111
+ }
9112
+ }
9113
+ }
9114
+ for (const arrayMap of componentArrayMaps) {
9115
+ if (!arrayMap.storeVar) continue;
9116
+ const itemPropsMethod = componentArrayItemPropsMethods.get(arrayMap);
9117
+ if (!itemPropsMethod) continue;
9118
+ const pathKey = arrayMap.arrayPathParts.join(".");
9119
+ const storeRef = stateRefs.get(arrayMap.storeVar);
9120
+ const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
9121
+ const getterDepKeys = new Set((getterDepPaths || []).map((dp) => buildObserveKey(dp, arrayMap.storeVar)));
9122
+ const externalDeps = /* @__PURE__ */ new Map();
9123
+ const clonedBody = t18.cloneNode(itemPropsMethod.body, true);
9124
+ traverse11(t18.program([t18.expressionStatement(t18.arrowFunctionExpression([], clonedBody))]), {
9125
+ noScope: true,
9126
+ Identifier(idPath) {
9127
+ if (idPath.parentPath && t18.isMemberExpression(idPath.parentPath.node) && idPath.parentPath.node.property === idPath.node && !idPath.parentPath.node.computed)
9128
+ return;
9129
+ const ref = stateRefs.get(idPath.node.name);
9130
+ if (!ref) return;
9131
+ if (itemPropsMethod.params.some((p) => t18.isIdentifier(p) && p.name === idPath.node.name)) return;
9132
+ if (ref.kind === "imported-destructured" && ref.storeVar && ref.propName) {
9133
+ const depKey = buildObserveKey([ref.propName], ref.storeVar);
9134
+ if (!getterDepKeys.has(depKey) && !externalDeps.has(depKey)) {
9135
+ externalDeps.set(depKey, { parts: [ref.propName], storeVar: ref.storeVar });
9136
+ }
9137
+ }
9138
+ },
9139
+ MemberExpression(mePath) {
9140
+ const resolved = resolvePath(mePath.node, stateRefs);
9141
+ if (!resolved?.parts?.length || !resolved.isImportedState) return;
9142
+ if (resolved.parts.some((p) => p === "__raw")) return;
9143
+ const depKey = buildObserveKey(resolved.parts, resolved.storeVar);
9144
+ if (!getterDepKeys.has(depKey) && !externalDeps.has(depKey)) {
9145
+ externalDeps.set(depKey, { parts: [...resolved.parts], storeVar: resolved.storeVar });
9146
+ }
9147
+ }
9148
+ });
9149
+ for (const [depKey, dep] of externalDeps) {
9150
+ const depMethodName = getObserveMethodName(dep.parts, dep.storeVar);
9151
+ if (!stateProps.has(depKey)) stateProps.set(depKey, dep.parts);
9152
+ const delegateBody = t18.blockStatement([
9153
+ t18.expressionStatement(
9154
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__refreshList")), [
9155
+ t18.stringLiteral(pathKey)
9156
+ ])
9157
+ )
9158
+ ]);
9159
+ const delegateMethod = t18.classMethod(
9160
+ "method",
9161
+ t18.identifier(depMethodName),
9162
+ [t18.identifier("__v"), t18.identifier("__c")],
9163
+ delegateBody
9164
+ );
9165
+ mergeObserveMethod(depKey, delegateMethod);
9166
+ }
9167
+ }
8380
9168
  const renderEventHandlers = [];
8381
9169
  htmlArrayMaps.forEach((arrayMap) => {
8382
- const { method } = generateRenderItemMethod(
9170
+ const { method, needsUnwrapHelper } = generateRenderItemMethod(
8383
9171
  arrayMap,
8384
9172
  imports,
8385
9173
  renderEventHandlers,
@@ -8387,6 +9175,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8387
9175
  classPath.node.body,
8388
9176
  tmplSetupCtx
8389
9177
  );
9178
+ if (needsUnwrapHelper) needsModuleLevelUnwrapHelper = true;
8390
9179
  if (method) {
8391
9180
  classPath.node.body.body.push(method);
8392
9181
  applied = true;
@@ -8405,42 +9194,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8405
9194
  }
8406
9195
  const observeKey = buildObserveKey(arrayMap.arrayPathParts, arrayMap.storeVar);
8407
9196
  const arrayHandlerMethodName = getObserveMethodName(arrayMap.arrayPathParts, arrayMap.storeVar);
8408
- generateArrayHandlers(arrayMap, arrayHandlerMethodName).forEach(
8409
- (h) => {
8410
- mergeObserveMethod(observeKey, h);
8411
- }
8412
- );
8413
- if (arrayMap.storeVar && arrayMap.arrayPathParts.length === 1) {
8414
- const storeRef = stateRefs.get(arrayMap.storeVar);
8415
- const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
8416
- if (getterDepPaths && getterDepPaths.length > 0) {
8417
- for (const depPath of getterDepPaths) {
8418
- const depObserveKey = buildObserveKey(depPath, arrayMap.storeVar);
8419
- const depMethodName = getObserveMethodName(depPath, arrayMap.storeVar);
8420
- const delegateBody = t18.blockStatement([
8421
- t18.expressionStatement(
8422
- t18.callExpression(
8423
- t18.memberExpression(t18.thisExpression(), t18.identifier(arrayHandlerMethodName)),
8424
- [
8425
- t18.memberExpression(
8426
- t18.identifier(arrayMap.storeVar),
8427
- t18.identifier(arrayMap.arrayPathParts[0])
8428
- ),
8429
- t18.nullLiteral()
8430
- ]
8431
- )
8432
- )
8433
- ]);
8434
- const delegateMethod = t18.classMethod(
8435
- "method",
8436
- t18.identifier(depMethodName),
8437
- [t18.identifier("__v"), t18.identifier("__c")],
8438
- delegateBody
8439
- );
8440
- mergeObserveMethod(depObserveKey, delegateMethod);
8441
- }
8442
- }
8443
- }
9197
+ generateArrayHandlers(arrayMap, arrayHandlerMethodName).forEach((h) => {
9198
+ mergeObserveMethod(observeKey, h);
9199
+ });
8444
9200
  });
8445
9201
  if ((analysis.conditionalSlots || []).length > 0) {
8446
9202
  const templatePropNames2 = getTemplatePropNames(classPath.node.body);
@@ -8448,7 +9204,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8448
9204
  classPath.node.body,
8449
9205
  analysis.conditionalSlots,
8450
9206
  templatePropNames2,
8451
- getTemplateParamIdentifier(classPath.node.body)
9207
+ getTemplateParamIdentifier(classPath.node.body),
9208
+ analysis.earlyReturnGuard
8452
9209
  );
8453
9210
  }
8454
9211
  if (htmlArrayMaps.length > 0) {
@@ -8468,17 +9225,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8468
9225
  t18.identifier(arrayMap.arrayPathParts[0])
8469
9226
  );
8470
9227
  } else {
8471
- valueExpr = t18.memberExpression(
8472
- t18.thisExpression(),
8473
- t18.identifier(arrayMap.arrayPathParts[0])
8474
- );
9228
+ valueExpr = t18.memberExpression(t18.thisExpression(), t18.identifier(arrayMap.arrayPathParts[0]));
8475
9229
  }
8476
9230
  afterRenderCalls.push(
8477
9231
  t18.expressionStatement(
8478
- t18.callExpression(
8479
- t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)),
8480
- [valueExpr, t18.nullLiteral()]
8481
- )
9232
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), [
9233
+ valueExpr,
9234
+ t18.nullLiteral()
9235
+ ])
8482
9236
  )
8483
9237
  );
8484
9238
  });
@@ -8489,10 +9243,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8489
9243
  [],
8490
9244
  t18.blockStatement([
8491
9245
  t18.expressionStatement(
8492
- t18.callExpression(
8493
- t18.memberExpression(t18.super(), t18.identifier("onAfterRender")),
8494
- []
8495
- )
9246
+ t18.callExpression(t18.memberExpression(t18.super(), t18.identifier("onAfterRender")), [])
8496
9247
  ),
8497
9248
  ...afterRenderCalls
8498
9249
  ])
@@ -8500,50 +9251,6 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8500
9251
  classPath.node.body.body.push(afterRenderMethod);
8501
9252
  }
8502
9253
  }
8503
- if (componentArrayMountMethods.length > 0) {
8504
- const mountCalls = componentArrayMountMethods.map(
8505
- (methodName) => t18.expressionStatement(
8506
- t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), [])
8507
- )
8508
- );
8509
- const existingAfterRender = classPath.node.body.body.find(
8510
- (m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === "onAfterRender"
8511
- );
8512
- if (existingAfterRender) {
8513
- existingAfterRender.body.body.push(...mountCalls);
8514
- } else {
8515
- const afterRenderMethod = t18.classMethod(
8516
- "method",
8517
- t18.identifier("onAfterRender"),
8518
- [],
8519
- t18.blockStatement([
8520
- t18.expressionStatement(
8521
- t18.callExpression(
8522
- t18.memberExpression(t18.super(), t18.identifier("onAfterRender")),
8523
- []
8524
- )
8525
- ),
8526
- ...mountCalls
8527
- ])
8528
- );
8529
- classPath.node.body.body.push(afterRenderMethod);
8530
- }
8531
- const rerenderOverride = t18.classMethod(
8532
- "method",
8533
- t18.identifier("__geaRequestRender"),
8534
- [],
8535
- t18.blockStatement([
8536
- t18.expressionStatement(
8537
- t18.callExpression(
8538
- t18.memberExpression(t18.super(), t18.identifier("__geaRequestRender")),
8539
- []
8540
- )
8541
- ),
8542
- ...mountCalls.map((stmt) => t18.cloneNode(stmt, true))
8543
- ])
8544
- );
8545
- classPath.node.body.body.push(rerenderOverride);
8546
- }
8547
9254
  if (renderEventHandlers.length > 0) {
8548
9255
  applied = appendCompiledEventMethods(classPath.node.body, renderEventHandlers) || applied;
8549
9256
  }
@@ -8563,7 +9270,6 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8563
9270
  }
8564
9271
  return importedStores.get(storeVar);
8565
9272
  };
8566
- const prevValueInits = [];
8567
9273
  addedMethods.forEach((_method, observeKey) => {
8568
9274
  const { parts, storeVar } = parseObserveKey(observeKey);
8569
9275
  if (!storeVar) {
@@ -8572,82 +9278,39 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8572
9278
  const compGetterDeps = componentGetterStoreDeps.get(parts[0]);
8573
9279
  if (compGetterDeps && compGetterDeps.length > 0) {
8574
9280
  const originalMethodName = getObserveMethodName(parts);
8575
- const wrapperMethodName = `${originalMethodName}__via`;
8576
- if (!classPath.node.body.body.some(
8577
- (m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === wrapperMethodName
8578
- )) {
8579
- classPath.node.body.body.push(
8580
- t18.classMethod(
8581
- "method",
8582
- t18.identifier(wrapperMethodName),
8583
- [t18.identifier("_v"), t18.identifier("change")],
8584
- t18.blockStatement([
8585
- t18.expressionStatement(
8586
- t18.callExpression(
8587
- t18.memberExpression(t18.thisExpression(), t18.identifier(originalMethodName)),
8588
- [
8589
- t18.memberExpression(t18.thisExpression(), t18.identifier(parts[0])),
8590
- t18.nullLiteral()
8591
- ]
8592
- )
8593
- )
8594
- ])
8595
- )
8596
- );
8597
- }
8598
9281
  for (const dep of compGetterDeps) {
8599
9282
  const depKey = buildObserveKey(dep.pathParts, dep.storeVar) + `__getter_${parts[0]}`;
8600
9283
  ensureStoreGroup(dep.storeVar).observeHandlers.set(depKey, {
8601
9284
  pathParts: dep.pathParts,
8602
- methodName: wrapperMethodName
9285
+ methodName: originalMethodName,
9286
+ isVia: true,
9287
+ rereadExpr: t18.memberExpression(t18.thisExpression(), t18.identifier(parts[0]))
8603
9288
  });
8604
9289
  }
8605
- const compPrevProp = `__geaPrev_${originalMethodName}`;
8606
- prevValueInits.push(
8607
- js7`try { this.${id11(compPrevProp)} = this.${id11(parts[0])}; } catch(_e) {}`
8608
- );
8609
9290
  }
8610
9291
  return;
8611
9292
  }
8612
9293
  localObserveHandlers.set(observeKey, { pathParts: parts, methodName: getObserveMethodName(parts) });
8613
9294
  return;
8614
9295
  }
8615
- if (parts.length === 1) {
9296
+ {
8616
9297
  const storeRef = stateRefs.get(storeVar);
8617
9298
  const getterDepPaths = storeRef?.getterDeps?.get(parts[0]);
8618
9299
  if (getterDepPaths && getterDepPaths.length > 0) {
8619
9300
  const originalMethodName = getObserveMethodName(parts, storeVar);
8620
- const wrapperMethodName = `${originalMethodName}__via`;
8621
- if (!classPath.node.body.body.some(
8622
- (m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === wrapperMethodName
8623
- )) {
8624
- classPath.node.body.body.push(
8625
- t18.classMethod(
8626
- "method",
8627
- t18.identifier(wrapperMethodName),
8628
- [t18.identifier("_v"), t18.identifier("change")],
8629
- t18.blockStatement([
8630
- t18.expressionStatement(
8631
- t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(originalMethodName)), [
8632
- t18.memberExpression(t18.identifier(storeVar), t18.identifier(parts[0])),
8633
- t18.nullLiteral()
8634
- ])
8635
- )
8636
- ])
8637
- )
8638
- );
9301
+ let rereadExpr = t18.memberExpression(t18.identifier(storeVar), t18.identifier(parts[0]));
9302
+ for (let i = 1; i < parts.length; i++) {
9303
+ rereadExpr = t18.optionalMemberExpression(rereadExpr, t18.identifier(parts[i]), false, true);
8639
9304
  }
8640
9305
  for (const depPath of getterDepPaths) {
8641
- const depKey = buildObserveKey(depPath, storeVar) + `__getter_${parts[0]}`;
9306
+ const depKey = buildObserveKey(depPath, storeVar) + `__getter_${parts.join("_")}`;
8642
9307
  ensureStoreGroup(storeVar).observeHandlers.set(depKey, {
8643
9308
  pathParts: depPath,
8644
- methodName: wrapperMethodName
9309
+ methodName: originalMethodName,
9310
+ isVia: true,
9311
+ rereadExpr
8645
9312
  });
8646
9313
  }
8647
- const prevProp = `__geaPrev_${originalMethodName}`;
8648
- prevValueInits.push(
8649
- js7`try { this.${id11(prevProp)} = ${t18.memberExpression(t18.identifier(storeVar), t18.identifier(parts[0]))}; } catch(_e) {}`
8650
- );
8651
9314
  return;
8652
9315
  }
8653
9316
  }
@@ -8711,28 +9374,148 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8711
9374
  methodName: obs.refreshMethodName
8712
9375
  });
8713
9376
  }
9377
+ if (guardStateKeys.size > 0) {
9378
+ addedMethods.forEach((method, observeKey) => {
9379
+ const { parts, storeVar: sv } = parseObserveKey(observeKey);
9380
+ if (!sv) return;
9381
+ if (parts.length >= 2) {
9382
+ for (let prefixLen = 1; prefixLen < parts.length; prefixLen++) {
9383
+ const prefixKey = buildObserveKey(parts.slice(0, prefixLen), sv);
9384
+ if (guardStateKeys.has(prefixKey)) {
9385
+ const guardCheck = t18.ifStatement(
9386
+ t18.binaryExpression(
9387
+ "==",
9388
+ t18.memberExpression(t18.identifier(sv), t18.identifier(parts[prefixLen - 1])),
9389
+ t18.nullLiteral()
9390
+ ),
9391
+ t18.returnStatement()
9392
+ );
9393
+ if (t18.isBlockStatement(method.body)) {
9394
+ method.body.body.unshift(guardCheck);
9395
+ }
9396
+ break;
9397
+ }
9398
+ }
9399
+ } else if (parts.length === 1) {
9400
+ const storeRef = stateRefs.get(sv);
9401
+ if (storeRef?.getterDeps) {
9402
+ for (const [getterName, depPaths] of storeRef.getterDeps) {
9403
+ const isDepOfGetter = depPaths.some((dp) => dp.length === 1 && dp[0] === parts[0]);
9404
+ if (!isDepOfGetter) continue;
9405
+ const guardKey = buildObserveKey([getterName], sv);
9406
+ if (!guardStateKeys.has(guardKey)) continue;
9407
+ const guardCheck = t18.ifStatement(
9408
+ t18.binaryExpression(
9409
+ "==",
9410
+ t18.memberExpression(t18.identifier(sv), t18.identifier(getterName)),
9411
+ t18.nullLiteral()
9412
+ ),
9413
+ t18.returnStatement()
9414
+ );
9415
+ if (t18.isBlockStatement(method.body)) {
9416
+ method.body.body.unshift(guardCheck);
9417
+ }
9418
+ break;
9419
+ }
9420
+ }
9421
+ }
9422
+ });
9423
+ }
9424
+ {
9425
+ const seen = /* @__PURE__ */ new Set();
9426
+ const methodEntries = [];
9427
+ addedMethods.forEach((method, observeKey) => {
9428
+ if (seen.has(method)) return;
9429
+ seen.add(method);
9430
+ const name = getMethodName(method);
9431
+ if (name) methodEntries.push({ observeKey, method, name });
9432
+ });
9433
+ const bodyGroups = /* @__PURE__ */ new Map();
9434
+ for (const entry of methodEntries) {
9435
+ const { storeVar } = parseObserveKey(entry.observeKey);
9436
+ const bodyCode = (storeVar || "") + ":" + generate2(t18.blockStatement(entry.method.body.body)).code;
9437
+ if (!bodyGroups.has(bodyCode)) bodyGroups.set(bodyCode, []);
9438
+ bodyGroups.get(bodyCode).push(entry);
9439
+ }
9440
+ const renameMap = /* @__PURE__ */ new Map();
9441
+ for (const [, group] of bodyGroups) {
9442
+ if (group.length < 2) continue;
9443
+ const canonical = group[0];
9444
+ for (let i = 1; i < group.length; i++) {
9445
+ const dup = group[i];
9446
+ renameMap.set(dup.name, canonical.name);
9447
+ const idx = classPath.node.body.body.indexOf(dup.method);
9448
+ if (idx !== -1) classPath.node.body.body.splice(idx, 1);
9449
+ }
9450
+ }
9451
+ if (renameMap.size > 0) {
9452
+ for (const [, config] of importedStores) {
9453
+ for (const [key, entry] of config.observeHandlers) {
9454
+ if (renameMap.has(entry.methodName)) {
9455
+ config.observeHandlers.set(key, { ...entry, methodName: renameMap.get(entry.methodName) });
9456
+ }
9457
+ }
9458
+ }
9459
+ for (const [key, entry] of localObserveHandlers) {
9460
+ if (renameMap.has(entry.methodName)) {
9461
+ localObserveHandlers.set(key, { ...entry, methodName: renameMap.get(entry.methodName) });
9462
+ }
9463
+ }
9464
+ }
9465
+ }
8714
9466
  if (importedStores.size > 0 || localObserveHandlers.size > 0 || mapRegistrations.length > 0) {
8715
9467
  const storeConfigs = Array.from(importedStores.entries()).map(([storeVar, config]) => ({
8716
9468
  storeVar,
8717
9469
  captureExpression: config.captureExpression,
8718
- observeHandlers: Array.from(config.observeHandlers.values()).map(({ pathParts, methodName }) => ({
8719
- pathParts,
8720
- methodName
8721
- }))
9470
+ observeHandlers: Array.from(config.observeHandlers.values()).map(
9471
+ ({ pathParts, methodName, isVia, rereadExpr }) => ({
9472
+ pathParts,
9473
+ methodName,
9474
+ isVia,
9475
+ rereadExpr
9476
+ })
9477
+ )
8722
9478
  }));
8723
- if (storeConfigs.length > 0 || mapRegistrations.length > 0) {
8724
- const createdHooksMethod = generateCreatedHooks(storeConfigs);
9479
+ for (const olc of observeListConfigs) {
9480
+ ensureStoreGroup(olc.storeVar);
9481
+ }
9482
+ if (storeConfigs.length > 0 || mapRegistrations.length > 0 || observeListConfigs.length > 0) {
9483
+ const createdHooksMethod = generateCreatedHooks(
9484
+ storeConfigs,
9485
+ htmlArrayMaps.length > 0,
9486
+ observeListConfigs
9487
+ );
8725
9488
  if (mapRegistrations.length > 0) {
8726
9489
  createdHooksMethod.body.body.push(...mapRegistrations);
8727
9490
  }
8728
- if (prevValueInits.length > 0) {
8729
- createdHooksMethod.body.body.push(...prevValueInits);
9491
+ const generatedCreatedHooksBody = createdHooksMethod.body.body;
9492
+ const existingCreatedHooks = classPath.node.body.body.find(
9493
+ (m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === "createdHooks"
9494
+ );
9495
+ if (existingCreatedHooks) {
9496
+ existingCreatedHooks.body.body.unshift(...generatedCreatedHooksBody);
9497
+ } else {
9498
+ classPath.node.body.body.push(createdHooksMethod);
8730
9499
  }
8731
- classPath.node.body.body.push(createdHooksMethod);
9500
+ }
9501
+ if (staticArrayRefreshOnMount.length > 0) {
9502
+ const refreshStmts = [...new Set(staticArrayRefreshOnMount)].map(
9503
+ (name) => t18.expressionStatement(
9504
+ t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(name)), [])
9505
+ )
9506
+ );
9507
+ const existingHook = classPath.node.body.body.find(
9508
+ (m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === "onAfterRenderHooks"
9509
+ );
9510
+ if (existingHook) existingHook.body.body.push(...refreshStmts);
9511
+ else
9512
+ classPath.node.body.body.push(
9513
+ t18.classMethod("method", t18.identifier("onAfterRenderHooks"), [], t18.blockStatement(refreshStmts))
9514
+ );
8732
9515
  }
8733
9516
  if (localObserveHandlers.size > 0) {
8734
9517
  classPath.node.body.body.push(
8735
- generateLocalStateObserverSetup(Array.from(localObserveHandlers.values()))
9518
+ generateLocalStateObserverSetup(Array.from(localObserveHandlers.values()), htmlArrayMaps.length > 0)
8736
9519
  );
8737
9520
  }
8738
9521
  }
@@ -8741,6 +9524,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
8741
9524
  });
8742
9525
  }
8743
9526
  });
9527
+ if (needsModuleLevelUnwrapHelper) {
9528
+ const alreadyHas = ast.program.body.some(
9529
+ (stmt) => t18.isVariableDeclaration(stmt) && stmt.declarations.some((d) => t18.isIdentifier(d.id) && d.id.name === "__v")
9530
+ );
9531
+ if (!alreadyHas) {
9532
+ ast.program.body.unshift(buildValueUnwrapHelper());
9533
+ }
9534
+ }
8744
9535
  return applied;
8745
9536
  }
8746
9537
  function collectUnresolvedDependencies(unresolvedMaps, stateRefs, classBody2) {
@@ -8773,8 +9564,8 @@ function collectUnresolvedDependencies(unresolvedMaps, stateRefs, classBody2) {
8773
9564
  }
8774
9565
  const depExpr = resolveHelperCallExpressionForDeps(unresolvedMap.computationExpr, classBody2);
8775
9566
  const targetExpr = depExpr || unresolvedMap.computationExpr;
8776
- const program9 = t18.program([t18.expressionStatement(t18.cloneNode(targetExpr, true))]);
8777
- traverse10(program9, {
9567
+ const program10 = t18.program([t18.expressionStatement(t18.cloneNode(targetExpr, true))]);
9568
+ traverse11(program10, {
8778
9569
  noScope: true,
8779
9570
  MemberExpression(path) {
8780
9571
  const targetExpr2 = path.parentPath && t18.isCallExpression(path.parentPath.node) && path.parentPath.node.callee === path.node ? path.node.object : path.node;
@@ -8803,8 +9594,8 @@ function collectHelperMethodDependencies(expr, classBody2, stateRefs, deps) {
8803
9594
  (node) => t18.isClassMethod(node) && t18.isIdentifier(node.key) && node.key.name === helperMethodName
8804
9595
  );
8805
9596
  if (!helperMethod || !t18.isBlockStatement(helperMethod.body)) return false;
8806
- const program9 = t18.program(helperMethod.body.body.map((stmt) => t18.cloneNode(stmt, true)));
8807
- traverse10(program9, {
9597
+ const program10 = t18.program(helperMethod.body.body.map((stmt) => t18.cloneNode(stmt, true)));
9598
+ traverse11(program10, {
8808
9599
  noScope: true,
8809
9600
  MemberExpression(path) {
8810
9601
  const resolved = resolvePath(path.node, stateRefs);
@@ -8844,7 +9635,7 @@ function generateUnresolvedRelationalObserver(arrayMap, unresolvedMap, relBindin
8844
9635
  t18.memberExpression(t18.thisExpression(), t18.identifier("id")),
8845
9636
  t18.stringLiteral("-" + arrayMap.containerBindingId)
8846
9637
  )
8847
- ]) : jsExpr5`this.$(":scope")`;
9638
+ ]) : jsExpr4`this.$(":scope")`;
8848
9639
  const setupStatements = replacePropRefsInStatements(
8849
9640
  (unresolvedMap.computationSetupStatements || []).map((s) => t18.cloneNode(s, true)),
8850
9641
  templatePropNames,
@@ -8866,7 +9657,7 @@ function generateUnresolvedRelationalObserver(arrayMap, unresolvedMap, relBindin
8866
9657
  method,
8867
9658
  js7`if (!this.rendered_) return;`,
8868
9659
  lazyInit2(containerName, containerLookup),
8869
- ...jsBlockBody5`if (!${containerRef}) return;`,
9660
+ ...jsBlockBody4`if (!${containerRef}) return;`,
8870
9661
  ...setupStatements,
8871
9662
  t18.variableDeclaration("var", [
8872
9663
  t18.variableDeclarator(
@@ -8878,7 +9669,7 @@ function generateUnresolvedRelationalObserver(arrayMap, unresolvedMap, relBindin
8878
9669
  )
8879
9670
  )
8880
9671
  ]),
8881
- ...jsBlockBody5`
9672
+ ...jsBlockBody4`
8882
9673
  var __items = ${containerRef}.querySelectorAll('[data-gea-item-id]');
8883
9674
  for (var __i = 0; __i < __items.length && __i < __arr.length; __i++) {
8884
9675
  var __child = __items[__i];
@@ -8909,18 +9700,14 @@ function generateMapRegistration(arrayMap, unresolvedMap, templatePropNames, who
8909
9700
  t18.memberExpression(t18.thisExpression(), t18.identifier("id")),
8910
9701
  t18.stringLiteral("-" + arrayMap.containerBindingId)
8911
9702
  )
8912
- ]) : jsExpr5`this.$(":scope")`;
9703
+ ]) : jsExpr4`this.$(":scope")`;
8913
9704
  let arrExpr = t18.cloneNode(unresolvedMap.computationExpr || t18.arrayExpression([]), true);
8914
- let setupStatements = [];
9705
+ let setupStatements = unresolvedMap.computationSetupStatements?.length ? unresolvedMap.computationSetupStatements.map((s) => t18.cloneNode(s, true)) : [];
8915
9706
  const needsReplace = templatePropNames && templatePropNames.size > 0 || wholeParamName;
8916
9707
  if (needsReplace) {
8917
9708
  arrExpr = replacePropRefsInExpression(arrExpr, templatePropNames || /* @__PURE__ */ new Set(), wholeParamName);
8918
- if (unresolvedMap.computationSetupStatements?.length) {
8919
- setupStatements = replacePropRefsInStatements(
8920
- unresolvedMap.computationSetupStatements.map((s) => t18.cloneNode(s, true)),
8921
- templatePropNames || /* @__PURE__ */ new Set(),
8922
- wholeParamName
8923
- );
9709
+ if (setupStatements.length) {
9710
+ setupStatements = replacePropRefsInStatements(setupStatements, templatePropNames || /* @__PURE__ */ new Set(), wholeParamName);
8924
9711
  }
8925
9712
  }
8926
9713
  const prunedSetup = pruneUnusedSetupStatements(setupStatements, arrExpr);
@@ -8948,7 +9735,7 @@ function generateMapRegistration(arrayMap, unresolvedMap, templatePropNames, who
8948
9735
  function collectFreeIdentifiers(nodes) {
8949
9736
  const names = /* @__PURE__ */ new Set();
8950
9737
  for (const node of nodes) {
8951
- traverse10(
9738
+ traverse11(
8952
9739
  t18.isProgram(node) ? node : t18.program([t18.isStatement(node) ? node : t18.expressionStatement(node)]),
8953
9740
  {
8954
9741
  noScope: true,
@@ -9017,12 +9804,12 @@ function getArrayPropNameFromExpr(expr) {
9017
9804
  return null;
9018
9805
  }
9019
9806
  function replaceMapWithComponentArrayItems(templateMethod, arrayExpr, itemsName) {
9020
- if (!arrayExpr || !t18.isBlockStatement(templateMethod.body)) return;
9807
+ if (!arrayExpr || !t18.isBlockStatement(templateMethod.body)) return false;
9021
9808
  const tempProg = t18.program([
9022
9809
  t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
9023
9810
  ]);
9024
9811
  let replaced = false;
9025
- traverse10(tempProg, {
9812
+ traverse11(tempProg, {
9026
9813
  noScope: true,
9027
9814
  CallExpression(path) {
9028
9815
  if (replaced) return;
@@ -9038,19 +9825,12 @@ function replaceMapWithComponentArrayItems(templateMethod, arrayExpr, itemsName)
9038
9825
  toReplace = path.parentPath.parentPath;
9039
9826
  }
9040
9827
  const itemsAccess = t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName));
9041
- const mapCallback = t18.arrowFunctionExpression(
9042
- [t18.identifier("__item")],
9043
- t18.templateLiteral(
9044
- [t18.templateElement({ raw: "", cooked: "" }), t18.templateElement({ raw: "", cooked: "" })],
9045
- [t18.identifier("__item")]
9046
- )
9047
- );
9048
- const mapCall = t18.callExpression(t18.memberExpression(itemsAccess, t18.identifier("map")), [mapCallback]);
9049
- const joinCall = t18.callExpression(t18.memberExpression(mapCall, t18.identifier("join")), [t18.stringLiteral("")]);
9828
+ const joinCall = t18.callExpression(t18.memberExpression(itemsAccess, t18.identifier("join")), [t18.stringLiteral("")]);
9050
9829
  toReplace.replaceWith(joinCall);
9051
9830
  replaced = true;
9052
9831
  }
9053
9832
  });
9833
+ return replaced;
9054
9834
  }
9055
9835
  function inlineIntoConstructor(classBody2, statements) {
9056
9836
  let ctor = classBody2.body.find(
@@ -9067,23 +9847,6 @@ function inlineIntoConstructor(classBody2, statements) {
9067
9847
  }
9068
9848
  ctor.body.body.push(...statements);
9069
9849
  }
9070
- function ensureConstructorCalls(classBody2, methodName) {
9071
- let ctor = classBody2.body.find(
9072
- (member) => t18.isClassMethod(member) && t18.isIdentifier(member.key) && member.key.name === "constructor"
9073
- );
9074
- if (!ctor) {
9075
- ctor = appendToBody5(
9076
- jsMethod8`${id11("constructor")}(...args) {}`,
9077
- t18.expressionStatement(t18.callExpression(t18.super(), [t18.spreadElement(t18.identifier("args"))])),
9078
- t18.expressionStatement(t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), []))
9079
- );
9080
- classBody2.body.unshift(ctor);
9081
- return;
9082
- }
9083
- ctor.body.body.push(
9084
- t18.expressionStatement(t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), []))
9085
- );
9086
- }
9087
9850
  function ensureDisposeCalls(classBody2, targets) {
9088
9851
  const disposeStatements = targets.map(
9089
9852
  (target) => js7`this.${id11(target)}?.forEach?.(item => item?.dispose?.());`
@@ -9151,28 +9914,47 @@ function ensureOnPropChangeMethod(classBody2, inlinePatchBodies, compiledChildre
9151
9914
  nonDirectChildren.push(child);
9152
9915
  }
9153
9916
  }
9154
- const childRefreshMethodNames = nonDirectChildren.filter((child) => child.dependencies.some((dep) => !dep.storeVar && dep.pathParts[0] === "props")).map((child) => `__refreshChildProps_${child.instanceVar.replace(/^_/, "")}`);
9155
- const arrayRefreshMethodNames = arrayRefreshDeps.filter((d) => d.propNames.length > 0).map((d) => d.methodName);
9156
- const refreshMethodNames = [.../* @__PURE__ */ new Set([...childRefreshMethodNames, ...arrayRefreshMethodNames])];
9157
- const refreshPropDeps = /* @__PURE__ */ new Map();
9158
- for (const child of nonDirectChildren) {
9159
- const methodName = `__refreshChildProps_${child.instanceVar.replace(/^_/, "")}`;
9917
+ const childRefreshEntries = nonDirectChildren.filter((child) => child.dependencies.some((dep) => !dep.storeVar && dep.pathParts[0] === "props")).map((child) => {
9160
9918
  const depProps = /* @__PURE__ */ new Set();
9161
9919
  for (const dep of child.dependencies) {
9162
9920
  if (!dep.storeVar && dep.pathParts[0] === "props" && dep.pathParts.length > 1) {
9163
9921
  depProps.add(dep.pathParts[1]);
9164
9922
  }
9165
9923
  }
9166
- if (depProps.size > 0) {
9167
- refreshPropDeps.set(methodName, depProps);
9168
- }
9169
- }
9924
+ return { child, depProps };
9925
+ });
9926
+ const arrayRefreshMethodNames = arrayRefreshDeps.filter((d) => d.propNames.length > 0).map((d) => d.methodName);
9927
+ const refreshPropDeps = /* @__PURE__ */ new Map();
9170
9928
  for (const { methodName, propNames } of arrayRefreshDeps) {
9171
9929
  if (propNames.length > 0) {
9172
9930
  refreshPropDeps.set(methodName, new Set(propNames));
9173
9931
  }
9174
9932
  }
9175
- const refreshCalls = refreshMethodNames.map((name) => {
9933
+ const childRefreshCalls = childRefreshEntries.map(({ child, depProps }) => {
9934
+ const call = t18.expressionStatement(
9935
+ t18.callExpression(
9936
+ t18.memberExpression(
9937
+ t18.memberExpression(t18.thisExpression(), t18.identifier(child.instanceVar)),
9938
+ t18.identifier("__geaUpdateProps")
9939
+ ),
9940
+ [
9941
+ t18.callExpression(
9942
+ t18.memberExpression(t18.thisExpression(), t18.identifier(`__buildProps_${child.instanceVar.replace(/^_/, "")}`)),
9943
+ []
9944
+ )
9945
+ ]
9946
+ )
9947
+ );
9948
+ if (depProps.size > 0) {
9949
+ const guard = Array.from(depProps).reduce((acc, prop) => {
9950
+ const test = t18.binaryExpression("===", t18.identifier("key"), t18.stringLiteral(prop));
9951
+ return acc ? t18.logicalExpression("||", acc, test) : test;
9952
+ }, void 0);
9953
+ return t18.ifStatement(guard, call);
9954
+ }
9955
+ return call;
9956
+ });
9957
+ const arrayRefreshCalls = arrayRefreshMethodNames.map((name) => {
9176
9958
  const deps = refreshPropDeps.get(name);
9177
9959
  const call = t18.expressionStatement(t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(name)), []));
9178
9960
  if (deps && deps.size > 0) {
@@ -9184,6 +9966,7 @@ function ensureOnPropChangeMethod(classBody2, inlinePatchBodies, compiledChildre
9184
9966
  }
9185
9967
  return call;
9186
9968
  });
9969
+ const refreshCalls = [...childRefreshCalls, ...arrayRefreshCalls];
9187
9970
  const condPatchCalls = [];
9188
9971
  if (conditionalSlots.length > 0) {
9189
9972
  for (let i = 0; i < conditionalSlots.length; i++) {
@@ -9205,10 +9988,7 @@ function ensureOnPropChangeMethod(classBody2, inlinePatchBodies, compiledChildre
9205
9988
  const patchCalls = Array.from(inlinePatchBodies.entries()).map(
9206
9989
  ([propName, bodyStmts]) => t18.ifStatement(
9207
9990
  t18.binaryExpression("===", t18.identifier("key"), t18.stringLiteral(propName)),
9208
- t18.tryStatement(
9209
- t18.blockStatement(bodyStmts.map((s) => t18.cloneNode(s, true))),
9210
- t18.catchClause(null, t18.blockStatement([]))
9211
- )
9991
+ t18.blockStatement(bodyStmts.map((s) => t18.cloneNode(s, true)))
9212
9992
  )
9213
9993
  );
9214
9994
  const unresolvedMapRefreshCalls = unresolvedMapPropRefreshDeps.map((dep) => {
@@ -9325,7 +10105,10 @@ function mergeKeyGuards(stmts) {
9325
10105
  }
9326
10106
  return result;
9327
10107
  }
9328
- function generateConditionalPatchMethods(classBody2, slots, templatePropNames, wholeParamName) {
10108
+ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, wholeParamName, earlyReturnGuard) {
10109
+ const guardedRoot = earlyReturnGuard ? earlyReturnFalsyBindingName(earlyReturnGuard) : null;
10110
+ const maybeOptStmts = (stmts) => guardedRoot ? optionalizeBindingRootInStatements(stmts, guardedRoot) : stmts;
10111
+ const maybeOptExpr = (e) => guardedRoot ? optionalizeMemberChainsFromBindingRoot(e, guardedRoot) : e;
9329
10112
  const collectDeduped = (stmts, seen, out) => {
9330
10113
  for (const stmt of stmts) {
9331
10114
  if (t18.isVariableDeclaration(stmt)) {
@@ -9362,9 +10145,12 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
9362
10145
  const rpExpr = (e) => replacePropRefsInExpression(e, templatePropNames, wholeParamName);
9363
10146
  const rpStmts = (s) => replacePropRefsInStatements(s, templatePropNames, wholeParamName);
9364
10147
  const rewrittenCondExprs = slots.map((s) => rpExpr(t18.cloneNode(s.conditionExpr, true)));
9365
- const initSetup = pruneDeadParamDestructuring(
9366
- rpStmts(allSetupStatements.map((s) => t18.cloneNode(s, true))),
9367
- rewrittenCondExprs
10148
+ const rewrittenCondExprsSafe = rewrittenCondExprs.map((e) => maybeOptExpr(e));
10149
+ const initSetup = maybeOptStmts(
10150
+ pruneDeadParamDestructuring(
10151
+ rpStmts(allSetupStatements.map((s) => t18.cloneNode(s, true))),
10152
+ rewrittenCondExprs
10153
+ )
9368
10154
  );
9369
10155
  const condAssignments = [];
9370
10156
  for (let i = 0; i < slots.length; i++) {
@@ -9373,7 +10159,7 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
9373
10159
  t18.assignmentExpression(
9374
10160
  "=",
9375
10161
  t18.memberExpression(t18.thisExpression(), t18.identifier(`__geaCond_${i}`)),
9376
- t18.unaryExpression("!", t18.unaryExpression("!", rewrittenCondExprs[i]))
10162
+ t18.unaryExpression("!", t18.unaryExpression("!", rewrittenCondExprsSafe[i]))
9377
10163
  )
9378
10164
  )
9379
10165
  );
@@ -9382,22 +10168,25 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
9382
10168
  for (let i = 0; i < slots.length; i++) {
9383
10169
  const slot = slots[i];
9384
10170
  const rewrittenCondExpr = rpExpr(t18.cloneNode(slot.conditionExpr, true));
9385
- const condSetup = pruneDeadParamDestructuring(
9386
- rpStmts(allSetupStatements.map((s) => t18.cloneNode(s, true))),
9387
- [rewrittenCondExpr]
10171
+ const condSetup = maybeOptStmts(
10172
+ pruneDeadParamDestructuring(rpStmts(allSetupStatements.map((s) => t18.cloneNode(s, true))), [
10173
+ rewrittenCondExpr
10174
+ ])
9388
10175
  );
9389
- const getCondBody = [...condSetup, t18.returnStatement(rewrittenCondExpr)];
10176
+ const getCondBody = [...condSetup, t18.returnStatement(maybeOptExpr(rewrittenCondExpr))];
9390
10177
  const buildHtmlFn = (htmlExpr) => {
9391
10178
  if (!htmlExpr) return t18.nullLiteral();
9392
10179
  const clonedHtmlExpr = rpExpr(t18.cloneNode(htmlExpr, true));
9393
- const htmlSetup = pruneDeadParamDestructuring(
9394
- rpStmts(allHtmlSetupStatements.map((s) => t18.cloneNode(s, true))),
9395
- [clonedHtmlExpr]
10180
+ const htmlSetup = maybeOptStmts(
10181
+ pruneDeadParamDestructuring(rpStmts(allHtmlSetupStatements.map((s) => t18.cloneNode(s, true))), [
10182
+ clonedHtmlExpr
10183
+ ])
9396
10184
  );
10185
+ const htmlExprSafe = maybeOptExpr(clonedHtmlExpr);
9397
10186
  if (htmlSetup.length > 0) {
9398
- return t18.arrowFunctionExpression([], t18.blockStatement([...htmlSetup, t18.returnStatement(clonedHtmlExpr)]));
10187
+ return t18.arrowFunctionExpression([], t18.blockStatement([...htmlSetup, t18.returnStatement(htmlExprSafe)]));
9399
10188
  }
9400
- return t18.arrowFunctionExpression([], clonedHtmlExpr);
10189
+ return t18.arrowFunctionExpression([], htmlExprSafe);
9401
10190
  };
9402
10191
  registerCondCalls.push(
9403
10192
  t18.expressionStatement(
@@ -9412,10 +10201,7 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
9412
10201
  );
9413
10202
  }
9414
10203
  const evalStatements = [...initSetup, ...condAssignments];
9415
- const initBody = evalStatements.length > 0 ? [
9416
- t18.tryStatement(t18.blockStatement(evalStatements), t18.catchClause(null, t18.blockStatement([]))),
9417
- ...registerCondCalls
9418
- ] : registerCondCalls;
10204
+ const initBody = evalStatements.length > 0 ? [...evalStatements, ...registerCondCalls] : registerCondCalls;
9419
10205
  inlineIntoConstructor(classBody2, initBody);
9420
10206
  }
9421
10207
  function getTemplatePropNames(classBody2) {
@@ -9443,7 +10229,7 @@ function getTemplateParamIdentifier(classBody2) {
9443
10229
  function collectPropNamesFromItemTemplate(itemTemplate, templatePropNames) {
9444
10230
  if (!itemTemplate) return [];
9445
10231
  const used = /* @__PURE__ */ new Set();
9446
- traverse10(itemTemplate, {
10232
+ traverse11(itemTemplate, {
9447
10233
  noScope: true,
9448
10234
  Identifier(path) {
9449
10235
  if (templatePropNames.has(path.node.name)) used.add(path.node.name);
@@ -9485,7 +10271,7 @@ function injectMapItemAttrsIntoTemplate(templateMethod, mapInfos) {
9485
10271
  const tempProg = t18.program([
9486
10272
  t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
9487
10273
  ]);
9488
- traverse10(tempProg, {
10274
+ traverse11(tempProg, {
9489
10275
  noScope: true,
9490
10276
  CallExpression(path) {
9491
10277
  if (!t18.isMemberExpression(path.node.callee)) return;
@@ -9560,7 +10346,7 @@ function addJoinToUnresolvedMapCalls(templateMethod, _unresolvedMaps) {
9560
10346
  const tempProg = t18.program([
9561
10347
  t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
9562
10348
  ]);
9563
- traverse10(tempProg, {
10349
+ traverse11(tempProg, {
9564
10350
  noScope: true,
9565
10351
  CallExpression(path) {
9566
10352
  if (!t18.isMemberExpression(path.node.callee)) return;
@@ -9593,7 +10379,7 @@ function replaceInlineMapWithRenderCall(classPath, arrayMap, renderMethodName) {
9593
10379
  const tempProg = t18.program([
9594
10380
  t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
9595
10381
  ]);
9596
- traverse10(tempProg, {
10382
+ traverse11(tempProg, {
9597
10383
  noScope: true,
9598
10384
  CallExpression(path) {
9599
10385
  if (!t18.isMemberExpression(path.node.callee)) return;
@@ -9642,7 +10428,7 @@ function replaceMapInConditionalSlots(slots, arrayMap, renderMethodName) {
9642
10428
  for (const expr of [slot.truthyHtmlExpr, slot.falsyHtmlExpr]) {
9643
10429
  if (!expr) continue;
9644
10430
  const tempProg = t18.program([t18.expressionStatement(expr)]);
9645
- traverse10(tempProg, {
10431
+ traverse11(tempProg, {
9646
10432
  noScope: true,
9647
10433
  CallExpression(path) {
9648
10434
  if (!t18.isMemberExpression(path.node.callee)) return;
@@ -9691,14 +10477,14 @@ function generateRerenderObserver(pathParts, storeVar, truthinessOnly) {
9691
10477
  const prevProp = `__geaPrev_${getObserveMethodName(pathParts, storeVar)}`;
9692
10478
  if (truthinessOnly) {
9693
10479
  method.body.body.push(
9694
- ...jsBlockBody5`
10480
+ ...jsBlockBody4`
9695
10481
  if (!value === !this.${id11(prevProp)}) return;
9696
10482
  this.${id11(prevProp)} = value;
9697
10483
  `
9698
10484
  );
9699
10485
  } else {
9700
10486
  method.body.body.push(
9701
- ...jsBlockBody5`
10487
+ ...jsBlockBody4`
9702
10488
  if (value === this.${id11(prevProp)}) return;
9703
10489
  this.${id11(prevProp)} = value;
9704
10490
  `
@@ -9707,15 +10493,7 @@ function generateRerenderObserver(pathParts, storeVar, truthinessOnly) {
9707
10493
  }
9708
10494
  method.body.body.push(
9709
10495
  t18.ifStatement(
9710
- t18.logicalExpression(
9711
- "&&",
9712
- t18.memberExpression(t18.thisExpression(), t18.identifier("rendered_")),
9713
- t18.binaryExpression(
9714
- "===",
9715
- t18.unaryExpression("typeof", t18.memberExpression(t18.thisExpression(), t18.identifier("__geaRequestRender"))),
9716
- t18.stringLiteral("function")
9717
- )
9718
- ),
10496
+ t18.memberExpression(t18.thisExpression(), t18.identifier("rendered_")),
9719
10497
  t18.blockStatement([
9720
10498
  t18.expressionStatement(
9721
10499
  t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__geaRequestRender")), [])
@@ -9781,6 +10559,22 @@ function generateStateChildSwapMethod(classBody2, stateChildSlots) {
9781
10559
  setupStatements.push(t18.cloneNode(stmt, true));
9782
10560
  }
9783
10561
  }
10562
+ const propsUpdateCalls = stateChildSlots.map((slot) => {
10563
+ const buildPropsName = `__buildProps_${slot.childInstanceVar.replace(/^_/, "")}`;
10564
+ const hasBuildProps = classBody2.body.some(
10565
+ (m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === buildPropsName
10566
+ );
10567
+ if (!hasBuildProps) return null;
10568
+ return t18.expressionStatement(
10569
+ t18.callExpression(
10570
+ t18.memberExpression(
10571
+ t18.memberExpression(t18.thisExpression(), t18.identifier(slot.childInstanceVar)),
10572
+ t18.identifier("__geaUpdateProps")
10573
+ ),
10574
+ [t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(buildPropsName)), [])]
10575
+ )
10576
+ );
10577
+ }).filter(Boolean);
9784
10578
  const swapCalls = stateChildSlots.map((slot) => {
9785
10579
  const guardClone = t18.cloneNode(slot.guardExpr, true);
9786
10580
  return t18.expressionStatement(
@@ -9789,17 +10583,17 @@ function generateStateChildSwapMethod(classBody2, stateChildSlots) {
9789
10583
  t18.logicalExpression(
9790
10584
  "&&",
9791
10585
  guardClone,
9792
- t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(slot.ensureMethodName)), [])
10586
+ t18.memberExpression(t18.thisExpression(), t18.identifier(slot.childInstanceVar))
9793
10587
  )
9794
10588
  ])
9795
10589
  );
9796
10590
  });
9797
- const filteredSetup = pruneUnusedSetupDestructuring(setupStatements, swapCalls);
10591
+ const filteredSetup = pruneUnusedSetupDestructuring(setupStatements, [...propsUpdateCalls, ...swapCalls]);
9798
10592
  const method = t18.classMethod(
9799
10593
  "method",
9800
10594
  t18.identifier("__geaSwapStateChildren"),
9801
10595
  [],
9802
- t18.blockStatement([...filteredSetup, ...swapCalls])
10596
+ t18.blockStatement([...filteredSetup, ...propsUpdateCalls, ...swapCalls])
9803
10597
  );
9804
10598
  classBody2.body.push(method);
9805
10599
  }
@@ -9810,7 +10604,7 @@ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
9810
10604
  import { dirname as dirname2, resolve as resolve2 } from "path";
9811
10605
  import { createRequire as createRequire12 } from "module";
9812
10606
  var require13 = createRequire12(import.meta.url);
9813
- var traverse11 = require13("@babel/traverse").default;
10607
+ var traverse12 = require13("@babel/traverse").default;
9814
10608
  function resolveImportPath2(importer, source) {
9815
10609
  const base = resolve2(dirname2(importer), source);
9816
10610
  const candidates = [
@@ -9837,8 +10631,8 @@ function isPrivateName(name) {
9837
10631
  function extractGetterStatePaths(method) {
9838
10632
  if (!t19.isBlockStatement(method.body)) return null;
9839
10633
  const paths = /* @__PURE__ */ new Map();
9840
- const program9 = t19.program(method.body.body.map((stmt) => t19.cloneNode(stmt, true)));
9841
- traverse11(program9, {
10634
+ const program10 = t19.program(method.body.body.map((stmt) => t19.cloneNode(stmt, true)));
10635
+ traverse12(program10, {
9842
10636
  noScope: true,
9843
10637
  MemberExpression(path) {
9844
10638
  const node = path.node;
@@ -9878,7 +10672,7 @@ function analyzeStoreFile(filePath) {
9878
10672
  const parsed = parseSource(source);
9879
10673
  if (!parsed?.ast) return null;
9880
10674
  const result = /* @__PURE__ */ new Map();
9881
- traverse11(parsed.ast, {
10675
+ traverse12(parsed.ast, {
9882
10676
  ClassDeclaration(classPath) {
9883
10677
  if (!classPath.node.superClass || !t19.isIdentifier(classPath.node.superClass) || classPath.node.superClass.name !== "Store") {
9884
10678
  return;
@@ -9935,7 +10729,7 @@ function getStoreFields(filePath) {
9935
10729
  const parsed = parseSource(source);
9936
10730
  if (!parsed?.ast) return null;
9937
10731
  const fields = /* @__PURE__ */ new Set();
9938
- traverse11(parsed.ast, {
10732
+ traverse12(parsed.ast, {
9939
10733
  ClassDeclaration(classPath) {
9940
10734
  if (!classPath.node.superClass || !t19.isIdentifier(classPath.node.superClass) || classPath.node.superClass.name !== "Store") {
9941
10735
  return;
@@ -9978,7 +10772,7 @@ function analyzeStoreGetters(sourceFile, storeImports) {
9978
10772
  // src/transform-component.ts
9979
10773
  import { createRequire as createRequire13 } from "module";
9980
10774
  var require14 = createRequire13(import.meta.url);
9981
- var traverse12 = require14("@babel/traverse").default;
10775
+ var traverse13 = require14("@babel/traverse").default;
9982
10776
  function transformComponentFile(ast, imports, storeImports, className, sourceFile, originalAST, compImportsUsedAsTags, knownComponentImports = /* @__PURE__ */ new Set()) {
9983
10777
  let transformed = false;
9984
10778
  const stateRefs = collectStateReferences(originalAST, storeImports);
@@ -9999,7 +10793,7 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
9999
10793
  const compiledChildren = [];
10000
10794
  const eventIdCounter = { value: 0 };
10001
10795
  const preTransformAnalysis = /* @__PURE__ */ new Map();
10002
- traverse12(ast, {
10796
+ traverse13(ast, {
10003
10797
  ClassMethod(path) {
10004
10798
  if (!t20.isIdentifier(path.node.key) || path.node.key.name !== "template") return;
10005
10799
  const ownerClass = path.findParent((p) => t20.isClassDeclaration(p.node));
@@ -10063,7 +10857,8 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
10063
10857
  elementPathToBindingId: analysis.elementPathToBindingId,
10064
10858
  templateSetupContext: {
10065
10859
  params: path.node.params,
10066
- statements: returnIndex >= 0 ? body.slice(0, returnIndex) : []
10860
+ statements: returnIndex >= 0 ? body.slice(0, returnIndex) : [],
10861
+ earlyReturnBarrierIndex: analysis.earlyReturnBarrierIndex
10067
10862
  },
10068
10863
  sourceFile,
10069
10864
  isRoot: true,
@@ -10279,7 +11074,7 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
10279
11074
  }
10280
11075
  function transformNonComponentJSX(ast, imports) {
10281
11076
  let transformed = false;
10282
- traverse12(ast, {
11077
+ traverse13(ast, {
10283
11078
  ClassMethod(path) {
10284
11079
  if (!t20.isIdentifier(path.node.key) || path.node.key.name !== "template") return;
10285
11080
  const body = path.node.body.body;
@@ -10375,7 +11170,7 @@ function addJoinToMapCallsInTemplates(ast) {
10375
11170
  function ensureComponentImport(ast, imports) {
10376
11171
  if (imports.has("Component")) return;
10377
11172
  let geaImportPath = null;
10378
- traverse12(ast, {
11173
+ traverse13(ast, {
10379
11174
  ImportDeclaration(path) {
10380
11175
  if (path.node.source.value === "@geajs/core") {
10381
11176
  geaImportPath = path;
@@ -10399,11 +11194,11 @@ function ensureComponentImport(ast, imports) {
10399
11194
  imports.set("Component", "@geajs/core");
10400
11195
  }
10401
11196
  function transformRemainingJSX(ast, imports) {
10402
- traverse12(ast, {
11197
+ traverse13(ast, {
10403
11198
  noScope: true,
10404
11199
  JSXElement(path) {
10405
- const classMethod7 = path.findParent((p) => t20.isClassMethod(p.node));
10406
- if (classMethod7 && t20.isClassMethod(classMethod7.node) && t20.isIdentifier(classMethod7.node.key) && classMethod7.node.key.name === "template")
11200
+ const classMethod8 = path.findParent((p) => t20.isClassMethod(p.node));
11201
+ if (classMethod8 && t20.isClassMethod(classMethod8.node) && t20.isIdentifier(classMethod8.node.key) && classMethod8.node.key.name === "template")
10407
11202
  return;
10408
11203
  try {
10409
11204
  path.replaceWith(transformJSXToTemplate(path.node, { imports }));
@@ -10412,8 +11207,8 @@ function transformRemainingJSX(ast, imports) {
10412
11207
  }
10413
11208
  },
10414
11209
  JSXFragment(path) {
10415
- const classMethod7 = path.findParent((p) => t20.isClassMethod(p.node));
10416
- if (classMethod7 && t20.isClassMethod(classMethod7.node) && t20.isIdentifier(classMethod7.node.key) && classMethod7.node.key.name === "template")
11210
+ const classMethod8 = path.findParent((p) => t20.isClassMethod(p.node));
11211
+ if (classMethod8 && t20.isClassMethod(classMethod8.node) && t20.isIdentifier(classMethod8.node.key) && classMethod8.node.key.name === "template")
10417
11212
  return;
10418
11213
  try {
10419
11214
  path.replaceWith(transformJSXFragmentToTemplate(path.node, { imports }));
@@ -10428,13 +11223,13 @@ function transformRemainingJSX(ast, imports) {
10428
11223
  import * as t21 from "@babel/types";
10429
11224
  import { createRequire as createRequire14 } from "module";
10430
11225
  var require15 = createRequire14(import.meta.url);
10431
- var traverse13 = require15("@babel/traverse").default;
11226
+ var traverse14 = require15("@babel/traverse").default;
10432
11227
  function convertFunctionalToClass(ast, info, imports) {
10433
11228
  let params = [t21.identifier("props")];
10434
11229
  let templateBody = [];
10435
11230
  let removeVarDeclPath = null;
10436
11231
  let exportPath = null;
10437
- traverse13(ast, {
11232
+ traverse14(ast, {
10438
11233
  ExportDefaultDeclaration(path) {
10439
11234
  exportPath = path;
10440
11235
  const decl = path.node.declaration;
@@ -10490,16 +11285,16 @@ function convertFunctionalToClass(ast, info, imports) {
10490
11285
  if (removeVarDeclPath) {
10491
11286
  removeVarDeclPath.remove();
10492
11287
  }
10493
- const program9 = ast.program;
10494
- const idx = program9.body.indexOf(exportPath.node);
11288
+ const program10 = ast.program;
11289
+ const idx = program10.body.indexOf(exportPath.node);
10495
11290
  if (idx >= 0) {
10496
- program9.body[idx] = t21.exportDefaultDeclaration(classDecl);
11291
+ program10.body[idx] = t21.exportDefaultDeclaration(classDecl);
10497
11292
  }
10498
11293
  }
10499
11294
  function ensureComponentImport2(ast, imports) {
10500
11295
  if (imports.get("Component")) return;
10501
11296
  let geaImportPath = null;
10502
- traverse13(ast, {
11297
+ traverse14(ast, {
10503
11298
  ImportDeclaration(path) {
10504
11299
  if (path.node.source.value === "@geajs/core") {
10505
11300
  geaImportPath = path;
@@ -10526,8 +11321,8 @@ import { dirname as dirname3, relative, resolve as resolve3 } from "path";
10526
11321
  import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync } from "fs";
10527
11322
  import { fileURLToPath } from "url";
10528
11323
  var pluginDir = dirname3(fileURLToPath(import.meta.url));
10529
- var traverse14 = typeof babelTraverse.default === "function" ? babelTraverse.default : babelTraverse;
10530
- var generate2 = typeof babelGenerator.default === "function" ? babelGenerator.default : babelGenerator;
11324
+ var traverse15 = typeof babelTraverse2.default === "function" ? babelTraverse2.default : babelTraverse2;
11325
+ var generate3 = typeof babelGenerator2.default === "function" ? babelGenerator2.default : babelGenerator2;
10531
11326
  var RECONCILE_ID = "virtual:gea-reconcile";
10532
11327
  var RESOLVED_RECONCILE_ID = "\0" + RECONCILE_ID;
10533
11328
  var HMR_RUNTIME_ID = "virtual:gea-hmr";
@@ -10865,7 +11660,7 @@ function geaPlugin() {
10865
11660
  convertFunctionalToClass(ast, functionalComponentInfo, imports);
10866
11661
  componentClassName = functionalComponentInfo.name;
10867
11662
  componentClassNames = [functionalComponentInfo.name];
10868
- const freshCode = generate2(ast, { retainLines: true }).code;
11663
+ const freshCode = generate3(ast, { retainLines: true }).code;
10869
11664
  const freshParsed = parseSource(freshCode);
10870
11665
  if (freshParsed) {
10871
11666
  ast = freshParsed.ast;
@@ -10887,7 +11682,7 @@ function geaPlugin() {
10887
11682
  const storeImports = /* @__PURE__ */ new Map();
10888
11683
  const knownComponentImports = /* @__PURE__ */ new Set();
10889
11684
  const namedImportSources = /* @__PURE__ */ new Map();
10890
- traverse14(ast, {
11685
+ traverse15(ast, {
10891
11686
  ExportDefaultDeclaration() {
10892
11687
  isDefaultExport = true;
10893
11688
  },
@@ -10910,7 +11705,8 @@ function geaPlugin() {
10910
11705
  storeImports.set(spec.local.name, source);
10911
11706
  }
10912
11707
  const importedName = spec.imported?.name ?? spec.local.name;
10913
- if (source === "@geajs/core" && isComponentTag(importedName)) {
11708
+ const geaCoreBaseClasses = ["Component", "Store"];
11709
+ if (source === "@geajs/core" && isComponentTag(importedName) && !geaCoreBaseClasses.includes(importedName)) {
10914
11710
  knownComponentImports.add(spec.local.name);
10915
11711
  }
10916
11712
  }
@@ -10957,7 +11753,7 @@ function geaPlugin() {
10957
11753
  if (hmrAdded) transformed = true;
10958
11754
  }
10959
11755
  if (!transformed) return null;
10960
- const output = generate2(ast, { sourceMaps: true, sourceFileName: cleanId }, code);
11756
+ const output = generate3(ast, { sourceMaps: true, sourceFileName: cleanId }, code);
10961
11757
  return { code: output.code, map: output.map };
10962
11758
  } catch (error) {
10963
11759
  if (error?.__geaCompileError) {