You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for this project.
I'm trying a simple automatic implementation à la Rust macros. I have a crude POC that is almost working:
//- find all createXXXStore methodsproject.getSourceFiles().forEach((sourceFile)=>{constfunc: FunctionDeclaration|undefined=sourceFile.getFunction((f)=>{constfunc_name=f.getName();if(func_name){constlow=func_name.toLowerCase();returnlow.startsWith("create")&&low.endsWith("store");}returnfalse;});if(!func)return;//- extract the store type from the first parameterconstinitial_type=func.getParameters()[0];constprops=initial_type.getType().getProperties();//- from each properties of our type we extract information to create setters.props.forEach((p)=>{constname=p.getName();constkind=p.getTypeAtLocation(initial_type);//- naive way to get the location before the return blockconstchild_location=func.getChildCount()-1;//- make our setterconstsetter=func.insertFunction(child_location,{name: toCamelCase("set-"+name),leadingTrivia: "// autogenerated with ts-morph",statements: `update((state) => { return { ...state,${name}, }; });`,parameters: [{name: name,type: kind.getText(),},],});});console.log(sourceFile.print({}));});
TLDR
func.getChildCount() in the above code does not return the proper value: InvalidOperationError: Invalid index: The max index is 4, but 5 was specified. so childCount returned 6 instead of the 4 children the method has
The text was updated successfully, but these errors were encountered:
Hi,
Thanks for this project.
I'm trying a simple automatic implementation à la Rust macros. I have a crude POC that is almost working:
TLDR
func.getChildCount()
in the above code does not return the proper value:InvalidOperationError: Invalid index: The max index is 4, but 5 was specified.
so childCount returned 6 instead of the 4 children the method hasThe text was updated successfully, but these errors were encountered: