Skip to content

Commit 3cf21b5

Browse files
committed
Fix exception for return andThen()
1 parent 174168b commit 3cf21b5

3 files changed

Lines changed: 67 additions & 16 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { test } from 'qunit';
2+
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
3+
4+
moduleForAcceptance('click');
5+
6+
test('visiting /foo', function(assert) {
7+
visit('/foo');
8+
andThen(function() {
9+
});
10+
11+
andThen(function() {
12+
assert.ok(true);
13+
});
14+
});
15+
16+
test('visiting /foo', function(assert) {
17+
visit('/foo');
18+
return andThen(function() {
19+
});
20+
});
21+
22+
test('visiting /foo', function(assert) {
23+
visit('/foo');
24+
return andThen(function() {
25+
assert.ok(true);
26+
});
27+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { visit } from '@ember/test-helpers';
2+
import { test } from 'qunit';
3+
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
4+
5+
moduleForAcceptance('click');
6+
7+
test('visiting /foo', async function(assert) {
8+
await visit('/foo');
9+
assert.ok(true);
10+
});
11+
12+
test('visiting /foo', async function(assert) {
13+
await visit('/foo');
14+
});
15+
16+
test('visiting /foo', async function(assert) {
17+
await visit('/foo');
18+
assert.ok(true);
19+
});

lib/utils.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/(.+?):eq\((\d+)\)$/);
131+
let [, query, eqIndex] = string.match(/(.+?):eq\((\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

249247
function 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

492497
function 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

Comments
 (0)