Subject: bug#47488: Treatment of # in js.el

From: Reuben Thomas <[email-masked]>
Date: Mon, 29 Mar 2021 21:28:29 +0000

I started using private class fields, as described here
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields>
(a stage 3 proposal that is widely implemented, though not actually
standardized yet AFAICT).

These are normal fields that start with a hash.

I find in js--proper-indentation the line (annotated by git blame):

17b5d0f7077 (Chong Yidong         2009-08-14 2864)           ((eq
(char-after) ?#) 0)

It sets the indentation for a line starting with # unconditionally to 0. I
cannot find any other use of # in JavaScript that would justify treating
lines starting with # apparently like C preprocessor macros. There is other
related code, and it all seems to go back to when js.el was first installed
in Emacs.

Is this just because the code was originally based on cc-mode or something,
and the references to hash were never removed? Or was cpp used with early
JavaScript?? I see references such as js--opt-cpp-start which says "Regexp
matching the prefix of a cpp directive", and a match for "#define" in
js--update-quick-match-re.

I cannot see any code in js-tests.el that tests this cpp-related
functionality.

Is there some reason to keep the cpp-related code in js.el? I presume
removing it would simplify then adding support for private class fields;
indeed, maybe no particular support is needed if cpp support is first
removed.

-- 
https://rrt.sc3d.org