File tree Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import iterateChain from './iterateChain'
55import getThenHandler from './getThenHandler'
66import getCatchHandler from './getCatchHandler'
77import getFinallyHandler from './getFinallyHandler'
8+ import isGetterOrSetter from './isGetterOrSetter'
89
910function chainLength ( path : NodePath < t . CallExpression > ) : number {
1011 let length = 0
@@ -36,9 +37,10 @@ export default function shouldIgnoreChain(
3637) : boolean {
3738 const { parentPath } = path
3839 if (
39- ! parentPath . isReturnStatement ( ) &&
40- ! parentPath . isAwaitExpression ( ) &&
41- ! parentPath . isFunction ( )
40+ ( ! parentPath . isReturnStatement ( ) &&
41+ ! parentPath . isAwaitExpression ( ) &&
42+ ! parentPath . isFunction ( ) ) ||
43+ isGetterOrSetter ( path . getFunctionParent ( ) )
4244 ) {
4345 if ( chainLength ( path ) <= 2 && ! hasComplexHandlers ( path ) ) return true
4446 }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ class A {
33 method() {return p.then(x => f(x))}
44 get prop() {return p.then(x => f(x))}
55 set prop(val) {return p.then(x => f(x))}
6+ get longchain() {return p.then(x => f(x)).then(y => g(y)).then(z => h(z))}
67}
78const obj = {
89 method() {return p.then(x => f(x))},
@@ -17,15 +18,17 @@ class A {
1718 return f(x);
1819 }
1920 get prop() {
20- return (async () => {
21- const x = await p;
22- return await f(x);
23- })()
21+ return p.then(x => f(x))
2422 }
2523 set prop(val) {
24+ return p.then(x => f(x))
25+ }
26+ get longchain() {
2627 return (async () => {
27- const x = await p;
28- return await f(x);
28+ const x = await p
29+ const y = await f(x)
30+ const z = await g(y)
31+ return await h(z)
2932 })()
3033 }
3134}
@@ -35,16 +38,10 @@ const obj = {
3538 return f(x);
3639 },
3740 get prop() {
38- return (async () => {
39- const x = await p;
40- return await f(x);
41- })()
41+ return p.then(x => f(x))
4242 },
4343 set prop(val) {
44- return (async () => {
45- const x = await p;
46- return await f(x);
47- })()
44+ return p.then(x => f(x))
4845 }
4946};
5047`
You can’t perform that action at this time.
0 commit comments