mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Compound assign location data (#5248)
* Assign declaration * For * Class * import/export * params * Catch * compound assign location data
This commit is contained in:
committed by
Geoffrey Booth
parent
74d6635f95
commit
f56515b100
@@ -1078,6 +1078,9 @@
|
||||
if ((ref1 = prev.data) != null ? ref1.original : void 0) {
|
||||
prev.data.original += '=';
|
||||
}
|
||||
prev[2].range = [prev[2].range[0], prev[2].range[1] + 1];
|
||||
prev[2].last_column += 1;
|
||||
prev[2].last_column_exclusive += 1;
|
||||
prev = this.tokens[this.tokens.length - 2];
|
||||
skipToken = true;
|
||||
}
|
||||
|
||||
@@ -740,6 +740,12 @@ exports.Lexer = class Lexer
|
||||
prev[0] = 'COMPOUND_ASSIGN'
|
||||
prev[1] += '='
|
||||
prev.data.original += '=' if prev.data?.original
|
||||
prev[2].range = [
|
||||
prev[2].range[0]
|
||||
prev[2].range[1] + 1
|
||||
]
|
||||
prev[2].last_column += 1
|
||||
prev[2].last_column_exclusive += 1
|
||||
prev = @tokens[@tokens.length - 2]
|
||||
skipToken = true
|
||||
if prev and prev[0] isnt 'PROPERTY'
|
||||
|
||||
@@ -720,3 +720,24 @@ test 'StringWithInterpolations::fromStringLiteral() assigns correct location to
|
||||
last_column: 5
|
||||
last_line_exclusive: 1
|
||||
last_column_exclusive: 0
|
||||
|
||||
test "Verify compound assignment operators have the right position", ->
|
||||
source = '''
|
||||
a or= b
|
||||
'''
|
||||
[a, operatorToken] = CoffeeScript.tokens source
|
||||
eq operatorToken[2].first_line, 0
|
||||
eq operatorToken[2].first_column, 2
|
||||
eq operatorToken[2].last_line, 0
|
||||
eq operatorToken[2].last_column, 4
|
||||
eq operatorToken[2].last_column_exclusive, 5
|
||||
|
||||
source = '''
|
||||
a and= b
|
||||
'''
|
||||
[a, operatorToken] = CoffeeScript.tokens source
|
||||
eq operatorToken[2].first_line, 0
|
||||
eq operatorToken[2].first_column, 2
|
||||
eq operatorToken[2].last_line, 0
|
||||
eq operatorToken[2].last_column, 5
|
||||
eq operatorToken[2].last_column_exclusive, 6
|
||||
|
||||
Reference in New Issue
Block a user