summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2017-06-07 12:53:22 +0000
committerMartin Probst <martin@probst.io>2017-06-07 12:53:22 +0000
commitd96a052cb1f38338193bb6f66cf19e9aeeba3217 (patch)
tree649087185ab486a01257b0827a25a450bd2b95e5
parentab0ecc00b740a9204c403f6933dd0469d28166d0 (diff)
downloadbcm5719-llvm-d96a052cb1f38338193bb6f66cf19e9aeeba3217.tar.gz
bcm5719-llvm-d96a052cb1f38338193bb6f66cf19e9aeeba3217.zip
clang-format: [JS] recognize exported type definitions.
Summary: Support "export type T = {...};", in addition to just "type T = {...};". Reviewers: klimek Differential Revision: https://reviews.llvm.org/D33980 llvm-svn: 304904
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp12
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp6
2 files changed, 15 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 2af931cdf1b..7ce699cf14a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -135,8 +135,11 @@ private:
if (Left->is(TT_OverloadedOperatorLParen)) {
Contexts.back().IsExpression = false;
} else if (Style.Language == FormatStyle::LK_JavaScript &&
- Line.startsWith(Keywords.kw_type, tok::identifier)) {
+ (Line.startsWith(Keywords.kw_type, tok::identifier) ||
+ Line.startsWith(tok::kw_export, Keywords.kw_type,
+ tok::identifier))) {
// type X = (...);
+ // export type X = (...);
Contexts.back().IsExpression = false;
} else if (Left->Previous &&
(Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_decltype,
@@ -979,9 +982,12 @@ private:
void modifyContext(const FormatToken &Current) {
if (Current.getPrecedence() == prec::Assignment &&
!Line.First->isOneOf(tok::kw_template, tok::kw_using, tok::kw_return) &&
- // Type aliases use `type X = ...;` in TypeScript.
+ // Type aliases use `type X = ...;` in TypeScript and can be exported
+ // using `export type ...`.
!(Style.Language == FormatStyle::LK_JavaScript &&
- Line.startsWith(Keywords.kw_type, tok::identifier)) &&
+ (Line.startsWith(Keywords.kw_type, tok::identifier) ||
+ Line.startsWith(tok::kw_export, Keywords.kw_type,
+ tok::identifier))) &&
(!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
Contexts.back().IsExpression = true;
if (!Line.startsWith(TT_UnaryOperator)) {
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 14af1c92f4a..e84f470687e 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1226,6 +1226,12 @@ TEST_F(FormatTestJS, UnionIntersectionTypes) {
verifyFormat("let x: Bar|Baz;");
verifyFormat("let x: Bar<X>|Baz;");
verifyFormat("let x: (Foo|Bar)[];");
+ verifyFormat("type X = {\n"
+ " a: Foo|Bar;\n"
+ "};");
+ verifyFormat("export type X = {\n"
+ " a: Foo|Bar;\n"
+ "};");
}
TEST_F(FormatTestJS, ClassDeclarations) {
OpenPOWER on IntegriCloud