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

Breaking: make 'useJSXTextNode:true' by default #544

Merged
merged 4 commits into from
Nov 10, 2018
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
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