clang-format: [JS] handle pseudo-keywords.
authorMartin Probst <martin@probst.io>
Mon, 6 Apr 2020 13:20:54 +0000 (15:20 +0200)
committerMartin Probst <martin@probst.io>
Mon, 6 Apr 2020 15:13:04 +0000 (17:13 +0200)
commit92201505cdecd8ba5795f5e33821c49dc57f0816
tree0527074e355256be3d03644c9c3f93d4c1347f71
parentab1fad8a3a8b8e3264c34448205061add013b8d7
clang-format: [JS] handle pseudo-keywords.

Summary:
The previous change in https://reviews.llvm.org/D77311 attempted to
detect more C++ keywords. However it also precisely detected all
JavaScript keywords. That's generally correct, but many JavaScripy
keywords, e.g. `get`, are so-called pseudo-keywords. They can be used in
positions where a keyword would never be legal, e.g. in a dotted
expression:

    x.type;  // type is a pseudo-keyword, but can be used here.
    x.get;   // same for get etc.

This change introduces an additional parameter to
`IsJavaScriptIdentifier`, allowing clients to toggle whether they want
to allow `IdentifierName` tokens, i.e. pseudo-keywords.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77548
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestJS.cpp