Skip to content

Commit c94fc10

Browse files
committed
Add docs
1 parent 4814962 commit c94fc10

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

docs.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Extends Justin with statements — practical JS subset (inspired by [Jessie](htt
142142
+ `let x`, `const x = 1`, `var x = 1`, `const {a, b} = x`
143143
+ `break`, `continue`, `return x` (inside functions only)
144144
+ `throw x`, `try { } catch (e) { } finally { }`
145-
+ `function f(a, b) { }`, `async function`, `function*`
145+
+ `function f(a, b) { }`, `async function`, `function*`, `await`, `yield`
146146
+ `class X { }`, `class X extends Y { }`
147147
+ `typeof x`, `void x`, `delete x`, `x instanceof Y`
148148
+ `new X()`, `new X(a, b)`
@@ -166,6 +166,18 @@ jessie`
166166
jessie`a + b`({ a: 1, b: 2 }) // 3
167167
```
168168

169+
#### Async/Await
170+
171+
Async functions return promises. `await` works in return position:
172+
173+
```js
174+
// Works: await in return
175+
jessie`async function f() { return await Promise.resolve(42) }`({ Promise })
176+
177+
// Limitation: await in assignment returns Promise, not value
178+
// let x = await y; x * 2 → NaN (x is Promise)
179+
```
180+
169181
#### ASI (Automatic Semicolon Insertion)
170182

171183
Jessie supports JS-style ASI – newlines at statement level act as semicolons:

test/feature/async-class.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,38 @@ test('async/class: await', () => {
1919
is(parse('await a.b'), ['await', ['.', 'a', 'b']]);
2020
});
2121

22+
test('async/class: compile async function', async () => {
23+
const ctx = { Promise };
24+
25+
// Basic async function
26+
compile(parse('async function f() { return 1 }'))(ctx);
27+
is(await ctx.f(), 1);
28+
29+
// Async with return await
30+
compile(parse('async function g() { return await Promise.resolve(42) }'))(ctx);
31+
is(await ctx.g(), 42);
32+
33+
// Async arrow
34+
const fn = compile(parse('async () => 1'))(ctx);
35+
is(await fn(), 1);
36+
37+
// Async arrow with await
38+
const fn2 = compile(parse('async (x) => await x'))(ctx);
39+
is(await fn2(Promise.resolve(99)), 99);
40+
});
41+
42+
test.skip('async/class: compile await assignment (BROKEN)', async () => {
43+
const ctx = { Promise };
44+
45+
// BUG: await in assignment doesn't work - x becomes Promise, not value
46+
compile(parse('async function f() { let x = await Promise.resolve(5); return x * 2 }'))(ctx);
47+
is(await ctx.f(), 10); // Currently returns NaN
48+
49+
// BUG: multiple awaits don't work
50+
compile(parse('async function g() { let a = await Promise.resolve(1); let b = await Promise.resolve(2); return a + b }'))(ctx);
51+
is(await ctx.g(), 3); // Currently returns "[object Promise][object Promise]"
52+
});
53+
2254
test('async/class: yield', () => {
2355
is(parse('yield x'), ['yield', 'x']);
2456
is(parse('yield* g'), ['yield*', 'g']);

0 commit comments

Comments
 (0)