Compare commits
3 Commits
ts-macros-
...
main
Author | SHA1 | Date |
---|---|---|
Jos de Jong | 6bfd06cafb | |
Jos de Jong | 0cdc9aba78 | |
Glen Whitney | 40146c2f48 |
|
@ -1,4 +1,4 @@
|
||||||
export type FunctionDef {
|
export type FunctionDef = {
|
||||||
name: string,
|
name: string,
|
||||||
aliasOf?: string,
|
aliasOf?: string,
|
||||||
signatures: Array<{
|
signatures: Array<{
|
||||||
|
@ -11,6 +11,7 @@ export type FunctionDef {
|
||||||
export type ImplementationDef = {
|
export type ImplementationDef = {
|
||||||
fn: FunctionDef,
|
fn: FunctionDef,
|
||||||
dependencies: Record<string, FunctionDef>
|
dependencies: Record<string, FunctionDef>
|
||||||
|
genericParameter: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +24,11 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme
|
||||||
const [factoryArgs, fnsClause] = split(reflectedType, '=>', 2).map(trim)
|
const [factoryArgs, fnsClause] = split(reflectedType, '=>', 2).map(trim)
|
||||||
const fn = parseAlias(name, fnsClause)
|
const fn = parseAlias(name, fnsClause)
|
||||||
|
|
||||||
|
// extract the generic parameter like '<T>' at the start of the type
|
||||||
|
const genericParameter = factoryArgs.trim().startsWith('<')
|
||||||
|
? findBlockContents(factoryArgs, '<', '>')?.innerText || null
|
||||||
|
: null
|
||||||
|
|
||||||
const factoryArgsInner = findBlockContents(factoryArgs, '(', ')')
|
const factoryArgsInner = findBlockContents(factoryArgs, '(', ')')
|
||||||
const depArg = split(factoryArgsInner.innerText, ':').map(trim)[1]
|
const depArg = split(factoryArgsInner.innerText, ':').map(trim)[1]
|
||||||
const depArgBlocks: string[] = depArg ? split(depArg, '&').map(trim) : []
|
const depArgBlocks: string[] = depArg ? split(depArg, '&').map(trim) : []
|
||||||
|
@ -39,7 +45,7 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme
|
||||||
|
|
||||||
const dependencies: Record<string, FunctionDef> = groupBy(deps, 'name')
|
const dependencies: Record<string, FunctionDef> = groupBy(deps, 'name')
|
||||||
|
|
||||||
return {fn, dependencies}
|
return {fn, dependencies, genericParameter }
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDependencies(deps: string): FunctionDef[] {
|
function parseDependencies(deps: string): FunctionDef[] {
|
||||||
|
|
Loading…
Reference in New Issue