@farm.js/react 0.1.0-beta.22 → 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 +8 -2
- 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 +109 -33
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +109 -33
- 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, {
|
|
@@ -6072,30 +6123,43 @@ function analyzePropsParameter(path) {
|
|
|
6072
6123
|
};
|
|
6073
6124
|
}
|
|
6074
6125
|
if (!types.isObjectPattern(parameter)) {
|
|
6075
|
-
return "components must use zero parameters, one props identifier, or
|
|
6126
|
+
return "components must use zero parameters, one props identifier, or object props destructuring";
|
|
6076
6127
|
}
|
|
6077
6128
|
const localNames = /* @__PURE__ */ new Set();
|
|
6078
|
-
|
|
6079
|
-
if (
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
if (types.isIdentifier(property.value)) {
|
|
6087
|
-
local = property.value;
|
|
6088
|
-
} else if (types.isAssignmentPattern(property.value) && types.isIdentifier(property.value.left)) {
|
|
6089
|
-
local = property.value.left;
|
|
6129
|
+
const collect = (pattern) => {
|
|
6130
|
+
if (!pattern) return void 0;
|
|
6131
|
+
if (types.isIdentifier(pattern)) {
|
|
6132
|
+
if (localNames.has(pattern.name)) {
|
|
6133
|
+
return "component props destructuring local names must be unique";
|
|
6134
|
+
}
|
|
6135
|
+
localNames.add(pattern.name);
|
|
6136
|
+
return void 0;
|
|
6090
6137
|
}
|
|
6091
|
-
if (
|
|
6092
|
-
|
|
6138
|
+
if (types.isAssignmentPattern(pattern)) return collect(pattern.left);
|
|
6139
|
+
if (types.isRestElement(pattern)) return collect(pattern.argument);
|
|
6140
|
+
if (types.isArrayPattern(pattern)) {
|
|
6141
|
+
for (const element of pattern.elements) {
|
|
6142
|
+
const reason2 = collect(element);
|
|
6143
|
+
if (reason2) return reason2;
|
|
6144
|
+
}
|
|
6145
|
+
return void 0;
|
|
6093
6146
|
}
|
|
6094
|
-
if (
|
|
6095
|
-
|
|
6147
|
+
if (types.isObjectPattern(pattern)) {
|
|
6148
|
+
for (const property of pattern.properties) {
|
|
6149
|
+
if (types.isObjectProperty(property) && property.computed) {
|
|
6150
|
+
return "computed component props destructuring is not supported yet";
|
|
6151
|
+
}
|
|
6152
|
+
const reason2 = collect(
|
|
6153
|
+
types.isRestElement(property) ? property : property.value
|
|
6154
|
+
);
|
|
6155
|
+
if (reason2) return reason2;
|
|
6156
|
+
}
|
|
6157
|
+
return void 0;
|
|
6096
6158
|
}
|
|
6097
|
-
|
|
6098
|
-
}
|
|
6159
|
+
return "components must use zero parameters, one props identifier, or object props destructuring";
|
|
6160
|
+
};
|
|
6161
|
+
const reason = collect(parameter);
|
|
6162
|
+
if (reason) return reason;
|
|
6099
6163
|
const definitionParameter = path.scope.generateUidIdentifier("props");
|
|
6100
6164
|
return {
|
|
6101
6165
|
definitionParameter,
|
|
@@ -6182,13 +6246,14 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6182
6246
|
}
|
|
6183
6247
|
if (types.isFunctionDeclaration(statement)) {
|
|
6184
6248
|
if (!statement.id) return "named event handler declarations must have a name";
|
|
6185
|
-
if (statement.
|
|
6186
|
-
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`;
|
|
6187
6251
|
}
|
|
6188
6252
|
locals.push({
|
|
6189
6253
|
kind: "handler",
|
|
6190
6254
|
name: statement.id.name,
|
|
6191
|
-
value: types.toExpression(types.cloneNode(statement, true))
|
|
6255
|
+
value: types.toExpression(types.cloneNode(statement, true)),
|
|
6256
|
+
statesBefore: states.length
|
|
6192
6257
|
});
|
|
6193
6258
|
continue;
|
|
6194
6259
|
}
|
|
@@ -6200,9 +6265,6 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6200
6265
|
if (declaration.id.elements.length !== 2 || !types.isIdentifier(declaration.id.elements[0]) || !types.isIdentifier(declaration.id.elements[1]) || !isUseStateCall(declaration.init, useStateNames, reactNames) || declaration.init.arguments.length > 1 || declaration.init.arguments[0] && !types.isExpression(declaration.init.arguments[0])) {
|
|
6201
6266
|
return "only const [value, setValue] = useState(initial) state declarations are supported";
|
|
6202
6267
|
}
|
|
6203
|
-
if (locals.length > 0) {
|
|
6204
|
-
return "useState declarations must appear before derived local values and event handlers";
|
|
6205
|
-
}
|
|
6206
6268
|
states.push({
|
|
6207
6269
|
valueName: declaration.id.elements[0].name,
|
|
6208
6270
|
setterName: declaration.id.elements[1].name,
|
|
@@ -6215,19 +6277,21 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6215
6277
|
return "derived const values and event handlers must use one identifier and one expression";
|
|
6216
6278
|
}
|
|
6217
6279
|
if (types.isArrowFunctionExpression(declaration.init) || types.isFunctionExpression(declaration.init)) {
|
|
6218
|
-
if (declaration.init.
|
|
6219
|
-
return `event handler ${declaration.id.name}
|
|
6280
|
+
if (declaration.init.generator) {
|
|
6281
|
+
return `event handler ${declaration.id.name} cannot be a generator`;
|
|
6220
6282
|
}
|
|
6221
6283
|
locals.push({
|
|
6222
6284
|
kind: "handler",
|
|
6223
6285
|
name: declaration.id.name,
|
|
6224
|
-
value: declaration.init
|
|
6286
|
+
value: declaration.init,
|
|
6287
|
+
statesBefore: states.length
|
|
6225
6288
|
});
|
|
6226
6289
|
} else {
|
|
6227
6290
|
locals.push({
|
|
6228
6291
|
kind: "derived",
|
|
6229
6292
|
name: declaration.id.name,
|
|
6230
|
-
value: declaration.init
|
|
6293
|
+
value: declaration.init,
|
|
6294
|
+
statesBefore: states.length
|
|
6231
6295
|
});
|
|
6232
6296
|
}
|
|
6233
6297
|
}
|
|
@@ -6246,6 +6310,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6246
6310
|
return "useState initializers cannot reference another local binding";
|
|
6247
6311
|
}
|
|
6248
6312
|
}
|
|
6313
|
+
for (const binding of locals) {
|
|
6314
|
+
if (binding.kind === "derived" && states.some(
|
|
6315
|
+
(state) => state.index >= binding.statesBefore && (referencesIdentifier(binding.value, state.valueName) || referencesIdentifier(binding.value, state.setterName))
|
|
6316
|
+
)) {
|
|
6317
|
+
return `derived local ${binding.name} reads a useState declared after it`;
|
|
6318
|
+
}
|
|
6319
|
+
}
|
|
6249
6320
|
const derivedByName = /* @__PURE__ */ new Map();
|
|
6250
6321
|
const handlersByName = /* @__PURE__ */ new Map();
|
|
6251
6322
|
for (const binding of locals) {
|
|
@@ -6273,8 +6344,12 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6273
6344
|
const handlerRewrite = rewriteHandlerAccess(rootWithDerived, handlersByName);
|
|
6274
6345
|
if (handlerRewrite.reason) return handlerRewrite.reason;
|
|
6275
6346
|
if (!handlerRewrite.root) return "event handlers could not be prepared safely";
|
|
6276
|
-
const
|
|
6347
|
+
const snapshotRoot = snapshotDeferredHandlerReads(
|
|
6277
6348
|
handlerRewrite.root,
|
|
6349
|
+
/* @__PURE__ */ new Set([...states.map((state) => state.valueName), ...propsPlan.destructuredNames])
|
|
6350
|
+
);
|
|
6351
|
+
const expandedRootWithDeferredEvents = rewriteDestructuredPropAccess(
|
|
6352
|
+
snapshotRoot,
|
|
6278
6353
|
propsPlan.destructuredNames,
|
|
6279
6354
|
propsPlan.definitionParameter
|
|
6280
6355
|
);
|
|
@@ -7148,7 +7223,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7148
7223
|
appliedPipelineMapHints > 0 || appliedQueuedReorderMapHints > 0 || appliedQueuedMappedStructuralHints > 0 || appliedQueuedStructuralMapHints > 0,
|
|
7149
7224
|
appliedMappedRollingWindowChainHints > 0,
|
|
7150
7225
|
appliedKeyedArrayRollingWindowHints > appliedMappedRollingWindowHints,
|
|
7151
|
-
appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0
|
|
7226
|
+
appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0,
|
|
7227
|
+
appliedKeyedArrayAppendHints > 0 && appliedKeyedMapUpdateHints === 0
|
|
7152
7228
|
);
|
|
7153
7229
|
markShortCircuitBindings(analysis.bindings || []);
|
|
7154
7230
|
assignStableBindingTargets(analysis.bindings || []);
|