@farm.js/react 0.1.0-beta.23 → 0.1.0-beta.24
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 +6 -0
- package/dist/compiler-runtime.cjs +145 -23
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +2 -1
- package/dist/compiler-runtime.d.ts +2 -1
- package/dist/compiler-runtime.mjs +145 -24
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/vite.cjs +64 -8
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +64 -8
- package/dist/vite.mjs.map +1 -1
- package/package.json +2 -2
package/dist/vite.mjs
CHANGED
|
@@ -71,6 +71,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
|
71
71
|
"keyed-rows-membership": "keyedRowsMembershipRuntimeFeature",
|
|
72
72
|
"keyed-rows-map-lookup": "keyedRowsMapLookupRuntimeFeature",
|
|
73
73
|
"keyed-rows-hinted": "keyedRowsHintedRuntimeFeature",
|
|
74
|
+
"keyed-rows-append-only": "keyedRowsAppendOnlyRuntimeFeature",
|
|
74
75
|
"keyed-rows-position-hinted": "keyedRowsPositionHintedRuntimeFeature",
|
|
75
76
|
"keyed-rows-batch-position-hinted": "keyedRowsBatchPositionHintedRuntimeFeature",
|
|
76
77
|
"keyed-rows-window-position-hinted": "keyedRowsWindowPositionHintedRuntimeFeature",
|
|
@@ -148,7 +149,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
|
148
149
|
"mixed-ranges": "mixedRangesRuntimeFeature",
|
|
149
150
|
component: "componentRuntimeFeature"
|
|
150
151
|
};
|
|
151
|
-
function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints, keyedArrayStructuralAppendHints, keyedArrayStructuralAppendMapHints, keyedArrayPrependHints, keyedArrayStructuralPrependHints, keyedArrayStructuralPrependMapHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayMapReorderHints, keyedArrayMappedRollingWindowChainHints, keyedArrayRollingWindowHints, keyedMapOrAppendHints) {
|
|
152
|
+
function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints, keyedArrayStructuralAppendHints, keyedArrayStructuralAppendMapHints, keyedArrayPrependHints, keyedArrayStructuralPrependHints, keyedArrayStructuralPrependMapHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayMapReorderHints, keyedArrayMappedRollingWindowChainHints, keyedArrayRollingWindowHints, keyedMapOrAppendHints, keyedArrayAppendOnlyHints) {
|
|
152
153
|
const features = /* @__PURE__ */ new Set();
|
|
153
154
|
let keyedRowsHaveConditionals = false;
|
|
154
155
|
let keyedRowsHaveHostBlocks = false;
|
|
@@ -173,7 +174,9 @@ function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints,
|
|
|
173
174
|
const arrayRangeHints = keyedArrayRollingWindowHints || keyedArrayFilterHints || keyedArrayPrependHints;
|
|
174
175
|
const needsCombinedStructuralPrependRuntime = keyedArrayStructuralPrependHints && (keyedArrayStructuralAppendMapHints || keyedArrayStructuralAppendHints || keyedArrayWindowReplaceHints || keyedArrayBatchInsertHints || keyedArrayPositionHints || keyedArrayReorderHints || keyedArrayRollingWindowHints);
|
|
175
176
|
const hintSuffix = keyedArrayMappedRollingWindowChainHints ? "-mapped-rolling-window-hinted" : keyedArrayStructuralPrependMapHints ? "-structural-prepend-map-hinted" : needsCombinedStructuralPrependRuntime ? "-structural-prepend-hinted" : keyedArrayStructuralAppendMapHints ? "-structural-append-map-hinted" : keyedArrayStructuralAppendHints ? "-structural-append-hinted" : keyedArrayWindowReplaceHints ? arrayRangeHints || keyedArrayReorderHints ? "-window-every-hinted" : "-window-position-hinted" : keyedArrayBatchInsertHints ? arrayRangeHints || keyedArrayReorderHints ? "-batch-every-hinted" : "-batch-position-hinted" : keyedArrayPositionHints && (arrayRangeHints || keyedArrayReorderHints) || keyedArrayReorderHints && arrayRangeHints ? "-every-hinted" : keyedArrayRollingWindowHints ? "-all-hinted" : keyedArrayPositionHints ? "-position-hinted" : keyedArrayMapReorderHints && keyedRowsFeature === "keyed-rows" ? "-map-reorder-hinted" : keyedArrayReorderHints ? "-reorder-hinted" : keyedArrayFilterHints && keyedArrayPrependHints ? "-filter-prepend-hinted" : keyedArrayFilterHints ? "-filter-hinted" : keyedArrayPrependHints ? "-prepend-hinted" : keyedUpdateHints ? "-hinted" : "";
|
|
176
|
-
if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-
|
|
177
|
+
if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-hinted" && keyedTargetKinds.size === 0 && keyedArrayAppendOnlyHints) {
|
|
178
|
+
features.add("keyed-rows-append-only");
|
|
179
|
+
} else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-filter-hinted" && keyedTargetKinds.size === 1 && keyedTargetKinds.has("identity")) {
|
|
177
180
|
features.add(
|
|
178
181
|
keyedMapOrAppendHints ? "keyed-rows-identity-filter-hinted" : "keyed-rows-identity-filter-only"
|
|
179
182
|
);
|
|
@@ -2760,6 +2763,54 @@ function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySe
|
|
|
2760
2763
|
count
|
|
2761
2764
|
};
|
|
2762
2765
|
}
|
|
2766
|
+
function snapshotDeferredHandlerReads(root, reactiveNames) {
|
|
2767
|
+
if (reactiveNames.size === 0) return root;
|
|
2768
|
+
const file = expressionFile(types.cloneNode(root, true));
|
|
2769
|
+
traverse(file, {
|
|
2770
|
+
JSXAttribute(path) {
|
|
2771
|
+
if (!types.isJSXIdentifier(path.node.name) || !/^on[A-Z]/.test(path.node.name.name)) return;
|
|
2772
|
+
const value = path.get("value");
|
|
2773
|
+
if (!value.isJSXExpressionContainer()) return;
|
|
2774
|
+
const handler = value.get("expression");
|
|
2775
|
+
if (!handler.isArrowFunctionExpression() && !handler.isFunctionExpression()) return;
|
|
2776
|
+
let defers = false;
|
|
2777
|
+
handler.traverse({
|
|
2778
|
+
AwaitExpression(inner) {
|
|
2779
|
+
defers = true;
|
|
2780
|
+
inner.stop();
|
|
2781
|
+
},
|
|
2782
|
+
Function(inner) {
|
|
2783
|
+
defers = true;
|
|
2784
|
+
inner.stop();
|
|
2785
|
+
}
|
|
2786
|
+
});
|
|
2787
|
+
if (!defers) return;
|
|
2788
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
2789
|
+
handler.traverse({
|
|
2790
|
+
ReferencedIdentifier(reference) {
|
|
2791
|
+
const name = reference.node.name;
|
|
2792
|
+
if (!reactiveNames.has(name) || reference.scope.hasBinding(name)) return;
|
|
2793
|
+
let snapshot = snapshots.get(name);
|
|
2794
|
+
if (!snapshot) {
|
|
2795
|
+
snapshot = handler.scope.generateUidIdentifier(name);
|
|
2796
|
+
snapshots.set(name, snapshot);
|
|
2797
|
+
}
|
|
2798
|
+
reference.replaceWith(types.cloneNode(snapshot));
|
|
2799
|
+
}
|
|
2800
|
+
});
|
|
2801
|
+
if (snapshots.size === 0) return;
|
|
2802
|
+
const declaration = types.variableDeclaration(
|
|
2803
|
+
"const",
|
|
2804
|
+
[...snapshots].map(
|
|
2805
|
+
([name, snapshot]) => types.variableDeclarator(snapshot, types.identifier(name))
|
|
2806
|
+
)
|
|
2807
|
+
);
|
|
2808
|
+
const body = handler.node.body;
|
|
2809
|
+
handler.node.body = types.isBlockStatement(body) ? types.blockStatement([declaration, ...body.body], body.directives) : types.blockStatement([declaration, types.returnStatement(body)]);
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
return file.program.body[0].expression;
|
|
2813
|
+
}
|
|
2763
2814
|
function rewriteStateAccess(expression, stateParameter, statesByValue, statesBySetter) {
|
|
2764
2815
|
const file = expressionFile(cloneExpression(expression));
|
|
2765
2816
|
traverse(file, {
|
|
@@ -6195,8 +6246,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6195
6246
|
}
|
|
6196
6247
|
if (types.isFunctionDeclaration(statement)) {
|
|
6197
6248
|
if (!statement.id) return "named event handler declarations must have a name";
|
|
6198
|
-
if (statement.
|
|
6199
|
-
return `event handler ${statement.id.name} must be
|
|
6249
|
+
if (statement.generator || statement.typeParameters) {
|
|
6250
|
+
return `event handler ${statement.id.name} must be a non-generator, non-generic function`;
|
|
6200
6251
|
}
|
|
6201
6252
|
locals.push({
|
|
6202
6253
|
kind: "handler",
|
|
@@ -6226,8 +6277,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6226
6277
|
return "derived const values and event handlers must use one identifier and one expression";
|
|
6227
6278
|
}
|
|
6228
6279
|
if (types.isArrowFunctionExpression(declaration.init) || types.isFunctionExpression(declaration.init)) {
|
|
6229
|
-
if (declaration.init.
|
|
6230
|
-
return `event handler ${declaration.id.name}
|
|
6280
|
+
if (declaration.init.generator) {
|
|
6281
|
+
return `event handler ${declaration.id.name} cannot be a generator`;
|
|
6231
6282
|
}
|
|
6232
6283
|
locals.push({
|
|
6233
6284
|
kind: "handler",
|
|
@@ -6293,8 +6344,12 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6293
6344
|
const handlerRewrite = rewriteHandlerAccess(rootWithDerived, handlersByName);
|
|
6294
6345
|
if (handlerRewrite.reason) return handlerRewrite.reason;
|
|
6295
6346
|
if (!handlerRewrite.root) return "event handlers could not be prepared safely";
|
|
6296
|
-
const
|
|
6347
|
+
const snapshotRoot = snapshotDeferredHandlerReads(
|
|
6297
6348
|
handlerRewrite.root,
|
|
6349
|
+
/* @__PURE__ */ new Set([...states.map((state) => state.valueName), ...propsPlan.destructuredNames])
|
|
6350
|
+
);
|
|
6351
|
+
const expandedRootWithDeferredEvents = rewriteDestructuredPropAccess(
|
|
6352
|
+
snapshotRoot,
|
|
6298
6353
|
propsPlan.destructuredNames,
|
|
6299
6354
|
propsPlan.definitionParameter
|
|
6300
6355
|
);
|
|
@@ -7168,7 +7223,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7168
7223
|
appliedPipelineMapHints > 0 || appliedQueuedReorderMapHints > 0 || appliedQueuedMappedStructuralHints > 0 || appliedQueuedStructuralMapHints > 0,
|
|
7169
7224
|
appliedMappedRollingWindowChainHints > 0,
|
|
7170
7225
|
appliedKeyedArrayRollingWindowHints > appliedMappedRollingWindowHints,
|
|
7171
|
-
appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0
|
|
7226
|
+
appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0,
|
|
7227
|
+
appliedKeyedArrayAppendHints > 0 && appliedKeyedMapUpdateHints === 0
|
|
7172
7228
|
);
|
|
7173
7229
|
markShortCircuitBindings(analysis.bindings || []);
|
|
7174
7230
|
assignStableBindingTargets(analysis.bindings || []);
|