]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix incorrect spacing around contextual keywords.
authorDaniel Jasper <djasper@google.com>
Thu, 17 Mar 2016 12:17:59 +0000 (12:17 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 17 Mar 2016 12:17:59 +0000 (12:17 +0000)
Before:
  x.of ();

After:
  x.of();

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

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

index f7cfe9fa5830ec7fadba51297d94718c30eef71f..96b1df82e56eb3488cc1c31df0834c1de4c87297 100644 (file)
@@ -2038,8 +2038,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
         Left.isOneOf(Keywords.kw_returns, Keywords.kw_option))
       return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
-    if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, TT_JsFatArrow,
-                     Keywords.kw_in, Keywords.kw_of))
+    if (Left.is(TT_JsFatArrow))
+      return true;
+    if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
+                     Keywords.kw_of) &&
+        (!Left.Previous || !Left.Previous->is(tok::period)))
       return true;
     if (Left.is(tok::kw_default) && Left.Previous &&
         Left.Previous->is(tok::kw_export))
index 8d03964fe165c92305d7caf15916d30cfe8476be..822d572b944185da857c148b013cd13ca303b33d 100644 (file)
@@ -125,6 +125,10 @@ TEST_F(FormatTestJS, ReservedWords) {
   verifyFormat("x.class.struct = 1;");
   verifyFormat("x.case = 1;");
   verifyFormat("x.interface = 1;");
+  verifyFormat("x.of() = 1;");
+  verifyFormat("x.in() = 1;");
+  verifyFormat("x.let() = 1;");
+  verifyFormat("x.var() = 1;");
   verifyFormat("x = {\n"
                "  a: 12,\n"
                "  interface: 1,\n"