From 0506c907ddd7a45134c2c944ea1347ac58e2bd69 Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 17 Jul 2026 13:35:29 +0200 Subject: [PATCH 1/2] wip --- packages/view/src/Parser/TempestViewLexer.php | 5 +++++ packages/view/tests/TempestViewLexerTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/view/src/Parser/TempestViewLexer.php b/packages/view/src/Parser/TempestViewLexer.php index 83ee0ff78..90fdb654f 100644 --- a/packages/view/src/Parser/TempestViewLexer.php +++ b/packages/view/src/Parser/TempestViewLexer.php @@ -88,6 +88,11 @@ private function consume(int $length = 1): string if ($length === 1) { $char = $this->html[$this->position++] ?? null; + + if ($char === "\n") { + $this->line++; + } + $this->current = $this->html[$this->position] ?? null; return $char ?? ''; } diff --git a/packages/view/tests/TempestViewLexerTest.php b/packages/view/tests/TempestViewLexerTest.php index cd1c555cd..287719069 100644 --- a/packages/view/tests/TempestViewLexerTest.php +++ b/packages/view/tests/TempestViewLexerTest.php @@ -393,6 +393,22 @@ public function test_single_quote_attributes(): void ); } + public function test_source_mapping_line_count(): void + { + $tokens = iterator_to_array( + new TempestViewLexer("
\n\n
")->lex(), + ); + + $this->assertSame(1, $tokens[0]->line); + $this->assertSame(1, $tokens[1]->line); + $this->assertSame(1, $tokens[2]->line); + $this->assertSame(2, $tokens[3]->line); + $this->assertSame(2, $tokens[4]->line); + $this->assertSame(2, $tokens[5]->line); + $this->assertSame(2, $tokens[6]->line); + $this->assertSame(3, $tokens[7]->line); + } + private function assertTokens(array $expected, TokenCollection $actual): void { $this->assertCount(count($expected), $actual); From 0426d88d83943c0ad631fcb4b5becbac1f6a193f Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jul 2026 13:50:46 +0200 Subject: [PATCH 2/2] wip --- packages/view/src/Parser/TempestViewLexer.php | 1 + packages/view/tests/TempestViewLexerTest.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/packages/view/src/Parser/TempestViewLexer.php b/packages/view/src/Parser/TempestViewLexer.php index 90fdb654f..238cfe0b8 100644 --- a/packages/view/src/Parser/TempestViewLexer.php +++ b/packages/view/src/Parser/TempestViewLexer.php @@ -99,6 +99,7 @@ private function consume(int $length = 1): string $buffer = substr($this->html, $this->position, $length); $this->position += $length; + $this->line += substr_count($buffer, "\n"); $this->current = $this->html[$this->position] ?? null; return $buffer; diff --git a/packages/view/tests/TempestViewLexerTest.php b/packages/view/tests/TempestViewLexerTest.php index 287719069..7e7d19401 100644 --- a/packages/view/tests/TempestViewLexerTest.php +++ b/packages/view/tests/TempestViewLexerTest.php @@ -409,6 +409,15 @@ public function test_source_mapping_line_count(): void $this->assertSame(3, $tokens[7]->line); } + public function test_source_mapping_line_count_with_indentation(): void + { + $tokens = iterator_to_array( + new TempestViewLexer("
\n \n
")->lex(), + ); + + $this->assertSame(2, $tokens[3]->line); + } + private function assertTokens(array $expected, TokenCollection $actual): void { $this->assertCount(count($expected), $actual);