r234091 - clang-format: [JS] Understand object literals with only methods.
Daniel Jasper
djasper at google.com
Sat Apr 4 00:56:55 PDT 2015
Author: djasper
Date: Sat Apr 4 02:56:55 2015
New Revision: 234091
URL: http://llvm.org/viewvc/llvm-project?rev=234091&view=rev
Log:
clang-format: [JS] Understand object literals with only methods.
Before:
let theObject = {someMethodName() {
doTheThing();
doTheOtherThing();
},
someOtherMethodName() {
doSomething();
doSomethingElse();
}};
After:
let theObject = {
someMethodName() {
doTheThing();
doTheOtherThing();
},
someOtherMethodName() {
doSomething();
doSomethingElse();
}
};
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=234091&r1=234090&r2=234091&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Apr 4 02:56:55 2015
@@ -342,7 +342,8 @@ private:
Style.Language == FormatStyle::LK_Proto) &&
Previous->is(tok::identifier))
Previous->Type = TT_SelectorName;
- if (CurrentToken->is(tok::colon))
+ if (CurrentToken->is(tok::colon) ||
+ Style.Language == FormatStyle::LK_JavaScript)
Left->Type = TT_DictLiteral;
}
if (!consumeToken())
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=234091&r1=234090&r2=234091&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Sat Apr 4 02:56:55 2015
@@ -163,6 +163,14 @@ TEST_F(FormatTestJS, MethodsInObjectLite
" doSomething(this.value + val);\n"
" }\n"
"};");
+ verifyFormat("var o = {\n"
+ " someMethod(val) { // method\n"
+ " doSomething(this.value + val);\n"
+ " },\n"
+ " someOtherMethod(val) { // method\n"
+ " doSomething(this.value + val);\n"
+ " }\n"
+ "};");
}
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
More information about the cfe-commits
mailing list