[PATCH] D43440: clang-format: [JS] fix `of` detection.

2018-02-19 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325489: clang-format: [JS] fix `of` detection. (authored by 
mprobst, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43440

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2496,7 +2496,7 @@
  // (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: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -294,6 +294,7 @@
   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();");


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2496,7 +2496,7 @@
  // (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: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -294,6 +294,7 @@
   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();");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43440: clang-format: [JS] fix `of` detection.

2018-02-19 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D43440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43440: clang-format: [JS] fix `of` detection.

2018-02-18 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
mprobst added a reviewer: djasper.
Herald added a subscriber: klimek.

`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);


Repository:
  rC Clang

https://reviews.llvm.org/D43440

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


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -294,6 +294,7 @@
   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();");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2496,7 +2496,7 @@
  // (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: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -294,6 +294,7 @@
   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();");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2496,7 +2496,7 @@
  // (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;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits