@@ -221,22 +221,26 @@ function processTopLevelAwait(src) {
221
221
return null ;
222
222
}
223
223
224
- const last = body . body [ body . body . length - 1 ] ;
225
- if ( last . type === 'ExpressionStatement' ) {
226
- // For an expression statement of the form
227
- // ( expr ) ;
228
- // ^^^^^^^^^^ // last
229
- // ^^^^ // last.expression
230
- //
231
- // We do not want the left parenthesis before the `return` keyword;
232
- // therefore we prepend the `return (` to `last`.
233
- //
234
- // On the other hand, we do not want the right parenthesis after the
235
- // semicolon. Since there can only be more right parentheses between
236
- // last.expression.end and the semicolon, appending one more to
237
- // last.expression should be fine.
238
- state . prepend ( last , 'return (' ) ;
239
- state . append ( last . expression , ')' ) ;
224
+ for ( let i = body . body . length - 1 ; i >= 0 ; i -- ) {
225
+ const node = body . body [ i ] ;
226
+ if ( node . type === 'EmptyStatement' ) continue ;
227
+ if ( node . type === 'ExpressionStatement' ) {
228
+ // For an expression statement of the form
229
+ // ( expr ) ;
230
+ // ^^^^^^^^^^ // node
231
+ // ^^^^ // node.expression
232
+ //
233
+ // We do not want the left parenthesis before the `return` keyword;
234
+ // therefore we prepend the `return (` to `node`.
235
+ //
236
+ // On the other hand, we do not want the right parenthesis after the
237
+ // semicolon. Since there can only be more right parentheses between
238
+ // node.expression.end and the semicolon, appending one more to
239
+ // node.expression should be fine.
240
+ state . prepend ( node , 'return (' ) ;
241
+ state . append ( node . expression , ')' ) ;
242
+ }
243
+ break ;
240
244
}
241
245
242
246
return (
0 commit comments