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

Fix: Convert range and line number corretly in JSX literals #277

Merged
merged 1 commit into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/comments/jsx-block-comment.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ module.exports = {
],
"loc": {
"start": {
"line": 4,
"column": 47
"line": 3,
"column": 13
},
"end": {
"line": 4,
Expand Down Expand Up @@ -268,8 +268,8 @@ module.exports = {
],
"loc": {
"start": {
"line": 5,
"column": 73
"line": 4,
"column": 25
},
"end": {
"line": 5,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/comments/jsx-tag-comments.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ module.exports = {
],
"loc": {
"start": {
"line": 7,
"column": 103
"line": 6,
"column": 9
},
"end": {
"line": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports = {
],
"loc": {
"start": {
"line": 2,
"line": 1,
"column": 5
},
"end": {
Expand Down Expand Up @@ -203,8 +203,8 @@ module.exports = {
],
"loc": {
"start": {
"line": 3,
"column": 17
"line": 2,
"column": 11
},
"end": {
"line": 3,
Expand Down