Skip to content

Ast types first #7233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 9, 2025
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
- Editor: Fix issue where pipe completions would not trigger with generic type arguments. https://github.com/rescript-lang/rescript/pull/7231
- Fix leftover assert false in code for `null != undefined`. https://github.com/rescript-lang/rescript/pull/7232

#### :house: Internal

- AST cleanup: Prepare for ast async cleanup: Refactor code for "@res.async" payload handling and clean up handling of type and term parameters, so that now each `=>` in a function definition corresponds to a function. https://github.com/rescript-lang/rescript/pull/7223
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing from previous PR

- AST: always put type parameters first in function definitions. https://github.com/rescript-lang/rescript/pull/7233

# 12.0.0-alpha.7

#### :bug: Bug fix
Expand Down
16 changes: 2 additions & 14 deletions compiler/ml/ast_async.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
let is_async : Parsetree.attribute -> bool = fun ({txt}, _) -> txt = "res.async"

let has_async_payload attrs = Ext_list.exists attrs is_async

let make_async_attr loc = (Location.mkloc "res.async" loc, Parsetree.PStr [])
let has_async_payload attrs =
Ext_list.exists attrs (fun ({Location.txt}, _) -> txt = "res.async")

let add_async_attribute ~async (body : Parsetree.expression) =
if async then
Expand All @@ -14,15 +11,6 @@ let add_async_attribute ~async (body : Parsetree.expression) =
}
else body

let extract_async_attribute attrs =
let rec process async acc attrs =
match attrs with
| [] -> (async, List.rev acc)
| ({Location.txt = "res.async"}, _) :: rest -> process true acc rest
| attr :: rest -> process async (attr :: acc) rest
in
process false [] attrs

let add_promise_type ?(loc = Location.none) ~async
(result : Parsetree.expression) =
if async then
Expand Down
8 changes: 2 additions & 6 deletions compiler/syntax/src/jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,8 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
modified_binding ~binding_loc ~binding_pat_loc ~fn_name binding
in
let is_async =
Ext_list.find_first binding.pvb_expr.pexp_attributes Ast_async.is_async
|> Option.is_some
Ast_async.has_async_payload binding.pvb_expr.pexp_attributes
in
(* do stuff here! *)
let named_arg_list, newtypes, _typeConstraints =
recursively_transform_named_args_for_make
(modified_binding_old binding)
Expand Down Expand Up @@ -1192,9 +1190,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
in

let is_async =
Ext_list.find_first modified_binding.pvb_expr.pexp_attributes
Ast_async.is_async
|> Option.is_some
Ast_async.has_async_payload modified_binding.pvb_expr.pexp_attributes
in

let make_new_binding ~loc ~full_module_name binding =
Expand Down
Loading
Loading