This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] do not collapse - - to --.
ClosedPublic

Authored by mprobst on Mar 29 2021, 4:16 AM.

Details

Summary

In JavaScript, - -1; is legal syntax, the language allows unary minus.
However the two tokens must not collapse together: --1 is prefix
decrement, i.e. different syntax.

Before:

  • -1; ==> --1;

After:

  • -1; ==> - -1;

This change makes no attempt to format this "nicely", given by all
likelihood this represents a programming mistake by the user, or odd
generated code.

The check is not guarded by language: this appears to be a problem in
Java as well, and will also be beneficial when formatting syntactically
incorrect C++ (e.g. during editing).

Diff Detail

Event Timeline

mprobst requested review of this revision.Mar 29 2021, 4:16 AM
mprobst created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2021, 4:16 AM
krasimir accepted this revision.Mar 29 2021, 4:40 AM
This revision is now accepted and ready to land.Mar 29 2021, 4:40 AM
This revision was automatically updated to reflect the committed changes.