Skip to content

Commit

Permalink
dont lift declarations when not intialized (fix #309) (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam authored and boopathi committed Dec 1, 2016
1 parent bcb486c commit b76482f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -135,6 +135,16 @@ describe("transform-merge-sibling-variables-plugin", () => {
expect(transform(source)).toBe(source);
});

it("dont lift when the declarations are not initialized", () => {
const source = unpad(`
for (var i = 0;;) {
var i;
}
`);

expect(transform(source)).toBe(source);
});

it("dont lift when there are multiple declarations", () => {
const source = unpad(`
for (var i = 0; i < 0; i++) {
Expand Down
Expand Up @@ -15,7 +15,7 @@ module.exports = function({ types: t }) {

let firstNode = body[0].node.declarations[0];

if (!t.isIdentifier(firstNode.id)) {
if (!t.isIdentifier(firstNode.id) || !firstNode.init) {
return;
}

Expand Down

0 comments on commit b76482f

Please sign in to comment.