Skip to content

Arrow function problems in classes #365

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

Closed
Kareeeeem opened this issue Apr 9, 2016 · 6 comments
Closed

Arrow function problems in classes #365

Kareeeeem opened this issue Apr 9, 2016 · 6 comments

Comments

@Kareeeeem
Copy link

Hi, I updated my plugins today and I encountered an error.

When putting arrow functions inside (react) classes it breaks highlighting and also matchfinding of braces.

This is what was working fine before. Notice the messed up highlighting and the last brace of the class that is mistakenly highlighted as an error.
screenshot 2016-04-09 at 22 01 49

To fix it I have to write normal functions like so.
screenshot 2016-04-09 at 22 01 06

for completeness here is the code and the minimal vimrc (I elimited the jsx highlighter as the culprit.)

filetype off                                                                    

call plug#begin('~/.vim/plugged')                                               

Plug 'pangloss/vim-javascript', {'for': '*javascript*'}                         
Plug 'mxw/vim-jsx', {'for': '*javascript*'}                                     
call plug#end()                                                                 
colorscheme ron                                                                 
let g:jsx_ext_required = 0
import React, { Component } from 'react'
import { connect } from 'react-redux'

function Button (props) {
  return <button
    name={props.name}
    onClick={props.handlePagination}
    disabled={props.disabled}
  >
    {props.children}
  </button>
}

function Pagination (props) {
  return (
    <div>
      <Button
        name='prev'
        handlePagination={props.handlePagination}
        disabled={props.disabledPrev}
      > prev </Button>

      <Button
        name='next'
        handlePagination={props.handlePagination}
        disabled={props.disabledNext}
      > next </Button>
    </div>
  )
}

class Paginated extends Component {
  handlePagination = (e) => {
    const pageTurn = e.target.name // either 'prev' or 'next'
    const newPageUrl = this.props.page[pageTurn] // either link or undefined
    // Only dispatch the pageturn if the newPageUrl evaluates to true
    // Pagination option should be diabled but just to be defensive against
    // errors.
    if (newPageUrl) this.props.getNewPage(newPageUrl)
  }

  componentDidMount () {
    if (!this.props.children.length) this.props.getNewPage()
  }

  render () {
    return (
      <div>
        {this.props.children}
        <Pagination
          disabledPrev={this.props.page.prev ? false : true}
          disabledNext={this.props.page.next ? false : true}
          handlePagination={this.handlePagination}
        />
      </div>
    )
  }
}

Paginated.propTypes = {
  page: React.PropTypes.object.isRequired,
  getNewPage: React.PropTypes.func.isRequired,
}

export default Paginated
@Kareeeeem
Copy link
Author

I saw vim-plug supports specifying commits and I just went back in time and the issue persists. So it wasnt an update.

I don't get it though because I've been working on this project for a while and today is the first time the highlighting broke.

@amadeus
Copy link
Collaborator

amadeus commented Apr 9, 2016

@Kareeeeem I think the reason I missed this, is because technically this feature is something from ES7, not ES6. I have a fix ready for this, although it does make me wonder what other ES7 things should be supported that might not be currently?

@amadeus
Copy link
Collaborator

amadeus commented Apr 9, 2016

I have created a fix for this in #366

@Kareeeeem
Copy link
Author

Wow that was quick. And i just installed it to check and it works.

However though as I mentioned above. I have been working on this project for a while and the highlighting broke today. I'm stumped. Anyways I'll keep your fork installed until it's merged. Thanks!

@amadeus
Copy link
Collaborator

amadeus commented Apr 11, 2016

@Kareeeeem the reason it appeared broken recently, is we just recently merged a bunch of stuff into the master branch, and thus you saw it all of a sudden.

@amadeus
Copy link
Collaborator

amadeus commented Apr 11, 2016

This issue should now be fixed in develop

@amadeus amadeus closed this as completed Apr 11, 2016
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