Skip to content

Commit 090695a

Browse files
committed
Engine: fixed source mapping with strict types [Closes #205]
1 parent 53d256f commit 090695a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Latte/Engine.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ public function compile(string $name): string
126126
throw $e->setSource($source, $line, $name);
127127
}
128128

129-
if (!preg_match('#\n|\?#', $name)) {
130-
$code = "<?php\n// source: $name\n?>" . $code;
131-
}
132129
if ($this->strictTypes) {
133130
$code = "<?php\ndeclare(strict_types=1);\n?>" . $code;
134131
}
132+
if (!preg_match('#\n|\?#', $name)) {
133+
$code = "<?php\n// source: $name\n?>" . $code;
134+
}
135135
$code = PhpHelpers::reformatCode($code);
136136
return $code;
137137
}

tests/Latte/Engine.strictTypes.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ require __DIR__ . '/../bootstrap.php';
1111
$latte = new Latte\Engine;
1212
$latte->setLoader(new Latte\Loaders\StringLoader);
1313
Assert::notContains('declare(strict_types=1)', $latte->compile(''));
14+
Assert::same('// source: {123}', explode("\n", $latte->compile('{123}'))[1]);
1415

1516
$latte->setStrictTypes(true);
1617
Assert::contains('declare(strict_types=1)', $latte->compile(''));
1718

1819
Assert::noError(function () use ($latte) {
1920
$latte->render('');
2021
});
22+
23+
Assert::contains('declare(strict_types=1)', $latte->compile(''));
24+
Assert::same('// source: {123}', explode("\n", $latte->compile('{123}'))[1]);

0 commit comments

Comments
 (0)