From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Felipe Ochoa Newsgroups: gmane.emacs.bugs Subject: bug#24896: JSX prop indentation after fat arrow Date: Mon, 7 Nov 2016 10:56:21 +0100 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bae45323c37730540b30929 X-Trace: blaine.gmane.org 1478536550 1288 195.159.176.226 (7 Nov 2016 16:35:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 7 Nov 2016 16:35:50 +0000 (UTC) To: 24896@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Nov 07 17:35:46 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c3mt1-0004ge-RV for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Nov 2016 17:35:08 +0100 Original-Received: from localhost ([::1]:55126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3mt4-0004kw-Tk for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Nov 2016 11:35:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3msy-0004kh-A2 for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2016 11:35:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3msx-0001RY-Cl for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2016 11:35:04 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33185) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c3msx-0001RM-8o for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2016 11:35:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c3msx-0007Mg-3K for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2016 11:35:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Felipe Ochoa Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Nov 2016 16:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24896 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.147853647128251 (code B ref -1); Mon, 07 Nov 2016 16:35:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Nov 2016 16:34:31 +0000 Original-Received: from localhost ([127.0.0.1]:48582 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c3msQ-0007Lb-ME for submit@debbugs.gnu.org; Mon, 07 Nov 2016 11:34:30 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:60034) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c3gfJ-0002Ve-3q for submit@debbugs.gnu.org; Mon, 07 Nov 2016 04:56:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3gfC-0000NL-KQ for submit@debbugs.gnu.org; Mon, 07 Nov 2016 04:56:27 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:33381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c3gfC-0000NH-HZ for submit@debbugs.gnu.org; Mon, 07 Nov 2016 04:56:26 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3gfB-0001II-4x for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2016 04:56:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3gfA-0000Me-2B for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2016 04:56:25 -0500 Original-Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:38616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c3gf9-0000MO-Pz for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2016 04:56:23 -0500 Original-Received: by mail-wm0-x235.google.com with SMTP id f82so107191650wmf.1 for ; Mon, 07 Nov 2016 01:56:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=VJmS/V1XIZDsh/rB37q8xNSwF79geYioHeOeS7gi8e4=; b=Fh8AG5UvMBGDId7JkcXw8EOs5xNgT9jcwXIWGoSxFP29rCv0q4+YniwjzRxohEw5YZ J0Khc0TVSwBAALIyjUG2xjzqwDoefzKREauQp9RyNQjwTyIxsbAr0uNBwTxwMcOPVJ1H Fn9WJN9UiEwY+LynH/kfZ3zC7qq/uYVMT8pq8zYHI1OI8xeG8sNRrGRPwvmk7UaFd2I+ ia+iY4wswIoDGh3PBV+wgW9G6T5E4tHrUR6PdnORfbS1wCjy4fWjIsN7NEy8XTVSrfCS Ab6dUc+iM28zL03pcFEqCUnS1KQK+n9awJ3KG4AtJGxhUkRc/NG4ee1AHQmvxE6hgcmo Oc7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=VJmS/V1XIZDsh/rB37q8xNSwF79geYioHeOeS7gi8e4=; b=exA1epqMbnHWlblebABBm79a9/qNRbYLX0MtxY8/FhPcIjg/CbD0gX01D4iqilu1p0 Q/XizWDS2zsIXfmc58OfbsQKOV32X/yE/TSFagVRI5oXsmInXBA55m1T2O+x8HY69N+9 F1SFvTuf5HOX8cIyQS5d5fEHb9uTtuh7cldekZsR0/2rAQ/aSh03m9yUQlob8jCwKzsl 3noE3O4x8U43qOTzScPD8nIpx90xlNKjGTmnmrKZEPvefAGLkA7i/Cg8HafNj9zimlFh esx7a84iazft0mUNmIRrUTLc2T1rkWeSGbxjxJC3f5BpWqoD/AArJxrDUjhN/fbxWftk Dfdw== X-Gm-Message-State: ABUngvfoL2K2ujyzEtLz6XDK2S93/xlpwIt+Dqo0epW7AnMIS91nP7T0TMvpqSgHxgUHhPXFjCZny4mQ6tERDA== X-Received: by 10.194.203.5 with SMTP id km5mr5638517wjc.230.1478512581816; Mon, 07 Nov 2016 01:56:21 -0800 (PST) Original-Received: by 10.194.185.5 with HTTP; Mon, 7 Nov 2016 01:56:21 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Mailman-Approved-At: Mon, 07 Nov 2016 11:34:29 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:125425 Archived-At: --047d7bae45323c37730540b30929 Content-Type: text/plain; charset=UTF-8 (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 c} b={123}> ); const Component = props => ( // Correct indentation ); 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 => ( /} b={123}> ); --047d7bae45323c37730540b30929 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
(Pree= mptive 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 confus= ed when there's a fat arrow function in a JSX prop. Compare the way the following two code blocks are=20 auto-indented:

const Co= mponent =3D props =3D> ( // Incorrect indentation
=C2=A0=C2=A0=C2=A0 = <FatArrow a=3D{e =3D> c}
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 b=3D{123}&= gt;
=C2=A0=C2=A0=C2=A0 </FatArrow>
);

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

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

Unfortunately, `js-jsx-indent-line'= calls `sgml-indent-line' using `js--as-sgml', which sets `parse-se= xp-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 on= ly use 'syntax-table propeties for regex literals.


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

const Compone= nt =3D props =3D> (
=C2=A0=C2=A0=C2=A0 <WithRegex a=3D{/>/}
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 b=3D{123}>
=C2=A0=C2=A0=C2=A0 </WithRegex>
);
<= /span>
--047d7bae45323c37730540b30929--