forked from qt-creator/qt-creator
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:
@@ -88,14 +88,15 @@ Rewriter::Range Rewriter::addBinding(AST::UiObjectInitializer *ast,
|
|||||||
bool needsTrailingSemicolon = false;
|
bool needsTrailingSemicolon = false;
|
||||||
|
|
||||||
if (isOneLiner) {
|
if (isOneLiner) {
|
||||||
|
bool hasTrailingSemicolon = propertyValue.endsWith(';');
|
||||||
if (insertAfter == nullptr) { // we're inserting after an lbrace
|
if (insertAfter == nullptr) { // we're inserting after an lbrace
|
||||||
if (ast->members) { // we're inserting before a member (and not the rbrace)
|
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
|
} else { // we're inserting after a member, not after the lbrace
|
||||||
if (endOfPreviousMember.isValid()) { // there already is a semicolon after the previous member
|
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:
|
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:
|
} else { // there is no semicolon after the previous member (probably because there is an rbrace after us/it, so:
|
||||||
needsPreceedingSemicolon = true;
|
needsPreceedingSemicolon = true;
|
||||||
|
Reference in New Issue
Block a user