@@ -1636,16 +1636,8 @@ export function createCssHelperConditionalHandler(ctx: CssHelperConditionalConte
16361636 continue ;
16371637 }
16381638
1639- const consResolved = resolveTemplateLiteralBranch ( tplCtx , {
1640- node : split . consTpl as Parameters < typeof resolveTemplateLiteralBranch > [ 1 ] [ "node" ] ,
1641- paramName,
1642- bindings,
1643- } ) ;
1644- const altResolved = resolveTemplateLiteralBranch ( tplCtx , {
1645- node : split . altTpl as Parameters < typeof resolveTemplateLiteralBranch > [ 1 ] [ "node" ] ,
1646- paramName,
1647- bindings,
1648- } ) ;
1639+ const consResolved = resolveTplBranch ( split . consTpl as ExpressionKind ) ;
1640+ const altResolved = resolveTplBranch ( split . altTpl as ExpressionKind ) ;
16491641 if ( ! consResolved || ! altResolved ) {
16501642 skipIndices . add ( split . ternaryIdx ) ;
16511643 continue ;
@@ -1703,97 +1695,72 @@ export function createCssHelperConditionalHandler(ctx: CssHelperConditionalConte
17031695 return false ;
17041696 } ;
17051697
1698+ // Helper to resolve a template literal branch and apply its entries
1699+ const resolveTplBranch = (
1700+ node : ExpressionKind ,
1701+ ) : ReturnType < typeof resolveTemplateLiteralBranch > =>
1702+ resolveTemplateLiteralBranch ( tplCtx , { node : node as any , paramName, bindings } ) ;
1703+
1704+ // Helper to apply all entries (style, dynamic, inline) from a resolved branch
1705+ const applyResolvedEntries = (
1706+ resolved : NonNullable < ReturnType < typeof resolveTemplateLiteralBranch > > ,
1707+ info : TestInfo ,
1708+ when : string ,
1709+ ) : void => {
1710+ if ( Object . keys ( resolved . style ) . length > 0 ) {
1711+ applyVariant ( info , resolved . style ) ;
1712+ }
1713+ if ( resolved . dynamicEntries . length > 0 ) {
1714+ applyDynamicEntries ( resolved . dynamicEntries , when ) ;
1715+ }
1716+ if ( resolved . inlineEntries . length > 0 ) {
1717+ applyInlineEntries ( resolved . inlineEntries , when ) ;
1718+ }
1719+ } ;
1720+
17061721 // Check altIsEmpty BEFORE altIsTpl since empty templates are also template literals
17071722 // and the altIsEmpty case doesn't require invertWhen (which fails for compound conditions)
17081723 if ( consIsTpl && altIsEmpty ) {
17091724 dropAllTestInfoProps ( testInfo ) ;
1710- const consResolved = resolveTemplateLiteralBranch ( tplCtx , {
1711- node : cons as any ,
1712- paramName,
1713- bindings,
1714- } ) ;
1725+ const consResolved = resolveTplBranch ( cons ) ;
17151726 if ( ! consResolved ) {
17161727 // Fallback: try splitting dynamic property name ternaries
17171728 if ( tryResolveDynamicPropertyNameTpl ( cons ) ) {
17181729 return true ;
17191730 }
17201731 return false ;
17211732 }
1722- if ( Object . keys ( consResolved . style ) . length > 0 ) {
1723- applyVariant ( testInfo , consResolved . style ) ;
1724- }
1725- if ( consResolved . dynamicEntries . length > 0 ) {
1726- applyDynamicEntries ( consResolved . dynamicEntries , testInfo . when ) ;
1727- }
1728- if ( consResolved . inlineEntries . length > 0 ) {
1729- applyInlineEntries ( consResolved . inlineEntries , testInfo . when ) ;
1730- }
1733+ applyResolvedEntries ( consResolved , testInfo , testInfo . when ) ;
17311734 return true ;
17321735 }
17331736
17341737 if ( consIsTpl && altIsTpl ) {
17351738 dropAllTestInfoProps ( testInfo ) ;
1736- const consResolved = resolveTemplateLiteralBranch ( tplCtx , {
1737- node : cons as any ,
1738- paramName,
1739- bindings,
1740- } ) ;
1741- const altResolved = resolveTemplateLiteralBranch ( tplCtx , {
1742- node : alt as any ,
1743- paramName,
1744- bindings,
1745- } ) ;
1739+ const consResolved = resolveTplBranch ( cons ) ;
1740+ const altResolved = resolveTplBranch ( alt ) ;
17461741 if ( ! consResolved || ! altResolved ) {
17471742 return false ;
17481743 }
17491744 const invertedWhen = invertWhen ( testInfo . when ) ;
17501745 if ( ! invertedWhen ) {
17511746 return false ;
17521747 }
1753- if ( Object . keys ( consResolved . style ) . length > 0 ) {
1754- applyVariant ( testInfo , consResolved . style ) ;
1755- }
1756- if ( Object . keys ( altResolved . style ) . length > 0 ) {
1757- applyVariant ( { ...testInfo , when : invertedWhen } , altResolved . style ) ;
1758- }
1759- if ( consResolved . dynamicEntries . length > 0 ) {
1760- applyDynamicEntries ( consResolved . dynamicEntries , testInfo . when ) ;
1761- }
1762- if ( altResolved . dynamicEntries . length > 0 ) {
1763- applyDynamicEntries ( altResolved . dynamicEntries , invertedWhen ) ;
1764- }
1765- if ( consResolved . inlineEntries . length > 0 ) {
1766- applyInlineEntries ( consResolved . inlineEntries , testInfo . when ) ;
1767- }
1768- if ( altResolved . inlineEntries . length > 0 ) {
1769- applyInlineEntries ( altResolved . inlineEntries , invertedWhen ) ;
1770- }
1748+ applyResolvedEntries ( consResolved , testInfo , testInfo . when ) ;
1749+ applyResolvedEntries ( altResolved , { ...testInfo , when : invertedWhen } , invertedWhen ) ;
17711750 return true ;
17721751 }
17731752
17741753 if ( consIsEmpty && altIsTpl ) {
17751754 dropAllTestInfoProps ( testInfo ) ;
1776- const altResolved = resolveTemplateLiteralBranch ( tplCtx , {
1777- node : alt as any ,
1778- paramName,
1779- bindings,
1780- } ) ;
1755+ const altResolved = resolveTplBranch ( alt ) ;
17811756 if ( ! altResolved ) {
17821757 return false ;
17831758 }
17841759 const invertedWhen = invertWhen ( testInfo . when ) ;
17851760 if ( ! invertedWhen ) {
17861761 return false ;
17871762 }
1788- if ( Object . keys ( altResolved . style ) . length > 0 ) {
1789- applyVariant ( { ...testInfo , when : invertedWhen } , altResolved . style ) ;
1790- }
1791- if ( altResolved . dynamicEntries . length > 0 ) {
1792- applyDynamicEntries ( altResolved . dynamicEntries , invertedWhen ) ;
1793- }
1794- if ( altResolved . inlineEntries . length > 0 ) {
1795- applyInlineEntries ( altResolved . inlineEntries , invertedWhen ) ;
1796- }
1763+ applyResolvedEntries ( altResolved , { ...testInfo , when : invertedWhen } , invertedWhen ) ;
17971764 return true ;
17981765 }
17991766
0 commit comments