add another try
This commit is contained in:
parent
94a0737555
commit
ab7fc4450e
3 changed files with 49 additions and 73 deletions
|
@ -35,7 +35,7 @@ const transformer: ts.TransformerFactory<ts.SourceFile> = context => {
|
|||
// WIP
|
||||
// @ts-ignore
|
||||
const type = checker.getTypeAtLocation(paramNode)
|
||||
const paramType = checker.typeToString(type, paramNode, ts.TypeFormatFlags.InTypeAlias)
|
||||
const paramType = checker.typeToString(type, undefined, ts.TypeFormatFlags.InTypeAlias)
|
||||
// const paramType = checker.typeToString(type)
|
||||
// TDOO: get checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration)
|
||||
console.log('PLUGIN: PARAM TYPE STRING', paramType)
|
||||
|
@ -60,10 +60,10 @@ const transformer: ts.TransformerFactory<ts.SourceFile> = context => {
|
|||
// }
|
||||
|
||||
// WIP
|
||||
const type0 = resolveTypeArgumentOfCall(checker, node, 0)
|
||||
// @ts-ignore
|
||||
const typeStr = checker.typeToString(type0);
|
||||
console.log('PLUGIN: RESOLVED TYPE ARGUMENT', typeStr)
|
||||
const type1 = checker.getTypeAtLocation(paramNode)
|
||||
const type2 = checker.getApparentType(type1)
|
||||
const typeStr = checker.typeToString(type2, undefined, ts.TypeFormatFlags.InTypeAlias)
|
||||
console.log('PLUGIN: RESOLVED TYPE ARGUMENT', typeStr) // TODO: not yet working
|
||||
|
||||
const depsAndReturnType = `{ deps: ${paramType}; return: ${returnType} }`
|
||||
|
||||
|
@ -81,34 +81,4 @@ const transformer: ts.TransformerFactory<ts.SourceFile> = context => {
|
|||
}
|
||||
}
|
||||
|
||||
// WIP
|
||||
function resolveTypeArgumentOfCall(checker: ts.TypeChecker, macroCall: ts.CallExpression, typeIndex: number) : ts.Type | undefined {
|
||||
|
||||
// @ts-ignore
|
||||
console.log( 'TEST D', macroCall.arguments[0].typeParameters)
|
||||
|
||||
if (!macroCall.typeArguments || !macroCall.typeArguments[typeIndex]) return;
|
||||
const type = checker.getTypeAtLocation(macroCall.typeArguments[typeIndex]);
|
||||
|
||||
console.log( 'TEST A', type, macroCall.typeArguments )
|
||||
|
||||
return type
|
||||
|
||||
// const lastMacroCall = this.getLastMacro();
|
||||
// if (!lastMacroCall) return type;
|
||||
// if (type.isTypeParameter()) {
|
||||
// const resolvedTypeParameterIndex = lastMacroCall.macro.typeParams.findIndex(arg => this.checker.getTypeAtLocation(arg) === type);
|
||||
// if (resolvedTypeParameterIndex === -1) return;
|
||||
// if (lastMacroCall.call && ts.isCallExpression(lastMacroCall.call)) {
|
||||
// const resolvedTypeParam = lastMacroCall.call.typeArguments?.[resolvedTypeParameterIndex];
|
||||
// if (!resolvedTypeParam) return resolveTypeArguments(this.checker, lastMacroCall.call)[resolvedTypeParameterIndex];
|
||||
// return this.checker.getTypeAtLocation(resolvedTypeParam);
|
||||
// } else return;
|
||||
// } else {
|
||||
// const allParams = lastMacroCall.macro.typeParams.map(p => this.checker.getTypeAtLocation(p));
|
||||
// const replacementTypes = resolveTypeArguments(this.checker, lastMacroCall.call as ts.CallExpression);
|
||||
// return resolveTypeWithTypeParams(type, allParams, replacementTypes);
|
||||
// }
|
||||
}
|
||||
|
||||
export default transformer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue