endel/js2php

brackets are lost

cuixiping opened this issue · 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/

2pha commented

I can confirm this

endel commented

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.