Skip to content

Commit

Permalink
fix(ast): incorrect visit order in function (#3681)
Browse files Browse the repository at this point in the history
```ts
function hello<T>(a: T): T {
  return 0 as T
}
```

The `T` is a type parameter. It can be used in `FormalParameters`, `ReturnType`, and `FunctionBody`. Therefore we need to visit `type_parameters` before visiting `FormalParameters`, `ReturnType`, and `FunctionBody`
  • Loading branch information
Dunqing committed Jun 15, 2024
1 parent 09b92b6 commit 2158268
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/oxc_ast/src/visit/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,13 +1247,13 @@ pub mod walk {
if let Some(ident) = &func.id {
visitor.visit_binding_identifier(ident);
}
if let Some(parameters) = &func.type_parameters {
visitor.visit_ts_type_parameter_declaration(parameters);
}
visitor.visit_formal_parameters(&func.params);
if let Some(body) = &func.body {
visitor.visit_function_body(body);
}
if let Some(parameters) = &func.type_parameters {
visitor.visit_ts_type_parameter_declaration(parameters);
}
if let Some(annotation) = &func.return_type {
visitor.visit_ts_type_annotation(annotation);
}
Expand Down

0 comments on commit 2158268

Please sign in to comment.