Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #31 from duilio/master

Issue in "for" visitors when the init is a function call
  • Loading branch information...
commit 0e8dd77d04fe5a29a2a9e8b6a2de1ec1bcfcadaf 2 parents c37b655 + 3832095
Ruslan Spivak authored
6 src/slimit/tests/test_cmd.py
View
@@ -88,8 +88,9 @@ def test_main_stdin_stdout(self):
# slimit.minifier should be deleted from sys.modules in order
# to have a proper reference to sys.stdin and sys.stdou when
# 'main' definition is evaluated during module import
+ old_module = None
try:
- del sys.modules['slimit.minifier']
+ old_module = sys.modules.pop('slimit.minifier')
except KeyError:
pass
@@ -99,6 +100,8 @@ def test_main_stdin_stdout(self):
main(['-m'])
self.assertEqual('function foo(){var a=5;}', out.getvalue())
+ if old_module:
+ sys.modules['slimit.minifier'] = old_module
def test_main_sys_argv(self):
out = StringIO.StringIO()
@@ -108,4 +111,3 @@ def test_main_sys_argv(self):
main(inp=inp, out=out)
self.assertEqual('var a=5;', out.getvalue())
-
6 src/slimit/tests/test_ecmavisitor.py
View
@@ -425,6 +425,12 @@ def setUp(self):
# typeof
'typeof second.length === "number";',
+
+ """
+ for (o(); i < 3; i++) {
+
+ }
+ """
]
def make_test_function(input, expected):
3  src/slimit/tests/test_minifier.py
View
@@ -376,6 +376,9 @@ def assertMinified(self, source, expected):
}(jQuery));
""",
"(function($){$.hello='world';}(jQuery));"),
+
+ # another issue
+ ('for(o();i<3;i++){}', 'for(o();i<3;i++){}'),
]
2  src/slimit/visitors/ecmavisitor.py
View
@@ -107,7 +107,7 @@ def visit_For(self, node):
s += self.visit(node.init)
if node.init is None:
s += ' ; '
- elif isinstance(node.init, (ast.Assign, ast.Comma)):
+ elif isinstance(node.init, (ast.Assign, ast.Comma, ast.FunctionCall)):
s += '; '
else:
s += ' '
3  src/slimit/visitors/minvisitor.py
View
@@ -140,7 +140,8 @@ def visit_For(self, node):
s += self.visit(node.init)
if node.init is None:
s += ';'
- elif isinstance(node.init, (ast.Assign, ast.Comma, ast.Conditional)):
+ elif isinstance(node.init, (ast.Assign, ast.Comma, ast.Conditional,
+ ast.FunctionCall)):
s += ';'
else:
s += ''
Please sign in to comment.
Something went wrong with that request. Please try again.