zwoop commented on code in PR #12956:
URL: https://github.com/apache/trafficserver/pull/12956#discussion_r2919705303
##########
tools/hrw4u/src/hrw_visitor.py:
##########
@@ -407,10 +395,27 @@ def _close_if_and_section(self) -> None:
def _ensure_section_open(self, section_label: SectionType) -> None:
"""Ensure a section is open for statements."""
if not self._section_opened:
+ relocated_lines = None
+ relocated_if_depth = 0
+ if self._if_depth > 0 and self._pre_section_if_start is not None:
+ relocated_lines = self.output[self._pre_section_if_start:]
+ relocated_if_depth = self._if_depth
+ self.output = self.output[:self._pre_section_if_start]
+ self.stmt_indent -= self._if_depth
+ self._if_depth = 0
+ self._pre_section_if_start = None
+
self.emit(f"{section_label.value} {{")
self._section_opened = True
self.increase_indent()
+ if relocated_lines:
+ indent_prefix = " " * SystemDefaults.INDENT_SPACES
+ for line in relocated_lines:
+ self.output.append(indent_prefix + line if line.strip()
else line)
+ self._if_depth = relocated_if_depth
+ self.stmt_indent += relocated_if_depth
Review Comment:
As intended. The relocated lines are already-formatted strings extracted
from self.output, so emit_line would require re-parsing their existing
indentation. Adding exactly one INDENT_SPACES prefix is the right approach for
this relocation; the constant is already taken from SystemDefaults.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]