Skip to content

Commit 712dec7

Browse files
authoredApr 4, 2025··
await AST node for expressions (#7368)
* wip: await AST * Restore ast ppx test. * cleanup * Clean up `cli.bsc.js` invocation and mentions. * final cleanup
1 parent 41e41b9 commit 712dec7

30 files changed

+222
-86
lines changed
 

Diff for: ‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367
2626
- Convert internal JavaScript codebase into ESM, ReScript package itself is now ESM (`"type": "module"`). https://github.com/rescript-lang/rescript/pull/6899
2727
- Add built-in support for the JavaScript `in` operator. https://github.com/rescript-lang/rescript/pull/7342
28+
- AST cleanup: add `Pexp_await` ast node instead of `res.await` attribute. (The attribute is still used for await on modules currently). https://github.com/rescript-lang/rescript/pull/7368
2829

2930
#### :nail_care: Polish
3031

Diff for: ‎CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ After adding a new file to the repository that should go into the npm package -
123123

124124
```sh
125125
make lib # Build compiler and standard library
126-
./cli/bsc myTestFile.res
126+
./cli/bsc.js myTestFile.res
127127
```
128128

129129
To view the untyped tree of the file run:
130130

131131
```sh
132-
./cli/bsc -dparsetree myTestFile.res
132+
./cli/bsc.js -dparsetree myTestFile.res
133133
```
134134

135135
To view the typed tree of the file run:
136136

137137
```sh
138-
./cli/bsc -dtypedtree myTestFile.res
138+
./cli/bsc.js -dtypedtree myTestFile.res
139139
```
140140

141141
### Project

Diff for: ‎analysis/src/CompletionFrontEnd.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,12 @@ let rec exprToContextPathInner ~(inJsxContext : bool) (e : Parsetree.expression)
312312
if List.length exprs = List.length exprsAsContextPaths then
313313
Some (CTuple exprsAsContextPaths)
314314
else None
315+
| Pexp_await e -> exprToContextPathInner ~inJsxContext e
315316
| _ -> None
316317

317318
and exprToContextPath ~(inJsxContext : bool) (e : Parsetree.expression) =
318319
match
319-
( Res_parsetree_viewer.has_await_attribute e.pexp_attributes,
320+
( Res_parsetree_viewer.expr_is_await e,
320321
exprToContextPathInner ~inJsxContext e )
321322
with
322323
| true, Some ctxPath -> Some (CPAwait ctxPath)

Diff for: ‎analysis/src/Utils.ml

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ let identifyPexp pexp =
111111
| Pexp_pack _ -> "Pexp_pack"
112112
| Pexp_extension _ -> "Pexp_extension"
113113
| Pexp_open _ -> "Pexp_open"
114+
| Pexp_await _ -> "Pexp_await"
114115

115116
let identifyPpat pat =
116117
match pat with

Diff for: ‎compiler/frontend/bs_ast_mapper.ml

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ module E = struct
366366
| Pexp_open (ovf, lid, e) ->
367367
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
368368
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
369+
| Pexp_await e -> await ~loc ~attrs (sub.expr sub e)
369370
end
370371

371372
module P = struct

Diff for: ‎compiler/frontend/bs_builtin_ppx.ml

+6-4
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
242242
|| Ast_attributes.has_await_payload attrs2 ->
243243
check_await ();
244244
result
245-
| _ when Ast_attributes.has_await_payload e.pexp_attributes ->
246-
check_await ();
247-
Ast_await.create_await_expression result
248-
| _ -> result
245+
| _ -> (
246+
match result.pexp_desc with
247+
| Pexp_await e ->
248+
check_await ();
249+
Ast_await.create_await_expression e
250+
| _ -> result)
249251

250252
let typ_mapper (self : mapper) (typ : Parsetree.core_type) =
251253
Ast_core_type_class_type.typ_mapper self typ

Diff for: ‎compiler/ml/ast_helper.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module Exp = struct
180180
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
181181
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))
182182
let extension ?loc ?attrs a = mk ?loc ?attrs (Pexp_extension a)
183-
183+
let await ?loc ?attrs a = mk ?loc ?attrs (Pexp_await a)
184184
let case lhs ?guard rhs = {pc_lhs = lhs; pc_guard = guard; pc_rhs = rhs}
185185
end
186186

Diff for: ‎compiler/ml/ast_helper.mli

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ module Exp : sig
210210
val extension : ?loc:loc -> ?attrs:attrs -> extension -> expression
211211

212212
val case : pattern -> ?guard:expression -> expression -> case
213+
val await : ?loc:loc -> ?attrs:attrs -> expression -> expression
213214
end
214215

215216
(** Value declarations *)

Diff for: ‎compiler/ml/ast_iterator.ml

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ module E = struct
344344
iter_loc sub lid;
345345
sub.expr sub e
346346
| Pexp_extension x -> sub.extension sub x
347+
| Pexp_await e -> sub.expr sub e
347348
end
348349

349350
module P = struct

Diff for: ‎compiler/ml/ast_mapper.ml

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ module E = struct
329329
| Pexp_open (ovf, lid, e) ->
330330
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
331331
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
332+
| Pexp_await e -> await ~loc ~attrs (sub.expr sub e)
332333
end
333334

334335
module P = struct

Diff for: ‎compiler/ml/ast_mapper_from0.ml

+20-1
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,30 @@ end
295295
module E = struct
296296
(* Value expressions for the core language *)
297297

298-
let map sub {pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} =
298+
let has_await_attribute attrs =
299+
List.exists
300+
(function
301+
| {Location.txt = "res.await"}, _ -> true
302+
| _ -> false)
303+
attrs
304+
305+
let remove_await_attribute attrs =
306+
List.filter
307+
(function
308+
| {Location.txt = "res.await"}, _ -> false
309+
| _ -> true)
310+
attrs
311+
312+
let map sub ({pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} as e)
313+
=
299314
let open Exp in
300315
let loc = sub.location sub loc in
301316
let attrs = sub.attributes sub attrs in
302317
match desc with
318+
| _ when has_await_attribute attrs ->
319+
let attrs = remove_await_attribute e.pexp_attributes in
320+
let e = sub.expr sub {e with pexp_attributes = attrs} in
321+
await ~loc e
303322
| Pexp_ident x -> ident ~loc ~attrs (map_loc sub x)
304323
| Pexp_constant x -> constant ~loc ~attrs (map_constant x)
305324
| Pexp_let (r, vbs, e) ->

Diff for: ‎compiler/ml/ast_mapper_to0.ml

+7
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ module E = struct
407407
| Pexp_open (ovf, lid, e) ->
408408
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
409409
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
410+
| Pexp_await e ->
411+
let e = sub.expr sub e in
412+
{
413+
e with
414+
pexp_attributes =
415+
(Location.mknoloc "res.await", Pt.PStr []) :: e.pexp_attributes;
416+
}
410417
end
411418

412419
module P = struct

Diff for: ‎compiler/ml/ast_uncurried.ml

-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,3 @@ let expr_is_uncurried_fun (expr : Parsetree.expression) =
1919
match expr.pexp_desc with
2020
| Pexp_fun {arity = Some _} -> true
2121
| _ -> false
22-
23-
let expr_extract_uncurried_fun (expr : Parsetree.expression) =
24-
match expr.pexp_desc with
25-
| Pexp_fun {arity = Some _} -> expr
26-
| _ -> assert false

Diff for: ‎compiler/ml/depend.ml

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ let rec add_expr bv exp =
289289
| Pstr_eval ({pexp_desc = Pexp_construct (c, None)}, _) -> add bv c
290290
| _ -> handle_extension e)
291291
| Pexp_extension e -> handle_extension e
292+
| Pexp_await e -> add_expr bv e
292293

293294
and add_cases bv cases = List.iter (add_case bv) cases
294295

Diff for: ‎compiler/ml/parsetree.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ and expression_desc =
313313
let open M in E
314314
let! open M in E *)
315315
| Pexp_extension of extension
316-
(* [%id] *)
317-
(* . *)
316+
(* [%id] *)
317+
(* . *)
318+
| Pexp_await of expression
318319

319320
and case = {
320321
(* (P -> E) or (P when E0 -> E) *)

Diff for: ‎compiler/ml/pprintast.ml

+1
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ and expression ctxt f x =
722722
(expression ctxt) e
723723
| Pexp_variant (l, Some eo) -> pp f "@[<2>`%s@;%a@]" l (simple_expr ctxt) eo
724724
| Pexp_extension e -> extension ctxt f e
725+
| Pexp_await e -> pp f "@[<hov2>await@ %a@]" (simple_expr ctxt) e
725726
| _ -> expression1 ctxt f x
726727

727728
and expression1 ctxt f x =

Diff for: ‎compiler/ml/printast.ml

+3
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ and expression i ppf x =
345345
| Pexp_extension (s, arg) ->
346346
line i ppf "Pexp_extension \"%s\"\n" s.txt;
347347
payload i ppf arg
348+
| Pexp_await e ->
349+
line i ppf "Pexp_await\n";
350+
expression i ppf e
348351

349352
and value_description i ppf x =
350353
line i ppf "value_description %a %a\n" fmt_string_loc x.pval_name fmt_location

Diff for: ‎compiler/ml/typecore.ml

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ let iter_expression f e =
178178
expr e;
179179
module_expr me
180180
| Pexp_pack me -> module_expr me
181+
| Pexp_await _ -> assert false (* should be handled earlier *)
181182
and case {pc_lhs = _; pc_guard; pc_rhs} =
182183
may expr pc_guard;
183184
expr pc_rhs
@@ -3195,6 +3196,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
31953196
| _ -> raise (Error (loc, env, Invalid_extension_constructor_payload)))
31963197
| Pexp_extension ext ->
31973198
raise (Error_forward (Builtin_attributes.error_of_extension ext))
3199+
| Pexp_await _ -> (* should be handled earlier *) assert false
31983200

31993201
and type_function ?in_function ~arity ~async loc attrs env ty_expected_ l
32003202
caselist =

Diff for: ‎compiler/syntax/src/res_ast_debugger.ml

+1
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ module SexpAst = struct
707707
]
708708
| Pexp_extension ext ->
709709
Sexp.list [Sexp.atom "Pexp_extension"; extension ext]
710+
| Pexp_await e -> Sexp.list [Sexp.atom "Pexp_await"; expression e]
710711
in
711712
Sexp.list [Sexp.atom "expression"; desc]
712713

Diff for: ‎compiler/syntax/src/res_core.ml

+3-6
Original file line numberDiff line numberDiff line change
@@ -3307,15 +3307,12 @@ and parse_async_arrow_expression ?(arrow_attrs = []) p =
33073307

33083308
and parse_await_expression p =
33093309
let await_loc = mk_loc p.Parser.start_pos p.end_pos in
3310-
let await_attr = make_await_attr await_loc in
33113310
Parser.expect Await p;
33123311
let token_prec = Token.precedence MinusGreater in
33133312
let expr = parse_binary_expr ~context:OrdinaryExpr p token_prec in
3314-
{
3315-
expr with
3316-
pexp_attributes = await_attr :: expr.pexp_attributes;
3317-
pexp_loc = {expr.pexp_loc with loc_start = await_loc.loc_start};
3318-
}
3313+
Ast_helper.Exp.await
3314+
~loc:{expr.pexp_loc with loc_start = await_loc.loc_start}
3315+
~attrs:[] expr
33193316

33203317
and parse_try_expression p =
33213318
let start_pos = p.Parser.start_pos in

Diff for: ‎compiler/syntax/src/res_parens.ml

+7-15
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ let call_expr expr =
5656
} ->
5757
Parenthesized
5858
| _ when Ast_uncurried.expr_is_uncurried_fun expr -> Parenthesized
59-
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
60-
Parenthesized
59+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
6160
| _ -> Nothing)
6261

6362
let structure_expr expr =
@@ -109,8 +108,7 @@ let unary_expr_operand expr =
109108
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
110109
} ->
111110
Parenthesized
112-
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
113-
Parenthesized
111+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
114112
| _ -> Nothing)
115113

116114
let binary_expr_operand ~is_lhs expr =
@@ -133,8 +131,7 @@ let binary_expr_operand ~is_lhs expr =
133131
| expr when ParsetreeViewer.is_binary_expression expr -> Parenthesized
134132
| expr when ParsetreeViewer.is_ternary_expr expr -> Parenthesized
135133
| {pexp_desc = Pexp_lazy _ | Pexp_assert _} when is_lhs -> Parenthesized
136-
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
137-
Parenthesized
134+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
138135
| {Parsetree.pexp_attributes = attrs} ->
139136
if ParsetreeViewer.has_printable_attributes attrs then Parenthesized
140137
else Nothing)
@@ -229,9 +226,7 @@ let lazy_or_assert_or_await_expr_rhs ?(in_await = false) expr =
229226
| Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
230227
} ->
231228
Parenthesized
232-
| _
233-
when (not in_await)
234-
&& ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
229+
| _ when (not in_await) && ParsetreeViewer.expr_is_await expr ->
235230
Parenthesized
236231
| _ -> Nothing)
237232

@@ -277,8 +272,7 @@ let field_expr expr =
277272
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
278273
} ->
279274
Parenthesized
280-
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
281-
Parenthesized
275+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
282276
| _ -> Nothing)
283277

284278
let set_field_expr_rhs expr =
@@ -339,8 +333,7 @@ let jsx_prop_expr expr =
339333
}
340334
when starts_with_minus x ->
341335
Parenthesized
342-
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
343-
Parenthesized
336+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
344337
| {
345338
Parsetree.pexp_desc =
346339
( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _
@@ -377,8 +370,7 @@ let jsx_child_expr expr =
377370
}
378371
when starts_with_minus x ->
379372
Parenthesized
380-
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
381-
Parenthesized
373+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
382374
| {
383375
Parsetree.pexp_desc =
384376
( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _

Diff for: ‎compiler/syntax/src/res_parsetree_viewer.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ let has_await_attribute attrs =
7272
| _ -> false)
7373
attrs
7474

75+
let expr_is_await e =
76+
match e.pexp_desc with
77+
| Pexp_await _ -> true
78+
| _ -> false
79+
7580
let has_inline_record_definition_attribute attrs =
7681
List.exists
7782
(function
@@ -111,12 +116,7 @@ let collect_list_expressions expr =
111116

112117
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
113118
let rewrite_underscore_apply expr =
114-
let expr_fun =
115-
if Ast_uncurried.expr_is_uncurried_fun expr then
116-
Ast_uncurried.expr_extract_uncurried_fun expr
117-
else expr
118-
in
119-
match expr_fun.pexp_desc with
119+
match expr.pexp_desc with
120120
| Pexp_fun
121121
{
122122
arg_label = Nolabel;

Diff for: ‎compiler/syntax/src/res_parsetree_viewer.mli

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ val functor_type :
1414
list
1515
* Parsetree.module_type
1616

17+
val expr_is_await : Parsetree.expression -> bool
1718
val has_await_attribute : Parsetree.attributes -> bool
1819
val has_inline_record_definition_attribute : Parsetree.attributes -> bool
1920
val has_res_pat_variant_spread_attribute : Parsetree.attributes -> bool

Diff for: ‎compiler/syntax/src/res_printer.ml

+10-17
Original file line numberDiff line numberDiff line change
@@ -2810,12 +2810,8 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
28102810
return_expr_doc;
28112811
])
28122812
in
2813-
let uncurried = Ast_uncurried.expr_is_uncurried_fun e in
2814-
let e_fun =
2815-
if uncurried then Ast_uncurried.expr_extract_uncurried_fun e else e
2816-
in
28172813
let printed_expression =
2818-
match e_fun.pexp_desc with
2814+
match e.pexp_desc with
28192815
| Pexp_fun
28202816
{
28212817
arg_label = Nolabel;
@@ -2825,7 +2821,7 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
28252821
} ->
28262822
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
28272823
print_expression_with_comments ~state
2828-
(ParsetreeViewer.rewrite_underscore_apply e_fun)
2824+
(ParsetreeViewer.rewrite_underscore_apply e)
28292825
cmt_tbl
28302826
| Pexp_fun _ | Pexp_newtype _ -> print_arrow e
28312827
| Parsetree.Pexp_constant c ->
@@ -3432,9 +3428,10 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
34323428
Doc.concat [Doc.text "\""; member_doc; Doc.text "\""]
34333429
in
34343430
Doc.group (Doc.concat [parent_doc; Doc.lbracket; member; Doc.rbracket])
3435-
in
3436-
let expr_with_await =
3437-
if ParsetreeViewer.has_await_attribute e.pexp_attributes then
3431+
| Pexp_await e ->
3432+
let printed_expression =
3433+
print_expression_with_comments ~state e cmt_tbl
3434+
in
34383435
let rhs =
34393436
match
34403437
Parens.lazy_or_assert_or_await_expr_rhs ~in_await:true
@@ -3453,7 +3450,6 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
34533450
| Nothing -> printed_expression
34543451
in
34553452
Doc.concat [Doc.text "await "; rhs]
3456-
else printed_expression
34573453
in
34583454
let should_print_its_own_attributes =
34593455
match e.pexp_desc with
@@ -3467,11 +3463,11 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
34673463
| _ -> false
34683464
in
34693465
match e.pexp_attributes with
3470-
| [] -> expr_with_await
3466+
| [] -> printed_expression
34713467
| attrs when not should_print_its_own_attributes ->
34723468
Doc.group
3473-
(Doc.concat [print_attributes ~state attrs cmt_tbl; expr_with_await])
3474-
| _ -> expr_with_await
3469+
(Doc.concat [print_attributes ~state attrs cmt_tbl; printed_expression])
3470+
| _ -> printed_expression
34753471

34763472
and print_pexp_fun ~state ~in_callback e cmt_tbl =
34773473
let async, parameters, return_expr = ParsetreeViewer.fun_expr e in
@@ -3760,11 +3756,8 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
37603756
| [] -> doc
37613757
| _ -> add_parens doc
37623758
in
3763-
let is_await =
3764-
ParsetreeViewer.has_await_attribute expr.pexp_attributes
3765-
in
37663759
let doc =
3767-
if is_await then
3760+
if ParsetreeViewer.expr_is_await expr then
37683761
let parens =
37693762
Res_parens.binary_operator_inside_await_needs_parens operator
37703763
in

Diff for: ‎tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let greetUser async [arity:1]userId =
2-
((let name = ((getUserName userId)[@res.await ]) in
2+
((let name = await (getUserName userId) in
33
({js|Hello |js} ++ name) ++ {js|!|js})
44
[@res.braces ])
55
;;async fun [arity:1]() -> 123
@@ -23,10 +23,10 @@ let f =
2323
[@res.ternary ])
2424
let foo = async ~a:34
2525
let bar async [arity:1]~a = a + 1
26-
let ex1 = ((3)[@res.await ]) + ((4)[@res.await ])
27-
let ex2 = ((3)[@res.await ]) ** ((4)[@res.await ])
28-
let ex3 = ((foo -> (bar ~arg))[@res.await ])
29-
let ex4 = (((foo.bar).baz)[@res.await ])
26+
let ex1 = (await 3) + (await 4)
27+
let ex2 = (await 3) ** (await 4)
28+
let ex3 = await (foo -> (bar ~arg))
29+
let ex4 = await ((foo.bar).baz)
3030
let attr1 = ((async fun [arity:1]x -> x + 1)[@a ])
3131
let attr2 = ((fun (type a) ->
3232
async fun [arity:1]() -> fun (type b) -> fun (type c) ->

Diff for: ‎tests/syntax_tests/data/parsing/grammar/expressions/expected/await.res.txt

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
;;((wait 2)[@res.await ])
1+
;;await (wait 2)
22
let maybeSomeValue =
3-
match ((fetchData url)[@res.await ]) with
3+
match await (fetchData url) with
44
| data -> Some data
55
| exception JsError _ -> None
6-
let x = ((1)[@res.await ]) + 2
7-
let x = ((wait 1)[@res.await ]) + ((wait 2)[@res.await ])
6+
let x = (await 1) + 2
7+
let x = (await (wait 1)) + (await (wait 2))
88
let () =
9-
((let response = ((fetch {js|/users.json|js})[@res.await ]) in
10-
let users = ((response.json ())[@res.await ]) in
11-
let comments =
12-
((((fetch {js|comment.json|js})[@res.await ]).json ())
13-
[@res.await ]).(0) in
9+
((let response = await (fetch {js|/users.json|js}) in
10+
let users = await (response.json ()) in
11+
let comments = (await ((await (fetch {js|comment.json|js})).json ())).(0) in
1412
Js.log2 users comments)
1513
[@res.braces ])
16-
let () = ((delay 10)[@res.braces ][@res.await ])
17-
let () = ((((delay 10)[@res.await ]); ((delay 20)[@res.await ]))
18-
[@res.braces ])
19-
let forEach = ((Js.Import Belt.List.forEach)[@res.await ][@a ][@b ])
14+
let () = ((await (delay 10))[@res.braces ])
15+
let () = ((await (delay 10); await (delay 20))[@res.braces ])
16+
let forEach = await ((Js.Import Belt.List.forEach)[@a ][@b ])
2017
module M = ((Belt.List)[@res.await ][@a ][@b ])
2118
let f [arity:1]() =
2219
((let module M = ((Belt.List)[@res.await ][@a ][@b ]) in M.forEach)

Diff for: ‎tests/syntax_tests/data/printer/expr/asyncAwait.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let _ = await (assert(x))
6666
let _ = await promises[0]
6767
let _ = await promises["resolved"]
6868
let _ = await (promises["resolved"] = sideEffect())
69-
let _ = await (@attr expr)
69+
let _ = @outer await @inner expr
7070
let _ = await module(Foo)
7171
let _ = await module(Foo: Bar)
7272
let _ = await Promise

Diff for: ‎tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ user.data = await fetch()
2929

3030
<Navbar promise={await gc()}> {await weirdReactSuspenseApi} </Navbar>
3131

32-
let inBinaryExpression = await x->Js.Promise.resolve + 1
33-
let inBinaryExpression = await x->Js.Promise.resolve + await y->Js.Promise.resolve
32+
let inBinaryExpression = (await x->Js.Promise.resolve) + 1
33+
let inBinaryExpression = (await x->Js.Promise.resolve) + (await y->Js.Promise.resolve)
3434

3535
let withCallback = async () => {
36-
async x => await x->Js.promise.resolve + 1
36+
async x => (await x->Js.promise.resolve) + 1
3737
}
3838

3939
let () = await (await fetch(url))->(await resolve)
@@ -68,7 +68,7 @@ let _ = await (
6868
let _ = await (condition() ? true : false)
6969
let _ = await f(x)
7070
let _ = await f(x)
71-
let _ = (await (f(x): Js.Promise.t<unit>))
71+
let _ = await (f(x): Js.Promise.t<unit>)
7272
let _ = await (
7373
while true {
7474
infiniteLoop()
@@ -88,7 +88,7 @@ let _ = await (assert(x))
8888
let _ = await promises[0]
8989
let _ = await promises["resolved"]
9090
let _ = await promises["resolved"] = sideEffect()
91-
let _ = @attr await (expr)
91+
let _ = @outer await (@inner expr)
9292
let _ = await module(Foo)
9393
let _ = await module(Foo: Bar)
9494
let _ = await Promise

Diff for: ‎tests/tools_tests/src/expected/TestPpx.res.jsout

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
'use strict';
3+
4+
let React = require("react");
5+
6+
console.log("ppx test");
7+
8+
console.log("ppx test");
9+
10+
let M = {
11+
v: 10
12+
};
13+
14+
let OptionalFields = {
15+
r: {
16+
y: 1.0
17+
}
18+
};
19+
20+
function one(x) {
21+
return x;
22+
}
23+
24+
function two(x, y) {
25+
return x + y | 0;
26+
}
27+
28+
let n = 6;
29+
30+
let Arity = {
31+
one: one,
32+
two: two,
33+
n: n
34+
};
35+
36+
React.useState(() => 0);
37+
38+
async function fpromise(promise, _x) {
39+
return await promise;
40+
}
41+
42+
let Uncurried = {};
43+
44+
async function async_succ(x) {
45+
return x + 1 | 0;
46+
}
47+
48+
async function async_foo(x, y) {
49+
let a = async_succ(x);
50+
let b = async_succ(y);
51+
return await a + await b | 0;
52+
}
53+
54+
function add(x, y) {
55+
return x + y | 0;
56+
}
57+
58+
function partial_add(extra) {
59+
return 3 + extra | 0;
60+
}
61+
62+
function plus(x, y) {
63+
return x + y | 0;
64+
}
65+
66+
let z = 3;
67+
68+
let Pipe = {
69+
plus: plus,
70+
z: z
71+
};
72+
73+
let concat = "ab";
74+
75+
async function test() {
76+
return 12;
77+
}
78+
79+
async function f() {
80+
return await test() + 1 | 0;
81+
}
82+
83+
let a = "A";
84+
85+
let b = "B";
86+
87+
let vv = 10;
88+
89+
let neq = false;
90+
91+
let neq2 = false;
92+
93+
let eq = true;
94+
95+
let eq2 = true;
96+
97+
exports.a = a;
98+
exports.b = b;
99+
exports.M = M;
100+
exports.vv = vv;
101+
exports.OptionalFields = OptionalFields;
102+
exports.Arity = Arity;
103+
exports.fpromise = fpromise;
104+
exports.Uncurried = Uncurried;
105+
exports.async_succ = async_succ;
106+
exports.async_foo = async_foo;
107+
exports.add = add;
108+
exports.partial_add = partial_add;
109+
exports.Pipe = Pipe;
110+
exports.concat = concat;
111+
exports.neq = neq;
112+
exports.neq2 = neq2;
113+
exports.eq = eq;
114+
exports.eq2 = eq2;
115+
exports.test = test;
116+
exports.f = f;
117+
/* Not a pure module */

Diff for: ‎tests/tools_tests/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ done
99

1010
for file in ppx/*.res; do
1111
output="src/expected/$(basename $file).jsout"
12-
../../cli/bsc -ppx "../../_build/install/default/bin/rescript-tools ppx" $file > $output
12+
../../cli/bsc.js -ppx "../../_build/install/default/bin/rescript-tools ppx" $file > $output
1313
# # CI. We use LF, and the CI OCaml fork prints CRLF. Convert.
1414
if [ "$RUNNER_OS" == "Windows" ]; then
1515
perl -pi -e 's/\r\n/\n/g' -- $output

0 commit comments

Comments
 (0)
Please sign in to comment.