summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2016-09-18 17:21:52 +0000
committerMartin Probst <martin@probst.io>2016-09-18 17:21:52 +0000
commitb9316ff84979e53260c1c3bcbfa0359a891ad1a9 (patch)
tree049f355dfda8add7ec28ec57a603fea2e8c6d778
parent3f307518f8bea834e7ba0fb522e990063d09cfb3 (diff)
downloadbcm5719-llvm-b9316ff84979e53260c1c3bcbfa0359a891ad1a9.tar.gz
bcm5719-llvm-b9316ff84979e53260c1c3bcbfa0359a891ad1a9.zip
clang-format: [JS] ASI insertion after boolean literals.
Summary: Before when a semicolon was missing after a boolean literal: a = true return 1; clang-format would parse this as one line and format as: a = true return 1; It turns out that C++ does not consider `true` and `false` to be literals, we have to check for that explicitly. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24574 llvm-svn: 281856
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp4
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp12
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 94dccc6e02b..76dc4131c0d 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -681,7 +681,9 @@ static bool mustBeJSIdent(const AdditionalKeywords &Keywords,
static bool mustBeJSIdentOrValue(const AdditionalKeywords &Keywords,
const FormatToken *FormatTok) {
- return FormatTok->Tok.isLiteral() || mustBeJSIdent(Keywords, FormatTok);
+ return FormatTok->Tok.isLiteral() ||
+ FormatTok->isOneOf(tok::kw_true, tok::kw_false) ||
+ mustBeJSIdent(Keywords, FormatTok);
}
// isJSDeclOrStmt returns true if |FormatTok| starts a declaration or statement
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 9ccb75b6296..dd95462daf4 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -774,6 +774,18 @@ TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
"String");
verifyFormat("function f(@Foo bar) {}", "function f(@Foo\n"
" bar) {}");
+ verifyFormat("a = true\n"
+ "return 1",
+ "a = true\n"
+ " return 1");
+ verifyFormat("a = 's'\n"
+ "return 1",
+ "a = 's'\n"
+ " return 1");
+ verifyFormat("a = null\n"
+ "return 1",
+ "a = null\n"
+ " return 1");
}
TEST_F(FormatTestJS, ClosureStyleCasts) {
OpenPOWER on IntegriCloud