Permalink
Browse files

fixes #1: conditionally separates variable declarations

using or caused lazy evaluation of truthy assignments. if not in a for loop, we can use ; to separate instead
  • Loading branch information...
1 parent a311b79 commit c73678c960df7525037267652c568202d5ed5abb @joeldart joeldart committed Mar 22, 2013
Showing with 9 additions and 2 deletions.
  1. +5 −2 slowmo/scope-mangler.js
  2. +4 −0 test/test-scope-mangler.js
View
@@ -42,8 +42,11 @@ define(function(require, module, exports) {
node.declarations.forEach(function(decl) {
decls.push(makeDeclareCode(decl.id.name, decl.init, decl));
});
- var newCode = decls.join(' || ');
- if (node.parent.type != "ForStatement")
+
+ var parentIsFor = node.parent.type === "ForStatement";
+ var separator = parentIsFor ? " || " : " ; ";
+ var newCode = decls.join(separator);
+ if (!parentIsFor)
newCode += ';'
return node.update(newCode);
}
@@ -87,6 +87,10 @@ defineTests([
declTest("var i, j = 2;", [["i", undefined, "i"], ["j", 2, "j = 2"]]);
});
+ test("var decls w/ commas work with value first", function() {
+ declTest("var i = 3, j = 2;", [["i", 3, "i = 3"], ["j", 2, "j = 2"]]);
+ });
+
test("multiple var decls work", function() {
declTest("var i; var j = 2;",
[["i", undefined, "i"], ["j", 2, "j = 2"]]);

0 comments on commit c73678c

Please sign in to comment.