| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9fa6dfb commit 344c03b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,8 @@ const testCases = [ | |||
| 22 | 22 | `(async () => { return (await ${surrogate}) })()` ], | |
| 23 | 23 | [ 'await 0;', | |
| 24 | 24 | '(async () => { return (await 0); })()' ], | |
| 25 | + [ 'await 0;;;', | ||
| 26 | + '(async () => { return (await 0);;; })()' ], | ||
| 25 | 27 | [ `await ${surrogate};`, | |
| 26 | 28 | `(async () => { return (await ${surrogate}); })()` ], | |
| 27 | 29 | [ `await ${surrogate};`, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments