// Parse function literal unless 'function' is the first token in a line
// in which case this should be treated as a free-standing function.
if (Style.Language == FormatStyle::LK_JavaScript &&
- FormatTok->isOneOf(Keywords.kw_async, Keywords.kw_function) &&
+ (FormatTok->is(Keywords.kw_function) ||
+ FormatTok->startsSequence(Keywords.kw_async,
+ Keywords.kw_function)) &&
Line->Tokens.size() > 0) {
tryToParseJSFunction();
break;
}
void UnwrappedLineParser::tryToParseJSFunction() {
- assert(FormatTok->isOneOf(Keywords.kw_async, Keywords.kw_function));
+ assert(FormatTok->is(Keywords.kw_function) ||
+ FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function));
if (FormatTok->is(Keywords.kw_async))
nextToken();
// Consume "function".
// replace this by using parseAssigmentExpression() inside.
do {
if (Style.Language == FormatStyle::LK_JavaScript) {
- if (FormatTok->isOneOf(Keywords.kw_async, Keywords.kw_function)) {
+ if (FormatTok->is(Keywords.kw_function) ||
+ FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function)) {
tryToParseJSFunction();
continue;
}
break;
case tok::identifier:
if (Style.Language == FormatStyle::LK_JavaScript &&
- FormatTok->isOneOf(Keywords.kw_async, Keywords.kw_function))
+ (FormatTok->is(Keywords.kw_function) ||
+ FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function)))
tryToParseJSFunction();
else
nextToken();
verifyFormat("class X {\n"
" async asyncMethod() { return fetch(1); }\n"
"}");
+ verifyFormat("function initialize() {\n"
+ " // Comment.\n"
+ " return async.then();\n"
+ "}\n");
}
TEST_F(FormatTestJS, ArrayLiterals) {