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:

  1. $ node
  2. > var esprima = require('esprima')
  3. > esprima.parse('var el= <title>${product}</title>', { jsx: true });
  4. Program {
  5. type: 'Program',
  6. body:
  7. [ VariableDeclaration {
  8. type: 'VariableDeclaration',
  9. declarations: [Object],
  10. kind: 'var' } ],
  11. sourceType: 'script' }