@farm.js/react 0.1.0-beta.4 → 0.1.0-beta.5
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 +13 -0
- package/dist/compiler-runtime.cjs +144 -49
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +31 -4
- package/dist/compiler-runtime.d.ts +31 -4
- package/dist/compiler-runtime.mjs +133 -50
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/vite.cjs +57 -3
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +57 -3
- package/dist/vite.mjs.map +1 -1
- package/package.json +5 -3
package/dist/vite.mjs
CHANGED
|
@@ -60,6 +60,40 @@ function canDelegateKeyedRowEvents(plan) {
|
|
|
60
60
|
(event) => DELEGATABLE_KEYED_ROW_EVENTS.has(event.name.replace(/Capture$/, ""))
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
|
+
var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
64
|
+
conditional: "conditionalRuntimeFeature",
|
|
65
|
+
"host-conditional": "hostConditionalRuntimeFeature",
|
|
66
|
+
"conditional-ranges": "conditionalRangesRuntimeFeature",
|
|
67
|
+
"keyed-list": "keyedListRuntimeFeature",
|
|
68
|
+
"keyed-rows": "keyedRowsRuntimeFeature",
|
|
69
|
+
"keyed-rows-conditional": "keyedRowsConditionalRuntimeFeature",
|
|
70
|
+
"keyed-rows-host": "keyedRowsHostRuntimeFeature",
|
|
71
|
+
"keyed-rows-complete": "keyedRowsCompleteRuntimeFeature",
|
|
72
|
+
"keyed-ranges": "keyedRangesRuntimeFeature",
|
|
73
|
+
"mixed-ranges": "mixedRangesRuntimeFeature",
|
|
74
|
+
component: "componentRuntimeFeature"
|
|
75
|
+
};
|
|
76
|
+
function runtimeFeaturesForPlans(plans) {
|
|
77
|
+
const features = /* @__PURE__ */ new Set();
|
|
78
|
+
let keyedRowsHaveConditionals = false;
|
|
79
|
+
let keyedRowsHaveHostBlocks = false;
|
|
80
|
+
for (const plan of plans) {
|
|
81
|
+
if (plan.kind === "keyed-rows") {
|
|
82
|
+
keyedRowsHaveConditionals || (keyedRowsHaveConditionals = plan.conditionals.length > 0);
|
|
83
|
+
keyedRowsHaveHostBlocks || (keyedRowsHaveHostBlocks = Boolean(plan.descriptorBlocks?.size));
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (plan.kind in COMPILER_RUNTIME_FEATURE_EXPORTS) {
|
|
87
|
+
features.add(plan.kind);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (plans.some((plan) => plan.kind === "keyed-rows")) {
|
|
91
|
+
features.add(
|
|
92
|
+
keyedRowsHaveConditionals && keyedRowsHaveHostBlocks ? "keyed-rows-complete" : keyedRowsHaveConditionals ? "keyed-rows-conditional" : keyedRowsHaveHostBlocks ? "keyed-rows-host" : "keyed-rows"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return [...features].sort();
|
|
96
|
+
}
|
|
63
97
|
var SAFE_GLOBAL_CALLS = /* @__PURE__ */ new Set(["Boolean", "Number", "String"]);
|
|
64
98
|
var SAFE_MATH_CALLS = /* @__PURE__ */ new Set(["abs", "ceil", "floor", "max", "min", "round", "sign", "trunc"]);
|
|
65
99
|
function isComponentName(name) {
|
|
@@ -3400,7 +3434,7 @@ function wrapperElement(definitionIdentifier, props) {
|
|
|
3400
3434
|
const attributes = props ? [types.jsxSpreadAttribute(types.cloneNode(props))] : [];
|
|
3401
3435
|
return types.jsxElement(types.jsxOpeningElement(name, attributes, true), null, [], true);
|
|
3402
3436
|
}
|
|
3403
|
-
function compileCandidate(candidate, createComponentIdentifier, useStateNames, reactNames, listNames, moduleId, reactivity) {
|
|
3437
|
+
function compileCandidate(candidate, createComponentIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, useStateNames, reactNames, listNames, moduleId, reactivity) {
|
|
3404
3438
|
const { path, name, statementPath } = candidate;
|
|
3405
3439
|
if (path.node.async || path.node.generator)
|
|
3406
3440
|
return "async and generator components are not supported";
|
|
@@ -3601,6 +3635,7 @@ function compileCandidate(candidate, createComponentIdentifier, useStateNames, r
|
|
|
3601
3635
|
if (blockAnalysis.reason) return blockAnalysis.reason;
|
|
3602
3636
|
if (analysis.reason) return analysis.reason;
|
|
3603
3637
|
const blockPlans = blockAnalysis.plans || [];
|
|
3638
|
+
const runtimeFeatures = runtimeFeaturesForPlans(blockPlans);
|
|
3604
3639
|
markShortCircuitBindings(analysis.bindings || []);
|
|
3605
3640
|
assignStableBindingTargets(analysis.bindings || []);
|
|
3606
3641
|
const stateParameter = path.scope.generateUidIdentifier("farmState");
|
|
@@ -3703,7 +3738,10 @@ function compileCandidate(candidate, createComponentIdentifier, useStateNames, r
|
|
|
3703
3738
|
)
|
|
3704
3739
|
)
|
|
3705
3740
|
)
|
|
3706
|
-
])
|
|
3741
|
+
]),
|
|
3742
|
+
types.arrayExpression(
|
|
3743
|
+
runtimeFeatures.map((feature) => types.cloneNode(runtimeFeatureIdentifiers.get(feature)))
|
|
3744
|
+
)
|
|
3707
3745
|
]);
|
|
3708
3746
|
path.get("body").replaceWith(
|
|
3709
3747
|
types.blockStatement([
|
|
@@ -3713,6 +3751,7 @@ function compileCandidate(candidate, createComponentIdentifier, useStateNames, r
|
|
|
3713
3751
|
statementPath.insertAfter(
|
|
3714
3752
|
types.variableDeclaration("const", [types.variableDeclarator(definitionIdentifier, definition)])
|
|
3715
3753
|
);
|
|
3754
|
+
for (const feature of runtimeFeatures) usedRuntimeFeatures.add(feature);
|
|
3716
3755
|
return void 0;
|
|
3717
3756
|
}
|
|
3718
3757
|
function collectCandidates(programPath) {
|
|
@@ -3780,6 +3819,13 @@ async function compileReactModule(code, id, options) {
|
|
|
3780
3819
|
}
|
|
3781
3820
|
const candidates = collectCandidates(programPath);
|
|
3782
3821
|
const createComponentIdentifier = programPath.scope.generateUidIdentifier("createCompiledComponent");
|
|
3822
|
+
const runtimeFeatureIdentifiers = new Map(
|
|
3823
|
+
Object.entries(COMPILER_RUNTIME_FEATURE_EXPORTS).map(([feature, exportName]) => [
|
|
3824
|
+
feature,
|
|
3825
|
+
programPath.scope.generateUidIdentifier(exportName)
|
|
3826
|
+
])
|
|
3827
|
+
);
|
|
3828
|
+
const usedRuntimeFeatures = /* @__PURE__ */ new Set();
|
|
3783
3829
|
for (const candidate of candidates) {
|
|
3784
3830
|
const functionDirectives = new Set(
|
|
3785
3831
|
types.isBlockStatement(candidate.path.node.body) ? directiveValues(candidate.path.node.body) : []
|
|
@@ -3790,6 +3836,8 @@ async function compileReactModule(code, id, options) {
|
|
|
3790
3836
|
const reason = compileCandidate(
|
|
3791
3837
|
candidate,
|
|
3792
3838
|
createComponentIdentifier,
|
|
3839
|
+
runtimeFeatureIdentifiers,
|
|
3840
|
+
usedRuntimeFeatures,
|
|
3793
3841
|
useStateNames,
|
|
3794
3842
|
reactNames,
|
|
3795
3843
|
listNames,
|
|
@@ -3813,7 +3861,13 @@ async function compileReactModule(code, id, options) {
|
|
|
3813
3861
|
[
|
|
3814
3862
|
types.importSpecifier(
|
|
3815
3863
|
createComponentIdentifier,
|
|
3816
|
-
types.identifier("
|
|
3864
|
+
types.identifier("createCompiledComponentWithFeatures")
|
|
3865
|
+
),
|
|
3866
|
+
...[...usedRuntimeFeatures].sort().map(
|
|
3867
|
+
(feature) => types.importSpecifier(
|
|
3868
|
+
types.cloneNode(runtimeFeatureIdentifiers.get(feature)),
|
|
3869
|
+
types.identifier(COMPILER_RUNTIME_FEATURE_EXPORTS[feature])
|
|
3870
|
+
)
|
|
3817
3871
|
)
|
|
3818
3872
|
],
|
|
3819
3873
|
types.stringLiteral("@farm.js/react/compiler-runtime")
|