@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.cjs
CHANGED
|
@@ -73,6 +73,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
|
73
73
|
"keyed-rows-membership": "keyedRowsMembershipRuntimeFeature",
|
|
74
74
|
"keyed-rows-map-lookup": "keyedRowsMapLookupRuntimeFeature",
|
|
75
75
|
"keyed-rows-hinted": "keyedRowsHintedRuntimeFeature",
|
|
76
|
+
"keyed-rows-append-only": "keyedRowsAppendOnlyRuntimeFeature",
|
|
76
77
|
"keyed-rows-position-hinted": "keyedRowsPositionHintedRuntimeFeature",
|
|
77
78
|
"keyed-rows-batch-position-hinted": "keyedRowsBatchPositionHintedRuntimeFeature",
|
|
78
79
|
"keyed-rows-window-position-hinted": "keyedRowsWindowPositionHintedRuntimeFeature",
|
|
@@ -150,7 +151,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
|
150
151
|
"mixed-ranges": "mixedRangesRuntimeFeature",
|
|
151
152
|
component: "componentRuntimeFeature"
|
|
152
153
|
};
|
|
153
|
-
function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints, keyedArrayStructuralAppendHints, keyedArrayStructuralAppendMapHints, keyedArrayPrependHints, keyedArrayStructuralPrependHints, keyedArrayStructuralPrependMapHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayMapReorderHints, keyedArrayMappedRollingWindowChainHints, keyedArrayRollingWindowHints, keyedMapOrAppendHints) {
|
|
154
|
+
function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints, keyedArrayStructuralAppendHints, keyedArrayStructuralAppendMapHints, keyedArrayPrependHints, keyedArrayStructuralPrependHints, keyedArrayStructuralPrependMapHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayMapReorderHints, keyedArrayMappedRollingWindowChainHints, keyedArrayRollingWindowHints, keyedMapOrAppendHints, keyedArrayAppendOnlyHints) {
|
|
154
155
|
const features = /* @__PURE__ */ new Set();
|
|
155
156
|
let keyedRowsHaveConditionals = false;
|
|
156
157
|
let keyedRowsHaveHostBlocks = false;
|
|
@@ -175,7 +176,9 @@ function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints,
|
|
|
175
176
|
const arrayRangeHints = keyedArrayRollingWindowHints || keyedArrayFilterHints || keyedArrayPrependHints;
|
|
176
177
|
const needsCombinedStructuralPrependRuntime = keyedArrayStructuralPrependHints && (keyedArrayStructuralAppendMapHints || keyedArrayStructuralAppendHints || keyedArrayWindowReplaceHints || keyedArrayBatchInsertHints || keyedArrayPositionHints || keyedArrayReorderHints || keyedArrayRollingWindowHints);
|
|
177
178
|
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" : "";
|
|
178
|
-
if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-
|
|
179
|
+
if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-hinted" && keyedTargetKinds.size === 0 && keyedArrayAppendOnlyHints) {
|
|
180
|
+
features.add("keyed-rows-append-only");
|
|
181
|
+
} else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-filter-hinted" && keyedTargetKinds.size === 1 && keyedTargetKinds.has("identity")) {
|
|
179
182
|
features.add(
|
|
180
183
|
keyedMapOrAppendHints ? "keyed-rows-identity-filter-hinted" : "keyed-rows-identity-filter-only"
|
|
181
184
|
);
|
|
@@ -2762,6 +2765,54 @@ function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySe
|
|
|
2762
2765
|
count
|
|
2763
2766
|
};
|
|
2764
2767
|
}
|
|
2768
|
+
function snapshotDeferredHandlerReads(root, reactiveNames) {
|
|
2769
|
+
if (reactiveNames.size === 0) return root;
|
|
2770
|
+
const file = expressionFile(core.types.cloneNode(root, true));
|
|
2771
|
+
core.traverse(file, {
|
|
2772
|
+
JSXAttribute(path) {
|
|
2773
|
+
if (!core.types.isJSXIdentifier(path.node.name) || !/^on[A-Z]/.test(path.node.name.name)) return;
|
|
2774
|
+
const value = path.get("value");
|
|
2775
|
+
if (!value.isJSXExpressionContainer()) return;
|
|
2776
|
+
const handler = value.get("expression");
|
|
2777
|
+
if (!handler.isArrowFunctionExpression() && !handler.isFunctionExpression()) return;
|
|
2778
|
+
let defers = false;
|
|
2779
|
+
handler.traverse({
|
|
2780
|
+
AwaitExpression(inner) {
|
|
2781
|
+
defers = true;
|
|
2782
|
+
inner.stop();
|
|
2783
|
+
},
|
|
2784
|
+
Function(inner) {
|
|
2785
|
+
defers = true;
|
|
2786
|
+
inner.stop();
|
|
2787
|
+
}
|
|
2788
|
+
});
|
|
2789
|
+
if (!defers) return;
|
|
2790
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
2791
|
+
handler.traverse({
|
|
2792
|
+
ReferencedIdentifier(reference) {
|
|
2793
|
+
const name = reference.node.name;
|
|
2794
|
+
if (!reactiveNames.has(name) || reference.scope.hasBinding(name)) return;
|
|
2795
|
+
let snapshot = snapshots.get(name);
|
|
2796
|
+
if (!snapshot) {
|
|
2797
|
+
snapshot = handler.scope.generateUidIdentifier(name);
|
|
2798
|
+
snapshots.set(name, snapshot);
|
|
2799
|
+
}
|
|
2800
|
+
reference.replaceWith(core.types.cloneNode(snapshot));
|
|
2801
|
+
}
|
|
2802
|
+
});
|
|
2803
|
+
if (snapshots.size === 0) return;
|
|
2804
|
+
const declaration = core.types.variableDeclaration(
|
|
2805
|
+
"const",
|
|
2806
|
+
[...snapshots].map(
|
|
2807
|
+
([name, snapshot]) => core.types.variableDeclarator(snapshot, core.types.identifier(name))
|
|
2808
|
+
)
|
|
2809
|
+
);
|
|
2810
|
+
const body = handler.node.body;
|
|
2811
|
+
handler.node.body = core.types.isBlockStatement(body) ? core.types.blockStatement([declaration, ...body.body], body.directives) : core.types.blockStatement([declaration, core.types.returnStatement(body)]);
|
|
2812
|
+
}
|
|
2813
|
+
});
|
|
2814
|
+
return file.program.body[0].expression;
|
|
2815
|
+
}
|
|
2765
2816
|
function rewriteStateAccess(expression, stateParameter, statesByValue, statesBySetter) {
|
|
2766
2817
|
const file = expressionFile(cloneExpression(expression));
|
|
2767
2818
|
core.traverse(file, {
|
|
@@ -6074,30 +6125,43 @@ function analyzePropsParameter(path) {
|
|
|
6074
6125
|
};
|
|
6075
6126
|
}
|
|
6076
6127
|
if (!core.types.isObjectPattern(parameter)) {
|
|
6077
|
-
return "components must use zero parameters, one props identifier, or
|
|
6128
|
+
return "components must use zero parameters, one props identifier, or object props destructuring";
|
|
6078
6129
|
}
|
|
6079
6130
|
const localNames = /* @__PURE__ */ new Set();
|
|
6080
|
-
|
|
6081
|
-
if (
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
if (core.types.isIdentifier(property.value)) {
|
|
6089
|
-
local = property.value;
|
|
6090
|
-
} else if (core.types.isAssignmentPattern(property.value) && core.types.isIdentifier(property.value.left)) {
|
|
6091
|
-
local = property.value.left;
|
|
6131
|
+
const collect = (pattern) => {
|
|
6132
|
+
if (!pattern) return void 0;
|
|
6133
|
+
if (core.types.isIdentifier(pattern)) {
|
|
6134
|
+
if (localNames.has(pattern.name)) {
|
|
6135
|
+
return "component props destructuring local names must be unique";
|
|
6136
|
+
}
|
|
6137
|
+
localNames.add(pattern.name);
|
|
6138
|
+
return void 0;
|
|
6092
6139
|
}
|
|
6093
|
-
if (
|
|
6094
|
-
|
|
6140
|
+
if (core.types.isAssignmentPattern(pattern)) return collect(pattern.left);
|
|
6141
|
+
if (core.types.isRestElement(pattern)) return collect(pattern.argument);
|
|
6142
|
+
if (core.types.isArrayPattern(pattern)) {
|
|
6143
|
+
for (const element of pattern.elements) {
|
|
6144
|
+
const reason2 = collect(element);
|
|
6145
|
+
if (reason2) return reason2;
|
|
6146
|
+
}
|
|
6147
|
+
return void 0;
|
|
6095
6148
|
}
|
|
6096
|
-
if (
|
|
6097
|
-
|
|
6149
|
+
if (core.types.isObjectPattern(pattern)) {
|
|
6150
|
+
for (const property of pattern.properties) {
|
|
6151
|
+
if (core.types.isObjectProperty(property) && property.computed) {
|
|
6152
|
+
return "computed component props destructuring is not supported yet";
|
|
6153
|
+
}
|
|
6154
|
+
const reason2 = collect(
|
|
6155
|
+
core.types.isRestElement(property) ? property : property.value
|
|
6156
|
+
);
|
|
6157
|
+
if (reason2) return reason2;
|
|
6158
|
+
}
|
|
6159
|
+
return void 0;
|
|
6098
6160
|
}
|
|
6099
|
-
|
|
6100
|
-
}
|
|
6161
|
+
return "components must use zero parameters, one props identifier, or object props destructuring";
|
|
6162
|
+
};
|
|
6163
|
+
const reason = collect(parameter);
|
|
6164
|
+
if (reason) return reason;
|
|
6101
6165
|
const definitionParameter = path.scope.generateUidIdentifier("props");
|
|
6102
6166
|
return {
|
|
6103
6167
|
definitionParameter,
|
|
@@ -6184,13 +6248,14 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6184
6248
|
}
|
|
6185
6249
|
if (core.types.isFunctionDeclaration(statement)) {
|
|
6186
6250
|
if (!statement.id) return "named event handler declarations must have a name";
|
|
6187
|
-
if (statement.
|
|
6188
|
-
return `event handler ${statement.id.name} must be
|
|
6251
|
+
if (statement.generator || statement.typeParameters) {
|
|
6252
|
+
return `event handler ${statement.id.name} must be a non-generator, non-generic function`;
|
|
6189
6253
|
}
|
|
6190
6254
|
locals.push({
|
|
6191
6255
|
kind: "handler",
|
|
6192
6256
|
name: statement.id.name,
|
|
6193
|
-
value: core.types.toExpression(core.types.cloneNode(statement, true))
|
|
6257
|
+
value: core.types.toExpression(core.types.cloneNode(statement, true)),
|
|
6258
|
+
statesBefore: states.length
|
|
6194
6259
|
});
|
|
6195
6260
|
continue;
|
|
6196
6261
|
}
|
|
@@ -6202,9 +6267,6 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6202
6267
|
if (declaration.id.elements.length !== 2 || !core.types.isIdentifier(declaration.id.elements[0]) || !core.types.isIdentifier(declaration.id.elements[1]) || !isUseStateCall(declaration.init, useStateNames, reactNames) || declaration.init.arguments.length > 1 || declaration.init.arguments[0] && !core.types.isExpression(declaration.init.arguments[0])) {
|
|
6203
6268
|
return "only const [value, setValue] = useState(initial) state declarations are supported";
|
|
6204
6269
|
}
|
|
6205
|
-
if (locals.length > 0) {
|
|
6206
|
-
return "useState declarations must appear before derived local values and event handlers";
|
|
6207
|
-
}
|
|
6208
6270
|
states.push({
|
|
6209
6271
|
valueName: declaration.id.elements[0].name,
|
|
6210
6272
|
setterName: declaration.id.elements[1].name,
|
|
@@ -6217,19 +6279,21 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6217
6279
|
return "derived const values and event handlers must use one identifier and one expression";
|
|
6218
6280
|
}
|
|
6219
6281
|
if (core.types.isArrowFunctionExpression(declaration.init) || core.types.isFunctionExpression(declaration.init)) {
|
|
6220
|
-
if (declaration.init.
|
|
6221
|
-
return `event handler ${declaration.id.name}
|
|
6282
|
+
if (declaration.init.generator) {
|
|
6283
|
+
return `event handler ${declaration.id.name} cannot be a generator`;
|
|
6222
6284
|
}
|
|
6223
6285
|
locals.push({
|
|
6224
6286
|
kind: "handler",
|
|
6225
6287
|
name: declaration.id.name,
|
|
6226
|
-
value: declaration.init
|
|
6288
|
+
value: declaration.init,
|
|
6289
|
+
statesBefore: states.length
|
|
6227
6290
|
});
|
|
6228
6291
|
} else {
|
|
6229
6292
|
locals.push({
|
|
6230
6293
|
kind: "derived",
|
|
6231
6294
|
name: declaration.id.name,
|
|
6232
|
-
value: declaration.init
|
|
6295
|
+
value: declaration.init,
|
|
6296
|
+
statesBefore: states.length
|
|
6233
6297
|
});
|
|
6234
6298
|
}
|
|
6235
6299
|
}
|
|
@@ -6248,6 +6312,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6248
6312
|
return "useState initializers cannot reference another local binding";
|
|
6249
6313
|
}
|
|
6250
6314
|
}
|
|
6315
|
+
for (const binding of locals) {
|
|
6316
|
+
if (binding.kind === "derived" && states.some(
|
|
6317
|
+
(state) => state.index >= binding.statesBefore && (referencesIdentifier(binding.value, state.valueName) || referencesIdentifier(binding.value, state.setterName))
|
|
6318
|
+
)) {
|
|
6319
|
+
return `derived local ${binding.name} reads a useState declared after it`;
|
|
6320
|
+
}
|
|
6321
|
+
}
|
|
6251
6322
|
const derivedByName = /* @__PURE__ */ new Map();
|
|
6252
6323
|
const handlersByName = /* @__PURE__ */ new Map();
|
|
6253
6324
|
for (const binding of locals) {
|
|
@@ -6275,8 +6346,12 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6275
6346
|
const handlerRewrite = rewriteHandlerAccess(rootWithDerived, handlersByName);
|
|
6276
6347
|
if (handlerRewrite.reason) return handlerRewrite.reason;
|
|
6277
6348
|
if (!handlerRewrite.root) return "event handlers could not be prepared safely";
|
|
6278
|
-
const
|
|
6349
|
+
const snapshotRoot = snapshotDeferredHandlerReads(
|
|
6279
6350
|
handlerRewrite.root,
|
|
6351
|
+
/* @__PURE__ */ new Set([...states.map((state) => state.valueName), ...propsPlan.destructuredNames])
|
|
6352
|
+
);
|
|
6353
|
+
const expandedRootWithDeferredEvents = rewriteDestructuredPropAccess(
|
|
6354
|
+
snapshotRoot,
|
|
6280
6355
|
propsPlan.destructuredNames,
|
|
6281
6356
|
propsPlan.definitionParameter
|
|
6282
6357
|
);
|
|
@@ -7150,7 +7225,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7150
7225
|
appliedPipelineMapHints > 0 || appliedQueuedReorderMapHints > 0 || appliedQueuedMappedStructuralHints > 0 || appliedQueuedStructuralMapHints > 0,
|
|
7151
7226
|
appliedMappedRollingWindowChainHints > 0,
|
|
7152
7227
|
appliedKeyedArrayRollingWindowHints > appliedMappedRollingWindowHints,
|
|
7153
|
-
appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0
|
|
7228
|
+
appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0,
|
|
7229
|
+
appliedKeyedArrayAppendHints > 0 && appliedKeyedMapUpdateHints === 0
|
|
7154
7230
|
);
|
|
7155
7231
|
markShortCircuitBindings(analysis.bindings || []);
|
|
7156
7232
|
assignStableBindingTargets(analysis.bindings || []);
|