forked from qt-creator/qt-creator
qmljs: correctly reformat js spread operator (...)
Fixes: QTCREATORBUG-23402 Change-Id: I6b4bd0846dac67116711b7ed046bd52d137b7674 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
@@ -989,6 +989,21 @@ protected:
|
||||
out("const ");
|
||||
}
|
||||
}
|
||||
switch (ast->type) {
|
||||
case PatternElement::Literal:
|
||||
case PatternElement::Method:
|
||||
case PatternElement::Binding:
|
||||
break;
|
||||
case PatternElement::Getter:
|
||||
out("get ");
|
||||
break;
|
||||
case PatternElement::Setter:
|
||||
out("set ");
|
||||
break;
|
||||
case PatternElement::SpreadElement:
|
||||
out("...");
|
||||
break;
|
||||
}
|
||||
out(ast->identifierToken);
|
||||
if (ast->initializer) {
|
||||
if (ast->isVariableDeclaration())
|
||||
@@ -1312,6 +1327,8 @@ protected:
|
||||
bool visit(ArgumentList *ast) override
|
||||
{
|
||||
for (ArgumentList *it = ast; it; it = it->next) {
|
||||
if (it->isSpreadElement)
|
||||
out("...");
|
||||
accept(it->expression);
|
||||
if (it->next) {
|
||||
out(", ", it->commaToken);
|
||||
|
@@ -12,6 +12,17 @@ function foo(a, b) {
|
||||
|
||||
var foo = function (a, b) {}
|
||||
|
||||
function spread() {
|
||||
iterableObj = [1, 2]
|
||||
obj = {
|
||||
"a": 42
|
||||
}
|
||||
foo(...iterableObj)
|
||||
let arr = [...iterableObj, '4', 'five', 6]
|
||||
foo(-1, ...args, 2, ...[3])
|
||||
console.log(Math.max(...[1, 2, 3, 4]))
|
||||
}
|
||||
|
||||
const func1 = x => x * 2
|
||||
const func2 = x => {
|
||||
return x * 7
|
||||
|
Reference in New Issue
Block a user