Skip to content

Commit 4f714cc

Browse files
authored
Merge pull request #4444 from alangpierce/upstream-fix-heregex-end-location
Place ending heregex tokens one index earlier
2 parents 3d0d04e + f757614 commit 4f714cc

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

lib/coffee-script/lexer.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ exports.Lexer = class Lexer
343343
@token 'CALL_START', '(', 0, 0
344344
@mergeInterpolationTokens tokens, {delimiter: '"', double: yes}, @formatHeregex
345345
if flags
346-
@token ',', ',', index, 0
347-
@token 'STRING', '"' + flags + '"', index, flags.length
348-
@token ')', ')', end, 0
349-
@token 'REGEX_END', ')', end, 0
346+
@token ',', ',', index - 1, 0
347+
@token 'STRING', '"' + flags + '"', index - 1, flags.length
348+
@token ')', ')', end - 1, 0
349+
@token 'REGEX_END', ')', end - 1, 0
350350

351351
end
352352

test/location.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,29 @@ test "Verify indented heredocs have the right position", ->
585585
eq stringToken[2].last_line, 3
586586
eq stringToken[2].last_column, 4
587587

588+
test "Verify heregexes with interpolations have the right ending position", ->
589+
source = '''
590+
[a ///#{b}///g]
591+
'''
592+
[..., stringEnd, comma, flagsString, regexCallEnd, regexEnd, fnCallEnd,
593+
arrayEnd, terminator] = CoffeeScript.tokens source
594+
595+
eq comma[0], ','
596+
eq arrayEnd[0], ']'
597+
598+
assertColumn = (token, column) ->
599+
eq token[2].first_line, 0
600+
eq token[2].first_column, column
601+
eq token[2].last_line, 0
602+
eq token[2].last_column, column
603+
604+
arrayEndColumn = arrayEnd[2].first_column
605+
for token in [comma, flagsString]
606+
assertColumn token, arrayEndColumn - 2
607+
for token in [regexCallEnd, regexEnd, fnCallEnd]
608+
assertColumn token, arrayEndColumn - 1
609+
assertColumn arrayEnd, arrayEndColumn
610+
588611
test "Verify all tokens get a location", ->
589612
doesNotThrow ->
590613
tokens = CoffeeScript.tokens testScript

0 commit comments

Comments
 (0)