X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/59acf8af38a72e57b26d739adb5d5e7f350e8f2c..21218b666aeafd1c089cbe998e730f97605d25b2:/src/black/trans.py diff --git a/src/black/trans.py b/src/black/trans.py index dc9c552..9e0284c 100644 --- a/src/black/trans.py +++ b/src/black/trans.py @@ -553,6 +553,9 @@ class StringMerger(StringTransformer, CustomSplitMapMixin): next_str_idx += 1 + # Take a note on the index of the non-STRING leaf. + non_string_idx = next_str_idx + S_leaf = Leaf(token.STRING, S) if self.normalize_strings: S_leaf.value = normalize_string_quotes(S_leaf.value) @@ -572,7 +575,18 @@ class StringMerger(StringTransformer, CustomSplitMapMixin): string_leaf = Leaf(token.STRING, S_leaf.value.replace(BREAK_MARK, "")) if atom_node is not None: - replace_child(atom_node, string_leaf) + # If not all children of the atom node are merged (this can happen + # when there is a standalone comment in the middle) ... + if non_string_idx - string_idx < len(atom_node.children): + # We need to replace the old STRING leaves with the new string leaf. + first_child_idx = LL[string_idx].remove() + for idx in range(string_idx + 1, non_string_idx): + LL[idx].remove() + if first_child_idx is not None: + atom_node.insert_child(first_child_idx, string_leaf) + else: + # Else replace the atom node with the new string leaf. + replace_child(atom_node, string_leaf) # Build the final line ('new_line') that this method will later return. new_line = line.clone()