mprobst created this revision. Herald added a subscriber: klimek. Async arrow functions should be marked with a whitespace after the async keyword, before the parameter list:
x = async () => foo(); Before: x = async() => foo(); This makes it easier to tell apart an async arrow function from a call to a function called async. https://reviews.llvm.org/D30399 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestJS.cpp Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -463,6 +463,8 @@ verifyFormat("export async function f() {\n" " return fetch(x);\n" "}"); + verifyFormat("let x = async () => f();"); + verifyFormat("let x = async();"); verifyFormat("class X {\n" " async asyncMethod() {\n" " return fetch(1);\n" Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2225,6 +2225,12 @@ } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; + if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) && + Right.MatchingParen && Right.MatchingParen->getNextNonComment() && + Right.MatchingParen->getNextNonComment()->is(TT_JsFatArrow)) + // An async arrow function, for example: `x = async () => foo();`, + // as opposed to calling a function called async: `x = async();` + return true; if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) || (Right.is(TT_TemplateString) && Right.TokenText.startswith("}"))) return false;
Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -463,6 +463,8 @@ verifyFormat("export async function f() {\n" " return fetch(x);\n" "}"); + verifyFormat("let x = async () => f();"); + verifyFormat("let x = async();"); verifyFormat("class X {\n" " async asyncMethod() {\n" " return fetch(1);\n" Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2225,6 +2225,12 @@ } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; + if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) && + Right.MatchingParen && Right.MatchingParen->getNextNonComment() && + Right.MatchingParen->getNextNonComment()->is(TT_JsFatArrow)) + // An async arrow function, for example: `x = async () => foo();`, + // as opposed to calling a function called async: `x = async();` + return true; if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) || (Right.is(TT_TemplateString) && Right.TokenText.startswith("}"))) return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits