summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2019-08-26 15:37:05 +0000
committerMartin Probst <martin@probst.io>2019-08-26 15:37:05 +0000
commit5836472ac48884432ca9af3fd279a3b203ec98e4 (patch)
tree8af288dcabb6cb94cf0fbe574ca225e9769ca930 /clang/lib/Format/TokenAnnotator.cpp
parent0cd4ab91abee8e5de876514dcc4479aadfe4417d (diff)
downloadbcm5719-llvm-5836472ac48884432ca9af3fd279a3b203ec98e4.tar.gz
bcm5719-llvm-5836472ac48884432ca9af3fd279a3b203ec98e4.zip
clang-format: [JS] handle `as const`.
Summary: TypeScript 3.4 supports casting into a const type using `as const`: const x = {x: 1} as const; Previously, clang-format would insert a space after the `const`. With this patch, no space is inserted after the sequence `as const`. Reviewers: krasimir Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66736 llvm-svn: 369916
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c391c489dc2..5be398565c9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2746,6 +2746,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
tok::kw_void))
return true;
}
+ // `foo as const;` casts into a const type.
+ if (Left.endsSequence(tok::kw_const, Keywords.kw_as)) {
+ return false;
+ }
if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
tok::kw_const) ||
// "of" is only a keyword if it appears after another identifier
OpenPOWER on IntegriCloud