@geajs/vite-plugin 1.0.5 → 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.
- package/dist/index.js +1067 -548
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
|
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 =
|
|
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
|
-
|
|
252
|
+
program10.body.reduce((idx, node, i) => t2.isImportDeclaration(node) ? i + 1 : idx, 0)
|
|
251
253
|
);
|
|
252
|
-
|
|
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 =
|
|
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
|
-
|
|
265
|
+
program10.body.reduce((idx, node, i) => t2.isImportDeclaration(node) ? i + 1 : idx, 0)
|
|
264
266
|
);
|
|
265
|
-
|
|
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"));
|
|
@@ -874,7 +1288,8 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
874
1288
|
const rewriteNode2 = (node) => {
|
|
875
1289
|
if (!node || typeof node !== "object") return;
|
|
876
1290
|
for (const key of Object.keys(node)) {
|
|
877
|
-
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments")
|
|
1291
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments")
|
|
1292
|
+
continue;
|
|
878
1293
|
const child = node[key];
|
|
879
1294
|
if (Array.isArray(child)) {
|
|
880
1295
|
for (let i = 0; i < child.length; i++) {
|
|
@@ -882,7 +1297,11 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
882
1297
|
if (t4.isIdentifier(child[i]) && indexMap.has(child[i].name)) {
|
|
883
1298
|
if (t4.isMemberExpression(node) && key === "property" && !node.computed) continue;
|
|
884
1299
|
if (t4.isObjectProperty(node) && key === "key") continue;
|
|
885
|
-
child[i] = t4.memberExpression(
|
|
1300
|
+
child[i] = t4.memberExpression(
|
|
1301
|
+
t4.identifier(itemName),
|
|
1302
|
+
t4.numericLiteral(indexMap.get(child[i].name)),
|
|
1303
|
+
true
|
|
1304
|
+
);
|
|
886
1305
|
} else {
|
|
887
1306
|
rewriteNode2(child[i]);
|
|
888
1307
|
}
|
|
@@ -892,7 +1311,11 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
892
1311
|
if (t4.isIdentifier(child) && indexMap.has(child.name)) {
|
|
893
1312
|
if (t4.isMemberExpression(node) && key === "property" && !node.computed) continue;
|
|
894
1313
|
if (t4.isObjectProperty(node) && key === "key") continue;
|
|
895
|
-
node[key] = t4.memberExpression(
|
|
1314
|
+
node[key] = t4.memberExpression(
|
|
1315
|
+
t4.identifier(itemName),
|
|
1316
|
+
t4.numericLiteral(indexMap.get(child.name)),
|
|
1317
|
+
true
|
|
1318
|
+
);
|
|
896
1319
|
} else {
|
|
897
1320
|
rewriteNode2(child);
|
|
898
1321
|
}
|
|
@@ -915,7 +1338,8 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
915
1338
|
const rewriteNode = (node) => {
|
|
916
1339
|
if (!node || typeof node !== "object") return;
|
|
917
1340
|
for (const key of Object.keys(node)) {
|
|
918
|
-
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments")
|
|
1341
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments")
|
|
1342
|
+
continue;
|
|
919
1343
|
const child = node[key];
|
|
920
1344
|
if (Array.isArray(child)) {
|
|
921
1345
|
for (let i = 0; i < child.length; i++) {
|
|
@@ -1021,7 +1445,7 @@ function detectContainerSelector(node, tagName) {
|
|
|
1021
1445
|
// src/analyze-map.ts
|
|
1022
1446
|
import { createRequire as createRequire3 } from "module";
|
|
1023
1447
|
var require4 = createRequire3(import.meta.url);
|
|
1024
|
-
var
|
|
1448
|
+
var traverse3 = require4("@babel/traverse").default;
|
|
1025
1449
|
function analyzeJSXInMap(node, arrayPath, itemVar, itemBindings, relationalBindings, conditionalBindings, elementPath, isImportedState, itemIdProperty, stateRefs, childIndices = [], storeVar) {
|
|
1026
1450
|
const context = { inMap: true, mapItemVar: itemVar };
|
|
1027
1451
|
node.openingElement.attributes.forEach((attr) => {
|
|
@@ -1224,8 +1648,8 @@ function analyzeItemTemplateLiteral(expr, arrayPath, itemVar, itemBindings, rela
|
|
|
1224
1648
|
function collectConditionalBindings(expr, type, attributeName, conditionalBindings, arrayPath, itemVar, elementPath, childPath, stateRefs, storeVar) {
|
|
1225
1649
|
const dependencies = /* @__PURE__ */ new Map();
|
|
1226
1650
|
const requiresRerender = conditionalExpressionRequiresRerender(expr);
|
|
1227
|
-
const
|
|
1228
|
-
|
|
1651
|
+
const program10 = t5.program([t5.expressionStatement(t5.cloneNode(expr, true))]);
|
|
1652
|
+
traverse3(program10, {
|
|
1229
1653
|
noScope: true,
|
|
1230
1654
|
MemberExpression(path) {
|
|
1231
1655
|
const parent = path.parentPath;
|
|
@@ -1268,8 +1692,8 @@ function collectConditionalBindings(expr, type, attributeName, conditionalBindin
|
|
|
1268
1692
|
}
|
|
1269
1693
|
function conditionalExpressionRequiresRerender(expr) {
|
|
1270
1694
|
let needsRerender = false;
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1695
|
+
const program10 = t5.program([t5.expressionStatement(t5.cloneNode(expr, true))]);
|
|
1696
|
+
traverse3(program10, {
|
|
1273
1697
|
noScope: true,
|
|
1274
1698
|
JSXElement(path) {
|
|
1275
1699
|
needsRerender = true;
|
|
@@ -1364,7 +1788,7 @@ function extractClassName(node) {
|
|
|
1364
1788
|
import * as t6 from "@babel/types";
|
|
1365
1789
|
import { createRequire as createRequire4 } from "module";
|
|
1366
1790
|
var require5 = createRequire4(import.meta.url);
|
|
1367
|
-
var
|
|
1791
|
+
var traverse4 = require5("@babel/traverse").default;
|
|
1368
1792
|
function buildComponentPropsExpression(jsxElement, imports, componentInstances, eventHandlers, stateRefs, templateSetupContext, transformExpression, transformFragment) {
|
|
1369
1793
|
const props = [];
|
|
1370
1794
|
const dependencies = /* @__PURE__ */ new Map();
|
|
@@ -1377,7 +1801,9 @@ function buildComponentPropsExpression(jsxElement, imports, componentInstances,
|
|
|
1377
1801
|
else if (t6.isJSXExpressionContainer(attr.value) && !t6.isJSXEmptyExpression(attr.value.expression)) {
|
|
1378
1802
|
const expr = attr.value.expression;
|
|
1379
1803
|
propValue = transformExpression(expr);
|
|
1380
|
-
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(
|
|
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)) {
|
|
1381
1807
|
const argsId = t6.identifier("args");
|
|
1382
1808
|
propValue = t6.arrowFunctionExpression(
|
|
1383
1809
|
[t6.restElement(argsId)],
|
|
@@ -1449,11 +1875,11 @@ function collectExpressionDependenciesInto(expr, stateRefs, dependencies, setupS
|
|
|
1449
1875
|
});
|
|
1450
1876
|
});
|
|
1451
1877
|
});
|
|
1452
|
-
const
|
|
1878
|
+
const program10 = t6.program([
|
|
1453
1879
|
...setupStatements.map((statement) => t6.cloneNode(statement, true)),
|
|
1454
1880
|
t6.expressionStatement(t6.cloneNode(expr, true))
|
|
1455
1881
|
]);
|
|
1456
|
-
|
|
1882
|
+
traverse4(program10, {
|
|
1457
1883
|
noScope: true,
|
|
1458
1884
|
MemberExpression(path) {
|
|
1459
1885
|
const parent = path.parentPath;
|
|
@@ -1533,6 +1959,28 @@ function collectTemplateSetupStatements(expr, templateSetupContext) {
|
|
|
1533
1959
|
};
|
|
1534
1960
|
collectReferencedIdentifiers(expr).forEach(includeName);
|
|
1535
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
|
+
}
|
|
1536
1984
|
for (const entry of ordered) {
|
|
1537
1985
|
if (entry.index !== -1) continue;
|
|
1538
1986
|
if (!t6.isVariableDeclaration(entry.statement)) continue;
|
|
@@ -1578,10 +2026,10 @@ function collectPatternIdentifiers(pattern) {
|
|
|
1578
2026
|
}
|
|
1579
2027
|
function collectReferencedIdentifiers(node) {
|
|
1580
2028
|
const names = /* @__PURE__ */ new Set();
|
|
1581
|
-
const
|
|
2029
|
+
const program10 = t6.program([
|
|
1582
2030
|
t6.isStatement(node) ? t6.cloneNode(node, true) : t6.expressionStatement(t6.cloneNode(node, true))
|
|
1583
2031
|
]);
|
|
1584
|
-
|
|
2032
|
+
traverse4(program10, {
|
|
1585
2033
|
noScope: true,
|
|
1586
2034
|
Identifier(path) {
|
|
1587
2035
|
if (!path.isReferencedIdentifier()) return;
|
|
@@ -1594,7 +2042,7 @@ function collectReferencedIdentifiers(node) {
|
|
|
1594
2042
|
// src/analyze.ts
|
|
1595
2043
|
import { createRequire as createRequire5 } from "module";
|
|
1596
2044
|
var require6 = createRequire5(import.meta.url);
|
|
1597
|
-
var
|
|
2045
|
+
var traverse5 = require6("@babel/traverse").default;
|
|
1598
2046
|
function buildTextTemplateExpressionFromParts(textTemplate, textExpressions) {
|
|
1599
2047
|
const templateParts = textTemplate.split(/\$\{(\d+)\}/g);
|
|
1600
2048
|
const quasis = [];
|
|
@@ -1687,16 +2135,8 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
1687
2135
|
conditionalSlotScopedStoreKeys: /* @__PURE__ */ new Set(),
|
|
1688
2136
|
conditionalSlotNodeMap: /* @__PURE__ */ new Map()
|
|
1689
2137
|
};
|
|
1690
|
-
let earlyReturnGuard;
|
|
1691
2138
|
const bodyStmts = templateMethod.body.body;
|
|
1692
|
-
|
|
1693
|
-
const s = bodyStmts[i];
|
|
1694
|
-
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])) {
|
|
1695
|
-
earlyReturnGuard = t7.cloneNode(s.test, true);
|
|
1696
|
-
break;
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
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);
|
|
1700
2140
|
if (!returnStmt?.argument)
|
|
1701
2141
|
return {
|
|
1702
2142
|
bindings,
|
|
@@ -1712,7 +2152,25 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
1712
2152
|
conditionalSlotScopedStoreKeys: /* @__PURE__ */ new Set(),
|
|
1713
2153
|
conditionalSlotNodeMap: /* @__PURE__ */ new Map()
|
|
1714
2154
|
};
|
|
1715
|
-
const returnIndex =
|
|
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
|
+
}
|
|
1716
2174
|
const templateSetupContext = {
|
|
1717
2175
|
params: templateMethod.params.filter(
|
|
1718
2176
|
(param) => !t7.isTSParameterProperty(param)
|
|
@@ -1837,7 +2295,8 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
1837
2295
|
elementPathToBindingId,
|
|
1838
2296
|
conditionalSlotScopedStoreKeys,
|
|
1839
2297
|
conditionalSlotNodeMap,
|
|
1840
|
-
earlyReturnGuard
|
|
2298
|
+
earlyReturnGuard,
|
|
2299
|
+
earlyReturnBarrierIndex
|
|
1841
2300
|
};
|
|
1842
2301
|
}
|
|
1843
2302
|
function computeConditionalSlotScopedStoreKeys(conditionalSlots, stateProps, stateRefs, templateSetupContext) {
|
|
@@ -2158,8 +2617,8 @@ function isMapCall(expr) {
|
|
|
2158
2617
|
function collectNestedMapCalls(expr) {
|
|
2159
2618
|
if (t7.isJSXEmptyExpression(expr)) return [];
|
|
2160
2619
|
const maps = [];
|
|
2161
|
-
const
|
|
2162
|
-
|
|
2620
|
+
const program10 = t7.program([t7.expressionStatement(t7.cloneNode(expr, true))]);
|
|
2621
|
+
traverse5(program10, {
|
|
2163
2622
|
noScope: true,
|
|
2164
2623
|
CallExpression(path) {
|
|
2165
2624
|
if (isMapCall(path.node)) {
|
|
@@ -2658,12 +3117,12 @@ function buildDerivedPropBindings(expr, type, attributeName, elementPath, propsP
|
|
|
2658
3117
|
}
|
|
2659
3118
|
function collectDependentPropNames(expr, setupStatements, propsParamName, destructuredPropNames, classBody2) {
|
|
2660
3119
|
const names = /* @__PURE__ */ new Set();
|
|
2661
|
-
const
|
|
3120
|
+
const program10 = t7.program([
|
|
2662
3121
|
...setupStatements.map((statement) => t7.cloneNode(statement, true)),
|
|
2663
3122
|
t7.expressionStatement(t7.cloneNode(expr, true))
|
|
2664
3123
|
]);
|
|
2665
3124
|
const getterNamesToExpand = /* @__PURE__ */ new Set();
|
|
2666
|
-
|
|
3125
|
+
traverse5(program10, {
|
|
2667
3126
|
noScope: true,
|
|
2668
3127
|
Identifier(path) {
|
|
2669
3128
|
if (!path.isReferencedIdentifier()) return;
|
|
@@ -2682,7 +3141,7 @@ function collectDependentPropNames(expr, setupStatements, propsParamName, destru
|
|
|
2682
3141
|
if (!t7.isClassMethod(member) || member.kind !== "get" || !t7.isIdentifier(member.key) || !getterNamesToExpand.has(member.key.name))
|
|
2683
3142
|
continue;
|
|
2684
3143
|
const getterProgram = t7.program(member.body.body.map((s) => t7.cloneNode(s, true)));
|
|
2685
|
-
|
|
3144
|
+
traverse5(getterProgram, {
|
|
2686
3145
|
noScope: true,
|
|
2687
3146
|
Identifier(path) {
|
|
2688
3147
|
if (!path.isReferencedIdentifier()) return;
|
|
@@ -2706,7 +3165,7 @@ function collectDependentPropNames(expr, setupStatements, propsParamName, destru
|
|
|
2706
3165
|
function collectAllStateAccesses(templateMethod, stateRefs, stateProps) {
|
|
2707
3166
|
const params = templateMethod.params.filter((param) => !t7.isTSParameterProperty(param));
|
|
2708
3167
|
const prog = t7.program([t7.expressionStatement(t7.arrowFunctionExpression(params, templateMethod.body))]);
|
|
2709
|
-
|
|
3168
|
+
traverse5(prog, {
|
|
2710
3169
|
noScope: true,
|
|
2711
3170
|
Identifier(path) {
|
|
2712
3171
|
if (!stateRefs.has(path.node.name)) return;
|
|
@@ -2766,7 +3225,7 @@ function collectAllStateAccesses(templateMethod, stateRefs, stateProps) {
|
|
|
2766
3225
|
function collectItemTemplateStoreDependencies(itemTemplate, itemVar, stateRefs, dependencies) {
|
|
2767
3226
|
if (!itemTemplate) return;
|
|
2768
3227
|
const prog = t7.program([t7.expressionStatement(t7.cloneNode(itemTemplate, true))]);
|
|
2769
|
-
|
|
3228
|
+
traverse5(prog, {
|
|
2770
3229
|
noScope: true,
|
|
2771
3230
|
MemberExpression(path) {
|
|
2772
3231
|
let root = path.node;
|
|
@@ -2926,7 +3385,8 @@ function extractSingleCallExpression(expr) {
|
|
|
2926
3385
|
}
|
|
2927
3386
|
function getHoistableRootEvent(attrName, expr, elementPath, context, selector) {
|
|
2928
3387
|
if (elementPath.length !== 0 || !selector) return null;
|
|
2929
|
-
if (attrName.startsWith("data-") || attrName === "class" || attrName === "className" || attrName === "style" || attrName === "id")
|
|
3388
|
+
if (attrName.startsWith("data-") || attrName === "class" || attrName === "className" || attrName === "style" || attrName === "id")
|
|
3389
|
+
return null;
|
|
2930
3390
|
const eventType = toGeaEventType(attrName);
|
|
2931
3391
|
const directProp = resolvePropCallbackName(expr, context);
|
|
2932
3392
|
if (directProp) return { eventType, propName: directProp, selector };
|
|
@@ -3215,12 +3675,7 @@ function buildClassObjectExpression(expr) {
|
|
|
3215
3675
|
),
|
|
3216
3676
|
t9.identifier("map")
|
|
3217
3677
|
),
|
|
3218
|
-
[
|
|
3219
|
-
t9.arrowFunctionExpression(
|
|
3220
|
-
[t9.arrayPattern([t9.identifier("__k")])],
|
|
3221
|
-
t9.identifier("__k")
|
|
3222
|
-
)
|
|
3223
|
-
]
|
|
3678
|
+
[t9.arrowFunctionExpression([t9.arrayPattern([t9.identifier("__k")])], t9.identifier("__k"))]
|
|
3224
3679
|
),
|
|
3225
3680
|
t9.identifier("join")
|
|
3226
3681
|
),
|
|
@@ -3257,10 +3712,10 @@ function buildStyleObjectExpression(expr) {
|
|
|
3257
3712
|
t9.templateElement({ raw: "", cooked: "" }, true)
|
|
3258
3713
|
],
|
|
3259
3714
|
[
|
|
3260
|
-
t9.callExpression(
|
|
3261
|
-
t9.
|
|
3262
|
-
|
|
3263
|
-
),
|
|
3715
|
+
t9.callExpression(t9.memberExpression(t9.identifier("__k"), t9.identifier("replace")), [
|
|
3716
|
+
t9.regExpLiteral("[A-Z]", "g"),
|
|
3717
|
+
t9.stringLiteral("-$&")
|
|
3718
|
+
]),
|
|
3264
3719
|
t9.conditionalExpression(
|
|
3265
3720
|
t9.logicalExpression(
|
|
3266
3721
|
"&&",
|
|
@@ -3332,6 +3787,7 @@ function canBeBoolean(expr) {
|
|
|
3332
3787
|
}
|
|
3333
3788
|
function isAlwaysTruthy(expr) {
|
|
3334
3789
|
if (t9.isStringLiteral(expr) || t9.isNumericLiteral(expr) || t9.isTemplateLiteral(expr)) return true;
|
|
3790
|
+
if (t9.isObjectExpression(expr) || t9.isArrayExpression(expr)) return true;
|
|
3335
3791
|
if (t9.isConditionalExpression(expr)) return isAlwaysTruthy(expr.consequent) && isAlwaysTruthy(expr.alternate);
|
|
3336
3792
|
return false;
|
|
3337
3793
|
}
|
|
@@ -3581,10 +4037,7 @@ function replaceJSXInExpression(node, mapJSXNodes, ctx) {
|
|
|
3581
4037
|
);
|
|
3582
4038
|
}
|
|
3583
4039
|
const newBody = replaceJSXInExpression(callee.body, mapJSXNodes, ctx);
|
|
3584
|
-
return t9.callExpression(
|
|
3585
|
-
t9.arrowFunctionExpression(callee.params, newBody, callee.async),
|
|
3586
|
-
node.arguments
|
|
3587
|
-
);
|
|
4040
|
+
return t9.callExpression(t9.arrowFunctionExpression(callee.params, newBody, callee.async), node.arguments);
|
|
3588
4041
|
}
|
|
3589
4042
|
return node;
|
|
3590
4043
|
}
|
|
@@ -3962,21 +4415,27 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
3962
4415
|
[t9.stringLiteral("; ")]
|
|
3963
4416
|
);
|
|
3964
4417
|
const skipCondition2 = buildAttrSkipCondition(styleExpr, rawExpr);
|
|
3965
|
-
|
|
3966
|
-
type: "
|
|
3967
|
-
value:
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
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
|
+
)
|
|
3976
4435
|
)
|
|
3977
|
-
)
|
|
3978
|
-
|
|
3979
|
-
|
|
4436
|
+
});
|
|
4437
|
+
html = "";
|
|
4438
|
+
}
|
|
3980
4439
|
return;
|
|
3981
4440
|
}
|
|
3982
4441
|
parts.push({ type: "string", value: html });
|
|
@@ -4209,16 +4668,7 @@ function ensureMapItemHelper(classBody2, ctx, helperName) {
|
|
|
4209
4668
|
if (ctx.arrayPathParts.length === 0) return base;
|
|
4210
4669
|
const [, ...rest] = ctx.arrayPathParts;
|
|
4211
4670
|
const isIndex = /^\d+$/.test(first);
|
|
4212
|
-
const optionalFirst = ctx.isImportedState ? t10.memberExpression(
|
|
4213
|
-
base,
|
|
4214
|
-
isIndex ? t10.numericLiteral(Number(first)) : t10.identifier(first),
|
|
4215
|
-
isIndex
|
|
4216
|
-
) : t10.optionalMemberExpression(
|
|
4217
|
-
base,
|
|
4218
|
-
isIndex ? t10.numericLiteral(Number(first)) : t10.identifier(first),
|
|
4219
|
-
isIndex,
|
|
4220
|
-
true
|
|
4221
|
-
);
|
|
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);
|
|
4222
4672
|
return rest.length > 0 ? buildMemberChainFromParts(optionalFirst, rest) : optionalFirst;
|
|
4223
4673
|
})();
|
|
4224
4674
|
const findPredicate = ctx.itemIdProperty && ctx.itemIdProperty !== ITEM_IS_KEY ? t10.arrowFunctionExpression(
|
|
@@ -4239,7 +4689,11 @@ function ensureMapItemHelper(classBody2, ctx, helperName) {
|
|
|
4239
4689
|
)
|
|
4240
4690
|
) : t10.arrowFunctionExpression(
|
|
4241
4691
|
[t10.identifier("_"), t10.identifier("__i")],
|
|
4242
|
-
t10.binaryExpression(
|
|
4692
|
+
t10.binaryExpression(
|
|
4693
|
+
"===",
|
|
4694
|
+
t10.callExpression(t10.identifier("String"), [t10.identifier("__i")]),
|
|
4695
|
+
t10.identifier("__itemId")
|
|
4696
|
+
)
|
|
4243
4697
|
);
|
|
4244
4698
|
const method = jsMethod`${id3(helperName)}(e) {
|
|
4245
4699
|
const __el = e.target.closest('[data-gea-item-id]');
|
|
@@ -4571,7 +5025,7 @@ function childHasNoProps(child) {
|
|
|
4571
5025
|
return t11.isObjectExpression(child.propsExpression) && child.propsExpression.properties.length === 0;
|
|
4572
5026
|
}
|
|
4573
5027
|
var require7 = createRequire6(import.meta.url);
|
|
4574
|
-
var
|
|
5028
|
+
var traverse6 = require7("@babel/traverse").default;
|
|
4575
5029
|
function getDirectPropMappings(child, templatePropNames) {
|
|
4576
5030
|
if (!child.propsExpression || !t11.isObjectExpression(child.propsExpression)) return null;
|
|
4577
5031
|
const mappings = [];
|
|
@@ -4592,7 +5046,7 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
|
|
|
4592
5046
|
const instanceStatements = buildInstanceStatements(constructionOrder, directForwardingChildren);
|
|
4593
5047
|
const lazyChildren = constructionOrder.filter((child) => child.lazy);
|
|
4594
5048
|
let injected = false;
|
|
4595
|
-
|
|
5049
|
+
traverse6(ast, {
|
|
4596
5050
|
ClassDeclaration(path) {
|
|
4597
5051
|
if (!t11.isIdentifier(path.node.superClass)) return;
|
|
4598
5052
|
const existingCtor = path.node.body.body.find(
|
|
@@ -4671,7 +5125,7 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
|
|
|
4671
5125
|
});
|
|
4672
5126
|
}
|
|
4673
5127
|
function injectComponentRegistrations(ast, componentInstances) {
|
|
4674
|
-
|
|
5128
|
+
traverse6(ast, {
|
|
4675
5129
|
ClassMethod(path) {
|
|
4676
5130
|
if (!t11.isIdentifier(path.node.key) || path.node.key.name !== "template") return;
|
|
4677
5131
|
const registrations = Array.from(componentInstances.keys()).map(
|
|
@@ -4801,6 +5255,7 @@ function buildPropsBuilderMethod(child) {
|
|
|
4801
5255
|
}
|
|
4802
5256
|
|
|
4803
5257
|
// src/apply-reactivity.ts
|
|
5258
|
+
import babelGenerator from "@babel/generator";
|
|
4804
5259
|
import * as t18 from "@babel/types";
|
|
4805
5260
|
import { appendToBody as appendToBody5, id as id11, js as js7, jsBlockBody as jsBlockBody4, jsExpr as jsExpr4, jsMethod as jsMethod8 } from "eszter";
|
|
4806
5261
|
|
|
@@ -4813,7 +5268,7 @@ import * as t12 from "@babel/types";
|
|
|
4813
5268
|
import { id as id5, js as js3, jsBlockBody as jsBlockBody2, jsExpr as jsExpr2 } from "eszter";
|
|
4814
5269
|
import { createRequire as createRequire7 } from "module";
|
|
4815
5270
|
var require8 = createRequire7(import.meta.url);
|
|
4816
|
-
var
|
|
5271
|
+
var traverse7 = require8("@babel/traverse").default;
|
|
4817
5272
|
function buildPathPartsEquals(expr, parts) {
|
|
4818
5273
|
return parts.reduce(
|
|
4819
5274
|
(acc, part, index) => t12.logicalExpression(
|
|
@@ -4859,10 +5314,7 @@ function buildValueExpression(textExpr, stateRefs) {
|
|
|
4859
5314
|
}
|
|
4860
5315
|
if (textExpr.isImportedState && textExpr.storeVar) {
|
|
4861
5316
|
return buildMemberChainFromParts(
|
|
4862
|
-
t12.memberExpression(
|
|
4863
|
-
t12.identifier(textExpr.storeVar),
|
|
4864
|
-
t12.identifier("__store")
|
|
4865
|
-
),
|
|
5317
|
+
t12.memberExpression(t12.identifier(textExpr.storeVar), t12.identifier("__store")),
|
|
4866
5318
|
textExpr.pathParts
|
|
4867
5319
|
);
|
|
4868
5320
|
}
|
|
@@ -4870,7 +5322,7 @@ function buildValueExpression(textExpr, stateRefs) {
|
|
|
4870
5322
|
}
|
|
4871
5323
|
function rewriteStateRefs(expr, stateRefs) {
|
|
4872
5324
|
const prog = t12.program([t12.expressionStatement(expr)]);
|
|
4873
|
-
|
|
5325
|
+
traverse7(prog, {
|
|
4874
5326
|
noScope: true,
|
|
4875
5327
|
Identifier(path) {
|
|
4876
5328
|
if (path.parentPath && t12.isMemberExpression(path.parentPath.node) && path.parentPath.node.property === path.node)
|
|
@@ -4888,17 +5340,10 @@ function rewriteStateRefs(expr, stateRefs) {
|
|
|
4888
5340
|
);
|
|
4889
5341
|
path.skip();
|
|
4890
5342
|
} else if (ref.kind === "local-destructured" && ref.propName) {
|
|
4891
|
-
path.replaceWith(
|
|
4892
|
-
t12.memberExpression(t12.thisExpression(), t12.identifier(ref.propName))
|
|
4893
|
-
);
|
|
5343
|
+
path.replaceWith(t12.memberExpression(t12.thisExpression(), t12.identifier(ref.propName)));
|
|
4894
5344
|
path.skip();
|
|
4895
5345
|
} else {
|
|
4896
|
-
path.replaceWith(
|
|
4897
|
-
t12.memberExpression(
|
|
4898
|
-
t12.identifier(path.node.name),
|
|
4899
|
-
t12.identifier("__store")
|
|
4900
|
-
)
|
|
4901
|
-
);
|
|
5346
|
+
path.replaceWith(t12.memberExpression(t12.identifier(path.node.name), t12.identifier("__store")));
|
|
4902
5347
|
path.skip();
|
|
4903
5348
|
}
|
|
4904
5349
|
}
|
|
@@ -5080,7 +5525,7 @@ import * as t14 from "@babel/types";
|
|
|
5080
5525
|
import { appendToBody as appendToBody2, id as id7, js as js4, jsMethod as jsMethod4 } from "eszter";
|
|
5081
5526
|
import { createRequire as createRequire8 } from "module";
|
|
5082
5527
|
var require9 = createRequire8(import.meta.url);
|
|
5083
|
-
var
|
|
5528
|
+
var traverse8 = require9("@babel/traverse").default;
|
|
5084
5529
|
var EVENT_NAMES = /* @__PURE__ */ new Set([
|
|
5085
5530
|
"click",
|
|
5086
5531
|
"dblclick",
|
|
@@ -5113,23 +5558,50 @@ var EVENT_NAMES = /* @__PURE__ */ new Set([
|
|
|
5113
5558
|
"dragleave",
|
|
5114
5559
|
"drop"
|
|
5115
5560
|
]);
|
|
5116
|
-
function
|
|
5117
|
-
const
|
|
5118
|
-
const
|
|
5119
|
-
|
|
5561
|
+
function collectItemTemplatePropTree(template, itemVar) {
|
|
5562
|
+
const tree = {};
|
|
5563
|
+
const program10 = t14.program([t14.expressionStatement(t14.cloneNode(template, true))]);
|
|
5564
|
+
traverse8(program10, {
|
|
5120
5565
|
noScope: true,
|
|
5121
5566
|
MemberExpression(path) {
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
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
|
+
}
|
|
5125
5584
|
}
|
|
5126
5585
|
});
|
|
5127
|
-
return
|
|
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);
|
|
5128
5600
|
}
|
|
5129
5601
|
function collectPatchEntries(arrayMap) {
|
|
5130
5602
|
const cloned = t14.cloneNode(arrayMap.itemTemplate, true);
|
|
5131
5603
|
const tempFile = t14.file(t14.program([t14.expressionStatement(cloned)]));
|
|
5132
|
-
|
|
5604
|
+
traverse8(tempFile, {
|
|
5133
5605
|
Identifier(path) {
|
|
5134
5606
|
if (path.node.name === arrayMap.itemVariable) path.node.name = "item";
|
|
5135
5607
|
else if (arrayMap.indexVariable && path.node.name === arrayMap.indexVariable) path.node.name = "__idx";
|
|
@@ -5143,6 +5615,9 @@ function collectPatchEntries(arrayMap) {
|
|
|
5143
5615
|
const rootIsComponent = isComponentTag(rootTagName);
|
|
5144
5616
|
walkJSXForPatch(modified, [], entries, rootIsComponent);
|
|
5145
5617
|
}
|
|
5618
|
+
for (const ent of entries) {
|
|
5619
|
+
ent.expression = optionalizeMemberChainsAfterComputedItemKey(ent.expression, "item");
|
|
5620
|
+
}
|
|
5146
5621
|
return { entries, requiresRerender };
|
|
5147
5622
|
}
|
|
5148
5623
|
function walkJSXForPatch(node, path, entries, rootIsComponent = false) {
|
|
@@ -5238,8 +5713,8 @@ function hoistStoreReads(entries, storeVar) {
|
|
|
5238
5713
|
let counter = 0;
|
|
5239
5714
|
function replaceStoreReads(expr) {
|
|
5240
5715
|
const cloned = t14.cloneNode(expr, true);
|
|
5241
|
-
const
|
|
5242
|
-
|
|
5716
|
+
const program10 = t14.program([t14.expressionStatement(cloned)]);
|
|
5717
|
+
traverse8(program10, {
|
|
5243
5718
|
noScope: true,
|
|
5244
5719
|
MemberExpression(path) {
|
|
5245
5720
|
if (!t14.isIdentifier(path.node.object, { name: storeVar })) return;
|
|
@@ -5254,7 +5729,7 @@ function hoistStoreReads(entries, storeVar) {
|
|
|
5254
5729
|
path.replaceWith(t14.identifier(hoist.varName));
|
|
5255
5730
|
}
|
|
5256
5731
|
});
|
|
5257
|
-
return
|
|
5732
|
+
return program10.body[0].expression;
|
|
5258
5733
|
}
|
|
5259
5734
|
const patchedEntries = entries.map((entry) => ({
|
|
5260
5735
|
...entry,
|
|
@@ -5294,7 +5769,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5294
5769
|
if (setupVarNames.size > 0) {
|
|
5295
5770
|
const freeVars = /* @__PURE__ */ new Set();
|
|
5296
5771
|
for (const entry of entries) {
|
|
5297
|
-
|
|
5772
|
+
traverse8(t14.expressionStatement(t14.cloneNode(entry.expression, true)), {
|
|
5298
5773
|
noScope: true,
|
|
5299
5774
|
Identifier(p) {
|
|
5300
5775
|
if (t14.isMemberExpression(p.parent) && p.parent.property === p.node && !p.parent.computed) return;
|
|
@@ -5347,7 +5822,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5347
5822
|
if (!t14.isJSXExpressionContainer(attr.value) || t14.isJSXEmptyExpression(attr.value.expression)) continue;
|
|
5348
5823
|
const exprClone = t14.cloneNode(attr.value.expression, true);
|
|
5349
5824
|
const tempProg = t14.file(t14.program([t14.expressionStatement(exprClone)]));
|
|
5350
|
-
|
|
5825
|
+
traverse8(tempProg, {
|
|
5351
5826
|
Identifier(path) {
|
|
5352
5827
|
if (path.node.name === arrayMap.itemVariable) path.node.name = "item";
|
|
5353
5828
|
else if (arrayMap.indexVariable && path.node.name === arrayMap.indexVariable) path.node.name = "__idx";
|
|
@@ -5366,7 +5841,8 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5366
5841
|
else if (t14.isObjectPattern(decl.id)) {
|
|
5367
5842
|
for (const prop of decl.id.properties) {
|
|
5368
5843
|
if (t14.isObjectProperty(prop) && t14.isIdentifier(prop.value)) setupVarNames.add(prop.value.name);
|
|
5369
|
-
else if (t14.isRestElement(prop) && t14.isIdentifier(prop.argument))
|
|
5844
|
+
else if (t14.isRestElement(prop) && t14.isIdentifier(prop.argument))
|
|
5845
|
+
setupVarNames.add(prop.argument.name);
|
|
5370
5846
|
}
|
|
5371
5847
|
}
|
|
5372
5848
|
}
|
|
@@ -5374,7 +5850,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5374
5850
|
}
|
|
5375
5851
|
const propsRefsFreeVars = /* @__PURE__ */ new Set();
|
|
5376
5852
|
for (const prop of propsProperties) {
|
|
5377
|
-
|
|
5853
|
+
traverse8(t14.expressionStatement(t14.cloneNode(prop.value, true)), {
|
|
5378
5854
|
noScope: true,
|
|
5379
5855
|
Identifier(p) {
|
|
5380
5856
|
if (t14.isMemberExpression(p.parent) && p.parent.property === p.node && !p.parent.computed) return;
|
|
@@ -5394,7 +5870,11 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5394
5870
|
for (const stmt of templateSetupContext.statements) {
|
|
5395
5871
|
let clonedStmt = t14.cloneNode(stmt, true);
|
|
5396
5872
|
if (propRefsNames.size > 0 || wholeParamName) {
|
|
5397
|
-
clonedStmt = replacePropRefsInExpression(
|
|
5873
|
+
clonedStmt = replacePropRefsInExpression(
|
|
5874
|
+
clonedStmt,
|
|
5875
|
+
propRefsNames,
|
|
5876
|
+
wholeParamName
|
|
5877
|
+
);
|
|
5398
5878
|
}
|
|
5399
5879
|
rerenderBody.push(clonedStmt);
|
|
5400
5880
|
}
|
|
@@ -5416,7 +5896,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5416
5896
|
}
|
|
5417
5897
|
if (entries.length === 0) return null;
|
|
5418
5898
|
const { hoists, patchedEntries } = hoistStoreReads(entries, arrayMap.storeVar);
|
|
5419
|
-
const
|
|
5899
|
+
const propTree = collectItemTemplatePropTree(arrayMap.itemTemplate, arrayMap.itemVariable);
|
|
5420
5900
|
const containerRef = t14.memberExpression(t14.thisExpression(), t14.identifier(containerProp));
|
|
5421
5901
|
const cVar = t14.identifier("__c");
|
|
5422
5902
|
const elVar = t14.identifier("el");
|
|
@@ -5424,25 +5904,16 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5424
5904
|
body.push(t14.variableDeclaration("var", [t14.variableDeclarator(cVar, containerRef)]));
|
|
5425
5905
|
const isPrimitiveKey = !itemIdProperty || itemIdProperty === ITEM_IS_KEY;
|
|
5426
5906
|
const dummyItem = isPrimitiveKey ? t14.stringLiteral("__dummy__") : (() => {
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
for (const prop of [itemIdProperty, ...itemProps]) {
|
|
5430
|
-
if (seen.has(prop)) continue;
|
|
5431
|
-
seen.add(prop);
|
|
5432
|
-
dummyProps.push(
|
|
5433
|
-
t14.objectProperty(t14.identifier(prop), prop === itemIdProperty ? t14.numericLiteral(0) : t14.stringLiteral(""))
|
|
5434
|
-
);
|
|
5435
|
-
}
|
|
5436
|
-
return t14.objectExpression(dummyProps);
|
|
5907
|
+
if (itemIdProperty && !(itemIdProperty in propTree)) propTree[itemIdProperty] = true;
|
|
5908
|
+
return buildDummyFromTree(propTree, itemIdProperty);
|
|
5437
5909
|
})();
|
|
5438
5910
|
const tplInit = [
|
|
5439
5911
|
t14.variableDeclaration("var", [
|
|
5440
5912
|
t14.variableDeclarator(
|
|
5441
5913
|
t14.identifier("__tw"),
|
|
5442
|
-
t14.callExpression(
|
|
5443
|
-
t14.
|
|
5444
|
-
|
|
5445
|
-
)
|
|
5914
|
+
t14.callExpression(t14.memberExpression(t14.identifier("document"), t14.identifier("createElement")), [
|
|
5915
|
+
t14.stringLiteral("template")
|
|
5916
|
+
])
|
|
5446
5917
|
)
|
|
5447
5918
|
]),
|
|
5448
5919
|
t14.expressionStatement(
|
|
@@ -5508,10 +5979,9 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5508
5979
|
t14.variableDeclaration("var", [
|
|
5509
5980
|
t14.variableDeclarator(
|
|
5510
5981
|
t14.identifier("__fw"),
|
|
5511
|
-
t14.callExpression(
|
|
5512
|
-
t14.
|
|
5513
|
-
|
|
5514
|
-
)
|
|
5982
|
+
t14.callExpression(t14.memberExpression(t14.identifier("document"), t14.identifier("createElement")), [
|
|
5983
|
+
t14.stringLiteral("template")
|
|
5984
|
+
])
|
|
5515
5985
|
)
|
|
5516
5986
|
]),
|
|
5517
5987
|
t14.expressionStatement(
|
|
@@ -5547,13 +6017,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5547
6017
|
const refName = childPathRefName(entry.childPath);
|
|
5548
6018
|
const navExpr = buildElementNavExpr(elVar, entry.childPath);
|
|
5549
6019
|
body.push(
|
|
5550
|
-
t14.expressionStatement(
|
|
5551
|
-
t14.assignmentExpression(
|
|
5552
|
-
"=",
|
|
5553
|
-
t14.memberExpression(elVar, t14.identifier(refName)),
|
|
5554
|
-
navExpr
|
|
5555
|
-
)
|
|
5556
|
-
)
|
|
6020
|
+
t14.expressionStatement(t14.assignmentExpression("=", t14.memberExpression(elVar, t14.identifier(refName)), navExpr))
|
|
5557
6021
|
);
|
|
5558
6022
|
refMap.set(key, t14.memberExpression(elVar, t14.identifier(refName)));
|
|
5559
6023
|
}
|
|
@@ -5600,17 +6064,26 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5600
6064
|
t14.memberExpression(
|
|
5601
6065
|
t14.callExpression(
|
|
5602
6066
|
t14.memberExpression(
|
|
5603
|
-
t14.callExpression(t14.memberExpression(t14.identifier("Object"), t14.identifier("entries")), [
|
|
6067
|
+
t14.callExpression(t14.memberExpression(t14.identifier("Object"), t14.identifier("entries")), [
|
|
6068
|
+
attrVal
|
|
6069
|
+
]),
|
|
5604
6070
|
t14.identifier("map")
|
|
5605
6071
|
),
|
|
5606
6072
|
[
|
|
5607
6073
|
t14.arrowFunctionExpression(
|
|
5608
6074
|
[t14.arrayPattern([t14.identifier("k"), t14.identifier("v")])],
|
|
5609
|
-
t14.binaryExpression(
|
|
6075
|
+
t14.binaryExpression(
|
|
5610
6076
|
"+",
|
|
5611
|
-
t14.
|
|
5612
|
-
|
|
5613
|
-
|
|
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
|
+
)
|
|
5614
6087
|
)
|
|
5615
6088
|
]
|
|
5616
6089
|
),
|
|
@@ -5686,7 +6159,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5686
6159
|
if (!t14.isJSXExpressionContainer(attr.value) || t14.isJSXEmptyExpression(attr.value.expression)) continue;
|
|
5687
6160
|
const exprClone = t14.cloneNode(attr.value.expression, true);
|
|
5688
6161
|
const tempProg = t14.file(t14.program([t14.expressionStatement(exprClone)]));
|
|
5689
|
-
|
|
6162
|
+
traverse8(tempProg, {
|
|
5690
6163
|
Identifier(path) {
|
|
5691
6164
|
if (path.node.name === arrayMap.itemVariable) path.node.name = "item";
|
|
5692
6165
|
else if (arrayMap.indexVariable && path.node.name === arrayMap.indexVariable) path.node.name = "__idx";
|
|
@@ -5721,7 +6194,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5721
6194
|
}
|
|
5722
6195
|
function templateRequiresRerender(file2) {
|
|
5723
6196
|
let requiresRerender = false;
|
|
5724
|
-
|
|
6197
|
+
traverse8(file2, {
|
|
5725
6198
|
noScope: true,
|
|
5726
6199
|
ConditionalExpression(path) {
|
|
5727
6200
|
if (branchContainsJSX(path.node.consequent) || branchContainsJSX(path.node.alternate)) {
|
|
@@ -5740,8 +6213,8 @@ function templateRequiresRerender(file2) {
|
|
|
5740
6213
|
}
|
|
5741
6214
|
function branchContainsJSX(expr) {
|
|
5742
6215
|
let containsJSX = false;
|
|
5743
|
-
const
|
|
5744
|
-
|
|
6216
|
+
const program10 = t14.program([t14.expressionStatement(t14.cloneNode(expr, true))]);
|
|
6217
|
+
traverse8(program10, {
|
|
5745
6218
|
noScope: true,
|
|
5746
6219
|
JSXElement(path) {
|
|
5747
6220
|
containsJSX = true;
|
|
@@ -5758,7 +6231,7 @@ function branchContainsJSX(expr) {
|
|
|
5758
6231
|
// src/generate-array.ts
|
|
5759
6232
|
import { createRequire as createRequire9 } from "module";
|
|
5760
6233
|
var require10 = createRequire9(import.meta.url);
|
|
5761
|
-
var
|
|
6234
|
+
var traverse9 = require10("@babel/traverse").default;
|
|
5762
6235
|
function getArrayPathParts(arrayMap) {
|
|
5763
6236
|
return arrayMap.arrayPathParts || normalizePathParts(arrayMap.arrayPath || "");
|
|
5764
6237
|
}
|
|
@@ -5827,22 +6300,35 @@ function buildPropPatcherFunction(binding, propName) {
|
|
|
5827
6300
|
"=",
|
|
5828
6301
|
t15.memberExpression(t15.memberExpression(target, t15.identifier("style")), t15.identifier("cssText")),
|
|
5829
6302
|
t15.conditionalExpression(
|
|
5830
|
-
t15.binaryExpression(
|
|
6303
|
+
t15.binaryExpression(
|
|
6304
|
+
"===",
|
|
6305
|
+
t15.unaryExpression("typeof", t15.identifier("__attrValue")),
|
|
6306
|
+
t15.stringLiteral("object")
|
|
6307
|
+
),
|
|
5831
6308
|
t15.callExpression(
|
|
5832
6309
|
t15.memberExpression(
|
|
5833
6310
|
t15.callExpression(
|
|
5834
6311
|
t15.memberExpression(
|
|
5835
|
-
t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [
|
|
6312
|
+
t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [
|
|
6313
|
+
t15.identifier("__attrValue")
|
|
6314
|
+
]),
|
|
5836
6315
|
t15.identifier("map")
|
|
5837
6316
|
),
|
|
5838
6317
|
[
|
|
5839
6318
|
t15.arrowFunctionExpression(
|
|
5840
6319
|
[t15.arrayPattern([t15.identifier("k"), t15.identifier("v")])],
|
|
5841
|
-
t15.binaryExpression(
|
|
6320
|
+
t15.binaryExpression(
|
|
5842
6321
|
"+",
|
|
5843
|
-
t15.
|
|
5844
|
-
|
|
5845
|
-
|
|
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
|
+
)
|
|
5846
6332
|
)
|
|
5847
6333
|
]
|
|
5848
6334
|
),
|
|
@@ -5908,8 +6394,8 @@ function buildPropPatcherFunction(binding, propName) {
|
|
|
5908
6394
|
}
|
|
5909
6395
|
function collectItemExpressionKeys(expr) {
|
|
5910
6396
|
const keys = /* @__PURE__ */ new Set();
|
|
5911
|
-
const
|
|
5912
|
-
|
|
6397
|
+
const program10 = t15.program([t15.expressionStatement(t15.cloneNode(expr, true))]);
|
|
6398
|
+
traverse9(program10, {
|
|
5913
6399
|
noScope: true,
|
|
5914
6400
|
MemberExpression(path) {
|
|
5915
6401
|
if (!t15.isIdentifier(path.node.object, { name: "item" })) return;
|
|
@@ -5951,22 +6437,35 @@ function buildPatchEntryPropPatcher(entry) {
|
|
|
5951
6437
|
"=",
|
|
5952
6438
|
t15.memberExpression(t15.memberExpression(target, t15.identifier("style")), t15.identifier("cssText")),
|
|
5953
6439
|
t15.conditionalExpression(
|
|
5954
|
-
t15.binaryExpression(
|
|
6440
|
+
t15.binaryExpression(
|
|
6441
|
+
"===",
|
|
6442
|
+
t15.unaryExpression("typeof", t15.identifier("__attrValue")),
|
|
6443
|
+
t15.stringLiteral("object")
|
|
6444
|
+
),
|
|
5955
6445
|
t15.callExpression(
|
|
5956
6446
|
t15.memberExpression(
|
|
5957
6447
|
t15.callExpression(
|
|
5958
6448
|
t15.memberExpression(
|
|
5959
|
-
t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [
|
|
6449
|
+
t15.callExpression(t15.memberExpression(t15.identifier("Object"), t15.identifier("entries")), [
|
|
6450
|
+
t15.identifier("__attrValue")
|
|
6451
|
+
]),
|
|
5960
6452
|
t15.identifier("map")
|
|
5961
6453
|
),
|
|
5962
6454
|
[
|
|
5963
6455
|
t15.arrowFunctionExpression(
|
|
5964
6456
|
[t15.arrayPattern([t15.identifier("k"), t15.identifier("v")])],
|
|
5965
|
-
t15.binaryExpression(
|
|
6457
|
+
t15.binaryExpression(
|
|
5966
6458
|
"+",
|
|
5967
|
-
t15.
|
|
5968
|
-
|
|
5969
|
-
|
|
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
|
+
)
|
|
5970
6469
|
)
|
|
5971
6470
|
]
|
|
5972
6471
|
),
|
|
@@ -6199,10 +6698,7 @@ function generateArrayConditionalPatchObserver(arrayMap, bindings, methodName) {
|
|
|
6199
6698
|
const containerName = `__${arrayPath.replace(/\./g, "_")}_container`;
|
|
6200
6699
|
const containerRef = t15.memberExpression(t15.thisExpression(), t15.identifier(containerName));
|
|
6201
6700
|
const proxiedArr = arrayMap.isImportedState ? buildMemberChain(
|
|
6202
|
-
t15.memberExpression(
|
|
6203
|
-
t15.identifier(arrayMap.storeVar || "store"),
|
|
6204
|
-
t15.identifier("__store")
|
|
6205
|
-
),
|
|
6701
|
+
t15.memberExpression(t15.identifier(arrayMap.storeVar || "store"), t15.identifier("__store")),
|
|
6206
6702
|
arrayPath
|
|
6207
6703
|
) : buildMemberChain(t15.thisExpression(), arrayPath);
|
|
6208
6704
|
const rawArrExpr = t15.logicalExpression(
|
|
@@ -6260,10 +6756,7 @@ function generateArrayConditionalRerenderObserver(arrayMap, methodName) {
|
|
|
6260
6756
|
const containerRef = t15.memberExpression(t15.thisExpression(), t15.identifier(containerName));
|
|
6261
6757
|
const configRef = t15.memberExpression(t15.thisExpression(), t15.identifier(getArrayConfigPropName(arrayMap)));
|
|
6262
6758
|
const proxiedArr = arrayMap.isImportedState ? buildMemberChain(
|
|
6263
|
-
t15.memberExpression(
|
|
6264
|
-
t15.identifier(arrayMap.storeVar || "store"),
|
|
6265
|
-
t15.identifier("__store")
|
|
6266
|
-
),
|
|
6759
|
+
t15.memberExpression(t15.identifier(arrayMap.storeVar || "store"), t15.identifier("__store")),
|
|
6267
6760
|
arrayPath
|
|
6268
6761
|
) : buildMemberChain(t15.thisExpression(), arrayPath);
|
|
6269
6762
|
const rawArrExpr = t15.logicalExpression(
|
|
@@ -6407,14 +6900,14 @@ function buildConditionalPatchStatement(binding, target, itemVariable) {
|
|
|
6407
6900
|
}
|
|
6408
6901
|
function renameItemVariable(expr, itemVariable) {
|
|
6409
6902
|
const cloned = t15.cloneNode(expr, true);
|
|
6410
|
-
const
|
|
6411
|
-
|
|
6903
|
+
const program10 = t15.program([t15.expressionStatement(cloned)]);
|
|
6904
|
+
traverse9(program10, {
|
|
6412
6905
|
noScope: true,
|
|
6413
6906
|
Identifier(path) {
|
|
6414
6907
|
if (path.node.name === itemVariable) path.node.name = "item";
|
|
6415
6908
|
}
|
|
6416
6909
|
});
|
|
6417
|
-
return
|
|
6910
|
+
return program10.body[0].expression;
|
|
6418
6911
|
}
|
|
6419
6912
|
function buildRelationalClassStatements(rowExpr, bindings, isMatch, phase) {
|
|
6420
6913
|
return bindings.flatMap((binding, index) => {
|
|
@@ -6681,7 +7174,8 @@ function unwrapComparisonOperands(node) {
|
|
|
6681
7174
|
}
|
|
6682
7175
|
function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCounter, classBody2, templateSetupContext) {
|
|
6683
7176
|
const renderEventHandlers = [];
|
|
6684
|
-
if (!arrayMap.itemTemplate)
|
|
7177
|
+
if (!arrayMap.itemTemplate)
|
|
7178
|
+
return { method: null, handlers: renderEventHandlers, handlerPropsInMap: [], needsUnwrapHelper: false };
|
|
6685
7179
|
const arrayPath = pathPartsToString(arrayMap.arrayPathParts || normalizePathParts(arrayMap.arrayPath || ""));
|
|
6686
7180
|
const modified = t16.cloneNode(arrayMap.itemTemplate, true);
|
|
6687
7181
|
const handlerPropsInMap = [];
|
|
@@ -6719,8 +7213,12 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
|
|
|
6719
7213
|
wholeParam = templateMethod.params[0].name;
|
|
6720
7214
|
}
|
|
6721
7215
|
}
|
|
7216
|
+
const itemKey = arrayMap.itemVariable;
|
|
6722
7217
|
wrapped.expressions = wrapped.expressions.map(
|
|
6723
|
-
(expr) =>
|
|
7218
|
+
(expr) => optionalizeMemberChainsAfterComputedItemKey(
|
|
7219
|
+
replacePropRefsInExpression(unwrapComparisonOperands(expr), propNames, wholeParam),
|
|
7220
|
+
itemKey
|
|
7221
|
+
)
|
|
6724
7222
|
);
|
|
6725
7223
|
const handlerRegStmts = buildHandlerRegistrationStatements(
|
|
6726
7224
|
handlerPropsInMap,
|
|
@@ -6734,8 +7232,14 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
|
|
|
6734
7232
|
t16.expressionStatement(wrapped)
|
|
6735
7233
|
]) : wrapped;
|
|
6736
7234
|
const setupStmts = collectTemplateSetupStatements(setupScope, templateSetupContext);
|
|
6737
|
-
const rewrittenSetup =
|
|
6738
|
-
|
|
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
|
+
);
|
|
6739
7243
|
const baseMethod = jsMethod6`${id9(methodName)}(${id9(arrayMap.itemVariable)}) {}`;
|
|
6740
7244
|
if (arrayMap.indexVariable) {
|
|
6741
7245
|
baseMethod.params.push(t16.identifier(arrayMap.indexVariable));
|
|
@@ -6756,13 +7260,7 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
|
|
|
6756
7260
|
return false;
|
|
6757
7261
|
}
|
|
6758
7262
|
const needsUnwrapHelper = [...rewrittenCallbackBody, returnStmt].some((stmt) => containsVCall(stmt));
|
|
6759
|
-
const method = appendToBody4(
|
|
6760
|
-
baseMethod,
|
|
6761
|
-
...rewrittenSetup,
|
|
6762
|
-
...rewrittenCallbackBody,
|
|
6763
|
-
...handlerRegStmts,
|
|
6764
|
-
returnStmt
|
|
6765
|
-
);
|
|
7263
|
+
const method = appendToBody4(baseMethod, ...rewrittenSetup, ...rewrittenCallbackBody, ...handlerRegStmts, returnStmt);
|
|
6766
7264
|
if (handlerPropsInMap.length > 0 && classBody2) {
|
|
6767
7265
|
const handleItemHandler = jsMethod6`__handleItemHandler(itemId, e) {
|
|
6768
7266
|
const fn = this.__itemHandlers_?.[itemId];
|
|
@@ -6790,7 +7288,7 @@ import * as t17 from "@babel/types";
|
|
|
6790
7288
|
import { id as id10, jsMethod as jsMethod7 } from "eszter";
|
|
6791
7289
|
import { createRequire as createRequire10 } from "module";
|
|
6792
7290
|
var require11 = createRequire10(import.meta.url);
|
|
6793
|
-
var
|
|
7291
|
+
var traverse10 = require11("@babel/traverse").default;
|
|
6794
7292
|
function isUnresolvedMapWithComponentChild(um, imports) {
|
|
6795
7293
|
const template = um.itemTemplate;
|
|
6796
7294
|
if (!template) return null;
|
|
@@ -6844,7 +7342,7 @@ function generateComponentArrayResult(um, arrayPropName, imports, propNames, _cl
|
|
|
6844
7342
|
let finalPropsExpr = propsExpr;
|
|
6845
7343
|
if (needsRename || needsIndexRename) {
|
|
6846
7344
|
const cloned = t17.cloneNode(propsExpr, true);
|
|
6847
|
-
|
|
7345
|
+
traverse10(cloned, {
|
|
6848
7346
|
noScope: true,
|
|
6849
7347
|
Identifier(path) {
|
|
6850
7348
|
if (needsRename && path.node.name === itemVar) {
|
|
@@ -6928,27 +7426,17 @@ function generateComponentArrayResult(um, arrayPropName, imports, propNames, _cl
|
|
|
6928
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"));
|
|
6929
7427
|
const mapParams = [t17.identifier("opt")];
|
|
6930
7428
|
if (indexVar || !itemIdProp) mapParams.push(t17.identifier("__k"));
|
|
6931
|
-
const childCall = t17.callExpression(
|
|
6932
|
-
t17.
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
t17.cloneNode(keyExpr, true)
|
|
6937
|
-
]
|
|
6938
|
-
);
|
|
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
|
+
]);
|
|
6939
7434
|
const mapCallback = t17.arrowFunctionExpression(mapParams, childCall);
|
|
6940
7435
|
const nullishCoalesce = t17.logicalExpression("??", t17.cloneNode(arrAccessExpr, true), t17.arrayExpression([]));
|
|
6941
7436
|
const parenthesized = t17.parenthesizedExpression ? t17.parenthesizedExpression(nullishCoalesce) : nullishCoalesce;
|
|
6942
|
-
const mapCallExpr = t17.callExpression(
|
|
6943
|
-
t17.memberExpression(parenthesized, t17.identifier("map")),
|
|
6944
|
-
[mapCallback]
|
|
6945
|
-
);
|
|
7437
|
+
const mapCallExpr = t17.callExpression(t17.memberExpression(parenthesized, t17.identifier("map")), [mapCallback]);
|
|
6946
7438
|
const constructorInit = t17.expressionStatement(
|
|
6947
|
-
t17.assignmentExpression(
|
|
6948
|
-
"=",
|
|
6949
|
-
t17.memberExpression(t17.thisExpression(), t17.identifier(itemsName)),
|
|
6950
|
-
mapCallExpr
|
|
6951
|
-
)
|
|
7439
|
+
t17.assignmentExpression("=", t17.memberExpression(t17.thisExpression(), t17.identifier(itemsName)), mapCallExpr)
|
|
6952
7440
|
);
|
|
6953
7441
|
return {
|
|
6954
7442
|
itemPropsMethod,
|
|
@@ -6963,8 +7451,9 @@ function generateComponentArrayResult(um, arrayPropName, imports, propNames, _cl
|
|
|
6963
7451
|
|
|
6964
7452
|
// src/apply-reactivity.ts
|
|
6965
7453
|
import { createRequire as createRequire11 } from "module";
|
|
7454
|
+
var generate2 = "default" in babelGenerator ? babelGenerator.default : babelGenerator;
|
|
6966
7455
|
var require12 = createRequire11(import.meta.url);
|
|
6967
|
-
var
|
|
7456
|
+
var traverse11 = require12("@babel/traverse").default;
|
|
6968
7457
|
var BOOLEAN_HTML_ATTRS = /* @__PURE__ */ new Set([
|
|
6969
7458
|
"disabled",
|
|
6970
7459
|
"hidden",
|
|
@@ -7010,14 +7499,11 @@ function generateCreatedHooks(stores, hasArrayConfigs, observeListConfigs = [])
|
|
|
7010
7499
|
if (handlers.length === 1 && !handlers[0].isVia) {
|
|
7011
7500
|
body.push(
|
|
7012
7501
|
t18.expressionStatement(
|
|
7013
|
-
t18.callExpression(
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(handlers[0].methodName))
|
|
7019
|
-
]
|
|
7020
|
-
)
|
|
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
|
+
])
|
|
7021
7507
|
)
|
|
7022
7508
|
);
|
|
7023
7509
|
} else {
|
|
@@ -7028,36 +7514,27 @@ function generateCreatedHooks(stores, hasArrayConfigs, observeListConfigs = [])
|
|
|
7028
7514
|
if (h.isVia && h.rereadExpr) {
|
|
7029
7515
|
callStmts.push(
|
|
7030
7516
|
t18.expressionStatement(
|
|
7031
|
-
t18.callExpression(
|
|
7032
|
-
t18.
|
|
7033
|
-
|
|
7034
|
-
)
|
|
7517
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)), [
|
|
7518
|
+
t18.cloneNode(h.rereadExpr, true),
|
|
7519
|
+
t18.nullLiteral()
|
|
7520
|
+
])
|
|
7035
7521
|
)
|
|
7036
7522
|
);
|
|
7037
7523
|
} else {
|
|
7038
7524
|
callStmts.push(
|
|
7039
7525
|
t18.expressionStatement(
|
|
7040
|
-
t18.callExpression(
|
|
7041
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)),
|
|
7042
|
-
[vParam, cParam]
|
|
7043
|
-
)
|
|
7526
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)), [vParam, cParam])
|
|
7044
7527
|
)
|
|
7045
7528
|
);
|
|
7046
7529
|
}
|
|
7047
7530
|
}
|
|
7048
7531
|
body.push(
|
|
7049
7532
|
t18.expressionStatement(
|
|
7050
|
-
t18.callExpression(
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
t18.arrowFunctionExpression(
|
|
7056
|
-
[vParam, cParam],
|
|
7057
|
-
t18.blockStatement(callStmts)
|
|
7058
|
-
)
|
|
7059
|
-
]
|
|
7060
|
-
)
|
|
7533
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__observe")), [
|
|
7534
|
+
storeVarExpr,
|
|
7535
|
+
pathArray,
|
|
7536
|
+
t18.arrowFunctionExpression([vParam, cParam], t18.blockStatement(callStmts))
|
|
7537
|
+
])
|
|
7061
7538
|
)
|
|
7062
7539
|
);
|
|
7063
7540
|
}
|
|
@@ -7067,22 +7544,15 @@ function generateCreatedHooks(stores, hasArrayConfigs, observeListConfigs = [])
|
|
|
7067
7544
|
const itemsName = getComponentArrayItemsName(config.arrayPropName);
|
|
7068
7545
|
const itemPropsMethodName = `__itemProps_${config.arrayPropName}`;
|
|
7069
7546
|
const configProps = [
|
|
7070
|
-
t18.objectProperty(
|
|
7071
|
-
|
|
7072
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName))
|
|
7073
|
-
),
|
|
7074
|
-
t18.objectProperty(
|
|
7075
|
-
t18.identifier("itemsKey"),
|
|
7076
|
-
t18.stringLiteral(itemsName)
|
|
7077
|
-
),
|
|
7547
|
+
t18.objectProperty(t18.identifier("items"), t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName))),
|
|
7548
|
+
t18.objectProperty(t18.identifier("itemsKey"), t18.stringLiteral(itemsName)),
|
|
7078
7549
|
t18.objectProperty(
|
|
7079
7550
|
t18.identifier("container"),
|
|
7080
7551
|
t18.arrowFunctionExpression(
|
|
7081
7552
|
[],
|
|
7082
|
-
config.containerBindingId ? t18.callExpression(
|
|
7083
|
-
t18.
|
|
7084
|
-
|
|
7085
|
-
) : jsExpr4`this.$(":scope")`
|
|
7553
|
+
config.containerBindingId ? t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__el")), [
|
|
7554
|
+
t18.stringLiteral(config.containerBindingId)
|
|
7555
|
+
]) : jsExpr4`this.$(":scope")`
|
|
7086
7556
|
)
|
|
7087
7557
|
),
|
|
7088
7558
|
t18.objectProperty(t18.identifier("Ctor"), t18.identifier(config.componentTag)),
|
|
@@ -7090,10 +7560,10 @@ function generateCreatedHooks(stores, hasArrayConfigs, observeListConfigs = [])
|
|
|
7090
7560
|
t18.identifier("props"),
|
|
7091
7561
|
t18.arrowFunctionExpression(
|
|
7092
7562
|
[t18.identifier("opt"), t18.identifier("__k")],
|
|
7093
|
-
t18.callExpression(
|
|
7094
|
-
t18.
|
|
7095
|
-
|
|
7096
|
-
)
|
|
7563
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(itemPropsMethodName)), [
|
|
7564
|
+
t18.identifier("opt"),
|
|
7565
|
+
t18.identifier("__k")
|
|
7566
|
+
])
|
|
7097
7567
|
)
|
|
7098
7568
|
),
|
|
7099
7569
|
t18.objectProperty(
|
|
@@ -7117,31 +7587,26 @@ function generateCreatedHooks(stores, hasArrayConfigs, observeListConfigs = [])
|
|
|
7117
7587
|
if (samePathHandlers.length > 0) {
|
|
7118
7588
|
const onchangeStmts = samePathHandlers.map(
|
|
7119
7589
|
(h) => t18.expressionStatement(
|
|
7120
|
-
h.isVia && h.rereadExpr ? t18.callExpression(
|
|
7121
|
-
t18.
|
|
7122
|
-
|
|
7123
|
-
) : t18.callExpression(
|
|
7124
|
-
t18.memberExpression(t18.
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
t18.nullLiteral()
|
|
7128
|
-
]
|
|
7129
|
-
)
|
|
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
|
+
])
|
|
7130
7597
|
)
|
|
7131
7598
|
);
|
|
7132
7599
|
configProps.push(
|
|
7133
|
-
t18.objectProperty(
|
|
7134
|
-
t18.identifier("onchange"),
|
|
7135
|
-
t18.arrowFunctionExpression([], t18.blockStatement(onchangeStmts))
|
|
7136
|
-
)
|
|
7600
|
+
t18.objectProperty(t18.identifier("onchange"), t18.arrowFunctionExpression([], t18.blockStatement(onchangeStmts)))
|
|
7137
7601
|
);
|
|
7138
7602
|
}
|
|
7139
7603
|
body.push(
|
|
7140
7604
|
t18.expressionStatement(
|
|
7141
|
-
t18.callExpression(
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7605
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__observeList")), [
|
|
7606
|
+
storeVarExpr,
|
|
7607
|
+
pathArray,
|
|
7608
|
+
t18.objectExpression(configProps)
|
|
7609
|
+
])
|
|
7145
7610
|
)
|
|
7146
7611
|
);
|
|
7147
7612
|
}
|
|
@@ -7160,14 +7625,11 @@ function generateLocalStateObserverSetup(observeHandlers, hasArrayConfigs) {
|
|
|
7160
7625
|
for (const observeHandler of observeHandlers) {
|
|
7161
7626
|
body.push(
|
|
7162
7627
|
t18.expressionStatement(
|
|
7163
|
-
t18.callExpression(
|
|
7164
|
-
t18.
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(observeHandler.methodName))
|
|
7169
|
-
]
|
|
7170
|
-
)
|
|
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
|
+
])
|
|
7171
7633
|
)
|
|
7172
7634
|
);
|
|
7173
7635
|
}
|
|
@@ -7185,7 +7647,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7185
7647
|
const classBody2 = t18.isClassBody(origPath.parent) ? origPath.parent : void 0;
|
|
7186
7648
|
return analyzeTemplate(origPath.node, stateRefs, classBody2);
|
|
7187
7649
|
};
|
|
7188
|
-
|
|
7650
|
+
traverse11(astToTraverse, {
|
|
7189
7651
|
ClassMethod(origPath) {
|
|
7190
7652
|
if (!t18.isIdentifier(origPath.node.key) || origPath.node.key.name !== "template") return;
|
|
7191
7653
|
const analysis = getAnalysis(className, origPath);
|
|
@@ -7193,7 +7655,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7193
7655
|
const hasCompiledChildStoreDeps = compiledChildren.some((child) => child.dependencies.some((dep) => dep.storeVar));
|
|
7194
7656
|
if (analysis.bindings.length === 0 && analysis.propBindings.length === 0 && analysis.arrayMaps.length === 0 && analysis.stateProps.size === 0 && analysis.unresolvedMaps.length === 0 && !hasCompiledChildStoreDeps)
|
|
7195
7657
|
return;
|
|
7196
|
-
|
|
7658
|
+
traverse11(ast, {
|
|
7197
7659
|
ClassDeclaration(classPath) {
|
|
7198
7660
|
if (!t18.isIdentifier(classPath.node.id) || classPath.node.id.name !== className) return;
|
|
7199
7661
|
const templateMethod = classPath.node.body.body.find(
|
|
@@ -7225,7 +7687,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7225
7687
|
}
|
|
7226
7688
|
if (renameMap.size === 0) return bodyStatements;
|
|
7227
7689
|
const tempProgram = t18.program(bodyStatements);
|
|
7228
|
-
|
|
7690
|
+
traverse11(tempProgram, {
|
|
7229
7691
|
noScope: true,
|
|
7230
7692
|
Identifier(path) {
|
|
7231
7693
|
const nextName = renameMap.get(path.node.name);
|
|
@@ -7343,10 +7805,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7343
7805
|
t18.memberExpression(
|
|
7344
7806
|
t18.callExpression(
|
|
7345
7807
|
t18.memberExpression(
|
|
7346
|
-
t18.callExpression(
|
|
7347
|
-
t18.
|
|
7348
|
-
|
|
7349
|
-
),
|
|
7808
|
+
t18.callExpression(t18.memberExpression(t18.identifier("Object"), t18.identifier("entries")), [
|
|
7809
|
+
t18.cloneNode(valueExpr, true)
|
|
7810
|
+
]),
|
|
7350
7811
|
t18.identifier("filter")
|
|
7351
7812
|
),
|
|
7352
7813
|
[
|
|
@@ -7358,12 +7819,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7358
7819
|
),
|
|
7359
7820
|
t18.identifier("map")
|
|
7360
7821
|
),
|
|
7361
|
-
[
|
|
7362
|
-
t18.arrowFunctionExpression(
|
|
7363
|
-
[t18.arrayPattern([t18.identifier("__k")])],
|
|
7364
|
-
t18.identifier("__k")
|
|
7365
|
-
)
|
|
7366
|
-
]
|
|
7822
|
+
[t18.arrowFunctionExpression([t18.arrayPattern([t18.identifier("__k")])], t18.identifier("__k"))]
|
|
7367
7823
|
),
|
|
7368
7824
|
t18.identifier("join")
|
|
7369
7825
|
),
|
|
@@ -7374,9 +7830,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7374
7830
|
t18.stringLiteral("")
|
|
7375
7831
|
);
|
|
7376
7832
|
updateStmt = t18.blockStatement([
|
|
7377
|
-
t18.variableDeclaration("const", [
|
|
7378
|
-
t18.variableDeclarator(t18.identifier("__newClass"), classValueExpr)
|
|
7379
|
-
]),
|
|
7833
|
+
t18.variableDeclaration("const", [t18.variableDeclarator(t18.identifier("__newClass"), classValueExpr)]),
|
|
7380
7834
|
t18.ifStatement(
|
|
7381
7835
|
t18.binaryExpression(
|
|
7382
7836
|
"!==",
|
|
@@ -7493,22 +7947,35 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7493
7947
|
} else {
|
|
7494
7948
|
continue;
|
|
7495
7949
|
}
|
|
7496
|
-
const
|
|
7497
|
-
|
|
7498
|
-
];
|
|
7499
|
-
|
|
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) {
|
|
7500
7956
|
const rewrittenSetup = replacePropRefsInStatements(
|
|
7501
7957
|
pb.setupStatements,
|
|
7502
7958
|
templatePropNames,
|
|
7503
7959
|
templateWholeParam
|
|
7504
7960
|
);
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
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(
|
|
7508
7967
|
t18.variableDeclaration("const", [t18.variableDeclarator(t18.identifier("__boundValue"), rewrittenExpr)])
|
|
7509
7968
|
);
|
|
7510
7969
|
}
|
|
7511
|
-
|
|
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;
|
|
7512
7979
|
patchStatementsByBinding.set(pb, blockStatements);
|
|
7513
7980
|
applied = true;
|
|
7514
7981
|
}
|
|
@@ -7554,7 +8021,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7554
8021
|
}
|
|
7555
8022
|
bindings.add(pb);
|
|
7556
8023
|
};
|
|
7557
|
-
|
|
8024
|
+
traverse11(scanProg, {
|
|
7558
8025
|
noScope: true,
|
|
7559
8026
|
Identifier(path) {
|
|
7560
8027
|
if (path.parentPath && t18.isMemberExpression(path.parentPath.node) && path.parentPath.node.object === path.node)
|
|
@@ -7588,9 +8055,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7588
8055
|
if (!hasStateOnly) continue;
|
|
7589
8056
|
for (const pb of bindings) {
|
|
7590
8057
|
if (pb.stateOnly) continue;
|
|
7591
|
-
const dup = [...bindings].some(
|
|
7592
|
-
(b) => b.stateOnly && b.selector === pb.selector && b.type === pb.type
|
|
7593
|
-
);
|
|
8058
|
+
const dup = [...bindings].some((b) => b.stateOnly && b.selector === pb.selector && b.type === pb.type);
|
|
7594
8059
|
if (dup) bindings.delete(pb);
|
|
7595
8060
|
}
|
|
7596
8061
|
}
|
|
@@ -7600,9 +8065,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7600
8065
|
if (analysis.earlyReturnGuard) {
|
|
7601
8066
|
const guardExpr = analysis.earlyReturnGuard;
|
|
7602
8067
|
const localToStoreExpr = /* @__PURE__ */ new Map();
|
|
7603
|
-
const setupStmts = templateMethod?.body.body.filter(
|
|
7604
|
-
(s) => t18.isVariableDeclaration(s)
|
|
7605
|
-
) || [];
|
|
8068
|
+
const setupStmts = templateMethod?.body.body.filter((s) => t18.isVariableDeclaration(s)) || [];
|
|
7606
8069
|
for (const decl of setupStmts) {
|
|
7607
8070
|
for (const d of decl.declarations) {
|
|
7608
8071
|
if (t18.isIdentifier(d.id) && t18.isMemberExpression(d.init)) {
|
|
@@ -7619,19 +8082,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7619
8082
|
rerenderStoreKeys.push({ observeKey: key, pathParts: parts });
|
|
7620
8083
|
}
|
|
7621
8084
|
};
|
|
7622
|
-
const guardScanProg = t18.program([
|
|
7623
|
-
|
|
7624
|
-
]);
|
|
7625
|
-
traverse10(guardScanProg, {
|
|
8085
|
+
const guardScanProg = t18.program([t18.expressionStatement(t18.cloneNode(guardExpr, true))]);
|
|
8086
|
+
traverse11(guardScanProg, {
|
|
7626
8087
|
noScope: true,
|
|
7627
8088
|
MemberExpression(path) {
|
|
7628
8089
|
const resolved = resolvePath(path.node, stateRefs);
|
|
7629
8090
|
if (!resolved?.parts?.length) return;
|
|
7630
8091
|
if (resolved.isImportedState || resolved.storeVar) {
|
|
7631
|
-
addRerenderDep(
|
|
7632
|
-
resolved.parts,
|
|
7633
|
-
resolved.isImportedState ? resolved.storeVar : void 0
|
|
7634
|
-
);
|
|
8092
|
+
addRerenderDep(resolved.parts, resolved.isImportedState ? resolved.storeVar : void 0);
|
|
7635
8093
|
}
|
|
7636
8094
|
},
|
|
7637
8095
|
Identifier(path) {
|
|
@@ -7661,7 +8119,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7661
8119
|
const parsed = JSON.parse(entry.observeKey);
|
|
7662
8120
|
const storeVarName = parsed.storeVar || void 0;
|
|
7663
8121
|
const methodNameStr = getObserveMethodName(propPath, storeVarName);
|
|
7664
|
-
const
|
|
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(); }`;
|
|
7665
8124
|
mergeObserveMethod(entry.observeKey, rerenderMethod);
|
|
7666
8125
|
if (!stateProps.has(entry.observeKey)) {
|
|
7667
8126
|
stateProps.set(entry.observeKey, entry.pathParts);
|
|
@@ -7675,6 +8134,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7675
8134
|
const componentArrayMountMethods = [];
|
|
7676
8135
|
const storeComponentArrayObservers = [];
|
|
7677
8136
|
const observeListConfigs = [];
|
|
8137
|
+
const staticArrayRefreshOnMount = [];
|
|
7678
8138
|
const mapItemAttrInfos = [];
|
|
7679
8139
|
const tmplBody = templateMethod?.body.body ?? [];
|
|
7680
8140
|
let tmplReturnIdx = -1;
|
|
@@ -7747,10 +8207,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7747
8207
|
const itemsName = getComponentArrayItemsName(arrayPropName);
|
|
7748
8208
|
const itemPropsMethodNameRef = `__itemProps_${arrayPropName}`;
|
|
7749
8209
|
const containerSuffix = arrayResult.containerBindingId;
|
|
7750
|
-
const containerExpr = containerSuffix ? t18.callExpression(
|
|
7751
|
-
t18.
|
|
7752
|
-
|
|
7753
|
-
) : jsExpr4`this.$(":scope")`;
|
|
8210
|
+
const containerExpr = containerSuffix ? t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__el")), [
|
|
8211
|
+
t18.stringLiteral(containerSuffix)
|
|
8212
|
+
]) : jsExpr4`this.$(":scope")`;
|
|
7754
8213
|
const itemIdProp = arrayResult.itemIdProperty;
|
|
7755
8214
|
const keyFn = itemIdProp && itemIdProp !== ITEM_IS_KEY ? t18.arrowFunctionExpression(
|
|
7756
8215
|
[t18.identifier("opt")],
|
|
@@ -7768,29 +8227,30 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7768
8227
|
t18.variableDeclaration("const", [
|
|
7769
8228
|
t18.variableDeclarator(
|
|
7770
8229
|
t18.identifier("__arr"),
|
|
7771
|
-
t18.logicalExpression(
|
|
8230
|
+
t18.logicalExpression(
|
|
8231
|
+
"??",
|
|
8232
|
+
t18.cloneNode(arrayResult.arrAccessExpr, true),
|
|
8233
|
+
t18.arrayExpression([])
|
|
8234
|
+
)
|
|
7772
8235
|
)
|
|
7773
8236
|
]),
|
|
7774
8237
|
t18.variableDeclaration("const", [
|
|
7775
8238
|
t18.variableDeclarator(
|
|
7776
8239
|
t18.identifier("__new"),
|
|
7777
|
-
t18.callExpression(
|
|
7778
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
t18.identifier(
|
|
7784
|
-
t18.
|
|
7785
|
-
|
|
7786
|
-
t18.
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
t18.cloneNode(keyFn, true)
|
|
7792
|
-
]
|
|
7793
|
-
)
|
|
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
|
+
])
|
|
7794
8254
|
)
|
|
7795
8255
|
]),
|
|
7796
8256
|
t18.expressionStatement(
|
|
@@ -7826,10 +8286,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7826
8286
|
t18.blockStatement([
|
|
7827
8287
|
t18.expressionStatement(
|
|
7828
8288
|
t18.callExpression(
|
|
7829
|
-
t18.memberExpression(
|
|
7830
|
-
t18.thisExpression(),
|
|
7831
|
-
t18.identifier(refreshMethodName)
|
|
7832
|
-
),
|
|
8289
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(refreshMethodName)),
|
|
7833
8290
|
[]
|
|
7834
8291
|
)
|
|
7835
8292
|
)
|
|
@@ -7880,11 +8337,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7880
8337
|
});
|
|
7881
8338
|
}
|
|
7882
8339
|
componentArrayDisposeTargets.push(getComponentArrayItemsName(arrayPropName));
|
|
7883
|
-
replaceMapWithComponentArrayItems(
|
|
8340
|
+
const wasReplacedInTemplate = replaceMapWithComponentArrayItems(
|
|
7884
8341
|
templateMethod,
|
|
7885
8342
|
um.computationExpr,
|
|
7886
8343
|
getComponentArrayItemsName(arrayPropName)
|
|
7887
8344
|
);
|
|
8345
|
+
if (!wasReplacedInTemplate && !storeArrayAccess) {
|
|
8346
|
+
staticArrayRefreshOnMount.push(getComponentArrayRefreshMethodName(arrayPropName));
|
|
8347
|
+
}
|
|
7888
8348
|
applied = true;
|
|
7889
8349
|
}
|
|
7890
8350
|
return;
|
|
@@ -7981,10 +8441,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7981
8441
|
[t18.identifier("value"), t18.identifier("change")],
|
|
7982
8442
|
t18.blockStatement([
|
|
7983
8443
|
t18.expressionStatement(
|
|
7984
|
-
t18.callExpression(
|
|
7985
|
-
t18.
|
|
7986
|
-
|
|
7987
|
-
)
|
|
8444
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__geaSyncMap")), [
|
|
8445
|
+
t18.numericLiteral(mapIdx)
|
|
8446
|
+
])
|
|
7988
8447
|
)
|
|
7989
8448
|
])
|
|
7990
8449
|
)
|
|
@@ -8002,7 +8461,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8002
8461
|
}
|
|
8003
8462
|
if (scanNodes.length > 0) {
|
|
8004
8463
|
const prog = t18.program(scanNodes);
|
|
8005
|
-
|
|
8464
|
+
traverse11(prog, {
|
|
8006
8465
|
noScope: true,
|
|
8007
8466
|
Identifier(path) {
|
|
8008
8467
|
if (templatePropNames.has(path.node.name)) usedPropNames.add(path.node.name);
|
|
@@ -8110,8 +8569,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8110
8569
|
if (!t18.isClassMethod(member) || member.kind !== "get" || !t18.isIdentifier(member.key)) continue;
|
|
8111
8570
|
const deps = [];
|
|
8112
8571
|
const localRefs = /* @__PURE__ */ new Set();
|
|
8113
|
-
const
|
|
8114
|
-
|
|
8572
|
+
const program10 = t18.program(member.body.body.map((s) => t18.cloneNode(s, true)));
|
|
8573
|
+
traverse11(program10, {
|
|
8115
8574
|
noScope: true,
|
|
8116
8575
|
MemberExpression(mePath) {
|
|
8117
8576
|
if (t18.isThisExpression(mePath.node.object) && t18.isIdentifier(mePath.node.property)) {
|
|
@@ -8159,7 +8618,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8159
8618
|
if (!t18.isIfStatement(stmt) || !(t18.isReturnStatement(stmt.consequent) || t18.isBlockStatement(stmt.consequent) && stmt.consequent.body.some((b) => t18.isReturnStatement(b))))
|
|
8160
8619
|
continue;
|
|
8161
8620
|
const guardProg = t18.program([t18.expressionStatement(t18.cloneNode(stmt.test, true))]);
|
|
8162
|
-
|
|
8621
|
+
traverse11(guardProg, {
|
|
8163
8622
|
noScope: true,
|
|
8164
8623
|
Identifier(idPath) {
|
|
8165
8624
|
if (t18.isMemberExpression(idPath.parent) && idPath.parent.property === idPath.node && !idPath.parent.computed)
|
|
@@ -8290,7 +8749,10 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8290
8749
|
if (allDepsCovered) continue;
|
|
8291
8750
|
}
|
|
8292
8751
|
}
|
|
8293
|
-
mergeObserveMethod(
|
|
8752
|
+
mergeObserveMethod(
|
|
8753
|
+
observeKey,
|
|
8754
|
+
generateRerenderObserver(propPath, storeVar, guardStateKeys.has(observeKey))
|
|
8755
|
+
);
|
|
8294
8756
|
} else if (guardStateKeys.has(observeKey)) {
|
|
8295
8757
|
mergeObserveMethod(observeKey, generateRerenderObserver(propPath, storeVar, true));
|
|
8296
8758
|
}
|
|
@@ -8311,7 +8773,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8311
8773
|
}
|
|
8312
8774
|
};
|
|
8313
8775
|
const wrapper = t18.expressionStatement(t18.cloneNode(childrenProp.value, true));
|
|
8314
|
-
|
|
8776
|
+
traverse11(t18.program([wrapper]), { noScope: true, ...check });
|
|
8315
8777
|
if (hasMap) childrenWithResolvedMap.add(child.instanceVar);
|
|
8316
8778
|
});
|
|
8317
8779
|
if (childrenWithResolvedMap.size > 0 && analysis.arrayMaps.length > 0) {
|
|
@@ -8352,7 +8814,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8352
8814
|
const methodName = member.key.name;
|
|
8353
8815
|
const isRelevant = childrenWithResolvedMap.size > 0 && methodName.startsWith("__buildProps_");
|
|
8354
8816
|
if (!isRelevant) continue;
|
|
8355
|
-
|
|
8817
|
+
traverse11(t18.program([t18.expressionStatement(t18.functionExpression(null, [], member.body))]), {
|
|
8356
8818
|
noScope: true,
|
|
8357
8819
|
TemplateLiteral(tlPath) {
|
|
8358
8820
|
const tl = tlPath.node;
|
|
@@ -8395,8 +8857,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8395
8857
|
return false;
|
|
8396
8858
|
}
|
|
8397
8859
|
return true;
|
|
8398
|
-
}).map(
|
|
8399
|
-
|
|
8860
|
+
}).map((child) => {
|
|
8861
|
+
const updateExpr = t18.expressionStatement(
|
|
8400
8862
|
t18.callExpression(
|
|
8401
8863
|
t18.memberExpression(
|
|
8402
8864
|
t18.memberExpression(t18.thisExpression(), t18.identifier(child.instanceVar)),
|
|
@@ -8412,8 +8874,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8412
8874
|
)
|
|
8413
8875
|
]
|
|
8414
8876
|
)
|
|
8415
|
-
)
|
|
8416
|
-
|
|
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
|
+
});
|
|
8417
8885
|
if (existing && t18.isBlockStatement(existing.body)) {
|
|
8418
8886
|
existing.body.body.unshift(...calls);
|
|
8419
8887
|
} else {
|
|
@@ -8512,7 +8980,11 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8512
8980
|
const htmlArrayMaps = [];
|
|
8513
8981
|
for (const arrayMap of analysis.arrayMaps) {
|
|
8514
8982
|
const compChild = isUnresolvedMapWithComponentChild(
|
|
8515
|
-
{
|
|
8983
|
+
{
|
|
8984
|
+
itemTemplate: arrayMap.itemTemplate,
|
|
8985
|
+
itemVariable: arrayMap.itemVariable,
|
|
8986
|
+
containerSelector: arrayMap.containerSelector
|
|
8987
|
+
},
|
|
8516
8988
|
imports
|
|
8517
8989
|
);
|
|
8518
8990
|
if (compChild) {
|
|
@@ -8593,11 +9065,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8593
9065
|
}
|
|
8594
9066
|
componentArrayDisposeTargets.push(getComponentArrayItemsName(arrayPropName));
|
|
8595
9067
|
const mapReplaceExpr = storeArrayAccess ? t18.memberExpression(t18.identifier(storeArrayAccess.storeVar), t18.identifier(storeArrayAccess.propName)) : computationExpr;
|
|
8596
|
-
replaceMapWithComponentArrayItems(
|
|
9068
|
+
const wasReplaced = replaceMapWithComponentArrayItems(
|
|
8597
9069
|
templateMethod,
|
|
8598
9070
|
mapReplaceExpr,
|
|
8599
9071
|
getComponentArrayItemsName(arrayPropName)
|
|
8600
9072
|
);
|
|
9073
|
+
if (!wasReplaced && !arrayMap.storeVar) {
|
|
9074
|
+
staticArrayRefreshOnMount.push(getComponentArrayRefreshMethodName(arrayPropName));
|
|
9075
|
+
}
|
|
8601
9076
|
applied = true;
|
|
8602
9077
|
}
|
|
8603
9078
|
}
|
|
@@ -8610,21 +9085,30 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8610
9085
|
for (const depPath of getterDepPaths) {
|
|
8611
9086
|
const depObserveKey = buildObserveKey(depPath, arrayMap.storeVar);
|
|
8612
9087
|
const depMethodName = getObserveMethodName(depPath, arrayMap.storeVar);
|
|
8613
|
-
const
|
|
8614
|
-
t18.
|
|
8615
|
-
t18.
|
|
8616
|
-
|
|
8617
|
-
[t18.stringLiteral(pathKey)]
|
|
8618
|
-
)
|
|
8619
|
-
)
|
|
8620
|
-
]);
|
|
8621
|
-
const delegateMethod = t18.classMethod(
|
|
8622
|
-
"method",
|
|
8623
|
-
t18.identifier(depMethodName),
|
|
8624
|
-
[t18.identifier("__v"), t18.identifier("__c")],
|
|
8625
|
-
delegateBody
|
|
9088
|
+
const refreshStmt = t18.expressionStatement(
|
|
9089
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__refreshList")), [
|
|
9090
|
+
t18.stringLiteral(pathKey)
|
|
9091
|
+
])
|
|
8626
9092
|
);
|
|
8627
|
-
|
|
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
|
+
}
|
|
8628
9112
|
}
|
|
8629
9113
|
}
|
|
8630
9114
|
for (const arrayMap of componentArrayMaps) {
|
|
@@ -8634,12 +9118,10 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8634
9118
|
const pathKey = arrayMap.arrayPathParts.join(".");
|
|
8635
9119
|
const storeRef = stateRefs.get(arrayMap.storeVar);
|
|
8636
9120
|
const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
|
|
8637
|
-
const getterDepKeys = new Set(
|
|
8638
|
-
(getterDepPaths || []).map((dp) => buildObserveKey(dp, arrayMap.storeVar))
|
|
8639
|
-
);
|
|
9121
|
+
const getterDepKeys = new Set((getterDepPaths || []).map((dp) => buildObserveKey(dp, arrayMap.storeVar)));
|
|
8640
9122
|
const externalDeps = /* @__PURE__ */ new Map();
|
|
8641
9123
|
const clonedBody = t18.cloneNode(itemPropsMethod.body, true);
|
|
8642
|
-
|
|
9124
|
+
traverse11(t18.program([t18.expressionStatement(t18.arrowFunctionExpression([], clonedBody))]), {
|
|
8643
9125
|
noScope: true,
|
|
8644
9126
|
Identifier(idPath) {
|
|
8645
9127
|
if (idPath.parentPath && t18.isMemberExpression(idPath.parentPath.node) && idPath.parentPath.node.property === idPath.node && !idPath.parentPath.node.computed)
|
|
@@ -8669,10 +9151,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8669
9151
|
if (!stateProps.has(depKey)) stateProps.set(depKey, dep.parts);
|
|
8670
9152
|
const delegateBody = t18.blockStatement([
|
|
8671
9153
|
t18.expressionStatement(
|
|
8672
|
-
t18.callExpression(
|
|
8673
|
-
t18.
|
|
8674
|
-
|
|
8675
|
-
)
|
|
9154
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__refreshList")), [
|
|
9155
|
+
t18.stringLiteral(pathKey)
|
|
9156
|
+
])
|
|
8676
9157
|
)
|
|
8677
9158
|
]);
|
|
8678
9159
|
const delegateMethod = t18.classMethod(
|
|
@@ -8713,46 +9194,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8713
9194
|
}
|
|
8714
9195
|
const observeKey = buildObserveKey(arrayMap.arrayPathParts, arrayMap.storeVar);
|
|
8715
9196
|
const arrayHandlerMethodName = getObserveMethodName(arrayMap.arrayPathParts, arrayMap.storeVar);
|
|
8716
|
-
generateArrayHandlers(arrayMap, arrayHandlerMethodName).forEach(
|
|
8717
|
-
(h)
|
|
8718
|
-
|
|
8719
|
-
}
|
|
8720
|
-
);
|
|
8721
|
-
if (arrayMap.storeVar) {
|
|
8722
|
-
const storeRef = stateRefs.get(arrayMap.storeVar);
|
|
8723
|
-
const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
|
|
8724
|
-
if (getterDepPaths && getterDepPaths.length > 0) {
|
|
8725
|
-
for (const depPath of getterDepPaths) {
|
|
8726
|
-
const depObserveKey = buildObserveKey(depPath, arrayMap.storeVar);
|
|
8727
|
-
const depMethodName = getObserveMethodName(depPath, arrayMap.storeVar);
|
|
8728
|
-
let rereadExpr = t18.memberExpression(
|
|
8729
|
-
t18.identifier(arrayMap.storeVar),
|
|
8730
|
-
t18.identifier(arrayMap.arrayPathParts[0])
|
|
8731
|
-
);
|
|
8732
|
-
for (let i = 1; i < arrayMap.arrayPathParts.length; i++) {
|
|
8733
|
-
rereadExpr = t18.memberExpression(
|
|
8734
|
-
rereadExpr,
|
|
8735
|
-
t18.identifier(arrayMap.arrayPathParts[i])
|
|
8736
|
-
);
|
|
8737
|
-
}
|
|
8738
|
-
const delegateBody = t18.blockStatement([
|
|
8739
|
-
t18.expressionStatement(
|
|
8740
|
-
t18.callExpression(
|
|
8741
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(arrayHandlerMethodName)),
|
|
8742
|
-
[rereadExpr, t18.nullLiteral()]
|
|
8743
|
-
)
|
|
8744
|
-
)
|
|
8745
|
-
]);
|
|
8746
|
-
const delegateMethod = t18.classMethod(
|
|
8747
|
-
"method",
|
|
8748
|
-
t18.identifier(depMethodName),
|
|
8749
|
-
[t18.identifier("__v"), t18.identifier("__c")],
|
|
8750
|
-
delegateBody
|
|
8751
|
-
);
|
|
8752
|
-
mergeObserveMethod(depObserveKey, delegateMethod);
|
|
8753
|
-
}
|
|
8754
|
-
}
|
|
8755
|
-
}
|
|
9197
|
+
generateArrayHandlers(arrayMap, arrayHandlerMethodName).forEach((h) => {
|
|
9198
|
+
mergeObserveMethod(observeKey, h);
|
|
9199
|
+
});
|
|
8756
9200
|
});
|
|
8757
9201
|
if ((analysis.conditionalSlots || []).length > 0) {
|
|
8758
9202
|
const templatePropNames2 = getTemplatePropNames(classPath.node.body);
|
|
@@ -8760,7 +9204,8 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8760
9204
|
classPath.node.body,
|
|
8761
9205
|
analysis.conditionalSlots,
|
|
8762
9206
|
templatePropNames2,
|
|
8763
|
-
getTemplateParamIdentifier(classPath.node.body)
|
|
9207
|
+
getTemplateParamIdentifier(classPath.node.body),
|
|
9208
|
+
analysis.earlyReturnGuard
|
|
8764
9209
|
);
|
|
8765
9210
|
}
|
|
8766
9211
|
if (htmlArrayMaps.length > 0) {
|
|
@@ -8780,17 +9225,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8780
9225
|
t18.identifier(arrayMap.arrayPathParts[0])
|
|
8781
9226
|
);
|
|
8782
9227
|
} else {
|
|
8783
|
-
valueExpr = t18.memberExpression(
|
|
8784
|
-
t18.thisExpression(),
|
|
8785
|
-
t18.identifier(arrayMap.arrayPathParts[0])
|
|
8786
|
-
);
|
|
9228
|
+
valueExpr = t18.memberExpression(t18.thisExpression(), t18.identifier(arrayMap.arrayPathParts[0]));
|
|
8787
9229
|
}
|
|
8788
9230
|
afterRenderCalls.push(
|
|
8789
9231
|
t18.expressionStatement(
|
|
8790
|
-
t18.callExpression(
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
)
|
|
9232
|
+
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), [
|
|
9233
|
+
valueExpr,
|
|
9234
|
+
t18.nullLiteral()
|
|
9235
|
+
])
|
|
8794
9236
|
)
|
|
8795
9237
|
);
|
|
8796
9238
|
});
|
|
@@ -8801,10 +9243,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8801
9243
|
[],
|
|
8802
9244
|
t18.blockStatement([
|
|
8803
9245
|
t18.expressionStatement(
|
|
8804
|
-
t18.callExpression(
|
|
8805
|
-
t18.memberExpression(t18.super(), t18.identifier("onAfterRender")),
|
|
8806
|
-
[]
|
|
8807
|
-
)
|
|
9246
|
+
t18.callExpression(t18.memberExpression(t18.super(), t18.identifier("onAfterRender")), [])
|
|
8808
9247
|
),
|
|
8809
9248
|
...afterRenderCalls
|
|
8810
9249
|
])
|
|
@@ -8859,12 +9298,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8859
9298
|
const getterDepPaths = storeRef?.getterDeps?.get(parts[0]);
|
|
8860
9299
|
if (getterDepPaths && getterDepPaths.length > 0) {
|
|
8861
9300
|
const originalMethodName = getObserveMethodName(parts, storeVar);
|
|
8862
|
-
let rereadExpr = t18.memberExpression(
|
|
8863
|
-
t18.identifier(storeVar),
|
|
8864
|
-
t18.identifier(parts[0])
|
|
8865
|
-
);
|
|
9301
|
+
let rereadExpr = t18.memberExpression(t18.identifier(storeVar), t18.identifier(parts[0]));
|
|
8866
9302
|
for (let i = 1; i < parts.length; i++) {
|
|
8867
|
-
rereadExpr = t18.
|
|
9303
|
+
rereadExpr = t18.optionalMemberExpression(rereadExpr, t18.identifier(parts[i]), false, true);
|
|
8868
9304
|
}
|
|
8869
9305
|
for (const depPath of getterDepPaths) {
|
|
8870
9306
|
const depKey = buildObserveKey(depPath, storeVar) + `__getter_${parts.join("_")}`;
|
|
@@ -8941,46 +9377,141 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8941
9377
|
if (guardStateKeys.size > 0) {
|
|
8942
9378
|
addedMethods.forEach((method, observeKey) => {
|
|
8943
9379
|
const { parts, storeVar: sv } = parseObserveKey(observeKey);
|
|
8944
|
-
if (!sv
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
t18.
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
method.body
|
|
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;
|
|
8958
9419
|
}
|
|
8959
|
-
break;
|
|
8960
9420
|
}
|
|
8961
9421
|
}
|
|
8962
9422
|
});
|
|
8963
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
|
+
}
|
|
8964
9466
|
if (importedStores.size > 0 || localObserveHandlers.size > 0 || mapRegistrations.length > 0) {
|
|
8965
9467
|
const storeConfigs = Array.from(importedStores.entries()).map(([storeVar, config]) => ({
|
|
8966
9468
|
storeVar,
|
|
8967
9469
|
captureExpression: config.captureExpression,
|
|
8968
|
-
observeHandlers: Array.from(config.observeHandlers.values()).map(
|
|
8969
|
-
pathParts,
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
9470
|
+
observeHandlers: Array.from(config.observeHandlers.values()).map(
|
|
9471
|
+
({ pathParts, methodName, isVia, rereadExpr }) => ({
|
|
9472
|
+
pathParts,
|
|
9473
|
+
methodName,
|
|
9474
|
+
isVia,
|
|
9475
|
+
rereadExpr
|
|
9476
|
+
})
|
|
9477
|
+
)
|
|
8974
9478
|
}));
|
|
8975
9479
|
for (const olc of observeListConfigs) {
|
|
8976
9480
|
ensureStoreGroup(olc.storeVar);
|
|
8977
9481
|
}
|
|
8978
9482
|
if (storeConfigs.length > 0 || mapRegistrations.length > 0 || observeListConfigs.length > 0) {
|
|
8979
|
-
const createdHooksMethod = generateCreatedHooks(
|
|
9483
|
+
const createdHooksMethod = generateCreatedHooks(
|
|
9484
|
+
storeConfigs,
|
|
9485
|
+
htmlArrayMaps.length > 0,
|
|
9486
|
+
observeListConfigs
|
|
9487
|
+
);
|
|
8980
9488
|
if (mapRegistrations.length > 0) {
|
|
8981
9489
|
createdHooksMethod.body.body.push(...mapRegistrations);
|
|
8982
9490
|
}
|
|
8983
|
-
|
|
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);
|
|
9499
|
+
}
|
|
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
|
+
);
|
|
8984
9515
|
}
|
|
8985
9516
|
if (localObserveHandlers.size > 0) {
|
|
8986
9517
|
classPath.node.body.body.push(
|
|
@@ -9033,8 +9564,8 @@ function collectUnresolvedDependencies(unresolvedMaps, stateRefs, classBody2) {
|
|
|
9033
9564
|
}
|
|
9034
9565
|
const depExpr = resolveHelperCallExpressionForDeps(unresolvedMap.computationExpr, classBody2);
|
|
9035
9566
|
const targetExpr = depExpr || unresolvedMap.computationExpr;
|
|
9036
|
-
const
|
|
9037
|
-
|
|
9567
|
+
const program10 = t18.program([t18.expressionStatement(t18.cloneNode(targetExpr, true))]);
|
|
9568
|
+
traverse11(program10, {
|
|
9038
9569
|
noScope: true,
|
|
9039
9570
|
MemberExpression(path) {
|
|
9040
9571
|
const targetExpr2 = path.parentPath && t18.isCallExpression(path.parentPath.node) && path.parentPath.node.callee === path.node ? path.node.object : path.node;
|
|
@@ -9063,8 +9594,8 @@ function collectHelperMethodDependencies(expr, classBody2, stateRefs, deps) {
|
|
|
9063
9594
|
(node) => t18.isClassMethod(node) && t18.isIdentifier(node.key) && node.key.name === helperMethodName
|
|
9064
9595
|
);
|
|
9065
9596
|
if (!helperMethod || !t18.isBlockStatement(helperMethod.body)) return false;
|
|
9066
|
-
const
|
|
9067
|
-
|
|
9597
|
+
const program10 = t18.program(helperMethod.body.body.map((stmt) => t18.cloneNode(stmt, true)));
|
|
9598
|
+
traverse11(program10, {
|
|
9068
9599
|
noScope: true,
|
|
9069
9600
|
MemberExpression(path) {
|
|
9070
9601
|
const resolved = resolvePath(path.node, stateRefs);
|
|
@@ -9176,11 +9707,7 @@ function generateMapRegistration(arrayMap, unresolvedMap, templatePropNames, who
|
|
|
9176
9707
|
if (needsReplace) {
|
|
9177
9708
|
arrExpr = replacePropRefsInExpression(arrExpr, templatePropNames || /* @__PURE__ */ new Set(), wholeParamName);
|
|
9178
9709
|
if (setupStatements.length) {
|
|
9179
|
-
setupStatements = replacePropRefsInStatements(
|
|
9180
|
-
setupStatements,
|
|
9181
|
-
templatePropNames || /* @__PURE__ */ new Set(),
|
|
9182
|
-
wholeParamName
|
|
9183
|
-
);
|
|
9710
|
+
setupStatements = replacePropRefsInStatements(setupStatements, templatePropNames || /* @__PURE__ */ new Set(), wholeParamName);
|
|
9184
9711
|
}
|
|
9185
9712
|
}
|
|
9186
9713
|
const prunedSetup = pruneUnusedSetupStatements(setupStatements, arrExpr);
|
|
@@ -9208,7 +9735,7 @@ function generateMapRegistration(arrayMap, unresolvedMap, templatePropNames, who
|
|
|
9208
9735
|
function collectFreeIdentifiers(nodes) {
|
|
9209
9736
|
const names = /* @__PURE__ */ new Set();
|
|
9210
9737
|
for (const node of nodes) {
|
|
9211
|
-
|
|
9738
|
+
traverse11(
|
|
9212
9739
|
t18.isProgram(node) ? node : t18.program([t18.isStatement(node) ? node : t18.expressionStatement(node)]),
|
|
9213
9740
|
{
|
|
9214
9741
|
noScope: true,
|
|
@@ -9277,12 +9804,12 @@ function getArrayPropNameFromExpr(expr) {
|
|
|
9277
9804
|
return null;
|
|
9278
9805
|
}
|
|
9279
9806
|
function replaceMapWithComponentArrayItems(templateMethod, arrayExpr, itemsName) {
|
|
9280
|
-
if (!arrayExpr || !t18.isBlockStatement(templateMethod.body)) return;
|
|
9807
|
+
if (!arrayExpr || !t18.isBlockStatement(templateMethod.body)) return false;
|
|
9281
9808
|
const tempProg = t18.program([
|
|
9282
9809
|
t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
|
|
9283
9810
|
]);
|
|
9284
9811
|
let replaced = false;
|
|
9285
|
-
|
|
9812
|
+
traverse11(tempProg, {
|
|
9286
9813
|
noScope: true,
|
|
9287
9814
|
CallExpression(path) {
|
|
9288
9815
|
if (replaced) return;
|
|
@@ -9303,6 +9830,7 @@ function replaceMapWithComponentArrayItems(templateMethod, arrayExpr, itemsName)
|
|
|
9303
9830
|
replaced = true;
|
|
9304
9831
|
}
|
|
9305
9832
|
});
|
|
9833
|
+
return replaced;
|
|
9306
9834
|
}
|
|
9307
9835
|
function inlineIntoConstructor(classBody2, statements) {
|
|
9308
9836
|
let ctor = classBody2.body.find(
|
|
@@ -9411,10 +9939,7 @@ function ensureOnPropChangeMethod(classBody2, inlinePatchBodies, compiledChildre
|
|
|
9411
9939
|
),
|
|
9412
9940
|
[
|
|
9413
9941
|
t18.callExpression(
|
|
9414
|
-
t18.memberExpression(
|
|
9415
|
-
t18.thisExpression(),
|
|
9416
|
-
t18.identifier(`__buildProps_${child.instanceVar.replace(/^_/, "")}`)
|
|
9417
|
-
),
|
|
9942
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(`__buildProps_${child.instanceVar.replace(/^_/, "")}`)),
|
|
9418
9943
|
[]
|
|
9419
9944
|
)
|
|
9420
9945
|
]
|
|
@@ -9580,7 +10105,10 @@ function mergeKeyGuards(stmts) {
|
|
|
9580
10105
|
}
|
|
9581
10106
|
return result;
|
|
9582
10107
|
}
|
|
9583
|
-
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;
|
|
9584
10112
|
const collectDeduped = (stmts, seen, out) => {
|
|
9585
10113
|
for (const stmt of stmts) {
|
|
9586
10114
|
if (t18.isVariableDeclaration(stmt)) {
|
|
@@ -9617,9 +10145,12 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
|
|
|
9617
10145
|
const rpExpr = (e) => replacePropRefsInExpression(e, templatePropNames, wholeParamName);
|
|
9618
10146
|
const rpStmts = (s) => replacePropRefsInStatements(s, templatePropNames, wholeParamName);
|
|
9619
10147
|
const rewrittenCondExprs = slots.map((s) => rpExpr(t18.cloneNode(s.conditionExpr, true)));
|
|
9620
|
-
const
|
|
9621
|
-
|
|
9622
|
-
|
|
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
|
+
)
|
|
9623
10154
|
);
|
|
9624
10155
|
const condAssignments = [];
|
|
9625
10156
|
for (let i = 0; i < slots.length; i++) {
|
|
@@ -9628,7 +10159,7 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
|
|
|
9628
10159
|
t18.assignmentExpression(
|
|
9629
10160
|
"=",
|
|
9630
10161
|
t18.memberExpression(t18.thisExpression(), t18.identifier(`__geaCond_${i}`)),
|
|
9631
|
-
t18.unaryExpression("!", t18.unaryExpression("!",
|
|
10162
|
+
t18.unaryExpression("!", t18.unaryExpression("!", rewrittenCondExprsSafe[i]))
|
|
9632
10163
|
)
|
|
9633
10164
|
)
|
|
9634
10165
|
);
|
|
@@ -9637,22 +10168,25 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
|
|
|
9637
10168
|
for (let i = 0; i < slots.length; i++) {
|
|
9638
10169
|
const slot = slots[i];
|
|
9639
10170
|
const rewrittenCondExpr = rpExpr(t18.cloneNode(slot.conditionExpr, true));
|
|
9640
|
-
const condSetup =
|
|
9641
|
-
rpStmts(allSetupStatements.map((s) => t18.cloneNode(s, true))),
|
|
9642
|
-
|
|
10171
|
+
const condSetup = maybeOptStmts(
|
|
10172
|
+
pruneDeadParamDestructuring(rpStmts(allSetupStatements.map((s) => t18.cloneNode(s, true))), [
|
|
10173
|
+
rewrittenCondExpr
|
|
10174
|
+
])
|
|
9643
10175
|
);
|
|
9644
|
-
const getCondBody = [...condSetup, t18.returnStatement(rewrittenCondExpr)];
|
|
10176
|
+
const getCondBody = [...condSetup, t18.returnStatement(maybeOptExpr(rewrittenCondExpr))];
|
|
9645
10177
|
const buildHtmlFn = (htmlExpr) => {
|
|
9646
10178
|
if (!htmlExpr) return t18.nullLiteral();
|
|
9647
10179
|
const clonedHtmlExpr = rpExpr(t18.cloneNode(htmlExpr, true));
|
|
9648
|
-
const htmlSetup =
|
|
9649
|
-
rpStmts(allHtmlSetupStatements.map((s) => t18.cloneNode(s, true))),
|
|
9650
|
-
|
|
10180
|
+
const htmlSetup = maybeOptStmts(
|
|
10181
|
+
pruneDeadParamDestructuring(rpStmts(allHtmlSetupStatements.map((s) => t18.cloneNode(s, true))), [
|
|
10182
|
+
clonedHtmlExpr
|
|
10183
|
+
])
|
|
9651
10184
|
);
|
|
10185
|
+
const htmlExprSafe = maybeOptExpr(clonedHtmlExpr);
|
|
9652
10186
|
if (htmlSetup.length > 0) {
|
|
9653
|
-
return t18.arrowFunctionExpression([], t18.blockStatement([...htmlSetup, t18.returnStatement(
|
|
10187
|
+
return t18.arrowFunctionExpression([], t18.blockStatement([...htmlSetup, t18.returnStatement(htmlExprSafe)]));
|
|
9654
10188
|
}
|
|
9655
|
-
return t18.arrowFunctionExpression([],
|
|
10189
|
+
return t18.arrowFunctionExpression([], htmlExprSafe);
|
|
9656
10190
|
};
|
|
9657
10191
|
registerCondCalls.push(
|
|
9658
10192
|
t18.expressionStatement(
|
|
@@ -9667,10 +10201,7 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
|
|
|
9667
10201
|
);
|
|
9668
10202
|
}
|
|
9669
10203
|
const evalStatements = [...initSetup, ...condAssignments];
|
|
9670
|
-
const initBody = evalStatements.length > 0 ? [
|
|
9671
|
-
t18.tryStatement(t18.blockStatement(evalStatements), loggingCatchClause()),
|
|
9672
|
-
...registerCondCalls
|
|
9673
|
-
] : registerCondCalls;
|
|
10204
|
+
const initBody = evalStatements.length > 0 ? [...evalStatements, ...registerCondCalls] : registerCondCalls;
|
|
9674
10205
|
inlineIntoConstructor(classBody2, initBody);
|
|
9675
10206
|
}
|
|
9676
10207
|
function getTemplatePropNames(classBody2) {
|
|
@@ -9698,7 +10229,7 @@ function getTemplateParamIdentifier(classBody2) {
|
|
|
9698
10229
|
function collectPropNamesFromItemTemplate(itemTemplate, templatePropNames) {
|
|
9699
10230
|
if (!itemTemplate) return [];
|
|
9700
10231
|
const used = /* @__PURE__ */ new Set();
|
|
9701
|
-
|
|
10232
|
+
traverse11(itemTemplate, {
|
|
9702
10233
|
noScope: true,
|
|
9703
10234
|
Identifier(path) {
|
|
9704
10235
|
if (templatePropNames.has(path.node.name)) used.add(path.node.name);
|
|
@@ -9740,7 +10271,7 @@ function injectMapItemAttrsIntoTemplate(templateMethod, mapInfos) {
|
|
|
9740
10271
|
const tempProg = t18.program([
|
|
9741
10272
|
t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
|
|
9742
10273
|
]);
|
|
9743
|
-
|
|
10274
|
+
traverse11(tempProg, {
|
|
9744
10275
|
noScope: true,
|
|
9745
10276
|
CallExpression(path) {
|
|
9746
10277
|
if (!t18.isMemberExpression(path.node.callee)) return;
|
|
@@ -9815,7 +10346,7 @@ function addJoinToUnresolvedMapCalls(templateMethod, _unresolvedMaps) {
|
|
|
9815
10346
|
const tempProg = t18.program([
|
|
9816
10347
|
t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
|
|
9817
10348
|
]);
|
|
9818
|
-
|
|
10349
|
+
traverse11(tempProg, {
|
|
9819
10350
|
noScope: true,
|
|
9820
10351
|
CallExpression(path) {
|
|
9821
10352
|
if (!t18.isMemberExpression(path.node.callee)) return;
|
|
@@ -9848,7 +10379,7 @@ function replaceInlineMapWithRenderCall(classPath, arrayMap, renderMethodName) {
|
|
|
9848
10379
|
const tempProg = t18.program([
|
|
9849
10380
|
t18.expressionStatement(t18.arrowFunctionExpression(templateMethod.params, templateMethod.body))
|
|
9850
10381
|
]);
|
|
9851
|
-
|
|
10382
|
+
traverse11(tempProg, {
|
|
9852
10383
|
noScope: true,
|
|
9853
10384
|
CallExpression(path) {
|
|
9854
10385
|
if (!t18.isMemberExpression(path.node.callee)) return;
|
|
@@ -9897,7 +10428,7 @@ function replaceMapInConditionalSlots(slots, arrayMap, renderMethodName) {
|
|
|
9897
10428
|
for (const expr of [slot.truthyHtmlExpr, slot.falsyHtmlExpr]) {
|
|
9898
10429
|
if (!expr) continue;
|
|
9899
10430
|
const tempProg = t18.program([t18.expressionStatement(expr)]);
|
|
9900
|
-
|
|
10431
|
+
traverse11(tempProg, {
|
|
9901
10432
|
noScope: true,
|
|
9902
10433
|
CallExpression(path) {
|
|
9903
10434
|
if (!t18.isMemberExpression(path.node.callee)) return;
|
|
@@ -9962,15 +10493,7 @@ function generateRerenderObserver(pathParts, storeVar, truthinessOnly) {
|
|
|
9962
10493
|
}
|
|
9963
10494
|
method.body.body.push(
|
|
9964
10495
|
t18.ifStatement(
|
|
9965
|
-
t18.
|
|
9966
|
-
"&&",
|
|
9967
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier("rendered_")),
|
|
9968
|
-
t18.binaryExpression(
|
|
9969
|
-
"===",
|
|
9970
|
-
t18.unaryExpression("typeof", t18.memberExpression(t18.thisExpression(), t18.identifier("__geaRequestRender"))),
|
|
9971
|
-
t18.stringLiteral("function")
|
|
9972
|
-
)
|
|
9973
|
-
),
|
|
10496
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("rendered_")),
|
|
9974
10497
|
t18.blockStatement([
|
|
9975
10498
|
t18.expressionStatement(
|
|
9976
10499
|
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier("__geaRequestRender")), [])
|
|
@@ -10048,12 +10571,7 @@ function generateStateChildSwapMethod(classBody2, stateChildSlots) {
|
|
|
10048
10571
|
t18.memberExpression(t18.thisExpression(), t18.identifier(slot.childInstanceVar)),
|
|
10049
10572
|
t18.identifier("__geaUpdateProps")
|
|
10050
10573
|
),
|
|
10051
|
-
[
|
|
10052
|
-
t18.callExpression(
|
|
10053
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(buildPropsName)),
|
|
10054
|
-
[]
|
|
10055
|
-
)
|
|
10056
|
-
]
|
|
10574
|
+
[t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(buildPropsName)), [])]
|
|
10057
10575
|
)
|
|
10058
10576
|
);
|
|
10059
10577
|
}).filter(Boolean);
|
|
@@ -10086,7 +10604,7 @@ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
|
10086
10604
|
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
10087
10605
|
import { createRequire as createRequire12 } from "module";
|
|
10088
10606
|
var require13 = createRequire12(import.meta.url);
|
|
10089
|
-
var
|
|
10607
|
+
var traverse12 = require13("@babel/traverse").default;
|
|
10090
10608
|
function resolveImportPath2(importer, source) {
|
|
10091
10609
|
const base = resolve2(dirname2(importer), source);
|
|
10092
10610
|
const candidates = [
|
|
@@ -10113,8 +10631,8 @@ function isPrivateName(name) {
|
|
|
10113
10631
|
function extractGetterStatePaths(method) {
|
|
10114
10632
|
if (!t19.isBlockStatement(method.body)) return null;
|
|
10115
10633
|
const paths = /* @__PURE__ */ new Map();
|
|
10116
|
-
const
|
|
10117
|
-
|
|
10634
|
+
const program10 = t19.program(method.body.body.map((stmt) => t19.cloneNode(stmt, true)));
|
|
10635
|
+
traverse12(program10, {
|
|
10118
10636
|
noScope: true,
|
|
10119
10637
|
MemberExpression(path) {
|
|
10120
10638
|
const node = path.node;
|
|
@@ -10154,7 +10672,7 @@ function analyzeStoreFile(filePath) {
|
|
|
10154
10672
|
const parsed = parseSource(source);
|
|
10155
10673
|
if (!parsed?.ast) return null;
|
|
10156
10674
|
const result = /* @__PURE__ */ new Map();
|
|
10157
|
-
|
|
10675
|
+
traverse12(parsed.ast, {
|
|
10158
10676
|
ClassDeclaration(classPath) {
|
|
10159
10677
|
if (!classPath.node.superClass || !t19.isIdentifier(classPath.node.superClass) || classPath.node.superClass.name !== "Store") {
|
|
10160
10678
|
return;
|
|
@@ -10211,7 +10729,7 @@ function getStoreFields(filePath) {
|
|
|
10211
10729
|
const parsed = parseSource(source);
|
|
10212
10730
|
if (!parsed?.ast) return null;
|
|
10213
10731
|
const fields = /* @__PURE__ */ new Set();
|
|
10214
|
-
|
|
10732
|
+
traverse12(parsed.ast, {
|
|
10215
10733
|
ClassDeclaration(classPath) {
|
|
10216
10734
|
if (!classPath.node.superClass || !t19.isIdentifier(classPath.node.superClass) || classPath.node.superClass.name !== "Store") {
|
|
10217
10735
|
return;
|
|
@@ -10254,7 +10772,7 @@ function analyzeStoreGetters(sourceFile, storeImports) {
|
|
|
10254
10772
|
// src/transform-component.ts
|
|
10255
10773
|
import { createRequire as createRequire13 } from "module";
|
|
10256
10774
|
var require14 = createRequire13(import.meta.url);
|
|
10257
|
-
var
|
|
10775
|
+
var traverse13 = require14("@babel/traverse").default;
|
|
10258
10776
|
function transformComponentFile(ast, imports, storeImports, className, sourceFile, originalAST, compImportsUsedAsTags, knownComponentImports = /* @__PURE__ */ new Set()) {
|
|
10259
10777
|
let transformed = false;
|
|
10260
10778
|
const stateRefs = collectStateReferences(originalAST, storeImports);
|
|
@@ -10275,7 +10793,7 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
|
|
|
10275
10793
|
const compiledChildren = [];
|
|
10276
10794
|
const eventIdCounter = { value: 0 };
|
|
10277
10795
|
const preTransformAnalysis = /* @__PURE__ */ new Map();
|
|
10278
|
-
|
|
10796
|
+
traverse13(ast, {
|
|
10279
10797
|
ClassMethod(path) {
|
|
10280
10798
|
if (!t20.isIdentifier(path.node.key) || path.node.key.name !== "template") return;
|
|
10281
10799
|
const ownerClass = path.findParent((p) => t20.isClassDeclaration(p.node));
|
|
@@ -10339,7 +10857,8 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
|
|
|
10339
10857
|
elementPathToBindingId: analysis.elementPathToBindingId,
|
|
10340
10858
|
templateSetupContext: {
|
|
10341
10859
|
params: path.node.params,
|
|
10342
|
-
statements: returnIndex >= 0 ? body.slice(0, returnIndex) : []
|
|
10860
|
+
statements: returnIndex >= 0 ? body.slice(0, returnIndex) : [],
|
|
10861
|
+
earlyReturnBarrierIndex: analysis.earlyReturnBarrierIndex
|
|
10343
10862
|
},
|
|
10344
10863
|
sourceFile,
|
|
10345
10864
|
isRoot: true,
|
|
@@ -10555,7 +11074,7 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
|
|
|
10555
11074
|
}
|
|
10556
11075
|
function transformNonComponentJSX(ast, imports) {
|
|
10557
11076
|
let transformed = false;
|
|
10558
|
-
|
|
11077
|
+
traverse13(ast, {
|
|
10559
11078
|
ClassMethod(path) {
|
|
10560
11079
|
if (!t20.isIdentifier(path.node.key) || path.node.key.name !== "template") return;
|
|
10561
11080
|
const body = path.node.body.body;
|
|
@@ -10651,7 +11170,7 @@ function addJoinToMapCallsInTemplates(ast) {
|
|
|
10651
11170
|
function ensureComponentImport(ast, imports) {
|
|
10652
11171
|
if (imports.has("Component")) return;
|
|
10653
11172
|
let geaImportPath = null;
|
|
10654
|
-
|
|
11173
|
+
traverse13(ast, {
|
|
10655
11174
|
ImportDeclaration(path) {
|
|
10656
11175
|
if (path.node.source.value === "@geajs/core") {
|
|
10657
11176
|
geaImportPath = path;
|
|
@@ -10675,7 +11194,7 @@ function ensureComponentImport(ast, imports) {
|
|
|
10675
11194
|
imports.set("Component", "@geajs/core");
|
|
10676
11195
|
}
|
|
10677
11196
|
function transformRemainingJSX(ast, imports) {
|
|
10678
|
-
|
|
11197
|
+
traverse13(ast, {
|
|
10679
11198
|
noScope: true,
|
|
10680
11199
|
JSXElement(path) {
|
|
10681
11200
|
const classMethod8 = path.findParent((p) => t20.isClassMethod(p.node));
|
|
@@ -10704,13 +11223,13 @@ function transformRemainingJSX(ast, imports) {
|
|
|
10704
11223
|
import * as t21 from "@babel/types";
|
|
10705
11224
|
import { createRequire as createRequire14 } from "module";
|
|
10706
11225
|
var require15 = createRequire14(import.meta.url);
|
|
10707
|
-
var
|
|
11226
|
+
var traverse14 = require15("@babel/traverse").default;
|
|
10708
11227
|
function convertFunctionalToClass(ast, info, imports) {
|
|
10709
11228
|
let params = [t21.identifier("props")];
|
|
10710
11229
|
let templateBody = [];
|
|
10711
11230
|
let removeVarDeclPath = null;
|
|
10712
11231
|
let exportPath = null;
|
|
10713
|
-
|
|
11232
|
+
traverse14(ast, {
|
|
10714
11233
|
ExportDefaultDeclaration(path) {
|
|
10715
11234
|
exportPath = path;
|
|
10716
11235
|
const decl = path.node.declaration;
|
|
@@ -10766,16 +11285,16 @@ function convertFunctionalToClass(ast, info, imports) {
|
|
|
10766
11285
|
if (removeVarDeclPath) {
|
|
10767
11286
|
removeVarDeclPath.remove();
|
|
10768
11287
|
}
|
|
10769
|
-
const
|
|
10770
|
-
const idx =
|
|
11288
|
+
const program10 = ast.program;
|
|
11289
|
+
const idx = program10.body.indexOf(exportPath.node);
|
|
10771
11290
|
if (idx >= 0) {
|
|
10772
|
-
|
|
11291
|
+
program10.body[idx] = t21.exportDefaultDeclaration(classDecl);
|
|
10773
11292
|
}
|
|
10774
11293
|
}
|
|
10775
11294
|
function ensureComponentImport2(ast, imports) {
|
|
10776
11295
|
if (imports.get("Component")) return;
|
|
10777
11296
|
let geaImportPath = null;
|
|
10778
|
-
|
|
11297
|
+
traverse14(ast, {
|
|
10779
11298
|
ImportDeclaration(path) {
|
|
10780
11299
|
if (path.node.source.value === "@geajs/core") {
|
|
10781
11300
|
geaImportPath = path;
|
|
@@ -10802,8 +11321,8 @@ import { dirname as dirname3, relative, resolve as resolve3 } from "path";
|
|
|
10802
11321
|
import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
10803
11322
|
import { fileURLToPath } from "url";
|
|
10804
11323
|
var pluginDir = dirname3(fileURLToPath(import.meta.url));
|
|
10805
|
-
var
|
|
10806
|
-
var
|
|
11324
|
+
var traverse15 = typeof babelTraverse2.default === "function" ? babelTraverse2.default : babelTraverse2;
|
|
11325
|
+
var generate3 = typeof babelGenerator2.default === "function" ? babelGenerator2.default : babelGenerator2;
|
|
10807
11326
|
var RECONCILE_ID = "virtual:gea-reconcile";
|
|
10808
11327
|
var RESOLVED_RECONCILE_ID = "\0" + RECONCILE_ID;
|
|
10809
11328
|
var HMR_RUNTIME_ID = "virtual:gea-hmr";
|
|
@@ -11141,7 +11660,7 @@ function geaPlugin() {
|
|
|
11141
11660
|
convertFunctionalToClass(ast, functionalComponentInfo, imports);
|
|
11142
11661
|
componentClassName = functionalComponentInfo.name;
|
|
11143
11662
|
componentClassNames = [functionalComponentInfo.name];
|
|
11144
|
-
const freshCode =
|
|
11663
|
+
const freshCode = generate3(ast, { retainLines: true }).code;
|
|
11145
11664
|
const freshParsed = parseSource(freshCode);
|
|
11146
11665
|
if (freshParsed) {
|
|
11147
11666
|
ast = freshParsed.ast;
|
|
@@ -11163,7 +11682,7 @@ function geaPlugin() {
|
|
|
11163
11682
|
const storeImports = /* @__PURE__ */ new Map();
|
|
11164
11683
|
const knownComponentImports = /* @__PURE__ */ new Set();
|
|
11165
11684
|
const namedImportSources = /* @__PURE__ */ new Map();
|
|
11166
|
-
|
|
11685
|
+
traverse15(ast, {
|
|
11167
11686
|
ExportDefaultDeclaration() {
|
|
11168
11687
|
isDefaultExport = true;
|
|
11169
11688
|
},
|
|
@@ -11234,7 +11753,7 @@ function geaPlugin() {
|
|
|
11234
11753
|
if (hmrAdded) transformed = true;
|
|
11235
11754
|
}
|
|
11236
11755
|
if (!transformed) return null;
|
|
11237
|
-
const output =
|
|
11756
|
+
const output = generate3(ast, { sourceMaps: true, sourceFileName: cleanId }, code);
|
|
11238
11757
|
return { code: output.code, map: output.map };
|
|
11239
11758
|
} catch (error) {
|
|
11240
11759
|
if (error?.__geaCompileError) {
|