r299533 - clang-format: [JS] fix whitespace around "of" operator.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 5 03:56:08 PDT 2017
Author: mprobst
Date: Wed Apr 5 05:56:07 2017
New Revision: 299533
URL: http://llvm.org/viewvc/llvm-project?rev=299533&view=rev
Log:
clang-format: [JS] fix whitespace around "of" operator.
Summary:
Previously:
import {of } from 'x';
of (null);
Now:
import {of} from 'x';
of(null);
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D31698
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=299533&r1=299532&r2=299533&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Apr 5 05:56:07 2017
@@ -2270,8 +2270,12 @@ bool TokenAnnotator::spaceRequiredBefore
if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
Left.Tok.getIdentifierInfo())
return false;
- if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
- Keywords.kw_of, tok::kw_const) &&
+ 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
+ // (e.g. as "const x of y" in a for loop).
+ (Left.is(Keywords.kw_of) && Left.Previous &&
+ Left.Previous->Tok.getIdentifierInfo())) &&
(!Left.Previous || !Left.Previous->is(tok::period)))
return true;
if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous &&
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=299533&r1=299532&r2=299533&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Apr 5 05:56:07 2017
@@ -132,6 +132,8 @@ TEST_F(FormatTestJS, ReservedWords) {
verifyFormat("x.interface = 1;");
verifyFormat("x.for = 1;");
verifyFormat("x.of() = 1;");
+ verifyFormat("of(null);");
+ verifyFormat("import {of} from 'x';");
verifyFormat("x.in() = 1;");
verifyFormat("x.let() = 1;");
verifyFormat("x.var() = 1;");
More information about the cfe-commits
mailing list