diff options
| author | Daniel Jasper <djasper@google.com> | 2014-09-30 17:57:06 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-09-30 17:57:06 +0000 |
| commit | 67f8ad258faa2c619fc8b2ef3e891ebe9f5ee6d5 (patch) | |
| tree | 4a849f183049d55755048f54ea51202e2abd3de3 /clang/lib/Format | |
| parent | f2787a0dc0eeb57990ecba67b76b7d3557e13b0b (diff) | |
| download | bcm5719-llvm-67f8ad258faa2c619fc8b2ef3e891ebe9f5ee6d5.tar.gz bcm5719-llvm-67f8ad258faa2c619fc8b2ef3e891ebe9f5ee6d5.zip | |
clang-format: [JS] Support AllowShortFunctionsOnASingleLine.
Specifically, this also counts for stuff like (with style "inline"):
var x = function() {
return 1;
};
llvm-svn: 218689
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index e70bad9f3be..d07f68d0226 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -414,6 +414,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.BreakBeforeTernaryOperators = false; GoogleStyle.MaxEmptyLinesToKeep = 3; GoogleStyle.SpacesInContainerLiterals = false; + GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; } else if (Language == FormatStyle::LK_Proto) { GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; GoogleStyle.SpacesInContainerLiterals = false; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 68e16268dff..43721ef95c0 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1734,6 +1734,13 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, Style.Language == FormatStyle::LK_Proto) { // Don't enums onto single lines in protocol buffers. return true; + } else if (Style.Language == FormatStyle::LK_JavaScript && + Right.is(tok::r_brace) && Left.is(tok::l_brace) && + !Left.Children.empty()) { + // Support AllowShortFunctionsOnASingleLine for JavaScript. + return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None || + (Left.NestingLevel == 0 && Line.Level == 0 && + Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline); } else if (isAllmanBrace(Left) || isAllmanBrace(Right)) { return Style.BreakBeforeBraces == FormatStyle::BS_Allman || Style.BreakBeforeBraces == FormatStyle::BS_GNU; |

