From: Martin Probst Date: Tue, 1 Aug 2017 15:54:43 +0000 (+0000) Subject: clang-format: [JS] support default imports. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e751234b0ab532101e4b73fa8bccf6aec0dd35a0;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309697 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/SortJavaScriptImports.cpp b/lib/Format/SortJavaScriptImports.cpp index e73695ca84..e08f4c3eec 100644 --- a/lib/Format/SortJavaScriptImports.cpp +++ b/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/unittests/Format/SortImportsTestJS.cpp b/unittests/Format/SortImportsTestJS.cpp index 4208b29702..91be0313cf 100644 --- a/unittests/Format/SortImportsTestJS.cpp +++ b/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