remove name argument from the reflect function

This commit is contained in:
Jos de Jong 2023-09-08 14:10:03 +02:00
parent 26631febf9
commit 7fc9d2a2f3
3 changed files with 6 additions and 6 deletions

View File

@ -1,10 +1,10 @@
export function typed<T>(name: string, types: string, arg: T) : T {
export function $reflect<T>(types: string, arg: T) : T {
// TODO: implement typed-function for real
if (types === '__infer__') {
console.error('__infer__ should be replaced with runtime type information by the TypeScript plugin')
}
console.log(`TYPED-FUNCTION: Creating function "${name}" with types ${types}`)
console.log(`INFER: Creating function with types ${types}`)
// TODO: here we can now turn the inputs into a real typed-function with a signature
return arg

View File

@ -1,6 +1,6 @@
import { typed } from '../core/typed.js'
import { $reflect } from '../core/$reflect.js'
export const square = typed('square', '__infer__', <T>(dep: {
export const square = $reflect('__infer__', <T>(dep: {
multiply: (a: T, b: T) => T,
unaryMinus: (x: T) => T, // just for the experiment
}): (a: T) => T =>

View File

@ -13,13 +13,13 @@ const transformer: ts.TransformerFactory<ts.SourceFile> = context => {
// we're looking for a function call like typed('name', '__infer__', deps => ...)
const parentNode = node.parent
if (ts.isCallExpression(parentNode) && ts.isIdentifier(parentNode.expression) && parentNode.expression.escapedText === 'typed') {
if (ts.isCallExpression(parentNode) && ts.isIdentifier(parentNode.expression) && parentNode.expression.escapedText === '$reflect') {
// console.log('PARENT')
// console.log(parentNode)
// TODO: validate that argNode is an ArrowFunction
// @ts-ignore
const argNode = parentNode.arguments[2]
const argNode = parentNode.arguments[1]
// @ts-ignore
const returnType = argNode.type.getText(sourceFile)
console.log('PLUGIN: RETURN TYPE')