Skip to content

Commit 5fce3fb

Browse files
committed
Merge branch 'master' of github.com:jashkenas/coffeescript
2 parents 16acd6c + afae0db commit 5fce3fb

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

lib/coffee-script/lexer.js

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

src/lexer.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,11 @@ exports.Lexer = class Lexer
573573

574574
[firstToken, ..., lastToken] = tokens
575575
firstToken[2].first_column -= delimiter.length
576-
lastToken[2].last_column += delimiter.length
576+
if lastToken[1].substr(-1) is '\n'
577+
lastToken[2].last_line += 1
578+
lastToken[2].last_column = delimiter.length - 1
579+
else
580+
lastToken[2].last_column += delimiter.length
577581
lastToken[2].last_column -= 1 if lastToken[1].length is 0
578582

579583
{tokens, index: offsetInChunk + delimiter.length}

test/location.coffee

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,42 @@ test "Verify real CALL_END tokens have the right position", ->
528528
eq callEnd[2].first_column, startIndex + 2
529529
eq callEnd[2].last_column, startIndex + 2
530530

531+
test "Verify normal heredocs have the right position", ->
532+
source = '''
533+
"""
534+
a"""
535+
'''
536+
[stringToken] = CoffeeScript.tokens source
537+
eq stringToken[2].first_line, 0
538+
eq stringToken[2].first_column, 0
539+
eq stringToken[2].last_line, 1
540+
eq stringToken[2].last_column, 3
541+
542+
test "Verify heredocs ending with a newline have the right position", ->
543+
source = '''
544+
"""
545+
a
546+
"""
547+
'''
548+
[stringToken] = CoffeeScript.tokens source
549+
eq stringToken[2].first_line, 0
550+
eq stringToken[2].first_column, 0
551+
eq stringToken[2].last_line, 2
552+
eq stringToken[2].last_column, 2
553+
554+
test "Verify indented heredocs have the right position", ->
555+
source = '''
556+
->
557+
"""
558+
a
559+
"""
560+
'''
561+
[arrow, indent, stringToken] = CoffeeScript.tokens source
562+
eq stringToken[2].first_line, 1
563+
eq stringToken[2].first_column, 2
564+
eq stringToken[2].last_line, 3
565+
eq stringToken[2].last_column, 4
566+
531567
test "Verify all tokens get a location", ->
532568
doesNotThrow ->
533569
tokens = CoffeeScript.tokens testScript

0 commit comments

Comments
 (0)