MCPcopy Create free account
hub / github.com/arktypeio/arktype / jsxComponentOf

Method jsxComponentOf

ark/aot/graph.ts:3179–3229  ·  view source on GitHub ↗
(
		name: Node,
		module: SourceModule,
		kindOfKey: KindOfKey
	)

Source from the content-addressed store, hash-verified

3177 }
3178
3179 private jsxComponentOf(
3180 name: Node,
3181 module: SourceModule,
3182 kindOfKey: KindOfKey
3183 ): [FunctionNode, SourceModule] | undefined {
3184 const props: string[] = []
3185 let root = name
3186 while (root.type === "JSXMemberExpression") {
3187 props.unshift(root.property.name)
3188 root = root.object
3189 }
3190 if (root.type !== "JSXIdentifier" || /^[a-z]/.test(root.name)) return
3191 const binding = module.scopes.byId.get(root)?.binding
3192 if (!binding) return
3193 if (!props.length) return this.componentFunctionOfBinding(binding, module)
3194 let target: ImportTarget =
3195 binding.kind === "import" ?
3196 this.importOf(binding, module)
3197 : { kind: "binding", module, binding, name: binding.name }
3198 for (const prop of props) {
3199 if (target.kind === "namespace")
3200 target = this.exportOf(target.module, prop)
3201 else if (target.kind === "binding" || target.kind === "expression") {
3202 const literal = this.targetLiteralOf(target, kindOfKey, new Set())
3203 const value = literal && this.valueIn(literal, prop)
3204 if (!value) return
3205 const vNode = unwrapChain(value.node)
3206 if (vNode.type === "Identifier") {
3207 const vb = value.module.scopes.byId.get(vNode)?.binding
3208 if (!vb) return
3209 target =
3210 vb.kind === "import" ?
3211 this.importOf(vb, value.module)
3212 : {
3213 kind: "binding",
3214 module: value.module,
3215 binding: vb,
3216 name: vb.name
3217 }
3218 } else
3219 target = { kind: "expression", module: value.module, node: vNode }
3220 } else return
3221 }
3222 return (
3223 target.kind === "binding" ?
3224 this.componentFunctionOfBinding(target.binding, target.module)
3225 : target.kind === "expression" ?
3226 this.componentFunctionOfNode(target.node, target.module)
3227 : undefined
3228 )
3229 }
3230
3231 private componentFunctionOfBinding(
3232 binding: Binding,

Callers 1

Calls 10

importOfMethod · 0.95
exportOfMethod · 0.95
targetLiteralOfMethod · 0.95
valueInMethod · 0.95
unwrapChainFunction · 0.90
unshiftMethod · 0.80
testMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected