Skip to content

Commit 87fbf8e

Browse files
cursoragentskovhus
andcommitted
refactor: extract markDeclNeedsUseThemeHook to shared types module
Consolidate the duplicated __runtimeCall needsUseThemeHook pattern into a single shared helper in types.ts, removing local copies from inline-style-props.ts and rule-interpolated-declaration.ts. Co-authored-by: Kenneth Skovhus <skovhus@users.noreply.github.com>
1 parent 9d407ec commit 87fbf8e

File tree

3 files changed

+21
-40
lines changed

3 files changed

+21
-40
lines changed

src/internal/lower-rules/inline-style-props.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { buildPseudoMediaPropValue } from "./variant-utils.js";
2121
import { extractStaticPartsForDecl } from "./interpolations.js";
2222
import { cssDeclarationToStylexDeclarations } from "../css-prop-mapping.js";
2323
import { isStylexShorthandCamelCase } from "../stylex-shorthands.js";
24-
import { ensureShouldForwardPropDrop } from "./types.js";
24+
import { ensureShouldForwardPropDrop, markDeclNeedsUseThemeHook } from "./types.js";
2525
import { cloneAstNode, getFunctionBodyExpr } from "../utilities/jscodeshift-utils.js";
2626
import { cssPropertyToIdentifier, makeCssPropKey } from "./shared.js";
2727
import { styleKeyWithSuffix } from "../transform/helpers.js";
@@ -366,17 +366,3 @@ export function handleInlineStyleValueFromProps(ctx: InlineStyleFromPropsContext
366366
function hasSimpleIdentifierParam(expr: { params?: Array<{ type?: string }> }): boolean {
367367
return expr.params?.length === 1 && expr.params[0]?.type === "Identifier";
368368
}
369-
370-
function markDeclNeedsUseThemeHook(decl: StyledDecl): void {
371-
if (!decl.needsUseThemeHook) {
372-
decl.needsUseThemeHook = [];
373-
}
374-
if (!decl.needsUseThemeHook.some((entry) => entry.themeProp === "__runtimeCall")) {
375-
decl.needsUseThemeHook.push({
376-
themeProp: "__runtimeCall",
377-
trueStyleKey: null,
378-
falseStyleKey: null,
379-
});
380-
}
381-
decl.needsWrapperComponent = true;
382-
}

src/internal/lower-rules/rule-interpolated-declaration.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ import {
3636
tryHandleInterpolatedStringValue,
3737
wrapExprWithStaticParts,
3838
} from "./interpolations.js";
39-
import { ensureShouldForwardPropDrop, literalToStaticValue } from "./types.js";
39+
import {
40+
ensureShouldForwardPropDrop,
41+
literalToStaticValue,
42+
markDeclNeedsUseThemeHook,
43+
} from "./types.js";
4044
import {
4145
buildTemplateWithStaticParts,
4246
collectPropsFromArrowFn,
@@ -232,16 +236,7 @@ export function handleInterpolatedDeclaration(args: InterpolatedDeclarationConte
232236
: baseRuntimeExpr;
233237

234238
if (hasThemeAccess) {
235-
if (!decl.needsUseThemeHook) {
236-
decl.needsUseThemeHook = [];
237-
}
238-
if (!decl.needsUseThemeHook.some((entry) => entry.themeProp === "__runtimeCall")) {
239-
decl.needsUseThemeHook.push({
240-
themeProp: "__runtimeCall",
241-
trueStyleKey: null,
242-
falseStyleKey: null,
243-
});
244-
}
239+
markDeclNeedsUseThemeHook(decl);
245240
}
246241

247242
const outs = cssDeclarationToStylexDeclarations(d);
@@ -2804,20 +2799,6 @@ function tryHandleMultiSlotTernary(ctx: DeclProcessingState, d: CssDeclarationIR
28042799
return true;
28052800
}
28062801

2807-
function markDeclNeedsUseThemeHook(decl: StyledDecl): void {
2808-
if (!decl.needsUseThemeHook) {
2809-
decl.needsUseThemeHook = [];
2810-
}
2811-
if (!decl.needsUseThemeHook.some((entry) => entry.themeProp === "__runtimeCall")) {
2812-
decl.needsUseThemeHook.push({
2813-
themeProp: "__runtimeCall",
2814-
trueStyleKey: null,
2815-
falseStyleKey: null,
2816-
});
2817-
}
2818-
decl.needsWrapperComponent = true;
2819-
}
2820-
28212802
/** CSS shorthand properties that cannot be represented as a single var() custom property. */
28222803
const UNSUPPORTED_CUSTOM_PROP_SHORTHANDS = new Set([
28232804
"border",

src/internal/lower-rules/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ import type { StyledDecl } from "../transform-types.js";
66

77
export { literalToStaticValue } from "../utilities/jscodeshift-utils.js";
88

9+
export function markDeclNeedsUseThemeHook(decl: StyledDecl): void {
10+
if (!decl.needsUseThemeHook) {
11+
decl.needsUseThemeHook = [];
12+
}
13+
if (!decl.needsUseThemeHook.some((entry) => entry.themeProp === "__runtimeCall")) {
14+
decl.needsUseThemeHook.push({
15+
themeProp: "__runtimeCall",
16+
trueStyleKey: null,
17+
falseStyleKey: null,
18+
});
19+
}
20+
decl.needsWrapperComponent = true;
21+
}
22+
923
export function ensureShouldForwardPropDrop(decl: StyledDecl, propName: string): void {
1024
// Ensure we generate a wrapper so we can consume the styling prop without forwarding it to DOM.
1125
decl.needsWrapperComponent = true;

0 commit comments

Comments
 (0)