@geajs/vite-plugin 1.1.0 → 1.1.3
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 +81 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1642,7 +1642,9 @@ function stmtUsesPropRefreshCall(stmt) {
|
|
|
1642
1642
|
}
|
|
1643
1643
|
function containsPropRefreshCall(node) {
|
|
1644
1644
|
if (t2.isMemberExpression(node) && t2.isIdentifier(node.property)) {
|
|
1645
|
-
|
|
1645
|
+
const n = node.property.name;
|
|
1646
|
+
if (n === "GEA_UPDATE_PROPS" || n === "GEA_SYNC_MAP" || n === "GEA_PATCH_COND" || n.startsWith("__refresh"))
|
|
1647
|
+
return true;
|
|
1646
1648
|
}
|
|
1647
1649
|
const keys = t2.VISITOR_KEYS[node.type];
|
|
1648
1650
|
if (!keys) return false;
|
|
@@ -3773,6 +3775,16 @@ function analyzeChildren(node, tagName, elementPath, bindings, propBindings, arr
|
|
|
3773
3775
|
);
|
|
3774
3776
|
const slotCountAfter = conditionalSlots?.length ?? 0;
|
|
3775
3777
|
const slotId = slotCountAfter > slotCountBefore ? conditionalSlots[slotCountAfter - 1].slotId : void 0;
|
|
3778
|
+
if (slotCountAfter > slotCountBefore && conditionalSlots && conditionalSlotNodeMap && templateSetupContext) {
|
|
3779
|
+
registerNestedConditionalsInBranches(
|
|
3780
|
+
expr,
|
|
3781
|
+
stateRefs,
|
|
3782
|
+
templateSetupContext,
|
|
3783
|
+
conditionalSlots,
|
|
3784
|
+
conditionalSlotNodeMap,
|
|
3785
|
+
classBody2
|
|
3786
|
+
);
|
|
3787
|
+
}
|
|
3776
3788
|
nestedMapCalls.forEach(({ mapExpr, parentElement, containerPath }) => {
|
|
3777
3789
|
let mapNode = node;
|
|
3778
3790
|
let mapElementPath = elementPath;
|
|
@@ -4320,6 +4332,59 @@ function extractConditionalControlExpression(expr) {
|
|
|
4320
4332
|
}
|
|
4321
4333
|
return null;
|
|
4322
4334
|
}
|
|
4335
|
+
function registerNestedConditionalsInBranches(expr, stateRefs, templateSetupContext, conditionalSlots, conditionalSlotNodeMap, classBody2) {
|
|
4336
|
+
function visitChildren(children) {
|
|
4337
|
+
for (const child of children) {
|
|
4338
|
+
if (t9.isJSXElement(child)) visitChildren(child.children);
|
|
4339
|
+
else if (t9.isJSXFragment(child)) visitChildren(child.children);
|
|
4340
|
+
else if (t9.isJSXExpressionContainer(child) && !t9.isJSXEmptyExpression(child.expression)) {
|
|
4341
|
+
const innerExpr = child.expression;
|
|
4342
|
+
if (!expressionMayProduceJSX(innerExpr)) continue;
|
|
4343
|
+
const conditionExpr = extractConditionalControlExpression(innerExpr);
|
|
4344
|
+
if (!conditionExpr) continue;
|
|
4345
|
+
const condSetupStatements = collectTemplateSetupStatements(conditionExpr, templateSetupContext);
|
|
4346
|
+
const fullSetupStatements = collectTemplateSetupStatements(innerExpr, templateSetupContext);
|
|
4347
|
+
const allDeps = collectExpressionDependencies(conditionExpr, stateRefs, condSetupStatements);
|
|
4348
|
+
if (allDeps.length === 0) continue;
|
|
4349
|
+
const slotId = `c${conditionalSlots.length}`;
|
|
4350
|
+
conditionalSlots.push({
|
|
4351
|
+
slotId,
|
|
4352
|
+
conditionExpr: t9.cloneNode(conditionExpr, true),
|
|
4353
|
+
setupStatements: condSetupStatements.map((s) => t9.cloneNode(s, true)),
|
|
4354
|
+
htmlSetupStatements: fullSetupStatements.map((s) => t9.cloneNode(s, true)),
|
|
4355
|
+
...expressionContainsComponentJSX(innerExpr) ? { hasCompiledChildren: true } : {},
|
|
4356
|
+
dependentPropNames: [],
|
|
4357
|
+
dependencies: allDeps.map((dep) => ({
|
|
4358
|
+
observeKey: dep.observeKey,
|
|
4359
|
+
pathParts: [...dep.pathParts],
|
|
4360
|
+
...dep.storeVar ? { storeVar: dep.storeVar } : {}
|
|
4361
|
+
})),
|
|
4362
|
+
originalExpr: t9.cloneNode(innerExpr, true)
|
|
4363
|
+
});
|
|
4364
|
+
conditionalSlotNodeMap.set(innerExpr, slotId);
|
|
4365
|
+
registerNestedConditionalsInBranches(
|
|
4366
|
+
innerExpr,
|
|
4367
|
+
stateRefs,
|
|
4368
|
+
templateSetupContext,
|
|
4369
|
+
conditionalSlots,
|
|
4370
|
+
conditionalSlotNodeMap,
|
|
4371
|
+
classBody2
|
|
4372
|
+
);
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
}
|
|
4376
|
+
function visitBranch(node) {
|
|
4377
|
+
if (t9.isJSXElement(node)) visitChildren(node.children);
|
|
4378
|
+
else if (t9.isJSXFragment(node)) visitChildren(node.children);
|
|
4379
|
+
else if (t9.isParenthesizedExpression(node)) visitBranch(node.expression);
|
|
4380
|
+
}
|
|
4381
|
+
if (t9.isConditionalExpression(expr)) {
|
|
4382
|
+
visitBranch(expr.consequent);
|
|
4383
|
+
visitBranch(expr.alternate);
|
|
4384
|
+
} else if (t9.isLogicalExpression(expr) && expr.operator === "&&") {
|
|
4385
|
+
visitBranch(expr.right);
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4323
4388
|
function buildDerivedPropBindings(expr, type, attributeName, elementPath, propsParamName, destructuredPropNames, templateSetupContext, classBody2) {
|
|
4324
4389
|
if (t9.isJSXEmptyExpression(expr) || !templateSetupContext) return [];
|
|
4325
4390
|
const setupStatements = collectTemplateSetupStatements(expr, templateSetupContext);
|
|
@@ -5724,8 +5789,15 @@ function processChildren(children, parts, ctx, elementPath, dcCursor, directChil
|
|
|
5724
5789
|
appendString(parts, `-->`);
|
|
5725
5790
|
pushString(parts, "");
|
|
5726
5791
|
const slotCtx = { ...ctx, elementPathPrefix: "__cs_" + slot.slotId };
|
|
5792
|
+
const eventIdBefore = ctx.eventIdCounter?.value ?? 0;
|
|
5727
5793
|
let condExpr = transformJSXExpression(rawExpr, slotCtx);
|
|
5728
|
-
const
|
|
5794
|
+
const extractCtx = {
|
|
5795
|
+
...ctx,
|
|
5796
|
+
isRoot: false,
|
|
5797
|
+
eventHandlers: ctx.eventHandlers ? [] : void 0,
|
|
5798
|
+
eventIdCounter: ctx.eventIdCounter ? { value: eventIdBefore } : void 0
|
|
5799
|
+
};
|
|
5800
|
+
const extracted = extractHtmlTemplatesFromRawConditional(rawExpr, extractCtx, slot.slotId) ?? extractHtmlTemplatesFromConditional(condExpr);
|
|
5729
5801
|
slot.truthyHtmlExpr = extracted.truthyHtmlExpr;
|
|
5730
5802
|
slot.falsyHtmlExpr = extracted.falsyHtmlExpr;
|
|
5731
5803
|
if (expressionMayBeFalsy(rawExpr)) {
|
|
@@ -7923,7 +7995,13 @@ function appendEventsGetterHandlers(classBody2, handlers, paramContext, setupSta
|
|
|
7923
7995
|
eventsObject.properties.push(eventTypeProp);
|
|
7924
7996
|
}
|
|
7925
7997
|
const selectorMap = eventTypeProp.value;
|
|
7926
|
-
|
|
7998
|
+
const selectorCode = generate2(selectorExpr).code;
|
|
7999
|
+
const isDuplicate = selectorMap.properties.some(
|
|
8000
|
+
(prop) => t13.isObjectProperty(prop) && generate2(prop.key).code === selectorCode
|
|
8001
|
+
);
|
|
8002
|
+
if (!isDuplicate) {
|
|
8003
|
+
selectorMap.properties.push(t13.objectProperty(selectorExpr, handlerRef, !handler.selector));
|
|
8004
|
+
}
|
|
7927
8005
|
});
|
|
7928
8006
|
}
|
|
7929
8007
|
function buildSelectorHandlerMethod(handler, methodName, paramContext, setupStatements) {
|