@farm.js/react 0.1.0-beta.21 → 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 +26 -11
- package/dist/compiler-runtime.cjs +285 -231
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +5 -0
- package/dist/compiler-runtime.d.ts +5 -0
- package/dist/compiler-runtime.mjs +285 -231
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/index.cjs +25 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +25 -2
- package/dist/index.mjs.map +1 -1
- package/dist/list.cjs +6 -0
- package/dist/list.cjs.map +1 -1
- package/dist/list.mjs +6 -0
- package/dist/list.mjs.map +1 -1
- package/dist/vite.cjs +88 -33
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +88 -33
- package/dist/vite.mjs.map +1 -1
- package/package.json +3 -3
package/dist/vite.mjs
CHANGED
|
@@ -4785,6 +4785,19 @@ function keyedRowConditionalObject(conditional, parameters) {
|
|
|
4785
4785
|
}
|
|
4786
4786
|
return types.objectExpression(properties);
|
|
4787
4787
|
}
|
|
4788
|
+
var UNCLONEABLE_KEYED_ROW_TAGS = /* @__PURE__ */ new Set(["input", "option", "select", "textarea"]);
|
|
4789
|
+
function canCloneKeyedRows(plan) {
|
|
4790
|
+
if (plan.descriptorBlocks?.size || plan.conditionals.length > 0) return false;
|
|
4791
|
+
if (plan.bindings.some((binding) => binding.kind === "style")) return false;
|
|
4792
|
+
const cloneable = (element) => {
|
|
4793
|
+
const tag = element.openingElement.name;
|
|
4794
|
+
if (!types.isJSXIdentifier(tag) || tag.name.includes("-") || UNCLONEABLE_KEYED_ROW_TAGS.has(tag.name)) {
|
|
4795
|
+
return false;
|
|
4796
|
+
}
|
|
4797
|
+
return element.children.every((child) => !types.isJSXElement(child) || cloneable(child));
|
|
4798
|
+
};
|
|
4799
|
+
return cloneable(plan.row);
|
|
4800
|
+
}
|
|
4788
4801
|
function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFilterHintedStateIndices, keyedArrayPrependHintedStateIndices, keyedArrayPositionHintedStateIndices, keyedArrayReorderHintedStateIndices) {
|
|
4789
4802
|
const name = types.jsxMemberExpression(
|
|
4790
4803
|
types.jsxIdentifier(blockRuntime.name),
|
|
@@ -4921,6 +4934,12 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
|
|
|
4921
4934
|
types.jsxIdentifier("hostBlocks"),
|
|
4922
4935
|
types.jsxExpressionContainer(types.booleanLiteral(true))
|
|
4923
4936
|
)
|
|
4937
|
+
] : [],
|
|
4938
|
+
...canCloneKeyedRows(plan) ? [
|
|
4939
|
+
types.jsxAttribute(
|
|
4940
|
+
types.jsxIdentifier("cloneRows"),
|
|
4941
|
+
types.jsxExpressionContainer(types.booleanLiteral(true))
|
|
4942
|
+
)
|
|
4924
4943
|
] : []
|
|
4925
4944
|
],
|
|
4926
4945
|
true
|
|
@@ -6053,30 +6072,43 @@ function analyzePropsParameter(path) {
|
|
|
6053
6072
|
};
|
|
6054
6073
|
}
|
|
6055
6074
|
if (!types.isObjectPattern(parameter)) {
|
|
6056
|
-
return "components must use zero parameters, one props identifier, or
|
|
6075
|
+
return "components must use zero parameters, one props identifier, or object props destructuring";
|
|
6057
6076
|
}
|
|
6058
6077
|
const localNames = /* @__PURE__ */ new Set();
|
|
6059
|
-
|
|
6060
|
-
if (
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
if (types.isIdentifier(property.value)) {
|
|
6068
|
-
local = property.value;
|
|
6069
|
-
} else if (types.isAssignmentPattern(property.value) && types.isIdentifier(property.value.left)) {
|
|
6070
|
-
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;
|
|
6071
6086
|
}
|
|
6072
|
-
if (
|
|
6073
|
-
|
|
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;
|
|
6074
6095
|
}
|
|
6075
|
-
if (
|
|
6076
|
-
|
|
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;
|
|
6077
6107
|
}
|
|
6078
|
-
|
|
6079
|
-
}
|
|
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;
|
|
6080
6112
|
const definitionParameter = path.scope.generateUidIdentifier("props");
|
|
6081
6113
|
return {
|
|
6082
6114
|
definitionParameter,
|
|
@@ -6169,7 +6201,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6169
6201
|
locals.push({
|
|
6170
6202
|
kind: "handler",
|
|
6171
6203
|
name: statement.id.name,
|
|
6172
|
-
value: types.toExpression(types.cloneNode(statement, true))
|
|
6204
|
+
value: types.toExpression(types.cloneNode(statement, true)),
|
|
6205
|
+
statesBefore: states.length
|
|
6173
6206
|
});
|
|
6174
6207
|
continue;
|
|
6175
6208
|
}
|
|
@@ -6181,9 +6214,6 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6181
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])) {
|
|
6182
6215
|
return "only const [value, setValue] = useState(initial) state declarations are supported";
|
|
6183
6216
|
}
|
|
6184
|
-
if (locals.length > 0) {
|
|
6185
|
-
return "useState declarations must appear before derived local values and event handlers";
|
|
6186
|
-
}
|
|
6187
6217
|
states.push({
|
|
6188
6218
|
valueName: declaration.id.elements[0].name,
|
|
6189
6219
|
setterName: declaration.id.elements[1].name,
|
|
@@ -6202,13 +6232,15 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6202
6232
|
locals.push({
|
|
6203
6233
|
kind: "handler",
|
|
6204
6234
|
name: declaration.id.name,
|
|
6205
|
-
value: declaration.init
|
|
6235
|
+
value: declaration.init,
|
|
6236
|
+
statesBefore: states.length
|
|
6206
6237
|
});
|
|
6207
6238
|
} else {
|
|
6208
6239
|
locals.push({
|
|
6209
6240
|
kind: "derived",
|
|
6210
6241
|
name: declaration.id.name,
|
|
6211
|
-
value: declaration.init
|
|
6242
|
+
value: declaration.init,
|
|
6243
|
+
statesBefore: states.length
|
|
6212
6244
|
});
|
|
6213
6245
|
}
|
|
6214
6246
|
}
|
|
@@ -6227,6 +6259,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6227
6259
|
return "useState initializers cannot reference another local binding";
|
|
6228
6260
|
}
|
|
6229
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
|
+
}
|
|
6230
6269
|
const derivedByName = /* @__PURE__ */ new Map();
|
|
6231
6270
|
const handlersByName = /* @__PURE__ */ new Map();
|
|
6232
6271
|
for (const binding of locals) {
|
|
@@ -7702,6 +7741,29 @@ async function compileReactModule(code, id, options) {
|
|
|
7702
7741
|
optimizations: optimizationCounts
|
|
7703
7742
|
};
|
|
7704
7743
|
}
|
|
7744
|
+
|
|
7745
|
+
// src/compiler-options.ts
|
|
7746
|
+
var warnedExperimentalCompiler = false;
|
|
7747
|
+
function resolveCompilerOption(options = {}, warnDeprecated = false) {
|
|
7748
|
+
const experimental = options.experimental;
|
|
7749
|
+
const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
|
|
7750
|
+
if (legacy !== void 0 && options.compiler !== void 0) {
|
|
7751
|
+
throw new TypeError(
|
|
7752
|
+
"Configure the React compiler with `compiler` only; remove `experimental.compiler`."
|
|
7753
|
+
);
|
|
7754
|
+
}
|
|
7755
|
+
const compiler = legacy === void 0 ? options.compiler : legacy;
|
|
7756
|
+
if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
|
|
7757
|
+
throw new TypeError("React compiler must be a boolean or compiler options object.");
|
|
7758
|
+
}
|
|
7759
|
+
if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
|
|
7760
|
+
warnedExperimentalCompiler = true;
|
|
7761
|
+
console.warn(
|
|
7762
|
+
"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
|
|
7763
|
+
);
|
|
7764
|
+
}
|
|
7765
|
+
return compiler;
|
|
7766
|
+
}
|
|
7705
7767
|
function projectRelativeId(projectRoot, id) {
|
|
7706
7768
|
return relative(projectRoot, id).replace(/\\/g, "/");
|
|
7707
7769
|
}
|
|
@@ -7871,16 +7933,9 @@ function normalizeReactCompilerOptions(value) {
|
|
|
7871
7933
|
|
|
7872
7934
|
// src/vite.ts
|
|
7873
7935
|
function readCompilerOptions(rendererOptions) {
|
|
7874
|
-
const
|
|
7875
|
-
if (!experimental || typeof experimental !== "object") return false;
|
|
7876
|
-
const compiler = experimental.compiler;
|
|
7936
|
+
const compiler = resolveCompilerOption(rendererOptions);
|
|
7877
7937
|
if (!compiler) return false;
|
|
7878
7938
|
if (compiler === true) return normalizeReactCompilerOptions(true);
|
|
7879
|
-
if (typeof compiler !== "object") {
|
|
7880
|
-
throw new TypeError(
|
|
7881
|
-
"React experimental.compiler must be a boolean or compiler options object."
|
|
7882
|
-
);
|
|
7883
|
-
}
|
|
7884
7939
|
const normalized = compiler;
|
|
7885
7940
|
if ((normalized.mode === "infer" || normalized.mode === "annotation") && typeof normalized.directive === "string" && (normalized.reactivity === "static" || normalized.reactivity === "hybrid") && (normalized.onUnsupported === "fallback" || normalized.onUnsupported === "warn" || normalized.onUnsupported === "error")) {
|
|
7886
7941
|
return normalized;
|