bowenni created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. bowenni retitled this revision from "Fix a JavaScript import order bug." to "[clang-format] Fix a JavaScript import order bug.".
When the imported symbol is exactly "template" the sorting is disabled. Repository: rC Clang https://reviews.llvm.org/D61663 Files: clang/lib/Format/SortJavaScriptImports.cpp clang/unittests/Format/SortImportsTestJS.cpp Index: clang/unittests/Format/SortImportsTestJS.cpp =================================================================== --- clang/unittests/Format/SortImportsTestJS.cpp +++ clang/unittests/Format/SortImportsTestJS.cpp @@ -307,6 +307,14 @@ "import {A} from 'a';\n"); } +TEST_F(SortImportsTestJS, TemplateKeyword) { + // Reproduces issue where importing "template" disables imports sorting. + verifySort("import {template} from './a';\n" + "import {b} from './b';\n", + "import {b} from './b';\n" + "import {template} from './a';\n"); +} + } // end namespace } // end namespace format } // end namespace clang Index: clang/lib/Format/SortJavaScriptImports.cpp =================================================================== --- clang/lib/Format/SortJavaScriptImports.cpp +++ clang/lib/Format/SortJavaScriptImports.cpp @@ -409,7 +409,7 @@ nextToken(); if (Current->is(tok::r_brace)) break; - if (!Current->isOneOf(tok::identifier, tok::kw_default)) + if (!Current->isOneOf(tok::identifier, tok::kw_default, tok::kw_template)) return false; JsImportedSymbol Symbol;
Index: clang/unittests/Format/SortImportsTestJS.cpp =================================================================== --- clang/unittests/Format/SortImportsTestJS.cpp +++ clang/unittests/Format/SortImportsTestJS.cpp @@ -307,6 +307,14 @@ "import {A} from 'a';\n"); } +TEST_F(SortImportsTestJS, TemplateKeyword) { + // Reproduces issue where importing "template" disables imports sorting. + verifySort("import {template} from './a';\n" + "import {b} from './b';\n", + "import {b} from './b';\n" + "import {template} from './a';\n"); +} + } // end namespace } // end namespace format } // end namespace clang Index: clang/lib/Format/SortJavaScriptImports.cpp =================================================================== --- clang/lib/Format/SortJavaScriptImports.cpp +++ clang/lib/Format/SortJavaScriptImports.cpp @@ -409,7 +409,7 @@ nextToken(); if (Current->is(tok::r_brace)) break; - if (!Current->isOneOf(tok::identifier, tok::kw_default)) + if (!Current->isOneOf(tok::identifier, tok::kw_default, tok::kw_template)) return false; JsImportedSymbol Symbol;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits