@farm.js/react 0.1.0-beta.35 → 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.mjs CHANGED
@@ -3286,7 +3286,6 @@ 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 foreignContentElements = /* @__PURE__ */ new WeakSet();
3290
3289
  var FOREIGN_ELEMENT_NAMES = new Set(
3291
3290
  [
3292
3291
  "animate animateMotion animateTransform circle clipPath defs desc ellipse",
@@ -3303,21 +3302,24 @@ var FOREIGN_ELEMENT_NAMES = new Set(
3303
3302
  ].join(" ").split(" ")
3304
3303
  );
3305
3304
  function markForeignContent(programPath) {
3305
+ let depth = 0;
3306
3306
  programPath.traverse({
3307
- JSXElement(path) {
3308
- const name = path.node.openingElement.name;
3309
- if (!types.isJSXIdentifier(name) || name.name !== "svg" && name.name !== "math") return;
3310
- path.traverse({
3311
- JSXElement(inner) {
3312
- foreignContentElements.add(inner.node);
3313
- }
3314
- });
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
+ }
3315
3317
  }
3316
3318
  });
3317
3319
  }
3318
3320
  function isForeignContent(element) {
3319
3321
  const name = element.openingElement.name;
3320
- return foreignContentElements.has(element) || types.isJSXIdentifier(name) && FOREIGN_ELEMENT_NAMES.has(name.name);
3322
+ return element.extra?.farmForeignContent === true || types.isJSXIdentifier(name) && FOREIGN_ELEMENT_NAMES.has(name.name);
3321
3323
  }
3322
3324
  function reactOwnedAttribute(name, attribute) {
3323
3325
  if (name === "defaultValue" || name === "defaultChecked") return true;
@@ -7606,6 +7608,10 @@ async function compileReactModule(code, id, options) {
7606
7608
  }
7607
7609
  const candidates = collectCandidates(programPath);
7608
7610
  const createComponentIdentifier = programPath.scope.generateUidIdentifier("createCompiledComponent");
7611
+ const createRefreshComponentIdentifier = programPath.scope.generateUidIdentifier("createRefreshComponent");
7612
+ const createProductionComponentIdentifier = programPath.scope.generateUidIdentifier(
7613
+ "createProductionComponent"
7614
+ );
7609
7615
  const keyedMapUpdateIdentifier = programPath.scope.generateUidIdentifier(
7610
7616
  "createCompilerKeyedMapUpdate"
7611
7617
  );
@@ -7750,14 +7756,34 @@ async function compileReactModule(code, id, options) {
7750
7756
  const hasKeyedArrayStructuralPrependHints = optimizationCounts.keyedArrayPrependHints > 0 && (optimizationCounts.keyedArrayFilterHints > 0 || optimizationCounts.keyedArraySliceHints > 0);
7751
7757
  const hasUnmappedKeyedArrayPrependHints = optimizationCounts.keyedArrayPrependHints > compilerUsage.keyedArrayMappedStructuralPrependHints;
7752
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
+ );
7753
7775
  programPath.unshiftContainer(
7754
7776
  "body",
7755
7777
  types.importDeclaration(
7756
7778
  [
7757
7779
  types.importSpecifier(
7758
- createComponentIdentifier,
7780
+ createRefreshComponentIdentifier,
7759
7781
  types.identifier("createCompiledComponentWithFeatures")
7760
7782
  ),
7783
+ types.importSpecifier(
7784
+ createProductionComponentIdentifier,
7785
+ types.identifier("createCompiledComponentWithoutRefresh")
7786
+ ),
7761
7787
  ...optimizationCounts.keyedMapUpdateHints > compilerUsage.keyedArrayMapUpdateHints ? [
7762
7788
  types.importSpecifier(
7763
7789
  keyedMapUpdateIdentifier,