diff options
author | Martin Probst <martin@probst.io> | 2016-09-19 07:02:34 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2016-09-19 07:02:34 +0000 |
commit | 63014581aad3a4ac37d2f53674a46dcae5b34f09 (patch) | |
tree | 3e7166b4207b6850bd8e57d108203bc90a48f657 /clang/lib/Format/SortJavaScriptImports.cpp | |
parent | cd2bfb1e7ca4148ab1e7526aa96ab96773f695ea (diff) | |
download | bcm5719-llvm-63014581aad3a4ac37d2f53674a46dcae5b34f09.tar.gz bcm5719-llvm-63014581aad3a4ac37d2f53674a46dcae5b34f09.zip |
clang-format: [JS] Fix line breaks before comments when sorting imports.
Summary:
Previously, clang-format would always insert an additional line break after the
import block if the main body started with a comment, due to loosing track of
the first non-import line.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D24708
llvm-svn: 281888
Diffstat (limited to 'clang/lib/Format/SortJavaScriptImports.cpp')
-rw-r--r-- | clang/lib/Format/SortJavaScriptImports.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index 42089c522ec..93cda491402 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/clang/lib/Format/SortJavaScriptImports.cpp @@ -293,14 +293,19 @@ private: // of the import that immediately follows them by using the previously // set Start. Start = Line->First->Tok.getLocation(); - if (!Current) - continue; // Only comments on this line. + if (!Current) { + // Only comments on this line. Could be the first non-import line. + FirstNonImportLine = Line; + continue; + } JsModuleReference Reference; Reference.Range.setBegin(Start); if (!parseModuleReference(Keywords, Reference)) { - FirstNonImportLine = Line; + if (!FirstNonImportLine) + FirstNonImportLine = Line; // if no comment before. break; } + FirstNonImportLine = nullptr; AnyImportAffected = AnyImportAffected || Line->Affected; Reference.Range.setEnd(LineEnd->Tok.getEndLoc()); DEBUG({ |