diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 12 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 1eca6cf79cf..eb74fc8f1d7 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1358,10 +1358,14 @@ private: Tok.Tok.getLength()); // For formatting, treat unterminated string literals like normal string // literals. - if (Tok.is(tok::unknown) && !Tok.TokenText.empty() && - Tok.TokenText[0] == '"') { - Tok.Tok.setKind(tok::string_literal); - Tok.IsUnterminatedLiteral = true; + if (Tok.is(tok::unknown)) { + if (!Tok.TokenText.empty() && Tok.TokenText[0] == '"') { + Tok.Tok.setKind(tok::string_literal); + Tok.IsUnterminatedLiteral = true; + } else if (Style.Language == FormatStyle::LK_JavaScript && + Tok.TokenText == "''") { + Tok.Tok.setKind(tok::char_constant); + } } } }; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 08969ff8e07..8a9ac9e20b8 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -84,5 +84,9 @@ TEST_F(FormatTestJS, SpacesInContainerLiterals) { verifyFormat("var obj = {a: 1, b: 2, c: 3};"); } +TEST_F(FormatTestJS, SingleQuoteStrings) { + verifyFormat("this.function('', true);"); +} + } // end namespace tooling } // end namespace clang |

