js2php icon indicating copy to clipboard operation
js2php copied to clipboard

brackets are lost

Open cuixiping opened this issue 8 years ago • 2 comments

function foo( a, b, c, d ) {
	return ( a + b ) * ( c + d );
}

is incorrectly converted to

<?php
function foo($a, $b, $c, $d) {
	return $a + $b * $c + $d;  //should be ($a + $b) * ($c + $d)
}

the brackets are lost.

tested on http://endel.me/js2php/

cuixiping avatar Nov 02 '17 15:11 cuixiping

I can confirm this

2pha avatar Jan 01 '18 15:01 2pha

This problem is because the tool uses only the AST node tree to rewrite the code, without taking the tokens into consideration. Each ( and ) are tokens that are not present in the AST node tree. You can inspect the results of espree.parse() to confirm this.

endel avatar Jun 19 '18 23:06 endel