Repository: swc-project/swc
File: crates/swc_ecma_transforms_react/src/jsx/mod.rs (Rust)

Code before:
fn jsx_text_to_str_with_entity_mask(t: &str, entity_mask: &[bool]) -> Atom {
    // Fast path: if no line terminators and no trimmable whitespace
    // (whitespace that's not from entities at the leading edge)
    let chars: Vec<char> = t.chars().collect();
    let has_line_terminator = chars.iter().any(|&c| is_line_terminator(c));

    // For single-line text, we keep all whitespace (matching original behavior)
    // The original jsx_text_to_str_impl preserves leading/trailing whitespace on
    // single-line text
    if !t.is_empty() && !has_line_terminator {
        return t.into();
    }

    let mut acc: Option<String> = None;
    let mut only_line: Option<String> = None;
    let mut line_start: Option<usize> = Some(0);
    let mut line_end: Option<usize> = None;
    // Track if we've seen any line terminators - used to decide whether to trim
    // leading whitespace on the final line
    let mut seen_line_terminator = false;

    for (char_idx, c) in chars.iter().enumerate() {
        let is_from_entity = *entity_mask.get(char_idx).unwrap_or(&false);

        if is_line_terminator(*c) {
            seen_line_terminator = true;
            // Process current line - trim both leading AND trailing (intermediate
            // line)
            if let (Some(start), Some(end)) = (line_start, line_end) {
                let line_text = extract_line_content(&chars, start, end, entity_mask, true, true);
                add_line_of_jsx_text_owned(line_text, &mut acc, &mut only_line);
            }
            line_start = None;
            line_end = None;
        } else if !is_white_space_single_line(*c) || is_from_entity {
            // Non-whitespace or entity-derived whitespace - counts as content
            line_end = Some(char_idx + 1);
            if line_start.is_none() {
                line_start = Some(char_idx);
            }
        }
    }

    // Handle final line - only trim leading if we've seen line terminators
    // (matching original jsx_text_to_str_impl behavior where leading whitespace
    // is preserved on single-line text)
    if let Some(start) = line_start {
        let line_text = extract_line_content(
            &chars,
            start,
            chars.len(),

Review comment (suggestion):
The comment states this processes an "intermediate line" that trims "both leading AND trailing", but when `is_first_line` is true (i.e., processing the first line before any line terminators), only trailing whitespace is trimmed, not leading. Consider updating the comment to clarify that the trimming behavior depends on whether this is the first line or a subsequent line.
```suggestion
            // Process current line. Trailing whitespace is always trimmed; leading
            // whitespace is trimmed only on lines after the first.
```

Code after:
fn jsx_text_to_str_with_entity_mask(t: &str, entity_mask: &[bool]) -> Atom {
    // Fast path: if no line terminators and no trimmable whitespace
    // (whitespace that's not from entities at the leading edge)
    let chars: Vec<char> = t.chars().collect();
    let has_line_terminator = chars.iter().any(|&c| is_line_terminator(c));

    // For single-line text, we keep all whitespace (matching original behavior)
    // The original jsx_text_to_str_impl preserves leading/trailing whitespace on
    // single-line text
    if !t.is_empty() && !has_line_terminator {
        return t.into();
    }

    let mut acc: Option<String> = None;
    let mut only_line: Option<String> = None;
    let mut line_start: Option<usize> = Some(0);
    let mut line_end: Option<usize> = None;
    // The first line preserves leading whitespace; subsequent lines trim it.
    let mut is_first_line = true;

    for (char_idx, c) in chars.iter().enumerate() {
        let is_from_entity = *entity_mask.get(char_idx).unwrap_or(&false);

        if is_line_terminator(*c) {
            // Process current line - trim both leading AND trailing (intermediate
            // line)
            if let (Some(start), Some(end)) = (line_start, line_end) {
                let line_text =
                    extract_line_content(&chars, start, end, entity_mask, !is_first_line, true);
                add_line_of_jsx_text_owned(line_text, &mut acc, &mut only_line);
            }
            is_first_line = false;
            line_start = None;
            line_end = None;
        } else if !is_white_space_single_line(*c) || is_from_entity {
            // Non-whitespace or entity-derived whitespace - counts as content
            line_end = Some(char_idx + 1);
            if line_start.is_none() {
                line_start = Some(char_idx);
            }
        }
    }

    // Handle final line. Leading whitespace is preserved only if this is still
    // the first line (single-line input).
    if let Some(start) = line_start {
        let line_text = extract_line_content(
            &chars,
            start,
            chars.len(),
            entity_mask,