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

Commit 6b56bfe

Browse files
soda0289JamesHenry
authored andcommitted
Fix: Use correct starting range and loc for JSXText tokens (fixes #227) (#271)
1 parent f5fcc87 commit 6b56bfe

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

lib/node-utils.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,16 @@ function getTokenType(token) {
588588
* @returns {ESTreeToken} the converted ESTreeToken
589589
*/
590590
function convertToken(token, ast) {
591-
const start = token.getStart(),
592-
value = ast.text.slice(start, token.end),
591+
const start = (token.kind === SyntaxKind.JsxText) ? token.getFullStart() : token.getStart(),
592+
end = token.getEnd(),
593+
value = ast.text.slice(start, end),
593594
newToken = {
594595
type: getTokenType(token),
595596
value,
596597
start,
597-
end: token.end,
598-
range: [start, token.end],
599-
loc: getLoc(token, ast)
598+
end,
599+
range: [start, end],
600+
loc: getLocFor(start, end, ast)
600601
};
601602

602603
if (newToken.type === "RegularExpression") {

tests/fixtures/comments/jsx-block-comment.result.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,15 @@ module.exports = {
512512
},
513513
{
514514
"type": "JSXText",
515-
"value": "",
515+
"value": "\n ",
516516
"range": [
517-
60,
517+
47,
518518
60
519519
],
520520
"loc": {
521521
"start": {
522-
"line": 4,
523-
"column": 12
522+
"line": 3,
523+
"column": 13
524524
},
525525
"end": {
526526
"line": 4,
@@ -566,15 +566,15 @@ module.exports = {
566566
},
567567
{
568568
"type": "JSXText",
569-
"value": "",
569+
"value": "\n ",
570570
"range": [
571-
82,
571+
73,
572572
82
573573
],
574574
"loc": {
575575
"start": {
576-
"line": 5,
577-
"column": 8
576+
"line": 4,
577+
"column": 25
578578
},
579579
"end": {
580580
"line": 5,

tests/fixtures/comments/jsx-tag-comments.result.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,15 @@ module.exports = {
459459
},
460460
{
461461
"type": "JSXText",
462-
"value": "",
462+
"value": "\n ",
463463
"range": [
464-
112,
464+
103,
465465
112
466466
],
467467
"loc": {
468468
"start": {
469-
"line": 7,
470-
"column": 8
469+
"line": 6,
470+
"column": 9
471471
},
472472
"end": {
473473
"line": 7,

tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.result.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,15 @@ module.exports = {
276276
},
277277
{
278278
"type": "JSXText",
279-
"value": "",
279+
"value": "\n ",
280280
"range": [
281-
10,
281+
5,
282282
10
283283
],
284284
"loc": {
285285
"start": {
286-
"line": 2,
287-
"column": 4
286+
"line": 1,
287+
"column": 5
288288
},
289289
"end": {
290290
"line": 2,
@@ -366,15 +366,15 @@ module.exports = {
366366
},
367367
{
368368
"type": "JSXText",
369-
"value": "",
369+
"value": "\n",
370370
"range": [
371-
18,
371+
17,
372372
18
373373
],
374374
"loc": {
375375
"start": {
376-
"line": 3,
377-
"column": 0
376+
"line": 2,
377+
"column": 11
378378
},
379379
"end": {
380380
"line": 3,

tests/lib/ecma-features.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ const FIXTURES_DIR = "./tests/fixtures/ecma-features";
2929
const filesWithOutsandingTSIssues = [
3030
"jsx/embedded-tags", // https://github.com/Microsoft/TypeScript/issues/7410
3131
"jsx/namespaced-attribute-and-value-inserted", // https://github.com/Microsoft/TypeScript/issues/7411
32-
"jsx/namespaced-name-and-attribute", // https://github.com/Microsoft/TypeScript/issues/7411
33-
"jsx/multiple-blank-spaces"
32+
"jsx/namespaced-name-and-attribute" // https://github.com/Microsoft/TypeScript/issues/7411
3433
];
3534

3635
const testFiles = shelljs.find(FIXTURES_DIR)

0 commit comments

Comments
 (0)