Skip to content

Commit 252418b

Browse files
wcjohnsonrattrayalex
authored andcommitted
Fix implicit returns of assignments
commit e5c5af2ba97c0068d52901f3a6dc30b5017181fa Author: William C. Johnson <wcjohnson@oigroup.net> Date: Sat May 13 15:17:37 2017 -0400 Fix implicit returns of assignments
1 parent 1c0ea1e commit 252418b

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

src/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,7 @@ export default function (babel) {
195195
if (!tailPath) continue;
196196

197197
if (tailPath.isExpressionStatement()) {
198-
// TODO: add linting to discourage
199-
if (tailPath.get("expression").isAssignmentExpression()) {
200-
tailPath.insertAfter(getNewNode(tailPath.node.expression.left, tailPath));
201-
} else {
202-
tailPath.replaceWith(getNewNode(tailPath.node.expression, tailPath));
203-
}
198+
tailPath.replaceWith(getNewNode(tailPath.node.expression, tailPath));
204199
} else if (tailPath.isVariableDeclaration()) {
205200
// TODO: handle declarations.length > 1
206201
// TODO: add linting to discourage
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
async function fn() {
2-
x.y = await fetch();
3-
return x.y;
4-
}
2+
return x.y = await fetch();
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let x = 0
2+
result = [for idx i in Array(10):
3+
now x = i
4+
]
5+
assert.deepEqual(result, [0,1,2,3,4,5,6,7,8,9])
6+
assert(x === 9)

test/fixtures/comprehensions/assignment-expr/expected.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
const _arr = [];
33

44
for (let _arr2 = Array(10), i = 0, _len = _arr2.length; i < _len; i++) {
5-
x = f(i);
6-
7-
_arr.push(x)
5+
_arr.push(x = f(i));
86
}
97

108
return _arr;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
function fn(x) {
2-
x = 4;
3-
return x;
4-
}
2+
return x = 4;
3+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
function fn(obj) {
2-
obj.x = 4;
3-
return obj.x;
4-
}
2+
return obj.x = 4;
3+
}

0 commit comments

Comments
 (0)