Skip to content

Commit

Permalink
Rebase on latest 10.0 alpha compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoc committed Jul 5, 2022
1 parent 02091f6 commit b90ac95
Show file tree
Hide file tree
Showing 8 changed files with 1,792 additions and 2,337 deletions.
199 changes: 100 additions & 99 deletions example-async/src/AA.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ function addTest(t) {

function addTest1(t, x) {
tests.push(function () {
return t(x);
});
return t(x);
});
}

async function foo(x, y) {
return x + y | 0;
return (x + y) | 0;
}

async function bar(ff) {
var a = await ff(3, 4);
var b = await foo(5, 6);
return a + b | 0;
return (a + b) | 0;
}

async function baz() {
Expand All @@ -40,14 +40,14 @@ async function testBaz() {

tests.push(testBaz);

var E = /* @__PURE__ */Caml_exceptions.create("AA.E");
var E = /* @__PURE__ */ Caml_exceptions.create("AA.E");

async function e1() {
throw {
RE_EXN_ID: E,
_1: 1000,
Error: new Error()
};
RE_EXN_ID: E,
_1: 1000,
Error: new Error(),
};
}

async function e2() {
Expand All @@ -62,21 +62,22 @@ async function e4() {
return await e2();
}

var e5 = (function() { return Promise.reject(new Error('fail')) });
var e5 = function () {
return Promise.reject(new Error("fail"));
};

async function testTryCatch(fn) {
try {
return await fn();
}
catch (raw_n){
} catch (raw_n) {
var n = Caml_js_exceptions.internalToOCamlException(raw_n);
if (n.RE_EXN_ID === E) {
console.log("testTryCatch: E", n._1);
return ;
return;
}
if (n.RE_EXN_ID === "JsError") {
console.log("testTryCatch: JsError");
return ;
return;
}
throw n;
}
Expand All @@ -93,11 +94,11 @@ addTest1(testTryCatch, e4);
addTest1(testTryCatch, e5);

async function singlePromise(x) {
return x + 1 | 0;
return (x + 1) | 0;
}

async function nestedPromise(x) {
var x$1 = singlePromise(x + 1 | 0);
var x$1 = singlePromise((x + 1) | 0);
[Promise.resolve(x$1)];
return 32;
}
Expand All @@ -112,21 +113,20 @@ function status(response) {

var Fetch = {
$$fetch: $$fetch$1,
status: status
status: status,
};

var explainError = ((e)=>e.toString());
var explainError = e => e.toString();

async function testFetch(url) {
var response;
try {
response = await fetch(url);
}
catch (raw_e){
} catch (raw_e) {
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
if (e.RE_EXN_ID === "JsError") {
console.log("Fetch returned an error:", explainError(e._1));
return ;
return;
}
throw e;
}
Expand All @@ -140,7 +140,7 @@ addTest1(testFetch, "https://www.google.comsdkjdkghdsg");

async function withCallback() {
return async function (x) {
return await Promise.resolve(x) + 1 | 0;
return ((await Promise.resolve(x)) + 1) | 0;
};
}

Expand All @@ -154,55 +154,58 @@ async function map(l, f) {
var loop = async function (l, acc) {
if (l) {
return await loop(l.tl, {
hd: await l.hd,
tl: acc
});
hd: await l.hd,
tl: acc,
});
} else {
return acc;
}
};
return await loop(Belt_List.mapReverse(l, (function (x) {
return f(x);
})), /* [] */0);
return await loop(
Belt_List.mapReverse(l, function (x) {
return f(x);
}),
/* [] */ 0
);
}

var AsyncList = {
map: map
map: map,
};

var counter = {
contents: 0
contents: 0,
};

async function ff(url) {
var response = await fetch(url);
counter.contents = counter.contents + 1 | 0;
return [
counter.contents,
response.status
];
counter.contents = (counter.contents + 1) | 0;
return [counter.contents, response.status];
}

async function testFetchMany() {
var fetchedItems = await map({
var fetchedItems = await map(
{
hd: "https://www.google.com",
tl: {
hd: "https://www.google.com",
tl: {
hd: "https://www.google.com",
tl: {
hd: "https://www.google.com",
tl: {
hd: "https://www.google.com",
tl: {
hd: "https://www.google.com",
tl: /* [] */0
}
}
}
}
}, ff);
return Belt_List.forEach(fetchedItems, (function (param) {
console.log("Fetched", param[0], param[1]);
}));
tl: /* [] */ 0,
},
},
},
},
},
ff
);
return Belt_List.forEach(fetchedItems, function (param) {
console.log("Fetched", param[0], param[1]);
});
}

tests.push(testFetchMany);
Expand All @@ -211,25 +214,24 @@ async function $$fetch$2(url) {
var response;
try {
response = await fetch(url);
}
catch (raw_e){
} catch (raw_e) {
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
if (e.RE_EXN_ID === "JsError") {
return {
TAG: /* Error */1,
_0: e._1
};
TAG: /* Error */ 1,
_0: e._1,
};
}
throw e;
}
return {
TAG: /* Ok */0,
_0: response
};
TAG: /* Ok */ 0,
_0: response,
};
}

var FetchResult = {
$$fetch: $$fetch$2
$$fetch: $$fetch$2,
};

function nextFetch(_response) {
Expand All @@ -238,18 +240,18 @@ function nextFetch(_response) {

async function testFetchWithResult() {
var response1 = await $$fetch$2("https://www.google.com");
if (response1.TAG !== /* Ok */0) {
return ;
if (response1.TAG !== /* Ok */ 0) {
return;
}
var response1$1 = response1._0;
console.log("FetchResult response1", response1$1.status);
var url = nextFetch(response1$1);
if (url === undefined) {
return ;
return;
}
var response2 = await $$fetch$2(url);
if (response2.TAG !== /* Ok */0) {
return ;
if (response2.TAG !== /* Ok */ 0) {
return;
}
console.log("FetchResult response2", response2._0.status);
}
Expand All @@ -259,9 +261,8 @@ tests.push(testFetchWithResult);
async function runAllTests(n) {
if (n >= 0 && n < tests.length) {
await Caml_array.get(tests, n)();
return await runAllTests(n + 1 | 0);
return await runAllTests((n + 1) | 0);
}

}

runAllTests(0);
Expand All @@ -272,51 +273,51 @@ async function bb(x) {

async function cc(x, yOpt, z) {
var y = yOpt !== undefined ? Caml_option.valFromOption(yOpt) : x;
return (await x + await y | 0) + await z | 0;
return ((((await x) + (await y)) | 0) + (await z)) | 0;
}

async function dd(x, y) {
return await x + await y | 0;
return ((await x) + (await y)) | 0;
}

async function ee(x, y) {
return await x + await y | 0;
return ((await x) + (await y)) | 0;
}

var fetchAndCount = ff;

export {
tests ,
addTest ,
addTest1 ,
foo ,
bar ,
baz ,
testBaz ,
E ,
e1 ,
e2 ,
e3 ,
e4 ,
e5 ,
testTryCatch ,
singlePromise ,
nestedPromise ,
Fetch ,
explainError ,
testFetch ,
withCallback ,
testWithCallback ,
AsyncList ,
fetchAndCount ,
testFetchMany ,
FetchResult ,
nextFetch ,
testFetchWithResult ,
runAllTests ,
bb ,
cc ,
dd ,
ee ,
}
tests,
addTest,
addTest1,
foo,
bar,
baz,
testBaz,
E,
e1,
e2,
e3,
e4,
e5,
testTryCatch,
singlePromise,
nestedPromise,
Fetch,
explainError,
testFetch,
withCallback,
testWithCallback,
AsyncList,
fetchAndCount,
testFetchMany,
FetchResult,
nextFetch,
testFetchWithResult,
runAllTests,
bb,
cc,
dd,
ee,
};
/* Not a pure module */
2 changes: 1 addition & 1 deletion jscomp/main/builtin_cmi_datasets.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* dec5d460e2475d3c05dee9d57da6d5f9 *)
(* ea8d7444220084bce9d9a044eb755297 *)
let module_names : string array = Obj.magic (
"Js" (* 5893 *),
"Arg" (* 3634 *),
Expand Down
2 changes: 1 addition & 1 deletion lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val module_data :

end = struct
#1 "builtin_cmi_datasets.ml"
(* dec5d460e2475d3c05dee9d57da6d5f9 *)
(* ea8d7444220084bce9d9a044eb755297 *)
let module_names : string array = Obj.magic (
"Js" (* 5893 *),
"Arg" (* 3634 *),
Expand Down
Loading

0 comments on commit b90ac95

Please sign in to comment.