use `CallSite` reflection to get some information out of `specifications` (WIP)

This commit is contained in:
Jos de Jong 2023-02-02 16:14:25 +01:00
parent 86688ca129
commit 946b4a495f
1 changed files with 19 additions and 13 deletions

View File

@ -1,7 +1,7 @@
import 'reflect-metadata'
import {Dispatcher} from './core/Dispatcher.js'
import * as Specifications from './all.js'
import * as specifications from './all.js'
import {Complex} from './Complex/type.js'
import {absquare as absquare_complex} from './Complex/arithmetic.js'
@ -58,24 +58,29 @@ console.log('parameter names', reflect(createFunction).parameters.map(parameter
// @ts-ignore
console.log('parameterTypes[0]', (reflect(createFunction).parameterTypes[0] as ReflectedObjectRef)._ref.m)
// TODO: more specific definition of Specifications
type Specifications = Record<string, Record<string, unknown>>
console.log()
console.log('CallSite')
function foo<T>(call? : CallSite) {
console.log(reflect(call).typeParameters[0].isClass(String))
function reflectSpecifications<T>(specifications: Specifications, callSite? : CallSite) {
console.log('specifications', reflect(callSite).parameters[0])
// @ts-ignore
console.log('specifications', reflect(callSite).parameters[0]._ref) // shows 'numbers', 'Complex, 'complex', 'generic'
// @ts-ignore
console.log('specifications', reflect(callSite).parameters[0]._ref.m
.find(item => item.n === 'generic').t.m) // shows 'square', 'unequal'
// @ts-ignore
console.log('specifications', reflect(callSite).parameters[0]._ref.m
.find(item => item.n === 'generic').t.m
.find(item => item.n === 'square').t.p) // [ { n: 'dep', t: [Function: t], b: undefined, v: null } ]
// @ts-ignore
// FIXME: now, we should be able to get the signature of the multiply dependency of the function square, but how?
}
function bar<T>(call? : CallSite) {
foo<T>();
}
bar<String>();
// FIXME: get all types out of Specifications
// console.log('Specifications', reflect(Specifications)) // Throws errors
reflectSpecifications<Specifications>(specifications);
// TODO: import all specificiations (turned off for debugging purposes)
// TODO: import all specifications (turned off for debugging purposes)
// export default new Dispatcher(Specifications)
@ -90,4 +95,5 @@ const quatAbsquare = absquare_complex({
const myabs = quatAbsquare({re: {re: 0, im: 1}, im: {re:2, im: 3}})
const typeTest: typeof myabs = 7 // check myabs is just a number
console.log()
console.log('Result is', myabs)