This revision was automatically updated to reflect the committed changes.
Closed by commit rL302580: clang-format: [JS] Don't indent JavaScript IIFEs.
(authored by mprobst).
Changed prior to commit:
https://reviews.llvm.org/D32989?vs=98332&id=98344#toc
Repository:
rL LLVM
https://reviews.ll
mprobst accepted this revision.
mprobst added inline comments.
This revision is now accepted and ready to land.
Comment at: unittests/Format/FormatTestJS.cpp:371
+TEST_F(FormatTestJS, IIFE) {
+ verifyFormat("(function() {\n"
+ "var a = 1;\n"
danbea
danbeam added inline comments.
Comment at: lib/Format/UnwrappedLineParser.cpp:2353
+ // expressions?
+ if (Line->Tokens.size() < 5)
+return false;
mprobst wrote:
> There's a `startsSequenceInternal` on `Line` that might come in handy here?
it wasn't on `Lin
danbeam updated this revision to Diff 98332.
danbeam marked 4 inline comments as done.
danbeam added a comment.
mprobst@ review
https://reviews.llvm.org/D32989
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
mprobst added inline comments.
Comment at: lib/Format/UnwrappedLineParser.cpp:2362
+ ++I;
+ if (I->Tok->isNot(tok::l_paren))
+return false;
One more - do we want to support IIFEs that take arguments?
```
(function(global) {
...
}(window));
```
https:/
mprobst added inline comments.
Comment at: lib/Format/UnwrappedLineParser.cpp:2346
+bool UnwrappedLineParser::isIIFE() const {
+ // Look for the start of an immediately invoked anonymous function.
Why not just a static function?
Comment at:
danbeam created this revision.
Herald added a subscriber: klimek.
Because IIFEs[1] are often used like an anonymous namespace around large
sections of JavaScript code, it's useful not to indent to them (which
effectively reduces the column limit by the indent amount needlessly).
It's also common