]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] fix `of` detection.
authorMartin Probst <martin@probst.io>
Mon, 19 Feb 2018 12:32:13 +0000 (12:32 +0000)
committerMartin Probst <martin@probst.io>
Mon, 19 Feb 2018 12:32:13 +0000 (12:32 +0000)
Summary:
`of` is only a keyword when after an identifier, but not when after
an actual keyword.

Before:
    return of (a, b, c);
After:
    return of(a, b, c);

Reviewers: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D43440

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

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

index be42d5046def75175ccc3a85a380f7beddff3ee8..75a3fdce80306c1e3911f323ebe8d2b6ac326c69 100644 (file)
@@ -2496,7 +2496,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
          // (e.g. as "const x of y" in a for loop), or after a destructuring
          // operation (const [x, y] of z, const {a, b} of c).
          (Left.is(Keywords.kw_of) && Left.Previous &&
-          (Left.Previous->Tok.getIdentifierInfo() ||
+          (Left.Previous->Tok.is(tok::identifier) ||
            Left.Previous->isOneOf(tok::r_square, tok::r_brace)))) &&
         (!Left.Previous || !Left.Previous->is(tok::period)))
       return true;
index 47886521008ed0bb444503730633a42a23f325f9..b9983f5c6e0482c424cb52b385608fe8accc407d 100644 (file)
@@ -294,6 +294,7 @@ TEST_F(FormatTestJS, ReservedWords) {
   verifyFormat("x.for = 1;");
   verifyFormat("x.of();");
   verifyFormat("of(null);");
+  verifyFormat("return of(null);");
   verifyFormat("import {of} from 'x';");
   verifyFormat("x.in();");
   verifyFormat("x.let();");