endel / js2php

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

return x[1]; #41

Open zaoqi opened 5 years ago

zaoqi commented 5 years ago

function f(x) {
    return x[1];
}

http://endel.me/js2php/

It cannot translate it.

zaoqi commented 5 years ago

But it can translate


function f(x) {
    return x[0];
}
zaoqi commented 5 years ago

and


function f(x) {
    return x[1+0];
}
zaoqi commented 5 years ago

function f(x) {
    return x[1+1];
}

and so on

garata commented 5 years ago

function f(x) { return x[+1]; }

The + operator triggers numeric conversion in this case. Does js2php support JS types coercion?

Very interesting issue anyway.