@@ -33,8 +33,8 @@ const visitorsWithoutAncestors = {
3333 if ( isTopLevelDeclaration ( state ) ) {
3434 state . prepend ( node , `${ node . id . name } =` ) ;
3535 ArrayPrototypePush (
36- state . hoistedDeclarationStatements ,
37- `let ${ node . id . name } ; `
36+ state . hoistedDeclaration ,
37+ `this. ${ node . id . name } = ${ node . id . name } ; `
3838 ) ;
3939 }
4040
@@ -49,8 +49,8 @@ const visitorsWithoutAncestors = {
4949 FunctionDeclaration ( node , state , c ) {
5050 state . prepend ( node , `${ node . id . name } =` ) ;
5151 ArrayPrototypePush (
52- state . hoistedDeclarationStatements ,
53- `var ${ node . id . name } ; `
52+ state . hoistedDeclaration ,
53+ `this. ${ node . id . name } = ${ node . id . name } ; `
5454 ) ;
5555 } ,
5656 FunctionExpression : noop ,
@@ -195,6 +195,7 @@ function processTopLevelAwait(src) {
195195 const state = {
196196 body,
197197 ancestors : [ ] ,
198+ hoistedDeclaration : [ ] ,
198199 hoistedDeclarationStatements : [ ] ,
199200 replace ( from , to , str ) {
200201 for ( let i = from ; i < to ; i ++ ) {
@@ -239,7 +240,10 @@ function processTopLevelAwait(src) {
239240 state . prepend ( last , 'return (' ) ;
240241 state . append ( last . expression , ')' ) ;
241242 }
242-
243+ const hoisted = ArrayPrototypeJoin ( state . hoistedDeclaration , '' ) ;
244+ if ( hoisted . length > 0 ) {
245+ wrappedArray [ wrapPrefix . length - 1 ] = hoisted ;
246+ }
243247 return (
244248 ArrayPrototypeJoin ( state . hoistedDeclarationStatements , '' ) +
245249 ArrayPrototypeJoin ( wrappedArray , '' )
0 commit comments