mxw / vim-jsx

React JSX syntax highlighting and indenting for vim.
1.59k stars 95 forks source link

Closing paren in nested jsx has incorrect indentation #98

Closed rbong closed 8 years ago

rbong commented 8 years ago

I have all dependencies. Here is my cut down .vimrc

au Filetype javascript setlocal expandtab tabstop=2 shiftwidth=2
call plug#begin('~/.vim/plugged')
    Plug 'pangloss/vim-javascript'
    let g:javascript_enable_domhtmlcss = 1
    Plug 'mxw/vim-jsx'
    let g:jsx_ext_required = 0
call plug#end()
filetype plugin indent on

Notice the line that the cursor is on has incorrect indent, but several lines later the correct indentation is present on the closing paren.

2016-07-02-105127_507x421_scrot

Here is the text.

import React, { Component } from 'react';

class Test extends Component {
  render() {
    return (
      <div>
        {
          Object.keys(test).map((test) => {
            return (
              <div>
              </div>
            );
          })
        }
      </div>
    );
  }
}
mxw commented 8 years ago

An actual bug report of an actual bug by a person who has read the README! A true unicorn.

I've repro'd this. I'm not sure off the top of my head why it's happening (since the outer return (); indents fine), but thank you for reporting; I will look into it when I have some time.

sheerun commented 8 years ago

Similar issue happens when using ?: operator:

<Navbar.Form pullRight>
  {
    auth.loggedIn()
      ? <Button onClick={this.logout}>Log Out</Button>
      : <Button bsStyle="primary" onClick={auth.login}>Log In</Button>
      }
    </Navbar.Form>
sheerun commented 8 years ago

Actually even without ?: it indents last } wrongly

mxw commented 8 years ago

Finally got around to looking at this. I believe I've fixed the issue (all the issues reported in this thread) by improving the heuristic for detecting whether we've left a jsxRegion across a line break. Please let me know if you find that this is still a problem—or, of course, if you find any new and exciting problems.

Thanks for reporting!

mxw commented 8 years ago

Also, apologies that the fix (and fixes in general) take so long. I don't do any sort of regular development with JSX, so I have to page a bunch of stuff in to test and fix. Thanks for your patience!

sheerun commented 8 years ago

Works awesome, thank you!

rbong commented 8 years ago

Works for me as well.