JSX Syntax Support
JSX is a syntax extension to JavaScript, popularly known to build web applications using React. JSX is not part of any official ECMAScript specification. Application code using JSX is typically preprocessed first into standard JavaScript.
Esprima parser fully understands JSX syntax when jsx
flag in the parsing configuration object is set to true, as illustrated in the following example:
- $ node
- > var esprima = require('esprima')
- > esprima.parseScript('var el= <title>${product}</title>', { jsx: true });
- Script {
- type: 'Program',
- body:
- [ VariableDeclaration {
- type: 'VariableDeclaration',
- declarations: [Object],
- kind: 'var' } ],
- sourceType: 'script' }