summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2018-09-27 06:48:13 +0000
committerMartin Probst <martin@probst.io>2018-09-27 06:48:13 +0000
commit3315aed44ad03f04a7ca2a53dec42ec2d8bc8001 (patch)
tree6924fdbdf905698e39d656dfb6ccfc308eaed020 /clang/lib
parent77708b2390879010fd866dad4eb8d361deaa15af (diff)
downloadbcm5719-llvm-3315aed44ad03f04a7ca2a53dec42ec2d8bc8001.tar.gz
bcm5719-llvm-3315aed44ad03f04a7ca2a53dec42ec2d8bc8001.zip
clang-format: [JS] conditional types.
Summary: This change adds some rudimentary support for conditional types. Specifically it avoids breaking before `extends` and `infer` keywords, which are subject to Automatic Semicolon Insertion, so breaking before them creates incorrect syntax. The actual formatting of the type expression is odd, but there is as of yet no clear idea on how to format these. See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#conditional-types. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52536 llvm-svn: 343179
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/FormatToken.h2
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp6
2 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index e3b31f92444..3733b888dd5 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -680,6 +680,7 @@ struct AdditionalKeywords {
kw_function = &IdentTable.get("function");
kw_get = &IdentTable.get("get");
kw_import = &IdentTable.get("import");
+ kw_infer = &IdentTable.get("infer");
kw_is = &IdentTable.get("is");
kw_let = &IdentTable.get("let");
kw_module = &IdentTable.get("module");
@@ -751,6 +752,7 @@ struct AdditionalKeywords {
IdentifierInfo *kw_function;
IdentifierInfo *kw_get;
IdentifierInfo *kw_import;
+ IdentifierInfo *kw_infer;
IdentifierInfo *kw_is;
IdentifierInfo *kw_let;
IdentifierInfo *kw_module;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 83c5b2e8b96..2cb4c0361b9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3088,6 +3088,12 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
return Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None;
if (Right.is(Keywords.kw_as))
return false; // must not break before as in 'x as type' casts
+ if (Right.isOneOf(Keywords.kw_extends, Keywords.kw_infer)) {
+ // extends and infer can appear as keywords in conditional types:
+ // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#conditional-types
+ // do not break before them, as the expressions are subject to ASI.
+ return false;
+ }
if (Left.is(Keywords.kw_as))
return true;
if (Left.is(TT_JsNonNullAssertion))
OpenPOWER on IntegriCloud