[PATCH] D42570: clang-format: [JS] Prevent ASI before [ and (.

2018-01-26 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323532: clang-format: [JS] Prevent ASI before [ and (. 
(authored by mprobst, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42570

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
@@ -2710,9 +2710,11 @@
 Keywords.kw_readonly, Keywords.kw_abstract, Keywords.kw_get,
 Keywords.kw_set, Keywords.kw_async, Keywords.kw_await))
   return false; // Otherwise automatic semicolon insertion would trigger.
-if (Left.Tok.getIdentifierInfo() &&
-Right.startsSequence(tok::l_square, tok::r_square))
-  return false;  // breaking in "foo[]" creates illegal TS type syntax.
+if (Right.NestingLevel == 0 &&
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::r_square, tok::r_paren)) &&
+Right.isOneOf(tok::l_square, tok::l_paren))
+  return false; // Otherwise automatic semicolon insertion would trigger.
 if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
   return false;
 if (Left.is(TT_JsTypeColon))
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1157,6 +1157,9 @@
"foo() {}",
getGoogleJSStyleWithColumns(10));
   verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10));
+  verifyFormat("x = (a['a']\n"
+   "  ['b']);", getGoogleJSStyleWithColumns(10));
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2710,9 +2710,11 @@
 Keywords.kw_readonly, Keywords.kw_abstract, Keywords.kw_get,
 Keywords.kw_set, Keywords.kw_async, Keywords.kw_await))
   return false; // Otherwise automatic semicolon insertion would trigger.
-if (Left.Tok.getIdentifierInfo() &&
-Right.startsSequence(tok::l_square, tok::r_square))
-  return false;  // breaking in "foo[]" creates illegal TS type syntax.
+if (Right.NestingLevel == 0 &&
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::r_square, tok::r_paren)) &&
+Right.isOneOf(tok::l_square, tok::l_paren))
+  return false; // Otherwise automatic semicolon insertion would trigger.
 if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
   return false;
 if (Left.is(TT_JsTypeColon))
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1157,6 +1157,9 @@
"foo() {}",
getGoogleJSStyleWithColumns(10));
   verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10));
+  verifyFormat("x = (a['a']\n"
+   "  ['b']);", getGoogleJSStyleWithColumns(10));
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42570: clang-format: [JS] Prevent ASI before [ and (.

2018-01-26 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.

Makes sense.


Repository:
  rC Clang

https://reviews.llvm.org/D42570



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


[PATCH] D42570: clang-format: [JS] Prevent ASI before [ and (.

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

JavaScript automatic semicolon insertion can trigger before [ and (, so
avoid breaking before them if the previous token is likely to terminate
an expression.


Repository:
  rC Clang

https://reviews.llvm.org/D42570

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


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1157,6 +1157,9 @@
"foo() {}",
getGoogleJSStyleWithColumns(10));
   verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10));
+  verifyFormat("x = (a['a']\n"
+   "  ['b']);", getGoogleJSStyleWithColumns(10));
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2710,9 +2710,11 @@
 Keywords.kw_readonly, Keywords.kw_abstract, Keywords.kw_get,
 Keywords.kw_set, Keywords.kw_async, Keywords.kw_await))
   return false; // Otherwise automatic semicolon insertion would trigger.
-if (Left.Tok.getIdentifierInfo() &&
-Right.startsSequence(tok::l_square, tok::r_square))
-  return false;  // breaking in "foo[]" creates illegal TS type syntax.
+if (Right.NestingLevel == 0 &&
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::r_square, tok::r_paren)) &&
+Right.isOneOf(tok::l_square, tok::l_paren))
+  return false; // Otherwise automatic semicolon insertion would trigger.
 if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
   return false;
 if (Left.is(TT_JsTypeColon))


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1157,6 +1157,9 @@
"foo() {}",
getGoogleJSStyleWithColumns(10));
   verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10));
+  verifyFormat("x = (a['a']\n"
+   "  ['b']);", getGoogleJSStyleWithColumns(10));
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2710,9 +2710,11 @@
 Keywords.kw_readonly, Keywords.kw_abstract, Keywords.kw_get,
 Keywords.kw_set, Keywords.kw_async, Keywords.kw_await))
   return false; // Otherwise automatic semicolon insertion would trigger.
-if (Left.Tok.getIdentifierInfo() &&
-Right.startsSequence(tok::l_square, tok::r_square))
-  return false;  // breaking in "foo[]" creates illegal TS type syntax.
+if (Right.NestingLevel == 0 &&
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::r_square, tok::r_paren)) &&
+Right.isOneOf(tok::l_square, tok::l_paren))
+  return false; // Otherwise automatic semicolon insertion would trigger.
 if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
   return false;
 if (Left.is(TT_JsTypeColon))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits