diff --git a/lib/coffee_script/lexer.js b/lib/coffee_script/lexer.js index 1f1f2d13..3070ad1d 100644 --- a/lib/coffee_script/lexer.js +++ b/lib/coffee_script/lexer.js @@ -29,7 +29,7 @@ STRING_NEWLINES = /\n[ \t]*/g; COMMENT_CLEANER = /(^[ \t]*#|\n[ \t]*$)/mg; NO_NEWLINE = /^([+\*&|\/\-%=<>:!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)$/; - HEREDOC_INDENT = /^[ \t]+/g; + HEREDOC_INDENT = /^[ \t]+/mg; // Tokens which a regular expression will never immediately follow, but which // a division operator might. // See: http://www.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions @@ -148,8 +148,8 @@ return false; } doc = match[2] || match[4]; - indent = doc.match(HEREDOC_INDENT).sort()[0]; - doc = doc.replace(new RegExp("^" + indent, 'g'), '').replace(MULTILINER, "\\n").replace('"', '\\"'); + indent = (doc.match(HEREDOC_INDENT) || ['']).sort()[0]; + doc = doc.replace(new RegExp("^" + indent, 'gm'), '').replace(MULTILINER, "\\n").replace('"', '\\"'); this.token('STRING', '"' + doc + '"'); this.line += this.count(match[1], "\n"); this.i += match[1].length; diff --git a/src/lexer.coffee b/src/lexer.coffee index 48f4031f..69ab3cfc 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -43,7 +43,7 @@ MULTILINER : /\n/g STRING_NEWLINES : /\n[ \t]*/g COMMENT_CLEANER : /(^[ \t]*#|\n[ \t]*$)/mg NO_NEWLINE : /^([+\*&|\/\-%=<>:!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)$/ -HEREDOC_INDENT : /^[ \t]+/g +HEREDOC_INDENT : /^[ \t]+/mg # Tokens which a regular expression will never immediately follow, but which # a division operator might. @@ -126,8 +126,8 @@ lex::string_token: -> lex::heredoc_token: -> return false unless match = @chunk.match(HEREDOC) doc: match[2] or match[4] - indent: doc.match(HEREDOC_INDENT).sort()[0] - doc: doc.replace(new RegExp("^" + indent, 'g'), '') + indent: (doc.match(HEREDOC_INDENT) or ['']).sort()[0] + doc: doc.replace(new RegExp("^" + indent, 'gm'), '') .replace(MULTILINER, "\\n") .replace('"', '\\"') @token 'STRING', '"' + doc + '"'