Skip to content

Instantly share code, notes, and snippets.

@Vannevelj
Created March 14, 2022 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vannevelj/2021897f32cde3dbd603289b9cf76b95 to your computer and use it in GitHub Desktop.
Save Vannevelj/2021897f32cde3dbd603289b9cf76b95 to your computer and use it in GitHub Desktop.
pub fn add_types(module: Module) -> String {
for module_item in &module.body {
let declaration = module_item.as_stmt().and_then(|st| st.as_decl());
match declaration {
Some(Decl::Fn(function)) => {
update_function_declaration(function);
}
_ => println!("not a statement"),
}
}
update_module(module)
}
fn update_function_declaration(declaration: FnDecl) {
for param in declaration.function.params {
update_param(param);
}
}
fn update_param(param: Param) {
update_pat(param.pat);
}
fn update_pat(pat: Pat) {
match pat.ident() {
Some(mut found) => {
let any_keyword = TsKeywordType {
span: Span::default(),
kind: TsKeywordTypeKind::TsAnyKeyword,
};
let type_annotation: TsTypeAnn = TsTypeAnn {
span: Span::default(),
type_ann: Box::new(TsType::TsKeywordType(any_keyword)),
};
found.type_ann = Some(type_annotation);
}
None => todo!(),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment