endel / js2php

JavaScript (ES6) to PHP source-to-source transpiler.
https://endel.github.io/js2php/
MIT License
333 stars 41 forks source link

there is a bug when converting "for" loop #13

Closed supersky07 closed 9 years ago

supersky07 commented 9 years ago

when convert"for(var i = 0; i < test.length; i++)"

endel commented 9 years ago

Hi @supersky07 ,

There is a test case for for and for in loops here: https://github.com/endel/js2php/blob/master/test/fixtures/loops.js

Could you write a test case to demonstrate the problem you've found?

Thank you.

supersky07 commented 9 years ago

hi @endel , Thank you for your reply. I saw that case.

Here are the problems: 1."for(var i = 0; i < 10; i++)" After converting, there is a "\n" after $i=0;

2."for(j=0;j<10;j++)" When there is only one variable before the first ";" and at the same time it has no "var".After converting, there is no ";" between "j=0" and "j<10".

PS: I try to read your code, but it is a little difficult for me to understand the main process. Do you have some flow chart for reference?

Thank you.

endel commented 9 years ago

@supersky07, actually after compilation there will be ";\n". It isn't a pretty output but it's a valid PHP syntax, as you can see in the test case:

To be sure that it outputs a valid syntax you may pipe the output string to php interpreter from the commandline:

./js2php test/fixtures/loops.js | php
int(1)
int(2)
int(3)
int(4)
...
supersky07 commented 9 years ago

I see, thank you. After compilation, I will format that code, it makes me a little uncomfortable, LOL.

Thanks again, it really helps me a lot!