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

Commit 76bef55

Browse files
committed
New: Create option to enable JSXText node type (fixes #266)
1 parent 6dd3696 commit 76bef55

File tree

105 files changed

+905
-15
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

+905
-15
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

+15-6
Original file line numberDiff line numberDiff line change
@@ -1613,16 +1613,25 @@ module.exports = function convert(config) {
16131613

16141614
}
16151615

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+
*/
16161622
case SyntaxKind.JsxText: {
1617-
Object.assign(result, {
1618-
type: AST_NODE_TYPES.Literal,
1619-
value: ast.text.slice(node.pos, node.end),
1620-
raw: ast.text.slice(node.pos, node.end)
1621-
});
1622-
16231623
const start = node.getFullStart();
16241624
const end = node.getEnd();
16251625

1626+
const type = (additionalOptions.useJSXTextNode)
1627+
? AST_NODE_TYPES.JSXText : AST_NODE_TYPES.Literal;
1628+
1629+
Object.assign(result, {
1630+
type,
1631+
value: ast.text.slice(start, end),
1632+
raw: ast.text.slice(start, end)
1633+
});
1634+
16261635
result.loc = nodeUtils.getLocFor(start, end, ast);
16271636
result.range = [start, end];
16281637

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)