Commit c6f4a5e
committed
Fix error caused by templates in ConditionalExpressions (jsx-indent)
Template strings are constructed differently from other tokens in
espree. Other tokens are created by the Token class and are thus
Token class objects. They look 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 ] }
```
Template tokens, however, are constructed differently and end up as
plain JavaScript objects, which look like this:
```
{ type: 'Template',
value: '`bar`',
loc:
{ start: Position { line: 4, column: 11 },
end: Position { line: 4, column: 16 } },
range: [ 44, 49 ] }
```
See: [espree's token-translator.js](https://github.com/eslint/espree/blob/58f75be6b89d8904b6366ed368045cb02c4a4e33/lib/token-translator.js#L43)
As a result of this different construction, the `start` and `end`
properties are not present on the template token object. To correct this
I've changed to using the `range` property, which I infer to be more
proper given the method it is being passed into is called
`getNodeByRangeIndex`. I also think we can safely rely on `range` being
present on all token types.
Fixes #10611 parent a4b6a85 commit c6f4a5e
2 files changed
+43
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
| 278 | + | |
| 279 | + | |
279 | 280 | | |
280 | 281 | | |
281 | 282 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
413 | 454 | | |
414 | 455 | | |
415 | 456 | | |
| |||
0 commit comments