generateElseBlock generates the else block content.
()
| 142 | |
| 143 | // generateElseBlock generates the else block content. |
| 144 | func (g *GuardGenerator) generateElseBlock() { |
| 145 | // If we have source bytes, extract the actual else block content |
| 146 | if g.SourceBytes != nil && g.Location.ElseStart >= 0 && g.Location.ElseEnd > g.Location.ElseStart { |
| 147 | elseContent := string(g.SourceBytes[g.Location.ElseStart:g.Location.ElseEnd]) |
| 148 | // Indent each line, preserving blank lines and original formatting |
| 149 | lines := strings.Split(elseContent, "\n") |
| 150 | for i, line := range lines { |
| 151 | g.Write("\t") |
| 152 | g.Write(line) |
| 153 | // Don't add extra newline after last line (already has it from split) |
| 154 | if i < len(lines)-1 || len(line) > 0 { |
| 155 | g.WriteByte('\n') |
| 156 | } |
| 157 | } |
| 158 | } else { |
| 159 | // Placeholder for when source bytes are not available (e.g., in unit tests) |
| 160 | g.Write("\t// GUARD_LET_ELSE_BLOCK\n") |
| 161 | g.Write("\treturn\n") |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // generateBindings generates variable bindings for the success case. |
| 166 | func (g *GuardGenerator) generateBindings(tmpVar string) { |
no test coverage detected