diff options
| author | Daniel Jasper <djasper@google.com> | 2014-01-15 15:09:08 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-01-15 15:09:08 +0000 |
| commit | b2e10a545902dca0b565379889a0e1e8b34d0e9e (patch) | |
| tree | 75e37b6374a0ac5cf245ae06cedcafae307a3bbc /clang/lib/Format | |
| parent | 7d63392da96299a219c81529752946b691a6f59f (diff) | |
| download | bcm5719-llvm-b2e10a545902dca0b565379889a0e1e8b34d0e9e.tar.gz bcm5719-llvm-b2e10a545902dca0b565379889a0e1e8b34d0e9e.zip | |
clang-format: Fixed formatting of JavaScript container literals
Before:
var arr = [ 1, 2, 3 ];
var obj = {a : 1, b : 2, c : 3};
After:
var arr = [1, 2, 3];
var obj = {a: 1, b: 2, c: 3};
llvm-svn: 199317
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 9 |
2 files changed, 8 insertions, 8 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 43651e2c632..a69570a1571 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -190,6 +190,8 @@ template <> struct MappingTraits<FormatStyle> { IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses); IO.mapOptional("SpacesInCStyleCastParentheses", Style.SpacesInCStyleCastParentheses); + IO.mapOptional("SpacesInContainerLiterals", + Style.SpacesInContainerLiterals); IO.mapOptional("SpaceBeforeAssignmentOperators", Style.SpaceBeforeAssignmentOperators); IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth); @@ -271,6 +273,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.UseTab = FormatStyle::UT_Never; LLVMStyle.SpacesInParentheses = false; LLVMStyle.SpaceInEmptyParentheses = false; + LLVMStyle.SpacesInContainerLiterals = true; LLVMStyle.SpacesInCStyleCastParentheses = false; LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements; LLVMStyle.SpaceBeforeAssignmentOperators = true; @@ -316,9 +319,7 @@ FormatStyle getGoogleJSStyle() { FormatStyle GoogleJSStyle = getGoogleStyle(); GoogleJSStyle.Language = FormatStyle::LK_JavaScript; GoogleJSStyle.BreakBeforeTernaryOperators = false; - // FIXME: Currently unimplemented: - // var arr = [1, 2, 3]; // No space after [ or before ]. - // var obj = {a: 1, b: 2, c: 3}; // No space after ':'. + GoogleJSStyle.SpacesInContainerLiterals = false; return GoogleJSStyle; } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 1584a052415..be9eabeec7f 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1321,17 +1321,15 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return false; if (Left.is(tok::l_square)) return Left.Type == TT_ArrayInitializerLSquare && - Right.isNot(tok::r_square); + Style.SpacesInContainerLiterals && Right.isNot(tok::r_square); if (Right.is(tok::r_square)) - return Right.MatchingParen && + return Right.MatchingParen && Style.SpacesInContainerLiterals && Right.MatchingParen->Type == TT_ArrayInitializerLSquare; if (Right.is(tok::l_square) && Right.Type != TT_ObjCMethodExpr && Right.Type != TT_LambdaLSquare && Left.isNot(tok::numeric_constant)) return false; if (Left.is(tok::colon)) return Left.Type != TT_ObjCMethodExpr; - if (Right.is(tok::colon)) - return Right.Type != TT_ObjCMethodExpr && !Left.is(tok::question); if (Right.is(tok::l_paren)) { if (Left.is(tok::r_paren) && Left.MatchingParen && Left.MatchingParen->Previous && @@ -1404,7 +1402,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if (Tok.is(tok::colon)) return !Line.First->isOneOf(tok::kw_case, tok::kw_default) && Tok.getNextNonComment() != NULL && Tok.Type != TT_ObjCMethodExpr && - !Tok.Previous->is(tok::question); + !Tok.Previous->is(tok::question) && + (Tok.Type != TT_DictLiteral || Style.SpacesInContainerLiterals); if (Tok.Previous->Type == TT_UnaryOperator || Tok.Previous->Type == TT_CastRParen) return false; |

