diff options
author | Martin Probst <martin@probst.io> | 2019-11-07 23:39:03 +0100 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2019-11-11 16:35:35 +0100 |
commit | a7638d384983e8e3eb44a2d8c757238efc7096dc (patch) | |
tree | 53214762176bda8ffaded6b59b65b643aaa1dbc3 /clang/unittests/Format/FormatTestJS.cpp | |
parent | 48b7068beca9d3a39dcfbebcb384b59b7898065f (diff) | |
download | bcm5719-llvm-a7638d384983e8e3eb44a2d8c757238efc7096dc.tar.gz bcm5719-llvm-a7638d384983e8e3eb44a2d8c757238efc7096dc.zip |
clang-format: [JS] support null operators.
Summary:
JavaScript / TypeScript is adding two new operators: the null
propagating operator `?.` and the nullish coalescing operator `??`.
const x = foo ?? 'default';
const z = foo?.bar?.baz;
This change adds support to lex and format both.
Reviewers: krasimir
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69971
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index ca2093a05cc..30a0b37ef69 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2222,6 +2222,16 @@ TEST_F(FormatTestJS, NonNullAssertionOperator) { verifyFormat("return !!x;\n"); } +TEST_F(FormatTestJS, NullPropagatingOperator) { + verifyFormat("let x = foo?.bar?.baz();\n"); + verifyFormat("let x = foo?.(foo);\n"); + verifyFormat("let x = foo?.['arr'];\n"); +} + +TEST_F(FormatTestJS, NullishCoalescingOperator) { + verifyFormat("const val = something ?? 'some other default';\n"); +} + TEST_F(FormatTestJS, Conditional) { verifyFormat("y = x ? 1 : 2;"); verifyFormat("x ? 1 : 2;"); |