@farm.js/react 0.1.0-beta.39 → 0.1.0-beta.40
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/dist/compiled-root.cjs +17 -0
- package/dist/compiled-root.cjs.map +1 -0
- package/dist/compiled-root.d.mts +12 -0
- package/dist/compiled-root.d.ts +12 -0
- package/dist/compiled-root.mjs +14 -0
- package/dist/compiled-root.mjs.map +1 -0
- package/dist/compiler-runtime.cjs +434 -12
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +51 -2
- package/dist/compiler-runtime.d.ts +51 -2
- package/dist/compiler-runtime.mjs +434 -13
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/vite.cjs +488 -66
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.mts +8 -1
- package/dist/vite.d.ts +8 -1
- package/dist/vite.mjs +488 -67
- package/dist/vite.mjs.map +1 -1
- package/package.json +7 -2
package/dist/vite.cjs
CHANGED
|
@@ -10,7 +10,6 @@ var path = require('path');
|
|
|
10
10
|
var DELEGATABLE_KEYED_ROW_EVENTS = /* @__PURE__ */ new Set([
|
|
11
11
|
"onBeforeInput",
|
|
12
12
|
"onBlur",
|
|
13
|
-
"onChange",
|
|
14
13
|
"onClick",
|
|
15
14
|
"onCompositionEnd",
|
|
16
15
|
"onCompositionStart",
|
|
@@ -52,16 +51,17 @@ var DELEGATABLE_KEYED_ROW_EVENTS = /* @__PURE__ */ new Set([
|
|
|
52
51
|
"onTouchStart",
|
|
53
52
|
"onWheel"
|
|
54
53
|
]);
|
|
55
|
-
function canDelegateKeyedRowEvents(plan) {
|
|
54
|
+
function canDelegateKeyedRowEvents(plan, withoutReact = false) {
|
|
56
55
|
if (plan.events.length === 0 || plan.conditionals.length > 0) return false;
|
|
57
56
|
if (plan.source.openingElement.attributes.some(
|
|
58
57
|
(attribute) => core.types.isJSXAttribute(attribute) && core.types.isJSXIdentifier(attribute.name) && /^on[A-Z]/.test(attribute.name.name)
|
|
59
58
|
)) {
|
|
60
59
|
return false;
|
|
61
60
|
}
|
|
62
|
-
return plan.events.every(
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
return plan.events.every((event) => {
|
|
62
|
+
const name = event.name.replace(/Capture$/, "");
|
|
63
|
+
return DELEGATABLE_KEYED_ROW_EVENTS.has(name) || withoutReact && name === "onChange";
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
66
|
var COMPILER_RUNTIME_FEATURE_EXPORTS = {
|
|
67
67
|
conditional: "conditionalRuntimeFeature",
|
|
@@ -565,9 +565,14 @@ function validateDerivedExpression(expression, safeGlobals, additionalSafeCall)
|
|
|
565
565
|
AssignmentExpression: (path) => reject("assignments", path),
|
|
566
566
|
AwaitExpression: (path) => reject("await expressions", path),
|
|
567
567
|
CallExpression(path) {
|
|
568
|
-
if (
|
|
569
|
-
|
|
568
|
+
if (isSafeCompilerCall(path.node, safeGlobals) || additionalSafeCall?.(path.node)) return;
|
|
569
|
+
if (isCollectionPipelineLength(path)) {
|
|
570
|
+
const unsupported2 = validateCollectionPipeline(path.node, safeGlobals);
|
|
571
|
+
if (unsupported2) reject(unsupported2, path);
|
|
572
|
+
else path.skip();
|
|
573
|
+
return;
|
|
570
574
|
}
|
|
575
|
+
reject("function calls", path);
|
|
571
576
|
},
|
|
572
577
|
ClassExpression: (path) => reject("class expressions", path),
|
|
573
578
|
Function: (path) => reject("function expressions", path),
|
|
@@ -3031,6 +3036,173 @@ function validateCollectionCallback(callback, method, safeGlobals) {
|
|
|
3031
3036
|
const unsupported = validateDerivedExpression(value, safeGlobals);
|
|
3032
3037
|
return unsupported ? `${method} callbacks cannot use ${unsupported}` : void 0;
|
|
3033
3038
|
}
|
|
3039
|
+
function isPrimitiveLiteral(node) {
|
|
3040
|
+
return core.types.isStringLiteral(node) || core.types.isNumericLiteral(node) || core.types.isBooleanLiteral(node) || core.types.isNullLiteral(node);
|
|
3041
|
+
}
|
|
3042
|
+
function inlinableChild(name, programPath) {
|
|
3043
|
+
const binding = programPath.scope.getBinding(name);
|
|
3044
|
+
if (!binding?.constant || binding.kind !== "hoisted" && binding.kind !== "const") return;
|
|
3045
|
+
const referencedOnlyAsTag = binding.referencePaths.every(
|
|
3046
|
+
(reference) => reference.isJSXIdentifier() || reference.parentPath?.isExportSpecifier() || reference.parentPath?.isExportDefaultDeclaration()
|
|
3047
|
+
);
|
|
3048
|
+
if (!referencedOnlyAsTag) return;
|
|
3049
|
+
const functionPath = binding.path.isFunctionDeclaration() ? binding.path : binding.path.isVariableDeclarator() ? binding.path.get("init") : void 0;
|
|
3050
|
+
if (!functionPath || Array.isArray(functionPath) || !(functionPath.isFunctionDeclaration() || functionPath.isArrowFunctionExpression() || functionPath.isFunctionExpression())) {
|
|
3051
|
+
return;
|
|
3052
|
+
}
|
|
3053
|
+
const fn = functionPath.node;
|
|
3054
|
+
if (fn.async || fn.generator || fn.params.length > 1) return;
|
|
3055
|
+
const props = /* @__PURE__ */ new Map();
|
|
3056
|
+
const param = fn.params[0];
|
|
3057
|
+
if (param) {
|
|
3058
|
+
if (!core.types.isObjectPattern(param)) return;
|
|
3059
|
+
for (const property of param.properties) {
|
|
3060
|
+
if (!core.types.isObjectProperty(property) || property.computed || !core.types.isIdentifier(property.key) || !core.types.isIdentifier(property.value) || property.key.name === "children") {
|
|
3061
|
+
return;
|
|
3062
|
+
}
|
|
3063
|
+
props.set(property.key.name, property.value.name);
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
const body = fn.body;
|
|
3067
|
+
const returned = core.types.isJSXElement(body) ? body : core.types.isBlockStatement(body) && body.body.length === 1 && core.types.isReturnStatement(body.body[0]) && core.types.isJSXElement(body.body[0].argument) ? body.body[0].argument : void 0;
|
|
3068
|
+
if (!returned) return;
|
|
3069
|
+
let unsafe = false;
|
|
3070
|
+
const localNames = /* @__PURE__ */ new Set();
|
|
3071
|
+
const freeNames = /* @__PURE__ */ new Set();
|
|
3072
|
+
functionPath.traverse({
|
|
3073
|
+
CallExpression(path) {
|
|
3074
|
+
const callee = path.node.callee;
|
|
3075
|
+
const calleeName = core.types.isIdentifier(callee) ? callee.name : core.types.isMemberExpression(callee) && !callee.computed && core.types.isIdentifier(callee.property) ? callee.property.name : "";
|
|
3076
|
+
if (/^use([A-Z0-9]|$)/.test(calleeName)) unsafe = true;
|
|
3077
|
+
},
|
|
3078
|
+
ThisExpression() {
|
|
3079
|
+
unsafe = true;
|
|
3080
|
+
},
|
|
3081
|
+
Identifier(path) {
|
|
3082
|
+
if (path.node.name === "arguments") unsafe = true;
|
|
3083
|
+
},
|
|
3084
|
+
JSXIdentifier(path) {
|
|
3085
|
+
if (path.node.name === name) unsafe = true;
|
|
3086
|
+
},
|
|
3087
|
+
Scopable(path) {
|
|
3088
|
+
for (const local of Object.keys(path.scope.bindings)) localNames.add(local);
|
|
3089
|
+
},
|
|
3090
|
+
ReferencedIdentifier(path) {
|
|
3091
|
+
const reference = path.node.name;
|
|
3092
|
+
const owner = path.scope.getBinding(reference);
|
|
3093
|
+
if (!owner || owner.scope === programPath.scope) freeNames.add(reference);
|
|
3094
|
+
}
|
|
3095
|
+
});
|
|
3096
|
+
if (unsafe) return;
|
|
3097
|
+
for (const local of props.values()) localNames.delete(local);
|
|
3098
|
+
return { props, root: returned, scope: functionPath.scope, localNames, freeNames };
|
|
3099
|
+
}
|
|
3100
|
+
function isDuplicableProp(expression, safeGlobals) {
|
|
3101
|
+
return core.types.isArrowFunctionExpression(expression) || core.types.isFunctionExpression(expression) || validateDerivedExpression(expression, safeGlobals) === void 0;
|
|
3102
|
+
}
|
|
3103
|
+
function inlineStatelessChildren(component, programPath, safeGlobals) {
|
|
3104
|
+
let budget = 64;
|
|
3105
|
+
component.traverse({
|
|
3106
|
+
JSXElement(path) {
|
|
3107
|
+
const tag = path.node.openingElement.name;
|
|
3108
|
+
if (!core.types.isJSXIdentifier(tag) || !isComponentName(tag.name) || budget <= 0) return;
|
|
3109
|
+
if (path.scope.getBinding(tag.name) !== programPath.scope.getBinding(tag.name)) return;
|
|
3110
|
+
const child = inlinableChild(tag.name, programPath);
|
|
3111
|
+
if (!child || meaningfulJsxChildren(path.node).length > 0) return;
|
|
3112
|
+
const values = /* @__PURE__ */ new Map();
|
|
3113
|
+
for (const attribute of path.node.openingElement.attributes) {
|
|
3114
|
+
if (!core.types.isJSXAttribute(attribute) || !core.types.isJSXIdentifier(attribute.name)) return;
|
|
3115
|
+
const prop = attribute.name.name;
|
|
3116
|
+
if (prop === "key" || prop === "ref" || prop === "children") return;
|
|
3117
|
+
const value = attribute.value;
|
|
3118
|
+
const expression = value === null || value === void 0 ? core.types.booleanLiteral(true) : core.types.isStringLiteral(value) ? core.types.stringLiteral(value.value) : core.types.isJSXExpressionContainer(value) && core.types.isExpression(value.expression) ? value.expression : void 0;
|
|
3119
|
+
if (!expression) return;
|
|
3120
|
+
values.set(prop, expression);
|
|
3121
|
+
}
|
|
3122
|
+
for (const [prop, expression] of values) {
|
|
3123
|
+
if (!child.props.has(prop) && !isDuplicableProp(expression, safeGlobals)) return;
|
|
3124
|
+
}
|
|
3125
|
+
for (const name of child.freeNames) {
|
|
3126
|
+
if (child.props.has(name) || [...child.props.values()].includes(name)) continue;
|
|
3127
|
+
if (path.scope.getBinding(name) !== child.scope.getBinding(name)) return;
|
|
3128
|
+
}
|
|
3129
|
+
const root = core.types.cloneNode(child.root, true);
|
|
3130
|
+
const file = expressionFile(root);
|
|
3131
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3132
|
+
const localToProp = new Map([...child.props].map(([prop, local]) => [local, prop]));
|
|
3133
|
+
let rejected = false;
|
|
3134
|
+
core.traverse(file, {
|
|
3135
|
+
ReferencedIdentifier(reference) {
|
|
3136
|
+
const prop = localToProp.get(reference.node.name);
|
|
3137
|
+
if (!prop || reference.scope.hasBinding(reference.node.name, { noGlobals: true })) return;
|
|
3138
|
+
if (core.types.isJSXIdentifier(reference.node)) rejected = true;
|
|
3139
|
+
counts.set(prop, (counts.get(prop) ?? 0) + 1);
|
|
3140
|
+
}
|
|
3141
|
+
});
|
|
3142
|
+
for (const [prop, count] of counts) {
|
|
3143
|
+
const value = values.get(prop);
|
|
3144
|
+
if (!value) continue;
|
|
3145
|
+
if (count > 1 && !isDuplicableProp(value, safeGlobals)) rejected = true;
|
|
3146
|
+
core.traverse(expressionFile(core.types.cloneNode(value, true)), {
|
|
3147
|
+
ReferencedIdentifier(reference) {
|
|
3148
|
+
if (child.localNames.has(reference.node.name)) rejected = true;
|
|
3149
|
+
}
|
|
3150
|
+
});
|
|
3151
|
+
}
|
|
3152
|
+
if (rejected) return;
|
|
3153
|
+
core.traverse(file, {
|
|
3154
|
+
ReferencedIdentifier(reference) {
|
|
3155
|
+
const prop = localToProp.get(reference.node.name);
|
|
3156
|
+
if (!prop || reference.scope.hasBinding(reference.node.name, { noGlobals: true })) return;
|
|
3157
|
+
const value = values.get(prop);
|
|
3158
|
+
const replacement = value ? core.types.cloneNode(value, true) : core.types.unaryExpression("void", core.types.numericLiteral(0));
|
|
3159
|
+
reference.replaceWith(replacement);
|
|
3160
|
+
reference.skip();
|
|
3161
|
+
}
|
|
3162
|
+
});
|
|
3163
|
+
budget -= 1;
|
|
3164
|
+
path.replaceWith(file.program.body[0].expression);
|
|
3165
|
+
}
|
|
3166
|
+
});
|
|
3167
|
+
}
|
|
3168
|
+
function hoistConstantListCollections(component, programPath) {
|
|
3169
|
+
const hoisted = [];
|
|
3170
|
+
component.traverse({
|
|
3171
|
+
CallExpression(path) {
|
|
3172
|
+
if (!isMapCall(path.node) || !path.findParent((parent) => parent.isJSXExpressionContainer()))
|
|
3173
|
+
return;
|
|
3174
|
+
const calls = [path.node];
|
|
3175
|
+
let source = path.node.callee.object;
|
|
3176
|
+
while (collectionPipelineMethod(source)) {
|
|
3177
|
+
calls.push(source);
|
|
3178
|
+
source = source.callee.object;
|
|
3179
|
+
}
|
|
3180
|
+
if (!core.types.isArrayExpression(source) || !source.elements.every(isPrimitiveLiteral)) return;
|
|
3181
|
+
const callbacksReachOnlyItems = calls.every(
|
|
3182
|
+
(call) => call.arguments.every(
|
|
3183
|
+
(argument) => !core.types.isFunction(argument) || (core.types.isArrowFunctionExpression(argument) || core.types.isFunctionExpression(argument)) && argument.params.length <= 2
|
|
3184
|
+
) && call.arguments.every(
|
|
3185
|
+
(argument) => core.types.isFunction(argument) || isPrimitiveLiteral(argument)
|
|
3186
|
+
)
|
|
3187
|
+
);
|
|
3188
|
+
if (!callbacksReachOnlyItems) return;
|
|
3189
|
+
const identifier = programPath.scope.generateUidIdentifier("farmListItems");
|
|
3190
|
+
hoisted.push(
|
|
3191
|
+
core.types.variableDeclaration("const", [core.types.variableDeclarator(identifier, core.types.cloneNode(source))])
|
|
3192
|
+
);
|
|
3193
|
+
const owner = calls[calls.length - 1].callee;
|
|
3194
|
+
owner.object = core.types.cloneNode(identifier);
|
|
3195
|
+
}
|
|
3196
|
+
});
|
|
3197
|
+
if (hoisted.length === 0) return;
|
|
3198
|
+
const lastImport = programPath.get("body").filter((statement) => statement.isImportDeclaration()).at(-1);
|
|
3199
|
+
if (lastImport) lastImport.insertAfter(hoisted);
|
|
3200
|
+
else programPath.unshiftContainer("body", hoisted);
|
|
3201
|
+
}
|
|
3202
|
+
function isCollectionPipelineLength(path) {
|
|
3203
|
+
const parent = path.parent;
|
|
3204
|
+
return core.types.isMemberExpression(parent) && parent.object === path.node && !parent.computed && core.types.isIdentifier(parent.property, { name: "length" }) && collectionPipelineMethod(path.node) !== void 0;
|
|
3205
|
+
}
|
|
3034
3206
|
function validateCollectionPipeline(expression, safeGlobals) {
|
|
3035
3207
|
const method = collectionPipelineMethod(expression);
|
|
3036
3208
|
if (!method || !core.types.isCallExpression(expression)) {
|
|
@@ -3329,6 +3501,47 @@ function reactOwnedAttribute(name, attribute) {
|
|
|
3329
3501
|
if (name === "defaultValue" || name === "defaultChecked") return true;
|
|
3330
3502
|
return (name === "spellCheck" || name === "draggable" || name === "contentEditable") && !core.types.isStringLiteral(attribute.value);
|
|
3331
3503
|
}
|
|
3504
|
+
function keyedRowEventHandler(attribute) {
|
|
3505
|
+
if (!core.types.isJSXExpressionContainer(attribute.value) || !core.types.isArrowFunctionExpression(attribute.value.expression) && !core.types.isFunctionExpression(attribute.value.expression)) {
|
|
3506
|
+
return "interactive compiled keyed rows require inline synchronous event handlers";
|
|
3507
|
+
}
|
|
3508
|
+
const handler = attribute.value.expression;
|
|
3509
|
+
if (handler.async || handler.generator) {
|
|
3510
|
+
return "interactive compiled keyed row handlers must be synchronous";
|
|
3511
|
+
}
|
|
3512
|
+
if (containsDirectHookCall(handler)) {
|
|
3513
|
+
return "Hooks cannot be called inside compiled keyed row handlers";
|
|
3514
|
+
}
|
|
3515
|
+
const unsupported = validateKeyedRowEventHandler(handler);
|
|
3516
|
+
if (unsupported) return `interactive compiled keyed row handlers cannot use ${unsupported}`;
|
|
3517
|
+
return handler;
|
|
3518
|
+
}
|
|
3519
|
+
function staticKeyedRowEvents(row, compilerSetters) {
|
|
3520
|
+
const events = [];
|
|
3521
|
+
const visit = (element, path) => {
|
|
3522
|
+
for (const attribute of element.openingElement.attributes) {
|
|
3523
|
+
if (!core.types.isJSXAttribute(attribute)) continue;
|
|
3524
|
+
const name = jsxAttributeName(attribute);
|
|
3525
|
+
if (!name || !/^on[A-Z]/.test(name)) continue;
|
|
3526
|
+
const handler = keyedRowEventHandler(attribute);
|
|
3527
|
+
if (typeof handler === "string") return false;
|
|
3528
|
+
events.push({
|
|
3529
|
+
id: events.length,
|
|
3530
|
+
path: [...path],
|
|
3531
|
+
name,
|
|
3532
|
+
value: stabilizeDeferredEventCurrentTarget(handler, compilerSetters)
|
|
3533
|
+
});
|
|
3534
|
+
}
|
|
3535
|
+
let elementIndex = 0;
|
|
3536
|
+
for (const child of element.children) {
|
|
3537
|
+
if (!core.types.isJSXElement(child)) continue;
|
|
3538
|
+
if (!visit(child, [...path, elementIndex])) return false;
|
|
3539
|
+
elementIndex += 1;
|
|
3540
|
+
}
|
|
3541
|
+
return true;
|
|
3542
|
+
};
|
|
3543
|
+
return visit(row, []) ? events : void 0;
|
|
3544
|
+
}
|
|
3332
3545
|
function analyzeKeyedRowTree(row, renderCallback, safeGlobals, compilerSetters, keyedTargetReactiveByValue) {
|
|
3333
3546
|
if (renderCallback.async || renderCallback.generator || renderCallback.params.length < 1 || renderCallback.params.length > 2 || !core.types.isIdentifier(renderCallback.params[0]) || renderCallback.params[1] !== void 0 && !core.types.isIdentifier(renderCallback.params[1])) {
|
|
3334
3547
|
return {
|
|
@@ -3389,20 +3602,8 @@ function analyzeKeyedRowTree(row, renderCallback, safeGlobals, compilerSetters,
|
|
|
3389
3602
|
}
|
|
3390
3603
|
if (name === "key") continue;
|
|
3391
3604
|
if (/^on[A-Z]/.test(name)) {
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
}
|
|
3395
|
-
const handler = attribute.value.expression;
|
|
3396
|
-
if (handler.async || handler.generator) {
|
|
3397
|
-
return "interactive compiled keyed row handlers must be synchronous";
|
|
3398
|
-
}
|
|
3399
|
-
if (containsDirectHookCall(handler)) {
|
|
3400
|
-
return "Hooks cannot be called inside compiled keyed row handlers";
|
|
3401
|
-
}
|
|
3402
|
-
const unsupported2 = validateKeyedRowEventHandler(handler);
|
|
3403
|
-
if (unsupported2) {
|
|
3404
|
-
return `interactive compiled keyed row handlers cannot use ${unsupported2}`;
|
|
3405
|
-
}
|
|
3605
|
+
const handler = keyedRowEventHandler(attribute);
|
|
3606
|
+
if (typeof handler === "string") return handler;
|
|
3406
3607
|
events.push({
|
|
3407
3608
|
id: events.length,
|
|
3408
3609
|
path: [...path],
|
|
@@ -3691,7 +3892,7 @@ function analyzeKeyedRowsContainer(container, statesByValue, safeGlobals, listNa
|
|
|
3691
3892
|
bindings
|
|
3692
3893
|
};
|
|
3693
3894
|
}
|
|
3694
|
-
function analyzeKeyedRangesContainer(container, statesByValue, safeGlobals, listNames, allowSingleRange = false) {
|
|
3895
|
+
function analyzeKeyedRangesContainer(container, statesByValue, safeGlobals, listNames, allowSingleRange = false, delegateWithoutReact = false) {
|
|
3695
3896
|
if (container.openingElement.attributes.some(
|
|
3696
3897
|
(attribute) => core.types.isJSXSpreadAttribute(attribute) || core.types.isJSXAttribute(attribute) && core.types.isJSXIdentifier(attribute.name) && (attribute.name.name === "ref" || attribute.name.name === "dangerouslySetInnerHTML")
|
|
3697
3898
|
)) {
|
|
@@ -3706,7 +3907,13 @@ function analyzeKeyedRangesContainer(container, statesByValue, safeGlobals, list
|
|
|
3706
3907
|
for (const child of children) {
|
|
3707
3908
|
const range = analyzeKeyedRowChild(child, statesByValue, safeGlobals, listNames);
|
|
3708
3909
|
if (range) {
|
|
3709
|
-
if (range.
|
|
3910
|
+
if (range.conditionals.length > 0) return void 0;
|
|
3911
|
+
if (range.events.length > 0 && !canDelegateKeyedRowEvents(
|
|
3912
|
+
{ events: range.events, conditionals: [], source: container },
|
|
3913
|
+
delegateWithoutReact
|
|
3914
|
+
)) {
|
|
3915
|
+
return void 0;
|
|
3916
|
+
}
|
|
3710
3917
|
ranges.push({
|
|
3711
3918
|
before: staticBefore,
|
|
3712
3919
|
source: range.source,
|
|
@@ -3715,6 +3922,7 @@ function analyzeKeyedRangesContainer(container, statesByValue, safeGlobals, list
|
|
|
3715
3922
|
renderCallback: range.renderCallback,
|
|
3716
3923
|
row: range.row,
|
|
3717
3924
|
bindings: range.bindings,
|
|
3925
|
+
...range.events.length > 0 ? { events: range.events } : {},
|
|
3718
3926
|
syntax: range.syntax
|
|
3719
3927
|
});
|
|
3720
3928
|
for (const dependency of range.dependencies) dependencies.add(dependency);
|
|
@@ -3872,7 +4080,7 @@ function analyzeHostConditionalTree(branch, safeGlobals, allowStaticEvents = fal
|
|
|
3872
4080
|
const reason = visit(branch, []);
|
|
3873
4081
|
return reason ? { reason } : { bindings };
|
|
3874
4082
|
}
|
|
3875
|
-
function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames, parent, allocateId) {
|
|
4083
|
+
function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames, parent, allocateId, delegatedEvents = /* @__PURE__ */ new Set()) {
|
|
3876
4084
|
const bindings = [];
|
|
3877
4085
|
const plans = [];
|
|
3878
4086
|
const blocks = /* @__PURE__ */ new Map();
|
|
@@ -3903,6 +4111,7 @@ function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames,
|
|
|
3903
4111
|
return `recursive compiler-owned block ${name} requires React ownership`;
|
|
3904
4112
|
}
|
|
3905
4113
|
if (/^on[A-Z]/.test(name)) {
|
|
4114
|
+
if (delegatedEvents.has(attribute)) continue;
|
|
3906
4115
|
return "recursive compiler-owned block events require React ownership";
|
|
3907
4116
|
}
|
|
3908
4117
|
if (!core.types.isJSXExpressionContainer(attribute.value) || core.types.isJSXEmptyExpression(attribute.value.expression)) {
|
|
@@ -3961,7 +4170,8 @@ function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames,
|
|
|
3961
4170
|
safeGlobals,
|
|
3962
4171
|
listNames,
|
|
3963
4172
|
id,
|
|
3964
|
-
allocateId
|
|
4173
|
+
allocateId,
|
|
4174
|
+
delegatedEvents
|
|
3965
4175
|
);
|
|
3966
4176
|
if (mixed) {
|
|
3967
4177
|
plans.push(...mixed.nestedPlans);
|
|
@@ -4011,7 +4221,8 @@ function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames,
|
|
|
4011
4221
|
safeGlobals,
|
|
4012
4222
|
listNames,
|
|
4013
4223
|
owner,
|
|
4014
|
-
allocateId
|
|
4224
|
+
allocateId,
|
|
4225
|
+
delegatedEvents
|
|
4015
4226
|
);
|
|
4016
4227
|
if (nested.reason) return nested.reason;
|
|
4017
4228
|
plans.push(...nested.plans);
|
|
@@ -4163,7 +4374,8 @@ function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames,
|
|
|
4163
4374
|
safeGlobals,
|
|
4164
4375
|
listNames,
|
|
4165
4376
|
owner,
|
|
4166
|
-
allocateId
|
|
4377
|
+
allocateId,
|
|
4378
|
+
delegatedEvents
|
|
4167
4379
|
);
|
|
4168
4380
|
if (nested.reason) return nested.reason;
|
|
4169
4381
|
plans.push(...nested.plans);
|
|
@@ -4233,19 +4445,80 @@ function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames,
|
|
|
4233
4445
|
const reason = visit(branch, [], parent);
|
|
4234
4446
|
return { bindings, plans, blocks, reason };
|
|
4235
4447
|
}
|
|
4236
|
-
function
|
|
4237
|
-
|
|
4448
|
+
function jsxCanRenderElements(expression) {
|
|
4449
|
+
let found = false;
|
|
4450
|
+
core.traverse(expressionFile(cloneExpression(expression)), {
|
|
4451
|
+
JSXElement(path) {
|
|
4452
|
+
found = true;
|
|
4453
|
+
path.stop();
|
|
4454
|
+
},
|
|
4455
|
+
JSXFragment(path) {
|
|
4456
|
+
found = true;
|
|
4457
|
+
path.stop();
|
|
4458
|
+
}
|
|
4459
|
+
});
|
|
4460
|
+
return found;
|
|
4461
|
+
}
|
|
4462
|
+
function keyedRowEventPathIsStable(row, path) {
|
|
4463
|
+
let element = row;
|
|
4464
|
+
for (const index of path) {
|
|
4465
|
+
let seen = 0;
|
|
4466
|
+
let next;
|
|
4467
|
+
for (const child of element.children) {
|
|
4468
|
+
if (core.types.isJSXElement(child)) {
|
|
4469
|
+
if (!isHostElement(child)) return false;
|
|
4470
|
+
if (seen === index) {
|
|
4471
|
+
next = child;
|
|
4472
|
+
break;
|
|
4473
|
+
}
|
|
4474
|
+
seen += 1;
|
|
4475
|
+
continue;
|
|
4476
|
+
}
|
|
4477
|
+
if (core.types.isJSXFragment(child)) return false;
|
|
4478
|
+
if (core.types.isJSXExpressionContainer(child) && !core.types.isJSXEmptyExpression(child.expression) && jsxCanRenderElements(child.expression)) {
|
|
4479
|
+
return false;
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
if (!next) return false;
|
|
4483
|
+
element = next;
|
|
4484
|
+
}
|
|
4485
|
+
return true;
|
|
4486
|
+
}
|
|
4487
|
+
function analyzeCompilerOwnedKeyedRowHostBlocks(shape, container, statesByValue, safeGlobals, listNames, parent, allocateId, delegateWithoutReact = false) {
|
|
4488
|
+
const events = shape.rowReason ? staticKeyedRowEvents(
|
|
4489
|
+
shape.row,
|
|
4490
|
+
new Set([...statesByValue.values()].map((state) => state.setterName))
|
|
4491
|
+
) : shape.events;
|
|
4492
|
+
if (!events || events.length > 0 && (!canDelegateKeyedRowEvents(
|
|
4493
|
+
{ events, conditionals: [], source: container },
|
|
4494
|
+
delegateWithoutReact
|
|
4495
|
+
) || !events.every((event) => keyedRowEventPathIsStable(shape.row, event.path)))) {
|
|
4496
|
+
return void 0;
|
|
4497
|
+
}
|
|
4238
4498
|
const row = core.types.cloneNode(shape.row, true);
|
|
4239
4499
|
row.openingElement.attributes = row.openingElement.attributes.filter(
|
|
4240
4500
|
(attribute) => !core.types.isJSXAttribute(attribute) || jsxAttributeName(attribute) !== "key"
|
|
4241
4501
|
);
|
|
4502
|
+
const delegatedEvents = /* @__PURE__ */ new Set();
|
|
4503
|
+
for (const event of events) {
|
|
4504
|
+
let element = row;
|
|
4505
|
+
for (const index of event.path) {
|
|
4506
|
+
element = element.children.filter((child) => core.types.isJSXElement(child))[index];
|
|
4507
|
+
}
|
|
4508
|
+
for (const attribute of element.openingElement.attributes) {
|
|
4509
|
+
if (core.types.isJSXAttribute(attribute) && jsxAttributeName(attribute) === event.name) {
|
|
4510
|
+
delegatedEvents.add(attribute);
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
4513
|
+
}
|
|
4242
4514
|
const analysis = analyzeRecursiveHostTree(
|
|
4243
4515
|
row,
|
|
4244
4516
|
statesByValue,
|
|
4245
4517
|
safeGlobals,
|
|
4246
4518
|
listNames,
|
|
4247
4519
|
parent,
|
|
4248
|
-
allocateId
|
|
4520
|
+
allocateId,
|
|
4521
|
+
delegatedEvents
|
|
4249
4522
|
);
|
|
4250
4523
|
if (analysis.reason || analysis.plans.length === 0) {
|
|
4251
4524
|
return void 0;
|
|
@@ -4254,7 +4527,8 @@ function analyzeCompilerOwnedKeyedRowHostBlocks(shape, statesByValue, safeGlobal
|
|
|
4254
4527
|
row,
|
|
4255
4528
|
bindings: analysis.bindings,
|
|
4256
4529
|
descriptorBlocks: analysis.blocks,
|
|
4257
|
-
nestedPlans: analysis.plans
|
|
4530
|
+
nestedPlans: analysis.plans,
|
|
4531
|
+
events
|
|
4258
4532
|
};
|
|
4259
4533
|
}
|
|
4260
4534
|
function analyzeHostConditionalContainer(container, statesByValue, safeGlobals, listNames, parent, allocateId) {
|
|
@@ -4418,7 +4692,7 @@ function analyzeConditionalRangesContainer(container, statesByValue, safeGlobals
|
|
|
4418
4692
|
nestedPlans
|
|
4419
4693
|
};
|
|
4420
4694
|
}
|
|
4421
|
-
function analyzeMixedRangesContainer(container, statesByValue, safeGlobals, listNames, parent, allocateId) {
|
|
4695
|
+
function analyzeMixedRangesContainer(container, statesByValue, safeGlobals, listNames, parent, allocateId, delegatedEvents = /* @__PURE__ */ new Set()) {
|
|
4422
4696
|
const containerName = container.openingElement.name;
|
|
4423
4697
|
if (!core.types.isJSXIdentifier(containerName) || !/^[a-z]/.test(containerName.name) || isForeignContent(container) || container.openingElement.attributes.some(
|
|
4424
4698
|
(attribute) => core.types.isJSXSpreadAttribute(attribute) || core.types.isJSXAttribute(attribute) && core.types.isJSXIdentifier(attribute.name) && (attribute.name.name === "ref" || attribute.name.name === "dangerouslySetInnerHTML")
|
|
@@ -4533,7 +4807,8 @@ function analyzeMixedRangesContainer(container, statesByValue, safeGlobals, list
|
|
|
4533
4807
|
safeGlobals,
|
|
4534
4808
|
listNames,
|
|
4535
4809
|
parent,
|
|
4536
|
-
allocateId
|
|
4810
|
+
allocateId,
|
|
4811
|
+
delegatedEvents
|
|
4537
4812
|
);
|
|
4538
4813
|
if (staticAnalysis.reason) return void 0;
|
|
4539
4814
|
for (const binding of staticAnalysis.bindings) {
|
|
@@ -4798,7 +5073,7 @@ function uniqueLocalIdentifier(base, nodes) {
|
|
|
4798
5073
|
while (names.has(name)) name = `${base}${suffix++}`;
|
|
4799
5074
|
return core.types.identifier(name);
|
|
4800
5075
|
}
|
|
4801
|
-
function rewriteKeyedRowEventAttributes(row, events, eventFactory, item, index) {
|
|
5076
|
+
function rewriteKeyedRowEventAttributes(row, events, eventFactory, item, index, extraArguments = []) {
|
|
4802
5077
|
const eventByLocation = new Map(
|
|
4803
5078
|
events.map((event) => [`${event.path.join(".")}:${event.name}`, event])
|
|
4804
5079
|
);
|
|
@@ -4813,7 +5088,8 @@ function rewriteKeyedRowEventAttributes(row, events, eventFactory, item, index)
|
|
|
4813
5088
|
core.types.callExpression(core.types.cloneNode(eventFactory), [
|
|
4814
5089
|
core.types.cloneNode(item),
|
|
4815
5090
|
core.types.cloneNode(index),
|
|
4816
|
-
core.types.numericLiteral(event.id)
|
|
5091
|
+
core.types.numericLiteral(event.id),
|
|
5092
|
+
...extraArguments.map((argument) => core.types.cloneNode(argument))
|
|
4817
5093
|
])
|
|
4818
5094
|
);
|
|
4819
5095
|
}
|
|
@@ -5040,6 +5316,7 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
|
|
|
5040
5316
|
...plan.conditionals.map((conditional) => conditional.test)
|
|
5041
5317
|
]);
|
|
5042
5318
|
const delegatedEvents = canDelegateKeyedRowEvents(plan);
|
|
5319
|
+
const delegatedWithoutReact = !delegatedEvents && canDelegateKeyedRowEvents(plan, true);
|
|
5043
5320
|
const bindingTargets = keyedRowBindingTargets(plan);
|
|
5044
5321
|
const renderSource = keyedRowsRenderSource(plan, eventFactory, conditionalFactory);
|
|
5045
5322
|
const renderFactoryParameters = plan.conditionals.length > 0 ? [core.types.cloneNode(eventFactory), core.types.cloneNode(conditionalFactory)] : plan.events.length > 0 ? [core.types.cloneNode(eventFactory)] : [];
|
|
@@ -5136,9 +5413,11 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
|
|
|
5136
5413
|
)
|
|
5137
5414
|
)
|
|
5138
5415
|
),
|
|
5139
|
-
...delegatedEvents ? [
|
|
5416
|
+
...delegatedEvents || delegatedWithoutReact ? [
|
|
5140
5417
|
core.types.jsxAttribute(
|
|
5141
|
-
core.types.jsxIdentifier(
|
|
5418
|
+
core.types.jsxIdentifier(
|
|
5419
|
+
delegatedEvents ? "delegateEvents" : "delegateEventsWithoutReact"
|
|
5420
|
+
),
|
|
5142
5421
|
core.types.jsxExpressionContainer(core.types.booleanLiteral(true))
|
|
5143
5422
|
)
|
|
5144
5423
|
] : []
|
|
@@ -5199,15 +5478,66 @@ function keyedRangeObject(range, descriptorBlocks = /* @__PURE__ */ new Map()) {
|
|
|
5199
5478
|
core.types.arrayExpression(
|
|
5200
5479
|
range.bindings.map((binding) => keyedRowBindingObject(binding, parameters))
|
|
5201
5480
|
)
|
|
5202
|
-
)
|
|
5481
|
+
),
|
|
5482
|
+
...range.events?.length ? [
|
|
5483
|
+
core.types.objectProperty(
|
|
5484
|
+
core.types.identifier("events"),
|
|
5485
|
+
core.types.arrayExpression(range.events.map((event) => keyedRowEventObject(event, parameters)))
|
|
5486
|
+
)
|
|
5487
|
+
] : []
|
|
5203
5488
|
]);
|
|
5204
5489
|
}
|
|
5490
|
+
function rewriteKeyedRangeEvents(source, plan, eventFactory) {
|
|
5491
|
+
let rangeIndex = 0;
|
|
5492
|
+
for (const child of meaningfulJsxChildren(source)) {
|
|
5493
|
+
if (core.types.isJSXElement(child) && isHostElement(child)) continue;
|
|
5494
|
+
const range = plan.ranges[rangeIndex];
|
|
5495
|
+
const currentRange = rangeIndex;
|
|
5496
|
+
rangeIndex += 1;
|
|
5497
|
+
if (!range?.events?.length) continue;
|
|
5498
|
+
let callback;
|
|
5499
|
+
if (core.types.isJSXExpressionContainer(child) && !core.types.isJSXEmptyExpression(child.expression) && isMapCall(child.expression)) {
|
|
5500
|
+
const candidate = child.expression.arguments[0];
|
|
5501
|
+
if (core.types.isArrowFunctionExpression(candidate) || core.types.isFunctionExpression(candidate)) {
|
|
5502
|
+
callback = candidate;
|
|
5503
|
+
}
|
|
5504
|
+
} else if (core.types.isJSXElement(child)) {
|
|
5505
|
+
const renderChild = meaningfulJsxChildren(child)[0];
|
|
5506
|
+
if (core.types.isJSXExpressionContainer(renderChild) && (core.types.isArrowFunctionExpression(renderChild.expression) || core.types.isFunctionExpression(renderChild.expression))) {
|
|
5507
|
+
callback = renderChild.expression;
|
|
5508
|
+
}
|
|
5509
|
+
}
|
|
5510
|
+
const row = callback && returnedExpression(callback);
|
|
5511
|
+
const item = callback?.params[0];
|
|
5512
|
+
const index = callback?.params[1];
|
|
5513
|
+
if (!core.types.isJSXElement(row) || !core.types.isIdentifier(item)) {
|
|
5514
|
+
throw new Error("keyed range events must belong to an inline row callback");
|
|
5515
|
+
}
|
|
5516
|
+
rewriteKeyedRowEventAttributes(
|
|
5517
|
+
row,
|
|
5518
|
+
range.events,
|
|
5519
|
+
eventFactory,
|
|
5520
|
+
item,
|
|
5521
|
+
core.types.isIdentifier(index) ? index : core.types.numericLiteral(0),
|
|
5522
|
+
[core.types.numericLiteral(currentRange)]
|
|
5523
|
+
);
|
|
5524
|
+
}
|
|
5525
|
+
}
|
|
5205
5526
|
function keyedRangesBoundary(blockRuntime, plan) {
|
|
5206
5527
|
const name = core.types.jsxMemberExpression(
|
|
5207
5528
|
core.types.jsxIdentifier(blockRuntime.name),
|
|
5208
5529
|
core.types.jsxIdentifier("KeyedRanges")
|
|
5209
5530
|
);
|
|
5210
5531
|
const source = core.types.cloneNode(plan.source, true);
|
|
5532
|
+
const hasEvents = plan.ranges.some((range) => range.events?.length);
|
|
5533
|
+
const delegatedEvents = plan.ranges.every(
|
|
5534
|
+
(range) => !range.events?.length || canDelegateKeyedRowEvents({ events: range.events, conditionals: [], source: plan.source })
|
|
5535
|
+
);
|
|
5536
|
+
const eventFactory = uniqueLocalIdentifier("_farmRowEvent", [
|
|
5537
|
+
plan.source,
|
|
5538
|
+
...plan.ranges.flatMap((range) => (range.events || []).map((event) => event.value))
|
|
5539
|
+
]);
|
|
5540
|
+
if (hasEvents) rewriteKeyedRangeEvents(source, plan, eventFactory);
|
|
5211
5541
|
let rootRef;
|
|
5212
5542
|
source.openingElement.attributes = source.openingElement.attributes.filter((attribute) => {
|
|
5213
5543
|
if (!core.types.isJSXAttribute(attribute) || jsxAttributeName(attribute) !== "ref" || !core.types.isJSXExpressionContainer(attribute.value) || core.types.isJSXEmptyExpression(attribute.value.expression)) {
|
|
@@ -5223,8 +5553,16 @@ function keyedRangesBoundary(blockRuntime, plan) {
|
|
|
5223
5553
|
core.types.jsxAttribute(core.types.jsxIdentifier("id"), core.types.jsxExpressionContainer(core.types.numericLiteral(plan.id))),
|
|
5224
5554
|
core.types.jsxAttribute(
|
|
5225
5555
|
core.types.jsxIdentifier("render"),
|
|
5226
|
-
core.types.jsxExpressionContainer(
|
|
5556
|
+
core.types.jsxExpressionContainer(
|
|
5557
|
+
core.types.arrowFunctionExpression(hasEvents ? [core.types.cloneNode(eventFactory)] : [], source)
|
|
5558
|
+
)
|
|
5227
5559
|
),
|
|
5560
|
+
...hasEvents ? [
|
|
5561
|
+
core.types.jsxAttribute(
|
|
5562
|
+
core.types.jsxIdentifier(delegatedEvents ? "delegateEvents" : "delegateEventsWithoutReact"),
|
|
5563
|
+
core.types.jsxExpressionContainer(core.types.booleanLiteral(true))
|
|
5564
|
+
)
|
|
5565
|
+
] : [],
|
|
5228
5566
|
...rootRef ? [core.types.jsxAttribute(core.types.jsxIdentifier("rootRef"), core.types.jsxExpressionContainer(rootRef))] : [],
|
|
5229
5567
|
core.types.jsxAttribute(
|
|
5230
5568
|
core.types.jsxIdentifier("ranges"),
|
|
@@ -5514,7 +5852,7 @@ function componentIslandBoundary(blockRuntime, plan, source) {
|
|
|
5514
5852
|
true
|
|
5515
5853
|
);
|
|
5516
5854
|
}
|
|
5517
|
-
function analyzeComposableBlocks(root, statesByValue, safeGlobals, listNames, allowedComponentNames) {
|
|
5855
|
+
function analyzeComposableBlocks(root, statesByValue, safeGlobals, listNames, allowedComponentNames, delegateWithoutReact) {
|
|
5518
5856
|
const plans = [];
|
|
5519
5857
|
const componentElements = /* @__PURE__ */ new Set();
|
|
5520
5858
|
const conditionalExpressions = /* @__PURE__ */ new Set();
|
|
@@ -5648,7 +5986,14 @@ function analyzeComposableBlocks(root, statesByValue, safeGlobals, listNames, al
|
|
|
5648
5986
|
continue;
|
|
5649
5987
|
}
|
|
5650
5988
|
nextId = mixedRangeStart;
|
|
5651
|
-
const keyedRanges = insideConditional ? void 0 : analyzeKeyedRangesContainer(
|
|
5989
|
+
const keyedRanges = insideConditional ? void 0 : analyzeKeyedRangesContainer(
|
|
5990
|
+
child,
|
|
5991
|
+
statesByValue,
|
|
5992
|
+
safeGlobals,
|
|
5993
|
+
listNames,
|
|
5994
|
+
false,
|
|
5995
|
+
delegateWithoutReact
|
|
5996
|
+
);
|
|
5652
5997
|
if (keyedRanges) {
|
|
5653
5998
|
plans.push({
|
|
5654
5999
|
kind: "keyed-ranges",
|
|
@@ -5726,11 +6071,13 @@ function analyzeComposableBlocks(root, statesByValue, safeGlobals, listNames, al
|
|
|
5726
6071
|
const nestedStart = nextId;
|
|
5727
6072
|
const hostBlocks = analyzeCompilerOwnedKeyedRowHostBlocks(
|
|
5728
6073
|
keyedRows,
|
|
6074
|
+
child,
|
|
5729
6075
|
statesByValue,
|
|
5730
6076
|
safeGlobals,
|
|
5731
6077
|
listNames,
|
|
5732
6078
|
keyedRowsId,
|
|
5733
|
-
() => nextId
|
|
6079
|
+
() => nextId++,
|
|
6080
|
+
delegateWithoutReact
|
|
5734
6081
|
);
|
|
5735
6082
|
if (!hostBlocks) nextId = nestedStart;
|
|
5736
6083
|
if (keyedRows.rowReason && !hostBlocks) {
|
|
@@ -5753,7 +6100,7 @@ function analyzeComposableBlocks(root, statesByValue, safeGlobals, listNames, al
|
|
|
5753
6100
|
renderCallback: keyedRows.renderCallback,
|
|
5754
6101
|
row: hostBlocks?.row || keyedRows.row,
|
|
5755
6102
|
bindings: hostBlocks?.bindings || keyedRows.bindings,
|
|
5756
|
-
events: keyedRows.events,
|
|
6103
|
+
events: hostBlocks?.events || keyedRows.events,
|
|
5757
6104
|
conditionals: hostBlocks ? [] : keyedRows.conditionals,
|
|
5758
6105
|
descriptorBlocks: hostBlocks?.descriptorBlocks,
|
|
5759
6106
|
syntax: keyedRows.syntax
|
|
@@ -5899,7 +6246,14 @@ function analyzeComposableBlocks(root, statesByValue, safeGlobals, listNames, al
|
|
|
5899
6246
|
};
|
|
5900
6247
|
}
|
|
5901
6248
|
nextId = rootMixedRangeStart;
|
|
5902
|
-
const rootRanges = analyzeKeyedRangesContainer(
|
|
6249
|
+
const rootRanges = analyzeKeyedRangesContainer(
|
|
6250
|
+
root,
|
|
6251
|
+
statesByValue,
|
|
6252
|
+
safeGlobals,
|
|
6253
|
+
listNames,
|
|
6254
|
+
true,
|
|
6255
|
+
delegateWithoutReact
|
|
6256
|
+
);
|
|
5903
6257
|
if (rootRanges) {
|
|
5904
6258
|
plans.push({
|
|
5905
6259
|
kind: "keyed-ranges",
|
|
@@ -6407,7 +6761,7 @@ function wrapperElement(definitionIdentifier, props) {
|
|
|
6407
6761
|
const attributes = props ? [core.types.jsxSpreadAttribute(core.types.cloneNode(props))] : [];
|
|
6408
6762
|
return core.types.jsxElement(core.types.jsxOpeningElement(name, attributes, true), null, [], true);
|
|
6409
6763
|
}
|
|
6410
|
-
function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayMapPipelineIdentifier, keyedArrayMappedStructuralAppendIdentifier, keyedArrayStructuralAppendMapPipelineIdentifier, keyedArrayMappedStructuralPrependIdentifier, keyedArrayStructuralPrependMapPipelineIdentifier, keyedArrayQueuedMapPipelineIdentifier, keyedArrayRollingWindowMapPipelineIdentifier, keyedArrayMappedRollingWindowIdentifier, keyedArrayMapReorderIdentifier, keyedArrayMappedStructuralIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayBatchInsertIdentifier, keyedArrayWindowReplaceIdentifier, keyedArrayReorderIdentifier, keyedArrayStructuralReorderIdentifier, keyedArraySortIdentifier, keyedArrayStructuralSortIdentifier, keyedArrayRollingWindowIdentifier, keyedArraySliceIdentifier, keyedCollectionUpdateIdentifier, keyedCollectionMutationIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, optimizationCounts, compilerUsage, useStateNames, reactNames, listNames, moduleId, reactivity) {
|
|
6764
|
+
function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayMapPipelineIdentifier, keyedArrayMappedStructuralAppendIdentifier, keyedArrayStructuralAppendMapPipelineIdentifier, keyedArrayMappedStructuralPrependIdentifier, keyedArrayStructuralPrependMapPipelineIdentifier, keyedArrayQueuedMapPipelineIdentifier, keyedArrayRollingWindowMapPipelineIdentifier, keyedArrayMappedRollingWindowIdentifier, keyedArrayMapReorderIdentifier, keyedArrayMappedStructuralIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayBatchInsertIdentifier, keyedArrayWindowReplaceIdentifier, keyedArrayReorderIdentifier, keyedArrayStructuralReorderIdentifier, keyedArraySortIdentifier, keyedArrayStructuralSortIdentifier, keyedArrayRollingWindowIdentifier, keyedArraySliceIdentifier, keyedCollectionUpdateIdentifier, keyedCollectionMutationIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, optimizationCounts, compilerUsage, useStateNames, reactNames, listNames, moduleId, reactivity, delegateWithoutReact) {
|
|
6411
6765
|
const { path, name, statementPath } = candidate;
|
|
6412
6766
|
if (path.node.async || path.node.generator)
|
|
6413
6767
|
return "async and generator components are not supported";
|
|
@@ -6593,7 +6947,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6593
6947
|
reactiveByValue,
|
|
6594
6948
|
safeGlobals,
|
|
6595
6949
|
listNames,
|
|
6596
|
-
allowedComponentNames
|
|
6950
|
+
allowedComponentNames,
|
|
6951
|
+
delegateWithoutReact
|
|
6597
6952
|
);
|
|
6598
6953
|
let analysis = analyzeHostTree(
|
|
6599
6954
|
expandedReactiveRoot,
|
|
@@ -6613,7 +6968,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6613
6968
|
reactiveByValue,
|
|
6614
6969
|
safeGlobals,
|
|
6615
6970
|
listNames,
|
|
6616
|
-
allowedComponentNames
|
|
6971
|
+
allowedComponentNames,
|
|
6972
|
+
delegateWithoutReact
|
|
6617
6973
|
);
|
|
6618
6974
|
analysis = analyzeHostTree(
|
|
6619
6975
|
expandedReactiveRoot,
|
|
@@ -6646,7 +7002,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6646
7002
|
reactiveByValue,
|
|
6647
7003
|
safeGlobals,
|
|
6648
7004
|
listNames,
|
|
6649
|
-
allowedComponentNames
|
|
7005
|
+
allowedComponentNames,
|
|
7006
|
+
delegateWithoutReact
|
|
6650
7007
|
);
|
|
6651
7008
|
const hintedAnalysis = analyzeHostTree(
|
|
6652
7009
|
hintedRoot.root,
|
|
@@ -6687,7 +7044,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6687
7044
|
reactiveByValue,
|
|
6688
7045
|
safeGlobals,
|
|
6689
7046
|
listNames,
|
|
6690
|
-
allowedComponentNames
|
|
7047
|
+
allowedComponentNames,
|
|
7048
|
+
delegateWithoutReact
|
|
6691
7049
|
);
|
|
6692
7050
|
const hintedAnalysis = analyzeHostTree(
|
|
6693
7051
|
appendHintedRoot.root,
|
|
@@ -6729,7 +7087,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6729
7087
|
reactiveByValue,
|
|
6730
7088
|
safeGlobals,
|
|
6731
7089
|
listNames,
|
|
6732
|
-
allowedComponentNames
|
|
7090
|
+
allowedComponentNames,
|
|
7091
|
+
delegateWithoutReact
|
|
6733
7092
|
);
|
|
6734
7093
|
const hintedAnalysis = analyzeHostTree(
|
|
6735
7094
|
prependHintedRoot.root,
|
|
@@ -6765,7 +7124,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6765
7124
|
reactiveByValue,
|
|
6766
7125
|
safeGlobals,
|
|
6767
7126
|
listNames,
|
|
6768
|
-
allowedComponentNames
|
|
7127
|
+
allowedComponentNames,
|
|
7128
|
+
delegateWithoutReact
|
|
6769
7129
|
);
|
|
6770
7130
|
const hintedAnalysis = analyzeHostTree(
|
|
6771
7131
|
rollingWindowHintedRoot.root,
|
|
@@ -6804,7 +7164,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6804
7164
|
reactiveByValue,
|
|
6805
7165
|
safeGlobals,
|
|
6806
7166
|
listNames,
|
|
6807
|
-
allowedComponentNames
|
|
7167
|
+
allowedComponentNames,
|
|
7168
|
+
delegateWithoutReact
|
|
6808
7169
|
);
|
|
6809
7170
|
const hintedAnalysis = analyzeHostTree(
|
|
6810
7171
|
positionHintedRoot.root,
|
|
@@ -6859,7 +7220,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6859
7220
|
reactiveByValue,
|
|
6860
7221
|
safeGlobals,
|
|
6861
7222
|
listNames,
|
|
6862
|
-
allowedComponentNames
|
|
7223
|
+
allowedComponentNames,
|
|
7224
|
+
delegateWithoutReact
|
|
6863
7225
|
);
|
|
6864
7226
|
const hintedAnalysis = analyzeHostTree(
|
|
6865
7227
|
reorderPipelineHintedRoot.root,
|
|
@@ -6908,7 +7270,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6908
7270
|
reactiveByValue,
|
|
6909
7271
|
safeGlobals,
|
|
6910
7272
|
listNames,
|
|
6911
|
-
allowedComponentNames
|
|
7273
|
+
allowedComponentNames,
|
|
7274
|
+
delegateWithoutReact
|
|
6912
7275
|
);
|
|
6913
7276
|
const hintedAnalysis = analyzeHostTree(
|
|
6914
7277
|
reorderHintedRoot.root,
|
|
@@ -6946,7 +7309,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6946
7309
|
reactiveByValue,
|
|
6947
7310
|
safeGlobals,
|
|
6948
7311
|
listNames,
|
|
6949
|
-
allowedComponentNames
|
|
7312
|
+
allowedComponentNames,
|
|
7313
|
+
delegateWithoutReact
|
|
6950
7314
|
);
|
|
6951
7315
|
const hintedAnalysis = analyzeHostTree(
|
|
6952
7316
|
sortHintedRoot.root,
|
|
@@ -6984,7 +7348,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
6984
7348
|
reactiveByValue,
|
|
6985
7349
|
safeGlobals,
|
|
6986
7350
|
listNames,
|
|
6987
|
-
allowedComponentNames
|
|
7351
|
+
allowedComponentNames,
|
|
7352
|
+
delegateWithoutReact
|
|
6988
7353
|
);
|
|
6989
7354
|
const hintedAnalysis = analyzeHostTree(
|
|
6990
7355
|
sliceHintedRoot.root,
|
|
@@ -7022,7 +7387,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7022
7387
|
reactiveByValue,
|
|
7023
7388
|
safeGlobals,
|
|
7024
7389
|
listNames,
|
|
7025
|
-
allowedComponentNames
|
|
7390
|
+
allowedComponentNames,
|
|
7391
|
+
delegateWithoutReact
|
|
7026
7392
|
);
|
|
7027
7393
|
const hintedAnalysis = analyzeHostTree(
|
|
7028
7394
|
filterHintedRoot.root,
|
|
@@ -7062,7 +7428,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7062
7428
|
reactiveByValue,
|
|
7063
7429
|
safeGlobals,
|
|
7064
7430
|
listNames,
|
|
7065
|
-
allowedComponentNames
|
|
7431
|
+
allowedComponentNames,
|
|
7432
|
+
delegateWithoutReact
|
|
7066
7433
|
);
|
|
7067
7434
|
const hintedAnalysis = analyzeHostTree(
|
|
7068
7435
|
queuedMappedStructuralHintedRoot.root,
|
|
@@ -7109,7 +7476,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7109
7476
|
reactiveByValue,
|
|
7110
7477
|
safeGlobals,
|
|
7111
7478
|
listNames,
|
|
7112
|
-
allowedComponentNames
|
|
7479
|
+
allowedComponentNames,
|
|
7480
|
+
delegateWithoutReact
|
|
7113
7481
|
);
|
|
7114
7482
|
const hintedAnalysis = analyzeHostTree(
|
|
7115
7483
|
queuedStructuralMapHintedRoot.root,
|
|
@@ -7156,7 +7524,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7156
7524
|
reactiveByValue,
|
|
7157
7525
|
safeGlobals,
|
|
7158
7526
|
listNames,
|
|
7159
|
-
allowedComponentNames
|
|
7527
|
+
allowedComponentNames,
|
|
7528
|
+
delegateWithoutReact
|
|
7160
7529
|
);
|
|
7161
7530
|
const hintedAnalysis = analyzeHostTree(
|
|
7162
7531
|
queuedStructuralPrependMapHintedRoot.root,
|
|
@@ -7199,7 +7568,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7199
7568
|
reactiveByValue,
|
|
7200
7569
|
safeGlobals,
|
|
7201
7570
|
listNames,
|
|
7202
|
-
allowedComponentNames
|
|
7571
|
+
allowedComponentNames,
|
|
7572
|
+
delegateWithoutReact
|
|
7203
7573
|
);
|
|
7204
7574
|
const hintedAnalysis = analyzeHostTree(
|
|
7205
7575
|
queuedRollingWindowMapHintedRoot.root,
|
|
@@ -7260,7 +7630,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7260
7630
|
reactiveByValue,
|
|
7261
7631
|
safeGlobals,
|
|
7262
7632
|
listNames,
|
|
7263
|
-
allowedComponentNames
|
|
7633
|
+
allowedComponentNames,
|
|
7634
|
+
delegateWithoutReact
|
|
7264
7635
|
);
|
|
7265
7636
|
const hintedAnalysis = analyzeHostTree(
|
|
7266
7637
|
queuedReorderMapHintedRoot.root,
|
|
@@ -7303,7 +7674,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7303
7674
|
reactiveByValue,
|
|
7304
7675
|
safeGlobals,
|
|
7305
7676
|
listNames,
|
|
7306
|
-
allowedComponentNames
|
|
7677
|
+
allowedComponentNames,
|
|
7678
|
+
delegateWithoutReact
|
|
7307
7679
|
);
|
|
7308
7680
|
const hintedAnalysis = analyzeHostTree(
|
|
7309
7681
|
queuedStructuralReorderHintedRoot.root,
|
|
@@ -7359,7 +7731,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
|
|
|
7359
7731
|
reactiveByValue,
|
|
7360
7732
|
safeGlobals,
|
|
7361
7733
|
listNames,
|
|
7362
|
-
allowedComponentNames
|
|
7734
|
+
allowedComponentNames,
|
|
7735
|
+
delegateWithoutReact
|
|
7363
7736
|
);
|
|
7364
7737
|
const hintedAnalysis = analyzeHostTree(
|
|
7365
7738
|
keyedCollectionHintedRoot.root,
|
|
@@ -7725,6 +8098,16 @@ async function compileReactModule(code, id, options) {
|
|
|
7725
8098
|
const runtimeFeatureIdentifiers = /* @__PURE__ */ new Map();
|
|
7726
8099
|
const usedRuntimeFeatures = /* @__PURE__ */ new Set();
|
|
7727
8100
|
for (const candidate of candidates) {
|
|
8101
|
+
hoistConstantListCollections(candidate.path, programPath);
|
|
8102
|
+
inlineStatelessChildren(
|
|
8103
|
+
candidate.path,
|
|
8104
|
+
programPath,
|
|
8105
|
+
new Set(
|
|
8106
|
+
[...SAFE_GLOBAL_CALLS, "Math"].filter(
|
|
8107
|
+
(name) => !candidate.path.scope.getBinding(name)
|
|
8108
|
+
)
|
|
8109
|
+
)
|
|
8110
|
+
);
|
|
7728
8111
|
const reason = compileCandidate(
|
|
7729
8112
|
candidate,
|
|
7730
8113
|
createComponentIdentifier,
|
|
@@ -7761,7 +8144,8 @@ async function compileReactModule(code, id, options) {
|
|
|
7761
8144
|
reactNames,
|
|
7762
8145
|
listNames,
|
|
7763
8146
|
id,
|
|
7764
|
-
options.reactivity
|
|
8147
|
+
options.reactivity,
|
|
8148
|
+
options.compiledRoot !== false
|
|
7765
8149
|
);
|
|
7766
8150
|
if (reason) {
|
|
7767
8151
|
diagnostics.push({
|
|
@@ -8270,7 +8654,11 @@ function normalizeReactCompilerOptions(value) {
|
|
|
8270
8654
|
}
|
|
8271
8655
|
const reportFile = normalizeCompilerReportFile(options.reportFile);
|
|
8272
8656
|
const report = options.report === true || options.reportFile !== void 0;
|
|
8273
|
-
|
|
8657
|
+
if (options.compiledRoot !== void 0 && typeof options.compiledRoot !== "boolean") {
|
|
8658
|
+
throw new TypeError("The React compiler compiledRoot option must be a boolean.");
|
|
8659
|
+
}
|
|
8660
|
+
const compiledRoot = options.compiledRoot !== false;
|
|
8661
|
+
return { mode, directive, onUnsupported, reactivity, report, reportFile, compiledRoot };
|
|
8274
8662
|
}
|
|
8275
8663
|
|
|
8276
8664
|
// src/vite.ts
|
|
@@ -8284,6 +8672,24 @@ function readCompilerOptions(rendererOptions) {
|
|
|
8284
8672
|
}
|
|
8285
8673
|
return normalizeReactCompilerOptions(compiler);
|
|
8286
8674
|
}
|
|
8675
|
+
function rewriteCompiledRootImports(code, program) {
|
|
8676
|
+
const edits = [];
|
|
8677
|
+
for (const statement of program.body) {
|
|
8678
|
+
const node = statement;
|
|
8679
|
+
if (node.type !== "ImportDeclaration" || node.importKind === "type" || node.source?.value !== "react-dom/client" || !node.specifiers?.length || !node.specifiers.every(
|
|
8680
|
+
(specifier) => specifier.type === "ImportSpecifier" && (specifier.imported?.name ?? specifier.imported?.value) === "createRoot"
|
|
8681
|
+
)) {
|
|
8682
|
+
continue;
|
|
8683
|
+
}
|
|
8684
|
+
edits.push(node.source);
|
|
8685
|
+
}
|
|
8686
|
+
if (edits.length === 0) return null;
|
|
8687
|
+
let result = code;
|
|
8688
|
+
for (const literal of edits.sort((left, right) => right.start - left.start)) {
|
|
8689
|
+
result = `${result.slice(0, literal.start)}"@farm.js/react/compiled-root"${result.slice(literal.end)}`;
|
|
8690
|
+
}
|
|
8691
|
+
return result;
|
|
8692
|
+
}
|
|
8287
8693
|
function createFarmRendererPlugin(options = {}) {
|
|
8288
8694
|
const compilerOptions = readCompilerOptions(options.rendererOptions);
|
|
8289
8695
|
if (!compilerOptions) return [];
|
|
@@ -8339,10 +8745,26 @@ function createFarmRendererPlugin(options = {}) {
|
|
|
8339
8745
|
reportObservations.values()
|
|
8340
8746
|
);
|
|
8341
8747
|
}
|
|
8748
|
+
},
|
|
8749
|
+
{
|
|
8750
|
+
// Runs after TypeScript and JSX are compiled, so the module parses as JavaScript.
|
|
8751
|
+
name: "farm:react-compiled-root",
|
|
8752
|
+
transform(code, id, transformOptions) {
|
|
8753
|
+
if (compilerOptions.compiledRoot === false || options.ssr || transformOptions?.ssr) {
|
|
8754
|
+
return null;
|
|
8755
|
+
}
|
|
8756
|
+
if (!code.includes("react-dom/client")) return null;
|
|
8757
|
+
const cleanId = vite.normalizePath(id.split("?", 1)[0]);
|
|
8758
|
+
if (!/\.[cm]?[jt]sx?$/.test(cleanId) || cleanId.includes("/node_modules/") || projectRoot && !cleanId.startsWith(`${projectRoot}/`)) {
|
|
8759
|
+
return null;
|
|
8760
|
+
}
|
|
8761
|
+
return rewriteCompiledRootImports(code, this.parse(code));
|
|
8762
|
+
}
|
|
8342
8763
|
}
|
|
8343
8764
|
];
|
|
8344
8765
|
}
|
|
8345
8766
|
|
|
8346
8767
|
exports.createFarmRendererPlugin = createFarmRendererPlugin;
|
|
8768
|
+
exports.rewriteCompiledRootImports = rewriteCompiledRootImports;
|
|
8347
8769
|
//# sourceMappingURL=vite.cjs.map
|
|
8348
8770
|
//# sourceMappingURL=vite.cjs.map
|