diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index 2ab1e5c4..9e3224f8 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -403,11 +403,11 @@ double: true }, this.formatHeregex); if (flags) { - this.token(',', ',', index, 0); - this.token('STRING', '"' + flags + '"', index, flags.length); + this.token(',', ',', index - 1, 0); + this.token('STRING', '"' + flags + '"', index - 1, flags.length); } - this.token(')', ')', end, 0); - this.token('REGEX_END', ')', end, 0); + this.token(')', ')', end - 1, 0); + this.token('REGEX_END', ')', end - 1, 0); } return end; }; diff --git a/src/lexer.coffee b/src/lexer.coffee index 529caf11..dc34f53d 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -332,10 +332,10 @@ exports.Lexer = class Lexer @token 'CALL_START', '(', 0, 0 @mergeInterpolationTokens tokens, {delimiter: '"', double: yes}, @formatHeregex if flags - @token ',', ',', index, 0 - @token 'STRING', '"' + flags + '"', index, flags.length - @token ')', ')', end, 0 - @token 'REGEX_END', ')', end, 0 + @token ',', ',', index - 1, 0 + @token 'STRING', '"' + flags + '"', index - 1, flags.length + @token ')', ')', end - 1, 0 + @token 'REGEX_END', ')', end - 1, 0 end diff --git a/test/location.coffee b/test/location.coffee index 2ffe951e..19eb3c62 100644 --- a/test/location.coffee +++ b/test/location.coffee @@ -564,6 +564,29 @@ test "Verify indented heredocs have the right position", -> eq stringToken[2].last_line, 3 eq stringToken[2].last_column, 4 +test "Verify heregexes with interpolations have the right ending position", -> + source = ''' + [a ///#{b}///g] + ''' + [..., stringEnd, comma, flagsString, regexCallEnd, regexEnd, fnCallEnd, + arrayEnd, terminator] = CoffeeScript.tokens source + + eq comma[0], ',' + eq arrayEnd[0], ']' + + assertColumn = (token, column) -> + eq token[2].first_line, 0 + eq token[2].first_column, column + eq token[2].last_line, 0 + eq token[2].last_column, column + + arrayEndColumn = arrayEnd[2].first_column + for token in [comma, flagsString] + assertColumn token, arrayEndColumn - 2 + for token in [regexCallEnd, regexEnd, fnCallEnd] + assertColumn token, arrayEndColumn - 1 + assertColumn arrayEnd, arrayEndColumn + test "Verify all tokens get a location", -> doesNotThrow -> tokens = CoffeeScript.tokens testScript