diff --git a/README.md b/README.md index fd8d6bb..e49bbb0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/parser.js b/parser.js index 10d3063..693992e 100644 --- a/parser.js +++ b/parser.js @@ -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 }); 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": " ", },