unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24896: JSX prop indentation after fat arrow
@ 2016-11-07  9:56 Felipe Ochoa
  2016-11-19 22:47 ` Dmitry Gutov
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Felipe Ochoa @ 2016-11-07  9:56 UTC (permalink / raw)
  To: 24896

[-- Attachment #1: Type: text/plain, Size: 1575 bytes --]

(Preemptive apologies if this is the wrong list/format for this comment --
first time filer here!)

When indenting JSX code using js2- or js-mode, the indentation function
gets confused when there's a fat arrow function in a JSX prop. Compare the
way the following two code blocks are auto-indented:

const Component = props => ( // Incorrect indentation
    <FatArrow a={e => c}
      b={123}>
    </FatArrow>
);

const Component = props => ( // Correct indentation
    <NoFatArrow a={123}
                b={123}>
    </NoFatArrow>
);

I've tracked the problem down to `sgml-calculate-indent' using
`parse-partial-sexp' with `sgml-tag-syntax-table', where `>' is treated as
a close-parenthesis character (and thus the end-of-tag marker). I don't
think there's a way to patch the syntax table that would let `>' flip
between punctuation and close-parens based on context, but one possible fix
when using js2-mode (not sure about js-mode) is to apply a "."
'syntax-table text property to the `>' when parsing a fat arrow.

Unfortunately, `js-jsx-indent-line' calls `sgml-indent-line' using
`js--as-sgml', which sets `parse-sexp-lookup-properties' to nil.

Would there be any harm in setting `parse-sexp-lookup-properties' to t
instead? As far as I can tell, js-mode and js2-mode only use 'syntax-table
propeties for regex literals.


As a side-note, there may well be a different solution to this problem; I
still don't understand why the following block is indented correctly:

const Component = props => (
    <WithRegex a={/>/}
               b={123}>
    </WithRegex>
);

[-- Attachment #2: Type: text/html, Size: 2475 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-06-06  6:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-07  9:56 bug#24896: JSX prop indentation after fat arrow Felipe Ochoa
2016-11-19 22:47 ` Dmitry Gutov
2016-11-22  5:48   ` Jackson Ray Hamilton
     [not found]     ` <CAHp7JggpF+APETs=BaX-yJMrcX+u55NoXanj_krbfdD-78WRTw@mail.gmail.com>
2016-12-08 11:12       ` Felipe Ochoa
2016-12-09  0:18         ` Dmitry Gutov
2017-01-06 17:44           ` Felipe Ochoa
2017-01-15  2:04             ` Dmitry Gutov
2017-01-23  9:26               ` Felipe Ochoa
2017-01-23 17:07                 ` Jackson Ray Hamilton
2017-01-25  1:59                 ` Dmitry Gutov
2019-06-05  2:47 ` Jackson Ray Hamilton
2019-06-06  6:59 ` Jackson Ray Hamilton

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).