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

Syntax error on spread operator in JSX component #562

Open
chetstone opened this issue Jul 29, 2020 · 2 comments
Open

Syntax error on spread operator in JSX component #562

chetstone opened this issue Jul 29, 2020 · 2 comments

Comments

@chetstone
Copy link

chetstone commented Jul 29, 2020

I'm using js2-mode 20200725.112 with emacs 28.0.50 and the setup advised in the README (js-mode with js2-minor-mode)

The following code gets a syntax error on {...this.props}

import React from 'react';

function logProps(WrappedComponent) {
  return class extends React.Component {
    componentDidUpdate(prevProps) {
      console.log('Current props: ', this.props);
      console.log('Previous props: ', prevProps);
    }
    render() {
      // Wraps the input component in a container, without mutating it. Good!
      return <WrappedComponent {...this.props} />;
    }
  };
}

This example is from the React blog on Higher Order Components (the second example at that anchor)

@chetstone chetstone changed the title Syntax error on spread operator Syntax error on spread operator in JSX component Jul 29, 2020
@dgutov
Copy link
Collaborator

dgutov commented Jul 29, 2020

Try https://github.com/felipeochoa/rjsx-mode/, it might be the best option for JSX now.

@matthemsteger
Copy link

Unfortunately, for those of us that use tabs for indentation, there is currently no real good solution. I was using rjsx-mode with a workaround for indentation that used js-mode. After emacs 27 landed it stopped working because of upstream changes and js2-mode not supporting 27 fully, see felipeochoa/rjsx-mode#85.

If js-mode with JSX and js2-minor-mode doesn't work well, there is not really a way around it when writing JSX if you want to take advantage of the js2 ecosystem.

I am looking at switching to simply js-mode and tree-sitter (for better syntax highlighting ala rjsx-mode) but then I lose out on js2-refactor et al if js2-minor-mode doesnt work.

It would be pretty nice if js2-mode simply deferred again to emacs for indentation in emacs 27 when using JSX and it worked properly. Then the status quo from emacs 26 continues where I can set rjsx-mode to defer to js-mode for indentation (since it extends js2-mode).

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

3 participants