[PATCH] clang-format: [js] support AtScript style annotations for JS.
Martin Probst
martinprobst at google.com
Wed Feb 18 08:58:23 PST 2015
Hi djasper,
Based on Java annotation support and style.
http://reviews.llvm.org/D7728
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -881,7 +881,9 @@
// Line.MightBeFunctionDecl can only be true after the parentheses of a
// function declaration have been found.
Current.Type = TT_TrailingAnnotation;
- } else if (Style.Language == FormatStyle::LK_Java && Current.Previous) {
+ } else if ((Style.Language == FormatStyle::LK_Java ||
+ Style.Language == FormatStyle::LK_JavaScript) &&
+ Current.Previous) {
if (Current.Previous->is(tok::at) &&
Current.isNot(Keywords.kw_interface)) {
const FormatToken &AtToken = *Current.Previous;
@@ -1920,6 +1922,10 @@
if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace) &&
Left.NestingLevel == 0)
return true;
+ if (Left.is(TT_LeadingJavaAnnotation) &&
+ Right.isNot(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) &&
+ Line.Last->is(tok::l_brace))
+ return true;
} else if (Style.Language == FormatStyle::LK_Java) {
if (Left.is(TT_LeadingJavaAnnotation) &&
Right.isNot(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) &&
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -510,5 +510,13 @@
verifyFormat("class C extends P implements I {}");
}
+TEST_F(FormatTestJS, MetadataAnnotations) {
+ verifyFormat("@A\nclass C {\n}");
+ verifyFormat("@A({arg: 'value'})\nclass C {\n}");
+ verifyFormat("@A\n at B\nclass C {\n}");
+ verifyFormat("class C {\n @A x: string;\n}");
+ verifyFormat("class C {\n @A\n private x(): string {\n return 'y';\n }\n}");
+}
+
} // end namespace tooling
} // end namespace clang
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7728.20192.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150218/bc364cb6/attachment.bin>
More information about the cfe-commits
mailing list