Skip to content

Commit 712dec7

Browse files
authored
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

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
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

analysis/src/CompletionFrontEnd.ml

Lines changed: 2 additions & 1 deletion
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)

analysis/src/Utils.ml

Lines changed: 1 addition & 0 deletions
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

compiler/frontend/bs_ast_mapper.ml

Lines changed: 1 addition & 0 deletions
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

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 6 additions & 4 deletions
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

compiler/ml/ast_helper.ml

Lines changed: 1 addition & 1 deletion
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

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 0 deletions
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 *)

compiler/ml/ast_iterator.ml

Lines changed: 1 addition & 0 deletions
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

compiler/ml/ast_mapper.ml

Lines changed: 1 addition & 0 deletions
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

0 commit comments

Comments
 (0)