From 806cec96a3b84664cec6ba7c798c12fc7c07bd29 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 8 Nov 2018 20:49:11 +0900 Subject: [PATCH 1/3] Breaking: make 'useJSXTextNode:true' by default --- parser.js | 6 ++++++ tests/lib/__snapshots__/comments.js.snap | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/parser.js b/parser.js index 32b4e7c..113b55f 100644 --- a/parser.js +++ b/parser.js @@ -20,6 +20,12 @@ const visitorKeys = require("./visitor-keys"); exports.version = require("./package.json").version; exports.parseForESLint = function parseForESLint(code, options) { + if (typeof options !== "object" || options === null) { + options = { useJSXTextNode: true }; + } else if (typeof options.useJSXTextNode !== "boolean") { + options = Object.assign({}, options, { useJSXTextNode: true }); + } + const ast = parse(code, options); traverser.traverse(ast, { enter: node => { diff --git a/tests/lib/__snapshots__/comments.js.snap b/tests/lib/__snapshots__/comments.js.snap index 41309c3..5672625 100644 --- a/tests/lib/__snapshots__/comments.js.snap +++ b/tests/lib/__snapshots__/comments.js.snap @@ -1219,7 +1219,7 @@ Object { ], "raw": " ", - "type": "Literal", + "type": "JSXText", "value": " ", }, @@ -1274,7 +1274,7 @@ Object { ], "raw": " ", - "type": "Literal", + "type": "JSXText", "value": " ", }, @@ -1960,7 +1960,7 @@ Object { ], "raw": " ", - "type": "Literal", + "type": "JSXText", "value": " ", }, From f73bbc6eaf768613de23a6fca1238ea965760522 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 8 Nov 2018 20:54:03 +0900 Subject: [PATCH 2/3] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68c8dee..4562562 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The following additional configuration options are available by specifying them **`jsx`** - default `false`. Enable parsing JSX when `true`. More details can be found [here](https://www.typescriptlang.org/docs/handbook/jsx.html). -**`useJSXTextNode`** - default `false`. The JSX AST changed the node type for string literals inside a JSX Element from `Literal` to `JSXText`. When value is `true`, these nodes will be parsed as type `JSXText`. When value is `false`, these nodes will be parsed as type `Literal`. +**`useJSXTextNode`** - default `true`. The JSX AST changed the node type for string literals inside a JSX Element from `Literal` to `JSXText`. When value is `true`, these nodes will be parsed as type `JSXText`. When value is `false`, these nodes will be parsed as type `Literal`. Please set `false` if you use this parser on ESLint v4. ### .eslintrc.json From 28a703c68ad18995edd466a0de764b187553e243 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 8 Nov 2018 22:15:19 +0900 Subject: [PATCH 3/3] modify the description of `useJSXTextNode` option --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4562562..cc53309 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The following additional configuration options are available by specifying them **`jsx`** - default `false`. Enable parsing JSX when `true`. More details can be found [here](https://www.typescriptlang.org/docs/handbook/jsx.html). -**`useJSXTextNode`** - default `true`. The JSX AST changed the node type for string literals inside a JSX Element from `Literal` to `JSXText`. When value is `true`, these nodes will be parsed as type `JSXText`. When value is `false`, these nodes will be parsed as type `Literal`. Please set `false` if you use this parser on ESLint v4. +**`useJSXTextNode`** - default `true`. Please set `false` if you use this parser on ESLint v4. If this is `false`, the parser creates the AST of JSX texts as the legacy style. ### .eslintrc.json