@fictjs/compiler 0.0.3 → 0.0.4
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/README.md +1 -1
- package/dist/index.cjs +99 -58
- package/dist/index.js +99 -58
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -14152,6 +14152,7 @@ var RUNTIME_HELPERS = {
|
|
|
14152
14152
|
bindClass: "bindClass",
|
|
14153
14153
|
bindStyle: "bindStyle",
|
|
14154
14154
|
bindEvent: "bindEvent",
|
|
14155
|
+
callEventHandler: "callEventHandler",
|
|
14155
14156
|
bindRef: "bindRef",
|
|
14156
14157
|
toNodeArray: "toNodeArray",
|
|
14157
14158
|
createKeyedListContainer: "createKeyedListContainer",
|
|
@@ -14191,6 +14192,7 @@ var RUNTIME_ALIASES = {
|
|
|
14191
14192
|
bindClass: "bindClass",
|
|
14192
14193
|
bindStyle: "bindStyle",
|
|
14193
14194
|
bindEvent: "bindEvent",
|
|
14195
|
+
callEventHandler: "callEventHandler",
|
|
14194
14196
|
bindRef: "bindRef",
|
|
14195
14197
|
toNodeArray: "toNodeArray",
|
|
14196
14198
|
createKeyedListContainer: "createKeyedListContainer",
|
|
@@ -19074,7 +19076,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19074
19076
|
const isTracked = ctx.trackedVars.has(baseName2);
|
|
19075
19077
|
const isSignal = ctx.signalVars?.has(baseName2) ?? false;
|
|
19076
19078
|
const aliasVars = ctx.aliasVars ?? (ctx.aliasVars = /* @__PURE__ */ new Set());
|
|
19077
|
-
const dependsOnTracked2 = expressionUsesTracked(instr.value, ctx);
|
|
19079
|
+
const dependsOnTracked2 = expressionUsesTracked(instr.value, ctx) || (ctx.memoVars?.has(baseName2) ?? false);
|
|
19078
19080
|
const capturedTracked = ctx.externalTracked && ctx.externalTracked.has(baseName2) && !declaredVars.has(baseName2);
|
|
19079
19081
|
const isShadowDeclaration = !!declKind && declaredVars.has(baseName2);
|
|
19080
19082
|
const treatAsTracked = !isShadowDeclaration && isTracked;
|
|
@@ -19082,6 +19084,9 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19082
19084
|
const isStateCall2 = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && instr.value.callee.name === "$state";
|
|
19083
19085
|
const inRegionMemo = ctx.inRegionMemo ?? false;
|
|
19084
19086
|
const isFunctionValue = instr.value.kind === "ArrowFunction" || instr.value.kind === "FunctionExpression";
|
|
19087
|
+
const isAccessorReturningCall = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && ["$memo", "createMemo", "useProp"].includes(instr.value.callee.name);
|
|
19088
|
+
const isReactiveObjectCall = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && ["mergeProps", "prop"].includes(instr.value.callee.name);
|
|
19089
|
+
const isMemoReturningCall = isAccessorReturningCall || isReactiveObjectCall;
|
|
19085
19090
|
const lowerAssignedValue = (forceAssigned = false) => lowerExpressionWithDeSSA(instr.value, ctx, forceAssigned || isFunctionValue);
|
|
19086
19091
|
const buildMemoCall = (expr) => {
|
|
19087
19092
|
const args = [
|
|
@@ -19128,7 +19133,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19128
19133
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19129
19134
|
]);
|
|
19130
19135
|
}
|
|
19131
|
-
ctx.memoVars?.add(baseName2);
|
|
19136
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19132
19137
|
if (ctx.noMemo) {
|
|
19133
19138
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19134
19139
|
t2.variableDeclarator(
|
|
@@ -19138,7 +19143,10 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19138
19143
|
]);
|
|
19139
19144
|
}
|
|
19140
19145
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19141
|
-
t2.variableDeclarator(
|
|
19146
|
+
t2.variableDeclarator(
|
|
19147
|
+
t2.identifier(baseName2),
|
|
19148
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19149
|
+
)
|
|
19142
19150
|
]);
|
|
19143
19151
|
}
|
|
19144
19152
|
}
|
|
@@ -19149,7 +19157,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19149
19157
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19150
19158
|
]);
|
|
19151
19159
|
}
|
|
19152
|
-
ctx.memoVars?.add(baseName2);
|
|
19160
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19153
19161
|
if (ctx.noMemo) {
|
|
19154
19162
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19155
19163
|
t2.variableDeclarator(
|
|
@@ -19159,7 +19167,10 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19159
19167
|
]);
|
|
19160
19168
|
}
|
|
19161
19169
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19162
|
-
t2.variableDeclarator(
|
|
19170
|
+
t2.variableDeclarator(
|
|
19171
|
+
t2.identifier(baseName2),
|
|
19172
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19173
|
+
)
|
|
19163
19174
|
]);
|
|
19164
19175
|
}
|
|
19165
19176
|
return t2.variableDeclaration(fallbackDecl, [
|
|
@@ -19217,7 +19228,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19217
19228
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19218
19229
|
]);
|
|
19219
19230
|
}
|
|
19220
|
-
ctx.memoVars?.add(baseName2);
|
|
19231
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19221
19232
|
if (ctx.noMemo) {
|
|
19222
19233
|
return t2.variableDeclaration("const", [
|
|
19223
19234
|
t2.variableDeclarator(
|
|
@@ -19227,7 +19238,10 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19227
19238
|
]);
|
|
19228
19239
|
}
|
|
19229
19240
|
return t2.variableDeclaration("const", [
|
|
19230
|
-
t2.variableDeclarator(
|
|
19241
|
+
t2.variableDeclarator(
|
|
19242
|
+
t2.identifier(baseName2),
|
|
19243
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19244
|
+
)
|
|
19231
19245
|
]);
|
|
19232
19246
|
}
|
|
19233
19247
|
return t2.variableDeclaration("let", [
|
|
@@ -19241,22 +19255,17 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19241
19255
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19242
19256
|
]);
|
|
19243
19257
|
}
|
|
19244
|
-
if (ctx.memoVars?.
|
|
19245
|
-
if (buildMemoCall) {
|
|
19246
|
-
console.log("Declaring memo var:", baseName2);
|
|
19247
|
-
return t2.variableDeclaration("const", [
|
|
19248
|
-
t2.variableDeclarator(t2.identifier(baseName2), buildMemoCall(derivedExpr))
|
|
19249
|
-
]);
|
|
19250
|
-
}
|
|
19251
|
-
}
|
|
19252
|
-
ctx.memoVars?.add(baseName2);
|
|
19258
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19253
19259
|
if (ctx.noMemo) {
|
|
19254
19260
|
return t2.variableDeclaration("const", [
|
|
19255
19261
|
t2.variableDeclarator(t2.identifier(baseName2), t2.arrowFunctionExpression([], derivedExpr))
|
|
19256
19262
|
]);
|
|
19257
19263
|
}
|
|
19258
19264
|
return t2.variableDeclaration("const", [
|
|
19259
|
-
t2.variableDeclarator(
|
|
19265
|
+
t2.variableDeclarator(
|
|
19266
|
+
t2.identifier(baseName2),
|
|
19267
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19268
|
+
)
|
|
19260
19269
|
]);
|
|
19261
19270
|
}
|
|
19262
19271
|
return t2.variableDeclaration("let", [
|
|
@@ -20334,7 +20343,8 @@ function collectExpressionIdentifiersDeep(expr, into, bound = /* @__PURE__ */ ne
|
|
|
20334
20343
|
case "CallExpression":
|
|
20335
20344
|
case "OptionalCallExpression": {
|
|
20336
20345
|
const isMacroCallee = expr.callee.kind === "Identifier" && (expr.callee.name === "$state" || expr.callee.name === "$effect" || expr.callee.name === "$store");
|
|
20337
|
-
|
|
20346
|
+
const isIIFE = expr.callee.kind === "ArrowFunction" || expr.callee.kind === "FunctionExpression";
|
|
20347
|
+
if (!isMacroCallee && !isIIFE) {
|
|
20338
20348
|
collectExpressionIdentifiersDeep(expr.callee, into, bound);
|
|
20339
20349
|
}
|
|
20340
20350
|
expr.arguments.forEach(
|
|
@@ -20375,73 +20385,81 @@ function collectExpressionIdentifiersDeep(expr, into, bound = /* @__PURE__ */ ne
|
|
|
20375
20385
|
);
|
|
20376
20386
|
return;
|
|
20377
20387
|
case "ArrowFunction": {
|
|
20378
|
-
const
|
|
20379
|
-
expr.params.forEach((p) => nextBound.add(deSSAVarName(p.name)));
|
|
20388
|
+
const tempSet = /* @__PURE__ */ new Set();
|
|
20380
20389
|
if (expr.isExpression && expr.body && !Array.isArray(expr.body)) {
|
|
20381
|
-
|
|
20390
|
+
collectExpressionIdentifiers(expr.body, tempSet);
|
|
20382
20391
|
} else if (Array.isArray(expr.body)) {
|
|
20383
20392
|
for (const block of expr.body) {
|
|
20384
20393
|
for (const instr of block.instructions) {
|
|
20385
20394
|
if (instr.kind === "Assign") {
|
|
20386
|
-
|
|
20395
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20387
20396
|
} else if (instr.kind === "Expression") {
|
|
20388
|
-
|
|
20397
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20389
20398
|
} else if (instr.kind === "Phi") {
|
|
20390
|
-
instr.sources.forEach((src) =>
|
|
20399
|
+
instr.sources.forEach((src) => tempSet.add(deSSAVarName(src.id.name)));
|
|
20391
20400
|
}
|
|
20392
20401
|
}
|
|
20393
20402
|
const term = block.terminator;
|
|
20394
20403
|
if (term.kind === "Branch") {
|
|
20395
|
-
|
|
20404
|
+
collectExpressionIdentifiers(term.test, tempSet);
|
|
20396
20405
|
} else if (term.kind === "Switch") {
|
|
20397
|
-
|
|
20406
|
+
collectExpressionIdentifiers(term.discriminant, tempSet);
|
|
20398
20407
|
term.cases.forEach((c) => {
|
|
20399
|
-
if (c.test)
|
|
20408
|
+
if (c.test) collectExpressionIdentifiers(c.test, tempSet);
|
|
20400
20409
|
});
|
|
20401
20410
|
} else if (term.kind === "ForOf") {
|
|
20402
|
-
|
|
20411
|
+
collectExpressionIdentifiers(term.iterable, tempSet);
|
|
20403
20412
|
} else if (term.kind === "ForIn") {
|
|
20404
|
-
|
|
20413
|
+
collectExpressionIdentifiers(term.object, tempSet);
|
|
20405
20414
|
} else if (term.kind === "Return" && term.argument) {
|
|
20406
|
-
|
|
20415
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20407
20416
|
} else if (term.kind === "Throw") {
|
|
20408
|
-
|
|
20417
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20409
20418
|
}
|
|
20410
20419
|
}
|
|
20411
20420
|
}
|
|
20421
|
+
const paramNames = new Set(expr.params.map((p) => deSSAVarName(p.name)));
|
|
20422
|
+
for (const name of bound) paramNames.add(name);
|
|
20423
|
+
for (const dep of tempSet) {
|
|
20424
|
+
if (!paramNames.has(dep)) into.add(dep);
|
|
20425
|
+
}
|
|
20412
20426
|
return;
|
|
20413
20427
|
}
|
|
20414
20428
|
case "FunctionExpression": {
|
|
20415
|
-
const
|
|
20416
|
-
expr.params.forEach((p) => nextBound.add(deSSAVarName(p.name)));
|
|
20429
|
+
const tempSet = /* @__PURE__ */ new Set();
|
|
20417
20430
|
for (const block of expr.body) {
|
|
20418
20431
|
for (const instr of block.instructions) {
|
|
20419
20432
|
if (instr.kind === "Assign") {
|
|
20420
|
-
|
|
20433
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20421
20434
|
} else if (instr.kind === "Expression") {
|
|
20422
|
-
|
|
20435
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20423
20436
|
} else if (instr.kind === "Phi") {
|
|
20424
|
-
instr.sources.forEach((src) =>
|
|
20437
|
+
instr.sources.forEach((src) => tempSet.add(deSSAVarName(src.id.name)));
|
|
20425
20438
|
}
|
|
20426
20439
|
}
|
|
20427
20440
|
const term = block.terminator;
|
|
20428
20441
|
if (term.kind === "Branch") {
|
|
20429
|
-
|
|
20442
|
+
collectExpressionIdentifiers(term.test, tempSet);
|
|
20430
20443
|
} else if (term.kind === "Switch") {
|
|
20431
|
-
|
|
20444
|
+
collectExpressionIdentifiers(term.discriminant, tempSet);
|
|
20432
20445
|
term.cases.forEach((c) => {
|
|
20433
|
-
if (c.test)
|
|
20446
|
+
if (c.test) collectExpressionIdentifiers(c.test, tempSet);
|
|
20434
20447
|
});
|
|
20435
20448
|
} else if (term.kind === "ForOf") {
|
|
20436
|
-
|
|
20449
|
+
collectExpressionIdentifiers(term.iterable, tempSet);
|
|
20437
20450
|
} else if (term.kind === "ForIn") {
|
|
20438
|
-
|
|
20451
|
+
collectExpressionIdentifiers(term.object, tempSet);
|
|
20439
20452
|
} else if (term.kind === "Return" && term.argument) {
|
|
20440
|
-
|
|
20453
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20441
20454
|
} else if (term.kind === "Throw") {
|
|
20442
|
-
|
|
20455
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20443
20456
|
}
|
|
20444
20457
|
}
|
|
20458
|
+
const paramNames = new Set(expr.params.map((p) => deSSAVarName(p.name)));
|
|
20459
|
+
for (const name of bound) paramNames.add(name);
|
|
20460
|
+
for (const dep of tempSet) {
|
|
20461
|
+
if (!paramNames.has(dep)) into.add(dep);
|
|
20462
|
+
}
|
|
20445
20463
|
return;
|
|
20446
20464
|
}
|
|
20447
20465
|
case "AssignmentExpression":
|
|
@@ -20510,6 +20528,13 @@ function getExpressionIdentifiers(expr) {
|
|
|
20510
20528
|
}
|
|
20511
20529
|
return deps;
|
|
20512
20530
|
}
|
|
20531
|
+
function getExpressionIdentifiersDeep(expr) {
|
|
20532
|
+
const deps = /* @__PURE__ */ new Set();
|
|
20533
|
+
if (expr) {
|
|
20534
|
+
collectExpressionIdentifiersDeep(expr, deps);
|
|
20535
|
+
}
|
|
20536
|
+
return deps;
|
|
20537
|
+
}
|
|
20513
20538
|
function buildControlDependencyMap(fn) {
|
|
20514
20539
|
const depsByInstruction = /* @__PURE__ */ new Map();
|
|
20515
20540
|
let structured;
|
|
@@ -20636,7 +20661,7 @@ function computeReactiveAccessors(fn, ctx) {
|
|
|
20636
20661
|
for (const instr of block.instructions) {
|
|
20637
20662
|
if (instr.kind === "Assign") {
|
|
20638
20663
|
const target = deSSAVarName(instr.target.name);
|
|
20639
|
-
const dataDeps =
|
|
20664
|
+
const dataDeps = getExpressionIdentifiersDeep(instr.value);
|
|
20640
20665
|
addDepsToTarget(target, dataDeps, dataDepsByTarget);
|
|
20641
20666
|
const controlDeps = controlDepsByInstr.get(instr) ?? /* @__PURE__ */ new Set();
|
|
20642
20667
|
addDepsToTarget(target, controlDeps, controlDepsByTarget);
|
|
@@ -20697,7 +20722,7 @@ function computeReactiveAccessors(fn, ctx) {
|
|
|
20697
20722
|
if (instr.kind === "Assign") {
|
|
20698
20723
|
const target = deSSAVarName(instr.target.name);
|
|
20699
20724
|
if (isFunctionVar(target)) continue;
|
|
20700
|
-
const dataDeps =
|
|
20725
|
+
const dataDeps = getExpressionIdentifiersDeep(instr.value);
|
|
20701
20726
|
const controlDepsForInstr = controlDepsByInstr.get(instr) ?? /* @__PURE__ */ new Set();
|
|
20702
20727
|
const hasDataDep = Array.from(dataDeps).some((dep) => tracked.has(dep));
|
|
20703
20728
|
const hasControlDep = Array.from(controlDepsForInstr).some((dep) => tracked.has(dep));
|
|
@@ -20707,7 +20732,8 @@ function computeReactiveAccessors(fn, ctx) {
|
|
|
20707
20732
|
tracked.add(target);
|
|
20708
20733
|
changed = true;
|
|
20709
20734
|
}
|
|
20710
|
-
|
|
20735
|
+
const isReactiveObjectCall = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && ["mergeProps", "prop"].includes(instr.value.callee.name);
|
|
20736
|
+
if (hasDataDep && !isSignal(target) && !isStore(target) && !isReactiveObjectCall) {
|
|
20711
20737
|
memo.add(target);
|
|
20712
20738
|
}
|
|
20713
20739
|
} else if (instr.kind === "Phi") {
|
|
@@ -21204,6 +21230,13 @@ function lowerExpressionImpl(expr, ctx, isAssigned = false) {
|
|
|
21204
21230
|
return t2.callExpression(t2.identifier(RUNTIME_ALIASES.mergeProps), args);
|
|
21205
21231
|
}
|
|
21206
21232
|
const isIIFE = (expr.callee.kind === "ArrowFunction" || expr.callee.kind === "FunctionExpression") && expr.arguments.length === 0 && expr.callee.params.length === 0;
|
|
21233
|
+
const calleeName = expr.callee.kind === "Identifier" ? deSSAVarName(expr.callee.name) : null;
|
|
21234
|
+
const calleeIsMemoAccessor = !!calleeName && ctx.memoVars?.has(calleeName);
|
|
21235
|
+
const calleeIsSignalLike = !!calleeName && (ctx.signalVars?.has(calleeName) || ctx.storeVars?.has(calleeName));
|
|
21236
|
+
if (calleeIsMemoAccessor && !calleeIsSignalLike && expr.arguments.length > 0) {
|
|
21237
|
+
const loweredArgs = expr.arguments.map((a) => lowerExpression(a, ctx));
|
|
21238
|
+
return t2.callExpression(t2.callExpression(t2.identifier(calleeName), []), loweredArgs);
|
|
21239
|
+
}
|
|
21207
21240
|
const lowerCallee = () => isIIFE ? withNonReactiveScope(ctx, () => lowerExpression(expr.callee, ctx)) : lowerExpression(expr.callee, ctx);
|
|
21208
21241
|
return t2.callExpression(
|
|
21209
21242
|
lowerCallee(),
|
|
@@ -21556,11 +21589,12 @@ function lowerExpressionImpl(expr, ctx, isAssigned = false) {
|
|
|
21556
21589
|
return t2.identifier("undefined");
|
|
21557
21590
|
}
|
|
21558
21591
|
}
|
|
21559
|
-
function lowerDomExpression(expr, ctx, region) {
|
|
21592
|
+
function lowerDomExpression(expr, ctx, region, options) {
|
|
21560
21593
|
let lowered = lowerExpression(expr, ctx);
|
|
21561
|
-
|
|
21594
|
+
const skipHookAccessors = options?.skipHookAccessors ?? false;
|
|
21595
|
+
if (!skipHookAccessors && ctx.t.isMemberExpression(lowered) && ctx.t.isIdentifier(lowered.object) && ctx.hookResultVarMap?.has(deSSAVarName(lowered.object.name))) {
|
|
21562
21596
|
lowered = ctx.t.callExpression(lowered, []);
|
|
21563
|
-
} else if (ctx.t.isIdentifier(lowered)) {
|
|
21597
|
+
} else if (!skipHookAccessors && ctx.t.isIdentifier(lowered)) {
|
|
21564
21598
|
const hookName = ctx.hookResultVarMap?.get(deSSAVarName(lowered.name));
|
|
21565
21599
|
if (hookName) {
|
|
21566
21600
|
const info = getHookReturnInfo(hookName, ctx);
|
|
@@ -21569,7 +21603,9 @@ function lowerDomExpression(expr, ctx, region) {
|
|
|
21569
21603
|
}
|
|
21570
21604
|
}
|
|
21571
21605
|
}
|
|
21572
|
-
return applyRegionMetadataToExpression(lowered, ctx, region
|
|
21606
|
+
return applyRegionMetadataToExpression(lowered, ctx, region, {
|
|
21607
|
+
skipRootOverride: options?.skipRegionRootOverride
|
|
21608
|
+
});
|
|
21573
21609
|
}
|
|
21574
21610
|
function lowerJSXChildNonFineGrained(child, ctx) {
|
|
21575
21611
|
const { t: t2 } = ctx;
|
|
@@ -21778,12 +21814,13 @@ function getDependencyPathFromNode(node, t2) {
|
|
|
21778
21814
|
}
|
|
21779
21815
|
return null;
|
|
21780
21816
|
}
|
|
21781
|
-
function applyRegionMetadataToExpression(expr, ctx, regionOverride) {
|
|
21817
|
+
function applyRegionMetadataToExpression(expr, ctx, regionOverride, options) {
|
|
21782
21818
|
if (ctx.inReturn && ctx.currentFnIsHook) {
|
|
21783
21819
|
return expr;
|
|
21784
21820
|
}
|
|
21785
21821
|
const region = regionOverride ?? ctx.currentRegion;
|
|
21786
21822
|
if (!region) return expr;
|
|
21823
|
+
const skipRootOverride = options?.skipRootOverride ?? false;
|
|
21787
21824
|
const metadata = regionInfoToMetadata(region);
|
|
21788
21825
|
const state = {};
|
|
21789
21826
|
applyRegionMetadata(state, {
|
|
@@ -21836,7 +21873,7 @@ function applyRegionMetadataToExpression(expr, ctx, regionOverride) {
|
|
|
21836
21873
|
if (Object.keys(overrides).length === 0) {
|
|
21837
21874
|
return expr;
|
|
21838
21875
|
}
|
|
21839
|
-
if (ctx.t.isIdentifier(expr)) {
|
|
21876
|
+
if (!skipRootOverride && ctx.t.isIdentifier(expr)) {
|
|
21840
21877
|
const key = normalizeDependencyKey2(expr.name);
|
|
21841
21878
|
const direct = overrides[key] ?? overrides[expr.name];
|
|
21842
21879
|
if (direct) {
|
|
@@ -21844,10 +21881,10 @@ function applyRegionMetadataToExpression(expr, ctx, regionOverride) {
|
|
|
21844
21881
|
}
|
|
21845
21882
|
}
|
|
21846
21883
|
const cloned = ctx.t.cloneNode(expr, true);
|
|
21847
|
-
replaceIdentifiersWithOverrides(cloned, overrides, ctx.t);
|
|
21884
|
+
replaceIdentifiersWithOverrides(cloned, overrides, ctx.t, void 0, void 0, skipRootOverride);
|
|
21848
21885
|
return cloned;
|
|
21849
21886
|
}
|
|
21850
|
-
function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parentKey) {
|
|
21887
|
+
function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parentKey, skipCurrentNode = false) {
|
|
21851
21888
|
const isCallTarget = parentKey === "callee" && (parentKind === "CallExpression" || parentKind === "OptionalCallExpression");
|
|
21852
21889
|
const collectParamNames = (params) => {
|
|
21853
21890
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -21883,7 +21920,7 @@ function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parent
|
|
|
21883
21920
|
params.forEach((p) => visitPattern(p));
|
|
21884
21921
|
return names;
|
|
21885
21922
|
};
|
|
21886
|
-
if (t2.isMemberExpression(node) || t2.isOptionalMemberExpression(node)) {
|
|
21923
|
+
if (!skipCurrentNode && (t2.isMemberExpression(node) || t2.isOptionalMemberExpression(node))) {
|
|
21887
21924
|
const path = getDependencyPathFromNode(node, t2);
|
|
21888
21925
|
const normalized = path ? normalizeDependencyKey2(path) : null;
|
|
21889
21926
|
const override = normalized && overrides[normalized] || (path ? overrides[path] : void 0);
|
|
@@ -21893,7 +21930,7 @@ function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parent
|
|
|
21893
21930
|
return;
|
|
21894
21931
|
}
|
|
21895
21932
|
}
|
|
21896
|
-
if (t2.isIdentifier(node)) {
|
|
21933
|
+
if (!skipCurrentNode && t2.isIdentifier(node)) {
|
|
21897
21934
|
const key = normalizeDependencyKey2(node.name);
|
|
21898
21935
|
const override = overrides[key] ?? overrides[node.name];
|
|
21899
21936
|
if (override && !isCallTarget) {
|
|
@@ -21938,7 +21975,8 @@ function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parent
|
|
|
21938
21975
|
overrides,
|
|
21939
21976
|
t2,
|
|
21940
21977
|
node.type,
|
|
21941
|
-
key
|
|
21978
|
+
key,
|
|
21979
|
+
false
|
|
21942
21980
|
);
|
|
21943
21981
|
}
|
|
21944
21982
|
}
|
|
@@ -22367,7 +22405,10 @@ function lowerIntrinsicElement(jsx, ctx) {
|
|
|
22367
22405
|
const shouldWrapHandler = isExpressionReactive(binding.expr, ctx);
|
|
22368
22406
|
const prevWrapTracked = ctx.wrapTrackedExpressions;
|
|
22369
22407
|
ctx.wrapTrackedExpressions = false;
|
|
22370
|
-
const valueExpr = lowerDomExpression(binding.expr, ctx, containingRegion
|
|
22408
|
+
const valueExpr = lowerDomExpression(binding.expr, ctx, containingRegion, {
|
|
22409
|
+
skipHookAccessors: true,
|
|
22410
|
+
skipRegionRootOverride: true
|
|
22411
|
+
});
|
|
22371
22412
|
ctx.wrapTrackedExpressions = prevWrapTracked;
|
|
22372
22413
|
const eventParam = t2.identifier("_e");
|
|
22373
22414
|
const isFn = t2.isArrowFunctionExpression(valueExpr) || t2.isFunctionExpression(valueExpr);
|
package/dist/index.js
CHANGED
|
@@ -14140,6 +14140,7 @@ var RUNTIME_HELPERS = {
|
|
|
14140
14140
|
bindClass: "bindClass",
|
|
14141
14141
|
bindStyle: "bindStyle",
|
|
14142
14142
|
bindEvent: "bindEvent",
|
|
14143
|
+
callEventHandler: "callEventHandler",
|
|
14143
14144
|
bindRef: "bindRef",
|
|
14144
14145
|
toNodeArray: "toNodeArray",
|
|
14145
14146
|
createKeyedListContainer: "createKeyedListContainer",
|
|
@@ -14179,6 +14180,7 @@ var RUNTIME_ALIASES = {
|
|
|
14179
14180
|
bindClass: "bindClass",
|
|
14180
14181
|
bindStyle: "bindStyle",
|
|
14181
14182
|
bindEvent: "bindEvent",
|
|
14183
|
+
callEventHandler: "callEventHandler",
|
|
14182
14184
|
bindRef: "bindRef",
|
|
14183
14185
|
toNodeArray: "toNodeArray",
|
|
14184
14186
|
createKeyedListContainer: "createKeyedListContainer",
|
|
@@ -19062,7 +19064,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19062
19064
|
const isTracked = ctx.trackedVars.has(baseName2);
|
|
19063
19065
|
const isSignal = ctx.signalVars?.has(baseName2) ?? false;
|
|
19064
19066
|
const aliasVars = ctx.aliasVars ?? (ctx.aliasVars = /* @__PURE__ */ new Set());
|
|
19065
|
-
const dependsOnTracked2 = expressionUsesTracked(instr.value, ctx);
|
|
19067
|
+
const dependsOnTracked2 = expressionUsesTracked(instr.value, ctx) || (ctx.memoVars?.has(baseName2) ?? false);
|
|
19066
19068
|
const capturedTracked = ctx.externalTracked && ctx.externalTracked.has(baseName2) && !declaredVars.has(baseName2);
|
|
19067
19069
|
const isShadowDeclaration = !!declKind && declaredVars.has(baseName2);
|
|
19068
19070
|
const treatAsTracked = !isShadowDeclaration && isTracked;
|
|
@@ -19070,6 +19072,9 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19070
19072
|
const isStateCall2 = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && instr.value.callee.name === "$state";
|
|
19071
19073
|
const inRegionMemo = ctx.inRegionMemo ?? false;
|
|
19072
19074
|
const isFunctionValue = instr.value.kind === "ArrowFunction" || instr.value.kind === "FunctionExpression";
|
|
19075
|
+
const isAccessorReturningCall = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && ["$memo", "createMemo", "useProp"].includes(instr.value.callee.name);
|
|
19076
|
+
const isReactiveObjectCall = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && ["mergeProps", "prop"].includes(instr.value.callee.name);
|
|
19077
|
+
const isMemoReturningCall = isAccessorReturningCall || isReactiveObjectCall;
|
|
19073
19078
|
const lowerAssignedValue = (forceAssigned = false) => lowerExpressionWithDeSSA(instr.value, ctx, forceAssigned || isFunctionValue);
|
|
19074
19079
|
const buildMemoCall = (expr) => {
|
|
19075
19080
|
const args = [
|
|
@@ -19116,7 +19121,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19116
19121
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19117
19122
|
]);
|
|
19118
19123
|
}
|
|
19119
|
-
ctx.memoVars?.add(baseName2);
|
|
19124
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19120
19125
|
if (ctx.noMemo) {
|
|
19121
19126
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19122
19127
|
t2.variableDeclarator(
|
|
@@ -19126,7 +19131,10 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19126
19131
|
]);
|
|
19127
19132
|
}
|
|
19128
19133
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19129
|
-
t2.variableDeclarator(
|
|
19134
|
+
t2.variableDeclarator(
|
|
19135
|
+
t2.identifier(baseName2),
|
|
19136
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19137
|
+
)
|
|
19130
19138
|
]);
|
|
19131
19139
|
}
|
|
19132
19140
|
}
|
|
@@ -19137,7 +19145,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19137
19145
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19138
19146
|
]);
|
|
19139
19147
|
}
|
|
19140
|
-
ctx.memoVars?.add(baseName2);
|
|
19148
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19141
19149
|
if (ctx.noMemo) {
|
|
19142
19150
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19143
19151
|
t2.variableDeclarator(
|
|
@@ -19147,7 +19155,10 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19147
19155
|
]);
|
|
19148
19156
|
}
|
|
19149
19157
|
return t2.variableDeclaration(normalizedDecl, [
|
|
19150
|
-
t2.variableDeclarator(
|
|
19158
|
+
t2.variableDeclarator(
|
|
19159
|
+
t2.identifier(baseName2),
|
|
19160
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19161
|
+
)
|
|
19151
19162
|
]);
|
|
19152
19163
|
}
|
|
19153
19164
|
return t2.variableDeclaration(fallbackDecl, [
|
|
@@ -19205,7 +19216,7 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19205
19216
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19206
19217
|
]);
|
|
19207
19218
|
}
|
|
19208
|
-
ctx.memoVars?.add(baseName2);
|
|
19219
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19209
19220
|
if (ctx.noMemo) {
|
|
19210
19221
|
return t2.variableDeclaration("const", [
|
|
19211
19222
|
t2.variableDeclarator(
|
|
@@ -19215,7 +19226,10 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19215
19226
|
]);
|
|
19216
19227
|
}
|
|
19217
19228
|
return t2.variableDeclaration("const", [
|
|
19218
|
-
t2.variableDeclarator(
|
|
19229
|
+
t2.variableDeclarator(
|
|
19230
|
+
t2.identifier(baseName2),
|
|
19231
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19232
|
+
)
|
|
19219
19233
|
]);
|
|
19220
19234
|
}
|
|
19221
19235
|
return t2.variableDeclaration("let", [
|
|
@@ -19229,22 +19243,17 @@ function instructionToStatement(instr, t2, declaredVars, ctx, _buildMemoCall) {
|
|
|
19229
19243
|
t2.variableDeclarator(t2.identifier(baseName2), derivedExpr)
|
|
19230
19244
|
]);
|
|
19231
19245
|
}
|
|
19232
|
-
if (ctx.memoVars?.
|
|
19233
|
-
if (buildMemoCall) {
|
|
19234
|
-
console.log("Declaring memo var:", baseName2);
|
|
19235
|
-
return t2.variableDeclaration("const", [
|
|
19236
|
-
t2.variableDeclarator(t2.identifier(baseName2), buildMemoCall(derivedExpr))
|
|
19237
|
-
]);
|
|
19238
|
-
}
|
|
19239
|
-
}
|
|
19240
|
-
ctx.memoVars?.add(baseName2);
|
|
19246
|
+
if (!isReactiveObjectCall) ctx.memoVars?.add(baseName2);
|
|
19241
19247
|
if (ctx.noMemo) {
|
|
19242
19248
|
return t2.variableDeclaration("const", [
|
|
19243
19249
|
t2.variableDeclarator(t2.identifier(baseName2), t2.arrowFunctionExpression([], derivedExpr))
|
|
19244
19250
|
]);
|
|
19245
19251
|
}
|
|
19246
19252
|
return t2.variableDeclaration("const", [
|
|
19247
|
-
t2.variableDeclarator(
|
|
19253
|
+
t2.variableDeclarator(
|
|
19254
|
+
t2.identifier(baseName2),
|
|
19255
|
+
isMemoReturningCall ? derivedExpr : buildMemoCall(derivedExpr)
|
|
19256
|
+
)
|
|
19248
19257
|
]);
|
|
19249
19258
|
}
|
|
19250
19259
|
return t2.variableDeclaration("let", [
|
|
@@ -20322,7 +20331,8 @@ function collectExpressionIdentifiersDeep(expr, into, bound = /* @__PURE__ */ ne
|
|
|
20322
20331
|
case "CallExpression":
|
|
20323
20332
|
case "OptionalCallExpression": {
|
|
20324
20333
|
const isMacroCallee = expr.callee.kind === "Identifier" && (expr.callee.name === "$state" || expr.callee.name === "$effect" || expr.callee.name === "$store");
|
|
20325
|
-
|
|
20334
|
+
const isIIFE = expr.callee.kind === "ArrowFunction" || expr.callee.kind === "FunctionExpression";
|
|
20335
|
+
if (!isMacroCallee && !isIIFE) {
|
|
20326
20336
|
collectExpressionIdentifiersDeep(expr.callee, into, bound);
|
|
20327
20337
|
}
|
|
20328
20338
|
expr.arguments.forEach(
|
|
@@ -20363,73 +20373,81 @@ function collectExpressionIdentifiersDeep(expr, into, bound = /* @__PURE__ */ ne
|
|
|
20363
20373
|
);
|
|
20364
20374
|
return;
|
|
20365
20375
|
case "ArrowFunction": {
|
|
20366
|
-
const
|
|
20367
|
-
expr.params.forEach((p) => nextBound.add(deSSAVarName(p.name)));
|
|
20376
|
+
const tempSet = /* @__PURE__ */ new Set();
|
|
20368
20377
|
if (expr.isExpression && expr.body && !Array.isArray(expr.body)) {
|
|
20369
|
-
|
|
20378
|
+
collectExpressionIdentifiers(expr.body, tempSet);
|
|
20370
20379
|
} else if (Array.isArray(expr.body)) {
|
|
20371
20380
|
for (const block of expr.body) {
|
|
20372
20381
|
for (const instr of block.instructions) {
|
|
20373
20382
|
if (instr.kind === "Assign") {
|
|
20374
|
-
|
|
20383
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20375
20384
|
} else if (instr.kind === "Expression") {
|
|
20376
|
-
|
|
20385
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20377
20386
|
} else if (instr.kind === "Phi") {
|
|
20378
|
-
instr.sources.forEach((src) =>
|
|
20387
|
+
instr.sources.forEach((src) => tempSet.add(deSSAVarName(src.id.name)));
|
|
20379
20388
|
}
|
|
20380
20389
|
}
|
|
20381
20390
|
const term = block.terminator;
|
|
20382
20391
|
if (term.kind === "Branch") {
|
|
20383
|
-
|
|
20392
|
+
collectExpressionIdentifiers(term.test, tempSet);
|
|
20384
20393
|
} else if (term.kind === "Switch") {
|
|
20385
|
-
|
|
20394
|
+
collectExpressionIdentifiers(term.discriminant, tempSet);
|
|
20386
20395
|
term.cases.forEach((c) => {
|
|
20387
|
-
if (c.test)
|
|
20396
|
+
if (c.test) collectExpressionIdentifiers(c.test, tempSet);
|
|
20388
20397
|
});
|
|
20389
20398
|
} else if (term.kind === "ForOf") {
|
|
20390
|
-
|
|
20399
|
+
collectExpressionIdentifiers(term.iterable, tempSet);
|
|
20391
20400
|
} else if (term.kind === "ForIn") {
|
|
20392
|
-
|
|
20401
|
+
collectExpressionIdentifiers(term.object, tempSet);
|
|
20393
20402
|
} else if (term.kind === "Return" && term.argument) {
|
|
20394
|
-
|
|
20403
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20395
20404
|
} else if (term.kind === "Throw") {
|
|
20396
|
-
|
|
20405
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20397
20406
|
}
|
|
20398
20407
|
}
|
|
20399
20408
|
}
|
|
20409
|
+
const paramNames = new Set(expr.params.map((p) => deSSAVarName(p.name)));
|
|
20410
|
+
for (const name of bound) paramNames.add(name);
|
|
20411
|
+
for (const dep of tempSet) {
|
|
20412
|
+
if (!paramNames.has(dep)) into.add(dep);
|
|
20413
|
+
}
|
|
20400
20414
|
return;
|
|
20401
20415
|
}
|
|
20402
20416
|
case "FunctionExpression": {
|
|
20403
|
-
const
|
|
20404
|
-
expr.params.forEach((p) => nextBound.add(deSSAVarName(p.name)));
|
|
20417
|
+
const tempSet = /* @__PURE__ */ new Set();
|
|
20405
20418
|
for (const block of expr.body) {
|
|
20406
20419
|
for (const instr of block.instructions) {
|
|
20407
20420
|
if (instr.kind === "Assign") {
|
|
20408
|
-
|
|
20421
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20409
20422
|
} else if (instr.kind === "Expression") {
|
|
20410
|
-
|
|
20423
|
+
collectExpressionIdentifiers(instr.value, tempSet);
|
|
20411
20424
|
} else if (instr.kind === "Phi") {
|
|
20412
|
-
instr.sources.forEach((src) =>
|
|
20425
|
+
instr.sources.forEach((src) => tempSet.add(deSSAVarName(src.id.name)));
|
|
20413
20426
|
}
|
|
20414
20427
|
}
|
|
20415
20428
|
const term = block.terminator;
|
|
20416
20429
|
if (term.kind === "Branch") {
|
|
20417
|
-
|
|
20430
|
+
collectExpressionIdentifiers(term.test, tempSet);
|
|
20418
20431
|
} else if (term.kind === "Switch") {
|
|
20419
|
-
|
|
20432
|
+
collectExpressionIdentifiers(term.discriminant, tempSet);
|
|
20420
20433
|
term.cases.forEach((c) => {
|
|
20421
|
-
if (c.test)
|
|
20434
|
+
if (c.test) collectExpressionIdentifiers(c.test, tempSet);
|
|
20422
20435
|
});
|
|
20423
20436
|
} else if (term.kind === "ForOf") {
|
|
20424
|
-
|
|
20437
|
+
collectExpressionIdentifiers(term.iterable, tempSet);
|
|
20425
20438
|
} else if (term.kind === "ForIn") {
|
|
20426
|
-
|
|
20439
|
+
collectExpressionIdentifiers(term.object, tempSet);
|
|
20427
20440
|
} else if (term.kind === "Return" && term.argument) {
|
|
20428
|
-
|
|
20441
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20429
20442
|
} else if (term.kind === "Throw") {
|
|
20430
|
-
|
|
20443
|
+
collectExpressionIdentifiers(term.argument, tempSet);
|
|
20431
20444
|
}
|
|
20432
20445
|
}
|
|
20446
|
+
const paramNames = new Set(expr.params.map((p) => deSSAVarName(p.name)));
|
|
20447
|
+
for (const name of bound) paramNames.add(name);
|
|
20448
|
+
for (const dep of tempSet) {
|
|
20449
|
+
if (!paramNames.has(dep)) into.add(dep);
|
|
20450
|
+
}
|
|
20433
20451
|
return;
|
|
20434
20452
|
}
|
|
20435
20453
|
case "AssignmentExpression":
|
|
@@ -20498,6 +20516,13 @@ function getExpressionIdentifiers(expr) {
|
|
|
20498
20516
|
}
|
|
20499
20517
|
return deps;
|
|
20500
20518
|
}
|
|
20519
|
+
function getExpressionIdentifiersDeep(expr) {
|
|
20520
|
+
const deps = /* @__PURE__ */ new Set();
|
|
20521
|
+
if (expr) {
|
|
20522
|
+
collectExpressionIdentifiersDeep(expr, deps);
|
|
20523
|
+
}
|
|
20524
|
+
return deps;
|
|
20525
|
+
}
|
|
20501
20526
|
function buildControlDependencyMap(fn) {
|
|
20502
20527
|
const depsByInstruction = /* @__PURE__ */ new Map();
|
|
20503
20528
|
let structured;
|
|
@@ -20624,7 +20649,7 @@ function computeReactiveAccessors(fn, ctx) {
|
|
|
20624
20649
|
for (const instr of block.instructions) {
|
|
20625
20650
|
if (instr.kind === "Assign") {
|
|
20626
20651
|
const target = deSSAVarName(instr.target.name);
|
|
20627
|
-
const dataDeps =
|
|
20652
|
+
const dataDeps = getExpressionIdentifiersDeep(instr.value);
|
|
20628
20653
|
addDepsToTarget(target, dataDeps, dataDepsByTarget);
|
|
20629
20654
|
const controlDeps = controlDepsByInstr.get(instr) ?? /* @__PURE__ */ new Set();
|
|
20630
20655
|
addDepsToTarget(target, controlDeps, controlDepsByTarget);
|
|
@@ -20685,7 +20710,7 @@ function computeReactiveAccessors(fn, ctx) {
|
|
|
20685
20710
|
if (instr.kind === "Assign") {
|
|
20686
20711
|
const target = deSSAVarName(instr.target.name);
|
|
20687
20712
|
if (isFunctionVar(target)) continue;
|
|
20688
|
-
const dataDeps =
|
|
20713
|
+
const dataDeps = getExpressionIdentifiersDeep(instr.value);
|
|
20689
20714
|
const controlDepsForInstr = controlDepsByInstr.get(instr) ?? /* @__PURE__ */ new Set();
|
|
20690
20715
|
const hasDataDep = Array.from(dataDeps).some((dep) => tracked.has(dep));
|
|
20691
20716
|
const hasControlDep = Array.from(controlDepsForInstr).some((dep) => tracked.has(dep));
|
|
@@ -20695,7 +20720,8 @@ function computeReactiveAccessors(fn, ctx) {
|
|
|
20695
20720
|
tracked.add(target);
|
|
20696
20721
|
changed = true;
|
|
20697
20722
|
}
|
|
20698
|
-
|
|
20723
|
+
const isReactiveObjectCall = instr.value.kind === "CallExpression" && instr.value.callee.kind === "Identifier" && ["mergeProps", "prop"].includes(instr.value.callee.name);
|
|
20724
|
+
if (hasDataDep && !isSignal(target) && !isStore(target) && !isReactiveObjectCall) {
|
|
20699
20725
|
memo.add(target);
|
|
20700
20726
|
}
|
|
20701
20727
|
} else if (instr.kind === "Phi") {
|
|
@@ -21192,6 +21218,13 @@ function lowerExpressionImpl(expr, ctx, isAssigned = false) {
|
|
|
21192
21218
|
return t2.callExpression(t2.identifier(RUNTIME_ALIASES.mergeProps), args);
|
|
21193
21219
|
}
|
|
21194
21220
|
const isIIFE = (expr.callee.kind === "ArrowFunction" || expr.callee.kind === "FunctionExpression") && expr.arguments.length === 0 && expr.callee.params.length === 0;
|
|
21221
|
+
const calleeName = expr.callee.kind === "Identifier" ? deSSAVarName(expr.callee.name) : null;
|
|
21222
|
+
const calleeIsMemoAccessor = !!calleeName && ctx.memoVars?.has(calleeName);
|
|
21223
|
+
const calleeIsSignalLike = !!calleeName && (ctx.signalVars?.has(calleeName) || ctx.storeVars?.has(calleeName));
|
|
21224
|
+
if (calleeIsMemoAccessor && !calleeIsSignalLike && expr.arguments.length > 0) {
|
|
21225
|
+
const loweredArgs = expr.arguments.map((a) => lowerExpression(a, ctx));
|
|
21226
|
+
return t2.callExpression(t2.callExpression(t2.identifier(calleeName), []), loweredArgs);
|
|
21227
|
+
}
|
|
21195
21228
|
const lowerCallee = () => isIIFE ? withNonReactiveScope(ctx, () => lowerExpression(expr.callee, ctx)) : lowerExpression(expr.callee, ctx);
|
|
21196
21229
|
return t2.callExpression(
|
|
21197
21230
|
lowerCallee(),
|
|
@@ -21544,11 +21577,12 @@ function lowerExpressionImpl(expr, ctx, isAssigned = false) {
|
|
|
21544
21577
|
return t2.identifier("undefined");
|
|
21545
21578
|
}
|
|
21546
21579
|
}
|
|
21547
|
-
function lowerDomExpression(expr, ctx, region) {
|
|
21580
|
+
function lowerDomExpression(expr, ctx, region, options) {
|
|
21548
21581
|
let lowered = lowerExpression(expr, ctx);
|
|
21549
|
-
|
|
21582
|
+
const skipHookAccessors = options?.skipHookAccessors ?? false;
|
|
21583
|
+
if (!skipHookAccessors && ctx.t.isMemberExpression(lowered) && ctx.t.isIdentifier(lowered.object) && ctx.hookResultVarMap?.has(deSSAVarName(lowered.object.name))) {
|
|
21550
21584
|
lowered = ctx.t.callExpression(lowered, []);
|
|
21551
|
-
} else if (ctx.t.isIdentifier(lowered)) {
|
|
21585
|
+
} else if (!skipHookAccessors && ctx.t.isIdentifier(lowered)) {
|
|
21552
21586
|
const hookName = ctx.hookResultVarMap?.get(deSSAVarName(lowered.name));
|
|
21553
21587
|
if (hookName) {
|
|
21554
21588
|
const info = getHookReturnInfo(hookName, ctx);
|
|
@@ -21557,7 +21591,9 @@ function lowerDomExpression(expr, ctx, region) {
|
|
|
21557
21591
|
}
|
|
21558
21592
|
}
|
|
21559
21593
|
}
|
|
21560
|
-
return applyRegionMetadataToExpression(lowered, ctx, region
|
|
21594
|
+
return applyRegionMetadataToExpression(lowered, ctx, region, {
|
|
21595
|
+
skipRootOverride: options?.skipRegionRootOverride
|
|
21596
|
+
});
|
|
21561
21597
|
}
|
|
21562
21598
|
function lowerJSXChildNonFineGrained(child, ctx) {
|
|
21563
21599
|
const { t: t2 } = ctx;
|
|
@@ -21766,12 +21802,13 @@ function getDependencyPathFromNode(node, t2) {
|
|
|
21766
21802
|
}
|
|
21767
21803
|
return null;
|
|
21768
21804
|
}
|
|
21769
|
-
function applyRegionMetadataToExpression(expr, ctx, regionOverride) {
|
|
21805
|
+
function applyRegionMetadataToExpression(expr, ctx, regionOverride, options) {
|
|
21770
21806
|
if (ctx.inReturn && ctx.currentFnIsHook) {
|
|
21771
21807
|
return expr;
|
|
21772
21808
|
}
|
|
21773
21809
|
const region = regionOverride ?? ctx.currentRegion;
|
|
21774
21810
|
if (!region) return expr;
|
|
21811
|
+
const skipRootOverride = options?.skipRootOverride ?? false;
|
|
21775
21812
|
const metadata = regionInfoToMetadata(region);
|
|
21776
21813
|
const state = {};
|
|
21777
21814
|
applyRegionMetadata(state, {
|
|
@@ -21824,7 +21861,7 @@ function applyRegionMetadataToExpression(expr, ctx, regionOverride) {
|
|
|
21824
21861
|
if (Object.keys(overrides).length === 0) {
|
|
21825
21862
|
return expr;
|
|
21826
21863
|
}
|
|
21827
|
-
if (ctx.t.isIdentifier(expr)) {
|
|
21864
|
+
if (!skipRootOverride && ctx.t.isIdentifier(expr)) {
|
|
21828
21865
|
const key = normalizeDependencyKey2(expr.name);
|
|
21829
21866
|
const direct = overrides[key] ?? overrides[expr.name];
|
|
21830
21867
|
if (direct) {
|
|
@@ -21832,10 +21869,10 @@ function applyRegionMetadataToExpression(expr, ctx, regionOverride) {
|
|
|
21832
21869
|
}
|
|
21833
21870
|
}
|
|
21834
21871
|
const cloned = ctx.t.cloneNode(expr, true);
|
|
21835
|
-
replaceIdentifiersWithOverrides(cloned, overrides, ctx.t);
|
|
21872
|
+
replaceIdentifiersWithOverrides(cloned, overrides, ctx.t, void 0, void 0, skipRootOverride);
|
|
21836
21873
|
return cloned;
|
|
21837
21874
|
}
|
|
21838
|
-
function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parentKey) {
|
|
21875
|
+
function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parentKey, skipCurrentNode = false) {
|
|
21839
21876
|
const isCallTarget = parentKey === "callee" && (parentKind === "CallExpression" || parentKind === "OptionalCallExpression");
|
|
21840
21877
|
const collectParamNames = (params) => {
|
|
21841
21878
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -21871,7 +21908,7 @@ function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parent
|
|
|
21871
21908
|
params.forEach((p) => visitPattern(p));
|
|
21872
21909
|
return names;
|
|
21873
21910
|
};
|
|
21874
|
-
if (t2.isMemberExpression(node) || t2.isOptionalMemberExpression(node)) {
|
|
21911
|
+
if (!skipCurrentNode && (t2.isMemberExpression(node) || t2.isOptionalMemberExpression(node))) {
|
|
21875
21912
|
const path = getDependencyPathFromNode(node, t2);
|
|
21876
21913
|
const normalized = path ? normalizeDependencyKey2(path) : null;
|
|
21877
21914
|
const override = normalized && overrides[normalized] || (path ? overrides[path] : void 0);
|
|
@@ -21881,7 +21918,7 @@ function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parent
|
|
|
21881
21918
|
return;
|
|
21882
21919
|
}
|
|
21883
21920
|
}
|
|
21884
|
-
if (t2.isIdentifier(node)) {
|
|
21921
|
+
if (!skipCurrentNode && t2.isIdentifier(node)) {
|
|
21885
21922
|
const key = normalizeDependencyKey2(node.name);
|
|
21886
21923
|
const override = overrides[key] ?? overrides[node.name];
|
|
21887
21924
|
if (override && !isCallTarget) {
|
|
@@ -21926,7 +21963,8 @@ function replaceIdentifiersWithOverrides(node, overrides, t2, parentKind, parent
|
|
|
21926
21963
|
overrides,
|
|
21927
21964
|
t2,
|
|
21928
21965
|
node.type,
|
|
21929
|
-
key
|
|
21966
|
+
key,
|
|
21967
|
+
false
|
|
21930
21968
|
);
|
|
21931
21969
|
}
|
|
21932
21970
|
}
|
|
@@ -22355,7 +22393,10 @@ function lowerIntrinsicElement(jsx, ctx) {
|
|
|
22355
22393
|
const shouldWrapHandler = isExpressionReactive(binding.expr, ctx);
|
|
22356
22394
|
const prevWrapTracked = ctx.wrapTrackedExpressions;
|
|
22357
22395
|
ctx.wrapTrackedExpressions = false;
|
|
22358
|
-
const valueExpr = lowerDomExpression(binding.expr, ctx, containingRegion
|
|
22396
|
+
const valueExpr = lowerDomExpression(binding.expr, ctx, containingRegion, {
|
|
22397
|
+
skipHookAccessors: true,
|
|
22398
|
+
skipRegionRootOverride: true
|
|
22399
|
+
});
|
|
22359
22400
|
ctx.wrapTrackedExpressions = prevWrapTracked;
|
|
22360
22401
|
const eventParam = t2.identifier("_e");
|
|
22361
22402
|
const isFn = t2.isArrowFunctionExpression(valueExpr) || t2.isFunctionExpression(valueExpr);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fictjs/compiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Babel plugin for Fict Compiler",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/babel__helper-plugin-utils": "^7.10.3",
|
|
39
39
|
"@types/babel__traverse": "^7.28.0",
|
|
40
40
|
"tsup": "^8.5.1",
|
|
41
|
-
"@fictjs/runtime": "0.0.
|
|
41
|
+
"@fictjs/runtime": "0.0.4"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|