/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * * * Shared visitor helpers for the unstable_defineVarsNested / unstable_defineConstsNested / * unstable_createThemeNested visitors. These extract common patterns (call detection, * validation, eval config setup) to avoid duplication across the 3 nested visitors. * * NOTE: These helpers only serve the NEW nested visitors. The existing flat visitors * (stylex-define-vars.js, stylex-define-consts.js, stylex-create-theme.js) are untouched. */ import type { NodePath } from '@babel/traverse'; import type { FunctionConfig } from '../utils/evaluate-path'; import type { InjectableStyle } from '../shared'; import * as t from '@babel/types'; import StateManager from '../utils/state-manager'; /** * Detects if a CallExpression matches a StyleX API call. * Handles both import patterns: * - Named import: import { unstable_defineVarsNested } from '@stylexjs/stylex'; * unstable_defineVarsNested({...}) * - Member expression: import stylex from '@stylexjs/stylex'; * stylex.unstable_defineVarsNested({...}) * * @param node - The CallExpression AST node * @param importSet - Set of local names from named imports (e.g., state.stylexDefineVarsNestedImport) * @param memberName - The property name to match on member expressions (e.g., 'unstable_defineVarsNested') * @param stylexImport - Set of local names for the default/namespace import (e.g., state.stylexImport) */ export declare function isCallTo( node: t.CallExpression, importSet: Set, memberName: string, stylexImport: Set, ): boolean; /** * Validates a StyleX define/createTheme call expression. * Checks: * 1. The call is assigned to a variable declarator with an Identifier name * 2. The variable is a named export (when requireExport=true — used by defineVars/defineConsts) * 3. The call has exactly `argCount` arguments * * Throws a SyntaxError with a code frame pointing to the call site on failure. * * @param callExpressionPath - Babel NodePath for the CallExpression * @param apiName - API name for error messages (e.g., 'unstable_defineVarsNested') * @param argCount - Expected number of arguments (1 for define*, 2 for createTheme) * @param requireExport - Whether the variable must be a named export (default: true) */ export declare function validateDefineCall( callExpressionPath: NodePath, apiName: string, argCount: number, requireExport?: boolean, ): void; /** * Builds the evaluation config for statically resolving special StyleX functions * within defineVarsNested/createThemeNested arguments. * * This enables nested token objects to contain: * - stylex.keyframes({...}) → resolved to animation name string * - stylex.positionTry({...}) → resolved to position-try name string * - stylex.types.color({...}) → resolved to CSSType instance * - stylex.env.* → resolved to compile-time constant * * The returned { identifiers, memberExpressions } maps are passed to the * evaluate() function which uses them to resolve these calls at compile time. * * @param state - The StateManager with import tracking info * @param otherInjectedCSSRules - Accumulator for CSS rules generated by keyframes/positionTry * @returns { identifiers, memberExpressions } for the evaluate() function */ export declare function buildEvalConfig( state: StateManager, otherInjectedCSSRules: { [$$Key$$: string]: InjectableStyle }, ): { identifiers: FunctionConfig['identifiers']; memberExpressions: FunctionConfig['memberExpressions']; };