Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Fix: Use correct starting range and loc for JSXText tokens (fixes #227) #271

Merged
merged 1 commit into from
May 15, 2017

Conversation

soda0289
Copy link
Member

We used to use the method getStart() to calculate the starting range for JSXText tokens. This would skip over whitespace and cause the value of these tokens to be empty. This would also result in the range and starting line number and column to be incorrect. This commit uses the method getFullStart(), on JSXText tokens, which does not skip over whitespace and allows for the correct range, value and loc to be set.

This also fixes issues with JSX indentation in the new indent rule and in the eslint-plugin-react.

@eslintbot
Copy link

LGTM

@soda0289 soda0289 force-pushed the fix-jsxtext-token branch from 8ead954 to 42f1f3e Compare May 14, 2017 21:19
@eslintbot
Copy link

LGTM

@@ -588,15 +588,16 @@ function getTokenType(token) {
* @returns {ESTreeToken} the converted ESTreeToken
*/
function convertToken(token, ast) {
const start = token.getStart(),
const start = (token.kind === SyntaxKind.JsxText) ? token.getFullStart() : token.getStart(),
end = token.getEnd(),
value = ast.text.slice(start, token.end),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other references to token.end were updated to the variable end, but not this one. Just checking that is intended/not significant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading through the code of typescript and noticed this method. I thought it looked a little cleaner since we use methods to access the starting point.

These are the methods to access token positions:

  • getFullStart() is the same as .pos
  • getEnd() is the same as .end
  • getStart() is the same as .pos but skipping over trivia and white space

If you want I can change the logic to use the properties to be more consistent with the rest of the code.

@soda0289 soda0289 force-pushed the fix-jsxtext-token branch from 42f1f3e to f190876 Compare May 15, 2017 14:17
@eslintbot
Copy link

LGTM

@JamesHenry JamesHenry merged commit 6b56bfe into master May 15, 2017
@JamesHenry JamesHenry deleted the fix-jsxtext-token branch May 15, 2017 14:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants