tame mangles raw regexps #27

debonet opened this Issue Dec 7, 2011 · 4 comments


None yet

3 participants



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