endel / js2php

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

Fail to convert function with split #14

Open hernaneche opened 8 years ago

hernaneche commented 8 years ago

Running with this code

function getStrAfter(str, delimiter) {
       var pre=str.split(delimiter,2);
       if(pre.length>1){
           return pre[1];
       }else{
           return str;
       }           
}

I got


 C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\core\string.js:116
    var regexpData = args[0].raw.match(/^\/([^\/]+)\/([gimy])?$/),
                                ^

TypeError: Cannot read property 'match' of undefined
    at module.exports.split (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\core\string.js:116:33)
    at Object.module.exports.evaluate (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\core.js:22:24)
    at visit (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:198:26)
    at visit (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:166:18)
    at visit (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:68:28)
    at visit (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:58:20)
    at visit (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:52:20)
    at visit (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:266:27)
    at visit (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:52:20)
    at module.exports (C:\Users\Me\AppData\Roaming\npm\node_modules\js2php\index.js:538:22)
endel commented 8 years ago

Hi @hernaneche,

Thanks for trying out this project and for reporting. Unfortunately I do not plan to support this library anymore, since there isn't a real usage scenario I can think of.

In case you'd like to fix this by yourself, it's perfectly feasible to do it by modifying the split call here: https://github.com/endel/js2php/blob/master/core/string.js#L109-L135

Cheers!