@homebound/truss 2.19.2 → 2.19.3

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.
@@ -1749,7 +1749,9 @@ function applyModifierNodeToConditionContext(context, node, mapping) {
1749
1749
  context.pseudoClass = pseudoSelector(node.name);
1750
1750
  }
1751
1751
  }
1752
- function resolveFullChain(chain, mapping, cssBindingName, initialContext = emptyConditionContext(), resolveCssChainReference2) {
1752
+ function resolveFullChain(ctx, chain) {
1753
+ const { mapping } = ctx;
1754
+ const initialContext = ctx.initialContext ?? emptyConditionContext();
1753
1755
  const parts = [];
1754
1756
  const markers = [];
1755
1757
  const nestedErrors = [];
@@ -1779,7 +1781,7 @@ function resolveFullChain(chain, mapping, cssBindingName, initialContext = empty
1779
1781
  }
1780
1782
  parts.push({
1781
1783
  type: "unconditional",
1782
- segments: resolveChain(currentNodes, mapping, currentNodesStartContext, cssBindingName, resolveCssChainReference2)
1784
+ segments: resolveChain({ ...ctx, initialContext: currentNodesStartContext }, currentNodes)
1783
1785
  });
1784
1786
  currentNodes = [];
1785
1787
  currentNodesStartContext = cloneConditionContext(currentContext);
@@ -1801,8 +1803,8 @@ function resolveFullChain(chain, mapping, cssBindingName, initialContext = empty
1801
1803
  const branchContext = cloneConditionContext(currentContext);
1802
1804
  const thenNodes = mediaStart.thenNodes ? [...mediaStart.thenNodes, ...filteredChain.slice(i + 1, elseIndex)] : filteredChain.slice(i, elseIndex);
1803
1805
  const elseNodes = [makeMediaQueryNode(mediaStart.inverseMediaQuery), ...filteredChain.slice(elseIndex + 1)];
1804
- const thenSegs = resolveChain(thenNodes, mapping, branchContext, cssBindingName, resolveCssChainReference2);
1805
- const elseSegs = resolveChain(elseNodes, mapping, branchContext, cssBindingName, resolveCssChainReference2);
1806
+ const thenSegs = resolveChain({ ...ctx, initialContext: branchContext }, thenNodes);
1807
+ const elseSegs = resolveChain({ ...ctx, initialContext: branchContext }, elseNodes);
1806
1808
  parts.push({ type: "unconditional", segments: [...thenSegs, ...elseSegs] });
1807
1809
  i = filteredChain.length;
1808
1810
  break;
@@ -1810,13 +1812,7 @@ function resolveFullChain(chain, mapping, cssBindingName, initialContext = empty
1810
1812
  }
1811
1813
  if (isWhenObjectCall(node)) {
1812
1814
  flushCurrentNodes();
1813
- const resolved = resolveWhenObjectSelectors(
1814
- node,
1815
- mapping,
1816
- cssBindingName,
1817
- currentContext,
1818
- resolveCssChainReference2
1819
- );
1815
+ const resolved = resolveWhenObjectSelectors(ctx, node, currentContext);
1820
1816
  parts.push(...resolved.parts);
1821
1817
  markers.push(...resolved.markers);
1822
1818
  nestedErrors.push(...resolved.errors);
@@ -1852,8 +1848,8 @@ function resolveFullChain(chain, mapping, cssBindingName, initialContext = empty
1852
1848
  }
1853
1849
  i++;
1854
1850
  }
1855
- const thenSegs = resolveChain(thenNodes, mapping, branchContext, cssBindingName, resolveCssChainReference2);
1856
- const elseSegs = resolveChain(elseNodes, mapping, branchContext, cssBindingName, resolveCssChainReference2);
1851
+ const thenSegs = resolveChain({ ...ctx, initialContext: branchContext }, thenNodes);
1852
+ const elseSegs = resolveChain({ ...ctx, initialContext: branchContext }, elseNodes);
1857
1853
  parts.push({
1858
1854
  type: "conditional",
1859
1855
  conditionNode: node.conditionNode,
@@ -1880,7 +1876,8 @@ function resolveFullChain(chain, mapping, cssBindingName, initialContext = empty
1880
1876
  function isWhenObjectCall(node) {
1881
1877
  return node.type === "call" && node.name === "when" && node.args.length === 1 && node.args[0].type === "ObjectExpression";
1882
1878
  }
1883
- function resolveWhenObjectSelectors(node, mapping, cssBindingName, initialContext, resolveCssChainReference2) {
1879
+ function resolveWhenObjectSelectors(ctx, node, initialContext) {
1880
+ const { cssBindingName } = ctx;
1884
1881
  if (!cssBindingName) {
1885
1882
  return {
1886
1883
  parts: [],
@@ -1907,13 +1904,13 @@ function resolveWhenObjectSelectors(node, mapping, cssBindingName, initialContex
1907
1904
  throw new UnsupportedPatternError(`when({ ... }) selector keys must be string literals`);
1908
1905
  }
1909
1906
  const value = unwrapExpression(property.value);
1910
- const innerChain = resolveWhenObjectValueChain(value, cssBindingName, resolveCssChainReference2);
1907
+ const innerChain = resolveWhenObjectValueChain(ctx, value);
1911
1908
  if (!innerChain) {
1912
1909
  throw new UnsupportedPatternError(`when({ ... }) values must be Css.*.$ expressions`);
1913
1910
  }
1914
1911
  const selectorContext = cloneConditionContext(initialContext);
1915
1912
  selectorContext.pseudoClass = property.key.value;
1916
- const resolved = resolveFullChain(innerChain, mapping, cssBindingName, selectorContext, resolveCssChainReference2);
1913
+ const resolved = resolveFullChain({ ...ctx, initialContext: selectorContext }, innerChain);
1917
1914
  parts.push(...resolved.parts);
1918
1915
  markers.push(...resolved.markers);
1919
1916
  errors.push(...resolved.errors);
@@ -1927,7 +1924,8 @@ function resolveWhenObjectSelectors(node, mapping, cssBindingName, initialContex
1927
1924
  }
1928
1925
  return { parts, markers, errors: [...new Set(errors)] };
1929
1926
  }
1930
- function resolveWhenObjectValueChain(value, cssBindingName, resolveCssChainReference2) {
1927
+ function resolveWhenObjectValueChain(ctx, value) {
1928
+ const { cssBindingName, resolveCssChainReference: resolveCssChainReference2 } = ctx;
1931
1929
  if (cssBindingName && value.type === "MemberExpression" && !value.computed && value.property.type === "Identifier" && value.property.name === "$") {
1932
1930
  return extractChain(value.object, cssBindingName);
1933
1931
  }
@@ -1993,7 +1991,9 @@ function invertMediaQuery(query) {
1993
1991
  }
1994
1992
  return query.replace("@media", "@media not");
1995
1993
  }
1996
- function resolveChain(chain, mapping, initialContext = emptyConditionContext(), cssBindingName, resolveCssChainReference2) {
1994
+ function resolveChain(ctx, chain) {
1995
+ const { mapping, cssBindingName } = ctx;
1996
+ const initialContext = ctx.initialContext ?? emptyConditionContext();
1997
1997
  const segments = [];
1998
1998
  const context = cloneConditionContext(initialContext);
1999
1999
  for (const node of chain) {
@@ -2093,13 +2093,7 @@ function resolveChain(chain, mapping, initialContext = emptyConditionContext(),
2093
2093
  }
2094
2094
  if (abbr === "when") {
2095
2095
  if (isWhenObjectCall(node)) {
2096
- const resolved2 = resolveWhenObjectSelectors(
2097
- node,
2098
- mapping,
2099
- cssBindingName,
2100
- context,
2101
- resolveCssChainReference2
2102
- );
2096
+ const resolved2 = resolveWhenObjectSelectors(ctx, node, context);
2103
2097
  segments.push(...flattenWhenObjectParts(resolved2));
2104
2098
  continue;
2105
2099
  }
@@ -3114,7 +3108,7 @@ function transformTruss(code, filename, mapping, options = {}) {
3114
3108
  return;
3115
3109
  }
3116
3110
  const resolveCssChainReference2 = buildCssChainReferenceResolver(path, cssBindingName);
3117
- const resolvedChain = resolveFullChain(chain, mapping, cssBindingName, void 0, resolveCssChainReference2);
3111
+ const resolvedChain = resolveFullChain({ mapping, cssBindingName, resolveCssChainReference: resolveCssChainReference2 }, chain);
3118
3112
  sites.push({ path, resolvedChain });
3119
3113
  const line = path.node.loc?.start.line ?? null;
3120
3114
  for (const err of resolvedChain.errors) {
@@ -3515,7 +3509,7 @@ function resolveCssExpression(node, cssBindingName, mapping, filename) {
3515
3509
  return { error: "when() modifiers are not supported in .css.ts files" };
3516
3510
  }
3517
3511
  }
3518
- const resolved = resolveFullChain(chain, mapping, cssBindingName);
3512
+ const resolved = resolveFullChain({ mapping, cssBindingName }, chain);
3519
3513
  if (resolved.errors.length > 0) {
3520
3514
  return { error: resolved.errors[0] };
3521
3515
  }