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 <ulf.hermann@qt.io>
This commit is contained in:
Christian Stenger
2020-06-08 14:55:28 +02:00
parent 92942f0f12
commit 128341d4e2

View File

@@ -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;