From 128341d4e223396a896363894b8a7f7fa92dff2b Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 8 Jun 2020 14:55:28 +0200 Subject: [PATCH] QmlJS: Fix possible duplicate semicolon When dragging a member inside or onto a "oneliner" item a duplicate semicolon can appear which makes the code invalid. Fixes: QTCREATORBUG-12560 Change-Id: Ifa824a64b951fde879625d321dfae48e167a9227 Reviewed-by: Ulf Hermann --- src/libs/qmljs/qmljsrewriter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/qmljs/qmljsrewriter.cpp b/src/libs/qmljs/qmljsrewriter.cpp index 62e56b4d985..a17ce722c9c 100644 --- a/src/libs/qmljs/qmljsrewriter.cpp +++ b/src/libs/qmljs/qmljsrewriter.cpp @@ -88,14 +88,15 @@ Rewriter::Range Rewriter::addBinding(AST::UiObjectInitializer *ast, bool needsTrailingSemicolon = false; if (isOneLiner) { + bool hasTrailingSemicolon = propertyValue.endsWith(';'); if (insertAfter == nullptr) { // we're inserting after an lbrace if (ast->members) { // we're inserting before a member (and not the rbrace) - needsTrailingSemicolon = bindingType == ScriptBinding; + needsTrailingSemicolon = bindingType == ScriptBinding && !hasTrailingSemicolon; } } else { // we're inserting after a member, not after the lbrace if (endOfPreviousMember.isValid()) { // there already is a semicolon after the previous member if (insertAfter->next && insertAfter->next->member) { // and the after us there is a member, not an rbrace, so: - needsTrailingSemicolon = bindingType == ScriptBinding; + needsTrailingSemicolon = bindingType == ScriptBinding && !hasTrailingSemicolon; } } else { // there is no semicolon after the previous member (probably because there is an rbrace after us/it, so: needsPreceedingSemicolon = true;