clang-format: [JS] handle default bindings in imports.
Summary: Default imports appear outside of named bindings in curly braces: import A from 'a'; import A, {symbol} from 'a'; Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D23973 llvm-svn: 280486
This commit is contained in:
parent
b480ffbcef
commit
6918dcafe8
|
@ -346,7 +346,6 @@ private:
|
||||||
|
|
||||||
if (!parseModuleBindings(Keywords, Reference))
|
if (!parseModuleBindings(Keywords, Reference))
|
||||||
return false;
|
return false;
|
||||||
nextToken();
|
|
||||||
|
|
||||||
if (Current->is(Keywords.kw_from)) {
|
if (Current->is(Keywords.kw_from)) {
|
||||||
// imports have a 'from' clause, exports might not.
|
// imports have a 'from' clause, exports might not.
|
||||||
|
@ -389,19 +388,28 @@ private:
|
||||||
if (Current->isNot(tok::identifier))
|
if (Current->isNot(tok::identifier))
|
||||||
return false;
|
return false;
|
||||||
Reference.Prefix = Current->TokenText;
|
Reference.Prefix = Current->TokenText;
|
||||||
|
nextToken();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parseNamedBindings(const AdditionalKeywords &Keywords,
|
bool parseNamedBindings(const AdditionalKeywords &Keywords,
|
||||||
JsModuleReference &Reference) {
|
JsModuleReference &Reference) {
|
||||||
|
if (Current->is(tok::identifier)) {
|
||||||
|
nextToken();
|
||||||
|
if (Current->is(Keywords.kw_from))
|
||||||
|
return true;
|
||||||
|
if (Current->isNot(tok::comma))
|
||||||
|
return false;
|
||||||
|
nextToken(); // eat comma.
|
||||||
|
}
|
||||||
if (Current->isNot(tok::l_brace))
|
if (Current->isNot(tok::l_brace))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// {sym as alias, sym2 as ...} from '...';
|
// {sym as alias, sym2 as ...} from '...';
|
||||||
nextToken();
|
while (Current->isNot(tok::r_brace)) {
|
||||||
while (true) {
|
nextToken();
|
||||||
if (Current->is(tok::r_brace))
|
if (Current->is(tok::r_brace))
|
||||||
return true;
|
break;
|
||||||
if (Current->isNot(tok::identifier))
|
if (Current->isNot(tok::identifier))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -422,12 +430,11 @@ private:
|
||||||
Symbol.Range.setEnd(Current->Tok.getLocation());
|
Symbol.Range.setEnd(Current->Tok.getLocation());
|
||||||
Reference.Symbols.push_back(Symbol);
|
Reference.Symbols.push_back(Symbol);
|
||||||
|
|
||||||
if (Current->is(tok::r_brace))
|
if (!Current->isOneOf(tok::r_brace, tok::comma))
|
||||||
return true;
|
|
||||||
if (Current->isNot(tok::comma))
|
|
||||||
return false;
|
return false;
|
||||||
nextToken();
|
|
||||||
}
|
}
|
||||||
|
nextToken(); // consume r_brace
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,26 @@ TEST_F(SortImportsTestJS, BasicSorting) {
|
||||||
"let x = 1;");
|
"let x = 1;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SortImportsTestJS, DefaultBinding) {
|
||||||
|
verifySort("import A from 'a';\n"
|
||||||
|
"import B from 'b';\n"
|
||||||
|
"\n"
|
||||||
|
"let x = 1;",
|
||||||
|
"import B from 'b';\n"
|
||||||
|
"import A from 'a';\n"
|
||||||
|
"let x = 1;");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SortImportsTestJS, DefaultAndNamedBinding) {
|
||||||
|
verifySort("import A, {a} from 'a';\n"
|
||||||
|
"import B, {b} from 'b';\n"
|
||||||
|
"\n"
|
||||||
|
"let x = 1;",
|
||||||
|
"import B, {b} from 'b';\n"
|
||||||
|
"import A, {a} from 'a';\n"
|
||||||
|
"let x = 1;");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SortImportsTestJS, WrappedImportStatements) {
|
TEST_F(SortImportsTestJS, WrappedImportStatements) {
|
||||||
verifySort("import {sym1, sym2} from 'a';\n"
|
verifySort("import {sym1, sym2} from 'a';\n"
|
||||||
"import {sym} from 'b';\n"
|
"import {sym} from 'b';\n"
|
||||||
|
|
Loading…
Reference in New Issue