From b9fc560709c2228c93e50ed54000698d6fcdf7a4 Mon Sep 17 00:00:00 2001 From: James Henry Date: Tue, 15 Aug 2017 15:55:47 +0100 Subject: [PATCH] Fix: Remove start and end values from JSX tokens (fixes #341) --- lib/node-utils.js | 2 - package.json | 2 +- tests/ast-alignment/parse.js | 2 + tests/ast-alignment/spec.js | 3 +- tests/fixtures/jsx/attributes.src.js | 2 +- tests/lib/__snapshots__/jsx.js.snap | 225 +++++++++------------------ 6 files changed, 83 insertions(+), 153 deletions(-) diff --git a/lib/node-utils.js b/lib/node-utils.js index eca668d..d10207e 100644 --- a/lib/node-utils.js +++ b/lib/node-utils.js @@ -627,8 +627,6 @@ function convertToken(token, ast) { newToken = { type: getTokenType(token), value, - start, - end, range: [start, end], loc: getLocFor(start, end, ast) }; diff --git a/package.json b/package.json index 227e748..91e31ee 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "license": "BSD-2-Clause", "devDependencies": { "babel-code-frame": "^6.22.0", - "babylon": "^7.0.0-beta.16", + "babylon": "^7.0.0-beta.19", "eslint": "3.19.0", "eslint-config-eslint": "4.0.0", "eslint-plugin-node": "4.2.2", diff --git a/tests/ast-alignment/parse.js b/tests/ast-alignment/parse.js index 2aca312..180d6f1 100644 --- a/tests/ast-alignment/parse.js +++ b/tests/ast-alignment/parse.js @@ -46,6 +46,8 @@ function parseWithTypeScriptESLintParser(text) { // eslint-disable-line range: true, tokens: false, comment: false, + useJSXTextNode: true, + errorOnUnknownASTType: true, ecmaFeatures: { jsx: true } diff --git a/tests/ast-alignment/spec.js b/tests/ast-alignment/spec.js index 44bd4a0..73bf551 100644 --- a/tests/ast-alignment/spec.js +++ b/tests/ast-alignment/spec.js @@ -11,7 +11,8 @@ const fixturePatternsToTest = [ "basics/instanceof.src.js", "basics/update-expression.src.js", "basics/new-without-parens.src.js", - "ecma-features/arrowFunctions/**/as*.src.js" + "ecma-features/arrowFunctions/**/as*.src.js", + "jsx/attributes.src.js" ]; const fixturesToTest = []; diff --git a/tests/fixtures/jsx/attributes.src.js b/tests/fixtures/jsx/attributes.src.js index c70e86b..5de9359 100644 --- a/tests/fixtures/jsx/attributes.src.js +++ b/tests/fixtures/jsx/attributes.src.js @@ -1 +1 @@ -test +test \ No newline at end of file diff --git a/tests/lib/__snapshots__/jsx.js.snap b/tests/lib/__snapshots__/jsx.js.snap index c18fea7..b2ed1b9 100644 --- a/tests/lib/__snapshots__/jsx.js.snap +++ b/tests/lib/__snapshots__/jsx.js.snap @@ -9,17 +9,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 46, + "column": 39, "line": 1, }, "start": Object { - "column": 42, + "column": 35, "line": 1, }, }, "range": Array [ - 42, - 46, + 35, + 39, ], "raw": "test", "type": "Literal", @@ -29,41 +29,41 @@ Object { "closingElement": Object { "loc": Object { "end": Object { - "column": 52, + "column": 45, "line": 1, }, "start": Object { - "column": 46, + "column": 39, "line": 1, }, }, "name": Object { "loc": Object { "end": Object { - "column": 51, + "column": 44, "line": 1, }, "start": Object { - "column": 48, + "column": 41, "line": 1, }, }, "name": "foo", "range": Array [ - 48, - 51, + 41, + 44, ], "type": "JSXIdentifier", }, "range": Array [ - 46, - 52, + 39, + 45, ], "type": "JSXClosingElement", }, "loc": Object { "end": Object { - "column": 52, + "column": 45, "line": 1, }, "start": Object { @@ -198,79 +198,44 @@ Object { }, }, Object { - "loc": Object { - "end": Object { - "column": 41, - "line": 1, - }, - "start": Object { - "column": 25, - "line": 1, - }, - }, - "name": Object { + "argument": Object { "loc": Object { "end": Object { - "column": 31, + "column": 33, "line": 1, }, "start": Object { - "column": 25, + "column": 29, "line": 1, }, }, - "name": "spread", + "name": "rest", "range": Array [ - 25, - 31, + 29, + 33, ], - "type": "JSXIdentifier", + "type": "Identifier", }, - "range": Array [ - 25, - 41, - ], - "type": "JSXAttribute", - "value": Object { - "expression": Object { - "loc": Object { - "end": Object { - "column": 40, - "line": 1, - }, - "start": Object { - "column": 36, - "line": 1, - }, - }, - "name": "rest", - "range": Array [ - 36, - 40, - ], - "type": "Identifier", + "loc": Object { + "end": Object { + "column": 34, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 41, - "line": 1, - }, - "start": Object { - "column": 32, - "line": 1, - }, + "start": Object { + "column": 25, + "line": 1, }, - "range": Array [ - 32, - 41, - ], - "type": "JSXExpressionContainer", }, + "range": Array [ + 25, + 34, + ], + "type": "JSXSpreadAttribute", }, ], "loc": Object { "end": Object { - "column": 42, + "column": 35, "line": 1, }, "start": Object { @@ -298,20 +263,20 @@ Object { }, "range": Array [ 0, - 42, + 35, ], "selfClosing": false, "type": "JSXOpeningElement", }, "range": Array [ 0, - 52, + 45, ], "type": "JSXElement", }, "loc": Object { "end": Object { - "column": 52, + "column": 45, "line": 1, }, "start": Object { @@ -321,14 +286,14 @@ Object { }, "range": Array [ 0, - 52, + 45, ], "type": "ExpressionStatement", }, ], "loc": Object { "end": Object { - "column": 52, + "column": 45, "line": 1, }, "start": Object { @@ -338,7 +303,7 @@ Object { }, "range": Array [ 0, - 52, + 45, ], "sourceType": "script", "tokens": Array [ @@ -525,7 +490,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 31, + "column": 26, "line": 1, }, "start": Object { @@ -535,43 +500,7 @@ Object { }, "range": Array [ 25, - 31, - ], - "type": "JSXIdentifier", - "value": "spread", - }, - Object { - "loc": Object { - "end": Object { - "column": 32, - "line": 1, - }, - "start": Object { - "column": 31, - "line": 1, - }, - }, - "range": Array [ - 31, - 32, - ], - "type": "Punctuator", - "value": "=", - }, - Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 1, - }, - "start": Object { - "column": 32, - "line": 1, - }, - }, - "range": Array [ - 32, - 33, + 26, ], "type": "Punctuator", "value": "{", @@ -579,17 +508,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 36, + "column": 29, "line": 1, }, "start": Object { - "column": 33, + "column": 26, "line": 1, }, }, "range": Array [ - 33, - 36, + 26, + 29, ], "type": "Punctuator", "value": "...", @@ -597,17 +526,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 40, + "column": 33, "line": 1, }, "start": Object { - "column": 36, + "column": 29, "line": 1, }, }, "range": Array [ - 36, - 40, + 29, + 33, ], "type": "Identifier", "value": "rest", @@ -615,17 +544,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 41, + "column": 34, "line": 1, }, "start": Object { - "column": 40, + "column": 33, "line": 1, }, }, "range": Array [ - 40, - 41, + 33, + 34, ], "type": "Punctuator", "value": "}", @@ -633,17 +562,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 42, + "column": 35, "line": 1, }, "start": Object { - "column": 41, + "column": 34, "line": 1, }, }, "range": Array [ - 41, - 42, + 34, + 35, ], "type": "Punctuator", "value": ">", @@ -651,17 +580,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 46, + "column": 39, "line": 1, }, "start": Object { - "column": 42, + "column": 35, "line": 1, }, }, "range": Array [ - 42, - 46, + 35, + 39, ], "type": "JSXText", "value": "test", @@ -669,17 +598,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 47, + "column": 40, "line": 1, }, "start": Object { - "column": 46, + "column": 39, "line": 1, }, }, "range": Array [ - 46, - 47, + 39, + 40, ], "type": "Punctuator", "value": "<", @@ -687,17 +616,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 48, + "column": 41, "line": 1, }, "start": Object { - "column": 47, + "column": 40, "line": 1, }, }, "range": Array [ - 47, - 48, + 40, + 41, ], "type": "Punctuator", "value": "/", @@ -705,17 +634,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 51, + "column": 44, "line": 1, }, "start": Object { - "column": 48, + "column": 41, "line": 1, }, }, "range": Array [ - 48, - 51, + 41, + 44, ], "type": "JSXIdentifier", "value": "foo", @@ -723,17 +652,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 52, + "column": 45, "line": 1, }, "start": Object { - "column": 51, + "column": 44, "line": 1, }, }, "range": Array [ - 51, - 52, + 44, + 45, ], "type": "Punctuator", "value": ">",