clang-format: [JS] Support ES6 destructuring assignments.
Before: var[a, b, c] = [1, 2, 3]; After: var [a, b, c] = [1, 2, 3]; llvm-svn: 209113
This commit is contained in:
parent
78214397a3
commit
0dd5291e69
|
@ -1381,6 +1381,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
||||||
if (Right.is(tok::l_paren) &&
|
if (Right.is(tok::l_paren) &&
|
||||||
(Left.TokenText == "returns" || Left.TokenText == "option"))
|
(Left.TokenText == "returns" || Left.TokenText == "option"))
|
||||||
return true;
|
return true;
|
||||||
|
} else if (Style.Language == FormatStyle::LK_JavaScript) {
|
||||||
|
if (Left.TokenText == "var")
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (Left.is(tok::kw_return) && Right.isNot(tok::semi))
|
if (Left.is(tok::kw_return) && Right.isNot(tok::semi))
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -81,6 +81,11 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
|
||||||
verifyFormat("var b = a.map((x) => x + 1);");
|
verifyFormat("var b = a.map((x) => x + 1);");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(FormatTestJS, ES6DestructuringAssignment) {
|
||||||
|
verifyFormat("var [a, b, c] = [1, 2, 3];");
|
||||||
|
verifyFormat("var {a, b} = {a: 1, b: 2};");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
|
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
|
||||||
verifyFormat("var arr = [1, 2, 3];");
|
verifyFormat("var arr = [1, 2, 3];");
|
||||||
verifyFormat("var obj = {a: 1, b: 2, c: 3};");
|
verifyFormat("var obj = {a: 1, b: 2, c: 3};");
|
||||||
|
|
Loading…
Reference in New Issue