]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] fix whitespace around "of" operator.
authorMartin Probst <martin@probst.io>
Wed, 5 Apr 2017 10:56:07 +0000 (10:56 +0000)
committerMartin Probst <martin@probst.io>
Wed, 5 Apr 2017 10:56:07 +0000 (10:56 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299533 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index fe7e4192719622b0b9c0d79f6039fbaf1ba509f0..a63b345cb9b1329cc3bcf64658c2593cccfedd29 100644 (file)
@@ -2270,8 +2270,12 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     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 &&
index f24ddc8fa2c62bcd2cc6146e310371c2d107e49c..d8fa8e4b942ce35a9bf7604fdc5606b4a2682a2f 100644 (file)
@@ -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;");