[PATCH] clang-format: [JS] Fix function formatting
Adam Strzelecki
ono at java.pl
Wed Jun 18 11:57:04 PDT 2014
Added tests.
http://reviews.llvm.org/D4190
Files:
lib/Format/UnwrappedLineParser.cpp
lib/Format/UnwrappedLineParser.h
unittests/Format/FormatTestJS.cpp
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -905,11 +905,11 @@
return false;
}
-void UnwrappedLineParser::tryToParseJSFunction() {
+void UnwrappedLineParser::tryToParseJSFunction(bool BracedList) {
nextToken();
- // Consume function name.
- if (FormatTok->is(tok::identifier))
+ // Consume function name if in braced list.
+ if (BracedList && FormatTok->is(tok::identifier))
nextToken();
if (FormatTok->isNot(tok::l_paren))
@@ -945,7 +945,7 @@
do {
if (Style.Language == FormatStyle::LK_JavaScript &&
FormatTok->TokenText == "function") {
- tryToParseJSFunction();
+ tryToParseJSFunction(true);
continue;
}
switch (FormatTok->Tok.getKind()) {
Index: lib/Format/UnwrappedLineParser.h
===================================================================
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -101,7 +101,7 @@
void parseObjCProtocol();
bool tryToParseLambda();
bool tryToParseLambdaIntroducer();
- void tryToParseJSFunction();
+ void tryToParseJSFunction(bool BracedList = false);
void addUnwrappedLine();
bool eof() const;
void nextToken();
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -184,6 +184,14 @@
" return 1;\n"
" }\n"
"};");
+ verifyFormat("function outer1(a, b) {\n"
+ " function inner1(a, b) { return a; }\n"
+ " inner1(a, b);\n"
+ "}\n"
+ "function outer2(a, b) {\n"
+ " function inner2(a, b) { return a; }\n"
+ " inner2(a, b);\n"
+ "}");
}
TEST_F(FormatTestJS, MultipleFunctionLiterals) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4190.10584.patch
Type: text/x-patch
Size: 1977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140618/8ec0ebac/attachment.bin>
More information about the cfe-commits
mailing list