@geajs/vite-plugin 1.0.4 → 1.0.5
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 +960 -683
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -632,6 +632,17 @@ function replacePropRefsInNode(node, propNames, wholeParamName, propDefaults) {
|
|
|
632
632
|
}
|
|
633
633
|
return node;
|
|
634
634
|
}
|
|
635
|
+
function loggingCatchClause(extra = []) {
|
|
636
|
+
return t2.catchClause(
|
|
637
|
+
t2.identifier("__err"),
|
|
638
|
+
t2.blockStatement([
|
|
639
|
+
t2.expressionStatement(
|
|
640
|
+
t2.callExpression(t2.memberExpression(t2.identifier("console"), t2.identifier("error")), [t2.identifier("__err")])
|
|
641
|
+
),
|
|
642
|
+
...extra
|
|
643
|
+
])
|
|
644
|
+
);
|
|
645
|
+
}
|
|
635
646
|
|
|
636
647
|
// src/hmr.ts
|
|
637
648
|
import { createRequire as createRequire2 } from "module";
|
|
@@ -781,6 +792,14 @@ function resolveExpr(expr, stateRefs) {
|
|
|
781
792
|
}
|
|
782
793
|
}
|
|
783
794
|
}
|
|
795
|
+
if (t4.isTemplateLiteral(expr)) {
|
|
796
|
+
for (const inner of expr.expressions) {
|
|
797
|
+
if (t4.isExpression(inner)) {
|
|
798
|
+
const result = resolveExpr(inner, stateRefs);
|
|
799
|
+
if (result?.parts?.length) return result;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
784
803
|
return null;
|
|
785
804
|
}
|
|
786
805
|
function applyImportedState(binding, result, stateProps) {
|
|
@@ -1973,8 +1992,24 @@ function collectTextChildren(node, stateRefs, stateProps) {
|
|
|
1973
1992
|
const expr = child.expression;
|
|
1974
1993
|
const isMap = t7.isCallExpression(expr) && t7.isMemberExpression(expr.callee) && t7.isIdentifier(expr.callee.property) && expr.callee.property.name === "map";
|
|
1975
1994
|
if (!isMap) {
|
|
1976
|
-
|
|
1977
|
-
|
|
1995
|
+
if (t7.isTemplateLiteral(expr)) {
|
|
1996
|
+
for (let i = 0; i < expr.quasis.length; i++) {
|
|
1997
|
+
const quasi = expr.quasis[i];
|
|
1998
|
+
if (quasi.value.raw) {
|
|
1999
|
+
textChildren.push({ type: "text", value: quasi.value.raw });
|
|
2000
|
+
}
|
|
2001
|
+
if (i < expr.expressions.length) {
|
|
2002
|
+
const innerExpr = expr.expressions[i];
|
|
2003
|
+
if (t7.isExpression(innerExpr)) {
|
|
2004
|
+
textChildren.push({ type: "expression", expression: innerExpr });
|
|
2005
|
+
hasExpr = true;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
} else {
|
|
2010
|
+
textChildren.push({ type: "expression", expression: expr });
|
|
2011
|
+
hasExpr = true;
|
|
2012
|
+
}
|
|
1978
2013
|
}
|
|
1979
2014
|
}
|
|
1980
2015
|
});
|
|
@@ -2676,8 +2711,12 @@ function collectAllStateAccesses(templateMethod, stateRefs, stateProps) {
|
|
|
2676
2711
|
Identifier(path) {
|
|
2677
2712
|
if (!stateRefs.has(path.node.name)) return;
|
|
2678
2713
|
const ref = stateRefs.get(path.node.name);
|
|
2679
|
-
if (path.parentPath && t7.isMemberExpression(path.parentPath.node) && path.parentPath.node.object === path.node)
|
|
2680
|
-
|
|
2714
|
+
if (path.parentPath && t7.isMemberExpression(path.parentPath.node) && path.parentPath.node.object === path.node && t7.isIdentifier(path.parentPath.node.property) && !path.parentPath.node.computed) {
|
|
2715
|
+
const grandParent = path.parentPath.parentPath;
|
|
2716
|
+
if (!(grandParent && t7.isCallExpression(grandParent.node) && grandParent.node.callee === path.parentPath.node)) {
|
|
2717
|
+
return;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2681
2720
|
if (ref.kind === "local-destructured" && ref.propName) {
|
|
2682
2721
|
const observeKey = buildObserveKey([ref.propName]);
|
|
2683
2722
|
if (!stateProps.has(observeKey)) stateProps.set(observeKey, [ref.propName]);
|
|
@@ -2686,11 +2725,8 @@ function collectAllStateAccesses(templateMethod, stateRefs, stateProps) {
|
|
|
2686
2725
|
if (ref.kind === "imported-destructured" && ref.propName && ref.storeVar) {
|
|
2687
2726
|
const storeRef = stateRefs.get(ref.storeVar);
|
|
2688
2727
|
if (storeRef?.getterDeps?.has(ref.propName)) {
|
|
2689
|
-
const
|
|
2690
|
-
|
|
2691
|
-
const observeKey = buildObserveKey(depPath, ref.storeVar);
|
|
2692
|
-
if (!stateProps.has(observeKey)) stateProps.set(observeKey, [...depPath]);
|
|
2693
|
-
}
|
|
2728
|
+
const observeKey = buildObserveKey([ref.propName], ref.storeVar);
|
|
2729
|
+
if (!stateProps.has(observeKey)) stateProps.set(observeKey, [ref.propName]);
|
|
2694
2730
|
} else if (storeRef?.reactiveFields?.has(ref.propName)) {
|
|
2695
2731
|
const observeKey = buildObserveKey([ref.propName], ref.storeVar);
|
|
2696
2732
|
if (!stateProps.has(observeKey)) stateProps.set(observeKey, [ref.propName]);
|
|
@@ -3146,6 +3182,51 @@ function pascalToKebabCase(tagName) {
|
|
|
3146
3182
|
function camelToKebab2(name) {
|
|
3147
3183
|
return name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
3148
3184
|
}
|
|
3185
|
+
function tryStaticClassObjectToString(expr) {
|
|
3186
|
+
const parts = [];
|
|
3187
|
+
for (const prop of expr.properties) {
|
|
3188
|
+
if (!t9.isObjectProperty(prop) || prop.computed) return null;
|
|
3189
|
+
const key = t9.isIdentifier(prop.key) ? prop.key.name : t9.isStringLiteral(prop.key) ? prop.key.value : null;
|
|
3190
|
+
if (!key) return null;
|
|
3191
|
+
if (t9.isBooleanLiteral(prop.value)) {
|
|
3192
|
+
if (prop.value.value) parts.push(key);
|
|
3193
|
+
} else {
|
|
3194
|
+
return null;
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
return parts.join(" ");
|
|
3198
|
+
}
|
|
3199
|
+
function buildClassObjectExpression(expr) {
|
|
3200
|
+
return t9.callExpression(
|
|
3201
|
+
t9.memberExpression(
|
|
3202
|
+
t9.callExpression(
|
|
3203
|
+
t9.memberExpression(
|
|
3204
|
+
t9.callExpression(
|
|
3205
|
+
t9.memberExpression(
|
|
3206
|
+
t9.callExpression(t9.memberExpression(t9.identifier("Object"), t9.identifier("entries")), [expr]),
|
|
3207
|
+
t9.identifier("filter")
|
|
3208
|
+
),
|
|
3209
|
+
[
|
|
3210
|
+
t9.arrowFunctionExpression(
|
|
3211
|
+
[t9.arrayPattern([t9.identifier("__k"), t9.identifier("__v")])],
|
|
3212
|
+
t9.identifier("__v")
|
|
3213
|
+
)
|
|
3214
|
+
]
|
|
3215
|
+
),
|
|
3216
|
+
t9.identifier("map")
|
|
3217
|
+
),
|
|
3218
|
+
[
|
|
3219
|
+
t9.arrowFunctionExpression(
|
|
3220
|
+
[t9.arrayPattern([t9.identifier("__k")])],
|
|
3221
|
+
t9.identifier("__k")
|
|
3222
|
+
)
|
|
3223
|
+
]
|
|
3224
|
+
),
|
|
3225
|
+
t9.identifier("join")
|
|
3226
|
+
),
|
|
3227
|
+
[t9.stringLiteral(" ")]
|
|
3228
|
+
);
|
|
3229
|
+
}
|
|
3149
3230
|
function tryStaticStyleObjectToCSS(expr) {
|
|
3150
3231
|
const parts = [];
|
|
3151
3232
|
for (const prop of expr.properties) {
|
|
@@ -3223,20 +3304,20 @@ function extractHtmlTemplatesFromConditional(expr) {
|
|
|
3223
3304
|
}
|
|
3224
3305
|
return {};
|
|
3225
3306
|
}
|
|
3226
|
-
function
|
|
3307
|
+
function extractChildInstanceRef(expr) {
|
|
3227
3308
|
if (!t9.isLogicalExpression(expr) || expr.operator !== "&&") return null;
|
|
3228
3309
|
const right = expr.right;
|
|
3229
|
-
let
|
|
3310
|
+
let memberExpr = null;
|
|
3230
3311
|
if (t9.isTemplateLiteral(right) && right.expressions.length === 1) {
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3312
|
+
const inner = right.expressions[0];
|
|
3313
|
+
if (t9.isMemberExpression(inner)) memberExpr = inner;
|
|
3314
|
+
} else if (t9.isMemberExpression(right)) {
|
|
3315
|
+
memberExpr = right;
|
|
3234
3316
|
}
|
|
3235
|
-
if (!
|
|
3317
|
+
if (!memberExpr || !t9.isThisExpression(memberExpr.object) || !t9.isIdentifier(memberExpr.property) || !memberExpr.property.name.startsWith("_"))
|
|
3236
3318
|
return null;
|
|
3237
|
-
const
|
|
3238
|
-
|
|
3239
|
-
return { instanceVar, ensureMethod, guardExpr: expr.left };
|
|
3319
|
+
const instanceVar = memberExpr.property.name;
|
|
3320
|
+
return { instanceVar, guardExpr: expr.left };
|
|
3240
3321
|
}
|
|
3241
3322
|
function expressionMayBeFalsy(expr) {
|
|
3242
3323
|
if (t9.isLogicalExpression(expr) && expr.operator === "&&") return true;
|
|
@@ -3629,13 +3710,7 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
3629
3710
|
pushString(parts, "");
|
|
3630
3711
|
parts.push({
|
|
3631
3712
|
type: "expression",
|
|
3632
|
-
value: t9.
|
|
3633
|
-
t9.memberExpression(
|
|
3634
|
-
t9.thisExpression(),
|
|
3635
|
-
t9.identifier(`__ensureChild_${instance.instanceVar.replace(/^_/, "")}`)
|
|
3636
|
-
),
|
|
3637
|
-
[]
|
|
3638
|
-
)
|
|
3713
|
+
value: t9.memberExpression(t9.thisExpression(), t9.identifier(instance.instanceVar))
|
|
3639
3714
|
});
|
|
3640
3715
|
return;
|
|
3641
3716
|
}
|
|
@@ -3860,6 +3935,21 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
3860
3935
|
err.__geaCompileError = true;
|
|
3861
3936
|
throw err;
|
|
3862
3937
|
}
|
|
3938
|
+
if (propAttrName === "class" && t9.isObjectExpression(rawExpr)) {
|
|
3939
|
+
const staticClass = tryStaticClassObjectToString(rawExpr);
|
|
3940
|
+
if (staticClass !== null) {
|
|
3941
|
+
if (staticClass) {
|
|
3942
|
+
html += ` class="${staticClass}"`;
|
|
3943
|
+
}
|
|
3944
|
+
return;
|
|
3945
|
+
}
|
|
3946
|
+
parts.push({ type: "string", value: html });
|
|
3947
|
+
const classExpr = buildClassObjectExpression(rawExpr);
|
|
3948
|
+
parts.push({ type: "string", value: ` class="` });
|
|
3949
|
+
parts.push({ type: "expression", value: classExpr });
|
|
3950
|
+
html = '"';
|
|
3951
|
+
return;
|
|
3952
|
+
}
|
|
3863
3953
|
if (propAttrName === "style" && t9.isObjectExpression(rawExpr)) {
|
|
3864
3954
|
const staticCSS = tryStaticStyleObjectToCSS(rawExpr);
|
|
3865
3955
|
if (staticCSS) {
|
|
@@ -3892,7 +3982,7 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
3892
3982
|
parts.push({ type: "string", value: html });
|
|
3893
3983
|
const expr = transformJSXExpression(rawExpr, ctx);
|
|
3894
3984
|
const skipCondition = buildAttrSkipCondition(expr, rawExpr);
|
|
3895
|
-
const templateExpr =
|
|
3985
|
+
const templateExpr = expr;
|
|
3896
3986
|
if (t9.isBooleanLiteral(skipCondition) && !skipCondition.value) {
|
|
3897
3987
|
parts.push({ type: "string", value: ` ${propAttrName}="` });
|
|
3898
3988
|
parts.push({ type: "expression", value: templateExpr });
|
|
@@ -4000,7 +4090,7 @@ function processChildren(children, parts, ctx, elementPath, dcCursor, directChil
|
|
|
4000
4090
|
let expr = transformJSXExpression(rawExpr, ctx);
|
|
4001
4091
|
const stateSlots = ctx.stateChildSlots;
|
|
4002
4092
|
const stateCounter = ctx.stateChildSlotCounter;
|
|
4003
|
-
const childCallInfo = stateSlots && stateCounter && expressionMayBeFalsy(rawExpr) ?
|
|
4093
|
+
const childCallInfo = stateSlots && stateCounter && expressionMayBeFalsy(rawExpr) ? extractChildInstanceRef(expr) : null;
|
|
4004
4094
|
if (childCallInfo && stateSlots && stateCounter) {
|
|
4005
4095
|
const markerId = `sc${stateCounter.value}`;
|
|
4006
4096
|
stateCounter.value++;
|
|
@@ -4008,7 +4098,6 @@ function processChildren(children, parts, ctx, elementPath, dcCursor, directChil
|
|
|
4008
4098
|
stateSlots.push({
|
|
4009
4099
|
markerId,
|
|
4010
4100
|
childInstanceVar: childCallInfo.instanceVar,
|
|
4011
|
-
ensureMethodName: childCallInfo.ensureMethod,
|
|
4012
4101
|
guardExpr: childCallInfo.guardExpr,
|
|
4013
4102
|
dependencies: collectExpressionDependencies(childCallInfo.guardExpr, ctx.stateRefs, setupStatements)
|
|
4014
4103
|
});
|
|
@@ -4120,7 +4209,11 @@ function ensureMapItemHelper(classBody2, ctx, helperName) {
|
|
|
4120
4209
|
if (ctx.arrayPathParts.length === 0) return base;
|
|
4121
4210
|
const [, ...rest] = ctx.arrayPathParts;
|
|
4122
4211
|
const isIndex = /^\d+$/.test(first);
|
|
4123
|
-
const optionalFirst = t10.
|
|
4212
|
+
const optionalFirst = ctx.isImportedState ? t10.memberExpression(
|
|
4213
|
+
base,
|
|
4214
|
+
isIndex ? t10.numericLiteral(Number(first)) : t10.identifier(first),
|
|
4215
|
+
isIndex
|
|
4216
|
+
) : t10.optionalMemberExpression(
|
|
4124
4217
|
base,
|
|
4125
4218
|
isIndex ? t10.numericLiteral(Number(first)) : t10.identifier(first),
|
|
4126
4219
|
isIndex,
|
|
@@ -4472,7 +4565,7 @@ function findClassMethod(classBody2, name) {
|
|
|
4472
4565
|
|
|
4473
4566
|
// src/generate-components.ts
|
|
4474
4567
|
import * as t11 from "@babel/types";
|
|
4475
|
-
import { appendToBody, id as id4,
|
|
4568
|
+
import { appendToBody, id as id4, jsMethod as jsMethod2 } from "eszter";
|
|
4476
4569
|
import { createRequire as createRequire6 } from "module";
|
|
4477
4570
|
function childHasNoProps(child) {
|
|
4478
4571
|
return t11.isObjectExpression(child.propsExpression) && child.propsExpression.properties.length === 0;
|
|
@@ -4496,7 +4589,8 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
|
|
|
4496
4589
|
if (componentInstances.size === 0) return;
|
|
4497
4590
|
const childComponents = Array.from(componentInstances.values()).flat();
|
|
4498
4591
|
const constructionOrder = [...childComponents].sort((a, b) => (b.dfsIndex ?? 0) - (a.dfsIndex ?? 0));
|
|
4499
|
-
const instanceStatements = buildInstanceStatements(constructionOrder);
|
|
4592
|
+
const instanceStatements = buildInstanceStatements(constructionOrder, directForwardingChildren);
|
|
4593
|
+
const lazyChildren = constructionOrder.filter((child) => child.lazy);
|
|
4500
4594
|
let injected = false;
|
|
4501
4595
|
traverse5(ast, {
|
|
4502
4596
|
ClassDeclaration(path) {
|
|
@@ -4516,17 +4610,63 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
|
|
|
4516
4610
|
path.node.body.body.unshift(ctor);
|
|
4517
4611
|
injected = true;
|
|
4518
4612
|
}
|
|
4613
|
+
for (const child of lazyChildren) {
|
|
4614
|
+
const isDirect = directForwardingChildren?.has(child.instanceVar);
|
|
4615
|
+
const noProps = childHasNoProps(child);
|
|
4616
|
+
const hasPropsBuilder = !isDirect && !noProps;
|
|
4617
|
+
const backingField = `__lazy${child.instanceVar}`;
|
|
4618
|
+
let propsArg;
|
|
4619
|
+
if (hasPropsBuilder) {
|
|
4620
|
+
propsArg = t11.callExpression(
|
|
4621
|
+
t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
|
|
4622
|
+
[]
|
|
4623
|
+
);
|
|
4624
|
+
} else if (child.directMappings && child.directMappings.length > 0) {
|
|
4625
|
+
propsArg = t11.objectExpression(
|
|
4626
|
+
child.directMappings.map(
|
|
4627
|
+
(m) => t11.objectProperty(
|
|
4628
|
+
t11.identifier(m.childPropName),
|
|
4629
|
+
t11.memberExpression(
|
|
4630
|
+
t11.memberExpression(t11.thisExpression(), t11.identifier("props")),
|
|
4631
|
+
t11.identifier(m.parentPropName)
|
|
4632
|
+
)
|
|
4633
|
+
)
|
|
4634
|
+
)
|
|
4635
|
+
);
|
|
4636
|
+
} else {
|
|
4637
|
+
propsArg = t11.objectExpression([]);
|
|
4638
|
+
}
|
|
4639
|
+
const getter = t11.classMethod(
|
|
4640
|
+
"get",
|
|
4641
|
+
t11.identifier(child.instanceVar),
|
|
4642
|
+
[],
|
|
4643
|
+
t11.blockStatement([
|
|
4644
|
+
t11.ifStatement(
|
|
4645
|
+
t11.unaryExpression("!", t11.memberExpression(t11.thisExpression(), t11.identifier(backingField))),
|
|
4646
|
+
t11.expressionStatement(
|
|
4647
|
+
t11.assignmentExpression(
|
|
4648
|
+
"=",
|
|
4649
|
+
t11.memberExpression(t11.thisExpression(), t11.identifier(backingField)),
|
|
4650
|
+
t11.callExpression(t11.memberExpression(t11.thisExpression(), t11.identifier("__child")), [
|
|
4651
|
+
t11.identifier(child.tagName),
|
|
4652
|
+
propsArg
|
|
4653
|
+
])
|
|
4654
|
+
)
|
|
4655
|
+
)
|
|
4656
|
+
),
|
|
4657
|
+
t11.returnStatement(t11.memberExpression(t11.thisExpression(), t11.identifier(backingField)))
|
|
4658
|
+
])
|
|
4659
|
+
);
|
|
4660
|
+
path.node.body.body.push(getter);
|
|
4661
|
+
}
|
|
4519
4662
|
childComponents.forEach((child) => {
|
|
4520
4663
|
const isDirect = directForwardingChildren?.has(child.instanceVar);
|
|
4521
4664
|
const noProps = childHasNoProps(child);
|
|
4522
4665
|
const hasPropsBuilder = !isDirect && !noProps;
|
|
4523
4666
|
if (hasPropsBuilder) {
|
|
4524
4667
|
path.node.body.body.push(buildPropsBuilderMethod(child));
|
|
4525
|
-
path.node.body.body.push(buildRefreshMethod(child));
|
|
4526
4668
|
}
|
|
4527
|
-
path.node.body.body.push(buildEnsureMethod(child, hasPropsBuilder));
|
|
4528
4669
|
});
|
|
4529
|
-
ensureDisposeMethod(path.node.body, childComponents);
|
|
4530
4670
|
}
|
|
4531
4671
|
});
|
|
4532
4672
|
}
|
|
@@ -4545,19 +4685,52 @@ function injectComponentRegistrations(ast, componentInstances) {
|
|
|
4545
4685
|
}
|
|
4546
4686
|
});
|
|
4547
4687
|
}
|
|
4548
|
-
function buildInstanceStatements(instances) {
|
|
4688
|
+
function buildInstanceStatements(instances, directForwardingChildren) {
|
|
4549
4689
|
const stmts = [];
|
|
4550
4690
|
instances.forEach((child) => {
|
|
4551
|
-
|
|
4691
|
+
if (child.lazy) return;
|
|
4692
|
+
let propsArg;
|
|
4693
|
+
const isDirect = directForwardingChildren?.has(child.instanceVar);
|
|
4694
|
+
const noProps = childHasNoProps(child);
|
|
4695
|
+
const hasPropsBuilder = !isDirect && !noProps;
|
|
4696
|
+
if (hasPropsBuilder) {
|
|
4697
|
+
propsArg = t11.callExpression(
|
|
4698
|
+
t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
|
|
4699
|
+
[]
|
|
4700
|
+
);
|
|
4701
|
+
} else if (child.directMappings && child.directMappings.length > 0) {
|
|
4702
|
+
propsArg = t11.objectExpression(
|
|
4703
|
+
child.directMappings.map(
|
|
4704
|
+
(m) => t11.objectProperty(
|
|
4705
|
+
t11.identifier(m.childPropName),
|
|
4706
|
+
t11.memberExpression(
|
|
4707
|
+
t11.memberExpression(t11.thisExpression(), t11.identifier("props")),
|
|
4708
|
+
t11.identifier(m.parentPropName)
|
|
4709
|
+
)
|
|
4710
|
+
)
|
|
4711
|
+
)
|
|
4712
|
+
);
|
|
4713
|
+
} else {
|
|
4714
|
+
propsArg = t11.objectExpression([]);
|
|
4715
|
+
}
|
|
4716
|
+
stmts.push(
|
|
4717
|
+
t11.expressionStatement(
|
|
4718
|
+
t11.assignmentExpression(
|
|
4719
|
+
"=",
|
|
4720
|
+
t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)),
|
|
4721
|
+
t11.callExpression(t11.memberExpression(t11.thisExpression(), t11.identifier("__child")), [
|
|
4722
|
+
t11.identifier(child.tagName),
|
|
4723
|
+
propsArg
|
|
4724
|
+
])
|
|
4725
|
+
)
|
|
4726
|
+
)
|
|
4727
|
+
);
|
|
4552
4728
|
});
|
|
4553
4729
|
return stmts;
|
|
4554
4730
|
}
|
|
4555
4731
|
function getPropsBuilderMethodName(child) {
|
|
4556
4732
|
return `__buildProps_${child.instanceVar.replace(/^_/, "")}`;
|
|
4557
4733
|
}
|
|
4558
|
-
function getEnsureChildMethodName(child) {
|
|
4559
|
-
return `__ensureChild_${child.instanceVar.replace(/^_/, "")}`;
|
|
4560
|
-
}
|
|
4561
4734
|
function collectBindingNames(stmt) {
|
|
4562
4735
|
if (t11.isVariableDeclaration(stmt)) {
|
|
4563
4736
|
const names = [];
|
|
@@ -4621,102 +4794,15 @@ function buildPropsBuilderMethod(child) {
|
|
|
4621
4794
|
);
|
|
4622
4795
|
if (hasPropsDestructure) {
|
|
4623
4796
|
const tryBlock = t11.blockStatement([...prunedSetup, returnStmt]);
|
|
4624
|
-
const
|
|
4625
|
-
const tryCatch = t11.tryStatement(tryBlock, t11.catchClause(null, catchBlock));
|
|
4797
|
+
const tryCatch = t11.tryStatement(tryBlock, loggingCatchClause([t11.returnStatement(t11.objectExpression([]))]));
|
|
4626
4798
|
return appendToBody(jsMethod2`${id4(getPropsBuilderMethodName(child))}() {}`, tryCatch);
|
|
4627
4799
|
}
|
|
4628
4800
|
return appendToBody(jsMethod2`${id4(getPropsBuilderMethodName(child))}() {}`, ...prunedSetup, returnStmt);
|
|
4629
4801
|
}
|
|
4630
|
-
function buildEnsureMethod(child, hasPropsBuilder = true) {
|
|
4631
|
-
let propsArg;
|
|
4632
|
-
if (hasPropsBuilder && !childHasNoProps(child)) {
|
|
4633
|
-
propsArg = t11.callExpression(
|
|
4634
|
-
t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
|
|
4635
|
-
[]
|
|
4636
|
-
);
|
|
4637
|
-
} else if (child.directMappings && child.directMappings.length > 0) {
|
|
4638
|
-
propsArg = t11.objectExpression(
|
|
4639
|
-
child.directMappings.map(
|
|
4640
|
-
(m) => t11.objectProperty(
|
|
4641
|
-
t11.identifier(m.childPropName),
|
|
4642
|
-
t11.memberExpression(
|
|
4643
|
-
t11.memberExpression(t11.thisExpression(), t11.identifier("props")),
|
|
4644
|
-
t11.identifier(m.parentPropName)
|
|
4645
|
-
)
|
|
4646
|
-
)
|
|
4647
|
-
)
|
|
4648
|
-
);
|
|
4649
|
-
} else {
|
|
4650
|
-
propsArg = t11.objectExpression([]);
|
|
4651
|
-
}
|
|
4652
|
-
const refreshPropsStmt = hasPropsBuilder && !childHasNoProps(child) ? t11.expressionStatement(
|
|
4653
|
-
t11.callExpression(
|
|
4654
|
-
t11.memberExpression(
|
|
4655
|
-
t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)),
|
|
4656
|
-
t11.identifier("__geaUpdateProps")
|
|
4657
|
-
),
|
|
4658
|
-
[
|
|
4659
|
-
t11.callExpression(
|
|
4660
|
-
t11.memberExpression(t11.thisExpression(), t11.identifier(getPropsBuilderMethodName(child))),
|
|
4661
|
-
[]
|
|
4662
|
-
)
|
|
4663
|
-
]
|
|
4664
|
-
)
|
|
4665
|
-
) : null;
|
|
4666
|
-
return appendToBody(
|
|
4667
|
-
jsMethod2`${id4(getEnsureChildMethodName(child))}() {}`,
|
|
4668
|
-
t11.ifStatement(
|
|
4669
|
-
t11.unaryExpression("!", t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar))),
|
|
4670
|
-
t11.blockStatement([
|
|
4671
|
-
t11.expressionStatement(
|
|
4672
|
-
t11.assignmentExpression(
|
|
4673
|
-
"=",
|
|
4674
|
-
t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)),
|
|
4675
|
-
t11.newExpression(t11.identifier(child.tagName), [propsArg])
|
|
4676
|
-
)
|
|
4677
|
-
),
|
|
4678
|
-
js2`this.${id4(child.instanceVar)}.parentComponent = this;`,
|
|
4679
|
-
js2`this.${id4(child.instanceVar)}.__geaCompiledChild = true;`
|
|
4680
|
-
]),
|
|
4681
|
-
refreshPropsStmt ? t11.blockStatement([refreshPropsStmt]) : void 0
|
|
4682
|
-
),
|
|
4683
|
-
t11.returnStatement(t11.memberExpression(t11.thisExpression(), t11.identifier(child.instanceVar)))
|
|
4684
|
-
);
|
|
4685
|
-
}
|
|
4686
|
-
function buildRefreshMethod(child) {
|
|
4687
|
-
const method = jsMethod2`${id4(`__refreshChildProps_${child.instanceVar.replace(/^_/, "")}`)}() {}`;
|
|
4688
|
-
method.body.body.push(js2`const child = this.${id4(child.instanceVar)};`);
|
|
4689
|
-
if (child.lazy) {
|
|
4690
|
-
method.body.body.push(
|
|
4691
|
-
t11.ifStatement(t11.unaryExpression("!", t11.identifier("child")), t11.blockStatement([t11.returnStatement()]))
|
|
4692
|
-
);
|
|
4693
|
-
} else {
|
|
4694
|
-
method.body.body.push(
|
|
4695
|
-
t11.ifStatement(t11.unaryExpression("!", t11.identifier("child")), t11.blockStatement([t11.returnStatement()]))
|
|
4696
|
-
);
|
|
4697
|
-
}
|
|
4698
|
-
method.body.body.push(
|
|
4699
|
-
js2`child.__geaUpdateProps(this.${id4(getPropsBuilderMethodName(child))}());`
|
|
4700
|
-
);
|
|
4701
|
-
return method;
|
|
4702
|
-
}
|
|
4703
|
-
function ensureDisposeMethod(classBody2, children) {
|
|
4704
|
-
const disposeCalls = children.map((child) => js2`this.${id4(child.instanceVar)}?.dispose?.();`);
|
|
4705
|
-
const existingDispose = classBody2.body.find(
|
|
4706
|
-
(member) => t11.isClassMethod(member) && t11.isIdentifier(member.key) && member.key.name === "dispose"
|
|
4707
|
-
);
|
|
4708
|
-
if (existingDispose) {
|
|
4709
|
-
existingDispose.body.body.unshift(...disposeCalls);
|
|
4710
|
-
return;
|
|
4711
|
-
}
|
|
4712
|
-
classBody2.body.push(
|
|
4713
|
-
appendToBody(jsMethod2`${id4("dispose")}() {}`, ...disposeCalls, js2`super.dispose();`)
|
|
4714
|
-
);
|
|
4715
|
-
}
|
|
4716
4802
|
|
|
4717
4803
|
// src/apply-reactivity.ts
|
|
4718
4804
|
import * as t18 from "@babel/types";
|
|
4719
|
-
import { appendToBody as appendToBody5, id as id11, js as js7, jsBlockBody as
|
|
4805
|
+
import { appendToBody as appendToBody5, id as id11, js as js7, jsBlockBody as jsBlockBody4, jsExpr as jsExpr4, jsMethod as jsMethod8 } from "eszter";
|
|
4720
4806
|
|
|
4721
4807
|
// src/generate-observe.ts
|
|
4722
4808
|
import * as t13 from "@babel/types";
|
|
@@ -4774,8 +4860,8 @@ function buildValueExpression(textExpr, stateRefs) {
|
|
|
4774
4860
|
if (textExpr.isImportedState && textExpr.storeVar) {
|
|
4775
4861
|
return buildMemberChainFromParts(
|
|
4776
4862
|
t12.memberExpression(
|
|
4777
|
-
t12.
|
|
4778
|
-
t12.identifier(
|
|
4863
|
+
t12.identifier(textExpr.storeVar),
|
|
4864
|
+
t12.identifier("__store")
|
|
4779
4865
|
),
|
|
4780
4866
|
textExpr.pathParts
|
|
4781
4867
|
);
|
|
@@ -4793,13 +4879,27 @@ function rewriteStateRefs(expr, stateRefs) {
|
|
|
4793
4879
|
const ref = stateRefs.get(path.node.name);
|
|
4794
4880
|
if (ref.kind === "local") {
|
|
4795
4881
|
path.replaceWith(t12.thisExpression());
|
|
4882
|
+
} else if (ref.kind === "imported-destructured" && ref.storeVar && ref.propName) {
|
|
4883
|
+
path.replaceWith(
|
|
4884
|
+
t12.memberExpression(
|
|
4885
|
+
t12.memberExpression(t12.identifier(ref.storeVar), t12.identifier("__store")),
|
|
4886
|
+
t12.identifier(ref.propName)
|
|
4887
|
+
)
|
|
4888
|
+
);
|
|
4889
|
+
path.skip();
|
|
4890
|
+
} else if (ref.kind === "local-destructured" && ref.propName) {
|
|
4891
|
+
path.replaceWith(
|
|
4892
|
+
t12.memberExpression(t12.thisExpression(), t12.identifier(ref.propName))
|
|
4893
|
+
);
|
|
4894
|
+
path.skip();
|
|
4796
4895
|
} else {
|
|
4797
4896
|
path.replaceWith(
|
|
4798
4897
|
t12.memberExpression(
|
|
4799
|
-
t12.
|
|
4800
|
-
t12.identifier(
|
|
4898
|
+
t12.identifier(path.node.name),
|
|
4899
|
+
t12.identifier("__store")
|
|
4801
4900
|
)
|
|
4802
4901
|
);
|
|
4902
|
+
path.skip();
|
|
4803
4903
|
}
|
|
4804
4904
|
}
|
|
4805
4905
|
});
|
|
@@ -4834,6 +4934,10 @@ function buildSimpleUpdate(binding, param, stateRefs) {
|
|
|
4834
4934
|
const idx = t12.numericLiteral(binding.textNodeIndex);
|
|
4835
4935
|
return js3`if (${el}) { const __tn = ${jsExpr2`${el}.childNodes[${idx}]`}; if (__tn && __tn.nodeValue !== ${valueExpr}) __tn.nodeValue = ${valueExpr}; }`;
|
|
4836
4936
|
}
|
|
4937
|
+
if (target === "textContent" && binding.bindingId && binding.bindingId !== "") {
|
|
4938
|
+
const suffix = t12.stringLiteral(binding.bindingId);
|
|
4939
|
+
return js3`${jsExpr2`this.__updateText(${suffix}, ${valueExpr})`};`;
|
|
4940
|
+
}
|
|
4837
4941
|
return js3`if (${el}) { ${jsExpr2`${el}.${id5(target)}`} = ${valueExpr}; }`;
|
|
4838
4942
|
}
|
|
4839
4943
|
function buildWildcardUpdate(binding, param, stateRefs) {
|
|
@@ -5125,6 +5229,9 @@ function buildElementNavExpr(base, childPath) {
|
|
|
5125
5229
|
}
|
|
5126
5230
|
return expr;
|
|
5127
5231
|
}
|
|
5232
|
+
function childPathRefName(path) {
|
|
5233
|
+
return `__ref_${path.join("_")}`;
|
|
5234
|
+
}
|
|
5128
5235
|
function hoistStoreReads(entries, storeVar) {
|
|
5129
5236
|
if (!storeVar) return { hoists: [], patchedEntries: entries };
|
|
5130
5237
|
const hoistMap = /* @__PURE__ */ new Map();
|
|
@@ -5362,7 +5469,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5362
5469
|
body.push(
|
|
5363
5470
|
t14.ifStatement(
|
|
5364
5471
|
t14.unaryExpression("!", t14.memberExpression(cVar, t14.identifier("__geaTpl"))),
|
|
5365
|
-
t14.blockStatement([t14.tryStatement(t14.blockStatement(tplInit),
|
|
5472
|
+
t14.blockStatement([t14.tryStatement(t14.blockStatement(tplInit), loggingCatchClause())])
|
|
5366
5473
|
)
|
|
5367
5474
|
);
|
|
5368
5475
|
if (arrayMap.containerBindingId) {
|
|
@@ -5432,8 +5539,26 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
5432
5539
|
for (const hoist of hoists) {
|
|
5433
5540
|
body.push(t14.variableDeclaration("var", [t14.variableDeclarator(t14.identifier(hoist.varName), hoist.expression)]));
|
|
5434
5541
|
}
|
|
5542
|
+
const refMap = /* @__PURE__ */ new Map();
|
|
5435
5543
|
for (const entry of patchedEntries) {
|
|
5544
|
+
if (entry.childPath.length === 0) continue;
|
|
5545
|
+
const key = entry.childPath.join("_");
|
|
5546
|
+
if (refMap.has(key)) continue;
|
|
5547
|
+
const refName = childPathRefName(entry.childPath);
|
|
5436
5548
|
const navExpr = buildElementNavExpr(elVar, entry.childPath);
|
|
5549
|
+
body.push(
|
|
5550
|
+
t14.expressionStatement(
|
|
5551
|
+
t14.assignmentExpression(
|
|
5552
|
+
"=",
|
|
5553
|
+
t14.memberExpression(elVar, t14.identifier(refName)),
|
|
5554
|
+
navExpr
|
|
5555
|
+
)
|
|
5556
|
+
)
|
|
5557
|
+
);
|
|
5558
|
+
refMap.set(key, t14.memberExpression(elVar, t14.identifier(refName)));
|
|
5559
|
+
}
|
|
5560
|
+
for (const entry of patchedEntries) {
|
|
5561
|
+
const navExpr = entry.childPath.length > 0 ? refMap.get(entry.childPath.join("_")) || buildElementNavExpr(elVar, entry.childPath) : elVar;
|
|
5437
5562
|
switch (entry.type) {
|
|
5438
5563
|
case "className":
|
|
5439
5564
|
body.push(
|
|
@@ -5799,22 +5924,25 @@ function buildPatchEntryPropPatcher(entry) {
|
|
|
5799
5924
|
const value = t15.identifier("value");
|
|
5800
5925
|
const item = t15.identifier("item");
|
|
5801
5926
|
const target = t15.identifier("__target");
|
|
5802
|
-
const targetExpr =
|
|
5927
|
+
const targetExpr = entry.childPath.length > 0 ? t15.memberExpression(row, t15.identifier(childPathRefName(entry.childPath))) : row;
|
|
5803
5928
|
if (entry.type === "className") {
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5929
|
+
const isRoot2 = entry.childPath.length === 0;
|
|
5930
|
+
const stmts2 = [];
|
|
5931
|
+
if (!isRoot2) {
|
|
5932
|
+
stmts2.push(t15.variableDeclaration("const", [t15.variableDeclarator(target, targetExpr)]));
|
|
5933
|
+
stmts2.push(t15.ifStatement(t15.unaryExpression("!", target), t15.returnStatement()));
|
|
5934
|
+
}
|
|
5935
|
+
const ref2 = isRoot2 ? row : target;
|
|
5936
|
+
stmts2.push(
|
|
5937
|
+
t15.expressionStatement(
|
|
5938
|
+
t15.assignmentExpression(
|
|
5939
|
+
"=",
|
|
5940
|
+
t15.memberExpression(ref2, t15.identifier("className")),
|
|
5941
|
+
t15.cloneNode(entry.expression, true)
|
|
5815
5942
|
)
|
|
5816
|
-
|
|
5943
|
+
)
|
|
5817
5944
|
);
|
|
5945
|
+
return t15.arrowFunctionExpression([row, value, item], t15.blockStatement(stmts2));
|
|
5818
5946
|
}
|
|
5819
5947
|
if (entry.type === "attribute") {
|
|
5820
5948
|
const attrName = entry.attributeName || "class";
|
|
@@ -5881,32 +6009,35 @@ function buildPatchEntryPropPatcher(entry) {
|
|
|
5881
6009
|
])
|
|
5882
6010
|
);
|
|
5883
6011
|
}
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
6012
|
+
const isRoot = entry.childPath.length === 0;
|
|
6013
|
+
const stmts = [];
|
|
6014
|
+
if (!isRoot) {
|
|
6015
|
+
stmts.push(t15.variableDeclaration("const", [t15.variableDeclarator(target, targetExpr)]));
|
|
6016
|
+
stmts.push(t15.ifStatement(t15.unaryExpression("!", target), t15.returnStatement()));
|
|
6017
|
+
}
|
|
6018
|
+
const ref = isRoot ? row : target;
|
|
6019
|
+
stmts.push(
|
|
6020
|
+
t15.expressionStatement(
|
|
6021
|
+
t15.logicalExpression(
|
|
6022
|
+
"||",
|
|
5890
6023
|
t15.logicalExpression(
|
|
5891
|
-
"
|
|
5892
|
-
t15.
|
|
5893
|
-
"&&",
|
|
5894
|
-
t15.memberExpression(target, t15.identifier("firstChild")),
|
|
5895
|
-
t15.assignmentExpression(
|
|
5896
|
-
"=",
|
|
5897
|
-
t15.memberExpression(t15.memberExpression(target, t15.identifier("firstChild")), t15.identifier("nodeValue")),
|
|
5898
|
-
t15.cloneNode(entry.expression, true)
|
|
5899
|
-
)
|
|
5900
|
-
),
|
|
6024
|
+
"&&",
|
|
6025
|
+
t15.memberExpression(ref, t15.identifier("firstChild")),
|
|
5901
6026
|
t15.assignmentExpression(
|
|
5902
6027
|
"=",
|
|
5903
|
-
t15.memberExpression(
|
|
6028
|
+
t15.memberExpression(t15.memberExpression(ref, t15.identifier("firstChild")), t15.identifier("nodeValue")),
|
|
5904
6029
|
t15.cloneNode(entry.expression, true)
|
|
5905
6030
|
)
|
|
6031
|
+
),
|
|
6032
|
+
t15.assignmentExpression(
|
|
6033
|
+
"=",
|
|
6034
|
+
t15.memberExpression(ref, t15.identifier("textContent")),
|
|
6035
|
+
t15.cloneNode(entry.expression, true)
|
|
5906
6036
|
)
|
|
5907
6037
|
)
|
|
5908
|
-
|
|
6038
|
+
)
|
|
5909
6039
|
);
|
|
6040
|
+
return t15.arrowFunctionExpression([row, value, item], t15.blockStatement(stmts));
|
|
5910
6041
|
}
|
|
5911
6042
|
function buildPropPatchersObject(arrayMap) {
|
|
5912
6043
|
const groups = /* @__PURE__ */ new Map();
|
|
@@ -5965,19 +6096,22 @@ function generateEnsureArrayConfigsMethod(arrayMaps) {
|
|
|
5965
6096
|
),
|
|
5966
6097
|
t15.objectProperty(
|
|
5967
6098
|
t15.identifier("render"),
|
|
5968
|
-
t15.
|
|
5969
|
-
|
|
5970
|
-
|
|
6099
|
+
t15.callExpression(
|
|
6100
|
+
t15.memberExpression(
|
|
6101
|
+
t15.memberExpression(t15.thisExpression(), t15.identifier(renderMethodName)),
|
|
6102
|
+
t15.identifier("bind")
|
|
6103
|
+
),
|
|
6104
|
+
[t15.thisExpression()]
|
|
5971
6105
|
)
|
|
5972
6106
|
),
|
|
5973
6107
|
t15.objectProperty(
|
|
5974
6108
|
t15.identifier("create"),
|
|
5975
|
-
t15.
|
|
5976
|
-
|
|
5977
|
-
t15.callExpression(
|
|
6109
|
+
t15.callExpression(
|
|
6110
|
+
t15.memberExpression(
|
|
5978
6111
|
t15.memberExpression(t15.thisExpression(), t15.identifier(createMethodName)),
|
|
5979
|
-
|
|
5980
|
-
)
|
|
6112
|
+
t15.identifier("bind")
|
|
6113
|
+
),
|
|
6114
|
+
[t15.thisExpression()]
|
|
5981
6115
|
)
|
|
5982
6116
|
)
|
|
5983
6117
|
];
|
|
@@ -6066,8 +6200,8 @@ function generateArrayConditionalPatchObserver(arrayMap, bindings, methodName) {
|
|
|
6066
6200
|
const containerRef = t15.memberExpression(t15.thisExpression(), t15.identifier(containerName));
|
|
6067
6201
|
const proxiedArr = arrayMap.isImportedState ? buildMemberChain(
|
|
6068
6202
|
t15.memberExpression(
|
|
6069
|
-
t15.
|
|
6070
|
-
t15.identifier(
|
|
6203
|
+
t15.identifier(arrayMap.storeVar || "store"),
|
|
6204
|
+
t15.identifier("__store")
|
|
6071
6205
|
),
|
|
6072
6206
|
arrayPath
|
|
6073
6207
|
) : buildMemberChain(t15.thisExpression(), arrayPath);
|
|
@@ -6127,8 +6261,8 @@ function generateArrayConditionalRerenderObserver(arrayMap, methodName) {
|
|
|
6127
6261
|
const configRef = t15.memberExpression(t15.thisExpression(), t15.identifier(getArrayConfigPropName(arrayMap)));
|
|
6128
6262
|
const proxiedArr = arrayMap.isImportedState ? buildMemberChain(
|
|
6129
6263
|
t15.memberExpression(
|
|
6130
|
-
t15.
|
|
6131
|
-
t15.identifier(
|
|
6264
|
+
t15.identifier(arrayMap.storeVar || "store"),
|
|
6265
|
+
t15.identifier("__store")
|
|
6132
6266
|
),
|
|
6133
6267
|
arrayPath
|
|
6134
6268
|
) : buildMemberChain(t15.thisExpression(), arrayPath);
|
|
@@ -6212,15 +6346,8 @@ function generateArrayConditionalRerenderObserver(arrayMap, methodName) {
|
|
|
6212
6346
|
t15.ifStatement(
|
|
6213
6347
|
t15.unaryExpression("!", t15.identifier("__skipArrayConditionalRerender")),
|
|
6214
6348
|
t15.blockStatement([
|
|
6215
|
-
t15.
|
|
6216
|
-
t15.
|
|
6217
|
-
"===",
|
|
6218
|
-
t15.unaryExpression("typeof", t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs"))),
|
|
6219
|
-
t15.stringLiteral("function")
|
|
6220
|
-
),
|
|
6221
|
-
t15.expressionStatement(
|
|
6222
|
-
t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
|
|
6223
|
-
)
|
|
6349
|
+
t15.expressionStatement(
|
|
6350
|
+
t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
|
|
6224
6351
|
),
|
|
6225
6352
|
t15.variableDeclaration("const", [
|
|
6226
6353
|
t15.variableDeclarator(
|
|
@@ -6251,7 +6378,7 @@ function buildConditionalPatchStatement(binding, target, itemVariable) {
|
|
|
6251
6378
|
return js5`${jsExpr3`${target}.textContent`} = ${expression};`;
|
|
6252
6379
|
}
|
|
6253
6380
|
if (binding.type === "className") {
|
|
6254
|
-
return js5`${jsExpr3`${target}.className`} =
|
|
6381
|
+
return js5`${jsExpr3`${target}.className`} = ${expression};`;
|
|
6255
6382
|
}
|
|
6256
6383
|
if (binding.attributeName === "style") {
|
|
6257
6384
|
return t15.blockStatement(
|
|
@@ -6291,21 +6418,19 @@ function renameItemVariable(expr, itemVariable) {
|
|
|
6291
6418
|
}
|
|
6292
6419
|
function buildRelationalClassStatements(rowExpr, bindings, isMatch, phase) {
|
|
6293
6420
|
return bindings.flatMap((binding, index) => {
|
|
6294
|
-
const targetVar = `__target_${phase}_${index}`;
|
|
6295
6421
|
const enabled = binding.classWhenMatch ? isMatch : !isMatch;
|
|
6296
|
-
const targetExpr = binding.selector === ":scope" ? t15.cloneNode(rowExpr, true) : t15.cloneNode(rowExpr, true);
|
|
6297
6422
|
if (binding.selector === ":scope") {
|
|
6423
|
+
const expr = t15.cloneNode(rowExpr, true);
|
|
6298
6424
|
return jsBlockBody3`
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
} else {
|
|
6304
|
-
${id8(targetVar)}.classList.toggle(${binding.classToggleName}, ${enabled});
|
|
6305
|
-
}
|
|
6425
|
+
if (${expr}.className === '' || ${expr}.className === ${binding.classToggleName}) {
|
|
6426
|
+
${expr}.className = ${enabled ? binding.classToggleName : ""};
|
|
6427
|
+
} else {
|
|
6428
|
+
${expr}.classList.toggle(${binding.classToggleName}, ${enabled});
|
|
6306
6429
|
}
|
|
6307
6430
|
`;
|
|
6308
6431
|
}
|
|
6432
|
+
const targetVar = `__target_${phase}_${index}`;
|
|
6433
|
+
const targetExpr = t15.cloneNode(rowExpr, true);
|
|
6309
6434
|
return jsBlockBody3`
|
|
6310
6435
|
var ${id8(targetVar)} = ${targetExpr};
|
|
6311
6436
|
if (${id8(targetVar)}) {
|
|
@@ -6365,15 +6490,8 @@ function generateArrayHandlers(arrayMap, methodName) {
|
|
|
6365
6490
|
t15.returnStatement()
|
|
6366
6491
|
])
|
|
6367
6492
|
),
|
|
6368
|
-
t15.
|
|
6369
|
-
t15.
|
|
6370
|
-
"===",
|
|
6371
|
-
t15.unaryExpression("typeof", t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs"))),
|
|
6372
|
-
t15.stringLiteral("function")
|
|
6373
|
-
),
|
|
6374
|
-
t15.expressionStatement(
|
|
6375
|
-
t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
|
|
6376
|
-
)
|
|
6493
|
+
t15.expressionStatement(
|
|
6494
|
+
t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__ensureArrayConfigs")), [])
|
|
6377
6495
|
),
|
|
6378
6496
|
t15.expressionStatement(
|
|
6379
6497
|
t15.callExpression(t15.memberExpression(t15.thisExpression(), t15.identifier("__applyListChanges")), [
|
|
@@ -6563,7 +6681,7 @@ function unwrapComparisonOperands(node) {
|
|
|
6563
6681
|
}
|
|
6564
6682
|
function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCounter, classBody2, templateSetupContext) {
|
|
6565
6683
|
const renderEventHandlers = [];
|
|
6566
|
-
if (!arrayMap.itemTemplate) return { method: null, handlers: renderEventHandlers, handlerPropsInMap: [] };
|
|
6684
|
+
if (!arrayMap.itemTemplate) return { method: null, handlers: renderEventHandlers, handlerPropsInMap: [], needsUnwrapHelper: false };
|
|
6567
6685
|
const arrayPath = pathPartsToString(arrayMap.arrayPathParts || normalizePathParts(arrayMap.arrayPath || ""));
|
|
6568
6686
|
const modified = t16.cloneNode(arrayMap.itemTemplate, true);
|
|
6569
6687
|
const handlerPropsInMap = [];
|
|
@@ -6641,7 +6759,6 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
|
|
|
6641
6759
|
const method = appendToBody4(
|
|
6642
6760
|
baseMethod,
|
|
6643
6761
|
...rewrittenSetup,
|
|
6644
|
-
...needsUnwrapHelper ? [buildValueUnwrapHelper()] : [],
|
|
6645
6762
|
...rewrittenCallbackBody,
|
|
6646
6763
|
...handlerRegStmts,
|
|
6647
6764
|
returnStmt
|
|
@@ -6665,12 +6782,12 @@ function generateRenderItemMethod(arrayMap, imports, eventHandlers, eventIdCount
|
|
|
6665
6782
|
};
|
|
6666
6783
|
});
|
|
6667
6784
|
if (eventHandlers) renderEventHandlers.forEach((h) => eventHandlers.push(h));
|
|
6668
|
-
return { method, handlers: renderEventHandlers, handlerPropsInMap };
|
|
6785
|
+
return { method, handlers: renderEventHandlers, handlerPropsInMap, needsUnwrapHelper };
|
|
6669
6786
|
}
|
|
6670
6787
|
|
|
6671
6788
|
// src/generate-array-slot-sync.ts
|
|
6672
6789
|
import * as t17 from "@babel/types";
|
|
6673
|
-
import { id as id10,
|
|
6790
|
+
import { id as id10, jsMethod as jsMethod7 } from "eszter";
|
|
6674
6791
|
import { createRequire as createRequire10 } from "module";
|
|
6675
6792
|
var require11 = createRequire10(import.meta.url);
|
|
6676
6793
|
var traverse9 = require11("@babel/traverse").default;
|
|
@@ -6689,20 +6806,14 @@ function getArrayCapName2(arrayPropName) {
|
|
|
6689
6806
|
function getComponentArrayItemsName(arrayPropName) {
|
|
6690
6807
|
return `_${arrayPropName}Items`;
|
|
6691
6808
|
}
|
|
6692
|
-
function getComponentArrayBuildMethodName(arrayPropName) {
|
|
6693
|
-
return `_build${getArrayCapName2(arrayPropName)}Items`;
|
|
6694
|
-
}
|
|
6695
6809
|
function getComponentArrayRefreshMethodName(arrayPropName) {
|
|
6696
6810
|
return `__refresh${getArrayCapName2(arrayPropName)}Items`;
|
|
6697
6811
|
}
|
|
6698
|
-
function
|
|
6699
|
-
return `__mount${getArrayCapName2(arrayPropName)}Items`;
|
|
6700
|
-
}
|
|
6701
|
-
function generateComponentArrayMethods(um, arrayPropName, imports, propNames, _classBody, storeArrayAccess, wholeParamName, templateSetupContext) {
|
|
6812
|
+
function generateComponentArrayResult(um, arrayPropName, imports, propNames, _classBody, storeArrayAccess, wholeParamName, templateSetupContext) {
|
|
6702
6813
|
const comp = isUnresolvedMapWithComponentChild(um, imports);
|
|
6703
|
-
if (!comp) return
|
|
6814
|
+
if (!comp) return null;
|
|
6704
6815
|
const itemTemplate = um.itemTemplate;
|
|
6705
|
-
if (!itemTemplate || !t17.isJSXElement(itemTemplate)) return
|
|
6816
|
+
if (!itemTemplate || !t17.isJSXElement(itemTemplate)) return null;
|
|
6706
6817
|
const mapJsxCtx = {
|
|
6707
6818
|
imports,
|
|
6708
6819
|
componentInstances: /* @__PURE__ */ new Map(),
|
|
@@ -6761,17 +6872,6 @@ function generateComponentArrayMethods(um, arrayPropName, imports, propNames, _c
|
|
|
6761
6872
|
finalPropsExpr = cloned;
|
|
6762
6873
|
}
|
|
6763
6874
|
const itemsName = getComponentArrayItemsName(arrayPropName);
|
|
6764
|
-
const buildMethodName = getComponentArrayBuildMethodName(arrayPropName);
|
|
6765
|
-
const refreshMethodName = getComponentArrayRefreshMethodName(arrayPropName);
|
|
6766
|
-
const mountMethodName = `__mount${getArrayCapName2(arrayPropName)}Items`;
|
|
6767
|
-
const containerName = `__${arrayPropName}ItemsContainer`;
|
|
6768
|
-
const containerLookupExpr = um.containerBindingId ? t17.callExpression(t17.memberExpression(t17.identifier("document"), t17.identifier("getElementById")), [
|
|
6769
|
-
t17.binaryExpression(
|
|
6770
|
-
"+",
|
|
6771
|
-
t17.memberExpression(t17.thisExpression(), t17.identifier("id")),
|
|
6772
|
-
t17.stringLiteral(`-${um.containerBindingId}`)
|
|
6773
|
-
)
|
|
6774
|
-
]) : jsExpr4`this.$(":scope")`;
|
|
6775
6875
|
let arrAccessExpr;
|
|
6776
6876
|
let arrSetupStatements = [];
|
|
6777
6877
|
if (storeArrayAccess) {
|
|
@@ -6798,169 +6898,67 @@ function generateComponentArrayMethods(um, arrayPropName, imports, propNames, _c
|
|
|
6798
6898
|
itemPropsCallArgs
|
|
6799
6899
|
);
|
|
6800
6900
|
const itemPropsSetup = collectTemplateSetupStatements(finalPropsExpr, templateSetupContext);
|
|
6901
|
+
const storeVarNames = /* @__PURE__ */ new Set();
|
|
6902
|
+
if (storeArrayAccess) storeVarNames.add(storeArrayAccess.storeVar);
|
|
6903
|
+
for (const stmt of [...itemPropsSetup, ...arrSetupStatements]) {
|
|
6904
|
+
if (!t17.isVariableDeclaration(stmt)) continue;
|
|
6905
|
+
for (const decl of stmt.declarations) {
|
|
6906
|
+
if (t17.isIdentifier(decl.init) && imports.has(decl.init.name)) {
|
|
6907
|
+
storeVarNames.add(decl.init.name);
|
|
6908
|
+
}
|
|
6909
|
+
}
|
|
6910
|
+
}
|
|
6911
|
+
const rewriteStoreDestructuring = (stmts) => {
|
|
6912
|
+
if (storeVarNames.size === 0) return;
|
|
6913
|
+
for (const stmt of stmts) {
|
|
6914
|
+
if (!t17.isVariableDeclaration(stmt)) continue;
|
|
6915
|
+
for (const decl of stmt.declarations) {
|
|
6916
|
+
if (t17.isIdentifier(decl.init) && storeVarNames.has(decl.init.name)) {
|
|
6917
|
+
decl.init = t17.memberExpression(t17.identifier(decl.init.name), t17.identifier("__raw"));
|
|
6918
|
+
}
|
|
6919
|
+
}
|
|
6920
|
+
}
|
|
6921
|
+
};
|
|
6922
|
+
rewriteStoreDestructuring(itemPropsSetup);
|
|
6923
|
+
rewriteStoreDestructuring(arrSetupStatements);
|
|
6801
6924
|
const itemPropsMethod = jsMethod7`${id10(itemPropsMethodName)}(opt) {}`;
|
|
6802
6925
|
if (indexVar) itemPropsMethod.params.push(t17.identifier("__k"));
|
|
6803
6926
|
itemPropsMethod.body.body.push(...itemPropsSetup, t17.returnStatement(finalPropsExpr));
|
|
6804
6927
|
const itemIdProp = um.itemIdProperty;
|
|
6805
6928
|
const keyExpr = itemIdProp && itemIdProp !== ITEM_IS_KEY ? t17.callExpression(t17.identifier("String"), [t17.memberExpression(t17.identifier("opt"), t17.identifier(itemIdProp))]) : itemIdProp === ITEM_IS_KEY ? t17.callExpression(t17.identifier("String"), [t17.identifier("opt")]) : t17.binaryExpression("+", t17.stringLiteral("__idx_"), t17.identifier("__k"));
|
|
6806
|
-
const
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
item.__geaItemKey = ${t17.cloneNode(keyExpr, true)};
|
|
6816
|
-
return item;
|
|
6817
|
-
});
|
|
6818
|
-
` : jsBlockBody4`
|
|
6819
|
-
const arr = ${arrAccessExpr} ?? [];
|
|
6820
|
-
this.${id10(itemsName)} = arr.map(opt => {
|
|
6821
|
-
const item = new ${id10(comp.componentTag)}(${t17.cloneNode(itemPropsCall, true)});
|
|
6822
|
-
item.parentComponent = this;
|
|
6823
|
-
item.__geaCompiledChild = true;
|
|
6824
|
-
return item;
|
|
6825
|
-
});
|
|
6826
|
-
`
|
|
6929
|
+
const mapParams = [t17.identifier("opt")];
|
|
6930
|
+
if (indexVar || !itemIdProp) mapParams.push(t17.identifier("__k"));
|
|
6931
|
+
const childCall = t17.callExpression(
|
|
6932
|
+
t17.memberExpression(t17.thisExpression(), t17.identifier("__child")),
|
|
6933
|
+
[
|
|
6934
|
+
t17.identifier(comp.componentTag),
|
|
6935
|
+
t17.cloneNode(itemPropsCall, true),
|
|
6936
|
+
t17.cloneNode(keyExpr, true)
|
|
6937
|
+
]
|
|
6827
6938
|
);
|
|
6828
|
-
const
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
if (!this.${id10(containerName)}) return;
|
|
6835
|
-
for (let i = 0; i < (this.${id10(itemsName)}?.length ?? 0); i++) {
|
|
6836
|
-
const item = this.${id10(itemsName)}[i];
|
|
6837
|
-
if (!item) continue;
|
|
6838
|
-
if (!this.__childComponents.includes(item)) {
|
|
6839
|
-
this.__childComponents.push(item);
|
|
6840
|
-
}
|
|
6841
|
-
item.render(this.${id10(containerName)});
|
|
6842
|
-
}
|
|
6843
|
-
`
|
|
6939
|
+
const mapCallback = t17.arrowFunctionExpression(mapParams, childCall);
|
|
6940
|
+
const nullishCoalesce = t17.logicalExpression("??", t17.cloneNode(arrAccessExpr, true), t17.arrayExpression([]));
|
|
6941
|
+
const parenthesized = t17.parenthesizedExpression ? t17.parenthesizedExpression(nullishCoalesce) : nullishCoalesce;
|
|
6942
|
+
const mapCallExpr = t17.callExpression(
|
|
6943
|
+
t17.memberExpression(parenthesized, t17.identifier("map")),
|
|
6944
|
+
[mapCallback]
|
|
6844
6945
|
);
|
|
6845
|
-
const
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
const __key = ${t17.cloneNode(keyExpr, true)};
|
|
6862
|
-
const __existing = __keyMap.get(__key);
|
|
6863
|
-
if (__existing) {
|
|
6864
|
-
__existing.__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
|
|
6865
|
-
__new.push(__existing);
|
|
6866
|
-
__keyMap.delete(__key);
|
|
6867
|
-
} else {
|
|
6868
|
-
const __item = new ${id10(comp.componentTag)}(${t17.cloneNode(itemPropsCall, true)});
|
|
6869
|
-
__item.parentComponent = this;
|
|
6870
|
-
__item.__geaCompiledChild = true;
|
|
6871
|
-
__item.__geaItemKey = __key;
|
|
6872
|
-
__new.push(__item);
|
|
6873
|
-
}
|
|
6874
|
-
}
|
|
6875
|
-
for (const [, __removed] of __keyMap) {
|
|
6876
|
-
__removed.dispose?.();
|
|
6877
|
-
}
|
|
6878
|
-
if ((!this.${id10(containerName)} || !this.${id10(containerName)}.isConnected) && this.rendered_) {
|
|
6879
|
-
this.${id10(containerName)} = ${t17.cloneNode(containerLookupExpr, true)};
|
|
6880
|
-
}
|
|
6881
|
-
const __container = this.${id10(containerName)};
|
|
6882
|
-
if (__container && this.rendered_) {
|
|
6883
|
-
for (let __k = 0; __k < __new.length; __k++) {
|
|
6884
|
-
if (!__new[__k].rendered_) {
|
|
6885
|
-
if (!this.__childComponents.includes(__new[__k])) {
|
|
6886
|
-
this.__childComponents.push(__new[__k]);
|
|
6887
|
-
}
|
|
6888
|
-
__new[__k].render(__container);
|
|
6889
|
-
}
|
|
6890
|
-
}
|
|
6891
|
-
let __cursor = __container.firstChild;
|
|
6892
|
-
for (let __k = 0; __k < __new.length; __k++) {
|
|
6893
|
-
let __el = __new[__k].element_;
|
|
6894
|
-
if (!__el) continue;
|
|
6895
|
-
while (__el.parentElement && __el.parentElement !== __container) __el = __el.parentElement;
|
|
6896
|
-
if (__el !== __cursor) {
|
|
6897
|
-
__container.insertBefore(__el, __cursor || null);
|
|
6898
|
-
} else {
|
|
6899
|
-
__cursor = __cursor.nextSibling;
|
|
6900
|
-
}
|
|
6901
|
-
}
|
|
6902
|
-
}
|
|
6903
|
-
this.${id10(itemsName)} = __new;
|
|
6904
|
-
this.__childComponents = (this.__childComponents || []).filter(
|
|
6905
|
-
child => !__old.includes(child) || __new.includes(child)
|
|
6906
|
-
);
|
|
6907
|
-
`
|
|
6908
|
-
);
|
|
6909
|
-
} else {
|
|
6910
|
-
refreshMethod.body.body.push(
|
|
6911
|
-
...arrSetupStatements.map((stmt) => t17.cloneNode(stmt, true)),
|
|
6912
|
-
...jsBlockBody4`
|
|
6913
|
-
const arr = ${t17.cloneNode(arrAccessExpr, true)} ?? [];
|
|
6914
|
-
const __old = this.${id10(itemsName)} ?? [];
|
|
6915
|
-
const __oldLen = __old.length;
|
|
6916
|
-
const __newLen = arr.length;
|
|
6917
|
-
if (__oldLen !== __newLen) {
|
|
6918
|
-
if (__newLen > __oldLen) {
|
|
6919
|
-
for (let __k = 0; __k < __oldLen; __k++) {
|
|
6920
|
-
const opt = arr[__k];
|
|
6921
|
-
__old[__k].__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
|
|
6922
|
-
}
|
|
6923
|
-
if ((!this.${id10(containerName)} || !this.${id10(containerName)}.isConnected) && this.rendered_) {
|
|
6924
|
-
this.${id10(containerName)} = ${t17.cloneNode(containerLookupExpr, true)};
|
|
6925
|
-
}
|
|
6926
|
-
for (let __k = __oldLen; __k < __newLen; __k++) {
|
|
6927
|
-
const opt = arr[__k];
|
|
6928
|
-
const __item = new ${id10(comp.componentTag)}(${t17.cloneNode(itemPropsCall, true)});
|
|
6929
|
-
__item.parentComponent = this;
|
|
6930
|
-
__item.__geaCompiledChild = true;
|
|
6931
|
-
this.${id10(itemsName)}.push(__item);
|
|
6932
|
-
if (!this.__childComponents.includes(__item)) {
|
|
6933
|
-
this.__childComponents.push(__item);
|
|
6934
|
-
}
|
|
6935
|
-
if (this.rendered_ && this.${id10(containerName)}) {
|
|
6936
|
-
__item.render(this.${id10(containerName)});
|
|
6937
|
-
}
|
|
6938
|
-
}
|
|
6939
|
-
return;
|
|
6940
|
-
}
|
|
6941
|
-
if (__newLen < __oldLen) {
|
|
6942
|
-
for (let __k = __newLen; __k < __oldLen; __k++) {
|
|
6943
|
-
__old[__k]?.dispose?.();
|
|
6944
|
-
}
|
|
6945
|
-
this.${id10(itemsName)}.length = __newLen;
|
|
6946
|
-
this.__childComponents = (this.__childComponents || []).filter(
|
|
6947
|
-
child => !__old.slice(__newLen).includes(child)
|
|
6948
|
-
);
|
|
6949
|
-
for (let __k = 0; __k < __newLen; __k++) {
|
|
6950
|
-
const opt = arr[__k];
|
|
6951
|
-
this.${id10(itemsName)}[__k].__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
|
|
6952
|
-
}
|
|
6953
|
-
return;
|
|
6954
|
-
}
|
|
6955
|
-
}
|
|
6956
|
-
for (let i = 0; i < arr.length; i++) {
|
|
6957
|
-
const opt = arr[i];
|
|
6958
|
-
this.${id10(itemsName)}[i].__geaUpdateProps(${t17.cloneNode(itemPropsCall, true)});
|
|
6959
|
-
}
|
|
6960
|
-
`
|
|
6961
|
-
);
|
|
6962
|
-
}
|
|
6963
|
-
return [itemPropsMethod, buildMethod, mountMethod, refreshMethod];
|
|
6946
|
+
const constructorInit = t17.expressionStatement(
|
|
6947
|
+
t17.assignmentExpression(
|
|
6948
|
+
"=",
|
|
6949
|
+
t17.memberExpression(t17.thisExpression(), t17.identifier(itemsName)),
|
|
6950
|
+
mapCallExpr
|
|
6951
|
+
)
|
|
6952
|
+
);
|
|
6953
|
+
return {
|
|
6954
|
+
itemPropsMethod,
|
|
6955
|
+
constructorInit,
|
|
6956
|
+
componentTag: comp.componentTag,
|
|
6957
|
+
containerBindingId: um.containerBindingId,
|
|
6958
|
+
itemIdProperty: itemIdProp,
|
|
6959
|
+
arrAccessExpr,
|
|
6960
|
+
arrSetupStatements
|
|
6961
|
+
};
|
|
6964
6962
|
}
|
|
6965
6963
|
|
|
6966
6964
|
// src/apply-reactivity.ts
|
|
@@ -6987,30 +6985,164 @@ var BOOLEAN_HTML_ATTRS = /* @__PURE__ */ new Set([
|
|
|
6987
6985
|
]);
|
|
6988
6986
|
function rewriteTemplateBodyForImportedState(_templateMethod, _stateRefs, _storeImports) {
|
|
6989
6987
|
}
|
|
6990
|
-
function generateCreatedHooks(stores) {
|
|
6991
|
-
const body =
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6988
|
+
function generateCreatedHooks(stores, hasArrayConfigs, observeListConfigs = []) {
|
|
6989
|
+
const body = [];
|
|
6990
|
+
if (hasArrayConfigs) {
|
|
6991
|
+
body.push(js7`this.__ensureArrayConfigs();`);
|
|
6992
|
+
}
|
|
6993
|
+
const observeListPathKeys = /* @__PURE__ */ new Set();
|
|
6994
|
+
for (const config of observeListConfigs) {
|
|
6995
|
+
observeListPathKeys.add(`${config.storeVar}:${JSON.stringify(config.pathParts)}`);
|
|
6996
|
+
}
|
|
6998
6997
|
for (const store of stores) {
|
|
6999
|
-
const
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
6998
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
6999
|
+
for (const handler of store.observeHandlers) {
|
|
7000
|
+
const pathKey = JSON.stringify(handler.pathParts);
|
|
7001
|
+
const listKey = `${store.storeVar}:${pathKey}`;
|
|
7002
|
+
if (observeListPathKeys.has(listKey)) continue;
|
|
7003
|
+
if (!byPath.has(pathKey)) byPath.set(pathKey, []);
|
|
7004
|
+
byPath.get(pathKey).push({ methodName: handler.methodName, isVia: handler.isVia, rereadExpr: handler.rereadExpr });
|
|
7005
|
+
}
|
|
7006
|
+
const storeVarExpr = t18.identifier(store.storeVar);
|
|
7007
|
+
for (const [pathKey, handlers] of byPath) {
|
|
7008
|
+
const pathParts = JSON.parse(pathKey);
|
|
7009
|
+
const pathArray = t18.arrayExpression(pathParts.map((part) => t18.stringLiteral(part)));
|
|
7010
|
+
if (handlers.length === 1 && !handlers[0].isVia) {
|
|
7011
|
+
body.push(
|
|
7012
|
+
t18.expressionStatement(
|
|
7013
|
+
t18.callExpression(
|
|
7014
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__observe")),
|
|
7015
|
+
[
|
|
7016
|
+
storeVarExpr,
|
|
7017
|
+
pathArray,
|
|
7018
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(handlers[0].methodName))
|
|
7019
|
+
]
|
|
7011
7020
|
)
|
|
7012
|
-
)
|
|
7013
|
-
|
|
7021
|
+
)
|
|
7022
|
+
);
|
|
7023
|
+
} else {
|
|
7024
|
+
const vParam = t18.identifier("__v");
|
|
7025
|
+
const cParam = t18.identifier("__c");
|
|
7026
|
+
const callStmts = [];
|
|
7027
|
+
for (const h of handlers) {
|
|
7028
|
+
if (h.isVia && h.rereadExpr) {
|
|
7029
|
+
callStmts.push(
|
|
7030
|
+
t18.expressionStatement(
|
|
7031
|
+
t18.callExpression(
|
|
7032
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)),
|
|
7033
|
+
[t18.cloneNode(h.rereadExpr, true), t18.nullLiteral()]
|
|
7034
|
+
)
|
|
7035
|
+
)
|
|
7036
|
+
);
|
|
7037
|
+
} else {
|
|
7038
|
+
callStmts.push(
|
|
7039
|
+
t18.expressionStatement(
|
|
7040
|
+
t18.callExpression(
|
|
7041
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)),
|
|
7042
|
+
[vParam, cParam]
|
|
7043
|
+
)
|
|
7044
|
+
)
|
|
7045
|
+
);
|
|
7046
|
+
}
|
|
7047
|
+
}
|
|
7048
|
+
body.push(
|
|
7049
|
+
t18.expressionStatement(
|
|
7050
|
+
t18.callExpression(
|
|
7051
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__observe")),
|
|
7052
|
+
[
|
|
7053
|
+
storeVarExpr,
|
|
7054
|
+
pathArray,
|
|
7055
|
+
t18.arrowFunctionExpression(
|
|
7056
|
+
[vParam, cParam],
|
|
7057
|
+
t18.blockStatement(callStmts)
|
|
7058
|
+
)
|
|
7059
|
+
]
|
|
7060
|
+
)
|
|
7061
|
+
)
|
|
7062
|
+
);
|
|
7063
|
+
}
|
|
7064
|
+
}
|
|
7065
|
+
for (const config of observeListConfigs.filter((c) => c.storeVar === store.storeVar)) {
|
|
7066
|
+
const pathArray = t18.arrayExpression(config.pathParts.map((part) => t18.stringLiteral(part)));
|
|
7067
|
+
const itemsName = getComponentArrayItemsName(config.arrayPropName);
|
|
7068
|
+
const itemPropsMethodName = `__itemProps_${config.arrayPropName}`;
|
|
7069
|
+
const configProps = [
|
|
7070
|
+
t18.objectProperty(
|
|
7071
|
+
t18.identifier("items"),
|
|
7072
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName))
|
|
7073
|
+
),
|
|
7074
|
+
t18.objectProperty(
|
|
7075
|
+
t18.identifier("itemsKey"),
|
|
7076
|
+
t18.stringLiteral(itemsName)
|
|
7077
|
+
),
|
|
7078
|
+
t18.objectProperty(
|
|
7079
|
+
t18.identifier("container"),
|
|
7080
|
+
t18.arrowFunctionExpression(
|
|
7081
|
+
[],
|
|
7082
|
+
config.containerBindingId ? t18.callExpression(
|
|
7083
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__el")),
|
|
7084
|
+
[t18.stringLiteral(config.containerBindingId)]
|
|
7085
|
+
) : jsExpr4`this.$(":scope")`
|
|
7086
|
+
)
|
|
7087
|
+
),
|
|
7088
|
+
t18.objectProperty(t18.identifier("Ctor"), t18.identifier(config.componentTag)),
|
|
7089
|
+
t18.objectProperty(
|
|
7090
|
+
t18.identifier("props"),
|
|
7091
|
+
t18.arrowFunctionExpression(
|
|
7092
|
+
[t18.identifier("opt"), t18.identifier("__k")],
|
|
7093
|
+
t18.callExpression(
|
|
7094
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(itemPropsMethodName)),
|
|
7095
|
+
[t18.identifier("opt"), t18.identifier("__k")]
|
|
7096
|
+
)
|
|
7097
|
+
)
|
|
7098
|
+
),
|
|
7099
|
+
t18.objectProperty(
|
|
7100
|
+
t18.identifier("key"),
|
|
7101
|
+
config.itemIdProperty && config.itemIdProperty !== ITEM_IS_KEY ? t18.arrowFunctionExpression(
|
|
7102
|
+
[t18.identifier("opt")],
|
|
7103
|
+
t18.memberExpression(t18.identifier("opt"), t18.identifier(config.itemIdProperty))
|
|
7104
|
+
) : config.itemIdProperty === ITEM_IS_KEY ? t18.arrowFunctionExpression([t18.identifier("opt")], t18.identifier("opt")) : t18.arrowFunctionExpression(
|
|
7105
|
+
[t18.identifier("opt"), t18.identifier("__k")],
|
|
7106
|
+
t18.binaryExpression("+", t18.stringLiteral("__idx_"), t18.identifier("__k"))
|
|
7107
|
+
)
|
|
7108
|
+
)
|
|
7109
|
+
];
|
|
7110
|
+
const samePathHandlers = [];
|
|
7111
|
+
const pathKey = JSON.stringify(config.pathParts);
|
|
7112
|
+
for (const handler of store.observeHandlers) {
|
|
7113
|
+
if (JSON.stringify(handler.pathParts) === pathKey) {
|
|
7114
|
+
samePathHandlers.push(handler);
|
|
7115
|
+
}
|
|
7116
|
+
}
|
|
7117
|
+
if (samePathHandlers.length > 0) {
|
|
7118
|
+
const onchangeStmts = samePathHandlers.map(
|
|
7119
|
+
(h) => t18.expressionStatement(
|
|
7120
|
+
h.isVia && h.rereadExpr ? t18.callExpression(
|
|
7121
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)),
|
|
7122
|
+
[t18.cloneNode(h.rereadExpr, true), t18.nullLiteral()]
|
|
7123
|
+
) : t18.callExpression(
|
|
7124
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(h.methodName)),
|
|
7125
|
+
[
|
|
7126
|
+
t18.memberExpression(t18.identifier(config.storeVar), t18.identifier(config.pathParts[0])),
|
|
7127
|
+
t18.nullLiteral()
|
|
7128
|
+
]
|
|
7129
|
+
)
|
|
7130
|
+
)
|
|
7131
|
+
);
|
|
7132
|
+
configProps.push(
|
|
7133
|
+
t18.objectProperty(
|
|
7134
|
+
t18.identifier("onchange"),
|
|
7135
|
+
t18.arrowFunctionExpression([], t18.blockStatement(onchangeStmts))
|
|
7136
|
+
)
|
|
7137
|
+
);
|
|
7138
|
+
}
|
|
7139
|
+
body.push(
|
|
7140
|
+
t18.expressionStatement(
|
|
7141
|
+
t18.callExpression(
|
|
7142
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__observeList")),
|
|
7143
|
+
[storeVarExpr, pathArray, t18.objectExpression(configProps)]
|
|
7144
|
+
)
|
|
7145
|
+
)
|
|
7014
7146
|
);
|
|
7015
7147
|
}
|
|
7016
7148
|
}
|
|
@@ -7018,30 +7150,34 @@ function generateCreatedHooks(stores) {
|
|
|
7018
7150
|
method.body.body.push(...body);
|
|
7019
7151
|
return method;
|
|
7020
7152
|
}
|
|
7021
|
-
function generateLocalStateObserverSetup(observeHandlers) {
|
|
7153
|
+
function generateLocalStateObserverSetup(observeHandlers, hasArrayConfigs) {
|
|
7022
7154
|
const localStore = t18.memberExpression(t18.thisExpression(), t18.identifier("__store"));
|
|
7023
|
-
const body = [
|
|
7024
|
-
|
|
7025
|
-
js7`
|
|
7026
|
-
|
|
7027
|
-
|
|
7155
|
+
const body = [];
|
|
7156
|
+
if (hasArrayConfigs) {
|
|
7157
|
+
body.push(js7`this.__ensureArrayConfigs();`);
|
|
7158
|
+
}
|
|
7159
|
+
body.push(js7`if (!${localStore}) { return; }`);
|
|
7160
|
+
for (const observeHandler of observeHandlers) {
|
|
7028
7161
|
body.push(
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
(
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7162
|
+
t18.expressionStatement(
|
|
7163
|
+
t18.callExpression(
|
|
7164
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__observe")),
|
|
7165
|
+
[
|
|
7166
|
+
t18.thisExpression(),
|
|
7167
|
+
t18.arrayExpression(observeHandler.pathParts.map((part) => t18.stringLiteral(part))),
|
|
7168
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(observeHandler.methodName))
|
|
7169
|
+
]
|
|
7170
|
+
)
|
|
7171
|
+
)
|
|
7037
7172
|
);
|
|
7038
|
-
}
|
|
7173
|
+
}
|
|
7039
7174
|
const method = jsMethod8`${id11("__setupLocalStateObservers")}() {}`;
|
|
7040
7175
|
method.body.body.push(...body);
|
|
7041
7176
|
return method;
|
|
7042
7177
|
}
|
|
7043
7178
|
function applyStaticReactivity(ast, originalAST, className, sourceFile, imports, stateRefs, storeImports, compiledChildren = [], eventIdCounter = { value: 0 }, preTransformAnalysis) {
|
|
7044
7179
|
let applied = false;
|
|
7180
|
+
let needsModuleLevelUnwrapHelper = false;
|
|
7045
7181
|
const astToTraverse = preTransformAnalysis?.has(className) ? ast : originalAST;
|
|
7046
7182
|
const getAnalysis = (clsName, origPath) => {
|
|
7047
7183
|
const cached = preTransformAnalysis?.get(clsName);
|
|
@@ -7200,22 +7336,46 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7200
7336
|
consequent
|
|
7201
7337
|
);
|
|
7202
7338
|
} else if (pb.type === "class") {
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
t18.
|
|
7208
|
-
t18.binaryExpression("!=", valueExpr, t18.nullLiteral()),
|
|
7339
|
+
const isObjectClass = pb.expression && t18.isObjectExpression(pb.expression);
|
|
7340
|
+
const classValueExpr = isObjectClass ? t18.callExpression(
|
|
7341
|
+
t18.memberExpression(
|
|
7342
|
+
t18.callExpression(
|
|
7343
|
+
t18.memberExpression(
|
|
7209
7344
|
t18.callExpression(
|
|
7210
7345
|
t18.memberExpression(
|
|
7211
|
-
t18.callExpression(
|
|
7212
|
-
|
|
7346
|
+
t18.callExpression(
|
|
7347
|
+
t18.memberExpression(t18.identifier("Object"), t18.identifier("entries")),
|
|
7348
|
+
[t18.cloneNode(valueExpr, true)]
|
|
7349
|
+
),
|
|
7350
|
+
t18.identifier("filter")
|
|
7213
7351
|
),
|
|
7214
|
-
[
|
|
7352
|
+
[
|
|
7353
|
+
t18.arrowFunctionExpression(
|
|
7354
|
+
[t18.arrayPattern([t18.identifier("__k"), t18.identifier("__v")])],
|
|
7355
|
+
t18.identifier("__v")
|
|
7356
|
+
)
|
|
7357
|
+
]
|
|
7215
7358
|
),
|
|
7216
|
-
t18.
|
|
7217
|
-
)
|
|
7218
|
-
|
|
7359
|
+
t18.identifier("map")
|
|
7360
|
+
),
|
|
7361
|
+
[
|
|
7362
|
+
t18.arrowFunctionExpression(
|
|
7363
|
+
[t18.arrayPattern([t18.identifier("__k")])],
|
|
7364
|
+
t18.identifier("__k")
|
|
7365
|
+
)
|
|
7366
|
+
]
|
|
7367
|
+
),
|
|
7368
|
+
t18.identifier("join")
|
|
7369
|
+
),
|
|
7370
|
+
[t18.stringLiteral(" ")]
|
|
7371
|
+
) : t18.conditionalExpression(
|
|
7372
|
+
t18.binaryExpression("!=", valueExpr, t18.nullLiteral()),
|
|
7373
|
+
t18.callExpression(t18.identifier("String"), [t18.cloneNode(valueExpr, true)]),
|
|
7374
|
+
t18.stringLiteral("")
|
|
7375
|
+
);
|
|
7376
|
+
updateStmt = t18.blockStatement([
|
|
7377
|
+
t18.variableDeclaration("const", [
|
|
7378
|
+
t18.variableDeclarator(t18.identifier("__newClass"), classValueExpr)
|
|
7219
7379
|
]),
|
|
7220
7380
|
t18.ifStatement(
|
|
7221
7381
|
t18.binaryExpression(
|
|
@@ -7514,6 +7674,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7514
7674
|
const componentArrayDisposeTargets = [];
|
|
7515
7675
|
const componentArrayMountMethods = [];
|
|
7516
7676
|
const storeComponentArrayObservers = [];
|
|
7677
|
+
const observeListConfigs = [];
|
|
7517
7678
|
const mapItemAttrInfos = [];
|
|
7518
7679
|
const tmplBody = templateMethod?.body.body ?? [];
|
|
7519
7680
|
let tmplReturnIdx = -1;
|
|
@@ -7542,7 +7703,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7542
7703
|
}
|
|
7543
7704
|
}
|
|
7544
7705
|
const propNames = getTemplatePropNames(classPath.node.body);
|
|
7545
|
-
const
|
|
7706
|
+
const arrayResult = generateComponentArrayResult(
|
|
7546
7707
|
um,
|
|
7547
7708
|
arrayPropName,
|
|
7548
7709
|
imports,
|
|
@@ -7552,9 +7713,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7552
7713
|
getTemplateParamIdentifier(classPath.node.body),
|
|
7553
7714
|
tmplSetupCtx
|
|
7554
7715
|
);
|
|
7555
|
-
if (
|
|
7556
|
-
|
|
7557
|
-
const importSource = imports.get(
|
|
7716
|
+
if (arrayResult && templateMethod) {
|
|
7717
|
+
classPath.node.body.body.push(arrayResult.itemPropsMethod);
|
|
7718
|
+
const importSource = imports.get(arrayResult.componentTag);
|
|
7558
7719
|
if (importSource) {
|
|
7559
7720
|
const delegatedEvents = getHoistableRootEventsForImport(sourceFile, importSource).map((meta) => ({
|
|
7560
7721
|
eventType: meta.eventType,
|
|
@@ -7567,15 +7728,93 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7567
7728
|
appendCompiledEventMethods(classPath.node.body, delegatedEvents);
|
|
7568
7729
|
}
|
|
7569
7730
|
}
|
|
7570
|
-
|
|
7731
|
+
inlineIntoConstructor(classPath.node.body, [
|
|
7732
|
+
...arrayResult.arrSetupStatements.map((s) => t18.cloneNode(s, true)),
|
|
7733
|
+
arrayResult.constructorInit
|
|
7734
|
+
]);
|
|
7571
7735
|
if (storeArrayAccess) {
|
|
7572
|
-
|
|
7736
|
+
observeListConfigs.push({
|
|
7573
7737
|
storeVar: storeArrayAccess.storeVar,
|
|
7574
|
-
|
|
7575
|
-
|
|
7738
|
+
pathParts: [storeArrayAccess.propName],
|
|
7739
|
+
arrayPropName,
|
|
7740
|
+
componentTag: arrayResult.componentTag,
|
|
7741
|
+
containerBindingId: arrayResult.containerBindingId,
|
|
7742
|
+
itemIdProperty: arrayResult.itemIdProperty
|
|
7576
7743
|
});
|
|
7577
7744
|
} else {
|
|
7578
7745
|
const computedDeps = (um.dependencies || collectUnresolvedDependencies([um], stateRefs, classPath.node.body)).filter((dep) => dep.storeVar || dep.pathParts[0] !== "props");
|
|
7746
|
+
const refreshMethodName = getComponentArrayRefreshMethodName(arrayPropName);
|
|
7747
|
+
const itemsName = getComponentArrayItemsName(arrayPropName);
|
|
7748
|
+
const itemPropsMethodNameRef = `__itemProps_${arrayPropName}`;
|
|
7749
|
+
const containerSuffix = arrayResult.containerBindingId;
|
|
7750
|
+
const containerExpr = containerSuffix ? t18.callExpression(
|
|
7751
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__el")),
|
|
7752
|
+
[t18.stringLiteral(containerSuffix)]
|
|
7753
|
+
) : jsExpr4`this.$(":scope")`;
|
|
7754
|
+
const itemIdProp = arrayResult.itemIdProperty;
|
|
7755
|
+
const keyFn = itemIdProp && itemIdProp !== ITEM_IS_KEY ? t18.arrowFunctionExpression(
|
|
7756
|
+
[t18.identifier("opt")],
|
|
7757
|
+
t18.memberExpression(t18.identifier("opt"), t18.identifier(itemIdProp))
|
|
7758
|
+
) : itemIdProp === ITEM_IS_KEY ? t18.arrowFunctionExpression([t18.identifier("opt")], t18.identifier("opt")) : t18.arrowFunctionExpression(
|
|
7759
|
+
[t18.identifier("opt"), t18.identifier("__k")],
|
|
7760
|
+
t18.binaryExpression("+", t18.stringLiteral("__idx_"), t18.identifier("__k"))
|
|
7761
|
+
);
|
|
7762
|
+
const refreshMethod = t18.classMethod(
|
|
7763
|
+
"method",
|
|
7764
|
+
t18.identifier(refreshMethodName),
|
|
7765
|
+
[],
|
|
7766
|
+
t18.blockStatement([
|
|
7767
|
+
...arrayResult.arrSetupStatements.map((s) => t18.cloneNode(s, true)),
|
|
7768
|
+
t18.variableDeclaration("const", [
|
|
7769
|
+
t18.variableDeclarator(
|
|
7770
|
+
t18.identifier("__arr"),
|
|
7771
|
+
t18.logicalExpression("??", t18.cloneNode(arrayResult.arrAccessExpr, true), t18.arrayExpression([]))
|
|
7772
|
+
)
|
|
7773
|
+
]),
|
|
7774
|
+
t18.variableDeclaration("const", [
|
|
7775
|
+
t18.variableDeclarator(
|
|
7776
|
+
t18.identifier("__new"),
|
|
7777
|
+
t18.callExpression(
|
|
7778
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__reconcileList")),
|
|
7779
|
+
[
|
|
7780
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName)),
|
|
7781
|
+
t18.identifier("__arr"),
|
|
7782
|
+
t18.cloneNode(containerExpr, true),
|
|
7783
|
+
t18.identifier(arrayResult.componentTag),
|
|
7784
|
+
t18.arrowFunctionExpression(
|
|
7785
|
+
[t18.identifier("opt")],
|
|
7786
|
+
t18.callExpression(
|
|
7787
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(itemPropsMethodNameRef)),
|
|
7788
|
+
[t18.identifier("opt")]
|
|
7789
|
+
)
|
|
7790
|
+
),
|
|
7791
|
+
t18.cloneNode(keyFn, true)
|
|
7792
|
+
]
|
|
7793
|
+
)
|
|
7794
|
+
)
|
|
7795
|
+
]),
|
|
7796
|
+
t18.expressionStatement(
|
|
7797
|
+
t18.assignmentExpression(
|
|
7798
|
+
"=",
|
|
7799
|
+
t18.memberExpression(
|
|
7800
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName)),
|
|
7801
|
+
t18.identifier("length")
|
|
7802
|
+
),
|
|
7803
|
+
t18.numericLiteral(0)
|
|
7804
|
+
)
|
|
7805
|
+
),
|
|
7806
|
+
t18.expressionStatement(
|
|
7807
|
+
t18.callExpression(
|
|
7808
|
+
t18.memberExpression(
|
|
7809
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName)),
|
|
7810
|
+
t18.identifier("push")
|
|
7811
|
+
),
|
|
7812
|
+
[t18.spreadElement(t18.identifier("__new"))]
|
|
7813
|
+
)
|
|
7814
|
+
)
|
|
7815
|
+
])
|
|
7816
|
+
);
|
|
7817
|
+
classPath.node.body.body.push(refreshMethod);
|
|
7579
7818
|
if (computedDeps.length > 0) {
|
|
7580
7819
|
computedDeps.forEach((dep) => {
|
|
7581
7820
|
mergeObserveMethod(
|
|
@@ -7589,7 +7828,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7589
7828
|
t18.callExpression(
|
|
7590
7829
|
t18.memberExpression(
|
|
7591
7830
|
t18.thisExpression(),
|
|
7592
|
-
t18.identifier(
|
|
7831
|
+
t18.identifier(refreshMethodName)
|
|
7593
7832
|
),
|
|
7594
7833
|
[]
|
|
7595
7834
|
)
|
|
@@ -7600,13 +7839,13 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7600
7839
|
if (dep.storeVar) {
|
|
7601
7840
|
storeComponentArrayObservers.push({
|
|
7602
7841
|
storeVar: dep.storeVar,
|
|
7603
|
-
refreshMethodName
|
|
7842
|
+
refreshMethodName,
|
|
7604
7843
|
pathParts: dep.pathParts
|
|
7605
7844
|
});
|
|
7606
7845
|
}
|
|
7607
7846
|
});
|
|
7608
7847
|
}
|
|
7609
|
-
const itemPropsMethod =
|
|
7848
|
+
const itemPropsMethod = arrayResult.itemPropsMethod;
|
|
7610
7849
|
if (itemPropsMethod && t18.isBlockStatement(itemPropsMethod.body)) {
|
|
7611
7850
|
const returnStmt = itemPropsMethod.body.body.find((s) => t18.isReturnStatement(s));
|
|
7612
7851
|
if (returnStmt?.argument && t18.isObjectExpression(returnStmt.argument)) {
|
|
@@ -7625,28 +7864,9 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7625
7864
|
const key = `${dep.storeVar}:${pathPartsToString(dep.pathParts)}`;
|
|
7626
7865
|
if (computedDepKeys.has(key)) continue;
|
|
7627
7866
|
computedDepKeys.add(key);
|
|
7628
|
-
mergeObserveMethod(
|
|
7629
|
-
dep.observeKey,
|
|
7630
|
-
t18.classMethod(
|
|
7631
|
-
"method",
|
|
7632
|
-
t18.identifier(getObserveMethodName(dep.pathParts, dep.storeVar)),
|
|
7633
|
-
[t18.identifier("value"), t18.identifier("change")],
|
|
7634
|
-
t18.blockStatement([
|
|
7635
|
-
t18.expressionStatement(
|
|
7636
|
-
t18.callExpression(
|
|
7637
|
-
t18.memberExpression(
|
|
7638
|
-
t18.thisExpression(),
|
|
7639
|
-
t18.identifier(getComponentArrayRefreshMethodName(arrayPropName))
|
|
7640
|
-
),
|
|
7641
|
-
[]
|
|
7642
|
-
)
|
|
7643
|
-
)
|
|
7644
|
-
])
|
|
7645
|
-
)
|
|
7646
|
-
);
|
|
7647
7867
|
storeComponentArrayObservers.push({
|
|
7648
7868
|
storeVar: dep.storeVar,
|
|
7649
|
-
refreshMethodName
|
|
7869
|
+
refreshMethodName,
|
|
7650
7870
|
pathParts: dep.pathParts
|
|
7651
7871
|
});
|
|
7652
7872
|
}
|
|
@@ -7655,12 +7875,11 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7655
7875
|
const itemTemplateProps = collectPropNamesFromItemTemplate(um.itemTemplate, propNames);
|
|
7656
7876
|
const allStoreManaged = computedDeps.length > 0 && computedDeps.every((dep) => dep.storeVar);
|
|
7657
7877
|
componentArrayRefreshDeps.push({
|
|
7658
|
-
methodName:
|
|
7878
|
+
methodName: refreshMethodName,
|
|
7659
7879
|
propNames: allStoreManaged ? [...itemTemplateProps] : [arrayPropName, ...itemTemplateProps]
|
|
7660
7880
|
});
|
|
7661
7881
|
}
|
|
7662
7882
|
componentArrayDisposeTargets.push(getComponentArrayItemsName(arrayPropName));
|
|
7663
|
-
componentArrayMountMethods.push(getComponentArrayMountMethodName(arrayPropName));
|
|
7664
7883
|
replaceMapWithComponentArrayItems(
|
|
7665
7884
|
templateMethod,
|
|
7666
7885
|
um.computationExpr,
|
|
@@ -7684,7 +7903,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7684
7903
|
};
|
|
7685
7904
|
unresolvedBindings.push({ info: um, binding: syntheticBinding });
|
|
7686
7905
|
const prevEventLen = unresolvedEventHandlers.length;
|
|
7687
|
-
const { method, handlerPropsInMap } = generateRenderItemMethod(
|
|
7906
|
+
const { method, handlerPropsInMap, needsUnwrapHelper } = generateRenderItemMethod(
|
|
7688
7907
|
syntheticBinding,
|
|
7689
7908
|
imports,
|
|
7690
7909
|
unresolvedEventHandlers,
|
|
@@ -7692,6 +7911,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7692
7911
|
classPath.node.body,
|
|
7693
7912
|
tmplSetupCtx
|
|
7694
7913
|
);
|
|
7914
|
+
if (needsUnwrapHelper) needsModuleLevelUnwrapHelper = true;
|
|
7695
7915
|
const newHandlers = unresolvedEventHandlers.slice(prevEventLen);
|
|
7696
7916
|
const tokenMatch = newHandlers[0]?.selector?.match(/data-gea-event="([^"]+)"/);
|
|
7697
7917
|
mapItemAttrInfos.push({
|
|
@@ -7865,7 +8085,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
7865
8085
|
});
|
|
7866
8086
|
const resolvedArrayMapDelegateKeys = /* @__PURE__ */ new Set();
|
|
7867
8087
|
analysis.arrayMaps.forEach((arrayMap) => {
|
|
7868
|
-
if (arrayMap.storeVar
|
|
8088
|
+
if (arrayMap.storeVar) {
|
|
7869
8089
|
const storeRef = stateRefs.get(arrayMap.storeVar);
|
|
7870
8090
|
const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
|
|
7871
8091
|
if (getterDepPaths && getterDepPaths.length > 0) {
|
|
@@ -8053,12 +8273,26 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8053
8273
|
if (unresolvedMapKeys.has(observeKey)) continue;
|
|
8054
8274
|
const handledByComponentArray = storeComponentArrayObservers.some(
|
|
8055
8275
|
(obs) => obs.storeVar === storeVar && pathPartsToString(obs.pathParts) === pathPartsToString(propPath)
|
|
8276
|
+
) || observeListConfigs.some(
|
|
8277
|
+
(olc) => olc.storeVar === storeVar && pathPartsToString(olc.pathParts) === pathPartsToString(propPath)
|
|
8056
8278
|
);
|
|
8057
8279
|
if (handledByComponentArray) continue;
|
|
8058
8280
|
if (!childObserveGroups.has(observeKey)) {
|
|
8059
8281
|
if (conditionalSlotIndices.length > 0) continue;
|
|
8060
8282
|
if (analysis.conditionalSlotScopedStoreKeys?.has(observeKey)) continue;
|
|
8283
|
+
if (storeVar && propPath.length >= 1) {
|
|
8284
|
+
const storeRef = stateRefs.get(storeVar);
|
|
8285
|
+
const getterDepPaths = storeRef?.getterDeps?.get(propPath[0]);
|
|
8286
|
+
if (getterDepPaths && getterDepPaths.length > 0) {
|
|
8287
|
+
const allDepsCovered = getterDepPaths.every(
|
|
8288
|
+
(depPath) => childObserveGroups.has(buildObserveKey(depPath, storeVar))
|
|
8289
|
+
);
|
|
8290
|
+
if (allDepsCovered) continue;
|
|
8291
|
+
}
|
|
8292
|
+
}
|
|
8061
8293
|
mergeObserveMethod(observeKey, generateRerenderObserver(propPath, storeVar, guardStateKeys.has(observeKey)));
|
|
8294
|
+
} else if (guardStateKeys.has(observeKey)) {
|
|
8295
|
+
mergeObserveMethod(observeKey, generateRerenderObserver(propPath, storeVar, true));
|
|
8062
8296
|
}
|
|
8063
8297
|
}
|
|
8064
8298
|
const childrenWithResolvedMap = /* @__PURE__ */ new Set();
|
|
@@ -8116,7 +8350,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8116
8350
|
for (const member of classPath.node.body.body) {
|
|
8117
8351
|
if (!t18.isClassMethod(member) || !t18.isIdentifier(member.key)) continue;
|
|
8118
8352
|
const methodName = member.key.name;
|
|
8119
|
-
const isRelevant = childrenWithResolvedMap.size > 0 &&
|
|
8353
|
+
const isRelevant = childrenWithResolvedMap.size > 0 && methodName.startsWith("__buildProps_");
|
|
8120
8354
|
if (!isRelevant) continue;
|
|
8121
8355
|
traverse10(t18.program([t18.expressionStatement(t18.functionExpression(null, [], member.body))]), {
|
|
8122
8356
|
noScope: true,
|
|
@@ -8165,15 +8399,23 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8165
8399
|
(child) => t18.expressionStatement(
|
|
8166
8400
|
t18.callExpression(
|
|
8167
8401
|
t18.memberExpression(
|
|
8168
|
-
t18.thisExpression(),
|
|
8169
|
-
t18.identifier(
|
|
8402
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(child.instanceVar)),
|
|
8403
|
+
t18.identifier("__geaUpdateProps")
|
|
8170
8404
|
),
|
|
8171
|
-
[
|
|
8405
|
+
[
|
|
8406
|
+
t18.callExpression(
|
|
8407
|
+
t18.memberExpression(
|
|
8408
|
+
t18.thisExpression(),
|
|
8409
|
+
t18.identifier(`__buildProps_${child.instanceVar.replace(/^_/, "")}`)
|
|
8410
|
+
),
|
|
8411
|
+
[]
|
|
8412
|
+
)
|
|
8413
|
+
]
|
|
8172
8414
|
)
|
|
8173
8415
|
)
|
|
8174
8416
|
);
|
|
8175
8417
|
if (existing && t18.isBlockStatement(existing.body)) {
|
|
8176
|
-
existing.body.body.
|
|
8418
|
+
existing.body.body.unshift(...calls);
|
|
8177
8419
|
} else {
|
|
8178
8420
|
const method = t18.classMethod(
|
|
8179
8421
|
"method",
|
|
@@ -8266,6 +8508,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8266
8508
|
addJoinToUnresolvedMapCalls(templateMethod, analysis.unresolvedMaps);
|
|
8267
8509
|
}
|
|
8268
8510
|
const componentArrayMaps = [];
|
|
8511
|
+
const componentArrayItemPropsMethods = /* @__PURE__ */ new Map();
|
|
8269
8512
|
const htmlArrayMaps = [];
|
|
8270
8513
|
for (const arrayMap of analysis.arrayMaps) {
|
|
8271
8514
|
const compChild = isUnresolvedMapWithComponentChild(
|
|
@@ -8308,7 +8551,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8308
8551
|
computationExpr: computationExprSafe ?? computationExpr
|
|
8309
8552
|
};
|
|
8310
8553
|
const propNames = getTemplatePropNames(classPath.node.body);
|
|
8311
|
-
const
|
|
8554
|
+
const arrayResult = generateComponentArrayResult(
|
|
8312
8555
|
um,
|
|
8313
8556
|
arrayPropName,
|
|
8314
8557
|
imports,
|
|
@@ -8318,11 +8561,10 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8318
8561
|
getTemplateParamIdentifier(classPath.node.body),
|
|
8319
8562
|
tmplSetupCtx
|
|
8320
8563
|
);
|
|
8321
|
-
if (
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
);
|
|
8564
|
+
if (arrayResult && templateMethod) {
|
|
8565
|
+
classPath.node.body.body.push(arrayResult.itemPropsMethod);
|
|
8566
|
+
componentArrayItemPropsMethods.set(arrayMap, arrayResult.itemPropsMethod);
|
|
8567
|
+
const importSource = imports.get(arrayResult.componentTag);
|
|
8326
8568
|
if (importSource) {
|
|
8327
8569
|
const delegatedEvents = getHoistableRootEventsForImport(sourceFile, importSource).map((meta) => ({
|
|
8328
8570
|
eventType: meta.eventType,
|
|
@@ -8335,39 +8577,21 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8335
8577
|
appendCompiledEventMethods(classPath.node.body, delegatedEvents);
|
|
8336
8578
|
}
|
|
8337
8579
|
}
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
});
|
|
8345
|
-
} else if (arrayMap.storeVar) {
|
|
8346
|
-
const refreshMethodName = getComponentArrayRefreshMethodName(arrayPropName);
|
|
8347
|
-
mergeObserveMethod(
|
|
8348
|
-
buildObserveKey(arrayMap.arrayPathParts, arrayMap.storeVar),
|
|
8349
|
-
t18.classMethod(
|
|
8350
|
-
"method",
|
|
8351
|
-
t18.identifier(getObserveMethodName(arrayMap.arrayPathParts, arrayMap.storeVar)),
|
|
8352
|
-
[t18.identifier("value"), t18.identifier("change")],
|
|
8353
|
-
t18.blockStatement([
|
|
8354
|
-
t18.expressionStatement(
|
|
8355
|
-
t18.callExpression(
|
|
8356
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(refreshMethodName)),
|
|
8357
|
-
[]
|
|
8358
|
-
)
|
|
8359
|
-
)
|
|
8360
|
-
])
|
|
8361
|
-
)
|
|
8362
|
-
);
|
|
8363
|
-
storeComponentArrayObservers.push({
|
|
8580
|
+
inlineIntoConstructor(classPath.node.body, [
|
|
8581
|
+
...arrayResult.arrSetupStatements.map((s) => t18.cloneNode(s, true)),
|
|
8582
|
+
arrayResult.constructorInit
|
|
8583
|
+
]);
|
|
8584
|
+
if (arrayMap.storeVar) {
|
|
8585
|
+
observeListConfigs.push({
|
|
8364
8586
|
storeVar: arrayMap.storeVar,
|
|
8365
|
-
|
|
8366
|
-
|
|
8587
|
+
pathParts: arrayMap.arrayPathParts,
|
|
8588
|
+
arrayPropName,
|
|
8589
|
+
componentTag: arrayResult.componentTag,
|
|
8590
|
+
containerBindingId: arrayResult.containerBindingId,
|
|
8591
|
+
itemIdProperty: arrayResult.itemIdProperty
|
|
8367
8592
|
});
|
|
8368
8593
|
}
|
|
8369
8594
|
componentArrayDisposeTargets.push(getComponentArrayItemsName(arrayPropName));
|
|
8370
|
-
componentArrayMountMethods.push(getComponentArrayMountMethodName(arrayPropName));
|
|
8371
8595
|
const mapReplaceExpr = storeArrayAccess ? t18.memberExpression(t18.identifier(storeArrayAccess.storeVar), t18.identifier(storeArrayAccess.propName)) : computationExpr;
|
|
8372
8596
|
replaceMapWithComponentArrayItems(
|
|
8373
8597
|
templateMethod,
|
|
@@ -8377,9 +8601,92 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8377
8601
|
applied = true;
|
|
8378
8602
|
}
|
|
8379
8603
|
}
|
|
8604
|
+
for (const arrayMap of componentArrayMaps) {
|
|
8605
|
+
if (!arrayMap.storeVar) continue;
|
|
8606
|
+
const storeRef = stateRefs.get(arrayMap.storeVar);
|
|
8607
|
+
const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
|
|
8608
|
+
if (!getterDepPaths || getterDepPaths.length === 0) continue;
|
|
8609
|
+
const pathKey = arrayMap.arrayPathParts.join(".");
|
|
8610
|
+
for (const depPath of getterDepPaths) {
|
|
8611
|
+
const depObserveKey = buildObserveKey(depPath, arrayMap.storeVar);
|
|
8612
|
+
const depMethodName = getObserveMethodName(depPath, arrayMap.storeVar);
|
|
8613
|
+
const delegateBody = t18.blockStatement([
|
|
8614
|
+
t18.expressionStatement(
|
|
8615
|
+
t18.callExpression(
|
|
8616
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__refreshList")),
|
|
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
|
|
8626
|
+
);
|
|
8627
|
+
mergeObserveMethod(depObserveKey, delegateMethod);
|
|
8628
|
+
}
|
|
8629
|
+
}
|
|
8630
|
+
for (const arrayMap of componentArrayMaps) {
|
|
8631
|
+
if (!arrayMap.storeVar) continue;
|
|
8632
|
+
const itemPropsMethod = componentArrayItemPropsMethods.get(arrayMap);
|
|
8633
|
+
if (!itemPropsMethod) continue;
|
|
8634
|
+
const pathKey = arrayMap.arrayPathParts.join(".");
|
|
8635
|
+
const storeRef = stateRefs.get(arrayMap.storeVar);
|
|
8636
|
+
const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
|
|
8637
|
+
const getterDepKeys = new Set(
|
|
8638
|
+
(getterDepPaths || []).map((dp) => buildObserveKey(dp, arrayMap.storeVar))
|
|
8639
|
+
);
|
|
8640
|
+
const externalDeps = /* @__PURE__ */ new Map();
|
|
8641
|
+
const clonedBody = t18.cloneNode(itemPropsMethod.body, true);
|
|
8642
|
+
traverse10(t18.program([t18.expressionStatement(t18.arrowFunctionExpression([], clonedBody))]), {
|
|
8643
|
+
noScope: true,
|
|
8644
|
+
Identifier(idPath) {
|
|
8645
|
+
if (idPath.parentPath && t18.isMemberExpression(idPath.parentPath.node) && idPath.parentPath.node.property === idPath.node && !idPath.parentPath.node.computed)
|
|
8646
|
+
return;
|
|
8647
|
+
const ref = stateRefs.get(idPath.node.name);
|
|
8648
|
+
if (!ref) return;
|
|
8649
|
+
if (itemPropsMethod.params.some((p) => t18.isIdentifier(p) && p.name === idPath.node.name)) return;
|
|
8650
|
+
if (ref.kind === "imported-destructured" && ref.storeVar && ref.propName) {
|
|
8651
|
+
const depKey = buildObserveKey([ref.propName], ref.storeVar);
|
|
8652
|
+
if (!getterDepKeys.has(depKey) && !externalDeps.has(depKey)) {
|
|
8653
|
+
externalDeps.set(depKey, { parts: [ref.propName], storeVar: ref.storeVar });
|
|
8654
|
+
}
|
|
8655
|
+
}
|
|
8656
|
+
},
|
|
8657
|
+
MemberExpression(mePath) {
|
|
8658
|
+
const resolved = resolvePath(mePath.node, stateRefs);
|
|
8659
|
+
if (!resolved?.parts?.length || !resolved.isImportedState) return;
|
|
8660
|
+
if (resolved.parts.some((p) => p === "__raw")) return;
|
|
8661
|
+
const depKey = buildObserveKey(resolved.parts, resolved.storeVar);
|
|
8662
|
+
if (!getterDepKeys.has(depKey) && !externalDeps.has(depKey)) {
|
|
8663
|
+
externalDeps.set(depKey, { parts: [...resolved.parts], storeVar: resolved.storeVar });
|
|
8664
|
+
}
|
|
8665
|
+
}
|
|
8666
|
+
});
|
|
8667
|
+
for (const [depKey, dep] of externalDeps) {
|
|
8668
|
+
const depMethodName = getObserveMethodName(dep.parts, dep.storeVar);
|
|
8669
|
+
if (!stateProps.has(depKey)) stateProps.set(depKey, dep.parts);
|
|
8670
|
+
const delegateBody = t18.blockStatement([
|
|
8671
|
+
t18.expressionStatement(
|
|
8672
|
+
t18.callExpression(
|
|
8673
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier("__refreshList")),
|
|
8674
|
+
[t18.stringLiteral(pathKey)]
|
|
8675
|
+
)
|
|
8676
|
+
)
|
|
8677
|
+
]);
|
|
8678
|
+
const delegateMethod = t18.classMethod(
|
|
8679
|
+
"method",
|
|
8680
|
+
t18.identifier(depMethodName),
|
|
8681
|
+
[t18.identifier("__v"), t18.identifier("__c")],
|
|
8682
|
+
delegateBody
|
|
8683
|
+
);
|
|
8684
|
+
mergeObserveMethod(depKey, delegateMethod);
|
|
8685
|
+
}
|
|
8686
|
+
}
|
|
8380
8687
|
const renderEventHandlers = [];
|
|
8381
8688
|
htmlArrayMaps.forEach((arrayMap) => {
|
|
8382
|
-
const { method } = generateRenderItemMethod(
|
|
8689
|
+
const { method, needsUnwrapHelper } = generateRenderItemMethod(
|
|
8383
8690
|
arrayMap,
|
|
8384
8691
|
imports,
|
|
8385
8692
|
renderEventHandlers,
|
|
@@ -8387,6 +8694,7 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8387
8694
|
classPath.node.body,
|
|
8388
8695
|
tmplSetupCtx
|
|
8389
8696
|
);
|
|
8697
|
+
if (needsUnwrapHelper) needsModuleLevelUnwrapHelper = true;
|
|
8390
8698
|
if (method) {
|
|
8391
8699
|
classPath.node.body.body.push(method);
|
|
8392
8700
|
applied = true;
|
|
@@ -8410,24 +8718,28 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8410
8718
|
mergeObserveMethod(observeKey, h);
|
|
8411
8719
|
}
|
|
8412
8720
|
);
|
|
8413
|
-
if (arrayMap.storeVar
|
|
8721
|
+
if (arrayMap.storeVar) {
|
|
8414
8722
|
const storeRef = stateRefs.get(arrayMap.storeVar);
|
|
8415
8723
|
const getterDepPaths = storeRef?.getterDeps?.get(arrayMap.arrayPathParts[0]);
|
|
8416
8724
|
if (getterDepPaths && getterDepPaths.length > 0) {
|
|
8417
8725
|
for (const depPath of getterDepPaths) {
|
|
8418
8726
|
const depObserveKey = buildObserveKey(depPath, arrayMap.storeVar);
|
|
8419
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
|
+
}
|
|
8420
8738
|
const delegateBody = t18.blockStatement([
|
|
8421
8739
|
t18.expressionStatement(
|
|
8422
8740
|
t18.callExpression(
|
|
8423
8741
|
t18.memberExpression(t18.thisExpression(), t18.identifier(arrayHandlerMethodName)),
|
|
8424
|
-
[
|
|
8425
|
-
t18.memberExpression(
|
|
8426
|
-
t18.identifier(arrayMap.storeVar),
|
|
8427
|
-
t18.identifier(arrayMap.arrayPathParts[0])
|
|
8428
|
-
),
|
|
8429
|
-
t18.nullLiteral()
|
|
8430
|
-
]
|
|
8742
|
+
[rereadExpr, t18.nullLiteral()]
|
|
8431
8743
|
)
|
|
8432
8744
|
)
|
|
8433
8745
|
]);
|
|
@@ -8500,50 +8812,6 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8500
8812
|
classPath.node.body.body.push(afterRenderMethod);
|
|
8501
8813
|
}
|
|
8502
8814
|
}
|
|
8503
|
-
if (componentArrayMountMethods.length > 0) {
|
|
8504
|
-
const mountCalls = componentArrayMountMethods.map(
|
|
8505
|
-
(methodName) => t18.expressionStatement(
|
|
8506
|
-
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), [])
|
|
8507
|
-
)
|
|
8508
|
-
);
|
|
8509
|
-
const existingAfterRender = classPath.node.body.body.find(
|
|
8510
|
-
(m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === "onAfterRender"
|
|
8511
|
-
);
|
|
8512
|
-
if (existingAfterRender) {
|
|
8513
|
-
existingAfterRender.body.body.push(...mountCalls);
|
|
8514
|
-
} else {
|
|
8515
|
-
const afterRenderMethod = t18.classMethod(
|
|
8516
|
-
"method",
|
|
8517
|
-
t18.identifier("onAfterRender"),
|
|
8518
|
-
[],
|
|
8519
|
-
t18.blockStatement([
|
|
8520
|
-
t18.expressionStatement(
|
|
8521
|
-
t18.callExpression(
|
|
8522
|
-
t18.memberExpression(t18.super(), t18.identifier("onAfterRender")),
|
|
8523
|
-
[]
|
|
8524
|
-
)
|
|
8525
|
-
),
|
|
8526
|
-
...mountCalls
|
|
8527
|
-
])
|
|
8528
|
-
);
|
|
8529
|
-
classPath.node.body.body.push(afterRenderMethod);
|
|
8530
|
-
}
|
|
8531
|
-
const rerenderOverride = t18.classMethod(
|
|
8532
|
-
"method",
|
|
8533
|
-
t18.identifier("__geaRequestRender"),
|
|
8534
|
-
[],
|
|
8535
|
-
t18.blockStatement([
|
|
8536
|
-
t18.expressionStatement(
|
|
8537
|
-
t18.callExpression(
|
|
8538
|
-
t18.memberExpression(t18.super(), t18.identifier("__geaRequestRender")),
|
|
8539
|
-
[]
|
|
8540
|
-
)
|
|
8541
|
-
),
|
|
8542
|
-
...mountCalls.map((stmt) => t18.cloneNode(stmt, true))
|
|
8543
|
-
])
|
|
8544
|
-
);
|
|
8545
|
-
classPath.node.body.body.push(rerenderOverride);
|
|
8546
|
-
}
|
|
8547
8815
|
if (renderEventHandlers.length > 0) {
|
|
8548
8816
|
applied = appendCompiledEventMethods(classPath.node.body, renderEventHandlers) || applied;
|
|
8549
8817
|
}
|
|
@@ -8563,7 +8831,6 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8563
8831
|
}
|
|
8564
8832
|
return importedStores.get(storeVar);
|
|
8565
8833
|
};
|
|
8566
|
-
const prevValueInits = [];
|
|
8567
8834
|
addedMethods.forEach((_method, observeKey) => {
|
|
8568
8835
|
const { parts, storeVar } = parseObserveKey(observeKey);
|
|
8569
8836
|
if (!storeVar) {
|
|
@@ -8572,82 +8839,42 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8572
8839
|
const compGetterDeps = componentGetterStoreDeps.get(parts[0]);
|
|
8573
8840
|
if (compGetterDeps && compGetterDeps.length > 0) {
|
|
8574
8841
|
const originalMethodName = getObserveMethodName(parts);
|
|
8575
|
-
const wrapperMethodName = `${originalMethodName}__via`;
|
|
8576
|
-
if (!classPath.node.body.body.some(
|
|
8577
|
-
(m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === wrapperMethodName
|
|
8578
|
-
)) {
|
|
8579
|
-
classPath.node.body.body.push(
|
|
8580
|
-
t18.classMethod(
|
|
8581
|
-
"method",
|
|
8582
|
-
t18.identifier(wrapperMethodName),
|
|
8583
|
-
[t18.identifier("_v"), t18.identifier("change")],
|
|
8584
|
-
t18.blockStatement([
|
|
8585
|
-
t18.expressionStatement(
|
|
8586
|
-
t18.callExpression(
|
|
8587
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(originalMethodName)),
|
|
8588
|
-
[
|
|
8589
|
-
t18.memberExpression(t18.thisExpression(), t18.identifier(parts[0])),
|
|
8590
|
-
t18.nullLiteral()
|
|
8591
|
-
]
|
|
8592
|
-
)
|
|
8593
|
-
)
|
|
8594
|
-
])
|
|
8595
|
-
)
|
|
8596
|
-
);
|
|
8597
|
-
}
|
|
8598
8842
|
for (const dep of compGetterDeps) {
|
|
8599
8843
|
const depKey = buildObserveKey(dep.pathParts, dep.storeVar) + `__getter_${parts[0]}`;
|
|
8600
8844
|
ensureStoreGroup(dep.storeVar).observeHandlers.set(depKey, {
|
|
8601
8845
|
pathParts: dep.pathParts,
|
|
8602
|
-
methodName:
|
|
8846
|
+
methodName: originalMethodName,
|
|
8847
|
+
isVia: true,
|
|
8848
|
+
rereadExpr: t18.memberExpression(t18.thisExpression(), t18.identifier(parts[0]))
|
|
8603
8849
|
});
|
|
8604
8850
|
}
|
|
8605
|
-
const compPrevProp = `__geaPrev_${originalMethodName}`;
|
|
8606
|
-
prevValueInits.push(
|
|
8607
|
-
js7`try { this.${id11(compPrevProp)} = this.${id11(parts[0])}; } catch(_e) {}`
|
|
8608
|
-
);
|
|
8609
8851
|
}
|
|
8610
8852
|
return;
|
|
8611
8853
|
}
|
|
8612
8854
|
localObserveHandlers.set(observeKey, { pathParts: parts, methodName: getObserveMethodName(parts) });
|
|
8613
8855
|
return;
|
|
8614
8856
|
}
|
|
8615
|
-
|
|
8857
|
+
{
|
|
8616
8858
|
const storeRef = stateRefs.get(storeVar);
|
|
8617
8859
|
const getterDepPaths = storeRef?.getterDeps?.get(parts[0]);
|
|
8618
8860
|
if (getterDepPaths && getterDepPaths.length > 0) {
|
|
8619
8861
|
const originalMethodName = getObserveMethodName(parts, storeVar);
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
)
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
"method",
|
|
8627
|
-
t18.identifier(wrapperMethodName),
|
|
8628
|
-
[t18.identifier("_v"), t18.identifier("change")],
|
|
8629
|
-
t18.blockStatement([
|
|
8630
|
-
t18.expressionStatement(
|
|
8631
|
-
t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(originalMethodName)), [
|
|
8632
|
-
t18.memberExpression(t18.identifier(storeVar), t18.identifier(parts[0])),
|
|
8633
|
-
t18.nullLiteral()
|
|
8634
|
-
])
|
|
8635
|
-
)
|
|
8636
|
-
])
|
|
8637
|
-
)
|
|
8638
|
-
);
|
|
8862
|
+
let rereadExpr = t18.memberExpression(
|
|
8863
|
+
t18.identifier(storeVar),
|
|
8864
|
+
t18.identifier(parts[0])
|
|
8865
|
+
);
|
|
8866
|
+
for (let i = 1; i < parts.length; i++) {
|
|
8867
|
+
rereadExpr = t18.memberExpression(rereadExpr, t18.identifier(parts[i]));
|
|
8639
8868
|
}
|
|
8640
8869
|
for (const depPath of getterDepPaths) {
|
|
8641
|
-
const depKey = buildObserveKey(depPath, storeVar) + `__getter_${parts
|
|
8870
|
+
const depKey = buildObserveKey(depPath, storeVar) + `__getter_${parts.join("_")}`;
|
|
8642
8871
|
ensureStoreGroup(storeVar).observeHandlers.set(depKey, {
|
|
8643
8872
|
pathParts: depPath,
|
|
8644
|
-
methodName:
|
|
8873
|
+
methodName: originalMethodName,
|
|
8874
|
+
isVia: true,
|
|
8875
|
+
rereadExpr
|
|
8645
8876
|
});
|
|
8646
8877
|
}
|
|
8647
|
-
const prevProp = `__geaPrev_${originalMethodName}`;
|
|
8648
|
-
prevValueInits.push(
|
|
8649
|
-
js7`try { this.${id11(prevProp)} = ${t18.memberExpression(t18.identifier(storeVar), t18.identifier(parts[0]))}; } catch(_e) {}`
|
|
8650
|
-
);
|
|
8651
8878
|
return;
|
|
8652
8879
|
}
|
|
8653
8880
|
}
|
|
@@ -8711,28 +8938,53 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8711
8938
|
methodName: obs.refreshMethodName
|
|
8712
8939
|
});
|
|
8713
8940
|
}
|
|
8941
|
+
if (guardStateKeys.size > 0) {
|
|
8942
|
+
addedMethods.forEach((method, observeKey) => {
|
|
8943
|
+
const { parts, storeVar: sv } = parseObserveKey(observeKey);
|
|
8944
|
+
if (!sv || parts.length < 2) return;
|
|
8945
|
+
for (let prefixLen = 1; prefixLen < parts.length; prefixLen++) {
|
|
8946
|
+
const prefixKey = buildObserveKey(parts.slice(0, prefixLen), sv);
|
|
8947
|
+
if (guardStateKeys.has(prefixKey)) {
|
|
8948
|
+
const guardCheck = t18.ifStatement(
|
|
8949
|
+
t18.binaryExpression(
|
|
8950
|
+
"==",
|
|
8951
|
+
t18.memberExpression(t18.identifier(sv), t18.identifier(parts[prefixLen - 1])),
|
|
8952
|
+
t18.nullLiteral()
|
|
8953
|
+
),
|
|
8954
|
+
t18.returnStatement()
|
|
8955
|
+
);
|
|
8956
|
+
if (t18.isBlockStatement(method.body)) {
|
|
8957
|
+
method.body.body.unshift(guardCheck);
|
|
8958
|
+
}
|
|
8959
|
+
break;
|
|
8960
|
+
}
|
|
8961
|
+
}
|
|
8962
|
+
});
|
|
8963
|
+
}
|
|
8714
8964
|
if (importedStores.size > 0 || localObserveHandlers.size > 0 || mapRegistrations.length > 0) {
|
|
8715
8965
|
const storeConfigs = Array.from(importedStores.entries()).map(([storeVar, config]) => ({
|
|
8716
8966
|
storeVar,
|
|
8717
8967
|
captureExpression: config.captureExpression,
|
|
8718
|
-
observeHandlers: Array.from(config.observeHandlers.values()).map(({ pathParts, methodName }) => ({
|
|
8968
|
+
observeHandlers: Array.from(config.observeHandlers.values()).map(({ pathParts, methodName, isVia, rereadExpr }) => ({
|
|
8719
8969
|
pathParts,
|
|
8720
|
-
methodName
|
|
8970
|
+
methodName,
|
|
8971
|
+
isVia,
|
|
8972
|
+
rereadExpr
|
|
8721
8973
|
}))
|
|
8722
8974
|
}));
|
|
8723
|
-
|
|
8724
|
-
|
|
8975
|
+
for (const olc of observeListConfigs) {
|
|
8976
|
+
ensureStoreGroup(olc.storeVar);
|
|
8977
|
+
}
|
|
8978
|
+
if (storeConfigs.length > 0 || mapRegistrations.length > 0 || observeListConfigs.length > 0) {
|
|
8979
|
+
const createdHooksMethod = generateCreatedHooks(storeConfigs, htmlArrayMaps.length > 0, observeListConfigs);
|
|
8725
8980
|
if (mapRegistrations.length > 0) {
|
|
8726
8981
|
createdHooksMethod.body.body.push(...mapRegistrations);
|
|
8727
8982
|
}
|
|
8728
|
-
if (prevValueInits.length > 0) {
|
|
8729
|
-
createdHooksMethod.body.body.push(...prevValueInits);
|
|
8730
|
-
}
|
|
8731
8983
|
classPath.node.body.body.push(createdHooksMethod);
|
|
8732
8984
|
}
|
|
8733
8985
|
if (localObserveHandlers.size > 0) {
|
|
8734
8986
|
classPath.node.body.body.push(
|
|
8735
|
-
generateLocalStateObserverSetup(Array.from(localObserveHandlers.values()))
|
|
8987
|
+
generateLocalStateObserverSetup(Array.from(localObserveHandlers.values()), htmlArrayMaps.length > 0)
|
|
8736
8988
|
);
|
|
8737
8989
|
}
|
|
8738
8990
|
}
|
|
@@ -8741,6 +8993,14 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
8741
8993
|
});
|
|
8742
8994
|
}
|
|
8743
8995
|
});
|
|
8996
|
+
if (needsModuleLevelUnwrapHelper) {
|
|
8997
|
+
const alreadyHas = ast.program.body.some(
|
|
8998
|
+
(stmt) => t18.isVariableDeclaration(stmt) && stmt.declarations.some((d) => t18.isIdentifier(d.id) && d.id.name === "__v")
|
|
8999
|
+
);
|
|
9000
|
+
if (!alreadyHas) {
|
|
9001
|
+
ast.program.body.unshift(buildValueUnwrapHelper());
|
|
9002
|
+
}
|
|
9003
|
+
}
|
|
8744
9004
|
return applied;
|
|
8745
9005
|
}
|
|
8746
9006
|
function collectUnresolvedDependencies(unresolvedMaps, stateRefs, classBody2) {
|
|
@@ -8844,7 +9104,7 @@ function generateUnresolvedRelationalObserver(arrayMap, unresolvedMap, relBindin
|
|
|
8844
9104
|
t18.memberExpression(t18.thisExpression(), t18.identifier("id")),
|
|
8845
9105
|
t18.stringLiteral("-" + arrayMap.containerBindingId)
|
|
8846
9106
|
)
|
|
8847
|
-
]) :
|
|
9107
|
+
]) : jsExpr4`this.$(":scope")`;
|
|
8848
9108
|
const setupStatements = replacePropRefsInStatements(
|
|
8849
9109
|
(unresolvedMap.computationSetupStatements || []).map((s) => t18.cloneNode(s, true)),
|
|
8850
9110
|
templatePropNames,
|
|
@@ -8866,7 +9126,7 @@ function generateUnresolvedRelationalObserver(arrayMap, unresolvedMap, relBindin
|
|
|
8866
9126
|
method,
|
|
8867
9127
|
js7`if (!this.rendered_) return;`,
|
|
8868
9128
|
lazyInit2(containerName, containerLookup),
|
|
8869
|
-
...
|
|
9129
|
+
...jsBlockBody4`if (!${containerRef}) return;`,
|
|
8870
9130
|
...setupStatements,
|
|
8871
9131
|
t18.variableDeclaration("var", [
|
|
8872
9132
|
t18.variableDeclarator(
|
|
@@ -8878,7 +9138,7 @@ function generateUnresolvedRelationalObserver(arrayMap, unresolvedMap, relBindin
|
|
|
8878
9138
|
)
|
|
8879
9139
|
)
|
|
8880
9140
|
]),
|
|
8881
|
-
...
|
|
9141
|
+
...jsBlockBody4`
|
|
8882
9142
|
var __items = ${containerRef}.querySelectorAll('[data-gea-item-id]');
|
|
8883
9143
|
for (var __i = 0; __i < __items.length && __i < __arr.length; __i++) {
|
|
8884
9144
|
var __child = __items[__i];
|
|
@@ -8909,15 +9169,15 @@ function generateMapRegistration(arrayMap, unresolvedMap, templatePropNames, who
|
|
|
8909
9169
|
t18.memberExpression(t18.thisExpression(), t18.identifier("id")),
|
|
8910
9170
|
t18.stringLiteral("-" + arrayMap.containerBindingId)
|
|
8911
9171
|
)
|
|
8912
|
-
]) :
|
|
9172
|
+
]) : jsExpr4`this.$(":scope")`;
|
|
8913
9173
|
let arrExpr = t18.cloneNode(unresolvedMap.computationExpr || t18.arrayExpression([]), true);
|
|
8914
|
-
let setupStatements = [];
|
|
9174
|
+
let setupStatements = unresolvedMap.computationSetupStatements?.length ? unresolvedMap.computationSetupStatements.map((s) => t18.cloneNode(s, true)) : [];
|
|
8915
9175
|
const needsReplace = templatePropNames && templatePropNames.size > 0 || wholeParamName;
|
|
8916
9176
|
if (needsReplace) {
|
|
8917
9177
|
arrExpr = replacePropRefsInExpression(arrExpr, templatePropNames || /* @__PURE__ */ new Set(), wholeParamName);
|
|
8918
|
-
if (
|
|
9178
|
+
if (setupStatements.length) {
|
|
8919
9179
|
setupStatements = replacePropRefsInStatements(
|
|
8920
|
-
|
|
9180
|
+
setupStatements,
|
|
8921
9181
|
templatePropNames || /* @__PURE__ */ new Set(),
|
|
8922
9182
|
wholeParamName
|
|
8923
9183
|
);
|
|
@@ -9038,15 +9298,7 @@ function replaceMapWithComponentArrayItems(templateMethod, arrayExpr, itemsName)
|
|
|
9038
9298
|
toReplace = path.parentPath.parentPath;
|
|
9039
9299
|
}
|
|
9040
9300
|
const itemsAccess = t18.memberExpression(t18.thisExpression(), t18.identifier(itemsName));
|
|
9041
|
-
const
|
|
9042
|
-
[t18.identifier("__item")],
|
|
9043
|
-
t18.templateLiteral(
|
|
9044
|
-
[t18.templateElement({ raw: "", cooked: "" }), t18.templateElement({ raw: "", cooked: "" })],
|
|
9045
|
-
[t18.identifier("__item")]
|
|
9046
|
-
)
|
|
9047
|
-
);
|
|
9048
|
-
const mapCall = t18.callExpression(t18.memberExpression(itemsAccess, t18.identifier("map")), [mapCallback]);
|
|
9049
|
-
const joinCall = t18.callExpression(t18.memberExpression(mapCall, t18.identifier("join")), [t18.stringLiteral("")]);
|
|
9301
|
+
const joinCall = t18.callExpression(t18.memberExpression(itemsAccess, t18.identifier("join")), [t18.stringLiteral("")]);
|
|
9050
9302
|
toReplace.replaceWith(joinCall);
|
|
9051
9303
|
replaced = true;
|
|
9052
9304
|
}
|
|
@@ -9067,23 +9319,6 @@ function inlineIntoConstructor(classBody2, statements) {
|
|
|
9067
9319
|
}
|
|
9068
9320
|
ctor.body.body.push(...statements);
|
|
9069
9321
|
}
|
|
9070
|
-
function ensureConstructorCalls(classBody2, methodName) {
|
|
9071
|
-
let ctor = classBody2.body.find(
|
|
9072
|
-
(member) => t18.isClassMethod(member) && t18.isIdentifier(member.key) && member.key.name === "constructor"
|
|
9073
|
-
);
|
|
9074
|
-
if (!ctor) {
|
|
9075
|
-
ctor = appendToBody5(
|
|
9076
|
-
jsMethod8`${id11("constructor")}(...args) {}`,
|
|
9077
|
-
t18.expressionStatement(t18.callExpression(t18.super(), [t18.spreadElement(t18.identifier("args"))])),
|
|
9078
|
-
t18.expressionStatement(t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), []))
|
|
9079
|
-
);
|
|
9080
|
-
classBody2.body.unshift(ctor);
|
|
9081
|
-
return;
|
|
9082
|
-
}
|
|
9083
|
-
ctor.body.body.push(
|
|
9084
|
-
t18.expressionStatement(t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(methodName)), []))
|
|
9085
|
-
);
|
|
9086
|
-
}
|
|
9087
9322
|
function ensureDisposeCalls(classBody2, targets) {
|
|
9088
9323
|
const disposeStatements = targets.map(
|
|
9089
9324
|
(target) => js7`this.${id11(target)}?.forEach?.(item => item?.dispose?.());`
|
|
@@ -9151,28 +9386,50 @@ function ensureOnPropChangeMethod(classBody2, inlinePatchBodies, compiledChildre
|
|
|
9151
9386
|
nonDirectChildren.push(child);
|
|
9152
9387
|
}
|
|
9153
9388
|
}
|
|
9154
|
-
const
|
|
9155
|
-
const arrayRefreshMethodNames = arrayRefreshDeps.filter((d) => d.propNames.length > 0).map((d) => d.methodName);
|
|
9156
|
-
const refreshMethodNames = [.../* @__PURE__ */ new Set([...childRefreshMethodNames, ...arrayRefreshMethodNames])];
|
|
9157
|
-
const refreshPropDeps = /* @__PURE__ */ new Map();
|
|
9158
|
-
for (const child of nonDirectChildren) {
|
|
9159
|
-
const methodName = `__refreshChildProps_${child.instanceVar.replace(/^_/, "")}`;
|
|
9389
|
+
const childRefreshEntries = nonDirectChildren.filter((child) => child.dependencies.some((dep) => !dep.storeVar && dep.pathParts[0] === "props")).map((child) => {
|
|
9160
9390
|
const depProps = /* @__PURE__ */ new Set();
|
|
9161
9391
|
for (const dep of child.dependencies) {
|
|
9162
9392
|
if (!dep.storeVar && dep.pathParts[0] === "props" && dep.pathParts.length > 1) {
|
|
9163
9393
|
depProps.add(dep.pathParts[1]);
|
|
9164
9394
|
}
|
|
9165
9395
|
}
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9396
|
+
return { child, depProps };
|
|
9397
|
+
});
|
|
9398
|
+
const arrayRefreshMethodNames = arrayRefreshDeps.filter((d) => d.propNames.length > 0).map((d) => d.methodName);
|
|
9399
|
+
const refreshPropDeps = /* @__PURE__ */ new Map();
|
|
9170
9400
|
for (const { methodName, propNames } of arrayRefreshDeps) {
|
|
9171
9401
|
if (propNames.length > 0) {
|
|
9172
9402
|
refreshPropDeps.set(methodName, new Set(propNames));
|
|
9173
9403
|
}
|
|
9174
9404
|
}
|
|
9175
|
-
const
|
|
9405
|
+
const childRefreshCalls = childRefreshEntries.map(({ child, depProps }) => {
|
|
9406
|
+
const call = t18.expressionStatement(
|
|
9407
|
+
t18.callExpression(
|
|
9408
|
+
t18.memberExpression(
|
|
9409
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(child.instanceVar)),
|
|
9410
|
+
t18.identifier("__geaUpdateProps")
|
|
9411
|
+
),
|
|
9412
|
+
[
|
|
9413
|
+
t18.callExpression(
|
|
9414
|
+
t18.memberExpression(
|
|
9415
|
+
t18.thisExpression(),
|
|
9416
|
+
t18.identifier(`__buildProps_${child.instanceVar.replace(/^_/, "")}`)
|
|
9417
|
+
),
|
|
9418
|
+
[]
|
|
9419
|
+
)
|
|
9420
|
+
]
|
|
9421
|
+
)
|
|
9422
|
+
);
|
|
9423
|
+
if (depProps.size > 0) {
|
|
9424
|
+
const guard = Array.from(depProps).reduce((acc, prop) => {
|
|
9425
|
+
const test = t18.binaryExpression("===", t18.identifier("key"), t18.stringLiteral(prop));
|
|
9426
|
+
return acc ? t18.logicalExpression("||", acc, test) : test;
|
|
9427
|
+
}, void 0);
|
|
9428
|
+
return t18.ifStatement(guard, call);
|
|
9429
|
+
}
|
|
9430
|
+
return call;
|
|
9431
|
+
});
|
|
9432
|
+
const arrayRefreshCalls = arrayRefreshMethodNames.map((name) => {
|
|
9176
9433
|
const deps = refreshPropDeps.get(name);
|
|
9177
9434
|
const call = t18.expressionStatement(t18.callExpression(t18.memberExpression(t18.thisExpression(), t18.identifier(name)), []));
|
|
9178
9435
|
if (deps && deps.size > 0) {
|
|
@@ -9184,6 +9441,7 @@ function ensureOnPropChangeMethod(classBody2, inlinePatchBodies, compiledChildre
|
|
|
9184
9441
|
}
|
|
9185
9442
|
return call;
|
|
9186
9443
|
});
|
|
9444
|
+
const refreshCalls = [...childRefreshCalls, ...arrayRefreshCalls];
|
|
9187
9445
|
const condPatchCalls = [];
|
|
9188
9446
|
if (conditionalSlots.length > 0) {
|
|
9189
9447
|
for (let i = 0; i < conditionalSlots.length; i++) {
|
|
@@ -9205,10 +9463,7 @@ function ensureOnPropChangeMethod(classBody2, inlinePatchBodies, compiledChildre
|
|
|
9205
9463
|
const patchCalls = Array.from(inlinePatchBodies.entries()).map(
|
|
9206
9464
|
([propName, bodyStmts]) => t18.ifStatement(
|
|
9207
9465
|
t18.binaryExpression("===", t18.identifier("key"), t18.stringLiteral(propName)),
|
|
9208
|
-
t18.
|
|
9209
|
-
t18.blockStatement(bodyStmts.map((s) => t18.cloneNode(s, true))),
|
|
9210
|
-
t18.catchClause(null, t18.blockStatement([]))
|
|
9211
|
-
)
|
|
9466
|
+
t18.blockStatement(bodyStmts.map((s) => t18.cloneNode(s, true)))
|
|
9212
9467
|
)
|
|
9213
9468
|
);
|
|
9214
9469
|
const unresolvedMapRefreshCalls = unresolvedMapPropRefreshDeps.map((dep) => {
|
|
@@ -9413,7 +9668,7 @@ function generateConditionalPatchMethods(classBody2, slots, templatePropNames, w
|
|
|
9413
9668
|
}
|
|
9414
9669
|
const evalStatements = [...initSetup, ...condAssignments];
|
|
9415
9670
|
const initBody = evalStatements.length > 0 ? [
|
|
9416
|
-
t18.tryStatement(t18.blockStatement(evalStatements),
|
|
9671
|
+
t18.tryStatement(t18.blockStatement(evalStatements), loggingCatchClause()),
|
|
9417
9672
|
...registerCondCalls
|
|
9418
9673
|
] : registerCondCalls;
|
|
9419
9674
|
inlineIntoConstructor(classBody2, initBody);
|
|
@@ -9691,14 +9946,14 @@ function generateRerenderObserver(pathParts, storeVar, truthinessOnly) {
|
|
|
9691
9946
|
const prevProp = `__geaPrev_${getObserveMethodName(pathParts, storeVar)}`;
|
|
9692
9947
|
if (truthinessOnly) {
|
|
9693
9948
|
method.body.body.push(
|
|
9694
|
-
...
|
|
9949
|
+
...jsBlockBody4`
|
|
9695
9950
|
if (!value === !this.${id11(prevProp)}) return;
|
|
9696
9951
|
this.${id11(prevProp)} = value;
|
|
9697
9952
|
`
|
|
9698
9953
|
);
|
|
9699
9954
|
} else {
|
|
9700
9955
|
method.body.body.push(
|
|
9701
|
-
...
|
|
9956
|
+
...jsBlockBody4`
|
|
9702
9957
|
if (value === this.${id11(prevProp)}) return;
|
|
9703
9958
|
this.${id11(prevProp)} = value;
|
|
9704
9959
|
`
|
|
@@ -9781,6 +10036,27 @@ function generateStateChildSwapMethod(classBody2, stateChildSlots) {
|
|
|
9781
10036
|
setupStatements.push(t18.cloneNode(stmt, true));
|
|
9782
10037
|
}
|
|
9783
10038
|
}
|
|
10039
|
+
const propsUpdateCalls = stateChildSlots.map((slot) => {
|
|
10040
|
+
const buildPropsName = `__buildProps_${slot.childInstanceVar.replace(/^_/, "")}`;
|
|
10041
|
+
const hasBuildProps = classBody2.body.some(
|
|
10042
|
+
(m) => t18.isClassMethod(m) && t18.isIdentifier(m.key) && m.key.name === buildPropsName
|
|
10043
|
+
);
|
|
10044
|
+
if (!hasBuildProps) return null;
|
|
10045
|
+
return t18.expressionStatement(
|
|
10046
|
+
t18.callExpression(
|
|
10047
|
+
t18.memberExpression(
|
|
10048
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(slot.childInstanceVar)),
|
|
10049
|
+
t18.identifier("__geaUpdateProps")
|
|
10050
|
+
),
|
|
10051
|
+
[
|
|
10052
|
+
t18.callExpression(
|
|
10053
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(buildPropsName)),
|
|
10054
|
+
[]
|
|
10055
|
+
)
|
|
10056
|
+
]
|
|
10057
|
+
)
|
|
10058
|
+
);
|
|
10059
|
+
}).filter(Boolean);
|
|
9784
10060
|
const swapCalls = stateChildSlots.map((slot) => {
|
|
9785
10061
|
const guardClone = t18.cloneNode(slot.guardExpr, true);
|
|
9786
10062
|
return t18.expressionStatement(
|
|
@@ -9789,17 +10065,17 @@ function generateStateChildSwapMethod(classBody2, stateChildSlots) {
|
|
|
9789
10065
|
t18.logicalExpression(
|
|
9790
10066
|
"&&",
|
|
9791
10067
|
guardClone,
|
|
9792
|
-
t18.
|
|
10068
|
+
t18.memberExpression(t18.thisExpression(), t18.identifier(slot.childInstanceVar))
|
|
9793
10069
|
)
|
|
9794
10070
|
])
|
|
9795
10071
|
);
|
|
9796
10072
|
});
|
|
9797
|
-
const filteredSetup = pruneUnusedSetupDestructuring(setupStatements, swapCalls);
|
|
10073
|
+
const filteredSetup = pruneUnusedSetupDestructuring(setupStatements, [...propsUpdateCalls, ...swapCalls]);
|
|
9798
10074
|
const method = t18.classMethod(
|
|
9799
10075
|
"method",
|
|
9800
10076
|
t18.identifier("__geaSwapStateChildren"),
|
|
9801
10077
|
[],
|
|
9802
|
-
t18.blockStatement([...filteredSetup, ...swapCalls])
|
|
10078
|
+
t18.blockStatement([...filteredSetup, ...propsUpdateCalls, ...swapCalls])
|
|
9803
10079
|
);
|
|
9804
10080
|
classBody2.body.push(method);
|
|
9805
10081
|
}
|
|
@@ -10402,8 +10678,8 @@ function transformRemainingJSX(ast, imports) {
|
|
|
10402
10678
|
traverse12(ast, {
|
|
10403
10679
|
noScope: true,
|
|
10404
10680
|
JSXElement(path) {
|
|
10405
|
-
const
|
|
10406
|
-
if (
|
|
10681
|
+
const classMethod8 = path.findParent((p) => t20.isClassMethod(p.node));
|
|
10682
|
+
if (classMethod8 && t20.isClassMethod(classMethod8.node) && t20.isIdentifier(classMethod8.node.key) && classMethod8.node.key.name === "template")
|
|
10407
10683
|
return;
|
|
10408
10684
|
try {
|
|
10409
10685
|
path.replaceWith(transformJSXToTemplate(path.node, { imports }));
|
|
@@ -10412,8 +10688,8 @@ function transformRemainingJSX(ast, imports) {
|
|
|
10412
10688
|
}
|
|
10413
10689
|
},
|
|
10414
10690
|
JSXFragment(path) {
|
|
10415
|
-
const
|
|
10416
|
-
if (
|
|
10691
|
+
const classMethod8 = path.findParent((p) => t20.isClassMethod(p.node));
|
|
10692
|
+
if (classMethod8 && t20.isClassMethod(classMethod8.node) && t20.isIdentifier(classMethod8.node.key) && classMethod8.node.key.name === "template")
|
|
10417
10693
|
return;
|
|
10418
10694
|
try {
|
|
10419
10695
|
path.replaceWith(transformJSXFragmentToTemplate(path.node, { imports }));
|
|
@@ -10910,7 +11186,8 @@ function geaPlugin() {
|
|
|
10910
11186
|
storeImports.set(spec.local.name, source);
|
|
10911
11187
|
}
|
|
10912
11188
|
const importedName = spec.imported?.name ?? spec.local.name;
|
|
10913
|
-
|
|
11189
|
+
const geaCoreBaseClasses = ["Component", "Store"];
|
|
11190
|
+
if (source === "@geajs/core" && isComponentTag(importedName) && !geaCoreBaseClasses.includes(importedName)) {
|
|
10914
11191
|
knownComponentImports.add(spec.local.name);
|
|
10915
11192
|
}
|
|
10916
11193
|
}
|