return false;
}
+void UnwrappedLineParser::tryToParseJSFunction() {
+ nextToken();
+ if (FormatTok->isNot(tok::l_paren))
+ return;
+ nextToken();
+ while (FormatTok->isNot(tok::l_brace)) {
+ // Err on the side of caution in order to avoid consuming the full file in
+ // case of incomplete code.
+ if (!FormatTok->isOneOf(tok::identifier, tok::comma, tok::r_paren,
+ tok::comment))
+ return;
+ nextToken();
+ }
+ parseChildBlock();
+}
+
bool UnwrappedLineParser::tryToParseBracedList() {
if (FormatTok->BlockKind == BK_Unknown)
calculateBraceTypes();
// FIXME: Once we have an expression parser in the UnwrappedLineParser,
// replace this by using parseAssigmentExpression() inside.
do {
- // FIXME: When we start to support lambdas, we'll want to parse them away
- // here, otherwise our bail-out scenarios below break. The better solution
- // might be to just implement a more or less complete expression parser.
+ if (Style.Language == FormatStyle::LK_JavaScript &&
+ FormatTok->TokenText == "function") {
+ tryToParseJSFunction();
+ continue;
+ }
switch (FormatTok->Tok.getKind()) {
case tok::caret:
nextToken();
TEST_F(FormatTestJS, Closures) {
verifyFormat("doFoo(function() { return 1; });");
verifyFormat("var func = function() { return 1; };");
+ verifyFormat("return {\n"
+ " body: {\n"
+ " setAttribute: function(key, val) { this[key] = val; },\n"
+ " getAttribute: function(key) { return this[key]; },\n"
+ " style: {direction: ''}\n"
+ " }\n"
+ "};");
}
TEST_F(FormatTestJS, ReturnStatements) {