File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change 19
19
#include " clang/Basic/OperatorPrecedence.h"
20
20
#include " clang/Basic/SourceManager.h"
21
21
#include " clang/Format/Format.h"
22
+ #include " llvm/ADT/StringSet.h"
22
23
#include " llvm/Support/Debug.h"
23
24
24
25
#define DEBUG_TYPE " format-indenter"
@@ -492,8 +493,12 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
492
493
return true ;
493
494
}
494
495
495
- // Break after the closing parenthesis of TypeScript decorators.
496
+ // Break after the closing parenthesis of TypeScript decorators before
497
+ // functions, getters and setters.
498
+ static const llvm::StringSet<> BreakBeforeDecoratedTokens = {" get" , " set" ,
499
+ " function" };
496
500
if (Style.Language == FormatStyle::LK_JavaScript &&
501
+ BreakBeforeDecoratedTokens.contains (Current.TokenText ) &&
497
502
Previous.is (tok::r_paren) && Previous.is (TT_JavaAnnotation)) {
498
503
return true ;
499
504
}
Original file line number Diff line number Diff line change @@ -701,15 +701,37 @@ TEST_F(FormatTestJS, FormatsFreestandingFunctions) {
701
701
getGoogleJSStyleWithColumns (20 )));
702
702
}
703
703
704
- TEST_F (FormatTestJS, FormatsDecoratedFunctions) {
705
- // Regression test: ensure that there is a break before `get`.
704
+ TEST_F (FormatTestJS, FormatsDecorators) {
705
+ // No line break after argument decorators.
706
+ verifyFormat (" class A {\n "
707
+ " constructor(@arg(DECOR) private arg: Type) {}\n "
708
+ " }" );
709
+ // Ensure that there is a break before functions, getters and setters.
706
710
EXPECT_EQ (" class A {\n "
707
711
" private p = () => {}\n "
708
712
" \n "
709
713
" @decorated('a')\n "
710
714
" get f() {\n "
711
715
" return result;\n "
712
716
" }\n "
717
+ " }\n "
718
+ " \n "
719
+ " class B {\n "
720
+ " private p = () => {}\n "
721
+ " \n "
722
+ " @decorated('a')\n "
723
+ " set f() {\n "
724
+ " return result;\n "
725
+ " }\n "
726
+ " }\n "
727
+ " \n "
728
+ " class C {\n "
729
+ " private p = () => {}\n "
730
+ " \n "
731
+ " @decorated('a')\n "
732
+ " function f() {\n "
733
+ " return result;\n "
734
+ " }\n "
713
735
" }" ,
714
736
format (" class A {\n "
715
737
" private p = () => {}\n "
@@ -718,6 +740,24 @@ TEST_F(FormatTestJS, FormatsDecoratedFunctions) {
718
740
" get f() {\n "
719
741
" return result;\n "
720
742
" }\n "
743
+ " }\n "
744
+ " \n "
745
+ " class B {\n "
746
+ " private p = () => {}\n "
747
+ " \n "
748
+ " @decorated('a')\n "
749
+ " set f() {\n "
750
+ " return result;\n "
751
+ " }\n "
752
+ " }\n "
753
+ " \n "
754
+ " class C {\n "
755
+ " private p = () => {}\n "
756
+ " \n "
757
+ " @decorated('a')\n "
758
+ " function f() {\n "
759
+ " return result;\n "
760
+ " }\n "
721
761
" }" ,
722
762
getGoogleJSStyleWithColumns (50 )));
723
763
}
You can’t perform that action at this time.
0 commit comments