[PATCH] D19240: clang-format: [JS] support `interface` as a free standing identifier.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 19 11:24:37 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266789: clang-format: [JS] support `interface` as a free standing identifier. (authored by mprobst).
Changed prior to commit:
http://reviews.llvm.org/D19240?vs=54218&id=54232#toc
Repository:
rL LLVM
http://reviews.llvm.org/D19240
Files:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1007,6 +1007,21 @@
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;
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -136,6 +136,9 @@
"};");
verifyFormat("var struct = 2;");
verifyFormat("var union = 2;");
+ verifyFormat("var interface = 2;");
+ verifyFormat("interface = 2;");
+ verifyFormat("x = interface instanceof y;");
}
TEST_F(FormatTestJS, CppKeywords) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19240.54232.patch
Type: text/x-patch
Size: 1737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160419/3c50c893/attachment.bin>
More information about the cfe-commits
mailing list