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

Commit 9be81da

Browse files
committed
New: Create option to enable JSXText node type (fixes #266)
1 parent f5fcc87 commit 9be81da

File tree

105 files changed

+897
-12
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

+897
-12
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

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

16141614
}
16151615

1616-
case SyntaxKind.JsxText:
1616+
case SyntaxKind.JsxText: {
1617+
const type = (additionalOptions.useJSXTextNode)
1618+
? AST_NODE_TYPES.JSXText : AST_NODE_TYPES.Literal;
1619+
16171620
Object.assign(result, {
1618-
type: AST_NODE_TYPES.Literal,
1621+
type,
16191622
value: ast.text.slice(node.pos, node.end),
16201623
raw: ast.text.slice(node.pos, node.end)
16211624
});
@@ -1624,6 +1627,7 @@ module.exports = function convert(config) {
16241627
result.range[0] = node.pos;
16251628

16261629
break;
1630+
}
16271631

16281632
case SyntaxKind.JsxSpreadAttribute:
16291633
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)