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