@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.cjs
CHANGED
|
@@ -62,6 +62,40 @@ function canDelegateKeyedRowEvents(plan) {
|
|
|
62
62
|
(event) => DELEGATABLE_KEYED_ROW_EVENTS.has(event.name.replace(/Capture$/, ""))
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
|
+
var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
66
|
+
conditional: "conditionalRuntimeFeature",
|
|
67
|
+
"host-conditional": "hostConditionalRuntimeFeature",
|
|
68
|
+
"conditional-ranges": "conditionalRangesRuntimeFeature",
|
|
69
|
+
"keyed-list": "keyedListRuntimeFeature",
|
|
70
|
+
"keyed-rows": "keyedRowsRuntimeFeature",
|
|
71
|
+
"keyed-rows-conditional": "keyedRowsConditionalRuntimeFeature",
|
|
72
|
+
"keyed-rows-host": "keyedRowsHostRuntimeFeature",
|
|
73
|
+
"keyed-rows-complete": "keyedRowsCompleteRuntimeFeature",
|
|
74
|
+
"keyed-ranges": "keyedRangesRuntimeFeature",
|
|
75
|
+
"mixed-ranges": "mixedRangesRuntimeFeature",
|
|
76
|
+
component: "componentRuntimeFeature"
|
|
77
|
+
};
|
|
78
|
+
function runtimeFeaturesForPlans(plans) {
|
|
79
|
+
const features = /* @__PURE__ */ new Set();
|
|
80
|
+
let keyedRowsHaveConditionals = false;
|
|
81
|
+
let keyedRowsHaveHostBlocks = false;
|
|
82
|
+
for (const plan of plans) {
|
|
83
|
+
if (plan.kind === "keyed-rows") {
|
|
84
|
+
keyedRowsHaveConditionals || (keyedRowsHaveConditionals = plan.conditionals.length > 0);
|
|
85
|
+
keyedRowsHaveHostBlocks || (keyedRowsHaveHostBlocks = Boolean(plan.descriptorBlocks?.size));
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (plan.kind in COMPILER_RUNTIME_FEATURE_EXPORTS) {
|
|
89
|
+
features.add(plan.kind);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (plans.some((plan) => plan.kind === "keyed-rows")) {
|
|
93
|
+
features.add(
|
|
94
|
+
keyedRowsHaveConditionals && keyedRowsHaveHostBlocks ? "keyed-rows-complete" : keyedRowsHaveConditionals ? "keyed-rows-conditional" : keyedRowsHaveHostBlocks ? "keyed-rows-host" : "keyed-rows"
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return [...features].sort();
|
|
98
|
+
}
|
|
65
99
|
var SAFE_GLOBAL_CALLS = /* @__PURE__ */ new Set(["Boolean", "Number", "String"]);
|
|
66
100
|
var SAFE_MATH_CALLS = /* @__PURE__ */ new Set(["abs", "ceil", "floor", "max", "min", "round", "sign", "trunc"]);
|
|
67
101
|
function isComponentName(name) {
|
|
@@ -3402,7 +3436,7 @@ function wrapperElement(definitionIdentifier, props) {
|
|
|
3402
3436
|
const attributes = props ? [core.types.jsxSpreadAttribute(core.types.cloneNode(props))] : [];
|
|
3403
3437
|
return core.types.jsxElement(core.types.jsxOpeningElement(name, attributes, true), null, [], true);
|
|
3404
3438
|
}
|
|
3405
|
-
function compileCandidate(candidate, createComponentIdentifier, useStateNames, reactNames, listNames, moduleId, reactivity) {
|
|
3439
|
+
function compileCandidate(candidate, createComponentIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, useStateNames, reactNames, listNames, moduleId, reactivity) {
|
|
3406
3440
|
const { path, name, statementPath } = candidate;
|
|
3407
3441
|
if (path.node.async || path.node.generator)
|
|
3408
3442
|
return "async and generator components are not supported";
|
|
@@ -3603,6 +3637,7 @@ function compileCandidate(candidate, createComponentIdentifier, useStateNames, r
|
|
|
3603
3637
|
if (blockAnalysis.reason) return blockAnalysis.reason;
|
|
3604
3638
|
if (analysis.reason) return analysis.reason;
|
|
3605
3639
|
const blockPlans = blockAnalysis.plans || [];
|
|
3640
|
+
const runtimeFeatures = runtimeFeaturesForPlans(blockPlans);
|
|
3606
3641
|
markShortCircuitBindings(analysis.bindings || []);
|
|
3607
3642
|
assignStableBindingTargets(analysis.bindings || []);
|
|
3608
3643
|
const stateParameter = path.scope.generateUidIdentifier("farmState");
|
|
@@ -3705,7 +3740,10 @@ function compileCandidate(candidate, createComponentIdentifier, useStateNames, r
|
|
|
3705
3740
|
)
|
|
3706
3741
|
)
|
|
3707
3742
|
)
|
|
3708
|
-
])
|
|
3743
|
+
]),
|
|
3744
|
+
core.types.arrayExpression(
|
|
3745
|
+
runtimeFeatures.map((feature) => core.types.cloneNode(runtimeFeatureIdentifiers.get(feature)))
|
|
3746
|
+
)
|
|
3709
3747
|
]);
|
|
3710
3748
|
path.get("body").replaceWith(
|
|
3711
3749
|
core.types.blockStatement([
|
|
@@ -3715,6 +3753,7 @@ function compileCandidate(candidate, createComponentIdentifier, useStateNames, r
|
|
|
3715
3753
|
statementPath.insertAfter(
|
|
3716
3754
|
core.types.variableDeclaration("const", [core.types.variableDeclarator(definitionIdentifier, definition)])
|
|
3717
3755
|
);
|
|
3756
|
+
for (const feature of runtimeFeatures) usedRuntimeFeatures.add(feature);
|
|
3718
3757
|
return void 0;
|
|
3719
3758
|
}
|
|
3720
3759
|
function collectCandidates(programPath) {
|
|
@@ -3782,6 +3821,13 @@ async function compileReactModule(code, id, options) {
|
|
|
3782
3821
|
}
|
|
3783
3822
|
const candidates = collectCandidates(programPath);
|
|
3784
3823
|
const createComponentIdentifier = programPath.scope.generateUidIdentifier("createCompiledComponent");
|
|
3824
|
+
const runtimeFeatureIdentifiers = new Map(
|
|
3825
|
+
Object.entries(COMPILER_RUNTIME_FEATURE_EXPORTS).map(([feature, exportName]) => [
|
|
3826
|
+
feature,
|
|
3827
|
+
programPath.scope.generateUidIdentifier(exportName)
|
|
3828
|
+
])
|
|
3829
|
+
);
|
|
3830
|
+
const usedRuntimeFeatures = /* @__PURE__ */ new Set();
|
|
3785
3831
|
for (const candidate of candidates) {
|
|
3786
3832
|
const functionDirectives = new Set(
|
|
3787
3833
|
core.types.isBlockStatement(candidate.path.node.body) ? directiveValues(candidate.path.node.body) : []
|
|
@@ -3792,6 +3838,8 @@ async function compileReactModule(code, id, options) {
|
|
|
3792
3838
|
const reason = compileCandidate(
|
|
3793
3839
|
candidate,
|
|
3794
3840
|
createComponentIdentifier,
|
|
3841
|
+
runtimeFeatureIdentifiers,
|
|
3842
|
+
usedRuntimeFeatures,
|
|
3795
3843
|
useStateNames,
|
|
3796
3844
|
reactNames,
|
|
3797
3845
|
listNames,
|
|
@@ -3815,7 +3863,13 @@ async function compileReactModule(code, id, options) {
|
|
|
3815
3863
|
[
|
|
3816
3864
|
core.types.importSpecifier(
|
|
3817
3865
|
createComponentIdentifier,
|
|
3818
|
-
core.types.identifier("
|
|
3866
|
+
core.types.identifier("createCompiledComponentWithFeatures")
|
|
3867
|
+
),
|
|
3868
|
+
...[...usedRuntimeFeatures].sort().map(
|
|
3869
|
+
(feature) => core.types.importSpecifier(
|
|
3870
|
+
core.types.cloneNode(runtimeFeatureIdentifiers.get(feature)),
|
|
3871
|
+
core.types.identifier(COMPILER_RUNTIME_FEATURE_EXPORTS[feature])
|
|
3872
|
+
)
|
|
3819
3873
|
)
|
|
3820
3874
|
],
|
|
3821
3875
|
core.types.stringLiteral("@farm.js/react/compiler-runtime")
|