diff options
author | Martin Probst <martin@probst.io> | 2017-08-04 17:07:15 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-08-04 17:07:15 +0000 |
commit | f785fd94c65c1268556ed89e2485a3673e343ae8 (patch) | |
tree | dc3a2d8a46a45b46f4dee90981bda5e05172d729 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | 4e22ee6745d12c935ee29cb1fbc99d753adf125f (diff) | |
download | bcm5719-llvm-f785fd94c65c1268556ed89e2485a3673e343ae8.tar.gz bcm5719-llvm-f785fd94c65c1268556ed89e2485a3673e343ae8.zip |
clang-format: [JS] support fields with case/switch/default labels.
Summary:
`case:` and `default:` would normally parse as labels for a `switch` block.
However in TypeScript, they can be used in field declarations, e.g.:
interface I {
case: string;
}
This change special cases parsing them in declaration lines to avoid wrapping
them.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D36148
llvm-svn: 310070
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 32853dc209e..e6afd1f9887 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -326,6 +326,11 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) { break; case tok::kw_default: case tok::kw_case: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) { + // A 'case: string' style field declaration. + parseStructuralElement(); + break; + } if (!SwitchLabelEncountered && (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 1))) ++Line->Level; @@ -953,13 +958,22 @@ void UnwrappedLineParser::parseStructuralElement() { parseDoWhile(); return; case tok::kw_switch: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // 'switch: string' field declaration. + break; parseSwitch(); return; case tok::kw_default: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // 'default: string' field declaration. + break; nextToken(); parseLabel(); return; case tok::kw_case: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // 'case: string' field declaration. + break; parseCaseLabel(); return; case tok::kw_try: |