Skip to content

Commit

Permalink
Merge branch 'master' into 2
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Oct 24, 2016
2 parents f14e8b2 + 887052d commit c04c385
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,11 @@ exports.Lexer = class Lexer

[firstToken, ..., lastToken] = tokens
firstToken[2].first_column -= delimiter.length
lastToken[2].last_column += delimiter.length
if lastToken[1].substr(-1) is '\n'
lastToken[2].last_line += 1
lastToken[2].last_column = delimiter.length - 1
else
lastToken[2].last_column += delimiter.length
lastToken[2].last_column -= 1 if lastToken[1].length is 0

{tokens, index: offsetInChunk + delimiter.length}
Expand Down
2 changes: 1 addition & 1 deletion src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class exports.Rewriter
# b: c
#
# Don't accept implicit calls of this type, when on the same line
# as the control strucutures below as that may misinterpret constructs like:
# as the control structures below as that may misinterpret constructs like:
#
# if f
# a: 1
Expand Down
36 changes: 36 additions & 0 deletions test/location.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,42 @@ test "Verify real CALL_END tokens have the right position", ->
eq callEnd[2].first_column, startIndex + 2
eq callEnd[2].last_column, startIndex + 2

test "Verify normal heredocs have the right position", ->
source = '''
"""
a"""
'''
[stringToken] = CoffeeScript.tokens source
eq stringToken[2].first_line, 0
eq stringToken[2].first_column, 0
eq stringToken[2].last_line, 1
eq stringToken[2].last_column, 3

test "Verify heredocs ending with a newline have the right position", ->
source = '''
"""
a
"""
'''
[stringToken] = CoffeeScript.tokens source
eq stringToken[2].first_line, 0
eq stringToken[2].first_column, 0
eq stringToken[2].last_line, 2
eq stringToken[2].last_column, 2

test "Verify indented heredocs have the right position", ->
source = '''
->
"""
a
"""
'''
[arrow, indent, stringToken] = CoffeeScript.tokens source
eq stringToken[2].first_line, 1
eq stringToken[2].first_column, 2
eq stringToken[2].last_line, 3
eq stringToken[2].last_column, 4

test "Verify all tokens get a location", ->
doesNotThrow ->
tokens = CoffeeScript.tokens testScript
Expand Down

0 comments on commit c04c385

Please sign in to comment.