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

Fix: Use correct starting range and loc for JSXText tokens (fixes #227) #271

Merged
merged 1 commit into from
May 15, 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
11 changes: 6 additions & 5 deletions lib/node-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,15 +588,16 @@ function getTokenType(token) {
* @returns {ESTreeToken} the converted ESTreeToken
*/
function convertToken(token, ast) {
const start = token.getStart(),
value = ast.text.slice(start, token.end),
const start = (token.kind === SyntaxKind.JsxText) ? token.getFullStart() : token.getStart(),
end = token.getEnd(),
value = ast.text.slice(start, end),
newToken = {
type: getTokenType(token),
value,
start,
end: token.end,
range: [start, token.end],
loc: getLoc(token, ast)
end,
range: [start, end],
loc: getLocFor(start, end, ast)
};

if (newToken.type === "RegularExpression") {
Expand Down
16 changes: 8 additions & 8 deletions tests/fixtures/comments/jsx-block-comment.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,15 @@ module.exports = {
},
{
"type": "JSXText",
"value": "",
"value": "\n ",
"range": [
60,
47,
60
],
"loc": {
"start": {
"line": 4,
"column": 12
"line": 3,
"column": 13
},
"end": {
"line": 4,
Expand Down Expand Up @@ -566,15 +566,15 @@ module.exports = {
},
{
"type": "JSXText",
"value": "",
"value": "\n ",
"range": [
82,
73,
82
],
"loc": {
"start": {
"line": 5,
"column": 8
"line": 4,
"column": 25
},
"end": {
"line": 5,
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/comments/jsx-tag-comments.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,15 @@ module.exports = {
},
{
"type": "JSXText",
"value": "",
"value": "\n ",
"range": [
112,
103,
112
],
"loc": {
"start": {
"line": 7,
"column": 8
"line": 6,
"column": 9
},
"end": {
"line": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ module.exports = {
},
{
"type": "JSXText",
"value": "",
"value": "\n ",
"range": [
10,
5,
10
],
"loc": {
"start": {
"line": 2,
"column": 4
"line": 1,
"column": 5
},
"end": {
"line": 2,
Expand Down Expand Up @@ -366,15 +366,15 @@ module.exports = {
},
{
"type": "JSXText",
"value": "",
"value": "\n",
"range": [
18,
17,
18
],
"loc": {
"start": {
"line": 3,
"column": 0
"line": 2,
"column": 11
},
"end": {
"line": 3,
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/ecma-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const FIXTURES_DIR = "./tests/fixtures/ecma-features";
const filesWithOutsandingTSIssues = [
"jsx/embedded-tags", // https://github.com/Microsoft/TypeScript/issues/7410
"jsx/namespaced-attribute-and-value-inserted", // https://github.com/Microsoft/TypeScript/issues/7411
"jsx/namespaced-name-and-attribute", // https://github.com/Microsoft/TypeScript/issues/7411
"jsx/multiple-blank-spaces"
"jsx/namespaced-name-and-attribute" // https://github.com/Microsoft/TypeScript/issues/7411
];

const testFiles = shelljs.find(FIXTURES_DIR)
Expand Down