[PATCH] D30874: clang-format: [JS] do not wrap after interface and type.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 12 10:59:35 PDT 2017
mprobst created this revision.
Herald added a subscriber: klimek.
`interface` and `type` are pseudo keywords and cause automatic semicolon
insertion when followed by a line break:
interface // gets parsed as a long variable access to "interface"
VeryLongInterfaceName {
}
With this change, clang-format not longer wraps after `interface` or `type`.
https://reviews.llvm.org/D30874
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1221,6 +1221,20 @@
"class C {}");
}
+TEST_F(FormatTestJS, TypeInterfaceLineWrapping) {
+ const FormatStyle &Style = getGoogleJSStyleWithColumns(20);
+ verifyFormat("type LongTypeIsReallyUnreasonablyLong =\n"
+ " string;\n",
+ "type LongTypeIsReallyUnreasonablyLong = string;\n",
+ Style);
+ verifyFormat(
+ "interface AbstractStrategyFactoryProvider {\n"
+ " a: number\n"
+ "}\n",
+ "interface AbstractStrategyFactoryProvider { a: number }\n",
+ Style);
+}
+
TEST_F(FormatTestJS, Modules) {
verifyFormat("import SomeThing from 'some/module.js';");
verifyFormat("import {X, Y} from 'some/module.js';");
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2509,11 +2509,10 @@
return true;
} else if (Style.Language == FormatStyle::LK_JavaScript) {
const FormatToken *NonComment = Right.getPreviousNonComment();
- if (Left.isOneOf(tok::kw_return, tok::kw_continue, tok::kw_break,
- tok::kw_throw) ||
- (NonComment &&
- NonComment->isOneOf(tok::kw_return, tok::kw_continue, tok::kw_break,
- tok::kw_throw)))
+ if (NonComment &&
+ NonComment->isOneOf(tok::kw_return, tok::kw_continue, tok::kw_break,
+ tok::kw_throw, Keywords.kw_interface,
+ Keywords.kw_type))
return false; // Otherwise a semicolon is inserted.
if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30874.91500.patch
Type: text/x-patch
Size: 1854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170312/e283d9f5/attachment.bin>
More information about the cfe-commits
mailing list