diff --git a/src/emit/mod.rs b/src/emit/mod.rs index d052418..95a92e6 100644 --- a/src/emit/mod.rs +++ b/src/emit/mod.rs @@ -122,9 +122,14 @@ fn emit_ast_expr( { previous_post_whitespace_content = post_whitespace_content; if let Some(ws) = prev_whitespace_content { - eval.push(Instruction::AppendContent { - content: ws.source().clone(), - }); + eval.insert( + eval.len() - 2, + Instruction::AppendContent { + content: ws.source().clone(), + }, + ); + let index_index = end_indices.len() - 1; + end_indices[index_index] += 1; } if let TemplateAstExpr::IfConditional { expression } = &**expression { diff --git a/src/emit/snapshots/nomo__emit__tests__check_if_else_if.snap b/src/emit/snapshots/nomo__emit__tests__check_if_else_if.snap index 14b290f..ee52b87 100644 --- a/src/emit/snapshots/nomo__emit__tests__check_if_else_if.snap +++ b/src/emit/snapshots/nomo__emit__tests__check_if_else_if.snap @@ -21,15 +21,15 @@ expression: emit AppendContent { content: "foo" (13..16), }, + AppendContent { + content: " " (16..17), + }, Jump { - jump: 14, + jump: 13, }, AppendContent { content: " " (12..13), }, - AppendContent { - content: " " (16..17), - }, LoadFromContextToSlot { name: "bar" (28..31), slot: VariableSlot { @@ -48,28 +48,28 @@ expression: emit AppendContent { content: "bar" (35..38), }, + AppendContent { + content: " " (38..39), + }, Jump { - jump: 7, + jump: 6, }, AppendContent { content: " " (34..35), }, - AppendContent { - content: " " (38..39), - }, AppendContent { content: " " (49..50), }, AppendContent { content: "foobar" (50..56), }, + AppendContent { + content: " " (56..57), + }, Jump { - jump: 2, + jump: 1, }, AppendContent { content: " " (49..50), }, - AppendContent { - content: " " (56..57), - }, ] diff --git a/tests/cases/3-instructions@condition.snap b/tests/cases/3-instructions@condition.snap index 943c455..c2901f7 100644 --- a/tests/cases/3-instructions@condition.snap +++ b/tests/cases/3-instructions@condition.snap @@ -22,15 +22,15 @@ input_file: tests/cases/condition.nomo AppendContent { content: "Hello World!" (18..30), }, + AppendContent { + content: "\n" (30..31), + }, Jump { - jump: 3, + jump: 2, }, AppendContent { content: "\n " (13..18), }, - AppendContent { - content: "\n" (30..31), - }, AppendContent { content: "\n\n" (40..42), }, diff --git a/tests/cases/3-instructions@if_else_if.snap b/tests/cases/3-instructions@if_else_if.snap index 14b47e7..d19a4ed 100644 --- a/tests/cases/3-instructions@if_else_if.snap +++ b/tests/cases/3-instructions@if_else_if.snap @@ -22,15 +22,15 @@ input_file: tests/cases/if_else_if.nomo AppendContent { content: "Not Hello World! :C" (18..37), }, + AppendContent { + content: "\n" (37..38), + }, Jump { - jump: 9, + jump: 8, }, AppendContent { content: "\n " (13..18), }, - AppendContent { - content: "\n" (37..38), - }, LoadFromContextToSlot { name: "another_test" (49..61), slot: VariableSlot { @@ -49,13 +49,13 @@ input_file: tests/cases/if_else_if.nomo AppendContent { content: "Hello World!" (69..81), }, + AppendContent { + content: "\n" (81..82), + }, Jump { - jump: 2, + jump: 1, }, AppendContent { content: "\n " (64..69), }, - AppendContent { - content: "\n" (81..82), - }, ] diff --git a/tests/cases/4-output@condition.snap b/tests/cases/4-output@condition.snap index 78c70f2..1d5af6f 100644 --- a/tests/cases/4-output@condition.snap +++ b/tests/cases/4-output@condition.snap @@ -3,4 +3,4 @@ source: tests/file_tests.rs expression: output input_file: tests/cases/condition.nomo --- -"\n Hello World!\n\nmore" +"\n Hello World!\n\n\nmore" diff --git a/tests/cases/4-output@if_else_if.snap b/tests/cases/4-output@if_else_if.snap index bee69fc..efb547b 100644 --- a/tests/cases/4-output@if_else_if.snap +++ b/tests/cases/4-output@if_else_if.snap @@ -3,4 +3,4 @@ source: tests/file_tests.rs expression: output input_file: tests/cases/if_else_if.nomo --- -"\n\n Hello World!\n" +"\n \n Hello World!\n\n "