diff options
author | Martin Probst <martin@probst.io> | 2017-11-25 09:33:47 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-11-25 09:33:47 +0000 |
commit | 1526085fa22713a6bde359b913abf74731a8fcdb (patch) | |
tree | 15c8088e78fb738c49520ae06f4279269bf783d3 /unittests | |
parent | 525eeeae5f1af0017fdafe109cfde6d49ab0c4b2 (diff) |
clang-format: [JS] handle semis in generic types.
Summary:
TypeScript generic type arguments can contain object (literal) types,
which in turn can contain semicolons:
const x: Array<{a: number; b: string;} = [];
Previously, clang-format would incorrectly categorize the braced list as
a block and terminate the line at the openening `{`, and then format the
entire expression badly.
With this change, clang-format recognizes `<` preceding a `{` as
introducing a type expression. In JS, `<` comparison with an object
literal can never be true, so the chance of introducing false positives
here is very low.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D40424
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318975 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/FormatTestJS.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index cfdd4b375b..187b50221d 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1414,6 +1414,7 @@ TEST_F(FormatTestJS, TypeAnnotations) { verifyFormat("function x(y: {a?: number;} = {}): number {\n" " return 12;\n" "}"); + verifyFormat("const x: Array<{a: number; b: string;}> = [];"); verifyFormat("((a: string, b: number): string => a + b);"); verifyFormat("var x: (y: number) => string;"); verifyFormat("var x: P<string, (a: number) => string>;"); |