Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSX support #426

Open
elizabethdinella opened this issue Jun 30, 2019 · 1 comment
Open

JSX support #426

elizabethdinella opened this issue Jun 30, 2019 · 1 comment

Comments

@elizabethdinella
Copy link

elizabethdinella commented Jun 30, 2019

Are there any plans to add support for JSX?

@bakkot
Copy link
Member

bakkot commented Jun 30, 2019

No, we track the ECMAScript spec.

That said, it probably would not be too hard to extend the parser yourself to do so. Something along the lines of

let { GenericParser } = require('shift-parser'); // or ParserWithLocation if you want the location side-table

class JSXParser extends GenericParser {
  parsePrimaryExpression() {
    if (this.match(TokenType.LT)) {
      return this.parseJSX();
    }
    return super.parsePrimaryExpression();
  }
  
  parseJSX() {
    // implementation goes here
  }
}

let ast = (new JSXParser(code)).parseModule();

You might need to override the tokenizer methods as well; I don't know JSX well enough to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants