mprobst updated this revision to Diff 109089. mprobst added a comment. - support switch, case, delete.
https://reviews.llvm.org/D36142 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestJS.cpp Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -232,6 +232,9 @@ verifyFormat("x.var() = 1;"); verifyFormat("x.for() = 1;"); verifyFormat("x.as() = 1;"); + verifyFormat("x.instanceof() = 1;"); + verifyFormat("x.switch() = 1;"); + verifyFormat("x.case() = 1;"); verifyFormat("x = {\n" " a: 12,\n" " interface: 1,\n" Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2347,6 +2347,13 @@ if (Right.is(tok::l_paren) && Line.MustBeDeclaration && Left.Tok.getIdentifierInfo()) return false; + // Valid JS method names can include keywords, e.g. `foo.delete()` or + // `bar.instanceof()`. + if (Right.is(tok::l_paren) && Left.Previous && + Left.Previous->is(tok::period) && + (Left.Tok.getIdentifierInfo() || + Left.isOneOf(tok::kw_switch, tok::kw_case, tok::kw_delete))) + 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
Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -232,6 +232,9 @@ verifyFormat("x.var() = 1;"); verifyFormat("x.for() = 1;"); verifyFormat("x.as() = 1;"); + verifyFormat("x.instanceof() = 1;"); + verifyFormat("x.switch() = 1;"); + verifyFormat("x.case() = 1;"); verifyFormat("x = {\n" " a: 12,\n" " interface: 1,\n" Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2347,6 +2347,13 @@ if (Right.is(tok::l_paren) && Line.MustBeDeclaration && Left.Tok.getIdentifierInfo()) return false; + // Valid JS method names can include keywords, e.g. `foo.delete()` or + // `bar.instanceof()`. + if (Right.is(tok::l_paren) && Left.Previous && + Left.Previous->is(tok::period) && + (Left.Tok.getIdentifierInfo() || + Left.isOneOf(tok::kw_switch, tok::kw_case, tok::kw_delete))) + 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits