Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

tame mangles raw regexps #27

debonet opened this Issue Dec 7, 2011 · 4 comments


None yet
3 participants

debonet commented Dec 7, 2011


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


maxtaco commented Dec 9, 2011

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.

debonet commented Dec 9, 2011

Thanks Max!

vjeux commented Jan 15, 2012

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

debonet commented Feb 17, 2012

@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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment