This repository was archived by the owner on Jun 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +33
-9
lines changed Expand file tree Collapse file tree 5 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,13 @@ let processFunctionAttributes attrs =
65
65
in
66
66
process false false [] attrs
67
67
68
+ let hasAwaitAttribute attrs =
69
+ List. exists
70
+ (function
71
+ | {Location. txt = "await" } , _ -> true
72
+ | _ -> false )
73
+ attrs
74
+
68
75
let collectListExpressions expr =
69
76
let rec collect acc expr =
70
77
match expr.pexp_desc with
@@ -178,8 +185,8 @@ let filterParsingAttrs attrs =
178
185
match attr with
179
186
| ( {
180
187
Location. txt =
181
- ( " ns.ternary" | " ns.braces" | " res.template" | " bs " | " ns.iflet "
182
- | " ns.namedArgLoc" | " ns.optional" );
188
+ ( " ns.ternary" | " ns.braces" | " res.template" | " await " | " bs "
189
+ | " ns.iflet " | " ns. namedArgLoc" | " ns.optional" );
183
190
},
184
191
_ ) ->
185
192
false
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ val processFunctionAttributes :
22
22
Parsetree .attributes ->
23
23
bool (* async *) * bool (* uncurried *) * Parsetree .attributes
24
24
25
+ val hasAwaitAttribute : Parsetree .attributes -> bool
26
+
25
27
type ifConditionKind =
26
28
| If of Parsetree .expression
27
29
| IfLet of Parsetree .pattern * Parsetree .expression
Original file line number Diff line number Diff line change @@ -3278,6 +3278,11 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
3278
3278
| Pexp_poly _ -> Doc. text " Pexp_poly not impemented in printer"
3279
3279
| Pexp_object _ -> Doc. text " Pexp_object not impemented in printer"
3280
3280
in
3281
+ let exprWithAwait =
3282
+ if ParsetreeViewer. hasAwaitAttribute e.pexp_attributes then
3283
+ Doc. concat [Doc. text " await " ; printedExpression]
3284
+ else printedExpression
3285
+ in
3281
3286
let shouldPrintItsOwnAttributes =
3282
3287
match e.pexp_desc with
3283
3288
| Pexp_apply _ | Pexp_fun _ | Pexp_newtype _ | Pexp_setfield _
@@ -3289,12 +3294,11 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
3289
3294
| _ -> false
3290
3295
in
3291
3296
match e.pexp_attributes with
3292
- | [] -> printedExpression
3297
+ | [] -> exprWithAwait
3293
3298
| attrs when not shouldPrintItsOwnAttributes ->
3294
3299
Doc. group
3295
- (Doc. concat
3296
- [printAttributes ~custom Layout attrs cmtTbl; printedExpression])
3297
- | _ -> printedExpression
3300
+ (Doc. concat [printAttributes ~custom Layout attrs cmtTbl; exprWithAwait])
3301
+ | _ -> exprWithAwait
3298
3302
3299
3303
and printPexpFun ~customLayout ~inCallback e cmtTbl =
3300
3304
let attrsOnArrow, parameters, returnExpr = ParsetreeViewer. funExpr e in
Original file line number Diff line number Diff line change @@ -10,4 +10,10 @@ let f = async () => ()
10
10
let f = async (.) => ()
11
11
let f = async f => f ()
12
12
let f = async (a , b ) => a + b
13
- let f = async (. a , b ) => a + b
13
+ let f = async (. a , b ) => a + b
14
+
15
+
16
+ let maybeSomeValue = switch await fetchData (url ) {
17
+ | data => Some (data )
18
+ | exception JsError (_ ) => None
19
+ }
Original file line number Diff line number Diff line change 1
1
let sequentialAwait = async () => {
2
- let result1 = @ await paused("first")
2
+ let result1 = await paused("first")
3
3
nodeJsAssert.equal(result1, "first")
4
4
5
- let result2 = @ await paused("second")
5
+ let result2 = await paused("second")
6
6
nodeJsAssert.equal(result2, "second")
7
7
}
8
8
@@ -11,3 +11,8 @@ let f = async (. ()) => ()
11
11
let f = async (f) => f()
12
12
let f = async (a, b) => a + b
13
13
let f = async (. a, b) => a + b
14
+
15
+ let maybeSomeValue = switch await fetchData(url) {
16
+ | data => Some(data)
17
+ | exception JsError(_) => None
18
+ }
You can’t perform that action at this time.
0 commit comments