diff options
| author | Martin Probst <martin@probst.io> | 2016-04-19 18:18:59 +0000 |
|---|---|---|
| committer | Martin Probst <martin@probst.io> | 2016-04-19 18:18:59 +0000 |
| commit | 1e8261ea0430ecc0bed0ace31e0ec724a5a69270 (patch) | |
| tree | 4d7c7087165130d2df79cab44fe91d82680d872c /clang/lib | |
| parent | 461f2ff4457f5d8270c86c164ee368b47b141b06 (diff) | |
| download | bcm5719-llvm-1e8261ea0430ecc0bed0ace31e0ec724a5a69270.tar.gz bcm5719-llvm-1e8261ea0430ecc0bed0ace31e0ec724a5a69270.zip | |
clang-format: [JS] support `interface` as a free standing identifier.
Summary:
`interface` can be used as a fee standing identifier in JavaScript/TypeScript.
This change uses the heuristic of whether it's followed by another identifier
as an indication.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D19240
llvm-svn: 266789
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 91856a74c35..6d2d2cb44c0 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1007,6 +1007,21 @@ void UnwrappedLineParser::parseStructuralElement() { if ((Style.Language == FormatStyle::LK_JavaScript || Style.Language == FormatStyle::LK_Java) && FormatTok->is(Keywords.kw_interface)) { + if (Style.Language == FormatStyle::LK_JavaScript) { + // In JavaScript/TypeScript, "interface" can be used as a standalone + // identifier, e.g. in `var interface = 1;`. If "interface" is + // followed by another identifier, it is very like to be an actual + // interface declaration. + unsigned StoredPosition = Tokens->getPosition(); + FormatToken *Next = Tokens->getNextToken(); + FormatTok = Tokens->setPosition(StoredPosition); + if (Next && (Next->isNot(tok::identifier) || + Next->isOneOf(Keywords.kw_instanceof, Keywords.kw_of, + Keywords.kw_in))) { + nextToken(); + break; + } + } parseRecord(); addUnwrappedLine(); return; |

