tame mangles raw regexps
debonet opened this issue · comments
Example:
if ( /^some/.test( "something" ) ){
... whatever
}
gets tamed into:
// ... tame goop
if ( / ^some / .test ( "something )) {
... whatever
}
// ... tame goop
Note the spaces before and after the /'s in the regexp which is a different regular expression all together
Too true! Sorry about this, for now, a workaround is new RegExp("..")
. I'm working a bit on coffee-script now, but will eventually return to tamejs with a big rewrite. That'll fix this, I hope.
Thanks Max!
Not only it messes up the regexp by adding spaces inside, it will also make the code not parse anymore if you use a modifier. For example
name.replace(/[=\s]+/g, '');
Will throw a parsing error when running the converted code:
name . replace ( / [ = \s ] + / g , '' ) ;
^
SyntaxError: Unexpected identifier
@vjeux using the new RegExp(pattern, modifier)
form will work for now. Eg. in your example use:
name.replace(new RegExp("[=\s]+","g"),'')
or better, if you do this multiple times:
var re = new RegExp("[=\s]+","g");
name.replace(re,'')