summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestJS.cpp
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2017-02-07 16:33:13 +0000
committerMartin Probst <martin@probst.io>2017-02-07 16:33:13 +0000
commit8e3eba037359409054c047c80b32e98ed150e55b (patch)
treed0b507d06efc6a0d2a8edf2f347291b044f93182 /clang/unittests/Format/FormatTestJS.cpp
parentf86708dbf57eba32d46a32b4d5e23ec6649d4a72 (diff)
downloadbcm5719-llvm-8e3eba037359409054c047c80b32e98ed150e55b.tar.gz
bcm5719-llvm-8e3eba037359409054c047c80b32e98ed150e55b.zip
clang-format: [JS] correcly format object literal methods.
Summary: In JavaScript, object literals can contain methods: var x = { a() { return 1; }, }; Previously, clang-format always parsed nested {} inside a braced list as further braced lists. Special case this logic for JavaScript to try parsing as a braced list, but fall back to parsing as a child block. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D29656 llvm-svn: 294315
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 61acce3a977..4038e512590 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -240,6 +240,18 @@ TEST_F(FormatTestJS, ContainerLiterals) {
"};");
verifyFormat("var x = {y: (a) => a};");
+ // Methods in object literals.
+ verifyFormat("var x = {\n"
+ " y(a: string): number {\n"
+ " return a;\n"
+ " }\n"
+ "};");
+ verifyFormat("var x = {\n"
+ " y(a: string) {\n"
+ " return a;\n"
+ " }\n"
+ "};");
+
// Computed keys.
verifyFormat("var x = {[a]: 1, b: 2, [c]: 3};");
verifyFormat("var x = {\n"
OpenPOWER on IntegriCloud