owenpan updated this revision to Diff 557879.
owenpan added a comment.
Make the test case pass.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61663/new/
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
@@ -514,6 +514,14 @@
"export {Y};\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
@@ -548,10 +548,12 @@
nextToken();
if (Current->is(tok::r_brace))
break;
- bool isTypeOnly =
- Current->is(Keywords.kw_type) && Current->Next &&
- Current->Next->isOneOf(tok::identifier, tok::kw_default);
- if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+ auto IsIdentifier = [](const auto *Tok) {
+ return Tok->isOneOf(tok::identifier, tok::kw_default,
tok::kw_template);
+ };
+ bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+ IsIdentifier(Current->Next);
+ if (!isTypeOnly && !IsIdentifier(Current))
return false;
JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
if (Current->is(Keywords.kw_as)) {
nextToken();
- if (!Current->isOneOf(tok::identifier, tok::kw_default))
+ if (!IsIdentifier(Current))
return false;
Symbol.Alias = Current->TokenText;
nextToken();
Index: clang/unittests/Format/SortImportsTestJS.cpp
===================================================================
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@
"export {Y};\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
@@ -548,10 +548,12 @@
nextToken();
if (Current->is(tok::r_brace))
break;
- bool isTypeOnly =
- Current->is(Keywords.kw_type) && Current->Next &&
- Current->Next->isOneOf(tok::identifier, tok::kw_default);
- if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+ auto IsIdentifier = [](const auto *Tok) {
+ return Tok->isOneOf(tok::identifier, tok::kw_default, tok::kw_template);
+ };
+ bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+ IsIdentifier(Current->Next);
+ if (!isTypeOnly && !IsIdentifier(Current))
return false;
JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
if (Current->is(Keywords.kw_as)) {
nextToken();
- if (!Current->isOneOf(tok::identifier, tok::kw_default))
+ if (!IsIdentifier(Current))
return false;
Symbol.Alias = Current->TokenText;
nextToken();
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits