AST: object colon location data (#5253)

* astNode()

* no override ast()

* add suggested comments

* astInitialize()

* astAddReturns()

* separate step

* recognize quoted constructor

* add params to scope

* object colon location data
This commit is contained in:
Julian Rosse
2019-12-08 15:41:15 -07:00
committed by Geoffrey Booth
parent 9cfcf8623c
commit 44be72a4d9
4 changed files with 16 additions and 4 deletions

View File

@@ -277,8 +277,7 @@
if (colon) {
colonOffset = input.lastIndexOf(inJSXTag ? '=' : ':');
colonToken = this.token(':', ':', {
offset: colonOffset,
length: colon.length
offset: colonOffset
});
if (inJSXTag) { // used by rewriter
colonToken.jsxColon = true;

View File

@@ -246,7 +246,7 @@ exports.Lexer = class Lexer
[poppedToken[2].first_line, poppedToken[2].first_column, poppedToken[2].range[0]]
if colon
colonOffset = input.lastIndexOf if inJSXTag then '=' else ':'
colonToken = @token ':', ':', offset: colonOffset, length: colon.length
colonToken = @token ':', ':', offset: colonOffset
colonToken.jsxColon = yes if inJSXTag # used by rewriter
if inJSXTag and tag is 'IDENTIFIER' and prev[0] isnt ':'
@token ',', ',', length: 0, origin: tagToken

View File

@@ -1894,7 +1894,7 @@ exports.JSXElement = class JSXElement extends Base
openingBrace: '{'
closingBrace: '}'
}
new JSXExpressionContainer emptyExpression, locationData: element.locationData
else
unwrapped = expression.unwrapAll()

View File

@@ -803,3 +803,16 @@ test "Verify carriage returns are accounted for in location data", ->
eq minusToken[2].last_column_exclusive, 4
eq minusToken[2].range[0], 7
eq minusToken[2].range[1], 8
test "Verify object colon location data", ->
source = '''
a : b
'''
[implicitBraceToken, aToken, colonToken] = CoffeeScript.tokens source
eq colonToken[2].first_line, 0
eq colonToken[2].first_column, 2
eq colonToken[2].last_line, 0
eq colonToken[2].last_column, 2
eq colonToken[2].last_column_exclusive, 3
eq colonToken[2].range[0], 2
eq colonToken[2].range[1], 3