@@ -18,6 +18,11 @@ function Plugin(babel) {
1818 function addTailCallBool ( seqExp ) {
1919 seqExp . expressions [ 0 ] . argument . arguments . push ( t . booleanLiteral ( true ) ) ;
2020 }
21+ function getParentNode ( path ) {
22+ const parentPath = path . getFunctionParent ( ) ;
23+ if ( parentPath === null ) return path . scope . getProgramParent ( ) . block ;
24+ return parentPath . node ;
25+ }
2126 // HzTokens are unique single-instance objects for wrapping user instructions and data.
2227 // Type 1: Invocation Tokens,
2328 // Wrap userland functors and any operands needed to invoke them.
@@ -239,7 +244,8 @@ function Plugin(babel) {
239244 null ,
240245 funcDec . params ,
241246 funcDec . body ,
242- true
247+ true ,
248+ funcDec . async
243249 ) )
244250 )
245251 ] ) ;
@@ -253,7 +259,8 @@ function Plugin(babel) {
253259 null ,
254260 funcDec . params ,
255261 funcDec . body ,
256- true
262+ true ,
263+ funcDec . async
257264 ) )
258265 )
259266 ] ) ;
@@ -303,9 +310,9 @@ function Plugin(babel) {
303310 if ( path . node . generator ) var varDec = declareHzGenerator ( path . node ) ;
304311 else var varDec = declareHzCoroutine ( path . node ) ;
305312 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 ) ;
309316 path . remove ( ) ;
310317 }
311318 } ,
@@ -415,7 +422,7 @@ function Plugin(babel) {
415422 // Check for TCO validity if the call is within a TryStatement
416423 if ( tryStack . length > 0 ) {
417424 const tryData = tryStack [ tryStack . length - 1 ] ;
418- const parentNode = path . getFunctionParent ( ) . node ;
425+ const parentNode = getParentNode ( path ) ;
419426 if ( parentNode === tryData . functionParent ) {
420427 if (
421428 tryData . blockType === "finalizer"
@@ -440,7 +447,7 @@ function Plugin(babel) {
440447 } ,
441448 // Transforms a ReturnStatement into an Instruction Token
442449 exit : function ( path ) {
443- if ( path . getFunctionParent ( ) . node . generator ) {
450+ if ( getParentNode ( path ) . generator ) {
444451 path . node . argument = hzReturnArg ( t . ObjectExpression ( [
445452 t . ObjectProperty (
446453 t . identifier ( "value" ) ,
@@ -489,7 +496,7 @@ function Plugin(babel) {
489496 // Records entry into a TryStatement
490497 enter : function ( path ) {
491498 tryStack . push ( {
492- functionParent : path . getFunctionParent ( ) . node ,
499+ functionParent : getParentNode ( path ) ,
493500 blockType : null
494501 } ) ;
495502 } ,
0 commit comments