[PATCH] D146247: [clang-format] Support TypeScript satisfies operator
MyDeveloperDay added a comment. Can you add a github issue and reference it here Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:1445 + EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName); + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_Unknown); I'd like to personally see this become a TT_JsSatisfies Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146247/new/ https://reviews.llvm.org/D146247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D146247: [clang-format] Support TypeScript satisfies operator
MyDeveloperDay added a comment. 1. your diff is messed up 2. you have to get an accept before anyone will commit for you. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146247/new/ https://reviews.llvm.org/D146247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D146247: [clang-format] Support TypeScript satisfies operator
taymonbeal added a comment. I don't have commit access; can someone who does commit this? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146247/new/ https://reviews.llvm.org/D146247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D146247: [clang-format] Support TypeScript satisfies operator
taymonbeal updated this revision to Diff 506153. taymonbeal added a comment. Add release notes and unit test in TokenAnnotatorTest.cpp Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146247/new/ https://reviews.llvm.org/D146247 Files: clang/docs/ReleaseNotes.rst clang/unittests/Format/TokenAnnotatorTest.cpp Index: clang/unittests/Format/TokenAnnotatorTest.cpp === --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1434,6 +1434,20 @@ EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace); } +TEST_F(TokenAnnotatorTest, UnderstandsTypeScriptSatisfiesOperator) { + auto Tokens = annotate("let x = foo satisfies Type;", + getGoogleStyle(FormatStyle::LK_JavaScript)); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName); + EXPECT_TOKEN(Tokens[2], tok::equal, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName); + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[6], tok::semi, TT_Unknown); + EXPECT_TOKEN(Tokens[7], tok::eof, TT_Unknown); +} + } // namespace } // namespace format } // namespace clang Index: clang/docs/ReleaseNotes.rst === --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -326,6 +326,7 @@ Compared to ``NextLine`` style, ``NextLineOnly`` style will not try to put the initializers on the current line first, instead, it will try to put the initializers on the next line only. +- Add support for the ``satisfies`` operator introduced in TypeScript 4.9. libclang Index: clang/unittests/Format/TokenAnnotatorTest.cpp === --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1434,6 +1434,20 @@ EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace); } +TEST_F(TokenAnnotatorTest, UnderstandsTypeScriptSatisfiesOperator) { + auto Tokens = annotate("let x = foo satisfies Type;", + getGoogleStyle(FormatStyle::LK_JavaScript)); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName); + EXPECT_TOKEN(Tokens[2], tok::equal, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName); + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[6], tok::semi, TT_Unknown); + EXPECT_TOKEN(Tokens[7], tok::eof, TT_Unknown); +} + } // namespace } // namespace format } // namespace clang Index: clang/docs/ReleaseNotes.rst === --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -326,6 +326,7 @@ Compared to ``NextLine`` style, ``NextLineOnly`` style will not try to put the initializers on the current line first, instead, it will try to put the initializers on the next line only. +- Add support for the ``satisfies`` operator introduced in TypeScript 4.9. libclang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D146247: [clang-format] Support TypeScript satisfies operator
MyDeveloperDay added a comment. I would like to see an annotator test just to be sure its getting annotated correctly. apart from that it looks pretty good, would you add this to the release notes please? Comment at: clang/unittests/Format/FormatTestJS.cpp:2186 +TEST_F(FormatTestJS, SatisfiesSyntax) { + verifyFormat("let x = foo satisfies Type;"); + verifyFormat("let x = (a + b) satisfies\n" would you take say this example and add it as an annotator test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146247/new/ https://reviews.llvm.org/D146247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D146247: [clang-format] Support TypeScript satisfies operator
taymonbeal created this revision. taymonbeal added reviewers: MyDeveloperDay, owenpan. Herald added a project: All. taymonbeal requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. The satisfies operator was added in TypeScript 4.9. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D146247 Files: clang/lib/Format/FormatToken.h clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestJS.cpp Index: clang/unittests/Format/FormatTestJS.cpp === --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -2182,6 +2182,21 @@ getGoogleJSStyleWithColumns(40)); } +TEST_F(FormatTestJS, SatisfiesSyntax) { + verifyFormat("let x = foo satisfies Type;"); + verifyFormat("let x = (a + b) satisfies\n" + "LongTypeIsLong;", + getGoogleJSStyleWithColumns(30)); + verifyFormat("let x = [{x: 1} satisfies Type];"); + verifyFormat("x = x satisfies [A, B];"); + verifyFormat("x = x satisfies {a: string};"); + verifyFormat("x = x satisfies (string);"); + verifyFormat("x = x! satisfies (string);"); + verifyFormat("let x = something.someFunction() satisfies\n" + "LongTypeIsLong;", + getGoogleJSStyleWithColumns(50)); +} + TEST_F(FormatTestJS, TypeArguments) { verifyFormat("class X {}"); verifyFormat("new X();"); Index: clang/lib/Format/UnwrappedLineParser.cpp === --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -556,10 +556,11 @@ // must also be part of it. ProbablyBracedList = LBraceStack.back()->is(TT_BracedListLBrace); - ProbablyBracedList = ProbablyBracedList || + ProbablyBracedList = + ProbablyBracedList || (Style.isJavaScript() && -NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, - Keywords.kw_as)); + NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, Keywords.kw_as, +Keywords.kw_satisfies)); ProbablyBracedList = ProbablyBracedList || (Style.isCpp() && NextTok->is(tok::l_paren)); @@ -1213,7 +1214,8 @@ Keywords.kw_let, Keywords.kw_var, tok::kw_const, Keywords.kw_abstract, Keywords.kw_extends, Keywords.kw_implements, Keywords.kw_instanceof, Keywords.kw_interface, - Keywords.kw_override, Keywords.kw_throws, Keywords.kw_from)); + Keywords.kw_override, Keywords.kw_satisfies, Keywords.kw_throws, + Keywords.kw_from)); } static bool mustBeJSIdentOrValue(const AdditionalKeywords , Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1882,7 +1882,8 @@ } } if (Current.Next && - Current.Next->isOneOf(TT_BinaryOperator, Keywords.kw_as)) { + Current.Next->isOneOf(TT_BinaryOperator, Keywords.kw_as, +Keywords.kw_satisfies)) { Current.setType(TT_NonNullAssertion); return; } @@ -2074,7 +2075,7 @@ return false; if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof, - Keywords.kw_as)) { + Keywords.kw_as, Keywords.kw_satisfies)) { return false; } if (Style.isJavaScript() && Tok.Previous->is(Keywords.kw_in)) @@ -2725,7 +2726,8 @@ return prec::Relational; } if (Style.isJavaScript() && - Current->isOneOf(Keywords.kw_in, Keywords.kw_as)) { + Current->isOneOf(Keywords.kw_in, Keywords.kw_as, + Keywords.kw_satisfies)) { return prec::Relational; } if (Current->is(TT_BinaryOperator) || Current->is(tok::comma)) @@ -4268,11 +4270,12 @@ (!Left.Previous || !Left.Previous->is(tok::period))) { return true; } -if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous && -Left.Previous->is(tok::period) && Right.is(tok::l_paren)) { +if (Left.isOneOf(tok::kw_for, Keywords.kw_as, Keywords.kw_satisfies) && +Left.Previous && Left.Previous->is(tok::period) && +Right.is(tok::l_paren)) { return false; } -if (Left.is(Keywords.kw_as) && +if (Left.isOneOf(Keywords.kw_as, Keywords.kw_satisfies) && Right.isOneOf(tok::l_square, tok::l_brace, tok::l_paren)) { return true; } @@ -4303,8 +4306,8 @@ if (Right.is(TT_NonNullAssertion)) return false; if (Left.is(TT_NonNullAssertion)