[PATCH] clang-format: [JS] Fix function formatting
Adam Strzelecki
ono at java.pl
Thu Jun 26 05:09:55 PDT 2014
Assume it is regular function declaration if previous token for function keyword is right brace, semicolon or none.
http://reviews.llvm.org/D4190
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -906,6 +906,15 @@
}
void UnwrappedLineParser::tryToParseJSFunction() {
+ // If it is regular function declaration parse as regular function.
+ // FIXME: This is a dirty way to access the previous token. Find a better
+ // solution.
+ if (Line->Tokens.empty() ||
+ Line->Tokens.back().Tok->isOneOf(tok::r_brace, tok::semi)) {
+ nextToken();
+ return;
+ }
+
nextToken();
// Consume function name.
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.10883.patch
Type: text/x-patch
Size: 1276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140626/5ed4463f/attachment.bin>
More information about the cfe-commits
mailing list