[PATCH] D33640: clang-format: [JS] fix indenting bound functions.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 29 00:51:17 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304135: clang-format: [JS] fix indenting bound functions. (authored by mprobst).
Changed prior to commit:
https://reviews.llvm.org/D33640?vs=100589&id=100591#toc
Repository:
rL LLVM
https://reviews.llvm.org/D33640
Files:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -717,6 +717,11 @@
" bar();\n"
"}.bind(this));");
+ verifyFormat("SomeFunction((function() {\n"
+ " foo();\n"
+ " bar();\n"
+ " }).bind(this));");
+
// FIXME: This is bad, we should be wrapping before "function() {".
verifyFormat("someFunction(function() {\n"
" doSomething(); // break\n"
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -215,7 +215,7 @@
// ...
// }.bind(...));
// FIXME: We should find a more generic solution to this problem.
- !(State.Column <= NewLineColumn && Previous.isNot(tok::r_paren) &&
+ !(State.Column <= NewLineColumn &&
Style.Language == FormatStyle::LK_JavaScript))
return true;
@@ -689,7 +689,18 @@
return State.Stack[State.Stack.size() - 2].LastSpace;
return State.FirstIndent;
}
- if (Current.is(tok::r_paren) && State.Stack.size() > 1)
+ // Indent a closing parenthesis at the previous level if followed by a semi or
+ // opening brace. This allows indentations such as:
+ // foo(
+ // a,
+ // );
+ // function foo(
+ // a,
+ // ) {
+ // code(); //
+ // }
+ if (Current.is(tok::r_paren) && State.Stack.size() > 1 &&
+ (!Current.Next || Current.Next->isOneOf(tok::semi, tok::l_brace)))
return State.Stack[State.Stack.size() - 2].LastSpace;
if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
return State.Stack[State.Stack.size() - 2].LastSpace;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33640.100591.patch
Type: text/x-patch
Size: 1975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170529/1467bc09/attachment.bin>
More information about the cfe-commits
mailing list