forked from OSchip/llvm-project
clang-format: (JavaScript) Don't crash on empty string literals.
Before, this would lead to a crash: f('', true); llvm-svn: 200540
This commit is contained in:
parent
e2dbedda76
commit
86fee2fa3d
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue