Skip to content

Commit 289a848

Browse files
committed
Make template token objects adhere token object structure
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
1 parent fd4c2ac commit 289a848

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/token-translator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ function convertTemplatePart(tokens, code) {
5757
}
5858

5959
if (firstToken.range) {
60-
token.range = [firstToken.range[0], lastTemplateToken.range[1]];
6160
token.start = firstToken.range[0];
6261
token.end = lastTemplateToken.range[1];
62+
token.range = [token.start, token.end];
6363
}
6464

6565
return token;

0 commit comments

Comments
 (0)