@barefootjs/vite 0.33.1 → 0.33.2

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.
Files changed (2) hide show
  1. package/dist/index.js +117 -39
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -10598,6 +10598,31 @@ function unwrapHoistedFragment(node) {
10598
10598
  return node;
10599
10599
  return { ...only, needsScope: true };
10600
10600
  }
10601
+ function markDataKeyCarrier(children) {
10602
+ for (let i = 0;i < children.length; i++) {
10603
+ const marked = markCarrierIn(children[i]);
10604
+ if (!marked)
10605
+ continue;
10606
+ const out = children.slice();
10607
+ out[i] = marked;
10608
+ return out;
10609
+ }
10610
+ return children;
10611
+ }
10612
+ function markCarrierIn(node) {
10613
+ if (node.type === "element") {
10614
+ return { ...node, carriesDataKey: true };
10615
+ }
10616
+ if (node.type === "conditional") {
10617
+ const cond = node;
10618
+ const whenTrue = markCarrierIn(cond.whenTrue);
10619
+ const whenFalse = markCarrierIn(cond.whenFalse);
10620
+ if (!whenTrue && !whenFalse)
10621
+ return null;
10622
+ return { ...cond, whenTrue: whenTrue ?? cond.whenTrue, whenFalse: whenFalse ?? cond.whenFalse };
10623
+ }
10624
+ return null;
10625
+ }
10601
10626
  function transformFragment(node, ctx) {
10602
10627
  const isFragmentRoot = ctx.isRoot;
10603
10628
  const isTransparent = isFragmentRoot && isTransparentFragment(node, ctx);
@@ -10608,7 +10633,7 @@ function transformFragment(node, ctx) {
10608
10633
  const needsScopeComment = isFragmentRoot && !isTransparent || undefined;
10609
10634
  return {
10610
10635
  type: "fragment",
10611
- children,
10636
+ children: needsScopeComment ? markDataKeyCarrier(children) : children,
10612
10637
  transparent: isTransparent || undefined,
10613
10638
  needsScopeComment,
10614
10639
  loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath)
@@ -13705,6 +13730,50 @@ function buildIfStatementChain(analyzer, ctx, opts) {
13705
13730
  }
13706
13731
 
13707
13732
  // ../jsx/src/ir-to-client-js/prop-handling.ts
13733
+ function resolveRestSpreadOrigin(ctx, name) {
13734
+ const byName = localConstantValues(ctx);
13735
+ const visited = new Set;
13736
+ let current = name.trim();
13737
+ while (current !== undefined && !visited.has(current)) {
13738
+ if (ctx.restPropsName && current === ctx.restPropsName)
13739
+ return "rest";
13740
+ if (ctx.propsObjectName && current === ctx.propsObjectName)
13741
+ return "props";
13742
+ visited.add(current);
13743
+ current = byName.get(current)?.trim();
13744
+ }
13745
+ return null;
13746
+ }
13747
+ var _localConstantValuesCache = new WeakMap;
13748
+ function localConstantValues(ctx) {
13749
+ const cached = _localConstantValuesCache.get(ctx);
13750
+ if (cached)
13751
+ return cached;
13752
+ const byName = new Map;
13753
+ for (const constant of ctx.localConstants) {
13754
+ if (!byName.has(constant.name))
13755
+ byName.set(constant.name, constant.value);
13756
+ }
13757
+ _localConstantValuesCache.set(ctx, byName);
13758
+ return byName;
13759
+ }
13760
+ var _restSpreadNamesCache = new WeakMap;
13761
+ function resolveRestSpreadNames(ctx) {
13762
+ const cached = _restSpreadNamesCache.get(ctx);
13763
+ if (cached)
13764
+ return cached;
13765
+ const names = new Set;
13766
+ if (ctx.restPropsName)
13767
+ names.add(ctx.restPropsName);
13768
+ if (ctx.propsObjectName)
13769
+ names.add(ctx.propsObjectName);
13770
+ for (const constant of ctx.localConstants) {
13771
+ if (resolveRestSpreadOrigin(ctx, constant.name) !== null)
13772
+ names.add(constant.name);
13773
+ }
13774
+ _restSpreadNamesCache.set(ctx, names);
13775
+ return names;
13776
+ }
13708
13777
  function expandDynamicPropValue(value, ctx, scope) {
13709
13778
  const trimmedValue = value.trim();
13710
13779
  if (scope?.isBound(trimmedValue))
@@ -13793,6 +13862,9 @@ function decideWrapForChildProp(expandedValue, ctx, prop) {
13793
13862
  return decideWrapForAttr(expandedValue, ctx, prop);
13794
13863
  }
13795
13864
  function needsEffectWrapper(expr, ctx, freeIdentifiers2) {
13865
+ return needsEffectWrapperCore(expr, ctx, freeIdentifiers2, new Set);
13866
+ }
13867
+ function needsEffectWrapperCore(expr, ctx, freeIdentifiers2, visitedConstants) {
13796
13868
  for (const signal of ctx.signals) {
13797
13869
  if (identifierCallPattern(signal.getter).test(expr)) {
13798
13870
  return true;
@@ -13815,6 +13887,19 @@ function needsEffectWrapper(expr, ctx, freeIdentifiers2) {
13815
13887
  if (propsAccess.test(expr))
13816
13888
  return true;
13817
13889
  }
13890
+ for (const constant of ctx.localConstants) {
13891
+ if (visitedConstants.has(constant.name))
13892
+ continue;
13893
+ if (constant.value === undefined || constant.containsArrow)
13894
+ continue;
13895
+ const referenced = freeIdentifiers2 ? freeIdentifiers2.has(constant.name) : tokenContainsIdent(expr, constant.name);
13896
+ if (!referenced)
13897
+ continue;
13898
+ visitedConstants.add(constant.name);
13899
+ if (needsEffectWrapperCore(constant.value, ctx, constant.freeIdentifiers, visitedConstants)) {
13900
+ return true;
13901
+ }
13902
+ }
13818
13903
  return false;
13819
13904
  }
13820
13905
  function classifyReactivity(expr, ctx, loopParam, loopParamBindings, freeIdentifiers2) {
@@ -14488,24 +14573,14 @@ function jsxChildrenContainComponent(nodes) {
14488
14573
  function isSingleElementJsxChildren2(nodes) {
14489
14574
  return nodes.length === 1 && nodes[0].type === "element";
14490
14575
  }
14491
- function buildRestSpreadNames(ctx) {
14492
- const names = new Set;
14493
- if (ctx.restPropsName)
14494
- names.add(ctx.restPropsName);
14495
- if (ctx.propsObjectName)
14496
- names.add(ctx.propsObjectName);
14497
- return names;
14498
- }
14499
14576
  function buildComponentPropsExpr(props, ctx) {
14500
- const restName = ctx.restPropsName;
14501
- const propsObjName = ctx.propsObjectName;
14502
14577
  const knownSpreadProp = props.find((p) => {
14503
14578
  if (p.name !== "..." && !p.name.startsWith("..."))
14504
14579
  return false;
14505
14580
  if (p.value.kind !== "spread" && p.value.kind !== "expression")
14506
14581
  return false;
14507
14582
  const expr = p.value.kind === "spread" ? p.value.expr : p.value.expr;
14508
- return expr === restName || expr === propsObjName;
14583
+ return resolveRestSpreadOrigin(ctx, expr) !== null;
14509
14584
  });
14510
14585
  const spreadSource = knownSpreadProp ? PROPS_PARAM : null;
14511
14586
  const propsForInit = [];
@@ -14653,13 +14728,13 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
14653
14728
  if (l.childComponent) {
14654
14729
  template = "";
14655
14730
  if (l.isStaticArray && l.children[0]) {
14656
- staticItemTemplate = irToHtmlTemplate(l.children[0], buildRestSpreadNames(ctx), 0, undefined, undefined);
14731
+ staticItemTemplate = irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, undefined, undefined);
14657
14732
  }
14658
14733
  } else if (l.children[0] && !projectionInner) {
14659
14734
  const loopParamSpec = [{ param: l.param, bindings: l.paramBindings }];
14660
- template = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], buildRestSpreadNames(ctx), 0, loopParamSpec) : irToHtmlTemplate(l.children[0], buildRestSpreadNames(ctx), 0, loopParamSpec);
14735
+ template = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpec) : irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpec);
14661
14736
  if (l.isStaticArray) {
14662
- staticItemTemplate = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], buildRestSpreadNames(ctx), 0) : irToHtmlTemplate(l.children[0], buildRestSpreadNames(ctx), 0);
14737
+ staticItemTemplate = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], resolveRestSpreadNames(ctx), 0) : irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0);
14663
14738
  } else if (!useElementReconciliation && !l.bodyIsMultiRoot && !l.bodyIsItemConditional) {
14664
14739
  const skeletonSafeSlots = {
14665
14740
  reactiveAttrKeys: new Set(bindings.reactiveAttrs.map((a) => `${a.childSlotId}::${a.attrName}`)),
@@ -14711,11 +14786,11 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
14711
14786
  preambleRegions: l.preambleRegions,
14712
14787
  flatMapClient: projectionInner ? {
14713
14788
  params: l.index ? `(${l.param}, ${l.index})` : `(${l.param})`,
14714
- body: renderFlatMapProjectionClientBody(projectionInner, buildRestSpreadNames(ctx)),
14789
+ body: renderFlatMapProjectionClientBody(projectionInner, resolveRestSpreadNames(ctx)),
14715
14790
  keyed: projectionInner.key !== null
14716
14791
  } : l.flatMapCallback ? {
14717
14792
  params: l.flatMapCallback.params,
14718
- body: renderFlatMapClientBody(l.flatMapCallback, buildRestSpreadNames(ctx)),
14793
+ body: renderFlatMapClientBody(l.flatMapCallback, resolveRestSpreadNames(ctx)),
14719
14794
  keyed: flatMapCallbackHasKeyedLeaf(l.flatMapCallback)
14720
14795
  } : undefined
14721
14796
  });
@@ -14782,10 +14857,9 @@ function collectFromElement(element, ctx, insideConditional = false) {
14782
14857
  for (const attr of element.attrs) {
14783
14858
  if (attr.name === "..." && attr.value) {
14784
14859
  const spreadVal = attrValueToString(attr.value) ?? "";
14785
- const elemRestName = ctx.restPropsName;
14786
- const elemPropsObjName = ctx.propsObjectName;
14787
- if (spreadVal && (spreadVal === elemRestName || spreadVal === elemPropsObjName)) {
14788
- const consumedKeys = spreadVal === elemRestName ? ctx.propsParams.map((p) => p.sourceName ?? p.name) : [];
14860
+ const spreadOrigin = spreadVal ? resolveRestSpreadOrigin(ctx, spreadVal) : null;
14861
+ if (spreadOrigin !== null) {
14862
+ const consumedKeys = spreadOrigin === "rest" ? ctx.propsParams.map((p) => p.sourceName ?? p.name) : [];
14789
14863
  const staticAttrKeys = element.attrs.filter((a) => a.name !== "...").map((a) => a.name);
14790
14864
  const excludeKeys = [...new Set([...consumedKeys, ...staticAttrKeys])];
14791
14865
  ctx.restAttrElements.push({
@@ -14864,7 +14938,7 @@ function collectBranchTextEffects(node) {
14864
14938
  }
14865
14939
  function collectBranchLoops(node, ctx, siblingOffsets) {
14866
14940
  const loops = [];
14867
- const restNames = ctx ? buildRestSpreadNames(ctx) : undefined;
14941
+ const restNames = ctx ? resolveRestSpreadNames(ctx) : undefined;
14868
14942
  walkIR(node, null, {
14869
14943
  ...stopAt("conditional", "ifStatement"),
14870
14944
  element: ({ node: el, scope: parentSlotId, descend }) => {
@@ -14932,7 +15006,7 @@ function collectBranchLoops(node, ctx, siblingOffsets) {
14932
15006
  return loops;
14933
15007
  }
14934
15008
  function buildConditionalMetadata(node, ctx, siblingOffsets) {
14935
- const restNames = buildRestSpreadNames(ctx);
15009
+ const restNames = resolveRestSpreadNames(ctx);
14936
15010
  return {
14937
15011
  slotId: node.slotId,
14938
15012
  condition: node.condition,
@@ -16576,12 +16650,9 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
16576
16650
  lines.push("");
16577
16651
  const propNamesForStaticCheck = new Set(ctx.propsParams.map((p) => p.name));
16578
16652
  const { inlinableConstants, unsafeLocalNames } = inlinability ?? buildInlinableConstants(ctx, graph, _ir.root);
16579
- const restSpreadNames = new Set;
16580
- if (ctx.restPropsName)
16581
- restSpreadNames.add(ctx.restPropsName);
16582
- if (ctx.propsObjectName)
16583
- restSpreadNames.add(ctx.propsObjectName);
16584
- const isCommentScope = _ir.root.type === "fragment" && _ir.root.needsScopeComment || _ir.root.type === "component";
16653
+ const restSpreadNames = resolveRestSpreadNames(ctx);
16654
+ const isFragmentRoot = _ir.root.type === "fragment" && !!_ir.root.needsScopeComment;
16655
+ const isCommentScope = isFragmentRoot || _ir.root.type === "component";
16585
16656
  const defParts = [`init: init${name}`];
16586
16657
  if (canGenerateStaticTemplate(_ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
16587
16658
  const markupSlotIds = new Set(ctx.dynamicElements.map((e) => e.slotId));
@@ -16599,6 +16670,9 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
16599
16670
  if (isCommentScope) {
16600
16671
  defParts.push("comment: true");
16601
16672
  }
16673
+ if (isFragmentRoot) {
16674
+ defParts.push("fragmentRoot: true");
16675
+ }
16602
16676
  const registryKey = nameForRegistryRef(name);
16603
16677
  if (registryKey !== name) {
16604
16678
  defParts.push(`name: '${name}'`);
@@ -21626,10 +21700,18 @@ var PHASES = [
21626
21700
 
21627
21701
  // ../jsx/src/ir-to-client-js/rewrite-props-object.ts
21628
21702
  import ts20 from "typescript";
21629
- function rewritePropsObjectRef(code, propsObjectName) {
21630
- const srcPropsName = propsObjectName ?? "props";
21631
- if (srcPropsName === PROPS_PARAM)
21632
- return code;
21703
+ function rewritePropsObjectRef(code, propsObjectName, restPropsName = null) {
21704
+ let result = code;
21705
+ const seen = new Set;
21706
+ for (const srcPropsName of [propsObjectName ?? "props", restPropsName]) {
21707
+ if (srcPropsName === null || srcPropsName === PROPS_PARAM || seen.has(srcPropsName))
21708
+ continue;
21709
+ seen.add(srcPropsName);
21710
+ result = rewriteOneName(result, srcPropsName);
21711
+ }
21712
+ return result;
21713
+ }
21714
+ function rewriteOneName(code, srcPropsName) {
21633
21715
  if (!identifierPattern(srcPropsName).test(code))
21634
21716
  return code;
21635
21717
  const sourceFile = ts20.createSourceFile("init-body.ts", code, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
@@ -21697,7 +21779,7 @@ function generateInitFunction(ir, ctx, siblingComponents, localImportPrefixes) {
21697
21779
  runPhases(lines, phaseCtx, PHASES);
21698
21780
  const hydrateLine = emitRegistrationAndHydration(lines, ctx, ir, graph, inlinability);
21699
21781
  let generatedCode = rewritePropsObjectRef(lines.join(`
21700
- `), ctx.propsObjectName);
21782
+ `), ctx.propsObjectName, ctx.restPropsName);
21701
21783
  generatedCode += `
21702
21784
  ` + hydrateLine;
21703
21785
  const moduleConstantsCode = emitModuleLevelDeclarations(classification.moduleLevelConstants, classification.moduleLevelFunctions, classification.moduleLevelSignals, classification.moduleLevelMemos);
@@ -21997,11 +22079,7 @@ function generateTemplateOnlyMount(ir, ctx) {
21997
22079
  const propNamesForStaticCheck = new Set(ctx.propsParams.map((p) => p.name));
21998
22080
  const graph = buildReferencesGraph(ctx, ir.root);
21999
22081
  const { inlinableConstants, unsafeLocalNames } = buildInlinableConstants(ctx, graph, ir.root);
22000
- const restSpreadNames = new Set;
22001
- if (ctx.restPropsName)
22002
- restSpreadNames.add(ctx.restPropsName);
22003
- if (ctx.propsObjectName)
22004
- restSpreadNames.add(ctx.propsObjectName);
22082
+ const restSpreadNames = resolveRestSpreadNames(ctx);
22005
22083
  let templateHtml;
22006
22084
  if (canGenerateStaticTemplate(ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
22007
22085
  const markupSlotIds = new Set(ctx.dynamicElements.map((e) => e.slotId));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/vite",
3
- "version": "0.33.1",
3
+ "version": "0.33.2",
4
4
  "description": "Vite plugin for BarefootJS: Vite/Rollup owns bundling, hashing, chunking, tree-shaking and minification of client assets, BarefootJS keeps only the JSX to (template, client JS) compile",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,17 +38,17 @@
38
38
  "directory": "packages/vite"
39
39
  },
40
40
  "dependencies": {
41
- "@barefootjs/shared": "0.33.1"
41
+ "@barefootjs/shared": "0.33.2"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@barefootjs/jsx": ">=0.2.0",
45
45
  "vite": "^6.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@barefootjs/client": "0.33.1",
49
- "@barefootjs/go-template": "0.33.1",
50
- "@barefootjs/hono": "0.33.1",
51
- "@barefootjs/jsx": "0.33.1",
48
+ "@barefootjs/client": "0.33.2",
49
+ "@barefootjs/go-template": "0.33.2",
50
+ "@barefootjs/hono": "0.33.2",
51
+ "@barefootjs/jsx": "0.33.2",
52
52
  "typescript": "^5.0.0",
53
53
  "vite": "^6.0.0"
54
54
  }