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

Commit b4eb0b5

Browse files
soda0289JamesHenry
authored andcommitted
Fix: Convert range and line number corretly in JSX literals (#277)
1 parent 3f9f41c commit b4eb0b5

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

lib/convert.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,17 +1613,21 @@ module.exports = function convert(config) {
16131613

16141614
}
16151615

1616-
case SyntaxKind.JsxText:
1616+
case SyntaxKind.JsxText: {
16171617
Object.assign(result, {
16181618
type: AST_NODE_TYPES.Literal,
16191619
value: ast.text.slice(node.pos, node.end),
16201620
raw: ast.text.slice(node.pos, node.end)
16211621
});
16221622

1623-
result.loc.start.column = node.pos;
1624-
result.range[0] = node.pos;
1623+
const start = node.getFullStart();
1624+
const end = node.getEnd();
1625+
1626+
result.loc = nodeUtils.getLocFor(start, end, ast);
1627+
result.range = [start, end];
16251628

16261629
break;
1630+
}
16271631

16281632
case SyntaxKind.JsxSpreadAttribute:
16291633
Object.assign(result, {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ module.exports = {
215215
],
216216
"loc": {
217217
"start": {
218-
"line": 4,
219-
"column": 47
218+
"line": 3,
219+
"column": 13
220220
},
221221
"end": {
222222
"line": 4,
@@ -268,8 +268,8 @@ module.exports = {
268268
],
269269
"loc": {
270270
"start": {
271-
"line": 5,
272-
"column": 73
271+
"line": 4,
272+
"column": 25
273273
},
274274
"end": {
275275
"line": 5,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ module.exports = {
215215
],
216216
"loc": {
217217
"start": {
218-
"line": 7,
219-
"column": 103
218+
"line": 6,
219+
"column": 9
220220
},
221221
"end": {
222222
"line": 7,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module.exports = {
128128
],
129129
"loc": {
130130
"start": {
131-
"line": 2,
131+
"line": 1,
132132
"column": 5
133133
},
134134
"end": {
@@ -203,8 +203,8 @@ module.exports = {
203203
],
204204
"loc": {
205205
"start": {
206-
"line": 3,
207-
"column": 17
206+
"line": 2,
207+
"column": 11
208208
},
209209
"end": {
210210
"line": 3,

0 commit comments

Comments
 (0)