1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fix multiple escaped backslashes in literal strings

This commit is contained in:
xixixao 2013-11-19 23:41:43 +00:00
parent 6847400ccb
commit 130899a39f
4 changed files with 7 additions and 6 deletions

View file

@ -68,9 +68,6 @@
if (opts.interactive) {
return require('./repl').start(replCliOpts);
}
if (opts.watch && !fs.watch) {
return printWarn("The --watch feature depends on Node v0.6.0+. You are running " + process.version + ".");
}
if (opts.stdio) {
return compileStdio();
}

View file

@ -770,7 +770,7 @@
if (heredoc) {
return str.replace(MULTILINER, '\\n');
} else {
return str.replace(/((^|[^\\])\\\\)\n/g, '$1 \\\n').replace(/\\\s*\n\s*/g, '').replace(/\s*\n\s*/g, ' ');
return str.replace(/((^|[^\\])(\\\\)+)\n/g, '$1 \\\n').replace(/\\\s*\n\s*/g, '').replace(/\s*\n\s*/g, ' ');
}
};

View file

@ -694,7 +694,7 @@ exports.Lexer = class Lexer
if heredoc
str.replace MULTILINER, '\\n'
else
str.replace(/((^|[^\\])\\\\)\n/g, '$1 \\\n') #escaped backslash
str.replace(/((^|[^\\])(\\\\)+)\n/g, '$1 \\\n') # escaped backslashes
.replace(/\\\s*\n\s*/g, '') # backslash at EOL
.replace(/\s*\n\s*/g, ' ')

View file

@ -82,8 +82,12 @@ test "#3229, multiline strings", ->
next line', 'escaped backslash before slash\\ next line'
eq 'triple backslash\\\
next line', 'triple backslash\\next line'
eq 'several escaped backslashes\\\\\\
ok', 'several escaped backslashes\\\\\\ ok'
eq 'several escaped backslashes\\\\\\\
ok', 'several escaped backslashes\\\\\\ok'
# Use backslashes at beginning of a line to specify whitespace between lines.
# Backslashes at beginning of lines.
eq 'first line
\ backslash at BOL', 'first line \ backslash at BOL'
eq 'first line\