Skip to content

Commit 8e62cd5

Browse files
committed
Restore ast ppx test.
1 parent c90f3d9 commit 8e62cd5

File tree

4 files changed

+145
-3
lines changed

4 files changed

+145
-3
lines changed

compiler/ml/ast_mapper_from0.ml

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

compiler/ml/ast_mapper_to0.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +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 _ -> (* TODO *) assert false
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+
}
411417
end
412418

413419
module P = struct
Lines changed: 117 additions & 0 deletions
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 */

tests/tools_tests/test.sh

Lines changed: 1 addition & 1 deletion
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+
node ../../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)