@farm.js/react 0.1.0-beta.22 → 0.1.0-beta.23

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @farm.js/react
2
2
 
3
- React renderer integration for FARMJS, including the opt-in AOT compiler.
3
+ React renderer integration for FARMJS, including the experimental AOT compiler.
4
4
 
5
5
  React remains the default renderer and needs no package or configuration. Install this package only
6
6
  when opting into the compiler:
@@ -23,7 +23,7 @@ export default defineConfig({
23
23
  `compiler: true` uses inference: every application TSX/JSX component is considered, eligible
24
24
  components are compiled with hybrid reactivity, and everything else keeps the normal React path.
25
25
 
26
- The compiler stays off when this option is omitted or `false`. The former
26
+ The compiler is experimental and stays off when this option is omitted or `false`. The former
27
27
  `react({ experimental: { compiler } })` spelling remains a deprecated alias with the same options
28
28
  and a one-time warning. Do not configure both spellings, even when one is `false`.
29
29
 
package/dist/vite.cjs CHANGED
@@ -6074,30 +6074,43 @@ function analyzePropsParameter(path) {
6074
6074
  };
6075
6075
  }
6076
6076
  if (!core.types.isObjectPattern(parameter)) {
6077
- return "components must use zero parameters, one props identifier, or flat object props destructuring";
6077
+ return "components must use zero parameters, one props identifier, or object props destructuring";
6078
6078
  }
6079
6079
  const localNames = /* @__PURE__ */ new Set();
6080
- for (const property of parameter.properties) {
6081
- if (core.types.isRestElement(property)) {
6082
- return "rest properties in component props destructuring are not supported yet";
6083
- }
6084
- if (property.computed) {
6085
- return "computed component props destructuring is not supported yet";
6086
- }
6087
- let local;
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;
6080
+ const collect = (pattern) => {
6081
+ if (!pattern) return void 0;
6082
+ if (core.types.isIdentifier(pattern)) {
6083
+ if (localNames.has(pattern.name)) {
6084
+ return "component props destructuring local names must be unique";
6085
+ }
6086
+ localNames.add(pattern.name);
6087
+ return void 0;
6092
6088
  }
6093
- if (!local) {
6094
- return "nested component props destructuring is not supported yet";
6089
+ if (core.types.isAssignmentPattern(pattern)) return collect(pattern.left);
6090
+ if (core.types.isRestElement(pattern)) return collect(pattern.argument);
6091
+ if (core.types.isArrayPattern(pattern)) {
6092
+ for (const element of pattern.elements) {
6093
+ const reason2 = collect(element);
6094
+ if (reason2) return reason2;
6095
+ }
6096
+ return void 0;
6095
6097
  }
6096
- if (localNames.has(local.name)) {
6097
- return "component props destructuring local names must be unique";
6098
+ if (core.types.isObjectPattern(pattern)) {
6099
+ for (const property of pattern.properties) {
6100
+ if (core.types.isObjectProperty(property) && property.computed) {
6101
+ return "computed component props destructuring is not supported yet";
6102
+ }
6103
+ const reason2 = collect(
6104
+ core.types.isRestElement(property) ? property : property.value
6105
+ );
6106
+ if (reason2) return reason2;
6107
+ }
6108
+ return void 0;
6098
6109
  }
6099
- localNames.add(local.name);
6100
- }
6110
+ return "components must use zero parameters, one props identifier, or object props destructuring";
6111
+ };
6112
+ const reason = collect(parameter);
6113
+ if (reason) return reason;
6101
6114
  const definitionParameter = path.scope.generateUidIdentifier("props");
6102
6115
  return {
6103
6116
  definitionParameter,
@@ -6190,7 +6203,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
6190
6203
  locals.push({
6191
6204
  kind: "handler",
6192
6205
  name: statement.id.name,
6193
- value: core.types.toExpression(core.types.cloneNode(statement, true))
6206
+ value: core.types.toExpression(core.types.cloneNode(statement, true)),
6207
+ statesBefore: states.length
6194
6208
  });
6195
6209
  continue;
6196
6210
  }
@@ -6202,9 +6216,6 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
6202
6216
  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
6217
  return "only const [value, setValue] = useState(initial) state declarations are supported";
6204
6218
  }
6205
- if (locals.length > 0) {
6206
- return "useState declarations must appear before derived local values and event handlers";
6207
- }
6208
6219
  states.push({
6209
6220
  valueName: declaration.id.elements[0].name,
6210
6221
  setterName: declaration.id.elements[1].name,
@@ -6223,13 +6234,15 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
6223
6234
  locals.push({
6224
6235
  kind: "handler",
6225
6236
  name: declaration.id.name,
6226
- value: declaration.init
6237
+ value: declaration.init,
6238
+ statesBefore: states.length
6227
6239
  });
6228
6240
  } else {
6229
6241
  locals.push({
6230
6242
  kind: "derived",
6231
6243
  name: declaration.id.name,
6232
- value: declaration.init
6244
+ value: declaration.init,
6245
+ statesBefore: states.length
6233
6246
  });
6234
6247
  }
6235
6248
  }
@@ -6248,6 +6261,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
6248
6261
  return "useState initializers cannot reference another local binding";
6249
6262
  }
6250
6263
  }
6264
+ for (const binding of locals) {
6265
+ if (binding.kind === "derived" && states.some(
6266
+ (state) => state.index >= binding.statesBefore && (referencesIdentifier(binding.value, state.valueName) || referencesIdentifier(binding.value, state.setterName))
6267
+ )) {
6268
+ return `derived local ${binding.name} reads a useState declared after it`;
6269
+ }
6270
+ }
6251
6271
  const derivedByName = /* @__PURE__ */ new Map();
6252
6272
  const handlersByName = /* @__PURE__ */ new Map();
6253
6273
  for (const binding of locals) {