summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-09-05 09:27:38 +0000
committerDaniel Jasper <djasper@google.com>2014-09-05 09:27:38 +0000
commit90ebc98e3da2024c5a7979cf61dae3ec6c1df550 (patch)
treef16769e52a8f2dac12b0b0be19e1bd496058f470
parent3a038de3c8f3b898d49df0c1988eecfea9cfdca8 (diff)
downloadbcm5719-llvm-90ebc98e3da2024c5a7979cf61dae3ec6c1df550.tar.gz
bcm5719-llvm-90ebc98e3da2024c5a7979cf61dae3ec6c1df550.zip
clang-format: [JS] Format embedded function literals more efficently.
Before: return { a: a, link: function() { f(); // }, link: function() { f(); // } }; After: return { a: a, link: function() { f(); // }, link: function() { f(); // } }; llvm-svn: 217238
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp3
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp14
2 files changed, 8 insertions, 9 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 828e7507626..afd20b22e3a 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -643,7 +643,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
State.Stack[State.Stack.size() - 2].JSFunctionInlined = false;
}
if (Current.TokenText == "function")
- State.Stack.back().JSFunctionInlined = !Newline;
+ State.Stack.back().JSFunctionInlined =
+ !Newline && Previous && Previous->Type != TT_DictLiteral;
}
moveStatePastFakeLParens(State, Newline);
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index bd931aaf0a3..b161699d943 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -110,14 +110,12 @@ TEST_F(FormatTestJS, ContainerLiterals) {
"};");
verifyFormat("return {\n"
" a: a,\n"
- " link:\n"
- " function() {\n"
- " f(); //\n"
- " },\n"
- " link:\n"
- " function() {\n"
- " f(); //\n"
- " }\n"
+ " link: function() {\n"
+ " f(); //\n"
+ " },\n"
+ " link: function() {\n"
+ " f(); //\n"
+ " }\n"
"};");
verifyFormat("var stuff = {\n"
" // comment for update\n"
OpenPOWER on IntegriCloud