Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8 from dmcinnes/master

Fix for loop ECMA Script rendering
  • Loading branch information...
commit 71f5c6814554167f0428c2bb2c6f9232e9cacf75 2 parents 90cdd3f + b9d80ba
@tenderlove authored
View
1  lib/rkelly/visitors/ecma_visitor.rb
@@ -35,6 +35,7 @@ def visit_NumberNode(o)
def visit_ForNode(o)
init = o.init ? o.init.accept(self) : ';'
+ init << ';' unless init[-1] == ';' # make sure it has a ;
test = o.test ? o.test.accept(self) : ''
counter = o.counter ? o.counter.accept(self) : ''
"for(#{init} #{test}; #{counter}) #{o.value.accept(self)}"
View
6 test/test_ecma_visitor.rb
@@ -183,6 +183,12 @@ def test_for_in_node
assert_to_ecma('for(foo in bar) { var x = 10; }')
end
+ def test_for_node
+ assert_to_ecma('for(var i = 0; i < 10; i++) { var x = 10; }')
+ assert_to_ecma('var i = 0; for(; i < 10; i++) { var x = 10; }')
+ assert_to_ecma('var i; for(i = 0; i < 6; ++i) { var x = 10; }')
+ end
+
def assert_to_ecma(expected, actual = nil)
ecma = @parser.parse(actual || expected).to_ecma
ecma = ecma.gsub(/\n/, ' ').gsub(/\s+/, ' ')
Please sign in to comment.
Something went wrong with that request. Please try again.