From 220eec817c3b4c275a0d2addb6d2fd7672e7c9a7 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Wed, 3 Oct 2012 19:03:31 +0200 Subject: [PATCH] Fix issue #37, handle simple identifier in FOR init --- CHANGES | 3 +++ src/slimit/tests/test_parser.py | 12 ++++++++++++ src/slimit/visitors/ecmavisitor.py | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a50bbd0..2f692e9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Change History ============== +0.7.x (unreleased) +- Bug fix (simple identifier in FOR init): https://github.com/rspivak/slimit/issues/37 + 0.7.4 (2012-06-5) ------------------ - Bug fix: https://github.com/rspivak/slimit/issues/34 diff --git a/src/slimit/tests/test_parser.py b/src/slimit/tests/test_parser.py index 6b0f253..911da30 100644 --- a/src/slimit/tests/test_parser.py +++ b/src/slimit/tests/test_parser.py @@ -193,6 +193,18 @@ class ASITestCase(unittest.TestCase): """ for ( ; i < length; i++) { + } + """), + + (""" + var i; + for (i; i < length; i++) { + } + """, + """ + var i; + for (i; i < length; i++) { + } """), ] diff --git a/src/slimit/visitors/ecmavisitor.py b/src/slimit/visitors/ecmavisitor.py index 03500c0..ed57ff6 100644 --- a/src/slimit/visitors/ecmavisitor.py +++ b/src/slimit/visitors/ecmavisitor.py @@ -138,7 +138,7 @@ def visit_For(self, node): if node.init is None: s += ' ; ' elif isinstance(node.init, (ast.Assign, ast.Comma, ast.FunctionCall, - ast.UnaryOp)): + ast.UnaryOp, ast.Identifier)): s += '; ' else: s += ' '