Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cfg: for in loop without declaration should work

  • Loading branch information...
commit e33e0e33df352d234536b2bf9454c3fa439978bd 1 parent 4356c82
@indutny authored
Showing with 21 additions and 1 deletion.
  1. +8 −0 lib/spoon/cfg.js
  2. +0 −1  test/asyncify-test.js
  3. +13 −0 test/cfg-test.js
View
8 lib/spoon/cfg.js
@@ -998,6 +998,14 @@ Cfg.prototype.visitForIn = function visitFor(ast) {
if (left.type === 'VariableDeclaration') {
this.visit(left);
left = left.declarations[0].id;
+ } else {
+ // No declaration?! Create assignment
+ this.visit({
+ type: 'AssignmentExpression',
+ operator: '=',
+ left: left,
+ right: { type: 'Identifier', name: 'undefined' }
+ });
}
var leftName = left.name;
View
1  test/asyncify-test.js
@@ -13,7 +13,6 @@ describe('Spoon', function() {
var out = spoon.render(cfg);
var code = uglify.uglify.gen_code(out, { beautify: true });
- console.log(code);
var res,
once = false;
View
13 test/cfg-test.js
@@ -118,6 +118,19 @@ describe('Spoon', function() {
9);
});
+ it('should work with for in loop (without declaration)', function() {
+ test('var obj = { 0: 1, 9: 1 };\n' +
+ 'for (i in obj) {\n' +
+ ' if (i == 9) {\n' +
+ ' break;\n' +
+ ' } else if (i > 10) {\n' +
+ ' continue;\n' +
+ ' }\n' +
+ '}\n' +
+ 'i',
+ 9);
+ });
+
it('should work with try catch', function() {
test('var a = 2;\n' +
'try {\n' +
Please sign in to comment.
Something went wrong with that request. Please try again.