@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 +2 -2
- package/dist/vite.cjs +45 -25
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +45 -25
- package/dist/vite.mjs.map +1 -1
- package/package.json +2 -2
package/dist/vite.mjs
CHANGED
|
@@ -6072,30 +6072,43 @@ function analyzePropsParameter(path) {
|
|
|
6072
6072
|
};
|
|
6073
6073
|
}
|
|
6074
6074
|
if (!types.isObjectPattern(parameter)) {
|
|
6075
|
-
return "components must use zero parameters, one props identifier, or
|
|
6075
|
+
return "components must use zero parameters, one props identifier, or object props destructuring";
|
|
6076
6076
|
}
|
|
6077
6077
|
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;
|
|
6078
|
+
const collect = (pattern) => {
|
|
6079
|
+
if (!pattern) return void 0;
|
|
6080
|
+
if (types.isIdentifier(pattern)) {
|
|
6081
|
+
if (localNames.has(pattern.name)) {
|
|
6082
|
+
return "component props destructuring local names must be unique";
|
|
6083
|
+
}
|
|
6084
|
+
localNames.add(pattern.name);
|
|
6085
|
+
return void 0;
|
|
6090
6086
|
}
|
|
6091
|
-
if (
|
|
6092
|
-
|
|
6087
|
+
if (types.isAssignmentPattern(pattern)) return collect(pattern.left);
|
|
6088
|
+
if (types.isRestElement(pattern)) return collect(pattern.argument);
|
|
6089
|
+
if (types.isArrayPattern(pattern)) {
|
|
6090
|
+
for (const element of pattern.elements) {
|
|
6091
|
+
const reason2 = collect(element);
|
|
6092
|
+
if (reason2) return reason2;
|
|
6093
|
+
}
|
|
6094
|
+
return void 0;
|
|
6093
6095
|
}
|
|
6094
|
-
if (
|
|
6095
|
-
|
|
6096
|
+
if (types.isObjectPattern(pattern)) {
|
|
6097
|
+
for (const property of pattern.properties) {
|
|
6098
|
+
if (types.isObjectProperty(property) && property.computed) {
|
|
6099
|
+
return "computed component props destructuring is not supported yet";
|
|
6100
|
+
}
|
|
6101
|
+
const reason2 = collect(
|
|
6102
|
+
types.isRestElement(property) ? property : property.value
|
|
6103
|
+
);
|
|
6104
|
+
if (reason2) return reason2;
|
|
6105
|
+
}
|
|
6106
|
+
return void 0;
|
|
6096
6107
|
}
|
|
6097
|
-
|
|
6098
|
-
}
|
|
6108
|
+
return "components must use zero parameters, one props identifier, or object props destructuring";
|
|
6109
|
+
};
|
|
6110
|
+
const reason = collect(parameter);
|
|
6111
|
+
if (reason) return reason;
|
|
6099
6112
|
const definitionParameter = path.scope.generateUidIdentifier("props");
|
|
6100
6113
|
return {
|
|
6101
6114
|
definitionParameter,
|
|
@@ -6188,7 +6201,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6188
6201
|
locals.push({
|
|
6189
6202
|
kind: "handler",
|
|
6190
6203
|
name: statement.id.name,
|
|
6191
|
-
value: types.toExpression(types.cloneNode(statement, true))
|
|
6204
|
+
value: types.toExpression(types.cloneNode(statement, true)),
|
|
6205
|
+
statesBefore: states.length
|
|
6192
6206
|
});
|
|
6193
6207
|
continue;
|
|
6194
6208
|
}
|
|
@@ -6200,9 +6214,6 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6200
6214
|
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
6215
|
return "only const [value, setValue] = useState(initial) state declarations are supported";
|
|
6202
6216
|
}
|
|
6203
|
-
if (locals.length > 0) {
|
|
6204
|
-
return "useState declarations must appear before derived local values and event handlers";
|
|
6205
|
-
}
|
|
6206
6217
|
states.push({
|
|
6207
6218
|
valueName: declaration.id.elements[0].name,
|
|
6208
6219
|
setterName: declaration.id.elements[1].name,
|
|
@@ -6221,13 +6232,15 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6221
6232
|
locals.push({
|
|
6222
6233
|
kind: "handler",
|
|
6223
6234
|
name: declaration.id.name,
|
|
6224
|
-
value: declaration.init
|
|
6235
|
+
value: declaration.init,
|
|
6236
|
+
statesBefore: states.length
|
|
6225
6237
|
});
|
|
6226
6238
|
} else {
|
|
6227
6239
|
locals.push({
|
|
6228
6240
|
kind: "derived",
|
|
6229
6241
|
name: declaration.id.name,
|
|
6230
|
-
value: declaration.init
|
|
6242
|
+
value: declaration.init,
|
|
6243
|
+
statesBefore: states.length
|
|
6231
6244
|
});
|
|
6232
6245
|
}
|
|
6233
6246
|
}
|
|
@@ -6246,6 +6259,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6246
6259
|
return "useState initializers cannot reference another local binding";
|
|
6247
6260
|
}
|
|
6248
6261
|
}
|
|
6262
|
+
for (const binding of locals) {
|
|
6263
|
+
if (binding.kind === "derived" && states.some(
|
|
6264
|
+
(state) => state.index >= binding.statesBefore && (referencesIdentifier(binding.value, state.valueName) || referencesIdentifier(binding.value, state.setterName))
|
|
6265
|
+
)) {
|
|
6266
|
+
return `derived local ${binding.name} reads a useState declared after it`;
|
|
6267
|
+
}
|
|
6268
|
+
}
|
|
6249
6269
|
const derivedByName = /* @__PURE__ */ new Map();
|
|
6250
6270
|
const handlersByName = /* @__PURE__ */ new Map();
|
|
6251
6271
|
for (const binding of locals) {
|