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 3 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 @@ -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`. 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
6 changes: 6 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
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