@homebound/truss 2.0.5 → 2.0.6

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.
@@ -1355,7 +1355,7 @@ function buildPropsArgs(segments, options) {
1355
1355
  if (seg.styleArrayArg) {
1356
1356
  args.push(
1357
1357
  t3.spreadElement(
1358
- buildUnknownObjectSpreadFallback(
1358
+ buildUnknownSpreadFallback(
1359
1359
  seg.styleArrayArg,
1360
1360
  options.asStyleArrayHelperName,
1361
1361
  options.needsAsStyleArrayHelper
@@ -1394,13 +1394,6 @@ function rewriteCssAttributeExpressions(ast, filename, debug, stylexNamespaceNam
1394
1394
  const value = path.node.value;
1395
1395
  if (!t3.isJSXExpressionContainer(value)) return;
1396
1396
  if (!t3.isExpression(value.expression)) return;
1397
- if (!isCssRewriteableExpression(value.expression, path)) {
1398
- skippedCssPropMessages.push({
1399
- message: explainSkippedCssRewrite(value.expression, path),
1400
- line: path.node.loc?.start.line ?? null
1401
- });
1402
- return;
1403
- }
1404
1397
  const propsArgs = lowerCssExpressionToPropsArgs(
1405
1398
  value.expression,
1406
1399
  path,
@@ -1464,11 +1457,8 @@ function buildDebugElements(line, options) {
1464
1457
  options.needsTrussDebugInfo.current = true;
1465
1458
  return [t3.newExpression(t3.identifier(options.trussDebugInfoName), [t3.stringLiteral(`${options.filename}:${line}`)])];
1466
1459
  }
1467
- function isCssRewriteableExpression(expr, path) {
1468
- return !!lowerCssExpressionToPropsArgs(expr, path, "asStyleArray", { current: false });
1469
- }
1470
1460
  function lowerCssExpressionToPropsArgs(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1471
- return buildStyleObjectPropsArgs(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper) ?? buildStyleArrayLikePropsArgsFromExpression(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper);
1461
+ return buildStyleObjectPropsArgs(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper) ?? buildStyleArrayLikePropsArgsFromExpression(expr, path);
1472
1462
  }
1473
1463
  function explainSkippedCssRewrite(expr, path) {
1474
1464
  if (t3.isObjectExpression(expr)) {
@@ -1476,7 +1466,7 @@ function explainSkippedCssRewrite(expr, path) {
1476
1466
  if (!t3.isSpreadElement(prop)) {
1477
1467
  return `[truss] Unsupported pattern: Could not rewrite css prop: object contains a non-spread property (${formatNodeSnippet(expr)})`;
1478
1468
  }
1479
- const normalizedArg = normalizeStyleArrayLikeExpression(prop.argument, path, /* @__PURE__ */ new Set());
1469
+ const normalizedArg = normalizeStyleExpression(prop.argument);
1480
1470
  if (!normalizedArg) {
1481
1471
  return `[truss] Unsupported pattern: Could not rewrite css prop: spread argument is not style-array-like (${formatNodeSnippet(prop.argument)})`;
1482
1472
  }
@@ -1520,53 +1510,46 @@ function removeExistingClassNameAttribute(path) {
1520
1510
  }
1521
1511
  function buildStyleObjectPropsArgs(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1522
1512
  if (!t3.isObjectExpression(expr) || expr.properties.length === 0) return null;
1523
- const result = collectStyleCompositionEntries(expr, path);
1524
- if (!result) {
1525
- if (expr.properties.every(function(prop) {
1526
- return t3.isSpreadElement(prop);
1527
- })) {
1528
- return expr.properties.map(function(prop) {
1529
- const spread = prop;
1530
- return t3.spreadElement(
1531
- buildUnknownObjectSpreadFallback(spread.argument, asStyleArrayHelperName, needsAsStyleArrayHelper)
1532
- // I.e. `css={{ ...css }}` or `css={{ ...xss }}`
1533
- );
1534
- });
1535
- }
1536
- return null;
1537
- }
1538
- if (result.droppedPropertyKeys.length > 0) return null;
1539
- return buildPropsArgsFromStyleCompositionEntries(
1540
- result.entries,
1541
- path,
1542
- asStyleArrayHelperName,
1543
- needsAsStyleArrayHelper
1544
- );
1513
+ const allSpreads = expr.properties.every(function(prop) {
1514
+ return t3.isSpreadElement(prop);
1515
+ });
1516
+ if (!allSpreads) return null;
1517
+ if (hasStyleArraySpread(expr, path)) {
1518
+ const result = flattenStyleObject(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper);
1519
+ return result.elements.filter(Boolean);
1520
+ }
1521
+ return expr.properties.map(function(prop) {
1522
+ const spread = prop;
1523
+ return t3.spreadElement(
1524
+ buildUnknownSpreadFallback(spread.argument, asStyleArrayHelperName, needsAsStyleArrayHelper)
1525
+ // I.e. `css={{ ...css }}` or `css={{ ...xss }}`
1526
+ );
1527
+ });
1545
1528
  }
1546
- function buildStyleArrayLikePropsArgsFromExpression(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1547
- const normalizedExpr = normalizeStyleArrayLikeExpression(expr, path, /* @__PURE__ */ new Set());
1529
+ function buildStyleArrayLikePropsArgsFromExpression(expr, path) {
1530
+ const normalizedExpr = normalizeStyleExpression(expr);
1548
1531
  if (!normalizedExpr) return null;
1549
- return buildStyleArrayLikePropsArgs(normalizedExpr, path, /* @__PURE__ */ new Set());
1532
+ return buildStyleArrayLikePropsArgs(normalizedExpr, path);
1550
1533
  }
1551
- function buildStyleArrayLikePropsArgs(expr, path, seen) {
1552
- if (seen.has(expr)) return null;
1553
- seen.add(expr);
1534
+ function buildStyleArrayLikePropsArgs(expr, path) {
1554
1535
  if (t3.isArrayExpression(expr)) {
1555
1536
  const propsArgs = [];
1556
1537
  for (const el of expr.elements) {
1557
1538
  if (!el) continue;
1558
1539
  if (t3.isSpreadElement(el)) {
1559
- const normalizedArg = normalizeStyleArrayLikeExpression(el.argument, path, /* @__PURE__ */ new Set());
1540
+ const normalizedArg = normalizeStyleExpression(el.argument);
1560
1541
  if (!normalizedArg) {
1561
1542
  propsArgs.push(t3.spreadElement(el.argument));
1562
1543
  continue;
1563
1544
  }
1564
- const nestedArgs = buildStyleArrayLikePropsArgs(normalizedArg, path, seen);
1565
- if (nestedArgs && t3.isArrayExpression(normalizedArg)) {
1566
- propsArgs.push(...nestedArgs);
1567
- } else {
1568
- propsArgs.push(t3.spreadElement(buildSafeSpreadArgument(normalizedArg)));
1545
+ if (t3.isArrayExpression(normalizedArg)) {
1546
+ const nestedArgs = buildStyleArrayLikePropsArgs(normalizedArg, path);
1547
+ if (nestedArgs) {
1548
+ propsArgs.push(...nestedArgs);
1549
+ continue;
1550
+ }
1569
1551
  }
1552
+ propsArgs.push(t3.spreadElement(buildSafeSpreadArgument(normalizedArg)));
1570
1553
  continue;
1571
1554
  }
1572
1555
  propsArgs.push(el);
@@ -1581,15 +1564,15 @@ function buildStyleArrayLikePropsArgs(expr, path, seen) {
1581
1564
  function rewriteStyleObjectExpressions(ast, messages, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1582
1565
  traverse(ast, {
1583
1566
  ObjectExpression(path) {
1584
- const result = tryBuildStyleArrayFromObject(path, asStyleArrayHelperName, needsAsStyleArrayHelper);
1585
- if (!result.rewritten) return;
1567
+ if (!hasStyleArraySpread(path.node, path)) return;
1568
+ const result = flattenStyleObject(path.node, path, asStyleArrayHelperName, needsAsStyleArrayHelper);
1586
1569
  if (result.droppedPropertyKeys.length > 0) {
1587
1570
  messages.push({
1588
1571
  message: `[truss] Unsupported pattern: Dropped non-spread properties from style composition object (${result.droppedPropertyKeys.join(", ")})`,
1589
1572
  line: path.node.loc?.start.line ?? null
1590
1573
  });
1591
1574
  }
1592
- path.replaceWith(result.rewritten);
1575
+ path.replaceWith(t3.arrayExpression(result.elements));
1593
1576
  }
1594
1577
  });
1595
1578
  }
@@ -1601,258 +1584,148 @@ function rewriteCssSpreadCalls(ast, cssBindingName, asStyleArrayHelperName, need
1601
1584
  if (!arg || t3.isSpreadElement(arg) || !t3.isExpression(arg) || path.node.arguments.length !== 1) return;
1602
1585
  const styleObject = unwrapStyleObjectExpression(arg);
1603
1586
  if (!styleObject) return;
1604
- const result = tryBuildStyleArrayFromObjectExpression(
1605
- styleObject,
1606
- path,
1607
- asStyleArrayHelperName,
1608
- needsAsStyleArrayHelper
1609
- );
1610
- if (!result.rewritten) return;
1611
- path.replaceWith(result.rewritten);
1587
+ if (!hasStyleArraySpread(styleObject, path)) return;
1588
+ const result = flattenStyleObject(styleObject, path, asStyleArrayHelperName, needsAsStyleArrayHelper);
1589
+ path.replaceWith(t3.arrayExpression(result.elements));
1612
1590
  }
1613
1591
  });
1614
1592
  }
1615
- function tryBuildStyleArrayFromObject(path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1616
- return tryBuildStyleArrayFromObjectExpression(path.node, path, asStyleArrayHelperName, needsAsStyleArrayHelper);
1617
- }
1618
- function tryBuildStyleArrayFromObjectExpression(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1619
- const result = collectStyleCompositionEntries(expr, path);
1620
- if (!result) return { rewritten: null, droppedPropertyKeys: [] };
1621
- const elements = buildArrayElementsFromStyleCompositionEntries(
1622
- result.entries,
1623
- path,
1624
- asStyleArrayHelperName,
1625
- needsAsStyleArrayHelper
1626
- );
1627
- return { rewritten: t3.arrayExpression(elements), droppedPropertyKeys: result.droppedPropertyKeys };
1628
- }
1629
- function collectStyleCompositionEntries(expr, path) {
1630
- if (expr.properties.length === 0) return null;
1631
- let sawKnownStyle = false;
1632
- const entries = [];
1593
+ function flattenStyleObject(expr, path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1594
+ const elements = [];
1633
1595
  const droppedPropertyKeys = [];
1634
1596
  for (const prop of expr.properties) {
1635
1597
  if (!t3.isSpreadElement(prop)) {
1636
1598
  droppedPropertyKeys.push(formatDroppedPropertyKey(prop));
1637
1599
  continue;
1638
1600
  }
1639
- const normalizedArg = normalizeStyleArrayLikeExpression(prop.argument, path, /* @__PURE__ */ new Set());
1640
- if (!normalizedArg) {
1641
- entries.push({ kind: "unknown", expr: prop.argument });
1601
+ const normalized = normalizeStyleExpression(prop.argument);
1602
+ if (!normalized) {
1603
+ elements.push(
1604
+ t3.spreadElement(buildUnknownSpreadFallback(prop.argument, asStyleArrayHelperName, needsAsStyleArrayHelper))
1605
+ );
1642
1606
  continue;
1643
1607
  }
1644
- if (isKnownStyleArrayLike(normalizedArg, path, /* @__PURE__ */ new Set())) {
1645
- sawKnownStyle = true;
1646
- entries.push({ kind: "known", expr: normalizedArg });
1608
+ if (t3.isArrayExpression(normalized)) {
1609
+ elements.push(...normalized.elements);
1610
+ } else if (expressionContainsArray(normalized, path)) {
1611
+ elements.push(t3.spreadElement(buildSafeSpreadArgument(normalized)));
1647
1612
  } else {
1648
- entries.push({ kind: "unknown", expr: normalizedArg });
1613
+ elements.push(
1614
+ t3.spreadElement(buildUnknownSpreadFallback(normalized, asStyleArrayHelperName, needsAsStyleArrayHelper))
1615
+ // I.e. `...borderBottomStyles`
1616
+ );
1649
1617
  }
1650
1618
  }
1651
- return sawKnownStyle ? { entries, droppedPropertyKeys } : null;
1619
+ return { elements, droppedPropertyKeys };
1652
1620
  }
1653
- function buildPropsArgsFromStyleCompositionEntries(entries, path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1654
- const propsArgs = [];
1655
- for (const entry of entries) {
1656
- const nestedArgs = entry.kind === "known" ? buildStyleArrayLikePropsArgs(entry.expr, path, /* @__PURE__ */ new Set()) : null;
1657
- if (nestedArgs && t3.isArrayExpression(entry.expr)) {
1658
- propsArgs.push(...nestedArgs);
1659
- continue;
1660
- }
1661
- propsArgs.push(
1662
- t3.spreadElement(
1663
- entry.kind === "known" ? buildSafeSpreadArgument(entry.expr) : buildUnknownObjectSpreadFallback(entry.expr, asStyleArrayHelperName, needsAsStyleArrayHelper)
1664
- )
1665
- );
1666
- }
1667
- return propsArgs;
1621
+ function hasStyleArraySpread(expr, path) {
1622
+ return expr.properties.some(function(prop) {
1623
+ return t3.isSpreadElement(prop) && expressionContainsArray(prop.argument, path);
1624
+ });
1668
1625
  }
1669
- function buildArrayElementsFromStyleCompositionEntries(entries, path, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1670
- const elements = [];
1671
- for (const entry of entries) {
1672
- const nestedArgs = entry.kind === "known" ? buildStyleArrayLikePropsArgs(entry.expr, path, /* @__PURE__ */ new Set()) : null;
1673
- if (nestedArgs && t3.isArrayExpression(entry.expr)) {
1674
- elements.push(...entry.expr.elements);
1675
- continue;
1626
+ function expressionContainsArray(expr, path) {
1627
+ if (t3.isArrayExpression(expr)) return true;
1628
+ if (t3.isConditionalExpression(expr)) {
1629
+ return expressionContainsArray(expr.consequent, path) || expressionContainsArray(expr.alternate, path);
1630
+ }
1631
+ if (t3.isLogicalExpression(expr)) {
1632
+ return expressionContainsArray(expr.left, path) || expressionContainsArray(expr.right, path);
1633
+ }
1634
+ if (t3.isObjectExpression(expr)) {
1635
+ return expr.properties.some(function(p) {
1636
+ return t3.isSpreadElement(p) && expressionContainsArray(p.argument, path);
1637
+ });
1638
+ }
1639
+ if (t3.isIdentifier(expr)) {
1640
+ const binding = path.scope.getBinding(expr.name);
1641
+ if (binding?.path.isVariableDeclarator()) {
1642
+ const init = binding.path.node.init;
1643
+ if (init) return expressionContainsArray(init, binding.path);
1644
+ }
1645
+ return false;
1646
+ }
1647
+ if (t3.isMemberExpression(expr) && t3.isIdentifier(expr.object)) {
1648
+ const binding = path.scope.getBinding(expr.object.name);
1649
+ if (binding?.path.isVariableDeclarator()) {
1650
+ const init = binding.path.node.init;
1651
+ if (init && t3.isObjectExpression(init)) {
1652
+ const propName = getStaticMemberPropertyName(expr, path);
1653
+ if (propName) {
1654
+ for (const prop of init.properties) {
1655
+ if (!t3.isObjectProperty(prop) || prop.computed) continue;
1656
+ if (!isMatchingPropertyName(prop.key, propName)) continue;
1657
+ if (t3.isExpression(prop.value)) {
1658
+ return expressionContainsArray(prop.value, binding.path);
1659
+ }
1660
+ }
1661
+ }
1662
+ }
1676
1663
  }
1677
- elements.push(
1678
- t3.spreadElement(
1679
- entry.kind === "known" ? buildSafeSpreadArgument(entry.expr) : asStyleArrayHelperName && needsAsStyleArrayHelper ? buildUnknownObjectSpreadFallback(entry.expr, asStyleArrayHelperName, needsAsStyleArrayHelper) : buildInlineAsStyleArrayExpression(entry.expr)
1680
- )
1681
- );
1664
+ return false;
1682
1665
  }
1683
- return elements;
1684
- }
1685
- function isCssSpreadCall(expr, cssBindingName) {
1686
- return t3.isMemberExpression(expr.callee) && !expr.callee.computed && t3.isIdentifier(expr.callee.object, { name: cssBindingName }) && t3.isIdentifier(expr.callee.property, { name: "spread" });
1687
- }
1688
- function unwrapStyleObjectExpression(expr) {
1689
- if (t3.isObjectExpression(expr)) return expr;
1690
- if (t3.isTSAsExpression(expr) || t3.isTSSatisfiesExpression(expr) || t3.isTSNonNullExpression(expr)) {
1691
- return unwrapStyleObjectExpression(expr.expression);
1666
+ if (t3.isCallExpression(expr)) {
1667
+ const returnExpr = getCallReturnExpression(expr, path);
1668
+ return returnExpr ? expressionContainsArray(returnExpr, path) : false;
1692
1669
  }
1693
- return null;
1670
+ return false;
1694
1671
  }
1695
- function normalizeStyleArrayLikeExpression(expr, path, seen) {
1696
- if (seen.has(expr)) return null;
1697
- seen.add(expr);
1672
+ function normalizeStyleExpression(expr) {
1698
1673
  if (t3.isArrayExpression(expr)) return expr;
1674
+ if (isEmptyObjectExpression(expr)) return t3.arrayExpression([]);
1699
1675
  if (t3.isLogicalExpression(expr) && expr.operator === "&&") {
1700
- const consequent = normalizeStyleArrayLikeExpression(expr.right, path, seen);
1676
+ const consequent = normalizeStyleExpression(expr.right);
1701
1677
  if (!consequent) return null;
1702
1678
  return t3.conditionalExpression(expr.left, consequent, t3.arrayExpression([]));
1703
1679
  }
1704
1680
  if (t3.isLogicalExpression(expr) && (expr.operator === "||" || expr.operator === "??")) {
1705
- const left = normalizeStyleArrayLikeExpression(expr.left, path, seen);
1706
- const right = normalizeStyleArrayLikeBranch(expr.right, path, seen);
1681
+ const left = normalizeStyleExpression(expr.left);
1682
+ const right = normalizeStyleBranch(expr.right);
1707
1683
  if (!left || !right) return null;
1708
1684
  return t3.logicalExpression(expr.operator, left, right);
1709
1685
  }
1710
1686
  if (t3.isConditionalExpression(expr)) {
1711
- const consequent = normalizeStyleArrayLikeBranch(expr.consequent, path, seen);
1712
- const alternate = normalizeStyleArrayLikeBranch(expr.alternate, path, seen);
1687
+ const consequent = normalizeStyleBranch(expr.consequent);
1688
+ const alternate = normalizeStyleBranch(expr.alternate);
1713
1689
  if (!consequent || !alternate) return null;
1714
1690
  return t3.conditionalExpression(expr.test, consequent, alternate);
1715
1691
  }
1716
1692
  if (t3.isIdentifier(expr) || t3.isMemberExpression(expr) || t3.isCallExpression(expr)) {
1717
- const nestedSeen = new Set(seen);
1718
- nestedSeen.delete(expr);
1719
- if (isStyleArrayLike(expr, path, nestedSeen)) return expr;
1693
+ return expr;
1720
1694
  }
1721
1695
  return null;
1722
1696
  }
1723
- function normalizeStyleArrayLikeBranch(expr, path, seen) {
1724
- if (isEmptyObjectExpression(expr)) {
1725
- return t3.arrayExpression([]);
1726
- }
1697
+ function normalizeStyleBranch(expr) {
1698
+ if (isEmptyObjectExpression(expr)) return t3.arrayExpression([]);
1727
1699
  if (t3.isObjectExpression(expr)) {
1728
- return tryBuildStyleArrayFromObjectExpression(expr, path).rewritten;
1729
- }
1730
- return normalizeStyleArrayLikeExpression(expr, path, seen);
1731
- }
1732
- function isStyleArrayLike(expr, path, seen) {
1733
- if (seen.has(expr)) return false;
1734
- seen.add(expr);
1735
- if (t3.isArrayExpression(expr)) return true;
1736
- if (t3.isLogicalExpression(expr) && expr.operator === "&&") {
1737
- return isStyleArrayLike(expr.right, path, seen);
1738
- }
1739
- if (t3.isLogicalExpression(expr) && (expr.operator === "||" || expr.operator === "??")) {
1740
- return isStyleArrayLike(expr.left, path, seen) && isStyleArrayLikeBranch(expr.right, path, seen);
1741
- }
1742
- if (t3.isConditionalExpression(expr)) {
1743
- return isStyleArrayLikeBranch(expr.consequent, path, seen) && isStyleArrayLikeBranch(expr.alternate, path, seen);
1744
- }
1745
- if (t3.isIdentifier(expr)) {
1746
- const possibleValues = resolvePossibleStyleValues(expr, path, new Set(seen));
1747
- if (possibleValues) {
1748
- return possibleValues.every(function(value) {
1749
- return isStyleArrayLike(value, path, new Set(seen));
1750
- });
1751
- }
1752
- const binding = path.scope.getBinding(expr.name);
1753
- const bindingPath = binding?.path;
1754
- if (!bindingPath || !bindingPath.isVariableDeclarator()) return false;
1755
- const init = bindingPath.node.init;
1756
- return !!(init && isStyleArrayLike(init, bindingPath, seen));
1757
- }
1758
- if (t3.isCallExpression(expr)) {
1759
- const possibleValues = resolvePossibleStyleValues(expr, path, new Set(seen));
1760
- if (possibleValues) {
1761
- return possibleValues.every(function(value) {
1762
- return isStyleArrayLike(value, path, new Set(seen));
1763
- });
1764
- }
1765
- const returnExpr = getCallStyleArrayLikeExpression(expr, path);
1766
- return returnExpr ? isStyleArrayLike(returnExpr, path, seen) : true;
1767
- }
1768
- if (t3.isMemberExpression(expr)) {
1769
- const possibleValues = resolvePossibleStyleValues(expr, path, new Set(seen));
1770
- if (possibleValues) {
1771
- return possibleValues.every(function(value) {
1772
- return isStyleArrayLike(value, path, new Set(seen));
1773
- });
1774
- }
1775
- const object = expr.object;
1776
- if (!t3.isIdentifier(object)) return false;
1777
- const binding = path.scope.getBinding(object.name);
1778
- const bindingPath = binding?.path;
1779
- if (!bindingPath || !bindingPath.isVariableDeclarator()) return false;
1780
- const init = bindingPath.node.init;
1781
- if (!init || !t3.isObjectExpression(init)) return false;
1782
- const propertyName = getStaticMemberPropertyName(expr, path);
1783
- if (!propertyName) return false;
1784
- for (const prop of init.properties) {
1785
- if (!t3.isObjectProperty(prop) || prop.computed) continue;
1786
- if (!isMatchingPropertyName(prop.key, propertyName)) continue;
1787
- const value = prop.value;
1788
- return t3.isExpression(value) && isStyleArrayLike(value, bindingPath, seen);
1700
+ if (expr.properties.length === 0) return t3.arrayExpression([]);
1701
+ const allSpreads = expr.properties.every(function(p) {
1702
+ return t3.isSpreadElement(p);
1703
+ });
1704
+ if (!allSpreads) return null;
1705
+ const elements = [];
1706
+ for (const prop of expr.properties) {
1707
+ const spread = prop;
1708
+ const normalized = normalizeStyleExpression(spread.argument);
1709
+ if (!normalized) return null;
1710
+ if (t3.isArrayExpression(normalized)) {
1711
+ elements.push(...normalized.elements);
1712
+ } else {
1713
+ elements.push(t3.spreadElement(buildSafeSpreadArgument(normalized)));
1714
+ }
1789
1715
  }
1716
+ return t3.arrayExpression(elements);
1790
1717
  }
1791
- return false;
1718
+ return normalizeStyleExpression(expr);
1792
1719
  }
1793
- function isKnownStyleArrayLike(expr, path, seen) {
1794
- if (seen.has(expr)) return false;
1795
- seen.add(expr);
1796
- if (t3.isArrayExpression(expr)) return true;
1797
- if (t3.isLogicalExpression(expr) && expr.operator === "&&") {
1798
- return isKnownStyleArrayLike(expr.right, path, seen);
1799
- }
1800
- if (t3.isLogicalExpression(expr) && (expr.operator === "||" || expr.operator === "??")) {
1801
- return isKnownStyleArrayLike(expr.left, path, seen) && isStyleArrayLikeBranch(expr.right, path, seen);
1802
- }
1803
- if (t3.isConditionalExpression(expr)) {
1804
- return isStyleArrayLikeBranch(expr.consequent, path, seen) && isStyleArrayLikeBranch(expr.alternate, path, seen);
1805
- }
1806
- if (t3.isIdentifier(expr)) {
1807
- const possibleValues = resolvePossibleStyleValues(expr, path, new Set(seen));
1808
- if (possibleValues) {
1809
- return possibleValues.every(function(value) {
1810
- return isKnownStyleArrayLike(value, path, new Set(seen));
1811
- });
1812
- }
1813
- const binding = path.scope.getBinding(expr.name);
1814
- const bindingPath = binding?.path;
1815
- if (!bindingPath || !bindingPath.isVariableDeclarator()) return false;
1816
- const init = bindingPath.node.init;
1817
- return !!(init && isKnownStyleArrayLike(init, bindingPath, seen));
1818
- }
1819
- if (t3.isCallExpression(expr)) {
1820
- const possibleValues = resolvePossibleStyleValues(expr, path, new Set(seen));
1821
- if (possibleValues) {
1822
- return possibleValues.every(function(value) {
1823
- return isKnownStyleArrayLike(value, path, new Set(seen));
1824
- });
1825
- }
1826
- const returnExpr = getCallStyleArrayLikeExpression(expr, path);
1827
- return !!(returnExpr && isKnownStyleArrayLike(returnExpr, path, seen));
1828
- }
1829
- if (t3.isMemberExpression(expr)) {
1830
- const possibleValues = resolvePossibleStyleValues(expr, path, new Set(seen));
1831
- if (possibleValues) {
1832
- return possibleValues.every(function(value) {
1833
- return isKnownStyleArrayLike(value, path, new Set(seen));
1834
- });
1835
- }
1836
- const object = expr.object;
1837
- if (!t3.isIdentifier(object)) return false;
1838
- const binding = path.scope.getBinding(object.name);
1839
- const bindingPath = binding?.path;
1840
- if (!bindingPath || !bindingPath.isVariableDeclarator()) return false;
1841
- const init = bindingPath.node.init;
1842
- if (!init || !t3.isObjectExpression(init)) return false;
1843
- const propertyName = getStaticMemberPropertyName(expr, path);
1844
- if (!propertyName) return false;
1845
- for (const prop of init.properties) {
1846
- if (!t3.isObjectProperty(prop) || prop.computed) continue;
1847
- if (!isMatchingPropertyName(prop.key, propertyName)) continue;
1848
- const value = prop.value;
1849
- return t3.isExpression(value) && isKnownStyleArrayLike(value, bindingPath, seen);
1850
- }
1851
- }
1852
- return false;
1720
+ function isCssSpreadCall(expr, cssBindingName) {
1721
+ return t3.isMemberExpression(expr.callee) && !expr.callee.computed && t3.isIdentifier(expr.callee.object, { name: cssBindingName }) && t3.isIdentifier(expr.callee.property, { name: "spread" });
1853
1722
  }
1854
- function isStyleArrayLikeBranch(expr, path, seen) {
1855
- return isEmptyObjectExpression(expr) || isStyleArrayLike(expr, path, seen);
1723
+ function unwrapStyleObjectExpression(expr) {
1724
+ if (t3.isObjectExpression(expr)) return expr;
1725
+ if (t3.isTSAsExpression(expr) || t3.isTSSatisfiesExpression(expr) || t3.isTSNonNullExpression(expr)) {
1726
+ return unwrapStyleObjectExpression(expr.expression);
1727
+ }
1728
+ return null;
1856
1729
  }
1857
1730
  function isMatchingPropertyName(key, name) {
1858
1731
  return t3.isIdentifier(key) && key.name === name || t3.isStringLiteral(key) && key.value === name;
@@ -1860,18 +1733,10 @@ function isMatchingPropertyName(key, name) {
1860
1733
  function isEmptyObjectExpression(expr) {
1861
1734
  return t3.isObjectExpression(expr) && expr.properties.length === 0;
1862
1735
  }
1863
- function buildUnknownObjectSpreadFallback(expr, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1736
+ function buildUnknownSpreadFallback(expr, asStyleArrayHelperName, needsAsStyleArrayHelper) {
1864
1737
  needsAsStyleArrayHelper.current = true;
1865
1738
  return t3.callExpression(t3.identifier(asStyleArrayHelperName), [expr]);
1866
1739
  }
1867
- function buildInlineAsStyleArrayExpression(expr) {
1868
- return t3.conditionalExpression(
1869
- t3.callExpression(t3.memberExpression(t3.identifier("Array"), t3.identifier("isArray")), [expr]),
1870
- expr,
1871
- t3.conditionalExpression(expr, t3.arrayExpression([expr]), t3.arrayExpression([]))
1872
- // I.e. `xss` becomes `[xss]` when truthy
1873
- );
1874
- }
1875
1740
  function buildSafeSpreadArgument(expr) {
1876
1741
  return t3.isConditionalExpression(expr) || t3.isLogicalExpression(expr) ? t3.parenthesizedExpression(expr) : expr;
1877
1742
  }
@@ -1884,14 +1749,13 @@ function getStaticMemberPropertyName(expr, path) {
1884
1749
  }
1885
1750
  if (t3.isIdentifier(expr.property)) {
1886
1751
  const binding = path.scope.getBinding(expr.property.name);
1887
- const bindingPath = binding?.path;
1888
- if (!bindingPath || !bindingPath.isVariableDeclarator()) return null;
1889
- const init = bindingPath.node.init;
1752
+ if (!binding?.path.isVariableDeclarator()) return null;
1753
+ const init = binding.path.node.init;
1890
1754
  return t3.isStringLiteral(init) ? init.value : null;
1891
1755
  }
1892
1756
  return null;
1893
1757
  }
1894
- function getCallStyleArrayLikeExpression(expr, path) {
1758
+ function getCallReturnExpression(expr, path) {
1895
1759
  const localReturnExpr = getLocalFunctionReturnExpression(expr, path);
1896
1760
  if (localReturnExpr) return localReturnExpr;
1897
1761
  const firstArg = expr.arguments[0];
@@ -1900,57 +1764,15 @@ function getCallStyleArrayLikeExpression(expr, path) {
1900
1764
  }
1901
1765
  return null;
1902
1766
  }
1903
- function resolvePossibleStyleValues(expr, path, seen) {
1904
- if (seen.has(expr)) return null;
1905
- seen.add(expr);
1906
- if (t3.isObjectExpression(expr) || t3.isArrayExpression(expr)) {
1907
- return [expr];
1908
- }
1909
- if (t3.isIdentifier(expr)) {
1910
- const binding = path.scope.getBinding(expr.name);
1911
- const bindingPath = binding?.path;
1912
- if (!bindingPath || !bindingPath.isVariableDeclarator()) return null;
1913
- const init = bindingPath.node.init;
1914
- return init && t3.isExpression(init) ? resolvePossibleStyleValues(init, bindingPath, seen) : null;
1915
- }
1916
- if (t3.isCallExpression(expr)) {
1917
- const returnExpr = getCallStyleArrayLikeExpression(expr, path);
1918
- return returnExpr ? resolvePossibleStyleValues(returnExpr, path, seen) : null;
1919
- }
1920
- if (t3.isMemberExpression(expr)) {
1921
- const object = expr.object;
1922
- if (!t3.isExpression(object)) return null;
1923
- const objectValues = resolvePossibleStyleValues(object, path, seen);
1924
- if (!objectValues) return null;
1925
- const propertyName = getStaticMemberPropertyName(expr, path);
1926
- const values = [];
1927
- for (const objectValue of objectValues) {
1928
- if (!t3.isObjectExpression(objectValue)) continue;
1929
- for (const prop of objectValue.properties) {
1930
- if (!t3.isObjectProperty(prop) || prop.computed || !t3.isExpression(prop.value)) continue;
1931
- if (propertyName) {
1932
- if (isMatchingPropertyName(prop.key, propertyName)) {
1933
- values.push(prop.value);
1934
- }
1935
- } else {
1936
- values.push(prop.value);
1937
- }
1938
- }
1939
- }
1940
- return values.length > 0 ? values : null;
1941
- }
1942
- return null;
1943
- }
1944
1767
  function getLocalFunctionReturnExpression(expr, path) {
1945
1768
  if (!t3.isIdentifier(expr.callee)) return null;
1946
1769
  const binding = path.scope.getBinding(expr.callee.name);
1947
- const bindingPath = binding?.path;
1948
- if (!bindingPath) return null;
1949
- if (bindingPath.isFunctionDeclaration()) {
1950
- return getFunctionLikeReturnExpression(bindingPath.node);
1770
+ if (!binding) return null;
1771
+ if (binding.path.isFunctionDeclaration()) {
1772
+ return getFunctionLikeReturnExpression(binding.path.node);
1951
1773
  }
1952
- if (bindingPath.isVariableDeclarator()) {
1953
- const init = bindingPath.node.init;
1774
+ if (binding.path.isVariableDeclarator()) {
1775
+ const init = binding.path.node.init;
1954
1776
  if (init && (t3.isArrowFunctionExpression(init) || t3.isFunctionExpression(init))) {
1955
1777
  return getFunctionLikeReturnExpression(init);
1956
1778
  }