diff options
| author | Martin Probst <martin@probst.io> | 2017-08-01 15:54:43 +0000 |
|---|---|---|
| committer | Martin Probst <martin@probst.io> | 2017-08-01 15:54:43 +0000 |
| commit | 4bf1d7ad81df8795c0323d258147b18affee3301 (patch) | |
| tree | 9d9f29168943c1796e09932d67b0e2c1e98e83b2 | |
| parent | 02d5870de33da24382d53def9914737a496e1948 (diff) | |
| download | bcm5719-llvm-4bf1d7ad81df8795c0323d258147b18affee3301.tar.gz bcm5719-llvm-4bf1d7ad81df8795c0323d258147b18affee3301.zip | |
clang-format: [JS] support default imports.
Summary: Formerly, `import {default as X} from y;` would not be recognized as an import.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D36132
llvm-svn: 309697
| -rw-r--r-- | clang/lib/Format/SortJavaScriptImports.cpp | 4 | ||||
| -rw-r--r-- | clang/unittests/Format/SortImportsTestJS.cpp | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index e73695ca847..e08f4c3eec3 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/clang/lib/Format/SortJavaScriptImports.cpp @@ -413,7 +413,7 @@ private: nextToken(); if (Current->is(tok::r_brace)) break; - if (Current->isNot(tok::identifier)) + if (!Current->isOneOf(tok::identifier, tok::kw_default)) return false; JsImportedSymbol Symbol; @@ -425,7 +425,7 @@ private: if (Current->is(Keywords.kw_as)) { nextToken(); - if (Current->isNot(tok::identifier)) + if (!Current->isOneOf(tok::identifier, tok::kw_default)) return false; Symbol.Alias = Current->TokenText; nextToken(); diff --git a/clang/unittests/Format/SortImportsTestJS.cpp b/clang/unittests/Format/SortImportsTestJS.cpp index 4208b29702d..91be0313cf8 100644 --- a/clang/unittests/Format/SortImportsTestJS.cpp +++ b/clang/unittests/Format/SortImportsTestJS.cpp @@ -300,6 +300,14 @@ TEST_F(SortImportsTestJS, SortMultiLine) { "1;"); } +TEST_F(SortImportsTestJS, SortDefaultImports) { + // Reproduces issue where multi-line import was not parsed correctly. + verifySort("import {A} from 'a';\n" + "import {default as B} from 'b';\n", + "import {default as B} from 'b';\n" + "import {A} from 'a';\n"); +} + } // end namespace } // end namespace format } // end namespace clang |

