use CallSite
reflection to get some information out of specifications
(WIP)
This commit is contained in:
parent
86688ca129
commit
946b4a495f
32
src/index.ts
32
src/index.ts
@ -1,7 +1,7 @@
|
|||||||
import 'reflect-metadata'
|
import 'reflect-metadata'
|
||||||
|
|
||||||
import {Dispatcher} from './core/Dispatcher.js'
|
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 {Complex} from './Complex/type.js'
|
||||||
import {absquare as absquare_complex} from './Complex/arithmetic.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
|
// @ts-ignore
|
||||||
console.log('parameterTypes[0]', (reflect(createFunction).parameterTypes[0] as ReflectedObjectRef)._ref.m)
|
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()
|
||||||
console.log('CallSite')
|
console.log('CallSite')
|
||||||
function foo<T>(call? : CallSite) {
|
function reflectSpecifications<T>(specifications: Specifications, callSite? : CallSite) {
|
||||||
console.log(reflect(call).typeParameters[0].isClass(String))
|
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?
|
||||||
}
|
}
|
||||||
|
reflectSpecifications<Specifications>(specifications);
|
||||||
function bar<T>(call? : CallSite) {
|
|
||||||
foo<T>();
|
|
||||||
}
|
|
||||||
bar<String>();
|
|
||||||
|
|
||||||
// FIXME: get all types out of Specifications
|
|
||||||
// console.log('Specifications', reflect(Specifications)) // Throws errors
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: import all specificiations (turned off for debugging purposes)
|
// TODO: import all specifications (turned off for debugging purposes)
|
||||||
// export default new Dispatcher(Specifications)
|
// 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 myabs = quatAbsquare({re: {re: 0, im: 1}, im: {re:2, im: 3}})
|
||||||
const typeTest: typeof myabs = 7 // check myabs is just a number
|
const typeTest: typeof myabs = 7 // check myabs is just a number
|
||||||
|
|
||||||
|
console.log()
|
||||||
console.log('Result is', myabs)
|
console.log('Result is', myabs)
|
||||||
|
Loading…
Reference in New Issue
Block a user