Created
March 14, 2022 20:30
-
-
Save Vannevelj/2021897f32cde3dbd603289b9cf76b95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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