diff --git a/src/runestone.jl b/src/runestone.jl index a77ef6e..127717e 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -203,6 +203,8 @@ function spaces_around_x(ctx::Context, node::JuliaSyntax.GreenNode, is_x::F) whe # Whitespace found at the beginning of next child. child_ws = first_leaf(child) looking_for_whitespace = JuliaSyntax.kind(last_leaf(child)) !== K"Whitespace" + @assert !is_x(child)::Bool + looking_for_x = true if JuliaSyntax.span(child_ws) == 1 # Accept the node accept_node!(ctx, child) @@ -216,6 +218,7 @@ function spaces_around_x(ctx::Context, node::JuliaSyntax.GreenNode, is_x::F) whe remaining_bytes_inclusive = @view original_bytes[(span_sum + 1 + bytes_to_skip - JuliaSyntax.span(child)):end] write_and_reset(ctx, remaining_bytes_inclusive) + accept_node!(ctx, child′) any_changes = true if children′ === children children′ = children[1:i - 1] diff --git a/test/runtests.jl b/test/runtests.jl index 5364102..100db48 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -143,6 +143,9 @@ end # JuliaSyntax.jl decides to place the K"Whitespace" node. @test format_string("$(sp)a$(sp)+$(sp)b$(sp)*$(sp)c$(sp)/$(sp)d$(sp)") == "$(sp)a + b * c / d$(sp)" + # Edgecase when using whitespace from the next leaf but the call chain continues + # after with more children. + @test format_string("$(sp)z$(sp)+$(sp)2x$(sp)+$(sp)z$(sp)") == "$(sp)z + 2x + z$(sp)" end end