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

Already on GitHub? Sign in to your account

Embedded JSX in parens breaks indentation #411

Open
benzitohhh opened this Issue Apr 6, 2017 · 1 comment

Comments

Projects
None yet
2 participants

benzitohhh commented Apr 6, 2017 edited

Hi there,

in js2-jsx-mode (and also rjsx-mode)...

when embedded JSX is wrapped in parens, the indentation breaks.

Some examples:

// All indents ok
let a = (
  <div>
    {condition && <Component/>}
    {condition && <Component/>}
    <div/>
  </div>
)

// Last line is wrongly indented
let b = (
  <div>
    {condition && (<Component/>)}
    <div/>
    </div>
)

// Penultimate line is wrongly indented
let c = (
  <div>
    {condition && (<Component/>)}
  {condition && "something"}
  </div>
)

// Penultimate line is wrongly indented
let d = (
  <div>
    {(<Component/>)}
  {condition && "something"}
  </div>
)

It seems like when previous line has embedded JSX in parens,
"indentation-type" is interpretted as "nil" (should be "nth")
i.e. see js-jsx-indent-line and js--jsx-indented-element-p (in js.el)

I get this behaviour in both Emacs 25.1 and also Emacs 25.1-2

Obviously one workaround would be to not use parens. But unfortunately I need to use parens to make certain rjsx functinality work (i.e. see felipeochoa/rjsx-mode#27 (comment) and https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24896#20)

Anyways any ideas would be really appreciated - thanks!

wd commented Jul 23, 2017

It seems I got the same issue:

            <View >
                <GANavBar goBack={()=>this.test} />
                    <View >test</View>
            </View>

Line 3 shouldn't indent. If I delete the '()=>', the indent works ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment