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

Commit

Permalink
Breaking: make 'useJSXTextNode:true' by default (#544)
Browse files Browse the repository at this point in the history
* Breaking: make 'useJSXTextNode:true' by default

* update README.md

* modify the description of `useJSXTextNode` option
  • Loading branch information
mysticatea authored Nov 10, 2018
1 parent 2d22321 commit 150ffe8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The following additional configuration options are available by specifying them
- It's `true` on `*.tsx` files regardless of this option.
- Otherwise, it respects this option.

- **`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`. 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

Expand Down
7 changes: 6 additions & 1 deletion parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const visitorKeys = require("./visitor-keys");
exports.version = require("./package.json").version;

exports.parseForESLint = function parseForESLint(code, options) {
if (options && typeof options.filePath === "string") {
if (typeof options !== "object" || options === null) {
options = { useJSXTextNode: true };
} else if (typeof options.useJSXTextNode !== "boolean") {
options = Object.assign({}, options, { useJSXTextNode: true });
}
if (typeof options.filePath === "string") {
const tsx = options.filePath.endsWith(".tsx");
if (tsx || options.filePath.endsWith(".ts")) {
options = Object.assign({}, options, { jsx: tsx });
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/__snapshots__/comments.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -1274,7 +1274,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -1960,7 +1960,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down

0 comments on commit 150ffe8

Please sign in to comment.