Compound assign location data (#5248)

* Assign declaration

* For

* Class

* import/export

* params

* Catch

* compound assign location data
This commit is contained in:
Julian Rosse
2019-11-30 19:51:48 -07:00
committed by Geoffrey Booth
parent 74d6635f95
commit f56515b100
3 changed files with 30 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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'

View File

@@ -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