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) {
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) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits