@@ -16,6 +16,10 @@ import {
1616 getArrowFnParamBindings ,
1717 getMemberPathFromIdentifier ,
1818 getNodeLocStart ,
19+ isFunctionNode ,
20+ isIdentifierNamed ,
21+ isNumericTsType ,
22+ patternBindsAnyName ,
1923 resolveIdentifierToPropName ,
2024} from "../utilities/jscodeshift-utils.js" ;
2125import type { DeclProcessingState } from "./decl-setup.js" ;
@@ -130,7 +134,10 @@ export function numericIdentifierSetForJsxProp(
130134 jsxProp : string ,
131135 findJsxPropTsType : ( propName : string ) => unknown ,
132136) : ReadonlySet < string > {
133- if ( jsxProp === "__props" || ! isNumericOrOptionalTsType ( findJsxPropTsType ( jsxProp ) ) ) {
137+ if (
138+ jsxProp === "__props" ||
139+ ! isNumericTsType ( findJsxPropTsType ( jsxProp ) , { allowOptional : true } )
140+ ) {
134141 return new Set ( ) ;
135142 }
136143 const names = new Set ( [ jsxProp ] ) ;
@@ -140,30 +147,6 @@ export function numericIdentifierSetForJsxProp(
140147 return names ;
141148}
142149
143- function isNumericOrOptionalTsType ( tsType : unknown ) : boolean {
144- if ( ! tsType || typeof tsType !== "object" ) {
145- return false ;
146- }
147- const type = tsType as { type ?: string ; types ?: unknown [ ] ; literal ?: { value ?: unknown } } ;
148- if ( type . type === "TSNumberKeyword" ) {
149- return true ;
150- }
151- if ( type . type === "TSLiteralType" ) {
152- return typeof type . literal ?. value === "number" ;
153- }
154- if ( type . type === "TSUnionType" && Array . isArray ( type . types ) ) {
155- return type . types . every ( ( member ) => {
156- const memberType = ( member as { type ?: string } | null ) ?. type ;
157- return (
158- memberType === "TSUndefinedKeyword" ||
159- memberType === "TSNullKeyword" ||
160- isNumericOrOptionalTsType ( member )
161- ) ;
162- } ) ;
163- }
164- return false ;
165- }
166-
167150/**
168151 * Handles dynamic interpolations inside pseudo-elements (::before / ::after / ::placeholder)
169152 * by emitting a StyleX dynamic style function whose body wraps the value in the pseudo-element
@@ -693,7 +676,7 @@ function expressionContainsFunctionBindingName(node: unknown, names: ReadonlySet
693676 }
694677
695678 const record = node as Record < string , unknown > ;
696- if ( isFunctionLikeNode ( record ) ) {
679+ if ( isFunctionNode ( record ) ) {
697680 const params = record . params ;
698681 if ( Array . isArray ( params ) && params . some ( ( param ) => patternBindsAnyName ( param , names ) ) ) {
699682 return true ;
@@ -711,48 +694,6 @@ function expressionContainsFunctionBindingName(node: unknown, names: ReadonlySet
711694 return false ;
712695}
713696
714- function isFunctionLikeNode ( node : Record < string , unknown > ) : boolean {
715- return (
716- node . type === "ArrowFunctionExpression" ||
717- node . type === "FunctionExpression" ||
718- node . type === "FunctionDeclaration" ||
719- node . type === "ObjectMethod" ||
720- node . type === "ClassMethod"
721- ) ;
722- }
723-
724- function patternBindsAnyName ( node : unknown , names : ReadonlySet < string > ) : boolean {
725- if ( ! node || typeof node !== "object" ) {
726- return false ;
727- }
728- const record = node as Record < string , unknown > ;
729- if ( record . type === "Identifier" ) {
730- return typeof record . name === "string" && names . has ( record . name ) ;
731- }
732- if ( record . type === "RestElement" ) {
733- return patternBindsAnyName ( record . argument , names ) ;
734- }
735- if ( record . type === "AssignmentPattern" ) {
736- return patternBindsAnyName ( record . left , names ) ;
737- }
738- if ( record . type === "ObjectPattern" ) {
739- return (
740- Array . isArray ( record . properties ) &&
741- record . properties . some ( ( prop ) => patternBindsAnyName ( prop , names ) )
742- ) ;
743- }
744- if ( record . type === "ObjectProperty" || record . type === "Property" ) {
745- return patternBindsAnyName ( record . value , names ) ;
746- }
747- if ( record . type === "ArrayPattern" ) {
748- return (
749- Array . isArray ( record . elements ) &&
750- record . elements . some ( ( element ) => patternBindsAnyName ( element , names ) )
751- ) ;
752- }
753- return false ;
754- }
755-
756697type DynamicHelperCallResult = {
757698 value : ExpressionKind ;
758699 binding : DynamicHelperCallArgument ;
@@ -1103,10 +1044,6 @@ function getStyledHelperCall(callExpr: CallExpressionLike): StyledHelperCall | n
11031044 } ;
11041045}
11051046
1106- function isIdentifierNamed ( node : ExpressionKind , name : string ) : boolean {
1107- return node ?. type === "Identifier" && node . name === name ;
1108- }
1109-
11101047type NullishLogicalExpression = ExpressionKind & {
11111048 type : "LogicalExpression" ;
11121049 operator : "??" ;
0 commit comments