endel / js2php

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

Global parseInt and parseFloat functions #33

Closed 2pha closed 6 years ago

2pha commented 6 years ago

The global javascript functions parseInt and parseFloat map pretty well to the PHP intval and floatval functions, it would be nice to support them. (and I need them on a project I am on).

I had a quick look in to it and it seems it won't be as easy as mapping functions that are on objects as these functions are in the global scope.

endel commented 6 years ago

Thanks for the suggestion @2pha, I've just published version 0.1.6 having this!

It's now possible to extend global functions on the global.js file: https://github.com/endel/js2php/blob/ebe309f3c5f085e1100c6790a95d4763040ada69/core/global.js#L5-L15

2pha commented 6 years ago

Awesome, thanks mate

2pha commented 6 years ago

A bit of a problem with this.

Add this to the "global_functions.js" fixture has an error. let temp = "50"; var_dump(parseInt(temp));

Error is: "'Cannot read property 'scope' of undefined' TypeError: Cannot read property 'scope' of undefined". in "at Object.get (/js2php/scope.js:66:14)"

34