( fn: FunctionNode, index: number, module: SourceModule, kindOfKey: KindOfKey )
| 3011 | // e.g. `item` in `<SearchableSelect.Root items={opts} getSearchFields={item => [item.label]} />` |
| 3012 | // or `<SearchableSelect.EachItem<Opt>>{({ item }) => item.label}</SearchableSelect.EachItem>` |
| 3013 | private jsxCallbackParamKindOf( |
| 3014 | fn: FunctionNode, |
| 3015 | index: number, |
| 3016 | module: SourceModule, |
| 3017 | kindOfKey: KindOfKey |
| 3018 | ): KindBits | undefined { |
| 3019 | let [operand, container] = operatorOf(fn) |
| 3020 | while ( |
| 3021 | (container?.type === "ConditionalExpression" && |
| 3022 | (container.consequent === operand || |
| 3023 | container.alternate === operand)) || |
| 3024 | (container?.type === "LogicalExpression" && container.right === operand) |
| 3025 | ) |
| 3026 | [operand, container] = operatorOf(container) |
| 3027 | if (container?.type !== "JSXExpressionContainer") return |
| 3028 | const parent = container.parent |
| 3029 | let opening: JSXOpeningElement | undefined |
| 3030 | let propName: string | undefined |
| 3031 | if ( |
| 3032 | parent?.type === "JSXAttribute" && |
| 3033 | parent.name.type === "JSXIdentifier" && |
| 3034 | parent.parent?.type === "JSXOpeningElement" |
| 3035 | ) { |
| 3036 | opening = parent.parent |
| 3037 | propName = parent.name.name |
| 3038 | } else if (parent?.type === "JSXElement") { |
| 3039 | opening = parent.openingElement |
| 3040 | propName = "children" |
| 3041 | } |
| 3042 | if (!opening || !propName) return |
| 3043 | const component = this.jsxComponentOf(opening.name, module, kindOfKey) |
| 3044 | if (!component) return |
| 3045 | const [compFn, compModule] = component |
| 3046 | const propsParam = this.componentPropsParamOf(compFn, compModule) |
| 3047 | if (!propsParam) return |
| 3048 | const [propsNode, propsContext, propsModule] = propsParam |
| 3049 | const typeParams = compFn.typeParameters?.params ?? [] |
| 3050 | const compTypeArgs = new Map<TSTypeParameter, KindBits | undefined>() |
| 3051 | const explicitArgs = opening.typeArguments?.params ?? [] |
| 3052 | for (let i = 0; i < typeParams.length; i++) { |
| 3053 | if (explicitArgs[i]) { |
| 3054 | compTypeArgs.set( |
| 3055 | typeParams[i], |
| 3056 | this.typeKindOf(explicitArgs[i], opening, module, kindOfKey, 0) |
| 3057 | ) |
| 3058 | } |
| 3059 | } |
| 3060 | const unbound = new Set( |
| 3061 | typeParams.filter(param => !compTypeArgs.has(param)) |
| 3062 | ) |
| 3063 | if (unbound.size) { |
| 3064 | const hasUnsafeSpread = opening.attributes.some( |
| 3065 | attr => |
| 3066 | attr.type === "JSXSpreadAttribute" && |
| 3067 | this.transfer(attr.argument, module, kindOfKey) !== kinds.data |
| 3068 | ) |
| 3069 | if (!hasUnsafeSpread) { |
| 3070 | const inferred = new Map<TSTypeParameter, KindBits>() |
no test coverage detected