@@ -18,6 +18,11 @@ function Plugin(babel) {
18
18
function addTailCallBool ( seqExp ) {
19
19
seqExp . expressions [ 0 ] . argument . arguments . push ( t . booleanLiteral ( true ) ) ;
20
20
}
21
+ function getParentNode ( path ) {
22
+ const parentPath = path . getFunctionParent ( ) ;
23
+ if ( parentPath === null ) return path . scope . getProgramParent ( ) . block ;
24
+ return parentPath . node ;
25
+ }
21
26
// HzTokens are unique single-instance objects for wrapping user instructions and data.
22
27
// Type 1: Invocation Tokens,
23
28
// Wrap userland functors and any operands needed to invoke them.
@@ -239,7 +244,8 @@ function Plugin(babel) {
239
244
null ,
240
245
funcDec . params ,
241
246
funcDec . body ,
242
- true
247
+ true ,
248
+ funcDec . async
243
249
) )
244
250
)
245
251
] ) ;
@@ -253,7 +259,8 @@ function Plugin(babel) {
253
259
null ,
254
260
funcDec . params ,
255
261
funcDec . body ,
256
- true
262
+ true ,
263
+ funcDec . async
257
264
) )
258
265
)
259
266
] ) ;
@@ -303,9 +310,9 @@ function Plugin(babel) {
303
310
if ( path . node . generator ) var varDec = declareHzGenerator ( path . node ) ;
304
311
else var varDec = declareHzCoroutine ( path . node ) ;
305
312
path . node . generator = true ;
306
- const parentPath = path . getFunctionParent ( ) ;
307
- if ( Array . isArray ( parentPath . node . body ) ) parentPath . node . body . unshift ( varDec ) ;
308
- else parentPath . node . body . body . unshift ( varDec ) ;
313
+ const parentNode = getParentNode ( path ) ;
314
+ if ( Array . isArray ( parentNode . body ) ) parentNode . body . unshift ( varDec ) ;
315
+ else parentNode . body . body . unshift ( varDec ) ;
309
316
path . remove ( ) ;
310
317
}
311
318
} ,
@@ -415,7 +422,7 @@ function Plugin(babel) {
415
422
// Check for TCO validity if the call is within a TryStatement
416
423
if ( tryStack . length > 0 ) {
417
424
const tryData = tryStack [ tryStack . length - 1 ] ;
418
- const parentNode = path . getFunctionParent ( ) . node ;
425
+ const parentNode = getParentNode ( path ) ;
419
426
if ( parentNode === tryData . functionParent ) {
420
427
if (
421
428
tryData . blockType === "finalizer"
@@ -440,7 +447,7 @@ function Plugin(babel) {
440
447
} ,
441
448
// Transforms a ReturnStatement into an Instruction Token
442
449
exit : function ( path ) {
443
- if ( path . getFunctionParent ( ) . node . generator ) {
450
+ if ( getParentNode ( path ) . generator ) {
444
451
path . node . argument = hzReturnArg ( t . ObjectExpression ( [
445
452
t . ObjectProperty (
446
453
t . identifier ( "value" ) ,
@@ -489,7 +496,7 @@ function Plugin(babel) {
489
496
// Records entry into a TryStatement
490
497
enter : function ( path ) {
491
498
tryStack . push ( {
492
- functionParent : path . getFunctionParent ( ) . node ,
499
+ functionParent : getParentNode ( path ) ,
493
500
blockType : null
494
501
} ) ;
495
502
} ,
0 commit comments