File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 55 needsAwait ,
66 isPromiseRejectCall ,
77 isInTryBlock ,
8+ isLastStatementInFunction ,
89} from './predicates'
910import { awaited } from './builders'
1011
@@ -14,6 +15,8 @@ function unwrapPromiseResolves(
1415 while ( node && isPromiseResolveCall ( node ) ) {
1516 node = ( node as t . CallExpression ) . arguments [ 0 ]
1617 }
18+ if ( node && node . type === 'Identifier' && node . name === 'undefined' )
19+ return undefined
1720 return node as t . Expression
1821}
1922
@@ -93,7 +96,11 @@ export default function finalCleanup(path: NodePath<t.Function>): void {
9396 ? awaited ( unwrapped )
9497 : unwrapped
9598 )
96- } else argument . remove ( )
99+ } else if ( isLastStatementInFunction ( path ) ) {
100+ path . remove ( )
101+ } else {
102+ argument . remove ( )
103+ }
97104 } else if ( value . isCallExpression ( ) && isPromiseRejectCall ( value ) ) {
98105 const argument = value . node . arguments [ 0 ]
99106 if ( t . isExpression ( argument ) ) {
Original file line number Diff line number Diff line change 1+ export const input = `
2+ function foo() {
3+ return Promise.resolve(2)
4+ }
5+ function bar() {
6+ return Promise.resolve()
7+ }
8+ function baz() {
9+ if (qux) {
10+ return Promise.resolve()
11+ }
12+ return Promise.resolve(3)
13+ }
14+ `
15+
16+ export const options = { }
17+
18+ export const expected = `
19+ async function foo() {
20+ return 2
21+ }
22+ async function bar() {
23+ }
24+ async function baz() {
25+ if (qux) {
26+ return
27+ }
28+ return 3
29+ }
30+ `
You can’t perform that action at this time.
0 commit comments