@homebound/truss 2.28.0 → 2.29.0

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.
@@ -1928,13 +1928,29 @@ function resolveFullChain(ctx, chain) {
1928
1928
  if (elseIndex !== -1) {
1929
1929
  flushCurrentNodes();
1930
1930
  const branchContext = cloneConditionContext(currentContext);
1931
+ let branchEnd = filteredChain.length;
1932
+ for (let branchIndex = elseIndex + 1; branchIndex < filteredChain.length; branchIndex++) {
1933
+ const branchNode = filteredChain[branchIndex];
1934
+ if (branchNode.type === "getter" && branchNode.name === "end") {
1935
+ branchEnd = branchIndex;
1936
+ break;
1937
+ }
1938
+ }
1931
1939
  const thenNodes = mediaStart.thenNodes ? [...mediaStart.thenNodes, ...filteredChain.slice(i + 1, elseIndex)] : filteredChain.slice(i, elseIndex);
1932
- const elseNodes = [makeMediaQueryNode(mediaStart.inverseMediaQuery), ...filteredChain.slice(elseIndex + 1)];
1940
+ const elseNodes = [
1941
+ makeMediaQueryNode(mediaStart.inverseMediaQuery),
1942
+ ...filteredChain.slice(elseIndex + 1, branchEnd)
1943
+ ];
1933
1944
  const thenSegs = resolveChain({ ...ctx, initialContext: branchContext }, thenNodes);
1934
1945
  const elseSegs = resolveChain({ ...ctx, initialContext: branchContext }, elseNodes);
1935
1946
  parts.push({ type: "unconditional", segments: [...thenSegs, ...elseSegs] });
1936
- i = filteredChain.length;
1937
- break;
1947
+ if (branchEnd === filteredChain.length) {
1948
+ i = filteredChain.length;
1949
+ break;
1950
+ }
1951
+ resetConditionContext(currentContext);
1952
+ i = branchEnd + 1;
1953
+ continue;
1938
1954
  }
1939
1955
  }
1940
1956
  if (isWhenObjectCall(node)) {
@@ -1960,18 +1976,24 @@ function resolveFullChain(ctx, chain) {
1960
1976
  i++;
1961
1977
  let inElse = false;
1962
1978
  while (i < filteredChain.length) {
1963
- if (filteredChain[i].type === "else") {
1979
+ const branchNode = filteredChain[i];
1980
+ if (branchNode.type === "getter" && branchNode.name === "end") {
1981
+ resetConditionContext(currentContext);
1982
+ i++;
1983
+ break;
1984
+ }
1985
+ if (branchNode.type === "else") {
1964
1986
  inElse = true;
1965
1987
  i++;
1966
1988
  continue;
1967
1989
  }
1968
- if (filteredChain[i].type === "if") {
1990
+ if (branchNode.type === "if") {
1969
1991
  break;
1970
1992
  }
1971
1993
  if (inElse) {
1972
- elseNodes.push(filteredChain[i]);
1994
+ elseNodes.push(branchNode);
1973
1995
  } else {
1974
- thenNodes.push(filteredChain[i]);
1996
+ thenNodes.push(branchNode);
1975
1997
  }
1976
1998
  i++;
1977
1999
  }
@@ -2109,10 +2131,14 @@ function getMediaConditionalStartNode(node, mapping) {
2109
2131
  }
2110
2132
  function findElseIndex(chain, start) {
2111
2133
  for (let i = start; i < chain.length; i++) {
2112
- if (chain[i].type === "if") {
2134
+ const node = chain[i];
2135
+ if (node.type === "if") {
2136
+ return -1;
2137
+ }
2138
+ if (node.type === "getter" && node.name === "end") {
2113
2139
  return -1;
2114
2140
  }
2115
- if (chain[i].type === "else") {
2141
+ if (node.type === "else") {
2116
2142
  return i;
2117
2143
  }
2118
2144
  }