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:
Fawzi Mohamed
2021-02-23 08:59:37 +01:00
parent 670616c6f9
commit c0f9f29097
2 changed files with 28 additions and 0 deletions

View File

@@ -989,6 +989,21 @@ protected:
out("const "); 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); out(ast->identifierToken);
if (ast->initializer) { if (ast->initializer) {
if (ast->isVariableDeclaration()) if (ast->isVariableDeclaration())
@@ -1312,6 +1327,8 @@ protected:
bool visit(ArgumentList *ast) override bool visit(ArgumentList *ast) override
{ {
for (ArgumentList *it = ast; it; it = it->next) { for (ArgumentList *it = ast; it; it = it->next) {
if (it->isSpreadElement)
out("...");
accept(it->expression); accept(it->expression);
if (it->next) { if (it->next) {
out(", ", it->commaToken); out(", ", it->commaToken);

View File

@@ -12,6 +12,17 @@ function foo(a, b) {
var foo = function (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 func1 = x => x * 2
const func2 = x => { const func2 = x => {
return x * 7 return x * 7