[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 05:16:40 PDT 2017
mprobst updated this revision to Diff 109089.
mprobst added a comment.
- support switch, case, delete.
https://reviews.llvm.org/D36142
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -232,6 +232,9 @@
verifyFormat("x.var() = 1;");
verifyFormat("x.for() = 1;");
verifyFormat("x.as() = 1;");
+ verifyFormat("x.instanceof() = 1;");
+ verifyFormat("x.switch() = 1;");
+ verifyFormat("x.case() = 1;");
verifyFormat("x = {\n"
" a: 12,\n"
" interface: 1,\n"
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,13 @@
if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
Left.Tok.getIdentifierInfo())
return false;
+ // Valid JS method names can include keywords, e.g. `foo.delete()` or
+ // `bar.instanceof()`.
+ if (Right.is(tok::l_paren) && Left.Previous &&
+ Left.Previous->is(tok::period) &&
+ (Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::kw_switch, tok::kw_case, tok::kw_delete)))
+ return false;
if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
tok::kw_const) ||
// "of" is only a keyword if it appears after another identifier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36142.109089.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170801/6e595b17/attachment.bin>
More information about the cfe-commits
mailing list