From e2496ae02e42d4accca6ca2c2f5a77ff513d0328 Mon Sep 17 00:00:00 2001 From: Reyad Attiyat Date: Sat, 20 May 2017 12:08:02 -0500 Subject: [PATCH] Fix: Convert range and line number corretly in JSX literals --- lib/convert.js | 10 +++++++--- tests/fixtures/comments/jsx-block-comment.result.js | 8 ++++---- tests/fixtures/comments/jsx-tag-comments.result.js | 4 ++-- .../jsx/self-closing-tag-inside-tag.result.js | 6 +++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/convert.js b/lib/convert.js index 083c278..cca30f0 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1613,17 +1613,21 @@ module.exports = function convert(config) { } - case SyntaxKind.JsxText: + case SyntaxKind.JsxText: { Object.assign(result, { type: AST_NODE_TYPES.Literal, value: ast.text.slice(node.pos, node.end), raw: ast.text.slice(node.pos, node.end) }); - result.loc.start.column = node.pos; - result.range[0] = node.pos; + const start = node.getFullStart(); + const end = node.getEnd(); + + result.loc = nodeUtils.getLocFor(start, end, ast); + result.range = [start, end]; break; + } case SyntaxKind.JsxSpreadAttribute: Object.assign(result, { diff --git a/tests/fixtures/comments/jsx-block-comment.result.js b/tests/fixtures/comments/jsx-block-comment.result.js index cee2a73..0334ec3 100644 --- a/tests/fixtures/comments/jsx-block-comment.result.js +++ b/tests/fixtures/comments/jsx-block-comment.result.js @@ -215,8 +215,8 @@ module.exports = { ], "loc": { "start": { - "line": 4, - "column": 47 + "line": 3, + "column": 13 }, "end": { "line": 4, @@ -268,8 +268,8 @@ module.exports = { ], "loc": { "start": { - "line": 5, - "column": 73 + "line": 4, + "column": 25 }, "end": { "line": 5, diff --git a/tests/fixtures/comments/jsx-tag-comments.result.js b/tests/fixtures/comments/jsx-tag-comments.result.js index 67c6527..1f28bc3 100644 --- a/tests/fixtures/comments/jsx-tag-comments.result.js +++ b/tests/fixtures/comments/jsx-tag-comments.result.js @@ -215,8 +215,8 @@ module.exports = { ], "loc": { "start": { - "line": 7, - "column": 103 + "line": 6, + "column": 9 }, "end": { "line": 7, diff --git a/tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.result.js b/tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.result.js index 32ad8e4..9cb593f 100644 --- a/tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.result.js +++ b/tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.result.js @@ -128,7 +128,7 @@ module.exports = { ], "loc": { "start": { - "line": 2, + "line": 1, "column": 5 }, "end": { @@ -203,8 +203,8 @@ module.exports = { ], "loc": { "start": { - "line": 3, - "column": 17 + "line": 2, + "column": 11 }, "end": { "line": 3,