From 946b4a495f7c64190e7ac763e05df7a2304e583f Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 2 Feb 2023 16:14:25 +0100 Subject: [PATCH] use `CallSite` reflection to get some information out of `specifications` (WIP) --- src/index.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 13c39fa..ce04c21 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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> console.log() console.log('CallSite') -function foo(call? : CallSite) { - console.log(reflect(call).typeParameters[0].isClass(String)) +function reflectSpecifications(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(call? : CallSite) { - foo(); -} -bar(); - -// FIXME: get all types out of Specifications -// console.log('Specifications', reflect(Specifications)) // Throws errors +reflectSpecifications(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)