@@ -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+
2254test ( 'async/class: yield' , ( ) => {
2355 is ( parse ( 'yield x' ) , [ 'yield' , 'x' ] ) ;
2456 is ( parse ( 'yield* g' ) , [ 'yield*' , 'g' ] ) ;
0 commit comments