[PATCH] clang-format: [JS] Better support for fat arrows.

Manuel Klimek klimek at google.com
Thu May 21 04:49:06 PDT 2015


================
Comment at: lib/Format/UnwrappedLineParser.cpp:885-887
@@ -884,1 +884,5 @@
     case tok::equal:
+      // Fat arrows (=>) have TokenKind tok::equal. The always start an
+      // expression or a child block if followed by a curly.
+      if (FormatTok->is(TT_JsFatArrow)) {
+        nextToken();
----------------
Seems like they have TokenKind TT_JsFatArrow now.

================
Comment at: lib/Format/UnwrappedLineParser.cpp:1044-1045
@@ -1020,1 +1043,4 @@
 
+void UnwrappedLineParser::parseBalanced(tok::TokenKind OpenKind,
+                                        tok::TokenKind CloseKind) {
+  int Depth = 1;
----------------
Most of the time we enter parse* functions with the first token of that projection. In this case, I'd expect the current token still be the OpenKind.

================
Comment at: lib/Format/UnwrappedLineParser.cpp:1048
@@ +1047,3 @@
+  while (Depth > 0 && !eof()) {
+    // Parse the formal parameter list
+    if (FormatTok->is(OpenKind)) {
----------------
Nit: add '.'

================
Comment at: lib/Format/UnwrappedLineParser.cpp:1050
@@ +1049,3 @@
+    if (FormatTok->is(OpenKind)) {
+      Depth++;
+    } else if (FormatTok->is(CloseKind)) {
----------------
Use pre-increment in C++.

================
Comment at: lib/Format/UnwrappedLineParser.h:110-114
@@ -109,2 +109,7 @@
   void tryToParseJSFunction();
+  // Parses tokens until encountering the CloseKind token, but balances tokens
+  // when encountering more OpenKind tokens. Useful for e.g. parsing a curly
+  // brace delimited block that can contain nested blocks.
+  // The parser must be positioned just past a token of OpenKind.
+  void parseBalanced(tok::TokenKind OpenKind, tok::TokenKind CloseKind);
   void addUnwrappedLine();
----------------
a) use doxygen comments for functions
b) we usually don't have nested parens or nested blocks where there can't be anything in we'd want to parse explicitly; I assume you know what you're doing for JS here, but I find that really curious

http://reviews.llvm.org/D9906

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list