File tree 2 files changed +38
-1
lines changed
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 5
5
needsAwait ,
6
6
isPromiseRejectCall ,
7
7
isInTryBlock ,
8
+ isLastStatementInFunction ,
8
9
} from './predicates'
9
10
import { awaited } from './builders'
10
11
@@ -14,6 +15,8 @@ function unwrapPromiseResolves(
14
15
while ( node && isPromiseResolveCall ( node ) ) {
15
16
node = ( node as t . CallExpression ) . arguments [ 0 ]
16
17
}
18
+ if ( node && node . type === 'Identifier' && node . name === 'undefined' )
19
+ return undefined
17
20
return node as t . Expression
18
21
}
19
22
@@ -93,7 +96,11 @@ export default function finalCleanup(path: NodePath<t.Function>): void {
93
96
? awaited ( unwrapped )
94
97
: unwrapped
95
98
)
96
- } else argument . remove ( )
99
+ } else if ( isLastStatementInFunction ( path ) ) {
100
+ path . remove ( )
101
+ } else {
102
+ argument . remove ( )
103
+ }
97
104
} else if ( value . isCallExpression ( ) && isPromiseRejectCall ( value ) ) {
98
105
const argument = value . node . arguments [ 0 ]
99
106
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