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:
Daniel Jasper 2014-01-31 12:49:42 +00:00
parent e2dbedda76
commit 86fee2fa3d
2 changed files with 12 additions and 4 deletions

View File

@ -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);
}
}
}
};

View File

@ -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