[PATCH] D19204: clang-format: [JS] generator and async functions.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 19 08:22:51 PDT 2016


mprobst marked an inline comment as done.

================
Comment at: unittests/Format/FormatTestJS.cpp:339
@@ +338,3 @@
+               "}");
+  verifyFormat("async function* f() {\n"
+               "  yield fetch(x);\n"
----------------
djasper wrote:
> What does the star mean here? Should we actually introduce a token type or do you think it's just going to work? Specifically, what happens if you need to line-wrap?
The star indicates that this is a function that returns a generator, i.e. implicitly returns an iterator in which you shove values with `yield`. I think you wouldn't want to wrap between `function` and `*`. We currently don't, but more by chance - it's a side effect of not breaking before a binary operator.

`function*` cannot be one token, there may be whitespace and comments in between. We could have a `generator star` token, but there are places where that'd be hard for us to detect, e.g. the class method above. Having a `generator star` only occasionally be recognized of course would be rather confusing.

So I'd punt on this for the time beimg. I've added a test to make sure we correctly wrap above. Does that make sense?


http://reviews.llvm.org/D19204





More information about the cfe-commits mailing list