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

Commit 852eafc

Browse files
committed
New: Create option to enable JSXText node type (fixes #266)
1 parent 69edd79 commit 852eafc

File tree

105 files changed

+902
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+902
-11
lines changed

lib/ast-converter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ module.exports = (ast, extra) => {
5656
parent: null,
5757
ast,
5858
additionalOptions: {
59-
errorOnUnknownASTType: extra.errorOnUnknownASTType || false
59+
errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
60+
useJSXTextNode: extra.useJSXTextNode || false
6061
}
6162
});
6263

lib/convert.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1613,9 +1613,18 @@ module.exports = function convert(config) {
16131613

16141614
}
16151615

1616-
case SyntaxKind.JsxText:
1616+
/**
1617+
* The JSX AST changed the node type for string literals
1618+
* inside a JSX Element from `Literal` to `JSXText`. We
1619+
* provide a flag to support both types until `Literal`
1620+
* node type is deprecated in ESLint v5.
1621+
*/
1622+
case SyntaxKind.JsxText: {
1623+
const type = (additionalOptions.useJSXTextNode)
1624+
? AST_NODE_TYPES.JSXText : AST_NODE_TYPES.Literal;
1625+
16171626
Object.assign(result, {
1618-
type: AST_NODE_TYPES.Literal,
1627+
type,
16191628
value: ast.text.slice(node.pos, node.end),
16201629
raw: ast.text.slice(node.pos, node.end)
16211630
});
@@ -1624,6 +1633,7 @@ module.exports = function convert(config) {
16241633
result.range[0] = node.pos;
16251634

16261635
break;
1636+
}
16271637

16281638
case SyntaxKind.JsxSpreadAttribute:
16291639
Object.assign(result, {

parser.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function resetExtra() {
4848
tolerant: false,
4949
errors: [],
5050
strict: false,
51-
ecmaFeatures: {}
51+
ecmaFeatures: {},
52+
useJSXTextNode: false
5253
};
5354
}
5455

@@ -104,6 +105,10 @@ function parse(code, options) {
104105
extra.errorOnUnknownASTType = true;
105106
}
106107

108+
if (typeof options.useJSXTextNode === "boolean" && options.useJSXTextNode) {
109+
extra.useJSXTextNode = true;
110+
}
111+
107112
}
108113

109114
// Even if jsx option is set in typescript compiler, filename still has to

0 commit comments

Comments
 (0)