-
-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make template token objects adhere token object structure #343
Make template token objects adhere token object structure #343
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance of a regression test? :-D
lib/token-translator.js
Outdated
@@ -58,6 +58,8 @@ function convertTemplatePart(tokens, code) { | |||
|
|||
if (firstToken.range) { | |||
token.range = [firstToken.range[0], lastTemplateToken.range[1]]; | |||
token.start = firstToken.range[0]; | |||
token.end = lastTemplateToken.range[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nbd but maybe token.range = [token.start, token.end]
after these lines would reduce some of the duplication?
@ljharb I'd be happy to add a test, but I'd need to be pointed in the correct direction. |
I think perhaps the tokenize fixtures might need |
@ljharb Looks like the tester explicitly strips out |
While fixing an issue in `eslint-plugin-react` (jsx-eslint/eslint-plugin-react#1061), I noticed that template tokens differ from other tokens. A typical token looks like this: ``` Token { type: 'String', value: '"bar"', start: 44, end: 49, loc: SourceLocation { start: Position { line: 4, column: 11 }, end: Position { line: 4, column: 16 } }, range: [ 44, 49 ] } ``` A template token looks like this: ``` { type: 'Template', value: '`bar`', loc: { start: Position { line: 4, column: 11 }, end: Position { line: 4, column: 16 } }, range: [ 44, 49 ] } ``` I've not be able to figure out why templates are plain JavaScript objects and not of the class type `Token` (aside from the fact that the template tokens are constructed differently in the token translator. This fix copies the `range` values into `start` and `end` properties on the template tokens to make them adhere to the same structure as other token objects. Fixes eslint#319
While fixing an issue in `eslint-plugin-react` (jsx-eslint/eslint-plugin-react#1061), I noticed that template tokens differ from other tokens. A typical token looks like this: ``` Token { type: 'String', value: '"bar"', start: 44, end: 49, loc: SourceLocation { start: Position { line: 4, column: 11 }, end: Position { line: 4, column: 16 } }, range: [ 44, 49 ] } ``` A template token looks like this: ``` { type: 'Template', value: '`bar`', loc: { start: Position { line: 4, column: 11 }, end: Position { line: 4, column: 16 } }, range: [ 44, 49 ] } ``` I've not be able to figure out why templates are plain JavaScript objects and not of the class type `Token` (aside from the fact that the template tokens are constructed differently in the token translator. This fix copies the `range` values into `start` and `end` properties on the template tokens to make them adhere to the same structure as other token objects. Fixes eslint#319
cbe68e7
to
289a848
Compare
If we're not testing these values anywhere else in our tests it seems to me like we shouldn't hold this change up for that. If we decide to merge this as is, I can make a follow up issue to see if we can make this testable somehow. As @nzakas mentioned in the original response, this seems like a pretty clear bug and an easy, low risk fix. @eslint/eslint-team Does anyone know why the tester does this? |
@kaicataldo totally; my comment wasn't meant as a blocker, more killing time/seeing if the PR can be improved while waiting for a response from eslint core ;-) it'd be great to merge it straightaway! |
Thanks for contributing! |
While fixing an issue in `eslint-plugin-react` (jsx-eslint/eslint-plugin-react#1061), I noticed that template tokens differ from other tokens. A typical token looks like this: ``` Token { type: 'String', value: '"bar"', start: 44, end: 49, loc: SourceLocation { start: Position { line: 4, column: 11 }, end: Position { line: 4, column: 16 } }, range: [ 44, 49 ] } ``` A template token looks like this: ``` { type: 'Template', value: '`bar`', loc: { start: Position { line: 4, column: 11 }, end: Position { line: 4, column: 16 } }, range: [ 44, 49 ] } ``` I've not be able to figure out why templates are plain JavaScript objects and not of the class type `Token` (aside from the fact that the template tokens are constructed differently in the token translator. This fix copies the `range` values into `start` and `end` properties on the template tokens to make them adhere to the same structure as other token objects. Fixes #319
While fixing an issue in
eslint-plugin-react
(jsx-eslint/eslint-plugin-react#1061), I noticed that template tokens differ from other tokens. A typical token looks like this:A template token looks like this:
I've not be able to figure out why templates are plain JavaScript objects and not of the class type
Token
(aside from the fact that the template tokens are constructed differently in the token translator.This fix copies the
range
values intostart
andend
properties on the template tokens to make them adhere to the same structure as other token objects.Fixes #319