@@ -96,8 +96,6 @@ function isJQuerySelectExpression(j, node, path) {
9696 return false ;
9797}
9898
99-
100-
10199/**
102100 * Check if `node` is a `find(selector)` expression
103101 *
@@ -130,15 +128,15 @@ function migrateSelector(j, selector) {
130128
131129 // Transform tail-eq selector to a find all
132130 if ( tailEqRegex . test ( string ) ) {
133- let [ , query , eqIndex ] = string . match ( / ( .+ ?) : e q \( ( \d + ) \) $ / ) ;
131+ let [ , query , eqIndex ] = string . match ( / ( .+ ?) : e q \( ( \d + ) \) $ / ) ;
134132 selector . value = query ;
135133 if ( eqIndex === '0' ) {
136134 // findAll('*')[0] === find('*')
137135 addImportStatement ( [ 'find' ] ) ;
138136 return createFindExpression ( j , [ selector ] ) ;
139137 } else {
140138 addImportStatement ( [ 'findAll' ] ) ;
141- return createArraySubscriptExpression ( j , createFindAllExpression ( j , [ selector ] ) , + eqIndex ) ;
139+ return createArraySubscriptExpression ( j , createFindAllExpression ( j , [ selector ] ) , + eqIndex ) ;
142140 }
143141 }
144142 }
@@ -248,11 +246,11 @@ function createQuerySelectorAllExpression(j, args, fileRoot) {
248246
249247function isQuerySelectorAllCallExpression ( j , node ) {
250248 return j . CallExpression . check ( node )
251- && j . MemberExpression . check ( node . callee )
252- && j . MemberExpression . check ( node . callee . object )
253- // && j.ThisExpression.check(node.callee.object.object)
254- && node . callee . object . property . name === 'element'
255- && node . callee . property . name === 'querySelectorAll' ;
249+ && j . MemberExpression . check ( node . callee )
250+ && j . MemberExpression . check ( node . callee . object )
251+ // && j.ThisExpression.check(node.callee.object.object)
252+ && node . callee . object . property . name === 'element'
253+ && node . callee . property . name === 'querySelectorAll' ;
256254}
257255
258256/**
@@ -332,7 +330,7 @@ function createBlurExpression(j, selector) {
332330 return j . awaitExpression (
333331 j . callExpression (
334332 j . identifier ( 'blur' ) ,
335- [ migrateSelector ( j , selector ) ]
333+ [ migrateSelector ( j , selector ) ]
336334 )
337335 ) ;
338336}
@@ -475,13 +473,20 @@ function dropAndThen(j, root) {
475473 . find ( j . CallExpression , { callee : { name : 'andThen' } } )
476474 . map ( ( path ) => path . parent )
477475 . replaceWith ( ( { node } ) => {
478- let body = node . expression . arguments [ 0 ] . body ;
479-
480- if ( j . CallExpression . check ( body ) ) {
481- return j . expressionStatement ( body ) ;
476+ let body ;
477+ if ( j . ExpressionStatement . check ( node ) ) {
478+ body = node . expression . arguments [ 0 ] . body ;
479+ } else if ( j . ReturnStatement . check ( node ) ) {
480+ body = node . argument . arguments [ 0 ] . body ;
482481 }
483482
484- return body . body ;
483+ if ( body ) {
484+ if ( j . CallExpression . check ( body ) ) {
485+ return j . expressionStatement ( body ) ;
486+ }
487+
488+ return body . body ;
489+ }
485490 } ) ;
486491
487492 if ( replacements . length > 0 ) {
@@ -491,7 +496,7 @@ function dropAndThen(j, root) {
491496
492497function makeAwait ( j , collection ) {
493498 collection
494- . filter ( ( { parent : { node } } ) => ! j . AwaitExpression . check ( node ) )
499+ . filter ( ( { parent : { node } } ) => ! j . AwaitExpression . check ( node ) )
495500 . replaceWith ( ( { node } ) => j . awaitExpression ( node ) )
496501 . forEach ( ( path ) => {
497502
0 commit comments