js2php
js2php copied to clipboard
Cannot read property 'match' of undefined
I've tried to transpile my S-Expression parser to php
But got this error:
/mnt/ssd/projects/jcubic/lip/node_modules/js2php/core/string.js:119
var regexpData = args[0].raw.match(/^\/([^\/]+)\/([gimy])?$/),
^
TypeError: Cannot read property 'match' of undefined
at split (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/core/string.js:119:34)
at Object.evaluate (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/core.js:26:18)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:235:26)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:196:20)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:269:21)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:196:20)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:269:21)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:196:20)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:182:24)
at visit (/mnt/ssd/projects/jcubic/lip/node_modules/js2php/index.js:52:20)
It may be because of this:
var re = new RegExp("((^|[^\\\\])(?:\\\\\\\\)*)" + quote, "g");
in my code I'm parsing multiline string that may have escaped quotes.
This also may be because of my regex for regexes:
var re_re = /^\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimy]*)$/;
Your regex is quite fragile you can't have escaped \/
inside regex literal.
@jcubic can you check this pull-request? there are a bunch of additions I haven't tested yet. maybe your case has been fixed here: https://github.com/endel/js2php/pull/42
when I tried some code on demo page I also got
Uncaught TypeError: (intermediate value).match is not a function
I narrowed down the line which causes it, it is:
y = i[+1];
I tried with different variable names. but seems that index [1] causing this. when I changed to y = i[0+1];
or y = i[+1];
it started working