Search code examples
javascriptregexinternet-explorer-8coffeescripthamlc

Haml Coffee ie8 error


I'm currently using haml_coffee_assets on a project with backbone. All browsers seem to work quite well........ except IE8.

Error I receive: Expected ']' in regular expression

the line it refers to is the following:

 HAML.findAndPreserve = function(text) {
      var tags;
      tags = 'textarea,pre'.split(',').join('|');
      // **THE LINE BELOW** 
      return text = text.replace(RegExp("<(" + tags + ")>([^]*?)<\\/\\1>", "g"), function(str, tag, content) {
        return "<" + tag + ">" + (window.HAML.preserve(content)) + "</" + tag + ">";
      });
    };

It is preventing the entire page from compiling on load. The data-bound divs are completely empty, but all other static elements are loading fine.


Solution

  • The RegExp in question is there to preserve newlines in certain tags by converting them to its HTML entity format, so

    <pre>Bar
    Baz</pre>
    

    becomes

    <pre>Bar&#x000A;Baz</pre>
    

    Since you cannot make the dot match newlines in JavaScript, you can use an empty negotiated character class to match everything. Since we're in the browser, you can easily overwrite HAML.findAndPreserve to test alternative approaches. I have no problems changing it for IE8, but I refuse to install a VM just to test it :-)

    An alternative to [^] is [\s\S] and I've successfully tested it in Node.js by changing the corresponding code in Haml Coffee and all specs are passing fine. Can you please try it in IE8 and report if that is valid and works? Thank you!