Merge pull request #4444 from alangpierce/upstream-fix-heregex-end-location

Place ending heregex tokens one index earlier
This commit is contained in:
Simon Lydell 2017-02-17 18:21:08 +01:00 committed by GitHub
commit 4f714cc7f9
3 changed files with 31 additions and 8 deletions

View File

@ -409,11 +409,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;
};

View File

@ -343,10 +343,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

View File

@ -585,6 +585,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