@farm.js/react 0.1.0-beta.34 → 0.1.0-beta.36
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 +16 -0
- package/dist/compiler-runtime.cjs +28 -17
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +8 -1
- package/dist/compiler-runtime.d.ts +8 -1
- package/dist/compiler-runtime.mjs +28 -18
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/vite.cjs +80 -8
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +80 -8
- package/dist/vite.mjs.map +1 -1
- package/package.json +2 -2
package/dist/vite.mjs
CHANGED
|
@@ -3286,6 +3286,45 @@ function stabilizeDeferredEventCurrentTargets(root, compilerSetters) {
|
|
|
3286
3286
|
const expression = file.program.body[0].expression;
|
|
3287
3287
|
return types.isJSXElement(expression) ? expression : types.cloneNode(root, true);
|
|
3288
3288
|
}
|
|
3289
|
+
var FOREIGN_ELEMENT_NAMES = new Set(
|
|
3290
|
+
[
|
|
3291
|
+
"animate animateMotion animateTransform circle clipPath defs desc ellipse",
|
|
3292
|
+
"feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix",
|
|
3293
|
+
"feDiffuseLighting feDisplacementMap feDistantLight feDropShadow feFlood",
|
|
3294
|
+
"feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode",
|
|
3295
|
+
"feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile",
|
|
3296
|
+
"feTurbulence filter foreignObject g image line linearGradient marker mask",
|
|
3297
|
+
"metadata mpath path pattern polygon polyline radialGradient rect set stop svg",
|
|
3298
|
+
"switch symbol text textPath tspan use view",
|
|
3299
|
+
"math maction menclose merror mfrac mi mmultiscripts mn mo mover mpadded",
|
|
3300
|
+
"mphantom mprescripts mroot mrow ms mspace msqrt mstyle msub msubsup msup",
|
|
3301
|
+
"mtable mtd mtext mtr munder munderover semantics annotation"
|
|
3302
|
+
].join(" ").split(" ")
|
|
3303
|
+
);
|
|
3304
|
+
function markForeignContent(programPath) {
|
|
3305
|
+
let depth = 0;
|
|
3306
|
+
programPath.traverse({
|
|
3307
|
+
JSXElement: {
|
|
3308
|
+
enter(path) {
|
|
3309
|
+
if (depth > 0) path.node.extra = { ...path.node.extra, farmForeignContent: true };
|
|
3310
|
+
const name = path.node.openingElement.name;
|
|
3311
|
+
if (types.isJSXIdentifier(name) && (name.name === "svg" || name.name === "math")) depth++;
|
|
3312
|
+
},
|
|
3313
|
+
exit(path) {
|
|
3314
|
+
const name = path.node.openingElement.name;
|
|
3315
|
+
if (types.isJSXIdentifier(name) && (name.name === "svg" || name.name === "math")) depth--;
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3320
|
+
function isForeignContent(element) {
|
|
3321
|
+
const name = element.openingElement.name;
|
|
3322
|
+
return element.extra?.farmForeignContent === true || types.isJSXIdentifier(name) && FOREIGN_ELEMENT_NAMES.has(name.name);
|
|
3323
|
+
}
|
|
3324
|
+
function reactOwnedAttribute(name, attribute) {
|
|
3325
|
+
if (name === "defaultValue" || name === "defaultChecked") return true;
|
|
3326
|
+
return (name === "spellCheck" || name === "draggable") && !types.isStringLiteral(attribute.value);
|
|
3327
|
+
}
|
|
3289
3328
|
function analyzeKeyedRowTree(row, renderCallback, safeGlobals, compilerSetters, keyedTargetReactiveByValue) {
|
|
3290
3329
|
if (renderCallback.async || renderCallback.generator || renderCallback.params.length < 1 || renderCallback.params.length > 2 || !types.isIdentifier(renderCallback.params[0]) || renderCallback.params[1] !== void 0 && !types.isIdentifier(renderCallback.params[1])) {
|
|
3291
3330
|
return {
|
|
@@ -3305,7 +3344,7 @@ function analyzeKeyedRowTree(row, renderCallback, safeGlobals, compilerSetters,
|
|
|
3305
3344
|
if (!types.isJSXIdentifier(tag) || !/^[a-z]/.test(tag.name)) {
|
|
3306
3345
|
return "compiled keyed rows support host elements only";
|
|
3307
3346
|
}
|
|
3308
|
-
if (
|
|
3347
|
+
if (isForeignContent(element)) return "compiled keyed rows do not support SVG yet";
|
|
3309
3348
|
const attributeNames = new Set(
|
|
3310
3349
|
element.openingElement.attributes.filter((attribute) => types.isJSXAttribute(attribute)).map(jsxAttributeName).filter((name) => name !== void 0)
|
|
3311
3350
|
);
|
|
@@ -3335,7 +3374,7 @@ function analyzeKeyedRowTree(row, renderCallback, safeGlobals, compilerSetters,
|
|
|
3335
3374
|
}
|
|
3336
3375
|
const name = jsxAttributeName(attribute);
|
|
3337
3376
|
if (!name) return "compiled keyed rows do not support namespaced JSX attributes";
|
|
3338
|
-
if (name === "ref" || name === "dangerouslySetInnerHTML") {
|
|
3377
|
+
if (name === "ref" || name === "dangerouslySetInnerHTML" || reactOwnedAttribute(name, attribute)) {
|
|
3339
3378
|
return `compiled keyed row ${name} requires React ownership`;
|
|
3340
3379
|
}
|
|
3341
3380
|
if (name === "key") continue;
|
|
@@ -3703,7 +3742,7 @@ function analyzeHostConditionalTree(branch, safeGlobals, allowStaticEvents = fal
|
|
|
3703
3742
|
if (!types.isJSXIdentifier(tag) || !/^[a-z]/.test(tag.name)) {
|
|
3704
3743
|
return "compiler-owned conditionals support host elements only";
|
|
3705
3744
|
}
|
|
3706
|
-
if (
|
|
3745
|
+
if (isForeignContent(element)) return "compiler-owned conditionals do not support SVG yet";
|
|
3707
3746
|
for (const attribute of element.openingElement.attributes) {
|
|
3708
3747
|
if (types.isJSXSpreadAttribute(attribute)) {
|
|
3709
3748
|
if (statefulOnly && !needsStaticBinding(attribute.argument)) continue;
|
|
@@ -3711,6 +3750,9 @@ function analyzeHostConditionalTree(branch, safeGlobals, allowStaticEvents = fal
|
|
|
3711
3750
|
}
|
|
3712
3751
|
const name = jsxAttributeName(attribute);
|
|
3713
3752
|
if (!name) return "compiler-owned conditionals do not support namespaced JSX attributes";
|
|
3753
|
+
if (reactOwnedAttribute(name, attribute)) {
|
|
3754
|
+
return `compiler-owned conditional ${name} requires React ownership`;
|
|
3755
|
+
}
|
|
3714
3756
|
if (name === "ref" || name === "dangerouslySetInnerHTML" || name === "key") {
|
|
3715
3757
|
if (statefulOnly && (!types.isJSXExpressionContainer(attribute.value) || types.isJSXEmptyExpression(attribute.value.expression) || !needsStaticBinding(attribute.value.expression))) {
|
|
3716
3758
|
continue;
|
|
@@ -3823,13 +3865,18 @@ function analyzeRecursiveHostTree(branch, statesByValue, safeGlobals, listNames,
|
|
|
3823
3865
|
if (!types.isJSXIdentifier(tag) || !/^[a-z]/.test(tag.name)) {
|
|
3824
3866
|
return "recursive compiler-owned blocks support host elements only";
|
|
3825
3867
|
}
|
|
3826
|
-
if (
|
|
3868
|
+
if (isForeignContent(element)) {
|
|
3869
|
+
return "recursive compiler-owned blocks do not support SVG yet";
|
|
3870
|
+
}
|
|
3827
3871
|
for (const attribute of element.openingElement.attributes) {
|
|
3828
3872
|
if (types.isJSXSpreadAttribute(attribute)) {
|
|
3829
3873
|
return "recursive compiler-owned blocks do not support JSX attribute spreads";
|
|
3830
3874
|
}
|
|
3831
3875
|
const name = jsxAttributeName(attribute);
|
|
3832
3876
|
if (!name) return "recursive compiler-owned blocks do not support namespaced attributes";
|
|
3877
|
+
if (reactOwnedAttribute(name, attribute)) {
|
|
3878
|
+
return `recursive compiler-owned block ${name} requires React ownership`;
|
|
3879
|
+
}
|
|
3833
3880
|
if (name === "ref" || name === "dangerouslySetInnerHTML" || name === "key") {
|
|
3834
3881
|
return `recursive compiler-owned block ${name} requires React ownership`;
|
|
3835
3882
|
}
|
|
@@ -4190,7 +4237,7 @@ function analyzeCompilerOwnedKeyedRowHostBlocks(shape, statesByValue, safeGlobal
|
|
|
4190
4237
|
}
|
|
4191
4238
|
function analyzeHostConditionalContainer(container, statesByValue, safeGlobals, listNames, parent, allocateId) {
|
|
4192
4239
|
const containerName = container.openingElement.name;
|
|
4193
|
-
if (!types.isJSXIdentifier(containerName) || !/^[a-z]/.test(containerName.name) ||
|
|
4240
|
+
if (!types.isJSXIdentifier(containerName) || !/^[a-z]/.test(containerName.name) || isForeignContent(container)) {
|
|
4194
4241
|
return void 0;
|
|
4195
4242
|
}
|
|
4196
4243
|
if (container.openingElement.attributes.some(
|
|
@@ -4255,7 +4302,7 @@ function analyzeHostConditionalContainer(container, statesByValue, safeGlobals,
|
|
|
4255
4302
|
}
|
|
4256
4303
|
function analyzeConditionalRangesContainer(container, statesByValue, safeGlobals, allowSingleRange, listNames, parent, allocateId) {
|
|
4257
4304
|
const containerName = container.openingElement.name;
|
|
4258
|
-
if (!types.isJSXIdentifier(containerName) || !/^[a-z]/.test(containerName.name) ||
|
|
4305
|
+
if (!types.isJSXIdentifier(containerName) || !/^[a-z]/.test(containerName.name) || isForeignContent(container) || container.openingElement.attributes.some(
|
|
4259
4306
|
(attribute) => types.isJSXSpreadAttribute(attribute) || types.isJSXAttribute(attribute) && types.isJSXIdentifier(attribute.name) && (attribute.name.name === "ref" || attribute.name.name === "dangerouslySetInnerHTML")
|
|
4260
4307
|
)) {
|
|
4261
4308
|
return void 0;
|
|
@@ -4351,7 +4398,7 @@ function analyzeConditionalRangesContainer(container, statesByValue, safeGlobals
|
|
|
4351
4398
|
}
|
|
4352
4399
|
function analyzeMixedRangesContainer(container, statesByValue, safeGlobals, listNames, parent, allocateId) {
|
|
4353
4400
|
const containerName = container.openingElement.name;
|
|
4354
|
-
if (!types.isJSXIdentifier(containerName) || !/^[a-z]/.test(containerName.name) ||
|
|
4401
|
+
if (!types.isJSXIdentifier(containerName) || !/^[a-z]/.test(containerName.name) || isForeignContent(container) || container.openingElement.attributes.some(
|
|
4355
4402
|
(attribute) => types.isJSXSpreadAttribute(attribute) || types.isJSXAttribute(attribute) && types.isJSXIdentifier(attribute.name) && (attribute.name.name === "ref" || attribute.name.name === "dangerouslySetInnerHTML")
|
|
4356
4403
|
)) {
|
|
4357
4404
|
return void 0;
|
|
@@ -7536,6 +7583,7 @@ async function compileReactModule(code, id, options) {
|
|
|
7536
7583
|
visitor: {
|
|
7537
7584
|
Program(programPath) {
|
|
7538
7585
|
const moduleDirectives = new Set(directiveValues(programPath.node));
|
|
7586
|
+
markForeignContent(programPath);
|
|
7539
7587
|
const useStateNames = /* @__PURE__ */ new Set();
|
|
7540
7588
|
const reactNames = /* @__PURE__ */ new Set();
|
|
7541
7589
|
const listNames = /* @__PURE__ */ new Set();
|
|
@@ -7560,6 +7608,10 @@ async function compileReactModule(code, id, options) {
|
|
|
7560
7608
|
}
|
|
7561
7609
|
const candidates = collectCandidates(programPath);
|
|
7562
7610
|
const createComponentIdentifier = programPath.scope.generateUidIdentifier("createCompiledComponent");
|
|
7611
|
+
const createRefreshComponentIdentifier = programPath.scope.generateUidIdentifier("createRefreshComponent");
|
|
7612
|
+
const createProductionComponentIdentifier = programPath.scope.generateUidIdentifier(
|
|
7613
|
+
"createProductionComponent"
|
|
7614
|
+
);
|
|
7563
7615
|
const keyedMapUpdateIdentifier = programPath.scope.generateUidIdentifier(
|
|
7564
7616
|
"createCompilerKeyedMapUpdate"
|
|
7565
7617
|
);
|
|
@@ -7704,14 +7756,34 @@ async function compileReactModule(code, id, options) {
|
|
|
7704
7756
|
const hasKeyedArrayStructuralPrependHints = optimizationCounts.keyedArrayPrependHints > 0 && (optimizationCounts.keyedArrayFilterHints > 0 || optimizationCounts.keyedArraySliceHints > 0);
|
|
7705
7757
|
const hasUnmappedKeyedArrayPrependHints = optimizationCounts.keyedArrayPrependHints > compilerUsage.keyedArrayMappedStructuralPrependHints;
|
|
7706
7758
|
if (compiled.length > 0) {
|
|
7759
|
+
programPath.unshiftContainer(
|
|
7760
|
+
"body",
|
|
7761
|
+
types.variableDeclaration("const", [
|
|
7762
|
+
types.variableDeclarator(
|
|
7763
|
+
types.cloneNode(createComponentIdentifier),
|
|
7764
|
+
types.conditionalExpression(
|
|
7765
|
+
types.memberExpression(
|
|
7766
|
+
types.metaProperty(types.identifier("import"), types.identifier("meta")),
|
|
7767
|
+
types.identifier("hot")
|
|
7768
|
+
),
|
|
7769
|
+
types.cloneNode(createRefreshComponentIdentifier),
|
|
7770
|
+
types.cloneNode(createProductionComponentIdentifier)
|
|
7771
|
+
)
|
|
7772
|
+
)
|
|
7773
|
+
])
|
|
7774
|
+
);
|
|
7707
7775
|
programPath.unshiftContainer(
|
|
7708
7776
|
"body",
|
|
7709
7777
|
types.importDeclaration(
|
|
7710
7778
|
[
|
|
7711
7779
|
types.importSpecifier(
|
|
7712
|
-
|
|
7780
|
+
createRefreshComponentIdentifier,
|
|
7713
7781
|
types.identifier("createCompiledComponentWithFeatures")
|
|
7714
7782
|
),
|
|
7783
|
+
types.importSpecifier(
|
|
7784
|
+
createProductionComponentIdentifier,
|
|
7785
|
+
types.identifier("createCompiledComponentWithoutRefresh")
|
|
7786
|
+
),
|
|
7715
7787
|
...optimizationCounts.keyedMapUpdateHints > compilerUsage.keyedArrayMapUpdateHints ? [
|
|
7716
7788
|
types.importSpecifier(
|
|
7717
7789
|
keyedMapUpdateIdentifier,
|