Merge pull request #3849 from lydell/regex-end-invalid-escape

Fix error message for invalid escape at end of regex
This commit is contained in:
Jeremy Ashkenas 2015-02-12 13:55:10 -05:00
commit dc8a2b17d0
3 changed files with 11 additions and 3 deletions

View File

@ -309,8 +309,9 @@
break;
case !(match = REGEX.exec(this.chunk)):
regex = match[0], body = match[1], closed = match[2];
this.validateEscapes(regex, {
isRegex: true
this.validateEscapes(body, {
isRegex: true,
offsetInChunk: 1
});
index = regex.length;
ref2 = this.tokens, prev = ref2[ref2.length - 1];

View File

@ -263,7 +263,7 @@ exports.Lexer = class Lexer
{tokens, index} = match
when match = REGEX.exec @chunk
[regex, body, closed] = match
@validateEscapes regex, isRegex: yes
@validateEscapes body, isRegex: yes, offsetInChunk: 1
index = regex.length
[..., prev] = @tokens
if prev

View File

@ -486,6 +486,13 @@ test "#3795: invalid escapes", ->
#{b} \\x0
^\^^
'''
assertErrorFormat '''
/ab\\u/
''', '''
[stdin]:1:4: error: invalid escape sequence \\u
/ab\\u/
^\^
'''
test "illegal herecomment", ->
assertErrorFormat '''