[PATCH] D33857: Correctly Indent Nested JavaScript Literals.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 6 05:39:09 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304791: clang-format: [JS] Correctly Indent Nested JavaScript Literals. (authored by mprobst).
Changed prior to commit:
https://reviews.llvm.org/D33857?vs=101296&id=101547#toc
Repository:
rL LLVM
https://reviews.llvm.org/D33857
Files:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -1036,8 +1036,8 @@
State.Stack.back().NestedBlockIndent);
if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
if (Current.opensBlockOrBlockTypeList(Style)) {
- NewIndent = State.Stack.back().NestedBlockIndent + Style.IndentWidth;
- NewIndent = std::min(State.Column + 2, NewIndent);
+ NewIndent = Style.IndentWidth +
+ std::min(State.Column, State.Stack.back().NestedBlockIndent);
} else {
NewIndent = State.Stack.back().LastSpace + Style.ContinuationIndentWidth;
}
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1869,5 +1869,44 @@
verifyFormat("squared **= 2;");
}
+TEST_F(FormatTestJS, NestedLiterals) {
+ FormatStyle FourSpaces = getGoogleJSStyleWithColumns(15);
+ FourSpaces.IndentWidth = 4;
+ verifyFormat("var l = [\n"
+ " [\n"
+ " 1,\n"
+ " ],\n"
+ "];", FourSpaces);
+ verifyFormat("var l = [\n"
+ " {\n"
+ " 1: 1,\n"
+ " },\n"
+ "];", FourSpaces);
+ verifyFormat("someFunction(\n"
+ " p1,\n"
+ " [\n"
+ " 1,\n"
+ " ],\n"
+ ");", FourSpaces);
+ verifyFormat("someFunction(\n"
+ " p1,\n"
+ " {\n"
+ " 1: 1,\n"
+ " },\n"
+ ");", FourSpaces);
+ verifyFormat("var o = {\n"
+ " 1: 1,\n"
+ " 2: {\n"
+ " 3: 3,\n"
+ " },\n"
+ "};", FourSpaces);
+ verifyFormat("var o = {\n"
+ " 1: 1,\n"
+ " 2: [\n"
+ " 3,\n"
+ " ],\n"
+ "};", FourSpaces);
+}
+
} // end namespace tooling
} // end namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33857.101547.patch
Type: text/x-patch
Size: 2303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170606/89c0d7d5/attachment.bin>
More information about the cfe-commits
mailing list