Skip to content

Commit f49a1bc

Browse files
authored
Merge pull request #25 from simonihmig/andthen-click
Fix andThen with arrow function
2 parents 8dfa37d + 3ce0939 commit f49a1bc

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

__testfixtures__/acceptance/nested-in-and-then.input.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ test('visiting /twiddles', function(assert) {
2626

2727
andThen(() => assert.ok(true));
2828
});
29+
30+
test('visiting /twiddles', function(assert) {
31+
andThen(() => {
32+
click('.foo');
33+
});
34+
});

__testfixtures__/acceptance/nested-in-and-then.output.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ test('visiting /twiddles', async function(assert) {
1414
assert.ok(true);
1515

1616
assert.ok(true);
17-
});
17+
});
18+
19+
test('visiting /twiddles', async function(assert) {
20+
await click('.foo');
21+
});

lib/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ function createImportStatement(j, source, imported, local) {
428428
*/
429429
function findParentFunction(j, path) {
430430
while (path = path.parent) {
431-
if (j.FunctionExpression.check(path.node) && !isAndThenCall(j, path) || j.FunctionDeclaration.check(path.node) || j.ArrowFunctionExpression.check(path.node)) {
431+
if (
432+
j.FunctionExpression.check(path.node) && !isAndThenCall(j, path)
433+
|| j.FunctionDeclaration.check(path.node)
434+
|| j.ArrowFunctionExpression.check(path.node) && !isAndThenCall(j, path)) {
432435
return path;
433436
}
434437
}
@@ -442,7 +445,8 @@ function findParentFunction(j, path) {
442445
*/
443446
function isAndThenCall(j, path) {
444447
let parentNode = path.parent.node;
445-
return j.FunctionExpression.check(path.node)
448+
return (
449+
j.FunctionExpression.check(path.node) || j.ArrowFunctionExpression.check(path.node))
446450
&& j.CallExpression.check(parentNode)
447451
&& j.Identifier.check(parentNode.callee)
448452
&& parentNode.callee.name === 'andThen';

0 commit comments

Comments
 (0)