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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369916
91177308-0d34-0410-b5e6-
96231b3b80d8
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
" .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
verifyFormat("const xIsALongIdent:\n"" YJustBarelyFitsLinex[];",
getGoogleJSStyleWithColumns(20));
+ verifyFormat("const x = {\n"
+ " y: 1\n"
+ "} as const;");
}
TEST_F(FormatTestJS, UnionIntersectionTypes) {