-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncjs.test.js
81 lines (78 loc) · 1.62 KB
/
syncjs.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import * as t from "https://deno.land/std/testing/asserts.ts";
import syncjs from "./syncjs.js";
Deno.test("simple", () => {
t.assertEquals(syncjs("f();"), "await f();");
});
Deno.test("await", () => {
t.assertEquals(syncjs("await f();"), "await f();");
});
Deno.test("in exp", () => {
t.assertEquals(syncjs("const n = f();"), "const n = await f();");
});
Deno.test("in func", () => {
t.assertEquals(syncjs("f(f());"), "await f(await f());");
});
Deno.test("promise, no await", () => {
t.assertEquals(syncjs("promise(f());"), "f();");
});
/*
before
{
"type": "Program",
"start": 0,
"end": 4,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 4,
"expression": {
"type": "CallExpression",
"start": 0,
"end": 3,
"callee": {
"type": "Identifier",
"start": 0,
"end": 1,
"name": "f"
},
"arguments": [],
"optional": false
}
}
],
"sourceType": "module"
}
after // CallExpression を AwaitExpression で囲む
{
"type": "Program",
"start": 0,
"end": 10,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 10,
"expression": {
"type": "AwaitExpression",
"start": 0,
"end": 9,
"argument": {
"type": "CallExpression",
"start": 6,
"end": 9,
"callee": {
"type": "Identifier",
"start": 6,
"end": 7,
"name": "f"
},
"arguments": [],
"optional": false
}
}
}
],
"sourceType": "module"
}
*/