-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Template token objects differ from other token objects #319
Comments
That seems like a reasonable fix for what appears to be an obvious bug. Probably just an oversight as we went back and forth on whether or not start and end should end up on the nodes. I'd still recommend using range in rules, as that is supported by all parsers whereas start and end are just Acorn leftovers in Espree. |
@iancmyers Sorry for losing track of this. Is this still something you'd be willing to make a PR for? |
Yep! Incoming soon. |
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
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 #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 #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).The more pressing issue, in my mind, is the omission of
start
andend
properties at the top level of the template token object. The issue cited above was caused by passingtoken.start
into eslint'sgetNodeByRangeIndex
method. I fixed the issue by usingrange[0]
(jsx-eslint/eslint-plugin-react#1077), however I fear that other downstream projects are relying on tokens have a consistent object construction and always havingstart
andend
.It seems like the quick-fix would be to copy the
range
values intostart
andend
properties on the template tokens. If that would be sufficient for now, I'd be happy to PR that.The text was updated successfully, but these errors were encountered: