summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp3
2 files changed, 7 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
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index b332f1bd975..ca2093a05cc 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1479,6 +1479,9 @@ TEST_F(FormatTestJS, TypeAnnotations) {
" .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
verifyFormat("const xIsALongIdent:\n"" YJustBarelyFitsLinex[];",
getGoogleJSStyleWithColumns(20));
+ verifyFormat("const x = {\n"
+ " y: 1\n"
+ "} as const;");
}
TEST_F(FormatTestJS, UnionIntersectionTypes) {
OpenPOWER on IntegriCloud