From f1908762c41e744e44626996e7bbc10ee9dac5b6 Mon Sep 17 00:00:00 2001 From: Reyad Attiyat Date: Sun, 14 May 2017 00:44:49 -0500 Subject: [PATCH] Fix: Use correct starting range and loc for JSXText tokens (fixes #227) --- lib/node-utils.js | 11 ++++++----- .../comments/jsx-block-comment.result.js | 16 ++++++++-------- .../fixtures/comments/jsx-tag-comments.result.js | 8 ++++---- .../jsx/self-closing-tag-inside-tag.result.js | 16 ++++++++-------- tests/lib/ecma-features.js | 3 +-- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/node-utils.js b/lib/node-utils.js index 3e7f0de..aafa359 100644 --- a/lib/node-utils.js +++ b/lib/node-utils.js @@ -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") { diff --git a/tests/fixtures/comments/jsx-block-comment.result.js b/tests/fixtures/comments/jsx-block-comment.result.js index 4e6b038..cee2a73 100644 --- a/tests/fixtures/comments/jsx-block-comment.result.js +++ b/tests/fixtures/comments/jsx-block-comment.result.js @@ -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, @@ -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, diff --git a/tests/fixtures/comments/jsx-tag-comments.result.js b/tests/fixtures/comments/jsx-tag-comments.result.js index cddb435..67c6527 100644 --- a/tests/fixtures/comments/jsx-tag-comments.result.js +++ b/tests/fixtures/comments/jsx-tag-comments.result.js @@ -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, 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 450dcb7..32ad8e4 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 @@ -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, @@ -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, diff --git a/tests/lib/ecma-features.js b/tests/lib/ecma-features.js index f7104aa..8813690 100644 --- a/tests/lib/ecma-features.js +++ b/tests/lib/ecma-features.js @@ -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)